aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2010-04-30 17:09:51 -0400
committerRichard Purdie <rpurdie@linux.intel.com>2010-05-26 08:08:31 -0400
commit82fd53b7f70af9855eda613450a7e4701ffdae20 (patch)
treeb23e2494e9e6734f83de81111150364b7ac9be00
parent9844ce0501b03843c44156d6e36afb80e847c974 (diff)
backlight: new driver for the ADP8860 backlight parts
The ADP8860 combines a programmable backlight LED charge pump driver with automatic phototransistor control. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
-rw-r--r--drivers/video/backlight/Kconfig12
-rw-r--r--drivers/video/backlight/Makefile1
-rw-r--r--drivers/video/backlight/adp8860_bl.c809
-rw-r--r--include/linux/i2c/adp8860.h137
4 files changed, 959 insertions, 0 deletions
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 4dfb5f44dffd..0f7e795f27f8 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -264,6 +264,18 @@ config BACKLIGHT_ADP5520
264 To compile this driver as a module, choose M here: the module will 264 To compile this driver as a module, choose M here: the module will
265 be called adp5520_bl. 265 be called adp5520_bl.
266 266
267config BACKLIGHT_ADP8860
268 tristate "Backlight Driver for ADP8860 using WLED"
269 depends on BACKLIGHT_CLASS_DEVICE && I2C
270 select NEW_LEDS
271 select LEDS_CLASS
272 help
273 If you have a LCD backlight connected to the ADP8860,
274 say Y here to enable this driver.
275
276 To compile this driver as a module, choose M here: the module will
277 be called adp8860_bl.
278
267config BACKLIGHT_88PM860X 279config BACKLIGHT_88PM860X
268 tristate "Backlight Driver for 88PM8606 using WLED" 280 tristate "Backlight Driver for 88PM8606 using WLED"
269 depends on MFD_88PM860X 281 depends on MFD_88PM860X
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 09d1f14d6257..3cbaacae8f9c 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -30,5 +30,6 @@ obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o
30obj-$(CONFIG_BACKLIGHT_WM831X) += wm831x_bl.o 30obj-$(CONFIG_BACKLIGHT_WM831X) += wm831x_bl.o
31obj-$(CONFIG_BACKLIGHT_ADX) += adx_bl.o 31obj-$(CONFIG_BACKLIGHT_ADX) += adx_bl.o
32obj-$(CONFIG_BACKLIGHT_ADP5520) += adp5520_bl.o 32obj-$(CONFIG_BACKLIGHT_ADP5520) += adp5520_bl.o
33obj-$(CONFIG_BACKLIGHT_ADP8860) += adp8860_bl.o
33obj-$(CONFIG_BACKLIGHT_88PM860X) += 88pm860x_bl.o 34obj-$(CONFIG_BACKLIGHT_88PM860X) += 88pm860x_bl.o
34 35
diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c
new file mode 100644
index 000000000000..3c449d2f68b9
--- /dev/null
+++ b/drivers/video/backlight/adp8860_bl.c
@@ -0,0 +1,809 @@
1/*
2 * Backlight driver for Analog Devices ADP8860 Backlight Devices
3 *
4 * Copyright 2009-2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/module.h>
10#include <linux/version.h>
11#include <linux/init.h>
12#include <linux/errno.h>
13#include <linux/pm.h>
14#include <linux/platform_device.h>
15#include <linux/i2c.h>
16#include <linux/fb.h>
17#include <linux/backlight.h>
18#include <linux/leds.h>
19#include <linux/workqueue.h>
20
21#include <linux/i2c/adp8860.h>
22#define ADP8860_EXT_FEATURES
23#define ADP8860_USE_LEDS
24
25#define ADP8860_MFDVID 0x00 /* Manufacturer and device ID */
26#define ADP8860_MDCR 0x01 /* Device mode and status */
27#define ADP8860_MDCR2 0x02 /* Device mode and Status Register 2 */
28#define ADP8860_INTR_EN 0x03 /* Interrupts enable */
29#define ADP8860_CFGR 0x04 /* Configuration register */
30#define ADP8860_BLSEN 0x05 /* Sink enable backlight or independent */
31#define ADP8860_BLOFF 0x06 /* Backlight off timeout */
32#define ADP8860_BLDIM 0x07 /* Backlight dim timeout */
33#define ADP8860_BLFR 0x08 /* Backlight fade in and out rates */
34#define ADP8860_BLMX1 0x09 /* Backlight (Brightness Level 1-daylight) maximum current */
35#define ADP8860_BLDM1 0x0A /* Backlight (Brightness Level 1-daylight) dim current */
36#define ADP8860_BLMX2 0x0B /* Backlight (Brightness Level 2-office) maximum current */
37#define ADP8860_BLDM2 0x0C /* Backlight (Brightness Level 2-office) dim current */
38#define ADP8860_BLMX3 0x0D /* Backlight (Brightness Level 3-dark) maximum current */
39#define ADP8860_BLDM3 0x0E /* Backlight (Brightness Level 3-dark) dim current */
40#define ADP8860_ISCFR 0x0F /* Independent sink current fade control register */
41#define ADP8860_ISCC 0x10 /* Independent sink current control register */
42#define ADP8860_ISCT1 0x11 /* Independent Sink Current Timer Register LED[7:5] */
43#define ADP8860_ISCT2 0x12 /* Independent Sink Current Timer Register LED[4:1] */
44#define ADP8860_ISCF 0x13 /* Independent sink current fade register */
45#define ADP8860_ISC7 0x14 /* Independent Sink Current LED7 */
46#define ADP8860_ISC6 0x15 /* Independent Sink Current LED6 */
47#define ADP8860_ISC5 0x16 /* Independent Sink Current LED5 */
48#define ADP8860_ISC4 0x17 /* Independent Sink Current LED4 */
49#define ADP8860_ISC3 0x18 /* Independent Sink Current LED3 */
50#define ADP8860_ISC2 0x19 /* Independent Sink Current LED2 */
51#define ADP8860_ISC1 0x1A /* Independent Sink Current LED1 */
52#define ADP8860_CCFG 0x1B /* Comparator configuration */
53#define ADP8860_CCFG2 0x1C /* Second comparator configuration */
54#define ADP8860_L2_TRP 0x1D /* L2 comparator reference */
55#define ADP8860_L2_HYS 0x1E /* L2 hysteresis */
56#define ADP8860_L3_TRP 0x1F /* L3 comparator reference */
57#define ADP8860_L3_HYS 0x20 /* L3 hysteresis */
58#define ADP8860_PH1LEVL 0x21 /* First phototransistor ambient light level-low byte register */
59#define ADP8860_PH1LEVH 0x22 /* First phototransistor ambient light level-high byte register */
60#define ADP8860_PH2LEVL 0x23 /* Second phototransistor ambient light level-low byte register */
61#define ADP8860_PH2LEVH 0x24 /* Second phototransistor ambient light level-high byte register */
62
63#define ADP8860_MANUFID 0x0 /* Analog Devices ADP8860 Manufacturer ID */
64#define ADP8860_DEVICEID 0x7 /* Analog Devices ADP8860 Device ID */
65#define ADP8860_DEVID(x) ((x) & 0xF)
66#define ADP8860_MANID(x) ((x) >> 4)
67
68/* MDCR Device mode and status */
69#define INT_CFG (1 << 6)
70#define NSTBY (1 << 5)
71#define DIM_EN (1 << 4)
72#define SIS_EN (1 << 2)
73#define CMP_AUTOEN (1 << 1)
74#define BLEN (1 << 0)
75
76/* ADP8860_CCFG Main ALS comparator level enable */
77#define L3_EN (1 << 1)
78#define L2_EN (1 << 0)
79
80#define CFGR_BLV_SHIFT 3
81#define CFGR_BLV_MASK 0x3
82#define ADP8860_FLAG_LED_MASK 0xFF
83
84#define FADE_VAL(in, out) ((0xF & (in)) | ((0xF & (out)) << 4))
85#define BL_CFGR_VAL(law, blv) ((((blv) & CFGR_BLV_MASK) << CFGR_BLV_SHIFT) | ((0x3 & (law)) << 1))
86#define ALS_CCFG_VAL(filt) ((0x7 & filt) << 5)
87
88struct adp8860_led {
89 struct led_classdev cdev;
90 struct work_struct work;
91 struct i2c_client *client;
92 enum led_brightness new_brightness;
93 int id;
94 int flags;
95};
96
97struct adp8860_bl {
98 struct i2c_client *client;
99 struct backlight_device *bl;
100 struct adp8860_led *led;
101 struct adp8860_backlight_platform_data *pdata;
102 struct mutex lock;
103 unsigned long cached_daylight_max;
104 int id;
105 int revid;
106 int current_brightness;
107};
108
109static int adp8860_read(struct i2c_client *client, int reg, uint8_t *val)
110{
111 int ret;
112
113 ret = i2c_smbus_read_byte_data(client, reg);
114 if (ret < 0) {
115 dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
116 return ret;
117 }
118
119 *val = (uint8_t)ret;
120 return 0;
121}
122
123
124static int adp8860_write(struct i2c_client *client, u8 reg, u8 val)
125{
126 return i2c_smbus_write_byte_data(client, reg, val);
127}
128
129static int adp8860_set_bits(struct i2c_client *client, int reg, uint8_t bit_mask)
130{
131 struct adp8860_bl *data = i2c_get_clientdata(client);
132 uint8_t reg_val;
133 int ret;
134
135 mutex_lock(&data->lock);
136
137 ret = adp8860_read(client, reg, &reg_val);
138
139 if (!ret && ((reg_val & bit_mask) == 0)) {
140 reg_val |= bit_mask;
141 ret = adp8860_write(client, reg, reg_val);
142 }
143
144 mutex_unlock(&data->lock);
145 return ret;
146}
147
148static int adp8860_clr_bits(struct i2c_client *client, int reg, uint8_t bit_mask)
149{
150 struct adp8860_bl *data = i2c_get_clientdata(client);
151 uint8_t reg_val;
152 int ret;
153
154 mutex_lock(&data->lock);
155
156 ret = adp8860_read(client, reg, &reg_val);
157
158 if (!ret && (reg_val & bit_mask)) {
159 reg_val &= ~bit_mask;
160 ret = adp8860_write(client, reg, reg_val);
161 }
162
163 mutex_unlock(&data->lock);
164 return ret;
165}
166
167/*
168 * Independent sink / LED
169 */
170#if defined(ADP8860_USE_LEDS)
171static void adp8860_led_work(struct work_struct *work)
172{
173 struct adp8860_led *led = container_of(work, struct adp8860_led, work);
174 adp8860_write(led->client, ADP8860_ISC1 - led->id + 1,
175 led->new_brightness >> 1);
176}
177
178static void adp8860_led_set(struct led_classdev *led_cdev,
179 enum led_brightness value)
180{
181 struct adp8860_led *led;
182
183 led = container_of(led_cdev, struct adp8860_led, cdev);
184 led->new_brightness = value;
185 schedule_work(&led->work);
186}
187
188static int adp8860_led_setup(struct adp8860_led *led)
189{
190 struct i2c_client *client = led->client;
191 int ret = 0;
192
193 ret = adp8860_write(client, ADP8860_ISC1 - led->id + 1, 0);
194 ret |= adp8860_set_bits(client, ADP8860_ISCC, 1 << (led->id - 1));
195
196 if (led->id > 4)
197 ret |= adp8860_set_bits(client, ADP8860_ISCT1,
198 (led->flags & 0x3) << ((led->id - 5) * 2));
199 else
200 ret |= adp8860_set_bits(client, ADP8860_ISCT2,
201 (led->flags & 0x3) << ((led->id - 1) * 2));
202
203 return ret;
204}
205
206static int __devinit adp8860_led_probe(struct i2c_client *client)
207{
208 struct adp8860_backlight_platform_data *pdata =
209 client->dev.platform_data;
210 struct adp8860_bl *data = i2c_get_clientdata(client);
211 struct adp8860_led *led, *led_dat;
212 struct led_info *cur_led;
213 int ret, i;
214
215 led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
216 if (led == NULL) {
217 dev_err(&client->dev, "failed to alloc memory\n");
218 return -ENOMEM;
219 }
220
221 ret = adp8860_write(client, ADP8860_ISCFR, pdata->led_fade_law);
222 ret = adp8860_write(client, ADP8860_ISCT1,
223 (pdata->led_on_time & 0x3) << 6);
224 ret |= adp8860_write(client, ADP8860_ISCF,
225 FADE_VAL(pdata->led_fade_in, pdata->led_fade_out));
226
227 if (ret) {
228 dev_err(&client->dev, "failed to write\n");
229 goto err_free;
230 }
231
232 for (i = 0; i < pdata->num_leds; ++i) {
233 cur_led = &pdata->leds[i];
234 led_dat = &led[i];
235
236 led_dat->id = cur_led->flags & ADP8860_FLAG_LED_MASK;
237
238 if (led_dat->id > 7 || led_dat->id < 1) {
239 dev_err(&client->dev, "Invalid LED ID %d\n",
240 led_dat->id);
241 goto err;
242 }
243
244 if (pdata->bl_led_assign & (1 << (led_dat->id - 1))) {
245 dev_err(&client->dev, "LED %d used by Backlight\n",
246 led_dat->id);
247 goto err;
248 }
249
250 led_dat->cdev.name = cur_led->name;
251 led_dat->cdev.default_trigger = cur_led->default_trigger;
252 led_dat->cdev.brightness_set = adp8860_led_set;
253 led_dat->cdev.brightness = LED_OFF;
254 led_dat->flags = cur_led->flags >> FLAG_OFFT_SHIFT;
255 led_dat->client = client;
256 led_dat->new_brightness = LED_OFF;
257 INIT_WORK(&led_dat->work, adp8860_led_work);
258
259 ret = led_classdev_register(&client->dev, &led_dat->cdev);
260 if (ret) {
261 dev_err(&client->dev, "failed to register LED %d\n",
262 led_dat->id);
263 goto err;
264 }
265
266 ret = adp8860_led_setup(led_dat);
267 if (ret) {
268 dev_err(&client->dev, "failed to write\n");
269 i++;
270 goto err;
271 }
272 }
273
274 data->led = led;
275
276 return 0;
277
278 err:
279 for (i = i - 1; i >= 0; --i) {
280 led_classdev_unregister(&led[i].cdev);
281 cancel_work_sync(&led[i].work);
282 }
283
284 err_free:
285 kfree(led);
286
287 return ret;
288}
289
290static int __devexit adp8860_led_remove(struct i2c_client *client)
291{
292 struct adp8860_backlight_platform_data *pdata =
293 client->dev.platform_data;
294 struct adp8860_bl *data = i2c_get_clientdata(client);
295 int i;
296
297 for (i = 0; i < pdata->num_leds; i++) {
298 led_classdev_unregister(&data->led[i].cdev);
299 cancel_work_sync(&data->led[i].work);
300 }
301
302 kfree(data->led);
303 return 0;
304}
305#else
306static int __devinit adp8860_led_probe(struct i2c_client *client)
307{
308 return 0;
309}
310
311static int __devexit adp8860_led_remove(struct i2c_client *client)
312{
313 return 0;
314}
315#endif
316
317static int adp8860_bl_set(struct backlight_device *bl, int brightness)
318{
319 struct adp8860_bl *data = bl_get_data(bl);
320 struct i2c_client *client = data->client;
321 int ret = 0;
322
323 if (data->pdata->en_ambl_sens) {
324 if ((brightness > 0) && (brightness < ADP8860_MAX_BRIGHTNESS)) {
325 /* Disable Ambient Light auto adjust */
326 ret |= adp8860_clr_bits(client, ADP8860_MDCR,
327 CMP_AUTOEN);
328 ret |= adp8860_write(client, ADP8860_BLMX1, brightness);
329 } else {
330 /*
331 * MAX_BRIGHTNESS -> Enable Ambient Light auto adjust
332 * restore daylight l1 sysfs brightness
333 */
334 ret |= adp8860_write(client, ADP8860_BLMX1,
335 data->cached_daylight_max);
336 ret |= adp8860_set_bits(client, ADP8860_MDCR,
337 CMP_AUTOEN);
338 }
339 } else
340 ret |= adp8860_write(client, ADP8860_BLMX1, brightness);
341
342 if (data->current_brightness && brightness == 0)
343 ret |= adp8860_set_bits(client,
344 ADP8860_MDCR, DIM_EN);
345 else if (data->current_brightness == 0 && brightness)
346 ret |= adp8860_clr_bits(client,
347 ADP8860_MDCR, DIM_EN);
348
349 if (!ret)
350 data->current_brightness = brightness;
351
352 return ret;
353}
354
355static int adp8860_bl_update_status(struct backlight_device *bl)
356{
357 int brightness = bl->props.brightness;
358 if (bl->props.power != FB_BLANK_UNBLANK)
359 brightness = 0;
360
361 if (bl->props.fb_blank != FB_BLANK_UNBLANK)
362 brightness = 0;
363
364 return adp8860_bl_set(bl, brightness);
365}
366
367static int adp8860_bl_get_brightness(struct backlight_device *bl)
368{
369 struct adp8860_bl *data = bl_get_data(bl);
370
371 return data->current_brightness;
372}
373
374static const struct backlight_ops adp8860_bl_ops = {
375 .update_status = adp8860_bl_update_status,
376 .get_brightness = adp8860_bl_get_brightness,
377};
378
379static int adp8860_bl_setup(struct backlight_device *bl)
380{
381 struct adp8860_bl *data = bl_get_data(bl);
382 struct i2c_client *client = data->client;
383 struct adp8860_backlight_platform_data *pdata = data->pdata;
384 int ret = 0;
385
386 ret |= adp8860_write(client, ADP8860_BLSEN, ~pdata->bl_led_assign);
387 ret |= adp8860_write(client, ADP8860_BLMX1, pdata->l1_daylight_max);
388 ret |= adp8860_write(client, ADP8860_BLDM1, pdata->l1_daylight_dim);
389
390 if (pdata->en_ambl_sens) {
391 data->cached_daylight_max = pdata->l1_daylight_max;
392 ret |= adp8860_write(client, ADP8860_BLMX2,
393 pdata->l2_office_max);
394 ret |= adp8860_write(client, ADP8860_BLDM2,
395 pdata->l2_office_dim);
396 ret |= adp8860_write(client, ADP8860_BLMX3,
397 pdata->l3_dark_max);
398 ret |= adp8860_write(client, ADP8860_BLDM3,
399 pdata->l3_dark_dim);
400
401 ret |= adp8860_write(client, ADP8860_L2_TRP, pdata->l2_trip);
402 ret |= adp8860_write(client, ADP8860_L2_HYS, pdata->l2_hyst);
403 ret |= adp8860_write(client, ADP8860_L3_TRP, pdata->l3_trip);
404 ret |= adp8860_write(client, ADP8860_L3_HYS, pdata->l3_hyst);
405 ret |= adp8860_write(client, ADP8860_CCFG, L2_EN | L3_EN |
406 ALS_CCFG_VAL(pdata->abml_filt));
407 }
408
409 ret |= adp8860_write(client, ADP8860_CFGR,
410 BL_CFGR_VAL(pdata->bl_fade_law, 0));
411
412 ret |= adp8860_write(client, ADP8860_BLFR, FADE_VAL(pdata->bl_fade_in,
413 pdata->bl_fade_out));
414
415 ret |= adp8860_set_bits(client, ADP8860_MDCR, BLEN | DIM_EN | NSTBY);
416
417 return ret;
418}
419
420static ssize_t adp8860_show(struct device *dev, char *buf, int reg)
421{
422 struct adp8860_bl *data = dev_get_drvdata(dev);
423 int error;
424 uint8_t reg_val;
425
426 mutex_lock(&data->lock);
427 error = adp8860_read(data->client, reg, &reg_val);
428 mutex_unlock(&data->lock);
429
430 if (error < 0)
431 return error;
432
433 return sprintf(buf, "%u\n", reg_val);
434}
435
436static ssize_t adp8860_store(struct device *dev, const char *buf,
437 size_t count, int reg)
438{
439 struct adp8860_bl *data = dev_get_drvdata(dev);
440 unsigned long val;
441 int ret;
442
443 ret = strict_strtoul(buf, 10, &val);
444 if (ret)
445 return ret;
446
447 mutex_lock(&data->lock);
448 adp8860_write(data->client, reg, val);
449 mutex_unlock(&data->lock);
450
451 return count;
452}
453
454static ssize_t adp8860_bl_l3_dark_max_show(struct device *dev,
455 struct device_attribute *attr, char *buf)
456{
457 return adp8860_show(dev, buf, ADP8860_BLMX3);
458}
459
460static ssize_t adp8860_bl_l3_dark_max_store(struct device *dev,
461 struct device_attribute *attr, const char *buf, size_t count)
462{
463 return adp8860_store(dev, buf, count, ADP8860_BLMX3);
464}
465
466static DEVICE_ATTR(l3_dark_max, 0664, adp8860_bl_l3_dark_max_show,
467 adp8860_bl_l3_dark_max_store);
468
469static ssize_t adp8860_bl_l2_office_max_show(struct device *dev,
470 struct device_attribute *attr, char *buf)
471{
472 return adp8860_show(dev, buf, ADP8860_BLMX2);
473}
474
475static ssize_t adp8860_bl_l2_office_max_store(struct device *dev,
476 struct device_attribute *attr, const char *buf, size_t count)
477{
478 return adp8860_store(dev, buf, count, ADP8860_BLMX2);
479}
480static DEVICE_ATTR(l2_office_max, 0664, adp8860_bl_l2_office_max_show,
481 adp8860_bl_l2_office_max_store);
482
483static ssize_t adp8860_bl_l1_daylight_max_show(struct device *dev,
484 struct device_attribute *attr, char *buf)
485{
486 return adp8860_show(dev, buf, ADP8860_BLMX1);
487}
488
489static ssize_t adp8860_bl_l1_daylight_max_store(struct device *dev,
490 struct device_attribute *attr, const char *buf, size_t count)
491{
492 struct adp8860_bl *data = dev_get_drvdata(dev);
493
494 strict_strtoul(buf, 10, &data->cached_daylight_max);
495 return adp8860_store(dev, buf, count, ADP8860_BLMX1);
496}
497static DEVICE_ATTR(l1_daylight_max, 0664, adp8860_bl_l1_daylight_max_show,
498 adp8860_bl_l1_daylight_max_store);
499
500static ssize_t adp8860_bl_l3_dark_dim_show(struct device *dev,
501 struct device_attribute *attr, char *buf)
502{
503 return adp8860_show(dev, buf, ADP8860_BLDM3);
504}
505
506static ssize_t adp8860_bl_l3_dark_dim_store(struct device *dev,
507 struct device_attribute *attr,
508 const char *buf, size_t count)
509{
510 return adp8860_store(dev, buf, count, ADP8860_BLDM3);
511}
512static DEVICE_ATTR(l3_dark_dim, 0664, adp8860_bl_l3_dark_dim_show,
513 adp8860_bl_l3_dark_dim_store);
514
515static ssize_t adp8860_bl_l2_office_dim_show(struct device *dev,
516 struct device_attribute *attr, char *buf)
517{
518 return adp8860_show(dev, buf, ADP8860_BLDM2);
519}
520
521static ssize_t adp8860_bl_l2_office_dim_store(struct device *dev,
522 struct device_attribute *attr,
523 const char *buf, size_t count)
524{
525 return adp8860_store(dev, buf, count, ADP8860_BLDM2);
526}
527static DEVICE_ATTR(l2_office_dim, 0664, adp8860_bl_l2_office_dim_show,
528 adp8860_bl_l2_office_dim_store);
529
530static ssize_t adp8860_bl_l1_daylight_dim_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
532{
533 return adp8860_show(dev, buf, ADP8860_BLDM1);
534}
535
536static ssize_t adp8860_bl_l1_daylight_dim_store(struct device *dev,
537 struct device_attribute *attr,
538 const char *buf, size_t count)
539{
540 return adp8860_store(dev, buf, count, ADP8860_BLDM1);
541}
542static DEVICE_ATTR(l1_daylight_dim, 0664, adp8860_bl_l1_daylight_dim_show,
543 adp8860_bl_l1_daylight_dim_store);
544
545#ifdef ADP8860_EXT_FEATURES
546static ssize_t adp8860_bl_ambient_light_level_show(struct device *dev,
547 struct device_attribute *attr, char *buf)
548{
549 struct adp8860_bl *data = dev_get_drvdata(dev);
550 int error;
551 uint8_t reg_val;
552 uint16_t ret_val;
553
554 mutex_lock(&data->lock);
555 error = adp8860_read(data->client, ADP8860_PH1LEVL, &reg_val);
556 ret_val = reg_val;
557 error |= adp8860_read(data->client, ADP8860_PH1LEVH, &reg_val);
558 mutex_unlock(&data->lock);
559
560 if (error < 0)
561 return error;
562
563 /* Return 13-bit conversion value for the first light sensor */
564 ret_val += (reg_val & 0x1F) << 8;
565
566 return sprintf(buf, "%u\n", ret_val);
567}
568static DEVICE_ATTR(ambient_light_level, 0444,
569 adp8860_bl_ambient_light_level_show, NULL);
570
571static ssize_t adp8860_bl_ambient_light_zone_show(struct device *dev,
572 struct device_attribute *attr, char *buf)
573{
574 struct adp8860_bl *data = dev_get_drvdata(dev);
575 int error;
576 uint8_t reg_val;
577
578 mutex_lock(&data->lock);
579 error = adp8860_read(data->client, ADP8860_CFGR, &reg_val);
580 mutex_unlock(&data->lock);
581
582 if (error < 0)
583 return error;
584
585 return sprintf(buf, "%u\n",
586 ((reg_val >> CFGR_BLV_SHIFT) & CFGR_BLV_MASK) + 1);
587}
588
589static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev,
590 struct device_attribute *attr,
591 const char *buf, size_t count)
592{
593 struct adp8860_bl *data = dev_get_drvdata(dev);
594 unsigned long val;
595 uint8_t reg_val;
596 int ret;
597
598 ret = strict_strtoul(buf, 10, &val);
599 if (ret)
600 return ret;
601
602 if (val == 0) {
603 /* Enable automatic ambient light sensing */
604 adp8860_set_bits(data->client, ADP8860_MDCR, CMP_AUTOEN);
605 } else if ((val > 0) && (val < 6)) {
606 /* Disable automatic ambient light sensing */
607 adp8860_clr_bits(data->client, ADP8860_MDCR, CMP_AUTOEN);
608
609 /* Set user supplied ambient light zone */
610 mutex_lock(&data->lock);
611 adp8860_read(data->client, ADP8860_CFGR, &reg_val);
612 reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT);
613 reg_val |= val << CFGR_BLV_SHIFT;
614 adp8860_write(data->client, ADP8860_CFGR, reg_val);
615 mutex_unlock(&data->lock);
616 }
617
618 return count;
619}
620static DEVICE_ATTR(ambient_light_zone, 0664,
621 adp8860_bl_ambient_light_zone_show,
622 adp8860_bl_ambient_light_zone_store);
623#endif
624
625static struct attribute *adp8860_bl_attributes[] = {
626 &dev_attr_l3_dark_max.attr,
627 &dev_attr_l3_dark_dim.attr,
628 &dev_attr_l2_office_max.attr,
629 &dev_attr_l2_office_dim.attr,
630 &dev_attr_l1_daylight_max.attr,
631 &dev_attr_l1_daylight_dim.attr,
632#ifdef ADP8860_EXT_FEATURES
633 &dev_attr_ambient_light_level.attr,
634 &dev_attr_ambient_light_zone.attr,
635#endif
636 NULL
637};
638
639static const struct attribute_group adp8860_bl_attr_group = {
640 .attrs = adp8860_bl_attributes,
641};
642
643static int __devinit adp8860_probe(struct i2c_client *client,
644 const struct i2c_device_id *id)
645{
646 struct backlight_device *bl;
647 struct adp8860_bl *data;
648 struct adp8860_backlight_platform_data *pdata =
649 client->dev.platform_data;
650 uint8_t reg_val;
651 int ret;
652
653 if (!i2c_check_functionality(client->adapter,
654 I2C_FUNC_SMBUS_BYTE_DATA)) {
655 dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
656 return -EIO;
657 }
658
659 if (!pdata) {
660 dev_err(&client->dev, "no platform data?\n");
661 return -EINVAL;
662 }
663
664 ret = adp8860_read(client, ADP8860_MFDVID, &reg_val);
665 if (ret < 0)
666 return -EIO;
667
668 if (ADP8860_MANID(reg_val) != ADP8860_MANUFID) {
669 dev_err(&client->dev, "failed to probe\n");
670 return -ENODEV;
671 }
672
673 data = kzalloc(sizeof(*data), GFP_KERNEL);
674 if (data == NULL)
675 return -ENOMEM;
676
677 /* It's confirmed that the DEVID field is actually a REVID */
678
679 data->revid = ADP8860_DEVID(reg_val);
680 data->client = client;
681 data->pdata = pdata;
682 data->id = id->driver_data;
683 data->current_brightness = 0;
684 i2c_set_clientdata(client, data);
685
686 mutex_init(&data->lock);
687
688 bl = backlight_device_register(dev_driver_string(&client->dev),
689 &client->dev, data, &adp8860_bl_ops);
690 if (IS_ERR(bl)) {
691 dev_err(&client->dev, "failed to register backlight\n");
692 ret = PTR_ERR(bl);
693 goto out2;
694 }
695
696 bl->props.max_brightness =
697 bl->props.brightness = ADP8860_MAX_BRIGHTNESS;
698
699 data->bl = bl;
700
701 if (pdata->en_ambl_sens)
702 ret = sysfs_create_group(&bl->dev.kobj,
703 &adp8860_bl_attr_group);
704
705 if (ret) {
706 dev_err(&client->dev, "failed to register sysfs\n");
707 goto out1;
708 }
709
710 ret = adp8860_bl_setup(bl);
711 if (ret) {
712 ret = -EIO;
713 goto out;
714 }
715
716 backlight_update_status(bl);
717
718 dev_info(&client->dev, "Rev.%d Backlight\n", data->revid);
719
720 if (pdata->num_leds)
721 adp8860_led_probe(client);
722
723 return 0;
724
725out:
726 if (data->pdata->en_ambl_sens)
727 sysfs_remove_group(&data->bl->dev.kobj,
728 &adp8860_bl_attr_group);
729out1:
730 backlight_device_unregister(bl);
731out2:
732 i2c_set_clientdata(client, NULL);
733 kfree(data);
734
735 return ret;
736}
737
738static int __devexit adp8860_remove(struct i2c_client *client)
739{
740 struct adp8860_bl *data = i2c_get_clientdata(client);
741
742 adp8860_clr_bits(client, ADP8860_MDCR, NSTBY);
743
744 if (data->led)
745 adp8860_led_remove(client);
746
747 if (data->pdata->en_ambl_sens)
748 sysfs_remove_group(&data->bl->dev.kobj,
749 &adp8860_bl_attr_group);
750
751 backlight_device_unregister(data->bl);
752 i2c_set_clientdata(client, NULL);
753 kfree(data);
754
755 return 0;
756}
757
758#ifdef CONFIG_PM
759static int adp8860_i2c_suspend(struct i2c_client *client, pm_message_t message)
760{
761 adp8860_clr_bits(client, ADP8860_MDCR, NSTBY);
762
763 return 0;
764}
765
766static int adp8860_i2c_resume(struct i2c_client *client)
767{
768 adp8860_set_bits(client, ADP8860_MDCR, NSTBY);
769
770 return 0;
771}
772#else
773#define adp8860_i2c_suspend NULL
774#define adp8860_i2c_resume NULL
775#endif
776
777static const struct i2c_device_id adp8860_id[] = {
778 { "adp8860", 0 },
779 { }
780};
781MODULE_DEVICE_TABLE(i2c, adp8860_id);
782
783static struct i2c_driver adp8860_driver = {
784 .driver = {
785 .name = KBUILD_MODNAME,
786 },
787 .probe = adp8860_probe,
788 .remove = __devexit_p(adp8860_remove),
789 .suspend = adp8860_i2c_suspend,
790 .resume = adp8860_i2c_resume,
791 .id_table = adp8860_id,
792};
793
794static int __init adp8860_init(void)
795{
796 return i2c_add_driver(&adp8860_driver);
797}
798module_init(adp8860_init);
799
800static void __exit adp8860_exit(void)
801{
802 i2c_del_driver(&adp8860_driver);
803}
804module_exit(adp8860_exit);
805
806MODULE_LICENSE("GPL v2");
807MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
808MODULE_DESCRIPTION("ADP8860 Backlight driver");
809MODULE_ALIAS("i2c:adp8860-backlight");
diff --git a/include/linux/i2c/adp8860.h b/include/linux/i2c/adp8860.h
new file mode 100644
index 000000000000..115514b7176e
--- /dev/null
+++ b/include/linux/i2c/adp8860.h
@@ -0,0 +1,137 @@
1/*
2 * Definitions and platform data for Analog Devices
3 * Backlight drivers ADP8860
4 *
5 * Copyright 2009-2010 Analog Devices Inc.
6 *
7 * Licensed under the GPL-2 or later.
8 */
9
10#ifndef __LINUX_I2C_ADP8860_H
11#define __LINUX_I2C_ADP8860_H
12
13#include <linux/leds.h>
14#include <linux/types.h>
15
16#define ID_ADP8860 8860
17
18#define ADP8860_MAX_BRIGHTNESS 0x7F
19#define FLAG_OFFT_SHIFT 8
20
21/*
22 * LEDs subdevice platform data
23 */
24
25#define ADP8860_LED_DIS_BLINK (0 << FLAG_OFFT_SHIFT)
26#define ADP8860_LED_OFFT_600ms (1 << FLAG_OFFT_SHIFT)
27#define ADP8860_LED_OFFT_1200ms (2 << FLAG_OFFT_SHIFT)
28#define ADP8860_LED_OFFT_1800ms (3 << FLAG_OFFT_SHIFT)
29
30#define ADP8860_LED_ONT_200ms 0
31#define ADP8860_LED_ONT_600ms 1
32#define ADP8860_LED_ONT_800ms 2
33#define ADP8860_LED_ONT_1200ms 3
34
35#define ADP8860_LED_D7 (7)
36#define ADP8860_LED_D6 (6)
37#define ADP8860_LED_D5 (5)
38#define ADP8860_LED_D4 (4)
39#define ADP8860_LED_D3 (3)
40#define ADP8860_LED_D2 (2)
41#define ADP8860_LED_D1 (1)
42
43/*
44 * Backlight subdevice platform data
45 */
46
47#define ADP8860_BL_D7 (1 << 6)
48#define ADP8860_BL_D6 (1 << 5)
49#define ADP8860_BL_D5 (1 << 4)
50#define ADP8860_BL_D4 (1 << 3)
51#define ADP8860_BL_D3 (1 << 2)
52#define ADP8860_BL_D2 (1 << 1)
53#define ADP8860_BL_D1 (1 << 0)
54
55#define ADP8860_FADE_T_DIS 0 /* Fade Timer Disabled */
56#define ADP8860_FADE_T_300ms 1 /* 0.3 Sec */
57#define ADP8860_FADE_T_600ms 2
58#define ADP8860_FADE_T_900ms 3
59#define ADP8860_FADE_T_1200ms 4
60#define ADP8860_FADE_T_1500ms 5
61#define ADP8860_FADE_T_1800ms 6
62#define ADP8860_FADE_T_2100ms 7
63#define ADP8860_FADE_T_2400ms 8
64#define ADP8860_FADE_T_2700ms 9
65#define ADP8860_FADE_T_3000ms 10
66#define ADP8860_FADE_T_3500ms 11
67#define ADP8860_FADE_T_4000ms 12
68#define ADP8860_FADE_T_4500ms 13
69#define ADP8860_FADE_T_5000ms 14
70#define ADP8860_FADE_T_5500ms 15 /* 5.5 Sec */
71
72#define ADP8860_FADE_LAW_LINEAR 0
73#define ADP8860_FADE_LAW_SQUARE 1
74#define ADP8860_FADE_LAW_CUBIC1 2
75#define ADP8860_FADE_LAW_CUBIC2 3
76
77#define ADP8860_BL_AMBL_FILT_80ms 0 /* Light sensor filter time */
78#define ADP8860_BL_AMBL_FILT_160ms 1
79#define ADP8860_BL_AMBL_FILT_320ms 2
80#define ADP8860_BL_AMBL_FILT_640ms 3
81#define ADP8860_BL_AMBL_FILT_1280ms 4
82#define ADP8860_BL_AMBL_FILT_2560ms 5
83#define ADP8860_BL_AMBL_FILT_5120ms 6
84#define ADP8860_BL_AMBL_FILT_10240ms 7 /* 10.24 sec */
85
86/*
87 * Blacklight current 0..30mA
88 */
89#define ADP8860_BL_CUR_mA(I) ((I * 127) / 30)
90
91/*
92 * L2 comparator current 0..1106uA
93 */
94#define ADP8860_L2_COMP_CURR_uA(I) ((I * 255) / 1106)
95
96/*
97 * L3 comparator current 0..138uA
98 */
99#define ADP8860_L3_COMP_CURR_uA(I) ((I * 255) / 138)
100
101struct adp8860_backlight_platform_data {
102 u8 bl_led_assign; /* 1 = Backlight 0 = Individual LED */
103
104 u8 bl_fade_in; /* Backlight Fade-In Timer */
105 u8 bl_fade_out; /* Backlight Fade-Out Timer */
106 u8 bl_fade_law; /* fade-on/fade-off transfer characteristic */
107
108 u8 en_ambl_sens; /* 1 = enable ambient light sensor */
109 u8 abml_filt; /* Light sensor filter time */
110
111 u8 l1_daylight_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
112 u8 l1_daylight_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
113 u8 l2_office_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
114 u8 l2_office_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
115 u8 l3_dark_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
116 u8 l3_dark_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
117
118 u8 l2_trip; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1106 uA */
119 u8 l2_hyst; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1106 uA */
120 u8 l3_trip; /* use L3_COMP_CURR_uA(I) 0 <= I <= 551 uA */
121 u8 l3_hyst; /* use L3_COMP_CURR_uA(I) 0 <= I <= 551 uA */
122
123 /**
124 * Independent Current Sinks / LEDS
125 * Sinks not assigned to the Backlight can be exposed to
126 * user space using the LEDS CLASS interface
127 */
128
129 int num_leds;
130 struct led_info *leds;
131 u8 led_fade_in; /* LED Fade-In Timer */
132 u8 led_fade_out; /* LED Fade-Out Timer */
133 u8 led_fade_law; /* fade-on/fade-off transfer characteristic */
134 u8 led_on_time;
135};
136
137#endif /* __LINUX_I2C_ADP8860_H */