Lines Matching +full:flash +full:- +full:max +full:- +full:timeout +full:- +full:us

1 // SPDX-License-Identifier: GPL-2.0-only
3 * LED driver : leds-ktd2692.c
12 #include <linux/led-class-flash.h>
24 /* Value related the flash mode */
29 /* Macro for getting offset of flash timeout */
30 #define GET_TIMEOUT_OFFSET(timeout, step) ((timeout) / (step)) argument
56 /* Movie / Flash Mode Control */
66 /* maximum LED current in flash mode */
68 /* maximum flash timeout */
70 /* max LED brightness level */
75 /* Related LED Flash class device */
97 gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); in ktd2692_expresswire_start()
103 gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); in ktd2692_expresswire_reset()
109 gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); in ktd2692_expresswire_end()
111 gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); in ktd2692_expresswire_end()
134 gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); in ktd2692_expresswire_set_bit()
136 gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); in ktd2692_expresswire_set_bit()
139 gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); in ktd2692_expresswire_set_bit()
141 gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); in ktd2692_expresswire_set_bit()
151 for (i = 7; i >= 0; i--) in ktd2692_expresswire_write()
162 mutex_lock(&led->lock); in ktd2692_led_brightness_set()
165 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_brightness_set()
166 gpiod_direction_output(led->aux_gpio, KTD2692_LOW); in ktd2692_led_brightness_set()
170 led->mode = KTD2692_MODE_MOVIE; in ktd2692_led_brightness_set()
173 ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); in ktd2692_led_brightness_set()
174 mutex_unlock(&led->lock); in ktd2692_led_brightness_set()
183 struct led_flash_setting *timeout = &fled_cdev->timeout; in ktd2692_led_flash_strobe_set() local
186 mutex_lock(&led->lock); in ktd2692_led_flash_strobe_set()
189 flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step); in ktd2692_led_flash_strobe_set()
193 led->mode = KTD2692_MODE_FLASH; in ktd2692_led_flash_strobe_set()
194 gpiod_direction_output(led->aux_gpio, KTD2692_HIGH); in ktd2692_led_flash_strobe_set()
196 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_flash_strobe_set()
197 gpiod_direction_output(led->aux_gpio, KTD2692_LOW); in ktd2692_led_flash_strobe_set()
200 ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); in ktd2692_led_flash_strobe_set()
202 fled_cdev->led_cdev.brightness = LED_OFF; in ktd2692_led_flash_strobe_set()
203 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_flash_strobe_set()
205 mutex_unlock(&led->lock); in ktd2692_led_flash_strobe_set()
211 u32 timeout) in ktd2692_led_flash_timeout_set() argument
222 step = KTD2692_MM_TO_FL_RATIO(cfg->flash_max_microamp) in ktd2692_init_movie_current_max()
227 offset--; in ktd2692_init_movie_current_max()
228 } while ((movie_current_microamp > cfg->movie_max_microamp) && in ktd2692_init_movie_current_max()
231 cfg->max_brightness = offset; in ktd2692_init_movie_current_max()
239 setting = &fled_cdev->timeout; in ktd2692_init_flash_timeout()
240 setting->min = KTD2692_FLASH_MODE_TIMEOUT_DISABLE; in ktd2692_init_flash_timeout()
241 setting->max = cfg->flash_max_timeout; in ktd2692_init_flash_timeout()
242 setting->step = cfg->flash_max_timeout in ktd2692_init_flash_timeout()
243 / (KTD2692_FLASH_MODE_TIMEOUT_LEVELS - 1); in ktd2692_init_flash_timeout()
244 setting->val = cfg->flash_max_timeout; in ktd2692_init_flash_timeout()
249 led->mode = KTD2692_MODE_DISABLE; in ktd2692_setup()
251 gpiod_direction_output(led->aux_gpio, KTD2692_LOW); in ktd2692_setup()
253 ktd2692_expresswire_write(led, (KTD2692_MM_MIN_CURR_THRESHOLD_SCALE - 1) in ktd2692_setup()
267 return -ENXIO; in ktd2692_parse_dt()
269 led->ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS); in ktd2692_parse_dt()
270 ret = PTR_ERR_OR_ZERO(led->ctrl_gpio); in ktd2692_parse_dt()
272 dev_err(dev, "cannot get ctrl-gpios %d\n", ret); in ktd2692_parse_dt()
276 led->aux_gpio = devm_gpiod_get(dev, "aux", GPIOD_ASIS); in ktd2692_parse_dt()
277 ret = PTR_ERR_OR_ZERO(led->aux_gpio); in ktd2692_parse_dt()
279 dev_err(dev, "cannot get aux-gpios %d\n", ret); in ktd2692_parse_dt()
283 led->regulator = devm_regulator_get(dev, "vin"); in ktd2692_parse_dt()
284 if (IS_ERR(led->regulator)) in ktd2692_parse_dt()
285 led->regulator = NULL; in ktd2692_parse_dt()
287 if (led->regulator) { in ktd2692_parse_dt()
288 ret = regulator_enable(led->regulator); in ktd2692_parse_dt()
296 return -EINVAL; in ktd2692_parse_dt()
299 led->fled_cdev.led_cdev.name = in ktd2692_parse_dt()
300 of_get_property(child_node, "label", NULL) ? : child_node->name; in ktd2692_parse_dt()
302 ret = of_property_read_u32(child_node, "led-max-microamp", in ktd2692_parse_dt()
303 &cfg->movie_max_microamp); in ktd2692_parse_dt()
305 dev_err(dev, "failed to parse led-max-microamp\n"); in ktd2692_parse_dt()
309 ret = of_property_read_u32(child_node, "flash-max-microamp", in ktd2692_parse_dt()
310 &cfg->flash_max_microamp); in ktd2692_parse_dt()
312 dev_err(dev, "failed to parse flash-max-microamp\n"); in ktd2692_parse_dt()
316 ret = of_property_read_u32(child_node, "flash-max-timeout-us", in ktd2692_parse_dt()
317 &cfg->flash_max_timeout); in ktd2692_parse_dt()
319 dev_err(dev, "failed to parse flash-max-timeout-us\n"); in ktd2692_parse_dt()
341 led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); in ktd2692_probe()
343 return -ENOMEM; in ktd2692_probe()
345 fled_cdev = &led->fled_cdev; in ktd2692_probe()
346 led_cdev = &fled_cdev->led_cdev; in ktd2692_probe()
348 ret = ktd2692_parse_dt(led, &pdev->dev, &led_cfg); in ktd2692_probe()
355 fled_cdev->ops = &flash_ops; in ktd2692_probe()
357 led_cdev->max_brightness = led_cfg.max_brightness; in ktd2692_probe()
358 led_cdev->brightness_set_blocking = ktd2692_led_brightness_set; in ktd2692_probe()
359 led_cdev->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; in ktd2692_probe()
361 mutex_init(&led->lock); in ktd2692_probe()
365 ret = led_classdev_flash_register(&pdev->dev, fled_cdev); in ktd2692_probe()
367 dev_err(&pdev->dev, "can't register LED %s\n", led_cdev->name); in ktd2692_probe()
368 mutex_destroy(&led->lock); in ktd2692_probe()
382 led_classdev_flash_unregister(&led->fled_cdev); in ktd2692_remove()
384 if (led->regulator) { in ktd2692_remove()
385 ret = regulator_disable(led->regulator); in ktd2692_remove()
387 dev_err(&pdev->dev, in ktd2692_remove()
391 mutex_destroy(&led->lock); in ktd2692_remove()