* [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip()
2025-08-12 9:57 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
@ 2025-08-12 9:57 ` Bartosz Golaszewski
0 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-12 9:57 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Provide a helper allowing to convert a struct gpio_chip address to the
struct gpio_generic_chip that wraps it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
include/linux/gpio/generic.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/gpio/generic.h b/include/linux/gpio/generic.h
index f3a8db4598bb59f1dba4fbebace24dc10be44ae4..5a85ecbef8d234d9cf0c2f1db7a97f5f3781b2e4 100644
--- a/include/linux/gpio/generic.h
+++ b/include/linux/gpio/generic.h
@@ -55,6 +55,12 @@ struct gpio_generic_chip {
struct gpio_chip gc;
};
+static inline struct gpio_generic_chip *
+to_gpio_generic_chip(struct gpio_chip *gc)
+{
+ return container_of(gc, struct gpio_generic_chip, gc);
+}
+
/**
* gpio_generic_chip_init() - Initialize a generic GPIO chip.
* @chip: Generic GPIO chip to set up.
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip()
2025-08-12 12:12 Bartosz Golaszewski
@ 2025-08-12 12:12 ` Bartosz Golaszewski
0 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-12 12:12 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Provide a helper allowing to convert a struct gpio_chip address to the
struct gpio_generic_chip that wraps it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
include/linux/gpio/generic.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/gpio/generic.h b/include/linux/gpio/generic.h
index f3a8db4598bb59f1dba4fbebace24dc10be44ae4..5a85ecbef8d234d9cf0c2f1db7a97f5f3781b2e4 100644
--- a/include/linux/gpio/generic.h
+++ b/include/linux/gpio/generic.h
@@ -55,6 +55,12 @@ struct gpio_generic_chip {
struct gpio_chip gc;
};
+static inline struct gpio_generic_chip *
+to_gpio_generic_chip(struct gpio_chip *gc)
+{
+ return container_of(gc, struct gpio_generic_chip, gc);
+}
+
/**
* gpio_generic_chip_init() - Initialize a generic GPIO chip.
* @chip: Generic GPIO chip to set up.
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative
@ 2025-08-25 9:48 Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
` (15 more replies)
0 siblings, 16 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
Resending due to some patches missing in lore.
This is the first round of GPIO driver conversions to using the
modernized variant of the gpio-mmio API.
While at it: sprinkle in some additional tweaks and refactoring.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
Bartosz Golaszewski (14):
gpio: generic: provide to_gpio_generic_chip()
gpio: generic: provide helpers for reading and writing registers
gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag
gpio: ts4800: remove the unnecessary call to platform_set_drvdata()
gpio: ts4800: use generic device properties
gpio: ts4800: use dev_err_probe()
gpio: ts4800: use new generic GPIO chip API
gpio: loongson-64bit: use new generic GPIO chip API
gpio: dwapb: use new generic GPIO chip API
gpio: amdpt: use new generic GPIO chip API
gpio: rda: use new generic GPIO chip API
gpio: grgpio: use new generic GPIO chip API
gpio: mpc8xxx: use new generic GPIO chip API
gpio: ge: use new generic GPIO chip API
drivers/gpio/gpio-amdpt.c | 44 +++++-----
drivers/gpio/gpio-dwapb.c | 160 ++++++++++++++++++++-----------------
drivers/gpio/gpio-ge.c | 25 ++++--
drivers/gpio/gpio-grgpio.c | 87 ++++++++++----------
drivers/gpio/gpio-hisi.c | 3 +-
drivers/gpio/gpio-loongson-64bit.c | 42 +++++-----
drivers/gpio/gpio-mpc8xxx.c | 102 +++++++++++++----------
drivers/gpio/gpio-rda.c | 35 ++++----
drivers/gpio/gpio-ts4800.c | 39 ++++-----
include/linux/gpio/generic.h | 37 +++++++++
10 files changed, 337 insertions(+), 237 deletions(-)
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250728-gpio-mmio-gpio-conv-623517c3df74
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip()
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 02/14] gpio: generic: provide helpers for reading and writing registers Bartosz Golaszewski
` (14 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Provide a helper allowing to convert a struct gpio_chip address to the
struct gpio_generic_chip that wraps it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
include/linux/gpio/generic.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/gpio/generic.h b/include/linux/gpio/generic.h
index f3a8db4598bb59f1dba4fbebace24dc10be44ae4..5a85ecbef8d234d9cf0c2f1db7a97f5f3781b2e4 100644
--- a/include/linux/gpio/generic.h
+++ b/include/linux/gpio/generic.h
@@ -55,6 +55,12 @@ struct gpio_generic_chip {
struct gpio_chip gc;
};
+static inline struct gpio_generic_chip *
+to_gpio_generic_chip(struct gpio_chip *gc)
+{
+ return container_of(gc, struct gpio_generic_chip, gc);
+}
+
/**
* gpio_generic_chip_init() - Initialize a generic GPIO chip.
* @chip: Generic GPIO chip to set up.
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 02/14] gpio: generic: provide helpers for reading and writing registers
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag Bartosz Golaszewski
` (13 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Provide helpers wrapping the read_reg() and write_reg() callbacks of the
generic GPIO API that are called directly by many users. This is done to
hide their implementation ahead of moving them into the separate generic
GPIO struct.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
include/linux/gpio/generic.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/include/linux/gpio/generic.h b/include/linux/gpio/generic.h
index 5a85ecbef8d234d9cf0c2f1db7a97f5f3781b2e4..4c0626b53ec90388a034bc7797eefa53e7ea064e 100644
--- a/include/linux/gpio/generic.h
+++ b/include/linux/gpio/generic.h
@@ -100,6 +100,37 @@ gpio_generic_chip_set(struct gpio_generic_chip *chip, unsigned int offset,
return chip->gc.set(&chip->gc, offset, value);
}
+/**
+ * gpio_generic_read_reg() - Read a register using the underlying callback.
+ * @chip: Generic GPIO chip to use.
+ * @reg: Register to read.
+ *
+ * Returns: value read from register.
+ */
+static inline unsigned long
+gpio_generic_read_reg(struct gpio_generic_chip *chip, void __iomem *reg)
+{
+ if (WARN_ON(!chip->gc.read_reg))
+ return 0;
+
+ return chip->gc.read_reg(reg);
+}
+
+/**
+ * gpio_generic_write_reg() - Write a register using the underlying callback.
+ * @chip: Generic GPIO chip to use.
+ * @reg: Register to write to.
+ * @val: New value to write.
+ */
+static inline void gpio_generic_write_reg(struct gpio_generic_chip *chip,
+ void __iomem *reg, unsigned long val)
+{
+ if (WARN_ON(!chip->gc.write_reg))
+ return;
+
+ chip->gc.write_reg(reg, val);
+}
+
#define gpio_generic_chip_lock(gen_gc) \
raw_spin_lock(&(gen_gc)->gc.bgpio_lock)
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 02/14] gpio: generic: provide helpers for reading and writing registers Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata() Bartosz Golaszewski
` (12 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
There's no reason for this driver to touch the gpio-mmio internals, we
have a dedicated flag passed to bgpio_init() indicating to the module
that the DIR register is unreadable.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-hisi.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-hisi.c b/drivers/gpio/gpio-hisi.c
index ef5cc654a24e2327510b872563e68fb0b9aaef71..6016e6f0ed0fb80ea670ebb575452d9ec23976fa 100644
--- a/drivers/gpio/gpio-hisi.c
+++ b/drivers/gpio/gpio-hisi.c
@@ -295,7 +295,7 @@ static int hisi_gpio_probe(struct platform_device *pdev)
hisi_gpio->reg_base + HISI_GPIO_SWPORT_DR_CLR_WX,
hisi_gpio->reg_base + HISI_GPIO_SWPORT_DDR_SET_WX,
hisi_gpio->reg_base + HISI_GPIO_SWPORT_DDR_CLR_WX,
- BGPIOF_NO_SET_ON_INPUT);
+ BGPIOF_NO_SET_ON_INPUT | BGPIOF_UNREADABLE_REG_DIR);
if (ret) {
dev_err(dev, "failed to init, ret = %d\n", ret);
return ret;
@@ -303,7 +303,6 @@ static int hisi_gpio_probe(struct platform_device *pdev)
hisi_gpio->chip.set_config = hisi_gpio_set_config;
hisi_gpio->chip.ngpio = hisi_gpio->line_num;
- hisi_gpio->chip.bgpio_dir_unreadable = 1;
hisi_gpio->chip.base = -1;
if (hisi_gpio->irq > 0)
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata()
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (2 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 05/14] gpio: ts4800: use generic device properties Bartosz Golaszewski
` (11 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
There's no corresponding call to platform_get_drvdata() or
dev_get_drvdata(). Remove the call to platform_set_drvdata() from
.probe().
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-ts4800.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index 4748e3d47106cd2db6a994928b20f76921540a60..86f7947ca9b2d23292c1e6660fe93c611e0cb837 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -51,8 +51,6 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
chip->ngpio = ngpios;
- platform_set_drvdata(pdev, chip);
-
return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
}
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 05/14] gpio: ts4800: use generic device properties
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (3 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata() Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-09-03 15:41 ` Andy Shevchenko
2025-08-25 9:48 ` [PATCH RESEND 06/14] gpio: ts4800: use dev_err_probe() Bartosz Golaszewski
` (10 subsequent siblings)
15 siblings, 1 reply; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Avoid pulling in linux/of.h by using the generic device properties.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-ts4800.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index 86f7947ca9b2d23292c1e6660fe93c611e0cb837..f4ae87325393c909c66eda3bb7b2f849e645b7a4 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -7,8 +7,8 @@
#include <linux/gpio/driver.h>
#include <linux/module.h>
-#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#define DEFAULT_PIN_NUMBER 16
#define INPUT_REG_OFFSET 0x00
@@ -17,7 +17,7 @@
static int ts4800_gpio_probe(struct platform_device *pdev)
{
- struct device_node *node;
+ struct device *dev = &pdev->dev;
struct gpio_chip *chip;
void __iomem *base_addr;
int retval;
@@ -31,11 +31,7 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
if (IS_ERR(base_addr))
return PTR_ERR(base_addr);
- node = pdev->dev.of_node;
- if (!node)
- return -EINVAL;
-
- retval = of_property_read_u32(node, "ngpios", &ngpios);
+ retval = device_property_read_u32(dev, "ngpios", &ngpios);
if (retval == -EINVAL)
ngpios = DEFAULT_PIN_NUMBER;
else if (retval)
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 06/14] gpio: ts4800: use dev_err_probe()
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (4 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 05/14] gpio: ts4800: use generic device properties Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API Bartosz Golaszewski
` (9 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Use dev_err_probe() where applicable.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-ts4800.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index f4ae87325393c909c66eda3bb7b2f849e645b7a4..cb3eeeb1e9df9aa687e880b16f8d0a31b04a3b07 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -40,10 +40,8 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET,
base_addr + OUTPUT_REG_OFFSET, NULL,
base_addr + DIRECTION_REG_OFFSET, NULL, 0);
- if (retval) {
- dev_err(&pdev->dev, "bgpio_init failed\n");
- return retval;
- }
+ if (retval)
+ return dev_err_probe(dev, retval, "bgpio_init failed\n");
chip->ngpio = ngpios;
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (5 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 06/14] gpio: ts4800: use dev_err_probe() Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-09-03 15:44 ` Andy Shevchenko
2025-08-25 9:48 ` [PATCH RESEND 08/14] gpio: loongson-64bit: " Bartosz Golaszewski
` (8 subsequent siblings)
15 siblings, 1 reply; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
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-ts4800.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index cb3eeeb1e9df9aa687e880b16f8d0a31b04a3b07..844347945e8e71fa0f456be0ba8de7217f6760a3 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -6,6 +6,7 @@
*/
#include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/property.h>
@@ -17,13 +18,14 @@
static int ts4800_gpio_probe(struct platform_device *pdev)
{
+ struct gpio_generic_chip_config config;
struct device *dev = &pdev->dev;
- struct gpio_chip *chip;
+ struct gpio_generic_chip *chip;
void __iomem *base_addr;
int retval;
u32 ngpios;
- chip = devm_kzalloc(&pdev->dev, sizeof(struct gpio_chip), GFP_KERNEL);
+ chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
return -ENOMEM;
@@ -37,15 +39,22 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
else if (retval)
return retval;
- retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET,
- base_addr + OUTPUT_REG_OFFSET, NULL,
- base_addr + DIRECTION_REG_OFFSET, NULL, 0);
+ config = (typeof(config)){
+ .dev = dev,
+ .sz = 2,
+ .dat = base_addr + INPUT_REG_OFFSET,
+ .set = base_addr + OUTPUT_REG_OFFSET,
+ .dirout = base_addr + DIRECTION_REG_OFFSET,
+ };
+
+ retval = gpio_generic_chip_init(chip, &config);
if (retval)
- return dev_err_probe(dev, retval, "bgpio_init failed\n");
+ return dev_err_probe(dev, retval,
+ "failed to initialize the generic GPIO chip\n");
- chip->ngpio = ngpios;
+ chip->gc.ngpio = ngpios;
- return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
+ return devm_gpiochip_add_data(dev, &chip->gc, NULL);
}
static const struct of_device_id ts4800_gpio_of_match[] = {
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 08/14] gpio: loongson-64bit: use new generic GPIO chip API
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (6 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 09/14] gpio: dwapb: " Bartosz Golaszewski
` (7 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
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-loongson-64bit.c | 42 ++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c
index 818c606fbc5149b2e4274f0776e558332700d916..482e64ba9b4209443c2f64ae7426b8fa9034011a 100644
--- a/drivers/gpio/gpio-loongson-64bit.c
+++ b/drivers/gpio/gpio-loongson-64bit.c
@@ -11,6 +11,7 @@
#include <linux/spinlock.h>
#include <linux/err.h>
#include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
#include <linux/platform_device.h>
#include <linux/bitops.h>
#include <asm/types.h>
@@ -30,7 +31,7 @@ struct loongson_gpio_chip_data {
};
struct loongson_gpio_chip {
- struct gpio_chip chip;
+ struct gpio_generic_chip chip;
spinlock_t lock;
void __iomem *reg_base;
const struct loongson_gpio_chip_data *chip_data;
@@ -38,7 +39,8 @@ struct loongson_gpio_chip {
static inline struct loongson_gpio_chip *to_loongson_gpio_chip(struct gpio_chip *chip)
{
- return container_of(chip, struct loongson_gpio_chip, chip);
+ return container_of(to_gpio_generic_chip(chip),
+ struct loongson_gpio_chip, chip);
}
static inline void loongson_commit_direction(struct loongson_gpio_chip *lgpio, unsigned int pin,
@@ -138,36 +140,40 @@ static int loongson_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
static int loongson_gpio_init(struct device *dev, struct loongson_gpio_chip *lgpio,
void __iomem *reg_base)
{
+ struct gpio_generic_chip_config config;
int ret;
lgpio->reg_base = reg_base;
if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
- ret = bgpio_init(&lgpio->chip, dev, 8,
- lgpio->reg_base + lgpio->chip_data->in_offset,
- lgpio->reg_base + lgpio->chip_data->out_offset,
- NULL, NULL,
- lgpio->reg_base + lgpio->chip_data->conf_offset,
- 0);
+ config = (typeof(config)){
+ .dev = dev,
+ .sz = 8,
+ .dat = lgpio->reg_base + lgpio->chip_data->in_offset,
+ .set = lgpio->reg_base + lgpio->chip_data->out_offset,
+ .dirin = lgpio->reg_base + lgpio->chip_data->conf_offset,
+ };
+
+ ret = gpio_generic_chip_init(&lgpio->chip, &config);
if (ret) {
dev_err(dev, "unable to init generic GPIO\n");
return ret;
}
} else {
- lgpio->chip.direction_input = loongson_gpio_direction_input;
- lgpio->chip.get = loongson_gpio_get;
- lgpio->chip.get_direction = loongson_gpio_get_direction;
- lgpio->chip.direction_output = loongson_gpio_direction_output;
- lgpio->chip.set = loongson_gpio_set;
- lgpio->chip.parent = dev;
+ lgpio->chip.gc.direction_input = loongson_gpio_direction_input;
+ lgpio->chip.gc.get = loongson_gpio_get;
+ lgpio->chip.gc.get_direction = loongson_gpio_get_direction;
+ lgpio->chip.gc.direction_output = loongson_gpio_direction_output;
+ lgpio->chip.gc.set = loongson_gpio_set;
+ lgpio->chip.gc.parent = dev;
spin_lock_init(&lgpio->lock);
}
- lgpio->chip.label = lgpio->chip_data->label;
- lgpio->chip.can_sleep = false;
+ lgpio->chip.gc.label = lgpio->chip_data->label;
+ lgpio->chip.gc.can_sleep = false;
if (lgpio->chip_data->inten_offset)
- lgpio->chip.to_irq = loongson_gpio_to_irq;
+ lgpio->chip.gc.to_irq = loongson_gpio_to_irq;
- return devm_gpiochip_add_data(dev, &lgpio->chip, lgpio);
+ return devm_gpiochip_add_data(dev, &lgpio->chip.gc, lgpio);
}
static int loongson_gpio_probe(struct platform_device *pdev)
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 09/14] gpio: dwapb: use new generic GPIO chip API
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (7 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 08/14] gpio: loongson-64bit: " Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-09-03 15:51 ` Andy Shevchenko
2025-08-25 9:48 ` [PATCH RESEND 10/14] gpio: amdpt: " Bartosz Golaszewski
` (6 subsequent siblings)
15 siblings, 1 reply; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
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-dwapb.c | 160 +++++++++++++++++++++++++---------------------
1 file changed, 86 insertions(+), 74 deletions(-)
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 43b667b41f5dce4a1a971af4506146e4ffb59b25..0fb781ca9da29545dce23ddbdf3bd5927c714b4c 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -8,6 +8,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -99,7 +100,7 @@ struct dwapb_gpio_port_irqchip {
};
struct dwapb_gpio_port {
- struct gpio_chip gc;
+ struct gpio_generic_chip chip;
struct dwapb_gpio_port_irqchip *pirq;
struct dwapb_gpio *gpio;
#ifdef CONFIG_PM_SLEEP
@@ -107,8 +108,12 @@ struct dwapb_gpio_port {
#endif
unsigned int idx;
};
-#define to_dwapb_gpio(_gc) \
- (container_of(_gc, struct dwapb_gpio_port, gc)->gpio)
+
+static inline struct dwapb_gpio *to_dwapb_gpio(struct gpio_chip *gc)
+{
+ return container_of(to_gpio_generic_chip(gc),
+ struct dwapb_gpio_port, chip)->gpio;
+}
struct dwapb_gpio {
struct device *dev;
@@ -148,19 +153,19 @@ static inline u32 gpio_reg_convert(struct dwapb_gpio *gpio, unsigned int offset)
static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset)
{
- struct gpio_chip *gc = &gpio->ports[0].gc;
- void __iomem *reg_base = gpio->regs;
+ struct gpio_generic_chip *chip = &gpio->ports[0].chip;
+ void __iomem *reg_base = gpio->regs;
- return gc->read_reg(reg_base + gpio_reg_convert(gpio, offset));
+ return gpio_generic_read_reg(chip, reg_base + gpio_reg_convert(gpio, offset));
}
static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset,
u32 val)
{
- struct gpio_chip *gc = &gpio->ports[0].gc;
- void __iomem *reg_base = gpio->regs;
+ struct gpio_generic_chip *chip = &gpio->ports[0].chip;
+ void __iomem *reg_base = gpio->regs;
- gc->write_reg(reg_base + gpio_reg_convert(gpio, offset), val);
+ gpio_generic_write_reg(chip, reg_base + gpio_reg_convert(gpio, offset), val);
}
static struct dwapb_gpio_port *dwapb_offs_to_port(struct dwapb_gpio *gpio, unsigned int offs)
@@ -186,7 +191,7 @@ static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs)
if (!port)
return;
- gc = &port->gc;
+ gc = &port->chip.gc;
pol = dwapb_read(gpio, GPIO_INT_POLARITY);
/* Just read the current value right out of the data register */
@@ -201,13 +206,13 @@ static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs)
static u32 dwapb_do_irq(struct dwapb_gpio *gpio)
{
- struct gpio_chip *gc = &gpio->ports[0].gc;
+ struct gpio_generic_chip *gen_gc = &gpio->ports[0].chip;
unsigned long irq_status;
irq_hw_number_t hwirq;
irq_status = dwapb_read(gpio, GPIO_INTSTATUS);
for_each_set_bit(hwirq, &irq_status, DWAPB_MAX_GPIOS) {
- int gpio_irq = irq_find_mapping(gc->irq.domain, hwirq);
+ int gpio_irq = irq_find_mapping(gen_gc->gc.irq.domain, hwirq);
u32 irq_type = irq_get_trigger_type(gpio_irq);
generic_handle_irq(gpio_irq);
@@ -237,27 +242,27 @@ static irqreturn_t dwapb_irq_handler_mfd(int irq, void *dev_id)
static void dwapb_irq_ack(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
u32 val = BIT(irqd_to_hwirq(d));
- unsigned long flags;
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(gen_gc);
+
dwapb_write(gpio, GPIO_PORTA_EOI, val);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
}
static void dwapb_irq_mask(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
irq_hw_number_t hwirq = irqd_to_hwirq(d);
- unsigned long flags;
u32 val;
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
- val = dwapb_read(gpio, GPIO_INTMASK) | BIT(hwirq);
- dwapb_write(gpio, GPIO_INTMASK, val);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
+ scoped_guard(gpio_generic_lock_irqsave, gen_gc) {
+ val = dwapb_read(gpio, GPIO_INTMASK) | BIT(hwirq);
+ dwapb_write(gpio, GPIO_INTMASK, val);
+ }
gpiochip_disable_irq(gc, hwirq);
}
@@ -265,59 +270,61 @@ static void dwapb_irq_mask(struct irq_data *d)
static void dwapb_irq_unmask(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
irq_hw_number_t hwirq = irqd_to_hwirq(d);
- unsigned long flags;
u32 val;
gpiochip_enable_irq(gc, hwirq);
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(gen_gc);
+
val = dwapb_read(gpio, GPIO_INTMASK) & ~BIT(hwirq);
dwapb_write(gpio, GPIO_INTMASK, val);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
}
static void dwapb_irq_enable(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
irq_hw_number_t hwirq = irqd_to_hwirq(d);
- unsigned long flags;
u32 val;
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(gen_gc);
+
val = dwapb_read(gpio, GPIO_INTEN) | BIT(hwirq);
dwapb_write(gpio, GPIO_INTEN, val);
val = dwapb_read(gpio, GPIO_INTMASK) & ~BIT(hwirq);
dwapb_write(gpio, GPIO_INTMASK, val);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
}
static void dwapb_irq_disable(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
irq_hw_number_t hwirq = irqd_to_hwirq(d);
- unsigned long flags;
u32 val;
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(gen_gc);
+
val = dwapb_read(gpio, GPIO_INTMASK) | BIT(hwirq);
dwapb_write(gpio, GPIO_INTMASK, val);
val = dwapb_read(gpio, GPIO_INTEN) & ~BIT(hwirq);
dwapb_write(gpio, GPIO_INTEN, val);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
}
static int dwapb_irq_set_type(struct irq_data *d, u32 type)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
irq_hw_number_t bit = irqd_to_hwirq(d);
- unsigned long level, polarity, flags;
+ unsigned long level, polarity;
+
+ guard(gpio_generic_lock_irqsave)(gen_gc);
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
level = dwapb_read(gpio, GPIO_INTTYPE_LEVEL);
polarity = dwapb_read(gpio, GPIO_INT_POLARITY);
@@ -352,7 +359,6 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type)
dwapb_write(gpio, GPIO_INTTYPE_LEVEL, level);
if (type != IRQ_TYPE_EDGE_BOTH)
dwapb_write(gpio, GPIO_INT_POLARITY, polarity);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
return 0;
}
@@ -393,11 +399,12 @@ static int dwapb_gpio_set_debounce(struct gpio_chip *gc,
unsigned offset, unsigned debounce)
{
struct dwapb_gpio_port *port = gpiochip_get_data(gc);
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct dwapb_gpio *gpio = port->gpio;
- unsigned long flags, val_deb;
+ unsigned long val_deb;
unsigned long mask = BIT(offset);
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(gen_gc);
val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE);
if (debounce)
@@ -406,8 +413,6 @@ static int dwapb_gpio_set_debounce(struct gpio_chip *gc,
val_deb &= ~mask;
dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
-
return 0;
}
@@ -445,7 +450,7 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio,
struct dwapb_port_property *pp)
{
struct dwapb_gpio_port_irqchip *pirq;
- struct gpio_chip *gc = &port->gc;
+ struct gpio_chip *gc = &port->chip.gc;
struct gpio_irq_chip *girq;
int err;
@@ -501,6 +506,7 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
struct dwapb_port_property *pp,
unsigned int offs)
{
+ struct gpio_generic_chip_config config;
struct dwapb_gpio_port *port;
void __iomem *dat, *set, *dirout;
int err;
@@ -519,32 +525,39 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
set = gpio->regs + GPIO_SWPORTA_DR + pp->idx * GPIO_SWPORT_DR_STRIDE;
dirout = gpio->regs + GPIO_SWPORTA_DDR + pp->idx * GPIO_SWPORT_DDR_STRIDE;
+ config = (typeof(config)){
+ .dev = gpio->dev,
+ .sz = 4,
+ .dat = dat,
+ .set = set,
+ .dirout = dirout,
+ };
+
/* This registers 32 GPIO lines per port */
- err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout,
- NULL, 0);
+ err = gpio_generic_chip_init(&port->chip, &config);
if (err) {
dev_err(gpio->dev, "failed to init gpio chip for port%d\n",
port->idx);
return err;
}
- port->gc.fwnode = pp->fwnode;
- port->gc.ngpio = pp->ngpio;
- port->gc.base = pp->gpio_base;
- port->gc.request = gpiochip_generic_request;
- port->gc.free = gpiochip_generic_free;
+ port->chip.gc.fwnode = pp->fwnode;
+ port->chip.gc.ngpio = pp->ngpio;
+ port->chip.gc.base = pp->gpio_base;
+ port->chip.gc.request = gpiochip_generic_request;
+ port->chip.gc.free = gpiochip_generic_free;
/* Only port A support debounce */
if (pp->idx == 0)
- port->gc.set_config = dwapb_gpio_set_config;
+ port->chip.gc.set_config = dwapb_gpio_set_config;
else
- port->gc.set_config = gpiochip_generic_config;
+ port->chip.gc.set_config = gpiochip_generic_config;
/* Only port A can provide interrupts in all configurations of the IP */
if (pp->idx == 0)
dwapb_configure_irqs(gpio, port, pp);
- err = devm_gpiochip_add_data(gpio->dev, &port->gc, port);
+ err = devm_gpiochip_add_data(gpio->dev, &port->chip.gc, port);
if (err) {
dev_err(gpio->dev, "failed to register gpiochip for port%d\n",
port->idx);
@@ -750,38 +763,37 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
static int dwapb_gpio_suspend(struct device *dev)
{
struct dwapb_gpio *gpio = dev_get_drvdata(dev);
- struct gpio_chip *gc = &gpio->ports[0].gc;
- unsigned long flags;
+ struct gpio_generic_chip *gen_gc = &gpio->ports[0].chip;
int i;
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
- for (i = 0; i < gpio->nr_ports; i++) {
- unsigned int offset;
- unsigned int idx = gpio->ports[i].idx;
- struct dwapb_context *ctx = gpio->ports[i].ctx;
+ scoped_guard(gpio_generic_lock_irqsave, gen_gc) {
+ for (i = 0; i < gpio->nr_ports; i++) {
+ unsigned int offset;
+ unsigned int idx = gpio->ports[i].idx;
+ struct dwapb_context *ctx = gpio->ports[i].ctx;
- offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE;
- ctx->dir = dwapb_read(gpio, offset);
+ offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE;
+ ctx->dir = dwapb_read(gpio, offset);
- offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE;
- ctx->data = dwapb_read(gpio, offset);
+ offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE;
+ ctx->data = dwapb_read(gpio, offset);
- offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_STRIDE;
- ctx->ext = dwapb_read(gpio, offset);
+ offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_STRIDE;
+ ctx->ext = dwapb_read(gpio, offset);
- /* Only port A can provide interrupts */
- if (idx == 0) {
- ctx->int_mask = dwapb_read(gpio, GPIO_INTMASK);
- ctx->int_en = dwapb_read(gpio, GPIO_INTEN);
- ctx->int_pol = dwapb_read(gpio, GPIO_INT_POLARITY);
- ctx->int_type = dwapb_read(gpio, GPIO_INTTYPE_LEVEL);
- ctx->int_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE);
+ /* Only port A can provide interrupts */
+ if (idx == 0) {
+ ctx->int_mask = dwapb_read(gpio, GPIO_INTMASK);
+ ctx->int_en = dwapb_read(gpio, GPIO_INTEN);
+ ctx->int_pol = dwapb_read(gpio, GPIO_INT_POLARITY);
+ ctx->int_type = dwapb_read(gpio, GPIO_INTTYPE_LEVEL);
+ ctx->int_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE);
- /* Mask out interrupts */
- dwapb_write(gpio, GPIO_INTMASK, ~ctx->wake_en);
+ /* Mask out interrupts */
+ dwapb_write(gpio, GPIO_INTMASK, ~ctx->wake_en);
+ }
}
}
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
clk_bulk_disable_unprepare(DWAPB_NR_CLOCKS, gpio->clks);
@@ -791,8 +803,8 @@ static int dwapb_gpio_suspend(struct device *dev)
static int dwapb_gpio_resume(struct device *dev)
{
struct dwapb_gpio *gpio = dev_get_drvdata(dev);
- struct gpio_chip *gc = &gpio->ports[0].gc;
- unsigned long flags;
+ struct gpio_chip *gc = &gpio->ports[0].chip.gc;
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
int i, err;
err = clk_bulk_prepare_enable(DWAPB_NR_CLOCKS, gpio->clks);
@@ -801,7 +813,8 @@ static int dwapb_gpio_resume(struct device *dev)
return err;
}
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(gen_gc);
+
for (i = 0; i < gpio->nr_ports; i++) {
unsigned int offset;
unsigned int idx = gpio->ports[i].idx;
@@ -828,7 +841,6 @@ static int dwapb_gpio_resume(struct device *dev)
dwapb_write(gpio, GPIO_PORTA_EOI, 0xffffffff);
}
}
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
return 0;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 10/14] gpio: amdpt: use new generic GPIO chip API
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (8 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 09/14] gpio: dwapb: " Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 11/14] gpio: rda: " Bartosz Golaszewski
` (5 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
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-amdpt.c | 44 +++++++++++++++++++++++---------------------
1 file changed, 23 insertions(+), 21 deletions(-)
diff --git a/drivers/gpio/gpio-amdpt.c b/drivers/gpio/gpio-amdpt.c
index b70036587d9c3f64bb73ed3b94e1c14f249c9e21..0a9b870705b90bdc9bdab93ce5a4a33ebdafccc6 100644
--- a/drivers/gpio/gpio-amdpt.c
+++ b/drivers/gpio/gpio-amdpt.c
@@ -9,6 +9,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
#include <linux/spinlock.h>
#include <linux/acpi.h>
#include <linux/platform_device.h>
@@ -24,54 +25,50 @@
#define PT_SYNC_REG 0x28
struct pt_gpio_chip {
- struct gpio_chip gc;
+ struct gpio_generic_chip chip;
void __iomem *reg_base;
};
static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
{
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
- unsigned long flags;
u32 using_pins;
dev_dbg(gc->parent, "pt_gpio_request offset=%x\n", offset);
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(gen_gc);
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
if (using_pins & BIT(offset)) {
dev_warn(gc->parent, "PT GPIO pin %x reconfigured\n",
offset);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
return -EINVAL;
}
writel(using_pins | BIT(offset), pt_gpio->reg_base + PT_SYNC_REG);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
-
return 0;
}
static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)
{
+ struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
- unsigned long flags;
u32 using_pins;
- raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(gen_gc);
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
using_pins &= ~BIT(offset);
writel(using_pins, pt_gpio->reg_base + PT_SYNC_REG);
- raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
-
dev_dbg(gc->parent, "pt_gpio_free offset=%x\n", offset);
}
static int pt_gpio_probe(struct platform_device *pdev)
{
+ struct gpio_generic_chip_config config;
struct device *dev = &pdev->dev;
struct pt_gpio_chip *pt_gpio;
int ret = 0;
@@ -91,22 +88,27 @@ static int pt_gpio_probe(struct platform_device *pdev)
return PTR_ERR(pt_gpio->reg_base);
}
- ret = bgpio_init(&pt_gpio->gc, dev, 4,
- pt_gpio->reg_base + PT_INPUTDATA_REG,
- pt_gpio->reg_base + PT_OUTPUTDATA_REG, NULL,
- pt_gpio->reg_base + PT_DIRECTION_REG, NULL,
- BGPIOF_READ_OUTPUT_REG_SET);
+ config = (typeof(config)){
+ .dev = dev,
+ .sz = 4,
+ .dat = pt_gpio->reg_base + PT_INPUTDATA_REG,
+ .set = pt_gpio->reg_base + PT_OUTPUTDATA_REG,
+ .dirout = pt_gpio->reg_base + PT_DIRECTION_REG,
+ .flags = BGPIOF_READ_OUTPUT_REG_SET,
+ };
+
+ ret = gpio_generic_chip_init(&pt_gpio->chip, &config);
if (ret) {
- dev_err(dev, "bgpio_init failed\n");
+ dev_err(dev, "failed to initialize the generic GPIO chip\n");
return ret;
}
- pt_gpio->gc.owner = THIS_MODULE;
- pt_gpio->gc.request = pt_gpio_request;
- pt_gpio->gc.free = pt_gpio_free;
- pt_gpio->gc.ngpio = (uintptr_t)device_get_match_data(dev);
+ pt_gpio->chip.gc.owner = THIS_MODULE;
+ pt_gpio->chip.gc.request = pt_gpio_request;
+ pt_gpio->chip.gc.free = pt_gpio_free;
+ pt_gpio->chip.gc.ngpio = (uintptr_t)device_get_match_data(dev);
- ret = devm_gpiochip_add_data(dev, &pt_gpio->gc, pt_gpio);
+ ret = devm_gpiochip_add_data(dev, &pt_gpio->chip.gc, pt_gpio);
if (ret) {
dev_err(dev, "Failed to register GPIO lib\n");
return ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 11/14] gpio: rda: use new generic GPIO chip API
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (9 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 10/14] gpio: amdpt: " Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 12/14] gpio: grgpio: " Bartosz Golaszewski
` (4 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
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-rda.c | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/drivers/gpio/gpio-rda.c b/drivers/gpio/gpio-rda.c
index cb2f63eee2aa10a2708ec91dfd610ed1ea76917d..bcd85a2237a532b875df9470d972ac88b95a91cc 100644
--- a/drivers/gpio/gpio-rda.c
+++ b/drivers/gpio/gpio-rda.c
@@ -8,6 +8,7 @@
#include <linux/bitops.h>
#include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@@ -35,7 +36,7 @@
#define RDA_GPIO_BANK_NR 32
struct rda_gpio {
- struct gpio_chip chip;
+ struct gpio_generic_chip chip;
void __iomem *base;
spinlock_t lock;
int irq;
@@ -208,6 +209,7 @@ static const struct irq_chip rda_gpio_irq_chip = {
static int rda_gpio_probe(struct platform_device *pdev)
{
+ struct gpio_generic_chip_config config;
struct device *dev = &pdev->dev;
struct gpio_irq_chip *girq;
struct rda_gpio *rda_gpio;
@@ -235,24 +237,29 @@ static int rda_gpio_probe(struct platform_device *pdev)
spin_lock_init(&rda_gpio->lock);
- ret = bgpio_init(&rda_gpio->chip, dev, 4,
- rda_gpio->base + RDA_GPIO_VAL,
- rda_gpio->base + RDA_GPIO_SET,
- rda_gpio->base + RDA_GPIO_CLR,
- rda_gpio->base + RDA_GPIO_OEN_SET_OUT,
- rda_gpio->base + RDA_GPIO_OEN_SET_IN,
- BGPIOF_READ_OUTPUT_REG_SET);
+ config = (typeof(config)){
+ .dev = dev,
+ .sz = 4,
+ .dat = rda_gpio->base + RDA_GPIO_VAL,
+ .set = rda_gpio->base + RDA_GPIO_SET,
+ .clr = rda_gpio->base + RDA_GPIO_CLR,
+ .dirout = rda_gpio->base + RDA_GPIO_OEN_SET_OUT,
+ .dirin = rda_gpio->base + RDA_GPIO_OEN_SET_IN,
+ .flags = BGPIOF_READ_OUTPUT_REG_SET,
+ };
+
+ ret = gpio_generic_chip_init(&rda_gpio->chip, &config);
if (ret) {
- dev_err(dev, "bgpio_init failed\n");
+ dev_err(dev, "failed to initialize the generic GPIO chip\n");
return ret;
}
- rda_gpio->chip.label = dev_name(dev);
- rda_gpio->chip.ngpio = ngpios;
- rda_gpio->chip.base = -1;
+ rda_gpio->chip.gc.label = dev_name(dev);
+ rda_gpio->chip.gc.ngpio = ngpios;
+ rda_gpio->chip.gc.base = -1;
if (rda_gpio->irq >= 0) {
- girq = &rda_gpio->chip.irq;
+ girq = &rda_gpio->chip.gc.irq;
gpio_irq_chip_set_chip(girq, &rda_gpio_irq_chip);
girq->handler = handle_bad_irq;
girq->default_type = IRQ_TYPE_NONE;
@@ -269,7 +276,7 @@ static int rda_gpio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, rda_gpio);
- return devm_gpiochip_add_data(dev, &rda_gpio->chip, rda_gpio);
+ return devm_gpiochip_add_data(dev, &rda_gpio->chip.gc, rda_gpio);
}
static const struct of_device_id rda_gpio_of_match[] = {
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 12/14] gpio: grgpio: use new generic GPIO chip API
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (10 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 11/14] gpio: rda: " Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 13/14] gpio: mpc8xxx: " Bartosz Golaszewski
` (3 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
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-grgpio.c | 87 +++++++++++++++++++++++-----------------------
1 file changed, 44 insertions(+), 43 deletions(-)
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index f3f8bab62f94cefb69d31d76b961ab2d346df49e..3b77fad00749cd5218268b267b5848515c6a26fc 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -19,6 +19,7 @@
#include <linux/bitops.h>
#include <linux/err.h>
#include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -59,7 +60,7 @@ struct grgpio_lirq {
};
struct grgpio_priv {
- struct gpio_chip gc;
+ struct gpio_generic_chip chip;
void __iomem *regs;
struct device *dev;
@@ -91,13 +92,12 @@ struct grgpio_priv {
static void grgpio_set_imask(struct grgpio_priv *priv, unsigned int offset,
int val)
{
- struct gpio_chip *gc = &priv->gc;
-
if (val)
priv->imask |= BIT(offset);
else
priv->imask &= ~BIT(offset);
- gc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask);
+
+ gpio_generic_write_reg(&priv->chip, priv->regs + GRGPIO_IMASK, priv->imask);
}
static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset)
@@ -118,7 +118,6 @@ static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset)
static int grgpio_irq_set_type(struct irq_data *d, unsigned int type)
{
struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
- unsigned long flags;
u32 mask = BIT(d->hwirq);
u32 ipol;
u32 iedge;
@@ -146,15 +145,13 @@ static int grgpio_irq_set_type(struct irq_data *d, unsigned int type)
return -EINVAL;
}
- raw_spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(&priv->chip);
- ipol = priv->gc.read_reg(priv->regs + GRGPIO_IPOL) & ~mask;
- iedge = priv->gc.read_reg(priv->regs + GRGPIO_IEDGE) & ~mask;
+ ipol = gpio_generic_read_reg(&priv->chip, priv->regs + GRGPIO_IPOL) & ~mask;
+ iedge = gpio_generic_read_reg(&priv->chip, priv->regs + GRGPIO_IEDGE) & ~mask;
- priv->gc.write_reg(priv->regs + GRGPIO_IPOL, ipol | pol);
- priv->gc.write_reg(priv->regs + GRGPIO_IEDGE, iedge | edge);
-
- raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
+ gpio_generic_write_reg(&priv->chip, priv->regs + GRGPIO_IPOL, ipol | pol);
+ gpio_generic_write_reg(&priv->chip, priv->regs + GRGPIO_IEDGE, iedge | edge);
return 0;
}
@@ -163,29 +160,23 @@ static void grgpio_irq_mask(struct irq_data *d)
{
struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
int offset = d->hwirq;
- unsigned long flags;
- raw_spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
+ scoped_guard(gpio_generic_lock_irqsave, &priv->chip)
+ grgpio_set_imask(priv, offset, 0);
- grgpio_set_imask(priv, offset, 0);
-
- raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
-
- gpiochip_disable_irq(&priv->gc, d->hwirq);
+ gpiochip_disable_irq(&priv->chip.gc, d->hwirq);
}
static void grgpio_irq_unmask(struct irq_data *d)
{
struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
int offset = d->hwirq;
- unsigned long flags;
- gpiochip_enable_irq(&priv->gc, d->hwirq);
- raw_spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
+ gpiochip_enable_irq(&priv->chip.gc, d->hwirq);
+
+ guard(gpio_generic_lock_irqsave)(&priv->chip);
grgpio_set_imask(priv, offset, 1);
-
- raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
}
static const struct irq_chip grgpio_irq_chip = {
@@ -200,12 +191,11 @@ static const struct irq_chip grgpio_irq_chip = {
static irqreturn_t grgpio_irq_handler(int irq, void *dev)
{
struct grgpio_priv *priv = dev;
- int ngpio = priv->gc.ngpio;
- unsigned long flags;
+ int ngpio = priv->chip.gc.ngpio;
int i;
int match = 0;
- raw_spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
+ guard(gpio_generic_lock_irqsave)(&priv->chip);
/*
* For each gpio line, call its interrupt handler if it its underlying
@@ -221,8 +211,6 @@ static irqreturn_t grgpio_irq_handler(int irq, void *dev)
}
}
- raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
-
if (!match)
dev_warn(priv->dev, "No gpio line matched irq %d\n", irq);
@@ -253,13 +241,18 @@ static int grgpio_irq_map(struct irq_domain *d, unsigned int irq,
dev_dbg(priv->dev, "Mapping irq %d for gpio line %d\n",
irq, offset);
- raw_spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
+ gpio_generic_chip_lock_irqsave(&priv->chip, flags);
/* Request underlying irq if not already requested */
lirq->irq = irq;
uirq = &priv->uirqs[lirq->index];
if (uirq->refcnt == 0) {
- raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
+ /*
+ * FIXME: This is not how locking works at all, you can't just
+ * release the lock for a moment to do something that can't
+ * sleep...
+ */
+ gpio_generic_chip_unlock_irqrestore(&priv->chip, flags);
ret = request_irq(uirq->uirq, grgpio_irq_handler, 0,
dev_name(priv->dev), priv);
if (ret) {
@@ -268,11 +261,11 @@ static int grgpio_irq_map(struct irq_domain *d, unsigned int irq,
uirq->uirq);
return ret;
}
- raw_spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
+ gpio_generic_chip_lock_irqsave(&priv->chip, flags);
}
uirq->refcnt++;
- raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
+ gpio_generic_chip_unlock_irqrestore(&priv->chip, flags);
/* Setup irq */
irq_set_chip_data(irq, priv);
@@ -290,13 +283,13 @@ static void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq)
struct grgpio_lirq *lirq;
struct grgpio_uirq *uirq;
unsigned long flags;
- int ngpio = priv->gc.ngpio;
+ int ngpio = priv->chip.gc.ngpio;
int i;
irq_set_chip_and_handler(irq, NULL, NULL);
irq_set_chip_data(irq, NULL);
- raw_spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
+ gpio_generic_chip_lock_irqsave(&priv->chip, flags);
/* Free underlying irq if last user unmapped */
index = -1;
@@ -315,13 +308,13 @@ static void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq)
uirq = &priv->uirqs[lirq->index];
uirq->refcnt--;
if (uirq->refcnt == 0) {
- raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
+ gpio_generic_chip_unlock_irqrestore(&priv->chip, flags);
free_irq(uirq->uirq, priv);
return;
}
}
- raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
+ gpio_generic_chip_unlock_irqrestore(&priv->chip, flags);
}
static void grgpio_irq_domain_remove(void *data)
@@ -341,6 +334,7 @@ static const struct irq_domain_ops grgpio_irq_domain_ops = {
static int grgpio_probe(struct platform_device *ofdev)
{
struct device_node *np = ofdev->dev.of_node;
+ struct gpio_generic_chip_config config;
struct device *dev = &ofdev->dev;
void __iomem *regs;
struct gpio_chip *gc;
@@ -359,17 +353,24 @@ static int grgpio_probe(struct platform_device *ofdev)
if (IS_ERR(regs))
return PTR_ERR(regs);
- gc = &priv->gc;
- err = bgpio_init(gc, dev, 4, regs + GRGPIO_DATA,
- regs + GRGPIO_OUTPUT, NULL, regs + GRGPIO_DIR, NULL,
- BGPIOF_BIG_ENDIAN_BYTE_ORDER);
+ config = (typeof(config)){
+ .dev = dev,
+ .sz = 4,
+ .dat = regs + GRGPIO_DATA,
+ .set = regs + GRGPIO_OUTPUT,
+ .dirout = regs + GRGPIO_DIR,
+ .flags = BGPIOF_BIG_ENDIAN_BYTE_ORDER,
+ };
+
+ gc = &priv->chip.gc;
+ err = gpio_generic_chip_init(&priv->chip, &config);
if (err) {
- dev_err(dev, "bgpio_init() failed\n");
+ dev_err(dev, "failed to initialize the generic GPIO chip\n");
return err;
}
priv->regs = regs;
- priv->imask = gc->read_reg(regs + GRGPIO_IMASK);
+ priv->imask = gpio_generic_read_reg(&priv->chip, regs + GRGPIO_IMASK);
priv->dev = dev;
gc->owner = THIS_MODULE;
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 13/14] gpio: mpc8xxx: use new generic GPIO chip API
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (11 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 12/14] gpio: grgpio: " Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 14/14] gpio: ge: " Bartosz Golaszewski
` (2 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
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-mpc8xxx.c | 102 +++++++++++++++++++++++++++-----------------
1 file changed, 62 insertions(+), 40 deletions(-)
diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 121efdd71e451d4f992fa195b0d56d7146a6f3dd..38643fb813c562957076aab48d804f8048cee5e4 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -9,6 +9,7 @@
#include <linux/acpi.h>
#include <linux/bitops.h>
#include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -34,7 +35,7 @@
#define GPIO_IBE 0x18
struct mpc8xxx_gpio_chip {
- struct gpio_chip gc;
+ struct gpio_generic_chip chip;
void __iomem *regs;
raw_spinlock_t lock;
@@ -66,8 +67,10 @@ static int mpc8572_gpio_get(struct gpio_chip *gc, unsigned int gpio)
struct mpc8xxx_gpio_chip *mpc8xxx_gc = gpiochip_get_data(gc);
u32 out_mask, out_shadow;
- out_mask = gc->read_reg(mpc8xxx_gc->regs + GPIO_DIR);
- val = gc->read_reg(mpc8xxx_gc->regs + GPIO_DAT) & ~out_mask;
+ out_mask = gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_DIR);
+ val = gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_DAT) & ~out_mask;
out_shadow = gc->bgpio_data & out_mask;
return !!((val | out_shadow) & mpc_pin2mask(gpio));
@@ -108,12 +111,13 @@ static int mpc8xxx_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
static irqreturn_t mpc8xxx_gpio_irq_cascade(int irq, void *data)
{
struct mpc8xxx_gpio_chip *mpc8xxx_gc = data;
- struct gpio_chip *gc = &mpc8xxx_gc->gc;
unsigned long mask;
int i;
- mask = gc->read_reg(mpc8xxx_gc->regs + GPIO_IER)
- & gc->read_reg(mpc8xxx_gc->regs + GPIO_IMR);
+ mask = gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_IER) &
+ gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_IMR);
for_each_set_bit(i, &mask, 32)
generic_handle_domain_irq(mpc8xxx_gc->irq, 31 - i);
@@ -124,15 +128,17 @@ static void mpc8xxx_irq_unmask(struct irq_data *d)
{
struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
irq_hw_number_t hwirq = irqd_to_hwirq(d);
- struct gpio_chip *gc = &mpc8xxx_gc->gc;
+ struct gpio_chip *gc = &mpc8xxx_gc->chip.gc;
unsigned long flags;
gpiochip_enable_irq(gc, hwirq);
raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
- gc->write_reg(mpc8xxx_gc->regs + GPIO_IMR,
- gc->read_reg(mpc8xxx_gc->regs + GPIO_IMR)
+ gpio_generic_write_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_IMR,
+ gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_IMR)
| mpc_pin2mask(irqd_to_hwirq(d)));
raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
@@ -142,13 +148,14 @@ static void mpc8xxx_irq_mask(struct irq_data *d)
{
struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
irq_hw_number_t hwirq = irqd_to_hwirq(d);
- struct gpio_chip *gc = &mpc8xxx_gc->gc;
+ struct gpio_chip *gc = &mpc8xxx_gc->chip.gc;
unsigned long flags;
raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
- gc->write_reg(mpc8xxx_gc->regs + GPIO_IMR,
- gc->read_reg(mpc8xxx_gc->regs + GPIO_IMR)
+ gpio_generic_write_reg(&mpc8xxx_gc->chip, mpc8xxx_gc->regs + GPIO_IMR,
+ gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_IMR)
& ~mpc_pin2mask(irqd_to_hwirq(d)));
raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
@@ -159,32 +166,34 @@ static void mpc8xxx_irq_mask(struct irq_data *d)
static void mpc8xxx_irq_ack(struct irq_data *d)
{
struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
- struct gpio_chip *gc = &mpc8xxx_gc->gc;
- gc->write_reg(mpc8xxx_gc->regs + GPIO_IER,
+ gpio_generic_write_reg(&mpc8xxx_gc->chip, mpc8xxx_gc->regs + GPIO_IER,
mpc_pin2mask(irqd_to_hwirq(d)));
}
static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type)
{
struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
- struct gpio_chip *gc = &mpc8xxx_gc->gc;
unsigned long flags;
switch (flow_type) {
case IRQ_TYPE_EDGE_FALLING:
case IRQ_TYPE_LEVEL_LOW:
raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
- gc->write_reg(mpc8xxx_gc->regs + GPIO_ICR,
- gc->read_reg(mpc8xxx_gc->regs + GPIO_ICR)
+ gpio_generic_write_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_ICR,
+ gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_ICR)
| mpc_pin2mask(irqd_to_hwirq(d)));
raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
break;
case IRQ_TYPE_EDGE_BOTH:
raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
- gc->write_reg(mpc8xxx_gc->regs + GPIO_ICR,
- gc->read_reg(mpc8xxx_gc->regs + GPIO_ICR)
+ gpio_generic_write_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_ICR,
+ gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_ICR)
& ~mpc_pin2mask(irqd_to_hwirq(d)));
raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
break;
@@ -199,7 +208,6 @@ static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type)
static int mpc512x_irq_set_type(struct irq_data *d, unsigned int flow_type)
{
struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
- struct gpio_chip *gc = &mpc8xxx_gc->gc;
unsigned long gpio = irqd_to_hwirq(d);
void __iomem *reg;
unsigned int shift;
@@ -217,7 +225,9 @@ static int mpc512x_irq_set_type(struct irq_data *d, unsigned int flow_type)
case IRQ_TYPE_EDGE_FALLING:
case IRQ_TYPE_LEVEL_LOW:
raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
- gc->write_reg(reg, (gc->read_reg(reg) & ~(3 << shift))
+ gpio_generic_write_reg(&mpc8xxx_gc->chip, reg,
+ (gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ reg) & ~(3 << shift))
| (2 << shift));
raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
break;
@@ -225,14 +235,18 @@ static int mpc512x_irq_set_type(struct irq_data *d, unsigned int flow_type)
case IRQ_TYPE_EDGE_RISING:
case IRQ_TYPE_LEVEL_HIGH:
raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
- gc->write_reg(reg, (gc->read_reg(reg) & ~(3 << shift))
+ gpio_generic_write_reg(&mpc8xxx_gc->chip, reg,
+ (gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ reg) & ~(3 << shift))
| (1 << shift));
raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
break;
case IRQ_TYPE_EDGE_BOTH:
raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
- gc->write_reg(reg, (gc->read_reg(reg) & ~(3 << shift)));
+ gpio_generic_write_reg(&mpc8xxx_gc->chip, reg,
+ (gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ reg) & ~(3 << shift)));
raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
break;
@@ -309,6 +323,7 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = {
static int mpc8xxx_probe(struct platform_device *pdev)
{
const struct mpc8xxx_gpio_devtype *devtype = NULL;
+ struct gpio_generic_chip_config config;
struct mpc8xxx_gpio_chip *mpc8xxx_gc;
struct device *dev = &pdev->dev;
struct fwnode_handle *fwnode;
@@ -327,26 +342,28 @@ static int mpc8xxx_probe(struct platform_device *pdev)
if (IS_ERR(mpc8xxx_gc->regs))
return PTR_ERR(mpc8xxx_gc->regs);
- gc = &mpc8xxx_gc->gc;
+ gc = &mpc8xxx_gc->chip.gc;
gc->parent = dev;
+ config = (typeof(config)){
+ .dev = dev,
+ .sz = 4,
+ .dat = mpc8xxx_gc->regs + GPIO_DAT,
+ .dirout = mpc8xxx_gc->regs + GPIO_DIR,
+ .flags = BGPIOF_BIG_ENDIAN
+ };
+
if (device_property_read_bool(dev, "little-endian")) {
- ret = bgpio_init(gc, dev, 4, mpc8xxx_gc->regs + GPIO_DAT,
- NULL, NULL, mpc8xxx_gc->regs + GPIO_DIR,
- NULL, BGPIOF_BIG_ENDIAN);
- if (ret)
- return ret;
dev_dbg(dev, "GPIO registers are LITTLE endian\n");
} else {
- ret = bgpio_init(gc, dev, 4, mpc8xxx_gc->regs + GPIO_DAT,
- NULL, NULL, mpc8xxx_gc->regs + GPIO_DIR,
- NULL, BGPIOF_BIG_ENDIAN
- | BGPIOF_BIG_ENDIAN_BYTE_ORDER);
- if (ret)
- return ret;
+ config.flags |= BGPIOF_BIG_ENDIAN_BYTE_ORDER;
dev_dbg(dev, "GPIO registers are BIG endian\n");
}
+ ret = gpio_generic_chip_init(&mpc8xxx_gc->chip, &config);
+ if (ret)
+ return ret;
+
mpc8xxx_gc->direction_output = gc->direction_output;
devtype = device_get_match_data(dev);
@@ -379,10 +396,13 @@ static int mpc8xxx_probe(struct platform_device *pdev)
device_is_compatible(dev, "fsl,ls1028a-gpio") ||
device_is_compatible(dev, "fsl,ls1088a-gpio") ||
is_acpi_node(fwnode)) {
- gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0xffffffff);
+ gpio_generic_write_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_IBE, 0xffffffff);
/* Also, latch state of GPIOs configured as output by bootloader. */
- gc->bgpio_data = gc->read_reg(mpc8xxx_gc->regs + GPIO_DAT) &
- gc->read_reg(mpc8xxx_gc->regs + GPIO_DIR);
+ gc->bgpio_data = gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_DAT) &
+ gpio_generic_read_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_DIR);
}
ret = devm_gpiochip_add_data(dev, gc, mpc8xxx_gc);
@@ -405,8 +425,10 @@ static int mpc8xxx_probe(struct platform_device *pdev)
return 0;
/* ack and mask all irqs */
- gc->write_reg(mpc8xxx_gc->regs + GPIO_IER, 0xffffffff);
- gc->write_reg(mpc8xxx_gc->regs + GPIO_IMR, 0);
+ gpio_generic_write_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_IER, 0xffffffff);
+ gpio_generic_write_reg(&mpc8xxx_gc->chip,
+ mpc8xxx_gc->regs + GPIO_IMR, 0);
ret = devm_request_irq(dev, mpc8xxx_gc->irqn,
mpc8xxx_gpio_irq_cascade,
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH RESEND 14/14] gpio: ge: use new generic GPIO chip API
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (12 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 13/14] gpio: mpc8xxx: " Bartosz Golaszewski
@ 2025-08-25 9:48 ` Bartosz Golaszewski
2025-08-25 10:00 ` [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-25 10:05 ` Bartosz Golaszewski
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
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-ge.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c
index 5dc49648d8e378e9741213f9c2de05b4c75b347f..a02dd322e0d4cecd4564a71a550204983df33568 100644
--- a/drivers/gpio/gpio-ge.c
+++ b/drivers/gpio/gpio-ge.c
@@ -16,6 +16,7 @@
*/
#include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/mod_devicetable.h>
@@ -51,24 +52,36 @@ MODULE_DEVICE_TABLE(of, gef_gpio_ids);
static int __init gef_gpio_probe(struct platform_device *pdev)
{
+ struct gpio_generic_chip_config config;
struct device *dev = &pdev->dev;
+ struct gpio_generic_chip *chip;
struct gpio_chip *gc;
void __iomem *regs;
int ret;
- gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
- if (!gc)
+ chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
+ if (!chip)
return -ENOMEM;
regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(regs))
return PTR_ERR(regs);
- ret = bgpio_init(gc, dev, 4, regs + GEF_GPIO_IN, regs + GEF_GPIO_OUT,
- NULL, NULL, regs + GEF_GPIO_DIRECT,
- BGPIOF_BIG_ENDIAN_BYTE_ORDER);
+ config = (typeof(config)){
+ .dev = dev,
+ .sz = 4,
+ .dat = regs + GEF_GPIO_IN,
+ .set = regs + GEF_GPIO_OUT,
+ .dirin = regs + GEF_GPIO_DIRECT,
+ .flags = BGPIOF_BIG_ENDIAN_BYTE_ORDER,
+ };
+
+ ret = gpio_generic_chip_init(chip, &config);
if (ret)
- return dev_err_probe(dev, ret, "bgpio_init failed\n");
+ return dev_err_probe(dev, ret,
+ "failed to initialize the generic GPIO chip\n");
+
+ gc = &chip->gc;
/* Setup pointers to chip functions */
gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pfw", dev_fwnode(dev));
--
2.48.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (13 preceding siblings ...)
2025-08-25 9:48 ` [PATCH RESEND 14/14] gpio: ge: " Bartosz Golaszewski
@ 2025-08-25 10:00 ` Bartosz Golaszewski
2025-08-25 10:05 ` Bartosz Golaszewski
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 10:00 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Yinbo Zhu, Hoan Tran,
Manivannan Sadhasivam, Yang Shen
Cc: linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
On Mon, Aug 25, 2025 at 11:48 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> Resending due to some patches missing in lore.
>
> This is the first round of GPIO driver conversions to using the
> modernized variant of the gpio-mmio API.
>
> While at it: sprinkle in some additional tweaks and refactoring.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> Bartosz Golaszewski (14):
> gpio: generic: provide to_gpio_generic_chip()
> gpio: generic: provide helpers for reading and writing registers
> gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag
> gpio: ts4800: remove the unnecessary call to platform_set_drvdata()
> gpio: ts4800: use generic device properties
> gpio: ts4800: use dev_err_probe()
> gpio: ts4800: use new generic GPIO chip API
> gpio: loongson-64bit: use new generic GPIO chip API
> gpio: dwapb: use new generic GPIO chip API
> gpio: amdpt: use new generic GPIO chip API
> gpio: rda: use new generic GPIO chip API
> gpio: grgpio: use new generic GPIO chip API
> gpio: mpc8xxx: use new generic GPIO chip API
> gpio: ge: use new generic GPIO chip API
>
> drivers/gpio/gpio-amdpt.c | 44 +++++-----
> drivers/gpio/gpio-dwapb.c | 160 ++++++++++++++++++++-----------------
> drivers/gpio/gpio-ge.c | 25 ++++--
> drivers/gpio/gpio-grgpio.c | 87 ++++++++++----------
> drivers/gpio/gpio-hisi.c | 3 +-
> drivers/gpio/gpio-loongson-64bit.c | 42 +++++-----
> drivers/gpio/gpio-mpc8xxx.c | 102 +++++++++++++----------
> drivers/gpio/gpio-rda.c | 35 ++++----
> drivers/gpio/gpio-ts4800.c | 39 ++++-----
> include/linux/gpio/generic.h | 37 +++++++++
> 10 files changed, 337 insertions(+), 237 deletions(-)
> ---
> base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
> change-id: 20250728-gpio-mmio-gpio-conv-623517c3df74
>
> Best regards,
> --
> Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (14 preceding siblings ...)
2025-08-25 10:00 ` [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
@ 2025-08-25 10:05 ` Bartosz Golaszewski
15 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-08-25 10:05 UTC (permalink / raw)
To: Linus Walleij, Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam,
Yang Shen, Bartosz Golaszewski
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, linux-arm-kernel,
linux-unisoc
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
On Mon, 25 Aug 2025 11:48:41 +0200, Bartosz Golaszewski wrote:
> Resending due to some patches missing in lore.
>
> This is the first round of GPIO driver conversions to using the
> modernized variant of the gpio-mmio API.
>
> While at it: sprinkle in some additional tweaks and refactoring.
>
> [...]
Applied, thanks!
[01/14] gpio: generic: provide to_gpio_generic_chip()
https://git.kernel.org/brgl/linux/c/6e376f245f19feeadddafb2c3fa5fbd6469ecdfe
[02/14] gpio: generic: provide helpers for reading and writing registers
https://git.kernel.org/brgl/linux/c/16397871b6e35fa46a2bec27b3558f93b050c6fc
[03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag
https://git.kernel.org/brgl/linux/c/13ba232ed8455a5decb187d509a0d326fd326b19
[04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata()
https://git.kernel.org/brgl/linux/c/d6307707d50b468d614a80daf60ead8b7036f156
[05/14] gpio: ts4800: use generic device properties
https://git.kernel.org/brgl/linux/c/8a8e9a1a9272f262699960ca2782de87ea69dd32
[06/14] gpio: ts4800: use dev_err_probe()
https://git.kernel.org/brgl/linux/c/ac1eca3ab9fc4d17b59da12597c671df7739f934
[07/14] gpio: ts4800: use new generic GPIO chip API
https://git.kernel.org/brgl/linux/c/9215a4fb59425588233d3362e886dc156c1739af
[08/14] gpio: loongson-64bit: use new generic GPIO chip API
https://git.kernel.org/brgl/linux/c/4ba2193ce0b94c28ec2095a1bb79353c82214d35
[09/14] gpio: dwapb: use new generic GPIO chip API
https://git.kernel.org/brgl/linux/c/84bebb7e7ed000a2c4786094698536a3a3f67083
[10/14] gpio: amdpt: use new generic GPIO chip API
https://git.kernel.org/brgl/linux/c/728e0ca4e196d65e00775ea3f7a49ce008fbd3a7
[11/14] gpio: rda: use new generic GPIO chip API
https://git.kernel.org/brgl/linux/c/ebd63ab0f20f4e1960191da6989797ac78fedc4c
[12/14] gpio: grgpio: use new generic GPIO chip API
https://git.kernel.org/brgl/linux/c/67e4be48f409ba70738eef3c195a81455f526f83
[13/14] gpio: mpc8xxx: use new generic GPIO chip API
https://git.kernel.org/brgl/linux/c/90ab7050358ffd3311c23b1697df2ba3c8f840c6
[14/14] gpio: ge: use new generic GPIO chip API
https://git.kernel.org/brgl/linux/c/56f548840ed90c30269f29c3bdf6037a8a9414a6
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 05/14] gpio: ts4800: use generic device properties
2025-08-25 9:48 ` [PATCH RESEND 05/14] gpio: ts4800: use generic device properties Bartosz Golaszewski
@ 2025-09-03 15:41 ` Andy Shevchenko
2025-09-03 16:12 ` Bartosz Golaszewski
0 siblings, 1 reply; 26+ messages in thread
From: Andy Shevchenko @ 2025-09-03 15:41 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam,
Yang Shen, linux-gpio, linux-kernel, linux-arm-kernel,
linux-unisoc, Bartosz Golaszewski
On Mon, Aug 25, 2025 at 11:48:46AM +0200, Bartosz Golaszewski wrote:
>
> Avoid pulling in linux/of.h by using the generic device properties.
...
> - retval = of_property_read_u32(node, "ngpios", &ngpios);
> + retval = device_property_read_u32(dev, "ngpios", &ngpios);
> if (retval == -EINVAL)
> ngpios = DEFAULT_PIN_NUMBER;
> else if (retval)
Don't we have a method in GPIOLIB that does this (can be called explicitly by the drivers)?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API
2025-08-25 9:48 ` [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API Bartosz Golaszewski
@ 2025-09-03 15:44 ` Andy Shevchenko
2025-09-03 15:48 ` Andy Shevchenko
0 siblings, 1 reply; 26+ messages in thread
From: Andy Shevchenko @ 2025-09-03 15:44 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam,
Yang Shen, linux-gpio, linux-kernel, linux-arm-kernel,
linux-unisoc, Bartosz Golaszewski
On Mon, Aug 25, 2025 at 11:48:48AM +0200, Bartosz Golaszewski wrote:
>
> Convert the driver to using the new generic GPIO chip interfaces from
> linux/gpio/generic.h.
...
> + config = (typeof(config)){
First of all, what's wrong with the pattern used in the kernel when we
explicitly show the compound literal? Also we put a space before {.
> + .dev = dev,
> + .sz = 2,
> + .dat = base_addr + INPUT_REG_OFFSET,
> + .set = base_addr + OUTPUT_REG_OFFSET,
> + .dirout = base_addr + DIRECTION_REG_OFFSET,
> + };
> +
> + retval = gpio_generic_chip_init(chip, &config);
> if (retval)
> - return dev_err_probe(dev, retval, "bgpio_init failed\n");
> + return dev_err_probe(dev, retval,
> + "failed to initialize the generic GPIO chip\n");
Second, can't it all be hidden in the GPIOLIB just by passing the pointer to
the above initialised structure? Yes, it will take a pointer space in GPIO chip
for all, but I think it will reduce the burden.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API
2025-09-03 15:44 ` Andy Shevchenko
@ 2025-09-03 15:48 ` Andy Shevchenko
2025-09-03 16:14 ` Bartosz Golaszewski
0 siblings, 1 reply; 26+ messages in thread
From: Andy Shevchenko @ 2025-09-03 15:48 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam,
Yang Shen, linux-gpio, linux-kernel, linux-arm-kernel,
linux-unisoc, Bartosz Golaszewski
On Wed, Sep 03, 2025 at 05:44:59PM +0200, Andy Shevchenko wrote:
> On Mon, Aug 25, 2025 at 11:48:48AM +0200, Bartosz Golaszewski wrote:
> >
> > Convert the driver to using the new generic GPIO chip interfaces from
> > linux/gpio/generic.h.
...
> > + config = (typeof(config)){
>
> First of all, what's wrong with the pattern used in the kernel when we
> explicitly show the compound literal? Also we put a space before {.
>
> > + .dev = dev,
> > + .sz = 2,
> > + .dat = base_addr + INPUT_REG_OFFSET,
> > + .set = base_addr + OUTPUT_REG_OFFSET,
> > + .dirout = base_addr + DIRECTION_REG_OFFSET,
> > + };
> > +
> > + retval = gpio_generic_chip_init(chip, &config);
> > if (retval)
> > - return dev_err_probe(dev, retval, "bgpio_init failed\n");
> > + return dev_err_probe(dev, retval,
> > + "failed to initialize the generic GPIO chip\n");
>
> Second, can't it all be hidden in the GPIOLIB just by passing the pointer to
> the above initialised structure? Yes, it will take a pointer space in GPIO chip
> for all, but I think it will reduce the burden.
Okay, it seems the motivation is to make it in align with, e.g., gpio-regmap.
But why not simply convert the drivers to use gpio-regmap instead?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 09/14] gpio: dwapb: use new generic GPIO chip API
2025-08-25 9:48 ` [PATCH RESEND 09/14] gpio: dwapb: " Bartosz Golaszewski
@ 2025-09-03 15:51 ` Andy Shevchenko
2025-09-03 16:16 ` Bartosz Golaszewski
0 siblings, 1 reply; 26+ messages in thread
From: Andy Shevchenko @ 2025-09-03 15:51 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam,
Yang Shen, linux-gpio, linux-kernel, linux-arm-kernel,
linux-unisoc, Bartosz Golaszewski
On Mon, Aug 25, 2025 at 11:48:50AM +0200, 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.
...
> +static inline struct dwapb_gpio *to_dwapb_gpio(struct gpio_chip *gc)
> +{
> + return container_of(to_gpio_generic_chip(gc),
> + struct dwapb_gpio_port, chip)->gpio;
> +}
Since it's not a macro anymore it can be done better:
struct dwapb_gpio_port *port;
port = container_of(to_gpio_generic_chip(gc), struct dwapb_gpio_port, chip);
return port->gpio;
Also, have you checked the bloat-o-meter before and after, wondering if we gain
something with this.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 05/14] gpio: ts4800: use generic device properties
2025-09-03 15:41 ` Andy Shevchenko
@ 2025-09-03 16:12 ` Bartosz Golaszewski
0 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-09-03 16:12 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam,
Yang Shen, linux-gpio, linux-kernel, linux-arm-kernel,
linux-unisoc, Bartosz Golaszewski
On Wed, Sep 3, 2025 at 5:41 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Mon, Aug 25, 2025 at 11:48:46AM +0200, Bartosz Golaszewski wrote:
> >
> > Avoid pulling in linux/of.h by using the generic device properties.
>
> ...
>
> > - retval = of_property_read_u32(node, "ngpios", &ngpios);
> > + retval = device_property_read_u32(dev, "ngpios", &ngpios);
> > if (retval == -EINVAL)
> > ngpios = DEFAULT_PIN_NUMBER;
> > else if (retval)
>
> Don't we have a method in GPIOLIB that does this (can be called explicitly by the drivers)?
>
Sure but we don't have the same behavior in GPIO core, we don't know
what DEFAULT_PIN_NUMBER is. I can't test this functionally so don't
want to change semantics.
Bart
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API
2025-09-03 15:48 ` Andy Shevchenko
@ 2025-09-03 16:14 ` Bartosz Golaszewski
0 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-09-03 16:14 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam,
Yang Shen, linux-gpio, linux-kernel, linux-arm-kernel,
linux-unisoc, Bartosz Golaszewski
On Wed, Sep 3, 2025 at 5:48 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Wed, Sep 03, 2025 at 05:44:59PM +0200, Andy Shevchenko wrote:
> > On Mon, Aug 25, 2025 at 11:48:48AM +0200, Bartosz Golaszewski wrote:
> > >
> > > Convert the driver to using the new generic GPIO chip interfaces from
> > > linux/gpio/generic.h.
>
> ...
>
> > > + config = (typeof(config)){
> >
> > First of all, what's wrong with the pattern used in the kernel when we
> > explicitly show the compound literal? Also we put a space before {.
> >
> > > + .dev = dev,
> > > + .sz = 2,
> > > + .dat = base_addr + INPUT_REG_OFFSET,
> > > + .set = base_addr + OUTPUT_REG_OFFSET,
> > > + .dirout = base_addr + DIRECTION_REG_OFFSET,
> > > + };
> > > +
> > > + retval = gpio_generic_chip_init(chip, &config);
> > > if (retval)
> > > - return dev_err_probe(dev, retval, "bgpio_init failed\n");
> > > + return dev_err_probe(dev, retval,
> > > + "failed to initialize the generic GPIO chip\n");
> >
> > Second, can't it all be hidden in the GPIOLIB just by passing the pointer to
> > the above initialised structure? Yes, it will take a pointer space in GPIO chip
> > for all, but I think it will reduce the burden.
>
> Okay, it seems the motivation is to make it in align with, e.g., gpio-regmap.
> But why not simply convert the drivers to use gpio-regmap instead?
>
Because the goal of this rework is removing the gpio-mmio fields out
of struct gpio_chip and also I can't test this conversion
functionally. Out of scope basically. But if you want to do the
conversion, I'm absolutely open to it. :)
Bart
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH RESEND 09/14] gpio: dwapb: use new generic GPIO chip API
2025-09-03 15:51 ` Andy Shevchenko
@ 2025-09-03 16:16 ` Bartosz Golaszewski
0 siblings, 0 replies; 26+ messages in thread
From: Bartosz Golaszewski @ 2025-09-03 16:16 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam,
Yang Shen, linux-gpio, linux-kernel, linux-arm-kernel,
linux-unisoc, Bartosz Golaszewski
On Wed, Sep 3, 2025 at 5:51 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Mon, Aug 25, 2025 at 11:48:50AM +0200, 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.
>
> ...
>
> > +static inline struct dwapb_gpio *to_dwapb_gpio(struct gpio_chip *gc)
> > +{
> > + return container_of(to_gpio_generic_chip(gc),
> > + struct dwapb_gpio_port, chip)->gpio;
> > +}
>
> Since it's not a macro anymore it can be done better:
>
> struct dwapb_gpio_port *port;
>
> port = container_of(to_gpio_generic_chip(gc), struct dwapb_gpio_port, chip);
> return port->gpio;
>
Sure. I already applied it so can you send a follow-up?
> Also, have you checked the bloat-o-meter before and after, wondering if we gain
> something with this.
>
Not yet we don't but we will move the gpio-mmio-specific fields out of
struct gpio_chip so we'll gain several fields worth of memory per
non-generic chip system-wide.
Bart
^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2025-09-03 16:16 UTC | newest]
Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-25 9:48 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 02/14] gpio: generic: provide helpers for reading and writing registers Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata() Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 05/14] gpio: ts4800: use generic device properties Bartosz Golaszewski
2025-09-03 15:41 ` Andy Shevchenko
2025-09-03 16:12 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 06/14] gpio: ts4800: use dev_err_probe() Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API Bartosz Golaszewski
2025-09-03 15:44 ` Andy Shevchenko
2025-09-03 15:48 ` Andy Shevchenko
2025-09-03 16:14 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 08/14] gpio: loongson-64bit: " Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 09/14] gpio: dwapb: " Bartosz Golaszewski
2025-09-03 15:51 ` Andy Shevchenko
2025-09-03 16:16 ` Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 10/14] gpio: amdpt: " Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 11/14] gpio: rda: " Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 12/14] gpio: grgpio: " Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 13/14] gpio: mpc8xxx: " Bartosz Golaszewski
2025-08-25 9:48 ` [PATCH RESEND 14/14] gpio: ge: " Bartosz Golaszewski
2025-08-25 10:00 ` [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-25 10:05 ` Bartosz Golaszewski
-- strict thread matches above, loose matches on Subject: below --
2025-08-12 12:12 Bartosz Golaszewski
2025-08-12 12:12 ` [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
2025-08-12 9:57 [PATCH RESEND 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-12 9:57 ` [PATCH RESEND 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
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).