Lines Matching full:coil
4 * AD5820 DAC driver for camera voice coil focus.
64 static int ad5820_write(struct ad5820_device *coil, u16 data) in ad5820_write() argument
66 struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); in ad5820_write()
94 static int ad5820_update_hw(struct ad5820_device *coil) in ad5820_update_hw() argument
98 status = RAMP_US_TO_CODE(coil->focus_ramp_time); in ad5820_update_hw()
99 status |= coil->focus_ramp_mode in ad5820_update_hw()
101 status |= coil->focus_absolute << AD5820_DAC_SHIFT; in ad5820_update_hw()
103 if (coil->standby) in ad5820_update_hw()
106 return ad5820_write(coil, status); in ad5820_update_hw()
112 static int ad5820_power_off(struct ad5820_device *coil, bool standby) in ad5820_power_off() argument
118 * (single power line control for both coil and sensor). in ad5820_power_off()
121 coil->standby = true; in ad5820_power_off()
122 ret = ad5820_update_hw(coil); in ad5820_power_off()
125 ret2 = regulator_disable(coil->vana); in ad5820_power_off()
131 static int ad5820_power_on(struct ad5820_device *coil, bool restore) in ad5820_power_on() argument
135 ret = regulator_enable(coil->vana); in ad5820_power_on()
141 coil->standby = false; in ad5820_power_on()
142 ret = ad5820_update_hw(coil); in ad5820_power_on()
149 coil->standby = true; in ad5820_power_on()
150 regulator_disable(coil->vana); in ad5820_power_on()
160 struct ad5820_device *coil = in ad5820_set_ctrl() local
165 coil->focus_absolute = ctrl->val; in ad5820_set_ctrl()
166 return ad5820_update_hw(coil); in ad5820_set_ctrl()
177 static int ad5820_init_controls(struct ad5820_device *coil) in ad5820_init_controls() argument
179 v4l2_ctrl_handler_init(&coil->ctrls, 1); in ad5820_init_controls()
193 v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, in ad5820_init_controls()
196 if (coil->ctrls.error) in ad5820_init_controls()
197 return coil->ctrls.error; in ad5820_init_controls()
199 coil->focus_absolute = 0; in ad5820_init_controls()
200 coil->focus_ramp_time = 0; in ad5820_init_controls()
201 coil->focus_ramp_mode = 0; in ad5820_init_controls()
203 coil->subdev.ctrl_handler = &coil->ctrls; in ad5820_init_controls()
213 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_registered() local
215 return ad5820_init_controls(coil); in ad5820_registered()
221 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_set_power() local
224 mutex_lock(&coil->power_lock); in ad5820_set_power()
230 if (coil->power_count == !on) { in ad5820_set_power()
231 ret = on ? ad5820_power_on(coil, true) : in ad5820_set_power()
232 ad5820_power_off(coil, true); in ad5820_set_power()
238 coil->power_count += on ? 1 : -1; in ad5820_set_power()
239 WARN_ON(coil->power_count < 0); in ad5820_set_power()
242 mutex_unlock(&coil->power_lock); in ad5820_set_power()
277 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_suspend() local
279 if (!coil->power_count) in ad5820_suspend()
282 return ad5820_power_off(coil, false); in ad5820_suspend()
289 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_resume() local
291 if (!coil->power_count) in ad5820_resume()
294 return ad5820_power_on(coil, true); in ad5820_resume()
300 struct ad5820_device *coil; in ad5820_probe() local
303 coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); in ad5820_probe()
304 if (!coil) in ad5820_probe()
307 coil->vana = devm_regulator_get(&client->dev, "VANA"); in ad5820_probe()
308 if (IS_ERR(coil->vana)) { in ad5820_probe()
309 ret = PTR_ERR(coil->vana); in ad5820_probe()
315 mutex_init(&coil->power_lock); in ad5820_probe()
317 v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); in ad5820_probe()
318 coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ad5820_probe()
319 coil->subdev.internal_ops = &ad5820_internal_ops; in ad5820_probe()
320 strcpy(coil->subdev.name, "ad5820 focus"); in ad5820_probe()
322 ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); in ad5820_probe()
326 ret = v4l2_async_register_subdev(&coil->subdev); in ad5820_probe()
333 mutex_destroy(&coil->power_lock); in ad5820_probe()
335 media_entity_cleanup(&coil->subdev.entity); in ad5820_probe()
342 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_remove() local
344 v4l2_async_unregister_subdev(&coil->subdev); in ad5820_remove()
345 v4l2_ctrl_handler_free(&coil->ctrls); in ad5820_remove()
346 media_entity_cleanup(&coil->subdev.entity); in ad5820_remove()
347 mutex_destroy(&coil->power_lock); in ad5820_remove()