180503b23SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2a59ec1e7SMichael Hennerich /*
3a59ec1e7SMichael Hennerich * Backlight driver for Analog Devices ADP8870 Backlight Devices
4a59ec1e7SMichael Hennerich *
5a59ec1e7SMichael Hennerich * Copyright 2009-2011 Analog Devices Inc.
6a59ec1e7SMichael Hennerich */
7a59ec1e7SMichael Hennerich
8a59ec1e7SMichael Hennerich #include <linux/module.h>
9a59ec1e7SMichael Hennerich #include <linux/init.h>
10a59ec1e7SMichael Hennerich #include <linux/errno.h>
11a59ec1e7SMichael Hennerich #include <linux/pm.h>
12a59ec1e7SMichael Hennerich #include <linux/platform_device.h>
13a59ec1e7SMichael Hennerich #include <linux/i2c.h>
14a59ec1e7SMichael Hennerich #include <linux/fb.h>
15a59ec1e7SMichael Hennerich #include <linux/backlight.h>
16a59ec1e7SMichael Hennerich #include <linux/leds.h>
17a59ec1e7SMichael Hennerich #include <linux/workqueue.h>
18a59ec1e7SMichael Hennerich #include <linux/slab.h>
19a59ec1e7SMichael Hennerich
20056d6ff4SWolfram Sang #include <linux/platform_data/adp8870.h>
21a59ec1e7SMichael Hennerich #define ADP8870_EXT_FEATURES
22a59ec1e7SMichael Hennerich #define ADP8870_USE_LEDS
23a59ec1e7SMichael Hennerich
24a59ec1e7SMichael Hennerich
25a59ec1e7SMichael Hennerich #define ADP8870_MFDVID 0x00 /* Manufacturer and device ID */
26a59ec1e7SMichael Hennerich #define ADP8870_MDCR 0x01 /* Device mode and status */
27a59ec1e7SMichael Hennerich #define ADP8870_INT_STAT 0x02 /* Interrupts status */
28a59ec1e7SMichael Hennerich #define ADP8870_INT_EN 0x03 /* Interrupts enable */
29a59ec1e7SMichael Hennerich #define ADP8870_CFGR 0x04 /* Configuration register */
30a59ec1e7SMichael Hennerich #define ADP8870_BLSEL 0x05 /* Sink enable backlight or independent */
31a59ec1e7SMichael Hennerich #define ADP8870_PWMLED 0x06 /* PWM Enable Selection Register */
32a59ec1e7SMichael Hennerich #define ADP8870_BLOFF 0x07 /* Backlight off timeout */
33a59ec1e7SMichael Hennerich #define ADP8870_BLDIM 0x08 /* Backlight dim timeout */
34a59ec1e7SMichael Hennerich #define ADP8870_BLFR 0x09 /* Backlight fade in and out rates */
35a59ec1e7SMichael Hennerich #define ADP8870_BLMX1 0x0A /* Backlight (Brightness Level 1-daylight) maximum current */
36a59ec1e7SMichael Hennerich #define ADP8870_BLDM1 0x0B /* Backlight (Brightness Level 1-daylight) dim current */
37a59ec1e7SMichael Hennerich #define ADP8870_BLMX2 0x0C /* Backlight (Brightness Level 2-bright) maximum current */
38a59ec1e7SMichael Hennerich #define ADP8870_BLDM2 0x0D /* Backlight (Brightness Level 2-bright) dim current */
39a59ec1e7SMichael Hennerich #define ADP8870_BLMX3 0x0E /* Backlight (Brightness Level 3-office) maximum current */
40a59ec1e7SMichael Hennerich #define ADP8870_BLDM3 0x0F /* Backlight (Brightness Level 3-office) dim current */
41a59ec1e7SMichael Hennerich #define ADP8870_BLMX4 0x10 /* Backlight (Brightness Level 4-indoor) maximum current */
42a59ec1e7SMichael Hennerich #define ADP8870_BLDM4 0x11 /* Backlight (Brightness Level 4-indoor) dim current */
43a59ec1e7SMichael Hennerich #define ADP8870_BLMX5 0x12 /* Backlight (Brightness Level 5-dark) maximum current */
44a59ec1e7SMichael Hennerich #define ADP8870_BLDM5 0x13 /* Backlight (Brightness Level 5-dark) dim current */
45a59ec1e7SMichael Hennerich #define ADP8870_ISCLAW 0x1A /* Independent sink current fade law register */
46a59ec1e7SMichael Hennerich #define ADP8870_ISCC 0x1B /* Independent sink current control register */
47a59ec1e7SMichael Hennerich #define ADP8870_ISCT1 0x1C /* Independent Sink Current Timer Register LED[7:5] */
48a59ec1e7SMichael Hennerich #define ADP8870_ISCT2 0x1D /* Independent Sink Current Timer Register LED[4:1] */
49a59ec1e7SMichael Hennerich #define ADP8870_ISCF 0x1E /* Independent sink current fade register */
50a59ec1e7SMichael Hennerich #define ADP8870_ISC1 0x1F /* Independent Sink Current LED1 */
51a59ec1e7SMichael Hennerich #define ADP8870_ISC2 0x20 /* Independent Sink Current LED2 */
52a59ec1e7SMichael Hennerich #define ADP8870_ISC3 0x21 /* Independent Sink Current LED3 */
53a59ec1e7SMichael Hennerich #define ADP8870_ISC4 0x22 /* Independent Sink Current LED4 */
54a59ec1e7SMichael Hennerich #define ADP8870_ISC5 0x23 /* Independent Sink Current LED5 */
55a59ec1e7SMichael Hennerich #define ADP8870_ISC6 0x24 /* Independent Sink Current LED6 */
56a59ec1e7SMichael Hennerich #define ADP8870_ISC7 0x25 /* Independent Sink Current LED7 (Brightness Level 1-daylight) */
57a59ec1e7SMichael Hennerich #define ADP8870_ISC7_L2 0x26 /* Independent Sink Current LED7 (Brightness Level 2-bright) */
58a59ec1e7SMichael Hennerich #define ADP8870_ISC7_L3 0x27 /* Independent Sink Current LED7 (Brightness Level 3-office) */
59a59ec1e7SMichael Hennerich #define ADP8870_ISC7_L4 0x28 /* Independent Sink Current LED7 (Brightness Level 4-indoor) */
60a59ec1e7SMichael Hennerich #define ADP8870_ISC7_L5 0x29 /* Independent Sink Current LED7 (Brightness Level 5-dark) */
61a59ec1e7SMichael Hennerich #define ADP8870_CMP_CTL 0x2D /* ALS Comparator Control Register */
62a59ec1e7SMichael Hennerich #define ADP8870_ALS1_EN 0x2E /* Main ALS comparator level enable */
63a59ec1e7SMichael Hennerich #define ADP8870_ALS2_EN 0x2F /* Second ALS comparator level enable */
64a59ec1e7SMichael Hennerich #define ADP8870_ALS1_STAT 0x30 /* Main ALS Comparator Status Register */
65a59ec1e7SMichael Hennerich #define ADP8870_ALS2_STAT 0x31 /* Second ALS Comparator Status Register */
66a59ec1e7SMichael Hennerich #define ADP8870_L2TRP 0x32 /* L2 comparator reference */
67a59ec1e7SMichael Hennerich #define ADP8870_L2HYS 0x33 /* L2 hysteresis */
68a59ec1e7SMichael Hennerich #define ADP8870_L3TRP 0x34 /* L3 comparator reference */
69a59ec1e7SMichael Hennerich #define ADP8870_L3HYS 0x35 /* L3 hysteresis */
70a59ec1e7SMichael Hennerich #define ADP8870_L4TRP 0x36 /* L4 comparator reference */
71a59ec1e7SMichael Hennerich #define ADP8870_L4HYS 0x37 /* L4 hysteresis */
72a59ec1e7SMichael Hennerich #define ADP8870_L5TRP 0x38 /* L5 comparator reference */
73a59ec1e7SMichael Hennerich #define ADP8870_L5HYS 0x39 /* L5 hysteresis */
74a59ec1e7SMichael Hennerich #define ADP8870_PH1LEVL 0x40 /* First phototransistor ambient light level-low byte register */
75a59ec1e7SMichael Hennerich #define ADP8870_PH1LEVH 0x41 /* First phototransistor ambient light level-high byte register */
76a59ec1e7SMichael Hennerich #define ADP8870_PH2LEVL 0x42 /* Second phototransistor ambient light level-low byte register */
77a59ec1e7SMichael Hennerich #define ADP8870_PH2LEVH 0x43 /* Second phototransistor ambient light level-high byte register */
78a59ec1e7SMichael Hennerich
79a59ec1e7SMichael Hennerich #define ADP8870_MANUFID 0x3 /* Analog Devices AD8870 Manufacturer and device ID */
80a59ec1e7SMichael Hennerich #define ADP8870_DEVID(x) ((x) & 0xF)
81a59ec1e7SMichael Hennerich #define ADP8870_MANID(x) ((x) >> 4)
82a59ec1e7SMichael Hennerich
83a59ec1e7SMichael Hennerich /* MDCR Device mode and status */
84a59ec1e7SMichael Hennerich #define D7ALSEN (1 << 7)
85a59ec1e7SMichael Hennerich #define INT_CFG (1 << 6)
86a59ec1e7SMichael Hennerich #define NSTBY (1 << 5)
87a59ec1e7SMichael Hennerich #define DIM_EN (1 << 4)
88a59ec1e7SMichael Hennerich #define GDWN_DIS (1 << 3)
89a59ec1e7SMichael Hennerich #define SIS_EN (1 << 2)
90a59ec1e7SMichael Hennerich #define CMP_AUTOEN (1 << 1)
91a59ec1e7SMichael Hennerich #define BLEN (1 << 0)
92a59ec1e7SMichael Hennerich
93a59ec1e7SMichael Hennerich /* ADP8870_ALS1_EN Main ALS comparator level enable */
94a59ec1e7SMichael Hennerich #define L5_EN (1 << 3)
95a59ec1e7SMichael Hennerich #define L4_EN (1 << 2)
96a59ec1e7SMichael Hennerich #define L3_EN (1 << 1)
97a59ec1e7SMichael Hennerich #define L2_EN (1 << 0)
98a59ec1e7SMichael Hennerich
99a59ec1e7SMichael Hennerich #define CFGR_BLV_SHIFT 3
100a59ec1e7SMichael Hennerich #define CFGR_BLV_MASK 0x7
101a59ec1e7SMichael Hennerich #define ADP8870_FLAG_LED_MASK 0xFF
102a59ec1e7SMichael Hennerich
103a59ec1e7SMichael Hennerich #define FADE_VAL(in, out) ((0xF & (in)) | ((0xF & (out)) << 4))
104a59ec1e7SMichael Hennerich #define BL_CFGR_VAL(law, blv) ((((blv) & CFGR_BLV_MASK) << CFGR_BLV_SHIFT) | ((0x3 & (law)) << 1))
105a59ec1e7SMichael Hennerich #define ALS_CMPR_CFG_VAL(filt) ((0x7 & (filt)) << 1)
106a59ec1e7SMichael Hennerich
107a59ec1e7SMichael Hennerich struct adp8870_bl {
108a59ec1e7SMichael Hennerich struct i2c_client *client;
109a59ec1e7SMichael Hennerich struct backlight_device *bl;
110a59ec1e7SMichael Hennerich struct adp8870_led *led;
111a59ec1e7SMichael Hennerich struct adp8870_backlight_platform_data *pdata;
112a59ec1e7SMichael Hennerich struct mutex lock;
113a59ec1e7SMichael Hennerich unsigned long cached_daylight_max;
114a59ec1e7SMichael Hennerich int id;
115a59ec1e7SMichael Hennerich int revid;
116a59ec1e7SMichael Hennerich int current_brightness;
117a59ec1e7SMichael Hennerich };
118a59ec1e7SMichael Hennerich
119a59ec1e7SMichael Hennerich struct adp8870_led {
120a59ec1e7SMichael Hennerich struct led_classdev cdev;
121a59ec1e7SMichael Hennerich struct work_struct work;
122a59ec1e7SMichael Hennerich struct i2c_client *client;
123a59ec1e7SMichael Hennerich enum led_brightness new_brightness;
124a59ec1e7SMichael Hennerich int id;
125a59ec1e7SMichael Hennerich int flags;
126a59ec1e7SMichael Hennerich };
127a59ec1e7SMichael Hennerich
adp8870_read(struct i2c_client * client,int reg,uint8_t * val)128a59ec1e7SMichael Hennerich static int adp8870_read(struct i2c_client *client, int reg, uint8_t *val)
129a59ec1e7SMichael Hennerich {
130a59ec1e7SMichael Hennerich int ret;
131a59ec1e7SMichael Hennerich
132a59ec1e7SMichael Hennerich ret = i2c_smbus_read_byte_data(client, reg);
133a59ec1e7SMichael Hennerich if (ret < 0) {
134a59ec1e7SMichael Hennerich dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
135a59ec1e7SMichael Hennerich return ret;
136a59ec1e7SMichael Hennerich }
137a59ec1e7SMichael Hennerich
138a59ec1e7SMichael Hennerich *val = ret;
139a59ec1e7SMichael Hennerich return 0;
140a59ec1e7SMichael Hennerich }
141a59ec1e7SMichael Hennerich
142a59ec1e7SMichael Hennerich
adp8870_write(struct i2c_client * client,u8 reg,u8 val)143a59ec1e7SMichael Hennerich static int adp8870_write(struct i2c_client *client, u8 reg, u8 val)
144a59ec1e7SMichael Hennerich {
145a59ec1e7SMichael Hennerich int ret = i2c_smbus_write_byte_data(client, reg, val);
146fe9a8623SJingoo Han
147a59ec1e7SMichael Hennerich if (ret)
148a59ec1e7SMichael Hennerich dev_err(&client->dev, "failed to write\n");
149a59ec1e7SMichael Hennerich
150a59ec1e7SMichael Hennerich return ret;
151a59ec1e7SMichael Hennerich }
152a59ec1e7SMichael Hennerich
adp8870_set_bits(struct i2c_client * client,int reg,uint8_t bit_mask)153a59ec1e7SMichael Hennerich static int adp8870_set_bits(struct i2c_client *client, int reg, uint8_t bit_mask)
154a59ec1e7SMichael Hennerich {
155a59ec1e7SMichael Hennerich struct adp8870_bl *data = i2c_get_clientdata(client);
156a59ec1e7SMichael Hennerich uint8_t reg_val;
157a59ec1e7SMichael Hennerich int ret;
158a59ec1e7SMichael Hennerich
159a59ec1e7SMichael Hennerich mutex_lock(&data->lock);
160a59ec1e7SMichael Hennerich
161a59ec1e7SMichael Hennerich ret = adp8870_read(client, reg, ®_val);
162a59ec1e7SMichael Hennerich
16336c3e759SAxel Lin if (!ret && ((reg_val & bit_mask) != bit_mask)) {
164a59ec1e7SMichael Hennerich reg_val |= bit_mask;
165a59ec1e7SMichael Hennerich ret = adp8870_write(client, reg, reg_val);
166a59ec1e7SMichael Hennerich }
167a59ec1e7SMichael Hennerich
168a59ec1e7SMichael Hennerich mutex_unlock(&data->lock);
169a59ec1e7SMichael Hennerich return ret;
170a59ec1e7SMichael Hennerich }
171a59ec1e7SMichael Hennerich
adp8870_clr_bits(struct i2c_client * client,int reg,uint8_t bit_mask)172a59ec1e7SMichael Hennerich static int adp8870_clr_bits(struct i2c_client *client, int reg, uint8_t bit_mask)
173a59ec1e7SMichael Hennerich {
174a59ec1e7SMichael Hennerich struct adp8870_bl *data = i2c_get_clientdata(client);
175a59ec1e7SMichael Hennerich uint8_t reg_val;
176a59ec1e7SMichael Hennerich int ret;
177a59ec1e7SMichael Hennerich
178a59ec1e7SMichael Hennerich mutex_lock(&data->lock);
179a59ec1e7SMichael Hennerich
180a59ec1e7SMichael Hennerich ret = adp8870_read(client, reg, ®_val);
181a59ec1e7SMichael Hennerich
182a59ec1e7SMichael Hennerich if (!ret && (reg_val & bit_mask)) {
183a59ec1e7SMichael Hennerich reg_val &= ~bit_mask;
184a59ec1e7SMichael Hennerich ret = adp8870_write(client, reg, reg_val);
185a59ec1e7SMichael Hennerich }
186a59ec1e7SMichael Hennerich
187a59ec1e7SMichael Hennerich mutex_unlock(&data->lock);
188a59ec1e7SMichael Hennerich return ret;
189a59ec1e7SMichael Hennerich }
190a59ec1e7SMichael Hennerich
191a59ec1e7SMichael Hennerich /*
192a59ec1e7SMichael Hennerich * Independent sink / LED
193a59ec1e7SMichael Hennerich */
194a59ec1e7SMichael Hennerich #if defined(ADP8870_USE_LEDS)
adp8870_led_work(struct work_struct * work)195a59ec1e7SMichael Hennerich static void adp8870_led_work(struct work_struct *work)
196a59ec1e7SMichael Hennerich {
197a59ec1e7SMichael Hennerich struct adp8870_led *led = container_of(work, struct adp8870_led, work);
198fe9a8623SJingoo Han
199a59ec1e7SMichael Hennerich adp8870_write(led->client, ADP8870_ISC1 + led->id - 1,
200a59ec1e7SMichael Hennerich led->new_brightness >> 1);
201a59ec1e7SMichael Hennerich }
202a59ec1e7SMichael Hennerich
adp8870_led_set(struct led_classdev * led_cdev,enum led_brightness value)203a59ec1e7SMichael Hennerich static void adp8870_led_set(struct led_classdev *led_cdev,
204a59ec1e7SMichael Hennerich enum led_brightness value)
205a59ec1e7SMichael Hennerich {
206a59ec1e7SMichael Hennerich struct adp8870_led *led;
207a59ec1e7SMichael Hennerich
208a59ec1e7SMichael Hennerich led = container_of(led_cdev, struct adp8870_led, cdev);
209a59ec1e7SMichael Hennerich led->new_brightness = value;
210a59ec1e7SMichael Hennerich /*
211a59ec1e7SMichael Hennerich * Use workqueue for IO since I2C operations can sleep.
212a59ec1e7SMichael Hennerich */
213a59ec1e7SMichael Hennerich schedule_work(&led->work);
214a59ec1e7SMichael Hennerich }
215a59ec1e7SMichael Hennerich
adp8870_led_setup(struct adp8870_led * led)216a59ec1e7SMichael Hennerich static int adp8870_led_setup(struct adp8870_led *led)
217a59ec1e7SMichael Hennerich {
218a59ec1e7SMichael Hennerich struct i2c_client *client = led->client;
219a59ec1e7SMichael Hennerich int ret = 0;
220a59ec1e7SMichael Hennerich
221a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_ISC1 + led->id - 1, 0);
222a59ec1e7SMichael Hennerich if (ret)
223a59ec1e7SMichael Hennerich return ret;
224a59ec1e7SMichael Hennerich
225a59ec1e7SMichael Hennerich ret = adp8870_set_bits(client, ADP8870_ISCC, 1 << (led->id - 1));
226a59ec1e7SMichael Hennerich if (ret)
227a59ec1e7SMichael Hennerich return ret;
228a59ec1e7SMichael Hennerich
229a59ec1e7SMichael Hennerich if (led->id > 4)
230a59ec1e7SMichael Hennerich ret = adp8870_set_bits(client, ADP8870_ISCT1,
231a59ec1e7SMichael Hennerich (led->flags & 0x3) << ((led->id - 5) * 2));
232a59ec1e7SMichael Hennerich else
233a59ec1e7SMichael Hennerich ret = adp8870_set_bits(client, ADP8870_ISCT2,
234a59ec1e7SMichael Hennerich (led->flags & 0x3) << ((led->id - 1) * 2));
235a59ec1e7SMichael Hennerich
236a59ec1e7SMichael Hennerich return ret;
237a59ec1e7SMichael Hennerich }
238a59ec1e7SMichael Hennerich
adp8870_led_probe(struct i2c_client * client)2391b9e450dSBill Pemberton static int adp8870_led_probe(struct i2c_client *client)
240a59ec1e7SMichael Hennerich {
241a59ec1e7SMichael Hennerich struct adp8870_backlight_platform_data *pdata =
242c512794cSJingoo Han dev_get_platdata(&client->dev);
243a59ec1e7SMichael Hennerich struct adp8870_bl *data = i2c_get_clientdata(client);
244a59ec1e7SMichael Hennerich struct adp8870_led *led, *led_dat;
245a59ec1e7SMichael Hennerich struct led_info *cur_led;
246a59ec1e7SMichael Hennerich int ret, i;
247a59ec1e7SMichael Hennerich
248a86854d0SKees Cook led = devm_kcalloc(&client->dev, pdata->num_leds, sizeof(*led),
24991cdb239SJingoo Han GFP_KERNEL);
2500167a956SJingoo Han if (led == NULL)
251a59ec1e7SMichael Hennerich return -ENOMEM;
252a59ec1e7SMichael Hennerich
253a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_ISCLAW, pdata->led_fade_law);
254a59ec1e7SMichael Hennerich if (ret)
25591cdb239SJingoo Han return ret;
256a59ec1e7SMichael Hennerich
257a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_ISCT1,
258a59ec1e7SMichael Hennerich (pdata->led_on_time & 0x3) << 6);
259a59ec1e7SMichael Hennerich if (ret)
26091cdb239SJingoo Han return ret;
261a59ec1e7SMichael Hennerich
262a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_ISCF,
263a59ec1e7SMichael Hennerich FADE_VAL(pdata->led_fade_in, pdata->led_fade_out));
264a59ec1e7SMichael Hennerich if (ret)
26591cdb239SJingoo Han return ret;
266a59ec1e7SMichael Hennerich
267a59ec1e7SMichael Hennerich for (i = 0; i < pdata->num_leds; ++i) {
268a59ec1e7SMichael Hennerich cur_led = &pdata->leds[i];
269a59ec1e7SMichael Hennerich led_dat = &led[i];
270a59ec1e7SMichael Hennerich
271a59ec1e7SMichael Hennerich led_dat->id = cur_led->flags & ADP8870_FLAG_LED_MASK;
272a59ec1e7SMichael Hennerich
273a59ec1e7SMichael Hennerich if (led_dat->id > 7 || led_dat->id < 1) {
274a59ec1e7SMichael Hennerich dev_err(&client->dev, "Invalid LED ID %d\n",
275a59ec1e7SMichael Hennerich led_dat->id);
276514f920aSWei Yongjun ret = -EINVAL;
277a59ec1e7SMichael Hennerich goto err;
278a59ec1e7SMichael Hennerich }
279a59ec1e7SMichael Hennerich
280a59ec1e7SMichael Hennerich if (pdata->bl_led_assign & (1 << (led_dat->id - 1))) {
281a59ec1e7SMichael Hennerich dev_err(&client->dev, "LED %d used by Backlight\n",
282a59ec1e7SMichael Hennerich led_dat->id);
283514f920aSWei Yongjun ret = -EBUSY;
284a59ec1e7SMichael Hennerich goto err;
285a59ec1e7SMichael Hennerich }
286a59ec1e7SMichael Hennerich
287a59ec1e7SMichael Hennerich led_dat->cdev.name = cur_led->name;
288a59ec1e7SMichael Hennerich led_dat->cdev.default_trigger = cur_led->default_trigger;
289a59ec1e7SMichael Hennerich led_dat->cdev.brightness_set = adp8870_led_set;
290a59ec1e7SMichael Hennerich led_dat->cdev.brightness = LED_OFF;
291a59ec1e7SMichael Hennerich led_dat->flags = cur_led->flags >> FLAG_OFFT_SHIFT;
292a59ec1e7SMichael Hennerich led_dat->client = client;
293a59ec1e7SMichael Hennerich led_dat->new_brightness = LED_OFF;
294a59ec1e7SMichael Hennerich INIT_WORK(&led_dat->work, adp8870_led_work);
295a59ec1e7SMichael Hennerich
296a59ec1e7SMichael Hennerich ret = led_classdev_register(&client->dev, &led_dat->cdev);
297a59ec1e7SMichael Hennerich if (ret) {
298a59ec1e7SMichael Hennerich dev_err(&client->dev, "failed to register LED %d\n",
299a59ec1e7SMichael Hennerich led_dat->id);
300a59ec1e7SMichael Hennerich goto err;
301a59ec1e7SMichael Hennerich }
302a59ec1e7SMichael Hennerich
303a59ec1e7SMichael Hennerich ret = adp8870_led_setup(led_dat);
304a59ec1e7SMichael Hennerich if (ret) {
305a59ec1e7SMichael Hennerich dev_err(&client->dev, "failed to write\n");
306a59ec1e7SMichael Hennerich i++;
307a59ec1e7SMichael Hennerich goto err;
308a59ec1e7SMichael Hennerich }
309a59ec1e7SMichael Hennerich }
310a59ec1e7SMichael Hennerich
311a59ec1e7SMichael Hennerich data->led = led;
312a59ec1e7SMichael Hennerich
313a59ec1e7SMichael Hennerich return 0;
314a59ec1e7SMichael Hennerich
315a59ec1e7SMichael Hennerich err:
316a59ec1e7SMichael Hennerich for (i = i - 1; i >= 0; --i) {
317a59ec1e7SMichael Hennerich led_classdev_unregister(&led[i].cdev);
318a59ec1e7SMichael Hennerich cancel_work_sync(&led[i].work);
319a59ec1e7SMichael Hennerich }
320a59ec1e7SMichael Hennerich
321a59ec1e7SMichael Hennerich return ret;
322a59ec1e7SMichael Hennerich }
323a59ec1e7SMichael Hennerich
adp8870_led_remove(struct i2c_client * client)3247e4b9d0bSBill Pemberton static int adp8870_led_remove(struct i2c_client *client)
325a59ec1e7SMichael Hennerich {
326a59ec1e7SMichael Hennerich struct adp8870_backlight_platform_data *pdata =
327c512794cSJingoo Han dev_get_platdata(&client->dev);
328a59ec1e7SMichael Hennerich struct adp8870_bl *data = i2c_get_clientdata(client);
329a59ec1e7SMichael Hennerich int i;
330a59ec1e7SMichael Hennerich
331a59ec1e7SMichael Hennerich for (i = 0; i < pdata->num_leds; i++) {
332a59ec1e7SMichael Hennerich led_classdev_unregister(&data->led[i].cdev);
333a59ec1e7SMichael Hennerich cancel_work_sync(&data->led[i].work);
334a59ec1e7SMichael Hennerich }
335a59ec1e7SMichael Hennerich
336a59ec1e7SMichael Hennerich return 0;
337a59ec1e7SMichael Hennerich }
338a59ec1e7SMichael Hennerich #else
adp8870_led_probe(struct i2c_client * client)3391b9e450dSBill Pemberton static int adp8870_led_probe(struct i2c_client *client)
340a59ec1e7SMichael Hennerich {
341a59ec1e7SMichael Hennerich return 0;
342a59ec1e7SMichael Hennerich }
343a59ec1e7SMichael Hennerich
adp8870_led_remove(struct i2c_client * client)3447e4b9d0bSBill Pemberton static int adp8870_led_remove(struct i2c_client *client)
345a59ec1e7SMichael Hennerich {
346a59ec1e7SMichael Hennerich return 0;
347a59ec1e7SMichael Hennerich }
348a59ec1e7SMichael Hennerich #endif
349a59ec1e7SMichael Hennerich
adp8870_bl_set(struct backlight_device * bl,int brightness)350a59ec1e7SMichael Hennerich static int adp8870_bl_set(struct backlight_device *bl, int brightness)
351a59ec1e7SMichael Hennerich {
352a59ec1e7SMichael Hennerich struct adp8870_bl *data = bl_get_data(bl);
353a59ec1e7SMichael Hennerich struct i2c_client *client = data->client;
354a59ec1e7SMichael Hennerich int ret = 0;
355a59ec1e7SMichael Hennerich
356a59ec1e7SMichael Hennerich if (data->pdata->en_ambl_sens) {
357a59ec1e7SMichael Hennerich if ((brightness > 0) && (brightness < ADP8870_MAX_BRIGHTNESS)) {
358a59ec1e7SMichael Hennerich /* Disable Ambient Light auto adjust */
359a59ec1e7SMichael Hennerich ret = adp8870_clr_bits(client, ADP8870_MDCR,
360a59ec1e7SMichael Hennerich CMP_AUTOEN);
361a59ec1e7SMichael Hennerich if (ret)
362a59ec1e7SMichael Hennerich return ret;
363a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLMX1, brightness);
364a59ec1e7SMichael Hennerich if (ret)
365a59ec1e7SMichael Hennerich return ret;
366a59ec1e7SMichael Hennerich } else {
367a59ec1e7SMichael Hennerich /*
368a59ec1e7SMichael Hennerich * MAX_BRIGHTNESS -> Enable Ambient Light auto adjust
369a59ec1e7SMichael Hennerich * restore daylight l1 sysfs brightness
370a59ec1e7SMichael Hennerich */
371a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLMX1,
372a59ec1e7SMichael Hennerich data->cached_daylight_max);
373a59ec1e7SMichael Hennerich if (ret)
374a59ec1e7SMichael Hennerich return ret;
375a59ec1e7SMichael Hennerich
376a59ec1e7SMichael Hennerich ret = adp8870_set_bits(client, ADP8870_MDCR,
377a59ec1e7SMichael Hennerich CMP_AUTOEN);
378a59ec1e7SMichael Hennerich if (ret)
379a59ec1e7SMichael Hennerich return ret;
380a59ec1e7SMichael Hennerich }
381a59ec1e7SMichael Hennerich } else {
382a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLMX1, brightness);
383a59ec1e7SMichael Hennerich if (ret)
384a59ec1e7SMichael Hennerich return ret;
385a59ec1e7SMichael Hennerich }
386a59ec1e7SMichael Hennerich
387a59ec1e7SMichael Hennerich if (data->current_brightness && brightness == 0)
388a59ec1e7SMichael Hennerich ret = adp8870_set_bits(client,
389a59ec1e7SMichael Hennerich ADP8870_MDCR, DIM_EN);
390a59ec1e7SMichael Hennerich else if (data->current_brightness == 0 && brightness)
391a59ec1e7SMichael Hennerich ret = adp8870_clr_bits(client,
392a59ec1e7SMichael Hennerich ADP8870_MDCR, DIM_EN);
393a59ec1e7SMichael Hennerich
394a59ec1e7SMichael Hennerich if (!ret)
395a59ec1e7SMichael Hennerich data->current_brightness = brightness;
396a59ec1e7SMichael Hennerich
397a59ec1e7SMichael Hennerich return ret;
398a59ec1e7SMichael Hennerich }
399a59ec1e7SMichael Hennerich
adp8870_bl_update_status(struct backlight_device * bl)400a59ec1e7SMichael Hennerich static int adp8870_bl_update_status(struct backlight_device *bl)
401a59ec1e7SMichael Hennerich {
40251d53e5bSSam Ravnborg return adp8870_bl_set(bl, backlight_get_brightness(bl));
403a59ec1e7SMichael Hennerich }
404a59ec1e7SMichael Hennerich
adp8870_bl_get_brightness(struct backlight_device * bl)405a59ec1e7SMichael Hennerich static int adp8870_bl_get_brightness(struct backlight_device *bl)
406a59ec1e7SMichael Hennerich {
407a59ec1e7SMichael Hennerich struct adp8870_bl *data = bl_get_data(bl);
408a59ec1e7SMichael Hennerich
409a59ec1e7SMichael Hennerich return data->current_brightness;
410a59ec1e7SMichael Hennerich }
411a59ec1e7SMichael Hennerich
412a59ec1e7SMichael Hennerich static const struct backlight_ops adp8870_bl_ops = {
413a59ec1e7SMichael Hennerich .update_status = adp8870_bl_update_status,
414a59ec1e7SMichael Hennerich .get_brightness = adp8870_bl_get_brightness,
415a59ec1e7SMichael Hennerich };
416a59ec1e7SMichael Hennerich
adp8870_bl_setup(struct backlight_device * bl)417a59ec1e7SMichael Hennerich static int adp8870_bl_setup(struct backlight_device *bl)
418a59ec1e7SMichael Hennerich {
419a59ec1e7SMichael Hennerich struct adp8870_bl *data = bl_get_data(bl);
420a59ec1e7SMichael Hennerich struct i2c_client *client = data->client;
421a59ec1e7SMichael Hennerich struct adp8870_backlight_platform_data *pdata = data->pdata;
422a59ec1e7SMichael Hennerich int ret = 0;
423a59ec1e7SMichael Hennerich
424a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLSEL, ~pdata->bl_led_assign);
425a59ec1e7SMichael Hennerich if (ret)
426a59ec1e7SMichael Hennerich return ret;
427a59ec1e7SMichael Hennerich
428a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_PWMLED, pdata->pwm_assign);
429a59ec1e7SMichael Hennerich if (ret)
430a59ec1e7SMichael Hennerich return ret;
431a59ec1e7SMichael Hennerich
432a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLMX1, pdata->l1_daylight_max);
433a59ec1e7SMichael Hennerich if (ret)
434a59ec1e7SMichael Hennerich return ret;
435a59ec1e7SMichael Hennerich
436a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLDM1, pdata->l1_daylight_dim);
437a59ec1e7SMichael Hennerich if (ret)
438a59ec1e7SMichael Hennerich return ret;
439a59ec1e7SMichael Hennerich
440a59ec1e7SMichael Hennerich if (pdata->en_ambl_sens) {
441a59ec1e7SMichael Hennerich data->cached_daylight_max = pdata->l1_daylight_max;
442a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLMX2,
443a59ec1e7SMichael Hennerich pdata->l2_bright_max);
444a59ec1e7SMichael Hennerich if (ret)
445a59ec1e7SMichael Hennerich return ret;
446a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLDM2,
447a59ec1e7SMichael Hennerich pdata->l2_bright_dim);
448a59ec1e7SMichael Hennerich if (ret)
449a59ec1e7SMichael Hennerich return ret;
450a59ec1e7SMichael Hennerich
451a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLMX3,
452a59ec1e7SMichael Hennerich pdata->l3_office_max);
453a59ec1e7SMichael Hennerich if (ret)
454a59ec1e7SMichael Hennerich return ret;
455a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLDM3,
456a59ec1e7SMichael Hennerich pdata->l3_office_dim);
457a59ec1e7SMichael Hennerich if (ret)
458a59ec1e7SMichael Hennerich return ret;
459a59ec1e7SMichael Hennerich
460a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLMX4,
461a59ec1e7SMichael Hennerich pdata->l4_indoor_max);
462a59ec1e7SMichael Hennerich if (ret)
463a59ec1e7SMichael Hennerich return ret;
464a59ec1e7SMichael Hennerich
465a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLDM4,
466a59ec1e7SMichael Hennerich pdata->l4_indor_dim);
467a59ec1e7SMichael Hennerich if (ret)
468a59ec1e7SMichael Hennerich return ret;
469a59ec1e7SMichael Hennerich
470a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLMX5,
471a59ec1e7SMichael Hennerich pdata->l5_dark_max);
472a59ec1e7SMichael Hennerich if (ret)
473a59ec1e7SMichael Hennerich return ret;
474a59ec1e7SMichael Hennerich
475a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLDM5,
476a59ec1e7SMichael Hennerich pdata->l5_dark_dim);
477a59ec1e7SMichael Hennerich if (ret)
478a59ec1e7SMichael Hennerich return ret;
479a59ec1e7SMichael Hennerich
480a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_L2TRP, pdata->l2_trip);
481a59ec1e7SMichael Hennerich if (ret)
482a59ec1e7SMichael Hennerich return ret;
483a59ec1e7SMichael Hennerich
484a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_L2HYS, pdata->l2_hyst);
485a59ec1e7SMichael Hennerich if (ret)
486a59ec1e7SMichael Hennerich return ret;
487a59ec1e7SMichael Hennerich
488a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_L3TRP, pdata->l3_trip);
489a59ec1e7SMichael Hennerich if (ret)
490a59ec1e7SMichael Hennerich return ret;
491a59ec1e7SMichael Hennerich
492a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_L3HYS, pdata->l3_hyst);
493a59ec1e7SMichael Hennerich if (ret)
494a59ec1e7SMichael Hennerich return ret;
495a59ec1e7SMichael Hennerich
496a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_L4TRP, pdata->l4_trip);
497a59ec1e7SMichael Hennerich if (ret)
498a59ec1e7SMichael Hennerich return ret;
499a59ec1e7SMichael Hennerich
500a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_L4HYS, pdata->l4_hyst);
501a59ec1e7SMichael Hennerich if (ret)
502a59ec1e7SMichael Hennerich return ret;
503a59ec1e7SMichael Hennerich
504a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_L5TRP, pdata->l5_trip);
505a59ec1e7SMichael Hennerich if (ret)
506a59ec1e7SMichael Hennerich return ret;
507a59ec1e7SMichael Hennerich
508a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_L5HYS, pdata->l5_hyst);
509a59ec1e7SMichael Hennerich if (ret)
510a59ec1e7SMichael Hennerich return ret;
511a59ec1e7SMichael Hennerich
512a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_ALS1_EN, L5_EN | L4_EN |
513a59ec1e7SMichael Hennerich L3_EN | L2_EN);
514a59ec1e7SMichael Hennerich if (ret)
515a59ec1e7SMichael Hennerich return ret;
516a59ec1e7SMichael Hennerich
517a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_CMP_CTL,
518a59ec1e7SMichael Hennerich ALS_CMPR_CFG_VAL(pdata->abml_filt));
519a59ec1e7SMichael Hennerich if (ret)
520a59ec1e7SMichael Hennerich return ret;
521a59ec1e7SMichael Hennerich }
522a59ec1e7SMichael Hennerich
523a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_CFGR,
524a59ec1e7SMichael Hennerich BL_CFGR_VAL(pdata->bl_fade_law, 0));
525a59ec1e7SMichael Hennerich if (ret)
526a59ec1e7SMichael Hennerich return ret;
527a59ec1e7SMichael Hennerich
528a59ec1e7SMichael Hennerich ret = adp8870_write(client, ADP8870_BLFR, FADE_VAL(pdata->bl_fade_in,
529a59ec1e7SMichael Hennerich pdata->bl_fade_out));
530a59ec1e7SMichael Hennerich if (ret)
531a59ec1e7SMichael Hennerich return ret;
532a59ec1e7SMichael Hennerich /*
533a59ec1e7SMichael Hennerich * ADP8870 Rev0 requires GDWN_DIS bit set
534a59ec1e7SMichael Hennerich */
535a59ec1e7SMichael Hennerich
536a59ec1e7SMichael Hennerich ret = adp8870_set_bits(client, ADP8870_MDCR, BLEN | DIM_EN | NSTBY |
537a59ec1e7SMichael Hennerich (data->revid == 0 ? GDWN_DIS : 0));
538a59ec1e7SMichael Hennerich
539a59ec1e7SMichael Hennerich return ret;
540a59ec1e7SMichael Hennerich }
541a59ec1e7SMichael Hennerich
adp8870_show(struct device * dev,char * buf,int reg)542a59ec1e7SMichael Hennerich static ssize_t adp8870_show(struct device *dev, char *buf, int reg)
543a59ec1e7SMichael Hennerich {
544a59ec1e7SMichael Hennerich struct adp8870_bl *data = dev_get_drvdata(dev);
545a59ec1e7SMichael Hennerich int error;
546a59ec1e7SMichael Hennerich uint8_t reg_val;
547a59ec1e7SMichael Hennerich
548a59ec1e7SMichael Hennerich mutex_lock(&data->lock);
549a59ec1e7SMichael Hennerich error = adp8870_read(data->client, reg, ®_val);
550a59ec1e7SMichael Hennerich mutex_unlock(&data->lock);
551a59ec1e7SMichael Hennerich
552a59ec1e7SMichael Hennerich if (error < 0)
553a59ec1e7SMichael Hennerich return error;
554a59ec1e7SMichael Hennerich
555a59ec1e7SMichael Hennerich return sprintf(buf, "%u\n", reg_val);
556a59ec1e7SMichael Hennerich }
557a59ec1e7SMichael Hennerich
adp8870_store(struct device * dev,const char * buf,size_t count,int reg)558a59ec1e7SMichael Hennerich static ssize_t adp8870_store(struct device *dev, const char *buf,
559a59ec1e7SMichael Hennerich size_t count, int reg)
560a59ec1e7SMichael Hennerich {
561a59ec1e7SMichael Hennerich struct adp8870_bl *data = dev_get_drvdata(dev);
562a59ec1e7SMichael Hennerich unsigned long val;
563a59ec1e7SMichael Hennerich int ret;
564a59ec1e7SMichael Hennerich
565dc406f56SJingoo Han ret = kstrtoul(buf, 10, &val);
566a59ec1e7SMichael Hennerich if (ret)
567a59ec1e7SMichael Hennerich return ret;
568a59ec1e7SMichael Hennerich
569a59ec1e7SMichael Hennerich mutex_lock(&data->lock);
570a59ec1e7SMichael Hennerich adp8870_write(data->client, reg, val);
571a59ec1e7SMichael Hennerich mutex_unlock(&data->lock);
572a59ec1e7SMichael Hennerich
573a59ec1e7SMichael Hennerich return count;
574a59ec1e7SMichael Hennerich }
575a59ec1e7SMichael Hennerich
adp8870_bl_l5_dark_max_show(struct device * dev,struct device_attribute * attr,char * buf)576a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l5_dark_max_show(struct device *dev,
577a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
578a59ec1e7SMichael Hennerich {
579a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLMX5);
580a59ec1e7SMichael Hennerich }
581a59ec1e7SMichael Hennerich
adp8870_bl_l5_dark_max_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)582a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l5_dark_max_store(struct device *dev,
583a59ec1e7SMichael Hennerich struct device_attribute *attr, const char *buf, size_t count)
584a59ec1e7SMichael Hennerich {
585a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLMX5);
586a59ec1e7SMichael Hennerich }
587a59ec1e7SMichael Hennerich static DEVICE_ATTR(l5_dark_max, 0664, adp8870_bl_l5_dark_max_show,
588a59ec1e7SMichael Hennerich adp8870_bl_l5_dark_max_store);
589a59ec1e7SMichael Hennerich
590a59ec1e7SMichael Hennerich
adp8870_bl_l4_indoor_max_show(struct device * dev,struct device_attribute * attr,char * buf)591a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l4_indoor_max_show(struct device *dev,
592a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
593a59ec1e7SMichael Hennerich {
594a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLMX4);
595a59ec1e7SMichael Hennerich }
596a59ec1e7SMichael Hennerich
adp8870_bl_l4_indoor_max_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)597a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l4_indoor_max_store(struct device *dev,
598a59ec1e7SMichael Hennerich struct device_attribute *attr, const char *buf, size_t count)
599a59ec1e7SMichael Hennerich {
600a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLMX4);
601a59ec1e7SMichael Hennerich }
602a59ec1e7SMichael Hennerich static DEVICE_ATTR(l4_indoor_max, 0664, adp8870_bl_l4_indoor_max_show,
603a59ec1e7SMichael Hennerich adp8870_bl_l4_indoor_max_store);
604a59ec1e7SMichael Hennerich
605a59ec1e7SMichael Hennerich
adp8870_bl_l3_office_max_show(struct device * dev,struct device_attribute * attr,char * buf)606a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l3_office_max_show(struct device *dev,
607a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
608a59ec1e7SMichael Hennerich {
609a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLMX3);
610a59ec1e7SMichael Hennerich }
611a59ec1e7SMichael Hennerich
adp8870_bl_l3_office_max_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)612a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l3_office_max_store(struct device *dev,
613a59ec1e7SMichael Hennerich struct device_attribute *attr, const char *buf, size_t count)
614a59ec1e7SMichael Hennerich {
615a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLMX3);
616a59ec1e7SMichael Hennerich }
617a59ec1e7SMichael Hennerich
618a59ec1e7SMichael Hennerich static DEVICE_ATTR(l3_office_max, 0664, adp8870_bl_l3_office_max_show,
619a59ec1e7SMichael Hennerich adp8870_bl_l3_office_max_store);
620a59ec1e7SMichael Hennerich
adp8870_bl_l2_bright_max_show(struct device * dev,struct device_attribute * attr,char * buf)621a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l2_bright_max_show(struct device *dev,
622a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
623a59ec1e7SMichael Hennerich {
624a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLMX2);
625a59ec1e7SMichael Hennerich }
626a59ec1e7SMichael Hennerich
adp8870_bl_l2_bright_max_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)627a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l2_bright_max_store(struct device *dev,
628a59ec1e7SMichael Hennerich struct device_attribute *attr, const char *buf, size_t count)
629a59ec1e7SMichael Hennerich {
630a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLMX2);
631a59ec1e7SMichael Hennerich }
632a59ec1e7SMichael Hennerich static DEVICE_ATTR(l2_bright_max, 0664, adp8870_bl_l2_bright_max_show,
633a59ec1e7SMichael Hennerich adp8870_bl_l2_bright_max_store);
634a59ec1e7SMichael Hennerich
adp8870_bl_l1_daylight_max_show(struct device * dev,struct device_attribute * attr,char * buf)635a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l1_daylight_max_show(struct device *dev,
636a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
637a59ec1e7SMichael Hennerich {
638a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLMX1);
639a59ec1e7SMichael Hennerich }
640a59ec1e7SMichael Hennerich
adp8870_bl_l1_daylight_max_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)641a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l1_daylight_max_store(struct device *dev,
642a59ec1e7SMichael Hennerich struct device_attribute *attr, const char *buf, size_t count)
643a59ec1e7SMichael Hennerich {
644a59ec1e7SMichael Hennerich struct adp8870_bl *data = dev_get_drvdata(dev);
645dc406f56SJingoo Han int ret = kstrtoul(buf, 10, &data->cached_daylight_max);
646fe9a8623SJingoo Han
647a59ec1e7SMichael Hennerich if (ret)
648a59ec1e7SMichael Hennerich return ret;
649a59ec1e7SMichael Hennerich
650a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLMX1);
651a59ec1e7SMichael Hennerich }
652a59ec1e7SMichael Hennerich static DEVICE_ATTR(l1_daylight_max, 0664, adp8870_bl_l1_daylight_max_show,
653a59ec1e7SMichael Hennerich adp8870_bl_l1_daylight_max_store);
654a59ec1e7SMichael Hennerich
adp8870_bl_l5_dark_dim_show(struct device * dev,struct device_attribute * attr,char * buf)655a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l5_dark_dim_show(struct device *dev,
656a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
657a59ec1e7SMichael Hennerich {
658a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLDM5);
659a59ec1e7SMichael Hennerich }
660a59ec1e7SMichael Hennerich
adp8870_bl_l5_dark_dim_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)661a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l5_dark_dim_store(struct device *dev,
662a59ec1e7SMichael Hennerich struct device_attribute *attr,
663a59ec1e7SMichael Hennerich const char *buf, size_t count)
664a59ec1e7SMichael Hennerich {
665a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLDM5);
666a59ec1e7SMichael Hennerich }
667a59ec1e7SMichael Hennerich static DEVICE_ATTR(l5_dark_dim, 0664, adp8870_bl_l5_dark_dim_show,
668a59ec1e7SMichael Hennerich adp8870_bl_l5_dark_dim_store);
669a59ec1e7SMichael Hennerich
adp8870_bl_l4_indoor_dim_show(struct device * dev,struct device_attribute * attr,char * buf)670a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l4_indoor_dim_show(struct device *dev,
671a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
672a59ec1e7SMichael Hennerich {
673a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLDM4);
674a59ec1e7SMichael Hennerich }
675a59ec1e7SMichael Hennerich
adp8870_bl_l4_indoor_dim_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)676a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l4_indoor_dim_store(struct device *dev,
677a59ec1e7SMichael Hennerich struct device_attribute *attr,
678a59ec1e7SMichael Hennerich const char *buf, size_t count)
679a59ec1e7SMichael Hennerich {
680a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLDM4);
681a59ec1e7SMichael Hennerich }
682a59ec1e7SMichael Hennerich static DEVICE_ATTR(l4_indoor_dim, 0664, adp8870_bl_l4_indoor_dim_show,
683a59ec1e7SMichael Hennerich adp8870_bl_l4_indoor_dim_store);
684a59ec1e7SMichael Hennerich
685a59ec1e7SMichael Hennerich
adp8870_bl_l3_office_dim_show(struct device * dev,struct device_attribute * attr,char * buf)686a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l3_office_dim_show(struct device *dev,
687a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
688a59ec1e7SMichael Hennerich {
689a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLDM3);
690a59ec1e7SMichael Hennerich }
691a59ec1e7SMichael Hennerich
adp8870_bl_l3_office_dim_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)692a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l3_office_dim_store(struct device *dev,
693a59ec1e7SMichael Hennerich struct device_attribute *attr,
694a59ec1e7SMichael Hennerich const char *buf, size_t count)
695a59ec1e7SMichael Hennerich {
696a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLDM3);
697a59ec1e7SMichael Hennerich }
698a59ec1e7SMichael Hennerich static DEVICE_ATTR(l3_office_dim, 0664, adp8870_bl_l3_office_dim_show,
699a59ec1e7SMichael Hennerich adp8870_bl_l3_office_dim_store);
700a59ec1e7SMichael Hennerich
adp8870_bl_l2_bright_dim_show(struct device * dev,struct device_attribute * attr,char * buf)701a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l2_bright_dim_show(struct device *dev,
702a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
703a59ec1e7SMichael Hennerich {
704a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLDM2);
705a59ec1e7SMichael Hennerich }
706a59ec1e7SMichael Hennerich
adp8870_bl_l2_bright_dim_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)707a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l2_bright_dim_store(struct device *dev,
708a59ec1e7SMichael Hennerich struct device_attribute *attr,
709a59ec1e7SMichael Hennerich const char *buf, size_t count)
710a59ec1e7SMichael Hennerich {
711a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLDM2);
712a59ec1e7SMichael Hennerich }
713a59ec1e7SMichael Hennerich static DEVICE_ATTR(l2_bright_dim, 0664, adp8870_bl_l2_bright_dim_show,
714a59ec1e7SMichael Hennerich adp8870_bl_l2_bright_dim_store);
715a59ec1e7SMichael Hennerich
adp8870_bl_l1_daylight_dim_show(struct device * dev,struct device_attribute * attr,char * buf)716a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l1_daylight_dim_show(struct device *dev,
717a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
718a59ec1e7SMichael Hennerich {
719a59ec1e7SMichael Hennerich return adp8870_show(dev, buf, ADP8870_BLDM1);
720a59ec1e7SMichael Hennerich }
721a59ec1e7SMichael Hennerich
adp8870_bl_l1_daylight_dim_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)722a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_l1_daylight_dim_store(struct device *dev,
723a59ec1e7SMichael Hennerich struct device_attribute *attr,
724a59ec1e7SMichael Hennerich const char *buf, size_t count)
725a59ec1e7SMichael Hennerich {
726a59ec1e7SMichael Hennerich return adp8870_store(dev, buf, count, ADP8870_BLDM1);
727a59ec1e7SMichael Hennerich }
728a59ec1e7SMichael Hennerich static DEVICE_ATTR(l1_daylight_dim, 0664, adp8870_bl_l1_daylight_dim_show,
729a59ec1e7SMichael Hennerich adp8870_bl_l1_daylight_dim_store);
730a59ec1e7SMichael Hennerich
731a59ec1e7SMichael Hennerich #ifdef ADP8870_EXT_FEATURES
adp8870_bl_ambient_light_level_show(struct device * dev,struct device_attribute * attr,char * buf)732a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_ambient_light_level_show(struct device *dev,
733a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
734a59ec1e7SMichael Hennerich {
735a59ec1e7SMichael Hennerich struct adp8870_bl *data = dev_get_drvdata(dev);
736a59ec1e7SMichael Hennerich int error;
737a59ec1e7SMichael Hennerich uint8_t reg_val;
738a59ec1e7SMichael Hennerich uint16_t ret_val;
739a59ec1e7SMichael Hennerich
740a59ec1e7SMichael Hennerich mutex_lock(&data->lock);
741a59ec1e7SMichael Hennerich error = adp8870_read(data->client, ADP8870_PH1LEVL, ®_val);
742a59ec1e7SMichael Hennerich if (error < 0) {
743a59ec1e7SMichael Hennerich mutex_unlock(&data->lock);
744a59ec1e7SMichael Hennerich return error;
745a59ec1e7SMichael Hennerich }
746a59ec1e7SMichael Hennerich ret_val = reg_val;
747a59ec1e7SMichael Hennerich error = adp8870_read(data->client, ADP8870_PH1LEVH, ®_val);
748a59ec1e7SMichael Hennerich mutex_unlock(&data->lock);
749a59ec1e7SMichael Hennerich
750a59ec1e7SMichael Hennerich if (error < 0)
751a59ec1e7SMichael Hennerich return error;
752a59ec1e7SMichael Hennerich
753a59ec1e7SMichael Hennerich /* Return 13-bit conversion value for the first light sensor */
754a59ec1e7SMichael Hennerich ret_val += (reg_val & 0x1F) << 8;
755a59ec1e7SMichael Hennerich
756a59ec1e7SMichael Hennerich return sprintf(buf, "%u\n", ret_val);
757a59ec1e7SMichael Hennerich }
758a59ec1e7SMichael Hennerich static DEVICE_ATTR(ambient_light_level, 0444,
759a59ec1e7SMichael Hennerich adp8870_bl_ambient_light_level_show, NULL);
760a59ec1e7SMichael Hennerich
adp8870_bl_ambient_light_zone_show(struct device * dev,struct device_attribute * attr,char * buf)761a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_ambient_light_zone_show(struct device *dev,
762a59ec1e7SMichael Hennerich struct device_attribute *attr, char *buf)
763a59ec1e7SMichael Hennerich {
764a59ec1e7SMichael Hennerich struct adp8870_bl *data = dev_get_drvdata(dev);
765a59ec1e7SMichael Hennerich int error;
766a59ec1e7SMichael Hennerich uint8_t reg_val;
767a59ec1e7SMichael Hennerich
768a59ec1e7SMichael Hennerich mutex_lock(&data->lock);
769a59ec1e7SMichael Hennerich error = adp8870_read(data->client, ADP8870_CFGR, ®_val);
770a59ec1e7SMichael Hennerich mutex_unlock(&data->lock);
771a59ec1e7SMichael Hennerich
772a59ec1e7SMichael Hennerich if (error < 0)
773a59ec1e7SMichael Hennerich return error;
774a59ec1e7SMichael Hennerich
775a59ec1e7SMichael Hennerich return sprintf(buf, "%u\n",
776a59ec1e7SMichael Hennerich ((reg_val >> CFGR_BLV_SHIFT) & CFGR_BLV_MASK) + 1);
777a59ec1e7SMichael Hennerich }
778a59ec1e7SMichael Hennerich
adp8870_bl_ambient_light_zone_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)779a59ec1e7SMichael Hennerich static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,
780a59ec1e7SMichael Hennerich struct device_attribute *attr,
781a59ec1e7SMichael Hennerich const char *buf, size_t count)
782a59ec1e7SMichael Hennerich {
783a59ec1e7SMichael Hennerich struct adp8870_bl *data = dev_get_drvdata(dev);
784a59ec1e7SMichael Hennerich unsigned long val;
785a59ec1e7SMichael Hennerich uint8_t reg_val;
786a59ec1e7SMichael Hennerich int ret;
787a59ec1e7SMichael Hennerich
788dc406f56SJingoo Han ret = kstrtoul(buf, 10, &val);
789a59ec1e7SMichael Hennerich if (ret)
790a59ec1e7SMichael Hennerich return ret;
791a59ec1e7SMichael Hennerich
792a59ec1e7SMichael Hennerich if (val == 0) {
793a59ec1e7SMichael Hennerich /* Enable automatic ambient light sensing */
794a59ec1e7SMichael Hennerich adp8870_set_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
795a59ec1e7SMichael Hennerich } else if ((val > 0) && (val < 6)) {
796a59ec1e7SMichael Hennerich /* Disable automatic ambient light sensing */
797a59ec1e7SMichael Hennerich adp8870_clr_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
798a59ec1e7SMichael Hennerich
799a59ec1e7SMichael Hennerich /* Set user supplied ambient light zone */
800a59ec1e7SMichael Hennerich mutex_lock(&data->lock);
80186c68e2fSArnd Bergmann ret = adp8870_read(data->client, ADP8870_CFGR, ®_val);
80286c68e2fSArnd Bergmann if (!ret) {
803a59ec1e7SMichael Hennerich reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT);
804a59ec1e7SMichael Hennerich reg_val |= (val - 1) << CFGR_BLV_SHIFT;
805a59ec1e7SMichael Hennerich adp8870_write(data->client, ADP8870_CFGR, reg_val);
80686c68e2fSArnd Bergmann }
807a59ec1e7SMichael Hennerich mutex_unlock(&data->lock);
808a59ec1e7SMichael Hennerich }
809a59ec1e7SMichael Hennerich
810a59ec1e7SMichael Hennerich return count;
811a59ec1e7SMichael Hennerich }
812a59ec1e7SMichael Hennerich static DEVICE_ATTR(ambient_light_zone, 0664,
813a59ec1e7SMichael Hennerich adp8870_bl_ambient_light_zone_show,
814a59ec1e7SMichael Hennerich adp8870_bl_ambient_light_zone_store);
815a59ec1e7SMichael Hennerich #endif
816a59ec1e7SMichael Hennerich
817a59ec1e7SMichael Hennerich static struct attribute *adp8870_bl_attributes[] = {
818a59ec1e7SMichael Hennerich &dev_attr_l5_dark_max.attr,
819a59ec1e7SMichael Hennerich &dev_attr_l5_dark_dim.attr,
820a59ec1e7SMichael Hennerich &dev_attr_l4_indoor_max.attr,
821a59ec1e7SMichael Hennerich &dev_attr_l4_indoor_dim.attr,
822a59ec1e7SMichael Hennerich &dev_attr_l3_office_max.attr,
823a59ec1e7SMichael Hennerich &dev_attr_l3_office_dim.attr,
824a59ec1e7SMichael Hennerich &dev_attr_l2_bright_max.attr,
825a59ec1e7SMichael Hennerich &dev_attr_l2_bright_dim.attr,
826a59ec1e7SMichael Hennerich &dev_attr_l1_daylight_max.attr,
827a59ec1e7SMichael Hennerich &dev_attr_l1_daylight_dim.attr,
828a59ec1e7SMichael Hennerich #ifdef ADP8870_EXT_FEATURES
829a59ec1e7SMichael Hennerich &dev_attr_ambient_light_level.attr,
830a59ec1e7SMichael Hennerich &dev_attr_ambient_light_zone.attr,
831a59ec1e7SMichael Hennerich #endif
832a59ec1e7SMichael Hennerich NULL
833a59ec1e7SMichael Hennerich };
834a59ec1e7SMichael Hennerich
835a59ec1e7SMichael Hennerich static const struct attribute_group adp8870_bl_attr_group = {
836a59ec1e7SMichael Hennerich .attrs = adp8870_bl_attributes,
837a59ec1e7SMichael Hennerich };
838a59ec1e7SMichael Hennerich
adp8870_probe(struct i2c_client * client)839e78b28b8SUwe Kleine-König static int adp8870_probe(struct i2c_client *client)
840a59ec1e7SMichael Hennerich {
841e78b28b8SUwe Kleine-König const struct i2c_device_id *id = i2c_client_get_device_id(client);
842a59ec1e7SMichael Hennerich struct backlight_properties props;
843a59ec1e7SMichael Hennerich struct backlight_device *bl;
844a59ec1e7SMichael Hennerich struct adp8870_bl *data;
845a59ec1e7SMichael Hennerich struct adp8870_backlight_platform_data *pdata =
846c512794cSJingoo Han dev_get_platdata(&client->dev);
847a59ec1e7SMichael Hennerich uint8_t reg_val;
848a59ec1e7SMichael Hennerich int ret;
849a59ec1e7SMichael Hennerich
850a59ec1e7SMichael Hennerich if (!i2c_check_functionality(client->adapter,
851a59ec1e7SMichael Hennerich I2C_FUNC_SMBUS_BYTE_DATA)) {
852a59ec1e7SMichael Hennerich dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
853a59ec1e7SMichael Hennerich return -EIO;
854a59ec1e7SMichael Hennerich }
855a59ec1e7SMichael Hennerich
856a59ec1e7SMichael Hennerich if (!pdata) {
857a59ec1e7SMichael Hennerich dev_err(&client->dev, "no platform data?\n");
858a59ec1e7SMichael Hennerich return -EINVAL;
859a59ec1e7SMichael Hennerich }
860a59ec1e7SMichael Hennerich
861a59ec1e7SMichael Hennerich ret = adp8870_read(client, ADP8870_MFDVID, ®_val);
862a59ec1e7SMichael Hennerich if (ret < 0)
863a59ec1e7SMichael Hennerich return -EIO;
864a59ec1e7SMichael Hennerich
865a59ec1e7SMichael Hennerich if (ADP8870_MANID(reg_val) != ADP8870_MANUFID) {
866a59ec1e7SMichael Hennerich dev_err(&client->dev, "failed to probe\n");
867a59ec1e7SMichael Hennerich return -ENODEV;
868a59ec1e7SMichael Hennerich }
869a59ec1e7SMichael Hennerich
87091cdb239SJingoo Han data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
871a59ec1e7SMichael Hennerich if (data == NULL)
872a59ec1e7SMichael Hennerich return -ENOMEM;
873a59ec1e7SMichael Hennerich
874a59ec1e7SMichael Hennerich data->revid = ADP8870_DEVID(reg_val);
875a59ec1e7SMichael Hennerich data->client = client;
876a59ec1e7SMichael Hennerich data->pdata = pdata;
877a59ec1e7SMichael Hennerich data->id = id->driver_data;
878a59ec1e7SMichael Hennerich data->current_brightness = 0;
879a59ec1e7SMichael Hennerich i2c_set_clientdata(client, data);
880a59ec1e7SMichael Hennerich
881a59ec1e7SMichael Hennerich mutex_init(&data->lock);
882a59ec1e7SMichael Hennerich
883a59ec1e7SMichael Hennerich memset(&props, 0, sizeof(props));
884e1bbd19bSAndrew Morton props.type = BACKLIGHT_RAW;
885a59ec1e7SMichael Hennerich props.max_brightness = props.brightness = ADP8870_MAX_BRIGHTNESS;
886568ee6c3SJingoo Han bl = devm_backlight_device_register(&client->dev,
887568ee6c3SJingoo Han dev_driver_string(&client->dev),
888a59ec1e7SMichael Hennerich &client->dev, data, &adp8870_bl_ops, &props);
889a59ec1e7SMichael Hennerich if (IS_ERR(bl)) {
890a59ec1e7SMichael Hennerich dev_err(&client->dev, "failed to register backlight\n");
89191cdb239SJingoo Han return PTR_ERR(bl);
892a59ec1e7SMichael Hennerich }
893a59ec1e7SMichael Hennerich
894a59ec1e7SMichael Hennerich data->bl = bl;
895a59ec1e7SMichael Hennerich
8968541b827SJingoo Han if (pdata->en_ambl_sens) {
897a59ec1e7SMichael Hennerich ret = sysfs_create_group(&bl->dev.kobj,
898a59ec1e7SMichael Hennerich &adp8870_bl_attr_group);
899a59ec1e7SMichael Hennerich if (ret) {
900a59ec1e7SMichael Hennerich dev_err(&client->dev, "failed to register sysfs\n");
901568ee6c3SJingoo Han return ret;
902a59ec1e7SMichael Hennerich }
9038541b827SJingoo Han }
904a59ec1e7SMichael Hennerich
905a59ec1e7SMichael Hennerich ret = adp8870_bl_setup(bl);
906a59ec1e7SMichael Hennerich if (ret) {
907a59ec1e7SMichael Hennerich ret = -EIO;
908a59ec1e7SMichael Hennerich goto out;
909a59ec1e7SMichael Hennerich }
910a59ec1e7SMichael Hennerich
911a59ec1e7SMichael Hennerich backlight_update_status(bl);
912a59ec1e7SMichael Hennerich
913a59ec1e7SMichael Hennerich dev_info(&client->dev, "Rev.%d Backlight\n", data->revid);
914a59ec1e7SMichael Hennerich
915a59ec1e7SMichael Hennerich if (pdata->num_leds)
916a59ec1e7SMichael Hennerich adp8870_led_probe(client);
917a59ec1e7SMichael Hennerich
918a59ec1e7SMichael Hennerich return 0;
919a59ec1e7SMichael Hennerich
920a59ec1e7SMichael Hennerich out:
921a59ec1e7SMichael Hennerich if (data->pdata->en_ambl_sens)
922a59ec1e7SMichael Hennerich sysfs_remove_group(&data->bl->dev.kobj,
923a59ec1e7SMichael Hennerich &adp8870_bl_attr_group);
924a59ec1e7SMichael Hennerich
925a59ec1e7SMichael Hennerich return ret;
926a59ec1e7SMichael Hennerich }
927a59ec1e7SMichael Hennerich
adp8870_remove(struct i2c_client * client)928ed5c2f5fSUwe Kleine-König static void adp8870_remove(struct i2c_client *client)
929a59ec1e7SMichael Hennerich {
930a59ec1e7SMichael Hennerich struct adp8870_bl *data = i2c_get_clientdata(client);
931a59ec1e7SMichael Hennerich
932a59ec1e7SMichael Hennerich adp8870_clr_bits(client, ADP8870_MDCR, NSTBY);
933a59ec1e7SMichael Hennerich
934a59ec1e7SMichael Hennerich if (data->led)
935a59ec1e7SMichael Hennerich adp8870_led_remove(client);
936a59ec1e7SMichael Hennerich
937a59ec1e7SMichael Hennerich if (data->pdata->en_ambl_sens)
938a59ec1e7SMichael Hennerich sysfs_remove_group(&data->bl->dev.kobj,
939a59ec1e7SMichael Hennerich &adp8870_bl_attr_group);
940a59ec1e7SMichael Hennerich }
941a59ec1e7SMichael Hennerich
9423cd4291aSJingoo Han #ifdef CONFIG_PM_SLEEP
adp8870_i2c_suspend(struct device * dev)9433cd4291aSJingoo Han static int adp8870_i2c_suspend(struct device *dev)
944a59ec1e7SMichael Hennerich {
9453cd4291aSJingoo Han struct i2c_client *client = to_i2c_client(dev);
9463cd4291aSJingoo Han
947a59ec1e7SMichael Hennerich adp8870_clr_bits(client, ADP8870_MDCR, NSTBY);
948a59ec1e7SMichael Hennerich
949a59ec1e7SMichael Hennerich return 0;
950a59ec1e7SMichael Hennerich }
951a59ec1e7SMichael Hennerich
adp8870_i2c_resume(struct device * dev)9523cd4291aSJingoo Han static int adp8870_i2c_resume(struct device *dev)
953a59ec1e7SMichael Hennerich {
9543cd4291aSJingoo Han struct i2c_client *client = to_i2c_client(dev);
9553cd4291aSJingoo Han
9565eb02c01SLars-Peter Clausen adp8870_set_bits(client, ADP8870_MDCR, NSTBY | BLEN);
957a59ec1e7SMichael Hennerich
958a59ec1e7SMichael Hennerich return 0;
959a59ec1e7SMichael Hennerich }
960a59ec1e7SMichael Hennerich #endif
961a59ec1e7SMichael Hennerich
9623cd4291aSJingoo Han static SIMPLE_DEV_PM_OPS(adp8870_i2c_pm_ops, adp8870_i2c_suspend,
9633cd4291aSJingoo Han adp8870_i2c_resume);
9643cd4291aSJingoo Han
965a59ec1e7SMichael Hennerich static const struct i2c_device_id adp8870_id[] = {
966a59ec1e7SMichael Hennerich { "adp8870", 0 },
967a59ec1e7SMichael Hennerich { }
968a59ec1e7SMichael Hennerich };
969a59ec1e7SMichael Hennerich MODULE_DEVICE_TABLE(i2c, adp8870_id);
970a59ec1e7SMichael Hennerich
971a59ec1e7SMichael Hennerich static struct i2c_driver adp8870_driver = {
972a59ec1e7SMichael Hennerich .driver = {
973a59ec1e7SMichael Hennerich .name = KBUILD_MODNAME,
9743cd4291aSJingoo Han .pm = &adp8870_i2c_pm_ops,
975a59ec1e7SMichael Hennerich },
976*29554f2eSUwe Kleine-König .probe = adp8870_probe,
977d1723fa2SBill Pemberton .remove = adp8870_remove,
978a59ec1e7SMichael Hennerich .id_table = adp8870_id,
979a59ec1e7SMichael Hennerich };
980a59ec1e7SMichael Hennerich
98181ce6864SAxel Lin module_i2c_driver(adp8870_driver);
982a59ec1e7SMichael Hennerich
983a59ec1e7SMichael Hennerich MODULE_LICENSE("GPL v2");
9840b193400SMichael Hennerich MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
985a59ec1e7SMichael Hennerich MODULE_DESCRIPTION("ADP8870 Backlight driver");
986