9 #include <linux/module.h>
11 #include <linux/errno.h>
14 #include <linux/i2c.h>
18 #include <linux/slab.h>
22 #define ADP8860_EXT_FEATURES
23 #define ADP8860_USE_LEDS
25 #define ADP8860_MFDVID 0x00
26 #define ADP8860_MDCR 0x01
27 #define ADP8860_MDCR2 0x02
28 #define ADP8860_INTR_EN 0x03
29 #define ADP8860_CFGR 0x04
30 #define ADP8860_BLSEN 0x05
31 #define ADP8860_BLOFF 0x06
32 #define ADP8860_BLDIM 0x07
33 #define ADP8860_BLFR 0x08
34 #define ADP8860_BLMX1 0x09
35 #define ADP8860_BLDM1 0x0A
36 #define ADP8860_BLMX2 0x0B
37 #define ADP8860_BLDM2 0x0C
38 #define ADP8860_BLMX3 0x0D
39 #define ADP8860_BLDM3 0x0E
40 #define ADP8860_ISCFR 0x0F
41 #define ADP8860_ISCC 0x10
42 #define ADP8860_ISCT1 0x11
43 #define ADP8860_ISCT2 0x12
44 #define ADP8860_ISCF 0x13
45 #define ADP8860_ISC7 0x14
46 #define ADP8860_ISC6 0x15
47 #define ADP8860_ISC5 0x16
48 #define ADP8860_ISC4 0x17
49 #define ADP8860_ISC3 0x18
50 #define ADP8860_ISC2 0x19
51 #define ADP8860_ISC1 0x1A
52 #define ADP8860_CCFG 0x1B
53 #define ADP8860_CCFG2 0x1C
54 #define ADP8860_L2_TRP 0x1D
55 #define ADP8860_L2_HYS 0x1E
56 #define ADP8860_L3_TRP 0x1F
57 #define ADP8860_L3_HYS 0x20
58 #define ADP8860_PH1LEVL 0x21
59 #define ADP8860_PH1LEVH 0x22
60 #define ADP8860_PH2LEVL 0x23
61 #define ADP8860_PH2LEVH 0x24
63 #define ADP8860_MANUFID 0x0
64 #define ADP8861_MANUFID 0x4
65 #define ADP8863_MANUFID 0x2
67 #define ADP8860_DEVID(x) ((x) & 0xF)
68 #define ADP8860_MANID(x) ((x) >> 4)
71 #define INT_CFG (1 << 6)
72 #define NSTBY (1 << 5)
73 #define DIM_EN (1 << 4)
74 #define GDWN_DIS (1 << 3)
75 #define SIS_EN (1 << 2)
76 #define CMP_AUTOEN (1 << 1)
80 #define L3_EN (1 << 1)
81 #define L2_EN (1 << 0)
83 #define CFGR_BLV_SHIFT 3
84 #define CFGR_BLV_MASK 0x3
85 #define ADP8860_FLAG_LED_MASK 0xFF
87 #define FADE_VAL(in, out) ((0xF & (in)) | ((0xF & (out)) << 4))
88 #define BL_CFGR_VAL(law, blv) ((((blv) & CFGR_BLV_MASK) << CFGR_BLV_SHIFT) | ((0x3 & (law)) << 1))
89 #define ALS_CCFG_VAL(filt) ((0x7 & filt) << 5)
126 dev_err(&client->
dev,
"failed reading at 0x%02x\n", reg);
147 ret = adp8860_read(client, reg, ®_val);
149 if (!ret && ((reg_val & bit_mask) != bit_mask)) {
151 ret = adp8860_write(client, reg, reg_val);
158 static int adp8860_clr_bits(
struct i2c_client *client,
int reg,
uint8_t bit_mask)
160 struct adp8860_bl *data = i2c_get_clientdata(client);
166 ret = adp8860_read(client, reg, ®_val);
168 if (!ret && (reg_val & bit_mask)) {
169 reg_val &= ~bit_mask;
170 ret = adp8860_write(client, reg, reg_val);
180 #if defined(ADP8860_USE_LEDS)
188 static void adp8860_led_set(
struct led_classdev *led_cdev,
204 ret |= adp8860_set_bits(client,
ADP8860_ISCC, 1 << (led->
id - 1));
208 (led->
flags & 0x3) << ((led->
id - 5) * 2));
211 (led->
flags & 0x3) << ((led->
id - 1) * 2));
219 client->
dev.platform_data;
220 struct adp8860_bl *data = i2c_get_clientdata(client);
228 dev_err(&client->
dev,
"failed to alloc memory\n");
244 cur_led = &pdata->
leds[
i];
249 if (led_dat->
id > 7 || led_dat->
id < 1) {
256 dev_err(&client->
dev,
"LED %d used by Backlight\n",
263 led_dat->
cdev.brightness_set = adp8860_led_set;
272 dev_err(&client->
dev,
"failed to register LED %d\n",
277 ret = adp8860_led_setup(led_dat);
290 for (i = i - 1; i >= 0; --
i) {
301 client->
dev.platform_data;
302 struct adp8860_bl *data = i2c_get_clientdata(client);
305 for (i = 0; i < pdata->
num_leds; i++) {
350 ret |= adp8860_set_bits(client,
353 ret |= adp8860_clr_bits(client,
364 int brightness = bl->
props.brightness;
371 return adp8860_bl_set(bl, brightness);
382 .update_status = adp8860_bl_update_status,
383 .get_brightness = adp8860_bl_get_brightness,
435 error = adp8860_read(data->
client, reg, ®_val);
441 return sprintf(buf,
"%u\n", reg_val);
444 static ssize_t adp8860_store(
struct device *dev,
const char *buf,
445 size_t count,
int reg)
451 ret = kstrtoul(buf, 10, &val);
456 adp8860_write(data->
client, reg, val);
462 static ssize_t adp8860_bl_l3_dark_max_show(
struct device *dev,
468 static ssize_t adp8860_bl_l3_dark_max_store(
struct device *dev,
474 static DEVICE_ATTR(l3_dark_max, 0664, adp8860_bl_l3_dark_max_show,
475 adp8860_bl_l3_dark_max_store);
477 static ssize_t adp8860_bl_l2_office_max_show(
struct device *dev,
483 static ssize_t adp8860_bl_l2_office_max_store(
struct device *dev,
488 static DEVICE_ATTR(l2_office_max, 0664, adp8860_bl_l2_office_max_show,
489 adp8860_bl_l2_office_max_store);
491 static ssize_t adp8860_bl_l1_daylight_max_show(
struct device *dev,
497 static ssize_t adp8860_bl_l1_daylight_max_store(
struct device *dev,
507 static DEVICE_ATTR(l1_daylight_max, 0664, adp8860_bl_l1_daylight_max_show,
508 adp8860_bl_l1_daylight_max_store);
510 static ssize_t adp8860_bl_l3_dark_dim_show(
struct device *dev,
516 static ssize_t adp8860_bl_l3_dark_dim_store(
struct device *dev,
518 const char *buf,
size_t count)
522 static DEVICE_ATTR(l3_dark_dim, 0664, adp8860_bl_l3_dark_dim_show,
523 adp8860_bl_l3_dark_dim_store);
525 static ssize_t adp8860_bl_l2_office_dim_show(
struct device *dev,
531 static ssize_t adp8860_bl_l2_office_dim_store(
struct device *dev,
533 const char *buf,
size_t count)
537 static DEVICE_ATTR(l2_office_dim, 0664, adp8860_bl_l2_office_dim_show,
538 adp8860_bl_l2_office_dim_store);
540 static ssize_t adp8860_bl_l1_daylight_dim_show(
struct device *dev,
546 static ssize_t adp8860_bl_l1_daylight_dim_store(
struct device *dev,
548 const char *buf,
size_t count)
552 static DEVICE_ATTR(l1_daylight_dim, 0664, adp8860_bl_l1_daylight_dim_show,
553 adp8860_bl_l1_daylight_dim_store);
555 #ifdef ADP8860_EXT_FEATURES
556 static ssize_t adp8860_bl_ambient_light_level_show(
struct device *dev,
574 ret_val += (reg_val & 0x1F) << 8;
576 return sprintf(buf,
"%u\n", ret_val);
579 adp8860_bl_ambient_light_level_show,
NULL);
581 static ssize_t adp8860_bl_ambient_light_zone_show(
struct device *dev,
599 static ssize_t adp8860_bl_ambient_light_zone_store(
struct device *dev,
601 const char *buf,
size_t count)
608 ret = kstrtoul(buf, 10, &val);
615 }
else if ((val > 0) && (val <= 3)) {
631 adp8860_bl_ambient_light_zone_show,
632 adp8860_bl_ambient_light_zone_store);
635 static struct attribute *adp8860_bl_attributes[] = {
636 &dev_attr_l3_dark_max.attr,
637 &dev_attr_l3_dark_dim.attr,
638 &dev_attr_l2_office_max.attr,
639 &dev_attr_l2_office_dim.attr,
640 &dev_attr_l1_daylight_max.attr,
641 &dev_attr_l1_daylight_dim.attr,
642 #ifdef ADP8860_EXT_FEATURES
643 &dev_attr_ambient_light_level.attr,
644 &dev_attr_ambient_light_zone.attr,
650 .attrs = adp8860_bl_attributes,
659 client->
dev.platform_data;
664 if (!i2c_check_functionality(client->
adapter,
666 dev_err(&client->
dev,
"SMBUS Byte Data not Supported\n");
702 data->
id =
id->driver_data;
704 i2c_set_clientdata(client, data);
706 memset(&props, 0,
sizeof(props));
713 &client->
dev, data, &adp8860_bl_ops, &props);
715 dev_err(&client->
dev,
"failed to register backlight\n");
725 &adp8860_bl_attr_group);
728 dev_err(&client->
dev,
"failed to register sysfs\n");
732 ret = adp8860_bl_setup(bl);
738 backlight_update_status(bl);
744 adp8860_led_probe(client);
751 &adp8860_bl_attr_group);
760 struct adp8860_bl *data = i2c_get_clientdata(client);
765 adp8860_led_remove(client);
769 &adp8860_bl_attr_group);
791 #define adp8860_i2c_suspend NULL
792 #define adp8860_i2c_resume NULL
805 .name = KBUILD_MODNAME,
807 .probe = adp8860_probe,
811 .id_table = adp8860_id,