Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4907980imm; Mon, 11 Jun 2018 22:29:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLhGl6Z1xYHEIrQGHSQneaKA+aI2t1MVqwwXc3TRctzS9nuI3qW1fYjJotZOs93KyniD1Qz X-Received: by 2002:a65:590c:: with SMTP id f12-v6mr1954615pgu.128.1528781376664; Mon, 11 Jun 2018 22:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528781376; cv=none; d=google.com; s=arc-20160816; b=Yb0T+Ictyty/AS80pM3ZxlL7B6VRpRw90hx+jBlJpSdGgrOMkxraaiVKjXMO8CUo/B KBtHSvMHHm3oKskYZvYM42bNQl2pwWyOrxXzqtJCTSrl9SIwaC0CJr0MV1Q4Gn7f06xG szZiQLBK8LW1h6YG8GWkqZ4TKhXL/PmsRqMBbwKZ7Dt5Ugx5pZxwk9UoPS65XuS9o53A A/r/tdBj/NsHce/ySIZFyOUKPrNQ8rfDaY9YVjNJUXsnarauG+/rhLJj9VolefKMBKxq jcPW33dpmu3T/eNzQyIhqTOyAUlXBrBsy7n9TLJqI7U61CABFtbGIg8n2/sVW06r0D1I SIZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=u3pM9a/KBLgU++yKBpplB/FFLh9A8ubHrXiUet4sDbQ=; b=M2Rt1i+oBwzmYIl/DPv1scHjN9OFrNWxph8wRuCg3yierNea+nQGzlKuWU9T4yNcLz MNVKgd7F/wDMy9Lm2RJXCAJw0y7otG5xrlgc+QYR7sD7LbglTIjwglcRopWN3LUkLyah Jf7lwOnFzDUJVFtbCdvOEC+WgqQozkE566+yPYbM1p7Me58vLJ/mbzKusQCaUzpZ0JyU CI9go6lgyEI6hZYn9Z2PlabKhM2ENC/Ww7ijX7GKa8VNyL2J09xX85yc+LKBZCUIGVIl 6dpJXxrCdIeO5ODZNYjVqsdHXQIeE8Gzzj/ZRFzm5w2Y7u9GWX9602XYVMoVo531tsGU Bbnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=vOIRJYjp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z15-v6si35031pgo.428.2018.06.11.22.29.22; Mon, 11 Jun 2018 22:29:36 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=vOIRJYjp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932961AbeFLF20 (ORCPT + 99 others); Tue, 12 Jun 2018 01:28:26 -0400 Received: from fllnx209.ext.ti.com ([198.47.19.16]:63276 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932286AbeFLF2X (ORCPT ); Tue, 12 Jun 2018 01:28:23 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w5C5SM7x003683; Tue, 12 Jun 2018 00:28:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1528781302; bh=u3pM9a/KBLgU++yKBpplB/FFLh9A8ubHrXiUet4sDbQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=vOIRJYjpObb1ZQPL9jZmnDBo6UAPUJrTGfY6X37geZZrkQU36rZggqBXTx0evwLlP mPIUgO0K5hQEpux4/CK0xPrxMAeXFJkjn5c0LnD3jEEqZhyGvsWkiKZnt4RNh2awdd C+hzwpdI03LHvVx7NV198yB0LKNkWFHr9tR5AYL8= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w5C5SM34009961; Tue, 12 Jun 2018 00:28:22 -0500 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Tue, 12 Jun 2018 00:28:22 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Tue, 12 Jun 2018 00:28:22 -0500 Received: from ula0393675.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w5C5S0Lo032243; Tue, 12 Jun 2018 00:28:20 -0500 From: Keerthy To: CC: , , , , Subject: [PATCH v2 2/2] gpio: davinci: Do not assume continuous IRQ numbering Date: Tue, 12 Jun 2018 10:57:53 +0530 Message-ID: <1528781273-18098-2-git-send-email-j-keerthy@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1528781273-18098-1-git-send-email-j-keerthy@ti.com> References: <1528781273-18098-1-git-send-email-j-keerthy@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the driver assumes that the interrupts are continuous and does platform_get_irq only once and assumes the rest are continuous, instead call platform_get_irq for all the interrupts and store them in an array for later use. Signed-off-by: Keerthy --- Tested for GPIO Interrupts on da850-lcdk and keystone-k2g-evm boards. Changes in v2: * Extended the logic of using saved IRQs to unbanked IRQs as per Grygorii's suggestion. drivers/gpio/gpio-davinci.c | 53 +++++++++++++++++++----------- include/linux/platform_data/gpio-davinci.h | 3 +- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c index 861f35b..b2119c0 100644 --- a/drivers/gpio/gpio-davinci.c +++ b/drivers/gpio/gpio-davinci.c @@ -55,7 +55,7 @@ static inline struct davinci_gpio_regs __iomem *irq2regs(struct irq_data *d) return g; } -static int davinci_gpio_irq_setup(struct platform_device *pdev, int bank_irq); +static int davinci_gpio_irq_setup(struct platform_device *pdev); /*--------------------------------------------------------------------------*/ @@ -168,7 +168,8 @@ static int davinci_gpio_probe(struct platform_device *pdev) { static int ctrl_num, bank_base; int gpio, bank, ret = 0; - unsigned ngpio, nbank, bank_irq; + unsigned int ngpio, nbank, nirq; + int i; struct davinci_gpio_controller *chips; struct davinci_gpio_platform_data *pdata; struct device *dev = &pdev->dev; @@ -197,6 +198,16 @@ static int davinci_gpio_probe(struct platform_device *pdev) if (WARN_ON(ARCH_NR_GPIOS < ngpio)) ngpio = ARCH_NR_GPIOS; + /* + * If there are unbanked interrupts then the number of + * interrupts is equal to number of gpios else all are banked so + * number of interrupts is equal to number of banks(each with 16 gpios) + */ + if (pdata->gpio_unbanked) + nirq = pdata->gpio_unbanked; + else + nirq = DIV_ROUND_UP(ngpio, 16); + nbank = DIV_ROUND_UP(ngpio, 32); chips = devm_kzalloc(dev, nbank * sizeof(struct davinci_gpio_controller), @@ -209,10 +220,13 @@ static int davinci_gpio_probe(struct platform_device *pdev) if (IS_ERR(gpio_base)) return PTR_ERR(gpio_base); - bank_irq = platform_get_irq(pdev, 0); - if (bank_irq < 0) { - dev_dbg(dev, "IRQ not populated\n"); - return bank_irq; + for (i = 0; i < nirq; i++) { + chips->irqs[i] = platform_get_irq(pdev, i); + if (chips->irqs[i] < 0) { + dev_info(dev, "IRQ not populated, err = %d\n", + chips->irqs[i]); + return chips->irqs[i]; + } } snprintf(label, MAX_LABEL_SIZE, "davinci_gpio.%d", ctrl_num++); @@ -249,7 +263,7 @@ static int davinci_gpio_probe(struct platform_device *pdev) goto err; platform_set_drvdata(pdev, chips); - ret = davinci_gpio_irq_setup(pdev, bank_irq); + ret = davinci_gpio_irq_setup(pdev); if (ret) goto err; @@ -383,7 +397,7 @@ static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset) * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). */ if (offset < d->gpio_unbanked) - return d->base_irq + offset; + return d->irqs[offset]; else return -ENODEV; } @@ -396,7 +410,7 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger) d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data); g = (struct davinci_gpio_regs __iomem *)d->regs[0]; - mask = __gpio_mask(data->irq - d->base_irq); + mask = __gpio_mask(data->irq - d->irqs[0]); if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) return -EINVAL; @@ -458,7 +472,7 @@ static struct irq_chip *keystone_gpio_get_irq_chip(unsigned int irq) * (dm6446) can be set appropriately for GPIOV33 pins. */ -static int davinci_gpio_irq_setup(struct platform_device *pdev, int bank_irq) +static int davinci_gpio_irq_setup(struct platform_device *pdev) { unsigned gpio, bank; int irq; @@ -492,6 +506,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev, int bank_irq) dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk)); return PTR_ERR(clk); } + ret = clk_prepare_enable(clk); if (ret) return ret; @@ -531,12 +546,11 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev, int bank_irq) if (pdata->gpio_unbanked) { /* pass "bank 0" GPIO IRQs to AINTC */ chips->chip.to_irq = gpio_to_irq_unbanked; - chips->base_irq = bank_irq; chips->gpio_unbanked = pdata->gpio_unbanked; binten = GENMASK(pdata->gpio_unbanked / 16, 0); /* AINTC handles mask/unmask; GPIO handles triggering */ - irq = bank_irq; + irq = chips->irqs[0]; irq_chip = gpio_get_irq_chip(irq); irq_chip->name = "GPIO-AINTC"; irq_chip->irq_set_type = gpio_irq_type_unbanked; @@ -547,10 +561,11 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev, int bank_irq) writel_relaxed(~0, &g->set_rising); /* set the direct IRQs up to use that irqchip */ - for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) { - irq_set_chip(irq, irq_chip); - irq_set_handler_data(irq, chips); - irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH); + for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++) { + irq_set_chip(chips->irqs[gpio], irq_chip); + irq_set_handler_data(chips->irqs[gpio], chips); + irq_set_status_flags(chips->irqs[gpio], + IRQ_TYPE_EDGE_BOTH); } goto done; @@ -560,7 +575,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev, int bank_irq) * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we * then chain through our own handler. */ - for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) { + for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 16) { /* disabled by default, enabled only as needed * There are register sets for 32 GPIOs. 2 banks of 16 * GPIOs are covered by each set of registers hence divide by 2 @@ -587,8 +602,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev, int bank_irq) irqdata->bank_num = bank; irqdata->chip = chips; - irq_set_chained_handler_and_data(bank_irq, gpio_irq_handler, - irqdata); + irq_set_chained_handler_and_data(chips->irqs[bank], + gpio_irq_handler, irqdata); binten |= BIT(bank); } diff --git a/include/linux/platform_data/gpio-davinci.h b/include/linux/platform_data/gpio-davinci.h index 90ae19c..cf884d1 100644 --- a/include/linux/platform_data/gpio-davinci.h +++ b/include/linux/platform_data/gpio-davinci.h @@ -22,6 +22,7 @@ #include #define MAX_REGS_BANKS 5 +#define MAX_INT_PER_BANK 32 struct davinci_gpio_platform_data { u32 ngpio; @@ -41,7 +42,7 @@ struct davinci_gpio_controller { spinlock_t lock; void __iomem *regs[MAX_REGS_BANKS]; int gpio_unbanked; - unsigned int base_irq; + unsigned int irqs[MAX_INT_PER_BANK]; unsigned int base; }; -- 1.9.1