* [PATCH] support for AD5820 camera auto-focus coil @ 2016-05-17 18:19 Pavel Machek 2016-05-17 18:33 ` Marcus Folkesson 2016-05-21 5:43 ` [PATCHv2] " Pavel Machek 0 siblings, 2 replies; 73+ messages in thread From: Pavel Machek @ 2016-05-17 18:19 UTC (permalink / raw) To: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, ivo.g.dimitrov.75, patrikbachan, serge, linux-media, mchehab, sakari.ailus This adds support for AD5820 autofocus coil, found for example in Nokia N900 smartphone. Signed-off-by: Pavel Machek <pavel@ucw.cz> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 993dc50..77313a1 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 To compile this driver as a module, choose M here: the module will be called ml86v7667. +config VIDEO_AD5820 + tristate "AD5820 lens voice coil support" + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + ---help--- + This is a driver for the AD5820 camera lens voice coil. + It is used for example in Nokia N900 (RX-51). + config VIDEO_SAA7110 tristate "Philips SAA7110 video decoder" depends on VIDEO_V4L2 && I2C diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 94f2c99..34434ae 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c new file mode 100644 index 0000000..b71cc11 --- /dev/null +++ b/drivers/media/i2c/ad5820.c @@ -0,0 +1,435 @@ +/* + * drivers/media/i2c/ad5820.c + * + * AD5820 DAC driver for camera voice coil focus. + * + * Copyright (C) 2008 Nokia Corporation + * Copyright (C) 2007 Texas Instruments + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> + * + * Contact: Tuukka Toivonen + * Sakari Ailus + * + * Based on af_d88.c by Texas Instruments. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/i2c.h> +#include <linux/slab.h> +#include <linux/sched.h> +#include <linux/delay.h> +#include <linux/bitops.h> +#include <linux/kernel.h> +#include <linux/regulator/consumer.h> + +#include <media/ad5820.h> +#include <media/v4l2-device.h> + +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) + +/** + * @brief I2C write using i2c_transfer(). + * @param coil - the driver data structure + * @param data - register value to be written + * @returns nonnegative on success, negative if failed + */ +static int ad5820_write(struct ad5820_device *coil, u16 data) +{ + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); + struct i2c_msg msg; + int r; + + if (!client->adapter) + return -ENODEV; + + data = cpu_to_be16(data); + msg.addr = client->addr; + msg.flags = 0; + msg.len = 2; + msg.buf = (u8 *)&data; + + r = i2c_transfer(client->adapter, &msg, 1); + if (r < 0) { + dev_err(&client->dev, "write failed, error %d\n", r); + return r; + } + + return 0; +} + +/* + * Calculate status word and write it to the device based on current + * values of V4L2 controls. It is assumed that the stored V4L2 control + * values are properly limited and rounded. + */ +static int ad5820_update_hw(struct ad5820_device *coil) +{ + u16 status; + + status = RAMP_US_TO_CODE(coil->focus_ramp_time); + status |= coil->focus_ramp_mode + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; + status |= coil->focus_absolute << AD5820_DAC_SHIFT; + + if (coil->standby) + status |= AD5820_POWER_DOWN; + + return ad5820_write(coil, status); +} + +/* + * Power handling + */ +static int ad5820_power_off(struct ad5820_device *coil, int standby) +{ + int ret = 0; + + /* + * Go to standby first as real power off my be denied by the hardware + * (single power line control for both coil and sensor). + */ + if (standby) { + coil->standby = 1; + ret = ad5820_update_hw(coil); + } + + ret |= regulator_disable(coil->vana); + + return ret; +} + +static int ad5820_power_on(struct ad5820_device *coil, int restore) +{ + int ret; + + printk("ad5820_power_on: 1\n"); + ret = regulator_enable(coil->vana); + if (ret < 0) + return ret; + + if (restore) { + /* Restore the hardware settings. */ + coil->standby = 0; + ret = ad5820_update_hw(coil); + if (ret) + goto fail; + } + return 0; + +fail: + coil->standby = 1; + regulator_disable(coil->vana); + + return ret; +} + +/* + * V4L2 controls + */ +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ad5820_device *coil = + container_of(ctrl->handler, struct ad5820_device, ctrls); + u32 code; + int r = 0; + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + coil->focus_absolute = ctrl->val; + return ad5820_update_hw(coil); + + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: + code = RAMP_US_TO_CODE(ctrl->val); + ctrl->val = CODE_TO_RAMP_US(code); + coil->focus_ramp_time = ctrl->val; + break; + + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: + coil->focus_ramp_mode = ctrl->val; + break; + } + + return r; +} + +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { + .s_ctrl = ad5820_set_ctrl, +}; + +static const char *ad5820_focus_menu[] = { + "Linear ramp", + "64/16 ramp", +}; + +static const struct v4l2_ctrl_config ad5820_ctrls[] = { + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Focus ramping time [us]", + .min = 0, + .max = 3200, + .step = 50, + .def = 0, + .flags = 0, + }, + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, + .type = V4L2_CTRL_TYPE_MENU, + .name = "Focus ramping mode", + .min = 0, + .max = ARRAY_SIZE(ad5820_focus_menu), + .step = 0, + .def = 0, + .flags = 0, + .qmenu = ad5820_focus_menu, + }, +}; + + +static int ad5820_init_controls(struct ad5820_device *coil) +{ + unsigned int i; + + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); + + /* + * V4L2_CID_FOCUS_ABSOLUTE + * + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] + * for focus position, because it is meaningless for user. Meaningful + * would be to use focus distance or even its inverse, but since the + * driver doesn't have sufficiently knowledge to do the conversion, we + * will just use abstract codes here. In any case, smaller value = focus + * position farther from camera. The default zero value means focus at + * infinity, and also least current consumption. + */ + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); + + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); + + if (coil->ctrls.error) + return coil->ctrls.error; + + coil->focus_absolute = 0; + coil->focus_ramp_time = 0; + coil->focus_ramp_mode = 0; + + coil->subdev.ctrl_handler = &coil->ctrls; + return 0; +} + +/* + * V4L2 subdev operations + */ +static int ad5820_registered(struct v4l2_subdev *subdev) +{ + static const int CHECK_VALUE = 0x3FF0; + + struct ad5820_device *coil = to_ad5820_device(subdev); + struct i2c_client *client = v4l2_get_subdevdata(subdev); + + coil->vana = regulator_get(&client->dev, "VANA"); + if (IS_ERR(coil->vana)) { + dev_err(&client->dev, "could not get regulator for vana\n"); + return -ENODEV; + } + + return ad5820_init_controls(coil); +} + +static int +ad5820_set_power(struct v4l2_subdev *subdev, int on) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + int ret = 0; + + mutex_lock(&coil->power_lock); + + /* + * If the power count is modified from 0 to != 0 or from != 0 to 0, + * update the power state. + */ + if (coil->power_count == !on) { + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); + if (ret < 0) + goto done; + } + + /* Update the power count. */ + coil->power_count += on ? 1 : -1; + WARN_ON(coil->power_count < 0); + +done: + mutex_unlock(&coil->power_lock); + return ret; +} + +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 1); +} + +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 0); +} + +static const struct v4l2_subdev_core_ops ad5820_core_ops = { + .s_power = ad5820_set_power, +}; + +static const struct v4l2_subdev_ops ad5820_ops = { + .core = &ad5820_core_ops, +}; + +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { + .registered = ad5820_registered, + .open = ad5820_open, + .close = ad5820_close, +}; + +/* + * I2C driver + */ +#ifdef CONFIG_PM + +static int ad5820_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_off(coil, 0); +} + +static int ad5820_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_on(coil, 1); +} + +#else + +#define ad5820_suspend NULL +#define ad5820_resume NULL + +#endif /* CONFIG_PM */ + +static int ad5820_probe(struct i2c_client *client, + const struct i2c_device_id *devid) +{ + struct ad5820_device *coil; + int ret = 0; + + coil = kzalloc(sizeof(*coil), GFP_KERNEL); + if (coil == NULL) + return -ENOMEM; + + mutex_init(&coil->power_lock); + + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + coil->subdev.internal_ops = &ad5820_internal_ops; + strcpy(coil->subdev.name, "ad5820 focus"); + + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); + if (ret < 0) { + kfree(coil); + return ret; + } + + ret = v4l2_async_register_subdev(&coil->subdev); + if (ret < 0) + kfree(coil); + + return ret; +} + +static int __exit ad5820_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + v4l2_device_unregister_subdev(&coil->subdev); + v4l2_ctrl_handler_free(&coil->ctrls); + media_entity_cleanup(&coil->subdev.entity); + if (coil->vana) + regulator_put(coil->vana); + + kfree(coil); + return 0; +} + +static const struct i2c_device_id ad5820_id_table[] = { + { AD5820_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); + +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); + +static struct i2c_driver ad5820_i2c_driver = { + .driver = { + .name = AD5820_NAME, + .pm = &ad5820_pm, + }, + .probe = ad5820_probe, + .remove = __exit_p(ad5820_remove), + .id_table = ad5820_id_table, +}; + +static int __init ad5820_init(void) +{ + int rval; + + rval = i2c_add_driver(&ad5820_i2c_driver); + if (rval) + printk(KERN_INFO "%s: failed registering " AD5820_NAME "\n", + __func__); + + return rval; +} + +static void __exit ad5820_exit(void) +{ + i2c_del_driver(&ad5820_i2c_driver); +} + + +module_init(ad5820_init); +module_exit(ad5820_exit); + +MODULE_AUTHOR("Tuukka Toivonen"); +MODULE_DESCRIPTION("AD5820 camera lens driver"); +MODULE_LICENSE("GPL"); -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCH] support for AD5820 camera auto-focus coil 2016-05-17 18:19 [PATCH] support for AD5820 camera auto-focus coil Pavel Machek @ 2016-05-17 18:33 ` Marcus Folkesson 2016-05-18 8:30 ` Pavel Machek 2016-05-21 5:43 ` [PATCHv2] " Pavel Machek 1 sibling, 1 reply; 73+ messages in thread From: Marcus Folkesson @ 2016-05-17 18:33 UTC (permalink / raw) To: Pavel Machek Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, ivo.g.dimitrov.75, patrikbachan, serge, linux-media, mchehab, sakari.ailus Hi Pavel, On Tue, May 17, 2016 at 08:19:27PM +0200, Pavel Machek wrote: > +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) > +{ > + struct ad5820_device *coil = > + container_of(ctrl->handler, struct ad5820_device, ctrls); > + u32 code; > + int r = 0; > + > + switch (ctrl->id) { > + case V4L2_CID_FOCUS_ABSOLUTE: > + coil->focus_absolute = ctrl->val; > + return ad5820_update_hw(coil); > + > + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: > + code = RAMP_US_TO_CODE(ctrl->val); > + ctrl->val = CODE_TO_RAMP_US(code); > + coil->focus_ramp_time = ctrl->val; > + break; > + > + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: > + coil->focus_ramp_mode = ctrl->val; > + break; > + } > + > + return r; Just return 0 instead, r is not used. > +static int ad5820_registered(struct v4l2_subdev *subdev) > +{ > + static const int CHECK_VALUE = 0x3FF0; CHECK_VALUE is not used? > +static int ad5820_probe(struct i2c_client *client, > + const struct i2c_device_id *devid) > +{ > + struct ad5820_device *coil; > + int ret = 0; > + > + coil = kzalloc(sizeof(*coil), GFP_KERNEL); > + if (coil == NULL) > + return -ENOMEM; > + > + mutex_init(&coil->power_lock); > + > + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); > + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; > + coil->subdev.internal_ops = &ad5820_internal_ops; > + strcpy(coil->subdev.name, "ad5820 focus"); > + > + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); > + if (ret < 0) { > + kfree(coil); > + return ret; > + } > + > + ret = v4l2_async_register_subdev(&coil->subdev); > + if (ret < 0) Do we need to call media_entity_cleanup() here? > +static int __init ad5820_init(void) > +{ > + int rval; > + > + rval = i2c_add_driver(&ad5820_i2c_driver); > + if (rval) > + printk(KERN_INFO "%s: failed registering " AD5820_NAME "\n", > + __func__); > + > + return rval; > +} > + > +static void __exit ad5820_exit(void) > +{ > + i2c_del_driver(&ad5820_i2c_driver); > +} > + > + > +module_init(ad5820_init); > +module_exit(ad5820_exit); Use module_i2c_driver() instead. Cheers Marcus Folkesson ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] support for AD5820 camera auto-focus coil 2016-05-17 18:33 ` Marcus Folkesson @ 2016-05-18 8:30 ` Pavel Machek 0 siblings, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-05-18 8:30 UTC (permalink / raw) To: Marcus Folkesson Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, ivo.g.dimitrov.75, patrikbachan, serge, linux-media, mchehab, sakari.ailus Hi! ... > Use module_i2c_driver() instead. Thanks for all the comments, I've fixed it up like this, will post new version soon. Best regards, Pavel commit 97a793fb20be29e7ed217c007e8bf857f9854968 Author: Pavel <pavel@ucw.cz> Date: Wed May 18 10:22:06 2016 +0200 Cleanups, as suggested by Marcus Folkesson diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c index b71cc11..7725829 100644 --- a/drivers/media/i2c/ad5820.c +++ b/drivers/media/i2c/ad5820.c @@ -147,7 +147,6 @@ static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) struct ad5820_device *coil = container_of(ctrl->handler, struct ad5820_device, ctrls); u32 code; - int r = 0; switch (ctrl->id) { case V4L2_CID_FOCUS_ABSOLUTE: @@ -165,7 +164,7 @@ static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) break; } - return r; + return 0; } static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { @@ -245,8 +244,6 @@ static int ad5820_init_controls(struct ad5820_device *coil) */ static int ad5820_registered(struct v4l2_subdev *subdev) { - static const int CHECK_VALUE = 0x3FF0; - struct ad5820_device *coil = to_ad5820_device(subdev); struct i2c_client *client = v4l2_get_subdevdata(subdev); @@ -364,16 +361,19 @@ static int ad5820_probe(struct i2c_client *client, strcpy(coil->subdev.name, "ad5820 focus"); ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); - if (ret < 0) { - kfree(coil); - return ret; - } + if (ret < 0) + goto free; ret = v4l2_async_register_subdev(&coil->subdev); if (ret < 0) - kfree(coil); + goto cleanup; return ret; +cleanup: + media_entity_cleanup(&coil->subdev.entity); +free: + kfree(coil); + return ret; } static int __exit ad5820_remove(struct i2c_client *client) @@ -409,26 +409,7 @@ static struct i2c_driver ad5820_i2c_driver = { .id_table = ad5820_id_table, }; -static int __init ad5820_init(void) -{ - int rval; - - rval = i2c_add_driver(&ad5820_i2c_driver); - if (rval) - printk(KERN_INFO "%s: failed registering " AD5820_NAME "\n", - __func__); - - return rval; -} - -static void __exit ad5820_exit(void) -{ - i2c_del_driver(&ad5820_i2c_driver); -} - - -module_init(ad5820_init); -module_exit(ad5820_exit); +module_i2c_driver(ad5820_i2c_driver); MODULE_AUTHOR("Tuukka Toivonen"); MODULE_DESCRIPTION("AD5820 camera lens driver"); -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* [PATCHv2] support for AD5820 camera auto-focus coil 2016-05-17 18:19 [PATCH] support for AD5820 camera auto-focus coil Pavel Machek 2016-05-17 18:33 ` Marcus Folkesson @ 2016-05-21 5:43 ` Pavel Machek 2016-05-21 6:25 ` Ivaylo Dimitrov 1 sibling, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-05-21 5:43 UTC (permalink / raw) To: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, ivo.g.dimitrov.75, patrikbachan, serge, linux-media, mchehab, sakari.ailus This adds support for AD5820 autofocus coil, found for example in Nokia N900 smartphone. Signed-off-by: Pavel Machek <pavel@ucw.cz> --- v2: simple cleanups, fix error paths, simplify probe I think it is ready. Please apply :-). diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 993dc50..77313a1 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 To compile this driver as a module, choose M here: the module will be called ml86v7667. +config VIDEO_AD5820 + tristate "AD5820 lens voice coil support" + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + ---help--- + This is a driver for the AD5820 camera lens voice coil. + It is used for example in Nokia N900 (RX-51). + config VIDEO_SAA7110 tristate "Philips SAA7110 video decoder" depends on VIDEO_V4L2 && I2C diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 94f2c99..34434ae 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c new file mode 100644 index 0000000..7725829 --- /dev/null +++ b/drivers/media/i2c/ad5820.c @@ -0,0 +1,416 @@ +/* + * drivers/media/i2c/ad5820.c + * + * AD5820 DAC driver for camera voice coil focus. + * + * Copyright (C) 2008 Nokia Corporation + * Copyright (C) 2007 Texas Instruments + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> + * + * Contact: Tuukka Toivonen + * Sakari Ailus + * + * Based on af_d88.c by Texas Instruments. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/i2c.h> +#include <linux/slab.h> +#include <linux/sched.h> +#include <linux/delay.h> +#include <linux/bitops.h> +#include <linux/kernel.h> +#include <linux/regulator/consumer.h> + +#include <media/ad5820.h> +#include <media/v4l2-device.h> + +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) + +/** + * @brief I2C write using i2c_transfer(). + * @param coil - the driver data structure + * @param data - register value to be written + * @returns nonnegative on success, negative if failed + */ +static int ad5820_write(struct ad5820_device *coil, u16 data) +{ + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); + struct i2c_msg msg; + int r; + + if (!client->adapter) + return -ENODEV; + + data = cpu_to_be16(data); + msg.addr = client->addr; + msg.flags = 0; + msg.len = 2; + msg.buf = (u8 *)&data; + + r = i2c_transfer(client->adapter, &msg, 1); + if (r < 0) { + dev_err(&client->dev, "write failed, error %d\n", r); + return r; + } + + return 0; +} + +/* + * Calculate status word and write it to the device based on current + * values of V4L2 controls. It is assumed that the stored V4L2 control + * values are properly limited and rounded. + */ +static int ad5820_update_hw(struct ad5820_device *coil) +{ + u16 status; + + status = RAMP_US_TO_CODE(coil->focus_ramp_time); + status |= coil->focus_ramp_mode + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; + status |= coil->focus_absolute << AD5820_DAC_SHIFT; + + if (coil->standby) + status |= AD5820_POWER_DOWN; + + return ad5820_write(coil, status); +} + +/* + * Power handling + */ +static int ad5820_power_off(struct ad5820_device *coil, int standby) +{ + int ret = 0; + + /* + * Go to standby first as real power off my be denied by the hardware + * (single power line control for both coil and sensor). + */ + if (standby) { + coil->standby = 1; + ret = ad5820_update_hw(coil); + } + + ret |= regulator_disable(coil->vana); + + return ret; +} + +static int ad5820_power_on(struct ad5820_device *coil, int restore) +{ + int ret; + + printk("ad5820_power_on: 1\n"); + ret = regulator_enable(coil->vana); + if (ret < 0) + return ret; + + if (restore) { + /* Restore the hardware settings. */ + coil->standby = 0; + ret = ad5820_update_hw(coil); + if (ret) + goto fail; + } + return 0; + +fail: + coil->standby = 1; + regulator_disable(coil->vana); + + return ret; +} + +/* + * V4L2 controls + */ +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ad5820_device *coil = + container_of(ctrl->handler, struct ad5820_device, ctrls); + u32 code; + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + coil->focus_absolute = ctrl->val; + return ad5820_update_hw(coil); + + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: + code = RAMP_US_TO_CODE(ctrl->val); + ctrl->val = CODE_TO_RAMP_US(code); + coil->focus_ramp_time = ctrl->val; + break; + + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: + coil->focus_ramp_mode = ctrl->val; + break; + } + + return 0; +} + +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { + .s_ctrl = ad5820_set_ctrl, +}; + +static const char *ad5820_focus_menu[] = { + "Linear ramp", + "64/16 ramp", +}; + +static const struct v4l2_ctrl_config ad5820_ctrls[] = { + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Focus ramping time [us]", + .min = 0, + .max = 3200, + .step = 50, + .def = 0, + .flags = 0, + }, + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, + .type = V4L2_CTRL_TYPE_MENU, + .name = "Focus ramping mode", + .min = 0, + .max = ARRAY_SIZE(ad5820_focus_menu), + .step = 0, + .def = 0, + .flags = 0, + .qmenu = ad5820_focus_menu, + }, +}; + + +static int ad5820_init_controls(struct ad5820_device *coil) +{ + unsigned int i; + + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); + + /* + * V4L2_CID_FOCUS_ABSOLUTE + * + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] + * for focus position, because it is meaningless for user. Meaningful + * would be to use focus distance or even its inverse, but since the + * driver doesn't have sufficiently knowledge to do the conversion, we + * will just use abstract codes here. In any case, smaller value = focus + * position farther from camera. The default zero value means focus at + * infinity, and also least current consumption. + */ + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); + + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); + + if (coil->ctrls.error) + return coil->ctrls.error; + + coil->focus_absolute = 0; + coil->focus_ramp_time = 0; + coil->focus_ramp_mode = 0; + + coil->subdev.ctrl_handler = &coil->ctrls; + return 0; +} + +/* + * V4L2 subdev operations + */ +static int ad5820_registered(struct v4l2_subdev *subdev) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + struct i2c_client *client = v4l2_get_subdevdata(subdev); + + coil->vana = regulator_get(&client->dev, "VANA"); + if (IS_ERR(coil->vana)) { + dev_err(&client->dev, "could not get regulator for vana\n"); + return -ENODEV; + } + + return ad5820_init_controls(coil); +} + +static int +ad5820_set_power(struct v4l2_subdev *subdev, int on) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + int ret = 0; + + mutex_lock(&coil->power_lock); + + /* + * If the power count is modified from 0 to != 0 or from != 0 to 0, + * update the power state. + */ + if (coil->power_count == !on) { + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); + if (ret < 0) + goto done; + } + + /* Update the power count. */ + coil->power_count += on ? 1 : -1; + WARN_ON(coil->power_count < 0); + +done: + mutex_unlock(&coil->power_lock); + return ret; +} + +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 1); +} + +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 0); +} + +static const struct v4l2_subdev_core_ops ad5820_core_ops = { + .s_power = ad5820_set_power, +}; + +static const struct v4l2_subdev_ops ad5820_ops = { + .core = &ad5820_core_ops, +}; + +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { + .registered = ad5820_registered, + .open = ad5820_open, + .close = ad5820_close, +}; + +/* + * I2C driver + */ +#ifdef CONFIG_PM + +static int ad5820_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_off(coil, 0); +} + +static int ad5820_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_on(coil, 1); +} + +#else + +#define ad5820_suspend NULL +#define ad5820_resume NULL + +#endif /* CONFIG_PM */ + +static int ad5820_probe(struct i2c_client *client, + const struct i2c_device_id *devid) +{ + struct ad5820_device *coil; + int ret = 0; + + coil = kzalloc(sizeof(*coil), GFP_KERNEL); + if (coil == NULL) + return -ENOMEM; + + mutex_init(&coil->power_lock); + + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + coil->subdev.internal_ops = &ad5820_internal_ops; + strcpy(coil->subdev.name, "ad5820 focus"); + + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); + if (ret < 0) + goto free; + + ret = v4l2_async_register_subdev(&coil->subdev); + if (ret < 0) + goto cleanup; + + return ret; +cleanup: + media_entity_cleanup(&coil->subdev.entity); +free: + kfree(coil); + return ret; +} + +static int __exit ad5820_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + v4l2_device_unregister_subdev(&coil->subdev); + v4l2_ctrl_handler_free(&coil->ctrls); + media_entity_cleanup(&coil->subdev.entity); + if (coil->vana) + regulator_put(coil->vana); + + kfree(coil); + return 0; +} + +static const struct i2c_device_id ad5820_id_table[] = { + { AD5820_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); + +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); + +static struct i2c_driver ad5820_i2c_driver = { + .driver = { + .name = AD5820_NAME, + .pm = &ad5820_pm, + }, + .probe = ad5820_probe, + .remove = __exit_p(ad5820_remove), + .id_table = ad5820_id_table, +}; + +module_i2c_driver(ad5820_i2c_driver); + +MODULE_AUTHOR("Tuukka Toivonen"); +MODULE_DESCRIPTION("AD5820 camera lens driver"); +MODULE_LICENSE("GPL"); -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv2] support for AD5820 camera auto-focus coil 2016-05-21 5:43 ` [PATCHv2] " Pavel Machek @ 2016-05-21 6:25 ` Ivaylo Dimitrov 2016-05-21 10:56 ` [PATCHv3] " Pavel Machek 0 siblings, 1 reply; 73+ messages in thread From: Ivaylo Dimitrov @ 2016-05-21 6:25 UTC (permalink / raw) To: Pavel Machek Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus Hi, On 21.05.2016 08:43, Pavel Machek wrote: > This adds support for AD5820 autofocus coil, found for example in > Nokia N900 smartphone. > > Signed-off-by: Pavel Machek <pavel@ucw.cz> > > --- > v2: simple cleanups, fix error paths, simplify probe > > I think it is ready. Please apply :-). > > diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig > index 993dc50..77313a1 100644 > --- a/drivers/media/i2c/Kconfig > +++ b/drivers/media/i2c/Kconfig > @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 > To compile this driver as a module, choose M here: the > module will be called ml86v7667. > > +config VIDEO_AD5820 > + tristate "AD5820 lens voice coil support" > + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER > + ---help--- > + This is a driver for the AD5820 camera lens voice coil. > + It is used for example in Nokia N900 (RX-51). > + > config VIDEO_SAA7110 > tristate "Philips SAA7110 video decoder" > depends on VIDEO_V4L2 && I2C > diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile > index 94f2c99..34434ae 100644 > --- a/drivers/media/i2c/Makefile > +++ b/drivers/media/i2c/Makefile > @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o > obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o > obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o > obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o > +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o > obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o > obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o > obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o > diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c > new file mode 100644 > index 0000000..7725829 > --- /dev/null > +++ b/drivers/media/i2c/ad5820.c > @@ -0,0 +1,416 @@ > +/* > + * drivers/media/i2c/ad5820.c > + * > + * AD5820 DAC driver for camera voice coil focus. > + * > + * Copyright (C) 2008 Nokia Corporation > + * Copyright (C) 2007 Texas Instruments > + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> > + * > + * Contact: Tuukka Toivonen > + * Sakari Ailus > + * > + * Based on af_d88.c by Texas Instruments. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * version 2 as published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, but > + * WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA > + * 02110-1301 USA > + */ > + Remove FSF address from the above. > +#include <linux/module.h> > +#include <linux/errno.h> > +#include <linux/i2c.h> > +#include <linux/slab.h> > +#include <linux/sched.h> > +#include <linux/delay.h> > +#include <linux/bitops.h> > +#include <linux/kernel.h> > +#include <linux/regulator/consumer.h> > + > +#include <media/ad5820.h> drivers/media/i2c/ad5820.c:40:26: fatal error: media/ad5820.h: No such file or directory > +#include <media/v4l2-device.h> > + > +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) > +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) > + > +/** > + * @brief I2C write using i2c_transfer(). > + * @param coil - the driver data structure > + * @param data - register value to be written > + * @returns nonnegative on success, negative if failed > + */ > +static int ad5820_write(struct ad5820_device *coil, u16 data) > +{ > + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); > + struct i2c_msg msg; > + int r; > + > + if (!client->adapter) > + return -ENODEV; > + > + data = cpu_to_be16(data); > + msg.addr = client->addr; > + msg.flags = 0; > + msg.len = 2; > + msg.buf = (u8 *)&data; > + > + r = i2c_transfer(client->adapter, &msg, 1); > + if (r < 0) { > + dev_err(&client->dev, "write failed, error %d\n", r); > + return r; > + } > + > + return 0; > +} > + > +/* > + * Calculate status word and write it to the device based on current > + * values of V4L2 controls. It is assumed that the stored V4L2 control > + * values are properly limited and rounded. > + */ > +static int ad5820_update_hw(struct ad5820_device *coil) > +{ > + u16 status; > + > + status = RAMP_US_TO_CODE(coil->focus_ramp_time); > + status |= coil->focus_ramp_mode > + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; > + status |= coil->focus_absolute << AD5820_DAC_SHIFT; > + > + if (coil->standby) > + status |= AD5820_POWER_DOWN; > + > + return ad5820_write(coil, status); > +} > + > +/* > + * Power handling > + */ > +static int ad5820_power_off(struct ad5820_device *coil, int standby) > +{ > + int ret = 0; > + > + /* > + * Go to standby first as real power off my be denied by the hardware > + * (single power line control for both coil and sensor). > + */ > + if (standby) { > + coil->standby = 1; > + ret = ad5820_update_hw(coil); > + } > + > + ret |= regulator_disable(coil->vana); > + > + return ret; > +} > + > +static int ad5820_power_on(struct ad5820_device *coil, int restore) > +{ > + int ret; > + > + printk("ad5820_power_on: 1\n"); Some remnants from testing? > + ret = regulator_enable(coil->vana); > + if (ret < 0) > + return ret; > + > + if (restore) { > + /* Restore the hardware settings. */ > + coil->standby = 0; > + ret = ad5820_update_hw(coil); > + if (ret) > + goto fail; > + } > + return 0; > + > +fail: > + coil->standby = 1; > + regulator_disable(coil->vana); > + > + return ret; > +} > + > +/* > + * V4L2 controls > + */ > +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) > +{ > + struct ad5820_device *coil = > + container_of(ctrl->handler, struct ad5820_device, ctrls); > + u32 code; > + > + switch (ctrl->id) { > + case V4L2_CID_FOCUS_ABSOLUTE: > + coil->focus_absolute = ctrl->val; > + return ad5820_update_hw(coil); > + > + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: > + code = RAMP_US_TO_CODE(ctrl->val); > + ctrl->val = CODE_TO_RAMP_US(code); > + coil->focus_ramp_time = ctrl->val; > + break; > + > + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: > + coil->focus_ramp_mode = ctrl->val; > + break; > + } > + > + return 0; > +} > + > +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { > + .s_ctrl = ad5820_set_ctrl, > +}; > + > +static const char *ad5820_focus_menu[] = { static const char * const ? > + "Linear ramp", > + "64/16 ramp", > +}; > + > +static const struct v4l2_ctrl_config ad5820_ctrls[] = { > + { > + .ops = &ad5820_ctrl_ops, > + .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, > + .type = V4L2_CTRL_TYPE_INTEGER, > + .name = "Focus ramping time [us]", > + .min = 0, > + .max = 3200, > + .step = 50, > + .def = 0, > + .flags = 0, > + }, > + { > + .ops = &ad5820_ctrl_ops, > + .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, > + .type = V4L2_CTRL_TYPE_MENU, > + .name = "Focus ramping mode", > + .min = 0, > + .max = ARRAY_SIZE(ad5820_focus_menu), > + .step = 0, > + .def = 0, > + .flags = 0, > + .qmenu = ad5820_focus_menu, > + }, > +}; > + > + > +static int ad5820_init_controls(struct ad5820_device *coil) > +{ > + unsigned int i; > + > + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); > + > + /* > + * V4L2_CID_FOCUS_ABSOLUTE > + * > + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is > + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] > + * for focus position, because it is meaningless for user. Meaningful > + * would be to use focus distance or even its inverse, but since the > + * driver doesn't have sufficiently knowledge to do the conversion, we > + * will just use abstract codes here. In any case, smaller value = focus > + * position farther from camera. The default zero value means focus at > + * infinity, and also least current consumption. > + */ > + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, > + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); > + > + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ > + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) > + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); > + > + if (coil->ctrls.error) > + return coil->ctrls.error; > + > + coil->focus_absolute = 0; > + coil->focus_ramp_time = 0; > + coil->focus_ramp_mode = 0; > + > + coil->subdev.ctrl_handler = &coil->ctrls; > + return 0; > +} please add a new line before return. > + > +/* > + * V4L2 subdev operations > + */ > +static int ad5820_registered(struct v4l2_subdev *subdev) > +{ > + struct ad5820_device *coil = to_ad5820_device(subdev); > + struct i2c_client *client = v4l2_get_subdevdata(subdev); > + > + coil->vana = regulator_get(&client->dev, "VANA"); > + if (IS_ERR(coil->vana)) { > + dev_err(&client->dev, "could not get regulator for vana\n"); > + return -ENODEV; > + } > + > + return ad5820_init_controls(coil); > +} > + > +static int > +ad5820_set_power(struct v4l2_subdev *subdev, int on) > +{ > + struct ad5820_device *coil = to_ad5820_device(subdev); > + int ret = 0; > + > + mutex_lock(&coil->power_lock); > + > + /* > + * If the power count is modified from 0 to != 0 or from != 0 to 0, > + * update the power state. > + */ > + if (coil->power_count == !on) { > + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); > + if (ret < 0) > + goto done; > + } > + > + /* Update the power count. */ > + coil->power_count += on ? 1 : -1; > + WARN_ON(coil->power_count < 0); > + > +done: > + mutex_unlock(&coil->power_lock); > + return ret; > +} > + > +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) > +{ > + return ad5820_set_power(sd, 1); > +} > + > +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) > +{ > + return ad5820_set_power(sd, 0); > +} > + > +static const struct v4l2_subdev_core_ops ad5820_core_ops = { > + .s_power = ad5820_set_power, > +}; > + > +static const struct v4l2_subdev_ops ad5820_ops = { > + .core = &ad5820_core_ops, > +}; > + > +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { > + .registered = ad5820_registered, > + .open = ad5820_open, > + .close = ad5820_close, > +}; > + > +/* > + * I2C driver > + */ > +#ifdef CONFIG_PM > + > +static int ad5820_suspend(struct device *dev) > +{ > + struct i2c_client *client = container_of(dev, struct i2c_client, dev); > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + if (!coil->power_count) > + return 0; > + > + return ad5820_power_off(coil, 0); > +} > + > +static int ad5820_resume(struct device *dev) > +{ > + struct i2c_client *client = container_of(dev, struct i2c_client, dev); > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + if (!coil->power_count) > + return 0; > + > + return ad5820_power_on(coil, 1); > +} > + > +#else > + > +#define ad5820_suspend NULL > +#define ad5820_resume NULL > + > +#endif /* CONFIG_PM */ > + > +static int ad5820_probe(struct i2c_client *client, > + const struct i2c_device_id *devid) > +{ > + struct ad5820_device *coil; > + int ret = 0; > + > + coil = kzalloc(sizeof(*coil), GFP_KERNEL); > + if (coil == NULL) if (!coil) ? > + return -ENOMEM; > + > + mutex_init(&coil->power_lock); > + > + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); > + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; > + coil->subdev.internal_ops = &ad5820_internal_ops; > + strcpy(coil->subdev.name, "ad5820 focus"); > + > + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); > + if (ret < 0) > + goto free; > + > + ret = v4l2_async_register_subdev(&coil->subdev); > + if (ret < 0) > + goto cleanup; > + > + return ret; > +cleanup: > + media_entity_cleanup(&coil->subdev.entity); > +free: > + kfree(coil); > + return ret; > +} new line before return, also I would put new lines before labels :) > + > +static int __exit ad5820_remove(struct i2c_client *client) > +{ > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + v4l2_device_unregister_subdev(&coil->subdev); > + v4l2_ctrl_handler_free(&coil->ctrls); > + media_entity_cleanup(&coil->subdev.entity); > + if (coil->vana) > + regulator_put(coil->vana); > + > + kfree(coil); new line here > + return 0; > +} > + > +static const struct i2c_device_id ad5820_id_table[] = { > + { AD5820_NAME, 0 }, > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); > + > +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); > + > +static struct i2c_driver ad5820_i2c_driver = { > + .driver = { > + .name = AD5820_NAME, > + .pm = &ad5820_pm, > + }, > + .probe = ad5820_probe, > + .remove = __exit_p(ad5820_remove), > + .id_table = ad5820_id_table, > +}; > + > +module_i2c_driver(ad5820_i2c_driver); > + > +MODULE_AUTHOR("Tuukka Toivonen"); > +MODULE_DESCRIPTION("AD5820 camera lens driver"); > +MODULE_LICENSE("GPL"); > Thanks, Ivo ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCHv3] support for AD5820 camera auto-focus coil 2016-05-21 6:25 ` Ivaylo Dimitrov @ 2016-05-21 10:56 ` Pavel Machek 2016-05-21 11:43 ` Ivaylo Dimitrov 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-05-21 10:56 UTC (permalink / raw) To: Ivaylo Dimitrov Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus This adds support for AD5820 autofocus coil, found for example in Nokia N900 smartphone. Signed-off-by: Pavel Machek <pavel@ucw.cz> --- v2: simple cleanups, fix error paths, simplify probe v3: more cleanups, remove printk, add include diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 993dc50..77313a1 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 To compile this driver as a module, choose M here: the module will be called ml86v7667. +config VIDEO_AD5820 + tristate "AD5820 lens voice coil support" + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + ---help--- + This is a driver for the AD5820 camera lens voice coil. + It is used for example in Nokia N900 (RX-51). + config VIDEO_SAA7110 tristate "Philips SAA7110 video decoder" depends on VIDEO_V4L2 && I2C diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 94f2c99..34434ae 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c new file mode 100644 index 0000000..7725829 --- /dev/null +++ b/drivers/media/i2c/ad5820.c @@ -0,0 +1,416 @@ +/* + * drivers/media/i2c/ad5820.c + * + * AD5820 DAC driver for camera voice coil focus. + * + * Copyright (C) 2008 Nokia Corporation + * Copyright (C) 2007 Texas Instruments + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> + * + * Contact: Tuukka Toivonen + * Sakari Ailus + * + * Based on af_d88.c by Texas Instruments. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/i2c.h> +#include <linux/slab.h> +#include <linux/sched.h> +#include <linux/delay.h> +#include <linux/bitops.h> +#include <linux/kernel.h> +#include <linux/regulator/consumer.h> + +#include <media/ad5820.h> +#include <media/v4l2-device.h> + +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) + +/** + * @brief I2C write using i2c_transfer(). + * @param coil - the driver data structure + * @param data - register value to be written + * @returns nonnegative on success, negative if failed + */ +static int ad5820_write(struct ad5820_device *coil, u16 data) +{ + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); + struct i2c_msg msg; + int r; + + if (!client->adapter) + return -ENODEV; + + data = cpu_to_be16(data); + msg.addr = client->addr; + msg.flags = 0; + msg.len = 2; + msg.buf = (u8 *)&data; + + r = i2c_transfer(client->adapter, &msg, 1); + if (r < 0) { + dev_err(&client->dev, "write failed, error %d\n", r); + return r; + } + + return 0; +} + +/* + * Calculate status word and write it to the device based on current + * values of V4L2 controls. It is assumed that the stored V4L2 control + * values are properly limited and rounded. + */ +static int ad5820_update_hw(struct ad5820_device *coil) +{ + u16 status; + + status = RAMP_US_TO_CODE(coil->focus_ramp_time); + status |= coil->focus_ramp_mode + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; + status |= coil->focus_absolute << AD5820_DAC_SHIFT; + + if (coil->standby) + status |= AD5820_POWER_DOWN; + + return ad5820_write(coil, status); +} + +/* + * Power handling + */ +static int ad5820_power_off(struct ad5820_device *coil, int standby) +{ + int ret = 0; + + /* + * Go to standby first as real power off my be denied by the hardware + * (single power line control for both coil and sensor). + */ + if (standby) { + coil->standby = 1; + ret = ad5820_update_hw(coil); + } + + ret |= regulator_disable(coil->vana); + + return ret; +} + +static int ad5820_power_on(struct ad5820_device *coil, int restore) +{ + int ret; + + printk("ad5820_power_on: 1\n"); + ret = regulator_enable(coil->vana); + if (ret < 0) + return ret; + + if (restore) { + /* Restore the hardware settings. */ + coil->standby = 0; + ret = ad5820_update_hw(coil); + if (ret) + goto fail; + } + return 0; + +fail: + coil->standby = 1; + regulator_disable(coil->vana); + + return ret; +} + +/* + * V4L2 controls + */ +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ad5820_device *coil = + container_of(ctrl->handler, struct ad5820_device, ctrls); + u32 code; + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + coil->focus_absolute = ctrl->val; + return ad5820_update_hw(coil); + + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: + code = RAMP_US_TO_CODE(ctrl->val); + ctrl->val = CODE_TO_RAMP_US(code); + coil->focus_ramp_time = ctrl->val; + break; + + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: + coil->focus_ramp_mode = ctrl->val; + break; + } + + return 0; +} + +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { + .s_ctrl = ad5820_set_ctrl, +}; + +static const char *ad5820_focus_menu[] = { + "Linear ramp", + "64/16 ramp", +}; + +static const struct v4l2_ctrl_config ad5820_ctrls[] = { + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Focus ramping time [us]", + .min = 0, + .max = 3200, + .step = 50, + .def = 0, + .flags = 0, + }, + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, + .type = V4L2_CTRL_TYPE_MENU, + .name = "Focus ramping mode", + .min = 0, + .max = ARRAY_SIZE(ad5820_focus_menu), + .step = 0, + .def = 0, + .flags = 0, + .qmenu = ad5820_focus_menu, + }, +}; + + +static int ad5820_init_controls(struct ad5820_device *coil) +{ + unsigned int i; + + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); + + /* + * V4L2_CID_FOCUS_ABSOLUTE + * + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] + * for focus position, because it is meaningless for user. Meaningful + * would be to use focus distance or even its inverse, but since the + * driver doesn't have sufficiently knowledge to do the conversion, we + * will just use abstract codes here. In any case, smaller value = focus + * position farther from camera. The default zero value means focus at + * infinity, and also least current consumption. + */ + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); + + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); + + if (coil->ctrls.error) + return coil->ctrls.error; + + coil->focus_absolute = 0; + coil->focus_ramp_time = 0; + coil->focus_ramp_mode = 0; + + coil->subdev.ctrl_handler = &coil->ctrls; + return 0; +} + +/* + * V4L2 subdev operations + */ +static int ad5820_registered(struct v4l2_subdev *subdev) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + struct i2c_client *client = v4l2_get_subdevdata(subdev); + + coil->vana = regulator_get(&client->dev, "VANA"); + if (IS_ERR(coil->vana)) { + dev_err(&client->dev, "could not get regulator for vana\n"); + return -ENODEV; + } + + return ad5820_init_controls(coil); +} + +static int +ad5820_set_power(struct v4l2_subdev *subdev, int on) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + int ret = 0; + + mutex_lock(&coil->power_lock); + + /* + * If the power count is modified from 0 to != 0 or from != 0 to 0, + * update the power state. + */ + if (coil->power_count == !on) { + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); + if (ret < 0) + goto done; + } + + /* Update the power count. */ + coil->power_count += on ? 1 : -1; + WARN_ON(coil->power_count < 0); + +done: + mutex_unlock(&coil->power_lock); + return ret; +} + +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 1); +} + +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 0); +} + +static const struct v4l2_subdev_core_ops ad5820_core_ops = { + .s_power = ad5820_set_power, +}; + +static const struct v4l2_subdev_ops ad5820_ops = { + .core = &ad5820_core_ops, +}; + +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { + .registered = ad5820_registered, + .open = ad5820_open, + .close = ad5820_close, +}; + +/* + * I2C driver + */ +#ifdef CONFIG_PM + +static int ad5820_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_off(coil, 0); +} + +static int ad5820_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_on(coil, 1); +} + +#else + +#define ad5820_suspend NULL +#define ad5820_resume NULL + +#endif /* CONFIG_PM */ + +static int ad5820_probe(struct i2c_client *client, + const struct i2c_device_id *devid) +{ + struct ad5820_device *coil; + int ret = 0; + + coil = kzalloc(sizeof(*coil), GFP_KERNEL); + if (coil == NULL) + return -ENOMEM; + + mutex_init(&coil->power_lock); + + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + coil->subdev.internal_ops = &ad5820_internal_ops; + strcpy(coil->subdev.name, "ad5820 focus"); + + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); + if (ret < 0) + goto free; + + ret = v4l2_async_register_subdev(&coil->subdev); + if (ret < 0) + goto cleanup; + + return ret; +cleanup: + media_entity_cleanup(&coil->subdev.entity); +free: + kfree(coil); + return ret; +} + +static int __exit ad5820_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + v4l2_device_unregister_subdev(&coil->subdev); + v4l2_ctrl_handler_free(&coil->ctrls); + media_entity_cleanup(&coil->subdev.entity); + if (coil->vana) + regulator_put(coil->vana); + + kfree(coil); + return 0; +} + +static const struct i2c_device_id ad5820_id_table[] = { + { AD5820_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); + +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); + +static struct i2c_driver ad5820_i2c_driver = { + .driver = { + .name = AD5820_NAME, + .pm = &ad5820_pm, + }, + .probe = ad5820_probe, + .remove = __exit_p(ad5820_remove), + .id_table = ad5820_id_table, +}; + +module_i2c_driver(ad5820_i2c_driver); + +MODULE_AUTHOR("Tuukka Toivonen"); +MODULE_DESCRIPTION("AD5820 camera lens driver"); +MODULE_LICENSE("GPL"); diff --git a/include/media/ad5820.h b/include/media/ad5820.h new file mode 100644 index 0000000..f5a1565 --- /dev/null +++ b/include/media/ad5820.h @@ -0,0 +1,70 @@ +/* + * include/media/ad5820.h + * + * Copyright (C) 2008 Nokia Corporation + * Copyright (C) 2007 Texas Instruments + * + * Contact: Tuukka Toivonen <tuukka.o.toivonen@nokia.com> + * Sakari Ailus <sakari.ailus@nokia.com> + * + * Based on af_d88.c by Texas Instruments. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef AD5820_H +#define AD5820_H + +#include <linux/i2c.h> +#include <linux/mutex.h> +#include <linux/videodev2.h> + +#include <media/v4l2-ctrls.h> +#include <media/v4l2-subdev.h> + +struct regulator; + +#define AD5820_NAME "ad5820" +#define AD5820_I2C_ADDR (0x18 >> 1) + +/* Register definitions */ +#define AD5820_POWER_DOWN (1 << 15) +#define AD5820_DAC_SHIFT 4 +#define AD5820_RAMP_MODE_LINEAR (0 << 3) +#define AD5820_RAMP_MODE_64_16 (1 << 3) + +struct ad5820_platform_data { + int (*set_xshutdown)(struct v4l2_subdev *subdev, int set); +}; + +#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) + +struct ad5820_device { + struct v4l2_subdev subdev; + struct ad5820_platform_data *platform_data; + struct regulator *vana; + + struct v4l2_ctrl_handler ctrls; + u32 focus_absolute; + u32 focus_ramp_time; + u32 focus_ramp_mode; + + struct mutex power_lock; + int power_count; + + int standby : 1; +}; + +#endif /* AD5820_H */ -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv3] support for AD5820 camera auto-focus coil 2016-05-21 10:56 ` [PATCHv3] " Pavel Machek @ 2016-05-21 11:43 ` Ivaylo Dimitrov 2016-05-23 7:41 ` Pali Rohár 2016-05-24 9:04 ` Pavel Machek 0 siblings, 2 replies; 73+ messages in thread From: Ivaylo Dimitrov @ 2016-05-21 11:43 UTC (permalink / raw) To: Pavel Machek Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus Hi, On 21.05.2016 13:56, Pavel Machek wrote: > This adds support for AD5820 autofocus coil, found for example in > Nokia N900 smartphone. > > Signed-off-by: Pavel Machek <pavel@ucw.cz> > > --- > v2: simple cleanups, fix error paths, simplify probe > > v3: more cleanups, remove printk, add include > > diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig > index 993dc50..77313a1 100644 > --- a/drivers/media/i2c/Kconfig > +++ b/drivers/media/i2c/Kconfig > @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 > To compile this driver as a module, choose M here: the > module will be called ml86v7667. > > +config VIDEO_AD5820 > + tristate "AD5820 lens voice coil support" > + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER > + ---help--- > + This is a driver for the AD5820 camera lens voice coil. > + It is used for example in Nokia N900 (RX-51). > + > config VIDEO_SAA7110 > tristate "Philips SAA7110 video decoder" > depends on VIDEO_V4L2 && I2C > diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile > index 94f2c99..34434ae 100644 > --- a/drivers/media/i2c/Makefile > +++ b/drivers/media/i2c/Makefile > @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o > obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o > obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o > obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o > +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o > obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o > obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o > obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o > diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c > new file mode 100644 > index 0000000..7725829 > --- /dev/null > +++ b/drivers/media/i2c/ad5820.c > @@ -0,0 +1,416 @@ > +/* > + * drivers/media/i2c/ad5820.c > + * > + * AD5820 DAC driver for camera voice coil focus. > + * > + * Copyright (C) 2008 Nokia Corporation > + * Copyright (C) 2007 Texas Instruments > + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> > + * > + * Contact: Tuukka Toivonen > + * Sakari Ailus > + * > + * Based on af_d88.c by Texas Instruments. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * version 2 as published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, but > + * WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA > + * 02110-1301 USA > + */ > + At least on my machine checkpatch.pl complains about FSF address. > +#include <linux/module.h> > +#include <linux/errno.h> > +#include <linux/i2c.h> > +#include <linux/slab.h> > +#include <linux/sched.h> > +#include <linux/delay.h> Doesn't seem to get used. > +#include <linux/bitops.h> > +#include <linux/kernel.h> > +#include <linux/regulator/consumer.h> > + > +#include <media/ad5820.h> > +#include <media/v4l2-device.h> > + > +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) > +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) > + > +/** > + * @brief I2C write using i2c_transfer(). > + * @param coil - the driver data structure > + * @param data - register value to be written > + * @returns nonnegative on success, negative if failed > + */ > +static int ad5820_write(struct ad5820_device *coil, u16 data) > +{ > + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); > + struct i2c_msg msg; > + int r; > + > + if (!client->adapter) > + return -ENODEV; > + > + data = cpu_to_be16(data); > + msg.addr = client->addr; > + msg.flags = 0; > + msg.len = 2; > + msg.buf = (u8 *)&data; > + > + r = i2c_transfer(client->adapter, &msg, 1); > + if (r < 0) { > + dev_err(&client->dev, "write failed, error %d\n", r); > + return r; > + } > + > + return 0; > +} > + > +/* > + * Calculate status word and write it to the device based on current > + * values of V4L2 controls. It is assumed that the stored V4L2 control > + * values are properly limited and rounded. > + */ > +static int ad5820_update_hw(struct ad5820_device *coil) > +{ > + u16 status; > + > + status = RAMP_US_TO_CODE(coil->focus_ramp_time); > + status |= coil->focus_ramp_mode > + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; > + status |= coil->focus_absolute << AD5820_DAC_SHIFT; > + > + if (coil->standby) > + status |= AD5820_POWER_DOWN; > + > + return ad5820_write(coil, status); > +} > + > +/* > + * Power handling > + */ > +static int ad5820_power_off(struct ad5820_device *coil, int standby) > +{ > + int ret = 0; > + > + /* > + * Go to standby first as real power off my be denied by the hardware > + * (single power line control for both coil and sensor). > + */ > + if (standby) { > + coil->standby = 1; > + ret = ad5820_update_hw(coil); > + } > + > + ret |= regulator_disable(coil->vana); > + > + return ret; > +} > + > +static int ad5820_power_on(struct ad5820_device *coil, int restore) > +{ > + int ret; > + > + printk("ad5820_power_on: 1\n"); > + ret = regulator_enable(coil->vana); > + if (ret < 0) > + return ret; > + > + if (restore) { > + /* Restore the hardware settings. */ > + coil->standby = 0; > + ret = ad5820_update_hw(coil); > + if (ret) > + goto fail; > + } > + return 0; > + > +fail: > + coil->standby = 1; > + regulator_disable(coil->vana); > + > + return ret; > +} > + > +/* > + * V4L2 controls > + */ > +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) > +{ > + struct ad5820_device *coil = > + container_of(ctrl->handler, struct ad5820_device, ctrls); > + u32 code; > + > + switch (ctrl->id) { > + case V4L2_CID_FOCUS_ABSOLUTE: > + coil->focus_absolute = ctrl->val; > + return ad5820_update_hw(coil); > + > + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: > + code = RAMP_US_TO_CODE(ctrl->val); > + ctrl->val = CODE_TO_RAMP_US(code); > + coil->focus_ramp_time = ctrl->val; > + break; > + > + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: > + coil->focus_ramp_mode = ctrl->val; > + break; > + } > + > + return 0; > +} > + > +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { > + .s_ctrl = ad5820_set_ctrl, > +}; > + > +static const char *ad5820_focus_menu[] = { > + "Linear ramp", > + "64/16 ramp", > +}; > + > +static const struct v4l2_ctrl_config ad5820_ctrls[] = { > + { > + .ops = &ad5820_ctrl_ops, > + .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, > + .type = V4L2_CTRL_TYPE_INTEGER, > + .name = "Focus ramping time [us]", > + .min = 0, > + .max = 3200, > + .step = 50, > + .def = 0, > + .flags = 0, > + }, > + { > + .ops = &ad5820_ctrl_ops, > + .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, > + .type = V4L2_CTRL_TYPE_MENU, > + .name = "Focus ramping mode", > + .min = 0, > + .max = ARRAY_SIZE(ad5820_focus_menu), > + .step = 0, > + .def = 0, > + .flags = 0, > + .qmenu = ad5820_focus_menu, > + }, > +}; > + > + > +static int ad5820_init_controls(struct ad5820_device *coil) > +{ > + unsigned int i; > + > + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); > + > + /* > + * V4L2_CID_FOCUS_ABSOLUTE > + * > + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is > + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] > + * for focus position, because it is meaningless for user. Meaningful > + * would be to use focus distance or even its inverse, but since the > + * driver doesn't have sufficiently knowledge to do the conversion, we > + * will just use abstract codes here. In any case, smaller value = focus > + * position farther from camera. The default zero value means focus at > + * infinity, and also least current consumption. > + */ > + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, > + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); > + > + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ > + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) > + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); > + > + if (coil->ctrls.error) > + return coil->ctrls.error; > + > + coil->focus_absolute = 0; > + coil->focus_ramp_time = 0; > + coil->focus_ramp_mode = 0; > + > + coil->subdev.ctrl_handler = &coil->ctrls; > + return 0; > +} > + > +/* > + * V4L2 subdev operations > + */ > +static int ad5820_registered(struct v4l2_subdev *subdev) > +{ > + struct ad5820_device *coil = to_ad5820_device(subdev); > + struct i2c_client *client = v4l2_get_subdevdata(subdev); > + > + coil->vana = regulator_get(&client->dev, "VANA"); devm_regulator_get()? > + if (IS_ERR(coil->vana)) { > + dev_err(&client->dev, "could not get regulator for vana\n"); > + return -ENODEV; > + } > + > + return ad5820_init_controls(coil); > +} > + > +static int > +ad5820_set_power(struct v4l2_subdev *subdev, int on) > +{ > + struct ad5820_device *coil = to_ad5820_device(subdev); > + int ret = 0; > + > + mutex_lock(&coil->power_lock); > + > + /* > + * If the power count is modified from 0 to != 0 or from != 0 to 0, > + * update the power state. > + */ > + if (coil->power_count == !on) { > + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); > + if (ret < 0) > + goto done; > + } > + > + /* Update the power count. */ > + coil->power_count += on ? 1 : -1; > + WARN_ON(coil->power_count < 0); > + > +done: > + mutex_unlock(&coil->power_lock); > + return ret; > +} > + > +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) > +{ > + return ad5820_set_power(sd, 1); > +} > + > +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) > +{ > + return ad5820_set_power(sd, 0); > +} > + > +static const struct v4l2_subdev_core_ops ad5820_core_ops = { > + .s_power = ad5820_set_power, > +}; > + > +static const struct v4l2_subdev_ops ad5820_ops = { > + .core = &ad5820_core_ops, > +}; > + > +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { > + .registered = ad5820_registered, > + .open = ad5820_open, > + .close = ad5820_close, > +}; > + > +/* > + * I2C driver > + */ > +#ifdef CONFIG_PM > + > +static int ad5820_suspend(struct device *dev) > +{ > + struct i2c_client *client = container_of(dev, struct i2c_client, dev); > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + if (!coil->power_count) > + return 0; > + > + return ad5820_power_off(coil, 0); > +} > + > +static int ad5820_resume(struct device *dev) > +{ > + struct i2c_client *client = container_of(dev, struct i2c_client, dev); > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + if (!coil->power_count) > + return 0; > + > + return ad5820_power_on(coil, 1); > +} > + > +#else > + > +#define ad5820_suspend NULL > +#define ad5820_resume NULL > + > +#endif /* CONFIG_PM */ > + > +static int ad5820_probe(struct i2c_client *client, > + const struct i2c_device_id *devid) > +{ > + struct ad5820_device *coil; > + int ret = 0; > + > + coil = kzalloc(sizeof(*coil), GFP_KERNEL); devm_kzalloc() ? > + if (coil == NULL) > + return -ENOMEM; > + > + mutex_init(&coil->power_lock); > + > + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); > + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; > + coil->subdev.internal_ops = &ad5820_internal_ops; > + strcpy(coil->subdev.name, "ad5820 focus"); > + > + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); > + if (ret < 0) > + goto free; > + > + ret = v4l2_async_register_subdev(&coil->subdev); > + if (ret < 0) > + goto cleanup; > + > + return ret; > +cleanup: > + media_entity_cleanup(&coil->subdev.entity); > +free: > + kfree(coil); > + return ret; > +} > + > +static int __exit ad5820_remove(struct i2c_client *client) > +{ > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + v4l2_device_unregister_subdev(&coil->subdev); > + v4l2_ctrl_handler_free(&coil->ctrls); > + media_entity_cleanup(&coil->subdev.entity); > + if (coil->vana) > + regulator_put(coil->vana); > + > + kfree(coil); > + return 0; > +} > + > +static const struct i2c_device_id ad5820_id_table[] = { > + { AD5820_NAME, 0 }, > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); > + > +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); > + > +static struct i2c_driver ad5820_i2c_driver = { > + .driver = { > + .name = AD5820_NAME, > + .pm = &ad5820_pm, > + }, > + .probe = ad5820_probe, > + .remove = __exit_p(ad5820_remove), > + .id_table = ad5820_id_table, > +}; > + > +module_i2c_driver(ad5820_i2c_driver); > + > +MODULE_AUTHOR("Tuukka Toivonen"); > +MODULE_DESCRIPTION("AD5820 camera lens driver"); > +MODULE_LICENSE("GPL"); > diff --git a/include/media/ad5820.h b/include/media/ad5820.h > new file mode 100644 > index 0000000..f5a1565 > --- /dev/null > +++ b/include/media/ad5820.h > @@ -0,0 +1,70 @@ > +/* > + * include/media/ad5820.h > + * > + * Copyright (C) 2008 Nokia Corporation > + * Copyright (C) 2007 Texas Instruments > + * > + * Contact: Tuukka Toivonen <tuukka.o.toivonen@nokia.com> > + * Sakari Ailus <sakari.ailus@nokia.com> > + * > + * Based on af_d88.c by Texas Instruments. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * version 2 as published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, but > + * WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA > + * 02110-1301 USA > + */ > + > +#ifndef AD5820_H > +#define AD5820_H > + > +#include <linux/i2c.h> > +#include <linux/mutex.h> > +#include <linux/videodev2.h> > + > +#include <media/v4l2-ctrls.h> > +#include <media/v4l2-subdev.h> > + > +struct regulator; > + > +#define AD5820_NAME "ad5820" > +#define AD5820_I2C_ADDR (0x18 >> 1) > + > +/* Register definitions */ > +#define AD5820_POWER_DOWN (1 << 15) > +#define AD5820_DAC_SHIFT 4 Do those defines really belong here? Isn't it better if they are moved to ad5820.c? > +#define AD5820_RAMP_MODE_LINEAR (0 << 3) > +#define AD5820_RAMP_MODE_64_16 (1 << 3) > + > +struct ad5820_platform_data { > + int (*set_xshutdown)(struct v4l2_subdev *subdev, int set); > +}; > + > +#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) > + > +struct ad5820_device { > + struct v4l2_subdev subdev; > + struct ad5820_platform_data *platform_data; > + struct regulator *vana; > + > + struct v4l2_ctrl_handler ctrls; > + u32 focus_absolute; > + u32 focus_ramp_time; > + u32 focus_ramp_mode; > + > + struct mutex power_lock; > + int power_count; > + > + int standby : 1; > +}; > + The same for struct ad5820_device, is it really part of the public API? > +#endif /* AD5820_H */ > > > ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv3] support for AD5820 camera auto-focus coil 2016-05-21 11:43 ` Ivaylo Dimitrov @ 2016-05-23 7:41 ` Pali Rohár 2016-05-24 9:04 ` Pavel Machek 1 sibling, 0 replies; 73+ messages in thread From: Pali Rohár @ 2016-05-23 7:41 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus On Saturday 21 May 2016 14:43:43 Ivaylo Dimitrov wrote: > >diff --git a/include/media/ad5820.h b/include/media/ad5820.h > >new file mode 100644 > >index 0000000..f5a1565 > >--- /dev/null > >+++ b/include/media/ad5820.h > >@@ -0,0 +1,70 @@ > >+/* > >+ * include/media/ad5820.h > >+ * > >+ * Copyright (C) 2008 Nokia Corporation > >+ * Copyright (C) 2007 Texas Instruments > >+ * > >+ * Contact: Tuukka Toivonen <tuukka.o.toivonen@nokia.com> > >+ * Sakari Ailus <sakari.ailus@nokia.com> > >+ * > >+ * Based on af_d88.c by Texas Instruments. > >+ * > >+ * This program is free software; you can redistribute it and/or > >+ * modify it under the terms of the GNU General Public License > >+ * version 2 as published by the Free Software Foundation. > >+ * > >+ * This program is distributed in the hope that it will be useful, but > >+ * WITHOUT ANY WARRANTY; without even the implied warranty of > >+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > >+ * General Public License for more details. > >+ * > >+ * You should have received a copy of the GNU General Public License > >+ * along with this program; if not, write to the Free Software > >+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA > >+ * 02110-1301 USA > >+ */ > >+ > >+#ifndef AD5820_H > >+#define AD5820_H > >+ > >+#include <linux/i2c.h> > >+#include <linux/mutex.h> > >+#include <linux/videodev2.h> > >+ > >+#include <media/v4l2-ctrls.h> > >+#include <media/v4l2-subdev.h> > >+ > >+struct regulator; > >+ > >+#define AD5820_NAME "ad5820" > >+#define AD5820_I2C_ADDR (0x18 >> 1) Maybe write I2C address is more readable form? What is reason such bit shift format? > >+/* Register definitions */ > >+#define AD5820_POWER_DOWN (1 << 15) > >+#define AD5820_DAC_SHIFT 4 > > Do those defines really belong here? Isn't it better if they are moved to > ad5820.c? For me it looks like this is private for ad5820.c. > >+#define AD5820_RAMP_MODE_LINEAR (0 << 3) > >+#define AD5820_RAMP_MODE_64_16 (1 << 3) > >+ > >+struct ad5820_platform_data { > >+ int (*set_xshutdown)(struct v4l2_subdev *subdev, int set); > >+}; This is for legacy board code support right? We need DT support for N900 as legacy board code is going to be deleted. > >+#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) > >+ > >+struct ad5820_device { > >+ struct v4l2_subdev subdev; > >+ struct ad5820_platform_data *platform_data; > >+ struct regulator *vana; > >+ > >+ struct v4l2_ctrl_handler ctrls; > >+ u32 focus_absolute; > >+ u32 focus_ramp_time; > >+ u32 focus_ramp_mode; > >+ > >+ struct mutex power_lock; > >+ int power_count; > >+ > >+ int standby : 1; > >+}; > >+ > > The same for struct ad5820_device, is it really part of the public API? Yes, this is also private for ad5820.c > >+#endif /* AD5820_H */ > > > > > > -- Pali Rohár pali.rohar@gmail.com ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv3] support for AD5820 camera auto-focus coil 2016-05-21 11:43 ` Ivaylo Dimitrov 2016-05-23 7:41 ` Pali Rohár @ 2016-05-24 9:04 ` Pavel Machek 2016-05-24 9:16 ` Ivaylo Dimitrov 2016-05-24 9:17 ` [PATCHv4] " Pavel Machek 1 sibling, 2 replies; 73+ messages in thread From: Pavel Machek @ 2016-05-24 9:04 UTC (permalink / raw) To: Ivaylo Dimitrov Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus Hi! > >+static int ad5820_registered(struct v4l2_subdev *subdev) > >+{ > >+ struct ad5820_device *coil = to_ad5820_device(subdev); > >+ struct i2c_client *client = v4l2_get_subdevdata(subdev); > >+ > >+ coil->vana = regulator_get(&client->dev, "VANA"); > > devm_regulator_get()? I'd rather avoid devm_ here. Driver is simple enough to allow it. > >+#define AD5820_RAMP_MODE_LINEAR (0 << 3) > >+#define AD5820_RAMP_MODE_64_16 (1 << 3) > >+ > >+struct ad5820_platform_data { > >+ int (*set_xshutdown)(struct v4l2_subdev *subdev, int set); > >+}; > >+ > >+#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) > >+ > >+struct ad5820_device { > >+ struct v4l2_subdev subdev; > >+ struct ad5820_platform_data *platform_data; > >+ struct regulator *vana; > >+ > >+ struct v4l2_ctrl_handler ctrls; > >+ u32 focus_absolute; > >+ u32 focus_ramp_time; > >+ u32 focus_ramp_mode; > >+ > >+ struct mutex power_lock; > >+ int power_count; > >+ > >+ int standby : 1; > >+}; > >+ > > The same for struct ad5820_device, is it really part of the public API? Let me check what can be done with it. Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv3] support for AD5820 camera auto-focus coil 2016-05-24 9:04 ` Pavel Machek @ 2016-05-24 9:16 ` Ivaylo Dimitrov 2016-05-24 20:20 ` Pavel Machek 2016-05-24 9:17 ` [PATCHv4] " Pavel Machek 1 sibling, 1 reply; 73+ messages in thread From: Ivaylo Dimitrov @ 2016-05-24 9:16 UTC (permalink / raw) To: Pavel Machek Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus On 24.05.2016 12:04, Pavel Machek wrote: > Hi! > >>> +static int ad5820_registered(struct v4l2_subdev *subdev) >>> +{ >>> + struct ad5820_device *coil = to_ad5820_device(subdev); >>> + struct i2c_client *client = v4l2_get_subdevdata(subdev); >>> + >>> + coil->vana = regulator_get(&client->dev, "VANA"); >> >> devm_regulator_get()? > > I'd rather avoid devm_ here. Driver is simple enough to allow it. > Now thinking about it, what would happen here if regulator_get() returns -EPROBE_DEFER? Wouldn't it be better to move regulator_get to the probe() function, something like: static int ad5820_probe(struct i2c_client *client, const struct i2c_device_id *devid) { struct ad5820_device *coil; int ret = 0; coil = devm_kzalloc(sizeof(*coil), GFP_KERNEL); if (coil == NULL) return -ENOMEM; coil->vana = devm_regulator_get(&client->dev, NULL); if (IS_ERR(coil->vana)) { ret = PTR_ERR(coil->vana); if (ret != -EPROBE_DEFER) dev_err(&client->dev, "could not get regulator for vana\n"); return ret; } mutex_init(&coil->power_lock); ... with the appropriate changes to remove() because of the devm API usage. >>> +#define AD5820_RAMP_MODE_LINEAR (0 << 3) >>> +#define AD5820_RAMP_MODE_64_16 (1 << 3) >>> + >>> +struct ad5820_platform_data { >>> + int (*set_xshutdown)(struct v4l2_subdev *subdev, int set); >>> +}; >>> + >>> +#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) >>> + >>> +struct ad5820_device { >>> + struct v4l2_subdev subdev; >>> + struct ad5820_platform_data *platform_data; >>> + struct regulator *vana; >>> + >>> + struct v4l2_ctrl_handler ctrls; >>> + u32 focus_absolute; >>> + u32 focus_ramp_time; >>> + u32 focus_ramp_mode; >>> + >>> + struct mutex power_lock; >>> + int power_count; >>> + >>> + int standby : 1; >>> +}; >>> + >> >> The same for struct ad5820_device, is it really part of the public API? > > Let me check what can be done with it. > Pavel > ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv3] support for AD5820 camera auto-focus coil 2016-05-24 9:16 ` Ivaylo Dimitrov @ 2016-05-24 20:20 ` Pavel Machek 2016-05-26 3:46 ` Ivaylo Dimitrov 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-05-24 20:20 UTC (permalink / raw) To: Ivaylo Dimitrov Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus Hi! > >>devm_regulator_get()? > > > >I'd rather avoid devm_ here. Driver is simple enough to allow it. > > > > Now thinking about it, what would happen here if regulator_get() returns > -EPROBE_DEFER? Wouldn't it be better to move regulator_get to the probe() > function, something like: Ok, I can do it. Oh, and don't try to complain about newlines before returns. It looks better this way. > static int ad5820_probe(struct i2c_client *client, > const struct i2c_device_id *devid) > { > struct ad5820_device *coil; > int ret = 0; > > coil = devm_kzalloc(sizeof(*coil), GFP_KERNEL); > if (coil == NULL) > return -ENOMEM; > > coil->vana = devm_regulator_get(&client->dev, NULL); > if (IS_ERR(coil->vana)) { > ret = PTR_ERR(coil->vana); > if (ret != -EPROBE_DEFER) > dev_err(&client->dev, "could not get regulator for vana\n"); > return ret; > } > > mutex_init(&coil->power_lock); > ... > > with the appropriate changes to remove() because of the devm API > usage. Something like this? diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c index f956bd3..f871366 100644 --- a/drivers/media/i2c/ad5820.c +++ b/drivers/media/i2c/ad5820.c @@ -8,7 +8,7 @@ * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> * * Contact: Tuukka Toivonen - * Sakari Ailus + * Sakari Ailus * * Based on af_d88.c by Texas Instruments. * @@ -263,13 +263,6 @@ static int ad5820_init_controls(struct ad5820_device *coil) static int ad5820_registered(struct v4l2_subdev *subdev) { struct ad5820_device *coil = to_ad5820_device(subdev); - struct i2c_client *client = v4l2_get_subdevdata(subdev); - - coil->vana = regulator_get(&client->dev, "VANA"); - if (IS_ERR(coil->vana)) { - dev_err(&client->dev, "could not get regulator for vana\n"); - return -ENODEV; - } return ad5820_init_controls(coil); } @@ -367,10 +360,18 @@ static int ad5820_probe(struct i2c_client *client, struct ad5820_device *coil; int ret = 0; - coil = kzalloc(sizeof(*coil), GFP_KERNEL); + coil = devm_kzalloc(sizeof(*coil), GFP_KERNEL); if (!coil) return -ENOMEM; + coil->vana = devm_regulator_get(&client->dev, NULL); + if (IS_ERR(coil->vana)) { + ret = PTR_ERR(coil->vana); + if (ret != -EPROBE_DEFER) + dev_err(&client->dev, "could not get regulator for vana\n"); + return ret; + } + mutex_init(&coil->power_lock); v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); @@ -390,10 +391,6 @@ static int ad5820_probe(struct i2c_client *client, cleanup: media_entity_cleanup(&coil->subdev.entity); - -free: - kfree(coil); - return ret; } @@ -405,11 +402,6 @@ static int __exit ad5820_remove(struct i2c_client *client) v4l2_device_unregister_subdev(&coil->subdev); v4l2_ctrl_handler_free(&coil->ctrls); media_entity_cleanup(&coil->subdev.entity); - if (coil->vana) - regulator_put(coil->vana); - - kfree(coil); - return 0; } -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv3] support for AD5820 camera auto-focus coil 2016-05-24 20:20 ` Pavel Machek @ 2016-05-26 3:46 ` Ivaylo Dimitrov 0 siblings, 0 replies; 73+ messages in thread From: Ivaylo Dimitrov @ 2016-05-26 3:46 UTC (permalink / raw) To: Pavel Machek Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus On 24.05.2016 23:20, Pavel Machek wrote: > Hi! > >>>> devm_regulator_get()? >>> >>> I'd rather avoid devm_ here. Driver is simple enough to allow it. >>> >> >> Now thinking about it, what would happen here if regulator_get() returns >> -EPROBE_DEFER? Wouldn't it be better to move regulator_get to the probe() >> function, something like: > > Ok, I can do it. > > Oh, and don't try to complain about newlines before returns. It looks > better this way. > All I complain about is missing empty line before a final return at the end of a function :). I guess it is a matter of preference though. >> static int ad5820_probe(struct i2c_client *client, >> const struct i2c_device_id *devid) >> { >> struct ad5820_device *coil; >> int ret = 0; >> >> coil = devm_kzalloc(sizeof(*coil), GFP_KERNEL); >> if (coil == NULL) >> return -ENOMEM; >> >> coil->vana = devm_regulator_get(&client->dev, NULL); >> if (IS_ERR(coil->vana)) { >> ret = PTR_ERR(coil->vana); >> if (ret != -EPROBE_DEFER) >> dev_err(&client->dev, "could not get regulator for vana\n"); >> return ret; >> } >> >> mutex_init(&coil->power_lock); >> ... >> >> with the appropriate changes to remove() because of the devm API >> usage. > > Something like this? > Didn't try to apply it, but yes, looks right. Besides the missing mutex_destroy(&coil->power_lock); pointed out by Sakari. > diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c > index f956bd3..f871366 100644 > --- a/drivers/media/i2c/ad5820.c > +++ b/drivers/media/i2c/ad5820.c > @@ -8,7 +8,7 @@ > * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> > * > * Contact: Tuukka Toivonen > - * Sakari Ailus > + * Sakari Ailus > * > * Based on af_d88.c by Texas Instruments. > * > @@ -263,13 +263,6 @@ static int ad5820_init_controls(struct ad5820_device *coil) > static int ad5820_registered(struct v4l2_subdev *subdev) > { > struct ad5820_device *coil = to_ad5820_device(subdev); > - struct i2c_client *client = v4l2_get_subdevdata(subdev); > - > - coil->vana = regulator_get(&client->dev, "VANA"); > - if (IS_ERR(coil->vana)) { > - dev_err(&client->dev, "could not get regulator for vana\n"); > - return -ENODEV; > - } > > return ad5820_init_controls(coil); > } > @@ -367,10 +360,18 @@ static int ad5820_probe(struct i2c_client *client, > struct ad5820_device *coil; > int ret = 0; > > - coil = kzalloc(sizeof(*coil), GFP_KERNEL); > + coil = devm_kzalloc(sizeof(*coil), GFP_KERNEL); > if (!coil) > return -ENOMEM; > > + coil->vana = devm_regulator_get(&client->dev, NULL); > + if (IS_ERR(coil->vana)) { > + ret = PTR_ERR(coil->vana); > + if (ret != -EPROBE_DEFER) > + dev_err(&client->dev, "could not get regulator for vana\n"); > + return ret; > + } > + > mutex_init(&coil->power_lock); > > v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); > @@ -390,10 +391,6 @@ static int ad5820_probe(struct i2c_client *client, > > cleanup: > media_entity_cleanup(&coil->subdev.entity); > - > -free: > - kfree(coil); > - > return ret; > } > > @@ -405,11 +402,6 @@ static int __exit ad5820_remove(struct i2c_client *client) > v4l2_device_unregister_subdev(&coil->subdev); > v4l2_ctrl_handler_free(&coil->ctrls); > media_entity_cleanup(&coil->subdev.entity); > - if (coil->vana) > - regulator_put(coil->vana); > - > - kfree(coil); > - > return 0; > } > ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCHv4] support for AD5820 camera auto-focus coil 2016-05-24 9:04 ` Pavel Machek 2016-05-24 9:16 ` Ivaylo Dimitrov @ 2016-05-24 9:17 ` Pavel Machek 2016-05-25 21:26 ` Sakari Ailus 1 sibling, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-05-24 9:17 UTC (permalink / raw) To: Ivaylo Dimitrov Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, sakari.ailus This adds support for AD5820 autofocus coil, found for example in Nokia N900 smartphone. Signed-off-by: Pavel Machek <pavel@ucw.cz> --- v2: simple cleanups, fix error paths, simplify probe v3: more cleanups, remove printk, add include v4: remove header file. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 993dc50..77313a1 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 To compile this driver as a module, choose M here: the module will be called ml86v7667. +config VIDEO_AD5820 + tristate "AD5820 lens voice coil support" + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + ---help--- + This is a driver for the AD5820 camera lens voice coil. + It is used for example in Nokia N900 (RX-51). + config VIDEO_SAA7110 tristate "Philips SAA7110 video decoder" depends on VIDEO_V4L2 && I2C diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 94f2c99..34434ae 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c new file mode 100644 index 0000000..f956bd3 --- /dev/null +++ b/drivers/media/i2c/ad5820.c @@ -0,0 +1,438 @@ +/* + * drivers/media/i2c/ad5820.c + * + * AD5820 DAC driver for camera voice coil focus. + * + * Copyright (C) 2008 Nokia Corporation + * Copyright (C) 2007 Texas Instruments + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> + * + * Contact: Tuukka Toivonen + * Sakari Ailus + * + * Based on af_d88.c by Texas Instruments. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/regulator/consumer.h> + +#include <media/v4l2-device.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-subdev.h> + +#define AD5820_NAME "ad5820" + +/* Register definitions */ +#define AD5820_POWER_DOWN (1 << 15) +#define AD5820_DAC_SHIFT 4 +#define AD5820_RAMP_MODE_LINEAR (0 << 3) +#define AD5820_RAMP_MODE_64_16 (1 << 3) + +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) + +#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) + +struct ad5820_device { + struct v4l2_subdev subdev; + struct ad5820_platform_data *platform_data; + struct regulator *vana; + + struct v4l2_ctrl_handler ctrls; + u32 focus_absolute; + u32 focus_ramp_time; + u32 focus_ramp_mode; + + struct mutex power_lock; + int power_count; + + int standby : 1; +}; + +/** + * @brief I2C write using i2c_transfer(). + * @param coil - the driver data structure + * @param data - register value to be written + * @returns nonnegative on success, negative if failed + */ +static int ad5820_write(struct ad5820_device *coil, u16 data) +{ + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); + struct i2c_msg msg; + int r; + + if (!client->adapter) + return -ENODEV; + + data = cpu_to_be16(data); + msg.addr = client->addr; + msg.flags = 0; + msg.len = 2; + msg.buf = (u8 *)&data; + + r = i2c_transfer(client->adapter, &msg, 1); + if (r < 0) { + dev_err(&client->dev, "write failed, error %d\n", r); + return r; + } + + return 0; +} + +/* + * Calculate status word and write it to the device based on current + * values of V4L2 controls. It is assumed that the stored V4L2 control + * values are properly limited and rounded. + */ +static int ad5820_update_hw(struct ad5820_device *coil) +{ + u16 status; + + status = RAMP_US_TO_CODE(coil->focus_ramp_time); + status |= coil->focus_ramp_mode + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; + status |= coil->focus_absolute << AD5820_DAC_SHIFT; + + if (coil->standby) + status |= AD5820_POWER_DOWN; + + return ad5820_write(coil, status); +} + +/* + * Power handling + */ +static int ad5820_power_off(struct ad5820_device *coil, int standby) +{ + int ret = 0; + + /* + * Go to standby first as real power off my be denied by the hardware + * (single power line control for both coil and sensor). + */ + if (standby) { + coil->standby = 1; + ret = ad5820_update_hw(coil); + } + + ret |= regulator_disable(coil->vana); + + return ret; +} + +static int ad5820_power_on(struct ad5820_device *coil, int restore) +{ + int ret; + + ret = regulator_enable(coil->vana); + if (ret < 0) + return ret; + + if (restore) { + /* Restore the hardware settings. */ + coil->standby = 0; + ret = ad5820_update_hw(coil); + if (ret) + goto fail; + } + return 0; + +fail: + coil->standby = 1; + regulator_disable(coil->vana); + + return ret; +} + +/* + * V4L2 controls + */ +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ad5820_device *coil = + container_of(ctrl->handler, struct ad5820_device, ctrls); + u32 code; + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + coil->focus_absolute = ctrl->val; + return ad5820_update_hw(coil); + + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: + code = RAMP_US_TO_CODE(ctrl->val); + ctrl->val = CODE_TO_RAMP_US(code); + coil->focus_ramp_time = ctrl->val; + break; + + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: + coil->focus_ramp_mode = ctrl->val; + break; + } + + return 0; +} + +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { + .s_ctrl = ad5820_set_ctrl, +}; + +static const char * const ad5820_focus_menu[] = { + "Linear ramp", + "64/16 ramp", +}; + +static const struct v4l2_ctrl_config ad5820_ctrls[] = { + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Focus ramping time [us]", + .min = 0, + .max = 3200, + .step = 50, + .def = 0, + .flags = 0, + }, + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, + .type = V4L2_CTRL_TYPE_MENU, + .name = "Focus ramping mode", + .min = 0, + .max = ARRAY_SIZE(ad5820_focus_menu), + .step = 0, + .def = 0, + .flags = 0, + .qmenu = ad5820_focus_menu, + }, +}; + + +static int ad5820_init_controls(struct ad5820_device *coil) +{ + unsigned int i; + + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); + + /* + * V4L2_CID_FOCUS_ABSOLUTE + * + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] + * for focus position, because it is meaningless for user. Meaningful + * would be to use focus distance or even its inverse, but since the + * driver doesn't have sufficiently knowledge to do the conversion, we + * will just use abstract codes here. In any case, smaller value = focus + * position farther from camera. The default zero value means focus at + * infinity, and also least current consumption. + */ + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); + + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); + + if (coil->ctrls.error) + return coil->ctrls.error; + + coil->focus_absolute = 0; + coil->focus_ramp_time = 0; + coil->focus_ramp_mode = 0; + + coil->subdev.ctrl_handler = &coil->ctrls; + + return 0; +} + +/* + * V4L2 subdev operations + */ +static int ad5820_registered(struct v4l2_subdev *subdev) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + struct i2c_client *client = v4l2_get_subdevdata(subdev); + + coil->vana = regulator_get(&client->dev, "VANA"); + if (IS_ERR(coil->vana)) { + dev_err(&client->dev, "could not get regulator for vana\n"); + return -ENODEV; + } + + return ad5820_init_controls(coil); +} + +static int +ad5820_set_power(struct v4l2_subdev *subdev, int on) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + int ret = 0; + + mutex_lock(&coil->power_lock); + + /* + * If the power count is modified from 0 to != 0 or from != 0 to 0, + * update the power state. + */ + if (coil->power_count == !on) { + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); + if (ret < 0) + goto done; + } + + /* Update the power count. */ + coil->power_count += on ? 1 : -1; + WARN_ON(coil->power_count < 0); + +done: + mutex_unlock(&coil->power_lock); + return ret; +} + +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 1); +} + +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 0); +} + +static const struct v4l2_subdev_core_ops ad5820_core_ops = { + .s_power = ad5820_set_power, +}; + +static const struct v4l2_subdev_ops ad5820_ops = { + .core = &ad5820_core_ops, +}; + +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { + .registered = ad5820_registered, + .open = ad5820_open, + .close = ad5820_close, +}; + +/* + * I2C driver + */ +#ifdef CONFIG_PM + +static int ad5820_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_off(coil, 0); +} + +static int ad5820_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_on(coil, 1); +} + +#else + +#define ad5820_suspend NULL +#define ad5820_resume NULL + +#endif /* CONFIG_PM */ + +static int ad5820_probe(struct i2c_client *client, + const struct i2c_device_id *devid) +{ + struct ad5820_device *coil; + int ret = 0; + + coil = kzalloc(sizeof(*coil), GFP_KERNEL); + if (!coil) + return -ENOMEM; + + mutex_init(&coil->power_lock); + + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + coil->subdev.internal_ops = &ad5820_internal_ops; + strcpy(coil->subdev.name, "ad5820 focus"); + + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); + if (ret < 0) + goto free; + + ret = v4l2_async_register_subdev(&coil->subdev); + if (ret < 0) + goto cleanup; + + return ret; + +cleanup: + media_entity_cleanup(&coil->subdev.entity); + +free: + kfree(coil); + + return ret; +} + +static int __exit ad5820_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + v4l2_device_unregister_subdev(&coil->subdev); + v4l2_ctrl_handler_free(&coil->ctrls); + media_entity_cleanup(&coil->subdev.entity); + if (coil->vana) + regulator_put(coil->vana); + + kfree(coil); + + return 0; +} + +static const struct i2c_device_id ad5820_id_table[] = { + { AD5820_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); + +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); + +static struct i2c_driver ad5820_i2c_driver = { + .driver = { + .name = AD5820_NAME, + .pm = &ad5820_pm, + }, + .probe = ad5820_probe, + .remove = __exit_p(ad5820_remove), + .id_table = ad5820_id_table, +}; + +module_i2c_driver(ad5820_i2c_driver); + +MODULE_AUTHOR("Tuukka Toivonen"); +MODULE_DESCRIPTION("AD5820 camera lens driver"); +MODULE_LICENSE("GPL"); -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv4] support for AD5820 camera auto-focus coil 2016-05-24 9:17 ` [PATCHv4] " Pavel Machek @ 2016-05-25 21:26 ` Sakari Ailus 2016-05-27 20:33 ` Pavel Machek 2016-05-27 20:51 ` [PATCHv5] " Pavel Machek 0 siblings, 2 replies; 73+ messages in thread From: Sakari Ailus @ 2016-05-25 21:26 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab Hi Pavel, Thanks for your continued work on this! :-) Some quite minor comments below. I think we're good then. On Tue, May 24, 2016 at 11:17:46AM +0200, Pavel Machek wrote: > This adds support for AD5820 autofocus coil, found for example in > Nokia N900 smartphone. > > Signed-off-by: Pavel Machek <pavel@ucw.cz> > > --- > v2: simple cleanups, fix error paths, simplify probe > v3: more cleanups, remove printk, add include > v4: remove header file. > > diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig > index 993dc50..77313a1 100644 > --- a/drivers/media/i2c/Kconfig > +++ b/drivers/media/i2c/Kconfig > @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 > To compile this driver as a module, choose M here: the > module will be called ml86v7667. > > +config VIDEO_AD5820 > + tristate "AD5820 lens voice coil support" > + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER > + ---help--- > + This is a driver for the AD5820 camera lens voice coil. > + It is used for example in Nokia N900 (RX-51). > + > config VIDEO_SAA7110 > tristate "Philips SAA7110 video decoder" > depends on VIDEO_V4L2 && I2C > diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile > index 94f2c99..34434ae 100644 > --- a/drivers/media/i2c/Makefile > +++ b/drivers/media/i2c/Makefile > @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o > obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o > obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o > obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o > +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o > obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o > obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o > obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o > diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c > new file mode 100644 > index 0000000..f956bd3 > --- /dev/null > +++ b/drivers/media/i2c/ad5820.c > @@ -0,0 +1,438 @@ > +/* > + * drivers/media/i2c/ad5820.c > + * > + * AD5820 DAC driver for camera voice coil focus. > + * > + * Copyright (C) 2008 Nokia Corporation > + * Copyright (C) 2007 Texas Instruments > + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> > + * > + * Contact: Tuukka Toivonen > + * Sakari Ailus Could you put the e-mail addresses back, please? Tuukka's e-mail is tuukkat76 at gmail.com . > + * > + * Based on af_d88.c by Texas Instruments. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * version 2 as published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, but > + * WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * General Public License for more details. > + */ > + > +#include <linux/module.h> > +#include <linux/errno.h> > +#include <linux/i2c.h> > +#include <linux/kernel.h> > +#include <linux/regulator/consumer.h> Alphabetical order would be nice. The same below. > + > +#include <media/v4l2-device.h> > +#include <media/v4l2-ctrls.h> > +#include <media/v4l2-subdev.h> > + > +#define AD5820_NAME "ad5820" > + > +/* Register definitions */ > +#define AD5820_POWER_DOWN (1 << 15) > +#define AD5820_DAC_SHIFT 4 > +#define AD5820_RAMP_MODE_LINEAR (0 << 3) > +#define AD5820_RAMP_MODE_64_16 (1 << 3) > + > +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) > +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) > + > +#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) > + > +struct ad5820_device { > + struct v4l2_subdev subdev; > + struct ad5820_platform_data *platform_data; > + struct regulator *vana; > + > + struct v4l2_ctrl_handler ctrls; > + u32 focus_absolute; > + u32 focus_ramp_time; > + u32 focus_ramp_mode; > + > + struct mutex power_lock; > + int power_count; > + > + int standby : 1; > +}; > + > +/** > + * @brief I2C write using i2c_transfer(). > + * @param coil - the driver data structure > + * @param data - register value to be written This does not look entirely right. But you could just remove the entire comment. It's useless. > + * @returns nonnegative on success, negative if failed > + */ > +static int ad5820_write(struct ad5820_device *coil, u16 data) > +{ > + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); > + struct i2c_msg msg; > + int r; > + > + if (!client->adapter) > + return -ENODEV; > + > + data = cpu_to_be16(data); > + msg.addr = client->addr; > + msg.flags = 0; > + msg.len = 2; > + msg.buf = (u8 *)&data; > + > + r = i2c_transfer(client->adapter, &msg, 1); > + if (r < 0) { > + dev_err(&client->dev, "write failed, error %d\n", r); > + return r; > + } > + > + return 0; > +} > + > +/* > + * Calculate status word and write it to the device based on current > + * values of V4L2 controls. It is assumed that the stored V4L2 control > + * values are properly limited and rounded. > + */ > +static int ad5820_update_hw(struct ad5820_device *coil) > +{ > + u16 status; > + > + status = RAMP_US_TO_CODE(coil->focus_ramp_time); > + status |= coil->focus_ramp_mode > + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; > + status |= coil->focus_absolute << AD5820_DAC_SHIFT; > + > + if (coil->standby) > + status |= AD5820_POWER_DOWN; > + > + return ad5820_write(coil, status); > +} > + > +/* > + * Power handling > + */ > +static int ad5820_power_off(struct ad5820_device *coil, int standby) > +{ > + int ret = 0; > + > + /* > + * Go to standby first as real power off my be denied by the hardware > + * (single power line control for both coil and sensor). > + */ > + if (standby) { > + coil->standby = 1; > + ret = ad5820_update_hw(coil); > + } > + > + ret |= regulator_disable(coil->vana); This is actually an error code and you shouldn't use or to combine two error codes. The result will make no sense. It might be the driver did this in the past but it should not be done. The right thing, as elsewhere, is to assign the value to ret and check it. The assigment in declaration may be dropped as well. I think this happens in a few places in the driver. > + > + return ret; > +} > + > +static int ad5820_power_on(struct ad5820_device *coil, int restore) > +{ > + int ret; > + > + ret = regulator_enable(coil->vana); > + if (ret < 0) > + return ret; > + > + if (restore) { > + /* Restore the hardware settings. */ > + coil->standby = 0; > + ret = ad5820_update_hw(coil); > + if (ret) > + goto fail; > + } > + return 0; > + > +fail: > + coil->standby = 1; > + regulator_disable(coil->vana); > + > + return ret; > +} > + > +/* > + * V4L2 controls > + */ > +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) > +{ > + struct ad5820_device *coil = > + container_of(ctrl->handler, struct ad5820_device, ctrls); > + u32 code; > + > + switch (ctrl->id) { > + case V4L2_CID_FOCUS_ABSOLUTE: > + coil->focus_absolute = ctrl->val; > + return ad5820_update_hw(coil); > + > + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: > + code = RAMP_US_TO_CODE(ctrl->val); > + ctrl->val = CODE_TO_RAMP_US(code); > + coil->focus_ramp_time = ctrl->val; > + break; > + > + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: > + coil->focus_ramp_mode = ctrl->val; > + break; > + } > + > + return 0; > +} > + > +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { > + .s_ctrl = ad5820_set_ctrl, > +}; > + > +static const char * const ad5820_focus_menu[] = { > + "Linear ramp", > + "64/16 ramp", > +}; > + > +static const struct v4l2_ctrl_config ad5820_ctrls[] = { > + { > + .ops = &ad5820_ctrl_ops, > + .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, > + .type = V4L2_CTRL_TYPE_INTEGER, > + .name = "Focus ramping time [us]", > + .min = 0, > + .max = 3200, > + .step = 50, > + .def = 0, > + .flags = 0, > + }, > + { > + .ops = &ad5820_ctrl_ops, > + .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, > + .type = V4L2_CTRL_TYPE_MENU, > + .name = "Focus ramping mode", > + .min = 0, > + .max = ARRAY_SIZE(ad5820_focus_menu), > + .step = 0, > + .def = 0, > + .flags = 0, > + .qmenu = ad5820_focus_menu, > + }, > +}; > + > + > +static int ad5820_init_controls(struct ad5820_device *coil) > +{ > + unsigned int i; > + > + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); > + > + /* > + * V4L2_CID_FOCUS_ABSOLUTE > + * > + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is > + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] > + * for focus position, because it is meaningless for user. Meaningful > + * would be to use focus distance or even its inverse, but since the > + * driver doesn't have sufficiently knowledge to do the conversion, we > + * will just use abstract codes here. In any case, smaller value = focus > + * position farther from camera. The default zero value means focus at > + * infinity, and also least current consumption. > + */ > + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, > + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); > + > + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ > + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) > + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); > + > + if (coil->ctrls.error) > + return coil->ctrls.error; > + > + coil->focus_absolute = 0; > + coil->focus_ramp_time = 0; > + coil->focus_ramp_mode = 0; > + > + coil->subdev.ctrl_handler = &coil->ctrls; > + > + return 0; > +} > + > +/* > + * V4L2 subdev operations > + */ > +static int ad5820_registered(struct v4l2_subdev *subdev) > +{ > + struct ad5820_device *coil = to_ad5820_device(subdev); > + struct i2c_client *client = v4l2_get_subdevdata(subdev); > + > + coil->vana = regulator_get(&client->dev, "VANA"); Is there a reason not to acquire this in probe instead? > + if (IS_ERR(coil->vana)) { > + dev_err(&client->dev, "could not get regulator for vana\n"); > + return -ENODEV; I wonder if -EPROBE_DEFER might be the right error code here. > + } > + > + return ad5820_init_controls(coil); > +} > + > +static int > +ad5820_set_power(struct v4l2_subdev *subdev, int on) > +{ > + struct ad5820_device *coil = to_ad5820_device(subdev); > + int ret = 0; > + > + mutex_lock(&coil->power_lock); > + > + /* > + * If the power count is modified from 0 to != 0 or from != 0 to 0, > + * update the power state. > + */ > + if (coil->power_count == !on) { > + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); > + if (ret < 0) > + goto done; > + } > + > + /* Update the power count. */ > + coil->power_count += on ? 1 : -1; > + WARN_ON(coil->power_count < 0); > + > +done: > + mutex_unlock(&coil->power_lock); > + return ret; > +} > + > +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) > +{ > + return ad5820_set_power(sd, 1); > +} > + > +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) > +{ > + return ad5820_set_power(sd, 0); > +} > + > +static const struct v4l2_subdev_core_ops ad5820_core_ops = { > + .s_power = ad5820_set_power, > +}; > + > +static const struct v4l2_subdev_ops ad5820_ops = { > + .core = &ad5820_core_ops, > +}; > + > +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { > + .registered = ad5820_registered, > + .open = ad5820_open, > + .close = ad5820_close, > +}; > + > +/* > + * I2C driver > + */ > +#ifdef CONFIG_PM > + > +static int ad5820_suspend(struct device *dev) > +{ > + struct i2c_client *client = container_of(dev, struct i2c_client, dev); > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + if (!coil->power_count) > + return 0; > + > + return ad5820_power_off(coil, 0); > +} > + > +static int ad5820_resume(struct device *dev) > +{ > + struct i2c_client *client = container_of(dev, struct i2c_client, dev); > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + if (!coil->power_count) > + return 0; > + > + return ad5820_power_on(coil, 1); > +} > + > +#else > + > +#define ad5820_suspend NULL > +#define ad5820_resume NULL > + > +#endif /* CONFIG_PM */ > + > +static int ad5820_probe(struct i2c_client *client, > + const struct i2c_device_id *devid) > +{ > + struct ad5820_device *coil; > + int ret = 0; No need to assign ret here. > + > + coil = kzalloc(sizeof(*coil), GFP_KERNEL); You could use devm_kzalloc() here and drop kfree() below and in _remove(). The driver might be actually older than the devm_*() functions. Not sure. At least they were not widely used back then. :-) > + if (!coil) > + return -ENOMEM; > + > + mutex_init(&coil->power_lock); > + > + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); > + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; > + coil->subdev.internal_ops = &ad5820_internal_ops; > + strcpy(coil->subdev.name, "ad5820 focus"); > + > + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); > + if (ret < 0) > + goto free; > + > + ret = v4l2_async_register_subdev(&coil->subdev); > + if (ret < 0) > + goto cleanup; > + > + return ret; > + > +cleanup: > + media_entity_cleanup(&coil->subdev.entity); > + > +free: > + kfree(coil); > + > + return ret; > +} > + > +static int __exit ad5820_remove(struct i2c_client *client) > +{ > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > + struct ad5820_device *coil = to_ad5820_device(subdev); > + > + v4l2_device_unregister_subdev(&coil->subdev); > + v4l2_ctrl_handler_free(&coil->ctrls); > + media_entity_cleanup(&coil->subdev.entity); > + if (coil->vana) > + regulator_put(coil->vana); mutex_destroy(&coil->power_lock); Here. And in probe() error paths as well. > + > + kfree(coil); > + > + return 0; > +} > + > +static const struct i2c_device_id ad5820_id_table[] = { > + { AD5820_NAME, 0 }, > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); > + > +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); > + > +static struct i2c_driver ad5820_i2c_driver = { > + .driver = { > + .name = AD5820_NAME, > + .pm = &ad5820_pm, > + }, > + .probe = ad5820_probe, > + .remove = __exit_p(ad5820_remove), > + .id_table = ad5820_id_table, > +}; > + > +module_i2c_driver(ad5820_i2c_driver); > + > +MODULE_AUTHOR("Tuukka Toivonen"); > +MODULE_DESCRIPTION("AD5820 camera lens driver"); > +MODULE_LICENSE("GPL"); -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv4] support for AD5820 camera auto-focus coil 2016-05-25 21:26 ` Sakari Ailus @ 2016-05-27 20:33 ` Pavel Machek 2016-05-27 20:51 ` [PATCHv5] " Pavel Machek 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-05-27 20:33 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab Hi! > > + * Contact: Tuukka Toivonen > > + * Sakari Ailus > > Could you put the e-mail addresses back, please? > > Tuukka's e-mail is tuukkat76 at gmail.com . Ok. > > +#include <linux/module.h> > > +#include <linux/errno.h> > > +#include <linux/i2c.h> > > +#include <linux/kernel.h> > > +#include <linux/regulator/consumer.h> > > Alphabetical order would be nice. The same below. I was afraid you'd ask. Ok. > > +/** > > + * @brief I2C write using i2c_transfer(). > > + * @param coil - the driver data structure > > + * @param data - register value to be written > > This does not look entirely right. But you could just remove the entire > comment. It's useless. Ok. > > + int ret = 0; > > + > > + /* > > + * Go to standby first as real power off my be denied by the hardware > > + * (single power line control for both coil and sensor). > > + */ > > + if (standby) { > > + coil->standby = 1; > > + ret = ad5820_update_hw(coil); > > + } > > + > > + ret |= regulator_disable(coil->vana); > > This is actually an error code and you shouldn't use or to combine two error > codes. The result will make no sense. > > It might be the driver did this in the past but it should not be done. The > right thing, as elsewhere, is to assign the value to ret and check it. The > assigment in declaration may be dropped as well. Yeah, its broken. Let me fix it. > I think this happens in a few places in the driver. Actually this was the only place left. > > + struct ad5820_device *coil = to_ad5820_device(subdev); > > + struct i2c_client *client = v4l2_get_subdevdata(subdev); > > + > > + coil->vana = regulator_get(&client->dev, "VANA"); > > Is there a reason not to acquire this in probe instead? Yeah, new version will do that (already done, Dmitry was faster). > > + if (IS_ERR(coil->vana)) { > > + dev_err(&client->dev, "could not get regulator for vana\n"); > > + return -ENODEV; > > I wonder if -EPROBE_DEFER might be the right error code here. ..and should handle PROBE_DEFER, too. > > +static int ad5820_probe(struct i2c_client *client, > > + const struct i2c_device_id *devid) > > +{ > > + struct ad5820_device *coil; > > + int ret = 0; > > No need to assign ret here. Ok. > > + > > + coil = kzalloc(sizeof(*coil), GFP_KERNEL); > > You could use devm_kzalloc() here and drop kfree() below and in _remove(). > > The driver might be actually older than the devm_*() functions. Not sure. At > least they were not widely used back then. :-) Already done, Dmitry was faster. > > +static int __exit ad5820_remove(struct i2c_client *client) > > +{ > > + struct v4l2_subdev *subdev = i2c_get_clientdata(client); > > + struct ad5820_device *coil = to_ad5820_device(subdev); > > + > > + v4l2_device_unregister_subdev(&coil->subdev); > > + v4l2_ctrl_handler_free(&coil->ctrls); > > + media_entity_cleanup(&coil->subdev.entity); > > + if (coil->vana) > > + regulator_put(coil->vana); > > mutex_destroy(&coil->power_lock); > > Here. And in probe() error paths as well. Ok. Can do, altrough it is pretty much a NOP in the error paths. Thanks, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCHv5] support for AD5820 camera auto-focus coil 2016-05-25 21:26 ` Sakari Ailus 2016-05-27 20:33 ` Pavel Machek @ 2016-05-27 20:51 ` Pavel Machek 2016-05-31 21:22 ` Sakari Ailus ` (4 more replies) 1 sibling, 5 replies; 73+ messages in thread From: Pavel Machek @ 2016-05-27 20:51 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab This adds support for AD5820 autofocus coil, found for example in Nokia N900 smartphone. Signed-off-by: Pavel Machek <pavel@ucw.cz> --- v2: simple cleanups, fix error paths, simplify probe v3: more cleanups, remove printk, add include v4: remove header file. v5: switch to devm_ , style cleanups, fixes diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 993dc50..77313a1 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 To compile this driver as a module, choose M here: the module will be called ml86v7667. +config VIDEO_AD5820 + tristate "AD5820 lens voice coil support" + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + ---help--- + This is a driver for the AD5820 camera lens voice coil. + It is used for example in Nokia N900 (RX-51). + config VIDEO_SAA7110 tristate "Philips SAA7110 video decoder" depends on VIDEO_V4L2 && I2C index 94f2c99..34434ae 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c new file mode 100644 index 0000000..2efa5dc1 --- /dev/null +++ b/drivers/media/i2c/ad5820.c @@ -0,0 +1,428 @@ +/* + * drivers/media/i2c/ad5820.c + * + * AD5820 DAC driver for camera voice coil focus. + * + * Copyright (C) 2008 Nokia Corporation + * Copyright (C) 2007 Texas Instruments + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> + * + * Contact: Tuukka Toivonen <tuukkat76@gmail.com> + * Sakari Ailus <sakari.ailus@iki.fi> + * + * Based on af_d88.c by Texas Instruments. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include <linux/errno.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/regulator/consumer.h> + +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-subdev.h> + +#define AD5820_NAME "ad5820" + +/* Register definitions */ +#define AD5820_POWER_DOWN (1 << 15) +#define AD5820_DAC_SHIFT 4 +#define AD5820_RAMP_MODE_LINEAR (0 << 3) +#define AD5820_RAMP_MODE_64_16 (1 << 3) + +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) + +#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) + +struct ad5820_device { + struct v4l2_subdev subdev; + struct ad5820_platform_data *platform_data; + struct regulator *vana; + + struct v4l2_ctrl_handler ctrls; + u32 focus_absolute; + u32 focus_ramp_time; + u32 focus_ramp_mode; + + struct mutex power_lock; + int power_count; + + int standby : 1; +}; + +static int ad5820_write(struct ad5820_device *coil, u16 data) +{ + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); + struct i2c_msg msg; + int r; + + if (!client->adapter) + return -ENODEV; + + data = cpu_to_be16(data); + msg.addr = client->addr; + msg.flags = 0; + msg.len = 2; + msg.buf = (u8 *)&data; + + r = i2c_transfer(client->adapter, &msg, 1); + if (r < 0) { + dev_err(&client->dev, "write failed, error %d\n", r); + return r; + } + + return 0; +} + +/* + * Calculate status word and write it to the device based on current + * values of V4L2 controls. It is assumed that the stored V4L2 control + * values are properly limited and rounded. + */ +static int ad5820_update_hw(struct ad5820_device *coil) +{ + u16 status; + + status = RAMP_US_TO_CODE(coil->focus_ramp_time); + status |= coil->focus_ramp_mode + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; + status |= coil->focus_absolute << AD5820_DAC_SHIFT; + + if (coil->standby) + status |= AD5820_POWER_DOWN; + + return ad5820_write(coil, status); +} + +/* + * Power handling + */ +static int ad5820_power_off(struct ad5820_device *coil, int standby) +{ + int ret = 0, ret2; + + /* + * Go to standby first as real power off my be denied by the hardware + * (single power line control for both coil and sensor). + */ + if (standby) { + coil->standby = 1; + ret = ad5820_update_hw(coil); + } + + ret2 = regulator_disable(coil->vana); + if (ret) + return ret; + return ret2; +} + +static int ad5820_power_on(struct ad5820_device *coil, int restore) +{ + int ret; + + ret = regulator_enable(coil->vana); + if (ret < 0) + return ret; + + if (restore) { + /* Restore the hardware settings. */ + coil->standby = 0; + ret = ad5820_update_hw(coil); + if (ret) + goto fail; + } + return 0; + +fail: + coil->standby = 1; + regulator_disable(coil->vana); + + return ret; +} + +/* + * V4L2 controls + */ +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ad5820_device *coil = + container_of(ctrl->handler, struct ad5820_device, ctrls); + u32 code; + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + coil->focus_absolute = ctrl->val; + return ad5820_update_hw(coil); + + case V4L2_CID_FOCUS_AD5820_RAMP_TIME: + code = RAMP_US_TO_CODE(ctrl->val); + ctrl->val = CODE_TO_RAMP_US(code); + coil->focus_ramp_time = ctrl->val; + break; + + case V4L2_CID_FOCUS_AD5820_RAMP_MODE: + coil->focus_ramp_mode = ctrl->val; + break; + } + + return 0; +} + +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { + .s_ctrl = ad5820_set_ctrl, +}; + +static const char * const ad5820_focus_menu[] = { + "Linear ramp", + "64/16 ramp", +}; + +static const struct v4l2_ctrl_config ad5820_ctrls[] = { + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Focus ramping time [us]", + .min = 0, + .max = 3200, + .step = 50, + .def = 0, + .flags = 0, + }, + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, + .type = V4L2_CTRL_TYPE_MENU, + .name = "Focus ramping mode", + .min = 0, + .max = ARRAY_SIZE(ad5820_focus_menu), + .step = 0, + .def = 0, + .flags = 0, + .qmenu = ad5820_focus_menu, + }, +}; + + +static int ad5820_init_controls(struct ad5820_device *coil) +{ + unsigned int i; + + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); + + /* + * V4L2_CID_FOCUS_ABSOLUTE + * + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] + * for focus position, because it is meaningless for user. Meaningful + * would be to use focus distance or even its inverse, but since the + * driver doesn't have sufficiently knowledge to do the conversion, we + * will just use abstract codes here. In any case, smaller value = focus + * position farther from camera. The default zero value means focus at + * infinity, and also least current consumption. + */ + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); + + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); + + if (coil->ctrls.error) + return coil->ctrls.error; + + coil->focus_absolute = 0; + coil->focus_ramp_time = 0; + coil->focus_ramp_mode = 0; + + coil->subdev.ctrl_handler = &coil->ctrls; + + return 0; +} + +/* + * V4L2 subdev operations + */ +static int ad5820_registered(struct v4l2_subdev *subdev) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + + return ad5820_init_controls(coil); +} + +static int +ad5820_set_power(struct v4l2_subdev *subdev, int on) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + int ret = 0; + + mutex_lock(&coil->power_lock); + + /* + * If the power count is modified from 0 to != 0 or from != 0 to 0, + * update the power state. + */ + if (coil->power_count == !on) { + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); + if (ret < 0) + goto done; + } + + /* Update the power count. */ + coil->power_count += on ? 1 : -1; + WARN_ON(coil->power_count < 0); + +done: + mutex_unlock(&coil->power_lock); + return ret; +} + +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 1); +} + +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 0); +} + +static const struct v4l2_subdev_core_ops ad5820_core_ops = { + .s_power = ad5820_set_power, +}; + +static const struct v4l2_subdev_ops ad5820_ops = { + .core = &ad5820_core_ops, +}; + +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { + .registered = ad5820_registered, + .open = ad5820_open, + .close = ad5820_close, +}; + +/* + * I2C driver + */ +#ifdef CONFIG_PM + +static int ad5820_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_off(coil, 0); +} + +static int ad5820_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_on(coil, 1); +} + +#else + +#define ad5820_suspend NULL +#define ad5820_resume NULL + +#endif /* CONFIG_PM */ + +static int ad5820_probe(struct i2c_client *client, + const struct i2c_device_id *devid) +{ + struct ad5820_device *coil; + int ret; + + coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); + if (!coil) + return -ENOMEM; + + coil->vana = devm_regulator_get(&client->dev, "VANA"); + if (IS_ERR(coil->vana)) { + ret = PTR_ERR(coil->vana); + if (ret != -EPROBE_DEFER) + dev_err(&client->dev, "could not get regulator for vana\n"); + return ret; + } + + mutex_init(&coil->power_lock); + + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + coil->subdev.internal_ops = &ad5820_internal_ops; + strcpy(coil->subdev.name, "ad5820 focus"); + + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); + if (ret < 0) + goto cleanup2; + + ret = v4l2_async_register_subdev(&coil->subdev); + if (ret < 0) + goto cleanup; + + return ret; + +cleanup2: + mutex_destroy(&coil->power_lock); +cleanup: + media_entity_cleanup(&coil->subdev.entity); + return ret; +} + +static int __exit ad5820_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + v4l2_device_unregister_subdev(&coil->subdev); + v4l2_ctrl_handler_free(&coil->ctrls); + media_entity_cleanup(&coil->subdev.entity); + mutex_destroy(&coil->power_lock); + return 0; +} + +static const struct i2c_device_id ad5820_id_table[] = { + { AD5820_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); + +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); + +static struct i2c_driver ad5820_i2c_driver = { + .driver = { + .name = AD5820_NAME, + .pm = &ad5820_pm, + }, + .probe = ad5820_probe, + .remove = __exit_p(ad5820_remove), + .id_table = ad5820_id_table, +}; + +module_i2c_driver(ad5820_i2c_driver); + +MODULE_AUTHOR("Tuukka Toivonen"); +MODULE_DESCRIPTION("AD5820 camera lens driver"); +MODULE_LICENSE("GPL"); -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-05-27 20:51 ` [PATCHv5] " Pavel Machek @ 2016-05-31 21:22 ` Sakari Ailus 2016-05-31 21:34 ` Pavel Machek 2016-06-04 23:27 ` [PATCHv5] support " kbuild test robot ` (3 subsequent siblings) 4 siblings, 1 reply; 73+ messages in thread From: Sakari Ailus @ 2016-05-31 21:22 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab Hi Pavel, On Fri, May 27, 2016 at 10:51:40PM +0200, Pavel Machek wrote: > > This adds support for AD5820 autofocus coil, found for example in > Nokia N900 smartphone. > > Signed-off-by: Pavel Machek <pavel@ucw.cz> The patch looks good to me but then I came to think of a question I've missed so far: is there DT documentation somewhere for the properties used by the driver? I might put that to a separate patch, and cc the relevant list. Whether we decide to have the module in DT or not is orthogonal to this. -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-05-31 21:22 ` Sakari Ailus @ 2016-05-31 21:34 ` Pavel Machek 2016-06-01 15:24 ` Sakari Ailus 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-05-31 21:34 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Wed 2016-06-01 00:22:22, Sakari Ailus wrote: > Hi Pavel, > > On Fri, May 27, 2016 at 10:51:40PM +0200, Pavel Machek wrote: > > > > This adds support for AD5820 autofocus coil, found for example in > > Nokia N900 smartphone. > > > > Signed-off-by: Pavel Machek <pavel@ucw.cz> > > The patch looks good to me but then I came to think of a question I've > missed so far: is there DT documentation somewhere for the properties used > by the driver? I might put that to a separate patch, and cc the relevant > list. Well, it does not use any dt properties. So there's not really much to discuss with dt people... Maybe "ad5820" needs to go to list of simple i2c drivers somewhere, but... Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-05-31 21:34 ` Pavel Machek @ 2016-06-01 15:24 ` Sakari Ailus 2016-06-01 22:08 ` Pavel Machek 0 siblings, 1 reply; 73+ messages in thread From: Sakari Ailus @ 2016-06-01 15:24 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab Hi Pavel, On Tue, May 31, 2016 at 11:34:37PM +0200, Pavel Machek wrote: > On Wed 2016-06-01 00:22:22, Sakari Ailus wrote: > > Hi Pavel, > > > > On Fri, May 27, 2016 at 10:51:40PM +0200, Pavel Machek wrote: > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > Nokia N900 smartphone. > > > > > > Signed-off-by: Pavel Machek <pavel@ucw.cz> > > > > The patch looks good to me but then I came to think of a question I've > > missed so far: is there DT documentation somewhere for the properties used > > by the driver? I might put that to a separate patch, and cc the relevant > > list. > > Well, it does not use any dt properties. So there's not really much to > discuss with dt people... > > Maybe "ad5820" needs to go to list of simple i2c drivers somewhere, > but... It's an I2C device and it does use a regulator. Not a lot, though, these are both quite basic stuff. This should still be documented as the people who write the DT bindings (in general) aren't expected to read driver code as well. That's at least my understanding. -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-06-01 15:24 ` Sakari Ailus @ 2016-06-01 22:08 ` Pavel Machek 2016-06-02 7:45 ` Sakari Ailus 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-01 22:08 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Wed 2016-06-01 18:24:39, Sakari Ailus wrote: > Hi Pavel, > > Well, it does not use any dt properties. So there's not really much to > > discuss with dt people... > > > > Maybe "ad5820" needs to go to list of simple i2c drivers somewhere, > > but... > > It's an I2C device and it does use a regulator. Not a lot, though, these are > both quite basic stuff. This should still be documented as the people who > write the DT bindings (in general) aren't expected to read driver code as > well. That's at least my understanding. Yep, you are right, I forgot about the regulator. Something like this? Thanks, Pavel diff --git a/Documentation/devicetree/bindings/media/i2c/ad5820.txt b/Documentation/devicetree/bindings/media/i2c/ad5820.txt new file mode 100644 index 0000000..87c98f1 --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/ad5820.txt @@ -0,0 +1,20 @@ +* Analog Devices AD5820 autofocus coil + +Required Properties: + + - compatible: Must contain "adi,ad5820" + + - reg: I2C slave address + + - VANA-supply: supply of voltage for VANA pin + +Example: + + /* D/A converter for auto-focus */ + ad5820: dac@0c { + compatible = "adi,ad5820"; + reg = <0x0c>; + + VANA-supply = <&vaux4>; + }; + -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-06-01 22:08 ` Pavel Machek @ 2016-06-02 7:45 ` Sakari Ailus 2016-06-02 19:27 ` Pavel Machek 2016-06-02 19:30 ` [PATCH] device tree description " Pavel Machek 0 siblings, 2 replies; 73+ messages in thread From: Sakari Ailus @ 2016-06-02 7:45 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Thu, Jun 02, 2016 at 12:08:40AM +0200, Pavel Machek wrote: > On Wed 2016-06-01 18:24:39, Sakari Ailus wrote: > > Hi Pavel, > > > > Well, it does not use any dt properties. So there's not really much to > > > discuss with dt people... > > > > > > Maybe "ad5820" needs to go to list of simple i2c drivers somewhere, > > > but... > > > > It's an I2C device and it does use a regulator. Not a lot, though, these are > > both quite basic stuff. This should still be documented as the people who > > write the DT bindings (in general) aren't expected to read driver code as > > well. That's at least my understanding. > > Yep, you are right, I forgot about the regulator. Something like this? > > Thanks, > Pavel > > diff --git a/Documentation/devicetree/bindings/media/i2c/ad5820.txt b/Documentation/devicetree/bindings/media/i2c/ad5820.txt > new file mode 100644 > index 0000000..87c98f1 > --- /dev/null > +++ b/Documentation/devicetree/bindings/media/i2c/ad5820.txt I might use the compatible string as such as a part of the file name. Up to you. > @@ -0,0 +1,20 @@ > +* Analog Devices AD5820 autofocus coil > + > +Required Properties: > + > + - compatible: Must contain "adi,ad5820" > + > + - reg: I2C slave address > + > + - VANA-supply: supply of voltage for VANA pin > + > +Example: > + > + /* D/A converter for auto-focus */ There is definitely D/A conversion happening there but I'm not sure I'd characterise the device as such. They're typically called "voice coil drivers", perhaps because the devices are similar to a parts of a loudspeaker. > + ad5820: dac@0c { > + compatible = "adi,ad5820"; > + reg = <0x0c>; > + > + VANA-supply = <&vaux4>; > + }; > + > > -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-06-02 7:45 ` Sakari Ailus @ 2016-06-02 19:27 ` Pavel Machek 2016-06-02 21:23 ` Sakari Ailus 2016-06-02 19:30 ` [PATCH] device tree description " Pavel Machek 1 sibling, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-02 19:27 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Thu 2016-06-02 10:45:45, Sakari Ailus wrote: > On Thu, Jun 02, 2016 at 12:08:40AM +0200, Pavel Machek wrote: > > On Wed 2016-06-01 18:24:39, Sakari Ailus wrote: > > > Hi Pavel, > > > > > > Well, it does not use any dt properties. So there's not really much to > > > > discuss with dt people... > > > > > > > > Maybe "ad5820" needs to go to list of simple i2c drivers somewhere, > > > > but... > > > > > > It's an I2C device and it does use a regulator. Not a lot, though, these are > > > both quite basic stuff. This should still be documented as the people who > > > write the DT bindings (in general) aren't expected to read driver code as > > > well. That's at least my understanding. > > > > Yep, you are right, I forgot about the regulator. Something like this? > > > > Thanks, > > Pavel > > > > diff --git a/Documentation/devicetree/bindings/media/i2c/ad5820.txt b/Documentation/devicetree/bindings/media/i2c/ad5820.txt > > new file mode 100644 > > index 0000000..87c98f1 > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/media/i2c/ad5820.txt > > I might use the compatible string as such as a part of the file name. Up to > you. Sorry, can't do that, for consistency with other ad* files in the directory. > > @@ -0,0 +1,20 @@ > > +* Analog Devices AD5820 autofocus coil > > + > > +Required Properties: > > + > > + - compatible: Must contain "adi,ad5820" > > + > > + - reg: I2C slave address > > + > > + - VANA-supply: supply of voltage for VANA pin > > + > > +Example: > > + > > + /* D/A converter for auto-focus */ > > There is definitely D/A conversion happening there but I'm not sure I'd > characterise the device as such. They're typically called "voice coil > drivers", perhaps because the devices are similar to a parts of a > loudspeaker. Well, I'm pretty sure I did not invent that comment, but I can drop it. Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-06-02 19:27 ` Pavel Machek @ 2016-06-02 21:23 ` Sakari Ailus 0 siblings, 0 replies; 73+ messages in thread From: Sakari Ailus @ 2016-06-02 21:23 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Thu, Jun 02, 2016 at 09:27:37PM +0200, Pavel Machek wrote: > On Thu 2016-06-02 10:45:45, Sakari Ailus wrote: > > On Thu, Jun 02, 2016 at 12:08:40AM +0200, Pavel Machek wrote: > > > On Wed 2016-06-01 18:24:39, Sakari Ailus wrote: > > > > Hi Pavel, > > > > > > > > Well, it does not use any dt properties. So there's not really much to > > > > > discuss with dt people... > > > > > > > > > > Maybe "ad5820" needs to go to list of simple i2c drivers somewhere, > > > > > but... > > > > > > > > It's an I2C device and it does use a regulator. Not a lot, though, these are > > > > both quite basic stuff. This should still be documented as the people who > > > > write the DT bindings (in general) aren't expected to read driver code as > > > > well. That's at least my understanding. > > > > > > Yep, you are right, I forgot about the regulator. Something like this? > > > > > > Thanks, > > > Pavel > > > > > > diff --git a/Documentation/devicetree/bindings/media/i2c/ad5820.txt b/Documentation/devicetree/bindings/media/i2c/ad5820.txt > > > new file mode 100644 > > > index 0000000..87c98f1 > > > --- /dev/null > > > +++ b/Documentation/devicetree/bindings/media/i2c/ad5820.txt > > > > I might use the compatible string as such as a part of the file name. Up to > > you. > > Sorry, can't do that, for consistency with other ad* files in the directory. > > > > @@ -0,0 +1,20 @@ > > > +* Analog Devices AD5820 autofocus coil > > > + > > > +Required Properties: > > > + > > > + - compatible: Must contain "adi,ad5820" > > > + > > > + - reg: I2C slave address > > > + > > > + - VANA-supply: supply of voltage for VANA pin > > > + > > > +Example: > > > + > > > + /* D/A converter for auto-focus */ > > > > There is definitely D/A conversion happening there but I'm not sure I'd > > characterise the device as such. They're typically called "voice coil > > drivers", perhaps because the devices are similar to a parts of a > > loudspeaker. > > Well, I'm pretty sure I did not invent that comment, but I can drop > it. Both are fine for me. -- Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCH] device tree description for AD5820 camera auto-focus coil 2016-06-02 7:45 ` Sakari Ailus 2016-06-02 19:27 ` Pavel Machek @ 2016-06-02 19:30 ` Pavel Machek 2016-06-02 21:27 ` Sakari Ailus ` (2 more replies) 1 sibling, 3 replies; 73+ messages in thread From: Pavel Machek @ 2016-06-02 19:30 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Add documentation for ad5820 device tree binding. Signed-off-by: Pavel Machek <pavel@denx.de> diff --git a/Documentation/devicetree/bindings/media/i2c/ad5820.txt b/Documentation/devicetree/bindings/media/i2c/ad5820.txt new file mode 100644 index 0000000..fb70ca5 --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/ad5820.txt @@ -0,0 +1,19 @@ +* Analog Devices AD5820 autofocus coil + +Required Properties: + + - compatible: Must contain "adi,ad5820" + + - reg: I2C slave address + + - VANA-supply: supply of voltage for VANA pin + +Example: + + ad5820: coil@0c { + compatible = "adi,ad5820"; + reg = <0x0c>; + + VANA-supply = <&vaux4>; + }; + -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCH] device tree description for AD5820 camera auto-focus coil 2016-06-02 19:30 ` [PATCH] device tree description " Pavel Machek @ 2016-06-02 21:27 ` Sakari Ailus 2016-06-03 6:19 ` Pavel Machek 2016-06-05 19:07 ` [PATCH] userspace API definitions for " Pavel Machek 2016-06-06 13:29 ` [PATCH] device tree description for AD5820 camera " Rob Herring 2016-06-07 7:10 ` [PATCHv2] " Pavel Machek 2 siblings, 2 replies; 73+ messages in thread From: Sakari Ailus @ 2016-06-02 21:27 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree On Thu, Jun 02, 2016 at 09:30:27PM +0200, Pavel Machek wrote: > > Add documentation for ad5820 device tree binding. > > Signed-off-by: Pavel Machek <pavel@denx.de> Thanks, Pavel!! Can I pick the two patches (this one + the driver) or would you like to send a pull request? In the latter case you can add: Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> -- Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] device tree description for AD5820 camera auto-focus coil 2016-06-02 21:27 ` Sakari Ailus @ 2016-06-03 6:19 ` Pavel Machek 2016-06-05 19:07 ` [PATCH] userspace API definitions for " Pavel Machek 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-06-03 6:19 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree On Fri 2016-06-03 00:27:46, Sakari Ailus wrote: > On Thu, Jun 02, 2016 at 09:30:27PM +0200, Pavel Machek wrote: > > > > Add documentation for ad5820 device tree binding. > > > > Signed-off-by: Pavel Machek <pavel@denx.de> > > Thanks, Pavel!! > > Can I pick the two patches (this one + the driver) or would you like to send > a pull request? In the latter case you can add: Yes please, pick up the two patches. Best regards, Pavel > Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> > -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCH] userspace API definitions for auto-focus coil 2016-06-02 21:27 ` Sakari Ailus 2016-06-03 6:19 ` Pavel Machek @ 2016-06-05 19:07 ` Pavel Machek 2016-06-06 6:06 ` Ivaylo Dimitrov 1 sibling, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-05 19:07 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Add userspace API definitions. Signed-off-by: Pavel Machek <pavel@ucw.cz> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index b6a357a..23011cc 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ +#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) +#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_FOCUS_AD5820_BASE+0) +#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) + #endif -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-05 19:07 ` [PATCH] userspace API definitions for " Pavel Machek @ 2016-06-06 6:06 ` Ivaylo Dimitrov 2016-06-06 7:21 ` Pavel Machek 2016-06-11 22:06 ` Sakari Ailus 0 siblings, 2 replies; 73+ messages in thread From: Ivaylo Dimitrov @ 2016-06-06 6:06 UTC (permalink / raw) To: Pavel Machek, Sakari Ailus Cc: pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi, On 5.06.2016 22:07, Pavel Machek wrote: > Add userspace API definitions. > > Signed-off-by: Pavel Machek <pavel@ucw.cz> > > diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > index b6a357a..23011cc 100644 > --- a/include/uapi/linux/v4l2-controls.h > +++ b/include/uapi/linux/v4l2-controls.h > @@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > +#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > +#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_FOCUS_AD5820_BASE+0) > +#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) > + > #endif > Sakari, what about adding those as standard camera controls? It seems ad5820 is not the only VCM driver to implement "antiringing" controls, http://rohmfs.rohm.com/en/products/databook/datasheet/ic/motor/mobile_module/bu64241gwz-e.pdf is another example I found by quick search. What about: #define V4L2_CID_FOCUS_STEP_MODE xxx enum v4l2_cid_focus_step_mode { V4L2_CID_FOCUS_STEP_MODE_DIRECT, V4L2_CID_FOCUS_STEP_MODE_LINEAR, V4L2_CID_FOCUS_STEP_MODE_AUTO }; #define V4L2_CID_FOCUS_STEP_TIME xxx+1 Also, how the userspace(or the kernel) is notified by v4l that there is an event? The point is - I think it is a good idea to notify when VCM has completed its movement, we can start a timer based on the current position, mode, step time etc and notify after the pre-calculated movement time. Here ftp://ftp.analog.com/pub/evalcd/AD5820_v1_0/AD5820_Quickstart.pdf can be found the modes/timings description for ad5820 along with the equations needed to calculate timings etc. Ivo ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-06 6:06 ` Ivaylo Dimitrov @ 2016-06-06 7:21 ` Pavel Machek 2016-06-11 22:06 ` Sakari Ailus 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-06-06 7:21 UTC (permalink / raw) To: Ivaylo Dimitrov Cc: Sakari Ailus, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi! > On 5.06.2016 22:07, Pavel Machek wrote: > >Add userspace API definitions. > > > >Signed-off-by: Pavel Machek <pavel@ucw.cz> > > > >diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > >index b6a357a..23011cc 100644 > >--- a/include/uapi/linux/v4l2-controls.h > >+++ b/include/uapi/linux/v4l2-controls.h > >@@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > > >+/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > >+#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > >+#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_FOCUS_AD5820_BASE+0) > >+#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) > >+ > > #endif > > > > Sakari, what about adding those as standard camera controls? It seems ad5820 > is not the only VCM driver to implement "antiringing" controls, http://rohmfs.rohm.com/en/products/databook/datasheet/ic/motor/mobile_module/bu64241gwz-e.pdf > is another example I found by quick search. Well, standartized API may be good idea... but I'd really like the driver to go in, and it looks like camera application needs to know quite a lot of details about the autofocus subsystem. > > What about: > > #define V4L2_CID_FOCUS_STEP_MODE xxx > enum v4l2_cid_focus_step_mode { > V4L2_CID_FOCUS_STEP_MODE_DIRECT, > V4L2_CID_FOCUS_STEP_MODE_LINEAR, > V4L2_CID_FOCUS_STEP_MODE_AUTO > }; > #define V4L2_CID_FOCUS_STEP_TIME xxx+1 > > Also, how the userspace(or the kernel) is notified by v4l that there is an > event? The point is - I think it is a good idea to notify when VCM has > completed its movement, we can start a timer based on the current > position, Why? Look at how fcam-dev/ works. It is not interested when movement is "done". It sets the focus to one distance, then says it to slowly refocus to another distance, and watches the stream for sharpness. When it is sharp, it computes likely lens position at the time of sharpness, and asks hardware to go back there. Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-06 6:06 ` Ivaylo Dimitrov 2016-06-06 7:21 ` Pavel Machek @ 2016-06-11 22:06 ` Sakari Ailus 2016-06-12 7:54 ` Pavel Machek 2016-06-12 8:48 ` Pavel Machek 1 sibling, 2 replies; 73+ messages in thread From: Sakari Ailus @ 2016-06-11 22:06 UTC (permalink / raw) To: Ivaylo Dimitrov Cc: Pavel Machek, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi Ivaylo, On Mon, Jun 06, 2016 at 09:06:29AM +0300, Ivaylo Dimitrov wrote: > Hi, > > On 5.06.2016 22:07, Pavel Machek wrote: > >Add userspace API definitions. > > > >Signed-off-by: Pavel Machek <pavel@ucw.cz> > > > >diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > >index b6a357a..23011cc 100644 > >--- a/include/uapi/linux/v4l2-controls.h > >+++ b/include/uapi/linux/v4l2-controls.h > >@@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > > >+/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > >+#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) Please check V4L2_CID_USER_*_BASE. That's how custom controls are handled nowadays. > >+#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_FOCUS_AD5820_BASE+0) > >+#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) > >+ > > #endif > > > > Sakari, what about adding those as standard camera controls? It seems ad5820 > is not the only VCM driver to implement "antiringing" controls, http://rohmfs.rohm.com/en/products/databook/datasheet/ic/motor/mobile_module/bu64241gwz-e.pdf > is another example I found by quick search. These controls however seem to be related to some thing else --- configuring the driver to drive the lens little by little to the target using a pre-defined step time and size. I presume it is intended for something else, most likely for performing a full search for a regular AF algorithm. I also wonder how much this functionality is used nowadays, most devices use continuous AF algorithm that has little or no use for such. It also provides no help in synchronising lens movement to exposure of the AF window. Now that I think about this, the original implementation in N900 very likely did not use either of the two controls; the device driver was still written to provide access to full capabilities of the chip. And that one had no continuous AF. > What about: > > #define V4L2_CID_FOCUS_STEP_MODE xxx > enum v4l2_cid_focus_step_mode { > V4L2_CID_FOCUS_STEP_MODE_DIRECT, > V4L2_CID_FOCUS_STEP_MODE_LINEAR, > V4L2_CID_FOCUS_STEP_MODE_AUTO > }; > #define V4L2_CID_FOCUS_STEP_TIME xxx+1 > > Also, how the userspace(or the kernel) is notified by v4l that there is an > event? The point is - I think it is a good idea to notify when VCM has > completed its movement, we can start a timer based on the current position, > mode, step time etc and notify after the pre-calculated movement time. You'd have to start modelling the movement of the lens somehow. And for that, we'd need to know about the lens and the spring in the kernel, too. I presume that's already a lot of the algorithm to get the lens moving, and supposing this is in the kernel, what else would go to the kernel? These device provide very basic functionality for moving the lens; current is applied on a coil and that has the effect of moving the lens, bringing the focus distance closer as more current is applied but that's pretty much it: there's no reliable way to focus at a particular distance for example. I might as well drop the two controls, up to you. If someone ever needs them they can always be reintroduced. I'd be happy to get a new patch, the current driver patch does not compile (just tried) as the definitions of these controls are missing. Ringing compensation functionality present in the other chip should be far more useful. If there are AF experts reading this, feel free to challenge me. :-) I can't claim to be one. -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-11 22:06 ` Sakari Ailus @ 2016-06-12 7:54 ` Pavel Machek 2016-06-17 21:28 ` Sakari Ailus 2016-06-12 8:48 ` Pavel Machek 1 sibling, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-12 7:54 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi! > > >@@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > > > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > > > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > > > > >+/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > > >+#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > > Please check V4L2_CID_USER_*_BASE. That's how custom controls are handled > nowadays. Let me see... > Now that I think about this, the original implementation in N900 very likely > did not use either of the two controls; the device driver was still written > to provide access to full capabilities of the chip. And that one had no > continuous AF. I'm not sure about the original implementation, but fcam-dev library (which is our best chance for usable camera) does use both: pavel@duo:~/g/fcam-dev$ grep -ri RAMP_TIME . ./.svn/pristine/05/0574680922f59e07bd49e16a951d69421690a323.svn-base: int val = ioctlSet(V4L2_CID_FOCUS_AD5820_RAMP_TIME, 1000000.0f/diopterRateToTickRate(speed)); ./src/N900/Lens.cpp: int val = ioctlSet(V4L2_CID_FOCUS_AD5820_RAMP_TIME, 1000000.0f/diopterRateToTickRate(speed)); pavel@duo:~/g/fcam-dev$ grep -ri RAMP_MODE . ./.svn/pristine/05/0574680922f59e07bd49e16a951d69421690a323.svn-base: ioctlSet(V4L2_CID_FOCUS_AD5820_RAMP_MODE, 0); ./src/N900/Lens.cpp: ioctlSet(V4L2_CID_FOCUS_AD5820_RAMP_MODE, 0); pavel@duo:~/g/fcam-dev$ > I might as well drop the two controls, up to you. If someone ever needs them > they can always be reintroduced. I'd be happy to get a new patch, the > current driver patch does not compile (just tried) as the definitions of > these controls are missing. I'd prefer to keep the controls, as we have userspace using them. I got it to compile but have yet to get it to work (subdevs split, so it needs some modifications). Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-12 7:54 ` Pavel Machek @ 2016-06-17 21:28 ` Sakari Ailus 0 siblings, 0 replies; 73+ messages in thread From: Sakari Ailus @ 2016-06-17 21:28 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi Pavel, On Sun, Jun 12, 2016 at 09:54:17AM +0200, Pavel Machek wrote: > Hi! > > > > >@@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > > > > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > > > > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > > > > > > >+/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > > > >+#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > > > > Please check V4L2_CID_USER_*_BASE. That's how custom controls are handled > > nowadays. > > Let me see... > > > Now that I think about this, the original implementation in N900 very likely > > did not use either of the two controls; the device driver was still written > > to provide access to full capabilities of the chip. And that one had no > > continuous AF. > > I'm not sure about the original implementation, but fcam-dev library > (which is our best chance for usable camera) does use both: > > pavel@duo:~/g/fcam-dev$ grep -ri RAMP_TIME . > ./.svn/pristine/05/0574680922f59e07bd49e16a951d69421690a323.svn-base: > int val = ioctlSet(V4L2_CID_FOCUS_AD5820_RAMP_TIME, > 1000000.0f/diopterRateToTickRate(speed)); > ./src/N900/Lens.cpp: int val = > ioctlSet(V4L2_CID_FOCUS_AD5820_RAMP_TIME, > 1000000.0f/diopterRateToTickRate(speed)); > pavel@duo:~/g/fcam-dev$ grep -ri RAMP_MODE . > ./.svn/pristine/05/0574680922f59e07bd49e16a951d69421690a323.svn-base: > ioctlSet(V4L2_CID_FOCUS_AD5820_RAMP_MODE, 0); > ./src/N900/Lens.cpp: ioctlSet(V4L2_CID_FOCUS_AD5820_RAMP_MODE, 0); > pavel@duo:~/g/fcam-dev$ > > > I might as well drop the two controls, up to you. If someone ever needs them > > they can always be reintroduced. I'd be happy to get a new patch, the > > current driver patch does not compile (just tried) as the definitions of > > these controls are missing. > > I'd prefer to keep the controls, as we have userspace using them. I > got it to compile but have yet to get it to work (subdevs split, so it > needs some modifications). Right. I didn't know Fcam used them. Still, using them is hardly an optimal way to control the lens (as far as camera functionality goes, using them requires less CPU time consumption though). The flash control patches should receive a proper RFC that discusses the problem area and proposes a solution. I'll write one in the near future. I think that for this particular controller it's relatively clear though: it provides very basic functionality that maps well to controls that I don't really see alternative options for that. I don't object defining standard controls for ramp mode nor time either. But I expect you to write a patch in that case. :-) -- Regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-11 22:06 ` Sakari Ailus 2016-06-12 7:54 ` Pavel Machek @ 2016-06-12 8:48 ` Pavel Machek 2016-06-12 11:22 ` Sakari Ailus 1 sibling, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-12 8:48 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi! > > >Add userspace API definitions. > > > > > >Signed-off-by: Pavel Machek <pavel@ucw.cz> > > > > > >diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > > >index b6a357a..23011cc 100644 > > >--- a/include/uapi/linux/v4l2-controls.h > > >+++ b/include/uapi/linux/v4l2-controls.h > > >@@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > > > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > > > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > > > > >+/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > > >+#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > > Please check V4L2_CID_USER_*_BASE. That's how custom controls are handled > nowadays. So something like this? Thanks, Pavel diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c index 2efa5dc1..b04b471 100644 --- a/drivers/media/i2c/ad5820.c +++ b/drivers/media/i2c/ad5820.c @@ -40,6 +40,11 @@ #define AD5820_RAMP_MODE_LINEAR (0 << 3) #define AD5820_RAMP_MODE_64_16 (1 << 3) +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ +#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_USER_AD5820_BASE+0) +#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) + + #define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) #define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index 23011cc..4b24546 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -181,6 +181,10 @@ enum v4l2_colorfx { * We reserve 16 controls for this driver. */ #define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) +/* The base for the ad5820 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_AD5820_BASE (V4L2_CID_USER_BASE + 0x1090) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ @@ -986,9 +990,4 @@ enum v4l2_detect_md_mode { #define V4L2_CID_MODE_SENSITIVITY (V4L2_CID_MODE_CLASS_BASE+6) #define V4L2_CID_MODE_OPSYSCLOCK (V4L2_CID_MODE_CLASS_BASE+7) -/* Control IDs specific to the AD5820 driver as defined by V4L2 */ -#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) -#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_FOCUS_AD5820_BASE+0) -#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) - #endif -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-12 8:48 ` Pavel Machek @ 2016-06-12 11:22 ` Sakari Ailus 2016-06-13 19:17 ` Pavel Machek 0 siblings, 1 reply; 73+ messages in thread From: Sakari Ailus @ 2016-06-12 11:22 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi Pavel, On Sun, Jun 12, 2016 at 10:48:11AM +0200, Pavel Machek wrote: > Hi! > > > > >Add userspace API definitions. > > > > > > > >Signed-off-by: Pavel Machek <pavel@ucw.cz> > > > > > > > >diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > > > >index b6a357a..23011cc 100644 > > > >--- a/include/uapi/linux/v4l2-controls.h > > > >+++ b/include/uapi/linux/v4l2-controls.h > > > >@@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > > > > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > > > > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > > > > > > >+/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > > > >+#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > > > > Please check V4L2_CID_USER_*_BASE. That's how custom controls are handled > > nowadays. > > So something like this? > > Thanks, > Pavel > > diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c > index 2efa5dc1..b04b471 100644 > --- a/drivers/media/i2c/ad5820.c > +++ b/drivers/media/i2c/ad5820.c > @@ -40,6 +40,11 @@ > #define AD5820_RAMP_MODE_LINEAR (0 << 3) > #define AD5820_RAMP_MODE_64_16 (1 << 3) > > +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > +#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_USER_AD5820_BASE+0) > +#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) > + > + We could still define these in a header file that can be included by the user space. Please use V4L2_CID_AD5820 prefix. A separate header file should be used, e.g. include/uapi/linux/ad5820.h. > #define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) > #define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) > > diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > index 23011cc..4b24546 100644 > --- a/include/uapi/linux/v4l2-controls.h > +++ b/include/uapi/linux/v4l2-controls.h > @@ -181,6 +181,10 @@ enum v4l2_colorfx { > * We reserve 16 controls for this driver. */ > #define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) > > +/* The base for the ad5820 driver controls. > + * We reserve 16 controls for this driver. */ > +#define V4L2_CID_USER_AD5820_BASE (V4L2_CID_USER_BASE + 0x1090) > + > /* MPEG-class control IDs */ > /* The MPEG controls are applicable to all codec controls > * and the 'MPEG' part of the define is historical */ > @@ -986,9 +990,4 @@ enum v4l2_detect_md_mode { > #define V4L2_CID_MODE_SENSITIVITY (V4L2_CID_MODE_CLASS_BASE+6) > #define V4L2_CID_MODE_OPSYSCLOCK (V4L2_CID_MODE_CLASS_BASE+7) > > -/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > -#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > -#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_FOCUS_AD5820_BASE+0) > -#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) > - > #endif > > -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-12 11:22 ` Sakari Ailus @ 2016-06-13 19:17 ` Pavel Machek 2016-06-17 21:35 ` Sakari Ailus 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-13 19:17 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree On Sun 2016-06-12 14:22:53, Sakari Ailus wrote: > Hi Pavel, > > On Sun, Jun 12, 2016 at 10:48:11AM +0200, Pavel Machek wrote: > > Hi! > > > > > > >Add userspace API definitions. > > > > > > > > > >Signed-off-by: Pavel Machek <pavel@ucw.cz> > > > > > > > > > >diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > > > > >index b6a357a..23011cc 100644 > > > > >--- a/include/uapi/linux/v4l2-controls.h > > > > >+++ b/include/uapi/linux/v4l2-controls.h > > > > >@@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > > > > > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > > > > > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > > > > > > > > >+/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > > > > >+#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > > > > > > Please check V4L2_CID_USER_*_BASE. That's how custom controls are handled > > > nowadays. > > > > So something like this? > > > > Thanks, > > Pavel > > > > diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c > > index 2efa5dc1..b04b471 100644 > > --- a/drivers/media/i2c/ad5820.c > > +++ b/drivers/media/i2c/ad5820.c > > @@ -40,6 +40,11 @@ > > #define AD5820_RAMP_MODE_LINEAR (0 << 3) > > #define AD5820_RAMP_MODE_64_16 (1 << 3) > > > > +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > > +#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_USER_AD5820_BASE+0) > > +#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) > > + > > + > > We could still define these in a header file that can be included by the > user space. Please use V4L2_CID_AD5820 prefix. Not V4L2_CID_USER_AD5820...? > A separate header file should be used, > e.g. include/uapi/linux/ad5820.h. Ok, separate header file for 2 lines seemed like a bit of overkill, but why not. Something like this? commit 8dd701d2580e41b06bb2285e6bd59a4f1702b4d8 Author: Pavel <pavel@ucw.cz> Date: Mon Jun 13 21:17:15 2016 +0200 Userspace api, as Sakari asked. diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c index 2efa5dc1..ed3facc 100644 --- a/drivers/media/i2c/ad5820.c +++ b/drivers/media/i2c/ad5820.c @@ -32,6 +32,8 @@ #include <media/v4l2-device.h> #include <media/v4l2-subdev.h> +#include <uapi/linux/ad5820.h> + #define AD5820_NAME "ad5820" /* Register definitions */ @@ -40,6 +42,8 @@ #define AD5820_RAMP_MODE_LINEAR (0 << 3) #define AD5820_RAMP_MODE_64_16 (1 << 3) + + #define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) #define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) @@ -165,13 +169,13 @@ static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) coil->focus_absolute = ctrl->val; return ad5820_update_hw(coil); - case V4L2_CID_FOCUS_AD5820_RAMP_TIME: + case V4L2_CID_AD5820_RAMP_TIME: code = RAMP_US_TO_CODE(ctrl->val); ctrl->val = CODE_TO_RAMP_US(code); coil->focus_ramp_time = ctrl->val; break; - case V4L2_CID_FOCUS_AD5820_RAMP_MODE: + case V4L2_CID_AD5820_RAMP_MODE: coil->focus_ramp_mode = ctrl->val; break; } @@ -191,7 +195,7 @@ static const char * const ad5820_focus_menu[] = { static const struct v4l2_ctrl_config ad5820_ctrls[] = { { .ops = &ad5820_ctrl_ops, - .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, + .id = V4L2_CID_AD5820_RAMP_TIME, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Focus ramping time [us]", .min = 0, @@ -202,7 +206,7 @@ static const struct v4l2_ctrl_config ad5820_ctrls[] = { }, { .ops = &ad5820_ctrl_ops, - .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, + .id = V4L2_CID_AD5820_RAMP_MODE, .type = V4L2_CTRL_TYPE_MENU, .name = "Focus ramping mode", .min = 0, diff --git a/include/uapi/linux/ad5820.h b/include/uapi/linux/ad5820.h new file mode 100644 index 0000000..d44ba9c --- /dev/null +++ b/include/uapi/linux/ad5820.h @@ -0,0 +1,18 @@ +/* + * AD5820 DAC driver for camera voice coil focus. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +#ifndef __LINUX_AD5820_H +#define __LINUX_AD5820_H + +#include <linux/v4l2-controls.h> + +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ +#define V4L2_CID_AD5820_RAMP_TIME (V4L2_CID_AD5820_BASE+0) +#define V4L2_CID_AD5820_RAMP_MODE (V4L2_CID_AD5820_BASE+1) + +#endif diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index 23011cc..015e90b 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -181,6 +181,10 @@ enum v4l2_colorfx { * We reserve 16 controls for this driver. */ #define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) +/* The base for the ad5820 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_AD5820_BASE (V4L2_CID_USER_BASE + 0x1090) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ @@ -986,9 +990,4 @@ enum v4l2_detect_md_mode { #define V4L2_CID_MODE_SENSITIVITY (V4L2_CID_MODE_CLASS_BASE+6) #define V4L2_CID_MODE_OPSYSCLOCK (V4L2_CID_MODE_CLASS_BASE+7) -/* Control IDs specific to the AD5820 driver as defined by V4L2 */ -#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) -#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_FOCUS_AD5820_BASE+0) -#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) - #endif -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-13 19:17 ` Pavel Machek @ 2016-06-17 21:35 ` Sakari Ailus 2016-06-18 15:37 ` [PATCHv4] support for AD5820 camera " Pavel Machek 2016-06-18 15:38 ` [PATCH] userspace API definitions for " Pavel Machek 0 siblings, 2 replies; 73+ messages in thread From: Sakari Ailus @ 2016-06-17 21:35 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi Pavel, On Mon, Jun 13, 2016 at 09:17:53PM +0200, Pavel Machek wrote: > On Sun 2016-06-12 14:22:53, Sakari Ailus wrote: > > Hi Pavel, > > > > On Sun, Jun 12, 2016 at 10:48:11AM +0200, Pavel Machek wrote: > > > Hi! > > > > > > > > >Add userspace API definitions. > > > > > > > > > > > >Signed-off-by: Pavel Machek <pavel@ucw.cz> > > > > > > > > > > > >diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > > > > > >index b6a357a..23011cc 100644 > > > > > >--- a/include/uapi/linux/v4l2-controls.h > > > > > >+++ b/include/uapi/linux/v4l2-controls.h > > > > > >@@ -974,4 +975,9 @@ enum v4l2_detect_md_mode { > > > > > > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > > > > > > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > > > > > > > > > > >+/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > > > > > >+#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > > > > > > > > Please check V4L2_CID_USER_*_BASE. That's how custom controls are handled > > > > nowadays. > > > > > > So something like this? > > > > > > Thanks, > > > Pavel > > > > > > diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c > > > index 2efa5dc1..b04b471 100644 > > > --- a/drivers/media/i2c/ad5820.c > > > +++ b/drivers/media/i2c/ad5820.c > > > @@ -40,6 +40,11 @@ > > > #define AD5820_RAMP_MODE_LINEAR (0 << 3) > > > #define AD5820_RAMP_MODE_64_16 (1 << 3) > > > > > > +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > > > +#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_USER_AD5820_BASE+0) > > > +#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) > > > + > > > + > > > > We could still define these in a header file that can be included by the > > user space. Please use V4L2_CID_AD5820 prefix. > > Not V4L2_CID_USER_AD5820...? The rest of the controls have no USER as part of the macro name, so I wouldn't use it here either. > > > A separate header file should be used, > > e.g. include/uapi/linux/ad5820.h. > > Ok, separate header file for 2 lines seemed like a bit of overkill, > but why not. That follows an existing pattern of how controls have been implemented in other drivers. > > Something like this? Yes. A few minor comments below. Could you merge this with the driver patch? I've dropped that from my ad5820 branch as it does not compile. > > commit 8dd701d2580e41b06bb2285e6bd59a4f1702b4d8 > Author: Pavel <pavel@ucw.cz> > Date: Mon Jun 13 21:17:15 2016 +0200 > > Userspace api, as Sakari asked. > > diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c > index 2efa5dc1..ed3facc 100644 > --- a/drivers/media/i2c/ad5820.c > +++ b/drivers/media/i2c/ad5820.c > @@ -32,6 +32,8 @@ > #include <media/v4l2-device.h> > #include <media/v4l2-subdev.h> > > +#include <uapi/linux/ad5820.h> > + > #define AD5820_NAME "ad5820" > > /* Register definitions */ > @@ -40,6 +42,8 @@ > #define AD5820_RAMP_MODE_LINEAR (0 << 3) > #define AD5820_RAMP_MODE_64_16 (1 << 3) > > + > + Extra newlines. > #define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) > #define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) > > @@ -165,13 +169,13 @@ static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) > coil->focus_absolute = ctrl->val; > return ad5820_update_hw(coil); > > - case V4L2_CID_FOCUS_AD5820_RAMP_TIME: > + case V4L2_CID_AD5820_RAMP_TIME: > code = RAMP_US_TO_CODE(ctrl->val); > ctrl->val = CODE_TO_RAMP_US(code); > coil->focus_ramp_time = ctrl->val; > break; > > - case V4L2_CID_FOCUS_AD5820_RAMP_MODE: > + case V4L2_CID_AD5820_RAMP_MODE: > coil->focus_ramp_mode = ctrl->val; > break; > } > @@ -191,7 +195,7 @@ static const char * const ad5820_focus_menu[] = { > static const struct v4l2_ctrl_config ad5820_ctrls[] = { > { > .ops = &ad5820_ctrl_ops, > - .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, > + .id = V4L2_CID_AD5820_RAMP_TIME, > .type = V4L2_CTRL_TYPE_INTEGER, > .name = "Focus ramping time [us]", > .min = 0, > @@ -202,7 +206,7 @@ static const struct v4l2_ctrl_config ad5820_ctrls[] = { > }, > { > .ops = &ad5820_ctrl_ops, > - .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, > + .id = V4L2_CID_AD5820_RAMP_MODE, > .type = V4L2_CTRL_TYPE_MENU, > .name = "Focus ramping mode", > .min = 0, > diff --git a/include/uapi/linux/ad5820.h b/include/uapi/linux/ad5820.h > new file mode 100644 > index 0000000..d44ba9c > --- /dev/null > +++ b/include/uapi/linux/ad5820.h > @@ -0,0 +1,18 @@ > +/* > + * AD5820 DAC driver for camera voice coil focus. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * version 2 as published by the Free Software Foundation. > + */ > + > +#ifndef __LINUX_AD5820_H > +#define __LINUX_AD5820_H > + > +#include <linux/v4l2-controls.h> > + > +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > +#define V4L2_CID_AD5820_RAMP_TIME (V4L2_CID_AD5820_BASE+0) (V4L2_CID_AD5820_BASE + 0) Same below. > +#define V4L2_CID_AD5820_RAMP_MODE (V4L2_CID_AD5820_BASE+1) > + > +#endif > diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > index 23011cc..015e90b 100644 > --- a/include/uapi/linux/v4l2-controls.h > +++ b/include/uapi/linux/v4l2-controls.h > @@ -181,6 +181,10 @@ enum v4l2_colorfx { > * We reserve 16 controls for this driver. */ > #define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) > > +/* The base for the ad5820 driver controls. > + * We reserve 16 controls for this driver. */ > +#define V4L2_CID_AD5820_BASE (V4L2_CID_USER_BASE + 0x1090) > + > /* MPEG-class control IDs */ > /* The MPEG controls are applicable to all codec controls > * and the 'MPEG' part of the define is historical */ > @@ -986,9 +990,4 @@ enum v4l2_detect_md_mode { > #define V4L2_CID_MODE_SENSITIVITY (V4L2_CID_MODE_CLASS_BASE+6) > #define V4L2_CID_MODE_OPSYSCLOCK (V4L2_CID_MODE_CLASS_BASE+7) > > -/* Control IDs specific to the AD5820 driver as defined by V4L2 */ > -#define V4L2_CID_FOCUS_AD5820_BASE (V4L2_CTRL_CLASS_CAMERA | 0x10af) > -#define V4L2_CID_FOCUS_AD5820_RAMP_TIME (V4L2_CID_FOCUS_AD5820_BASE+0) > -#define V4L2_CID_FOCUS_AD5820_RAMP_MODE (V4L2_CID_FOCUS_AD5820_BASE+1) > - > #endif > > -- Regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCHv4] support for AD5820 camera auto-focus coil 2016-06-17 21:35 ` Sakari Ailus @ 2016-06-18 15:37 ` Pavel Machek 2016-06-18 15:38 ` [PATCH] userspace API definitions for " Pavel Machek 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-06-18 15:37 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree This adds support for AD5820 autofocus coil, found for example in Nokia N900 smartphone. Signed-off-by: Pavel Machek <pavel@ucw.cz> --- v2: simple cleanups, fix error paths, simplify probe v3: more cleanups, remove printk, add include v4: add uapi definitions diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 993dc50..77313a1 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 To compile this driver as a module, choose M here: the module will be called ml86v7667. +config VIDEO_AD5820 + tristate "AD5820 lens voice coil support" + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + ---help--- + This is a driver for the AD5820 camera lens voice coil. + It is used for example in Nokia N900 (RX-51). + config VIDEO_SAA7110 tristate "Philips SAA7110 video decoder" depends on VIDEO_V4L2 && I2C diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 94f2c99..34434ae 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -19,6 +20,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c new file mode 100644 index 0000000..a1be956 --- /dev/null +++ b/drivers/media/i2c/ad5820.c @@ -0,0 +1,430 @@ +/* + * drivers/media/i2c/ad5820.c + * + * AD5820 DAC driver for camera voice coil focus. + * + * Copyright (C) 2008 Nokia Corporation + * Copyright (C) 2007 Texas Instruments + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> + * + * Contact: Tuukka Toivonen <tuukkat76@gmail.com> + * Sakari Ailus <sakari.ailus@iki.fi> + * + * Based on af_d88.c by Texas Instruments. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include <linux/errno.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/regulator/consumer.h> + +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-subdev.h> + +#include <uapi/linux/ad5820.h> + +#define AD5820_NAME "ad5820" + +/* Register definitions */ +#define AD5820_POWER_DOWN (1 << 15) +#define AD5820_DAC_SHIFT 4 +#define AD5820_RAMP_MODE_LINEAR (0 << 3) +#define AD5820_RAMP_MODE_64_16 (1 << 3) + +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) + +#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) + +struct ad5820_device { + struct v4l2_subdev subdev; + struct ad5820_platform_data *platform_data; + struct regulator *vana; + + struct v4l2_ctrl_handler ctrls; + u32 focus_absolute; + u32 focus_ramp_time; + u32 focus_ramp_mode; + + struct mutex power_lock; + int power_count; + + int standby : 1; +}; + +static int ad5820_write(struct ad5820_device *coil, u16 data) +{ + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); + struct i2c_msg msg; + int r; + + if (!client->adapter) + return -ENODEV; + + data = cpu_to_be16(data); + msg.addr = client->addr; + msg.flags = 0; + msg.len = 2; + msg.buf = (u8 *)&data; + + r = i2c_transfer(client->adapter, &msg, 1); + if (r < 0) { + dev_err(&client->dev, "write failed, error %d\n", r); + return r; + } + + return 0; +} + +/* + * Calculate status word and write it to the device based on current + * values of V4L2 controls. It is assumed that the stored V4L2 control + * values are properly limited and rounded. + */ +static int ad5820_update_hw(struct ad5820_device *coil) +{ + u16 status; + + status = RAMP_US_TO_CODE(coil->focus_ramp_time); + status |= coil->focus_ramp_mode + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; + status |= coil->focus_absolute << AD5820_DAC_SHIFT; + + if (coil->standby) + status |= AD5820_POWER_DOWN; + + return ad5820_write(coil, status); +} + +/* + * Power handling + */ +static int ad5820_power_off(struct ad5820_device *coil, int standby) +{ + int ret = 0, ret2; + + /* + * Go to standby first as real power off my be denied by the hardware + * (single power line control for both coil and sensor). + */ + if (standby) { + coil->standby = 1; + ret = ad5820_update_hw(coil); + } + + ret2 = regulator_disable(coil->vana); + if (ret) + return ret; + return ret2; +} + +static int ad5820_power_on(struct ad5820_device *coil, int restore) +{ + int ret; + + ret = regulator_enable(coil->vana); + if (ret < 0) + return ret; + + if (restore) { + /* Restore the hardware settings. */ + coil->standby = 0; + ret = ad5820_update_hw(coil); + if (ret) + goto fail; + } + return 0; + +fail: + coil->standby = 1; + regulator_disable(coil->vana); + + return ret; +} + +/* + * V4L2 controls + */ +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ad5820_device *coil = + container_of(ctrl->handler, struct ad5820_device, ctrls); + u32 code; + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + coil->focus_absolute = ctrl->val; + return ad5820_update_hw(coil); + + case V4L2_CID_AD5820_RAMP_TIME: + code = RAMP_US_TO_CODE(ctrl->val); + ctrl->val = CODE_TO_RAMP_US(code); + coil->focus_ramp_time = ctrl->val; + break; + + case V4L2_CID_AD5820_RAMP_MODE: + coil->focus_ramp_mode = ctrl->val; + break; + } + + return 0; +} + +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { + .s_ctrl = ad5820_set_ctrl, +}; + +static const char * const ad5820_focus_menu[] = { + "Linear ramp", + "64/16 ramp", +}; + +static const struct v4l2_ctrl_config ad5820_ctrls[] = { + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_AD5820_RAMP_TIME, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Focus ramping time [us]", + .min = 0, + .max = 3200, + .step = 50, + .def = 0, + .flags = 0, + }, + { + .ops = &ad5820_ctrl_ops, + .id = V4L2_CID_AD5820_RAMP_MODE, + .type = V4L2_CTRL_TYPE_MENU, + .name = "Focus ramping mode", + .min = 0, + .max = ARRAY_SIZE(ad5820_focus_menu), + .step = 0, + .def = 0, + .flags = 0, + .qmenu = ad5820_focus_menu, + }, +}; + + +static int ad5820_init_controls(struct ad5820_device *coil) +{ + unsigned int i; + + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); + + /* + * V4L2_CID_FOCUS_ABSOLUTE + * + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] + * for focus position, because it is meaningless for user. Meaningful + * would be to use focus distance or even its inverse, but since the + * driver doesn't have sufficiently knowledge to do the conversion, we + * will just use abstract codes here. In any case, smaller value = focus + * position farther from camera. The default zero value means focus at + * infinity, and also least current consumption. + */ + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); + + /* V4L2_CID_TEST_PATTERN and V4L2_CID_MODE_* */ + for (i = 0; i < ARRAY_SIZE(ad5820_ctrls); ++i) + v4l2_ctrl_new_custom(&coil->ctrls, &ad5820_ctrls[i], NULL); + + if (coil->ctrls.error) + return coil->ctrls.error; + + coil->focus_absolute = 0; + coil->focus_ramp_time = 0; + coil->focus_ramp_mode = 0; + + coil->subdev.ctrl_handler = &coil->ctrls; + + return 0; +} + +/* + * V4L2 subdev operations + */ +static int ad5820_registered(struct v4l2_subdev *subdev) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + + return ad5820_init_controls(coil); +} + +static int +ad5820_set_power(struct v4l2_subdev *subdev, int on) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + int ret = 0; + + mutex_lock(&coil->power_lock); + + /* + * If the power count is modified from 0 to != 0 or from != 0 to 0, + * update the power state. + */ + if (coil->power_count == !on) { + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); + if (ret < 0) + goto done; + } + + /* Update the power count. */ + coil->power_count += on ? 1 : -1; + WARN_ON(coil->power_count < 0); + +done: + mutex_unlock(&coil->power_lock); + return ret; +} + +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 1); +} + +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 0); +} + +static const struct v4l2_subdev_core_ops ad5820_core_ops = { + .s_power = ad5820_set_power, +}; + +static const struct v4l2_subdev_ops ad5820_ops = { + .core = &ad5820_core_ops, +}; + +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { + .registered = ad5820_registered, + .open = ad5820_open, + .close = ad5820_close, +}; + +/* + * I2C driver + */ +#ifdef CONFIG_PM + +static int ad5820_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_off(coil, 0); +} + +static int ad5820_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_on(coil, 1); +} + +#else + +#define ad5820_suspend NULL +#define ad5820_resume NULL + +#endif /* CONFIG_PM */ + +static int ad5820_probe(struct i2c_client *client, + const struct i2c_device_id *devid) +{ + struct ad5820_device *coil; + int ret; + + coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); + if (!coil) + return -ENOMEM; + + coil->vana = devm_regulator_get(&client->dev, "VANA"); + if (IS_ERR(coil->vana)) { + ret = PTR_ERR(coil->vana); + if (ret != -EPROBE_DEFER) + dev_err(&client->dev, "could not get regulator for vana\n"); + return ret; + } + + mutex_init(&coil->power_lock); + + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + coil->subdev.internal_ops = &ad5820_internal_ops; + strcpy(coil->subdev.name, "ad5820 focus"); + + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); + if (ret < 0) + goto cleanup2; + + ret = v4l2_async_register_subdev(&coil->subdev); + if (ret < 0) + goto cleanup; + + return ret; + +cleanup2: + mutex_destroy(&coil->power_lock); +cleanup: + media_entity_cleanup(&coil->subdev.entity); + return ret; +} + +static int __exit ad5820_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + v4l2_device_unregister_subdev(&coil->subdev); + v4l2_ctrl_handler_free(&coil->ctrls); + media_entity_cleanup(&coil->subdev.entity); + mutex_destroy(&coil->power_lock); + return 0; +} + +static const struct i2c_device_id ad5820_id_table[] = { + { AD5820_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); + +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); + +static struct i2c_driver ad5820_i2c_driver = { + .driver = { + .name = AD5820_NAME, + .pm = &ad5820_pm, + }, + .probe = ad5820_probe, + .remove = __exit_p(ad5820_remove), + .id_table = ad5820_id_table, +}; + +module_i2c_driver(ad5820_i2c_driver); + +MODULE_AUTHOR("Tuukka Toivonen"); +MODULE_DESCRIPTION("AD5820 camera lens driver"); +MODULE_LICENSE("GPL"); diff --git a/include/uapi/linux/ad5820.h b/include/uapi/linux/ad5820.h new file mode 100644 index 0000000..4e541e8 --- /dev/null +++ b/include/uapi/linux/ad5820.h @@ -0,0 +1,18 @@ +/* + * AD5820 DAC driver for camera voice coil focus. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +#ifndef __LINUX_AD5820_H +#define __LINUX_AD5820_H + +#include <linux/v4l2-controls.h> + +/* Control IDs specific to the AD5820 driver as defined by V4L2 */ +#define V4L2_CID_AD5820_RAMP_TIME (V4L2_CID_AD5820_BASE + 0) +#define V4L2_CID_AD5820_RAMP_MODE (V4L2_CID_AD5820_BASE + 1) + +#endif diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index b6a357a..015e90b 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -180,6 +181,10 @@ enum v4l2_colorfx { * We reserve 16 controls for this driver. */ #define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) +/* The base for the ad5820 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_AD5820_BASE (V4L2_CID_USER_BASE + 0x1090) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-17 21:35 ` Sakari Ailus 2016-06-18 15:37 ` [PATCHv4] support for AD5820 camera " Pavel Machek @ 2016-06-18 15:38 ` Pavel Machek 2016-07-12 23:32 ` Mauro Carvalho Chehab 1 sibling, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-18 15:38 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Hi! > > Not V4L2_CID_USER_AD5820...? > > The rest of the controls have no USER as part of the macro name, so I > wouldn't use it here either. Ok. > > Ok, separate header file for 2 lines seemed like a bit of overkill, > > but why not. > > That follows an existing pattern of how controls have been implemented in > other drivers. Ok. > Could you merge this with the driver patch? I've dropped that from my ad5820 > branch as it does not compile. Yes, merged patch should be in your inbox now. Thanks, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-06-18 15:38 ` [PATCH] userspace API definitions for " Pavel Machek @ 2016-07-12 23:32 ` Mauro Carvalho Chehab 2016-07-13 6:57 ` Pavel Machek 2016-07-13 7:26 ` Pavel Machek 0 siblings, 2 replies; 73+ messages in thread From: Mauro Carvalho Chehab @ 2016-07-12 23:32 UTC (permalink / raw) To: Pavel Machek Cc: Sakari Ailus, Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Em Sat, 18 Jun 2016 17:38:46 +0200 Pavel Machek <pavel@ucw.cz> escreveu: > Hi! > > > > Not V4L2_CID_USER_AD5820...? > > > > The rest of the controls have no USER as part of the macro name, so I > > wouldn't use it here either. > > Ok. > > > > Ok, separate header file for 2 lines seemed like a bit of overkill, > > > but why not. > > > > That follows an existing pattern of how controls have been implemented in > > other drivers. > > Ok. > > > Could you merge this with the driver patch? I've dropped that from my ad5820 > > branch as it does not compile. > > Yes, merged patch should be in your inbox now. The V4L2 core changes should be on a separate patch. Btw, you'll also need to patch documentation to reflect such changes. We're right now moving from DocBook to ReST markup language. The patches for it are right now on a separate topic branch (docs-next), to be merged for Kernel 4.8 on the next merge window. You should either base the patch on such branch or wait for it to be merged back mainstream to write such documentation additions. > > Thanks, > Pavel > -- Thanks, Mauro ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-07-12 23:32 ` Mauro Carvalho Chehab @ 2016-07-13 6:57 ` Pavel Machek 2016-07-13 7:26 ` Pavel Machek 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-07-13 6:57 UTC (permalink / raw) To: Mauro Carvalho Chehab Cc: Sakari Ailus, Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree On Tue 2016-07-12 20:32:01, Mauro Carvalho Chehab wrote: 1;2802;0c> Em Sat, 18 Jun 2016 17:38:46 +0200 > Pavel Machek <pavel@ucw.cz> escreveu: > > > Hi! > > > > > > Not V4L2_CID_USER_AD5820...? > > > > > > The rest of the controls have no USER as part of the macro name, so I > > > wouldn't use it here either. > > > > Ok. > > > > > > Ok, separate header file for 2 lines seemed like a bit of overkill, > > > > but why not. > > > > > > That follows an existing pattern of how controls have been implemented in > > > other drivers. > > > > Ok. > > > > > Could you merge this with the driver patch? I've dropped that from my ad5820 > > > branch as it does not compile. > > > > Yes, merged patch should be in your inbox now. > > The V4L2 core changes should be on a separate patch. Btw, you'll also > need to patch documentation to reflect such changes. We're right now > moving from DocBook to ReST markup language. The patches for it are > right now on a separate topic branch (docs-next), to be merged for > Kernel 4.8 on the next merge window. > > You should either base the patch on such branch or wait for it to be > merged back mainstream to write such documentation additions. So how many iterations and how many releases does it take to get trivial driver into the tree? I did what Sakari asked me to do. The driver is trivial. You can see pretty easily what I'm changing in the core... and it is not much. Can you just add your acked-by to it, merge it and me done with it? If some more docs is required, I can do the docs, but stalling patch for months and then claiming "hey, we have these new rules you have to follow" is not a nice thing. Thanks, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] userspace API definitions for auto-focus coil 2016-07-12 23:32 ` Mauro Carvalho Chehab 2016-07-13 6:57 ` Pavel Machek @ 2016-07-13 7:26 ` Pavel Machek 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-07-13 7:26 UTC (permalink / raw) To: Mauro Carvalho Chehab Cc: Sakari Ailus, Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree On Tue 2016-07-12 20:32:01, Mauro Carvalho Chehab wrote: > Em Sat, 18 Jun 2016 17:38:46 +0200 > Pavel Machek <pavel@ucw.cz> escreveu: > > > Hi! > > > > > > Not V4L2_CID_USER_AD5820...? > > > > > > The rest of the controls have no USER as part of the macro name, so I > > > wouldn't use it here either. > > > > Ok. > > > > > > Ok, separate header file for 2 lines seemed like a bit of overkill, > > > > but why not. > > > > > > That follows an existing pattern of how controls have been implemented in > > > other drivers. > > > > Ok. > > > > > Could you merge this with the driver patch? I've dropped that from my ad5820 > > > branch as it does not compile. > > > > Yes, merged patch should be in your inbox now. > > The V4L2 core changes should be on a separate patch. Btw, you'll also > need to patch documentation to reflect such changes. We're right now > moving from DocBook to ReST markup language. The patches for it are > right now on a separate topic branch (docs-next), to be merged for > Kernel 4.8 on the next merge window. What about: I drop all the functionality but FOCUS_ABSOLUTE, which is core functionality, anyway, and does not need core changes. When V4L2 core stabilizes, it can be reintroduced. Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH] device tree description for AD5820 camera auto-focus coil 2016-06-02 19:30 ` [PATCH] device tree description " Pavel Machek 2016-06-02 21:27 ` Sakari Ailus @ 2016-06-06 13:29 ` Rob Herring 2016-06-07 7:10 ` [PATCHv2] " Pavel Machek 2 siblings, 0 replies; 73+ messages in thread From: Rob Herring @ 2016-06-06 13:29 UTC (permalink / raw) To: Pavel Machek Cc: Sakari Ailus, Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree On Thu, Jun 02, 2016 at 09:30:27PM +0200, Pavel Machek wrote: > > Add documentation for ad5820 device tree binding. > > Signed-off-by: Pavel Machek <pavel@denx.de> > > diff --git a/Documentation/devicetree/bindings/media/i2c/ad5820.txt b/Documentation/devicetree/bindings/media/i2c/ad5820.txt > new file mode 100644 > index 0000000..fb70ca5 > --- /dev/null > +++ b/Documentation/devicetree/bindings/media/i2c/ad5820.txt > @@ -0,0 +1,19 @@ > +* Analog Devices AD5820 autofocus coil > + > +Required Properties: > + > + - compatible: Must contain "adi,ad5820" > + > + - reg: I2C slave address > + > + - VANA-supply: supply of voltage for VANA pin > + > +Example: > + > + ad5820: coil@0c { Drop the leading 0. With that, Acked-by: Rob Herring <robh@kernel.org> ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCHv2] device tree description for AD5820 camera auto-focus coil 2016-06-02 19:30 ` [PATCH] device tree description " Pavel Machek 2016-06-02 21:27 ` Sakari Ailus 2016-06-06 13:29 ` [PATCH] device tree description for AD5820 camera " Rob Herring @ 2016-06-07 7:10 ` Pavel Machek 2016-06-09 22:37 ` Sakari Ailus 2 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-07 7:10 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree Add documentation for ad5820 device tree binding. Signed-off-by: Pavel Machek <pavel@denx.de> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Rob Herring <robh@kernel.org> --- v2: Fixed nit in example, added acks. diff --git a/Documentation/devicetree/bindings/media/i2c/ad5820.txt b/Documentation/devicetree/bindings/media/i2c/ad5820.txt new file mode 100644 index 0000000..fb70ca5 --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/ad5820.txt @@ -0,0 +1,19 @@ +* Analog Devices AD5820 autofocus coil + +Required Properties: + + - compatible: Must contain "adi,ad5820" + + - reg: I2C slave address + + - VANA-supply: supply of voltage for VANA pin + +Example: + + ad5820: coil@c { + compatible = "adi,ad5820"; + reg = <0x0c>; + + VANA-supply = <&vaux4>; + }; + -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv2] device tree description for AD5820 camera auto-focus coil 2016-06-07 7:10 ` [PATCHv2] " Pavel Machek @ 2016-06-09 22:37 ` Sakari Ailus 0 siblings, 0 replies; 73+ messages in thread From: Sakari Ailus @ 2016-06-09 22:37 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, devicetree On Tue, Jun 07, 2016 at 09:10:04AM +0200, Pavel Machek wrote: > > Add documentation for ad5820 device tree binding. > > Signed-off-by: Pavel Machek <pavel@denx.de> > Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> > Acked-by: Rob Herring <robh@kernel.org> Thanks! I've replaced the patch in my tree, will send a pull req later. -- Cheers, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-05-27 20:51 ` [PATCHv5] " Pavel Machek 2016-05-31 21:22 ` Sakari Ailus @ 2016-06-04 23:27 ` kbuild test robot 2016-06-05 0:46 ` kbuild test robot ` (2 subsequent siblings) 4 siblings, 0 replies; 73+ messages in thread From: kbuild test robot @ 2016-06-04 23:27 UTC (permalink / raw) To: Pavel Machek Cc: kbuild-all, Sakari Ailus, Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab [-- Attachment #1: Type: text/plain, Size: 2160 bytes --] Hi, [auto build test ERROR on linuxtv-media/master] [also build test ERROR on v4.7-rc1 next-20160603] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Pavel-Machek/support-for-AD5820-camera-auto-focus-coil/20160528-045306 base: git://linuxtv.org/media_tree.git master config: tile-allyesconfig (attached as .config) compiler: tilegx-linux-gcc (GCC) 4.6.2 reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=tile All errors (new ones prefixed by >>): drivers/media/i2c/ad5820.c: In function 'ad5820_set_ctrl': drivers/media/i2c/ad5820.c:168:7: error: 'V4L2_CID_FOCUS_AD5820_RAMP_TIME' undeclared (first use in this function) drivers/media/i2c/ad5820.c:168:7: note: each undeclared identifier is reported only once for each function it appears in >> drivers/media/i2c/ad5820.c:174:7: error: 'V4L2_CID_FOCUS_AD5820_RAMP_MODE' undeclared (first use in this function) drivers/media/i2c/ad5820.c: At top level: drivers/media/i2c/ad5820.c:194:10: error: 'V4L2_CID_FOCUS_AD5820_RAMP_TIME' undeclared here (not in a function) drivers/media/i2c/ad5820.c:205:10: error: 'V4L2_CID_FOCUS_AD5820_RAMP_MODE' undeclared here (not in a function) vim +/V4L2_CID_FOCUS_AD5820_RAMP_MODE +174 drivers/media/i2c/ad5820.c 162 163 switch (ctrl->id) { 164 case V4L2_CID_FOCUS_ABSOLUTE: 165 coil->focus_absolute = ctrl->val; 166 return ad5820_update_hw(coil); 167 > 168 case V4L2_CID_FOCUS_AD5820_RAMP_TIME: 169 code = RAMP_US_TO_CODE(ctrl->val); 170 ctrl->val = CODE_TO_RAMP_US(code); 171 coil->focus_ramp_time = ctrl->val; 172 break; 173 > 174 case V4L2_CID_FOCUS_AD5820_RAMP_MODE: 175 coil->focus_ramp_mode = ctrl->val; 176 break; 177 } --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation [-- Attachment #2: .config.gz --] [-- Type: application/octet-stream, Size: 43906 bytes --] ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv5] support for AD5820 camera auto-focus coil 2016-05-27 20:51 ` [PATCHv5] " Pavel Machek 2016-05-31 21:22 ` Sakari Ailus 2016-06-04 23:27 ` [PATCHv5] support " kbuild test robot @ 2016-06-05 0:46 ` kbuild test robot 2016-06-12 20:41 ` [PATCH 1/1] v4l: Add camera voice coil lens control class, current control Sakari Ailus 2016-08-05 10:26 ` [PATCHv6] support for AD5820 camera auto-focus coil Pavel Machek 4 siblings, 0 replies; 73+ messages in thread From: kbuild test robot @ 2016-06-05 0:46 UTC (permalink / raw) To: Pavel Machek Cc: kbuild-all, Sakari Ailus, Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab [-- Attachment #1: Type: text/plain, Size: 3583 bytes --] Hi, [auto build test ERROR on linuxtv-media/master] [also build test ERROR on v4.7-rc1 next-20160603] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Pavel-Machek/support-for-AD5820-camera-auto-focus-coil/20160528-045306 base: git://linuxtv.org/media_tree.git master config: sh-allyesconfig (attached as .config) compiler: sh4-linux-gnu-gcc (Debian 5.3.1-8) 5.3.1 20160205 reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=sh All errors (new ones prefixed by >>): drivers/media/i2c/ad5820.c: In function 'ad5820_set_ctrl': >> drivers/media/i2c/ad5820.c:168:7: error: 'V4L2_CID_FOCUS_AD5820_RAMP_TIME' undeclared (first use in this function) case V4L2_CID_FOCUS_AD5820_RAMP_TIME: ^ drivers/media/i2c/ad5820.c:168:7: note: each undeclared identifier is reported only once for each function it appears in drivers/media/i2c/ad5820.c:174:7: error: 'V4L2_CID_FOCUS_AD5820_RAMP_MODE' undeclared (first use in this function) case V4L2_CID_FOCUS_AD5820_RAMP_MODE: ^ drivers/media/i2c/ad5820.c: At top level: >> drivers/media/i2c/ad5820.c:194:10: error: 'V4L2_CID_FOCUS_AD5820_RAMP_TIME' undeclared here (not in a function) .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, ^ >> drivers/media/i2c/ad5820.c:205:10: error: 'V4L2_CID_FOCUS_AD5820_RAMP_MODE' undeclared here (not in a function) .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, ^ drivers/media/i2c/ad5820.c:321:12: warning: 'ad5820_suspend' defined but not used [-Wunused-function] static int ad5820_suspend(struct device *dev) ^ drivers/media/i2c/ad5820.c:333:12: warning: 'ad5820_resume' defined but not used [-Wunused-function] static int ad5820_resume(struct device *dev) ^ vim +/V4L2_CID_FOCUS_AD5820_RAMP_TIME +168 drivers/media/i2c/ad5820.c 162 163 switch (ctrl->id) { 164 case V4L2_CID_FOCUS_ABSOLUTE: 165 coil->focus_absolute = ctrl->val; 166 return ad5820_update_hw(coil); 167 > 168 case V4L2_CID_FOCUS_AD5820_RAMP_TIME: 169 code = RAMP_US_TO_CODE(ctrl->val); 170 ctrl->val = CODE_TO_RAMP_US(code); 171 coil->focus_ramp_time = ctrl->val; 172 break; 173 174 case V4L2_CID_FOCUS_AD5820_RAMP_MODE: 175 coil->focus_ramp_mode = ctrl->val; 176 break; 177 } 178 179 return 0; 180 } 181 182 static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { 183 .s_ctrl = ad5820_set_ctrl, 184 }; 185 186 static const char * const ad5820_focus_menu[] = { 187 "Linear ramp", 188 "64/16 ramp", 189 }; 190 191 static const struct v4l2_ctrl_config ad5820_ctrls[] = { 192 { 193 .ops = &ad5820_ctrl_ops, > 194 .id = V4L2_CID_FOCUS_AD5820_RAMP_TIME, 195 .type = V4L2_CTRL_TYPE_INTEGER, 196 .name = "Focus ramping time [us]", 197 .min = 0, 198 .max = 3200, 199 .step = 50, 200 .def = 0, 201 .flags = 0, 202 }, 203 { 204 .ops = &ad5820_ctrl_ops, > 205 .id = V4L2_CID_FOCUS_AD5820_RAMP_MODE, 206 .type = V4L2_CTRL_TYPE_MENU, 207 .name = "Focus ramping mode", 208 .min = 0, --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation [-- Attachment #2: .config.gz --] [-- Type: application/octet-stream, Size: 39262 bytes --] ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCH 1/1] v4l: Add camera voice coil lens control class, current control 2016-05-27 20:51 ` [PATCHv5] " Pavel Machek ` (2 preceding siblings ...) 2016-06-05 0:46 ` kbuild test robot @ 2016-06-12 20:41 ` Sakari Ailus 2016-06-12 21:48 ` Ivaylo Dimitrov 2016-06-17 22:06 ` Pavel Machek 2016-08-05 10:26 ` [PATCHv6] support for AD5820 camera auto-focus coil Pavel Machek 4 siblings, 2 replies; 73+ messages in thread From: Sakari Ailus @ 2016-06-12 20:41 UTC (permalink / raw) To: pavel Cc: ivo.g.dimitrov.75, pali.rohar, sre, linux-kernel, linux-media, hverkuil, laurent.pinchart, Sakari Ailus From: Sakari Ailus <sakari.ailus@iki.fi> Add a V4L2 control class for voice coil lens driver devices. These are simple devices that are used to move a camera lens from its resting position. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> --- Hi Pavel, I also don't think the FOCUS_ABSOLUTE controls is a really good one for the voice coil lens current. I expect more voice coil lens controls (linear vs. PWM mode, ringing compensation...) to be needed so I think it's worth a new class. Cc others, too... Kind regards, Sakari Documentation/DocBook/media/v4l/controls.xml | 55 +++++++++++++++++++++++++++- include/uapi/linux/v4l2-controls.h | 7 ++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Documentation/DocBook/media/v4l/controls.xml b/Documentation/DocBook/media/v4l/controls.xml index e2e5484..aa7169c 100644 --- a/Documentation/DocBook/media/v4l/controls.xml +++ b/Documentation/DocBook/media/v4l/controls.xml @@ -5502,4 +5502,57 @@ receiving given frequency when that control is set. This is a read-only control. </tgroup> </table> </section> -</section> + + <section id="voice-coil-controls"> + <title>Voice Coil Control Reference</title> + + <para>The Voice Coil class controls are used to control voice + coil lens devices. These are very simple devices that consist of + a voice coil, a spring and a lens. The current applied on a + voice coil is used to move the lens away from the resting + position which typically is (close to) infinity.</para> + + <table pgwide="1" frame="none" id="voice-coil-control-id"> + <title>Voice Coil Control IDs</title> + + <tgroup cols="4"> + <colspec colname="c1" colwidth="1*" /> + <colspec colname="c2" colwidth="6*" /> + <colspec colname="c3" colwidth="2*" /> + <colspec colname="c4" colwidth="6*" /> + <spanspec namest="c1" nameend="c2" spanname="id" /> + <spanspec namest="c2" nameend="c4" spanname="descr" /> + <thead> + <row> + <entry spanname="id" align="left">ID</entry> + <entry align="left">Type</entry> + </row><row rowsep="1"><entry spanname="descr" align="left">Description</entry> + </row> + </thead> + <tbody valign="top"> + <row><entry></entry></row> + <row> + <entry spanname="id"><constant>V4L2_CID_VOICE_COIL_CLASS</constant> </entry> + <entry>class</entry> + </row><row><entry spanname="descr">The Voice Coil class +descriptor. Calling &VIDIOC-QUERYCTRL; for this control will return a +description of this control class.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_VOICE_COIL_CURRENT</constant> </entry> + <entry>integer</entry> + </row><row><entry spanname="descr">Current applied on a + voice coil. The more current is applied, the more is the + position of the lens moved from its resting position. Do + note that there may be a ringing effect; the lens will + oscillate after changing the current applied unless the + device implements ringing compensation. + </entry> + </row> + </tbody> + </tgroup> + </table> + + </section> + + </section> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index b6a357a..c6b1261 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -62,6 +62,7 @@ #define V4L2_CTRL_CLASS_FM_RX 0x00a10000 /* FM Receiver controls */ #define V4L2_CTRL_CLASS_RF_TUNER 0x00a20000 /* RF tuner controls */ #define V4L2_CTRL_CLASS_DETECT 0x00a30000 /* Detection controls */ +#define V4L2_CTRL_CLASS_VOICE_COIL 0x00a40000 /* Voice coil lens driver */ /* User-class control IDs */ @@ -974,4 +975,10 @@ enum v4l2_detect_md_mode { #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) +/* Voice coil lens driver control IDs defined by V4L2 */ +#define V4L2_CID_VOICE_COIL_CLASS_BASE (V4L2_CTRL_CLASS_VOICE_COIL | 0x900) +#define V4L2_CID_VOICE_COIL_CLASS (V4L2_CTRL_CLASS_VOICE_COIL | 1) + +#define V4L2_CID_VOICE_COIL_CURRENT (V4L2_CID_VOICE_COIL_CLASS_BASE + 1) + #endif -- 2.1.4 ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCH 1/1] v4l: Add camera voice coil lens control class, current control 2016-06-12 20:41 ` [PATCH 1/1] v4l: Add camera voice coil lens control class, current control Sakari Ailus @ 2016-06-12 21:48 ` Ivaylo Dimitrov 2016-06-17 22:11 ` Pavel Machek 2016-06-17 22:06 ` Pavel Machek 1 sibling, 1 reply; 73+ messages in thread From: Ivaylo Dimitrov @ 2016-06-12 21:48 UTC (permalink / raw) To: Sakari Ailus, pavel Cc: pali.rohar, sre, linux-kernel, linux-media, hverkuil, laurent.pinchart, Sakari Ailus Hi, On 12.06.2016 23:41, Sakari Ailus wrote: > From: Sakari Ailus <sakari.ailus@iki.fi> > > Add a V4L2 control class for voice coil lens driver devices. These are > simple devices that are used to move a camera lens from its resting > position. > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > --- > Hi Pavel, > > I also don't think the FOCUS_ABSOLUTE controls is a really good one for > the voice coil lens current. I expect more voice coil lens controls > (linear vs. PWM mode, ringing compensation...) to be needed so I think > it's worth a new class. > Right, I still think movement mode should be standard control :) > Cc others, too... > > Kind regards, > Sakari > > Documentation/DocBook/media/v4l/controls.xml | 55 +++++++++++++++++++++++++++- > include/uapi/linux/v4l2-controls.h | 7 ++++ > 2 files changed, 61 insertions(+), 1 deletion(-) > > diff --git a/Documentation/DocBook/media/v4l/controls.xml b/Documentation/DocBook/media/v4l/controls.xml > index e2e5484..aa7169c 100644 > --- a/Documentation/DocBook/media/v4l/controls.xml > +++ b/Documentation/DocBook/media/v4l/controls.xml > @@ -5502,4 +5502,57 @@ receiving given frequency when that control is set. This is a read-only control. > </tgroup> > </table> > </section> > -</section> > + > + <section id="voice-coil-controls"> > + <title>Voice Coil Control Reference</title> > + > + <para>The Voice Coil class controls are used to control voice > + coil lens devices. These are very simple devices that consist of > + a voice coil, a spring and a lens. The current applied on a There should be a magnet as well. > + voice coil is used to move the lens away from the resting > + position which typically is (close to) infinity.</para> > + > + <table pgwide="1" frame="none" id="voice-coil-control-id"> > + <title>Voice Coil Control IDs</title> > + > + <tgroup cols="4"> > + <colspec colname="c1" colwidth="1*" /> > + <colspec colname="c2" colwidth="6*" /> > + <colspec colname="c3" colwidth="2*" /> > + <colspec colname="c4" colwidth="6*" /> > + <spanspec namest="c1" nameend="c2" spanname="id" /> > + <spanspec namest="c2" nameend="c4" spanname="descr" /> > + <thead> > + <row> > + <entry spanname="id" align="left">ID</entry> > + <entry align="left">Type</entry> > + </row><row rowsep="1"><entry spanname="descr" align="left">Description</entry> > + </row> > + </thead> > + <tbody valign="top"> > + <row><entry></entry></row> > + <row> > + <entry spanname="id"><constant>V4L2_CID_VOICE_COIL_CLASS</constant> </entry> > + <entry>class</entry> > + </row><row><entry spanname="descr">The Voice Coil class > +descriptor. Calling &VIDIOC-QUERYCTRL; for this control will return a > +description of this control class.</entry> > + </row> > + <row> > + <entry spanname="id"><constant>V4L2_CID_VOICE_COIL_CURRENT</constant> </entry> > + <entry>integer</entry> I think this is no better than FOCUS_ABSOLUTE - nor "absolute" neither "current" give any idea where is the lens (relatively to the rest position) without userspace doing some calculations. What about V4L2_CID_VOICE_COIL_POSITION, 0.000%-100.000% (pcm units)? > + </row><row><entry spanname="descr">Current applied on a > + voice coil. The more current is applied, the more is the > + position of the lens moved from its resting position. Do > + note that there may be a ringing effect; the lens will > + oscillate after changing the current applied unless the > + device implements ringing compensation. > + </entry> > + </row> > + </tbody> > + </tgroup> > + </table> > + > + </section> > + > + </section> > diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h > index b6a357a..c6b1261 100644 > --- a/include/uapi/linux/v4l2-controls.h > +++ b/include/uapi/linux/v4l2-controls.h > @@ -62,6 +62,7 @@ > #define V4L2_CTRL_CLASS_FM_RX 0x00a10000 /* FM Receiver controls */ > #define V4L2_CTRL_CLASS_RF_TUNER 0x00a20000 /* RF tuner controls */ > #define V4L2_CTRL_CLASS_DETECT 0x00a30000 /* Detection controls */ > +#define V4L2_CTRL_CLASS_VOICE_COIL 0x00a40000 /* Voice coil lens driver */ > > /* User-class control IDs */ > > @@ -974,4 +975,10 @@ enum v4l2_detect_md_mode { > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > +/* Voice coil lens driver control IDs defined by V4L2 */ > +#define V4L2_CID_VOICE_COIL_CLASS_BASE (V4L2_CTRL_CLASS_VOICE_COIL | 0x900) > +#define V4L2_CID_VOICE_COIL_CLASS (V4L2_CTRL_CLASS_VOICE_COIL | 1) > + > +#define V4L2_CID_VOICE_COIL_CURRENT (V4L2_CID_VOICE_COIL_CLASS_BASE + 1) > + > #endif > Ivo ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH 1/1] v4l: Add camera voice coil lens control class, current control 2016-06-12 21:48 ` Ivaylo Dimitrov @ 2016-06-17 22:11 ` Pavel Machek 2016-06-17 22:39 ` Laurent Pinchart 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-06-17 22:11 UTC (permalink / raw) To: Ivaylo Dimitrov Cc: Sakari Ailus, pali.rohar, sre, linux-kernel, linux-media, hverkuil, laurent.pinchart, Sakari Ailus Hi! > >I also don't think the FOCUS_ABSOLUTE controls is a really good one for > >the voice coil lens current. I expect more voice coil lens controls > >(linear vs. PWM mode, ringing compensation...) to be needed so I think > >it's worth a new class. Well, I do agree that that the new class is fine (and have no problem with your proposal), but I'd like to understand why FOCUS_ABSOLUTE is unsuitable. I'm actually thinking about writing very simple userspace camera, without autofocus, where user would just select "infinity"/"1m"/"50cm" ... and for that FOCUS_ABSOLUTE is equivalent to VOICE_COIL_CURRENT... > Right, I still think movement mode should be standard control :) What options would you like to see for movement mode? Thanks, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH 1/1] v4l: Add camera voice coil lens control class, current control 2016-06-17 22:11 ` Pavel Machek @ 2016-06-17 22:39 ` Laurent Pinchart 2016-06-18 11:28 ` Pavel Machek 0 siblings, 1 reply; 73+ messages in thread From: Laurent Pinchart @ 2016-06-17 22:39 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, Sakari Ailus, pali.rohar, sre, linux-kernel, linux-media, hverkuil, Sakari Ailus Hello, On Saturday 18 Jun 2016 00:11:49 Pavel Machek wrote: > Hi! > > >> I also don't think the FOCUS_ABSOLUTE controls is a really good one for > >> the voice coil lens current. I expect more voice coil lens controls > >> (linear vs. PWM mode, ringing compensation...) to be needed so I think > >> it's worth a new class. > > Well, I do agree that that the new class is fine (and have no problem > with your proposal), but I'd like to understand why FOCUS_ABSOLUTE is > unsuitable. I'm actually thinking about writing very simple userspace > camera, without autofocus, where user would just select > "infinity"/"1m"/"50cm" ... and for that FOCUS_ABSOLUTE is equivalent > to VOICE_COIL_CURRENT... > > > Right, I still think movement mode should be standard control :) > > What options would you like to see for movement mode? I've discussed this with Sakari offline a few days ago. I won't nack this patch, but to ack it I'd like to have a better understanding of the big picture when it comes to focus and lens control. The proposed new control can make sense when taken in isolation, but I can't tell whether it still would when associated with the other controls that would be needed to properly control a voice coil lens. If someone has analyzed the existing voice coil lens controllers and could share the result, in term of what parameters need to be controlled by the system and how they should be controlled, that would be very appreciated. Even better would be a real userspace implementation of a voice coil lens control algorithm. -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH 1/1] v4l: Add camera voice coil lens control class, current control 2016-06-17 22:39 ` Laurent Pinchart @ 2016-06-18 11:28 ` Pavel Machek 0 siblings, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-06-18 11:28 UTC (permalink / raw) To: Laurent Pinchart Cc: Ivaylo Dimitrov, Sakari Ailus, pali.rohar, sre, linux-kernel, linux-media, hverkuil, Sakari Ailus Hi! > If someone has analyzed the existing voice coil lens controllers and could > share the result, in term of what parameters need to be controlled by the > system and how they should be controlled, that would be very appreciated. Even > better would be a real userspace implementation of a voice coil lens control > algorithm. Userspace implementation exists, it is called fcam-dev. What it does... Starts capture, selects focus speed, makes it go through focus range, looks for the sharpest image in the stream. Then it computes time when the image was sharpest and thus lens position, and goes back there. So for ad5820, we need basically focus position and focus speed. (And some 16/64 option). Other coil drivers also have PWM vs. linear option. Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCH 1/1] v4l: Add camera voice coil lens control class, current control 2016-06-12 20:41 ` [PATCH 1/1] v4l: Add camera voice coil lens control class, current control Sakari Ailus 2016-06-12 21:48 ` Ivaylo Dimitrov @ 2016-06-17 22:06 ` Pavel Machek 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-06-17 22:06 UTC (permalink / raw) To: Sakari Ailus Cc: ivo.g.dimitrov.75, pali.rohar, sre, linux-kernel, linux-media, hverkuil, laurent.pinchart, Sakari Ailus Hi! > -</section> > + > + <section id="voice-coil-controls"> > + <title>Voice Coil Control Reference</title> > + > + <para>The Voice Coil class controls are used to control voice > + coil lens devices. These are very simple devices that consist of > + a voice coil, a spring and a lens. The current applied on a "on the"? > + voice coil is used to move the lens away from the resting > + position which typically is (close to) infinity.</para> Insert explanation that this all is for autofocus somewhere? > /* User-class control IDs */ > > @@ -974,4 +975,10 @@ enum v4l2_detect_md_mode { > #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) > #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) > > +/* Voice coil lens driver control IDs defined by V4L2 */ Too many spaces after '/*'. Otherwise, you have my "acked-by". Thanks, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* [PATCHv6] support for AD5820 camera auto-focus coil 2016-05-27 20:51 ` [PATCHv5] " Pavel Machek ` (3 preceding siblings ...) 2016-06-12 20:41 ` [PATCH 1/1] v4l: Add camera voice coil lens control class, current control Sakari Ailus @ 2016-08-05 10:26 ` Pavel Machek 2016-08-05 10:30 ` Pali Rohár 2016-08-08 8:09 ` Sakari Ailus 4 siblings, 2 replies; 73+ messages in thread From: Pavel Machek @ 2016-08-05 10:26 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab This adds support for AD5820 autofocus coil, found for example in Nokia N900 smartphone. Signed-off-by: Pavel Machek <pavel@ucw.cz> --- v2: simple cleanups, fix error paths, simplify probe v3: more cleanups, remove printk, add include v4: remove header file. v5: switch to devm_ , style cleanups, fixes v6: remove new userspace APIs. Can we finally get the patch in, please? diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 993dc50..20e8e89 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -279,6 +279,13 @@ config VIDEO_ML86V7667 To compile this driver as a module, choose M here: the module will be called ml86v7667. +config VIDEO_AD5820 + tristate "AD5820 lens voice coil support" + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + ---help--- + This is a driver for the AD5820 camera lens voice coil. + It is used for example in Nokia N900 (RX-51). + config VIDEO_SAA7110 tristate "Philips SAA7110 video decoder" depends on VIDEO_V4L2 && I2C diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 94f2c99..0216af0 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o +obj-$(CONFIG_VIDEO_AD5820) += ad5820.o obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c new file mode 100644 index 0000000..62cc1f5 --- /dev/null +++ b/drivers/media/i2c/ad5820.c @@ -0,0 +1,380 @@ +/* + * drivers/media/i2c/ad5820.c + * + * AD5820 DAC driver for camera voice coil focus. + * + * Copyright (C) 2008 Nokia Corporation + * Copyright (C) 2007 Texas Instruments + * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz> + * + * Contact: Tuukka Toivonen <tuukkat76@gmail.com> + * Sakari Ailus <sakari.ailus@iki.fi> + * + * Based on af_d88.c by Texas Instruments. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include <linux/errno.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/regulator/consumer.h> + +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-subdev.h> + +#define AD5820_NAME "ad5820" + +/* Register definitions */ +#define AD5820_POWER_DOWN (1 << 15) +#define AD5820_DAC_SHIFT 4 +#define AD5820_RAMP_MODE_LINEAR (0 << 3) +#define AD5820_RAMP_MODE_64_16 (1 << 3) + +#define CODE_TO_RAMP_US(s) ((s) == 0 ? 0 : (1 << ((s) - 1)) * 50) +#define RAMP_US_TO_CODE(c) fls(((c) + ((c)>>1)) / 50) + +#define to_ad5820_device(sd) container_of(sd, struct ad5820_device, subdev) + +struct ad5820_device { + struct v4l2_subdev subdev; + struct ad5820_platform_data *platform_data; + struct regulator *vana; + + struct v4l2_ctrl_handler ctrls; + u32 focus_absolute; + u32 focus_ramp_time; + u32 focus_ramp_mode; + + struct mutex power_lock; + int power_count; + + int standby : 1; +}; + +static int ad5820_write(struct ad5820_device *coil, u16 data) +{ + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev); + struct i2c_msg msg; + int r; + + if (!client->adapter) + return -ENODEV; + + data = cpu_to_be16(data); + msg.addr = client->addr; + msg.flags = 0; + msg.len = 2; + msg.buf = (u8 *)&data; + + r = i2c_transfer(client->adapter, &msg, 1); + if (r < 0) { + dev_err(&client->dev, "write failed, error %d\n", r); + return r; + } + + return 0; +} + +/* + * Calculate status word and write it to the device based on current + * values of V4L2 controls. It is assumed that the stored V4L2 control + * values are properly limited and rounded. + */ +static int ad5820_update_hw(struct ad5820_device *coil) +{ + u16 status; + + status = RAMP_US_TO_CODE(coil->focus_ramp_time); + status |= coil->focus_ramp_mode + ? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR; + status |= coil->focus_absolute << AD5820_DAC_SHIFT; + + if (coil->standby) + status |= AD5820_POWER_DOWN; + + return ad5820_write(coil, status); +} + +/* + * Power handling + */ +static int ad5820_power_off(struct ad5820_device *coil, int standby) +{ + int ret = 0, ret2; + + /* + * Go to standby first as real power off my be denied by the hardware + * (single power line control for both coil and sensor). + */ + if (standby) { + coil->standby = 1; + ret = ad5820_update_hw(coil); + } + + ret2 = regulator_disable(coil->vana); + if (ret) + return ret; + return ret2; +} + +static int ad5820_power_on(struct ad5820_device *coil, int restore) +{ + int ret; + + ret = regulator_enable(coil->vana); + if (ret < 0) + return ret; + + if (restore) { + /* Restore the hardware settings. */ + coil->standby = 0; + ret = ad5820_update_hw(coil); + if (ret) + goto fail; + } + return 0; + +fail: + coil->standby = 1; + regulator_disable(coil->vana); + + return ret; +} + +/* + * V4L2 controls + */ +static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ad5820_device *coil = + container_of(ctrl->handler, struct ad5820_device, ctrls); + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + coil->focus_absolute = ctrl->val; + return ad5820_update_hw(coil); + } + + return 0; +} + +static const struct v4l2_ctrl_ops ad5820_ctrl_ops = { + .s_ctrl = ad5820_set_ctrl, +}; + + +static int ad5820_init_controls(struct ad5820_device *coil) +{ + v4l2_ctrl_handler_init(&coil->ctrls, 1); + + /* + * V4L2_CID_FOCUS_ABSOLUTE + * + * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is + * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA] + * for focus position, because it is meaningless for user. Meaningful + * would be to use focus distance or even its inverse, but since the + * driver doesn't have sufficiently knowledge to do the conversion, we + * will just use abstract codes here. In any case, smaller value = focus + * position farther from camera. The default zero value means focus at + * infinity, and also least current consumption. + */ + v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops, + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0); + + if (coil->ctrls.error) + return coil->ctrls.error; + + coil->focus_absolute = 0; + coil->focus_ramp_time = 0; + coil->focus_ramp_mode = 0; + + coil->subdev.ctrl_handler = &coil->ctrls; + + return 0; +} + +/* + * V4L2 subdev operations + */ +static int ad5820_registered(struct v4l2_subdev *subdev) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + + return ad5820_init_controls(coil); +} + +static int +ad5820_set_power(struct v4l2_subdev *subdev, int on) +{ + struct ad5820_device *coil = to_ad5820_device(subdev); + int ret = 0; + + mutex_lock(&coil->power_lock); + + /* + * If the power count is modified from 0 to != 0 or from != 0 to 0, + * update the power state. + */ + if (coil->power_count == !on) { + ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1); + if (ret < 0) + goto done; + } + + /* Update the power count. */ + coil->power_count += on ? 1 : -1; + WARN_ON(coil->power_count < 0); + +done: + mutex_unlock(&coil->power_lock); + return ret; +} + +static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 1); +} + +static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + return ad5820_set_power(sd, 0); +} + +static const struct v4l2_subdev_core_ops ad5820_core_ops = { + .s_power = ad5820_set_power, +}; + +static const struct v4l2_subdev_ops ad5820_ops = { + .core = &ad5820_core_ops, +}; + +static const struct v4l2_subdev_internal_ops ad5820_internal_ops = { + .registered = ad5820_registered, + .open = ad5820_open, + .close = ad5820_close, +}; + +/* + * I2C driver + */ +#ifdef CONFIG_PM + +static int ad5820_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_off(coil, 0); +} + +static int ad5820_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + if (!coil->power_count) + return 0; + + return ad5820_power_on(coil, 1); +} + +#else + +#define ad5820_suspend NULL +#define ad5820_resume NULL + +#endif /* CONFIG_PM */ + +static int ad5820_probe(struct i2c_client *client, + const struct i2c_device_id *devid) +{ + struct ad5820_device *coil; + int ret; + + coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); + if (!coil) + return -ENOMEM; + + coil->vana = devm_regulator_get(&client->dev, "VANA"); + if (IS_ERR(coil->vana)) { + ret = PTR_ERR(coil->vana); + if (ret != -EPROBE_DEFER) + dev_err(&client->dev, "could not get regulator for vana\n"); + return ret; + } + + mutex_init(&coil->power_lock); + + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops); + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + coil->subdev.internal_ops = &ad5820_internal_ops; + strcpy(coil->subdev.name, "ad5820 focus"); + + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL); + if (ret < 0) + goto cleanup2; + + ret = v4l2_async_register_subdev(&coil->subdev); + if (ret < 0) + goto cleanup; + + return ret; + +cleanup2: + mutex_destroy(&coil->power_lock); +cleanup: + media_entity_cleanup(&coil->subdev.entity); + return ret; +} + +static int __exit ad5820_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ad5820_device *coil = to_ad5820_device(subdev); + + v4l2_device_unregister_subdev(&coil->subdev); + v4l2_ctrl_handler_free(&coil->ctrls); + media_entity_cleanup(&coil->subdev.entity); + mutex_destroy(&coil->power_lock); + return 0; +} + +static const struct i2c_device_id ad5820_id_table[] = { + { AD5820_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ad5820_id_table); + +static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume); + +static struct i2c_driver ad5820_i2c_driver = { + .driver = { + .name = AD5820_NAME, + .pm = &ad5820_pm, + }, + .probe = ad5820_probe, + .remove = __exit_p(ad5820_remove), + .id_table = ad5820_id_table, +}; + +module_i2c_driver(ad5820_i2c_driver); + +MODULE_AUTHOR("Tuukka Toivonen"); +MODULE_DESCRIPTION("AD5820 camera lens driver"); +MODULE_LICENSE("GPL"); -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-05 10:26 ` [PATCHv6] support for AD5820 camera auto-focus coil Pavel Machek @ 2016-08-05 10:30 ` Pali Rohár 2016-08-08 8:09 ` Sakari Ailus 1 sibling, 0 replies; 73+ messages in thread From: Pali Rohár @ 2016-08-05 10:30 UTC (permalink / raw) To: Pavel Machek Cc: Sakari Ailus, Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Friday 05 August 2016 12:26:11 Pavel Machek wrote: > > This adds support for AD5820 autofocus coil, found for example in > Nokia N900 smartphone. > > Signed-off-by: Pavel Machek <pavel@ucw.cz> Acked-by: Pali Rohár <pali.rohar@gmail.com> > --- > v2: simple cleanups, fix error paths, simplify probe > v3: more cleanups, remove printk, add include > v4: remove header file. > v5: switch to devm_ , style cleanups, fixes > v6: remove new userspace APIs. > > Can we finally get the patch in, please? This patch is on ML for months or years, right? Please merge it... -- Pali Rohár pali.rohar@gmail.com ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-05 10:26 ` [PATCHv6] support for AD5820 camera auto-focus coil Pavel Machek 2016-08-05 10:30 ` Pali Rohár @ 2016-08-08 8:09 ` Sakari Ailus 2016-08-08 21:41 ` Pavel Machek 2016-08-10 7:34 ` Pali Rohár 1 sibling, 2 replies; 73+ messages in thread From: Sakari Ailus @ 2016-08-08 8:09 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > This adds support for AD5820 autofocus coil, found for example in > Nokia N900 smartphone. Thanks, Pavel! Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something better in the future, we'll switch to that then. I've applied this to ad5820 branch in my tree. -- Cheers, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-08 8:09 ` Sakari Ailus @ 2016-08-08 21:41 ` Pavel Machek 2016-08-10 12:01 ` Sakari Ailus 2016-12-14 13:38 ` Pali Rohár 2016-08-10 7:34 ` Pali Rohár 1 sibling, 2 replies; 73+ messages in thread From: Pavel Machek @ 2016-08-08 21:41 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > This adds support for AD5820 autofocus coil, found for example in > > Nokia N900 smartphone. > > Thanks, Pavel! > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > better in the future, we'll switch to that then. > > I've applied this to ad5820 branch in my tree. Thanks. If I understands things correctly, both DTS patch and this patch are waiting in your tree, so we should be good to go for 4.9 (unless some unexpected problems surface)? Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-08 21:41 ` Pavel Machek @ 2016-08-10 12:01 ` Sakari Ailus 2016-08-08 23:23 ` Pavel Machek 2016-12-14 13:38 ` Pali Rohár 1 sibling, 1 reply; 73+ messages in thread From: Sakari Ailus @ 2016-08-10 12:01 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote: > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > Nokia N900 smartphone. > > > > Thanks, Pavel! > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > > better in the future, we'll switch to that then. > > > > I've applied this to ad5820 branch in my tree. > > Thanks. If I understands things correctly, both DTS patch and this patch are > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected > problems surface)? Yeah. I just compiled it but haven't tested it. I presume it'll work. :-) -- Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-10 12:01 ` Sakari Ailus @ 2016-08-08 23:23 ` Pavel Machek 2016-08-11 11:16 ` Sakari Ailus 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-08-08 23:23 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Wed 2016-08-10 15:01:05, Sakari Ailus wrote: > On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote: > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > > Nokia N900 smartphone. > > > > > > Thanks, Pavel! > > > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > > > better in the future, we'll switch to that then. > > > > > > I've applied this to ad5820 branch in my tree. > > > > Thanks. If I understands things correctly, both DTS patch and this patch are > > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected > > problems surface)? > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-) I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the test... What hardware do you have? Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-08 23:23 ` Pavel Machek @ 2016-08-11 11:16 ` Sakari Ailus 2016-08-18 10:45 ` Pavel Machek 0 siblings, 1 reply; 73+ messages in thread From: Sakari Ailus @ 2016-08-11 11:16 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Tue, Aug 09, 2016 at 01:23:23AM +0200, Pavel Machek wrote: > On Wed 2016-08-10 15:01:05, Sakari Ailus wrote: > > On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote: > > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > > > Nokia N900 smartphone. > > > > > > > > Thanks, Pavel! > > > > > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > > > > better in the future, we'll switch to that then. > > > > > > > > I've applied this to ad5820 branch in my tree. > > > > > > Thanks. If I understands things correctly, both DTS patch and this patch are > > > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected > > > problems surface)? > > > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-) > > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the > test... > > What hardware do you have? N900. What else could it be? :-) :-) -- Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-11 11:16 ` Sakari Ailus @ 2016-08-18 10:45 ` Pavel Machek 2016-08-18 20:26 ` Sakari Ailus 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-08-18 10:45 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Thu 2016-08-11 14:16:34, Sakari Ailus wrote: > On Tue, Aug 09, 2016 at 01:23:23AM +0200, Pavel Machek wrote: > > On Wed 2016-08-10 15:01:05, Sakari Ailus wrote: > > > On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote: > > > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > > > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > > > > Nokia N900 smartphone. > > > > > > > > > > Thanks, Pavel! > > > > > > > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > > > > > better in the future, we'll switch to that then. > > > > > > > > > > I've applied this to ad5820 branch in my tree. > > > > > > > > Thanks. If I understands things correctly, both DTS patch and this patch are > > > > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected > > > > problems surface)? > > > > > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-) > > > > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the > > test... > > > > What hardware do you have? > > N900. What else could it be? :-) :-) Heh. Basically anything is easier to develop for than n900 :-(. Ok, for real testing, Ivaylo's camera patchset is useful, so that you have picture to work with, plus your subdevs for omap3 patchset (which needs a forward port). I have patches against v4.7, if you are interested. I guess subdevs for omap3 should be merged at this point. Do you have any plans to do that, or should I take a look? Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-18 10:45 ` Pavel Machek @ 2016-08-18 20:26 ` Sakari Ailus 2016-08-18 21:28 ` Pavel Machek 2016-11-03 10:27 ` Pavel Machek 0 siblings, 2 replies; 73+ messages in thread From: Sakari Ailus @ 2016-08-18 20:26 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab Hi Pavel, On Thu, Aug 18, 2016 at 12:45:39PM +0200, Pavel Machek wrote: > On Thu 2016-08-11 14:16:34, Sakari Ailus wrote: > > On Tue, Aug 09, 2016 at 01:23:23AM +0200, Pavel Machek wrote: > > > On Wed 2016-08-10 15:01:05, Sakari Ailus wrote: > > > > On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote: > > > > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > > > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > > > > > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > > > > > Nokia N900 smartphone. > > > > > > > > > > > > Thanks, Pavel! > > > > > > > > > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > > > > > > better in the future, we'll switch to that then. > > > > > > > > > > > > I've applied this to ad5820 branch in my tree. > > > > > > > > > > Thanks. If I understands things correctly, both DTS patch and this patch are > > > > > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected > > > > > problems surface)? > > > > > > > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-) > > > > > > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the > > > test... > > > > > > What hardware do you have? > > > > N900. What else could it be? :-) :-) > > Heh. Basically anything is easier to develop for than n900 :-(. Is it? I actually find the old Nokia devices very practical. It's easy to boot your own kernel and things just work... until musb broke a bit recently. It requires reconnecting the usb cable again to function. I have to admit I mostly use an N9. > > Ok, for real testing, Ivaylo's camera patchset is useful, so that you > have picture to work with, plus your subdevs for omap3 patchset (which > needs a forward port). > > I have patches against v4.7, if you are interested. They should be pretty close to mainline. The rebase should be very easy. Patches against media-tree master branch would always be better naturally. :-) > > I guess subdevs for omap3 should be merged at this point. Do you have > any plans to do that, or should I take a look? What's still missing? I think I've yet to check the et8ek8 driver and the device tree description is missing. That's what comes to mind right now. -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-18 20:26 ` Sakari Ailus @ 2016-08-18 21:28 ` Pavel Machek 2016-11-03 10:27 ` Pavel Machek 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-08-18 21:28 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab Hi! > > Heh. Basically anything is easier to develop for than n900 :-(. > > Is it? > > I actually find the old Nokia devices very practical. It's easy to boot your > own kernel and things just work... until musb broke a bit recently. It > requires reconnecting the usb cable again to function. > > I have to admit I mostly use an N9. Well, yes, I guess it sucks less than most phones, but... I wish I had working .5TB drive, and CPU fast enough to compile kernel in say hour, and enough memory to run emacs and g++ at the same time, ethernet connection, working RTC and real keyboard and monitor... Development would be way easier if I could just disconnect the N900 peripherals and connect them to the PC. Ok, I can dream, right? > > I guess subdevs for omap3 should be merged at this point. Do you have > > any plans to do that, or should I take a look? > > What's still missing? I think I've yet to check the et8ek8 driver and the > device tree description is missing. That's what comes to mind right now. et8ek8 driver is important, yes. But there's the support for parsing sub-devices from the dt missing, too. This stuff (I believe it is originally from you). Best regards, Pavel diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c index 5d54e2c..23d484c 100644 --- a/drivers/media/platform/omap3isp/isp.c +++ b/drivers/media/platform/omap3isp/isp.c @@ -2098,10 +2151,51 @@ static int isp_of_parse_node(struct device *dev, struct device_node *node, return 0; } +static int isp_of_parse_node(struct device *dev, struct device_node *node, + struct v4l2_async_notifier *notifier, + u32 group_id, bool link) +{ + struct isp_async_subdev *isd; + + isd = devm_kzalloc(dev, sizeof(*isd), GFP_KERNEL); + if (!isd) { + of_node_put(node); + return -ENOMEM; + } + + notifier->subdevs[notifier->num_subdevs] = &isd->asd; + + if (link) { + if (isp_of_parse_node_endpoint(dev, node, isd)) { + of_node_put(node); + return -EINVAL; + } + + isd->asd.match.of.node = of_graph_get_remote_port_parent(node); + of_node_put(node); + } else { + isd->asd.match.of.node = node; + } + + if (!isd->asd.match.of.node) { + dev_warn(dev, "bad remote port parent\n"); + return -EINVAL; + } + + isd->asd.match_type = V4L2_ASYNC_MATCH_OF; + isd->group_id = group_id; + notifier->num_subdevs++; + + return 0; +} + static int isp_of_parse_nodes(struct device *dev, struct v4l2_async_notifier *notifier) { struct device_node *node = NULL; + int ret; + unsigned int flash = 0; + u32 group_id = 0; notifier->subdevs = devm_kcalloc( dev, ISP_MAX_SUBDEVS, sizeof(*notifier->subdevs), GFP_KERNEL); @@ -2110,30 +2204,57 @@ static int isp_of_parse_nodes(struct device *dev, while (notifier->num_subdevs < ISP_MAX_SUBDEVS && (node = of_graph_get_next_endpoint(dev->of_node, node))) { - struct isp_async_subdev *isd; + ret = isp_of_parse_node(dev, node, notifier, group_id++, true); + if (ret) + return ret; + } - isd = devm_kzalloc(dev, sizeof(*isd), GFP_KERNEL); - if (!isd) { - of_node_put(node); - return -ENOMEM; - } + while (notifier->num_subdevs < ISP_MAX_SUBDEVS && + (node = of_parse_phandle(dev->of_node, "ti,camera-flashes", + flash++))) { + struct device_node *sensor_node = + of_parse_phandle(dev->of_node, "ti,camera-flashes", + flash++); + unsigned int i; + u32 flash_group_id; + + if (!sensor_node) + return -EINVAL; - notifier->subdevs[notifier->num_subdevs] = &isd->asd; + for (i = 0; i < notifier->num_subdevs; i++) { + struct isp_async_subdev *isd = container_of( + notifier->subdevs[i], struct isp_async_subdev, + asd); - if (isp_of_parse_node(dev, node, isd)) { - of_node_put(node); - return -EINVAL; + if (!isd->bus) + continue; + + dev_dbg(dev, "match \"%s\", \"%s\"\n",sensor_node->name, + isd->asd.match.of.node->name); + + if (sensor_node != isd->asd.match.of.node) + continue; + + dev_dbg(dev, "found\n"); + + flash_group_id = isd->group_id; + break; } - isd->asd.match.of.node = of_graph_get_remote_port_parent(node); - of_node_put(node); - if (!isd->asd.match.of.node) { - dev_warn(dev, "bad remote port parent\n"); - return -EINVAL; + /* + * No sensor was found --- complain and allocate a new + * group ID. + */ + if (i == notifier->num_subdevs) { + dev_warn(dev, "no device node \"%s\" was found", + sensor_node->name); + flash_group_id = group_id++; } - isd->asd.match_type = V4L2_ASYNC_MATCH_OF; - notifier->num_subdevs++; + ret = isp_of_parse_node(dev, node, notifier, flash_group_id, + false); + if (ret) + return ret; } return notifier->num_subdevs; @@ -2146,8 +2267,9 @@ static int isp_subdev_notifier_bound(struct v4l2_async_notifier *async, struct isp_async_subdev *isd = container_of(asd, struct isp_async_subdev, asd); +// subdev->entity.group_id = isd->group_id; isd->sd = subdev; - isd->sd->host_priv = &isd->bus; + isd->sd->host_priv = isd->bus; return 0; } @@ -2350,12 +2472,15 @@ static int isp_probe(struct platform_device *pdev) if (ret < 0) goto error_register_entities; - isp->notifier.bound = isp_subdev_notifier_bound; - isp->notifier.complete = isp_subdev_notifier_complete; + if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) { + isp->notifier.bound = isp_subdev_notifier_bound; + isp->notifier.complete = isp_subdev_notifier_complete; - ret = v4l2_async_notifier_register(&isp->v4l2_dev, &isp->notifier); - if (ret) - goto error_register_entities; + ret = v4l2_async_notifier_register(&isp->v4l2_dev, + &isp->notifier); + if (ret) + goto error_register_entities; + } isp_core_init(isp, 1); omap3isp_put(isp); diff --git a/drivers/media/platform/omap3isp/isp.h b/drivers/media/platform/omap3isp/isp.h index 7e6f663..639b3ca 100644 --- a/drivers/media/platform/omap3isp/isp.h +++ b/drivers/media/platform/omap3isp/isp.h @@ -228,8 +228,9 @@ struct isp_device { struct isp_async_subdev { struct v4l2_subdev *sd; - struct isp_bus_cfg bus; + struct isp_bus_cfg *bus; struct v4l2_async_subdev asd; + u32 group_id; }; #define v4l2_dev_to_isp_device(dev) \ -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-18 20:26 ` Sakari Ailus 2016-08-18 21:28 ` Pavel Machek @ 2016-11-03 10:27 ` Pavel Machek 2016-11-03 21:49 ` Sakari Ailus 1 sibling, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-11-03 10:27 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab [-- Attachment #1: Type: text/plain, Size: 1170 bytes --] Hi! > > > > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-) > > > > > > > > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the > > > > test... > > > > > > > > What hardware do you have? > > > > > > N900. What else could it be? :-) :-) > > > > Heh. Basically anything is easier to develop for than n900 :-(. > > Is it? > > I actually find the old Nokia devices very practical. It's easy to boot your > own kernel and things just work... until musb broke a bit recently. It > requires reconnecting the usb cable again to function. > > I have to admit I mostly use an N9. Well, if you compare that to development on PC, I prefer PC. Even arm development boards are usually easier, as they don't need too complex userspace, and do have working serial ports. But I do have a serial adapter for N900 now (thanks, sre), so my main problem now is that N900 takes a lot of time to boot into usable state. Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 181 bytes --] ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-11-03 10:27 ` Pavel Machek @ 2016-11-03 21:49 ` Sakari Ailus 2016-11-04 7:45 ` Pavel Machek 0 siblings, 1 reply; 73+ messages in thread From: Sakari Ailus @ 2016-11-03 21:49 UTC (permalink / raw) To: Pavel Machek Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Thu, Nov 03, 2016 at 11:27:27AM +0100, Pavel Machek wrote: > Hi! > > > > > > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-) > > > > > > > > > > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the > > > > > test... > > > > > > > > > > What hardware do you have? > > > > > > > > N900. What else could it be? :-) :-) > > > > > > Heh. Basically anything is easier to develop for than n900 :-(. > > > > Is it? > > > > I actually find the old Nokia devices very practical. It's easy to boot your > > own kernel and things just work... until musb broke a bit recently. It > > requires reconnecting the usb cable again to function. > > > > I have to admit I mostly use an N9. > > Well, if you compare that to development on PC, I prefer PC. > > Even arm development boards are usually easier, as they don't need too > complex userspace, and do have working serial ports. > > But I do have a serial adapter for N900 now (thanks, sre), so my main > problem now is that N900 takes a lot of time to boot into usable > state. Yeah... I just upgraded my Debian installation (armel over NFS) a few major numbers and I find it a lot slower than it used to do. I presume that's mostly because of systemd... -- Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-11-03 21:49 ` Sakari Ailus @ 2016-11-04 7:45 ` Pavel Machek 2016-11-04 14:49 ` Tony Lindgren 0 siblings, 1 reply; 73+ messages in thread From: Pavel Machek @ 2016-11-04 7:45 UTC (permalink / raw) To: Sakari Ailus Cc: Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab [-- Attachment #1: Type: text/plain, Size: 977 bytes --] Hi! > > > I have to admit I mostly use an N9. > > > > Well, if you compare that to development on PC, I prefer PC. > > > > Even arm development boards are usually easier, as they don't need too > > complex userspace, and do have working serial ports. > > > > But I do have a serial adapter for N900 now (thanks, sre), so my main > > problem now is that N900 takes a lot of time to boot into usable > > state. > > Yeah... I just upgraded my Debian installation (armel over NFS) a few major > numbers and I find it a lot slower than it used to do. I presume that's > mostly because of systemd... I'm not sure if systemd is to blame. (I'm booting into full GUI...) And yes, I noticed the slowdown in Debian 7 -> 8 transition, so I'm basically staying at Debian 7 as far as I can. Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 181 bytes --] ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-11-04 7:45 ` Pavel Machek @ 2016-11-04 14:49 ` Tony Lindgren 0 siblings, 0 replies; 73+ messages in thread From: Tony Lindgren @ 2016-11-04 14:49 UTC (permalink / raw) To: Pavel Machek Cc: Sakari Ailus, Ivaylo Dimitrov, pali.rohar, sre, kernel list, linux-arm-kernel, linux-omap, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab * Pavel Machek <pavel@ucw.cz> [161104 00:45]: > Hi! > > > > > I have to admit I mostly use an N9. > > > > > > Well, if you compare that to development on PC, I prefer PC. > > > > > > Even arm development boards are usually easier, as they don't need too > > > complex userspace, and do have working serial ports. > > > > > > But I do have a serial adapter for N900 now (thanks, sre), so my main > > > problem now is that N900 takes a lot of time to boot into usable > > > state. > > > > Yeah... I just upgraded my Debian installation (armel over NFS) a few major > > numbers and I find it a lot slower than it used to do. I presume that's > > mostly because of systemd... > > I'm not sure if systemd is to blame. (I'm booting into full GUI...) > > And yes, I noticed the slowdown in Debian 7 -> 8 transition, so I'm > basically staying at Debian 7 as far as I can. Maybe it's the armel vs armhf causing the slowdown? Regards, Tony ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-08 21:41 ` Pavel Machek 2016-08-10 12:01 ` Sakari Ailus @ 2016-12-14 13:38 ` Pali Rohár 2016-12-14 15:08 ` Tony Lindgren 1 sibling, 1 reply; 73+ messages in thread From: Pali Rohár @ 2016-12-14 13:38 UTC (permalink / raw) To: Pavel Machek Cc: Sakari Ailus, Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab [-- Attachment #1: Type: Text/Plain, Size: 883 bytes --] On Monday 08 August 2016 23:41:32 Pavel Machek wrote: > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > This adds support for AD5820 autofocus coil, found for example in > > > Nokia N900 smartphone. > > > > Thanks, Pavel! > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get > > something better in the future, we'll switch to that then. > > > > I've applied this to ad5820 branch in my tree. > > Thanks. If I understands things correctly, both DTS patch and this > patch are waiting in your tree, so we should be good to go for 4.9 > (unless some unexpected problems surface)? > > Best regards, > Pavel Was DTS patch merged into 4.9? At least I do not see updated that dts file omap3-n900.dts in linus tree... -- Pali Rohár pali.rohar@gmail.com [-- Attachment #2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-12-14 13:38 ` Pali Rohár @ 2016-12-14 15:08 ` Tony Lindgren 2016-12-15 6:50 ` Sakari Ailus 0 siblings, 1 reply; 73+ messages in thread From: Tony Lindgren @ 2016-12-14 15:08 UTC (permalink / raw) To: Pali Rohár Cc: Pavel Machek, Sakari Ailus, Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab * Pali Rohár <pali.rohar@gmail.com> [161214 05:38]: > On Monday 08 August 2016 23:41:32 Pavel Machek wrote: > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > This adds support for AD5820 autofocus coil, found for example in > > > > Nokia N900 smartphone. > > > > > > Thanks, Pavel! > > > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get > > > something better in the future, we'll switch to that then. > > > > > > I've applied this to ad5820 branch in my tree. > > > > Thanks. If I understands things correctly, both DTS patch and this > > patch are waiting in your tree, so we should be good to go for 4.9 > > (unless some unexpected problems surface)? > > > > Best regards, > > Pavel > > Was DTS patch merged into 4.9? At least I do not see updated that dts > file omap3-n900.dts in linus tree... If it's not in current mainline or next, it's off my radar so sounds like I've somehow missed it and needs resending.. Tony ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-12-14 15:08 ` Tony Lindgren @ 2016-12-15 6:50 ` Sakari Ailus 2016-12-19 22:23 ` Pavel Machek 0 siblings, 1 reply; 73+ messages in thread From: Sakari Ailus @ 2016-12-15 6:50 UTC (permalink / raw) To: Tony Lindgren Cc: Pali Rohár, Pavel Machek, Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab Hi Pali and Tony, On Wed, Dec 14, 2016 at 07:08:19AM -0800, Tony Lindgren wrote: > * Pali Rohár <pali.rohar@gmail.com> [161214 05:38]: > > On Monday 08 August 2016 23:41:32 Pavel Machek wrote: > > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > This adds support for AD5820 autofocus coil, found for example in > > > > > Nokia N900 smartphone. > > > > > > > > Thanks, Pavel! > > > > > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get > > > > something better in the future, we'll switch to that then. > > > > > > > > I've applied this to ad5820 branch in my tree. > > > > > > Thanks. If I understands things correctly, both DTS patch and this > > > patch are waiting in your tree, so we should be good to go for 4.9 > > > (unless some unexpected problems surface)? > > > > > > Best regards, > > > Pavel > > > > Was DTS patch merged into 4.9? At least I do not see updated that dts > > file omap3-n900.dts in linus tree... > > If it's not in current mainline or next, it's off my radar so sounds > like I've somehow missed it and needs resending.. Where's this patch? I remember seeing the driver patch and the DT documentation but no actual DT source patch for the N900. -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-12-15 6:50 ` Sakari Ailus @ 2016-12-19 22:23 ` Pavel Machek 0 siblings, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-12-19 22:23 UTC (permalink / raw) To: Sakari Ailus Cc: Tony Lindgren, Pali Rohár, Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab [-- Attachment #1: Type: text/plain, Size: 1810 bytes --] Hi! > Hi Pali and Tony, > On Wed, Dec 14, 2016 at 07:08:19AM -0800, Tony Lindgren wrote: > > * Pali Rohár <pali.rohar@gmail.com> [161214 05:38]: > > > On Monday 08 August 2016 23:41:32 Pavel Machek wrote: > > > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote: > > > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > > > > Nokia N900 smartphone. > > > > > > > > > > Thanks, Pavel! > > > > > > > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get > > > > > something better in the future, we'll switch to that then. > > > > > > > > > > I've applied this to ad5820 branch in my tree. > > > > > > > > Thanks. If I understands things correctly, both DTS patch and this > > > > patch are waiting in your tree, so we should be good to go for 4.9 > > > > (unless some unexpected problems surface)? > > > > > > > > Best regards, > > > > Pavel > > > > > > Was DTS patch merged into 4.9? At least I do not see updated that dts > > > file omap3-n900.dts in linus tree... > > > > If it's not in current mainline or next, it's off my radar so sounds > > like I've somehow missed it and needs resending.. > > Where's this patch? I remember seeing the driver patch and the DT > documentation but no actual DT source patch for the N900. The patch was not yet submitted. Autofocus coil is not too useful withou camera support, and we don't yet have support for v4l subdevs for omap3. I have it in the camera tree, but there are still pieces to be done before this is useful. Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 181 bytes --] ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-08 8:09 ` Sakari Ailus 2016-08-08 21:41 ` Pavel Machek @ 2016-08-10 7:34 ` Pali Rohár 2016-08-08 21:40 ` Pavel Machek 2016-08-10 12:00 ` Sakari Ailus 1 sibling, 2 replies; 73+ messages in thread From: Pali Rohár @ 2016-08-10 7:34 UTC (permalink / raw) To: Sakari Ailus Cc: Pavel Machek, Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Monday 08 August 2016 11:09:56 Sakari Ailus wrote: > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > This adds support for AD5820 autofocus coil, found for example in > > Nokia N900 smartphone. > > Thanks, Pavel! > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > better in the future, we'll switch to that then. Ok, and what with AD5820_RAMP_TIME and AD5820_RAMP_MODE? > I've applied this to ad5820 branch in my tree. Are you going to finally send this patch to media tree or pull request to Linus? -- Pali Rohár pali.rohar@gmail.com ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-10 7:34 ` Pali Rohár @ 2016-08-08 21:40 ` Pavel Machek 2016-08-10 12:00 ` Sakari Ailus 1 sibling, 0 replies; 73+ messages in thread From: Pavel Machek @ 2016-08-08 21:40 UTC (permalink / raw) To: Pali Rohár Cc: Sakari Ailus, Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Wed 2016-08-10 09:34:03, Pali Rohár wrote: > On Monday 08 August 2016 11:09:56 Sakari Ailus wrote: > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > Nokia N900 smartphone. > > > > Thanks, Pavel! > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > > better in the future, we'll switch to that then. > > Ok, and what with AD5820_RAMP_TIME and AD5820_RAMP_MODE? Lets forget about those for now. I'll wait till current support works in the Linus' tree, then I can write the docs and re-add the ioctls. Best regards, Pavel (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: [PATCHv6] support for AD5820 camera auto-focus coil 2016-08-10 7:34 ` Pali Rohár 2016-08-08 21:40 ` Pavel Machek @ 2016-08-10 12:00 ` Sakari Ailus 1 sibling, 0 replies; 73+ messages in thread From: Sakari Ailus @ 2016-08-10 12:00 UTC (permalink / raw) To: Pali Rohár Cc: Pavel Machek, Ivaylo Dimitrov, sre, kernel list, linux-arm-kernel, linux-omap, tony, khilman, aaro.koskinen, patrikbachan, serge, linux-media, mchehab On Wed, Aug 10, 2016 at 09:34:03AM +0200, Pali Rohár wrote: > On Monday 08 August 2016 11:09:56 Sakari Ailus wrote: > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote: > > > > > > This adds support for AD5820 autofocus coil, found for example in > > > Nokia N900 smartphone. > > > > Thanks, Pavel! > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something > > better in the future, we'll switch to that then. > > Ok, and what with AD5820_RAMP_TIME and AD5820_RAMP_MODE? > > > I've applied this to ad5820 branch in my tree. > > Are you going to finally send this patch to media tree or pull request > to Linus? That'll be through media-tree. -- Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 73+ messages in thread
end of thread, other threads:[~2016-12-19 22:23 UTC | newest] Thread overview: 73+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-05-17 18:19 [PATCH] support for AD5820 camera auto-focus coil Pavel Machek 2016-05-17 18:33 ` Marcus Folkesson 2016-05-18 8:30 ` Pavel Machek 2016-05-21 5:43 ` [PATCHv2] " Pavel Machek 2016-05-21 6:25 ` Ivaylo Dimitrov 2016-05-21 10:56 ` [PATCHv3] " Pavel Machek 2016-05-21 11:43 ` Ivaylo Dimitrov 2016-05-23 7:41 ` Pali Rohár 2016-05-24 9:04 ` Pavel Machek 2016-05-24 9:16 ` Ivaylo Dimitrov 2016-05-24 20:20 ` Pavel Machek 2016-05-26 3:46 ` Ivaylo Dimitrov 2016-05-24 9:17 ` [PATCHv4] " Pavel Machek 2016-05-25 21:26 ` Sakari Ailus 2016-05-27 20:33 ` Pavel Machek 2016-05-27 20:51 ` [PATCHv5] " Pavel Machek 2016-05-31 21:22 ` Sakari Ailus 2016-05-31 21:34 ` Pavel Machek 2016-06-01 15:24 ` Sakari Ailus 2016-06-01 22:08 ` Pavel Machek 2016-06-02 7:45 ` Sakari Ailus 2016-06-02 19:27 ` Pavel Machek 2016-06-02 21:23 ` Sakari Ailus 2016-06-02 19:30 ` [PATCH] device tree description " Pavel Machek 2016-06-02 21:27 ` Sakari Ailus 2016-06-03 6:19 ` Pavel Machek 2016-06-05 19:07 ` [PATCH] userspace API definitions for " Pavel Machek 2016-06-06 6:06 ` Ivaylo Dimitrov 2016-06-06 7:21 ` Pavel Machek 2016-06-11 22:06 ` Sakari Ailus 2016-06-12 7:54 ` Pavel Machek 2016-06-17 21:28 ` Sakari Ailus 2016-06-12 8:48 ` Pavel Machek 2016-06-12 11:22 ` Sakari Ailus 2016-06-13 19:17 ` Pavel Machek 2016-06-17 21:35 ` Sakari Ailus 2016-06-18 15:37 ` [PATCHv4] support for AD5820 camera " Pavel Machek 2016-06-18 15:38 ` [PATCH] userspace API definitions for " Pavel Machek 2016-07-12 23:32 ` Mauro Carvalho Chehab 2016-07-13 6:57 ` Pavel Machek 2016-07-13 7:26 ` Pavel Machek 2016-06-06 13:29 ` [PATCH] device tree description for AD5820 camera " Rob Herring 2016-06-07 7:10 ` [PATCHv2] " Pavel Machek 2016-06-09 22:37 ` Sakari Ailus 2016-06-04 23:27 ` [PATCHv5] support " kbuild test robot 2016-06-05 0:46 ` kbuild test robot 2016-06-12 20:41 ` [PATCH 1/1] v4l: Add camera voice coil lens control class, current control Sakari Ailus 2016-06-12 21:48 ` Ivaylo Dimitrov 2016-06-17 22:11 ` Pavel Machek 2016-06-17 22:39 ` Laurent Pinchart 2016-06-18 11:28 ` Pavel Machek 2016-06-17 22:06 ` Pavel Machek 2016-08-05 10:26 ` [PATCHv6] support for AD5820 camera auto-focus coil Pavel Machek 2016-08-05 10:30 ` Pali Rohár 2016-08-08 8:09 ` Sakari Ailus 2016-08-08 21:41 ` Pavel Machek 2016-08-10 12:01 ` Sakari Ailus 2016-08-08 23:23 ` Pavel Machek 2016-08-11 11:16 ` Sakari Ailus 2016-08-18 10:45 ` Pavel Machek 2016-08-18 20:26 ` Sakari Ailus 2016-08-18 21:28 ` Pavel Machek 2016-11-03 10:27 ` Pavel Machek 2016-11-03 21:49 ` Sakari Ailus 2016-11-04 7:45 ` Pavel Machek 2016-11-04 14:49 ` Tony Lindgren 2016-12-14 13:38 ` Pali Rohár 2016-12-14 15:08 ` Tony Lindgren 2016-12-15 6:50 ` Sakari Ailus 2016-12-19 22:23 ` Pavel Machek 2016-08-10 7:34 ` Pali Rohár 2016-08-08 21:40 ` Pavel Machek 2016-08-10 12:00 ` Sakari Ailus
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).