aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2017-05-30 07:48:21 -0400
committerLee Jones <lee.jones@linaro.org>2017-08-07 12:04:32 -0400
commitde7389003ab77fc63296b2adee4cd9c48dc41d5a (patch)
tree0c2235b92ed7abbc373994ab0a94bc0f8a0b3f73
parent62cdfe658535c39003d4d1b9d7f9b5a23a0db6bf (diff)
backlight: gpio_backlight: Convert to use GPIO descriptor
This driver is predominantly used by device tree systems, all of which can deal with modern GPIO descriptors. The legacy GPIO API is only used by one SH board so make the GPIO descriptor the default way to deal with it. As an intended side effect we do not need to look around in the device tree for the inversion flag since the GPIO descriptors will intrinsically deal with this. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Daniel Thompson <daniel.thompson@linaro.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
-rw-r--r--drivers/video/backlight/gpio_backlight.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c
index 18134416b154..5ffaff1e4142 100644
--- a/drivers/video/backlight/gpio_backlight.c
+++ b/drivers/video/backlight/gpio_backlight.c
@@ -9,7 +9,8 @@
9#include <linux/backlight.h> 9#include <linux/backlight.h>
10#include <linux/err.h> 10#include <linux/err.h>
11#include <linux/fb.h> 11#include <linux/fb.h>
12#include <linux/gpio.h> 12#include <linux/gpio.h> /* Only for legacy support */
13#include <linux/gpio/consumer.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/module.h> 16#include <linux/module.h>
@@ -23,7 +24,7 @@ struct gpio_backlight {
23 struct device *dev; 24 struct device *dev;
24 struct device *fbdev; 25 struct device *fbdev;
25 26
26 int gpio; 27 struct gpio_desc *gpiod;
27 int active; 28 int active;
28 int def_value; 29 int def_value;
29}; 30};
@@ -38,8 +39,8 @@ static int gpio_backlight_update_status(struct backlight_device *bl)
38 bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) 39 bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
39 brightness = 0; 40 brightness = 0;
40 41
41 gpio_set_value_cansleep(gbl->gpio, 42 gpiod_set_value_cansleep(gbl->gpiod,
42 brightness ? gbl->active : !gbl->active); 43 brightness ? gbl->active : !gbl->active);
43 44
44 return 0; 45 return 0;
45} 46}
@@ -61,23 +62,27 @@ static const struct backlight_ops gpio_backlight_ops = {
61static int gpio_backlight_probe_dt(struct platform_device *pdev, 62static int gpio_backlight_probe_dt(struct platform_device *pdev,
62 struct gpio_backlight *gbl) 63 struct gpio_backlight *gbl)
63{ 64{
64 struct device_node *np = pdev->dev.of_node; 65 struct device *dev = &pdev->dev;
65 enum of_gpio_flags gpio_flags; 66 struct device_node *np = dev->of_node;
67 enum gpiod_flags flags;
68 int ret;
69
70 gbl->def_value = of_property_read_bool(np, "default-on");
71 flags = gbl->def_value ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
72 /* GPIO descriptors keep track of inversion */
73 gbl->active = 1;
66 74
67 gbl->gpio = of_get_gpio_flags(np, 0, &gpio_flags); 75 gbl->gpiod = devm_gpiod_get(dev, NULL, flags);
76 if (IS_ERR(gbl->gpiod)) {
77 ret = PTR_ERR(gbl->gpiod);
68 78
69 if (!gpio_is_valid(gbl->gpio)) { 79 if (ret != -EPROBE_DEFER) {
70 if (gbl->gpio != -EPROBE_DEFER) { 80 dev_err(dev,
71 dev_err(&pdev->dev,
72 "Error: The gpios parameter is missing or invalid.\n"); 81 "Error: The gpios parameter is missing or invalid.\n");
73 } 82 }
74 return gbl->gpio; 83 return ret;
75 } 84 }
76 85
77 gbl->active = (gpio_flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1;
78
79 gbl->def_value = of_property_read_bool(np, "default-on");
80
81 return 0; 86 return 0;
82} 87}
83 88
@@ -89,7 +94,6 @@ static int gpio_backlight_probe(struct platform_device *pdev)
89 struct backlight_device *bl; 94 struct backlight_device *bl;
90 struct gpio_backlight *gbl; 95 struct gpio_backlight *gbl;
91 struct device_node *np = pdev->dev.of_node; 96 struct device_node *np = pdev->dev.of_node;
92 unsigned long flags = GPIOF_DIR_OUT;
93 int ret; 97 int ret;
94 98
95 if (!pdata && !np) { 99 if (!pdata && !np) {
@@ -109,22 +113,33 @@ static int gpio_backlight_probe(struct platform_device *pdev)
109 if (ret) 113 if (ret)
110 return ret; 114 return ret;
111 } else { 115 } else {
116 /*
117 * Legacy platform data GPIO retrieveal. Do not expand
118 * the use of this code path, currently only used by one
119 * SH board.
120 */
121 unsigned long flags = GPIOF_DIR_OUT;
122
112 gbl->fbdev = pdata->fbdev; 123 gbl->fbdev = pdata->fbdev;
113 gbl->gpio = pdata->gpio;
114 gbl->active = pdata->active_low ? 0 : 1; 124 gbl->active = pdata->active_low ? 0 : 1;
115 gbl->def_value = pdata->def_value; 125 gbl->def_value = pdata->def_value;
116 }
117
118 if (gbl->active)
119 flags |= gbl->def_value ? GPIOF_INIT_HIGH : GPIOF_INIT_LOW;
120 else
121 flags |= gbl->def_value ? GPIOF_INIT_LOW : GPIOF_INIT_HIGH;
122 126
123 ret = devm_gpio_request_one(gbl->dev, gbl->gpio, flags, 127 if (gbl->active)
124 pdata ? pdata->name : "backlight"); 128 flags |= gbl->def_value ?
125 if (ret < 0) { 129 GPIOF_INIT_HIGH : GPIOF_INIT_LOW;
126 dev_err(&pdev->dev, "unable to request GPIO\n"); 130 else
127 return ret; 131 flags |= gbl->def_value ?
132 GPIOF_INIT_LOW : GPIOF_INIT_HIGH;
133
134 ret = devm_gpio_request_one(gbl->dev, pdata->gpio, flags,
135 pdata ? pdata->name : "backlight");
136 if (ret < 0) {
137 dev_err(&pdev->dev, "unable to request GPIO\n");
138 return ret;
139 }
140 gbl->gpiod = gpio_to_desc(pdata->gpio);
141 if (!gbl->gpiod)
142 return -EINVAL;
128 } 143 }
129 144
130 memset(&props, 0, sizeof(props)); 145 memset(&props, 0, sizeof(props));