Lines Matching +full:flash +full:- +full:led

1 // SPDX-License-Identifier: GPL-2.0-only
3 * LED driver : leds-ktd2692.c
12 #include <linux/leds-expresswire.h>
13 #include <linux/led-class-flash.h>
25 /* Value related the flash mode */
30 /* Macro for getting offset of flash timeout */
44 /* Movie / Flash Mode Control */
52 /* maximum LED current in movie mode */
54 /* maximum LED current in flash mode */
56 /* maximum flash timeout */
58 /* max LED brightness level */
75 /* Related LED Flash class device */
98 struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); in ktd2692_led_brightness_set() local
100 mutex_lock(&led->lock); in ktd2692_led_brightness_set()
103 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_brightness_set()
104 gpiod_direction_output(led->aux_gpio, 0); in ktd2692_led_brightness_set()
106 expresswire_write_u8(&led->props, brightness | in ktd2692_led_brightness_set()
108 led->mode = KTD2692_MODE_MOVIE; in ktd2692_led_brightness_set()
111 expresswire_write_u8(&led->props, led->mode | KTD2692_REG_MODE_BASE); in ktd2692_led_brightness_set()
112 mutex_unlock(&led->lock); in ktd2692_led_brightness_set()
120 struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); in ktd2692_led_flash_strobe_set() local
121 struct led_flash_setting *timeout = &fled_cdev->timeout; in ktd2692_led_flash_strobe_set()
124 mutex_lock(&led->lock); in ktd2692_led_flash_strobe_set()
127 flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step); in ktd2692_led_flash_strobe_set()
128 expresswire_write_u8(&led->props, flash_tm_reg in ktd2692_led_flash_strobe_set()
131 led->mode = KTD2692_MODE_FLASH; in ktd2692_led_flash_strobe_set()
132 gpiod_direction_output(led->aux_gpio, 1); in ktd2692_led_flash_strobe_set()
134 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_flash_strobe_set()
135 gpiod_direction_output(led->aux_gpio, 0); in ktd2692_led_flash_strobe_set()
138 expresswire_write_u8(&led->props, led->mode | KTD2692_REG_MODE_BASE); in ktd2692_led_flash_strobe_set()
140 fled_cdev->led_cdev.brightness = LED_OFF; in ktd2692_led_flash_strobe_set()
141 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_flash_strobe_set()
143 mutex_unlock(&led->lock); in ktd2692_led_flash_strobe_set()
160 step = KTD2692_MM_TO_FL_RATIO(cfg->flash_max_microamp) in ktd2692_init_movie_current_max()
165 offset--; in ktd2692_init_movie_current_max()
166 } while ((movie_current_microamp > cfg->movie_max_microamp) && in ktd2692_init_movie_current_max()
169 cfg->max_brightness = offset; in ktd2692_init_movie_current_max()
177 setting = &fled_cdev->timeout; in ktd2692_init_flash_timeout()
178 setting->min = KTD2692_FLASH_MODE_TIMEOUT_DISABLE; in ktd2692_init_flash_timeout()
179 setting->max = cfg->flash_max_timeout; in ktd2692_init_flash_timeout()
180 setting->step = cfg->flash_max_timeout in ktd2692_init_flash_timeout()
181 / (KTD2692_FLASH_MODE_TIMEOUT_LEVELS - 1); in ktd2692_init_flash_timeout()
182 setting->val = cfg->flash_max_timeout; in ktd2692_init_flash_timeout()
185 static void ktd2692_setup(struct ktd2692_context *led) in ktd2692_setup() argument
187 led->mode = KTD2692_MODE_DISABLE; in ktd2692_setup()
188 expresswire_power_off(&led->props); in ktd2692_setup()
189 gpiod_direction_output(led->aux_gpio, 0); in ktd2692_setup()
191 expresswire_write_u8(&led->props, (KTD2692_MM_MIN_CURR_THRESHOLD_SCALE - 1) in ktd2692_setup()
193 expresswire_write_u8(&led->props, KTD2692_FLASH_MODE_CURR_PERCENT(45) in ktd2692_setup()
200 struct ktd2692_context *led = dev_get_drvdata(dev); in regulator_disable_action() local
203 ret = regulator_disable(led->regulator); in regulator_disable_action()
208 static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev, in ktd2692_parse_dt() argument
215 return -ENXIO; in ktd2692_parse_dt()
217 led->props.ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS); in ktd2692_parse_dt()
218 ret = PTR_ERR_OR_ZERO(led->props.ctrl_gpio); in ktd2692_parse_dt()
220 return dev_err_probe(dev, ret, "cannot get ctrl-gpios\n"); in ktd2692_parse_dt()
222 led->aux_gpio = devm_gpiod_get_optional(dev, "aux", GPIOD_ASIS); in ktd2692_parse_dt()
223 if (IS_ERR(led->aux_gpio)) in ktd2692_parse_dt()
224 return dev_err_probe(dev, PTR_ERR(led->aux_gpio), "cannot get aux-gpios\n"); in ktd2692_parse_dt()
226 led->regulator = devm_regulator_get(dev, "vin"); in ktd2692_parse_dt()
227 if (IS_ERR(led->regulator)) in ktd2692_parse_dt()
228 led->regulator = NULL; in ktd2692_parse_dt()
230 if (led->regulator) { in ktd2692_parse_dt()
231 ret = regulator_enable(led->regulator); in ktd2692_parse_dt()
245 dev_err(dev, "No DT child node found for connected LED.\n"); in ktd2692_parse_dt()
246 return -EINVAL; in ktd2692_parse_dt()
249 led->fled_cdev.led_cdev.name = in ktd2692_parse_dt()
250 of_get_property(child_node, "label", NULL) ? : child_node->name; in ktd2692_parse_dt()
252 ret = of_property_read_u32(child_node, "led-max-microamp", in ktd2692_parse_dt()
253 &cfg->movie_max_microamp); in ktd2692_parse_dt()
255 dev_err(dev, "failed to parse led-max-microamp\n"); in ktd2692_parse_dt()
259 ret = of_property_read_u32(child_node, "flash-max-microamp", in ktd2692_parse_dt()
260 &cfg->flash_max_microamp); in ktd2692_parse_dt()
262 dev_err(dev, "failed to parse flash-max-microamp\n"); in ktd2692_parse_dt()
266 ret = of_property_read_u32(child_node, "flash-max-timeout-us", in ktd2692_parse_dt()
267 &cfg->flash_max_timeout); in ktd2692_parse_dt()
269 dev_err(dev, "failed to parse flash-max-timeout-us\n"); in ktd2692_parse_dt()
283 struct ktd2692_context *led; in ktd2692_probe() local
289 led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); in ktd2692_probe()
290 if (!led) in ktd2692_probe()
291 return -ENOMEM; in ktd2692_probe()
293 fled_cdev = &led->fled_cdev; in ktd2692_probe()
294 led_cdev = &fled_cdev->led_cdev; in ktd2692_probe()
295 led->props.timing = ktd2692_timing; in ktd2692_probe()
297 ret = ktd2692_parse_dt(led, &pdev->dev, &led_cfg); in ktd2692_probe()
304 fled_cdev->ops = &flash_ops; in ktd2692_probe()
306 led_cdev->max_brightness = led_cfg.max_brightness; in ktd2692_probe()
307 led_cdev->brightness_set_blocking = ktd2692_led_brightness_set; in ktd2692_probe()
308 led_cdev->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; in ktd2692_probe()
310 mutex_init(&led->lock); in ktd2692_probe()
312 platform_set_drvdata(pdev, led); in ktd2692_probe()
314 ret = led_classdev_flash_register(&pdev->dev, fled_cdev); in ktd2692_probe()
316 dev_err(&pdev->dev, "can't register LED %s\n", led_cdev->name); in ktd2692_probe()
317 mutex_destroy(&led->lock); in ktd2692_probe()
321 ktd2692_setup(led); in ktd2692_probe()
328 struct ktd2692_context *led = platform_get_drvdata(pdev); in ktd2692_remove() local
330 led_classdev_flash_unregister(&led->fled_cdev); in ktd2692_remove()
332 mutex_destroy(&led->lock); in ktd2692_remove()
354 MODULE_DESCRIPTION("Kinetic KTD2692 LED driver");