From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Philipp Zabel <p.zabel@pengutronix.de>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Théo Lebrun" <theo.lebrun@bootlin.com>
Subject: [PATCH 16/23] gpio: nomadik: support shared GPIO IRQs
Date: Wed, 14 Feb 2024 17:24:09 +0100 [thread overview]
Message-ID: <20240214-mbly-gpio-v1-16-f88c0ccf372b@bootlin.com> (raw)
In-Reply-To: <20240214-mbly-gpio-v1-0-f88c0ccf372b@bootlin.com>
Support a single IRQs used by multiple GPIO banks. Change the IRQ
handler type from a chained handler (as used by gpiolib
for ->parent_handler) to a threaded IRQ.
Use a fake raw spinlock to ensure generic_handle_irq() is called in a
no-irq context. See Documentation/driver-api/gpio/driver.rst, "CHAINED
CASCADED GPIO IRQCHIPS" for additional information.
The Mobileye EyeQ5 platform uses this GPIO controller and share an IRQ
for its two banks.
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/gpio/gpio-nomadik.c | 67 +++++++++++++++++++++------------------
include/linux/gpio/gpio-nomadik.h | 1 +
2 files changed, 38 insertions(+), 30 deletions(-)
diff --git a/drivers/gpio/gpio-nomadik.c b/drivers/gpio/gpio-nomadik.c
index 25c8490aa1b6..5b1e3b3efcff 100644
--- a/drivers/gpio/gpio-nomadik.c
+++ b/drivers/gpio/gpio-nomadik.c
@@ -254,27 +254,31 @@ static void nmk_gpio_irq_shutdown(struct irq_data *d)
clk_disable(nmk_chip->clk);
}
-static void nmk_gpio_irq_handler(struct irq_desc *desc)
+static irqreturn_t nmk_gpio_irq_handler(int irq, void *dev_id)
{
- struct irq_chip *host_chip = irq_desc_get_chip(desc);
- struct gpio_chip *chip = irq_desc_get_handler_data(desc);
- struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip);
- u32 status;
-
- chained_irq_enter(host_chip, desc);
+ struct nmk_gpio_chip *nmk_chip = dev_id;
+ struct gpio_chip *chip = &nmk_chip->chip;
+ unsigned long mask = GENMASK(chip->ngpio - 1, 0);
+ unsigned long flags, status;
+ int bit;
clk_enable(nmk_chip->clk);
+
status = readl(nmk_chip->addr + NMK_GPIO_IS);
- clk_disable(nmk_chip->clk);
- while (status) {
- int bit = __ffs(status);
+ /* Ensure we cannot leave pending bits; this should never occur. */
+ if (unlikely(status & ~mask))
+ writel(status & ~mask, nmk_chip->addr + NMK_GPIO_IC);
+
+ clk_disable(nmk_chip->clk);
+ for_each_set_bit(bit, &status, chip->ngpio) {
+ raw_spin_lock_irqsave(&nmk_chip->fake_lock, flags);
generic_handle_domain_irq(chip->irq.domain, bit);
- status &= ~BIT(bit);
+ raw_spin_unlock_irqrestore(&nmk_chip->fake_lock, flags);
}
- chained_irq_exit(host_chip, desc);
+ return IRQ_RETVAL((status & mask) != 0);
}
/* I/O Functions */
@@ -566,19 +570,20 @@ static const struct irq_chip nmk_irq_chip = {
GPIOCHIP_IRQ_RESOURCE_HELPERS,
};
-static int nmk_gpio_probe(struct platform_device *dev)
+static int nmk_gpio_probe(struct platform_device *pdev)
{
- struct device_node *np = dev->dev.of_node;
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
struct nmk_gpio_chip *nmk_chip;
- struct gpio_chip *chip;
struct gpio_irq_chip *girq;
bool supports_sleepmode;
+ struct gpio_chip *chip;
int irq;
int ret;
- nmk_chip = nmk_gpio_populate_chip(np, dev);
+ nmk_chip = nmk_gpio_populate_chip(np, pdev);
if (IS_ERR(nmk_chip)) {
- dev_err(&dev->dev, "could not populate nmk chip struct\n");
+ dev_err(dev, "could not populate nmk chip struct\n");
return PTR_ERR(nmk_chip);
}
@@ -586,9 +591,9 @@ static int nmk_gpio_probe(struct platform_device *dev)
of_property_read_bool(np, "st,supports-sleepmode");
/* Correct platform device ID */
- dev->id = nmk_chip->bank;
+ pdev->id = nmk_chip->bank;
- irq = platform_get_irq(dev, 0);
+ irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
@@ -600,7 +605,7 @@ static int nmk_gpio_probe(struct platform_device *dev)
spin_lock_init(&nmk_chip->lock);
chip = &nmk_chip->chip;
- chip->parent = &dev->dev;
+ chip->parent = dev;
chip->request = gpiochip_generic_request;
chip->free = gpiochip_generic_free;
chip->get_direction = nmk_gpio_get_dir;
@@ -614,17 +619,19 @@ static int nmk_gpio_probe(struct platform_device *dev)
girq = &chip->irq;
gpio_irq_chip_set_chip(girq, &nmk_irq_chip);
- girq->parent_handler = nmk_gpio_irq_handler;
- girq->num_parents = 1;
- girq->parents = devm_kcalloc(&dev->dev, 1,
- sizeof(*girq->parents),
- GFP_KERNEL);
- if (!girq->parents)
- return -ENOMEM;
- girq->parents[0] = irq;
+ girq->parent_handler = NULL;
+ girq->num_parents = 0;
+ girq->parents = NULL;
girq->default_type = IRQ_TYPE_NONE;
girq->handler = handle_edge_irq;
+ ret = devm_request_irq(dev, irq, nmk_gpio_irq_handler, IRQF_SHARED,
+ dev_name(dev), nmk_chip);
+ if (ret) {
+ dev_err(dev, "failed requesting IRQ\n");
+ return ret;
+ }
+
clk_enable(nmk_chip->clk);
nmk_chip->lowemi = readl_relaxed(nmk_chip->addr + NMK_GPIO_LOWEMI);
clk_disable(nmk_chip->clk);
@@ -633,9 +640,9 @@ static int nmk_gpio_probe(struct platform_device *dev)
if (ret)
return ret;
- platform_set_drvdata(dev, nmk_chip);
+ platform_set_drvdata(pdev, nmk_chip);
- dev_info(&dev->dev, "chip registered\n");
+ dev_info(dev, "chip registered\n");
return 0;
}
diff --git a/include/linux/gpio/gpio-nomadik.h b/include/linux/gpio/gpio-nomadik.h
index 0166ddb71f43..8f7bb756ad35 100644
--- a/include/linux/gpio/gpio-nomadik.h
+++ b/include/linux/gpio/gpio-nomadik.h
@@ -56,6 +56,7 @@ struct nmk_gpio_chip {
unsigned int bank;
void (*set_ioforce)(bool enable);
spinlock_t lock;
+ raw_spinlock_t fake_lock;
bool sleepmode;
/* Keep track of configured edges */
u32 edge_rising;
--
2.43.1
next prev parent reply other threads:[~2024-02-14 16:24 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 16:23 [PATCH 00/23] Rework Nomadik GPIO to add Mobileye EyeQ5 support Théo Lebrun
2024-02-14 16:23 ` [PATCH 01/23] dt-bindings: gpio: nomadik: convert into yaml format Théo Lebrun
2024-02-15 9:11 ` Krzysztof Kozlowski
2024-02-15 9:47 ` Théo Lebrun
2024-02-19 14:50 ` Linus Walleij
2024-02-14 16:23 ` [PATCH 02/23] dt-bindings: gpio: nomadik: add optional ngpios property Théo Lebrun
2024-02-15 9:12 ` Krzysztof Kozlowski
2024-02-19 14:50 ` Linus Walleij
2024-02-19 14:55 ` Théo Lebrun
2024-02-14 16:23 ` [PATCH 03/23] dt-bindings: gpio: nomadik: add mobileye,eyeq5-gpio compatible Théo Lebrun
2024-02-15 9:13 ` Krzysztof Kozlowski
2024-02-15 9:52 ` Théo Lebrun
2024-02-14 16:23 ` [PATCH 04/23] dt-bindings: gpio: nomadik: add optional reset property Théo Lebrun
2024-02-15 9:13 ` Krzysztof Kozlowski
2024-02-19 14:55 ` Linus Walleij
2024-02-14 16:23 ` [PATCH 05/23] gpio: nomadik: extract GPIO platform driver from drivers/pinctrl/nomadik/ Théo Lebrun
2024-02-15 10:03 ` Philipp Zabel
2024-02-16 10:43 ` Théo Lebrun
2024-02-19 15:33 ` Bartosz Golaszewski
2024-02-21 11:41 ` Philipp Zabel
2024-02-19 16:08 ` Bartosz Golaszewski
2024-02-21 16:02 ` Théo Lebrun
2024-02-21 14:37 ` Linus Walleij
2024-02-21 16:20 ` Théo Lebrun
2024-02-21 19:31 ` Linus Walleij
2024-02-14 16:23 ` [PATCH 06/23] pinctrl: nomadik: fix build warning (-Wformat) Théo Lebrun
2024-02-14 16:24 ` [PATCH 07/23] pinctrl: nomadik: fix build warning (-Wpointer-to-int-cast) Théo Lebrun
2024-02-14 16:24 ` [PATCH 08/23] pinctrl: nomadik: minimise indentation in probe Théo Lebrun
2024-02-14 16:24 ` [PATCH 09/23] pinctrl: nomadik: follow type-system kernel coding conventions Théo Lebrun
2024-02-14 16:24 ` [PATCH 10/23] pinctrl: nomadik: follow whitespace " Théo Lebrun
2024-02-14 16:24 ` [PATCH 11/23] pinctrl: nomadik: follow conditional " Théo Lebrun
2024-02-14 16:24 ` [PATCH 12/23] gpio: nomadik: request dynamic ID allocation Théo Lebrun
2024-02-14 16:24 ` [PATCH 13/23] gpio: nomadik: fix offset bug in nmk_pmx_set() Théo Lebrun
2024-02-19 15:54 ` Bartosz Golaszewski
2024-02-21 15:57 ` Théo Lebrun
2024-02-19 21:56 ` Linus Walleij
2024-02-21 16:05 ` Théo Lebrun
2024-02-14 16:24 ` [PATCH 14/23] gpio: nomadik: make clock optional Théo Lebrun
2024-02-14 16:24 ` [PATCH 15/23] gpio: nomadik: change driver name from gpio to gpio-nomadik Théo Lebrun
2024-02-14 16:24 ` Théo Lebrun [this message]
2024-02-19 15:48 ` [PATCH 16/23] gpio: nomadik: support shared GPIO IRQs Bartosz Golaszewski
2024-02-19 15:54 ` Théo Lebrun
2024-02-19 16:17 ` Bartosz Golaszewski
2024-02-20 8:07 ` Linus Walleij
2024-02-14 16:24 ` [PATCH 17/23] gpio: nomadik: handle variadic GPIO count Théo Lebrun
2024-02-19 16:17 ` Bartosz Golaszewski
2024-02-20 8:08 ` Linus Walleij
2024-02-14 16:24 ` [PATCH 18/23] gpio: nomadik: support mobileye,eyeq5-gpio Théo Lebrun
2024-02-21 13:45 ` Linus Walleij
2024-02-21 16:22 ` Théo Lebrun
2024-02-21 14:31 ` Linus Walleij
2024-02-21 16:16 ` Théo Lebrun
2024-02-21 19:36 ` Linus Walleij
2024-02-22 9:37 ` Théo Lebrun
2024-02-14 16:24 ` [PATCH 19/23] gpio: nomadik: grab optional reset control and deassert it at probe Théo Lebrun
2024-02-15 10:19 ` Philipp Zabel
2024-02-16 10:46 ` Théo Lebrun
2024-02-14 16:24 ` [PATCH 20/23] MIPS: eyeq5_defconfig: enable GPIO by default Théo Lebrun
2024-02-14 16:24 ` [PATCH 21/23] MIPS: mobileye: eyeq5: add two GPIO bank nodes Théo Lebrun
2024-02-14 16:24 ` [PATCH 22/23] MIPS: mobileye: eyeq5: add resets to GPIO banks Théo Lebrun
2024-02-14 16:24 ` [PATCH 23/23] MIPS: mobileye: eyeq5: map GPIOs to pins using gpio-ranges Théo Lebrun
2024-02-19 15:44 ` [PATCH 00/23] Rework Nomadik GPIO to add Mobileye EyeQ5 support Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240214-mbly-gpio-v1-16-f88c0ccf372b@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregory.clement@bootlin.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh+dt@kernel.org \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tsbogend@alpha.franken.de \
--cc=vladimir.kondratiev@mobileye.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).