Lines Matching +full:client +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0
18 #include <linux/rk-camera-module.h>
19 #include <linux/rk-led-flash.h>
22 #include <media/v4l2-ctrls.h>
23 #include <media/v4l2-device.h>
61 (((a) - AW36518_MIN_FLASH_INTENSITY) / AW36518_FLASH_INTENSITY_STEP))
74 (((a) - AW36518_MIN_TORCH_INTENSITY) / AW36518_TORCH_INTENSITY_STEP))
90 (((a) - TIMEOUT_MIN) / TIMEOUT_STEP))
96 MODULE_PARM_DESC(debug, "debug level (0-2)");
116 struct i2c_client *client; member
138 struct i2c_client *client = flash->client; in aw36518_i2c_write() local
141 ret = i2c_smbus_write_byte_data(client, reg, val); in aw36518_i2c_write()
143 dev_err(&client->dev, in aw36518_i2c_write()
147 v4l2_dbg(2, debug, &flash->leds[0].sd, in aw36518_i2c_write()
156 struct i2c_client *client = flash->client; in aw36518_i2c_read() local
159 ret = i2c_smbus_read_byte_data(client, reg); in aw36518_i2c_read()
161 dev_err(&client->dev, in aw36518_i2c_read()
165 dev_dbg(&client->dev, "%s: reg:0x%x val:0x%x\n", in aw36518_i2c_read()
173 struct i2c_client *client = flash->client; in aw36518_led_on() local
177 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_led_on()
182 dev_err(&client->dev, in aw36518_led_on()
186 if (flash->led_mode == V4L2_FLASH_LED_MODE_FLASH && on) in aw36518_led_on()
191 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_led_on()
195 flash->leds[0].timestamp = ns_to_kernel_old_timeval(ktime_get_ns()); in aw36518_led_on()
196 flash->leds[1].timestamp = flash->leds[0].timestamp; in aw36518_led_on()
207 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_get_fault()
221 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_timeout_cal()
222 "%s: timeout:%dUS\n", __func__, flash->flash_timeout); in aw36518_timeout_cal()
224 if (flash->flash_timeout < 400000) in aw36518_timeout_cal()
225 val = AW36518_FLASH_TOUT_ms_TO_REG(flash->flash_timeout); in aw36518_timeout_cal()
227 val = (flash->flash_timeout - 0x400000) / TIMEOUT_STEP2; in aw36518_timeout_cal()
239 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_set_timeout()
241 __func__, flash->flash_timeout); in aw36518_set_timeout()
243 flash->flash_timeout = timeout; in aw36518_set_timeout()
254 enum aw36518_led_id id) in aw36518_torch_brt() argument
256 struct aw36518_led *led = &flash->leds[id]; in aw36518_torch_brt()
259 v4l2_dbg(1, debug, &led->sd, in aw36518_torch_brt()
260 "%s: %d\n", __func__, led->torch_brt->val); in aw36518_torch_brt()
262 val = AW36518_TORCH_BRT_uA_TO_REG(led->torch_brt->val); in aw36518_torch_brt()
263 reg = id ? AW36518_REG_LED1_TORCH_CUR : AW36518_REG_LED0_TORCH_CUR; in aw36518_torch_brt()
268 enum aw36518_led_id id) in aw36518_flash_brt() argument
270 struct aw36518_led *led = &flash->leds[id]; in aw36518_flash_brt()
273 v4l2_dbg(1, debug, &led->sd, in aw36518_flash_brt()
274 "%s: %d\n", __func__, led->flash_brt->val); in aw36518_flash_brt()
276 val = AW36518_FLASH_BRT_uA_TO_REG(led->flash_brt->val); in aw36518_flash_brt()
277 reg = id ? AW36518_REG_LED1_FLASH_CUR : AW36518_REG_LED0_FLASH_CUR; in aw36518_flash_brt()
282 enum aw36518_led_id id, unsigned int mode) in aw36518_set_mode() argument
286 v4l2_dbg(1, debug, &flash->leds[id].sd, in aw36518_set_mode()
288 mode, flash->led_mode); in aw36518_set_mode()
290 if (flash->led_mode == mode) in aw36518_set_mode()
295 flash->led_mode = mode; in aw36518_set_mode()
306 if (flash->torch_gpio) { in aw36518_set_mode()
307 v4l2_dbg(1, debug, &flash->leds[id].sd, in aw36518_set_mode()
309 gpiod_set_value_cansleep(flash->torch_gpio, 1); in aw36518_set_mode()
314 if (flash->torch_gpio) { in aw36518_set_mode()
315 v4l2_dbg(1, debug, &flash->leds[id].sd, in aw36518_set_mode()
317 gpiod_set_value_cansleep(flash->torch_gpio, 0); in aw36518_set_mode()
329 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_strobe()
332 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) in aw36518_strobe()
333 return -EBUSY; in aw36518_strobe()
339 static int aw36518_get_ctrl(struct v4l2_ctrl *ctrl, enum aw36518_led_id id) in aw36518_get_ctrl() argument
342 container_of(ctrl->handler, struct aw36518_led, ctrls); in aw36518_get_ctrl()
344 container_of(led, struct aw36518_flash, leds[id]); in aw36518_get_ctrl()
346 struct i2c_client *client = flash->client; in aw36518_get_ctrl() local
348 v4l2_dbg(1, debug, &flash->leds[id].sd, in aw36518_get_ctrl()
349 "%s: id 0x%x\n", __func__, ctrl->id); in aw36518_get_ctrl()
351 mutex_lock(&flash->lock); in aw36518_get_ctrl()
352 switch (ctrl->id) { in aw36518_get_ctrl()
355 ctrl->val = 0; in aw36518_get_ctrl()
357 ctrl->val |= V4L2_FLASH_FAULT_SHORT_CIRCUIT; in aw36518_get_ctrl()
359 ctrl->val |= V4L2_FLASH_FAULT_OVER_TEMPERATURE; in aw36518_get_ctrl()
361 ctrl->val |= V4L2_FLASH_FAULT_TIMEOUT; in aw36518_get_ctrl()
363 ctrl->val |= V4L2_FLASH_FAULT_OVER_VOLTAGE; in aw36518_get_ctrl()
367 dev_err(&client->dev, in aw36518_get_ctrl()
368 "ctrl 0x%x not supported\n", ctrl->id); in aw36518_get_ctrl()
369 ret = -EINVAL; in aw36518_get_ctrl()
373 mutex_unlock(&flash->lock); in aw36518_get_ctrl()
377 static int aw36518_set_ctrl(struct v4l2_ctrl *ctrl, enum aw36518_led_id id) in aw36518_set_ctrl() argument
380 container_of(ctrl->handler, struct aw36518_led, ctrls); in aw36518_set_ctrl()
382 container_of(led, struct aw36518_flash, leds[id]); in aw36518_set_ctrl()
384 struct i2c_client *client = flash->client; in aw36518_set_ctrl() local
386 v4l2_dbg(1, debug, &led->sd, in aw36518_set_ctrl()
387 "%s: id 0x%x val 0x%x\n", in aw36518_set_ctrl()
388 __func__, ctrl->id, ctrl->val); in aw36518_set_ctrl()
390 mutex_lock(&flash->lock); in aw36518_set_ctrl()
396 (ctrl->id == V4L2_CID_FLASH_STROBE || in aw36518_set_ctrl()
397 ctrl->id == V4L2_CID_FLASH_TORCH_INTENSITY || in aw36518_set_ctrl()
398 ctrl->id == V4L2_CID_FLASH_LED_MODE)) { in aw36518_set_ctrl()
399 ret = -EBUSY; in aw36518_set_ctrl()
403 switch (ctrl->id) { in aw36518_set_ctrl()
405 ret = aw36518_set_mode(flash, id, ctrl->val); in aw36518_set_ctrl()
414 ret = aw36518_set_timeout(flash, ctrl->val); in aw36518_set_ctrl()
417 ret = aw36518_flash_brt(flash, id); in aw36518_set_ctrl()
420 ret = aw36518_torch_brt(flash, id); in aw36518_set_ctrl()
423 dev_err(&client->dev, in aw36518_set_ctrl()
424 "ctrl 0x%x not supported\n", ctrl->id); in aw36518_set_ctrl()
425 ret = -EINVAL; in aw36518_set_ctrl()
430 mutex_unlock(&flash->lock); in aw36518_set_ctrl()
466 enum aw36518_led_id id) in aw36518_init_controls() argument
469 struct v4l2_ctrl_handler *hdl = &flash->leds[id].ctrls; in aw36518_init_controls()
470 const struct v4l2_ctrl_ops *ops = &aw36518_ctrl_ops[id]; in aw36518_init_controls()
471 struct aw36518_led *led = &flash->leds[id]; in aw36518_init_controls()
478 flash->led_mode = V4L2_FLASH_LED_MODE_NONE; in aw36518_init_controls()
492 led->max_flash_timeout, in aw36518_init_controls()
494 led->max_flash_timeout); in aw36518_init_controls()
495 flash->flash_timeout = led->max_flash_timeout; in aw36518_init_controls()
497 flash->leds[id].flash_brt = in aw36518_init_controls()
501 led->max_flash_intensity, in aw36518_init_controls()
505 flash->leds[id].torch_brt = in aw36518_init_controls()
509 led->max_torch_intensity, in aw36518_init_controls()
520 if (hdl->error) in aw36518_init_controls()
521 return hdl->error; in aw36518_init_controls()
523 fault->flags |= V4L2_CTRL_FLAG_VOLATILE; in aw36518_init_controls()
525 flash->leds[id].sd.ctrl_handler = hdl; in aw36518_init_controls()
536 ti->tv_sec = led->timestamp.tv_sec; in aw36518_get_time_info()
537 ti->tv_usec = led->timestamp.tv_usec; in aw36518_get_time_info()
539 "%s: tv_sec:%ld, tv_usec:%ld\n", __func__, ti->tv_sec, ti->tv_usec); in aw36518_get_time_info()
553 ret = -ENOIOCTLCMD; in aw36518_ioctl()
576 ret = -ENOMEM; in aw36518_compat_ioctl32()
581 compat_t->tv_sec = t.tv_sec; in aw36518_compat_ioctl32()
582 compat_t->tv_usec = t.tv_usec; in aw36518_compat_ioctl32()
585 ret = -EFAULT; in aw36518_compat_ioctl32()
591 ret = -ENOIOCTLCMD; in aw36518_compat_ioctl32()
603 rval = pm_runtime_get_sync(sd->dev); in aw36518_open()
605 pm_runtime_put_noidle(sd->dev); in aw36518_open()
614 pm_runtime_put(sd->dev); in aw36518_close()
625 struct i2c_client *client = flash->client; in aw36518_s_power() local
627 dev_info(&client->dev, "%s on(%d)\n", __func__, on); in aw36518_s_power()
628 mutex_lock(&flash->lock); in aw36518_s_power()
630 /* If the power state is not modified - no work to do. */ in aw36518_s_power()
631 if (flash->power_on == !!on) in aw36518_s_power()
635 ret = pm_runtime_get_sync(&client->dev); in aw36518_s_power()
637 pm_runtime_put_noidle(&client->dev); in aw36518_s_power()
640 flash->power_on = true; in aw36518_s_power()
642 pm_runtime_put(&client->dev); in aw36518_s_power()
643 flash->power_on = false; in aw36518_s_power()
647 mutex_unlock(&flash->lock); in aw36518_s_power()
671 gpiod_direction_output(flash->en_gpio, on); in __aw36518_set_power()
683 dev_err(&flash->client->dev, in aw36518_check_id()
684 "Read chip id error\n"); in aw36518_check_id()
685 return -ENODEV; in aw36518_check_id()
688 dev_info(&flash->client->dev, in aw36518_check_id()
689 "Detected aw36518 flash id:0x%x\n", ret); in aw36518_check_id()
693 static int aw36518_of_init(struct i2c_client *client, in aw36518_of_init() argument
696 struct device_node *node = client->dev.of_node; in aw36518_of_init()
702 dev_err(&client->dev, in aw36518_of_init()
709 &flash->module_index); in aw36518_of_init()
712 &flash->module_facing); in aw36518_of_init()
714 dev_err(&client->dev, in aw36518_of_init()
719 flash->en_gpio = devm_gpiod_get(&client->dev, in aw36518_of_init()
721 if (IS_ERR(flash->en_gpio)) { in aw36518_of_init()
722 flash->en_gpio = NULL; in aw36518_of_init()
723 dev_warn(&client->dev, in aw36518_of_init()
724 "get enable-gpio failed, using assist light mode\n"); in aw36518_of_init()
727 flash->torch_gpio = devm_gpiod_get(&client->dev, in aw36518_of_init()
729 if (IS_ERR(flash->torch_gpio)) { in aw36518_of_init()
730 flash->torch_gpio = NULL; in aw36518_of_init()
731 dev_warn(&client->dev, in aw36518_of_init()
732 "get torch-gpio failed, using assist light mode\n"); in aw36518_of_init()
735 flash->strobe_gpio = devm_gpiod_get(&client->dev, in aw36518_of_init()
737 if (IS_ERR(flash->strobe_gpio)) { in aw36518_of_init()
738 flash->strobe_gpio = NULL; in aw36518_of_init()
739 dev_warn(&client->dev, in aw36518_of_init()
740 "get strobe-gpio failed, using assist light mode\n"); in aw36518_of_init()
743 flash->tx_gpio = devm_gpiod_get(&client->dev, in aw36518_of_init()
745 if (IS_ERR(flash->tx_gpio)) { in aw36518_of_init()
746 flash->tx_gpio = NULL; in aw36518_of_init()
747 dev_warn(&client->dev, in aw36518_of_init()
748 "get tx-gpio failed, using assist light mode\n"); in aw36518_of_init()
752 u32 id = 0; in aw36518_of_init() local
754 of_property_read_u32(child, "reg", &id); in aw36518_of_init()
755 if (id >= LED_MAX) { in aw36518_of_init()
756 dev_err(&client->dev, "only support 2 leds\n"); in aw36518_of_init()
759 led = &flash->leds[id]; in aw36518_of_init()
760 led->sd.fwnode = of_fwnode_handle(child); in aw36518_of_init()
761 if (of_property_read_u32(child, "flash-max-timeout-us", in aw36518_of_init()
762 &led->max_flash_timeout)) { in aw36518_of_init()
763 dev_err(&client->dev, in aw36518_of_init()
764 "get led%d flash-max-timeout-us fail\n", id); in aw36518_of_init()
767 if (led->max_flash_timeout > TIMEOUT_MAX) in aw36518_of_init()
768 led->max_flash_timeout = TIMEOUT_MAX; in aw36518_of_init()
770 if (of_property_read_u32(child, "flash-max-microamp", in aw36518_of_init()
771 &led->max_flash_intensity)) { in aw36518_of_init()
772 dev_err(&client->dev, in aw36518_of_init()
773 "get led%d flash-max-microamp fail\n", id); in aw36518_of_init()
776 if (led->max_flash_intensity > AW36518_MAX_FLASH_INTENSITY) in aw36518_of_init()
777 led->max_flash_intensity = AW36518_MAX_FLASH_INTENSITY; in aw36518_of_init()
779 if (of_property_read_u32(child, "led-max-microamp", in aw36518_of_init()
780 &led->max_torch_intensity)) { in aw36518_of_init()
781 dev_err(&client->dev, in aw36518_of_init()
782 "get led%d led-max-microamp fail\n", id); in aw36518_of_init()
785 if (led->max_torch_intensity > AW36518_MAX_TORCH_INTENSITY) in aw36518_of_init()
786 led->max_torch_intensity = AW36518_MAX_TORCH_INTENSITY; in aw36518_of_init()
788 v4l2_dbg(1, debug, &led->sd, in aw36518_of_init()
790 id, led->max_torch_intensity, in aw36518_of_init()
791 led->max_flash_intensity, in aw36518_of_init()
792 led->max_flash_timeout); in aw36518_of_init()
797 return -EINVAL; in aw36518_of_init()
804 struct i2c_client *client = flash->client; in aw36518_init_device() local
807 flash->led_mode = V4L2_FLASH_LED_MODE_NONE; in aw36518_init_device()
813 dev_info(&client->dev, "%s: fault: 0x%x.\n", __func__, reg_val); in aw36518_init_device()
815 if (flash->tx_gpio) in aw36518_init_device()
816 gpiod_direction_output(flash->tx_gpio, 0); in aw36518_init_device()
818 if (flash->torch_gpio) in aw36518_init_device()
819 gpiod_set_value_cansleep(flash->torch_gpio, 0); in aw36518_init_device()
824 static int aw36518_probe(struct i2c_client *client, in aw36518_probe() argument
832 dev_info(&client->dev, "driver version: %02x.%02x.%02x", in aw36518_probe()
837 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); in aw36518_probe()
839 return -ENOMEM; in aw36518_probe()
841 flash->client = client; in aw36518_probe()
843 ret = aw36518_of_init(client, flash); in aw36518_probe()
852 sd = &flash->leds[i].sd; in aw36518_probe()
853 v4l2_i2c_subdev_init(sd, client, &aw36518_ops); in aw36518_probe()
854 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in aw36518_probe()
855 sd->internal_ops = &aw36518_internal_ops; in aw36518_probe()
858 if (strcmp(flash->module_facing, "back") == 0) in aw36518_probe()
866 snprintf(sd->name, sizeof(sd->name), in aw36518_probe()
868 flash->module_index, facing, in aw36518_probe()
869 AW36518_NAME, i, dev_name(sd->dev)); in aw36518_probe()
875 ret = media_entity_pads_init(&sd->entity, 0, NULL); in aw36518_probe()
879 sd->entity.function = MEDIA_ENT_F_FLASH; in aw36518_probe()
889 i2c_set_clientdata(client, flash); in aw36518_probe()
891 mutex_init(&flash->lock); in aw36518_probe()
893 pm_runtime_set_active(&client->dev); in aw36518_probe()
894 pm_runtime_enable(&client->dev); in aw36518_probe()
895 pm_runtime_idle(&client->dev); in aw36518_probe()
897 dev_info(&client->dev, "probing successful\n"); in aw36518_probe()
901 media_entity_cleanup(&flash->leds[i].sd.entity); in aw36518_probe()
903 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in aw36518_probe()
905 for (--i; i >= 0; --i) { in aw36518_probe()
906 v4l2_device_unregister_subdev(&flash->leds[i].sd); in aw36518_probe()
907 media_entity_cleanup(&flash->leds[i].sd.entity); in aw36518_probe()
908 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in aw36518_probe()
915 static int aw36518_remove(struct i2c_client *client) in aw36518_remove() argument
917 struct aw36518_flash *flash = i2c_get_clientdata(client); in aw36518_remove()
920 pm_runtime_disable(&client->dev); in aw36518_remove()
922 v4l2_device_unregister_subdev(&flash->leds[i].sd); in aw36518_remove()
923 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in aw36518_remove()
924 media_entity_cleanup(&flash->leds[i].sd.entity); in aw36518_remove()
926 mutex_destroy(&flash->lock); in aw36518_remove()
932 struct i2c_client *client = to_i2c_client(dev); in aw36518_runtime_suspend() local
933 struct aw36518_flash *flash = i2c_get_clientdata(client); in aw36518_runtime_suspend()
940 struct i2c_client *client = to_i2c_client(dev); in aw36518_runtime_resume() local
941 struct aw36518_flash *flash = i2c_get_clientdata(client); in aw36518_runtime_resume()