Lines Matching +full:client +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0
13 #include <linux/rk-camera-module.h>
14 #include <linux/rk-led-flash.h>
17 #include <media/v4l2-ctrls.h>
18 #include <media/v4l2-device.h>
57 MODULE_PARM_DESC(debug, "debug level (0-2)");
77 struct i2c_client *client; member
95 struct i2c_client *client = flash->client; in sgm3784_i2c_write() local
98 ret = i2c_smbus_write_byte_data(client, reg, val); in sgm3784_i2c_write()
100 dev_err(&client->dev, in sgm3784_i2c_write()
104 v4l2_dbg(2, debug, &flash->leds[0].sd, in sgm3784_i2c_write()
113 struct i2c_client *client = flash->client; in sgm3784_i2c_read() local
116 ret = i2c_smbus_read_byte_data(client, reg); in sgm3784_i2c_read()
118 dev_err(&client->dev, in sgm3784_i2c_read()
122 v4l2_dbg(2, debug, &flash->leds[0].sd, in sgm3784_i2c_read()
133 v4l2_dbg(1, debug, &flash->leds[0].sd, in sgm3784_led_on()
138 flash->leds[0].timestamp = ns_to_kernel_old_timeval(ktime_get_ns()); in sgm3784_led_on()
139 flash->leds[1].timestamp = flash->leds[0].timestamp; in sgm3784_led_on()
154 v4l2_info(&flash->leds[0].sd, in sgm3784_get_fault()
164 v4l2_dbg(1, debug, &flash->leds[0].sd, in sgm3784_set_timeout()
166 __func__, flash->flash_timeout); in sgm3784_set_timeout()
172 val = (flash->flash_timeout - TIMEOUT_MIN) / TIMEOUT_STEP; in sgm3784_set_timeout()
177 enum sgm3784_led_id id) in sgm3784_torch_brt() argument
179 struct sgm3784_led *led = &flash->leds[id]; in sgm3784_torch_brt()
182 v4l2_dbg(1, debug, &led->sd, in sgm3784_torch_brt()
183 "%s: %d\n", __func__, led->torch_brt->val); in sgm3784_torch_brt()
185 val = led->torch_brt->val / SGM3784_INTENSITY_STEP; in sgm3784_torch_brt()
186 reg = id ? SGM3784_REG_LED1_TORCH_CUR : SGM3784_REG_LED0_TORCH_CUR; in sgm3784_torch_brt()
191 enum sgm3784_led_id id) in sgm3784_flash_brt() argument
193 struct sgm3784_led *led = &flash->leds[id]; in sgm3784_flash_brt()
196 v4l2_dbg(1, debug, &led->sd, in sgm3784_flash_brt()
197 "%s: %d\n", __func__, led->flash_brt->val); in sgm3784_flash_brt()
199 val = led->flash_brt->val / SGM3784_INTENSITY_STEP; in sgm3784_flash_brt()
200 reg = id ? SGM3784_REG_LED1_FLASH_CUR : SGM3784_REG_LED0_FLASH_CUR; in sgm3784_flash_brt()
205 enum sgm3784_led_id id, unsigned int mode) in sgm3784_set_mode() argument
210 v4l2_dbg(1, debug, &flash->leds[id].sd, in sgm3784_set_mode()
212 mode, flash->cur_mode); in sgm3784_set_mode()
214 if (flash->cur_mode == mode) in sgm3784_set_mode()
219 flash->cur_mode = mode; in sgm3784_set_mode()
221 val = (flash->flash_timeout - TIMEOUT_MIN) / TIMEOUT_STEP; in sgm3784_set_mode()
223 if (flash->torch_gpio) in sgm3784_set_mode()
224 gpiod_direction_output(flash->torch_gpio, 0); in sgm3784_set_mode()
230 gpiod_direction_output(flash->strobe_gpio, 1); in sgm3784_set_mode()
232 gpiod_direction_output(flash->strobe_gpio, 0); in sgm3784_set_mode()
233 if (flash->torch_gpio) { in sgm3784_set_mode()
246 if (flash->torch_gpio) in sgm3784_set_mode()
247 gpiod_direction_output(flash->torch_gpio, 1); in sgm3784_set_mode()
250 gpiod_direction_output(flash->strobe_gpio, 0); in sgm3784_set_mode()
251 if (flash->torch_gpio) in sgm3784_set_mode()
252 gpiod_direction_output(flash->torch_gpio, 0); in sgm3784_set_mode()
260 v4l2_dbg(1, debug, &flash->leds[0].sd, in sgm3784_strobe()
263 if (flash->cur_mode != V4L2_FLASH_LED_MODE_FLASH) in sgm3784_strobe()
264 return -EBUSY; in sgm3784_strobe()
269 static int sgm3784_get_ctrl(struct v4l2_ctrl *ctrl, enum sgm3784_led_id id) in sgm3784_get_ctrl() argument
272 container_of(ctrl->handler, struct sgm3784_led, ctrls); in sgm3784_get_ctrl()
274 container_of(led, struct sgm3784_flash, leds[id]); in sgm3784_get_ctrl()
277 v4l2_dbg(1, debug, &led->sd, in sgm3784_get_ctrl()
278 "%s: id 0x%x\n", __func__, ctrl->id); in sgm3784_get_ctrl()
280 mutex_lock(&flash->lock); in sgm3784_get_ctrl()
281 switch (ctrl->id) { in sgm3784_get_ctrl()
284 ctrl->val = 0; in sgm3784_get_ctrl()
286 ctrl->val |= V4L2_FLASH_FAULT_SHORT_CIRCUIT; in sgm3784_get_ctrl()
288 ctrl->val |= V4L2_FLASH_FAULT_OVER_TEMPERATURE; in sgm3784_get_ctrl()
290 ctrl->val |= V4L2_FLASH_FAULT_TIMEOUT; in sgm3784_get_ctrl()
292 ctrl->val |= V4L2_FLASH_FAULT_OVER_VOLTAGE; in sgm3784_get_ctrl()
296 v4l2_err(&led->sd, in sgm3784_get_ctrl()
297 "ctrl 0x%x not supported\n", ctrl->id); in sgm3784_get_ctrl()
298 ret = -EINVAL; in sgm3784_get_ctrl()
302 mutex_unlock(&flash->lock); in sgm3784_get_ctrl()
306 static int sgm3784_set_ctrl(struct v4l2_ctrl *ctrl, enum sgm3784_led_id id) in sgm3784_set_ctrl() argument
309 container_of(ctrl->handler, struct sgm3784_led, ctrls); in sgm3784_set_ctrl()
311 container_of(led, struct sgm3784_flash, leds[id]); in sgm3784_set_ctrl()
314 v4l2_dbg(1, debug, &led->sd, in sgm3784_set_ctrl()
315 "%s: id 0x%x val 0x%x\n", in sgm3784_set_ctrl()
316 __func__, ctrl->id, ctrl->val); in sgm3784_set_ctrl()
318 mutex_lock(&flash->lock); in sgm3784_set_ctrl()
326 (ctrl->id == V4L2_CID_FLASH_STROBE || in sgm3784_set_ctrl()
327 ctrl->id == V4L2_CID_FLASH_TORCH_INTENSITY || in sgm3784_set_ctrl()
328 ctrl->id == V4L2_CID_FLASH_LED_MODE)) { in sgm3784_set_ctrl()
329 ret = -EBUSY; in sgm3784_set_ctrl()
333 switch (ctrl->id) { in sgm3784_set_ctrl()
335 ret = sgm3784_set_mode(flash, id, ctrl->val); in sgm3784_set_ctrl()
347 ret = sgm3784_flash_brt(flash, id); in sgm3784_set_ctrl()
350 ret = sgm3784_torch_brt(flash, id); in sgm3784_set_ctrl()
353 v4l2_err(&led->sd, in sgm3784_set_ctrl()
354 "ctrl 0x%x not supported\n", ctrl->id); in sgm3784_set_ctrl()
355 ret = -EINVAL; in sgm3784_set_ctrl()
360 mutex_unlock(&flash->lock); in sgm3784_set_ctrl()
396 enum sgm3784_led_id id) in sgm3784_init_controls() argument
399 struct v4l2_ctrl_handler *hdl = &flash->leds[id].ctrls; in sgm3784_init_controls()
400 const struct v4l2_ctrl_ops *ops = &sgm3784_ctrl_ops[id]; in sgm3784_init_controls()
401 struct sgm3784_led *led = &flash->leds[id]; in sgm3784_init_controls()
408 flash->cur_mode = V4L2_FLASH_LED_MODE_NONE; in sgm3784_init_controls()
422 led->max_flash_timeout, in sgm3784_init_controls()
424 led->max_flash_timeout); in sgm3784_init_controls()
425 flash->flash_timeout = led->max_flash_timeout; in sgm3784_init_controls()
427 flash->leds[id].flash_brt = in sgm3784_init_controls()
431 led->max_flash_intensity, in sgm3784_init_controls()
435 flash->leds[id].torch_brt = in sgm3784_init_controls()
439 led->max_torch_intensity, in sgm3784_init_controls()
450 if (hdl->error) in sgm3784_init_controls()
451 return hdl->error; in sgm3784_init_controls()
453 fault->flags |= V4L2_CTRL_FLAG_VOLATILE; in sgm3784_init_controls()
455 flash->leds[id].sd.ctrl_handler = hdl; in sgm3784_init_controls()
466 ti->tv_sec = led->timestamp.tv_sec; in sgm3784_get_time_info()
467 ti->tv_usec = led->timestamp.tv_usec; in sgm3784_get_time_info()
469 "%s: tv_sec:%ld, tv_usec:%ld\n", __func__, ti->tv_sec, ti->tv_usec); in sgm3784_get_time_info()
483 ret = -ENOIOCTLCMD; in sgm3784_ioctl()
509 ret = -ENOMEM; in sgm3784_compat_ioctl32()
514 compat_t->tv_sec = t.tv_sec; in sgm3784_compat_ioctl32()
515 compat_t->tv_usec = t.tv_usec; in sgm3784_compat_ioctl32()
518 ret = -EFAULT; in sgm3784_compat_ioctl32()
524 ret = -ENOIOCTLCMD; in sgm3784_compat_ioctl32()
537 rval = pm_runtime_get_sync(sd->dev); in sgm3784_open()
539 pm_runtime_put_noidle(sd->dev); in sgm3784_open()
548 pm_runtime_put(sd->dev); in sgm3784_close()
571 gpiod_direction_output(flash->en_gpio, on); in __sgm3784_set_power()
584 dev_err(&flash->client->dev, in sgm3784_check_id()
585 "Read chip id error\n"); in sgm3784_check_id()
586 return -ENODEV; in sgm3784_check_id()
589 dev_info(&flash->client->dev, in sgm3784_check_id()
590 "Detected sgm3784 flash id:0x%x\n", ret); in sgm3784_check_id()
594 static int sgm3784_of_init(struct i2c_client *client, in sgm3784_of_init() argument
597 struct device_node *node = client->dev.of_node; in sgm3784_of_init()
603 dev_err(&client->dev, in sgm3784_of_init()
610 &flash->module_index); in sgm3784_of_init()
613 &flash->module_facing); in sgm3784_of_init()
615 dev_err(&client->dev, in sgm3784_of_init()
620 flash->en_gpio = devm_gpiod_get(&client->dev, in sgm3784_of_init()
622 if (IS_ERR(flash->en_gpio)) { in sgm3784_of_init()
623 dev_err(&client->dev, "get enable-gpio failed\n"); in sgm3784_of_init()
627 flash->torch_gpio = devm_gpiod_get(&client->dev, in sgm3784_of_init()
629 if (IS_ERR(flash->torch_gpio)) { in sgm3784_of_init()
630 flash->torch_gpio = NULL; in sgm3784_of_init()
631 dev_warn(&client->dev, in sgm3784_of_init()
632 "get torch-gpio failed, using assist light mode\n"); in sgm3784_of_init()
635 flash->strobe_gpio = devm_gpiod_get(&client->dev, in sgm3784_of_init()
637 if (IS_ERR(flash->en_gpio)) { in sgm3784_of_init()
638 dev_err(&client->dev, "get strobe-gpio failed\n"); in sgm3784_of_init()
643 u32 id = 0; in sgm3784_of_init() local
645 of_property_read_u32(child, "reg", &id); in sgm3784_of_init()
646 if (id >= LED_MAX) { in sgm3784_of_init()
647 dev_err(&client->dev, "only support 2 leds\n"); in sgm3784_of_init()
650 led = &flash->leds[id]; in sgm3784_of_init()
651 led->sd.fwnode = of_fwnode_handle(child); in sgm3784_of_init()
652 if (of_property_read_u32(child, "flash-max-timeout-us", in sgm3784_of_init()
653 &led->max_flash_timeout)) { in sgm3784_of_init()
654 dev_err(&client->dev, in sgm3784_of_init()
655 "get led%d flash-max-timeout-us fail\n", id); in sgm3784_of_init()
658 if (led->max_flash_timeout > TIMEOUT_MAX) in sgm3784_of_init()
659 led->max_flash_timeout = TIMEOUT_MAX; in sgm3784_of_init()
661 if (of_property_read_u32(child, "flash-max-microamp", in sgm3784_of_init()
662 &led->max_flash_intensity)) { in sgm3784_of_init()
663 dev_err(&client->dev, in sgm3784_of_init()
664 "get led%d flash-max-microamp fail\n", id); in sgm3784_of_init()
667 if (led->max_flash_intensity > SGM3784_MAX_FLASH_INTENSITY) in sgm3784_of_init()
668 led->max_flash_intensity = SGM3784_MAX_FLASH_INTENSITY; in sgm3784_of_init()
670 if (of_property_read_u32(child, "led-max-microamp", in sgm3784_of_init()
671 &led->max_torch_intensity)) { in sgm3784_of_init()
672 dev_err(&client->dev, in sgm3784_of_init()
673 "get led%d led-max-microamp fail\n", id); in sgm3784_of_init()
676 if (led->max_torch_intensity > SGM3784_MAX_TORCH_INTENSITY) in sgm3784_of_init()
677 led->max_torch_intensity = SGM3784_MAX_TORCH_INTENSITY; in sgm3784_of_init()
679 dev_info(&client->dev, in sgm3784_of_init()
681 id, led->max_torch_intensity, in sgm3784_of_init()
682 led->max_flash_intensity, in sgm3784_of_init()
683 led->max_flash_timeout); in sgm3784_of_init()
688 return -EINVAL; in sgm3784_of_init()
691 static int sgm3784_probe(struct i2c_client *client, in sgm3784_probe() argument
699 dev_info(&client->dev, "driver version: %02x.%02x.%02x", in sgm3784_probe()
704 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); in sgm3784_probe()
706 return -ENOMEM; in sgm3784_probe()
708 flash->client = client; in sgm3784_probe()
710 ret = sgm3784_of_init(client, flash); in sgm3784_probe()
719 sd = &flash->leds[i].sd; in sgm3784_probe()
720 v4l2_i2c_subdev_init(sd, client, &sgm3784_ops); in sgm3784_probe()
721 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in sgm3784_probe()
722 sd->internal_ops = &sgm3784_internal_ops; in sgm3784_probe()
725 if (strcmp(flash->module_facing, "back") == 0) in sgm3784_probe()
733 snprintf(sd->name, sizeof(sd->name), in sgm3784_probe()
735 flash->module_index, facing, in sgm3784_probe()
736 SGM3784_NAME, i, dev_name(sd->dev)); in sgm3784_probe()
742 ret = media_entity_pads_init(&sd->entity, 0, NULL); in sgm3784_probe()
746 sd->entity.function = MEDIA_ENT_F_FLASH; in sgm3784_probe()
752 i2c_set_clientdata(client, flash); in sgm3784_probe()
754 mutex_init(&flash->lock); in sgm3784_probe()
756 pm_runtime_set_active(&client->dev); in sgm3784_probe()
757 pm_runtime_enable(&client->dev); in sgm3784_probe()
758 pm_runtime_idle(&client->dev); in sgm3784_probe()
760 dev_info(&client->dev, "probing successful\n"); in sgm3784_probe()
764 media_entity_cleanup(&flash->leds[i].sd.entity); in sgm3784_probe()
766 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in sgm3784_probe()
768 for (--i; i >= 0; --i) { in sgm3784_probe()
769 v4l2_device_unregister_subdev(&flash->leds[i].sd); in sgm3784_probe()
770 media_entity_cleanup(&flash->leds[i].sd.entity); in sgm3784_probe()
771 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in sgm3784_probe()
776 static int sgm3784_remove(struct i2c_client *client) in sgm3784_remove() argument
778 struct sgm3784_flash *flash = i2c_get_clientdata(client); in sgm3784_remove()
781 pm_runtime_disable(&client->dev); in sgm3784_remove()
783 v4l2_device_unregister_subdev(&flash->leds[i].sd); in sgm3784_remove()
784 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in sgm3784_remove()
785 media_entity_cleanup(&flash->leds[i].sd.entity); in sgm3784_remove()
787 mutex_destroy(&flash->lock); in sgm3784_remove()
793 struct i2c_client *client = to_i2c_client(dev); in sgm3784_runtime_suspend() local
794 struct sgm3784_flash *flash = i2c_get_clientdata(client); in sgm3784_runtime_suspend()
801 struct i2c_client *client = to_i2c_client(dev); in sgm3784_runtime_resume() local
802 struct sgm3784_flash *flash = i2c_get_clientdata(client); in sgm3784_runtime_resume()