Skip to contentSkip to conversation

video: backlight: Replace old GPIO APIs with GPIO Consumer APIs for sky81542-backlight driver

PATCH In review Shobhit Kukreti 3 participants 5 messages Jun 12, 2019 – Jun 13, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 video: backlight: Replace old GPIO APIs with GPIO Consumer APIs for sky81542-backlight driver

Port the sky81452-backlight driver to adhere to new gpio descriptor based APIs. Modified the file sky81452-backlight.c and sky81452-backlight.h. The gpio descriptor property in device tree should be "sky81452-en-gpios"

Removed unnecessary header files "linux/gpio.h" and "linux/of_gpio.h".

---
 drivers/video/backlight/sky81452-backlight.c     | 24 ++++++++++++------------
 include/linux/platform_data/sky81452-backlight.h |  4 +++-
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/video/backlight/sky81452-backlight.c +12 -12
index d414c7a..12ef628 100644
@@ -19,12 +19,10 @@
 
 #include <linux/backlight.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/platform_data/sky81452-backlight.h>
@@ -193,7 +191,6 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	pdata->ignore_pwm = of_property_read_bool(np, "skyworks,ignore-pwm");
 	pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode");
 	pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift");
-	pdata->gpio_enable = of_get_gpio(np, 0);
 
 	ret = of_property_count_u32_elems(np, "led-sources");
 	if (ret < 0) {
@@ -274,13 +271,17 @@ static int sky81452_bl_probe(struct platform_device *pdev)
 		if (IS_ERR(pdata))
 			return PTR_ERR(pdata);
 	}
