uvcvideo: Add quirk for Quanta NL3 laptop camera
Subsystems (2)
PATCH 1/1 uvcvideo: Add quirk for Quanta NL3 laptop camera
The Quanta NL3 laptop has a UVC camera which the descriptor says comes from Realtek: https://gist.github.com/dsd/9a6567baa53c747fd306
Probe fails, because the output terminal (ID 3) references a non-existent source with ID 6. Fixing it to add itself onto the end of the chain makes the camera work.
--- drivers/media/usb/uvc/uvc_driver.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 37 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +36 -0
@@ -1575,6 +1575,30 @@ static const char *uvc_print_chain(struct uvc_video_chain *chain) }/* +* This Realtek camera has a broken descriptor. The output terminal +* references a non-existent source. The rest of the simple chain is +* fine. Fix the OT to chain on to the end. +*/ +static void uvc_handle_rtl57a7 (struct uvc_device *dev) +{ +struct uvc_entity *term; + + term =uvc_entity_by_id (dev,3 ); +if (!term) { +uvc_printk (KERN_INFO ,"RTL57A7: no entity with id 3\n" ); +return ; + } + +if (!UVC_ENTITY_IS_OTERM (term)) { +uvc_printk (KERN_INFO ,"RTL57A7: entity 3 is not OT\n" ); +return ; + } + + term->baSourceID[0 ] =4 ; +uvc_printk (KERN_INFO ,"Applied RTL57A7 chain quirk.\n" ); +} + +/* * Scan the device for video chains and register video devices. * * Chains are scanned starting at their output terminals and walked backwards.
@@ -1584,6 +1608,9 @@ static int uvc_scan_device(struct uvc_device *dev)struct uvc_video_chain *chain;struct uvc_entity *term; +if (dev->quirks &UVC_QUIRK_RTL57A7 ) +uvc_handle_rtl57a7 (dev); +list_for_each_entry (term, &dev->entities, list) {if (!UVC_ENTITY_IS_OTERM (term))continue ;
@@ -2351,6 +2378,15 @@ static struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_QUIRK_PROBE_MINMAX }, +/* Realtek camera in Quanta NL3 laptop */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x0bda, + .idProduct = 0x57a7, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_QUIRK_RTL57A7 }, /* MT6227 */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
drivers/media/usb/uvc/uvcvideo.h +1 -0
@@ -152,6 +152,7 @@#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200#define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400#define UVC_QUIRK_FORCE_Y8 0x00000800 +#define UVC_QUIRK_RTL57A7 0x00001000/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001
Signature · 1 line
2.1.0
Laurent Pinchart
maintainerHi Daniel,
Thank you for the patch and sorry for the late response.
Quoted 6 lines · On Thursday 12 March 2015 14:59:07 Daniel Drake wrote:
The Quanta NL3 laptop has a UVC camera which the descriptor says comes from Realtek: https://gist.github.com/dsd/9a6567baa53c747fd306
Probe fails, because the output terminal (ID 3) references a non-existent source with ID 6. Fixing it to add itself onto the end of the chain makes the camera work.
I knew a device with broken descriptors would come one day. It actually took much longer than I expected.
I'm not sure that adding a device-specific quirk is the bast way to handle this problem, as it wouldn't really scale if other devices expose buggy descriptors. A more generic way to patch or override descriptors might be better, with a single quirk and a pointer to a patch function. This would require refactoring the quirks system to store a structure pointer instead of a bitfield in the driver_info field.
What's your opinion ?
Quoted 81 lines
Signed-off-by Daniel Drake <[email protected]>--- drivers/media/usb/uvc/uvc_driver.c | 36 +++++++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 37 insertions(+)(quoted diff) +0
-0
b/drivers/media/usb/uvc/uvc_driver.cindex cf27006..3cb4be3 100644drivers/media/usb/uvc/uvc_driver.c +24
-0@@ -1575,6 +1575,30 @@ static const char *uvc_print_chain(struct uvc_video_chain *chain) }/* +* This Realtek camera has a broken descriptor. The output terminal +* references a non-existent source. The rest of the simple chain is +* fine. Fix the OT to chain on to the end. +*/ +static void uvc_handle_rtl57a7 (struct uvc_device *dev) +{ +struct uvc_entity *term; + + term =uvc_entity_by_id (dev,3 ); +if (!term) { +uvc_printk (KERN_INFO ,"RTL57A7: no entity with id 3\n" ); +return ; + } + +if (!UVC_ENTITY_IS_OTERM (term)) { +uvc_printk (KERN_INFO ,"RTL57A7: entity 3 is not OT\n" ); +return ; + } + + term->baSourceID[0 ] =4 ; +uvc_printk (KERN_INFO ,"Applied RTL57A7 chain quirk.\n" ); +} + +/* * Scan the device for video chains and register video devices. * * Chains are scanned starting at their output terminals and walked backwards. @@ -1584,6 +1608,9 @@ static int
uvc_scan_device(struct uvc_device *dev)structuvc_video_chain*chain;drivers/media/usb/uvc/uvc_driver.c +12
-0struct uvc_entity *term; +if (dev->quirks &UVC_QUIRK_RTL57A7 ) +uvc_handle_rtl57a7 (dev); +list_for_each_entry (term, &dev->entities, list) {if (!UVC_ENTITY_IS_OTERM (term))continue ;@@ -2351,6 +2378,15 @@ static struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_QUIRK_PROBE_MINMAX }, +/* Realtek camera in Quanta NL3 laptop */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x0bda, + .idProduct = 0x57a7, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_QUIRK_RTL57A7 }, /* MT6227 */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICEdrivers/media/usb/uvc/uvc_driver.c +0
-0| USB_DEVICE_ID_MATCH_INT_INFO,(quoted diff) +0
-0
b/drivers/media/usb/uvc/uvcvideo.hindex c63e5b5..710e480 100644drivers/media/usb/uvc/uvcvideo.h +1
-0@@ -152,6 +152,7 @@#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200#define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400#define UVC_QUIRK_FORCE_Y8 0x00000800 +#define UVC_QUIRK_RTL57A7 0x00001000/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Quoted 6 lines · Laurent Pinchart
I'm not sure that adding a device-specific quirk is the bast way to handle this problem, as it wouldn't really scale if other devices expose buggy descriptors. A more generic way to patch or override descriptors might be better, with a single quirk and a pointer to a patch function. This would require refactoring the quirks system to store a structure pointer instead of a bitfield in the
driver_infofield.
I agree, but I don't currently have time to work on a more advanced approach.
I think that's OK for everyone, as I can work with this patch for the time being, and if nobody else has broken descriptors, there's no particular rush.
Thanks,
Daniel