2 * Backlight driver for Analog Devices ADP8860 Backlight Devices
4 * Copyright 2009-2010 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
9 #include <linux/module.h>
10 #include <linux/version.h>
11 #include <linux/init.h>
12 #include <linux/errno.h>
14 #include <linux/platform_device.h>
15 #include <linux/i2c.h>
17 #include <linux/backlight.h>
18 #include <linux/leds.h>
19 #include <linux/slab.h>
20 #include <linux/workqueue.h>
22 #include <linux/i2c/adp8860.h>
23 #define ADP8860_EXT_FEATURES
24 #define ADP8860_USE_LEDS
26 #define ADP8860_MFDVID 0x00 /* Manufacturer and device ID */
27 #define ADP8860_MDCR 0x01 /* Device mode and status */
28 #define ADP8860_MDCR2 0x02 /* Device mode and Status Register 2 */
29 #define ADP8860_INTR_EN 0x03 /* Interrupts enable */
30 #define ADP8860_CFGR 0x04 /* Configuration register */
31 #define ADP8860_BLSEN 0x05 /* Sink enable backlight or independent */
32 #define ADP8860_BLOFF 0x06 /* Backlight off timeout */
33 #define ADP8860_BLDIM 0x07 /* Backlight dim timeout */
34 #define ADP8860_BLFR 0x08 /* Backlight fade in and out rates */
35 #define ADP8860_BLMX1 0x09 /* Backlight (Brightness Level 1-daylight) maximum current */
36 #define ADP8860_BLDM1 0x0A /* Backlight (Brightness Level 1-daylight) dim current */
37 #define ADP8860_BLMX2 0x0B /* Backlight (Brightness Level 2-office) maximum current */
38 #define ADP8860_BLDM2 0x0C /* Backlight (Brightness Level 2-office) dim current */
39 #define ADP8860_BLMX3 0x0D /* Backlight (Brightness Level 3-dark) maximum current */
40 #define ADP8860_BLDM3 0x0E /* Backlight (Brightness Level 3-dark) dim current */
41 #define ADP8860_ISCFR 0x0F /* Independent sink current fade control register */
42 #define ADP8860_ISCC 0x10 /* Independent sink current control register */
43 #define ADP8860_ISCT1 0x11 /* Independent Sink Current Timer Register LED[7:5] */
44 #define ADP8860_ISCT2 0x12 /* Independent Sink Current Timer Register LED[4:1] */
45 #define ADP8860_ISCF 0x13 /* Independent sink current fade register */
46 #define ADP8860_ISC7 0x14 /* Independent Sink Current LED7 */
47 #define ADP8860_ISC6 0x15 /* Independent Sink Current LED6 */
48 #define ADP8860_ISC5 0x16 /* Independent Sink Current LED5 */
49 #define ADP8860_ISC4 0x17 /* Independent Sink Current LED4 */
50 #define ADP8860_ISC3 0x18 /* Independent Sink Current LED3 */
51 #define ADP8860_ISC2 0x19 /* Independent Sink Current LED2 */
52 #define ADP8860_ISC1 0x1A /* Independent Sink Current LED1 */
53 #define ADP8860_CCFG 0x1B /* Comparator configuration */
54 #define ADP8860_CCFG2 0x1C /* Second comparator configuration */
55 #define ADP8860_L2_TRP 0x1D /* L2 comparator reference */
56 #define ADP8860_L2_HYS 0x1E /* L2 hysteresis */
57 #define ADP8860_L3_TRP 0x1F /* L3 comparator reference */
58 #define ADP8860_L3_HYS 0x20 /* L3 hysteresis */
59 #define ADP8860_PH1LEVL 0x21 /* First phototransistor ambient light level-low byte register */
60 #define ADP8860_PH1LEVH 0x22 /* First phototransistor ambient light level-high byte register */
61 #define ADP8860_PH2LEVL 0x23 /* Second phototransistor ambient light level-low byte register */
62 #define ADP8860_PH2LEVH 0x24 /* Second phototransistor ambient light level-high byte register */
64 #define ADP8860_MANUFID 0x0 /* Analog Devices ADP8860 Manufacturer ID */
65 #define ADP8860_DEVICEID 0x7 /* Analog Devices ADP8860 Device ID */
66 #define ADP8860_DEVID(x) ((x) & 0xF)
67 #define ADP8860_MANID(x) ((x) >> 4)
69 /* MDCR Device mode and status */
70 #define INT_CFG (1 << 6)
71 #define NSTBY (1 << 5)
72 #define DIM_EN (1 << 4)
73 #define SIS_EN (1 << 2)
74 #define CMP_AUTOEN (1 << 1)
77 /* ADP8860_CCFG Main ALS comparator level enable */
78 #define L3_EN (1 << 1)
79 #define L2_EN (1 << 0)
81 #define CFGR_BLV_SHIFT 3
82 #define CFGR_BLV_MASK 0x3
83 #define ADP8860_FLAG_LED_MASK 0xFF
85 #define FADE_VAL(in, out) ((0xF & (in)) | ((0xF & (out)) << 4))
86 #define BL_CFGR_VAL(law, blv) ((((blv) & CFGR_BLV_MASK) << CFGR_BLV_SHIFT) | ((0x3 & (law)) << 1))
87 #define ALS_CCFG_VAL(filt) ((0x7 & filt) << 5)
90 struct led_classdev cdev
;
91 struct work_struct work
;
92 struct i2c_client
*client
;
93 enum led_brightness new_brightness
;
99 struct i2c_client
*client
;
100 struct backlight_device
*bl
;
101 struct adp8860_led
*led
;
102 struct adp8860_backlight_platform_data
*pdata
;
104 unsigned long cached_daylight_max
;
107 int current_brightness
;
110 static int adp8860_read(struct i2c_client
*client
, int reg
, uint8_t *val
)
114 ret
= i2c_smbus_read_byte_data(client
, reg
);
116 dev_err(&client
->dev
, "failed reading at 0x%02x\n", reg
);
125 static int adp8860_write(struct i2c_client
*client
, u8 reg
, u8 val
)
127 return i2c_smbus_write_byte_data(client
, reg
, val
);
130 static int adp8860_set_bits(struct i2c_client
*client
, int reg
, uint8_t bit_mask
)
132 struct adp8860_bl
*data
= i2c_get_clientdata(client
);
136 mutex_lock(&data
->lock
);
138 ret
= adp8860_read(client
, reg
, ®_val
);
140 if (!ret
&& ((reg_val
& bit_mask
) == 0)) {
142 ret
= adp8860_write(client
, reg
, reg_val
);
145 mutex_unlock(&data
->lock
);
149 static int adp8860_clr_bits(struct i2c_client
*client
, int reg
, uint8_t bit_mask
)
151 struct adp8860_bl
*data
= i2c_get_clientdata(client
);
155 mutex_lock(&data
->lock
);
157 ret
= adp8860_read(client
, reg
, ®_val
);
159 if (!ret
&& (reg_val
& bit_mask
)) {
160 reg_val
&= ~bit_mask
;
161 ret
= adp8860_write(client
, reg
, reg_val
);
164 mutex_unlock(&data
->lock
);
169 * Independent sink / LED
171 #if defined(ADP8860_USE_LEDS)
172 static void adp8860_led_work(struct work_struct
*work
)
174 struct adp8860_led
*led
= container_of(work
, struct adp8860_led
, work
);
175 adp8860_write(led
->client
, ADP8860_ISC1
- led
->id
+ 1,
176 led
->new_brightness
>> 1);
179 static void adp8860_led_set(struct led_classdev
*led_cdev
,
180 enum led_brightness value
)
182 struct adp8860_led
*led
;
184 led
= container_of(led_cdev
, struct adp8860_led
, cdev
);
185 led
->new_brightness
= value
;
186 schedule_work(&led
->work
);
189 static int adp8860_led_setup(struct adp8860_led
*led
)
191 struct i2c_client
*client
= led
->client
;
194 ret
= adp8860_write(client
, ADP8860_ISC1
- led
->id
+ 1, 0);
195 ret
|= adp8860_set_bits(client
, ADP8860_ISCC
, 1 << (led
->id
- 1));
198 ret
|= adp8860_set_bits(client
, ADP8860_ISCT1
,
199 (led
->flags
& 0x3) << ((led
->id
- 5) * 2));
201 ret
|= adp8860_set_bits(client
, ADP8860_ISCT2
,
202 (led
->flags
& 0x3) << ((led
->id
- 1) * 2));
207 static int __devinit
adp8860_led_probe(struct i2c_client
*client
)
209 struct adp8860_backlight_platform_data
*pdata
=
210 client
->dev
.platform_data
;
211 struct adp8860_bl
*data
= i2c_get_clientdata(client
);
212 struct adp8860_led
*led
, *led_dat
;
213 struct led_info
*cur_led
;
216 led
= kzalloc(sizeof(*led
) * pdata
->num_leds
, GFP_KERNEL
);
218 dev_err(&client
->dev
, "failed to alloc memory\n");
222 ret
= adp8860_write(client
, ADP8860_ISCFR
, pdata
->led_fade_law
);
223 ret
= adp8860_write(client
, ADP8860_ISCT1
,
224 (pdata
->led_on_time
& 0x3) << 6);
225 ret
|= adp8860_write(client
, ADP8860_ISCF
,
226 FADE_VAL(pdata
->led_fade_in
, pdata
->led_fade_out
));
229 dev_err(&client
->dev
, "failed to write\n");
233 for (i
= 0; i
< pdata
->num_leds
; ++i
) {
234 cur_led
= &pdata
->leds
[i
];
237 led_dat
->id
= cur_led
->flags
& ADP8860_FLAG_LED_MASK
;
239 if (led_dat
->id
> 7 || led_dat
->id
< 1) {
240 dev_err(&client
->dev
, "Invalid LED ID %d\n",
245 if (pdata
->bl_led_assign
& (1 << (led_dat
->id
- 1))) {
246 dev_err(&client
->dev
, "LED %d used by Backlight\n",
251 led_dat
->cdev
.name
= cur_led
->name
;
252 led_dat
->cdev
.default_trigger
= cur_led
->default_trigger
;
253 led_dat
->cdev
.brightness_set
= adp8860_led_set
;
254 led_dat
->cdev
.brightness
= LED_OFF
;
255 led_dat
->flags
= cur_led
->flags
>> FLAG_OFFT_SHIFT
;
256 led_dat
->client
= client
;
257 led_dat
->new_brightness
= LED_OFF
;
258 INIT_WORK(&led_dat
->work
, adp8860_led_work
);
260 ret
= led_classdev_register(&client
->dev
, &led_dat
->cdev
);
262 dev_err(&client
->dev
, "failed to register LED %d\n",
267 ret
= adp8860_led_setup(led_dat
);
269 dev_err(&client
->dev
, "failed to write\n");
280 for (i
= i
- 1; i
>= 0; --i
) {
281 led_classdev_unregister(&led
[i
].cdev
);
282 cancel_work_sync(&led
[i
].work
);
291 static int __devexit
adp8860_led_remove(struct i2c_client
*client
)
293 struct adp8860_backlight_platform_data
*pdata
=
294 client
->dev
.platform_data
;
295 struct adp8860_bl
*data
= i2c_get_clientdata(client
);
298 for (i
= 0; i
< pdata
->num_leds
; i
++) {
299 led_classdev_unregister(&data
->led
[i
].cdev
);
300 cancel_work_sync(&data
->led
[i
].work
);
307 static int __devinit
adp8860_led_probe(struct i2c_client
*client
)
312 static int __devexit
adp8860_led_remove(struct i2c_client
*client
)
318 static int adp8860_bl_set(struct backlight_device
*bl
, int brightness
)
320 struct adp8860_bl
*data
= bl_get_data(bl
);
321 struct i2c_client
*client
= data
->client
;
324 if (data
->pdata
->en_ambl_sens
) {
325 if ((brightness
> 0) && (brightness
< ADP8860_MAX_BRIGHTNESS
)) {
326 /* Disable Ambient Light auto adjust */
327 ret
|= adp8860_clr_bits(client
, ADP8860_MDCR
,
329 ret
|= adp8860_write(client
, ADP8860_BLMX1
, brightness
);
332 * MAX_BRIGHTNESS -> Enable Ambient Light auto adjust
333 * restore daylight l1 sysfs brightness
335 ret
|= adp8860_write(client
, ADP8860_BLMX1
,
336 data
->cached_daylight_max
);
337 ret
|= adp8860_set_bits(client
, ADP8860_MDCR
,
341 ret
|= adp8860_write(client
, ADP8860_BLMX1
, brightness
);
343 if (data
->current_brightness
&& brightness
== 0)
344 ret
|= adp8860_set_bits(client
,
345 ADP8860_MDCR
, DIM_EN
);
346 else if (data
->current_brightness
== 0 && brightness
)
347 ret
|= adp8860_clr_bits(client
,
348 ADP8860_MDCR
, DIM_EN
);
351 data
->current_brightness
= brightness
;
356 static int adp8860_bl_update_status(struct backlight_device
*bl
)
358 int brightness
= bl
->props
.brightness
;
359 if (bl
->props
.power
!= FB_BLANK_UNBLANK
)
362 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
365 return adp8860_bl_set(bl
, brightness
);
368 static int adp8860_bl_get_brightness(struct backlight_device
*bl
)
370 struct adp8860_bl
*data
= bl_get_data(bl
);
372 return data
->current_brightness
;
375 static const struct backlight_ops adp8860_bl_ops
= {
376 .update_status
= adp8860_bl_update_status
,
377 .get_brightness
= adp8860_bl_get_brightness
,
380 static int adp8860_bl_setup(struct backlight_device
*bl
)
382 struct adp8860_bl
*data
= bl_get_data(bl
);
383 struct i2c_client
*client
= data
->client
;
384 struct adp8860_backlight_platform_data
*pdata
= data
->pdata
;
387 ret
|= adp8860_write(client
, ADP8860_BLSEN
, ~pdata
->bl_led_assign
);
388 ret
|= adp8860_write(client
, ADP8860_BLMX1
, pdata
->l1_daylight_max
);
389 ret
|= adp8860_write(client
, ADP8860_BLDM1
, pdata
->l1_daylight_dim
);
391 if (pdata
->en_ambl_sens
) {
392 data
->cached_daylight_max
= pdata
->l1_daylight_max
;
393 ret
|= adp8860_write(client
, ADP8860_BLMX2
,
394 pdata
->l2_office_max
);
395 ret
|= adp8860_write(client
, ADP8860_BLDM2
,
396 pdata
->l2_office_dim
);
397 ret
|= adp8860_write(client
, ADP8860_BLMX3
,
399 ret
|= adp8860_write(client
, ADP8860_BLDM3
,
402 ret
|= adp8860_write(client
, ADP8860_L2_TRP
, pdata
->l2_trip
);
403 ret
|= adp8860_write(client
, ADP8860_L2_HYS
, pdata
->l2_hyst
);
404 ret
|= adp8860_write(client
, ADP8860_L3_TRP
, pdata
->l3_trip
);
405 ret
|= adp8860_write(client
, ADP8860_L3_HYS
, pdata
->l3_hyst
);
406 ret
|= adp8860_write(client
, ADP8860_CCFG
, L2_EN
| L3_EN
|
407 ALS_CCFG_VAL(pdata
->abml_filt
));
410 ret
|= adp8860_write(client
, ADP8860_CFGR
,
411 BL_CFGR_VAL(pdata
->bl_fade_law
, 0));
413 ret
|= adp8860_write(client
, ADP8860_BLFR
, FADE_VAL(pdata
->bl_fade_in
,
414 pdata
->bl_fade_out
));
416 ret
|= adp8860_set_bits(client
, ADP8860_MDCR
, BLEN
| DIM_EN
| NSTBY
);
421 static ssize_t
adp8860_show(struct device
*dev
, char *buf
, int reg
)
423 struct adp8860_bl
*data
= dev_get_drvdata(dev
);
427 mutex_lock(&data
->lock
);
428 error
= adp8860_read(data
->client
, reg
, ®_val
);
429 mutex_unlock(&data
->lock
);
434 return sprintf(buf
, "%u\n", reg_val
);
437 static ssize_t
adp8860_store(struct device
*dev
, const char *buf
,
438 size_t count
, int reg
)
440 struct adp8860_bl
*data
= dev_get_drvdata(dev
);
444 ret
= strict_strtoul(buf
, 10, &val
);
448 mutex_lock(&data
->lock
);
449 adp8860_write(data
->client
, reg
, val
);
450 mutex_unlock(&data
->lock
);
455 static ssize_t
adp8860_bl_l3_dark_max_show(struct device
*dev
,
456 struct device_attribute
*attr
, char *buf
)
458 return adp8860_show(dev
, buf
, ADP8860_BLMX3
);
461 static ssize_t
adp8860_bl_l3_dark_max_store(struct device
*dev
,
462 struct device_attribute
*attr
, const char *buf
, size_t count
)
464 return adp8860_store(dev
, buf
, count
, ADP8860_BLMX3
);
467 static DEVICE_ATTR(l3_dark_max
, 0664, adp8860_bl_l3_dark_max_show
,
468 adp8860_bl_l3_dark_max_store
);
470 static ssize_t
adp8860_bl_l2_office_max_show(struct device
*dev
,
471 struct device_attribute
*attr
, char *buf
)
473 return adp8860_show(dev
, buf
, ADP8860_BLMX2
);
476 static ssize_t
adp8860_bl_l2_office_max_store(struct device
*dev
,
477 struct device_attribute
*attr
, const char *buf
, size_t count
)
479 return adp8860_store(dev
, buf
, count
, ADP8860_BLMX2
);
481 static DEVICE_ATTR(l2_office_max
, 0664, adp8860_bl_l2_office_max_show
,
482 adp8860_bl_l2_office_max_store
);
484 static ssize_t
adp8860_bl_l1_daylight_max_show(struct device
*dev
,
485 struct device_attribute
*attr
, char *buf
)
487 return adp8860_show(dev
, buf
, ADP8860_BLMX1
);
490 static ssize_t
adp8860_bl_l1_daylight_max_store(struct device
*dev
,
491 struct device_attribute
*attr
, const char *buf
, size_t count
)
493 struct adp8860_bl
*data
= dev_get_drvdata(dev
);
495 strict_strtoul(buf
, 10, &data
->cached_daylight_max
);
496 return adp8860_store(dev
, buf
, count
, ADP8860_BLMX1
);
498 static DEVICE_ATTR(l1_daylight_max
, 0664, adp8860_bl_l1_daylight_max_show
,
499 adp8860_bl_l1_daylight_max_store
);
501 static ssize_t
adp8860_bl_l3_dark_dim_show(struct device
*dev
,
502 struct device_attribute
*attr
, char *buf
)
504 return adp8860_show(dev
, buf
, ADP8860_BLDM3
);
507 static ssize_t
adp8860_bl_l3_dark_dim_store(struct device
*dev
,
508 struct device_attribute
*attr
,
509 const char *buf
, size_t count
)
511 return adp8860_store(dev
, buf
, count
, ADP8860_BLDM3
);
513 static DEVICE_ATTR(l3_dark_dim
, 0664, adp8860_bl_l3_dark_dim_show
,
514 adp8860_bl_l3_dark_dim_store
);
516 static ssize_t
adp8860_bl_l2_office_dim_show(struct device
*dev
,
517 struct device_attribute
*attr
, char *buf
)
519 return adp8860_show(dev
, buf
, ADP8860_BLDM2
);
522 static ssize_t
adp8860_bl_l2_office_dim_store(struct device
*dev
,
523 struct device_attribute
*attr
,
524 const char *buf
, size_t count
)
526 return adp8860_store(dev
, buf
, count
, ADP8860_BLDM2
);
528 static DEVICE_ATTR(l2_office_dim
, 0664, adp8860_bl_l2_office_dim_show
,
529 adp8860_bl_l2_office_dim_store
);
531 static ssize_t
adp8860_bl_l1_daylight_dim_show(struct device
*dev
,
532 struct device_attribute
*attr
, char *buf
)
534 return adp8860_show(dev
, buf
, ADP8860_BLDM1
);
537 static ssize_t
adp8860_bl_l1_daylight_dim_store(struct device
*dev
,
538 struct device_attribute
*attr
,
539 const char *buf
, size_t count
)
541 return adp8860_store(dev
, buf
, count
, ADP8860_BLDM1
);
543 static DEVICE_ATTR(l1_daylight_dim
, 0664, adp8860_bl_l1_daylight_dim_show
,
544 adp8860_bl_l1_daylight_dim_store
);
546 #ifdef ADP8860_EXT_FEATURES
547 static ssize_t
adp8860_bl_ambient_light_level_show(struct device
*dev
,
548 struct device_attribute
*attr
, char *buf
)
550 struct adp8860_bl
*data
= dev_get_drvdata(dev
);
555 mutex_lock(&data
->lock
);
556 error
= adp8860_read(data
->client
, ADP8860_PH1LEVL
, ®_val
);
558 error
|= adp8860_read(data
->client
, ADP8860_PH1LEVH
, ®_val
);
559 mutex_unlock(&data
->lock
);
564 /* Return 13-bit conversion value for the first light sensor */
565 ret_val
+= (reg_val
& 0x1F) << 8;
567 return sprintf(buf
, "%u\n", ret_val
);
569 static DEVICE_ATTR(ambient_light_level
, 0444,
570 adp8860_bl_ambient_light_level_show
, NULL
);
572 static ssize_t
adp8860_bl_ambient_light_zone_show(struct device
*dev
,
573 struct device_attribute
*attr
, char *buf
)
575 struct adp8860_bl
*data
= dev_get_drvdata(dev
);
579 mutex_lock(&data
->lock
);
580 error
= adp8860_read(data
->client
, ADP8860_CFGR
, ®_val
);
581 mutex_unlock(&data
->lock
);
586 return sprintf(buf
, "%u\n",
587 ((reg_val
>> CFGR_BLV_SHIFT
) & CFGR_BLV_MASK
) + 1);
590 static ssize_t
adp8860_bl_ambient_light_zone_store(struct device
*dev
,
591 struct device_attribute
*attr
,
592 const char *buf
, size_t count
)
594 struct adp8860_bl
*data
= dev_get_drvdata(dev
);
599 ret
= strict_strtoul(buf
, 10, &val
);
604 /* Enable automatic ambient light sensing */
605 adp8860_set_bits(data
->client
, ADP8860_MDCR
, CMP_AUTOEN
);
606 } else if ((val
> 0) && (val
< 6)) {
607 /* Disable automatic ambient light sensing */
608 adp8860_clr_bits(data
->client
, ADP8860_MDCR
, CMP_AUTOEN
);
610 /* Set user supplied ambient light zone */
611 mutex_lock(&data
->lock
);
612 adp8860_read(data
->client
, ADP8860_CFGR
, ®_val
);
613 reg_val
&= ~(CFGR_BLV_MASK
<< CFGR_BLV_SHIFT
);
614 reg_val
|= val
<< CFGR_BLV_SHIFT
;
615 adp8860_write(data
->client
, ADP8860_CFGR
, reg_val
);
616 mutex_unlock(&data
->lock
);
621 static DEVICE_ATTR(ambient_light_zone
, 0664,
622 adp8860_bl_ambient_light_zone_show
,
623 adp8860_bl_ambient_light_zone_store
);
626 static struct attribute
*adp8860_bl_attributes
[] = {
627 &dev_attr_l3_dark_max
.attr
,
628 &dev_attr_l3_dark_dim
.attr
,
629 &dev_attr_l2_office_max
.attr
,
630 &dev_attr_l2_office_dim
.attr
,
631 &dev_attr_l1_daylight_max
.attr
,
632 &dev_attr_l1_daylight_dim
.attr
,
633 #ifdef ADP8860_EXT_FEATURES
634 &dev_attr_ambient_light_level
.attr
,
635 &dev_attr_ambient_light_zone
.attr
,
640 static const struct attribute_group adp8860_bl_attr_group
= {
641 .attrs
= adp8860_bl_attributes
,
644 static int __devinit
adp8860_probe(struct i2c_client
*client
,
645 const struct i2c_device_id
*id
)
647 struct backlight_device
*bl
;
648 struct adp8860_bl
*data
;
649 struct adp8860_backlight_platform_data
*pdata
=
650 client
->dev
.platform_data
;
651 struct backlight_properties props
;
655 if (!i2c_check_functionality(client
->adapter
,
656 I2C_FUNC_SMBUS_BYTE_DATA
)) {
657 dev_err(&client
->dev
, "SMBUS Byte Data not Supported\n");
662 dev_err(&client
->dev
, "no platform data?\n");
666 ret
= adp8860_read(client
, ADP8860_MFDVID
, ®_val
);
670 if (ADP8860_MANID(reg_val
) != ADP8860_MANUFID
) {
671 dev_err(&client
->dev
, "failed to probe\n");
675 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
679 /* It's confirmed that the DEVID field is actually a REVID */
681 data
->revid
= ADP8860_DEVID(reg_val
);
682 data
->client
= client
;
684 data
->id
= id
->driver_data
;
685 data
->current_brightness
= 0;
686 i2c_set_clientdata(client
, data
);
688 memset(&props
, 0, sizeof(props
));
689 props
.max_brightness
= ADP8860_MAX_BRIGHTNESS
;
691 mutex_init(&data
->lock
);
693 bl
= backlight_device_register(dev_driver_string(&client
->dev
),
694 &client
->dev
, data
, &adp8860_bl_ops
, &props
);
696 dev_err(&client
->dev
, "failed to register backlight\n");
701 bl
->props
.max_brightness
=
702 bl
->props
.brightness
= ADP8860_MAX_BRIGHTNESS
;
706 if (pdata
->en_ambl_sens
)
707 ret
= sysfs_create_group(&bl
->dev
.kobj
,
708 &adp8860_bl_attr_group
);
711 dev_err(&client
->dev
, "failed to register sysfs\n");
715 ret
= adp8860_bl_setup(bl
);
721 backlight_update_status(bl
);
723 dev_info(&client
->dev
, "Rev.%d Backlight\n", data
->revid
);
726 adp8860_led_probe(client
);
731 if (data
->pdata
->en_ambl_sens
)
732 sysfs_remove_group(&data
->bl
->dev
.kobj
,
733 &adp8860_bl_attr_group
);
735 backlight_device_unregister(bl
);
737 i2c_set_clientdata(client
, NULL
);
743 static int __devexit
adp8860_remove(struct i2c_client
*client
)
745 struct adp8860_bl
*data
= i2c_get_clientdata(client
);
747 adp8860_clr_bits(client
, ADP8860_MDCR
, NSTBY
);
750 adp8860_led_remove(client
);
752 if (data
->pdata
->en_ambl_sens
)
753 sysfs_remove_group(&data
->bl
->dev
.kobj
,
754 &adp8860_bl_attr_group
);
756 backlight_device_unregister(data
->bl
);
757 i2c_set_clientdata(client
, NULL
);
764 static int adp8860_i2c_suspend(struct i2c_client
*client
, pm_message_t message
)
766 adp8860_clr_bits(client
, ADP8860_MDCR
, NSTBY
);
771 static int adp8860_i2c_resume(struct i2c_client
*client
)
773 adp8860_set_bits(client
, ADP8860_MDCR
, NSTBY
);
778 #define adp8860_i2c_suspend NULL
779 #define adp8860_i2c_resume NULL
782 static const struct i2c_device_id adp8860_id
[] = {
786 MODULE_DEVICE_TABLE(i2c
, adp8860_id
);
788 static struct i2c_driver adp8860_driver
= {
790 .name
= KBUILD_MODNAME
,
792 .probe
= adp8860_probe
,
793 .remove
= __devexit_p(adp8860_remove
),
794 .suspend
= adp8860_i2c_suspend
,
795 .resume
= adp8860_i2c_resume
,
796 .id_table
= adp8860_id
,
799 static int __init
adp8860_init(void)
801 return i2c_add_driver(&adp8860_driver
);
803 module_init(adp8860_init
);
805 static void __exit
adp8860_exit(void)
807 i2c_del_driver(&adp8860_driver
);
809 module_exit(adp8860_exit
);
811 MODULE_LICENSE("GPL v2");
812 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
813 MODULE_DESCRIPTION("ADP8860 Backlight driver");
814 MODULE_ALIAS("i2c:adp8860-backlight");