aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video
diff options
context:
space:
mode:
authorDenis Carikli <denis@eukrea.com>2014-02-27 09:28:33 -0500
committerLee Jones <lee.jones@linaro.org>2014-04-08 08:20:40 -0400
commit9a6adb339e5d1827da5e8b2459b12863d72ed3e7 (patch)
treeb7b2e59f74713375f20b397c5f68eecba997586a /drivers/video
parent35762a47c0a24072a689cbd98ecf8c62b037ef8a (diff)
backlight: gpio-backlight: Add DT support
Signed-off-by: Denis Carikli <denis@eukrea.com> Acked-by: Jingoo Han <jg1.han@samsung.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/backlight/gpio_backlight.c58
1 files changed, 51 insertions, 7 deletions
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};