Skip to contentSkip to conversation

video: fbdev: atmel_lcdfb: convert to use GPIO descriptors

PATCH RESEND Superseded Ludovic Desroches 4 participants 6 messages Feb 5, 2018 – Feb 6, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 video: fbdev: atmel_lcdfb: convert to use GPIO descriptors

Use GPIO descriptors instead of relying on the old method.

---
 drivers/video/fbdev/atmel_lcdfb.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/video/fbdev/atmel_lcdfb.c +12 -18
index 3dee267d7c75..ef3d4198014f 100644
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/backlight.h>
 #include <linux/gfp.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -61,8 +62,7 @@ struct atmel_lcdfb_info {
 };
 
 struct atmel_lcdfb_power_ctrl_gpio {
-	int gpio;
-	int active_low;
+	struct gpio_desc *gpiod;
 
 	struct list_head list;
 };
@@ -1018,7 +1018,7 @@ static void atmel_lcdfb_power_control_gpio(struct atmel_lcdfb_pdata *pdata, int
 	struct atmel_lcdfb_power_ctrl_gpio *og;
 
 	list_for_each_entry(og, &pdata->pwr_gpios, list)
-		gpio_set_value(og->gpio, on);
+		gpiod_set_value(og->gpiod, on);
 }
 
 static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)
@@ -1031,11 +1031,11 @@ static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)
 	struct device_node *display_np;
 	struct device_node *timings_np;
 	struct display_timings *timings;
-	enum of_gpio_flags flags;
 	struct atmel_lcdfb_power_ctrl_gpio *og;
 	bool is_gpio_power = false;
 	int ret = -ENOENT;
-	int i, gpio;
+	int i;
+	struct gpio_desc *gpiod;
 
 	sinfo->config = (struct atmel_lcdfb_config*)
 		of_match_device(atmel_lcdfb_dt_ids, dev)->data;
@@ -1072,28 +1072,22 @@ static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)
 
 	INIT_LIST_HEAD(&pdata->pwr_gpios);
 	ret = -ENOMEM;
-	for (i = 0; i < of_gpio_named_count(display_np, "atmel,power-control-gpio"); i++) {
-		gpio = of_get_named_gpio_flags(display_np, "atmel,power-control-gpio",
-					       i, &flags);
-		if (gpio < 0)
+	for (i = 0; i < gpiod_count(dev, "atmel,power-control"); i++) {
+		gpiod = devm_gpiod_get_index_optional(dev,
+				"atmel,power-control", i, GPIOD_ASIS);
+		if (!gpiod)
 			continue;
 
 		og = devm_kzalloc(dev, sizeof(*og), GFP_KERNEL);
 		if (!og)
 			goto put_display_node;
 
-		og->gpio = gpio;
-		og->active_low = flags & OF_GPIO_ACTIVE_LOW;
+		og->gpiod = gpiod;
 		is_gpio_power = true;
-		ret = devm_gpio_request(dev, gpio, "lcd-power-control-gpio");
-		if (ret) {
-			dev_err(dev, "request gpio %d failed\n", gpio);
-			goto put_display_node;
-		}
 
-		ret = gpio_direction_output(gpio, og->active_low);
+		ret = gpiod_direction_output(gpiod, gpiod_is_active_low(gpiod));
 		if (ret) {
-			dev_err(dev, "set direction output gpio %d failed\n", gpio);
+			dev_err(dev, "set direction output gpio atmel,power-control[%d] failed\n", i);
 			goto put_display_node;
 		}
 		list_add(&og->list, &pdata->pwr_gpios);
Signature · 1 line
2.12.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Ludovic Desroches

Use GPIO descriptors instead of relying on the old method.

On this resent patch as well ;-)

Quoted 86 lines
---
 drivers/video/fbdev/atmel_lcdfb.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/video/fbdev/atmel_lcdfb.c +12 -18
index 3dee267d7c75..ef3d4198014f 100644
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/backlight.h>
 #include <linux/gfp.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -61,8 +62,7 @@ struct atmel_lcdfb_info {
 };
 
 struct atmel_lcdfb_power_ctrl_gpio {
-	int gpio;
-	int active_low;
+	struct gpio_desc *gpiod;
 
 	struct list_head list;
 };
