Lines Matching +full:1000 +full:base +full:- +full:t
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * leds-lm3533.c -- LM3533 LED driver
5 * Copyright (C) 2011-2012 Texas Instruments
61 return led->id + 2; in lm3533_led_get_ctrlbank_id()
64 static inline u8 lm3533_led_get_lv_reg(struct lm3533_led *led, u8 base) in lm3533_led_get_lv_reg() argument
66 return base + led->id; in lm3533_led_get_lv_reg()
71 return led->id; in lm3533_led_get_pattern()
75 u8 base) in lm3533_led_get_pattern_reg() argument
77 return base + lm3533_led_get_pattern(led) * LM3533_REG_PATTERN_STEP; in lm3533_led_get_pattern_reg()
88 dev_dbg(led->cdev.dev, "%s - %d\n", __func__, enable); in lm3533_led_pattern_enable()
90 mutex_lock(&led->mutex); in lm3533_led_pattern_enable()
92 state = test_bit(LM3533_LED_FLAG_PATTERN_ENABLE, &led->flags); in lm3533_led_pattern_enable()
104 ret = lm3533_update(led->lm3533, LM3533_REG_PATTERN_ENABLE, val, mask); in lm3533_led_pattern_enable()
106 dev_err(led->cdev.dev, "failed to enable pattern %d (%d)\n", in lm3533_led_pattern_enable()
111 __change_bit(LM3533_LED_FLAG_PATTERN_ENABLE, &led->flags); in lm3533_led_pattern_enable()
113 mutex_unlock(&led->mutex); in lm3533_led_pattern_enable()
123 dev_dbg(led->cdev.dev, "%s - %d\n", __func__, value); in lm3533_led_set()
128 return lm3533_ctrlbank_set_brightness(&led->cb, value); in lm3533_led_set()
137 ret = lm3533_ctrlbank_get_brightness(&led->cb, &val); in lm3533_led_get()
141 dev_dbg(led->cdev.dev, "%s - %u\n", __func__, val); in lm3533_led_get()
151 #define LM3533_LED_DELAY1_VMAX (LM3533_LED_DELAY2_VMIN - 1)
152 #define LM3533_LED_DELAY2_VMAX (LM3533_LED_DELAY3_VMIN - 1)
163 /* t_step = (t_max - t_min) / (v_max - v_min) */
170 ((LM3533_LED_DELAY2_TMAX + LM3533_LED_DELAY2_TSTEP / 2) / 1000)
172 ((LM3533_LED_DELAY3_TMAX + LM3533_LED_DELAY3_TSTEP / 2) / 1000)
175 * Returns linear map of *t from [t_min,t_max] to [v_min,v_max] with a step
178 * t_step = (t_max - t_min) / (v_max - v_min)
180 * and updates *t to reflect the mapped value.
182 static u8 time_to_val(unsigned *t, unsigned t_min, unsigned t_step, in time_to_val() argument
187 val = (*t + t_step / 2 - t_min) / t_step + v_min; in time_to_val()
189 *t = t_step * (val - v_min) + t_min; in time_to_val()
199 * the following ranges and step-sizes:
209 unsigned t; in lm3533_led_get_hw_delay() local
212 t = *delay * 1000; in lm3533_led_get_hw_delay()
214 if (t >= (LM3533_LED_DELAY2_TMAX + LM3533_LED_DELAY3_TMIN) / 2) { in lm3533_led_get_hw_delay()
215 t = clamp(t, LM3533_LED_DELAY3_TMIN, LM3533_LED_DELAY3_TMAX); in lm3533_led_get_hw_delay()
216 val = time_to_val(&t, LM3533_LED_DELAY3_TMIN, in lm3533_led_get_hw_delay()
220 } else if (t >= (LM3533_LED_DELAY1_TMAX + LM3533_LED_DELAY2_TMIN) / 2) { in lm3533_led_get_hw_delay()
221 t = clamp(t, LM3533_LED_DELAY2_TMIN, LM3533_LED_DELAY2_TMAX); in lm3533_led_get_hw_delay()
222 val = time_to_val(&t, LM3533_LED_DELAY2_TMIN, in lm3533_led_get_hw_delay()
227 t = clamp(t, LM3533_LED_DELAY1_TMIN, LM3533_LED_DELAY1_TMAX); in lm3533_led_get_hw_delay()
228 val = time_to_val(&t, LM3533_LED_DELAY1_TMIN, in lm3533_led_get_hw_delay()
234 *delay = (t + 500) / 1000; in lm3533_led_get_hw_delay()
240 * Set delay register base to *delay (in ms) and update *delay to reflect
243 static u8 lm3533_led_delay_set(struct lm3533_led *led, u8 base, in lm3533_led_delay_set() argument
246 unsigned t; in lm3533_led_delay_set() local
251 t = (unsigned)*delay; in lm3533_led_delay_set()
254 if (base != LM3533_REG_PATTERN_LOW_TIME_BASE) in lm3533_led_delay_set()
255 t = min(t, LM3533_LED_DELAY2_TMAX / 1000); in lm3533_led_delay_set()
257 val = lm3533_led_get_hw_delay(&t); in lm3533_led_delay_set()
259 dev_dbg(led->cdev.dev, "%s - %lu: %u (0x%02x)\n", __func__, in lm3533_led_delay_set()
260 *delay, t, val); in lm3533_led_delay_set()
261 reg = lm3533_led_get_pattern_reg(led, base); in lm3533_led_delay_set()
262 ret = lm3533_write(led->lm3533, reg, val); in lm3533_led_delay_set()
264 dev_err(led->cdev.dev, "failed to set delay (%02x)\n", reg); in lm3533_led_delay_set()
266 *delay = t; in lm3533_led_delay_set()
271 static int lm3533_led_delay_on_set(struct lm3533_led *led, unsigned long *t) in lm3533_led_delay_on_set() argument
273 return lm3533_led_delay_set(led, LM3533_REG_PATTERN_HIGH_TIME_BASE, t); in lm3533_led_delay_on_set()
276 static int lm3533_led_delay_off_set(struct lm3533_led *led, unsigned long *t) in lm3533_led_delay_off_set() argument
278 return lm3533_led_delay_set(led, LM3533_REG_PATTERN_LOW_TIME_BASE, t); in lm3533_led_delay_off_set()
288 dev_dbg(led->cdev.dev, "%s - on = %lu, off = %lu\n", __func__, in lm3533_led_blink_set()
293 return -EINVAL; in lm3533_led_blink_set()
317 return sysfs_emit(buf, "%d\n", led->id); in show_id()
323 * 0 - 2048 us (default)
324 * 1 - 262 ms
325 * 2 - 524 ms
326 * 3 - 1.049 s
327 * 4 - 2.097 s
328 * 5 - 4.194 s
329 * 6 - 8.389 s
330 * 7 - 16.78 s
334 char *buf, u8 base) in show_risefalltime() argument
342 reg = lm3533_led_get_pattern_reg(led, base); in show_risefalltime()
343 ret = lm3533_read(led->lm3533, reg, &val); in show_risefalltime()
366 const char *buf, size_t len, u8 base) in store_risefalltime() argument
375 return -EINVAL; in store_risefalltime()
377 reg = lm3533_led_get_pattern_reg(led, base); in store_risefalltime()
378 ret = lm3533_write(led->lm3533, reg, val); in store_risefalltime()
412 ret = lm3533_read(led->lm3533, reg, &val); in show_als_channel()
434 return -EINVAL; in store_als_channel()
438 return -EINVAL; in store_als_channel()
442 val = channel - 1; in store_als_channel()
444 ret = lm3533_update(led->lm3533, reg, val, mask); in store_als_channel()
462 ret = lm3533_read(led->lm3533, reg, &val); in show_als_en()
484 return -EINVAL; in store_als_en()
494 ret = lm3533_update(led->lm3533, reg, val, mask); in store_als_en()
512 ret = lm3533_read(led->lm3533, reg, &val); in show_linear()
537 return -EINVAL; in store_linear()
547 ret = lm3533_update(led->lm3533, reg, val, mask); in store_linear()
563 ret = lm3533_ctrlbank_get_pwm(&led->cb, &val); in show_pwm()
580 return -EINVAL; in store_pwm()
582 ret = lm3533_ctrlbank_set_pwm(&led->cb, val); in store_pwm()
614 umode_t mode = attr->mode; in lm3533_led_attr_is_visible()
618 if (!led->lm3533->have_als) in lm3533_led_attr_is_visible()
640 ret = lm3533_ctrlbank_set_max_current(&led->cb, pdata->max_current); in lm3533_led_setup()
644 return lm3533_ctrlbank_set_pwm(&led->cb, pdata->pwm); in lm3533_led_setup()
654 dev_dbg(&pdev->dev, "%s\n", __func__); in lm3533_led_probe()
656 lm3533 = dev_get_drvdata(pdev->dev.parent); in lm3533_led_probe()
658 return -EINVAL; in lm3533_led_probe()
660 pdata = dev_get_platdata(&pdev->dev); in lm3533_led_probe()
662 dev_err(&pdev->dev, "no platform data\n"); in lm3533_led_probe()
663 return -EINVAL; in lm3533_led_probe()
666 if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) { in lm3533_led_probe()
667 dev_err(&pdev->dev, "illegal LED id %d\n", pdev->id); in lm3533_led_probe()
668 return -EINVAL; in lm3533_led_probe()
671 led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); in lm3533_led_probe()
673 return -ENOMEM; in lm3533_led_probe()
675 led->lm3533 = lm3533; in lm3533_led_probe()
676 led->cdev.name = pdata->name; in lm3533_led_probe()
677 led->cdev.default_trigger = pdata->default_trigger; in lm3533_led_probe()
678 led->cdev.brightness_set_blocking = lm3533_led_set; in lm3533_led_probe()
679 led->cdev.brightness_get = lm3533_led_get; in lm3533_led_probe()
680 led->cdev.blink_set = lm3533_led_blink_set; in lm3533_led_probe()
681 led->cdev.brightness = LED_OFF; in lm3533_led_probe()
682 led->cdev.groups = lm3533_led_attribute_groups; in lm3533_led_probe()
683 led->id = pdev->id; in lm3533_led_probe()
685 mutex_init(&led->mutex); in lm3533_led_probe()
691 led->cb.lm3533 = lm3533; in lm3533_led_probe()
692 led->cb.id = lm3533_led_get_ctrlbank_id(led); in lm3533_led_probe()
693 led->cb.dev = lm3533->dev; in lm3533_led_probe()
697 ret = led_classdev_register(pdev->dev.parent, &led->cdev); in lm3533_led_probe()
699 dev_err(&pdev->dev, "failed to register LED %d\n", pdev->id); in lm3533_led_probe()
703 led->cb.dev = led->cdev.dev; in lm3533_led_probe()
709 ret = lm3533_ctrlbank_enable(&led->cb); in lm3533_led_probe()
716 led_classdev_unregister(&led->cdev); in lm3533_led_probe()
725 dev_dbg(&pdev->dev, "%s\n", __func__); in lm3533_led_remove()
727 lm3533_ctrlbank_disable(&led->cb); in lm3533_led_remove()
728 led_classdev_unregister(&led->cdev); in lm3533_led_remove()
736 dev_dbg(&pdev->dev, "%s\n", __func__); in lm3533_led_shutdown()
738 lm3533_ctrlbank_disable(&led->cb); in lm3533_led_shutdown()
739 lm3533_led_set(&led->cdev, LED_OFF); /* disable blink */ in lm3533_led_shutdown()
744 .name = "lm3533-leds",
755 MODULE_ALIAS("platform:lm3533-leds");