blob: b26306f6724dcebc1605625405625aeebe022298 [file] [log] [blame]
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -07001/*
2 * Copyright (C) 2011 ST-Ericsson SA.
3 * Copyright (C) 2009 Motorola, Inc.
4 *
5 * License Terms: GNU General Public License v2
6 *
7 * Simple driver for National Semiconductor LM3530 Backlight driver chip
8 *
9 * Author: Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>
10 * based on leds-lm3530.c by Dan Murphy <D.Murphy@motorola.com>
11 */
12
13#include <linux/i2c.h>
14#include <linux/leds.h>
15#include <linux/slab.h>
16#include <linux/platform_device.h>
17#include <linux/input.h>
18#include <linux/led-lm3530.h>
19#include <linux/types.h>
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -070020#include <linux/regulator/consumer.h>
Paul Gortmaker54f4ded2011-07-03 13:56:03 -040021#include <linux/module.h>
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -070022
23#define LM3530_LED_DEV "lcd-backlight"
24#define LM3530_NAME "lm3530-led"
25
26#define LM3530_GEN_CONFIG 0x10
27#define LM3530_ALS_CONFIG 0x20
28#define LM3530_BRT_RAMP_RATE 0x30
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -070029#define LM3530_ALS_IMP_SELECT 0x41
30#define LM3530_BRT_CTRL_REG 0xA0
31#define LM3530_ALS_ZB0_REG 0x60
32#define LM3530_ALS_ZB1_REG 0x61
33#define LM3530_ALS_ZB2_REG 0x62
34#define LM3530_ALS_ZB3_REG 0x63
35#define LM3530_ALS_Z0T_REG 0x70
36#define LM3530_ALS_Z1T_REG 0x71
37#define LM3530_ALS_Z2T_REG 0x72
38#define LM3530_ALS_Z3T_REG 0x73
39#define LM3530_ALS_Z4T_REG 0x74
Kim, Milo8544d0e2012-03-23 15:02:12 -070040#define LM3530_REG_MAX 14
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -070041
42/* General Control Register */
43#define LM3530_EN_I2C_SHIFT (0)
44#define LM3530_RAMP_LAW_SHIFT (1)
45#define LM3530_MAX_CURR_SHIFT (2)
46#define LM3530_EN_PWM_SHIFT (5)
47#define LM3530_PWM_POL_SHIFT (6)
48#define LM3530_EN_PWM_SIMPLE_SHIFT (7)
49
50#define LM3530_ENABLE_I2C (1 << LM3530_EN_I2C_SHIFT)
51#define LM3530_ENABLE_PWM (1 << LM3530_EN_PWM_SHIFT)
52#define LM3530_POL_LOW (1 << LM3530_PWM_POL_SHIFT)
53#define LM3530_ENABLE_PWM_SIMPLE (1 << LM3530_EN_PWM_SIMPLE_SHIFT)
54
55/* ALS Config Register Options */
56#define LM3530_ALS_AVG_TIME_SHIFT (0)
57#define LM3530_EN_ALS_SHIFT (3)
58#define LM3530_ALS_SEL_SHIFT (5)
59
60#define LM3530_ENABLE_ALS (3 << LM3530_EN_ALS_SHIFT)
61
62/* Brightness Ramp Rate Register */
63#define LM3530_BRT_RAMP_FALL_SHIFT (0)
64#define LM3530_BRT_RAMP_RISE_SHIFT (3)
65
66/* ALS Resistor Select */
67#define LM3530_ALS1_IMP_SHIFT (0)
68#define LM3530_ALS2_IMP_SHIFT (4)
69
70/* Zone Boundary Register defaults */
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -070071#define LM3530_ALS_ZB_MAX (4)
72#define LM3530_ALS_WINDOW_mV (1000)
73#define LM3530_ALS_OFFSET_mV (4)
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -070074
75/* Zone Target Register defaults */
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -070076#define LM3530_DEF_ZT_0 (0x7F)
77#define LM3530_DEF_ZT_1 (0x66)
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -070078#define LM3530_DEF_ZT_2 (0x4C)
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -070079#define LM3530_DEF_ZT_3 (0x33)
80#define LM3530_DEF_ZT_4 (0x19)
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -070081
Kim, Milobbe64532012-03-23 15:02:11 -070082/* 7 bits are used for the brightness : LM3530_BRT_CTRL_REG */
83#define MAX_BRIGHTNESS (127)
84
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -070085struct lm3530_mode_map {
86 const char *mode;
87 enum lm3530_mode mode_val;
88};
89
90static struct lm3530_mode_map mode_map[] = {
91 { "man", LM3530_BL_MODE_MANUAL },
92 { "als", LM3530_BL_MODE_ALS },
93 { "pwm", LM3530_BL_MODE_PWM },
94};
95
96/**
97 * struct lm3530_data
98 * @led_dev: led class device
99 * @client: i2c client
100 * @pdata: LM3530 platform data
101 * @mode: mode of operation - manual, ALS, PWM
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700102 * @regulator: regulator
103 * @brighness: previous brightness value
104 * @enable: regulator is enabled
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700105 */
106struct lm3530_data {
107 struct led_classdev led_dev;
108 struct i2c_client *client;
109 struct lm3530_platform_data *pdata;
110 enum lm3530_mode mode;
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700111 struct regulator *regulator;
112 enum led_brightness brightness;
113 bool enable;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700114};
115
Kim, Milo6335f8f2012-05-29 15:07:29 -0700116/*
117 * struct lm3530_als_data
118 * @config : value of ALS configuration register
119 * @imp_sel : value of ALS resistor select register
120 * @zone : values of ALS ZB(Zone Boundary) registers
121 */
122struct lm3530_als_data {
123 u8 config;
124 u8 imp_sel;
125 u8 zones[LM3530_ALS_ZB_MAX];
126};
127
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700128static const u8 lm3530_reg[LM3530_REG_MAX] = {
129 LM3530_GEN_CONFIG,
130 LM3530_ALS_CONFIG,
131 LM3530_BRT_RAMP_RATE,
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700132 LM3530_ALS_IMP_SELECT,
133 LM3530_BRT_CTRL_REG,
134 LM3530_ALS_ZB0_REG,
135 LM3530_ALS_ZB1_REG,
136 LM3530_ALS_ZB2_REG,
137 LM3530_ALS_ZB3_REG,
138 LM3530_ALS_Z0T_REG,
139 LM3530_ALS_Z1T_REG,
140 LM3530_ALS_Z2T_REG,
141 LM3530_ALS_Z3T_REG,
142 LM3530_ALS_Z4T_REG,
143};
144
145static int lm3530_get_mode_from_str(const char *str)
146{
147 int i;
148
149 for (i = 0; i < ARRAY_SIZE(mode_map); i++)
150 if (sysfs_streq(str, mode_map[i].mode))
151 return mode_map[i].mode_val;
152
Sachin Kamate0e02162012-09-12 14:34:09 +0800153 return -EINVAL;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700154}
155
Kim, Milo6335f8f2012-05-29 15:07:29 -0700156static void lm3530_als_configure(struct lm3530_platform_data *pdata,
157 struct lm3530_als_data *als)
158{
159 int i;
160 u32 als_vmin, als_vmax, als_vstep;
161
162 if (pdata->als_vmax == 0) {
163 pdata->als_vmin = 0;
164 pdata->als_vmax = LM3530_ALS_WINDOW_mV;
165 }
166
167 als_vmin = pdata->als_vmin;
168 als_vmax = pdata->als_vmax;
169
170 if ((als_vmax - als_vmin) > LM3530_ALS_WINDOW_mV)
171 pdata->als_vmax = als_vmax = als_vmin + LM3530_ALS_WINDOW_mV;
172
173 /* n zone boundary makes n+1 zones */
174 als_vstep = (als_vmax - als_vmin) / (LM3530_ALS_ZB_MAX + 1);
175
176 for (i = 0; i < LM3530_ALS_ZB_MAX; i++)
177 als->zones[i] = (((als_vmin + LM3530_ALS_OFFSET_mV) +
178 als_vstep + (i * als_vstep)) * LED_FULL) / 1000;
179
180 als->config =
181 (pdata->als_avrg_time << LM3530_ALS_AVG_TIME_SHIFT) |
182 (LM3530_ENABLE_ALS) |
183 (pdata->als_input_mode << LM3530_ALS_SEL_SHIFT);
184
185 als->imp_sel =
186 (pdata->als1_resistor_sel << LM3530_ALS1_IMP_SHIFT) |
187 (pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT);
188}
189
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700190static int lm3530_init_registers(struct lm3530_data *drvdata)
191{
192 int ret = 0;
193 int i;
194 u8 gen_config;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700195 u8 brt_ramp;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700196 u8 brightness;
197 u8 reg_val[LM3530_REG_MAX];
Kim, Milo99ad98d2012-03-23 15:02:13 -0700198 struct lm3530_platform_data *pdata = drvdata->pdata;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700199 struct i2c_client *client = drvdata->client;
Kim, Milo99ad98d2012-03-23 15:02:13 -0700200 struct lm3530_pwm_data *pwm = &pdata->pwm_data;
Kim, Milo6335f8f2012-05-29 15:07:29 -0700201 struct lm3530_als_data als;
202
203 memset(&als, 0, sizeof(struct lm3530_als_data));
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700204
Kim, Milo99ad98d2012-03-23 15:02:13 -0700205 gen_config = (pdata->brt_ramp_law << LM3530_RAMP_LAW_SHIFT) |
206 ((pdata->max_current & 7) << LM3530_MAX_CURR_SHIFT);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700207
Axel Lincea694c2012-03-23 15:02:13 -0700208 switch (drvdata->mode) {
209 case LM3530_BL_MODE_MANUAL:
Kim, Milo6335f8f2012-05-29 15:07:29 -0700210 gen_config |= LM3530_ENABLE_I2C;
211 break;
Axel Lincea694c2012-03-23 15:02:13 -0700212 case LM3530_BL_MODE_ALS:
213 gen_config |= LM3530_ENABLE_I2C;
Kim, Milo6335f8f2012-05-29 15:07:29 -0700214 lm3530_als_configure(pdata, &als);
Axel Lincea694c2012-03-23 15:02:13 -0700215 break;
216 case LM3530_BL_MODE_PWM:
217 gen_config |= LM3530_ENABLE_PWM | LM3530_ENABLE_PWM_SIMPLE |
218 (pdata->pwm_pol_hi << LM3530_PWM_POL_SHIFT);
219 break;
220 }
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700221
Kim, Milo99ad98d2012-03-23 15:02:13 -0700222 brt_ramp = (pdata->brt_ramp_fall << LM3530_BRT_RAMP_FALL_SHIFT) |
223 (pdata->brt_ramp_rise << LM3530_BRT_RAMP_RISE_SHIFT);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700224
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700225 if (drvdata->brightness)
226 brightness = drvdata->brightness;
227 else
Kim, Milo99ad98d2012-03-23 15:02:13 -0700228 brightness = drvdata->brightness = pdata->brt_val;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700229
Kim, Milobbe64532012-03-23 15:02:11 -0700230 if (brightness > drvdata->led_dev.max_brightness)
231 brightness = drvdata->led_dev.max_brightness;
232
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700233 reg_val[0] = gen_config; /* LM3530_GEN_CONFIG */
Kim, Milo6335f8f2012-05-29 15:07:29 -0700234 reg_val[1] = als.config; /* LM3530_ALS_CONFIG */
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700235 reg_val[2] = brt_ramp; /* LM3530_BRT_RAMP_RATE */
Kim, Milo6335f8f2012-05-29 15:07:29 -0700236 reg_val[3] = als.imp_sel; /* LM3530_ALS_IMP_SELECT */
Kim, Milo8544d0e2012-03-23 15:02:12 -0700237 reg_val[4] = brightness; /* LM3530_BRT_CTRL_REG */
Kim, Milo6335f8f2012-05-29 15:07:29 -0700238 reg_val[5] = als.zones[0]; /* LM3530_ALS_ZB0_REG */
239 reg_val[6] = als.zones[1]; /* LM3530_ALS_ZB1_REG */
240 reg_val[7] = als.zones[2]; /* LM3530_ALS_ZB2_REG */
241 reg_val[8] = als.zones[3]; /* LM3530_ALS_ZB3_REG */
Kim, Milo8544d0e2012-03-23 15:02:12 -0700242 reg_val[9] = LM3530_DEF_ZT_0; /* LM3530_ALS_Z0T_REG */
243 reg_val[10] = LM3530_DEF_ZT_1; /* LM3530_ALS_Z1T_REG */
244 reg_val[11] = LM3530_DEF_ZT_2; /* LM3530_ALS_Z2T_REG */
245 reg_val[12] = LM3530_DEF_ZT_3; /* LM3530_ALS_Z3T_REG */
246 reg_val[13] = LM3530_DEF_ZT_4; /* LM3530_ALS_Z4T_REG */
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700247
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700248 if (!drvdata->enable) {
249 ret = regulator_enable(drvdata->regulator);
250 if (ret) {
251 dev_err(&drvdata->client->dev,
252 "Enable regulator failed\n");
253 return ret;
254 }
255 drvdata->enable = true;
256 }
257
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700258 for (i = 0; i < LM3530_REG_MAX; i++) {
Kim, Milobb982002012-03-23 15:02:12 -0700259 /* do not update brightness register when pwm mode */
260 if (lm3530_reg[i] == LM3530_BRT_CTRL_REG &&
261 drvdata->mode == LM3530_BL_MODE_PWM) {
262 if (pwm->pwm_set_intensity)
263 pwm->pwm_set_intensity(reg_val[i],
264 drvdata->led_dev.max_brightness);
265 continue;
266 }
267
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700268 ret = i2c_smbus_write_byte_data(client,
269 lm3530_reg[i], reg_val[i]);
270 if (ret)
271 break;
272 }
273
274 return ret;
275}
276
277static void lm3530_brightness_set(struct led_classdev *led_cdev,
278 enum led_brightness brt_val)
279{
280 int err;
281 struct lm3530_data *drvdata =
282 container_of(led_cdev, struct lm3530_data, led_dev);
Kim, Milobb982002012-03-23 15:02:12 -0700283 struct lm3530_platform_data *pdata = drvdata->pdata;
284 struct lm3530_pwm_data *pwm = &pdata->pwm_data;
285 u8 max_brightness = led_cdev->max_brightness;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700286
287 switch (drvdata->mode) {
288 case LM3530_BL_MODE_MANUAL:
289
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700290 if (!drvdata->enable) {
291 err = lm3530_init_registers(drvdata);
292 if (err) {
293 dev_err(&drvdata->client->dev,
294 "Register Init failed: %d\n", err);
295 break;
296 }
297 }
298
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700299 /* set the brightness in brightness control register*/
300 err = i2c_smbus_write_byte_data(drvdata->client,
Kim, Milobbe64532012-03-23 15:02:11 -0700301 LM3530_BRT_CTRL_REG, brt_val);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700302 if (err)
303 dev_err(&drvdata->client->dev,
304 "Unable to set brightness: %d\n", err);
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700305 else
Kim, Milobbe64532012-03-23 15:02:11 -0700306 drvdata->brightness = brt_val;
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700307
308 if (brt_val == 0) {
309 err = regulator_disable(drvdata->regulator);
310 if (err)
311 dev_err(&drvdata->client->dev,
312 "Disable regulator failed\n");
313 drvdata->enable = false;
314 }
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700315 break;
316 case LM3530_BL_MODE_ALS:
317 break;
318 case LM3530_BL_MODE_PWM:
Kim, Milobb982002012-03-23 15:02:12 -0700319 if (pwm->pwm_set_intensity)
320 pwm->pwm_set_intensity(brt_val, max_brightness);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700321 break;
322 default:
323 break;
324 }
325}
326
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700327static ssize_t lm3530_mode_get(struct device *dev,
328 struct device_attribute *attr, char *buf)
329{
Kim, Miloe13d9782012-03-23 15:02:11 -0700330 struct led_classdev *led_cdev = dev_get_drvdata(dev);
331 struct lm3530_data *drvdata;
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700332 int i, len = 0;
333
Kim, Miloe13d9782012-03-23 15:02:11 -0700334 drvdata = container_of(led_cdev, struct lm3530_data, led_dev);
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700335 for (i = 0; i < ARRAY_SIZE(mode_map); i++)
336 if (drvdata->mode == mode_map[i].mode_val)
337 len += sprintf(buf + len, "[%s] ", mode_map[i].mode);
338 else
339 len += sprintf(buf + len, "%s ", mode_map[i].mode);
340
341 len += sprintf(buf + len, "\n");
342
343 return len;
344}
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700345
346static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute
347 *attr, const char *buf, size_t size)
348{
Kim, Miloe13d9782012-03-23 15:02:11 -0700349 struct led_classdev *led_cdev = dev_get_drvdata(dev);
350 struct lm3530_data *drvdata;
Kim, Milobb982002012-03-23 15:02:12 -0700351 struct lm3530_pwm_data *pwm;
352 u8 max_brightness;
Kim, Miloe13d9782012-03-23 15:02:11 -0700353 int mode, err;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700354
Kim, Miloe13d9782012-03-23 15:02:11 -0700355 drvdata = container_of(led_cdev, struct lm3530_data, led_dev);
Kim, Milobb982002012-03-23 15:02:12 -0700356 pwm = &drvdata->pdata->pwm_data;
357 max_brightness = led_cdev->max_brightness;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700358 mode = lm3530_get_mode_from_str(buf);
359 if (mode < 0) {
360 dev_err(dev, "Invalid mode\n");
Sachin Kamate0e02162012-09-12 14:34:09 +0800361 return mode;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700362 }
363
Kim, Milobb982002012-03-23 15:02:12 -0700364 drvdata->mode = mode;
365
366 /* set pwm to low if unnecessary */
367 if (mode != LM3530_BL_MODE_PWM && pwm->pwm_set_intensity)
368 pwm->pwm_set_intensity(0, max_brightness);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700369
370 err = lm3530_init_registers(drvdata);
371 if (err) {
372 dev_err(dev, "Setting %s Mode failed :%d\n", buf, err);
373 return err;
374 }
375
376 return sizeof(drvdata->mode);
377}
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700378static DEVICE_ATTR(mode, 0644, lm3530_mode_get, lm3530_mode_set);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700379
380static int __devinit lm3530_probe(struct i2c_client *client,
381 const struct i2c_device_id *id)
382{
383 struct lm3530_platform_data *pdata = client->dev.platform_data;
384 struct lm3530_data *drvdata;
385 int err = 0;
386
387 if (pdata == NULL) {
388 dev_err(&client->dev, "platform data required\n");
Bryan Wu0b873f32012-07-04 12:24:40 +0800389 return -ENODEV;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700390 }
391
392 /* BL mode */
393 if (pdata->mode > LM3530_BL_MODE_PWM) {
394 dev_err(&client->dev, "Illegal Mode request\n");
Bryan Wu0b873f32012-07-04 12:24:40 +0800395 return -EINVAL;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700396 }
397
398 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
399 dev_err(&client->dev, "I2C_FUNC_I2C not supported\n");
Bryan Wu0b873f32012-07-04 12:24:40 +0800400 return -EIO;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700401 }
402
Bryan Wu0b873f32012-07-04 12:24:40 +0800403 drvdata = devm_kzalloc(&client->dev, sizeof(struct lm3530_data),
404 GFP_KERNEL);
405 if (drvdata == NULL)
406 return -ENOMEM;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700407
408 drvdata->mode = pdata->mode;
409 drvdata->client = client;
410 drvdata->pdata = pdata;
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700411 drvdata->brightness = LED_OFF;
412 drvdata->enable = false;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700413 drvdata->led_dev.name = LM3530_LED_DEV;
414 drvdata->led_dev.brightness_set = lm3530_brightness_set;
Kim, Milobbe64532012-03-23 15:02:11 -0700415 drvdata->led_dev.max_brightness = MAX_BRIGHTNESS;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700416
417 i2c_set_clientdata(client, drvdata);
418
Sachin Kamata47df972012-09-11 19:42:10 +0800419 drvdata->regulator = devm_regulator_get(&client->dev, "vin");
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700420 if (IS_ERR(drvdata->regulator)) {
421 dev_err(&client->dev, "regulator get failed\n");
422 err = PTR_ERR(drvdata->regulator);
423 drvdata->regulator = NULL;
Bryan Wu0b873f32012-07-04 12:24:40 +0800424 return err;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700425 }
426
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700427 if (drvdata->pdata->brt_val) {
428 err = lm3530_init_registers(drvdata);
429 if (err < 0) {
430 dev_err(&client->dev,
431 "Register Init failed: %d\n", err);
Sachin Kamate0e02162012-09-12 14:34:09 +0800432 return err;
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700433 }
434 }
435 err = led_classdev_register(&client->dev, &drvdata->led_dev);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700436 if (err < 0) {
437 dev_err(&client->dev, "Register led class failed: %d\n", err);
Sachin Kamate0e02162012-09-12 14:34:09 +0800438 return err;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700439 }
440
441 err = device_create_file(drvdata->led_dev.dev, &dev_attr_mode);
442 if (err < 0) {
443 dev_err(&client->dev, "File device creation failed: %d\n", err);
444 err = -ENODEV;
445 goto err_create_file;
446 }
447
448 return 0;
449
450err_create_file:
451 led_classdev_unregister(&drvdata->led_dev);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700452 return err;
453}
454
455static int __devexit lm3530_remove(struct i2c_client *client)
456{
457 struct lm3530_data *drvdata = i2c_get_clientdata(client);
458
459 device_remove_file(drvdata->led_dev.dev, &dev_attr_mode);
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700460
461 if (drvdata->enable)
462 regulator_disable(drvdata->regulator);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700463 led_classdev_unregister(&drvdata->led_dev);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700464 return 0;
465}
466
467static const struct i2c_device_id lm3530_id[] = {
468 {LM3530_NAME, 0},
469 {}
470};
Axel Lind5f33d42011-05-17 15:44:09 -0700471MODULE_DEVICE_TABLE(i2c, lm3530_id);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700472
473static struct i2c_driver lm3530_i2c_driver = {
474 .probe = lm3530_probe,
Axel Lin93f53982011-10-31 17:12:15 -0700475 .remove = __devexit_p(lm3530_remove),
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700476 .id_table = lm3530_id,
477 .driver = {
478 .name = LM3530_NAME,
479 .owner = THIS_MODULE,
480 },
481};
482
Axel Lin09a0d182012-01-10 15:09:27 -0800483module_i2c_driver(lm3530_i2c_driver);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700484
485MODULE_DESCRIPTION("Back Light driver for LM3530");
486MODULE_LICENSE("GPL v2");
487MODULE_AUTHOR("Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>");