[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-mainline-3.2 / beagle / 0012-backlight-Add-TLC59108-backlight-control-driver.patch
1 From 9f4af290c74b77e16555858a338feb467a8eedb0 Mon Sep 17 00:00:00 2001
2 From: "Manjunathappa, Prakash" <prakash.pm@ti.com>
3 Date: Mon, 1 Aug 2011 18:25:11 +0530
4 Subject: [PATCH 12/13] backlight: Add TLC59108 backlight control driver
6 This patch adds support for I2C configurable TLC59108 backlight
7 control driver.
9 Signed-off-by: Manjunathappa, Prakash <prakash.pm@ti.com>
10 Signed-off-by: Vaibhav Hiremath <hvaibhav@ti.com>
11 ---
12 drivers/video/backlight/Kconfig | 8 ++
13 drivers/video/backlight/Makefile | 1 +
14 drivers/video/backlight/tlc59108.c | 160 ++++++++++++++++++++++++++++++++++++
15 3 files changed, 169 insertions(+), 0 deletions(-)
16 create mode 100755 drivers/video/backlight/tlc59108.c
18 diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
19 index 278aeaa..df9dac7 100644
20 --- a/drivers/video/backlight/Kconfig
21 +++ b/drivers/video/backlight/Kconfig
22 @@ -342,6 +342,14 @@ config BACKLIGHT_AAT2870
23 If you have a AnalogicTech AAT2870 say Y to enable the
24 backlight driver.
26 +config BACKLIGHT_TLC59108
27 + tristate "TLC59108 LCD Backlight Driver"
28 + depends on I2C && BACKLIGHT_CLASS_DEVICE
29 + default n
30 + help
31 + If you have an LCD Panel with backlight control via TLC59108,
32 + say Y to enable its LCD control driver.
33 +
34 endif # BACKLIGHT_CLASS_DEVICE
36 endif # BACKLIGHT_LCD_SUPPORT
37 diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
38 index fdd1fc4..ba31474 100644
39 --- a/drivers/video/backlight/Makefile
40 +++ b/drivers/video/backlight/Makefile
41 @@ -39,4 +39,5 @@ obj-$(CONFIG_BACKLIGHT_ADP8870) += adp8870_bl.o
42 obj-$(CONFIG_BACKLIGHT_88PM860X) += 88pm860x_bl.o
43 obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o
44 obj-$(CONFIG_BACKLIGHT_AAT2870) += aat2870_bl.o
45 +obj-$(CONFIG_BACKLIGHT_TLC59108) += tlc59108.o
47 diff --git a/drivers/video/backlight/tlc59108.c b/drivers/video/backlight/tlc59108.c
48 new file mode 100755
49 index 0000000..4f4ea34
50 --- /dev/null
51 +++ b/drivers/video/backlight/tlc59108.c
52 @@ -0,0 +1,160 @@
53 +/*
54 + * ti81xxhdmi_tlc59108.c
55 + *
56 + * Copyright (C) 2011 Texas Instruments
57 + * Author: Senthil Natarajan
58 + *
59 + * tlc59108 HDMI Driver
60 + *
61 + * This program is free software; you can redistribute it and/or modify it
62 + * under the terms of the GNU General Public License version 2 as published by
63 + * the Free Software Foundation.
64 + *
65 + * This program is distributed in the hope that it will be useful, but WITHOUT
66 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
68 + * more details.
69 + *
70 + * You should have received a copy of the GNU General Public License along with
71 + * this program. If not, see <http://www.gnu.org/licenses/>.
72 + * History:
73 + *
74 + * Senthil Natarajan<senthil.n@ti.com> July 2011 I2C driver for tlc59108
75 + * backlight control
76 + */
77 +
78 +#include <linux/i2c.h>
79 +#include <linux/kernel.h>
80 +#include <linux/module.h>
81 +#include <linux/backlight.h>
82 +#include <linux/fb.h>
83 +
84 +#define tlc59108_MODULE_NAME "tlc59108"
85 +#define TLC59108_MODE1 0x00
86 +#define TLC59108_PWM2 0x04
87 +#define TLC59108_LEDOUT0 0x0c
88 +#define TLC59108_LEDOUT1 0x0d
89 +#define TLC59108_MAX_BRIGHTNESS 0xFF
90 +
91 +struct tlc59108_bl {
92 + struct i2c_client *client;
93 + struct backlight_device *bl;
94 +};
95 +
96 +static void tlc59108_bl_set_backlight(struct tlc59108_bl *data, int brightness)
97 +{
98 + /* Set Mode1 Register */
99 + i2c_smbus_write_byte_data(data->client, TLC59108_MODE1, 0x00);
100 +
101 + /* Set LEDOUT0 Register */
102 + i2c_smbus_write_byte_data(data->client, TLC59108_LEDOUT0, 0x21);
103 +
104 + /* Set Backlight Duty Cycle*/
105 + i2c_smbus_write_byte_data(data->client, TLC59108_PWM2,
106 + brightness & 0xff);
107 +}
108 +
109 +static int tlc59108_bl_get_brightness(struct backlight_device *dev)
110 +{
111 + struct backlight_properties *props = &dev->props;
112 +
113 + return props->brightness;
114 +}
115 +
116 +static int tlc59108_bl_update_status(struct backlight_device *dev)
117 +{
118 + struct backlight_properties *props = &dev->props;
119 + struct tlc59108_bl *data = dev_get_drvdata(&dev->dev);
120 + int brightness = props->brightness;
121 +
122 + tlc59108_bl_set_backlight(data, brightness);
123 +
124 + return 0;
125 +}
126 +
127 +static const struct backlight_ops bl_ops = {
128 + .get_brightness = tlc59108_bl_get_brightness,
129 + .update_status = tlc59108_bl_update_status,
130 +};
131 +
132 +static int tlc59108_probe(struct i2c_client *c, const struct i2c_device_id *id)
133 +{
134 + struct backlight_properties props;
135 + struct tlc59108_bl *data = kzalloc(sizeof(struct tlc59108_bl),
136 + GFP_KERNEL);
137 + int ret = 0;
138 +
139 + if (!data)
140 + return -ENOMEM;
141 +
142 + i2c_set_clientdata(c, data);
143 + data->client = c;
144 +
145 + memset(&props, 0, sizeof(struct backlight_properties));
146 + props.max_brightness = TLC59108_MAX_BRIGHTNESS;
147 + props.type = BACKLIGHT_RAW;
148 + data->bl = backlight_device_register("tlc59108-bl", &c->dev, data,
149 + &bl_ops, &props);
150 + if (IS_ERR(data->bl)) {
151 + ret = PTR_ERR(data->bl);
152 + goto err_reg;
153 + }
154 +
155 + data->bl->props.brightness = TLC59108_MAX_BRIGHTNESS;
156 +
157 + backlight_update_status(data->bl);
158 +
159 + return 0;
160 +
161 +err_reg:
162 + data->bl = NULL;
163 + kfree(data);
164 + return ret;
165 +}
166 +
167 +static int tlc59108_remove(struct i2c_client *c)
168 +{
169 + struct tlc59108_bl *data = i2c_get_clientdata(c);
170 +
171 + backlight_device_unregister(data->bl);
172 + data->bl = NULL;
173 +
174 + kfree(data);
175 +
176 + return 0;
177 +}
178 +
179 +/* I2C Device ID table */
180 +static const struct i2c_device_id tlc59108_id[] = {
181 + { "tlc59108", 0 },
182 + { }
183 +};
184 +MODULE_DEVICE_TABLE(i2c, tlc59108_id);
185 +
186 +/* I2C driver data */
187 +static struct i2c_driver tlc59108_driver = {
188 + .driver = {
189 + .owner = THIS_MODULE,
190 + .name = tlc59108_MODULE_NAME,
191 + },
192 + .probe = tlc59108_probe,
193 + .remove = tlc59108_remove,
194 + .id_table = tlc59108_id,
195 +};
196 +
197 +static int __init tlc59108_init(void)
198 +{
199 + return i2c_add_driver(&tlc59108_driver);
200 +}
201 +
202 +static void __exit tlc59108_exit(void)
203 +{
204 + i2c_del_driver(&tlc59108_driver);
205 +}
206 +
207 +module_init(tlc59108_init);
208 +module_exit(tlc59108_exit);
209 +
210 +MODULE_DESCRIPTION("LCD/Backlight control for TLC59108");
211 +MODULE_AUTHOR("Senthil Natarajan <senthil.n@ti.com>");
212 +MODULE_LICENSE("GPL v2");
213 --
214 1.7.7.4