mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Giandomenico Rossi <rossi@amelchem.com>
To: barebox@lists.infradead.org
Cc: Giandomenico Rossi <rossi@amelchem.com>, Nicola Fontana <ntd@entidi.it>
Subject: [PATCH 1/4] usb: typec: add typec_port_from_device()
Date: Sat, 14 Nov 2026 17:19:50 +0100	[thread overview]
Message-ID: <20261114161953.1457428-2-rossi@amelchem.com> (raw)
In-Reply-To: <20261114161953.1457428-1-rossi@amelchem.com>

Add an exported helper to retrieve the struct typec_port associated
with a struct device.

This allows callers holding a Type-C port device to obtain the
corresponding typec_port handle, whose definition is private to
drivers/usb/typec/class.c.

Reviewed-by: Nicola Fontana <ntd@entidi.it>
Signed-off-by: Giandomenico Rossi <rossi@amelchem.com>
---
 drivers/usb/typec/class.c | 21 +++++++++++++++++++++
 include/linux/usb/typec.h |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index e03eaccbb9..e13699719b 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -83,6 +83,27 @@ int typec_set_role(struct typec_port *port, enum usb_role role)
 }
 EXPORT_SYMBOL_GPL(typec_set_role);
 
+
+/**
+ * typec_port_from_device() - get the typec_port embedding a struct device
+ * @dev: device backing a registered Type-C port
+ *
+ * Resolves the struct typec_port that contains @dev. Intended for callers
+ * that hold a struct device (e.g. from get_device_by_name()) and need the
+ * opaque typec_port handle, which they cannot obtain themselves since the
+ * type is private to this file.
+ *
+ * The caller must ensure @dev actually backs a Type-C port; passing an
+ * unrelated device yields an invalid pointer.
+ *
+ * Return: the struct typec_port containing @dev.
+ */
+struct typec_port *typec_port_from_device(struct device *dev)
+{
+	return container_of(dev, struct typec_port, dev);
+}
+EXPORT_SYMBOL(typec_port_from_device);
+
 /**
  * typec_get_drvdata - Return private driver data pointer
  * @port: USB Type-C port
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 315dee95e4..2de110d592 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -51,4 +51,6 @@ int typec_set_role(struct typec_port *port, enum usb_role role);
 
 void *typec_get_drvdata(struct typec_port *port);
 
+struct typec_port *typec_port_from_device(struct device *dev);
+
 #endif /* __LINUX_USB_TYPEC_H */
-- 
2.34.1




  reply	other threads:[~2026-11-14 16:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 16:19 [PATCH 0/4] usb: typec: add STUSB4500 USB-C PD sink support Giandomenico Rossi
2026-11-14 16:19 ` Giandomenico Rossi [this message]
2026-11-14 16:19 ` [PATCH 2/4] usb: typec: stusb4500: add USB PD fixed supply driver Giandomenico Rossi
2026-11-17 11:27   ` Sascha Hauer
2026-11-14 16:19 ` [PATCH 3/4] dt-bindings: usb: add STUSB4500 USB PD sink controller binding Giandomenico Rossi
2026-11-14 16:19 ` [PATCH 4/4] commands: stusb4500: add USB-C PD control command Giandomenico Rossi
2026-11-17 11:46   ` Sascha Hauer
2026-11-17 13:12     ` Giandomenico Rossi

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=20261114161953.1457428-2-rossi@amelchem.com \
    --to=rossi@amelchem.com \
    --cc=barebox@lists.infradead.org \
    --cc=ntd@entidi.it \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox