public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: typec: Expose Product Type VDOs via sysfs
@ 2020-10-22  6:15 Prashant Malani
  2020-10-22  6:57 ` Greg KH
  0 siblings, 1 reply; 10+ messages in thread
From: Prashant Malani @ 2020-10-22  6:15 UTC (permalink / raw)
  To: linux-kernel, linux-usb, gregkh
  Cc: Prashant Malani, Benson Leung, Heikki Krogerus

A PD-capable device can return up to 3 Product Type VDOs as part of its
DiscoverIdentity Response (USB PD Spec, Rev 3.0, Version 2.0, Section
6.4.4.3.1). Add a sysfs attribute to expose these to userspace.

Cc: Benson Leung <bleung@chromium.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
---

NOTE: I didn't include Benson's Reviewed-by from v1, since this version
introduced the sysfs_notify() call.

Changes in v2:
- Added sysfs_notify() call for the attribute.
- Added description for the attribute in
  Documentation/ABI/testing/sysfs-class-typec.

 Documentation/ABI/testing/sysfs-class-typec | 17 +++++++++++++++++
 drivers/usb/typec/class.c                   | 11 +++++++++++
 2 files changed, 28 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
index b834671522d6..16440a236b66 100644
--- a/Documentation/ABI/testing/sysfs-class-typec
+++ b/Documentation/ABI/testing/sysfs-class-typec
@@ -170,6 +170,14 @@ Description:
 		will show 0 until Discover Identity command result becomes
 		available. The value can be polled.
 
+What:		/sys/class/typec/<port>-partner/identity/product_type_vdo
+Date:		October 2020
+Contact:	Prashant Malani <pmalani@chromium.org>
+Description:
+		Product Type VDOs part of Discover Identity command result. 3 values
+		are displayed (for the 3 possible Product Type VDOs), one per line.
+		The values will show 0s until Discover Identity command result becomes
+		available. The values can be polled.
 
 USB Type-C cable devices (eg. /sys/class/typec/port0-cable/)
 
@@ -230,6 +238,15 @@ Description:
 		will show 0 until Discover Identity command result becomes
 		available. The value can be polled.
 
+What:		/sys/class/typec/<port>-cable/identity/product_type_vdo
+Date:		October 2020
+Contact:	Prashant Malani <pmalani@chromium.org>
+Description:
+		Product Type VDOs part of Discover Identity command result. 3 values
+		are displayed (for the 3 possible Product Type VDOs), one per line.
+		The values will show 0s until Discover Identity command result becomes
+		available. The values can be polled.
+
 
 USB Type-C port alternate mode devices.
 
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 35eec707cb51..37fa4501e75f 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -122,10 +122,20 @@ static ssize_t product_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(product);
 
+static ssize_t product_type_vdo_show(struct device *dev, struct device_attribute *attr,
+				     char *buf)
+{
+	struct usb_pd_identity *id = get_pd_identity(dev);
+
+	return sprintf(buf, "0x%08x\n0x%08x\n0x%08x\n", id->vdo[0], id->vdo[1], id->vdo[2]);
+}
+static DEVICE_ATTR_RO(product_type_vdo);
+
 static struct attribute *usb_pd_id_attrs[] = {
 	&dev_attr_id_header.attr,
 	&dev_attr_cert_stat.attr,
 	&dev_attr_product.attr,
+	&dev_attr_product_type_vdo.attr,
 	NULL
 };
 
@@ -144,6 +154,7 @@ static void typec_report_identity(struct device *dev)
 	sysfs_notify(&dev->kobj, "identity", "id_header");
 	sysfs_notify(&dev->kobj, "identity", "cert_stat");
 	sysfs_notify(&dev->kobj, "identity", "product");
+	sysfs_notify(&dev->kobj, "identity", "product_type_vdo");
 }
 
 /* ------------------------------------------------------------------------- */
-- 
2.29.0.rc1.297.gfa9743e501-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-10-23 21:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-22  6:15 [PATCH v2] usb: typec: Expose Product Type VDOs via sysfs Prashant Malani
2020-10-22  6:57 ` Greg KH
2020-10-22  7:13   ` Prashant Malani
2020-10-22  7:17     ` Greg KH
2020-10-22  7:25       ` Prashant Malani
2020-10-22 12:42         ` Heikki Krogerus
2020-10-22 18:18           ` Prashant Malani
2020-10-22 23:25           ` Benson Leung
2020-10-23  9:34             ` Heikki Krogerus
2020-10-23 21:52     ` Prashant Malani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox