Lines Matching +full:regulator +full:- +full:state +full:- +full:standby
1 // SPDX-License-Identifier: GPL-2.0-only
21 #include <linux/regulator/consumer.h>
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)
42 struct regulator *vana;
54 bool standby; member
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()
105 static int ad5820_power_off(struct ad5820_device *coil, bool standby) in ad5820_power_off() argument
110 * Go to standby first as real power off my be denied by the hardware in ad5820_power_off()
113 if (standby) { in ad5820_power_off()
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()
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()
226 * update the power state. 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()
276 if (!coil->power_count) in ad5820_suspend()
287 if (!coil->power_count) in ad5820_resume()
298 coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); in ad5820_probe()
300 return -ENOMEM; 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()
305 "could not get regulator for vana\n"); 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()
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()