Lines Matching +full:max +full:- +full:brightness
1 // SPDX-License-Identifier: GPL-2.0-or-later
28 #include <linux/led-class-flash.h>
35 #include <media/v4l2-flash-led-class.h>
37 /* We can provide 15-700 mA out to the LED */
40 /* The maximum intensity is 1-16 for flash and 1-100 for torch */
56 u32 max_timeout; /* Flash max timeout */
68 gpiod_set_value(rt->enable_flash, 0); in rt8515_gpio_led_off()
69 gpiod_set_value(rt->enable_torch, 0); in rt8515_gpio_led_off()
73 int brightness) in rt8515_gpio_brightness_commit() argument
79 * brightness one step at a time. in rt8515_gpio_brightness_commit()
81 for (i = 0; i < brightness; i++) { in rt8515_gpio_brightness_commit()
91 enum led_brightness brightness) in rt8515_led_brightness_set() argument
96 mutex_lock(&rt->lock); in rt8515_led_brightness_set()
98 if (brightness == LED_OFF) { in rt8515_led_brightness_set()
101 } else if (brightness < RT8515_TORCH_MAX) { in rt8515_led_brightness_set()
102 /* Step it up to movie mode brightness using the flash pin */ in rt8515_led_brightness_set()
103 rt8515_gpio_brightness_commit(rt->enable_torch, brightness); in rt8515_led_brightness_set()
105 /* Max torch brightness requested */ in rt8515_led_brightness_set()
106 gpiod_set_value(rt->enable_torch, 1); in rt8515_led_brightness_set()
109 mutex_unlock(&rt->lock); in rt8515_led_brightness_set()
118 struct led_flash_setting *timeout = &fled->timeout; in rt8515_led_flash_strobe_set()
119 int brightness = rt->flash_max_intensity; in rt8515_led_flash_strobe_set() local
121 mutex_lock(&rt->lock); in rt8515_led_flash_strobe_set()
124 /* Enable LED flash mode and set brightness */ in rt8515_led_flash_strobe_set()
125 rt8515_gpio_brightness_commit(rt->enable_flash, brightness); in rt8515_led_flash_strobe_set()
127 mod_timer(&rt->powerdown_timer, in rt8515_led_flash_strobe_set()
128 jiffies + usecs_to_jiffies(timeout->val)); in rt8515_led_flash_strobe_set()
130 del_timer_sync(&rt->powerdown_timer); in rt8515_led_flash_strobe_set()
135 fled->led_cdev.brightness = LED_OFF; in rt8515_led_flash_strobe_set()
138 mutex_unlock(&rt->lock); in rt8515_led_flash_strobe_set()
148 *state = timer_pending(&rt->powerdown_timer); in rt8515_led_flash_strobe_get()
156 /* The timeout is stored in the led-class-flash core */ in rt8515_led_flash_timeout_set()
176 struct led_classdev_flash *fled = &rt->fled; in rt8515_init_flash_timeout()
180 s = &fled->timeout; in rt8515_init_flash_timeout()
181 s->min = 1; in rt8515_init_flash_timeout()
182 s->max = rt->max_timeout; in rt8515_init_flash_timeout()
183 s->step = 1; in rt8515_init_flash_timeout()
188 s->val = min(rt->max_timeout, RT8515_TIMEOUT_US); in rt8515_init_flash_timeout()
196 struct led_classdev *led = &rt->fled.led_cdev; in rt8515_init_v4l2_flash_config()
199 strscpy(v4l2_sd_cfg->dev_name, led->dev->kobj.name, in rt8515_init_v4l2_flash_config()
200 sizeof(v4l2_sd_cfg->dev_name)); in rt8515_init_v4l2_flash_config()
204 * capped from the device tree max intensity setting in rt8515_init_v4l2_flash_config()
207 s = &v4l2_sd_cfg->intensity; in rt8515_init_v4l2_flash_config()
208 s->min = 1; in rt8515_init_v4l2_flash_config()
209 s->max = rt->flash_max_intensity; in rt8515_init_v4l2_flash_config()
210 s->step = 1; in rt8515_init_v4l2_flash_config()
211 s->val = s->max; in rt8515_init_v4l2_flash_config()
216 v4l2_flash_release(rt->v4l2_flash); in rt8515_v4l2_flash_release()
242 fwnode_property_read_u32(rt->dev->fwnode, resistance, &res); in rt8515_determine_max_intensity()
247 dev_err(rt->dev, in rt8515_determine_max_intensity()
248 "either %s or %s missing from DT, using HW max\n", in rt8515_determine_max_intensity()
261 * Calculate max intensity (linear scaling) in rt8515_determine_max_intensity()
266 dev_info(rt->dev, in rt8515_determine_max_intensity()
267 "current restricted from %u to %u mA, max intensity %d/100\n", in rt8515_determine_max_intensity()
271 dev_info(rt->dev, "max intensity %d/%d = %d mA\n", in rt8515_determine_max_intensity()
278 struct device *dev = &pdev->dev; in rt8515_probe()
289 return -ENOMEM; in rt8515_probe()
291 rt->dev = dev; in rt8515_probe()
292 fled = &rt->fled; in rt8515_probe()
293 led = &fled->led_cdev; in rt8515_probe()
295 /* ENF - Enable Flash line */ in rt8515_probe()
296 rt->enable_flash = devm_gpiod_get(dev, "enf", GPIOD_OUT_LOW); in rt8515_probe()
297 if (IS_ERR(rt->enable_flash)) in rt8515_probe()
298 return dev_err_probe(dev, PTR_ERR(rt->enable_flash), in rt8515_probe()
301 /* ENT - Enable Torch line */ in rt8515_probe()
302 rt->enable_torch = devm_gpiod_get(dev, "ent", GPIOD_OUT_LOW); in rt8515_probe()
303 if (IS_ERR(rt->enable_torch)) in rt8515_probe()
304 return dev_err_probe(dev, PTR_ERR(rt->enable_torch), in rt8515_probe()
307 child = fwnode_get_next_available_child_node(dev->fwnode, NULL); in rt8515_probe()
311 return -EINVAL; in rt8515_probe()
315 rt8515_determine_max_intensity(rt, child, "richtek,rfs-ohms", in rt8515_probe()
316 "flash-max-microamp", in rt8515_probe()
318 &rt->flash_max_intensity); in rt8515_probe()
319 rt8515_determine_max_intensity(rt, child, "richtek,rts-ohms", in rt8515_probe()
320 "led-max-microamp", in rt8515_probe()
322 &rt->torch_max_intensity); in rt8515_probe()
324 ret = fwnode_property_read_u32(child, "flash-max-timeout-us", in rt8515_probe()
325 &rt->max_timeout); in rt8515_probe()
327 rt->max_timeout = RT8515_MAX_TIMEOUT_US; in rt8515_probe()
329 "flash-max-timeout-us property missing\n"); in rt8515_probe()
331 timer_setup(&rt->powerdown_timer, rt8515_powerdown_timer, 0); in rt8515_probe()
334 fled->ops = &rt8515_flash_ops; in rt8515_probe()
336 led->max_brightness = rt->torch_max_intensity; in rt8515_probe()
337 led->brightness_set_blocking = rt8515_led_brightness_set; in rt8515_probe()
338 led->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; in rt8515_probe()
340 mutex_init(&rt->lock); in rt8515_probe()
347 mutex_destroy(&rt->lock); in rt8515_probe()
348 dev_err(dev, "can't register LED %s\n", led->name); in rt8515_probe()
355 rt->v4l2_flash = v4l2_flash_init(dev, child, fled, NULL, &v4l2_sd_cfg); in rt8515_probe()
356 if (IS_ERR(rt->v4l2_flash)) { in rt8515_probe()
357 ret = PTR_ERR(rt->v4l2_flash); in rt8515_probe()
375 del_timer_sync(&rt->powerdown_timer); in rt8515_remove()
376 mutex_destroy(&rt->lock); in rt8515_remove()