[PATCH RESEND 05/14] gpio: ts4800: use generic device properties

Bartosz Golaszewski posted 14 patches 1 month, 1 week ago
[PATCH RESEND 05/14] gpio: ts4800: use generic device properties
Posted by Bartosz Golaszewski 1 month, 1 week ago
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
Re: [PATCH RESEND 05/14] gpio: ts4800: use generic device properties
Posted by Andy Shevchenko 1 month ago
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
Re: [PATCH RESEND 05/14] gpio: ts4800: use generic device properties
Posted by Bartosz Golaszewski 1 month ago
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