Lines Matching refs:coil
57 static int ad5820_write(struct ad5820_device *coil, u16 data) in ad5820_write() argument
59 struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); in ad5820_write()
87 static int ad5820_update_hw(struct ad5820_device *coil) in ad5820_update_hw() argument
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()
99 return ad5820_write(coil, status); in ad5820_update_hw()
105 static int ad5820_power_off(struct ad5820_device *coil, bool standby) in ad5820_power_off() argument
114 coil->standby = true; in ad5820_power_off()
115 ret = ad5820_update_hw(coil); 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()
126 static int ad5820_power_on(struct ad5820_device *coil, bool restore) in ad5820_power_on() argument
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()
139 ret = ad5820_update_hw(coil); 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()
158 struct ad5820_device *coil = in ad5820_set_ctrl() local
163 coil->focus_absolute = ctrl->val; in ad5820_set_ctrl()
164 return ad5820_update_hw(coil); in ad5820_set_ctrl()
175 static int ad5820_init_controls(struct ad5820_device *coil) in ad5820_init_controls() argument
177 v4l2_ctrl_handler_init(&coil->ctrls, 1); 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()
211 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_registered() local
213 return ad5820_init_controls(coil); in ad5820_registered()
219 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_set_power() local
222 mutex_lock(&coil->power_lock); in ad5820_set_power()
228 if (coil->power_count == !on) { in ad5820_set_power()
229 ret = on ? ad5820_power_on(coil, true) : in ad5820_set_power()
230 ad5820_power_off(coil, true); 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()
274 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_suspend() local
276 if (!coil->power_count) in ad5820_suspend()
279 return ad5820_power_off(coil, false); in ad5820_suspend()
285 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_resume() local
287 if (!coil->power_count) in ad5820_resume()
290 return ad5820_power_on(coil, true); in ad5820_resume()
295 struct ad5820_device *coil; in ad5820_probe() local
298 coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); in ad5820_probe()
299 if (!coil) in ad5820_probe()
302 coil->vana = devm_regulator_get(&client->dev, "VANA"); in ad5820_probe()
303 if (IS_ERR(coil->vana)) in ad5820_probe()
304 return dev_err_probe(&client->dev, PTR_ERR(coil->vana), in ad5820_probe()
307 coil->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable", in ad5820_probe()
309 if (IS_ERR(coil->enable_gpio)) in ad5820_probe()
310 return dev_err_probe(&client->dev, PTR_ERR(coil->enable_gpio), in ad5820_probe()
313 mutex_init(&coil->power_lock); in ad5820_probe()
315 v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); in ad5820_probe()
316 coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ad5820_probe()
317 coil->subdev.internal_ops = &ad5820_internal_ops; in ad5820_probe()
318 coil->subdev.entity.function = MEDIA_ENT_F_LENS; in ad5820_probe()
319 strscpy(coil->subdev.name, "ad5820 focus", sizeof(coil->subdev.name)); in ad5820_probe()
321 ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); in ad5820_probe()
325 ret = v4l2_async_register_subdev(&coil->subdev); in ad5820_probe()
332 media_entity_cleanup(&coil->subdev.entity); in ad5820_probe()
334 mutex_destroy(&coil->power_lock); in ad5820_probe()
341 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_remove() local
343 v4l2_async_unregister_subdev(&coil->subdev); in ad5820_remove()
344 v4l2_ctrl_handler_free(&coil->ctrls); in ad5820_remove()
345 media_entity_cleanup(&coil->subdev.entity); in ad5820_remove()
346 mutex_destroy(&coil->power_lock); in ad5820_remove()