* [PATCH 01/14] gpio: generic: provide to_gpio_generic_chip()
2025-08-12 9:51 [PATCH 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
@ 2025-08-12 9:51 ` Bartosz Golaszewski
2025-08-19 10:17 ` Linus Walleij
2025-08-12 9:51 ` [PATCH 02/14] gpio: generic: provide helpers for reading and writing registers Bartosz Golaszewski
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-08-12 9:51 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] 7+ messages in thread
* Re: [PATCH 01/14] gpio: generic: provide to_gpio_generic_chip()
2025-08-12 9:51 ` [PATCH 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
@ 2025-08-19 10:17 ` Linus Walleij
0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2025-08-19 10:17 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Yinbo Zhu, Hoan Tran, Manivannan Sadhasivam, Yang Shen,
linux-gpio, linux-kernel, linux-arm-kernel, linux-unisoc,
Bartosz Golaszewski
On Tue, Aug 12, 2025 at 11:52 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> 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>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 02/14] gpio: generic: provide helpers for reading and writing registers
2025-08-12 9:51 [PATCH 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-12 9:51 ` [PATCH 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
@ 2025-08-12 9:51 ` Bartosz Golaszewski
2025-08-12 9:52 ` [PATCH 03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag Bartosz Golaszewski
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-08-12 9:51 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] 7+ messages in thread
* [PATCH 03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag
2025-08-12 9:51 [PATCH 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
2025-08-12 9:51 ` [PATCH 01/14] gpio: generic: provide to_gpio_generic_chip() Bartosz Golaszewski
2025-08-12 9:51 ` [PATCH 02/14] gpio: generic: provide helpers for reading and writing registers Bartosz Golaszewski
@ 2025-08-12 9:52 ` Bartosz Golaszewski
2025-08-12 9:52 ` [PATCH 04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata() Bartosz Golaszewski
2025-08-12 9:52 ` [PATCH 05/14] gpio: ts4800: use generic device properties Bartosz Golaszewski
4 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-08-12 9:52 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] 7+ messages in thread
* [PATCH 04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata()
2025-08-12 9:51 [PATCH 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (2 preceding siblings ...)
2025-08-12 9:52 ` [PATCH 03/14] gpio: hisi: use the BGPIOF_UNREADABLE_REG_DIR flag Bartosz Golaszewski
@ 2025-08-12 9:52 ` Bartosz Golaszewski
2025-08-12 9:52 ` [PATCH 05/14] gpio: ts4800: use generic device properties Bartosz Golaszewski
4 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-08-12 9:52 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] 7+ messages in thread
* [PATCH 05/14] gpio: ts4800: use generic device properties
2025-08-12 9:51 [PATCH 00/14] gpio: replace legacy bgpio_init() with its modernized alternative Bartosz Golaszewski
` (3 preceding siblings ...)
2025-08-12 9:52 ` [PATCH 04/14] gpio: ts4800: remove the unnecessary call to platform_set_drvdata() Bartosz Golaszewski
@ 2025-08-12 9:52 ` Bartosz Golaszewski
4 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-08-12 9:52 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] 7+ messages in thread