aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lm3530.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/leds/leds-lm3530.c')
-rw-r--r--drivers/leds/leds-lm3530.c100
1 files changed, 58 insertions, 42 deletions
diff --git a/drivers/leds/leds-lm3530.c b/drivers/leds/leds-lm3530.c
index 968fd5fef4fc..84ba6de8039c 100644
--- a/drivers/leds/leds-lm3530.c
+++ b/drivers/leds/leds-lm3530.c
@@ -113,6 +113,18 @@ struct lm3530_data {
113 bool enable; 113 bool enable;
114}; 114};
115 115
116/*
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
116static const u8 lm3530_reg[LM3530_REG_MAX] = { 128static const u8 lm3530_reg[LM3530_REG_MAX] = {
117 LM3530_GEN_CONFIG, 129 LM3530_GEN_CONFIG,
118 LM3530_ALS_CONFIG, 130 LM3530_ALS_CONFIG,
@@ -141,29 +153,65 @@ static int lm3530_get_mode_from_str(const char *str)
141 return -1; 153 return -1;
142} 154}
143 155
156static 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
144static int lm3530_init_registers(struct lm3530_data *drvdata) 190static int lm3530_init_registers(struct lm3530_data *drvdata)
145{ 191{
146 int ret = 0; 192 int ret = 0;
147 int i; 193 int i;
148 u8 gen_config; 194 u8 gen_config;
149 u8 als_config = 0;
150 u8 brt_ramp; 195 u8 brt_ramp;
151 u8 als_imp_sel = 0;
152 u8 brightness; 196 u8 brightness;
153 u8 reg_val[LM3530_REG_MAX]; 197 u8 reg_val[LM3530_REG_MAX];
154 u8 zones[LM3530_ALS_ZB_MAX];
155 u32 als_vmin, als_vmax, als_vstep;
156 struct lm3530_platform_data *pdata = drvdata->pdata; 198 struct lm3530_platform_data *pdata = drvdata->pdata;
157 struct i2c_client *client = drvdata->client; 199 struct i2c_client *client = drvdata->client;
158 struct lm3530_pwm_data *pwm = &pdata->pwm_data; 200 struct lm3530_pwm_data *pwm = &pdata->pwm_data;
201 struct lm3530_als_data als;
202
203 memset(&als, 0, sizeof(struct lm3530_als_data));
159 204
160 gen_config = (pdata->brt_ramp_law << LM3530_RAMP_LAW_SHIFT) | 205 gen_config = (pdata->brt_ramp_law << LM3530_RAMP_LAW_SHIFT) |
161 ((pdata->max_current & 7) << LM3530_MAX_CURR_SHIFT); 206 ((pdata->max_current & 7) << LM3530_MAX_CURR_SHIFT);
162 207
163 switch (drvdata->mode) { 208 switch (drvdata->mode) {
164 case LM3530_BL_MODE_MANUAL: 209 case LM3530_BL_MODE_MANUAL:
210 gen_config |= LM3530_ENABLE_I2C;
211 break;
165 case LM3530_BL_MODE_ALS: 212 case LM3530_BL_MODE_ALS:
166 gen_config |= LM3530_ENABLE_I2C; 213 gen_config |= LM3530_ENABLE_I2C;
214 lm3530_als_configure(pdata, &als);
167 break; 215 break;
168 case LM3530_BL_MODE_PWM: 216 case LM3530_BL_MODE_PWM:
169 gen_config |= LM3530_ENABLE_PWM | LM3530_ENABLE_PWM_SIMPLE | 217 gen_config |= LM3530_ENABLE_PWM | LM3530_ENABLE_PWM_SIMPLE |
@@ -171,38 +219,6 @@ static int lm3530_init_registers(struct lm3530_data *drvdata)
171 break; 219 break;
172 } 220 }
173 221
174 if (drvdata->mode == LM3530_BL_MODE_ALS) {
175 if (pdata->als_vmax == 0) {
176 pdata->als_vmin = 0;
177 pdata->als_vmax = LM3530_ALS_WINDOW_mV;
178 }
179
180 als_vmin = pdata->als_vmin;
181 als_vmax = pdata->als_vmax;
182
183 if ((als_vmax - als_vmin) > LM3530_ALS_WINDOW_mV)
184 pdata->als_vmax = als_vmax =
185 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
195 als_config =
196 (pdata->als_avrg_time << LM3530_ALS_AVG_TIME_SHIFT) |
197 (LM3530_ENABLE_ALS) |
198 (pdata->als_input_mode << LM3530_ALS_SEL_SHIFT);
199
200 als_imp_sel =
201 (pdata->als1_resistor_sel << LM3530_ALS1_IMP_SHIFT) |
202 (pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT);
203
204 }
205
206 brt_ramp = (pdata->brt_ramp_fall << LM3530_BRT_RAMP_FALL_SHIFT) | 222 brt_ramp = (pdata->brt_ramp_fall << LM3530_BRT_RAMP_FALL_SHIFT) |
207 (pdata->brt_ramp_rise << LM3530_BRT_RAMP_RISE_SHIFT); 223 (pdata->brt_ramp_rise << LM3530_BRT_RAMP_RISE_SHIFT);
208 224
@@ -215,14 +231,14 @@ static int lm3530_init_registers(struct lm3530_data *drvdata)
215 brightness = drvdata->led_dev.max_brightness; 231 brightness = drvdata->led_dev.max_brightness;
216 232
217 reg_val[0] = gen_config; /* LM3530_GEN_CONFIG */ 233 reg_val[0] = gen_config; /* LM3530_GEN_CONFIG */
218 reg_val[1] = als_config; /* LM3530_ALS_CONFIG */ 234 reg_val[1] = als.config; /* LM3530_ALS_CONFIG */
219 reg_val[2] = brt_ramp; /* LM3530_BRT_RAMP_RATE */ 235 reg_val[2] = brt_ramp; /* LM3530_BRT_RAMP_RATE */
220 reg_val[3] = als_imp_sel; /* LM3530_ALS_IMP_SELECT */ 236 reg_val[3] = als.imp_sel; /* LM3530_ALS_IMP_SELECT */
221 reg_val[4] = brightness; /* LM3530_BRT_CTRL_REG */ 237 reg_val[4] = brightness; /* LM3530_BRT_CTRL_REG */
222 reg_val[5] = zones[0]; /* LM3530_ALS_ZB0_REG */ 238 reg_val[5] = als.zones[0]; /* LM3530_ALS_ZB0_REG */
223 reg_val[6] = zones[1]; /* LM3530_ALS_ZB1_REG */ 239 reg_val[6] = als.zones[1]; /* LM3530_ALS_ZB1_REG */
224 reg_val[7] = zones[2]; /* LM3530_ALS_ZB2_REG */ 240 reg_val[7] = als.zones[2]; /* LM3530_ALS_ZB2_REG */
225 reg_val[8] = zones[3]; /* LM3530_ALS_ZB3_REG */ 241 reg_val[8] = als.zones[3]; /* LM3530_ALS_ZB3_REG */
226 reg_val[9] = LM3530_DEF_ZT_0; /* LM3530_ALS_Z0T_REG */ 242 reg_val[9] = LM3530_DEF_ZT_0; /* LM3530_ALS_Z0T_REG */
227 reg_val[10] = LM3530_DEF_ZT_1; /* LM3530_ALS_Z1T_REG */ 243 reg_val[10] = LM3530_DEF_ZT_1; /* LM3530_ALS_Z1T_REG */
228 reg_val[11] = LM3530_DEF_ZT_2; /* LM3530_ALS_Z2T_REG */ 244 reg_val[11] = LM3530_DEF_ZT_2; /* LM3530_ALS_Z2T_REG */