diff options
author | Pavel <pavel@ucw.cz> | 2018-10-28 16:10:54 +0100 |
---|---|---|
committer | Pavel <pavel@ucw.cz> | 2019-01-07 11:23:22 +0100 |
commit | 2deb0682355c80bac2eebb61a3dc3bf01755cc4d (patch) | |
tree | 82764949776866ac794e5b63291a07b92a6d45e2 | |
parent | db5bff92d335619f8bc995b72a6314974a2e6b9a (diff) | |
download | linux-k-2deb0682355c80bac2eebb61a3dc3bf01755cc4d.tar.gz |
n900: camera focus: add userland interface with full controls.
-rw-r--r-- | drivers/media/i2c/ad5820.c | 51 | ||||
-rw-r--r-- | include/uapi/linux/ad5820.h | 18 | ||||
-rw-r--r-- | include/uapi/linux/v4l2-controls.h | 4 |
3 files changed, 72 insertions, 1 deletions
diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c index 907323f0ca3b63..f6afc07645f2e1 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 */ @@ -159,11 +161,21 @@ 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; @@ -173,10 +185,43 @@ 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) { - v4l2_ctrl_handler_init(&coil->ctrls, 1); + unsigned int i; + + v4l2_ctrl_handler_init(&coil->ctrls, ARRAY_SIZE(ad5820_ctrls) + 1); /* * V4L2_CID_FOCUS_ABSOLUTE @@ -193,6 +238,10 @@ static int ad5820_init_controls(struct ad5820_device *coil) 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; diff --git a/include/uapi/linux/ad5820.h b/include/uapi/linux/ad5820.h new file mode 100644 index 00000000000000..4e541e844746e4 --- /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 3dcfc6148f99bd..37a5d68153d6ea 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -192,6 +192,10 @@ enum v4l2_colorfx { * We reserve 16 controls for this driver. */ #define V4L2_CID_USER_IMX_BASE (V4L2_CID_USER_BASE + 0x10b0) +/* The base for the ad5820 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_AD5820_BASE (V4L2_CID_USER_BASE + 0x10a0) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ |