Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 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> |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 10 | #include <linux/init.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/pm.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/i2c.h> |
| 15 | #include <linux/fb.h> |
| 16 | #include <linux/backlight.h> |
| 17 | #include <linux/leds.h> |
Randy Dunlap | 3f43f8b | 2010-05-12 13:49:12 -0700 | [diff] [blame] | 18 | #include <linux/slab.h> |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 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 */ |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 64 | #define ADP8861_MANUFID 0x4 /* Analog Devices ADP8861 Manufacturer ID */ |
| 65 | #define ADP8863_MANUFID 0x2 /* Analog Devices ADP8863 Manufacturer ID */ |
| 66 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 67 | #define ADP8860_DEVID(x) ((x) & 0xF) |
| 68 | #define ADP8860_MANID(x) ((x) >> 4) |
| 69 | |
| 70 | /* MDCR Device mode and status */ |
| 71 | #define INT_CFG (1 << 6) |
| 72 | #define NSTBY (1 << 5) |
| 73 | #define DIM_EN (1 << 4) |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 74 | #define GDWN_DIS (1 << 3) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 75 | #define SIS_EN (1 << 2) |
| 76 | #define CMP_AUTOEN (1 << 1) |
| 77 | #define BLEN (1 << 0) |
| 78 | |
| 79 | /* ADP8860_CCFG Main ALS comparator level enable */ |
| 80 | #define L3_EN (1 << 1) |
| 81 | #define L2_EN (1 << 0) |
| 82 | |
| 83 | #define CFGR_BLV_SHIFT 3 |
| 84 | #define CFGR_BLV_MASK 0x3 |
| 85 | #define ADP8860_FLAG_LED_MASK 0xFF |
| 86 | |
| 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) |
| 90 | |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 91 | enum { |
| 92 | adp8860, |
| 93 | adp8861, |
| 94 | adp8863 |
| 95 | }; |
| 96 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 97 | struct adp8860_led { |
| 98 | struct led_classdev cdev; |
| 99 | struct work_struct work; |
| 100 | struct i2c_client *client; |
| 101 | enum led_brightness new_brightness; |
| 102 | int id; |
| 103 | int flags; |
| 104 | }; |
| 105 | |
| 106 | struct adp8860_bl { |
| 107 | struct i2c_client *client; |
| 108 | struct backlight_device *bl; |
| 109 | struct adp8860_led *led; |
| 110 | struct adp8860_backlight_platform_data *pdata; |
| 111 | struct mutex lock; |
| 112 | unsigned long cached_daylight_max; |
| 113 | int id; |
| 114 | int revid; |
| 115 | int current_brightness; |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 116 | unsigned en_ambl_sens:1; |
| 117 | unsigned gdwn_dis:1; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | static int adp8860_read(struct i2c_client *client, int reg, uint8_t *val) |
| 121 | { |
| 122 | int ret; |
| 123 | |
| 124 | ret = i2c_smbus_read_byte_data(client, reg); |
| 125 | if (ret < 0) { |
| 126 | dev_err(&client->dev, "failed reading at 0x%02x\n", reg); |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | *val = (uint8_t)ret; |
| 131 | return 0; |
| 132 | } |
| 133 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 134 | static int adp8860_write(struct i2c_client *client, u8 reg, u8 val) |
| 135 | { |
| 136 | return i2c_smbus_write_byte_data(client, reg, val); |
| 137 | } |
| 138 | |
| 139 | static int adp8860_set_bits(struct i2c_client *client, int reg, uint8_t bit_mask) |
| 140 | { |
| 141 | struct adp8860_bl *data = i2c_get_clientdata(client); |
| 142 | uint8_t reg_val; |
| 143 | int ret; |
| 144 | |
| 145 | mutex_lock(&data->lock); |
| 146 | |
| 147 | ret = adp8860_read(client, reg, ®_val); |
| 148 | |
Axel Lin | 36c3e75 | 2012-01-20 14:34:05 -0800 | [diff] [blame] | 149 | if (!ret && ((reg_val & bit_mask) != bit_mask)) { |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 150 | reg_val |= bit_mask; |
| 151 | ret = adp8860_write(client, reg, reg_val); |
| 152 | } |
| 153 | |
| 154 | mutex_unlock(&data->lock); |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | static int adp8860_clr_bits(struct i2c_client *client, int reg, uint8_t bit_mask) |
| 159 | { |
| 160 | struct adp8860_bl *data = i2c_get_clientdata(client); |
| 161 | uint8_t reg_val; |
| 162 | int ret; |
| 163 | |
| 164 | mutex_lock(&data->lock); |
| 165 | |
| 166 | ret = adp8860_read(client, reg, ®_val); |
| 167 | |
| 168 | if (!ret && (reg_val & bit_mask)) { |
| 169 | reg_val &= ~bit_mask; |
| 170 | ret = adp8860_write(client, reg, reg_val); |
| 171 | } |
| 172 | |
| 173 | mutex_unlock(&data->lock); |
| 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Independent sink / LED |
| 179 | */ |
| 180 | #if defined(ADP8860_USE_LEDS) |
| 181 | static void adp8860_led_work(struct work_struct *work) |
| 182 | { |
| 183 | struct adp8860_led *led = container_of(work, struct adp8860_led, work); |
Jingoo Han | 5e548f0 | 2014-08-27 10:09:52 +0900 | [diff] [blame] | 184 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 185 | adp8860_write(led->client, ADP8860_ISC1 - led->id + 1, |
| 186 | led->new_brightness >> 1); |
| 187 | } |
| 188 | |
| 189 | static void adp8860_led_set(struct led_classdev *led_cdev, |
| 190 | enum led_brightness value) |
| 191 | { |
| 192 | struct adp8860_led *led; |
| 193 | |
| 194 | led = container_of(led_cdev, struct adp8860_led, cdev); |
| 195 | led->new_brightness = value; |
| 196 | schedule_work(&led->work); |
| 197 | } |
| 198 | |
| 199 | static int adp8860_led_setup(struct adp8860_led *led) |
| 200 | { |
| 201 | struct i2c_client *client = led->client; |
| 202 | int ret = 0; |
| 203 | |
| 204 | ret = adp8860_write(client, ADP8860_ISC1 - led->id + 1, 0); |
| 205 | ret |= adp8860_set_bits(client, ADP8860_ISCC, 1 << (led->id - 1)); |
| 206 | |
| 207 | if (led->id > 4) |
| 208 | ret |= adp8860_set_bits(client, ADP8860_ISCT1, |
| 209 | (led->flags & 0x3) << ((led->id - 5) * 2)); |
| 210 | else |
| 211 | ret |= adp8860_set_bits(client, ADP8860_ISCT2, |
| 212 | (led->flags & 0x3) << ((led->id - 1) * 2)); |
| 213 | |
| 214 | return ret; |
| 215 | } |
| 216 | |
Bill Pemberton | 1b9e450 | 2012-11-19 13:21:46 -0500 | [diff] [blame] | 217 | static int adp8860_led_probe(struct i2c_client *client) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 218 | { |
| 219 | struct adp8860_backlight_platform_data *pdata = |
Jingoo Han | c512794c | 2013-11-12 15:09:04 -0800 | [diff] [blame] | 220 | dev_get_platdata(&client->dev); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 221 | struct adp8860_bl *data = i2c_get_clientdata(client); |
| 222 | struct adp8860_led *led, *led_dat; |
| 223 | struct led_info *cur_led; |
| 224 | int ret, i; |
| 225 | |
Jingoo Han | 58875ea | 2012-05-29 15:07:21 -0700 | [diff] [blame] | 226 | led = devm_kzalloc(&client->dev, sizeof(*led) * pdata->num_leds, |
| 227 | GFP_KERNEL); |
Jingoo Han | ba464d0 | 2014-04-03 14:48:57 -0700 | [diff] [blame] | 228 | if (led == NULL) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 229 | return -ENOMEM; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 230 | |
| 231 | ret = adp8860_write(client, ADP8860_ISCFR, pdata->led_fade_law); |
| 232 | ret = adp8860_write(client, ADP8860_ISCT1, |
| 233 | (pdata->led_on_time & 0x3) << 6); |
| 234 | ret |= adp8860_write(client, ADP8860_ISCF, |
| 235 | FADE_VAL(pdata->led_fade_in, pdata->led_fade_out)); |
| 236 | |
| 237 | if (ret) { |
| 238 | dev_err(&client->dev, "failed to write\n"); |
Jingoo Han | 58875ea | 2012-05-29 15:07:21 -0700 | [diff] [blame] | 239 | return ret; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | for (i = 0; i < pdata->num_leds; ++i) { |
| 243 | cur_led = &pdata->leds[i]; |
| 244 | led_dat = &led[i]; |
| 245 | |
| 246 | led_dat->id = cur_led->flags & ADP8860_FLAG_LED_MASK; |
| 247 | |
| 248 | if (led_dat->id > 7 || led_dat->id < 1) { |
| 249 | dev_err(&client->dev, "Invalid LED ID %d\n", |
| 250 | led_dat->id); |
Wei Yongjun | 84eba9e | 2013-04-29 16:17:53 -0700 | [diff] [blame] | 251 | ret = -EINVAL; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 252 | goto err; |
| 253 | } |
| 254 | |
| 255 | if (pdata->bl_led_assign & (1 << (led_dat->id - 1))) { |
| 256 | dev_err(&client->dev, "LED %d used by Backlight\n", |
| 257 | led_dat->id); |
Wei Yongjun | 84eba9e | 2013-04-29 16:17:53 -0700 | [diff] [blame] | 258 | ret = -EBUSY; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 259 | goto err; |
| 260 | } |
| 261 | |
| 262 | led_dat->cdev.name = cur_led->name; |
| 263 | led_dat->cdev.default_trigger = cur_led->default_trigger; |
| 264 | led_dat->cdev.brightness_set = adp8860_led_set; |
| 265 | led_dat->cdev.brightness = LED_OFF; |
| 266 | led_dat->flags = cur_led->flags >> FLAG_OFFT_SHIFT; |
| 267 | led_dat->client = client; |
| 268 | led_dat->new_brightness = LED_OFF; |
| 269 | INIT_WORK(&led_dat->work, adp8860_led_work); |
| 270 | |
| 271 | ret = led_classdev_register(&client->dev, &led_dat->cdev); |
| 272 | if (ret) { |
| 273 | dev_err(&client->dev, "failed to register LED %d\n", |
| 274 | led_dat->id); |
| 275 | goto err; |
| 276 | } |
| 277 | |
| 278 | ret = adp8860_led_setup(led_dat); |
| 279 | if (ret) { |
| 280 | dev_err(&client->dev, "failed to write\n"); |
| 281 | i++; |
| 282 | goto err; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | data->led = led; |
| 287 | |
| 288 | return 0; |
| 289 | |
| 290 | err: |
| 291 | for (i = i - 1; i >= 0; --i) { |
| 292 | led_classdev_unregister(&led[i].cdev); |
| 293 | cancel_work_sync(&led[i].work); |
| 294 | } |
| 295 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 296 | return ret; |
| 297 | } |
| 298 | |
Bill Pemberton | 7e4b9d0 | 2012-11-19 13:26:34 -0500 | [diff] [blame] | 299 | static int adp8860_led_remove(struct i2c_client *client) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 300 | { |
| 301 | struct adp8860_backlight_platform_data *pdata = |
Jingoo Han | c512794c | 2013-11-12 15:09:04 -0800 | [diff] [blame] | 302 | dev_get_platdata(&client->dev); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 303 | struct adp8860_bl *data = i2c_get_clientdata(client); |
| 304 | int i; |
| 305 | |
| 306 | for (i = 0; i < pdata->num_leds; i++) { |
| 307 | led_classdev_unregister(&data->led[i].cdev); |
| 308 | cancel_work_sync(&data->led[i].work); |
| 309 | } |
| 310 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | #else |
Bill Pemberton | 1b9e450 | 2012-11-19 13:21:46 -0500 | [diff] [blame] | 314 | static int adp8860_led_probe(struct i2c_client *client) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 315 | { |
| 316 | return 0; |
| 317 | } |
| 318 | |
Bill Pemberton | 7e4b9d0 | 2012-11-19 13:26:34 -0500 | [diff] [blame] | 319 | static int adp8860_led_remove(struct i2c_client *client) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 320 | { |
| 321 | return 0; |
| 322 | } |
| 323 | #endif |
| 324 | |
| 325 | static int adp8860_bl_set(struct backlight_device *bl, int brightness) |
| 326 | { |
| 327 | struct adp8860_bl *data = bl_get_data(bl); |
| 328 | struct i2c_client *client = data->client; |
| 329 | int ret = 0; |
| 330 | |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 331 | if (data->en_ambl_sens) { |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 332 | if ((brightness > 0) && (brightness < ADP8860_MAX_BRIGHTNESS)) { |
| 333 | /* Disable Ambient Light auto adjust */ |
| 334 | ret |= adp8860_clr_bits(client, ADP8860_MDCR, |
| 335 | CMP_AUTOEN); |
| 336 | ret |= adp8860_write(client, ADP8860_BLMX1, brightness); |
| 337 | } else { |
| 338 | /* |
| 339 | * MAX_BRIGHTNESS -> Enable Ambient Light auto adjust |
| 340 | * restore daylight l1 sysfs brightness |
| 341 | */ |
| 342 | ret |= adp8860_write(client, ADP8860_BLMX1, |
| 343 | data->cached_daylight_max); |
| 344 | ret |= adp8860_set_bits(client, ADP8860_MDCR, |
| 345 | CMP_AUTOEN); |
| 346 | } |
| 347 | } else |
| 348 | ret |= adp8860_write(client, ADP8860_BLMX1, brightness); |
| 349 | |
| 350 | if (data->current_brightness && brightness == 0) |
| 351 | ret |= adp8860_set_bits(client, |
| 352 | ADP8860_MDCR, DIM_EN); |
| 353 | else if (data->current_brightness == 0 && brightness) |
| 354 | ret |= adp8860_clr_bits(client, |
| 355 | ADP8860_MDCR, DIM_EN); |
| 356 | |
| 357 | if (!ret) |
| 358 | data->current_brightness = brightness; |
| 359 | |
| 360 | return ret; |
| 361 | } |
| 362 | |
| 363 | static int adp8860_bl_update_status(struct backlight_device *bl) |
| 364 | { |
| 365 | int brightness = bl->props.brightness; |
Jingoo Han | 5e548f0 | 2014-08-27 10:09:52 +0900 | [diff] [blame] | 366 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 367 | if (bl->props.power != FB_BLANK_UNBLANK) |
| 368 | brightness = 0; |
| 369 | |
| 370 | if (bl->props.fb_blank != FB_BLANK_UNBLANK) |
| 371 | brightness = 0; |
| 372 | |
| 373 | return adp8860_bl_set(bl, brightness); |
| 374 | } |
| 375 | |
| 376 | static int adp8860_bl_get_brightness(struct backlight_device *bl) |
| 377 | { |
| 378 | struct adp8860_bl *data = bl_get_data(bl); |
| 379 | |
| 380 | return data->current_brightness; |
| 381 | } |
| 382 | |
| 383 | static const struct backlight_ops adp8860_bl_ops = { |
| 384 | .update_status = adp8860_bl_update_status, |
| 385 | .get_brightness = adp8860_bl_get_brightness, |
| 386 | }; |
| 387 | |
| 388 | static int adp8860_bl_setup(struct backlight_device *bl) |
| 389 | { |
| 390 | struct adp8860_bl *data = bl_get_data(bl); |
| 391 | struct i2c_client *client = data->client; |
| 392 | struct adp8860_backlight_platform_data *pdata = data->pdata; |
| 393 | int ret = 0; |
| 394 | |
| 395 | ret |= adp8860_write(client, ADP8860_BLSEN, ~pdata->bl_led_assign); |
| 396 | ret |= adp8860_write(client, ADP8860_BLMX1, pdata->l1_daylight_max); |
| 397 | ret |= adp8860_write(client, ADP8860_BLDM1, pdata->l1_daylight_dim); |
| 398 | |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 399 | if (data->en_ambl_sens) { |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 400 | data->cached_daylight_max = pdata->l1_daylight_max; |
| 401 | ret |= adp8860_write(client, ADP8860_BLMX2, |
| 402 | pdata->l2_office_max); |
| 403 | ret |= adp8860_write(client, ADP8860_BLDM2, |
| 404 | pdata->l2_office_dim); |
| 405 | ret |= adp8860_write(client, ADP8860_BLMX3, |
| 406 | pdata->l3_dark_max); |
| 407 | ret |= adp8860_write(client, ADP8860_BLDM3, |
| 408 | pdata->l3_dark_dim); |
| 409 | |
| 410 | ret |= adp8860_write(client, ADP8860_L2_TRP, pdata->l2_trip); |
| 411 | ret |= adp8860_write(client, ADP8860_L2_HYS, pdata->l2_hyst); |
| 412 | ret |= adp8860_write(client, ADP8860_L3_TRP, pdata->l3_trip); |
| 413 | ret |= adp8860_write(client, ADP8860_L3_HYS, pdata->l3_hyst); |
| 414 | ret |= adp8860_write(client, ADP8860_CCFG, L2_EN | L3_EN | |
| 415 | ALS_CCFG_VAL(pdata->abml_filt)); |
| 416 | } |
| 417 | |
| 418 | ret |= adp8860_write(client, ADP8860_CFGR, |
| 419 | BL_CFGR_VAL(pdata->bl_fade_law, 0)); |
| 420 | |
| 421 | ret |= adp8860_write(client, ADP8860_BLFR, FADE_VAL(pdata->bl_fade_in, |
| 422 | pdata->bl_fade_out)); |
| 423 | |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 424 | ret |= adp8860_set_bits(client, ADP8860_MDCR, BLEN | DIM_EN | NSTBY | |
| 425 | (data->gdwn_dis ? GDWN_DIS : 0)); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 426 | |
| 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | static ssize_t adp8860_show(struct device *dev, char *buf, int reg) |
| 431 | { |
| 432 | struct adp8860_bl *data = dev_get_drvdata(dev); |
| 433 | int error; |
| 434 | uint8_t reg_val; |
| 435 | |
| 436 | mutex_lock(&data->lock); |
| 437 | error = adp8860_read(data->client, reg, ®_val); |
| 438 | mutex_unlock(&data->lock); |
| 439 | |
| 440 | if (error < 0) |
| 441 | return error; |
| 442 | |
| 443 | return sprintf(buf, "%u\n", reg_val); |
| 444 | } |
| 445 | |
| 446 | static ssize_t adp8860_store(struct device *dev, const char *buf, |
| 447 | size_t count, int reg) |
| 448 | { |
| 449 | struct adp8860_bl *data = dev_get_drvdata(dev); |
| 450 | unsigned long val; |
| 451 | int ret; |
| 452 | |
Jingoo Han | 8dd9d7f | 2012-05-29 15:07:15 -0700 | [diff] [blame] | 453 | ret = kstrtoul(buf, 10, &val); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 454 | if (ret) |
| 455 | return ret; |
| 456 | |
| 457 | mutex_lock(&data->lock); |
| 458 | adp8860_write(data->client, reg, val); |
| 459 | mutex_unlock(&data->lock); |
| 460 | |
| 461 | return count; |
| 462 | } |
| 463 | |
| 464 | static ssize_t adp8860_bl_l3_dark_max_show(struct device *dev, |
| 465 | struct device_attribute *attr, char *buf) |
| 466 | { |
| 467 | return adp8860_show(dev, buf, ADP8860_BLMX3); |
| 468 | } |
| 469 | |
| 470 | static ssize_t adp8860_bl_l3_dark_max_store(struct device *dev, |
| 471 | struct device_attribute *attr, const char *buf, size_t count) |
| 472 | { |
| 473 | return adp8860_store(dev, buf, count, ADP8860_BLMX3); |
| 474 | } |
| 475 | |
| 476 | static DEVICE_ATTR(l3_dark_max, 0664, adp8860_bl_l3_dark_max_show, |
| 477 | adp8860_bl_l3_dark_max_store); |
| 478 | |
| 479 | static ssize_t adp8860_bl_l2_office_max_show(struct device *dev, |
| 480 | struct device_attribute *attr, char *buf) |
| 481 | { |
| 482 | return adp8860_show(dev, buf, ADP8860_BLMX2); |
| 483 | } |
| 484 | |
| 485 | static ssize_t adp8860_bl_l2_office_max_store(struct device *dev, |
| 486 | struct device_attribute *attr, const char *buf, size_t count) |
| 487 | { |
| 488 | return adp8860_store(dev, buf, count, ADP8860_BLMX2); |
| 489 | } |
| 490 | static DEVICE_ATTR(l2_office_max, 0664, adp8860_bl_l2_office_max_show, |
| 491 | adp8860_bl_l2_office_max_store); |
| 492 | |
| 493 | static ssize_t adp8860_bl_l1_daylight_max_show(struct device *dev, |
| 494 | struct device_attribute *attr, char *buf) |
| 495 | { |
| 496 | return adp8860_show(dev, buf, ADP8860_BLMX1); |
| 497 | } |
| 498 | |
| 499 | static ssize_t adp8860_bl_l1_daylight_max_store(struct device *dev, |
| 500 | struct device_attribute *attr, const char *buf, size_t count) |
| 501 | { |
| 502 | struct adp8860_bl *data = dev_get_drvdata(dev); |
Jingoo Han | 8dd9d7f | 2012-05-29 15:07:15 -0700 | [diff] [blame] | 503 | int ret = kstrtoul(buf, 10, &data->cached_daylight_max); |
Jingoo Han | 5e548f0 | 2014-08-27 10:09:52 +0900 | [diff] [blame] | 504 | |
Michael Hennerich | 4f1aa84 | 2010-11-11 14:05:29 -0800 | [diff] [blame] | 505 | if (ret) |
| 506 | return ret; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 507 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 508 | return adp8860_store(dev, buf, count, ADP8860_BLMX1); |
| 509 | } |
| 510 | static DEVICE_ATTR(l1_daylight_max, 0664, adp8860_bl_l1_daylight_max_show, |
| 511 | adp8860_bl_l1_daylight_max_store); |
| 512 | |
| 513 | static ssize_t adp8860_bl_l3_dark_dim_show(struct device *dev, |
| 514 | struct device_attribute *attr, char *buf) |
| 515 | { |
| 516 | return adp8860_show(dev, buf, ADP8860_BLDM3); |
| 517 | } |
| 518 | |
| 519 | static ssize_t adp8860_bl_l3_dark_dim_store(struct device *dev, |
| 520 | struct device_attribute *attr, |
| 521 | const char *buf, size_t count) |
| 522 | { |
| 523 | return adp8860_store(dev, buf, count, ADP8860_BLDM3); |
| 524 | } |
| 525 | static DEVICE_ATTR(l3_dark_dim, 0664, adp8860_bl_l3_dark_dim_show, |
| 526 | adp8860_bl_l3_dark_dim_store); |
| 527 | |
| 528 | static ssize_t adp8860_bl_l2_office_dim_show(struct device *dev, |
| 529 | struct device_attribute *attr, char *buf) |
| 530 | { |
| 531 | return adp8860_show(dev, buf, ADP8860_BLDM2); |
| 532 | } |
| 533 | |
| 534 | static ssize_t adp8860_bl_l2_office_dim_store(struct device *dev, |
| 535 | struct device_attribute *attr, |
| 536 | const char *buf, size_t count) |
| 537 | { |
| 538 | return adp8860_store(dev, buf, count, ADP8860_BLDM2); |
| 539 | } |
| 540 | static DEVICE_ATTR(l2_office_dim, 0664, adp8860_bl_l2_office_dim_show, |
| 541 | adp8860_bl_l2_office_dim_store); |
| 542 | |
| 543 | static ssize_t adp8860_bl_l1_daylight_dim_show(struct device *dev, |
| 544 | struct device_attribute *attr, char *buf) |
| 545 | { |
| 546 | return adp8860_show(dev, buf, ADP8860_BLDM1); |
| 547 | } |
| 548 | |
| 549 | static ssize_t adp8860_bl_l1_daylight_dim_store(struct device *dev, |
| 550 | struct device_attribute *attr, |
| 551 | const char *buf, size_t count) |
| 552 | { |
| 553 | return adp8860_store(dev, buf, count, ADP8860_BLDM1); |
| 554 | } |
| 555 | static DEVICE_ATTR(l1_daylight_dim, 0664, adp8860_bl_l1_daylight_dim_show, |
| 556 | adp8860_bl_l1_daylight_dim_store); |
| 557 | |
| 558 | #ifdef ADP8860_EXT_FEATURES |
| 559 | static ssize_t adp8860_bl_ambient_light_level_show(struct device *dev, |
| 560 | struct device_attribute *attr, char *buf) |
| 561 | { |
| 562 | struct adp8860_bl *data = dev_get_drvdata(dev); |
| 563 | int error; |
| 564 | uint8_t reg_val; |
| 565 | uint16_t ret_val; |
| 566 | |
| 567 | mutex_lock(&data->lock); |
| 568 | error = adp8860_read(data->client, ADP8860_PH1LEVL, ®_val); |
Arnd Bergmann | 02f22c0 | 2015-11-30 12:24:23 +0100 | [diff] [blame^] | 569 | if (!error) { |
| 570 | ret_val = reg_val; |
| 571 | error = adp8860_read(data->client, ADP8860_PH1LEVH, ®_val); |
| 572 | } |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 573 | mutex_unlock(&data->lock); |
| 574 | |
Arnd Bergmann | 02f22c0 | 2015-11-30 12:24:23 +0100 | [diff] [blame^] | 575 | if (error) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 576 | return error; |
| 577 | |
| 578 | /* Return 13-bit conversion value for the first light sensor */ |
| 579 | ret_val += (reg_val & 0x1F) << 8; |
| 580 | |
| 581 | return sprintf(buf, "%u\n", ret_val); |
| 582 | } |
| 583 | static DEVICE_ATTR(ambient_light_level, 0444, |
| 584 | adp8860_bl_ambient_light_level_show, NULL); |
| 585 | |
| 586 | static ssize_t adp8860_bl_ambient_light_zone_show(struct device *dev, |
| 587 | struct device_attribute *attr, char *buf) |
| 588 | { |
| 589 | struct adp8860_bl *data = dev_get_drvdata(dev); |
| 590 | int error; |
| 591 | uint8_t reg_val; |
| 592 | |
| 593 | mutex_lock(&data->lock); |
| 594 | error = adp8860_read(data->client, ADP8860_CFGR, ®_val); |
| 595 | mutex_unlock(&data->lock); |
| 596 | |
| 597 | if (error < 0) |
| 598 | return error; |
| 599 | |
| 600 | return sprintf(buf, "%u\n", |
| 601 | ((reg_val >> CFGR_BLV_SHIFT) & CFGR_BLV_MASK) + 1); |
| 602 | } |
| 603 | |
| 604 | static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev, |
| 605 | struct device_attribute *attr, |
| 606 | const char *buf, size_t count) |
| 607 | { |
| 608 | struct adp8860_bl *data = dev_get_drvdata(dev); |
| 609 | unsigned long val; |
| 610 | uint8_t reg_val; |
| 611 | int ret; |
| 612 | |
Jingoo Han | 8dd9d7f | 2012-05-29 15:07:15 -0700 | [diff] [blame] | 613 | ret = kstrtoul(buf, 10, &val); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 614 | if (ret) |
| 615 | return ret; |
| 616 | |
| 617 | if (val == 0) { |
| 618 | /* Enable automatic ambient light sensing */ |
| 619 | adp8860_set_bits(data->client, ADP8860_MDCR, CMP_AUTOEN); |
Michael Hennerich | c7ce250 | 2010-11-11 14:05:29 -0800 | [diff] [blame] | 620 | } else if ((val > 0) && (val <= 3)) { |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 621 | /* Disable automatic ambient light sensing */ |
| 622 | adp8860_clr_bits(data->client, ADP8860_MDCR, CMP_AUTOEN); |
| 623 | |
| 624 | /* Set user supplied ambient light zone */ |
| 625 | mutex_lock(&data->lock); |
Arnd Bergmann | 86c68e2 | 2015-11-23 14:44:13 +0100 | [diff] [blame] | 626 | ret = adp8860_read(data->client, ADP8860_CFGR, ®_val); |
| 627 | if (!ret) { |
| 628 | reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); |
| 629 | reg_val |= (val - 1) << CFGR_BLV_SHIFT; |
| 630 | adp8860_write(data->client, ADP8860_CFGR, reg_val); |
| 631 | } |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 632 | mutex_unlock(&data->lock); |
| 633 | } |
| 634 | |
| 635 | return count; |
| 636 | } |
| 637 | static DEVICE_ATTR(ambient_light_zone, 0664, |
| 638 | adp8860_bl_ambient_light_zone_show, |
| 639 | adp8860_bl_ambient_light_zone_store); |
| 640 | #endif |
| 641 | |
| 642 | static struct attribute *adp8860_bl_attributes[] = { |
| 643 | &dev_attr_l3_dark_max.attr, |
| 644 | &dev_attr_l3_dark_dim.attr, |
| 645 | &dev_attr_l2_office_max.attr, |
| 646 | &dev_attr_l2_office_dim.attr, |
| 647 | &dev_attr_l1_daylight_max.attr, |
| 648 | &dev_attr_l1_daylight_dim.attr, |
| 649 | #ifdef ADP8860_EXT_FEATURES |
| 650 | &dev_attr_ambient_light_level.attr, |
| 651 | &dev_attr_ambient_light_zone.attr, |
| 652 | #endif |
| 653 | NULL |
| 654 | }; |
| 655 | |
| 656 | static const struct attribute_group adp8860_bl_attr_group = { |
| 657 | .attrs = adp8860_bl_attributes, |
| 658 | }; |
| 659 | |
Bill Pemberton | 1b9e450 | 2012-11-19 13:21:46 -0500 | [diff] [blame] | 660 | static int adp8860_probe(struct i2c_client *client, |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 661 | const struct i2c_device_id *id) |
| 662 | { |
| 663 | struct backlight_device *bl; |
| 664 | struct adp8860_bl *data; |
| 665 | struct adp8860_backlight_platform_data *pdata = |
Jingoo Han | c512794c | 2013-11-12 15:09:04 -0800 | [diff] [blame] | 666 | dev_get_platdata(&client->dev); |
Randy Dunlap | 3f43f8b | 2010-05-12 13:49:12 -0700 | [diff] [blame] | 667 | struct backlight_properties props; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 668 | uint8_t reg_val; |
| 669 | int ret; |
| 670 | |
| 671 | if (!i2c_check_functionality(client->adapter, |
| 672 | I2C_FUNC_SMBUS_BYTE_DATA)) { |
| 673 | dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); |
| 674 | return -EIO; |
| 675 | } |
| 676 | |
| 677 | if (!pdata) { |
| 678 | dev_err(&client->dev, "no platform data?\n"); |
| 679 | return -EINVAL; |
| 680 | } |
| 681 | |
Jingoo Han | 58875ea | 2012-05-29 15:07:21 -0700 | [diff] [blame] | 682 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 683 | if (data == NULL) |
| 684 | return -ENOMEM; |
| 685 | |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 686 | ret = adp8860_read(client, ADP8860_MFDVID, ®_val); |
| 687 | if (ret < 0) |
Jingoo Han | 58875ea | 2012-05-29 15:07:21 -0700 | [diff] [blame] | 688 | return ret; |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 689 | |
| 690 | switch (ADP8860_MANID(reg_val)) { |
| 691 | case ADP8863_MANUFID: |
| 692 | data->gdwn_dis = !!pdata->gdwn_dis; |
| 693 | case ADP8860_MANUFID: |
| 694 | data->en_ambl_sens = !!pdata->en_ambl_sens; |
| 695 | break; |
| 696 | case ADP8861_MANUFID: |
| 697 | data->gdwn_dis = !!pdata->gdwn_dis; |
| 698 | break; |
| 699 | default: |
| 700 | dev_err(&client->dev, "failed to probe\n"); |
Jingoo Han | 58875ea | 2012-05-29 15:07:21 -0700 | [diff] [blame] | 701 | return -ENODEV; |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 702 | } |
| 703 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 704 | /* It's confirmed that the DEVID field is actually a REVID */ |
| 705 | |
| 706 | data->revid = ADP8860_DEVID(reg_val); |
| 707 | data->client = client; |
| 708 | data->pdata = pdata; |
| 709 | data->id = id->driver_data; |
| 710 | data->current_brightness = 0; |
| 711 | i2c_set_clientdata(client, data); |
| 712 | |
Randy Dunlap | 3f43f8b | 2010-05-12 13:49:12 -0700 | [diff] [blame] | 713 | memset(&props, 0, sizeof(props)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 714 | props.type = BACKLIGHT_RAW; |
Randy Dunlap | 3f43f8b | 2010-05-12 13:49:12 -0700 | [diff] [blame] | 715 | props.max_brightness = ADP8860_MAX_BRIGHTNESS; |
| 716 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 717 | mutex_init(&data->lock); |
| 718 | |
Jingoo Han | 91fa4ee | 2013-11-12 15:09:08 -0800 | [diff] [blame] | 719 | bl = devm_backlight_device_register(&client->dev, |
| 720 | dev_driver_string(&client->dev), |
| 721 | &client->dev, data, &adp8860_bl_ops, &props); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 722 | if (IS_ERR(bl)) { |
| 723 | dev_err(&client->dev, "failed to register backlight\n"); |
Jingoo Han | 58875ea | 2012-05-29 15:07:21 -0700 | [diff] [blame] | 724 | return PTR_ERR(bl); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Axel Lin | 6b19bad | 2011-07-25 17:11:59 -0700 | [diff] [blame] | 727 | bl->props.brightness = ADP8860_MAX_BRIGHTNESS; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 728 | |
| 729 | data->bl = bl; |
| 730 | |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 731 | if (data->en_ambl_sens) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 732 | ret = sysfs_create_group(&bl->dev.kobj, |
| 733 | &adp8860_bl_attr_group); |
| 734 | |
| 735 | if (ret) { |
| 736 | dev_err(&client->dev, "failed to register sysfs\n"); |
Jingoo Han | 91fa4ee | 2013-11-12 15:09:08 -0800 | [diff] [blame] | 737 | return ret; |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | ret = adp8860_bl_setup(bl); |
| 741 | if (ret) { |
| 742 | ret = -EIO; |
| 743 | goto out; |
| 744 | } |
| 745 | |
| 746 | backlight_update_status(bl); |
| 747 | |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 748 | dev_info(&client->dev, "%s Rev.%d Backlight\n", |
| 749 | client->name, data->revid); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 750 | |
| 751 | if (pdata->num_leds) |
| 752 | adp8860_led_probe(client); |
| 753 | |
| 754 | return 0; |
| 755 | |
| 756 | out: |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 757 | if (data->en_ambl_sens) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 758 | sysfs_remove_group(&data->bl->dev.kobj, |
| 759 | &adp8860_bl_attr_group); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 760 | |
| 761 | return ret; |
| 762 | } |
| 763 | |
Bill Pemberton | 7e4b9d0 | 2012-11-19 13:26:34 -0500 | [diff] [blame] | 764 | static int adp8860_remove(struct i2c_client *client) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 765 | { |
| 766 | struct adp8860_bl *data = i2c_get_clientdata(client); |
| 767 | |
| 768 | adp8860_clr_bits(client, ADP8860_MDCR, NSTBY); |
| 769 | |
| 770 | if (data->led) |
| 771 | adp8860_led_remove(client); |
| 772 | |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 773 | if (data->en_ambl_sens) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 774 | sysfs_remove_group(&data->bl->dev.kobj, |
| 775 | &adp8860_bl_attr_group); |
| 776 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 777 | return 0; |
| 778 | } |
| 779 | |
Jingoo Han | cf108b5 | 2013-04-29 16:17:39 -0700 | [diff] [blame] | 780 | #ifdef CONFIG_PM_SLEEP |
| 781 | static int adp8860_i2c_suspend(struct device *dev) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 782 | { |
Jingoo Han | cf108b5 | 2013-04-29 16:17:39 -0700 | [diff] [blame] | 783 | struct i2c_client *client = to_i2c_client(dev); |
| 784 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 785 | adp8860_clr_bits(client, ADP8860_MDCR, NSTBY); |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
Jingoo Han | cf108b5 | 2013-04-29 16:17:39 -0700 | [diff] [blame] | 790 | static int adp8860_i2c_resume(struct device *dev) |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 791 | { |
Jingoo Han | cf108b5 | 2013-04-29 16:17:39 -0700 | [diff] [blame] | 792 | struct i2c_client *client = to_i2c_client(dev); |
| 793 | |
Lars-Peter Clausen | 5eb02c0 | 2013-02-21 16:44:04 -0800 | [diff] [blame] | 794 | adp8860_set_bits(client, ADP8860_MDCR, NSTBY | BLEN); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 795 | |
| 796 | return 0; |
| 797 | } |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 798 | #endif |
| 799 | |
Jingoo Han | cf108b5 | 2013-04-29 16:17:39 -0700 | [diff] [blame] | 800 | static SIMPLE_DEV_PM_OPS(adp8860_i2c_pm_ops, adp8860_i2c_suspend, |
| 801 | adp8860_i2c_resume); |
| 802 | |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 803 | static const struct i2c_device_id adp8860_id[] = { |
Michael Hennerich | c7c06d8 | 2010-05-26 03:00:59 -0400 | [diff] [blame] | 804 | { "adp8860", adp8860 }, |
| 805 | { "adp8861", adp8861 }, |
| 806 | { "adp8863", adp8863 }, |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 807 | { } |
| 808 | }; |
| 809 | MODULE_DEVICE_TABLE(i2c, adp8860_id); |
| 810 | |
| 811 | static struct i2c_driver adp8860_driver = { |
| 812 | .driver = { |
Jingoo Han | cf108b5 | 2013-04-29 16:17:39 -0700 | [diff] [blame] | 813 | .name = KBUILD_MODNAME, |
| 814 | .pm = &adp8860_i2c_pm_ops, |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 815 | }, |
| 816 | .probe = adp8860_probe, |
Bill Pemberton | d1723fa | 2012-11-19 13:21:09 -0500 | [diff] [blame] | 817 | .remove = adp8860_remove, |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 818 | .id_table = adp8860_id, |
| 819 | }; |
| 820 | |
Axel Lin | 81ce686 | 2012-03-23 15:01:59 -0700 | [diff] [blame] | 821 | module_i2c_driver(adp8860_driver); |
Michael Hennerich | 82fd53b | 2010-04-30 14:09:51 -0700 | [diff] [blame] | 822 | |
| 823 | MODULE_LICENSE("GPL v2"); |
| 824 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
| 825 | MODULE_DESCRIPTION("ADP8860 Backlight driver"); |