| From a7b14e542610f2a1c895254c87427034b9daadb0 Mon Sep 17 00:00:00 2001 |
| From: Sergey Senozhatsky <senozhatsky@chromium.org> |
| Date: Wed, 23 Jun 2021 12:08:36 +0900 |
| Subject: [PATCH] CHROMIUM: FROMLIST: media: uvcvideo: add ROI auto controls |
| |
| This patch adds support for Region of Interest bmAutoControls. |
| |
| ROI control is a compound data type: |
| Control Selector CT_REGION_OF_INTEREST_CONTROL |
| Mandatory Requests SET_CUR, GET_CUR, GET_MIN, GET_MAX, GET_DEF |
| wLength 10 |
| Offset Field Size |
| 0 wROI_Top 2 |
| 2 wROI_Left 2 |
| 4 wROI_Bottom 2 |
| 6 wROI_Right 2 |
| 8 bmAutoControls 2 (Bitmap) |
| |
| uvc_control_mapping, however, can handle only s32 data type at the |
| moment: ->get() returns s32 value, ->set() accepts s32 value; while |
| v4l2_ctrl maximum/minimum/default_value can hold only s64 values. |
| |
| Hence ROI control handling is split into two patches: |
| a) bmAutoControls is handled via uvc_control_mapping as V4L2_CTRL_TYPE_BITMASK |
| b) ROI rectangle (SET_CUR, GET_CUR, GET_DEF, etc.) handling is implemented |
| separately, by the means of selection API. |
| |
| [senozhatsky: this patch includes an extra change that uses SHRT_MAX as |
| CID value, see crrev.com/c/2984868] |
| |
| (am from https://lore.kernel.org/lkml/20210501082001.100533-4-senozhatsky@chromium.org) |
| |
| BUG=b:186835892 |
| TEST=backport of a series that was tested on v4.19 kernel |
| TEST=v4l2-ctl on hatch and drallion |
| |
| Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> |
| Change-Id: Ibe3194dca45bf6746b2475e0b5d9f0b9856c4846 |
| Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2981316 |
| Reviewed-by: Ricardo Ribalda <ribalda@chromium.org> |
| --- |
| drivers/media/usb/uvc/uvc_ctrl.c | 19 +++++++++++++++++++ |
| include/uapi/linux/usb/video.h | 1 + |
| include/uapi/linux/v4l2-controls.h | 20 +++++++++++++++++++- |
| 3 files changed, 39 insertions(+), 1 deletion(-) |
| |
| diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c |
| index 159783876e39..3641787458ea 100644 |
| --- a/drivers/media/usb/uvc/uvc_ctrl.c |
| +++ b/drivers/media/usb/uvc/uvc_ctrl.c |
| @@ -355,6 +355,15 @@ static const struct uvc_control_info uvc_ctrls[] = { |
| .flags = UVC_CTRL_FLAG_GET_CUR |
| | UVC_CTRL_FLAG_AUTO_UPDATE, |
| }, |
| + { |
| + .entity = UVC_GUID_UVC_CAMERA, |
| + .selector = UVC_CT_REGION_OF_INTEREST_CONTROL, |
| + .index = 21, |
| + .size = 10, |
| + .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| + | UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX |
| + | UVC_CTRL_FLAG_GET_DEF |
| + }, |
| }; |
| |
| static const struct uvc_menu_info power_line_frequency_controls[] = { |
| @@ -753,6 +762,16 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { |
| .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, |
| .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, |
| }, |
| + { |
| + .id = V4L2_CID_REGION_OF_INTEREST_AUTO, |
| + .name = "Region of Interest (auto)", |
| + .entity = UVC_GUID_UVC_CAMERA, |
| + .selector = UVC_CT_REGION_OF_INTEREST_CONTROL, |
| + .size = 16, |
| + .offset = 64, |
| + .v4l2_type = V4L2_CTRL_TYPE_BITMASK, |
| + .data_type = UVC_CTRL_DATA_TYPE_BITMASK, |
| + }, |
| }; |
| |
| /* ------------------------------------------------------------------------ |
| diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h |
| index bfdae12cdacf..9076a444758a 100644 |
| --- a/include/uapi/linux/usb/video.h |
| +++ b/include/uapi/linux/usb/video.h |
| @@ -104,6 +104,7 @@ |
| #define UVC_CT_ROLL_ABSOLUTE_CONTROL 0x0f |
| #define UVC_CT_ROLL_RELATIVE_CONTROL 0x10 |
| #define UVC_CT_PRIVACY_CONTROL 0x11 |
| +#define UVC_CT_REGION_OF_INTEREST_CONTROL 0x14 |
| |
| /* A.9.5. Processing Unit Control Selectors */ |
| #define UVC_PU_CONTROL_UNDEFINED 0x00 |
| diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h |
| index fdf97a6d7d18..4f0b4a1a31f1 100644 |
| --- a/include/uapi/linux/v4l2-controls.h |
| +++ b/include/uapi/linux/v4l2-controls.h |
| @@ -986,7 +986,6 @@ enum v4l2_auto_focus_range { |
| |
| #define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32) |
| #define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33) |
| - |
| #define V4L2_CID_CAMERA_ORIENTATION (V4L2_CID_CAMERA_CLASS_BASE+34) |
| #define V4L2_CAMERA_ORIENTATION_FRONT 0 |
| #define V4L2_CAMERA_ORIENTATION_BACK 1 |
| @@ -994,6 +993,25 @@ enum v4l2_auto_focus_range { |
| |
| #define V4L2_CID_CAMERA_SENSOR_ROTATION (V4L2_CID_CAMERA_CLASS_BASE+35) |
| |
| +/* |
| + * senozhatsky@ b:191930245 |
| + * |
| + * These are FROMLIST defines. Use very high value to avoid collisions |
| + * with upstream patches. Controls classes are USHRT_MAX apart from each |
| + * other, but the lower 0x900 are not being used. This leaves us with the |
| + * USHRT_MAX - 0x900 values. Use SHRT_MAX. |
| + */ |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO \ |
| + (V4L2_CID_CAMERA_CLASS_BASE + SHRT_MAX) |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE (1 << 0) |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS (1 << 1) |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE (1 << 2) |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS (1 << 3) |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT (1 << 4) |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK (1 << 5) |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION (1 << 6) |
| +#define V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY (1 << 7) |
| + |
| /* FM Modulator class control IDs */ |
| |
| #define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900) |
| -- |
| 2.32.0.93.g670b81a890-goog |
| |