@@ -1018,7 +1018,7 @@ static void atmel_lcdfb_power_control_gpio(struct atmel_lcdfb_pdata *pdata, int
 	struct atmel_lcdfb_power_ctrl_gpio *og;
 
 	list_for_each_entry(og, &pdata->pwr_gpios, list)
-		gpio_set_value(og->gpio, on);
+		gpiod_set_value(og->gpiod, on);
 }
 
 static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)
@@ -1031,11 +1031,11 @@ static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)
 	struct device_node *display_np;
 	struct device_node *timings_np;
 	struct display_timings *timings;
-	enum of_gpio_flags flags;
 	struct atmel_lcdfb_power_ctrl_gpio *og;
 	bool is_gpio_power = false;
 	int ret = -ENOENT;
-	int i, gpio;
+	int i;
+	struct gpio_desc *gpiod;
 
 	sinfo->config = (struct atmel_lcdfb_config*)
 		of_match_device(atmel_lcdfb_dt_ids, dev)->data;
@@ -1072,28 +1072,22 @@ static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)
 
 	INIT_LIST_HEAD(&pdata->pwr_gpios);
 	ret = -ENOMEM;
-	for (i = 0; i < of_gpio_named_count(display_np, "atmel,power-control-gpio"); i++) {
-		gpio = of_get_named_gpio_flags(display_np, "atmel,power-control-gpio",
-					       i, &flags);
-		if (gpio < 0)
+	for (i = 0; i < gpiod_count(dev, "atmel,power-control"); i++) {
+		gpiod = devm_gpiod_get_index_optional(dev,
+				"atmel,power-control", i, GPIOD_ASIS);
+		if (!gpiod)
 			continue;
 
 		og = devm_kzalloc(dev, sizeof(*og), GFP_KERNEL);
 		if (!og)
 			goto put_display_node;
 
-		og->gpio = gpio;
-		og->active_low = flags & OF_GPIO_ACTIVE_LOW;
+		og->gpiod = gpiod;
 		is_gpio_power = true;
-		ret = devm_gpio_request(dev, gpio, "lcd-power-control-gpio");
-		if (ret) {
-			dev_err(dev, "request gpio %d failed\n", gpio);
-			goto put_display_node;
-		}
 
-		ret = gpio_direction_output(gpio, og->active_low);
+		ret = gpiod_direction_output(gpiod, gpiod_is_active_low(gpiod));
 		if (ret) {
-			dev_err(dev, "set direction output gpio %d failed\n", gpio);
+			dev_err(dev, "set direction output gpio atmel,power-control[%d] failed\n", i);
 			goto put_display_node;
 		}
 		list_add(&og->list, &pdata->pwr_gpios);
Signature · 1 line
Nicolas Ferre
#3 lore raw
Quoted 5 lines · Linus Walleij
Quoted 2 lines · Ludovic Desroches

Use GPIO descriptors instead of relying on the old method.

Quoted 7 lines
Quoted 1 line

Ah there it is :D

PS: why not move it all over to use DRI/DRM/KMS? It's becoming easier and easier.

It concerns old products, that's why it's not converted yet.

Regards

Ludovic

Quoted 3 lines

Yours,
Linus Walleij

Reviewed-by on v1 1/1
#4 lore raw
In reply to Ludovic Desroches
Quoted 1 line · Ludovic Desroches

Use GPIO descriptors instead of relying on the old method.

Though few nitpicks below.

drivers/video/fbdev/atmel_lcdfb.c line 22

Quoted 8 lines
drivers/video/fbdev/atmel_lcdfb.c +1 -0
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/backlight.h>
 #include <linux/gfp.h>
 
+#include <linux/gpio/consumer.h>

I think you forgot to remove of_gpio.h.

Quoted 7 lines
drivers/video/fbdev/atmel_lcdfb.c +0 -0
 #include <linux/module.h>
 #include <linux/of.h>

#include <linux/of_device.h>

        struct device_node *display_np;
        struct device_node *timings_np;
        struct display_timings *timings;

drivers/video/fbdev/atmel_lcdfb.c static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo) · line 1038

Quoted 7 lines
drivers/video/fbdev/atmel_lcdfb.c +2 -2
-       enum of_gpio_flags flags;
        struct atmel_lcdfb_power_ctrl_gpio *og;
        bool is_gpio_power = false;
        int ret = -ENOENT;
-       int i, gpio;
+       int i;
+       struct gpio_desc *gpiod;

I would rather preserve reversed tree style, i.e. put longer line upper.

drivers/video/fbdev/atmel_lcdfb.c static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo) · line 1079

