media: uvcvideo: Add quirk for exponential exposure
Subsystems (2)
cover media: uvcvideo: Add quirk for exponential exposure
Ever since I started using them, I've noticed that the absolute exposure control for the LifeCam webcam hasn't functioned properly. After some poking around, I managed to charactarize the behavior. To summarize, only values which follow an exponential pattern appear to result in the intended change to the webcam's image.
Ideally this quirky behavior could be handled with an extension unit, but I'm not sure this behavior can be implemented there. I tested this patch with the two LifeCam webcams I have on hand.
Scott K Logan (1):
media: uvcvideo: Add quirk for exponential exposure
drivers/media/usb/uvc/uvc_ctrl.c | 41 ++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_driver.c | 18 +++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 60 insertions(+)
Signature · 1 line
2.31.1
PATCH 1/1 media: uvcvideo: Add quirk for exponential exposure
At least some of the Microsoft LifeCam series of webcams exhibit a behavior which requires a 'quirk' to be handled properly. When configuring the absolute exposure value of the image, there are only a handful of values which will result in a consistent change to the image exposure, while all other values appear to result in a maximum exposure.
The valid values appear to follow an exponential pattern from the maximum value (10000) down to the minimum, yielding less than 15 possible values depending on the device's reported minimum.
--- drivers/media/usb/uvc/uvc_ctrl.c | 41 ++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_driver.c | 18 +++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 60 insertions(+)
drivers/media/usb/uvc/uvc_ctrl.c +41 -0
@@ -2142,6 +2142,40 @@ int uvc_ctrl_restore_values(struct uvc_device *dev)return 0 ; } +/* -------------------------------------------------------------------------- +* Quirks +*/ + +static s32 uvc_ctrl_get_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,u8 query,const u8 *data) +{ +s32 i; +s32 value =uvc_get_le_value (mapping, query, data); + +switch (query) { +case UVC_GET_CUR : +case UVC_GET_MIN : +case UVC_GET_MAX : +case UVC_GET_DEF : +for (i =0 ; i <14 ; ++i) { +if (10000 >> i <= value) +break ; + } +return 14 - i; +case UVC_GET_RES : +return 1 ; +default : +return value; + } +} + +static void uvc_ctrl_set_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,s32 value,u8 *data) +{ + value =10000 >> (14 - value); +uvc_set_le_value (mapping, value, data); +} +/* -------------------------------------------------------------------------- * Control and mapping handling */
@@ -2210,6 +2244,13 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, } } +if ((chain->dev->quirks &UVC_QUIRK_EXPONENTIAL_EXPOSURE ) && + ctrl->info.selector ==UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL ) { +uvc_dbg (chain->dev,CONTROL ,"Applying exponential exposure quirk\n" ); + map->get = uvc_ctrl_get_abs_exposure_exponential; + map->set = uvc_ctrl_set_abs_exposure_exponential; + } +list_add_tail (&map->list, &ctrl->info.mappings); uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", uvc_map_get_name(map), ctrl->info.entity,
drivers/media/usb/uvc/uvc_driver.c +18 -0
@@ -2718,6 +2718,24 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, +/* Microsoft Lifecam HD-5000 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x076d, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, + /* Microsoft Lifecam Studio */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x0772, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, /* Logitech Quickcam Fusion */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
drivers/media/usb/uvc/uvcvideo.h +1 -0
@@ -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_EXPONENTIAL_EXPOSURE 0x00002000/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001
Signature · 1 line
2.31.1
Quoted 9 lines · Scott K Logan
At least some of the Microsoft LifeCam series of webcams exhibit a behavior which requires a 'quirk' to be handled properly. When configuring the absolute exposure value of the image, there are only a handful of values which will result in a consistent change to the image exposure, while all other values appear to result in a maximum exposure.
The valid values appear to follow an exponential pattern from the maximum value (10000) down to the minimum, yielding less than 15 possible values depending on the device's reported minimum.
FTR, I have not tested patch (yet), but I checked
idVendor 0x045e Microsoft Corp.
idProduct 0x0810 LifeCam HD-3000
bcdDevice 1.08
iManufacturer 1 iProduct 2 iSerial 0
and it exhibit same behavior (only (1e4>>i) works, other values interpreted as max), so you may want to add chunk below
Quoted 73 lines
Signed-off-by Scott K Logan <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 41 ++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_driver.c | 18 +++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 60 insertions(+)drivers/media/usb/uvc/uvc_ctrl.c +41
-0@@ -2142,6 +2142,40 @@ int uvc_ctrl_restore_values(struct uvc_device *dev)return 0 ; } +/* -------------------------------------------------------------------------- +* Quirks +*/ + +static s32 uvc_ctrl_get_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,u8 query,const u8 *data) +{ +s32 i; +s32 value =uvc_get_le_value (mapping, query, data); + +switch (query) { +case UVC_GET_CUR : +case UVC_GET_MIN : +case UVC_GET_MAX : +case UVC_GET_DEF : +for (i =0 ; i <14 ; ++i) { +if (10000 >> i <= value) +break ; + } +return 14 - i; +case UVC_GET_RES : +return 1 ; +default : +return value; + } +} + +static void uvc_ctrl_set_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,s32 value,u8 *data) +{ + value =10000 >> (14 - value); +uvc_set_le_value (mapping, value, data); +} +/* -------------------------------------------------------------------------- * Control and mapping handling */ @@ -2210,6 +2244,13 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, } } +if ((chain->dev->quirks &UVC_QUIRK_EXPONENTIAL_EXPOSURE ) && + ctrl->info.selector ==UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL ) { +uvc_dbg (chain->dev,CONTROL ,"Applying exponential exposure quirk\n" ); + map->get = uvc_ctrl_get_abs_exposure_exponential; + map->set = uvc_ctrl_set_abs_exposure_exponential; + } +list_add_tail (&map->list, &ctrl->info.mappings); uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", uvc_map_get_name(map), ctrl->info.entity,drivers/media/usb/uvc/uvc_driver.c +0
-0@@ -2718,6 +2718,24 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0,
drivers/media/usb/uvc/uvc_driver.c static const struct usb_device_id uvc_ids[] = { · line 2729
Quoted 10 lines
drivers/media/usb/uvc/uvc_driver.c +9
-0.driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, +/* Microsoft Lifecam HD-5000 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x076d, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) },
+ /* Microsoft Lifecam HD-3000 */
+ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
+ | USB_DEVICE_ID_MATCH_INT_INFO,
+ .idVendor = 0x045e, + .idProduct = 0x0810, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) },
Quoted 27 lines
drivers/media/usb/uvc/uvc_driver.c +9
-0+/* Microsoft Lifecam Studio */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x0772, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, /* Logitech Quickcam Fusion */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,drivers/media/usb/uvc/uvcvideo.h +1
-0@@ -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_EXPONENTIAL_EXPOSURE 0x00002000/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001Signature · 1 line
2.31.1
PATCH v2 1/1 media: uvcvideo: Add quirk for exponential exposure
In reply to Scott K LoganAt least some of the Microsoft LifeCam series of webcams exhibit a behavior which requires a 'quirk' to be handled properly. When configuring the absolute exposure value of the image, there are only a handful of values which will result in a consistent change to the image exposure, while all other values appear to result in a maximum exposure.
The valid values appear to follow an exponential pattern from the maximum value (10000) down to the minimum, yielding less than 15 possible values depending on the device's reported minimum.
--- drivers/media/usb/uvc/uvc_ctrl.c | 41 ++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_driver.c | 27 ++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 69 insertions(+)
drivers/media/usb/uvc/uvc_ctrl.c +41 -0
@@ -2142,6 +2142,40 @@ int uvc_ctrl_restore_values(struct uvc_device *dev)return 0 ; } +/* -------------------------------------------------------------------------- +* Quirks +*/ + +static s32 uvc_ctrl_get_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,u8 query,const u8 *data) +{ +s32 i; +s32 value =uvc_get_le_value (mapping, query, data); + +switch (query) { +case UVC_GET_CUR : +case UVC_GET_MIN : +case UVC_GET_MAX : +case UVC_GET_DEF : +for (i =0 ; i <14 ; ++i) { +if (10000 >> i <= value) +break ; + } +return 14 - i; +case UVC_GET_RES : +return 1 ; +default : +return value; + } +} + +static void uvc_ctrl_set_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,s32 value,u8 *data) +{ + value =10000 >> (14 - value); +uvc_set_le_value (mapping, value, data); +} +/* -------------------------------------------------------------------------- * Control and mapping handling */
@@ -2210,6 +2244,13 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, } } +if ((chain->dev->quirks &UVC_QUIRK_EXPONENTIAL_EXPOSURE ) && + ctrl->info.selector ==UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL ) { +uvc_dbg (chain->dev,CONTROL ,"Applying exponential exposure quirk\n" ); + map->get = uvc_ctrl_get_abs_exposure_exponential; + map->set = uvc_ctrl_set_abs_exposure_exponential; + } +list_add_tail (&map->list, &ctrl->info.mappings); uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", uvc_map_get_name(map), ctrl->info.entity,
drivers/media/usb/uvc/uvc_driver.c +27 -0
@@ -2718,6 +2718,33 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, +/* Microsoft Lifecam HD-5000 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x076d, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, + /* Microsoft Lifecam Studio */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x0772, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, + /* Microsoft Lifecam HD-3000 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x0810, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, /* Logitech Quickcam Fusion */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
drivers/media/usb/uvc/uvcvideo.h +1 -0
@@ -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_EXPONENTIAL_EXPOSURE 0x00002000/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001
Signature · 1 line
2.33.1
Laurent Pinchart
maintainerHi Scott,
Thank you for the patch.
Quoted 46 lines · Scott K Logan
At least some of the Microsoft LifeCam series of webcams exhibit a behavior which requires a 'quirk' to be handled properly. When configuring the absolute exposure value of the image, there are only a handful of values which will result in a consistent change to the image exposure, while all other values appear to result in a maximum exposure.
The valid values appear to follow an exponential pattern from the maximum value (10000) down to the minimum, yielding less than 15 possible values depending on the device's reported minimum.Signed-off-by Scott K Logan <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 41 ++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_driver.c | 27 ++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 69 insertions(+)drivers/media/usb/uvc/uvc_ctrl.c +21
-0@@ -2142,6 +2142,40 @@ int uvc_ctrl_restore_values(struct uvc_device *dev)return 0 ; } +/* -------------------------------------------------------------------------- +* Quirks +*/ + +static s32 uvc_ctrl_get_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,u8 query,const u8 *data) +{ +s32 i; +s32 value =uvc_get_le_value (mapping, query, data); + +switch (query) { +case UVC_GET_CUR : +case UVC_GET_MIN : +case UVC_GET_MAX : +case UVC_GET_DEF : +for (i =0 ; i <14 ; ++i) { +if (10000 >> i <= value) +break ; + } +return 14 - i; +case UVC_GET_RES :
drivers/media/usb/uvc/uvc_ctrl.c int uvc_ctrl_restore_values(struct uvc_device *dev) · line 2175
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+return 1 ; +default : +return value; + } +} + +static void uvc_ctrl_set_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,s32 value,u8 *data) +{ + value =10000 >> (14 - value);
In addition to restricting the values to the ones correctly supported by the device, this maps a linear scale (1 to 10000) to an exponential scale (1 to 14). The V4L2 control V4L2_CID_EXPOSURE_ABSOLUTE is supposed to be linear, and documented as expressed in 100 µs units.
Wouldn't it be better to keep the original scale (1 to 10000) and round the requested value to the closest supported value ?
Additionally, do we have a guarantee that all the devices that need this quirk will have the same exposure range (1 to 10000), or could the maximum value be different ?
Quoted 70 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+uvc_set_le_value (mapping, value, data); +} +/* -------------------------------------------------------------------------- * Control and mapping handling */ @@ -2210,6 +2244,13 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, } } +if ((chain->dev->quirks &UVC_QUIRK_EXPONENTIAL_EXPOSURE ) && + ctrl->info.selector ==UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL ) { +uvc_dbg (chain->dev,CONTROL ,"Applying exponential exposure quirk\n" ); + map->get = uvc_ctrl_get_abs_exposure_exponential; + map->set = uvc_ctrl_set_abs_exposure_exponential; + } +list_add_tail (&map->list, &ctrl->info.mappings); uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", uvc_map_get_name(map), ctrl->info.entity,drivers/media/usb/uvc/uvc_driver.c +27
-0@@ -2718,6 +2718,33 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, +/* Microsoft Lifecam HD-5000 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x076d, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, + /* Microsoft Lifecam Studio */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x0772, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, + /* Microsoft Lifecam HD-3000 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x0810, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, /* Logitech Quickcam Fusion */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,drivers/media/usb/uvc/uvcvideo.h +1
-0@@ -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_EXPONENTIAL_EXPOSURE 0x00002000/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001
Signature · 3 lines
Regards, Laurent Pinchart
Thanks very much for taking a look, Laurent.
Quoted 67 lines · Laurent Pinchart
Hi Scott,
Thank you for the patch.
Quoted 46 lines · Scott K Logan
At least some of the Microsoft LifeCam series of webcams exhibit a behavior which requires a 'quirk' to be handled properly. When configuring the absolute exposure value of the image, there are only a handful of values which will result in a consistent change to the image exposure, while all other values appear to result in a maximum exposure.
The valid values appear to follow an exponential pattern from the maximum value (10000) down to the minimum, yielding less than 15 possible values depending on the device's reported minimum.Signed-off-by Scott K Logan <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 41 ++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_driver.c | 27 ++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 69 insertions(+)drivers/media/usb/uvc/uvc_ctrl.c +21
-0@@ -2142,6 +2142,40 @@ int uvc_ctrl_restore_values(struct uvc_device *dev)return 0 ; } +/* -------------------------------------------------------------------------- +* Quirks +*/ + +static s32 uvc_ctrl_get_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,u8 query,const u8 *data) +{ +s32 i; +s32 value =uvc_get_le_value (mapping, query, data); + +switch (query) { +case UVC_GET_CUR : +case UVC_GET_MIN : +case UVC_GET_MAX : +case UVC_GET_DEF : +for (i =0 ; i <14 ; ++i) { +if (10000 >> i <= value) +break ; + } +return 14 - i; +case UVC_GET_RES :drivers/media/usb/uvc/uvc_ctrl.c int uvc_ctrl_restore_values(struct uvc_device *dev) · line 2175
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+return 1 ; +default : +return value; + } +} + +static void uvc_ctrl_set_abs_exposure_exponential ( +struct uvc_control_mapping *mapping,s32 value,u8 *data) +{ + value =10000 >> (14 - value);In addition to restricting the values to the ones correctly supported by the device, this maps a linear scale (1 to 10000) to an exponential scale (1 to 14). The V4L2 control
V4L2_CID_EXPOSURE_ABSOLUTEis supposed to be linear, and documented as expressed in 100 µs units.
Quoted 2 lines
Wouldn't it be better to keep the original scale (1 to 10000) and round the requested value to the closest supported value ?
This is a very valid point. I'm not in a position to measure the exposure accurately, but this morning I took the time to plot the average pixel intensity across a series of stills at varying exposure settings. While the data didn't look quite as linear as my laptop's built-in camera, it was substantially closer than the data without the scaling. If the scale is supposed to be linear, this patch will certainly make it more so.
As a gut check, I've been operating my LifeCam camera in meetings at the manual exposure level of 156 out of 10000. The exponentially scaled value would be 8, which is roughly half way through the advertised scale (1-14).
Quoted 3 lines
Additionally, do we have a guarantee that all the devices that need this quirk will have the same exposure range (1 to 10000), or could the maximum value be different ?
I actually didn't think about that. It appears to be the case for both of the models I own as well as the one Yuriy has (by the way, thanks for your reply!).
I could change the patch to query UVC_GET_MAX for each get/set operation if you think that might be worth it. It would obviously be better to stash the value for later use, but I'm not sure there's a convenient spot.
Quoted 70 lines
Quoted 70 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+uvc_set_le_value (mapping, value, data); +} +/* -------------------------------------------------------------------------- * Control and mapping handling */ @@ -2210,6 +2244,13 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, } } +if ((chain->dev->quirks &UVC_QUIRK_EXPONENTIAL_EXPOSURE ) && + ctrl->info.selector ==UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL ) { +uvc_dbg (chain->dev,CONTROL ,"Applying exponential exposure quirk\n" ); + map->get = uvc_ctrl_get_abs_exposure_exponential; + map->set = uvc_ctrl_set_abs_exposure_exponential; + } +list_add_tail (&map->list, &ctrl->info.mappings); uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", uvc_map_get_name(map), ctrl->info.entity,drivers/media/usb/uvc/uvc_driver.c +27
-0@@ -2718,6 +2718,33 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, +/* Microsoft Lifecam HD-5000 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x076d, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, + /* Microsoft Lifecam Studio */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x0772, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, + /* Microsoft Lifecam HD-3000 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x045e, + .idProduct = 0x0810, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_EXPONENTIAL_EXPOSURE) }, /* Logitech Quickcam Fusion */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,drivers/media/usb/uvc/uvcvideo.h +1
-0@@ -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_EXPONENTIAL_EXPOSURE 0x00002000/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001