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

From: Shobhit Kukreti
Date: Wed Jun 12 2019 - 00:37:19 EST


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

Signed-off-by: Shobhit Kukreti <shobhitkukreti@xxxxxxxxx>
---
drivers/video/backlight/sky81452-backlight.c | 24 ++++++++++++------------
include/linux/platform_data/sky81452-backlight.h | 4 +++-
2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/video/backlight/sky81452-backlight.c b/drivers/video/backlight/sky81452-backlight.c
index d414c7a..12ef628 100644
--- a/drivers/video/backlight/sky81452-backlight.c
+++ b/drivers/video/backlight/sky81452-backlight.c
@@ -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;
}
diff --git a/include/linux/platform_data/sky81452-backlight.h b/include/linux/platform_data/sky81452-backlight.h
index 1231e9b..dc4cb85 100644
--- a/include/linux/platform_data/sky81452-backlight.h
+++ b/include/linux/platform_data/sky81452-backlight.h
@@ -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;
--
2.7.4