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

1 // SPDX-License-Identifier: GPL-2.0-only
6 #include <linux/led-class-flash.h>
11 #include <media/v4l2-flash-led-class.h>
48 struct led_classdev_flash flash; member
56 container_of(lcdev, struct rt4505_priv, flash.led_cdev); in rt4505_torch_brightness_set()
60 mutex_lock(&priv->lock); in rt4505_torch_brightness_set()
63 ret = regmap_update_bits(priv->regmap, in rt4505_torch_brightness_set()
65 (level - 1) << RT4505_ITORCH_SHIFT); in rt4505_torch_brightness_set()
72 ret = regmap_update_bits(priv->regmap, RT4505_REG_ENABLE, in rt4505_torch_brightness_set()
76 mutex_unlock(&priv->lock); in rt4505_torch_brightness_set()
84 container_of(lcdev, struct rt4505_priv, flash.led_cdev); in rt4505_torch_brightness_get()
88 mutex_lock(&priv->lock); in rt4505_torch_brightness_get()
90 ret = regmap_read(priv->regmap, RT4505_REG_ENABLE, &val); in rt4505_torch_brightness_get()
92 dev_err(lcdev->dev, "Failed to get LED enable\n"); in rt4505_torch_brightness_get()
102 ret = regmap_read(priv->regmap, RT4505_REG_ILED, &val); in rt4505_torch_brightness_get()
104 dev_err(lcdev->dev, "Failed to get LED brightness\n"); in rt4505_torch_brightness_get()
112 mutex_unlock(&priv->lock); in rt4505_torch_brightness_get()
120 container_of(fled_cdev, struct rt4505_priv, flash); in rt4505_flash_brightness_set()
121 struct led_flash_setting *s = &fled_cdev->brightness; in rt4505_flash_brightness_set()
122 u32 val = (brightness - s->min) / s->step; in rt4505_flash_brightness_set()
125 mutex_lock(&priv->lock); in rt4505_flash_brightness_set()
126 ret = regmap_update_bits(priv->regmap, RT4505_REG_ILED, in rt4505_flash_brightness_set()
128 mutex_unlock(&priv->lock); in rt4505_flash_brightness_set()
137 container_of(fled_cdev, struct rt4505_priv, flash); in rt4505_flash_strobe_set()
141 mutex_lock(&priv->lock); in rt4505_flash_strobe_set()
142 ret = regmap_update_bits(priv->regmap, RT4505_REG_ENABLE, in rt4505_flash_strobe_set()
144 mutex_unlock(&priv->lock); in rt4505_flash_strobe_set()
153 container_of(fled_cdev, struct rt4505_priv, flash); in rt4505_flash_strobe_get()
157 mutex_lock(&priv->lock); in rt4505_flash_strobe_get()
159 ret = regmap_read(priv->regmap, RT4505_REG_ENABLE, &val); in rt4505_flash_strobe_get()
166 mutex_unlock(&priv->lock); in rt4505_flash_strobe_get()
171 u32 timeout) in rt4505_flash_timeout_set() argument
174 container_of(fled_cdev, struct rt4505_priv, flash); in rt4505_flash_timeout_set()
175 struct led_flash_setting *s = &fled_cdev->timeout; in rt4505_flash_timeout_set()
176 u32 val = (timeout - s->min) / s->step; in rt4505_flash_timeout_set()
179 mutex_lock(&priv->lock); in rt4505_flash_timeout_set()
180 ret = regmap_update_bits(priv->regmap, RT4505_REG_CONFIG, in rt4505_flash_timeout_set()
182 mutex_unlock(&priv->lock); in rt4505_flash_timeout_set()
190 container_of(fled_cdev, struct rt4505_priv, flash); in rt4505_fault_get()
194 ret = regmap_read(priv->regmap, RT4505_REG_FLAGS, &val); in rt4505_fault_get()
243 struct led_classdev_flash *flash = v4l2_flash->fled_cdev; in rt4505_flash_external_strobe_set() local
245 container_of(flash, struct rt4505_priv, flash); in rt4505_flash_external_strobe_set()
249 mutex_lock(&priv->lock); in rt4505_flash_external_strobe_set()
250 ret = regmap_update_bits(priv->regmap, RT4505_REG_ENABLE, in rt4505_flash_external_strobe_set()
252 mutex_unlock(&priv->lock); in rt4505_flash_external_strobe_set()
264 struct led_classdev_flash *flash = &priv->flash; in rt4505_init_v4l2_config() local
265 struct led_classdev *lcdev = &flash->led_cdev; in rt4505_init_v4l2_config()
268 strscpy(config->dev_name, lcdev->dev->kobj.name, in rt4505_init_v4l2_config()
269 sizeof(config->dev_name)); in rt4505_init_v4l2_config()
271 s = &config->intensity; in rt4505_init_v4l2_config()
272 s->min = RT4505_ITORCH_MINUA; in rt4505_init_v4l2_config()
273 s->step = RT4505_ITORCH_STPUA; in rt4505_init_v4l2_config()
274 s->max = s->val = s->min + (lcdev->max_brightness - 1) * s->step; in rt4505_init_v4l2_config()
276 config->flash_faults = LED_FAULT_OVER_VOLTAGE | in rt4505_init_v4l2_config()
280 config->has_external_strobe = 1; in rt4505_init_v4l2_config()
293 struct led_classdev_flash *flash = &priv->flash; in rt4505_init_flash_properties() local
294 struct led_classdev *lcdev = &flash->led_cdev; in rt4505_init_flash_properties()
299 ret = fwnode_property_read_u32(child, "led-max-microamp", &val); in rt4505_init_flash_properties()
301 dev_warn(priv->dev, "led-max-microamp DT property missing\n"); in rt4505_init_flash_properties()
306 lcdev->max_brightness = in rt4505_init_flash_properties()
307 (val - RT4505_ITORCH_MINUA) / RT4505_ITORCH_STPUA + 1; in rt4505_init_flash_properties()
308 lcdev->brightness_set_blocking = rt4505_torch_brightness_set; in rt4505_init_flash_properties()
309 lcdev->brightness_get = rt4505_torch_brightness_get; in rt4505_init_flash_properties()
310 lcdev->flags |= LED_DEV_CAP_FLASH; in rt4505_init_flash_properties()
312 ret = fwnode_property_read_u32(child, "flash-max-microamp", &val); in rt4505_init_flash_properties()
314 dev_warn(priv->dev, "flash-max-microamp DT property missing\n"); in rt4505_init_flash_properties()
319 s = &flash->brightness; in rt4505_init_flash_properties()
320 s->min = RT4505_IFLASH_MINUA; in rt4505_init_flash_properties()
321 s->step = RT4505_IFLASH_STPUA; in rt4505_init_flash_properties()
322 s->max = s->val = val; in rt4505_init_flash_properties()
324 ret = fwnode_property_read_u32(child, "flash-max-timeout-us", &val); in rt4505_init_flash_properties()
326 dev_warn(priv->dev, in rt4505_init_flash_properties()
327 "flash-max-timeout-us DT property missing\n"); in rt4505_init_flash_properties()
333 s = &flash->timeout; in rt4505_init_flash_properties()
334 s->min = RT4505_FLASHTO_MINUS; in rt4505_init_flash_properties()
335 s->step = RT4505_FLASHTO_STPUS; in rt4505_init_flash_properties()
336 s->max = s->val = val; in rt4505_init_flash_properties()
338 flash->ops = &rt4505_flash_ops; in rt4505_init_flash_properties()
349 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); in rt4505_probe()
351 return -ENOMEM; in rt4505_probe()
353 priv->dev = &client->dev; in rt4505_probe()
354 mutex_init(&priv->lock); in rt4505_probe()
356 priv->regmap = devm_regmap_init_i2c(client, &rt4505_regmap_config); in rt4505_probe()
357 if (IS_ERR(priv->regmap)) { in rt4505_probe()
358 dev_err(priv->dev, "Failed to allocate register map\n"); in rt4505_probe()
359 return PTR_ERR(priv->regmap); in rt4505_probe()
362 ret = regmap_write(priv->regmap, RT4505_REG_RESET, RT4505_RESET_MASK); in rt4505_probe()
364 dev_err(priv->dev, "Failed to reset registers\n"); in rt4505_probe()
368 child = fwnode_get_next_available_child_node(client->dev.fwnode, NULL); in rt4505_probe()
370 dev_err(priv->dev, "Failed to get child node\n"); in rt4505_probe()
371 return -EINVAL; in rt4505_probe()
376 ret = devm_led_classdev_flash_register_ext(priv->dev, &priv->flash, in rt4505_probe()
379 dev_err(priv->dev, "Failed to register flash\n"); in rt4505_probe()
384 priv->v4l2_flash = v4l2_flash_init(priv->dev, init_data.fwnode, in rt4505_probe()
385 &priv->flash, &v4l2_flash_ops, in rt4505_probe()
387 if (IS_ERR(priv->v4l2_flash)) { in rt4505_probe()
388 dev_err(priv->dev, "Failed to register v4l2 flash\n"); in rt4505_probe()
389 return PTR_ERR(priv->v4l2_flash); in rt4505_probe()
400 v4l2_flash_release(priv->v4l2_flash); in rt4505_remove()
408 regmap_write(priv->regmap, RT4505_REG_RESET, RT4505_RESET_MASK); in rt4505_shutdown()