aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-11 17:06:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-11 17:06:55 -0400
commit7f33e7241d3dbad3c0563fd1fc79fc9380b5c351 (patch)
tree4f0f72e0954e9a5a60679780a4cdf0bf243d47e1 /drivers/video
parent2dc24b0d0636349d403ae803bbad0c84f6c2ea57 (diff)
parent39fd3f99aba3f7683fc9b62e916e4c886a1cb6b0 (diff)
Merge tag 'pwm/for-3.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm changes from Thierry Reding: "The majority of these changes are cleanups and fixes across all drivers. Redundant error messages are removed and more PWM controllers set the .can_sleep flag to signal that they can't be used in atomic context. Support is added for the Broadcom Kona family of SoCs and the Intel LPSS driver can now probe PCI devices in addition to ACPI devices. Upon shutdown, the pwm-backlight driver will now power off the backlight. It also uses the new descriptor-based GPIO API for more concise GPIO handling. A large chunk of these changes also converts platforms to use the lookup mechanism rather than relying on the global number space to reference PWM devices. This is largely in preparation for more unification and cleanups in future patches. Eventually it will allow the legacy PWM API to be removed" * tag 'pwm/for-3.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (38 commits) pwm: fsl-ftm: set pwm_chip can_sleep flag pwm: ab8500: Fix wrong value shift for disable/enable PWM pwm: samsung: do not set manual update bit in pwm_samsung_config pwm: lp3943: Set pwm_chip can_sleep flag pwm: atmel: set pwm_chip can_sleep flag pwm: mxs: set pwm_chip can_sleep flag pwm: tiehrpwm: inline accessor functions pwm: tiehrpwm: don't build PM related functions when not needed pwm-backlight: retrieve configured PWM period leds: leds-pwm: retrieve configured PWM period ARM: pxa: hx4700: use PWM_LOOKUP to initialize struct pwm_lookup ARM: shmobile: armadillo: use PWM_LOOKUP to initialize struct pwm_lookup ARM: OMAP3: Beagle: use PWM_LOOKUP to initialize struct pwm_lookup pwm: modify PWM_LOOKUP to initialize all struct pwm_lookup members ARM: pxa: hx4700: initialize all the struct pwm_lookup members ARM: OMAP3: Beagle: initialize all the struct pwm_lookup members pwm: renesas-tpu: remove unused struct tpu_pwm_platform_data ARM: shmobile: armadillo: initialize all struct pwm_lookup members pwm: add period and polarity to struct pwm_lookup pwm: twl: Really disable twl6030 PWMs ...
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/backlight/pwm_bl.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index b75201ff46f6..38ca88bc5c3e 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
@@ -304,12 +296,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
304 /* 296 /*
305 * The DT case will set the pwm_period_ns field to 0 and store the 297 * The DT case will set the pwm_period_ns field to 0 and store the
306 * period, parsed from the DT, in the PWM device. For the non-DT case, 298 * period, parsed from the DT, in the PWM device. For the non-DT case,
307 * set the period from platform data. 299 * set the period from platform data if it has not already been set
300 * via the PWM lookup table.
308 */ 301 */
309 if (data->pwm_period_ns > 0) 302 pb->period = pwm_get_period(pb->pwm);
303 if (!pb->period && (data->pwm_period_ns > 0)) {
304 pb->period = data->pwm_period_ns;
310 pwm_set_period(pb->pwm, data->pwm_period_ns); 305 pwm_set_period(pb->pwm, data->pwm_period_ns);
306 }
311 307
312 pb->period = pwm_get_period(pb->pwm);
313 pb->lth_brightness = data->lth_brightness * (pb->period / pb->scale); 308 pb->lth_brightness = data->lth_brightness * (pb->period / pb->scale);
314 309
315 memset(&props, 0, sizeof(struct backlight_properties)); 310 memset(&props, 0, sizeof(struct backlight_properties));
@@ -320,7 +315,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
320 if (IS_ERR(bl)) { 315 if (IS_ERR(bl)) {
321 dev_err(&pdev->dev, "failed to register backlight\n"); 316 dev_err(&pdev->dev, "failed to register backlight\n");
322 ret = PTR_ERR(bl); 317 ret = PTR_ERR(bl);
323 goto err_gpio; 318 goto err_alloc;
324 } 319 }
325 320
326 if (data->dft_brightness > data->max_brightness) { 321 if (data->dft_brightness > data->max_brightness) {
@@ -336,9 +331,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
336 platform_set_drvdata(pdev, bl); 331 platform_set_drvdata(pdev, bl);
337 return 0; 332 return 0;
338 333
339err_gpio:
340 if (gpio_is_valid(pb->enable_gpio))
341 gpio_free(pb->enable_gpio);
342err_alloc: 334err_alloc:
343 if (data->exit) 335 if (data->exit)
344 data->exit(&pdev->dev); 336 data->exit(&pdev->dev);
@@ -359,6 +351,14 @@ static int pwm_backlight_remove(struct platform_device *pdev)
359 return 0; 351 return 0;
360} 352}
361 353
354static void pwm_backlight_shutdown(struct platform_device *pdev)
355{
356 struct backlight_device *bl = platform_get_drvdata(pdev);
357 struct pwm_bl_data *pb = bl_get_data(bl);
358
359 pwm_backlight_power_off(pb);
360}
361
362#ifdef CONFIG_PM_SLEEP 362#ifdef CONFIG_PM_SLEEP
363static int pwm_backlight_suspend(struct device *dev) 363static int pwm_backlight_suspend(struct device *dev)
364{ 364{
@@ -404,6 +404,7 @@ static struct platform_driver pwm_backlight_driver = {
404 }, 404 },
405 .probe = pwm_backlight_probe, 405 .probe = pwm_backlight_probe,
406 .remove = pwm_backlight_remove, 406 .remove = pwm_backlight_remove,
407 .shutdown = pwm_backlight_shutdown,
407}; 408};
408 409
409module_platform_driver(pwm_backlight_driver); 410module_platform_driver(pwm_backlight_driver);