Quoted 5 lines
drivers/video/fbdev/atmel_lcdfb.c +4 -0
+       for (i = 0; i < gpiod_count(dev, "atmel,power-control"); i++) {
+               gpiod = devm_gpiod_get_index_optional(dev,
+                               "atmel,power-control", i, GPIOD_ASIS);
+               if (!gpiod)
                        continue;

What about IS_ERR() case?

drivers/video/fbdev/atmel_lcdfb.c static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo) · line 1089

Quoted 10 lines
                og = devm_kzalloc(dev, sizeof(*og), GFP_KERNEL);
                if (!og)
                        goto put_display_node;
drivers/video/fbdev/atmel_lcdfb.c +2 -0
+               og->gpiod = gpiod;
                is_gpio_power = true;
 
+               ret = gpiod_direction_output(gpiod, gpiod_is_active_low(gpiod));
                if (ret) {

I'm not sure this will be needed if you check IS_ERR() above.

Quoted 3 lines
+                       dev_err(dev, "set direction output gpio atmel,power-control[%d] failed\n", i);
                        goto put_display_node;
                }
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 16 lines · Andy Shevchenko
Quoted 1 line · Ludovic Desroches

Use GPIO descriptors instead of relying on the old method.

Though few nitpicks below.

Quoted 6 lines
drivers/video/fbdev/atmel_lcdfb.c +0 -0
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/backlight.h>
 #include <linux/gfp.h>
Quoted 3 lines

drivers/video/fbdev/atmel_lcdfb.c line 21

Quoted 1 line
drivers/video/fbdev/atmel_lcdfb.c +1 -0
+#include <linux/gpio/consumer.h>

I think you forgot to remove of_gpio.h.

Right. I'll remove it.

Quoted 16 lines
Quoted 8 lines
drivers/video/fbdev/atmel_lcdfb.c +0 -0
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
        struct device_node *display_np;
        struct device_node *timings_np;
        struct display_timings *timings;

drivers/video/fbdev/atmel_lcdfb.c static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo) · line 1038

Quoted 7 lines
drivers/video/fbdev/atmel_lcdfb.c +2 -2
-       enum of_gpio_flags flags;
        struct atmel_lcdfb_power_ctrl_gpio *og;
        bool is_gpio_power = false;
        int ret = -ENOENT;
-       int i, gpio;
+       int i;
+       struct gpio_desc *gpiod;
Quoted 1 line

I would rather preserve reversed tree style, i.e. put longer line upper.

Ok.

Quoted 9 lines

drivers/video/fbdev/atmel_lcdfb.c static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo) · line 1079

Quoted 7 lines
drivers/video/fbdev/atmel_lcdfb.c +4 -0
+       for (i = 0; i < gpiod_count(dev, "atmel,power-control"); i++) {
+               gpiod = devm_gpiod_get_index_optional(dev,
+                               "atmel,power-control", i, GPIOD_ASIS);
+               if (!gpiod)
                        continue;

What about IS_ERR() case?

if (!gpiod || IS_ERR(gpiod))

	continue;

Thanks.

Quoted 6 lines
Quoted 6 lines

                og = devm_kzalloc(dev, sizeof(*og), GFP_KERNEL);
                if (!og)
                        goto put_display_node;
Quoted 8 lines

drivers/video/fbdev/atmel_lcdfb.c static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo) · line 1089

Quoted 5 lines
drivers/video/fbdev/atmel_lcdfb.c +2 -0
+               og->gpiod = gpiod;
                is_gpio_power = true;
 
+               ret = gpiod_direction_output(gpiod, gpiod_is_active_low(gpiod));
                if (ret) {

I'm not sure this will be needed if you check IS_ERR() above.

When in doubt, I keep it.

Regards

Ludovic

Quoted 12 lines
Quoted 3 lines
+                       dev_err(dev, "set direction output gpio atmel,power-control[%d] failed\n", i);
                        goto put_display_node;
                }
Signature · 6 lines
With Best Regards,
Andy Shevchenko
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel