Skip to content

Commit

Permalink
usb: gadget: uvc: Allow definition of XUs in configfs
Browse files Browse the repository at this point in the history
The UVC gadget at present has no support for extension units. Add the
infrastructure to uvc_configfs.c that allows users to create XUs via
configfs. These will be stored in a new child of uvcg_control_grp_type
with the name "extensions".

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
Link: https://lore.kernel.org/r/20230206161802.892954-4-dan.scally@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Daniel Scally authored and Greg Kroah-Hartman committed Feb 7, 2023
1 parent 0df2860 commit 0525210
Showing 5 changed files with 553 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Documentation/ABI/testing/configfs-usb-gadget-uvc
Original file line number Diff line number Diff line change
@@ -113,6 +113,34 @@ Description: Default processing unit descriptors
bUnitID a non-zero id of this unit
=============== ========================================

What: /config/usb-gadget/gadget/functions/uvc.name/control/extensions
Date: Nov 2022
KernelVersion: 6.1
Description: Extension unit descriptors

What: /config/usb-gadget/gadget/functions/uvc.name/control/extensions/name
Date: Nov 2022
KernelVersion: 6.1
Description: Extension Unit (XU) Descriptor

bLength, bUnitID and iExtension are read-only. All others are
read-write.

================= ========================================
bLength size of the descriptor in bytes
bUnitID non-zero ID of this unit
guidExtensionCode Vendor-specific code identifying the XU
bNumControls number of controls in this XU
bNrInPins number of input pins for this unit
baSourceID list of the IDs of the units or terminals
to which this XU is connected
bControlSize size of the bmControls field in bytes
bmControls list of bitmaps detailing which vendor
specific controls are supported
iExtension index of a string descriptor that describes
this extension unit
================= ========================================

What: /config/usb-gadget/gadget/functions/uvc.name/control/header
Date: Dec 2014
KernelVersion: 4.0
9 changes: 9 additions & 0 deletions drivers/usb/gadget/function/f_uvc.c
Original file line number Diff line number Diff line change
@@ -865,6 +865,13 @@ static struct usb_function_instance *uvc_alloc_inst(void)
od->bSourceID = 2;
od->iTerminal = 0;

/*
* With the ability to add XUs to the UVC function graph, we need to be
* able to allocate unique unit IDs to them. The IDs are 1-based, with
* the CT, PU and OT above consuming the first 3.
*/
opts->last_unit_id = 3;

/* Prepare fs control class descriptors for configfs-based gadgets */
ctl_cls = opts->uvc_fs_control_cls;
ctl_cls[0] = NULL; /* assigned elsewhere by configfs */
@@ -885,6 +892,8 @@ static struct usb_function_instance *uvc_alloc_inst(void)
opts->ss_control =
(const struct uvc_descriptor_header * const *)ctl_cls;

INIT_LIST_HEAD(&opts->extension_units);

opts->streaming_interval = 1;
opts->streaming_maxpacket = 1024;
snprintf(opts->function_name, sizeof(opts->function_name), "UVC Camera");
7 changes: 7 additions & 0 deletions drivers/usb/gadget/function/u_uvc.h
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ struct f_uvc_opts {
unsigned int control_interface;
unsigned int streaming_interface;
char function_name[32];
unsigned int last_unit_id;

bool enable_interrupt_ep;

@@ -65,6 +66,12 @@ struct f_uvc_opts {
struct uvc_descriptor_header *uvc_fs_control_cls[5];
struct uvc_descriptor_header *uvc_ss_control_cls[5];

/*
* Control descriptors for extension units. There could be any number
* of these, including none at all.
*/
struct list_head extension_units;

/*
* Streaming descriptors for full-speed, high-speed and super-speed.
* Used by configfs only, must not be touched by legacy gadgets. The
Loading

0 comments on commit 0525210

Please sign in to comment.