blob: 968fd5fef4fc5e2871dc7b5539f80b6b5328ea1b [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
Axel Lincea694c2012-03-23 15:02:13 -0700163 switch (drvdata->mode) {
164 case LM3530_BL_MODE_MANUAL:
165 case LM3530_BL_MODE_ALS:
166 gen_config |= LM3530_ENABLE_I2C;
167 break;
168 case LM3530_BL_MODE_PWM:
169 gen_config |= LM3530_ENABLE_PWM | LM3530_ENABLE_PWM_SIMPLE |
170 (pdata->pwm_pol_hi << LM3530_PWM_POL_SHIFT);
171 break;
172 }
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700173
174 if (drvdata->mode == LM3530_BL_MODE_ALS) {
Kim, Milo99ad98d2012-03-23 15:02:13 -0700175 if (pdata->als_vmax == 0) {
176 pdata->als_vmin = 0;
177 pdata->als_vmax = LM3530_ALS_WINDOW_mV;
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700178 }
179
Kim, Milo99ad98d2012-03-23 15:02:13 -0700180 als_vmin = pdata->als_vmin;
181 als_vmax = pdata->als_vmax;
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700182
183 if ((als_vmax - als_vmin) > LM3530_ALS_WINDOW_mV)
Kim, Milo99ad98d2012-03-23 15:02:13 -0700184 pdata->als_vmax = als_vmax =
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700185 als_vmin + LM3530_ALS_WINDOW_mV;
186
187 /* n zone boundary makes n+1 zones */
188 als_vstep = (als_vmax - als_vmin) / (LM3530_ALS_ZB_MAX + 1);
189
190 for (i = 0; i < LM3530_ALS_ZB_MAX; i++)
191 zones[i] = (((als_vmin + LM3530_ALS_OFFSET_mV) +
192 als_vstep + (i * als_vstep)) * LED_FULL)
193 / 1000;
194
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700195 als_config =
Kim, Milo99ad98d2012-03-23 15:02:13 -0700196 (pdata->als_avrg_time << LM3530_ALS_AVG_TIME_SHIFT) |
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700197 (LM3530_ENABLE_ALS) |
Kim, Milo99ad98d2012-03-23 15:02:13 -0700198 (pdata->als_input_mode << LM3530_ALS_SEL_SHIFT);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700199
200 als_imp_sel =
Kim, Milo99ad98d2012-03-23 15:02:13 -0700201 (pdata->als1_resistor_sel << LM3530_ALS1_IMP_SHIFT) |
202 (pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT);
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700203
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700204 }
205
Kim, Milo99ad98d2012-03-23 15:02:13 -0700206 brt_ramp = (pdata->brt_ramp_fall << LM3530_BRT_RAMP_FALL_SHIFT) |
207 (pdata->brt_ramp_rise << LM3530_BRT_RAMP_RISE_SHIFT);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700208
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700209 if (drvdata->brightness)
210 brightness = drvdata->brightness;
211 else
Kim, Milo99ad98d2012-03-23 15:02:13 -0700212 brightness = drvdata->brightness = pdata->brt_val;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700213
Kim, Milobbe64532012-03-23 15:02:11 -0700214 if (brightness > drvdata->led_dev.max_brightness)
215 brightness = drvdata->led_dev.max_brightness;
216
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700217 reg_val[0] = gen_config; /* LM3530_GEN_CONFIG */
218 reg_val[1] = als_config; /* LM3530_ALS_CONFIG */
219 reg_val[2] = brt_ramp; /* LM3530_BRT_RAMP_RATE */
Kim, Milo8544d0e2012-03-23 15:02:12 -0700220 reg_val[3] = als_imp_sel; /* LM3530_ALS_IMP_SELECT */
221 reg_val[4] = brightness; /* LM3530_BRT_CTRL_REG */
222 reg_val[5] = zones[0]; /* LM3530_ALS_ZB0_REG */
223 reg_val[6] = zones[1]; /* LM3530_ALS_ZB1_REG */
224 reg_val[7] = zones[2]; /* LM3530_ALS_ZB2_REG */
225 reg_val[8] = zones[3]; /* LM3530_ALS_ZB3_REG */
226 reg_val[9] = LM3530_DEF_ZT_0; /* LM3530_ALS_Z0T_REG */
227 reg_val[10] = LM3530_DEF_ZT_1; /* LM3530_ALS_Z1T_REG */
228 reg_val[11] = LM3530_DEF_ZT_2; /* LM3530_ALS_Z2T_REG */
229 reg_val[12] = LM3530_DEF_ZT_3; /* LM3530_ALS_Z3T_REG */
230 reg_val[13] = LM3530_DEF_ZT_4; /* LM3530_ALS_Z4T_REG */
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700231
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700232 if (!drvdata->enable) {
233 ret = regulator_enable(drvdata->regulator);
234 if (ret) {
235 dev_err(&drvdata->client->dev,
236 "Enable regulator failed\n");
237 return ret;
238 }
239 drvdata->enable = true;
240 }
241
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700242 for (i = 0; i < LM3530_REG_MAX; i++) {
Kim, Milobb982002012-03-23 15:02:12 -0700243 /* do not update brightness register when pwm mode */
244 if (lm3530_reg[i] == LM3530_BRT_CTRL_REG &&
245 drvdata->mode == LM3530_BL_MODE_PWM) {
246 if (pwm->pwm_set_intensity)
247 pwm->pwm_set_intensity(reg_val[i],
248 drvdata->led_dev.max_brightness);
249 continue;
250 }
251
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700252 ret = i2c_smbus_write_byte_data(client,
253 lm3530_reg[i], reg_val[i]);
254 if (ret)
255 break;
256 }
257
258 return ret;
259}
260
261static void lm3530_brightness_set(struct led_classdev *led_cdev,
262 enum led_brightness brt_val)
263{
264 int err;
265 struct lm3530_data *drvdata =
266 container_of(led_cdev, struct lm3530_data, led_dev);
Kim, Milobb982002012-03-23 15:02:12 -0700267 struct lm3530_platform_data *pdata = drvdata->pdata;
268 struct lm3530_pwm_data *pwm = &pdata->pwm_data;
269 u8 max_brightness = led_cdev->max_brightness;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700270
271 switch (drvdata->mode) {
272 case LM3530_BL_MODE_MANUAL:
273
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700274 if (!drvdata->enable) {
275 err = lm3530_init_registers(drvdata);
276 if (err) {
277 dev_err(&drvdata->client->dev,
278 "Register Init failed: %d\n", err);
279 break;
280 }
281 }
282
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700283 /* set the brightness in brightness control register*/
284 err = i2c_smbus_write_byte_data(drvdata->client,
Kim, Milobbe64532012-03-23 15:02:11 -0700285 LM3530_BRT_CTRL_REG, brt_val);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700286 if (err)
287 dev_err(&drvdata->client->dev,
288 "Unable to set brightness: %d\n", err);
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700289 else
Kim, Milobbe64532012-03-23 15:02:11 -0700290 drvdata->brightness = brt_val;
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700291
292 if (brt_val == 0) {
293 err = regulator_disable(drvdata->regulator);
294 if (err)
295 dev_err(&drvdata->client->dev,
296 "Disable regulator failed\n");
297 drvdata->enable = false;
298 }
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700299 break;
300 case LM3530_BL_MODE_ALS:
301 break;
302 case LM3530_BL_MODE_PWM:
Kim, Milobb982002012-03-23 15:02:12 -0700303 if (pwm->pwm_set_intensity)
304 pwm->pwm_set_intensity(brt_val, max_brightness);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700305 break;
306 default:
307 break;
308 }
309}
310
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700311static ssize_t lm3530_mode_get(struct device *dev,
312 struct device_attribute *attr, char *buf)
313{
Kim, Miloe13d9782012-03-23 15:02:11 -0700314 struct led_classdev *led_cdev = dev_get_drvdata(dev);
315 struct lm3530_data *drvdata;
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700316 int i, len = 0;
317
Kim, Miloe13d9782012-03-23 15:02:11 -0700318 drvdata = container_of(led_cdev, struct lm3530_data, led_dev);
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700319 for (i = 0; i < ARRAY_SIZE(mode_map); i++)
320 if (drvdata->mode == mode_map[i].mode_val)
321 len += sprintf(buf + len, "[%s] ", mode_map[i].mode);
322 else
323 len += sprintf(buf + len, "%s ", mode_map[i].mode);
324
325 len += sprintf(buf + len, "\n");
326
327 return len;
328}
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700329
330static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute
331 *attr, const char *buf, size_t size)
332{
Kim, Miloe13d9782012-03-23 15:02:11 -0700333 struct led_classdev *led_cdev = dev_get_drvdata(dev);
334 struct lm3530_data *drvdata;
Kim, Milobb982002012-03-23 15:02:12 -0700335 struct lm3530_pwm_data *pwm;
336 u8 max_brightness;
Kim, Miloe13d9782012-03-23 15:02:11 -0700337 int mode, err;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700338
Kim, Miloe13d9782012-03-23 15:02:11 -0700339 drvdata = container_of(led_cdev, struct lm3530_data, led_dev);
Kim, Milobb982002012-03-23 15:02:12 -0700340 pwm = &drvdata->pdata->pwm_data;
341 max_brightness = led_cdev->max_brightness;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700342 mode = lm3530_get_mode_from_str(buf);
343 if (mode < 0) {
344 dev_err(dev, "Invalid mode\n");
345 return -EINVAL;
346 }
347
Kim, Milobb982002012-03-23 15:02:12 -0700348 drvdata->mode = mode;
349
350 /* set pwm to low if unnecessary */
351 if (mode != LM3530_BL_MODE_PWM && pwm->pwm_set_intensity)
352 pwm->pwm_set_intensity(0, max_brightness);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700353
354 err = lm3530_init_registers(drvdata);
355 if (err) {
356 dev_err(dev, "Setting %s Mode failed :%d\n", buf, err);
357 return err;
358 }
359
360 return sizeof(drvdata->mode);
361}
Shreshtha Kumar Sahu40b14452011-07-25 17:13:17 -0700362static DEVICE_ATTR(mode, 0644, lm3530_mode_get, lm3530_mode_set);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700363
364static int __devinit lm3530_probe(struct i2c_client *client,
365 const struct i2c_device_id *id)
366{
367 struct lm3530_platform_data *pdata = client->dev.platform_data;
368 struct lm3530_data *drvdata;
369 int err = 0;
370
371 if (pdata == NULL) {
372 dev_err(&client->dev, "platform data required\n");
373 err = -ENODEV;
374 goto err_out;
375 }
376
377 /* BL mode */
378 if (pdata->mode > LM3530_BL_MODE_PWM) {
379 dev_err(&client->dev, "Illegal Mode request\n");
380 err = -EINVAL;
381 goto err_out;
382 }
383
384 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
385 dev_err(&client->dev, "I2C_FUNC_I2C not supported\n");
386 err = -EIO;
387 goto err_out;
388 }
389
390 drvdata = kzalloc(sizeof(struct lm3530_data), GFP_KERNEL);
391 if (drvdata == NULL) {
392 err = -ENOMEM;
393 goto err_out;
394 }
395
396 drvdata->mode = pdata->mode;
397 drvdata->client = client;
398 drvdata->pdata = pdata;
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700399 drvdata->brightness = LED_OFF;
400 drvdata->enable = false;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700401 drvdata->led_dev.name = LM3530_LED_DEV;
402 drvdata->led_dev.brightness_set = lm3530_brightness_set;
Kim, Milobbe64532012-03-23 15:02:11 -0700403 drvdata->led_dev.max_brightness = MAX_BRIGHTNESS;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700404
405 i2c_set_clientdata(client, drvdata);
406
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700407 drvdata->regulator = regulator_get(&client->dev, "vin");
408 if (IS_ERR(drvdata->regulator)) {
409 dev_err(&client->dev, "regulator get failed\n");
410 err = PTR_ERR(drvdata->regulator);
411 drvdata->regulator = NULL;
412 goto err_regulator_get;
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700413 }
414
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700415 if (drvdata->pdata->brt_val) {
416 err = lm3530_init_registers(drvdata);
417 if (err < 0) {
418 dev_err(&client->dev,
419 "Register Init failed: %d\n", err);
420 err = -ENODEV;
421 goto err_reg_init;
422 }
423 }
424 err = led_classdev_register(&client->dev, &drvdata->led_dev);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700425 if (err < 0) {
426 dev_err(&client->dev, "Register led class failed: %d\n", err);
427 err = -ENODEV;
428 goto err_class_register;
429 }
430
431 err = device_create_file(drvdata->led_dev.dev, &dev_attr_mode);
432 if (err < 0) {
433 dev_err(&client->dev, "File device creation failed: %d\n", err);
434 err = -ENODEV;
435 goto err_create_file;
436 }
437
438 return 0;
439
440err_create_file:
441 led_classdev_unregister(&drvdata->led_dev);
442err_class_register:
443err_reg_init:
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700444 regulator_put(drvdata->regulator);
445err_regulator_get:
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700446 kfree(drvdata);
447err_out:
448 return err;
449}
450
451static int __devexit lm3530_remove(struct i2c_client *client)
452{
453 struct lm3530_data *drvdata = i2c_get_clientdata(client);
454
455 device_remove_file(drvdata->led_dev.dev, &dev_attr_mode);
Shreshtha Kumar Sahu9b2da532011-05-24 17:13:28 -0700456
457 if (drvdata->enable)
458 regulator_disable(drvdata->regulator);
459 regulator_put(drvdata->regulator);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700460 led_classdev_unregister(&drvdata->led_dev);
461 kfree(drvdata);
462 return 0;
463}
464
465static const struct i2c_device_id lm3530_id[] = {
466 {LM3530_NAME, 0},
467 {}
468};
Axel Lind5f33d42011-05-17 15:44:09 -0700469MODULE_DEVICE_TABLE(i2c, lm3530_id);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700470
471static struct i2c_driver lm3530_i2c_driver = {
472 .probe = lm3530_probe,
Axel Lin93f53982011-10-31 17:12:15 -0700473 .remove = __devexit_p(lm3530_remove),
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700474 .id_table = lm3530_id,
475 .driver = {
476 .name = LM3530_NAME,
477 .owner = THIS_MODULE,
478 },
479};
480
Axel Lin09a0d182012-01-10 15:09:27 -0800481module_i2c_driver(lm3530_i2c_driver);
Shreshtha Kumar Sahub1e6b702011-03-22 16:30:16 -0700482
483MODULE_DESCRIPTION("Back Light driver for LM3530");
484MODULE_LICENSE("GPL v2");
485MODULE_AUTHOR("Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>");