From: Yunke Cao <yunkec@google.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Tomasz Figa <tfiga@chromium.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Ricardo Ribalda <ribalda@chromium.org>,
linux-media@vger.kernel.org, Yunke Cao <yunkec@google.com>
Subject: [PATCH v10 03/11 RESEND] media: uvcvideo: introduce __uvc_ctrl_get_std()
Date: Thu, 1 Dec 2022 11:31:56 +0900 [thread overview]
Message-ID: <20221201023204.2177458-4-yunkec@google.com> (raw)
In-Reply-To: <20221201023204.2177458-1-yunkec@google.com>
Refactor uvc_ctrl to make adding compound control easier.
Currently uvc_ctrl_get() only work for non-compound controls.
Move the logic into uvc_ctrl_std(), return error for compound
controls.
Signed-off-by: Yunke Cao <yunkec@google.com>
---
Changelog since v9:
- No change.
Changelog since v8:
- No change.
Changelog since v7:
- Newly added patch. Split the refactoring of uvc_ctrl_get from v7 3/7.
drivers/media/usb/uvc/uvc_ctrl.c | 40 +++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index dfb9d1daece6..93ae7ba5d0cc 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1028,15 +1028,15 @@ static int __uvc_ctrl_load_cur(struct uvc_video_chain *chain,
return ret;
}
-static int __uvc_ctrl_get(struct uvc_video_chain *chain,
- struct uvc_control *ctrl,
- struct uvc_control_mapping *mapping,
- s32 *value)
+static int __uvc_ctrl_get_std(struct uvc_video_chain *chain,
+ struct uvc_control *ctrl,
+ struct uvc_control_mapping *mapping,
+ s32 *value)
{
int ret;
- if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0)
- return -EACCES;
+ if (uvc_ctrl_mapping_is_compound(mapping))
+ return -EINVAL;
ret = __uvc_ctrl_load_cur(chain, ctrl);
if (ret < 0)
@@ -1153,8 +1153,13 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
__uvc_find_control(ctrl->entity, mapping->master_id,
&master_map, &master_ctrl, 0);
if (master_ctrl && (master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) {
- s32 val;
- int ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val);
+ s32 val = 0;
+ int ret;
+
+ if (uvc_ctrl_mapping_is_compound(master_map))
+ return -EINVAL;
+
+ ret = __uvc_ctrl_get_std(chain, master_ctrl, master_map, &val);
if (ret < 0)
return ret;
@@ -1399,7 +1404,8 @@ static void uvc_ctrl_send_slave_event(struct uvc_video_chain *chain,
if (ctrl == NULL)
return;
- if (__uvc_ctrl_get(chain, ctrl, mapping, &val) == 0)
+ if (uvc_ctrl_mapping_is_compound(mapping) ||
+ __uvc_ctrl_get_std(chain, ctrl, mapping, &val) == 0)
changes |= V4L2_EVENT_CTRL_CH_VALUE;
uvc_ctrl_send_event(chain, handle, ctrl, mapping, val, changes);
@@ -1566,7 +1572,8 @@ static int uvc_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems)
u32 changes = V4L2_EVENT_CTRL_CH_FLAGS;
s32 val = 0;
- if (__uvc_ctrl_get(handle->chain, ctrl, mapping, &val) == 0)
+ if (uvc_ctrl_mapping_is_compound(mapping) ||
+ __uvc_ctrl_get_std(handle->chain, ctrl, mapping, &val) == 0)
changes |= V4L2_EVENT_CTRL_CH_VALUE;
uvc_ctrl_fill_event(handle->chain, &ev, ctrl, mapping, val,
@@ -1746,7 +1753,10 @@ int uvc_ctrl_get(struct uvc_video_chain *chain,
if (ctrl == NULL)
return -EINVAL;
- return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value);
+ if (uvc_ctrl_mapping_is_compound(mapping))
+ return -EINVAL;
+ else
+ return __uvc_ctrl_get_std(chain, ctrl, mapping, &xctrl->value);
}
static int __uvc_ctrl_get_boundary_std(struct uvc_video_chain *chain,
@@ -1893,8 +1903,12 @@ int uvc_ctrl_set(struct uvc_fh *handle,
ctrl->info.size);
}
- mapping->set(mapping, value,
- uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
+ if (!uvc_ctrl_mapping_is_compound(mapping))
+ mapping->set(mapping, value,
+ uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
+ else
+ return -EINVAL;
+
if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS)
ctrl->handle = handle;
--
2.38.1.584.g0f3c55d4c2-goog
next prev parent reply other threads:[~2022-12-01 2:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 2:31 [PATCH v10 00/11 RESEND] media: Implement UVC v1.5 ROI Yunke Cao
2022-12-01 2:31 ` [PATCH v10 01/11 RESEND] media: v4l2_ctrl: Add V4L2_CTRL_TYPE_RECT Yunke Cao
2022-12-01 3:43 ` Sergey Senozhatsky
2022-12-01 2:31 ` [PATCH v10 02/11 RESEND] media: uvcvideo: add uvc_ctrl_get_boundary for getting default value Yunke Cao
2022-12-01 3:47 ` Sergey Senozhatsky
2022-12-01 7:15 ` kernel test robot
2022-12-01 7:44 ` Yunke Cao
2022-12-01 2:31 ` Yunke Cao [this message]
2022-12-01 2:31 ` [PATCH v10 04/11 RESEND] media: uvcvideo: Split uvc_control_mapping.size to v4l2 and data size Yunke Cao
2022-12-01 2:31 ` [PATCH v10 05/11 RESEND] media: uvcvideo: Add support for compound controls Yunke Cao
2022-12-01 2:31 ` [PATCH v10 06/11 RESEND] media: uvcvideo: implement UVC v1.5 ROI Yunke Cao
2022-12-01 2:32 ` [PATCH v10 07/11 RESEND] media: uvcvideo: initilaize ROI control to default value Yunke Cao
2022-12-01 2:32 ` [PATCH v10 08/11 RESEND] v4l2-ctrls: add support for V4L2_CTRL_WHICH_MIN/MAX_VAL Yunke Cao
2022-12-01 2:32 ` [PATCH v10 09/11 RESEND] media: v4l2: document the usage of min/max for V4L2_CTRL_TYPE_RECT Yunke Cao
2022-12-01 3:59 ` Sergey Senozhatsky
2022-12-06 8:45 ` Yunke Cao
2022-12-01 2:32 ` [PATCH v10 10/11 RESEND] media: uvcvideo: support V4L2_CTRL_WHICH_MIN/MAX_VAL Yunke Cao
2022-12-01 3:51 ` Sergey Senozhatsky
2022-12-01 2:32 ` [PATCH v10 11/11 RESEND] media: uvcvideo: document UVC v1.5 ROI Yunke Cao
2022-12-01 3:50 ` Sergey Senozhatsky
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=20221201023204.2177458-4-yunkec@google.com \
--to=yunkec@google.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=ribalda@chromium.org \
--cc=senozhatsky@chromium.org \
--cc=tfiga@chromium.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox