aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2014-02-27 00:53:34 -0500
committerThierry Reding <thierry.reding@gmail.com>2014-05-07 04:15:31 -0400
commit257462dbf3ed233de0dc2e489dcc58579535b33f (patch)
treecd119efc19caf1d3ebc4cbc76693480e3cda7745 /drivers/video
parenta4406f165faa222a0d2c5e660473bb6822850a55 (diff)
pwm-backlight: switch to gpiod interface
Switch to the new gpiod interface, which allows to handle GPIO properties such as active low transparently and removes a whole bunch of code. There are still a couple of users of this driver that rely on passing the enable GPIO number through platform data, so a fallback mechanism using a GPIO number is still available to avoid breaking them. It will be removed once current users have switched to the GPIO lookup tables provided by the gpiod interface. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/backlight/pwm_bl.c69
1 files changed, 29 insertions, 40 deletions
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index fa7f5c35b7fb..cc49347bbcc0 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -10,8 +10,8 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/gpio/consumer.h>
13#include <linux/gpio.h> 14#include <linux/gpio.h>
14#include <linux/of_gpio.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/init.h> 17#include <linux/init.h>
@@ -32,8 +32,7 @@ struct pwm_bl_data {
32 unsigned int *levels; 32 unsigned int *levels;
33 bool enabled; 33 bool enabled;
34 struct regulator *power_supply; 34 struct regulator *power_supply;
35 int enable_gpio; 35 struct gpio_desc *enable_gpio;
36 unsigned long enable_gpio_flags;
37 unsigned int scale; 36 unsigned int scale;
38 int (*notify)(struct device *, 37 int (*notify)(struct device *,
39 int brightness); 38 int brightness);
@@ -54,12 +53,8 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
54 if (err < 0) 53 if (err < 0)
55 dev_err(pb->dev, "failed to enable power supply\n"); 54 dev_err(pb->dev, "failed to enable power supply\n");
56 55
57 if (gpio_is_valid(pb->enable_gpio)) { 56 if (pb->enable_gpio)
58 if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) 57 gpiod_set_value(pb->enable_gpio, 1);
59 gpio_set_value(pb->enable_gpio, 0);
60 else
61 gpio_set_value(pb->enable_gpio, 1);
62 }
63 58
64 pwm_enable(pb->pwm); 59 pwm_enable(pb->pwm);
65 pb->enabled = true; 60 pb->enabled = true;
@@ -73,12 +68,8 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb)
73 pwm_config(pb->pwm, 0, pb->period); 68 pwm_config(pb->pwm, 0, pb->period);
74 pwm_disable(pb->pwm); 69 pwm_disable(pb->pwm);
75 70
76 if (gpio_is_valid(pb->enable_gpio)) { 71 if (pb->enable_gpio)
77 if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) 72 gpiod_set_value(pb->enable_gpio, 0);
78 gpio_set_value(pb->enable_gpio, 1);
79 else
80 gpio_set_value(pb->enable_gpio, 0);
81 }
82 73
83 regulator_disable(pb->power_supply); 74 regulator_disable(pb->power_supply);
84 pb->enabled = false; 75 pb->enabled = false;
@@ -148,7 +139,6 @@ static int pwm_backlight_parse_dt(struct device *dev,
148 struct platform_pwm_backlight_data *data) 139 struct platform_pwm_backlight_data *data)
149{ 140{
150 struct device_node *node = dev->of_node; 141 struct device_node *node = dev->of_node;
151 enum of_gpio_flags flags;
152 struct property *prop; 142 struct property *prop;
153 int length; 143 int length;
154 u32 value; 144 u32 value;
@@ -189,14 +179,6 @@ static int pwm_backlight_parse_dt(struct device *dev,
189 data->max_brightness--; 179 data->max_brightness--;
190 } 180 }
191 181
192 data->enable_gpio = of_get_named_gpio_flags(node, "enable-gpios", 0,
193 &flags);
194 if (data->enable_gpio == -EPROBE_DEFER)
195 return -EPROBE_DEFER;
196
197 if (gpio_is_valid(data->enable_gpio) && (flags & OF_GPIO_ACTIVE_LOW))
198 data->enable_gpio_flags |= PWM_BACKLIGHT_GPIO_ACTIVE_LOW;
199
200 return 0; 182 return 0;
201} 183}
202 184
@@ -256,8 +238,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
256 } else 238 } else
257 pb->scale = data->max_brightness; 239 pb->scale = data->max_brightness;
258 240
259 pb->enable_gpio = data->enable_gpio;
260 pb->enable_gpio_flags = data->enable_gpio_flags;
261 pb->notify = data->notify; 241 pb->notify = data->notify;
262 pb->notify_after = data->notify_after; 242 pb->notify_after = data->notify_after;
263 pb->check_fb = data->check_fb; 243 pb->check_fb = data->check_fb;
@@ -265,26 +245,38 @@ static int pwm_backlight_probe(struct platform_device *pdev)
265 pb->dev = &pdev->dev; 245 pb->dev = &pdev->dev;
266 pb->enabled = false; 246 pb->enabled = false;
267 247
268 if (gpio_is_valid(pb->enable_gpio)) { 248 pb->enable_gpio = devm_gpiod_get(&pdev->dev, "enable");
269 unsigned long flags; 249 if (IS_ERR(pb->enable_gpio)) {
270 250 ret = PTR_ERR(pb->enable_gpio);
271 if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) 251 if (ret == -ENOENT)
272 flags = GPIOF_OUT_INIT_HIGH; 252 pb->enable_gpio = NULL;
273 else 253 else
274 flags = GPIOF_OUT_INIT_LOW; 254 goto err_alloc;
255 }
275 256
276 ret = gpio_request_one(pb->enable_gpio, flags, "enable"); 257 /*
258 * Compatibility fallback for drivers still using the integer GPIO
259 * platform data. Must go away soon.
260 */
261 if (!pb->enable_gpio && gpio_is_valid(data->enable_gpio)) {
262 ret = devm_gpio_request_one(&pdev->dev, data->enable_gpio,
263 GPIOF_OUT_INIT_HIGH, "enable");
277 if (ret < 0) { 264 if (ret < 0) {
278 dev_err(&pdev->dev, "failed to request GPIO#%d: %d\n", 265 dev_err(&pdev->dev, "failed to request GPIO#%d: %d\n",
279 pb->enable_gpio, ret); 266 data->enable_gpio, ret);
280 goto err_alloc; 267 goto err_alloc;
281 } 268 }
269
270 pb->enable_gpio = gpio_to_desc(data->enable_gpio);
282 } 271 }
283 272
273 if (pb->enable_gpio)
274 gpiod_direction_output(pb->enable_gpio, 1);
275
284 pb->power_supply = devm_regulator_get(&pdev->dev, "power"); 276 pb->power_supply = devm_regulator_get(&pdev->dev, "power");
285 if (IS_ERR(pb->power_supply)) { 277 if (IS_ERR(pb->power_supply)) {
286 ret = PTR_ERR(pb->power_supply); 278 ret = PTR_ERR(pb->power_supply);
287 goto err_gpio; 279 goto err_alloc;
288 } 280 }
289 281
290 pb->pwm = devm_pwm_get(&pdev->dev, NULL); 282 pb->pwm = devm_pwm_get(&pdev->dev, NULL);
@@ -295,7 +287,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
295 if (IS_ERR(pb->pwm)) { 287 if (IS_ERR(pb->pwm)) {
296 dev_err(&pdev->dev, "unable to request legacy PWM\n"); 288 dev_err(&pdev->dev, "unable to request legacy PWM\n");
297 ret = PTR_ERR(pb->pwm); 289 ret = PTR_ERR(pb->pwm);
298 goto err_gpio; 290 goto err_alloc;
299 } 291 }
300 } 292 }
301 293
@@ -320,7 +312,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
320 if (IS_ERR(bl)) { 312 if (IS_ERR(bl)) {
321 dev_err(&pdev->dev, "failed to register backlight\n"); 313 dev_err(&pdev->dev, "failed to register backlight\n");
322 ret = PTR_ERR(bl); 314 ret = PTR_ERR(bl);
323 goto err_gpio; 315 goto err_alloc;
324 } 316 }
325 317
326 if (data->dft_brightness > data->max_brightness) { 318 if (data->dft_brightness > data->max_brightness) {
@@ -336,9 +328,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
336 platform_set_drvdata(pdev, bl); 328 platform_set_drvdata(pdev, bl);
337 return 0; 329 return 0;
338 330
339err_gpio:
340 if (gpio_is_valid(pb->enable_gpio))
341 gpio_free(pb->enable_gpio);
342err_alloc: 331err_alloc:
343 if (data->exit) 332 if (data->exit)
344 data->exit(&pdev->dev); 333 data->exit(&pdev->dev);