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->enable_gpio, 1); in sgm3140_brightness_set()
119 gpiod_set_value_cansleep(priv->enable_gpio, 0); in sgm3140_brightness_set()
120 ret = regulator_disable(priv->vin_regulator); in sgm3140_brightness_set()
122 dev_err(led_cdev->dev, in sgm3140_brightness_set()
128 priv->enabled = enable; in sgm3140_brightness_set()
137 gpiod_set_value(priv->enable_gpio, 0); in sgm3140_powerdown_timer()
138 gpiod_set_value(priv->flash_gpio, 0); in sgm3140_powerdown_timer()
139 regulator_disable(priv->vin_regulator); in sgm3140_powerdown_timer()
141 priv->enabled = false; in sgm3140_powerdown_timer()
146 struct led_classdev_flash *fled_cdev = &priv->fled_cdev; in sgm3140_init_flash_timeout()
149 /* Init flash timeout setting */ in sgm3140_init_flash_timeout()
150 s = &fled_cdev->timeout; in sgm3140_init_flash_timeout()
151 s->min = 1; in sgm3140_init_flash_timeout()
152 s->max = priv->max_timeout; in sgm3140_init_flash_timeout()
153 s->step = 1; in sgm3140_init_flash_timeout()
154 s->val = FLASH_TIMEOUT_DEFAULT; in sgm3140_init_flash_timeout()
161 struct led_classdev *led_cdev = &priv->fled_cdev.led_cdev; in sgm3140_init_v4l2_flash_config()
164 strscpy(v4l2_sd_cfg->dev_name, led_cdev->dev->kobj.name, in sgm3140_init_v4l2_flash_config()
165 sizeof(v4l2_sd_cfg->dev_name)); in sgm3140_init_v4l2_flash_config()
167 /* Init flash intensity setting */ in sgm3140_init_v4l2_flash_config()
168 s = &v4l2_sd_cfg->intensity; in sgm3140_init_v4l2_flash_config()
169 s->min = 0; in sgm3140_init_v4l2_flash_config()
170 s->max = 1; in sgm3140_init_v4l2_flash_config()
171 s->step = 1; in sgm3140_init_v4l2_flash_config()
172 s->val = 1; in sgm3140_init_v4l2_flash_config()
192 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in sgm3140_probe()
194 return -ENOMEM; in sgm3140_probe()
196 priv->flash_gpio = devm_gpiod_get(&pdev->dev, "flash", GPIOD_OUT_LOW); in sgm3140_probe()
197 ret = PTR_ERR_OR_ZERO(priv->flash_gpio); in sgm3140_probe()
199 return dev_err_probe(&pdev->dev, ret, in sgm3140_probe()
200 "Failed to request flash gpio\n"); in sgm3140_probe()
202 priv->enable_gpio = devm_gpiod_get(&pdev->dev, "enable", GPIOD_OUT_LOW); in sgm3140_probe()
203 ret = PTR_ERR_OR_ZERO(priv->enable_gpio); in sgm3140_probe()
205 return dev_err_probe(&pdev->dev, ret, in sgm3140_probe()
208 priv->vin_regulator = devm_regulator_get(&pdev->dev, "vin"); in sgm3140_probe()
209 ret = PTR_ERR_OR_ZERO(priv->vin_regulator); in sgm3140_probe()
211 return dev_err_probe(&pdev->dev, ret, in sgm3140_probe()
214 child_node = fwnode_get_next_available_child_node(pdev->dev.fwnode, in sgm3140_probe()
217 dev_err(&pdev->dev, in sgm3140_probe()
219 return -EINVAL; in sgm3140_probe()
222 ret = fwnode_property_read_u32(child_node, "flash-max-timeout-us", in sgm3140_probe()
223 &priv->max_timeout); in sgm3140_probe()
225 priv->max_timeout = FLASH_MAX_TIMEOUT_DEFAULT; in sgm3140_probe()
226 dev_warn(&pdev->dev, in sgm3140_probe()
227 "flash-max-timeout-us property missing\n"); in sgm3140_probe()
231 * Set default timeout to FLASH_DEFAULT_TIMEOUT except if max_timeout in sgm3140_probe()
234 priv->timeout = min(priv->max_timeout, FLASH_TIMEOUT_DEFAULT); in sgm3140_probe()
236 timer_setup(&priv->powerdown_timer, sgm3140_powerdown_timer, 0); in sgm3140_probe()
238 fled_cdev = &priv->fled_cdev; in sgm3140_probe()
239 led_cdev = &fled_cdev->led_cdev; in sgm3140_probe()
241 fled_cdev->ops = &sgm3140_flash_ops; in sgm3140_probe()
243 led_cdev->brightness_set_blocking = sgm3140_brightness_set; in sgm3140_probe()
244 led_cdev->max_brightness = LED_ON; in sgm3140_probe()
245 led_cdev->flags |= LED_DEV_CAP_FLASH; in sgm3140_probe()
254 ret = devm_led_classdev_flash_register_ext(&pdev->dev, in sgm3140_probe()
257 dev_err(&pdev->dev, "Failed to register flash device: %d\n", in sgm3140_probe()
264 /* Create V4L2 Flash subdev */ in sgm3140_probe()
265 priv->v4l2_flash = v4l2_flash_init(&pdev->dev, in sgm3140_probe()
269 if (IS_ERR(priv->v4l2_flash)) { in sgm3140_probe()
270 ret = PTR_ERR(priv->v4l2_flash); in sgm3140_probe()
285 del_timer_sync(&priv->powerdown_timer); in sgm3140_remove()
287 v4l2_flash_release(priv->v4l2_flash); in sgm3140_remove()