diff options
author | Shreshtha Kumar Sahu <shreshthakumar.sahu@stericsson.com> | 2011-07-25 20:13:17 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-25 23:57:15 -0400 |
commit | 40b1445b1b6afc1ddac6ac31f4533277a0fb75dc (patch) | |
tree | cdf04e397edef0b2913acf862a3bc3f293894e8c /drivers/leds/leds-lm3530.c | |
parent | 2504f6da50f4d9656cad353798bf07657ec12eea (diff) |
arch/arm/mach-ux500/board-u5500.c: calibrate ALS input voltage
Provide the support for auto calibration of ALS Zone boundaries based on
min/max ALS input voltage.
Signed-off-by: Shreshtha Kumar Sahu <shreshthakumar.sahu@stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Cc: Richard Purdie <rpurdie@rpsys.net>
Cc: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/leds/leds-lm3530.c')
-rw-r--r-- | drivers/leds/leds-lm3530.c | 67 |
1 files changed, 53 insertions, 14 deletions
diff --git a/drivers/leds/leds-lm3530.c b/drivers/leds/leds-lm3530.c index 4d7ce7631acf..3dd7090a9a9b 100644 --- a/drivers/leds/leds-lm3530.c +++ b/drivers/leds/leds-lm3530.c | |||
@@ -68,17 +68,16 @@ | |||
68 | #define LM3530_ALS2_IMP_SHIFT (4) | 68 | #define LM3530_ALS2_IMP_SHIFT (4) |
69 | 69 | ||
70 | /* Zone Boundary Register defaults */ | 70 | /* Zone Boundary Register defaults */ |
71 | #define LM3530_DEF_ZB_0 (0x33) | 71 | #define LM3530_ALS_ZB_MAX (4) |
72 | #define LM3530_DEF_ZB_1 (0x66) | 72 | #define LM3530_ALS_WINDOW_mV (1000) |
73 | #define LM3530_DEF_ZB_2 (0x99) | 73 | #define LM3530_ALS_OFFSET_mV (4) |
74 | #define LM3530_DEF_ZB_3 (0xCC) | ||
75 | 74 | ||
76 | /* Zone Target Register defaults */ | 75 | /* Zone Target Register defaults */ |
77 | #define LM3530_DEF_ZT_0 (0x19) | 76 | #define LM3530_DEF_ZT_0 (0x7F) |
78 | #define LM3530_DEF_ZT_1 (0x33) | 77 | #define LM3530_DEF_ZT_1 (0x66) |
79 | #define LM3530_DEF_ZT_2 (0x4C) | 78 | #define LM3530_DEF_ZT_2 (0x4C) |
80 | #define LM3530_DEF_ZT_3 (0x66) | 79 | #define LM3530_DEF_ZT_3 (0x33) |
81 | #define LM3530_DEF_ZT_4 (0x7F) | 80 | #define LM3530_DEF_ZT_4 (0x19) |
82 | 81 | ||
83 | struct lm3530_mode_map { | 82 | struct lm3530_mode_map { |
84 | const char *mode; | 83 | const char *mode; |
@@ -150,6 +149,8 @@ static int lm3530_init_registers(struct lm3530_data *drvdata) | |||
150 | u8 als_imp_sel = 0; | 149 | u8 als_imp_sel = 0; |
151 | u8 brightness; | 150 | u8 brightness; |
152 | u8 reg_val[LM3530_REG_MAX]; | 151 | u8 reg_val[LM3530_REG_MAX]; |
152 | u8 zones[LM3530_ALS_ZB_MAX]; | ||
153 | u32 als_vmin, als_vmax, als_vstep; | ||
153 | struct lm3530_platform_data *pltfm = drvdata->pdata; | 154 | struct lm3530_platform_data *pltfm = drvdata->pdata; |
154 | struct i2c_client *client = drvdata->client; | 155 | struct i2c_client *client = drvdata->client; |
155 | 156 | ||
@@ -161,6 +162,26 @@ static int lm3530_init_registers(struct lm3530_data *drvdata) | |||
161 | gen_config |= (LM3530_ENABLE_I2C); | 162 | gen_config |= (LM3530_ENABLE_I2C); |
162 | 163 | ||
163 | if (drvdata->mode == LM3530_BL_MODE_ALS) { | 164 | if (drvdata->mode == LM3530_BL_MODE_ALS) { |
165 | if (pltfm->als_vmax == 0) { | ||
166 | pltfm->als_vmin = als_vmin = 0; | ||
167 | pltfm->als_vmin = als_vmax = LM3530_ALS_WINDOW_mV; | ||
168 | } | ||
169 | |||
170 | als_vmin = pltfm->als_vmin; | ||
171 | als_vmax = pltfm->als_vmax; | ||
172 | |||
173 | if ((als_vmax - als_vmin) > LM3530_ALS_WINDOW_mV) | ||
174 | pltfm->als_vmax = als_vmax = | ||
175 | als_vmin + LM3530_ALS_WINDOW_mV; | ||
176 | |||
177 | /* n zone boundary makes n+1 zones */ | ||
178 | als_vstep = (als_vmax - als_vmin) / (LM3530_ALS_ZB_MAX + 1); | ||
179 | |||
180 | for (i = 0; i < LM3530_ALS_ZB_MAX; i++) | ||
181 | zones[i] = (((als_vmin + LM3530_ALS_OFFSET_mV) + | ||
182 | als_vstep + (i * als_vstep)) * LED_FULL) | ||
183 | / 1000; | ||
184 | |||
164 | als_config = | 185 | als_config = |
165 | (pltfm->als_avrg_time << LM3530_ALS_AVG_TIME_SHIFT) | | 186 | (pltfm->als_avrg_time << LM3530_ALS_AVG_TIME_SHIFT) | |
166 | (LM3530_ENABLE_ALS) | | 187 | (LM3530_ENABLE_ALS) | |
@@ -169,6 +190,7 @@ static int lm3530_init_registers(struct lm3530_data *drvdata) | |||
169 | als_imp_sel = | 190 | als_imp_sel = |
170 | (pltfm->als1_resistor_sel << LM3530_ALS1_IMP_SHIFT) | | 191 | (pltfm->als1_resistor_sel << LM3530_ALS1_IMP_SHIFT) | |
171 | (pltfm->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT); | 192 | (pltfm->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT); |
193 | |||
172 | } | 194 | } |
173 | 195 | ||
174 | if (drvdata->mode == LM3530_BL_MODE_PWM) | 196 | if (drvdata->mode == LM3530_BL_MODE_PWM) |
@@ -190,10 +212,10 @@ static int lm3530_init_registers(struct lm3530_data *drvdata) | |||
190 | reg_val[3] = 0x00; /* LM3530_ALS_ZONE_REG */ | 212 | reg_val[3] = 0x00; /* LM3530_ALS_ZONE_REG */ |
191 | reg_val[4] = als_imp_sel; /* LM3530_ALS_IMP_SELECT */ | 213 | reg_val[4] = als_imp_sel; /* LM3530_ALS_IMP_SELECT */ |
192 | reg_val[5] = brightness; /* LM3530_BRT_CTRL_REG */ | 214 | reg_val[5] = brightness; /* LM3530_BRT_CTRL_REG */ |
193 | reg_val[6] = LM3530_DEF_ZB_0; /* LM3530_ALS_ZB0_REG */ | 215 | reg_val[6] = zones[0]; /* LM3530_ALS_ZB0_REG */ |
194 | reg_val[7] = LM3530_DEF_ZB_1; /* LM3530_ALS_ZB1_REG */ | 216 | reg_val[7] = zones[1]; /* LM3530_ALS_ZB1_REG */ |
195 | reg_val[8] = LM3530_DEF_ZB_2; /* LM3530_ALS_ZB2_REG */ | 217 | reg_val[8] = zones[2]; /* LM3530_ALS_ZB2_REG */ |
196 | reg_val[9] = LM3530_DEF_ZB_3; /* LM3530_ALS_ZB3_REG */ | 218 | reg_val[9] = zones[3]; /* LM3530_ALS_ZB3_REG */ |
197 | reg_val[10] = LM3530_DEF_ZT_0; /* LM3530_ALS_Z0T_REG */ | 219 | reg_val[10] = LM3530_DEF_ZT_0; /* LM3530_ALS_Z0T_REG */ |
198 | reg_val[11] = LM3530_DEF_ZT_1; /* LM3530_ALS_Z1T_REG */ | 220 | reg_val[11] = LM3530_DEF_ZT_1; /* LM3530_ALS_Z1T_REG */ |
199 | reg_val[12] = LM3530_DEF_ZT_2; /* LM3530_ALS_Z2T_REG */ | 221 | reg_val[12] = LM3530_DEF_ZT_2; /* LM3530_ALS_Z2T_REG */ |
@@ -265,6 +287,24 @@ static void lm3530_brightness_set(struct led_classdev *led_cdev, | |||
265 | } | 287 | } |
266 | } | 288 | } |
267 | 289 | ||
290 | static ssize_t lm3530_mode_get(struct device *dev, | ||
291 | struct device_attribute *attr, char *buf) | ||
292 | { | ||
293 | struct i2c_client *client = container_of( | ||
294 | dev->parent, struct i2c_client, dev); | ||
295 | struct lm3530_data *drvdata = i2c_get_clientdata(client); | ||
296 | int i, len = 0; | ||
297 | |||
298 | for (i = 0; i < ARRAY_SIZE(mode_map); i++) | ||
299 | if (drvdata->mode == mode_map[i].mode_val) | ||
300 | len += sprintf(buf + len, "[%s] ", mode_map[i].mode); | ||
301 | else | ||
302 | len += sprintf(buf + len, "%s ", mode_map[i].mode); | ||
303 | |||
304 | len += sprintf(buf + len, "\n"); | ||
305 | |||
306 | return len; | ||
307 | } | ||
268 | 308 | ||
269 | static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute | 309 | static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute |
270 | *attr, const char *buf, size_t size) | 310 | *attr, const char *buf, size_t size) |
@@ -298,8 +338,7 @@ static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute | |||
298 | 338 | ||
299 | return sizeof(drvdata->mode); | 339 | return sizeof(drvdata->mode); |
300 | } | 340 | } |
301 | 341 | static DEVICE_ATTR(mode, 0644, lm3530_mode_get, lm3530_mode_set); | |
302 | static DEVICE_ATTR(mode, 0644, NULL, lm3530_mode_set); | ||
303 | 342 | ||
304 | static int __devinit lm3530_probe(struct i2c_client *client, | 343 | static int __devinit lm3530_probe(struct i2c_client *client, |
305 | const struct i2c_device_id *id) | 344 | const struct i2c_device_id *id) |