Lines Matching +full:lens +full:- +full:focus
1 // SPDX-License-Identifier: GPL-2.0-only
5 * AD5820 DAC driver for camera voice coil focus.
24 #include <media/v4l2-ctrls.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-subdev.h>
34 #define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50)
59 struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); in ad5820_write()
64 if (!client->adapter) in ad5820_write()
65 return -ENODEV; in ad5820_write()
68 msg.addr = client->addr; in ad5820_write()
73 r = i2c_transfer(client->adapter, &msg, 1); in ad5820_write()
75 dev_err(&client->dev, "write failed, error %d\n", r); in ad5820_write()
91 status = RAMP_US_TO_CODE(coil->focus_ramp_time); in ad5820_update_hw()
92 status |= coil->focus_ramp_mode in ad5820_update_hw()
94 status |= coil->focus_absolute << AD5820_DAC_SHIFT; in ad5820_update_hw()
96 if (coil->standby) in ad5820_update_hw()
114 coil->standby = true; in ad5820_power_off()
118 gpiod_set_value_cansleep(coil->enable_gpio, 0); in ad5820_power_off()
120 ret2 = regulator_disable(coil->vana); in ad5820_power_off()
130 ret = regulator_enable(coil->vana); in ad5820_power_on()
134 gpiod_set_value_cansleep(coil->enable_gpio, 1); in ad5820_power_on()
138 coil->standby = false; in ad5820_power_on()
146 gpiod_set_value_cansleep(coil->enable_gpio, 0); in ad5820_power_on()
147 coil->standby = true; in ad5820_power_on()
148 regulator_disable(coil->vana); in ad5820_power_on()
159 container_of(ctrl->handler, struct ad5820_device, ctrls); in ad5820_set_ctrl()
161 switch (ctrl->id) { in ad5820_set_ctrl()
163 coil->focus_absolute = ctrl->val; in ad5820_set_ctrl()
177 v4l2_ctrl_handler_init(&coil->ctrls, 1); in ad5820_init_controls()
184 * for focus position, because it is meaningless for user. Meaningful in ad5820_init_controls()
185 * would be to use focus distance or even its inverse, but since the in ad5820_init_controls()
187 * will just use abstract codes here. In any case, smaller value = focus in ad5820_init_controls()
188 * position farther from camera. The default zero value means focus at in ad5820_init_controls()
191 v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, in ad5820_init_controls()
194 if (coil->ctrls.error) in ad5820_init_controls()
195 return coil->ctrls.error; in ad5820_init_controls()
197 coil->focus_absolute = 0; in ad5820_init_controls()
198 coil->focus_ramp_time = 0; in ad5820_init_controls()
199 coil->focus_ramp_mode = 0; in ad5820_init_controls()
201 coil->subdev.ctrl_handler = &coil->ctrls; in ad5820_init_controls()
222 mutex_lock(&coil->power_lock); in ad5820_set_power()
228 if (coil->power_count == !on) { in ad5820_set_power()
236 coil->power_count += on ? 1 : -1; in ad5820_set_power()
237 WARN_ON(coil->power_count < 0); in ad5820_set_power()
240 mutex_unlock(&coil->power_lock); in ad5820_set_power()
277 if (!coil->power_count) in ad5820_suspend()
289 if (!coil->power_count) in ad5820_resume()
301 coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); in ad5820_probe()
303 return -ENOMEM; in ad5820_probe()
305 coil->vana = devm_regulator_get(&client->dev, "VANA"); in ad5820_probe()
306 if (IS_ERR(coil->vana)) { in ad5820_probe()
307 ret = PTR_ERR(coil->vana); in ad5820_probe()
308 if (ret != -EPROBE_DEFER) in ad5820_probe()
309 dev_err(&client->dev, "could not get regulator for vana\n"); in ad5820_probe()
313 coil->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable", in ad5820_probe()
315 if (IS_ERR(coil->enable_gpio)) { in ad5820_probe()
316 ret = PTR_ERR(coil->enable_gpio); in ad5820_probe()
317 if (ret != -EPROBE_DEFER) in ad5820_probe()
318 dev_err(&client->dev, "could not get enable gpio\n"); in ad5820_probe()
322 mutex_init(&coil->power_lock); in ad5820_probe()
324 v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); in ad5820_probe()
325 coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ad5820_probe()
326 coil->subdev.internal_ops = &ad5820_internal_ops; in ad5820_probe()
327 coil->subdev.entity.function = MEDIA_ENT_F_LENS; in ad5820_probe()
328 strscpy(coil->subdev.name, "ad5820 focus", sizeof(coil->subdev.name)); in ad5820_probe()
330 ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); in ad5820_probe()
334 ret = v4l2_async_register_subdev(&coil->subdev); in ad5820_probe()
341 media_entity_cleanup(&coil->subdev.entity); in ad5820_probe()
343 mutex_destroy(&coil->power_lock); in ad5820_probe()
352 v4l2_async_unregister_subdev(&coil->subdev); in ad5820_remove()
353 v4l2_ctrl_handler_free(&coil->ctrls); in ad5820_remove()
354 media_entity_cleanup(&coil->subdev.entity); in ad5820_remove()
355 mutex_destroy(&coil->power_lock); in ad5820_remove()
389 MODULE_DESCRIPTION("AD5820 camera lens driver");