All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Scally <dan.scally@ideasonboard.com>
To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org,
	laurent.pinchart@ideasonboard.com
Cc: mgr@pengutronix.de, balbi@kernel.org,
	kieran.bingham@ideasonboard.com, torleiv@huddly.com,
	stern@rowland.harvard.edu,
	Daniel Scally <dan.scally@ideasonboard.com>
Subject: [PATCH v5 11/11] usb: gadget: uvc: Use custom strings if available
Date: Mon,  6 Feb 2023 16:18:02 +0000	[thread overview]
Message-ID: <20230206161802.892954-12-dan.scally@ideasonboard.com> (raw)
In-Reply-To: <20230206161802.892954-1-dan.scally@ideasonboard.com>

If the user has defined a custom string descriptor for the IAD or the
VideoStreaming interfaces then set their index field to point to the
custom descriptor instead of the hardcoded defaults. If no custom
descriptors have been linked to, then use the default ones.

Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
Changes in v5:

	- None

Changes in v4:

	- None

Changes in v3:

	- Dropped the VideoControl description since there's an attribute for
	that now

Changes in v2:

	- New patch

 drivers/usb/gadget/function/f_uvc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 7588ab21f952..5e919fb65833 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -745,6 +745,10 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
 		if (xu->string_descriptor_index)
 			xu->desc.iExtension = cdev->usb_strings[xu->string_descriptor_index].id;
 
+	/*
+	 * We attach the hard-coded defaults incase the user does not provide
+	 * any more appropriate strings through configfs.
+	 */
 	uvc_en_us_strings[UVC_STRING_CONTROL_IDX].s = opts->function_name;
 	us = usb_gstrings_attach(cdev, uvc_function_strings,
 				 ARRAY_SIZE(uvc_en_us_strings));
@@ -752,11 +756,15 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
 		ret = PTR_ERR(us);
 		goto error;
 	}
-	uvc_iad.iFunction = us[UVC_STRING_CONTROL_IDX].id;
-	uvc_control_intf.iInterface = us[UVC_STRING_CONTROL_IDX].id;
-	ret = us[UVC_STRING_STREAMING_IDX].id;
-	uvc_streaming_intf_alt0.iInterface = ret;
-	uvc_streaming_intf_alt1.iInterface = ret;
+
+	uvc_iad.iFunction = opts->iad_index ? cdev->usb_strings[opts->iad_index].id :
+			    us[UVC_STRING_CONTROL_IDX].id;
+	uvc_streaming_intf_alt0.iInterface = opts->vs0_index ?
+					     cdev->usb_strings[opts->vs0_index].id :
+					     us[UVC_STRING_STREAMING_IDX].id;
+	uvc_streaming_intf_alt1.iInterface = opts->vs1_index ?
+					     cdev->usb_strings[opts->vs1_index].id :
+					     us[UVC_STRING_STREAMING_IDX].id;
 
 	/* Allocate interface IDs. */
 	if ((ret = usb_interface_id(c, f)) < 0)
-- 
2.34.1


      parent reply	other threads:[~2023-02-06 16:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 16:17 [PATCH v5 00/11] Add XU support to UVC Gadget Daniel Scally
2023-02-06 16:17 ` [PATCH v5 01/11] usb: gadget: uvc: Make bSourceID read/write Daniel Scally
2023-02-06 16:17 ` [PATCH v5 02/11] usb: gadget: uvc: Generalise helper functions for reuse Daniel Scally
2023-02-06 16:17 ` [PATCH v5 03/11] usb: gadget: uvc: Allow definition of XUs in configfs Daniel Scally
2023-02-06 16:17 ` [PATCH v5 04/11] usb: gadget: uvc: Copy XU descriptors during .bind() Daniel Scally
2023-02-06 16:17 ` [PATCH v5 05/11] usb: gadget: configfs: Rename struct gadget_strings Daniel Scally
2023-02-06 16:17 ` [PATCH v5 06/11] usb: gadget: configfs: Support arbitrary string descriptors Daniel Scally
2023-02-06 16:17 ` [PATCH v5 07/11] usb: gadget: configfs: Attach arbitrary strings to cdev Daniel Scally
2023-02-06 16:17 ` [PATCH v5 08/11] usb: gadget: uvc: Allow linking XUs to string descriptors Daniel Scally
2023-02-06 16:18 ` [PATCH v5 09/11] usb: gadget: uvc: Pick up custom string descriptor IDs Daniel Scally
2023-02-06 16:18 ` [PATCH v5 10/11] usb: gadget: uvc: Allow linking function to string descs Daniel Scally
2023-02-06 16:18 ` Daniel Scally [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230206161802.892954-12-dan.scally@ideasonboard.com \
    --to=dan.scally@ideasonboard.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mgr@pengutronix.de \
    --cc=stern@rowland.harvard.edu \
    --cc=torleiv@huddly.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.