aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-04-10 11:52:35 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-10 11:52:35 -0400
commitedf2377c4776ce20ae990f27f0248e88a37e25c4 (patch)
tree2072ff0353aac87a46fdd0e79fb6a3e666720ee0
parent39de65aa2c3eee901db020a4f1396998e09602a3 (diff)
parentf1740e4cffede3e919a3511bf4e5113d642f09ec (diff)
Merge tag 'backlight-for-linus-3.15' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight
Pull backlight changes from Lee Jones: - core: call put_device() instead of kfree() - gpio-backlight: add DT support - lm3639_bl driver: use managed resources * tag 'backlight-for-linus-3.15' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight: backlight: lm3639: Use devm_backlight_device_register() backlight: gpio-backlight: Add DT support backlight: core: Replace kfree with put_device
-rw-r--r--Documentation/devicetree/bindings/video/backlight/gpio-backlight.txt16
-rw-r--r--drivers/video/backlight/backlight.c2
-rw-r--r--drivers/video/backlight/gpio_backlight.c58
-rw-r--r--drivers/video/backlight/lm3639_bl.c17
4 files changed, 75 insertions, 18 deletions
diff --git a/Documentation/devicetree/bindings/video/backlight/gpio-backlight.txt b/Documentation/devicetree/bindings/video/backlight/gpio-backlight.txt
new file mode 100644
index 000000000000..321be6640533
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/backlight/gpio-backlight.txt
@@ -0,0 +1,16 @@
1gpio-backlight bindings
2
3Required properties:
4 - compatible: "gpio-backlight"
5 - gpios: describes the gpio that is used for enabling/disabling the backlight.
6 refer to bindings/gpio/gpio.txt for more details.
7
8Optional properties:
9 - default-on: enable the backlight at boot.
10
11Example:
12 backlight {
13 compatible = "gpio-backlight";
14 gpios = <&gpio3 4 GPIO_ACTIVE_HIGH>;
15 default-on;
16 };
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 27d3cf255e78..bd2172c2d650 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -347,7 +347,7 @@ struct backlight_device *backlight_device_register(const char *name,
347 347
348 rc = device_register(&new_bd->dev); 348 rc = device_register(&new_bd->dev);
349 if (rc) { 349 if (rc) {
350 kfree(new_bd); 350 put_device(&new_bd->dev);
351 return ERR_PTR(rc); 351 return ERR_PTR(rc);
352 } 352 }
353 353
diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c
index 81fb12770c2a..a2eba12e1cb7 100644
--- a/drivers/video/backlight/gpio_backlight.c
+++ b/drivers/video/backlight/gpio_backlight.c
@@ -13,6 +13,8 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/of.h>
17#include <linux/of_gpio.h>
16#include <linux/platform_data/gpio_backlight.h> 18#include <linux/platform_data/gpio_backlight.h>
17#include <linux/platform_device.h> 19#include <linux/platform_device.h>
18#include <linux/slab.h> 20#include <linux/slab.h>
@@ -23,6 +25,7 @@ struct gpio_backlight {
23 25
24 int gpio; 26 int gpio;
25 int active; 27 int active;
28 int def_value;
26}; 29};
27 30
28static int gpio_backlight_update_status(struct backlight_device *bl) 31static int gpio_backlight_update_status(struct backlight_device *bl)
@@ -60,6 +63,29 @@ static const struct backlight_ops gpio_backlight_ops = {
60 .check_fb = gpio_backlight_check_fb, 63 .check_fb = gpio_backlight_check_fb,
61}; 64};
62 65
66static int gpio_backlight_probe_dt(struct platform_device *pdev,
67 struct gpio_backlight *gbl)
68{
69 struct device_node *np = pdev->dev.of_node;
70 enum of_gpio_flags gpio_flags;
71
72 gbl->gpio = of_get_gpio_flags(np, 0, &gpio_flags);
73
74 if (!gpio_is_valid(gbl->gpio)) {
75 if (gbl->gpio != -EPROBE_DEFER) {
76 dev_err(&pdev->dev,
77 "Error: The gpios parameter is missing or invalid.\n");
78 }
79 return gbl->gpio;
80 }
81
82 gbl->active = (gpio_flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1;
83
84 gbl->def_value = of_property_read_bool(np, "default-on");
85
86 return 0;
87}
88
63static int gpio_backlight_probe(struct platform_device *pdev) 89static int gpio_backlight_probe(struct platform_device *pdev)
64{ 90{
65 struct gpio_backlight_platform_data *pdata = 91 struct gpio_backlight_platform_data *pdata =
@@ -67,10 +93,12 @@ static int gpio_backlight_probe(struct platform_device *pdev)
67 struct backlight_properties props; 93 struct backlight_properties props;
68 struct backlight_device *bl; 94 struct backlight_device *bl;
69 struct gpio_backlight *gbl; 95 struct gpio_backlight *gbl;
96 struct device_node *np = pdev->dev.of_node;
70 int ret; 97 int ret;
71 98
72 if (!pdata) { 99 if (!pdata && !np) {
73 dev_err(&pdev->dev, "failed to find platform data\n"); 100 dev_err(&pdev->dev,
101 "failed to find platform data or device tree node.\n");
74 return -ENODEV; 102 return -ENODEV;
75 } 103 }
76 104
@@ -79,14 +107,22 @@ static int gpio_backlight_probe(struct platform_device *pdev)
79 return -ENOMEM; 107 return -ENOMEM;
80 108
81 gbl->dev = &pdev->dev; 109 gbl->dev = &pdev->dev;
82 gbl->fbdev = pdata->fbdev; 110
83 gbl->gpio = pdata->gpio; 111 if (np) {
84 gbl->active = pdata->active_low ? 0 : 1; 112 ret = gpio_backlight_probe_dt(pdev, gbl);
113 if (ret)
114 return ret;
115 } else {
116 gbl->fbdev = pdata->fbdev;
117 gbl->gpio = pdata->gpio;
118 gbl->active = pdata->active_low ? 0 : 1;
119 gbl->def_value = pdata->def_value;
120 }
85 121
86 ret = devm_gpio_request_one(gbl->dev, gbl->gpio, GPIOF_DIR_OUT | 122 ret = devm_gpio_request_one(gbl->dev, gbl->gpio, GPIOF_DIR_OUT |
87 (gbl->active ? GPIOF_INIT_LOW 123 (gbl->active ? GPIOF_INIT_LOW
88 : GPIOF_INIT_HIGH), 124 : GPIOF_INIT_HIGH),
89 pdata->name); 125 pdata ? pdata->name : "backlight");
90 if (ret < 0) { 126 if (ret < 0) {
91 dev_err(&pdev->dev, "unable to request GPIO\n"); 127 dev_err(&pdev->dev, "unable to request GPIO\n");
92 return ret; 128 return ret;
@@ -103,17 +139,25 @@ static int gpio_backlight_probe(struct platform_device *pdev)
103 return PTR_ERR(bl); 139 return PTR_ERR(bl);
104 } 140 }
105 141
106 bl->props.brightness = pdata->def_value; 142 bl->props.brightness = gbl->def_value;
107 backlight_update_status(bl); 143 backlight_update_status(bl);
108 144
109 platform_set_drvdata(pdev, bl); 145 platform_set_drvdata(pdev, bl);
110 return 0; 146 return 0;
111} 147}
112 148
149#ifdef CONFIG_OF
150static struct of_device_id gpio_backlight_of_match[] = {
151 { .compatible = "gpio-backlight" },
152 { /* sentinel */ }
153};
154#endif
155
113static struct platform_driver gpio_backlight_driver = { 156static struct platform_driver gpio_backlight_driver = {
114 .driver = { 157 .driver = {
115 .name = "gpio-backlight", 158 .name = "gpio-backlight",
116 .owner = THIS_MODULE, 159 .owner = THIS_MODULE,
160 .of_match_table = of_match_ptr(gpio_backlight_of_match),
117 }, 161 },
118 .probe = gpio_backlight_probe, 162 .probe = gpio_backlight_probe,
119}; 163};
diff --git a/drivers/video/backlight/lm3639_bl.c b/drivers/video/backlight/lm3639_bl.c
index 6fd60adf922e..5f36808d214f 100644
--- a/drivers/video/backlight/lm3639_bl.c
+++ b/drivers/video/backlight/lm3639_bl.c
@@ -349,8 +349,9 @@ static int lm3639_probe(struct i2c_client *client,
349 props.brightness = pdata->init_brt_led; 349 props.brightness = pdata->init_brt_led;
350 props.max_brightness = pdata->max_brt_led; 350 props.max_brightness = pdata->max_brt_led;
351 pchip->bled = 351 pchip->bled =
352 backlight_device_register("lm3639_bled", pchip->dev, pchip, 352 devm_backlight_device_register(pchip->dev, "lm3639_bled",
353 &lm3639_bled_ops, &props); 353 pchip->dev, pchip, &lm3639_bled_ops,
354 &props);
354 if (IS_ERR(pchip->bled)) { 355 if (IS_ERR(pchip->bled)) {
355 dev_err(&client->dev, "fail : backlight register\n"); 356 dev_err(&client->dev, "fail : backlight register\n");
356 ret = PTR_ERR(pchip->bled); 357 ret = PTR_ERR(pchip->bled);
@@ -360,7 +361,7 @@ static int lm3639_probe(struct i2c_client *client,
360 ret = device_create_file(&(pchip->bled->dev), &dev_attr_bled_mode); 361 ret = device_create_file(&(pchip->bled->dev), &dev_attr_bled_mode);
361 if (ret < 0) { 362 if (ret < 0) {
362 dev_err(&client->dev, "failed : add sysfs entries\n"); 363 dev_err(&client->dev, "failed : add sysfs entries\n");
363 goto err_bled_mode; 364 goto err_out;
364 } 365 }
365 366
366 /* flash */ 367 /* flash */
@@ -391,8 +392,6 @@ err_torch:
391 led_classdev_unregister(&pchip->cdev_flash); 392 led_classdev_unregister(&pchip->cdev_flash);
392err_flash: 393err_flash:
393 device_remove_file(&(pchip->bled->dev), &dev_attr_bled_mode); 394 device_remove_file(&(pchip->bled->dev), &dev_attr_bled_mode);
394err_bled_mode:
395 backlight_device_unregister(pchip->bled);
396err_out: 395err_out:
397 return ret; 396 return ret;
398} 397}
@@ -407,10 +406,8 @@ static int lm3639_remove(struct i2c_client *client)
407 led_classdev_unregister(&pchip->cdev_torch); 406 led_classdev_unregister(&pchip->cdev_torch);
408 if (&pchip->cdev_flash) 407 if (&pchip->cdev_flash)
409 led_classdev_unregister(&pchip->cdev_flash); 408 led_classdev_unregister(&pchip->cdev_flash);
410 if (pchip->bled) { 409 if (pchip->bled)
411 device_remove_file(&(pchip->bled->dev), &dev_attr_bled_mode); 410 device_remove_file(&(pchip->bled->dev), &dev_attr_bled_mode);
412 backlight_device_unregister(pchip->bled);
413 }
414 return 0; 411 return 0;
415} 412}
416 413
@@ -432,6 +429,6 @@ static struct i2c_driver lm3639_i2c_driver = {
432module_i2c_driver(lm3639_i2c_driver); 429module_i2c_driver(lm3639_i2c_driver);
433 430
434MODULE_DESCRIPTION("Texas Instruments Backlight+Flash LED driver for LM3639"); 431MODULE_DESCRIPTION("Texas Instruments Backlight+Flash LED driver for LM3639");
435MODULE_AUTHOR("Daniel Jeong <daniel.jeong@ti.com>"); 432MODULE_AUTHOR("Daniel Jeong <gshark.jeong@gmail.com>");
436MODULE_AUTHOR("G.Shark Jeong <gshark.jeong@gmail.com>"); 433MODULE_AUTHOR("Ldd Mlp <ldd-mlp@list.ti.com>");
437MODULE_LICENSE("GPL v2"); 434MODULE_LICENSE("GPL v2");