From patchwork Fri Sep 18 14:53:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 53917 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 159B4218E3 for ; Fri, 18 Sep 2015 15:00:31 +0000 (UTC) Received: by wicuu12 with SMTP id uu12sf9951478wic.2 for ; Fri, 18 Sep 2015 08:00:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=Et4wz2SsHgGzS+mQXt/xARmWAnSlwCHO0k4e879jx50=; b=kVUkoC8fS5fWs9i07mUlUPYisnXt2LJspxTgwhLEQJKhPxhhA+3ZLIyq4aowbWBqCk qc3Sv9eMcQn0pJJSG40I7WN3zhzF1QsFOAoNSTjW3Up47fRlcoEgHP8VkgoPkGJbueCO 8g2YJoF/c6iPO8xEgP/4eb0fMJ0W7KYBymABalCqBNh+KF6zCuo/+peLoLuSI+IP3tBY kT/xxhfhdI2VtWysReuK6GeNHH9BOOsPsVOev95fyV1RKIMh7FfUAQTjYouWyx3MaRx/ GmST+6HsM89kqGPEtlLiw8O5mEjBPtTLNh4DN9SdDS/cip2coFZFCjb3J0qXn8ryjuQc M8jQ== X-Gm-Message-State: ALoCoQkejG+T/Z+yDIPChGCHQU1D6ui+elZqEChaXtsfRMGh5XLjAdANeBO4mLeFi9aOUQLkbWnr X-Received: by 10.152.26.5 with SMTP id h5mr993658lag.5.1442588430375; Fri, 18 Sep 2015 08:00:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.100 with SMTP id l4ls85455lam.67.gmail; Fri, 18 Sep 2015 08:00:30 -0700 (PDT) X-Received: by 10.112.54.169 with SMTP id k9mr3212058lbp.95.1442588430209; Fri, 18 Sep 2015 08:00:30 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id i8si6393247lam.54.2015.09.18.08.00.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Sep 2015 08:00:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by lamp12 with SMTP id p12so31556164lam.0 for ; Fri, 18 Sep 2015 08:00:30 -0700 (PDT) X-Received: by 10.152.21.196 with SMTP id x4mr3394550lae.86.1442588430072; Fri, 18 Sep 2015 08:00:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp347212lbq; Fri, 18 Sep 2015 08:00:28 -0700 (PDT) X-Received: by 10.107.164.26 with SMTP id n26mr14347514ioe.189.1442588428377; Fri, 18 Sep 2015 08:00:28 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f201si7129888iof.103.2015.09.18.08.00.27; Fri, 18 Sep 2015 08:00:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754778AbbIRPAZ (ORCPT + 30 others); Fri, 18 Sep 2015 11:00:25 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:50526 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752598AbbIRO4H (ORCPT ); Fri, 18 Sep 2015 10:56:07 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id t8IEtcNc025249; Fri, 18 Sep 2015 09:55:38 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id t8IEtcB8020713; Fri, 18 Sep 2015 09:55:38 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Fri, 18 Sep 2015 09:55:38 -0500 Received: from rockdesk.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id t8IEseAX002598; Fri, 18 Sep 2015 09:55:35 -0500 From: Roger Quadros To: CC: , , , , , , , , , , Roger Quadros Subject: [PATCH v3 17/27] memory: omap-gpmc: Add irqchip support to the gpiochip Date: Fri, 18 Sep 2015 17:53:39 +0300 Message-ID: <1442588029-13769-18-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1442588029-13769-1-git-send-email-rogerq@ti.com> References: <1442588029-13769-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The WAIT pins support either rising or falling edge interrupts so add irqchip support to the gpiochip model. Signed-off-by: Roger Quadros --- drivers/memory/omap-gpmc.c | 132 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c index fdf19eeb..764e24a 100644 --- a/drivers/memory/omap-gpmc.c +++ b/drivers/memory/omap-gpmc.c @@ -13,6 +13,7 @@ * published by the Free Software Foundation. */ #include +#include #include #include #include @@ -227,6 +228,7 @@ struct omap3_gpmc_regs { struct gpmc_device { struct device *dev; struct gpio_chip gpio_chip; + struct irq_chip irq_chip; }; static struct resource gpmc_mem_root; @@ -1944,6 +1946,99 @@ err: return ret; } +static int gpmc_irq_endis(unsigned long hwirq, bool endis) +{ + u32 regval; + + /* WAITPIN starts at BIT 8 */ + hwirq += 8; + + regval = gpmc_read_reg(GPMC_IRQENABLE); + if (endis) + regval |= BIT(hwirq); + else + regval &= ~BIT(hwirq); + gpmc_write_reg(GPMC_IRQENABLE, regval); + + return 0; +} + +static void gpmc_irq_edge_config(unsigned long hwirq, bool rising_edge) +{ + u32 regval; + + /* WAITPIN starts at BIT 8 */ + hwirq += 8; + + regval = gpmc_read_reg(GPMC_CONFIG); + if (rising_edge) + regval &= ~BIT(hwirq); + else + regval |= BIT(hwirq); + + gpmc_write_reg(GPMC_CONFIG, regval); +} + +static void gpmc_irq_mask(struct irq_data *d) +{ + gpmc_irq_endis(d->hwirq, false); +} + +static void gpmc_irq_unmask(struct irq_data *d) +{ + gpmc_irq_endis(d->hwirq, true); +} + +static void gpmc_irq_ack(struct irq_data *d) +{ + unsigned hwirq = d->hwirq + 8; + + /* Setting bit to 1 clears (or Acks) the interrupt */ + gpmc_write_reg(GPMC_IRQSTATUS, BIT(hwirq)); +} + +static int gpmc_irq_set_type(struct irq_data *d, unsigned trigger) +{ + /* We can support either rising or falling edge at a time */ + if (trigger == IRQ_TYPE_EDGE_FALLING) + gpmc_irq_edge_config(d->hwirq, false); + else if (trigger == IRQ_TYPE_EDGE_RISING) + gpmc_irq_edge_config(d->hwirq, true); + else + return -EINVAL; + + return 0; +} + +static irqreturn_t gpmc_handle_irq(int irq, void *data) +{ + int hwirq, virq; + u32 regval; + struct gpmc_device *gpmc = data; + + regval = gpmc_read_reg(GPMC_IRQSTATUS); + regval >>= 8; /* we're only interested in WAIT pins */ + + if (!regval) + return IRQ_NONE; + + for (hwirq = 0; hwirq < gpmc->gpio_chip.ngpio; hwirq++) { + if (regval & BIT(hwirq)) { + virq = irq_find_mapping(gpmc->gpio_chip.irqdomain, + hwirq); + if (!virq) { + dev_warn(gpmc_dev, + "spurious irq detected hwirq %d, virq %d\n", + hwirq, virq); + } + + generic_handle_irq(virq); + } + } + + return IRQ_HANDLED; +} + static int gpmc_gpio_get_direction(struct gpio_chip *chip, unsigned offset) { return 1; /* we're input only */ @@ -1978,6 +2073,7 @@ static int gpmc_gpio_get(struct gpio_chip *chip, unsigned offset) static int gpmc_gpio_init(struct gpmc_device *gpmc) { int ret; + u32 regval; gpmc->gpio_chip.dev = gpmc->dev; gpmc->gpio_chip.owner = THIS_MODULE; @@ -1996,7 +2092,43 @@ static int gpmc_gpio_init(struct gpmc_device *gpmc) return ret; } + /* Disable interrupts */ + gpmc_write_reg(GPMC_IRQENABLE, 0); + + /* clear interrupts */ + regval = gpmc_read_reg(GPMC_IRQSTATUS); + gpmc_write_reg(GPMC_IRQSTATUS, regval); + + gpmc->irq_chip.name = DEVICE_NAME; + gpmc->irq_chip.irq_ack = gpmc_irq_ack; + gpmc->irq_chip.irq_mask = gpmc_irq_mask; + gpmc->irq_chip.irq_unmask = gpmc_irq_unmask; + gpmc->irq_chip.irq_set_type = gpmc_irq_set_type; + + ret = gpiochip_irqchip_add(&gpmc->gpio_chip, &gpmc->irq_chip, 0, + handle_edge_irq, IRQ_TYPE_NONE); + + if (ret) { + dev_err(gpmc->dev, "could not add irqchip to gpiochip: %d\n", + ret); + goto fail; + } + + /* We're sharing this IRQ with OMAP NAND driver */ + ret = devm_request_irq(gpmc->dev, gpmc_irq, gpmc_handle_irq, + IRQF_SHARED, DEVICE_NAME, gpmc); + if (ret) { + dev_err(gpmc->dev, "could not request gpmc irq (%d): %d\n", + gpmc_irq, ret); + goto fail; + } + return 0; + +fail: + gpiochip_remove(&gpmc->gpio_chip); + + return ret; } static void gpmc_gpio_exit(struct gpmc_device *gpmc)