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

1 // SPDX-License-Identifier: GPL-2.0
5 #include <linux/led-class-flash.h>
10 #include <media/v4l2-flash-led-class.h>
27 /* current timeout in us */
28 u32 timeout; member
29 /* maximum timeout in us */
43 if (priv->enabled == state) in sgm3140_strobe_set()
47 ret = regulator_enable(priv->vin_regulator); in sgm3140_strobe_set()
49 dev_err(fled_cdev->led_cdev.dev, in sgm3140_strobe_set()
53 gpiod_set_value_cansleep(priv->flash_gpio, 1); in sgm3140_strobe_set()
54 gpiod_set_value_cansleep(priv->enable_gpio, 1); in sgm3140_strobe_set()
55 mod_timer(&priv->powerdown_timer, in sgm3140_strobe_set()
56 jiffies + usecs_to_jiffies(priv->timeout)); in sgm3140_strobe_set()
58 del_timer_sync(&priv->powerdown_timer); in sgm3140_strobe_set()
59 gpiod_set_value_cansleep(priv->enable_gpio, 0); in sgm3140_strobe_set()
60 gpiod_set_value_cansleep(priv->flash_gpio, 0); in sgm3140_strobe_set()
61 ret = regulator_disable(priv->vin_regulator); in sgm3140_strobe_set()
63 dev_err(fled_cdev->led_cdev.dev, in sgm3140_strobe_set()
69 priv->enabled = state; in sgm3140_strobe_set()
78 *state = timer_pending(&priv->powerdown_timer); in sgm3140_strobe_get()
84 u32 timeout) in sgm3140_timeout_set() argument
88 priv->timeout = timeout; in sgm3140_timeout_set()
107 if (priv->enabled == enable) in sgm3140_brightness_set()
111 ret = regulator_enable(priv->vin_regulator); in sgm3140_brightness_set()
113 dev_err(led_cdev->dev, in sgm3140_brightness_set()
117 gpiod_set_value_cansleep(priv->flash_gpio, 0); in sgm3140_brightness_set()
118 gpiod_set_value_cansleep(priv->enable_gpio, 1); in sgm3140_brightness_set()
120 del_timer_sync(&priv->powerdown_timer); in sgm3140_brightness_set()
121 gpiod_set_value_cansleep(priv->flash_gpio, 0); in sgm3140_brightness_set()
122 gpiod_set_value_cansleep(priv->enable_gpio, 0); in sgm3140_brightness_set()
123 ret = regulator_disable(priv->vin_regulator); in sgm3140_brightness_set()
125 dev_err(led_cdev->dev, in sgm3140_brightness_set()
131 priv->enabled = enable; in sgm3140_brightness_set()
140 gpiod_set_value(priv->enable_gpio, 0); in sgm3140_powerdown_timer()
141 gpiod_set_value(priv->flash_gpio, 0); in sgm3140_powerdown_timer()
142 regulator_disable(priv->vin_regulator); in sgm3140_powerdown_timer()
144 priv->enabled = false; in sgm3140_powerdown_timer()
149 struct led_classdev_flash *fled_cdev = &priv->fled_cdev; in sgm3140_init_flash_timeout()
152 /* Init flash timeout setting */ in sgm3140_init_flash_timeout()
153 s = &fled_cdev->timeout; in sgm3140_init_flash_timeout()
154 s->min = 1; in sgm3140_init_flash_timeout()
155 s->max = priv->max_timeout; in sgm3140_init_flash_timeout()
156 s->step = 1; in sgm3140_init_flash_timeout()
157 s->val = FLASH_TIMEOUT_DEFAULT; in sgm3140_init_flash_timeout()
164 struct led_classdev *led_cdev = &priv->fled_cdev.led_cdev; in sgm3140_init_v4l2_flash_config()
167 strscpy(v4l2_sd_cfg->dev_name, led_cdev->dev->kobj.name, in sgm3140_init_v4l2_flash_config()
168 sizeof(v4l2_sd_cfg->dev_name)); in sgm3140_init_v4l2_flash_config()
170 /* Init flash intensity setting */ in sgm3140_init_v4l2_flash_config()
171 s = &v4l2_sd_cfg->intensity; in sgm3140_init_v4l2_flash_config()
172 s->min = 0; in sgm3140_init_v4l2_flash_config()
173 s->max = 1; in sgm3140_init_v4l2_flash_config()
174 s->step = 1; in sgm3140_init_v4l2_flash_config()
175 s->val = 1; in sgm3140_init_v4l2_flash_config()
195 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in sgm3140_probe()
197 return -ENOMEM; in sgm3140_probe()
199 priv->flash_gpio = devm_gpiod_get(&pdev->dev, "flash", GPIOD_OUT_LOW); in sgm3140_probe()
200 ret = PTR_ERR_OR_ZERO(priv->flash_gpio); in sgm3140_probe()
202 return dev_err_probe(&pdev->dev, ret, in sgm3140_probe()
203 "Failed to request flash gpio\n"); in sgm3140_probe()
205 priv->enable_gpio = devm_gpiod_get(&pdev->dev, "enable", GPIOD_OUT_LOW); in sgm3140_probe()
206 ret = PTR_ERR_OR_ZERO(priv->enable_gpio); in sgm3140_probe()
208 return dev_err_probe(&pdev->dev, ret, in sgm3140_probe()
211 priv->vin_regulator = devm_regulator_get(&pdev->dev, "vin"); in sgm3140_probe()
212 ret = PTR_ERR_OR_ZERO(priv->vin_regulator); in sgm3140_probe()
214 return dev_err_probe(&pdev->dev, ret, in sgm3140_probe()
217 child_node = fwnode_get_next_available_child_node(pdev->dev.fwnode, in sgm3140_probe()
220 dev_err(&pdev->dev, in sgm3140_probe()
222 return -EINVAL; in sgm3140_probe()
225 ret = fwnode_property_read_u32(child_node, "flash-max-timeout-us", in sgm3140_probe()
226 &priv->max_timeout); in sgm3140_probe()
228 priv->max_timeout = FLASH_MAX_TIMEOUT_DEFAULT; in sgm3140_probe()
229 dev_warn(&pdev->dev, in sgm3140_probe()
230 "flash-max-timeout-us property missing\n"); in sgm3140_probe()
234 * Set default timeout to FLASH_DEFAULT_TIMEOUT except if max_timeout in sgm3140_probe()
237 priv->timeout = min(priv->max_timeout, FLASH_TIMEOUT_DEFAULT); in sgm3140_probe()
239 timer_setup(&priv->powerdown_timer, sgm3140_powerdown_timer, 0); in sgm3140_probe()
241 fled_cdev = &priv->fled_cdev; in sgm3140_probe()
242 led_cdev = &fled_cdev->led_cdev; in sgm3140_probe()
244 fled_cdev->ops = &sgm3140_flash_ops; in sgm3140_probe()
246 led_cdev->brightness_set_blocking = sgm3140_brightness_set; in sgm3140_probe()
247 led_cdev->max_brightness = LED_ON; in sgm3140_probe()
248 led_cdev->flags |= LED_DEV_CAP_FLASH; in sgm3140_probe()
257 ret = devm_led_classdev_flash_register_ext(&pdev->dev, in sgm3140_probe()
260 dev_err(&pdev->dev, "Failed to register flash device: %d\n", in sgm3140_probe()
267 /* Create V4L2 Flash subdev */ in sgm3140_probe()
268 priv->v4l2_flash = v4l2_flash_init(&pdev->dev, in sgm3140_probe()
272 if (IS_ERR(priv->v4l2_flash)) { in sgm3140_probe()
273 ret = PTR_ERR(priv->v4l2_flash); in sgm3140_probe()
288 del_timer_sync(&priv->powerdown_timer); in sgm3140_remove()
290 v4l2_flash_release(priv->v4l2_flash); in sgm3140_remove()
295 { .compatible = "richtek,rt5033-led" },