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 08/11] usb: gadget: uvc: Allow linking XUs to string descriptors
Date: Mon,  6 Feb 2023 16:17:59 +0000	[thread overview]
Message-ID: <20230206161802.892954-9-dan.scally@ideasonboard.com> (raw)
In-Reply-To: <20230206161802.892954-1-dan.scally@ideasonboard.com>

Add .allow_link() and .drop_link() callbacks to allow users to link
an extension unit descriptor to a string descriptor.

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

	- None

Changes in v4:

	- None

Changes in v3:

	- Changed the target of the links to in <gadget root>/strings

Changes in v2:

	- New patch

 drivers/usb/gadget/function/uvc_configfs.c | 52 ++++++++++++++++++++++
 drivers/usb/gadget/function/uvc_configfs.h |  1 +
 2 files changed, 53 insertions(+)

diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
index c365f323af45..3ac27838514c 100644
--- a/drivers/usb/gadget/function/uvc_configfs.c
+++ b/drivers/usb/gadget/function/uvc_configfs.c
@@ -1064,8 +1064,60 @@ static void uvcg_extension_release(struct config_item *item)
 	kfree(xu);
 }
 
+static int uvcg_extension_allow_link(struct config_item *src, struct config_item *tgt)
+{
+	struct mutex *su_mutex = &src->ci_group->cg_subsys->su_mutex;
+	struct uvcg_extension *xu = to_uvcg_extension(src);
+	struct config_item *gadget_item;
+	struct gadget_string *string;
+	struct config_item *strings;
+	int ret = 0;
+
+	mutex_lock(su_mutex); /* for navigating configfs hierarchy */
+
+	/* Validate that the target of the link is an entry in strings/<langid> */
+	gadget_item = src->ci_parent->ci_parent->ci_parent->ci_parent->ci_parent;
+	strings = config_group_find_item(to_config_group(gadget_item), "strings");
+	if (!strings || tgt->ci_parent->ci_parent != strings) {
+		ret = -EINVAL;
+		goto put_strings;
+	}
+
+	string = to_gadget_string(tgt);
+	xu->string_descriptor_index = string->usb_string.id;
+
+put_strings:
+	config_item_put(strings);
+	mutex_unlock(su_mutex);
+
+	return ret;
+}
+
+static void uvcg_extension_drop_link(struct config_item *src, struct config_item *tgt)
+{
+	struct mutex *su_mutex = &src->ci_group->cg_subsys->su_mutex;
+	struct uvcg_extension *xu = to_uvcg_extension(src);
+	struct config_item *opts_item;
+	struct f_uvc_opts *opts;
+
+	mutex_lock(su_mutex); /* for navigating configfs hierarchy */
+
+	opts_item = src->ci_parent->ci_parent->ci_parent;
+	opts = to_f_uvc_opts(opts_item);
+
+	mutex_lock(&opts->lock);
+
+	xu->string_descriptor_index = 0;
+
+	mutex_unlock(&opts->lock);
+
+	mutex_unlock(su_mutex);
+}
+
 static struct configfs_item_operations uvcg_extension_item_ops = {
 	.release	= uvcg_extension_release,
+	.allow_link	= uvcg_extension_allow_link,
+	.drop_link	= uvcg_extension_drop_link,
 };
 
 static const struct config_item_type uvcg_extension_type = {
diff --git a/drivers/usb/gadget/function/uvc_configfs.h b/drivers/usb/gadget/function/uvc_configfs.h
index 5557813bcca9..c6a690158138 100644
--- a/drivers/usb/gadget/function/uvc_configfs.h
+++ b/drivers/usb/gadget/function/uvc_configfs.h
@@ -163,6 +163,7 @@ struct uvcg_extension_unit_descriptor {
 struct uvcg_extension {
 	struct config_item item;
 	struct list_head list;
+	u8 string_descriptor_index;
 	struct uvcg_extension_unit_descriptor desc;
 };
 
-- 
2.34.1


  parent reply	other threads:[~2023-02-06 16:20 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 ` Daniel Scally [this message]
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 ` [PATCH v5 11/11] usb: gadget: uvc: Use custom strings if available Daniel Scally

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-9-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.