From: Samuel Holland <samuel.holland@sifive.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
Linus Walleij <linus.walleij@linaro.org>,
Keguang Zhang <keguang.zhang@gmail.com>,
Alban Bedel <albeu@free.fr>, Doug Berger <opendmb@gmail.com>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Yixun Lan <dlan@gentoo.org>, Andy Shevchenko <andy@kernel.org>
Subject: Re: [PATCH v2 11/15] gpio: sifive: use new generic GPIO chip API
Date: Wed, 10 Sep 2025 19:37:46 -0500 [thread overview]
Message-ID: <01a7cc78-fdae-4a1e-bf78-961e7ec214b2@sifive.com> (raw)
In-Reply-To: <20250910-gpio-mmio-gpio-conv-part4-v2-11-f3d1a4c57124@linaro.org>
Hi Bartosz,
On 2025-09-10 2:12 AM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Convert the driver to using the new generic GPIO chip interfaces from
> linux/gpio/generic.h.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> drivers/gpio/gpio-sifive.c | 73 ++++++++++++++++++++++++----------------------
> 1 file changed, 38 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
> index 98ef975c44d9a6c9238605cfd1d5820fd70a66ca..2ced87ffd3bbf219c11857391eb4ea808adc0527 100644
> --- a/drivers/gpio/gpio-sifive.c
> +++ b/drivers/gpio/gpio-sifive.c
> @@ -7,6 +7,7 @@
> #include <linux/device.h>
> #include <linux/errno.h>
> #include <linux/gpio/driver.h>
> +#include <linux/gpio/generic.h>
> #include <linux/init.h>
> #include <linux/platform_device.h>
> #include <linux/property.h>
> @@ -32,7 +33,7 @@
>
> struct sifive_gpio {
> void __iomem *base;
> - struct gpio_chip gc;
> + struct gpio_generic_chip gen_gc;
> struct regmap *regs;
> unsigned long irq_state;
> unsigned int trigger[SIFIVE_GPIO_MAX];
> @@ -41,10 +42,10 @@ struct sifive_gpio {
>
> static void sifive_gpio_set_ie(struct sifive_gpio *chip, unsigned int offset)
> {
> - unsigned long flags;
> unsigned int trigger;
>
> - raw_spin_lock_irqsave(&chip->gc.bgpio_lock, flags);
> + guard(gpio_generic_lock_irqsave)(&chip->gen_gc);
> +
> trigger = (chip->irq_state & BIT(offset)) ? chip->trigger[offset] : 0;
> regmap_update_bits(chip->regs, SIFIVE_GPIO_RISE_IE, BIT(offset),
> (trigger & IRQ_TYPE_EDGE_RISING) ? BIT(offset) : 0);
> @@ -54,7 +55,6 @@ static void sifive_gpio_set_ie(struct sifive_gpio *chip, unsigned int offset)
> (trigger & IRQ_TYPE_LEVEL_HIGH) ? BIT(offset) : 0);
> regmap_update_bits(chip->regs, SIFIVE_GPIO_LOW_IE, BIT(offset),
> (trigger & IRQ_TYPE_LEVEL_LOW) ? BIT(offset) : 0);
> - raw_spin_unlock_irqrestore(&chip->gc.bgpio_lock, flags);
> }
>
> static int sifive_gpio_irq_set_type(struct irq_data *d, unsigned int trigger)
> @@ -72,13 +72,12 @@ static int sifive_gpio_irq_set_type(struct irq_data *d, unsigned int trigger)
> }
>
> static void sifive_gpio_irq_enable(struct irq_data *d)
> -{
> + {
This looks like an unintentional whitespace change.
> struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> struct sifive_gpio *chip = gpiochip_get_data(gc);
> irq_hw_number_t hwirq = irqd_to_hwirq(d);
> int offset = hwirq % SIFIVE_GPIO_MAX;
> u32 bit = BIT(offset);
> - unsigned long flags;
>
> gpiochip_enable_irq(gc, hwirq);
> irq_chip_enable_parent(d);
> @@ -86,13 +85,13 @@ static void sifive_gpio_irq_enable(struct irq_data *d)
> /* Switch to input */
> gc->direction_input(gc, offset);
>
> - raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
> - /* Clear any sticky pending interrupts */
> - regmap_write(chip->regs, SIFIVE_GPIO_RISE_IP, bit);
> - regmap_write(chip->regs, SIFIVE_GPIO_FALL_IP, bit);
> - regmap_write(chip->regs, SIFIVE_GPIO_HIGH_IP, bit);
> - regmap_write(chip->regs, SIFIVE_GPIO_LOW_IP, bit);
> - raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
> + scoped_guard(gpio_generic_lock_irqsave, &chip->gen_gc) {
> + /* Clear any sticky pending interrupts */
> + regmap_write(chip->regs, SIFIVE_GPIO_RISE_IP, bit);
> + regmap_write(chip->regs, SIFIVE_GPIO_FALL_IP, bit);
> + regmap_write(chip->regs, SIFIVE_GPIO_HIGH_IP, bit);
> + regmap_write(chip->regs, SIFIVE_GPIO_LOW_IP, bit);
> + }
This block (and the copy below) don't actually need any locking, since these are
R/W1C bits. From the manual: "Once the interrupt is pending, it will remain set
until a 1 is written to the *_ip register at that bit." I can send this as a
follow-up improvement if you want to keep this limited to the API conversion.
So with the minor whitespace fix:
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
Regards,
Samuel
>
> /* Enable interrupts */
> assign_bit(offset, &chip->irq_state, 1);
> @@ -118,15 +117,14 @@ static void sifive_gpio_irq_eoi(struct irq_data *d)
> struct sifive_gpio *chip = gpiochip_get_data(gc);
> int offset = irqd_to_hwirq(d) % SIFIVE_GPIO_MAX;
> u32 bit = BIT(offset);
> - unsigned long flags;
>
> - raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
> - /* Clear all pending interrupts */
> - regmap_write(chip->regs, SIFIVE_GPIO_RISE_IP, bit);
> - regmap_write(chip->regs, SIFIVE_GPIO_FALL_IP, bit);
> - regmap_write(chip->regs, SIFIVE_GPIO_HIGH_IP, bit);
> - regmap_write(chip->regs, SIFIVE_GPIO_LOW_IP, bit);
> - raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
> + scoped_guard(gpio_generic_lock_irqsave, &chip->gen_gc) {
> + /* Clear all pending interrupts */
> + regmap_write(chip->regs, SIFIVE_GPIO_RISE_IP, bit);
> + regmap_write(chip->regs, SIFIVE_GPIO_FALL_IP, bit);
> + regmap_write(chip->regs, SIFIVE_GPIO_HIGH_IP, bit);
> + regmap_write(chip->regs, SIFIVE_GPIO_LOW_IP, bit);
> + }
>
> irq_chip_eoi_parent(d);
> }
> @@ -179,6 +177,7 @@ static const struct regmap_config sifive_gpio_regmap_config = {
>
> static int sifive_gpio_probe(struct platform_device *pdev)
> {
> + struct gpio_generic_chip_config config;
> struct device *dev = &pdev->dev;
> struct irq_domain *parent;
> struct gpio_irq_chip *girq;
> @@ -217,13 +216,17 @@ static int sifive_gpio_probe(struct platform_device *pdev)
> */
> parent = irq_get_irq_data(chip->irq_number[0])->domain;
>
> - ret = bgpio_init(&chip->gc, dev, 4,
> - chip->base + SIFIVE_GPIO_INPUT_VAL,
> - chip->base + SIFIVE_GPIO_OUTPUT_VAL,
> - NULL,
> - chip->base + SIFIVE_GPIO_OUTPUT_EN,
> - chip->base + SIFIVE_GPIO_INPUT_EN,
> - BGPIOF_READ_OUTPUT_REG_SET);
> + config = (struct gpio_generic_chip_config) {
> + .dev = dev,
> + .sz = 4,
> + .dat = chip->base + SIFIVE_GPIO_INPUT_VAL,
> + .set = chip->base + SIFIVE_GPIO_OUTPUT_VAL,
> + .dirout = chip->base + SIFIVE_GPIO_OUTPUT_EN,
> + .dirin = chip->base + SIFIVE_GPIO_INPUT_EN,
> + .flags = BGPIOF_READ_OUTPUT_REG_SET,
> + };
> +
> + ret = gpio_generic_chip_init(&chip->gen_gc, &config);
> if (ret) {
> dev_err(dev, "unable to init generic GPIO\n");
> return ret;
> @@ -236,12 +239,12 @@ static int sifive_gpio_probe(struct platform_device *pdev)
> regmap_write(chip->regs, SIFIVE_GPIO_LOW_IE, 0);
> chip->irq_state = 0;
>
> - chip->gc.base = -1;
> - chip->gc.ngpio = ngpio;
> - chip->gc.label = dev_name(dev);
> - chip->gc.parent = dev;
> - chip->gc.owner = THIS_MODULE;
> - girq = &chip->gc.irq;
> + chip->gen_gc.gc.base = -1;
> + chip->gen_gc.gc.ngpio = ngpio;
> + chip->gen_gc.gc.label = dev_name(dev);
> + chip->gen_gc.gc.parent = dev;
> + chip->gen_gc.gc.owner = THIS_MODULE;
> + girq = &chip->gen_gc.gc.irq;
> gpio_irq_chip_set_chip(girq, &sifive_gpio_irqchip);
> girq->fwnode = dev_fwnode(dev);
> girq->parent_domain = parent;
> @@ -249,7 +252,7 @@ static int sifive_gpio_probe(struct platform_device *pdev)
> girq->handler = handle_bad_irq;
> girq->default_type = IRQ_TYPE_NONE;
>
> - return gpiochip_add_data(&chip->gc, chip);
> + return gpiochip_add_data(&chip->gen_gc.gc, chip);
> }
>
> static const struct of_device_id sifive_gpio_match[] = {
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-09-11 0:38 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-10 7:12 [PATCH v2 00/15] gpio: replace legacy bgpio_init() with its modernized alternative - part 4 Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 01/15] gpio: loongson1: allow building the module with COMPILE_TEST enabled Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 02/15] gpio: loongson1: use new generic GPIO chip API Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 03/15] gpio: hlwd: " Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 04/15] gpio: ath79: " Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 05/15] gpio: ath79: use the generic GPIO chip lock for IRQ handling Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 06/15] gpio: xgene-sb: use generic GPIO chip register read and write APIs Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 07/15] gpio: brcmstb: use new generic GPIO chip API Bartosz Golaszewski
2025-09-10 22:05 ` Florian Fainelli
2025-09-11 0:11 ` Doug Berger
2025-09-11 7:56 ` Bartosz Golaszewski
2025-09-11 8:02 ` Andy Shevchenko
2025-09-11 19:50 ` Doug Berger
2025-09-10 7:12 ` [PATCH v2 08/15] gpio: mt7621: " Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 09/15] gpio: mt7621: use the generic GPIO chip lock for IRQ handling Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 10/15] gpio: menz127: use new generic GPIO chip API Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 11/15] gpio: sifive: " Bartosz Golaszewski
2025-09-11 0:37 ` Samuel Holland [this message]
2025-09-11 7:58 ` Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 12/15] gpio: spacemit-k1: " Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 13/15] gpio: sodaville: " Bartosz Golaszewski
2025-09-10 7:19 ` Andy Shevchenko
2025-09-10 7:28 ` Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 14/15] gpio: mmio: " Bartosz Golaszewski
2025-09-10 7:12 ` [PATCH v2 15/15] gpio: move gpio-mmio-specific fields out of struct gpio_chip Bartosz Golaszewski
2025-09-10 21:32 ` [PATCH v2 00/15] gpio: replace legacy bgpio_init() with its modernized alternative - part 4 Linus Walleij
2025-09-11 7:38 ` Bartosz Golaszewski
2025-09-12 7:33 ` Linus Walleij
2025-09-12 7:26 ` 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=01a7cc78-fdae-4a1e-bf78-961e7ec214b2@sifive.com \
--to=samuel.holland@sifive.com \
--cc=albeu@free.fr \
--cc=andy@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=brgl@bgdev.pl \
--cc=dlan@gentoo.org \
--cc=florian.fainelli@broadcom.com \
--cc=keguang.zhang@gmail.com \
--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-mediatek@lists.infradead.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=opendmb@gmail.com \
--cc=paul.walmsley@sifive.com \
--cc=spacemit@lists.linux.dev \
/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