diff mbox series

[v2,2/4] media: uvcvideo: Add UVC_QUIRK_LIMITED_POWERLINE

Message ID 20220519181306.42136-3-ribalda@chromium.org (mailing list archive)
State New
Headers show
Series uvcvideo: Fix handling of power_line_frequency | expand

Commit Message

Ricardo Ribalda May 19, 2022, 6:13 p.m. UTC
Add a quirk for devices that only support a limited set of Power Line
frequencies.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 drivers/media/usb/uvc/uvc_ctrl.c | 24 ++++++++++++++++++++++++
 drivers/media/usb/uvc/uvcvideo.h |  1 +
 2 files changed, 25 insertions(+)
diff mbox series

Patch

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index a942021dfbe1..5027fedc4f39 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -375,6 +375,11 @@  static const struct uvc_menu_info power_line_frequency_controls_uvc15[] = {
 	{ 3, "Auto" },
 };
 
+static const struct uvc_menu_info power_line_frequency_controls_limited[] = {
+	{ 1, "50 Hz" },
+	{ 2, "60 Hz" },
+};
+
 static const struct uvc_menu_info exposure_auto_controls[] = {
 	{ 2, "Auto Mode" },
 	{ 1, "Manual Mode" },
@@ -752,6 +757,19 @@  struct uvc_control_mapping power_line_mapping_uvc15 = {
 	.menu_count	= ARRAY_SIZE(power_line_frequency_controls_uvc15),
 };
 
+static const
+struct uvc_control_mapping power_line_mapping_limited = {
+	.id		= V4L2_CID_POWER_LINE_FREQUENCY,
+	.entity		= UVC_GUID_UVC_PROCESSING,
+	.selector	= UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
+	.size		= 2,
+	.offset		= 0,
+	.v4l2_type	= V4L2_CTRL_TYPE_MENU,
+	.data_type	= UVC_CTRL_DATA_TYPE_ENUM,
+	.menu_info	= power_line_frequency_controls_limited,
+	.menu_count	= ARRAY_SIZE(power_line_frequency_controls_limited),
+};
+
 /* ------------------------------------------------------------------------
  * Utility functions
  */
@@ -2395,6 +2413,12 @@  static void uvc_ctrl_prune_entity(struct uvc_device *dev,
 static void uvc_ctrl_init_powerline(struct uvc_video_chain *chain,
 				    struct uvc_control *ctrl)
 {
+	if (chain->dev->quirks & UVC_QUIRK_LIMITED_POWERLINE) {
+		__uvc_ctrl_add_mapping(chain, ctrl,
+				       &power_line_mapping_limited);
+		return;
+	}
+
 	if (chain->dev->uvc_version < 0x0150) {
 		__uvc_ctrl_add_mapping(chain, ctrl,
 				       &power_line_mapping_uvc11);
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 143230b3275b..06779eb4f5fa 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -209,6 +209,7 @@ 
 #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT	0x00000400
 #define UVC_QUIRK_FORCE_Y8		0x00000800
 #define UVC_QUIRK_FORCE_BPP		0x00001000
+#define UVC_QUIRK_LIMITED_POWERLINE     0x00002000
 
 /* Format flags */
 #define UVC_FMT_FLAG_COMPRESSED		0x00000001