linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] backlight: hx8357: Convert to agnostic GPIO API
@ 2023-03-17 18:52 Andy Shevchenko
  2023-03-17 20:53 ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2023-03-17 18:52 UTC (permalink / raw)
  To: Bartosz Golaszewski, Dmitry Torokhov, Andy Shevchenko,
	linux-gpio, linux-kernel, dri-devel, linux-fbdev
  Cc: Linus Walleij, Bartosz Golaszewski, Lee Jones, Daniel Thompson,
	Jingoo Han, Helge Deller

The of_gpio.h is going to be removed. In preparation of that convert
the driver to the agnostic API.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib-of.c        |  4 +-
 drivers/video/backlight/hx8357.c | 74 ++++++++++----------------------
 2 files changed, 24 insertions(+), 54 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 1436cdb5fa26..cdd536a391be 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -184,7 +184,7 @@ static void of_gpio_try_fixup_polarity(const struct device_node *np,
 		const char *propname;
 		bool active_high;
 	} gpios[] = {
-#if !IS_ENABLED(CONFIG_LCD_HX8357)
+#if IS_ENABLED(CONFIG_LCD_HX8357)
 		/*
 		 * Himax LCD controllers used incorrectly named
 		 * "gpios-reset" property and also specified wrong
@@ -452,7 +452,7 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
 		 */
 		const char *compatible;
 	} gpios[] = {
-#if !IS_ENABLED(CONFIG_LCD_HX8357)
+#if IS_ENABLED(CONFIG_LCD_HX8357)
 		/* Himax LCD controllers used "gpios-reset" */
 		{ "reset",	"gpios-reset",	"himax,hx8357" },
 		{ "reset",	"gpios-reset",	"himax,hx8369" },
diff --git a/drivers/video/backlight/hx8357.c b/drivers/video/backlight/hx8357.c
index 9b50bc96e00f..d7298376cf74 100644
--- a/drivers/video/backlight/hx8357.c
+++ b/drivers/video/backlight/hx8357.c
@@ -6,11 +6,11 @@
  */
 
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/lcd.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <linux/spi/spi.h>
 
 #define HX8357_NUM_IM_PINS	3
@@ -83,11 +83,10 @@
 #define HX8369_SET_GAMMA_CURVE_RELATED		0xe0
 
 struct hx8357_data {
-	unsigned		im_pins[HX8357_NUM_IM_PINS];
-	unsigned		reset;
+	struct gpio_descs	*im_pins;
+	struct gpio_desc	*reset;
 	struct spi_device	*spi;
 	int			state;
-	bool			use_im_pins;
 };
 
 static u8 hx8357_seq_power[] = {
@@ -321,11 +320,11 @@ static void hx8357_lcd_reset(struct lcd_device *lcdev)
 	struct hx8357_data *lcd = lcd_get_data(lcdev);
 
 	/* Reset the screen */
-	gpio_set_value(lcd->reset, 1);
+	gpiod_set_value(lcd->reset, 0);
 	usleep_range(10000, 12000);
-	gpio_set_value(lcd->reset, 0);
+	gpiod_set_value(lcd->reset, 1);
 	usleep_range(10000, 12000);
-	gpio_set_value(lcd->reset, 1);
+	gpiod_set_value(lcd->reset, 0);
 
 	/* The controller needs 120ms to recover from reset */
 	msleep(120);
@@ -340,10 +339,10 @@ static int hx8357_lcd_init(struct lcd_device *lcdev)
 	 * Set the interface selection pins to SPI mode, with three
 	 * wires
 	 */
-	if (lcd->use_im_pins) {
-		gpio_set_value_cansleep(lcd->im_pins[0], 1);
-		gpio_set_value_cansleep(lcd->im_pins[1], 0);
-		gpio_set_value_cansleep(lcd->im_pins[2], 1);
+	if (lcd->im_pins) {
+		gpiod_set_value_cansleep(lcd->im_pins->desc[0], 1);
+		gpiod_set_value_cansleep(lcd->im_pins->desc[1], 0);
+		gpiod_set_value_cansleep(lcd->im_pins->desc[2], 1);
 	}
 
 	ret = hx8357_spi_write_array(lcdev, hx8357_seq_power,
@@ -580,6 +579,7 @@ MODULE_DEVICE_TABLE(of, hx8357_dt_ids);
 
 static int hx8357_probe(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
 	struct lcd_device *lcdev;
 	struct hx8357_data *lcd;
 	const struct of_device_id *match;
@@ -601,49 +601,19 @@ static int hx8357_probe(struct spi_device *spi)
 	if (!match || !match->data)
 		return -EINVAL;
 
-	lcd->reset = of_get_named_gpio(spi->dev.of_node, "gpios-reset", 0);
-	if (!gpio_is_valid(lcd->reset)) {
-		dev_err(&spi->dev, "Missing dt property: gpios-reset\n");
-		return -EINVAL;
-	}
+	lcd->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(lcd->reset))
+		return dev_err_probe(dev, PTR_ERR(lcd->reset), "failed to request reset GPIO\n");
+	gpiod_set_consumer_name(lcd->reset, "hx8357-reset");
 
-	ret = devm_gpio_request_one(&spi->dev, lcd->reset,
-				    GPIOF_OUT_INIT_HIGH,
-				    "hx8357-reset");
-	if (ret) {
-		dev_err(&spi->dev,
-			"failed to request gpio %d: %d\n",
-			lcd->reset, ret);
-		return -EINVAL;
-	}
+	lcd->im_pins = devm_gpiod_get_array_optional(dev, "im", GPIOD_OUT_LOW);
+	if (IS_ERR(lcd->im_pins))
+		return dev_err_probe(dev, PTR_ERR(lcd->im_pins), "failed to request im GPIOs\n");
+	if (lcd->im_pins->ndescs < HX8357_NUM_IM_PINS)
+		return dev_err_probe(dev, -EINVAL, "not enough im GPIOs\n");
 
-	if (of_find_property(spi->dev.of_node, "im-gpios", NULL)) {
-		lcd->use_im_pins = 1;
-
-		for (i = 0; i < HX8357_NUM_IM_PINS; i++) {
-			lcd->im_pins[i] = of_get_named_gpio(spi->dev.of_node,
-							    "im-gpios", i);
-			if (lcd->im_pins[i] == -EPROBE_DEFER) {
-				dev_info(&spi->dev, "GPIO requested is not here yet, deferring the probe\n");
-				return -EPROBE_DEFER;
-			}
-			if (!gpio_is_valid(lcd->im_pins[i])) {
-				dev_err(&spi->dev, "Missing dt property: im-gpios\n");
-				return -EINVAL;
-			}
-
-			ret = devm_gpio_request_one(&spi->dev, lcd->im_pins[i],
-						    GPIOF_OUT_INIT_LOW,
-						    "im_pins");
-			if (ret) {
-				dev_err(&spi->dev, "failed to request gpio %d: %d\n",
-					lcd->im_pins[i], ret);
-				return -EINVAL;
-			}
-		}
-	} else {
-		lcd->use_im_pins = 0;
-	}
+	for (i = 0; i < HX8357_NUM_IM_PINS; i++)
+		gpiod_set_consumer_name(lcd->im_pins->desc[i], "im_pins");
 
 	lcdev = devm_lcd_device_register(&spi->dev, "mxsfb", &spi->dev, lcd,
 					&hx8357_ops);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/1] backlight: hx8357: Convert to agnostic GPIO API
  2023-03-17 18:52 [PATCH v1 1/1] backlight: hx8357: Convert to agnostic GPIO API Andy Shevchenko
@ 2023-03-17 20:53 ` Linus Walleij
  2023-03-20 11:54   ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2023-03-17 20:53 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bartosz Golaszewski, Dmitry Torokhov, linux-gpio, linux-kernel,
	dri-devel, linux-fbdev, Bartosz Golaszewski, Lee Jones,
	Daniel Thompson, Jingoo Han, Helge Deller

On Fri, Mar 17, 2023 at 7:51 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> The of_gpio.h is going to be removed. In preparation of that convert
> the driver to the agnostic API.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks for fixing this Andy!

> -#if !IS_ENABLED(CONFIG_LCD_HX8357)
> +#if IS_ENABLED(CONFIG_LCD_HX8357)
>                 /*
>                  * Himax LCD controllers used incorrectly named
>                  * "gpios-reset" property and also specified wrong
> @@ -452,7 +452,7 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
>                  */
>                 const char *compatible;
>         } gpios[] = {
> -#if !IS_ENABLED(CONFIG_LCD_HX8357)
> +#if IS_ENABLED(CONFIG_LCD_HX8357)
>                 /* Himax LCD controllers used "gpios-reset" */
>                 { "reset",      "gpios-reset",  "himax,hx8357" },
>                 { "reset",      "gpios-reset",  "himax,hx8369" },

Eh what happened here .. it's even intuitively wrong.
I would add
Fixes: fbbbcd177a27 ("gpiolib: of: add quirk for locating reset lines
with legacy bindings")

It wasn't used until now it seems so not a regression and no
need for a separate patch.

Other than that it looks correct.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/1] backlight: hx8357: Convert to agnostic GPIO API
  2023-03-17 20:53 ` Linus Walleij
@ 2023-03-20 11:54   ` Andy Shevchenko
  2023-06-05 16:07     ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2023-03-20 11:54 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Bartosz Golaszewski, Dmitry Torokhov, linux-gpio, linux-kernel,
	dri-devel, linux-fbdev, Bartosz Golaszewski, Lee Jones,
	Daniel Thompson, Jingoo Han, Helge Deller

On Fri, Mar 17, 2023 at 09:53:40PM +0100, Linus Walleij wrote:
> On Fri, Mar 17, 2023 at 7:51 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> 
> > The of_gpio.h is going to be removed. In preparation of that convert
> > the driver to the agnostic API.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Thanks for fixing this Andy!
> 
> > -#if !IS_ENABLED(CONFIG_LCD_HX8357)
> > +#if IS_ENABLED(CONFIG_LCD_HX8357)
> >                 /*
> >                  * Himax LCD controllers used incorrectly named
> >                  * "gpios-reset" property and also specified wrong
> > @@ -452,7 +452,7 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
> >                  */
> >                 const char *compatible;
> >         } gpios[] = {
> > -#if !IS_ENABLED(CONFIG_LCD_HX8357)
> > +#if IS_ENABLED(CONFIG_LCD_HX8357)
> >                 /* Himax LCD controllers used "gpios-reset" */
> >                 { "reset",      "gpios-reset",  "himax,hx8357" },
> >                 { "reset",      "gpios-reset",  "himax,hx8369" },
> 
> Eh what happened here .. it's even intuitively wrong.

I believe it had to be something  like

	#if 0 && IS_ENABLED()

to show that this change is for the future.
Currently it does something unneeded for the kernels with that option off.

> I would add
> Fixes: fbbbcd177a27 ("gpiolib: of: add quirk for locating reset lines
> with legacy bindings")

I'm not sure. But it's fine, I can add it. Just want to double confirm
you really want this Fixes tag.

> It wasn't used until now it seems so not a regression and no
> need for a separate patch.

Exactly why I'm not sure about the tag :-)

> Other than that it looks correct.
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Thank you!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/1] backlight: hx8357: Convert to agnostic GPIO API
  2023-03-20 11:54   ` Andy Shevchenko
@ 2023-06-05 16:07     ` Andy Shevchenko
  2023-06-06  8:17       ` Daniel Thompson
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2023-06-05 16:07 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Bartosz Golaszewski, Dmitry Torokhov, linux-gpio, linux-kernel,
	dri-devel, linux-fbdev, Bartosz Golaszewski, Lee Jones,
	Daniel Thompson, Jingoo Han, Helge Deller

On Mon, Mar 20, 2023 at 01:54:26PM +0200, Andy Shevchenko wrote:
> On Fri, Mar 17, 2023 at 09:53:40PM +0100, Linus Walleij wrote:
> > On Fri, Mar 17, 2023 at 7:51 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > 
> > > The of_gpio.h is going to be removed. In preparation of that convert
> > > the driver to the agnostic API.
> > >
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > Thanks for fixing this Andy!
> > 
> > > -#if !IS_ENABLED(CONFIG_LCD_HX8357)
> > > +#if IS_ENABLED(CONFIG_LCD_HX8357)
> > >                 /*
> > >                  * Himax LCD controllers used incorrectly named
> > >                  * "gpios-reset" property and also specified wrong
> > > @@ -452,7 +452,7 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
> > >                  */
> > >                 const char *compatible;
> > >         } gpios[] = {
> > > -#if !IS_ENABLED(CONFIG_LCD_HX8357)
> > > +#if IS_ENABLED(CONFIG_LCD_HX8357)
> > >                 /* Himax LCD controllers used "gpios-reset" */
> > >                 { "reset",      "gpios-reset",  "himax,hx8357" },
> > >                 { "reset",      "gpios-reset",  "himax,hx8369" },
> > 
> > Eh what happened here .. it's even intuitively wrong.
> 
> I believe it had to be something  like
> 
> 	#if 0 && IS_ENABLED()
> 
> to show that this change is for the future.
> Currently it does something unneeded for the kernels with that option off.
> 
> > I would add
> > Fixes: fbbbcd177a27 ("gpiolib: of: add quirk for locating reset lines
> > with legacy bindings")
> 
> I'm not sure. But it's fine, I can add it. Just want to double confirm
> you really want this Fixes tag.
> 
> > It wasn't used until now it seems so not a regression and no
> > need for a separate patch.
> 
> Exactly why I'm not sure about the tag :-)
> 
> > Other than that it looks correct.
> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> 
> Thank you!

Lee, is anything I can do here to move this forward?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/1] backlight: hx8357: Convert to agnostic GPIO API
  2023-06-05 16:07     ` Andy Shevchenko
@ 2023-06-06  8:17       ` Daniel Thompson
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Thompson @ 2023-06-06  8:17 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Bartosz Golaszewski, Dmitry Torokhov, linux-gpio,
	linux-kernel, dri-devel, linux-fbdev, Bartosz Golaszewski,
	Lee Jones, Jingoo Han, Helge Deller

On Mon, Jun 05, 2023 at 07:07:24PM +0300, Andy Shevchenko wrote:
> On Mon, Mar 20, 2023 at 01:54:26PM +0200, Andy Shevchenko wrote:
> > On Fri, Mar 17, 2023 at 09:53:40PM +0100, Linus Walleij wrote:
> > > On Fri, Mar 17, 2023 at 7:51 PM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > > The of_gpio.h is going to be removed. In preparation of that convert
> > > > the driver to the agnostic API.
> > > >
> > > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > >
> > > Thanks for fixing this Andy!
> > >
> > > > -#if !IS_ENABLED(CONFIG_LCD_HX8357)
> > > > +#if IS_ENABLED(CONFIG_LCD_HX8357)
> > > >                 /*
> > > >                  * Himax LCD controllers used incorrectly named
> > > >                  * "gpios-reset" property and also specified wrong
> > > > @@ -452,7 +452,7 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
> > > >                  */
> > > >                 const char *compatible;
> > > >         } gpios[] = {
> > > > -#if !IS_ENABLED(CONFIG_LCD_HX8357)
> > > > +#if IS_ENABLED(CONFIG_LCD_HX8357)
> > > >                 /* Himax LCD controllers used "gpios-reset" */
> > > >                 { "reset",      "gpios-reset",  "himax,hx8357" },
> > > >                 { "reset",      "gpios-reset",  "himax,hx8369" },
> > >
> > > Eh what happened here .. it's even intuitively wrong.
> >
> > I believe it had to be something  like
> >
> > 	#if 0 && IS_ENABLED()
> >
> > to show that this change is for the future.
> > Currently it does something unneeded for the kernels with that option off.
> >
> > > I would add
> > > Fixes: fbbbcd177a27 ("gpiolib: of: add quirk for locating reset lines
> > > with legacy bindings")
> >
> > I'm not sure. But it's fine, I can add it. Just want to double confirm
> > you really want this Fixes tag.
> >
> > > It wasn't used until now it seems so not a regression and no
> > > need for a separate patch.
> >
> > Exactly why I'm not sure about the tag :-)
> >
> > > Other than that it looks correct.
> > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> >
> > Thank you!
>
> Lee, is anything I can do here to move this forward?

Backlight code looks OK to me (although I might regard the Fixes:
discussion as unresolved)there is an unresolved):
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>


Daniel.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-06  8:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 18:52 [PATCH v1 1/1] backlight: hx8357: Convert to agnostic GPIO API Andy Shevchenko
2023-03-17 20:53 ` Linus Walleij
2023-03-20 11:54   ` Andy Shevchenko
2023-06-05 16:07     ` Andy Shevchenko
2023-06-06  8:17       ` Daniel Thompson

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).