summaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-pca963x.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index 407eba11e187..b6ce1f2ec33e 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -59,6 +59,7 @@ struct pca963x_chipdef {
59 u8 grpfreq; 59 u8 grpfreq;
60 u8 ledout_base; 60 u8 ledout_base;
61 int n_leds; 61 int n_leds;
62 unsigned int scaling;
62}; 63};
63 64
64static struct pca963x_chipdef pca963x_chipdefs[] = { 65static struct pca963x_chipdef pca963x_chipdefs[] = {
@@ -189,6 +190,14 @@ static int pca963x_led_set(struct led_classdev *led_cdev,
189 return pca963x_brightness(pca963x, value); 190 return pca963x_brightness(pca963x, value);
190} 191}
191 192
193static unsigned int pca963x_period_scale(struct pca963x_led *pca963x,
194 unsigned int val)
195{
196 unsigned int scaling = pca963x->chip->chipdef->scaling;
197
198 return scaling ? DIV_ROUND_CLOSEST(val * scaling, 1000) : val;
199}
200
192static int pca963x_blink_set(struct led_classdev *led_cdev, 201static int pca963x_blink_set(struct led_classdev *led_cdev,
193 unsigned long *delay_on, unsigned long *delay_off) 202 unsigned long *delay_on, unsigned long *delay_off)
194{ 203{
@@ -207,14 +216,14 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
207 time_off = 500; 216 time_off = 500;
208 } 217 }
209 218
210 period = time_on + time_off; 219 period = pca963x_period_scale(pca963x, time_on + time_off);
211 220
212 /* If period not supported by hardware, default to someting sane. */ 221 /* If period not supported by hardware, default to someting sane. */
213 if ((period < PCA963X_BLINK_PERIOD_MIN) || 222 if ((period < PCA963X_BLINK_PERIOD_MIN) ||
214 (period > PCA963X_BLINK_PERIOD_MAX)) { 223 (period > PCA963X_BLINK_PERIOD_MAX)) {
215 time_on = 500; 224 time_on = 500;
216 time_off = 500; 225 time_off = 500;
217 period = time_on + time_off; 226 period = pca963x_period_scale(pca963x, 1000);
218 } 227 }
219 228
220 /* 229 /*
@@ -222,7 +231,7 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
222 * (time_on / period) = (GDC / 256) -> 231 * (time_on / period) = (GDC / 256) ->
223 * GDC = ((time_on * 256) / period) 232 * GDC = ((time_on * 256) / period)
224 */ 233 */
225 gdc = (time_on * 256) / period; 234 gdc = (pca963x_period_scale(pca963x, time_on) * 256) / period;
226 235
227 /* 236 /*
228 * From manual: period = ((GFRQ + 1) / 24) in seconds. 237 * From manual: period = ((GFRQ + 1) / 24) in seconds.
@@ -294,6 +303,9 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip)
294 else 303 else
295 pdata->blink_type = PCA963X_SW_BLINK; 304 pdata->blink_type = PCA963X_SW_BLINK;
296 305
306 if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling))
307 chip->scaling = 1000;
308
297 return pdata; 309 return pdata;
298} 310}
299 311