media: uvc: Probe PLF limits at start-up
Subsystems (2)
cover media: uvc: Probe PLF limits at start-up
The UVC standard descries the values for the PLF control for its versions 1.1 and and 1.5, but it does not describe which values MUST be implemented.
So far, we have been adding "device quirks" to provide proper limits for the control, but this is failing to scale.
Add a function that during probe-time checks the capability of the control.
---
Ricardo Ribalda (5):
media: uvcvideo: Allow custom control mapping
media: uvcvideo: Refactor Power Line Frequency limit selection
media: uvcvideo: Probe the PLF characteristics
media: uvcvideo: Cleanup version-specific mapping
media: uvcvideo: Remove PLF device quirking
drivers/media/usb/uvc/uvc_ctrl.c | 173 ++++++++++++++++++++++++------------- drivers/media/usb/uvc/uvc_driver.c | 122 -------------------------- drivers/media/usb/uvc/uvcvideo.h | 61 ++++++------- 3 files changed, 143 insertions(+), 213 deletions(-)
---
base-commit: b14257abe7057def6127f6fb2f14f9adc8acabdb
change-id: 20240313-billion-5b2a45fa86f4
Best regards,
Signature · 1 line
Ricardo Ribalda <[email protected]>
PATCH 1/5 media: uvcvideo: Allow custom control mapping
Some advanced controls might not be completely implemented by vendors.
If the controls are a enumeration, UVC does not gives a way to probe what is implemented and what is not.
Lets create a new callback function where heuristics can be implemented to detect what is implemented and what not.
--- drivers/media/usb/uvc/uvc_ctrl.c | 15 ++++++++-- drivers/media/usb/uvc/uvcvideo.h | 59 +++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 31 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +12 -3
@@ -2434,6 +2434,14 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,return -ENOMEM ; } +static int __uvc_ctrl_add_custom_mapping (struct uvc_video_chain *chain, +struct uvc_control *ctrl,const struct uvc_control_mapping *mapping) +{ +if (mapping && mapping->add_mapping) +return mapping->add_mapping (chain, ctrl, mapping); +return __uvc_ctrl_add_mapping (chain, ctrl, mapping); +} +int uvc_ctrl_add_mapping (struct uvc_video_chain *chain,const struct uvc_control_mapping *mapping) {
@@ -2637,7 +2645,8 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) { -__uvc_ctrl_add_mapping (chain, ctrl, mapping); +__uvc_ctrl_add_custom_mapping (chain, ctrl, + mapping); custom = true; } }
@@ -2652,7 +2661,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) -__uvc_ctrl_add_mapping (chain, ctrl, mapping); +__uvc_ctrl_add_custom_mapping (chain, ctrl, mapping); }/* Finally process version-specific mappings. */
@@ -2664,7 +2673,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) -__uvc_ctrl_add_mapping (chain, ctrl, mapping); +__uvc_ctrl_add_custom_mapping (chain, ctrl, mapping); } }
drivers/media/usb/uvc/uvcvideo.h +31 -28
71 lines not on this page · raw message
Signature · 1 line
2.44.0.291.gc1ea87d7ee-goog
Laurent Pinchart
maintainerRe: [PATCH 1/5] media: uvcvideo: Allow custom control mapping
Hi Ricardo,
Thank you for the patch.
Quoted 6 lines · Ricardo Ribalda
Some advanced controls might not be completely implemented by vendors.
If the controls are a enumeration, UVC does not gives a way to probe what is implemented and what is not.
Lets create a new callback function where heuristics can be implemented
s/Lets/Let's/
Quoted 13 lines
to detect what is implemented and what not.
Signed-off-by Ricardo Ribalda <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 15 ++++++++-- drivers/media/usb/uvc/uvcvideo.h | 59 +++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 31 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +0
-0
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 2438
Quoted 5 lines
drivers/media/usb/uvc/uvc_ctrl.c +2
-0@@ -2434,6 +2434,14 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,return -ENOMEM ; } +static int __uvc_ctrl_add_custom_mapping (struct uvc_video_chain *chain, +struct uvc_control *ctrl,const struct uvc_control_mapping *mapping)
The name isn't great is in most cases it doesn't add a custom mapping.
Quoted 63 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-3+{ +if (mapping && mapping->add_mapping) +return mapping->add_mapping (chain, ctrl, mapping); +return __uvc_ctrl_add_mapping (chain, ctrl, mapping); +} +int uvc_ctrl_add_mapping (struct uvc_video_chain *chain,const struct uvc_control_mapping *mapping) {@@ -2637,7 +2645,8 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) { -__uvc_ctrl_add_mapping (chain, ctrl, mapping); +__uvc_ctrl_add_custom_mapping (chain, ctrl, + mapping); custom = true; } }@@ -2652,7 +2661,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) -__uvc_ctrl_add_mapping (chain, ctrl, mapping); +__uvc_ctrl_add_custom_mapping (chain, ctrl, mapping); }/* Finally process version-specific mappings. */ @@ -2664,7 +2673,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) -__uvc_ctrl_add_mapping (chain, ctrl, mapping); +__uvc_ctrl_add_custom_mapping (chain, ctrl, mapping); } }drivers/media/usb/uvc/uvcvideo.h +0
-18@@ -101,34 +101,6 @@ struct uvc_control_info {u32 flags; }; -struct uvc_control_mapping { -struct list_head list; -struct list_head ev_subs; - -u32 id; -char *name; -u8 entity[16 ]; -u8 selector; - -u8 size; -u8 offset; -enum v4l2_ctrl_type v4l2_type; -u32 data_type; - -const u32 *menu_mapping; -const char (*menu_names)[UVC_MENU_NAME_LEN ]; -unsigned long menu_mask; -
drivers/media/usb/uvc/uvcvideo.h struct uvc_control_info { · line 131
Quoted 10 lines
drivers/media/usb/uvc/uvcvideo.h +0
-10-u32 master_id; -s32 master_manual; -u32 slave_ids[2 ]; - -s32 (*get)(struct uvc_control_mapping *mapping,u8 query, -const u8 *data); -void (*set)(struct uvc_control_mapping *mapping,s32 value, -u8 *data); -}; -
You can leave the structure here, close to the other related structuers, and add forward declarations of the uvc_video_chain and uvc_control structures just before the existing forward declaration of uvc_device.
Quoted 42 lines
drivers/media/usb/uvc/uvcvideo.h +31
-0struct uvc_control {struct uvc_entity *entity;struct uvc_control_info info;@@ -336,6 +308,37 @@ struct uvc_video_chain {u8 ctrl_class_bitmap;/* Bitmap of valid classes */ }; +struct uvc_control_mapping { +struct list_head list; +struct list_head ev_subs; + +u32 id; +char *name; +u8 entity[16 ]; +u8 selector; + +u8 size; +u8 offset; +enum v4l2_ctrl_type v4l2_type; +u32 data_type; + +const u32 *menu_mapping; +const char (*menu_names)[UVC_MENU_NAME_LEN ]; +unsigned long menu_mask; + +u32 master_id; +s32 master_manual; +u32 slave_ids[2 ]; + +int (*add_mapping)(struct uvc_video_chain *chain, +struct uvc_control *ctrl, +const struct uvc_control_mapping *mapping); +s32 (*get)(struct uvc_control_mapping *mapping,u8 query, +const u8 *data); +void (*set)(struct uvc_control_mapping *mapping,s32 value, +u8 *data); +}; +struct uvc_stats_frame {unsigned int size;/* Number of bytes captured */ unsigned int first_data;/* Index of the first non-empty packet */
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 2/5 media: uvcvideo: Refactor Power Line Frequency limit selection
In reply to Ricardo RibaldaMove the PLF mapping logic to its own function. This patch does not introduce any new functionality to the logic, it is just a preparation patch.
--- drivers/media/usb/uvc/uvc_ctrl.c | 93 ++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 38 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +55 -38
@@ -459,6 +459,56 @@ static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, data[first+1 ] =min_t (int,abs (value),0xff ); } +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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_60HZ , +V4L2_CID_POWER_LINE_FREQUENCY_50HZ ), +}; + +const struct uvc_control_mapping uvc_ctrl_power_line_mapping_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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_60HZ , +V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ), +}; + +static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_AUTO , +V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ), +}; + +static int __uvc_ctrl_add_mapping (struct uvc_video_chain *chain, +struct uvc_control *ctrl,const struct uvc_control_mapping *mapping); + +static int uvc_ctrl_add_plf_mapping (struct uvc_video_chain *chain, +struct uvc_control *ctrl,const struct uvc_control_mapping *mapping) +{ +if (chain->dev->uvc_version <0x150 ) +return __uvc_ctrl_add_mapping (chain, ctrl, + &uvc_ctrl_power_line_mapping_uvc11); + +return __uvc_ctrl_add_mapping (chain, ctrl, + &uvc_ctrl_power_line_mapping_uvc15); +} +static const struct uvc_control_mapping uvc_ctrl_mappings[] = { { .id =V4L2_CID_BRIGHTNESS ,
@@ -748,51 +798,18 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, }, -}; - -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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_60HZ , -V4L2_CID_POWER_LINE_FREQUENCY_50HZ ), -}; - -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_60HZ , -V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ), + { + .entity = UVC_GUID_UVC_PROCESSING, + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, + .add_mapping = uvc_ctrl_add_plf_mapping, + }, };static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc11[] = { - &uvc_ctrl_power_line_mapping_uvc11,NULL ,/* Sentinel */ }; -static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_AUTO , -V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ), -}; -static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc15[] = { - &uvc_ctrl_power_line_mapping_uvc15,NULL ,/* Sentinel */ };
Signature · 1 line
2.44.0.291.gc1ea87d7ee-goog
Laurent Pinchart
maintainerRe: [PATCH 2/5] media: uvcvideo: Refactor Power Line Frequency limit selection
Hi Ricardo,
Thank you for the patch.
Quoted 45 lines · Ricardo Ribalda
Move the PLF mapping logic to its own function. This patch does not introduce any new functionality to the logic, it is just a preparation patch.
Signed-off-by Ricardo Ribalda <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 93 ++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 38 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +28
-0@@ -459,6 +459,56 @@ static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, data[first+1 ] =min_t (int,abs (value),0xff ); } +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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_60HZ , +V4L2_CID_POWER_LINE_FREQUENCY_50HZ ), +}; + +const struct uvc_control_mapping uvc_ctrl_power_line_mapping_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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_60HZ , +V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ), +}; + +static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc15 = { + .id =V4L2_CID_POWER_LINE_FREQUENCY , + .entity =UVC_GUID_UVC_PROCESSING , + .selector =UVC_PU_POWER_LINE_FREQUENCY_CONTROL ,
drivers/media/usb/uvc/uvc_ctrl.c static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, · line 499
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+ .size = 2, + .offset = 0, + .v4l2_type = V4L2_CTRL_TYPE_MENU, + .data_type = UVC_CTRL_DATA_TYPE_ENUM, + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO, + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), +}; + +static int __uvc_ctrl_add_mapping (struct uvc_video_chain *chain, +struct uvc_control *ctrl,const struct uvc_control_mapping *mapping);
I wonder if we could avoid the forward declaration by turning the .add_mapping() operation into a .filter_mapping() (name to be bikshedded) that would return a replacement mapping instead of adding it. The caller (the __uvc_ctrl_add_custom_mapping() function) would then call __uvc_ctrl_add_mapping() unconditionally. You could actually call the new operation directly in __uvc_ctrl_add_custom_mapping() without having to add a new __uvc_ctrl_add_custom_mapping() function. What do you think, would that be simpler and more redable ?
Quoted 72 lines
drivers/media/usb/uvc/uvc_ctrl.c +17
-38+ +static int uvc_ctrl_add_plf_mapping (struct uvc_video_chain *chain, +struct uvc_control *ctrl,const struct uvc_control_mapping *mapping) +{ +if (chain->dev->uvc_version <0x150 ) +return __uvc_ctrl_add_mapping (chain, ctrl, + &uvc_ctrl_power_line_mapping_uvc11); + +return __uvc_ctrl_add_mapping (chain, ctrl, + &uvc_ctrl_power_line_mapping_uvc15); +} +static const struct uvc_control_mapping uvc_ctrl_mappings[] = { { .id =V4L2_CID_BRIGHTNESS ,@@ -748,51 +798,18 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, }, -}; - -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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_60HZ , -V4L2_CID_POWER_LINE_FREQUENCY_50HZ ), -}; - -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_60HZ , -V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ), + { + .entity = UVC_GUID_UVC_PROCESSING, + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, + .add_mapping = uvc_ctrl_add_plf_mapping, + }, };static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc11[] = { - &uvc_ctrl_power_line_mapping_uvc11,NULL ,/* Sentinel */ }; -static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_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_mask =GENMASK (V4L2_CID_POWER_LINE_FREQUENCY_AUTO , -V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ), -}; -static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc15[] = { - &uvc_ctrl_power_line_mapping_uvc15,NULL ,/* Sentinel */ };
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 2/5] media: uvcvideo: Refactor Power Line Frequency limit selection
Hi Laurent
Quoted 11 lines · Laurent Pinchart
drivers/media/usb/uvc/uvc_ctrl.c static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, · line 499
Quoted 2 lines
drivers/media/usb/uvc/uvc_ctrl.c +2
-0+static int __uvc_ctrl_add_mapping (struct uvc_video_chain *chain, +struct uvc_control *ctrl,const struct uvc_control_mapping *mapping);I wonder if we could avoid the forward declaration by turning the .add_mapping() operation into a .filter_mapping() (name to be bikshedded) that would return a replacement mapping instead of adding it. The caller (the
__uvc_ctrl_add_custom_mapping()function) would then call__uvc_ctrl_add_mapping()unconditionally. You could actually call the new operation directly in__uvc_ctrl_add_custom_mapping()without having to add a new__uvc_ctrl_add_custom_mapping()function. What do you think, would that be simpler and more redable ?
Let me add it as a forward patch, let me know what you think.
Regards!
PATCH 3/5 media: uvcvideo: Probe the PLF characteristics
In reply to Ricardo RibaldaThe UVC 1.5 standard defines 4 values for the PLF control: Off, 50Hz, 60Hz and Auto. But it does not clearly define if all the values must be implemented or not.
Instead of just using the UVC version to determine what the PLF control can do, probe it.
--- drivers/media/usb/uvc/uvc_ctrl.c | 54 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +50 -4
@@ -501,12 +501,58 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,static int uvc_ctrl_add_plf_mapping (struct uvc_video_chain *chain,struct uvc_control *ctrl,const struct uvc_control_mapping *mapping) { +const struct uvc_control_mapping *out_mapping = + &uvc_ctrl_power_line_mapping_uvc11; +u8 init_val; +u8 *buf; +int ret; + + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +/* Save the default PLF value, so we can restore it. */ + ret =uvc_query_ctrl (chain->dev,UVC_GET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); +/* If we cannot read the control skip it. */ +if (ret) { +kfree (buf); +return ret; + } + init_val = *buf; + +/* If PLF value cannot be set to off, it is limited. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ; + ret =uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); +if (ret) { + out_mapping = &uvc_ctrl_power_line_mapping_limited; + goto end; + } + +/* UVC 1.1 does not define auto, we can exit. */ if (chain->dev->uvc_version <0x150 ) -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc11); + goto end; + +/* Check if the device supports auto. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_AUTO ; + ret =uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); +if (!ret) + out_mapping = &uvc_ctrl_power_line_mapping_uvc15; + +end: +/* Restore initial value and add mapping. */ + *buf = init_val; +uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc15); +kfree (buf); +return __uvc_ctrl_add_mapping (chain, ctrl, out_mapping); }static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
Signature · 1 line
2.44.0.291.gc1ea87d7ee-goog
Laurent Pinchart
maintainerRe: [PATCH 3/5] media: uvcvideo: Probe the PLF characteristics
Hi Ricardo,
Thank you for the patch.
Quoted 17 lines · Ricardo Ribalda
The UVC 1.5 standard defines 4 values for the PLF control: Off, 50Hz, 60Hz and Auto. But it does not clearly define if all the values must be implemented or not.
Instead of just using the UVC version to determine what the PLF control can do, probe it.
Signed-off-by Ricardo Ribalda <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 54 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +0
-0
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 507
Quoted 7 lines
drivers/media/usb/uvc/uvc_ctrl.c +4
-0@@ -501,12 +501,58 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,static int uvc_ctrl_add_plf_mapping (struct uvc_video_chain *chain,struct uvc_control *ctrl,const struct uvc_control_mapping *mapping) { +const struct uvc_control_mapping *out_mapping = + &uvc_ctrl_power_line_mapping_uvc11; +u8 init_val; +u8 *buf;
u8 *buf __free(kfree) = NULL;
will simplify the exit paths.
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 517
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+int ret; + + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +/* Save the default PLF value, so we can restore it. */ + ret =uvc_query_ctrl (chain->dev,UVC_GET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf));
That's the current value, not the default. Is that intended ?
Quoted 5 lines
drivers/media/usb/uvc/uvc_ctrl.c +5
-0+/* If we cannot read the control skip it. */ +if (ret) { +kfree (buf); +return ret; + }
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 532
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+ init_val = *buf; + +/* If PLF value cannot be set to off, it is limited. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ; + ret =uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); +if (ret) { + out_mapping = &uvc_ctrl_power_line_mapping_limited; + goto end;
If setting the value failed you don't need to restore it, do you ?
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 543
Quoted 13 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-2+ } + +/* UVC 1.1 does not define auto, we can exit. */ if (chain->dev->uvc_version <0x150 ) -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc11); + goto end; + +/* Check if the device supports auto. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_AUTO ; + ret =uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf));
Now for the real annoying question. I've encountered quite a few devices that would crash when the driver tried to get/set lots of controls at probe time. This is why the control cache is populated the first time a control is queried, and not when the device is probed. I'm always worried when adding more control accesses at probe time that some devices will behave improperly.
Given the number of UVC users I tend to be on the conservative side, but obviously, if we were to strictly avoid new access patterns to the device, the driver wouldn't be able to evolve. I do like patches 4/5 and 5/5, so I'm tempted to take the risk and revert this series later if needed. That would likely make some other users unhappy if they rely on the heuristic.
Another issue is how to get vendors to implement the power line frequency control correctly. With the series applied, vendors won't notice they're doing something wrong. Of course, they probably don't check the behaviour of their devices with Linux in the first place, so I'm not sure what we could do.
Quoted 17 lines
drivers/media/usb/uvc/uvc_ctrl.c +11
-2+if (!ret) + out_mapping = &uvc_ctrl_power_line_mapping_uvc15; + +end: +/* Restore initial value and add mapping. */ + *buf = init_val; +uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc15); +kfree (buf); +return __uvc_ctrl_add_mapping (chain, ctrl, out_mapping); }static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 3/5] media: uvcvideo: Probe the PLF characteristics
Hi Laurent
Quoted 35 lines · Laurent Pinchart
Hi Ricardo,
Thank you for the patch.
Quoted 17 lines · Ricardo Ribalda
The UVC 1.5 standard defines 4 values for the PLF control: Off, 50Hz, 60Hz and Auto. But it does not clearly define if all the values must be implemented or not.
Instead of just using the UVC version to determine what the PLF control can do, probe it.
Signed-off-by Ricardo Ribalda <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 54 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +0
-0drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 507
Quoted 7 lines
drivers/media/usb/uvc/uvc_ctrl.c +4
-0@@ -501,12 +501,58 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,static int uvc_ctrl_add_plf_mapping (struct uvc_video_chain *chain,struct uvc_control *ctrl,const struct uvc_control_mapping *mapping) { +const struct uvc_control_mapping *out_mapping = + &uvc_ctrl_power_line_mapping_uvc11; +u8 init_val; +u8 *buf;u8 *buf __free(kfree) = NULL;will simplify the exit paths.
Quoted 12 lines
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 517
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+int ret; + + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +/* Save the default PLF value, so we can restore it. */ + ret =uvc_query_ctrl (chain->dev,UVC_GET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf));That's the current value, not the default. Is that intended ?
Yes, the driver does not init the other controls to the default value. So I'd rather be consistent.
Quoted 31 lines
Quoted 6 lines
drivers/media/usb/uvc/uvc_ctrl.c +5
-0+/* If we cannot read the control skip it. */ +if (ret) { +kfree (buf); +return ret; + }drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 532
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+ init_val = *buf; + +/* If PLF value cannot be set to off, it is limited. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ; + ret =uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); +if (ret) { + out_mapping = &uvc_ctrl_power_line_mapping_limited; + goto end;If setting the value failed you don't need to restore it, do you ?
Quoted 12 lines
drivers/media/usb/uvc/uvc_ctrl.c +9
-2+ } + +/* UVC 1.1 does not define auto, we can exit. */ if (chain->dev->uvc_version <0x150 ) -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc11); + goto end; + +/* Check if the device supports auto. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_AUTO ; + ret = uvc_query_ctrl(chain->dev, UVC_SET_CUR, ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector,
Quoted 8 lines
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 543
Quoted 1 line
drivers/media/usb/uvc/uvc_ctrl.c +1
-0+ buf, sizeof(*buf));Now for the real annoying question. I've encountered quite a few devices that would crash when the driver tried to get/set lots of controls at probe time. This is why the control cache is populated the first time a control is queried, and not when the device is probed. I'm always worried when adding more control accesses at probe time that some devices will behave improperly.
If we encounter a device like that we could quirk it.
Quoted 8 lines
Given the number of UVC users I tend to be on the conservative side, but obviously, if we were to strictly avoid new access patterns to the device, the driver wouldn't be able to evolve. I do like patches 4/5 and 5/5, so I'm tempted to take the risk and revert this series later if needed. That would likely make some other users unhappy if they rely on the heuristic.
Quoted 5 lines
Another issue is how to get vendors to implement the power line frequency control correctly. With the series applied, vendors won't notice they're doing something wrong. Of course, they probably don't check the behaviour of their devices with Linux in the first place, so I'm not sure what we could do.
We can add the check to v4l2-compliance....
Although I would love to see a uvc-compliance tool. If the tool can be easily run in windows/linux without a driver I guess ISP vendors will run it to validate their code.
Right now there is no way to validate a usb camera beyond: it runs in windows and in cheese.
Quoted 23 lines
Quoted 8 lines
drivers/media/usb/uvc/uvc_ctrl.c +7
-0+if (!ret) + out_mapping = &uvc_ctrl_power_line_mapping_uvc15; + +end: +/* Restore initial value and add mapping. */ + *buf = init_val; + uvc_query_ctrl(chain->dev, UVC_SET_CUR, ctrl->entity->id,drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 558
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +4
-2+ chain->dev->intfnum, ctrl->info.selector, + buf, sizeof(*buf)); -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc15); +kfree (buf); +return __uvc_ctrl_add_mapping (chain, ctrl, out_mapping); }static const struct uvc_control_mapping uvc_ctrl_mappings[] = {--
Regards,Laurent Pinchart
Signature · 1 line
Ricardo Ribalda
Laurent Pinchart
maintainerRe: [PATCH 3/5] media: uvcvideo: Probe the PLF characteristics
Hi Ricardo,
Quoted 44 lines · Ricardo Ribalda
Quoted 30 lines · Laurent Pinchart
Quoted 17 lines · Ricardo Ribalda
The UVC 1.5 standard defines 4 values for the PLF control: Off, 50Hz, 60Hz and Auto. But it does not clearly define if all the values must be implemented or not.
Instead of just using the UVC version to determine what the PLF control can do, probe it.
Signed-off-by Ricardo Ribalda <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 54 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +0
-0drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 507
Quoted 7 lines
drivers/media/usb/uvc/uvc_ctrl.c +4
-0@@ -501,12 +501,58 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,static int uvc_ctrl_add_plf_mapping (struct uvc_video_chain *chain,struct uvc_control *ctrl,const struct uvc_control_mapping *mapping) { +const struct uvc_control_mapping *out_mapping = + &uvc_ctrl_power_line_mapping_uvc11; +u8 init_val; +u8 *buf;u8 *buf __free(kfree) = NULL;will simplify the exit paths.
Quoted 12 lines
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 517
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+int ret; + + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +/* Save the default PLF value, so we can restore it. */ + ret =uvc_query_ctrl (chain->dev,UVC_GET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf));That's the current value, not the default. Is that intended ?
Quoted 2 lines
Yes, the driver does not init the other controls to the default value. So I'd rather be consistent.
I'm fine with that, let's update the comment to "Save the current PLF value".
Quoted 39 lines
Quoted 30 lines
Quoted 5 lines
drivers/media/usb/uvc/uvc_ctrl.c +5
-0+/* If we cannot read the control skip it. */ +if (ret) { +kfree (buf); +return ret; + }drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 532
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+ init_val = *buf; + +/* If PLF value cannot be set to off, it is limited. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ; + ret =uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); +if (ret) { + out_mapping = &uvc_ctrl_power_line_mapping_limited; + goto end;If setting the value failed you don't need to restore it, do you ?
Quoted 12 lines
drivers/media/usb/uvc/uvc_ctrl.c +9
-2+ } + +/* UVC 1.1 does not define auto, we can exit. */ if (chain->dev->uvc_version <0x150 ) -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc11); + goto end; + +/* Check if the device supports auto. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_AUTO ; + ret = uvc_query_ctrl(chain->dev, UVC_SET_CUR, ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector,Quoted 8 lines
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 543
Quoted 1 line
drivers/media/usb/uvc/uvc_ctrl.c +1
-0+ buf, sizeof(*buf));Now for the real annoying question. I've encountered quite a few devices that would crash when the driver tried to get/set lots of controls at probe time. This is why the control cache is populated the first time a control is queried, and not when the device is probed. I'm always worried when adding more control accesses at probe time that some devices will behave improperly.
Quoted 1 line
If we encounter a device like that we could quirk it.
Now we could place bets on what is less likely to scale, quirking devices that have a bad PLF implementation, or quirking devices whose firmware will crash when queried too much at probe time :-)
Quoted 13 lines
Quoted 7 lines
Given the number of UVC users I tend to be on the conservative side, but obviously, if we were to strictly avoid new access patterns to the device, the driver wouldn't be able to evolve. I do like patches 4/5 and 5/5, so I'm tempted to take the risk and revert this series later if needed. That would likely make some other users unhappy if they rely on the heuristic.
Quoted 5 lines
Another issue is how to get vendors to implement the power line frequency control correctly. With the series applied, vendors won't notice they're doing something wrong. Of course, they probably don't check the behaviour of their devices with Linux in the first place, so I'm not sure what we could do.
Quoted 5 lines
We can add the check to v4l2-compliance....
Although I would love to see a uvc-compliance tool. If the tool can be easily run in windows/linux without a driver I guess ISP vendors will run it to validate their code.
*without a driver* is doable with libusb but would be *lots* of work, basically duplicating the whole uvcvideo driver in userspace. That's not a project I would start, but it would be interesting.
Quoted 2 lines
Right now there is no way to validate a usb camera beyond: it runs in windows and in cheese.
Isn't the USB-IF supposed to have a compliance test suite ? Given all the broken devices we hear about, it must either not be very good, or not be used by vendors.
I think a compliance tool based on top of the uvcvideo kernel driver would already be a good step forward.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
drivers/media/usb/uvc/uvc_ctrl.c +11
-2+if (!ret) + out_mapping = &uvc_ctrl_power_line_mapping_uvc15; + +end: +/* Restore initial value and add mapping. */ + *buf = init_val; +uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc15); +kfree (buf); +return __uvc_ctrl_add_mapping (chain, ctrl, out_mapping); }static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 3/5] media: uvcvideo: Probe the PLF characteristics
Hi Laurent
Quoted 48 lines · Laurent Pinchart
Hi Ricardo,
Quoted 44 lines · Ricardo Ribalda
Quoted 42 lines · Laurent Pinchart
Quoted 17 lines · Ricardo Ribalda
The UVC 1.5 standard defines 4 values for the PLF control: Off, 50Hz, 60Hz and Auto. But it does not clearly define if all the values must be implemented or not.
Instead of just using the UVC version to determine what the PLF control can do, probe it.
Signed-off-by Ricardo Ribalda <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 54 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +0
-0drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 507
Quoted 7 lines
drivers/media/usb/uvc/uvc_ctrl.c +4
-0@@ -501,12 +501,58 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain,static int uvc_ctrl_add_plf_mapping (struct uvc_video_chain *chain,struct uvc_control *ctrl,const struct uvc_control_mapping *mapping) { +const struct uvc_control_mapping *out_mapping = + &uvc_ctrl_power_line_mapping_uvc11; +u8 init_val; +u8 *buf;u8 *buf __free(kfree) = NULL;will simplify the exit paths.
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 517
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+int ret; + + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +/* Save the default PLF value, so we can restore it. */ + ret =uvc_query_ctrl (chain->dev,UVC_GET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf));That's the current value, not the default. Is that intended ?
Quoted 5 lines
Quoted 2 lines
Yes, the driver does not init the other controls to the default value. So I'd rather be consistent.
I'm fine with that, let's update the comment to "Save the current PLF value".
done in my tree, if there is a v3 I will fix it, otherwise you are free to modify it if you want ;)
Quoted 40 lines
Quoted 40 lines
Quoted 39 lines
Quoted 6 lines
drivers/media/usb/uvc/uvc_ctrl.c +5
-0+/* If we cannot read the control skip it. */ +if (ret) { +kfree (buf); +return ret; + }drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 532
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+ init_val = *buf; + +/* If PLF value cannot be set to off, it is limited. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_DISABLED ; + ret =uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); +if (ret) { + out_mapping = &uvc_ctrl_power_line_mapping_limited; + goto end;If setting the value failed you don't need to restore it, do you ?
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 543
Quoted 13 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-2+ } + +/* UVC 1.1 does not define auto, we can exit. */ if (chain->dev->uvc_version <0x150 ) -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc11); + goto end; + +/* Check if the device supports auto. */ + *buf =V4L2_CID_POWER_LINE_FREQUENCY_AUTO ; + ret =uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf));Now for the real annoying question. I've encountered quite a few devices that would crash when the driver tried to get/set lots of controls at probe time. This is why the control cache is populated the first time a control is queried, and not when the device is probed. I'm always worried when adding more control accesses at probe time that some devices will behave improperly.
Quoted 5 lines
Quoted 1 line
If we encounter a device like that we could quirk it.
Now we could place bets on what is less likely to scale, quirking devices that have a bad PLF implementation, or quirking devices whose firmware will crash when queried too much at probe time :-)
:)
Quoted 24 lines
Quoted 14 lines
Quoted 8 lines
Given the number of UVC users I tend to be on the conservative side, but obviously, if we were to strictly avoid new access patterns to the device, the driver wouldn't be able to evolve. I do like patches 4/5 and 5/5, so I'm tempted to take the risk and revert this series later if needed. That would likely make some other users unhappy if they rely on the heuristic.
Quoted 5 lines
Another issue is how to get vendors to implement the power line frequency control correctly. With the series applied, vendors won't notice they're doing something wrong. Of course, they probably don't check the behaviour of their devices with Linux in the first place, so I'm not sure what we could do.
Quoted 5 lines
We can add the check to v4l2-compliance....
Although I would love to see a uvc-compliance tool. If the tool can be easily run in windows/linux without a driver I guess ISP vendors will run it to validate their code.
*without a driver* is doable with libusb but would be *lots* of work, basically duplicating the whole uvcvideo driver in userspace. That's not a project I would start, but it would be interesting.
Quoted 6 lines
Quoted 2 lines
Right now there is no way to validate a usb camera beyond: it runs in windows and in cheese.
Isn't the USB-IF supposed to have a compliance test suite ? Given all the broken devices we hear about, it must either not be very good, or not be used by vendors.
At least there is no public compliance test suite, and if third parties cannot validate the results the test is not very useful.
Quoted 20 lines
I think a compliance tool based on top of the uvcvideo kernel driver would already be a good step forward.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/media/usb/uvc/uvc_ctrl.c +11
-2+if (!ret) + out_mapping = &uvc_ctrl_power_line_mapping_uvc15; + +end: +/* Restore initial value and add mapping. */ + *buf = init_val; +uvc_query_ctrl (chain->dev,UVC_SET_CUR , ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + buf,sizeof (*buf)); -return __uvc_ctrl_add_mapping (chain, ctrl, - &uvc_ctrl_power_line_mapping_uvc15); +kfree (buf); +return __uvc_ctrl_add_mapping (chain, ctrl, out_mapping); }
Quoted 6 lines
Quoted 1 line
Quoted 1 line
drivers/media/usb/uvc/uvc_ctrl.c static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 558
Quoted 1 line
drivers/media/usb/uvc/uvc_ctrl.c +0
-0static const struct uvc_control_mapping uvc_ctrl_mappings[] = {--
Regards,Laurent Pinchart
Regards!
Signature · 1 line
Ricardo Ribalda
PATCH 4/5 media: uvcvideo: Cleanup version-specific mapping
In reply to Ricardo RibaldaWe do not have more version specific mappings. Let's remove this code for now. It can be easily reverted later if needed.
--- drivers/media/usb/uvc/uvc_ctrl.c | 21 --------------------- 1 file changed, 21 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +0 -21
@@ -851,14 +851,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, }; -static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc11[] = { -NULL ,/* Sentinel */ -}; - -static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc15[] = { -NULL ,/* Sentinel */ -}; -/* ------------------------------------------------------------------------ * Utility functions */
@@ -2660,7 +2652,6 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev,static void uvc_ctrl_init_ctrl (struct uvc_video_chain *chain,struct uvc_control *ctrl) { -const struct uvc_control_mapping **mappings;unsigned int i;/*
@@ -2726,18 +2717,6 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, ctrl->info.selector == mapping->selector)__uvc_ctrl_add_custom_mapping (chain, ctrl, mapping); } - -/* Finally process version-specific mappings. */ - mappings = chain->dev->uvc_version <0x0150 - ? uvc_ctrl_mappings_uvc11 : uvc_ctrl_mappings_uvc15; - -for (i =0 ; mappings[i]; ++i) { -const struct uvc_control_mapping *mapping = mappings[i]; - -if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && - ctrl->info.selector == mapping->selector) -__uvc_ctrl_add_custom_mapping (chain, ctrl, mapping); - } }/*
Signature · 1 line
2.44.0.291.gc1ea87d7ee-goog
Re: [PATCH 4/5] media: uvcvideo: Cleanup version-specific mapping
Hi Ricardo,
Thank you for the patch.
Quoted 4 lines · Ricardo Ribalda
We do not have more version specific mappings. Let's remove this code for now. It can be easily reverted later if needed.
Signed-off-by Ricardo Ribalda <[email protected]>
Quoted 50 lines
--- drivers/media/usb/uvc/uvc_ctrl.c | 21 --------------------- 1 file changed, 21 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +0
-21@@ -851,14 +851,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, }; -static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc11[] = { -NULL ,/* Sentinel */ -}; - -static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc15[] = { -NULL ,/* Sentinel */ -}; -/* ------------------------------------------------------------------------ * Utility functions */ @@ -2660,7 +2652,6 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev,static void uvc_ctrl_init_ctrl (struct uvc_video_chain *chain,struct uvc_control *ctrl) { -const struct uvc_control_mapping **mappings;unsigned int i;/* @@ -2726,18 +2717,6 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, ctrl->info.selector == mapping->selector)__uvc_ctrl_add_custom_mapping (chain, ctrl, mapping); } - -/* Finally process version-specific mappings. */ - mappings = chain->dev->uvc_version <0x0150 - ? uvc_ctrl_mappings_uvc11 : uvc_ctrl_mappings_uvc15; - -for (i =0 ; mappings[i]; ++i) { -const struct uvc_control_mapping *mapping = mappings[i]; - -if (uvc_entity_match_guid (ctrl->entity, mapping->entity) && - ctrl->info.selector == mapping->selector) -__uvc_ctrl_add_custom_mapping (chain, ctrl, mapping); - } }/*
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 5/5 media: uvcvideo: Remove PLF device quirking
In reply to Ricardo RibaldaWe can use heuristics to figure out the proper range of the control instead of quirking every single device.
--- drivers/media/usb/uvc/uvc_ctrl.c | 4 +- drivers/media/usb/uvc/uvc_driver.c | 122 ------------------------------------- drivers/media/usb/uvc/uvcvideo.h | 2 - 3 files changed, 2 insertions(+), 126 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +2 -2
@@ -459,7 +459,7 @@ static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, data[first+1 ] =min_t (int,abs (value),0xff ); } -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { +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 ,
@@ -471,7 +471,7 @@ const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { V4L2_CID_POWER_LINE_FREQUENCY_50HZ), }; -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { +static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { .id =V4L2_CID_POWER_LINE_FREQUENCY , .entity =UVC_GUID_UVC_PROCESSING , .selector =UVC_PU_POWER_LINE_FREQUENCY_CONTROL ,
drivers/media/usb/uvc/uvc_driver.c +0 -122
146 lines not on this page · raw message
drivers/media/usb/uvc/uvcvideo.h +0 -2
@@ -751,8 +751,6 @@ int uvc_status_start(struct uvc_device *dev, gfp_t flags);void uvc_status_stop (struct uvc_device *dev);/* Controls */ -extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited; -extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11;extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
Signature · 1 line
2.44.0.291.gc1ea87d7ee-goog
Laurent Pinchart
maintainerRe: [PATCH 5/5] media: uvcvideo: Remove PLF device quirking
Hi Ricardo,
Thank you for the patch.
Quoted 37 lines · Ricardo Ribalda
We can use heuristics to figure out the proper range of the control instead of quirking every single device.
Signed-off-by Ricardo Ribalda <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 4 +- drivers/media/usb/uvc/uvc_driver.c | 122 ------------------------------------- drivers/media/usb/uvc/uvcvideo.h | 2 - 3 files changed, 2 insertions(+), 126 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +2
-2@@ -459,7 +459,7 @@ static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, data[first+1 ] =min_t (int,abs (value),0xff ); } -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { +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 ,@@ -471,7 +471,7 @@ const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { V4L2_CID_POWER_LINE_FREQUENCY_50HZ), }; -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { +static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { .id =V4L2_CID_POWER_LINE_FREQUENCY , .entity =UVC_GUID_UVC_PROCESSING , .selector =UVC_PU_POWER_LINE_FREQUENCY_CONTROL ,drivers/media/usb/uvc/uvc_driver.c +0
-0
drivers/media/usb/uvc/uvc_driver.c MODULE_PARM_DESC(timeout, "Streaming control requests timeout"); · line 2390
Quoted 8 lines
drivers/media/usb/uvc/uvc_driver.c +0
-5@@ -2383,20 +2383,6 @@ MODULE_PARM_DESC(timeout, "Streaming control requests timeout");* Driver initialization and cleanup */ -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 */ - },
I think you can drop the mappings field from the uvc_device_info structure, as well as the corresponding code in uvc_ctrl_init_ctrl().
Quoted 155 lines
drivers/media/usb/uvc/uvc_driver.c +0
-117-}; - -static const struct uvc_device_info uvc_ctrl_power_line_uvc11 = { - .mappings = (const struct uvc_control_mapping *[]) { - &uvc_ctrl_power_line_mapping_uvc11, -NULL ,/* Sentinel */ - }, -}; -static const struct uvc_device_info uvc_quirk_probe_minmax = { .quirks =UVC_QUIRK_PROBE_MINMAX , };@@ -2427,33 +2413,6 @@ 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 }, -/* 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 =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 =0x4034 , - .bInterfaceClass =USB_CLASS_VIDEO , - .bInterfaceSubClass =1 , - .bInterfaceProtocol =UVC_PC_PROTOCOL_15 , - .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 ,@@ -2583,42 +2542,6 @@ 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 = 0xb5eb, - .bInterfaceClass = USB_CLASS_VIDEO, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = 0, - .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited }, -/* Chicony Electronics Co., Ltd Integrated Camera */ - { .match_flags = USB_DEVICE_ID_MATCH_DEVICE - | USB_DEVICE_ID_MATCH_INT_INFO, - .idVendor = 0x04f2, - .idProduct = 0xb67c, - .bInterfaceClass = USB_CLASS_VIDEO, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = UVC_PC_PROTOCOL_15, - .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 }, -/* 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,@@ -3003,51 +2926,6 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) }, -/* SunplusIT Inc HD Camera */ - { .match_flags = USB_DEVICE_ID_MATCH_DEVICE - | USB_DEVICE_ID_MATCH_INT_INFO, - .idVendor = 0x2b7e, - .idProduct = 0xb752, - .bInterfaceClass = USB_CLASS_VIDEO, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = UVC_PC_PROTOCOL_15, - .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 }, -/* Lenovo Integrated Camera */ - { .match_flags = USB_DEVICE_ID_MATCH_DEVICE - | USB_DEVICE_ID_MATCH_INT_INFO, - .idVendor = 0x30c9, - .idProduct = 0x0093, - .bInterfaceClass = USB_CLASS_VIDEO, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = UVC_PC_PROTOCOL_15, - .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 }, -/* Sonix Technology USB 2.0 Camera */ - { .match_flags = USB_DEVICE_ID_MATCH_DEVICE - | USB_DEVICE_ID_MATCH_INT_INFO, - .idVendor = 0x3277, - .idProduct = 0x0072, - .bInterfaceClass = USB_CLASS_VIDEO, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = 0, - .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited }, -/* 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 }, -/* Acer EasyCamera */ - { .match_flags = USB_DEVICE_ID_MATCH_DEVICE - | USB_DEVICE_ID_MATCH_INT_INFO, - .idVendor = 0x5986, - .idProduct = 0x1180, - .bInterfaceClass = USB_CLASS_VIDEO, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = 0, - .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_limited },/* Intel D410/ASR depth camera */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,drivers/media/usb/uvc/uvcvideo.h +0
-2@@ -751,8 +751,6 @@ int uvc_status_start(struct uvc_device *dev, gfp_t flags);void uvc_status_stop (struct uvc_device *dev);/* Controls */ -extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited; -extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11;extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 5 lines · Ricardo Ribalda
The UVC standard descries the values for the PLF control for its versions 1.1 and and 1.5, but it does not describe which values MUST be implemented.
Quoted 7 lines
So far, we have been adding "device quirks" to provide proper limits for the control, but this is failing to scale.
Add a function that during probe-time checks the capability of the control.
Signed-off-by Ricardo Ribalda <[email protected]>
Looks good to me
FWIW