diff options
author | Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> | 2013-07-04 15:13:24 -0400 |
---|---|---|
committer | Simon Horman <horms+renesas@verge.net.au> | 2013-07-16 00:01:05 -0400 |
commit | 8b770e3c9824c98eafe67950ad6e41e09ec9c98a (patch) | |
tree | bc1dc14d2ec6b70cec3091b7c57e522d1bd4d64b | |
parent | ad81f0545ef01ea651886dddac4bef6cec930092 (diff) |
backlight: Add GPIO-based backlight driver
The GPIO backlight driver controls the backlight in on/off mode through
a single GPIO.
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
-rw-r--r-- | drivers/video/backlight/Kconfig | 7 | ||||
-rw-r--r-- | drivers/video/backlight/Makefile | 1 | ||||
-rw-r--r-- | drivers/video/backlight/gpio_backlight.c | 133 | ||||
-rw-r--r-- | include/linux/platform_data/gpio_backlight.h | 21 |
4 files changed, 162 insertions, 0 deletions
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index d5ab6583f440..5ab64237c972 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig | |||
@@ -425,6 +425,13 @@ config BACKLIGHT_AS3711 | |||
425 | If you have an Austrian Microsystems AS3711 say Y to enable the | 425 | If you have an Austrian Microsystems AS3711 say Y to enable the |
426 | backlight driver. | 426 | backlight driver. |
427 | 427 | ||
428 | config BACKLIGHT_GPIO | ||
429 | tristate "Generic GPIO based Backlight Driver" | ||
430 | depends on GPIOLIB | ||
431 | help | ||
432 | If you have a LCD backlight adjustable by GPIO, say Y to enable | ||
433 | this driver. | ||
434 | |||
428 | endif # BACKLIGHT_CLASS_DEVICE | 435 | endif # BACKLIGHT_CLASS_DEVICE |
429 | 436 | ||
430 | endif # BACKLIGHT_LCD_SUPPORT | 437 | endif # BACKLIGHT_LCD_SUPPORT |
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index 92711fe60464..65698a882c2f 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile | |||
@@ -32,6 +32,7 @@ obj-$(CONFIG_BACKLIGHT_DA903X) += da903x_bl.o | |||
32 | obj-$(CONFIG_BACKLIGHT_DA9052) += da9052_bl.o | 32 | obj-$(CONFIG_BACKLIGHT_DA9052) += da9052_bl.o |
33 | obj-$(CONFIG_BACKLIGHT_EP93XX) += ep93xx_bl.o | 33 | obj-$(CONFIG_BACKLIGHT_EP93XX) += ep93xx_bl.o |
34 | obj-$(CONFIG_BACKLIGHT_GENERIC) += generic_bl.o | 34 | obj-$(CONFIG_BACKLIGHT_GENERIC) += generic_bl.o |
35 | obj-$(CONFIG_BACKLIGHT_GPIO) += gpio_backlight.o | ||
35 | obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o | 36 | obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o |
36 | obj-$(CONFIG_BACKLIGHT_HP700) += jornada720_bl.o | 37 | obj-$(CONFIG_BACKLIGHT_HP700) += jornada720_bl.o |
37 | obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o | 38 | obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o |
diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c new file mode 100644 index 000000000000..5fa217f9f445 --- /dev/null +++ b/drivers/video/backlight/gpio_backlight.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * gpio_backlight.c - Simple GPIO-controlled backlight | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #include <linux/backlight.h> | ||
10 | #include <linux/err.h> | ||
11 | #include <linux/fb.h> | ||
12 | #include <linux/gpio.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/platform_data/gpio_backlight.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/slab.h> | ||
19 | |||
20 | struct gpio_backlight { | ||
21 | struct device *dev; | ||
22 | struct device *fbdev; | ||
23 | |||
24 | int gpio; | ||
25 | int active; | ||
26 | }; | ||
27 | |||
28 | static int gpio_backlight_update_status(struct backlight_device *bl) | ||
29 | { | ||
30 | struct gpio_backlight *gbl = bl_get_data(bl); | ||
31 | int brightness = bl->props.brightness; | ||
32 | |||
33 | if (bl->props.power != FB_BLANK_UNBLANK || | ||
34 | bl->props.fb_blank != FB_BLANK_UNBLANK || | ||
35 | bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) | ||
36 | brightness = 0; | ||
37 | |||
38 | gpio_set_value(gbl->gpio, brightness ? gbl->active : !gbl->active); | ||
39 | |||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | static int gpio_backlight_get_brightness(struct backlight_device *bl) | ||
44 | { | ||
45 | return bl->props.brightness; | ||
46 | } | ||
47 | |||
48 | static int gpio_backlight_check_fb(struct backlight_device *bl, | ||
49 | struct fb_info *info) | ||
50 | { | ||
51 | struct gpio_backlight *gbl = bl_get_data(bl); | ||
52 | |||
53 | return gbl->fbdev == NULL || gbl->fbdev == info->dev; | ||
54 | } | ||
55 | |||
56 | static const struct backlight_ops gpio_backlight_ops = { | ||
57 | .options = BL_CORE_SUSPENDRESUME, | ||
58 | .update_status = gpio_backlight_update_status, | ||
59 | .get_brightness = gpio_backlight_get_brightness, | ||
60 | .check_fb = gpio_backlight_check_fb, | ||
61 | }; | ||
62 | |||
63 | static int gpio_backlight_probe(struct platform_device *pdev) | ||
64 | { | ||
65 | struct gpio_backlight_platform_data *pdata = pdev->dev.platform_data; | ||
66 | struct backlight_properties props; | ||
67 | struct backlight_device *bl; | ||
68 | struct gpio_backlight *gbl; | ||
69 | int ret; | ||
70 | |||
71 | if (!pdata) { | ||
72 | dev_err(&pdev->dev, "failed to find platform data\n"); | ||
73 | return -ENODEV; | ||
74 | } | ||
75 | |||
76 | gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL); | ||
77 | if (gbl == NULL) | ||
78 | return -ENOMEM; | ||
79 | |||
80 | gbl->dev = &pdev->dev; | ||
81 | gbl->fbdev = pdata->fbdev; | ||
82 | gbl->gpio = pdata->gpio; | ||
83 | gbl->active = pdata->active_low ? 0 : 1; | ||
84 | |||
85 | ret = devm_gpio_request_one(gbl->dev, gbl->gpio, GPIOF_DIR_OUT | | ||
86 | (gbl->active ? GPIOF_INIT_LOW | ||
87 | : GPIOF_INIT_HIGH), | ||
88 | pdata->name); | ||
89 | if (ret < 0) { | ||
90 | dev_err(&pdev->dev, "unable to request GPIO\n"); | ||
91 | return ret; | ||
92 | } | ||
93 | |||
94 | memset(&props, 0, sizeof(props)); | ||
95 | props.type = BACKLIGHT_RAW; | ||
96 | props.max_brightness = 1; | ||
97 | bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, gbl, | ||
98 | &gpio_backlight_ops, &props); | ||
99 | if (IS_ERR(bl)) { | ||
100 | dev_err(&pdev->dev, "failed to register backlight\n"); | ||
101 | return PTR_ERR(bl); | ||
102 | } | ||
103 | |||
104 | bl->props.brightness = pdata->def_value; | ||
105 | backlight_update_status(bl); | ||
106 | |||
107 | platform_set_drvdata(pdev, bl); | ||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | static int gpio_backlight_remove(struct platform_device *pdev) | ||
112 | { | ||
113 | struct backlight_device *bl = platform_get_drvdata(pdev); | ||
114 | |||
115 | backlight_device_unregister(bl); | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static struct platform_driver gpio_backlight_driver = { | ||
120 | .driver = { | ||
121 | .name = "gpio-backlight", | ||
122 | .owner = THIS_MODULE, | ||
123 | }, | ||
124 | .probe = gpio_backlight_probe, | ||
125 | .remove = gpio_backlight_remove, | ||
126 | }; | ||
127 | |||
128 | module_platform_driver(gpio_backlight_driver); | ||
129 | |||
130 | MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>"); | ||
131 | MODULE_DESCRIPTION("GPIO-based Backlight Driver"); | ||
132 | MODULE_LICENSE("GPL"); | ||
133 | MODULE_ALIAS("platform:gpio-backlight"); | ||
diff --git a/include/linux/platform_data/gpio_backlight.h b/include/linux/platform_data/gpio_backlight.h new file mode 100644 index 000000000000..5ae0d9c80d4d --- /dev/null +++ b/include/linux/platform_data/gpio_backlight.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * gpio_backlight.h - Simple GPIO-controlled backlight | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | #ifndef __GPIO_BACKLIGHT_H__ | ||
9 | #define __GPIO_BACKLIGHT_H__ | ||
10 | |||
11 | struct device; | ||
12 | |||
13 | struct gpio_backlight_platform_data { | ||
14 | struct device *fbdev; | ||
15 | int gpio; | ||
16 | int def_value; | ||
17 | bool active_low; | ||
18 | const char *name; | ||
19 | }; | ||
20 | |||
21 | #endif | ||