Lines Matching refs:coil
56 static int ad5820_write(struct ad5820_device *coil, u16 data) in ad5820_write() argument
58 struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); in ad5820_write()
86 static int ad5820_update_hw(struct ad5820_device *coil) in ad5820_update_hw() argument
90 status = RAMP_US_TO_CODE(coil->focus_ramp_time); in ad5820_update_hw()
91 status |= coil->focus_ramp_mode in ad5820_update_hw()
93 status |= coil->focus_absolute << AD5820_DAC_SHIFT; in ad5820_update_hw()
95 if (coil->standby) in ad5820_update_hw()
98 return ad5820_write(coil, status); in ad5820_update_hw()
104 static int ad5820_power_off(struct ad5820_device *coil, bool standby) in ad5820_power_off() argument
113 coil->standby = true; in ad5820_power_off()
114 ret = ad5820_update_hw(coil); in ad5820_power_off()
117 ret2 = regulator_disable(coil->vana); in ad5820_power_off()
123 static int ad5820_power_on(struct ad5820_device *coil, bool restore) in ad5820_power_on() argument
127 ret = regulator_enable(coil->vana); in ad5820_power_on()
133 coil->standby = false; in ad5820_power_on()
134 ret = ad5820_update_hw(coil); in ad5820_power_on()
141 coil->standby = true; in ad5820_power_on()
142 regulator_disable(coil->vana); in ad5820_power_on()
152 struct ad5820_device *coil = in ad5820_set_ctrl() local
157 coil->focus_absolute = ctrl->val; in ad5820_set_ctrl()
158 return ad5820_update_hw(coil); in ad5820_set_ctrl()
169 static int ad5820_init_controls(struct ad5820_device *coil) in ad5820_init_controls() argument
171 v4l2_ctrl_handler_init(&coil->ctrls, 1); in ad5820_init_controls()
185 v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, in ad5820_init_controls()
188 if (coil->ctrls.error) in ad5820_init_controls()
189 return coil->ctrls.error; in ad5820_init_controls()
191 coil->focus_absolute = 0; in ad5820_init_controls()
192 coil->focus_ramp_time = 0; in ad5820_init_controls()
193 coil->focus_ramp_mode = 0; in ad5820_init_controls()
195 coil->subdev.ctrl_handler = &coil->ctrls; in ad5820_init_controls()
205 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_registered() local
207 return ad5820_init_controls(coil); in ad5820_registered()
213 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_set_power() local
216 mutex_lock(&coil->power_lock); in ad5820_set_power()
222 if (coil->power_count == !on) { in ad5820_set_power()
223 ret = on ? ad5820_power_on(coil, true) : in ad5820_set_power()
224 ad5820_power_off(coil, true); in ad5820_set_power()
230 coil->power_count += on ? 1 : -1; in ad5820_set_power()
231 WARN_ON(coil->power_count < 0); in ad5820_set_power()
234 mutex_unlock(&coil->power_lock); in ad5820_set_power()
269 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_suspend() local
271 if (!coil->power_count) in ad5820_suspend()
274 return ad5820_power_off(coil, false); in ad5820_suspend()
281 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_resume() local
283 if (!coil->power_count) in ad5820_resume()
286 return ad5820_power_on(coil, true); in ad5820_resume()
292 struct ad5820_device *coil; in ad5820_probe() local
295 coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); in ad5820_probe()
296 if (!coil) in ad5820_probe()
299 coil->vana = devm_regulator_get(&client->dev, "VANA"); in ad5820_probe()
300 if (IS_ERR(coil->vana)) { in ad5820_probe()
301 ret = PTR_ERR(coil->vana); in ad5820_probe()
307 mutex_init(&coil->power_lock); in ad5820_probe()
309 v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); in ad5820_probe()
310 coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ad5820_probe()
311 coil->subdev.internal_ops = &ad5820_internal_ops; in ad5820_probe()
312 strscpy(coil->subdev.name, "ad5820 focus", sizeof(coil->subdev.name)); in ad5820_probe()
314 ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); in ad5820_probe()
318 ret = v4l2_async_register_subdev(&coil->subdev); in ad5820_probe()
325 mutex_destroy(&coil->power_lock); in ad5820_probe()
327 media_entity_cleanup(&coil->subdev.entity); in ad5820_probe()
334 struct ad5820_device *coil = to_ad5820_device(subdev); in ad5820_remove() local
336 v4l2_async_unregister_subdev(&coil->subdev); in ad5820_remove()
337 v4l2_ctrl_handler_free(&coil->ctrls); in ad5820_remove()
338 media_entity_cleanup(&coil->subdev.entity); in ad5820_remove()
339 mutex_destroy(&coil->power_lock); in ad5820_remove()