uvcvideo: Fix handling of power_line_frequency
Subsystems (2)
v6 cover uvcvideo: Fix handling of power_line_frequency
Hello,
This series is a new version of "[PATCH v3 0/7] uvcvideo: Fix handling of power_line_frequency", with an attempt to generalize the UVC_QUIRK_LIMITED_POWERLINE quirk that it introduced and turn it into a control mappings override mechanism.
The goal is still to support the UVC 1.5 power line frequency control extra option (patch 1/7), and work around an issue with devices that do not implement support for disabling the power line frequency (patches 2/7 to 7/7).
Changelog v8:
- Add support for per-device control mapping overrides Fix invalid memory access
- Support minimum for V4L2_CTRL_TYPE_MENU
New patch
- Limit power line control for Quanta UVC Webcam Fix id
Ricardo Ribalda (8):
media: uvcvideo: Add missing value for power_line_frequency
media: uvcvideo: Add support for per-device control mapping overrides
media: uvcvideo: Support minimum for V4L2_CTRL_TYPE_MENU
media: uvcvideo: Limit power line control for Quanta UVC Webcam
media: uvcvideo: Limit power line control for Chicony Easycamera
media: uvcvideo: Limit power line control for Chicony Easycamera
media: uvcvideo: Limit power line control for Quanta cameras
media: uvcvideo: Limit power line control for Acer EasyCamera
drivers/media/usb/uvc/uvc_ctrl.c | 87 ++++++++++++++++++++++++----- drivers/media/usb/uvc/uvc_driver.c | 89 ++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 2 + 3 files changed, 163 insertions(+), 15 deletions(-)
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v6 1/8 media: uvcvideo: Add missing value for power_line_frequency
UVC 1.5 class defines 4 values for this control on:
4.2.2.3.6 Power Line Frequency Control
Add the missing value when the UVC version is 1.5.
--- drivers/media/usb/uvc/uvc_ctrl.c | 56 +++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 11 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +45 -11
@@ -366,6 +366,7 @@ static const struct uvc_menu_info power_line_frequency_controls[] = { { 0, "Disabled" }, { 1, "50 Hz" }, { 2, "60 Hz" }, + { 3, "Auto" }, }; static const struct uvc_menu_info exposure_auto_controls[] = {
@@ -504,17 +505,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_INTEGER, .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, }, - { - .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, - .menu_count = ARRAY_SIZE(power_line_frequency_controls), - }, { .id = V4L2_CID_HUE_AUTO, .entity = UVC_GUID_UVC_PROCESSING,
@@ -730,6 +720,34 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, }; +static const struct uvc_control_mapping uvc_ctrl_mappings_uvc11[] = { + { + .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, + .menu_count =ARRAY_SIZE (power_line_frequency_controls) -1 , + }, +}; + +static const struct uvc_control_mapping uvc_ctrl_mappings_uvc15[] = { + { + .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, + .menu_count =ARRAY_SIZE (power_line_frequency_controls), + }, +}; +/* ------------------------------------------------------------------------ * Utility functions */
@@ -2415,6 +2433,22 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,if (!ctrl->initialized)return ; +/* Process common mappings first. */ +for (; mapping < mend; ++mapping) { +if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && + ctrl->info.selector == mapping->selector) +__uvc_ctrl_add_mapping (chain, ctrl, mapping); + } + +/* And then version-specific mappings. */ +if (chain->dev->uvc_version <0x0150 ) { + mapping = uvc_ctrl_mappings_uvc11; + mend = mapping +ARRAY_SIZE (uvc_ctrl_mappings_uvc11); + }else { + mapping = uvc_ctrl_mappings_uvc15; + mend = mapping +ARRAY_SIZE (uvc_ctrl_mappings_uvc15); + } +for (; mapping < mend; ++mapping) {if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector)
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v6 2/8 media: uvcvideo: Add support for per-device control mapping overrides
In reply to Ricardo RibaldaSome devices do not implement all their controls in a way that complies with the UVC specification. This is for instance the case for several devices that do not support the disabled mode for the power line frequency control. Add a mechanism to allow per-device control mapping overrides to avoid errors when accessing non-compliant controls.
--- drivers/media/usb/uvc/uvc_ctrl.c | 35 ++++++++++++++++++++++++++------ drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 30 insertions(+), 6 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +29 -6
@@ -2403,9 +2403,8 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, {const struct uvc_control_info *info = uvc_ctrls;const struct uvc_control_info *iend = info +ARRAY_SIZE (uvc_ctrls); -const struct uvc_control_mapping *mapping = uvc_ctrl_mappings; -const struct uvc_control_mapping *mend = - mapping +ARRAY_SIZE (uvc_ctrl_mappings); +const struct uvc_control_mapping *mapping; +const struct uvc_control_mapping *mend;/* XU controls initialization requires querying the device for control * information. As some buggy UVC devices will crash when queried
@@ -2433,14 +2432,38 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,if (!ctrl->initialized)return ; -/* Process common mappings first. */ -for (; mapping < mend; ++mapping) { +/* +* First check if the device provides a custom mapping for this control, +* used to override standard mappings for non-conformant devices. Don't +* process standard mappings if a custom mapping is found. This +* mechanism doesn't support combining standard and custom mappings for +* a single control. +*/ +if (chain->dev->info->mappings) { +bool custom = false; +unsigned int i; + +for (i =0 ; (mapping = chain->dev->info->mappings[i]); ++i) { +if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && + ctrl->info.selector == mapping->selector) { +__uvc_ctrl_add_mapping (chain, ctrl, mapping); + custom = true; + } + } + +if (custom) +return ; + } + +/* Process common mappings next. */ + mend = mapping +ARRAY_SIZE (uvc_ctrl_mappings); +for (mapping = uvc_ctrl_mappings; mapping < mend; ++mapping) {if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector)__uvc_ctrl_add_mapping (chain, ctrl, mapping); } -/* And then version-specific mappings. */ +/* Finally process version-specific mappings. */ if (chain->dev->uvc_version <0x0150 ) { mapping = uvc_ctrl_mappings_uvc11; mend = mapping +ARRAY_SIZE (uvc_ctrl_mappings_uvc11);
drivers/media/usb/uvc/uvcvideo.h +1 -0
@@ -667,6 +667,7 @@ struct uvc_device_info {u32 quirks;u32 meta_format;u16 uvc_version; +const struct uvc_control_mapping **mappings; };struct uvc_device {
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v6 3/8 media: uvcvideo: Support minimum for V4L2_CTRL_TYPE_MENU
In reply to Ricardo RibaldaCurrently all mappings of type V4L2_CTRL_TYPE_MENU, have a minimum of 0, but there are some controls (limited powerline), that start with a value different than 0.
--- drivers/media/usb/uvc/uvc_ctrl.c | 2 +- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_ctrl.c +1 -1
@@ -1144,7 +1144,7 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,switch (mapping->v4l2_type) {case V4L2_CTRL_TYPE_MENU : - v4l2_ctrl->minimum =0 ; + v4l2_ctrl->minimum = mapping->menu_min; v4l2_ctrl->maximum = mapping->menu_count -1 ; v4l2_ctrl->step =1 ;
drivers/media/usb/uvc/uvcvideo.h +1 -0
@@ -254,6 +254,7 @@ struct uvc_control_mapping {u32 data_type;const struct uvc_menu_info *menu_info; +u32 menu_min;u32 menu_count;u32 master_id;
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v6 4/8 media: uvcvideo: Limit power line control for Quanta UVC Webcam
In reply to Ricardo RibaldaThe device does not implement the power line control correctly. Add a corresponding control mapping override.
Bus 001 Device 003: ID 0408:3090 Quanta Computer, Inc. USB2.0 HD UVC WebCam Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x0408 Quanta Computer, Inc.
idProduct 0x3090
bcdDevice 0.04
iManufacturer 3 Quanta iProduct 1 USB2.0 HD UVC WebCam iSerial 2 0x0001 bNumConfigurations 1
--- drivers/media/usb/uvc/uvc_driver.c | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +35 -0
@@ -2643,6 +2643,32 @@ MODULE_PARM_DESC(timeout, "Streaming control requests timeout");* Driver initialization and cleanup */ +static const struct uvc_menu_info power_line_frequency_controls_limited[] = { + {0 ,"Invalid" }, + {1 ,"50 Hz" }, + {2 ,"60 Hz" }, +}; + +static const struct uvc_control_mapping uvc_ctrl_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_min =1 , + .menu_count =ARRAY_SIZE (power_line_frequency_controls_limited), +}; + +static const struct uvc_device_info uvc_ctrl_power_line_limited = { + .mappings = (const struct uvc_control_mapping *[]) { + &uvc_ctrl_power_line_mapping_limited, +NULL ,/* Sentinel */ + }, +}; +static const struct uvc_device_info uvc_quirk_probe_minmax = { .quirks =UVC_QUIRK_PROBE_MINMAX , };
@@ -2673,6 +2699,15 @@ static const struct uvc_device_info uvc_quirk_force_y8 = {* though they are compliant. */ static const struct usb_device_id uvc_ids[] = { +/* Quanta USB2.0 HD UVC Webcam */ + { .match_flags =USB_DEVICE_ID_MATCH_DEVICE + |USB_DEVICE_ID_MATCH_INT_INFO , + .idVendor =0x0408 , + .idProduct =0x3090 , + .bInterfaceClass =USB_CLASS_VIDEO , + .bInterfaceSubClass =1 , + .bInterfaceProtocol =0 , + .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },/* LogiLink Wireless Webcam */ { .match_flags =USB_DEVICE_ID_MATCH_DEVICE |USB_DEVICE_ID_MATCH_INT_INFO ,
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v6 5/8 media: uvcvideo: Limit power line control for Chicony Easycamera
In reply to Ricardo RibaldaTwo different Easycamera devices do not implement the power line control correctly. Add a corresponding control mapping override.
Bus 001 Device 003: ID 04f2:b6ba Chicony Electronics Co., Ltd EasyCamera Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x04f2 Chicony Electronics Co., Ltd
idProduct 0xb6ba
bcdDevice 10.70
iManufacturer 3 Chicony Electronics Co.,Ltd. iProduct 1 EasyCamera iSerial 2 0001 bNumConfigurations 1
Bus 001 Device 003: ID 04f2:b746 Chicony Electronics Co., Ltd EasyCamera Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x04f2 Chicony Electronics Co., Ltd
idProduct 0xb746
bcdDevice 97.57
iManufacturer 3 Chicony Electronics Co.,Ltd. iProduct 1 EasyCamera iSerial 2 0001 bNumConfigurations 1
--- drivers/media/usb/uvc/uvc_driver.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +18 -0
@@ -2819,6 +2819,24 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) }, +/* Chicony EasyCamera */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x04f2, + .idProduct = 0xb6ba, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited }, +/* Chicony EasyCamera */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x04f2, + .idProduct = 0xb746, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },/* Alcor Micro AU3820 (Future Boy PC USB Webcam) */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v6 6/8 media: uvcvideo: Limit power line control for Chicony Easycamera
In reply to Ricardo RibaldaAnother Chicony camera device does not implement the power line control correctly. Add a corresponding control mapping override.
Bus 001 Device 003: ID 04f2:b5eb Chicony Electronics Co., Ltd EasyCamera Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x04f2 Chicony Electronics Co., Ltd
idProduct 0xb5eb
bcdDevice 90.45
iManufacturer 3 Chicony Electronics Co.,Ltd. iProduct 1 EasyCamera iSerial 2 0001 bNumConfigurations 1
--- drivers/media/usb/uvc/uvc_driver.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +9 -0
@@ -2820,6 +2820,15 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceProtocol = 0, .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTRICT_FRAME_RATE) },/* Chicony EasyCamera */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x04f2, + .idProduct = 0xb5eb, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited }, +/* Chicony EasyCamera */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, .idVendor = 0x04f2,
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v6 7/8 media: uvcvideo: Limit power line control for Quanta cameras
In reply to Ricardo RibaldaTwo more cameras do not implement the power line control correctly. Add a corresponding control mapping override.
Bus 001 Device 003: ID 0408:4034 Quanta Computer, Inc. ACER HD User Facing Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.01
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x0408 Quanta Computer, Inc.
idProduct 0x4034
bcdDevice 0.01
iManufacturer 1 Quanta iProduct 2 ACER HD User Facing iSerial 3 01.00.00 bNumConfigurations 1
Bus 001 Device 003: ID 0408:4030 Quanta Computer, Inc. HD User Facing Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.01
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x0408 Quanta Computer, Inc.
idProduct 0x4030
bcdDevice 0.02
iManufacturer 1 Quanta iProduct 2 HD User Facing iSerial 3 01.00.00 bNumConfigurations 1
--- drivers/media/usb/uvc/uvc_driver.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +18 -0
@@ -2708,6 +2708,24 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited }, +/* Quanta USB2.0 HD UVC Webcam */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x0408, + .idProduct = 0x4030, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 1, + .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited }, +/* Quanta USB2.0 HD UVC Webcam */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x0408, + .idProduct = 0x4034, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },/* LogiLink Wireless Webcam */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v6 8/8 media: uvcvideo: Limit power line control for Acer EasyCamera
In reply to Ricardo RibaldaThe device does not implement the power line control correctly. Add a corresponding control mapping override.
Bus 001 Device 003: ID 5986:1172 Acer, Inc EasyCamera Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x5986 Acer, Inc
idProduct 0x1172
bcdDevice 56.04
iManufacturer 3 Bison iProduct 1 EasyCamera iSerial 2 bNumConfigurations 1
--- drivers/media/usb/uvc/uvc_driver.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +9 -0
@@ -3248,6 +3248,15 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) }, +/* Acer EasyCamera */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x5986, + .idProduct = 0x1172, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },/* Intel RealSense D4M */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
Signature · 1 line
2.36.1.476.g0c4daa206d-goog