blob: 9f49d9550e8876e23c1da0d52355e0ce4965c743 [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
116static const u8 lm3530_reg[LM3530_REG_MAX] = {
117 LM3530_GEN_CONFIG,
118 LM3530_ALS_CONFIG,
119 LM3530_BRT_RAMP_RATE,
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700120 LM3530_ALS_IMP_SELECT,
121 LM3530_BRT_CTRL_REG,
122 LM3530_ALS_ZB0_REG,
123 LM3530_ALS_ZB1_REG,
124 LM3530_ALS_ZB2_REG,
125 LM3530_ALS_ZB3_REG,
126 LM3530_ALS_Z0T_REG,
127 LM3530_ALS_Z1T_REG,
128 LM3530_ALS_Z2T_REG,
129 LM3530_ALS_Z3T_REG,
130 LM3530_ALS_Z4T_REG,
131};
132
133static int lm3530_get_mode_from_str(const char *str)
134{
135 int i;
136
137 for (i = 0; i < ARRAY_SIZE(mode_map); i++)
138 if (sysfs_streq(str, mode_map[i].mode))
139 return mode_map[i].mode_val;
140
141 return -1;
142}
143
144static int lm3530_init_registers(struct lm3530_data *drvdata)
145{
146 int ret = 0;
147 int i;
148 u8 gen_config;
149 u8 als_config = 0;
150 u8 brt_ramp;
151 u8 als_imp_sel = 0;
152 u8 brightness;
153 u8 reg_val[LM3530_REG_MAX];
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700154 u8 zones[LM3530_ALS_ZB_MAX];
155 u32 als_vmin, als_vmax, als_vstep;
Kim, Milo99ad98d2012-03-23 15:02:13 -0700156 struct lm3530_platform_data *pdata = drvdata->pdata;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700157 struct i2c_client *client = drvdata->client;
Kim, Milo99ad98d2012-03-23 15:02:13 -0700158 struct lm3530_pwm_data *pwm = &pdata->pwm_data;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700159
Kim, Milo99ad98d2012-03-23 15:02:13 -0700160 gen_config = (pdata->brt_ramp_law << LM3530_RAMP_LAW_SHIFT) |
161 ((pdata->max_current & 7) << LM3530_MAX_CURR_SHIFT);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700162
163 if (drvdata->mode == LM3530_BL_MODE_MANUAL ||
164 drvdata->mode == LM3530_BL_MODE_ALS)
165 gen_config |= (LM3530_ENABLE_I2C);
166
167 if (drvdata->mode == LM3530_BL_MODE_ALS) {
Kim, Milo99ad98d2012-03-23 15:02:13 -0700168 if (pdata->als_vmax == 0) {
169 pdata->als_vmin = 0;
170 pdata->als_vmax = LM3530_ALS_WINDOW_mV;
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700171 }
172
Kim, Milo99ad98d2012-03-23 15:02:13 -0700173 als_vmin = pdata->als_vmin;
174 als_vmax = pdata->als_vmax;
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700175
176 if ((als_vmax - als_vmin) > LM3530_ALS_WINDOW_mV)
Kim, Milo99ad98d2012-03-23 15:02:13 -0700177 pdata->als_vmax = als_vmax =
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700178 als_vmin + LM3530_ALS_WINDOW_mV;
179
180 /* n zone boundary makes n+1 zones */
181 als_vstep = (als_vmax - als_vmin) / (LM3530_ALS_ZB_MAX + 1);
182
183 for (i = 0; i < LM3530_ALS_ZB_MAX; i++)
184 zones[i] = (((als_vmin + LM3530_ALS_OFFSET_mV) +
185 als_vstep + (i * als_vstep)) * LED_FULL)
186 / 1000;
187
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700188 als_config =
Kim, Milo99ad98d2012-03-23 15:02:13 -0700189 (pdata->als_avrg_time << LM3530_ALS_AVG_TIME_SHIFT) |
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700190 (LM3530_ENABLE_ALS) |
Kim, Milo99ad98d2012-03-23 15:02:13 -0700191 (pdata->als_input_mode << LM3530_ALS_SEL_SHIFT);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700192
193 als_imp_sel =
Kim, Milo99ad98d2012-03-23 15:02:13 -0700194 (pdata->als1_resistor_sel << LM3530_ALS1_IMP_SHIFT) |
195 (pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT);
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700196
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700197 }
198
199 if (drvdata->mode == LM3530_BL_MODE_PWM)
200 gen_config |= (LM3530_ENABLE_PWM) |
Kim, Milo99ad98d2012-03-23 15:02:13 -0700201 (pdata->pwm_pol_hi << LM3530_PWM_POL_SHIFT) |
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700202 (LM3530_ENABLE_PWM_SIMPLE);
203
Kim, Milo99ad98d2012-03-23 15:02:13 -0700204 brt_ramp = (pdata->brt_ramp_fall << LM3530_BRT_RAMP_FALL_SHIFT) |
205 (pdata->brt_ramp_rise << LM3530_BRT_RAMP_RISE_SHIFT);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700206
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700207 if (drvdata->brightness)
208 brightness = drvdata->brightness;
209 else
Kim, Milo99ad98d2012-03-23 15:02:13 -0700210 brightness = drvdata->brightness = pdata->brt_val;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700211
Kim, Milobbe64532012-03-23 15:02:11 -0700212 if (brightness > drvdata->led_dev.max_brightness)
213 brightness = drvdata->led_dev.max_brightness;
214
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700215 reg_val[0] = gen_config; /* LM3530_GEN_CONFIG */
216 reg_val[1] = als_config; /* LM3530_ALS_CONFIG */
217 reg_val[2] = brt_ramp; /* LM3530_BRT_RAMP_RATE */
Kim, Milo8544d0e2012-03-23 15:02:12 -0700218 reg_val[3] = als_imp_sel; /* LM3530_ALS_IMP_SELECT */
219 reg_val[4] = brightness; /* LM3530_BRT_CTRL_REG */
220 reg_val[5] = zones[0]; /* LM3530_ALS_ZB0_REG */
221 reg_val[6] = zones[1]; /* LM3530_ALS_ZB1_REG */
222 reg_val[7] = zones[2]; /* LM3530_ALS_ZB2_REG */
223 reg_val[8] = zones[3]; /* LM3530_ALS_ZB3_REG */
224 reg_val[9] = LM3530_DEF_ZT_0; /* LM3530_ALS_Z0T_REG */
225 reg_val[10] = LM3530_DEF_ZT_1; /* LM3530_ALS_Z1T_REG */
226 reg_val[11] = LM3530_DEF_ZT_2; /* LM3530_ALS_Z2T_REG */
227 reg_val[12] = LM3530_DEF_ZT_3; /* LM3530_ALS_Z3T_REG */
228 reg_val[13] = LM3530_DEF_ZT_4; /* LM3530_ALS_Z4T_REG */
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700229
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700230 if (!drvdata->enable) {
231 ret = regulator_enable(drvdata->regulator);
232 if (ret) {
233 dev_err(&drvdata->client->dev,
234 "Enable regulator failed\n");
235 return ret;
236 }
237 drvdata->enable = true;
238 }
239
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700240 for (i = 0; i < LM3530_REG_MAX; i++) {
Kim, Milobb982002012-03-23 15:02:12 -0700241 /* do not update brightness register when pwm mode */
242 if (lm3530_reg[i] == LM3530_BRT_CTRL_REG &&
243 drvdata->mode == LM3530_BL_MODE_PWM) {
244 if (pwm->pwm_set_intensity)
245 pwm->pwm_set_intensity(reg_val[i],
246 drvdata->led_dev.max_brightness);
247 continue;
248 }
249
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700250 ret = i2c_smbus_write_byte_data(client,
251 lm3530_reg[i], reg_val[i]);
252 if (ret)
253 break;
254 }
255
256 return ret;
257}
258
259static void lm3530_brightness_set(struct led_classdev *led_cdev,
260 enum led_brightness brt_val)
261{
262 int err;
263 struct lm3530_data *drvdata =
264 container_of(led_cdev, struct lm3530_data, led_dev);
Kim, Milobb982002012-03-23 15:02:12 -0700265 struct lm3530_platform_data *pdata = drvdata->pdata;
266 struct lm3530_pwm_data *pwm = &pdata->pwm_data;
267 u8 max_brightness = led_cdev->max_brightness;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700268
269 switch (drvdata->mode) {
270 case LM3530_BL_MODE_MANUAL:
271
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700272 if (!drvdata->enable) {
273 err = lm3530_init_registers(drvdata);
274 if (err) {
275 dev_err(&drvdata->client->dev,
276 "Register Init failed: %d\n", err);
277 break;
278 }
279 }
280
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700281 /* set the brightness in brightness control register*/
282 err = i2c_smbus_write_byte_data(drvdata->client,
Kim, Milobbe64532012-03-23 15:02:11 -0700283 LM3530_BRT_CTRL_REG, brt_val);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700284 if (err)
285 dev_err(&drvdata->client->dev,
286 "Unable to set brightness: %d\n", err);
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700287 else
Kim, Milobbe64532012-03-23 15:02:11 -0700288 drvdata->brightness = brt_val;
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700289
290 if (brt_val == 0) {
291 err = regulator_disable(drvdata->regulator);
292 if (err)
293 dev_err(&drvdata->client->dev,
294 "Disable regulator failed\n");
295 drvdata->enable = false;
296 }
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700297 break;
298 case LM3530_BL_MODE_ALS:
299 break;
300 case LM3530_BL_MODE_PWM:
Kim, Milobb982002012-03-23 15:02:12 -0700301 if (pwm->pwm_set_intensity)
302 pwm->pwm_set_intensity(brt_val, max_brightness);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700303 break;
304 default:
305 break;
306 }
307}
308
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700309static ssize_t lm3530_mode_get(struct device *dev,
310 struct device_attribute *attr, char *buf)
311{
Kim, Miloe13d9782012-03-23 15:02:11 -0700312 struct led_classdev *led_cdev = dev_get_drvdata(dev);
313 struct lm3530_data *drvdata;
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700314 int i, len = 0;
315
Kim, Miloe13d9782012-03-23 15:02:11 -0700316 drvdata = container_of(led_cdev, struct lm3530_data, led_dev);
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700317 for (i = 0; i < ARRAY_SIZE(mode_map); i++)
318 if (drvdata->mode == mode_map[i].mode_val)
319 len += sprintf(buf + len, "[%s] ", mode_map[i].mode);
320 else
321 len += sprintf(buf + len, "%s ", mode_map[i].mode);
322
323 len += sprintf(buf + len, "\n");
324
325 return len;
326}
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700327
328static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute
329 *attr, const char *buf, size_t size)
330{
Kim, Miloe13d9782012-03-23 15:02:11 -0700331 struct led_classdev *led_cdev = dev_get_drvdata(dev);
332 struct lm3530_data *drvdata;
Kim, Milobb982002012-03-23 15:02:12 -0700333 struct lm3530_pwm_data *pwm;
334 u8 max_brightness;
Kim, Miloe13d9782012-03-23 15:02:11 -0700335 int mode, err;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700336
Kim, Miloe13d9782012-03-23 15:02:11 -0700337 drvdata = container_of(led_cdev, struct lm3530_data, led_dev);
Kim, Milobb982002012-03-23 15:02:12 -0700338 pwm = &drvdata->pdata->pwm_data;
339 max_brightness = led_cdev->max_brightness;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700340 mode = lm3530_get_mode_from_str(buf);
341 if (mode < 0) {
342 dev_err(dev, "Invalid mode\n");
343 return -EINVAL;
344 }
345
Kim, Milobb982002012-03-23 15:02:12 -0700346 drvdata->mode = mode;
347
348 /* set pwm to low if unnecessary */
349 if (mode != LM3530_BL_MODE_PWM && pwm->pwm_set_intensity)
350 pwm->pwm_set_intensity(0, max_brightness);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700351
352 err = lm3530_init_registers(drvdata);
353 if (err) {
354 dev_err(dev, "Setting %s Mode failed :%d\n", buf, err);
355 return err;
356 }
357
358 return sizeof(drvdata->mode);
359}
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700360static DEVICE_ATTR(mode, 0644, lm3530_mode_get, lm3530_mode_set);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700361
362static int __devinit lm3530_probe(struct i2c_client *client,
363 const struct i2c_device_id *id)
364{
365 struct lm3530_platform_data *pdata = client->dev.platform_data;
366 struct lm3530_data *drvdata;
367 int err = 0;
368
369 if (pdata == NULL) {
370 dev_err(&client->dev, "platform data required\n");
371 err = -ENODEV;
372 goto err_out;
373 }
374
375 /* BL mode */
376 if (pdata->mode > LM3530_BL_MODE_PWM) {
377 dev_err(&client->dev, "Illegal Mode request\n");
378 err = -EINVAL;
379 goto err_out;
380 }
381
382 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
383 dev_err(&client->dev, "I2C_FUNC_I2C not supported\n");
384 err = -EIO;
385 goto err_out;
386 }
387
388 drvdata = kzalloc(sizeof(struct lm3530_data), GFP_KERNEL);
389 if (drvdata == NULL) {
390 err = -ENOMEM;
391 goto err_out;
392 }
393
394 drvdata->mode = pdata->mode;
395 drvdata->client = client;
396 drvdata->pdata = pdata;
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700397 drvdata->brightness = LED_OFF;
398 drvdata->enable = false;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700399 drvdata->led_dev.name = LM3530_LED_DEV;
400 drvdata->led_dev.brightness_set = lm3530_brightness_set;
Kim, Milobbe64532012-03-23 15:02:11 -0700401 drvdata->led_dev.max_brightness = MAX_BRIGHTNESS;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700402
403 i2c_set_clientdata(client, drvdata);
404
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700405 drvdata->regulator = regulator_get(&client->dev, "vin");
406 if (IS_ERR(drvdata->regulator)) {
407 dev_err(&client->dev, "regulator get failed\n");
408 err = PTR_ERR(drvdata->regulator);
409 drvdata->regulator = NULL;
410 goto err_regulator_get;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700411 }
412
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700413 if (drvdata->pdata->brt_val) {
414 err = lm3530_init_registers(drvdata);
415 if (err < 0) {
416 dev_err(&client->dev,
417 "Register Init failed: %d\n", err);
418 err = -ENODEV;
419 goto err_reg_init;
420 }
421 }
422 err = led_classdev_register(&client->dev, &drvdata->led_dev);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700423 if (err < 0) {
424 dev_err(&client->dev, "Register led class failed: %d\n", err);
425 err = -ENODEV;
426 goto err_class_register;
427 }
428
429 err = device_create_file(drvdata->led_dev.dev, &dev_attr_mode);
430 if (err < 0) {
431 dev_err(&client->dev, "File device creation failed: %d\n", err);
432 err = -ENODEV;
433 goto err_create_file;
434 }
435
436 return 0;
437
438err_create_file:
439 led_classdev_unregister(&drvdata->led_dev);
440err_class_register:
441err_reg_init:
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700442 regulator_put(drvdata->regulator);
443err_regulator_get:
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700444 kfree(drvdata);
445err_out:
446 return err;
447}
448
449static int __devexit lm3530_remove(struct i2c_client *client)
450{
451 struct lm3530_data *drvdata = i2c_get_clientdata(client);
452
453 device_remove_file(drvdata->led_dev.dev, &dev_attr_mode);
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700454
455 if (drvdata->enable)
456 regulator_disable(drvdata->regulator);
457 regulator_put(drvdata->regulator);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700458 led_classdev_unregister(&drvdata->led_dev);
459 kfree(drvdata);
460 return 0;
461}
462
463static const struct i2c_device_id lm3530_id[] = {
464 {LM3530_NAME, 0},
465 {}
466};
Axel Lind5f33d42011-05-17 15:44:09 -0700467MODULE_DEVICE_TABLE(i2c, lm3530_id);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700468
469static struct i2c_driver lm3530_i2c_driver = {
470 .probe = lm3530_probe,
Axel Lin93f53982011-10-31 17:12:15 -0700471 .remove = __devexit_p(lm3530_remove),
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700472 .id_table = lm3530_id,
473 .driver = {
474 .name = LM3530_NAME,
475 .owner = THIS_MODULE,
476 },
477};
478
Axel Lin09a0d182012-01-10 15:09:27 -0800479module_i2c_driver(lm3530_i2c_driver);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700480
481MODULE_DESCRIPTION("Back Light driver for LM3530");
482MODULE_LICENSE("GPL v2");
483MODULE_AUTHOR("Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>");