13 #include <linux/i2c.h>
15 #include <linux/slab.h>
17 #include <linux/input.h>
19 #include <linux/types.h>
21 #include <linux/module.h>
23 #define LM3530_LED_DEV "lcd-backlight"
24 #define LM3530_NAME "lm3530-led"
26 #define LM3530_GEN_CONFIG 0x10
27 #define LM3530_ALS_CONFIG 0x20
28 #define LM3530_BRT_RAMP_RATE 0x30
29 #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
40 #define LM3530_REG_MAX 14
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)
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)
56 #define LM3530_ALS_AVG_TIME_SHIFT (0)
57 #define LM3530_EN_ALS_SHIFT (3)
58 #define LM3530_ALS_SEL_SHIFT (5)
60 #define LM3530_ENABLE_ALS (3 << LM3530_EN_ALS_SHIFT)
63 #define LM3530_BRT_RAMP_FALL_SHIFT (0)
64 #define LM3530_BRT_RAMP_RISE_SHIFT (3)
67 #define LM3530_ALS1_IMP_SHIFT (0)
68 #define LM3530_ALS2_IMP_SHIFT (4)
71 #define LM3530_ALS_ZB_MAX (4)
72 #define LM3530_ALS_WINDOW_mV (1000)
73 #define LM3530_ALS_OFFSET_mV (4)
76 #define LM3530_DEF_ZT_0 (0x7F)
77 #define LM3530_DEF_ZT_1 (0x66)
78 #define LM3530_DEF_ZT_2 (0x4C)
79 #define LM3530_DEF_ZT_3 (0x33)
80 #define LM3530_DEF_ZT_4 (0x19)
83 #define MAX_BRIGHTNESS (127)
145 static int lm3530_get_mode_from_str(
const char *
str)
151 return mode_map[i].mode_val;
160 u32 als_vmin, als_vmax, als_vstep;
178 als_vstep + (i * als_vstep)) *
LED_FULL) / 1000;
208 switch (drvdata->
mode) {
214 lm3530_als_configure(pdata, &als);
230 if (brightness > drvdata->
led_dev.max_brightness)
231 brightness = drvdata->
led_dev.max_brightness;
233 reg_val[0] = gen_config;
235 reg_val[2] = brt_ramp;
238 reg_val[5] = als.
zones[0];
239 reg_val[6] = als.
zones[1];
240 reg_val[7] = als.
zones[2];
241 reg_val[8] = als.
zones[3];
252 "Enable regulator failed\n");
264 drvdata->
led_dev.max_brightness);
269 lm3530_reg[i], reg_val[i]);
277 static void lm3530_brightness_set(
struct led_classdev *led_cdev,
287 switch (drvdata->
mode) {
291 err = lm3530_init_registers(drvdata);
294 "Register Init failed: %d\n", err);
304 "Unable to set brightness: %d\n", err);
312 "Disable regulator failed\n");
337 len +=
sprintf(buf + len,
"[%s] ", mode_map[i].
mode);
339 len +=
sprintf(buf + len,
"%s ", mode_map[i].
mode);
341 len +=
sprintf(buf + len,
"\n");
347 *attr,
const char *buf,
size_t size)
356 pwm = &drvdata->
pdata->pwm_data;
358 mode = lm3530_get_mode_from_str(buf);
360 dev_err(dev,
"Invalid mode\n");
370 err = lm3530_init_registers(drvdata);
372 dev_err(dev,
"Setting %s Mode failed :%d\n", buf, err);
376 return sizeof(drvdata->
mode);
378 static DEVICE_ATTR(mode, 0644, lm3530_mode_get, lm3530_mode_set);
388 dev_err(&client->
dev,
"platform data required\n");
394 dev_err(&client->
dev,
"Illegal Mode request\n");
399 dev_err(&client->
dev,
"I2C_FUNC_I2C not supported\n");
414 drvdata->
led_dev.brightness_set = lm3530_brightness_set;
417 i2c_set_clientdata(client, drvdata);
421 dev_err(&client->
dev,
"regulator get failed\n");
427 if (drvdata->
pdata->brt_val) {
428 err = lm3530_init_registers(drvdata);
431 "Register Init failed: %d\n", err);
437 dev_err(&client->
dev,
"Register led class failed: %d\n", err);
443 dev_err(&client->
dev,
"File device creation failed: %d\n", err);
445 goto err_create_file;
457 struct lm3530_data *drvdata = i2c_get_clientdata(client);
473 static struct i2c_driver lm3530_i2c_driver = {
474 .probe = lm3530_probe,
476 .id_table = lm3530_id,