Lines Matching +full:pwm +full:- +full:off +full:- +full:delay +full:- +full:ms

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()
66 return base + led->id; in lm3533_led_get_lv_reg()
71 return led->id; in lm3533_led_get_pattern()
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) */
168 /* Delay limits for hardware accelerated blinking (in ms). */
178 * t_step = (t_max - t_min) / (v_max - v_min)
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()
195 * Returns time code corresponding to *delay (in ms) and updates *delay to
196 * reflect actual hardware delay.
198 * Hardware supports 256 discrete delay times, divided into three groups with
199 * the following ranges and step-sizes:
201 * [ 16, 999] [0x00, 0x3e] step 16 ms
202 * [ 1130, 9781] [0x3d, 0x7f] step 131 ms
203 * [10306, 76890] [0x80, 0xff] step 524 ms
205 * Note that delay group 3 is only available for delay_off.
207 static u8 lm3533_led_get_hw_delay(unsigned *delay) in lm3533_led_get_hw_delay() argument
212 t = *delay * 1000; 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
241 * actual hardware delay used.
244 unsigned long *delay) in lm3533_led_delay_set() argument
251 t = (unsigned)*delay; in lm3533_led_delay_set()
253 /* Delay group 3 is only available for low time (delay off). */ 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()
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()
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
343 ret = lm3533_read(led->lm3533, reg, &val); in show_risefalltime()
375 return -EINVAL; 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()
594 static LM3533_ATTR_RW(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()
738 dev_dbg(&pdev->dev, "%s\n", __func__); in lm3533_led_shutdown()
740 lm3533_ctrlbank_disable(&led->cb); in lm3533_led_shutdown()
741 lm3533_led_set(&led->cdev, LED_OFF); /* disable blink */ in lm3533_led_shutdown()
746 .name = "lm3533-leds",
757 MODULE_ALIAS("platform:lm3533-leds");