-
-	if (gpio_is_valid(pdata->gpio_enable)) {
-		ret = devm_gpio_request_one(dev, pdata->gpio_enable,
-					GPIOF_OUT_INIT_HIGH, "sky81452-en");
-		if (ret < 0) {
-			dev_err(dev, "failed to request GPIO. err=%d\n", ret);
-			return ret;
+	pdata->gpiod_enable = devm_gpiod_get(dev, "sk81452-en", GPIOD_OUT_HIGH);
+	if (IS_ERR(pdata->gpiod_enable)) {
+		long ret = PTR_ERR(pdata->gpiod_enable);
+
+		/**
+		 * gpiod_enable is optional in device tree.
+		 * Return error only if gpio was assigned in device tree
+		 */
+		if (ret != -ENOENT) {
+			dev_err(dev, "failed to request GPIO. err=%ld\n", ret);
+			return PTR_ERR(pdata->gpiod_enable);
 		}
 	}
 
@@ -323,8 +324,7 @@ static int sky81452_bl_remove(struct platform_device *pdev)
 	bd->props.brightness = 0;
 	backlight_update_status(bd);
 
-	if (gpio_is_valid(pdata->gpio_enable))
-		gpio_set_value_cansleep(pdata->gpio_enable, 0);
+	gpiod_set_value_cansleep(pdata->gpiod_enable, 0);
 
 	return 0;
 }
include/linux/platform_data/sky81452-backlight.h +3 -1
index 1231e9b..dc4cb85 100644
@@ -20,6 +20,8 @@
 #ifndef _SKY81452_BACKLIGHT_H
 #define _SKY81452_BACKLIGHT_H
 
+#include <linux/gpio/consumer.h>
+
 /**
  * struct sky81452_platform_data
  * @name:	backlight driver name.
@@ -34,7 +36,7 @@
  */
 struct sky81452_bl_platform_data {
 	const char *name;
-	int gpio_enable;
+	struct gpio_desc *gpiod_enable;
 	unsigned int enable;
 	bool ignore_pwm;
 	bool dpwm_mode;
Signature · 1 line
2.7.4
#1 lore raw

Hi Shobhit

Thanks for the patch. Feedback below...

Quoted 3 lines · Shobhit Kukreti

Port the sky81452-backlight driver to adhere to new gpio descriptor based APIs. Modified the file sky81452-backlight.c and sky81452-backlight.h. The gpio descriptor property in device tree should be "sky81452-en-gpios"

That is contradicted by the device tree bindings. The property should remain "gpios" as it was before this conversion.

Quoted 3 lines

Removed unnecessary header files "linux/gpio.h" and "linux/of_gpio.h".

What level of testing have you done? Is this a fix for hardware you own or a cleanup after searching the sources?

Quoted 32 lines
---
 drivers/video/backlight/sky81452-backlight.c     | 24 ++++++++++++------------
 include/linux/platform_data/sky81452-backlight.h |  4 +++-
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/video/backlight/sky81452-backlight.c +0 -3
index d414c7a..12ef628 100644
@@ -19,12 +19,10 @@
 
 #include <linux/backlight.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/platform_data/sky81452-backlight.h>
@@ -193,7 +191,6 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	pdata->ignore_pwm = of_property_read_bool(np, "skyworks,ignore-pwm");
 	pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode");
 	pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift");
-	pdata->gpio_enable = of_get_gpio(np, 0);
 
 	ret = of_property_count_u32_elems(np, "led-sources");
 	if (ret < 0) {
@@ -274,13 +271,17 @@ static int sky81452_bl_probe(struct platform_device *pdev)
 		if (IS_ERR(pdata))

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 274

Quoted 10 lines
drivers/video/backlight/sky81452-backlight.c +1 -7
 			return PTR_ERR(pdata);
 	}
-
-	if (gpio_is_valid(pdata->gpio_enable)) {
-		ret = devm_gpio_request_one(dev, pdata->gpio_enable,
-					GPIOF_OUT_INIT_HIGH, "sky81452-en");
-		if (ret < 0) {
-			dev_err(dev, "failed to request GPIO. err=%d\n", ret);
-			return ret;
+	pdata->gpiod_enable = devm_gpiod_get(dev, "sk81452-en", GPIOD_OUT_HIGH);

As above... I think the second argument here needs to be NULL in order to preserve the current DT bindings.

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 278

Quoted 4 lines
drivers/video/backlight/sky81452-backlight.c +4 -0
+	if (IS_ERR(pdata->gpiod_enable)) {
+		long ret = PTR_ERR(pdata->gpiod_enable);
+
+		/**

Nitpicking... but no second star here. That's a trigger symbold for documentation processors.

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 280

Quoted 2 lines
drivers/video/backlight/sky81452-backlight.c +2 -0
+		 * gpiod_enable is optional in device tree.
+		 * Return error only if gpio was assigned in device tree

Also nitpicking but I had to read this a few times because gpiod_enable is not in device tree, gpios is.

This is a common pattern so the comment can be very short. Something like:

This DT property is optional so no need to propagate ENOENT

Quoted 22 lines
drivers/video/backlight/sky81452-backlight.c +5 -2
+		 */
+		if (ret != -ENOENT) {
+			dev_err(dev, "failed to request GPIO. err=%ld\n", ret);
+			return PTR_ERR(pdata->gpiod_enable);
 		}
 	}
 
@@ -323,8 +324,7 @@ static int sky81452_bl_remove(struct platform_device *pdev)
 	bd->props.brightness = 0;
 	backlight_update_status(bd);
 
-	if (gpio_is_valid(pdata->gpio_enable))
-		gpio_set_value_cansleep(pdata->gpio_enable, 0);
+	gpiod_set_value_cansleep(pdata->gpiod_enable, 0);
 
 	return 0;
 }
include/linux/platform_data/sky81452-backlight.h +0 -0
index 1231e9b..dc4cb85 100644

include/linux/platform_data/sky81452-backlight.h line 24

Quoted 5 lines
include/linux/platform_data/sky81452-backlight.h +2 -0
@@ -20,6 +20,8 @@
 #ifndef _SKY81452_BACKLIGHT_H
 #define _SKY81452_BACKLIGHT_H
 
+#include <linux/gpio/consumer.h>
+

This heaer file should be included from the C file... it is not required to parse the header.

Daniel.

Quoted 15 lines
include/linux/platform_data/sky81452-backlight.h +1 -1
 /**
  * struct sky81452_platform_data
  * @name:	backlight driver name.
@@ -34,7 +36,7 @@
  */
 struct sky81452_bl_platform_data {
 	const char *name;
-	int gpio_enable;
+	struct gpio_desc *gpiod_enable;
 	unsigned int enable;
 	bool ignore_pwm;
 	bool dpwm_mode;
Signature · 1 line
2.7.4
#4 lore raw
In reply to Shobhit Kukreti

Hi Shobhit

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 276

Quoted 8 lines
drivers/video/backlight/sky81452-backlight.c +3 -3
-	if (gpio_is_valid(pdata->gpio_enable)) {
-		ret = devm_gpio_request_one(dev, pdata->gpio_enable,
-					GPIOF_OUT_INIT_HIGH, "sky81452-en");
 
 
+	pdata->gpiod_enable = devm_gpiod_get(dev, "sk81452-en", GPIOD_OUT_HIGH);
+	if (IS_ERR(pdata->gpiod_enable)) {
+		long ret = PTR_ERR(pdata->gpiod_enable);

In the old code the property was named "sky81452-en". In the new code the property is named "sk81452-en".

Most likely a bug.

Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
In reply to Daniel Thompson
Quoted 3 lines · Daniel Thompson

Hi Shobhit

Thanks for the patch. Feedback below...

Hi Daneil,

You provided some valuable feedback. Thank you for your time and effort.

Quoted 9 lines · Shobhit Kukreti
Quoted 3 lines

Port the sky81452-backlight driver to adhere to new gpio descriptor based APIs. Modified the file sky81452-backlight.c and sky81452-backlight.h. The gpio descriptor property in device tree should be "sky81452-en-gpios"

That is contradicted by the device tree bindings. The property should remain "gpios" as it was before this conversion.

You are correct.

Quoted 9 lines
Quoted 5 lines

Removed unnecessary header files "linux/gpio.h" and "linux/of_gpio.h".

What level of testing have you done? Is this a fix for hardware you own or a cleanup after searching the sources?

I did not the test on actual hardware. I was trying to do a clean up and boot on QEMU/rock960 board. I will drop the patch until I can find the sk81452 hardware to test it.

Quoted 38 lines
Quoted 38 lines
---
 drivers/video/backlight/sky81452-backlight.c     | 24 ++++++++++++------------
 include/linux/platform_data/sky81452-backlight.h |  4 +++-
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/video/backlight/sky81452-backlight.c +0 -6
index d414c7a..12ef628 100644
@@ -19,12 +19,10 @@
 
 #include <linux/backlight.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/platform_data/sky81452-backlight.h>
@@ -193,7 +191,6 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	pdata->ignore_pwm = of_property_read_bool(np, "skyworks,ignore-pwm");
 	pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode");
 	pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift");
-	pdata->gpio_enable = of_get_gpio(np, 0);
 
 	ret = of_property_count_u32_elems(np, "led-sources");
 	if (ret < 0) {
@@ -274,13 +271,17 @@ static int sky81452_bl_probe(struct platform_device *pdev)
 		if (IS_ERR(pdata))
 			return PTR_ERR(pdata);
 	}
-
-	if (gpio_is_valid(pdata->gpio_enable)) {
-		ret = devm_gpio_request_one(dev, pdata->gpio_enable,
Quoted 8 lines

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 274

Quoted 5 lines
drivers/video/backlight/sky81452-backlight.c +1 -4
-					GPIOF_OUT_INIT_HIGH, "sky81452-en");
-		if (ret < 0) {
-			dev_err(dev, "failed to request GPIO. err=%d\n", ret);
-			return ret;
+	pdata->gpiod_enable = devm_gpiod_get(dev, "sk81452-en", GPIOD_OUT_HIGH);

As above... I think the second argument here needs to be NULL in order to preserve the current DT bindings.

You are correct. I was testing this driver with a custom dtb in rock960 board and named the property as above in the dts. It should be NULL.

Quoted 8 lines

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 278

Quoted 5 lines
drivers/video/backlight/sky81452-backlight.c +4 -0
+	if (IS_ERR(pdata->gpiod_enable)) {
+		long ret = PTR_ERR(pdata->gpiod_enable);
+
+		/**

Nitpicking... but no second star here. That's a trigger symbold for documentation processors.

That is a great feedback. I will keep that in mind.

Quoted 6 lines

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 280

Quoted 3 lines
drivers/video/backlight/sky81452-backlight.c +2 -0
+		 * gpiod_enable is optional in device tree.
+		 * Return error only if gpio was assigned in device tree

Also nitpicking but I had to read this a few times because gpiod_enable is not in device tree, gpios is.

You are correct. I will make necessary changes.

Quoted 5 lines

This is a common pattern so the comment can be very short. Something like:

This DT property is optional so no need to propagate ENOENT

Noted.

Quoted 27 lines
Quoted 27 lines
drivers/video/backlight/sky81452-backlight.c +5 -2
+		 */
+		if (ret != -ENOENT) {
+			dev_err(dev, "failed to request GPIO. err=%ld\n", ret);
+			return PTR_ERR(pdata->gpiod_enable);
 		}
 	}
 
@@ -323,8 +324,7 @@ static int sky81452_bl_remove(struct platform_device *pdev)
 	bd->props.brightness = 0;
 	backlight_update_status(bd);
 
-	if (gpio_is_valid(pdata->gpio_enable))
-		gpio_set_value_cansleep(pdata->gpio_enable, 0);
+	gpiod_set_value_cansleep(pdata->gpiod_enable, 0);
 
 	return 0;
 }
include/linux/platform_data/sky81452-backlight.h +0 -0
index 1231e9b..dc4cb85 100644
@@ -20,6 +20,8 @@
 #ifndef _SKY81452_BACKLIGHT_H
 #define _SKY81452_BACKLIGHT_H
 
Quoted 5 lines

include/linux/platform_data/sky81452-backlight.h line 24

Quoted 2 lines
include/linux/platform_data/sky81452-backlight.h +2 -0
+#include <linux/gpio/consumer.h>
+

This heaer file should be included from the C file... it is not required to parse the header.

I appreciate the feedback. I will keep that in mind to avoid future errors.

Quoted 20 lines

Daniel.

Quoted 15 lines
include/linux/platform_data/sky81452-backlight.h +1 -1
 /**
  * struct sky81452_platform_data
  * @name:	backlight driver name.
@@ -34,7 +36,7 @@
  */
 struct sky81452_bl_platform_data {
 	const char *name;
-	int gpio_enable;
+	struct gpio_desc *gpiod_enable;
 	unsigned int enable;
 	bool ignore_pwm;
 	bool dpwm_mode;
Signature · 1 line
2.7.4
#3 lore raw
Quoted 24 lines · Shobhit Kukreti
Quoted 3 lines · Daniel Thompson

Hi Shobhit

Thanks for the patch. Feedback below...

Hi Daneil,

You provided some valuable feedback. Thank you for your time and effort.

Quoted 9 lines · Shobhit Kukreti
Quoted 3 lines

Port the sky81452-backlight driver to adhere to new gpio descriptor based APIs. Modified the file sky81452-backlight.c and sky81452-backlight.h. The gpio descriptor property in device tree should be "sky81452-en-gpios"

That is contradicted by the device tree bindings. The property should remain "gpios" as it was before this conversion.

You are correct.

Quoted 4 lines
Quoted 4 lines

Removed unnecessary header files "linux/gpio.h" and "linux/of_gpio.h".

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What level of testing have you done? Is this a fix for hardware you own or a cleanup after searching the sources?

I did not the test on actual hardware. I was trying to do a clean up and boot on QEMU/rock960 board. I will drop the patch until I can find the sk81452 hardware to test it.

Blind bug fixes are not prohibited by any means. However a clean up without no (intentional) functional changes will certainly attract much closer review and might also need more care when constructing a Cc: list for the patch (e.g. to include the original author for their review or testing, etc).

Daniel.

Quoted 116 lines
Quoted 39 lines
Quoted 39 lines
  

---
 drivers/video/backlight/sky81452-backlight.c     | 24 ++++++++++++------------
 include/linux/platform_data/sky81452-backlight.h |  4 +++-
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/video/backlight/sky81452-backlight.c +0 -6
index d414c7a..12ef628 100644
@@ -19,12 +19,10 @@
 
 #include <linux/backlight.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/platform_data/sky81452-backlight.h>
@@ -193,7 +191,6 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	pdata->ignore_pwm = of_property_read_bool(np, "skyworks,ignore-pwm");
 	pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode");
 	pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift");
-	pdata->gpio_enable = of_get_gpio(np, 0);
 
 	ret = of_property_count_u32_elems(np, "led-sources");
 	if (ret < 0) {
@@ -274,13 +271,17 @@ static int sky81452_bl_probe(struct platform_device *pdev)
 		if (IS_ERR(pdata))
 			return PTR_ERR(pdata);
 	}
-
-	if (gpio_is_valid(pdata->gpio_enable)) {
-		ret = devm_gpio_request_one(dev, pdata->gpio_enable,
Quoted 8 lines

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 274

Quoted 5 lines
drivers/video/backlight/sky81452-backlight.c +1 -4
-					GPIOF_OUT_INIT_HIGH, "sky81452-en");
-		if (ret < 0) {
-			dev_err(dev, "failed to request GPIO. err=%d\n", ret);
-			return ret;
+	pdata->gpiod_enable = devm_gpiod_get(dev, "sk81452-en", GPIOD_OUT_HIGH);

As above... I think the second argument here needs to be NULL in order to preserve the current DT bindings.

You are correct. I was testing this driver with a custom dtb in rock960 board and named the property as above in the dts. It should be NULL.

Quoted 8 lines

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 278

Quoted 5 lines
drivers/video/backlight/sky81452-backlight.c +4 -0
+	if (IS_ERR(pdata->gpiod_enable)) {
+		long ret = PTR_ERR(pdata->gpiod_enable);
+
+		/**

Nitpicking... but no second star here. That's a trigger symbold for documentation processors.

That is a great feedback. I will keep that in mind.

Quoted 6 lines

drivers/video/backlight/sky81452-backlight.c static int sky81452_bl_probe(struct platform_device *pdev) · line 280

Quoted 3 lines
drivers/video/backlight/sky81452-backlight.c +2 -0
+		 * gpiod_enable is optional in device tree.
+		 * Return error only if gpio was assigned in device tree

Also nitpicking but I had to read this a few times because gpiod_enable is not in device tree, gpios is.

You are correct. I will make necessary changes.

Quoted 5 lines

This is a common pattern so the comment can be very short. Something like:

This DT property is optional so no need to propagate ENOENT

Noted.

Quoted 27 lines
Quoted 27 lines
drivers/video/backlight/sky81452-backlight.c +5 -2
+		 */
+		if (ret != -ENOENT) {
+			dev_err(dev, "failed to request GPIO. err=%ld\n", ret);
+			return PTR_ERR(pdata->gpiod_enable);
 		}
 	}
 
@@ -323,8 +324,7 @@ static int sky81452_bl_remove(struct platform_device *pdev)
 	bd->props.brightness = 0;
 	backlight_update_status(bd);
 
-	if (gpio_is_valid(pdata->gpio_enable))
-		gpio_set_value_cansleep(pdata->gpio_enable, 0);
+	gpiod_set_value_cansleep(pdata->gpiod_enable, 0);
 
 	return 0;
 }
include/linux/platform_data/sky81452-backlight.h +0 -0
index 1231e9b..dc4cb85 100644
@@ -20,6 +20,8 @@
 #ifndef _SKY81452_BACKLIGHT_H
 #define _SKY81452_BACKLIGHT_H
 
Quoted 5 lines

include/linux/platform_data/sky81452-backlight.h line 24

Quoted 2 lines
include/linux/platform_data/sky81452-backlight.h +2 -0
+#include <linux/gpio/consumer.h>
+

This heaer file should be included from the C file... it is not required to parse the header.

I appreciate the feedback. I will keep that in mind to avoid future errors.

Quoted 5 lines

Daniel.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
include/linux/platform_data/sky81452-backlight.h +0 -0
 /**
  * struct sky81452_platform_data
  * @name:	backlight driver name.
@@ -34,7 +36,7 @@
  */
 struct sky81452_bl_platform_data {
 	const char *name;
Quoted 8 lines
Quoted 8 lines
include/linux/platform_data/sky81452-backlight.h +1 -1
-	int gpio_enable;
+	struct gpio_desc *gpiod_enable;
 	unsigned int enable;
 	bool ignore_pwm;
 	bool dpwm_mode;
Signature · 1 line
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel