From: Huang Shijie <shijie8@gmail.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [RFC PATCH 14/18] tlg2300: implement the control framework.
Date: Sun, 03 Feb 2013 23:46:53 -0500 [thread overview]
Message-ID: <510F3D3D.1010304@gmail.com> (raw)
In-Reply-To: <36ec60bc7420a183eab3a2637f187576b9cea780.1359627298.git.hans.verkuil@cisco.com>
于 2013年01月31日 05:25, Hans Verkuil 写道:
> From: Hans Verkuil <hans.verkuil@cisco.com>
>
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
> drivers/media/usb/tlg2300/pd-common.h | 1 +
> drivers/media/usb/tlg2300/pd-video.c | 128 +++++++++++----------------------
> 2 files changed, 41 insertions(+), 88 deletions(-)
>
> diff --git a/drivers/media/usb/tlg2300/pd-common.h b/drivers/media/usb/tlg2300/pd-common.h
> index 55fe66e..cb5cb0f 100644
> --- a/drivers/media/usb/tlg2300/pd-common.h
> +++ b/drivers/media/usb/tlg2300/pd-common.h
> @@ -64,6 +64,7 @@ struct running_context {
> struct video_data {
> /* v4l2 video device */
> struct video_device v_dev;
> + struct v4l2_ctrl_handler ctrl_handler;
>
> /* the working context */
> struct running_context context;
> diff --git a/drivers/media/usb/tlg2300/pd-video.c b/drivers/media/usb/tlg2300/pd-video.c
> index 122f299..849c4bb 100644
> --- a/drivers/media/usb/tlg2300/pd-video.c
> +++ b/drivers/media/usb/tlg2300/pd-video.c
> @@ -8,6 +8,7 @@
>
> #include <media/v4l2-ioctl.h>
> #include <media/v4l2-dev.h>
> +#include <media/v4l2-ctrls.h>
>
> #include "pd-common.h"
> #include "vendorcmds.h"
> @@ -82,31 +83,6 @@ static const struct pd_input pd_inputs[] = {
> };
> static const unsigned int POSEIDON_INPUTS = ARRAY_SIZE(pd_inputs);
>
> -struct poseidon_control {
> - struct v4l2_queryctrl v4l2_ctrl;
> - enum cmd_custom_param_id vc_id;
> -};
> -
> -static struct poseidon_control controls[] = {
> - {
> - { V4L2_CID_BRIGHTNESS, V4L2_CTRL_TYPE_INTEGER,
> - "brightness", 0, 10000, 1, 100, 0, },
> - CUST_PARM_ID_BRIGHTNESS_CTRL
> - }, {
> - { V4L2_CID_CONTRAST, V4L2_CTRL_TYPE_INTEGER,
> - "contrast", 0, 10000, 1, 100, 0, },
> - CUST_PARM_ID_CONTRAST_CTRL,
> - }, {
> - { V4L2_CID_HUE, V4L2_CTRL_TYPE_INTEGER,
> - "hue", 0, 10000, 1, 100, 0, },
> - CUST_PARM_ID_HUE_CTRL,
> - }, {
> - { V4L2_CID_SATURATION, V4L2_CTRL_TYPE_INTEGER,
> - "saturation", 0, 10000, 1, 100, 0, },
> - CUST_PARM_ID_SATURATION_CTRL,
> - },
> -};
> -
> struct video_std_to_audio_std {
> v4l2_std_id video_std;
> int audio_std;
> @@ -940,68 +916,28 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
> return 0;
> }
>
> -static struct poseidon_control *check_control_id(u32 id)
> -{
> - struct poseidon_control *control = &controls[0];
> - int array_size = ARRAY_SIZE(controls);
> -
> - for (; control < &controls[array_size]; control++)
> - if (control->v4l2_ctrl.id == id)
> - return control;
> - return NULL;
> -}
> -
> -static int vidioc_queryctrl(struct file *file, void *fh,
> - struct v4l2_queryctrl *a)
> -{
> - struct poseidon_control *control = NULL;
> -
> - control = check_control_id(a->id);
> - if (!control)
> - return -EINVAL;
> -
> - *a = control->v4l2_ctrl;
> - return 0;
> -}
> -
> -static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *ctrl)
> -{
> - struct front_face *front = fh;
> - struct poseidon *pd = front->pd;
> - struct poseidon_control *control = NULL;
> - struct tuner_custom_parameter_s tuner_param;
> - s32 ret = 0, cmd_status;
> -
> - control = check_control_id(ctrl->id);
> - if (!control)
> - return -EINVAL;
> -
> - mutex_lock(&pd->lock);
> - ret = send_get_req(pd, TUNER_CUSTOM_PARAMETER, control->vc_id,
> - &tuner_param, &cmd_status, sizeof(tuner_param));
> - mutex_unlock(&pd->lock);
> -
> - if (ret || cmd_status)
> - return -1;
> -
> - ctrl->value = tuner_param.param_value;
> - return 0;
> -}
> -
> -static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *a)
> +static int tlg_s_ctrl(struct v4l2_ctrl *c)
> {
> + struct poseidon *pd = container_of(c->handler, struct poseidon,
> + video_data.ctrl_handler);
> struct tuner_custom_parameter_s param = {0};
> - struct poseidon_control *control = NULL;
> - struct front_face *front = fh;
> - struct poseidon *pd = front->pd;
> s32 ret = 0, cmd_status, params;
>
> - control = check_control_id(a->id);
> - if (!control)
> - return -EINVAL;
> -
> - param.param_value = a->value;
> - param.param_id = control->vc_id;
> + switch (c->id) {
> + case V4L2_CID_BRIGHTNESS:
> + param.param_id = CUST_PARM_ID_BRIGHTNESS_CTRL;
> + break;
> + case V4L2_CID_CONTRAST:
> + param.param_id = CUST_PARM_ID_CONTRAST_CTRL;
> + break;
> + case V4L2_CID_HUE:
> + param.param_id = CUST_PARM_ID_HUE_CTRL;
> + break;
> + case V4L2_CID_SATURATION:
> + param.param_id = CUST_PARM_ID_SATURATION_CTRL;
> + break;
> + }
> + param.param_value = c->val;
> params = *(s32 *)¶m; /* temp code */
>
> mutex_lock(&pd->lock);
> @@ -1587,11 +1523,6 @@ static const struct v4l2_ioctl_ops pd_video_ioctl_ops = {
> /* Stream on/off */
> .vidioc_streamon = vidioc_streamon,
> .vidioc_streamoff = vidioc_streamoff,
> -
> - /* Control handling */
> - .vidioc_queryctrl = vidioc_queryctrl,
> - .vidioc_g_ctrl = vidioc_g_ctrl,
> - .vidioc_s_ctrl = vidioc_s_ctrl,
> };
>
> static struct video_device pd_video_template = {
> @@ -1603,6 +1534,10 @@ static struct video_device pd_video_template = {
> .ioctl_ops = &pd_video_ioctl_ops,
> };
>
> +static const struct v4l2_ctrl_ops tlg_ctrl_ops = {
> + .s_ctrl = tlg_s_ctrl,
> +};
> +
> void pd_video_exit(struct poseidon *pd)
> {
> struct video_data *video = &pd->video_data;
> @@ -1610,6 +1545,7 @@ void pd_video_exit(struct poseidon *pd)
>
> video_unregister_device(&video->v_dev);
> video_unregister_device(&vbi->v_dev);
> + v4l2_ctrl_handler_free(&video->ctrl_handler);
> log();
> }
>
> @@ -1617,12 +1553,27 @@ int pd_video_init(struct poseidon *pd)
> {
> struct video_data *video = &pd->video_data;
> struct vbi_data *vbi = &pd->vbi_data;
> + struct v4l2_ctrl_handler *hdl = &video->ctrl_handler;
> u32 freq = TUNER_FREQ_MIN / 62500;
> int ret = -ENOMEM;
>
> + v4l2_ctrl_handler_init(hdl, 4);
> + v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_BRIGHTNESS,
> + 0, 10000, 1, 100);
> + v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_CONTRAST,
> + 0, 10000, 1, 100);
> + v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_HUE,
> + 0, 10000, 1, 100);
> + v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_SATURATION,
> + 0, 10000, 1, 100);
> + if (hdl->error) {
> + v4l2_ctrl_handler_free(hdl);
> + return hdl->error;
> + }
> set_frequency(pd, &freq);
> video->v_dev = pd_video_template;
> video->v_dev.v4l2_dev = &pd->v4l2_dev;
> + video->v_dev.ctrl_handler = hdl;
> video_set_drvdata(&video->v_dev, pd);
>
> ret = video_register_device(&video->v_dev, VFL_TYPE_GRABBER, -1);
> @@ -1632,6 +1583,7 @@ int pd_video_init(struct poseidon *pd)
> /* VBI uses the same template as video */
> vbi->v_dev = pd_video_template;
> vbi->v_dev.v4l2_dev = &pd->v4l2_dev;
> + vbi->v_dev.ctrl_handler = hdl;
> video_set_drvdata(&vbi->v_dev, pd);
> ret = video_register_device(&vbi->v_dev, VFL_TYPE_VBI, -1);
> if (ret != 0)
Acked-by: Huang Shijie <shijie8@gmail.com>
next prev parent reply other threads:[~2013-02-03 15:43 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-31 10:25 [RFC PATCH 00/18] tlg2300: various v4l2-compliance fixes Hans Verkuil
2013-01-31 10:25 ` [RFC PATCH 01/18] tlg2300: use correct device parent Hans Verkuil
2013-01-31 10:25 ` [RFC PATCH 02/18] tlg2300: fix tuner and frequency handling of the radio device Hans Verkuil
2013-02-04 3:46 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 03/18] tlg2300: switch to unlocked_ioctl Hans Verkuil
2013-02-04 3:48 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 04/18] tlg2300: remove ioctls that are invalid for radio devices Hans Verkuil
2013-02-04 4:16 ` Huang Shijie
2013-02-04 8:34 ` Hans Verkuil
2013-02-05 4:03 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 05/18] tlg2300: embed video_device instead of allocating it Hans Verkuil
2013-02-04 4:26 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 06/18] tlg2300: add control handler for radio device node Hans Verkuil
2013-02-04 4:47 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 07/18] tlg2300: switch to v4l2_fh Hans Verkuil
2013-02-04 4:32 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 08/18] tlg2300: fix radio querycap Hans Verkuil
2013-02-04 4:36 ` Huang Shijie
2013-02-04 8:38 ` Hans Verkuil
2013-02-05 4:07 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 09/18] tlg2300: add missing video_unregister_device Hans Verkuil
2013-02-04 4:38 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 10/18] tlg2300: embed video_device Hans Verkuil
2013-02-04 4:39 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 11/18] tlg2300: fix querycap Hans Verkuil
2013-02-04 4:43 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 12/18] tlg2300: fix frequency handling Hans Verkuil
2013-02-04 4:44 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 13/18] tlg2300: fix missing audioset Hans Verkuil
2013-02-04 4:48 ` Huang Shijie
2013-02-04 8:39 ` Hans Verkuil
2013-02-05 4:07 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 14/18] tlg2300: implement the control framework Hans Verkuil
2013-02-04 4:46 ` Huang Shijie [this message]
2013-01-31 10:25 ` [RFC PATCH 15/18] tlg2300: remove empty vidioc_try_fmt_vid_cap, add missing g_std Hans Verkuil
2013-02-04 4:51 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 16/18] tlg2300: allow multiple opens Hans Verkuil
2013-02-04 4:54 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 17/18] tlg2300: Remove logs() macro Hans Verkuil
2013-02-04 4:54 ` Huang Shijie
2013-01-31 10:25 ` [RFC PATCH 18/18] tlg2300: update MAINTAINERS file Hans Verkuil
2013-02-04 4:55 ` Huang Shijie
2013-02-04 8:40 ` Hans Verkuil
2013-02-04 2:40 ` [RFC PATCH 01/18] tlg2300: use correct device parent Huang Shijie
2013-02-04 8:40 ` Hans Verkuil
2013-02-01 2:22 ` [RFC PATCH 00/18] tlg2300: various v4l2-compliance fixes Huang Shijie
2013-02-01 7:49 ` Hans Verkuil
2013-02-01 8:02 ` Huang Shijie
2013-02-01 8:07 ` Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=510F3D3D.1010304@gmail.com \
--to=shijie8@gmail.com \
--cc=hans.verkuil@cisco.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.