* [PATCH v4 2/2] usb: typec: Expose Product Type VDOs via sysfs
2020-11-24 20:10 [PATCH v4 1/2] usb: typec: Consolidate sysfs ABI documentation Prashant Malani
@ 2020-11-24 20:10 ` Prashant Malani
2020-11-24 20:32 ` [PATCH v4 1/2] usb: typec: Consolidate sysfs ABI documentation Prashant Malani
1 sibling, 0 replies; 6+ messages in thread
From: Prashant Malani @ 2020-11-24 20:10 UTC (permalink / raw)
To: linux-kernel, linux-usb, gregkh, heikki.krogerus; +Cc: bleung, Prashant Malani
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 sysfs attributes 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>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
Changes in v4:
- Added Reviewed-by tag from v3's review.
- Rebased on top of usb-next + Patch 1/2
Changes in v3:
- Split each product type VDO into a separate attribute.
- Changed sprintf() to sysfs_emit().
- Changed ABI documentation based on consolidation of identity VDO
descriptions in the previous patch (1/2).
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 | 24 +++++++++++++++
drivers/usb/typec/class.c | 33 +++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
index 88ffc14d4cd2..619c4c67432b 100644
--- a/Documentation/ABI/testing/sysfs-class-typec
+++ b/Documentation/ABI/testing/sysfs-class-typec
@@ -228,6 +228,30 @@ Description:
will show 0 until Discover Identity command result becomes
available. The value can be polled.
+What: /sys/class/typec/<port>-{partner|cable}/identity/product_type_vdo1
+Date: October 2020
+Contact: Prashant Malani <pmalani@chromium.org>
+Description:
+ 1st Product Type VDO of Discover Identity command result.
+ The value will show 0 until Discover Identity command result becomes
+ available and a valid Product Type VDO is returned.
+
+What: /sys/class/typec/<port>-{partner|cable}/identity/product_type_vdo2
+Date: October 2020
+Contact: Prashant Malani <pmalani@chromium.org>
+Description:
+ 2nd Product Type VDO of Discover Identity command result.
+ The value will show 0 until Discover Identity command result becomes
+ available and a valid Product Type VDO is returned.
+
+What: /sys/class/typec/<port>-{partner|cable}/identity/product_type_vdo3
+Date: October 2020
+Contact: Prashant Malani <pmalani@chromium.org>
+Description:
+ 3rd Product Type VDO of Discover Identity command result.
+ The value will show 0 until Discover Identity command result becomes
+ available and a valid Product Type VDO is returned.
+
USB Type-C port alternate mode devices.
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index cb1362187a7c..df4478baf95b 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -124,10 +124,40 @@ static ssize_t product_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(product);
+static ssize_t product_type_vdo1_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct usb_pd_identity *id = get_pd_identity(dev);
+
+ return sysfs_emit(buf, "0x%08x\n", id->vdo[0]);
+}
+static DEVICE_ATTR_RO(product_type_vdo1);
+
+static ssize_t product_type_vdo2_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct usb_pd_identity *id = get_pd_identity(dev);
+
+ return sysfs_emit(buf, "0x%08x\n", id->vdo[1]);
+}
+static DEVICE_ATTR_RO(product_type_vdo2);
+
+static ssize_t product_type_vdo3_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct usb_pd_identity *id = get_pd_identity(dev);
+
+ return sysfs_emit(buf, "0x%08x\n", id->vdo[2]);
+}
+static DEVICE_ATTR_RO(product_type_vdo3);
+
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_vdo1.attr,
+ &dev_attr_product_type_vdo2.attr,
+ &dev_attr_product_type_vdo3.attr,
NULL
};
@@ -146,6 +176,9 @@ 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_vdo1");
+ sysfs_notify(&dev->kobj, "identity", "product_type_vdo2");
+ sysfs_notify(&dev->kobj, "identity", "product_type_vdo3");
}
/* ------------------------------------------------------------------------- */
--
2.29.2.454.gaff20da3a2-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v4 1/2] usb: typec: Consolidate sysfs ABI documentation
2020-11-24 20:10 [PATCH v4 1/2] usb: typec: Consolidate sysfs ABI documentation Prashant Malani
2020-11-24 20:10 ` [PATCH v4 2/2] usb: typec: Expose Product Type VDOs via sysfs Prashant Malani
@ 2020-11-24 20:32 ` Prashant Malani
2020-11-25 7:46 ` Heikki Krogerus
1 sibling, 1 reply; 6+ messages in thread
From: Prashant Malani @ 2020-11-24 20:32 UTC (permalink / raw)
To: linux-kernel, linux-usb, gregkh, heikki.krogerus; +Cc: bleung, Heikki Krogerus
Hi,
On Tue, Nov 24, 2020 at 12:10:31PM -0800, Prashant Malani wrote:
> Both partner and cable have identity VDOs. These are listed separately
> in the Documentation/ABI/testing/sysfs-class-typec. Factor these out
> into a common location to avoid the duplication.
>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>
> Acked-by: Heikki Krogerus <heikki.krogeurus@linux.intel.com>
I copied the Acked-by line from v3 [1] as is, but looks like there was a
typo there and the email address should be
"heikki.krogerus@linux.intel.com".
Please let me know if it's fine as is or whether I should send another
patchset.
[1]
https://lore.kernel.org/linux-usb/20201110105225.GH1224435@kuha.fi.intel.com/
> ---
>
> Changes in v4:
> - Rebased on top of the usb-next tree.
> - Added Acked-by tag from pevious version's review.
> - Corrected a typo ('syfs' -> 'sysfs') in the subject line.
>
> Patch first introduced in v3.
>
> Documentation/ABI/testing/sysfs-class-typec | 59 ++++++---------------
> 1 file changed, 17 insertions(+), 42 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
> index 4eccb343fc7b..88ffc14d4cd2 100644
> --- a/Documentation/ABI/testing/sysfs-class-typec
> +++ b/Documentation/ABI/testing/sysfs-class-typec
> @@ -147,42 +147,6 @@ Description:
> during Power Delivery discovery. This file remains hidden until a value
> greater than or equal to 0 is set by Type C port driver.
>
> -What: /sys/class/typec/<port>-partner>/identity/
> -Date: April 2017
> -Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> -Description:
> - This directory appears only if the port device driver is capable
> - of showing the result of Discover Identity USB power delivery
> - command. That will not always be possible even when USB power
> - delivery is supported, for example when USB power delivery
> - communication for the port is mostly handled in firmware. If the
> - directory exists, it will have an attribute file for every VDO
> - in Discover Identity command result.
> -
> -What: /sys/class/typec/<port>-partner/identity/id_header
> -Date: April 2017
> -Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> -Description:
> - ID Header VDO part of Discover Identity command result. The
> - value will show 0 until Discover Identity command result becomes
> - available. The value can be polled.
> -
> -What: /sys/class/typec/<port>-partner/identity/cert_stat
> -Date: April 2017
> -Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> -Description:
> - Cert Stat VDO part of Discover Identity command result. The
> - value will show 0 until Discover Identity command result becomes
> - available. The value can be polled.
> -
> -What: /sys/class/typec/<port>-partner/identity/product
> -Date: April 2017
> -Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> -Description:
> - Product VDO part of Discover Identity command result. The value
> - will show 0 until Discover Identity command result becomes
> - available. The value can be polled.
> -
>
> USB Type-C cable devices (eg. /sys/class/typec/port0-cable/)
>
> @@ -219,17 +183,28 @@ Description:
> This file remains hidden until a value greater than or equal to 0
> is set by Type C port driver.
>
> -What: /sys/class/typec/<port>-cable/identity/
> +
> +USB Type-C partner/cable Power Delivery Identity objects
> +
> +NOTE: The following attributes will be applicable to both
> +partner (e.g /sys/class/typec/port0-partner/) and
> +cable (e.g /sys/class/typec/port0-cable/) devices. Consequently, the example file
> +paths below are prefixed with "/sys/class/typec/<port>-{partner|cable}/" to
> +reflect this.
> +
> +What: /sys/class/typec/<port>-{partner|cable}/identity/
> Date: April 2017
> Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Description:
> This directory appears only if the port device driver is capable
> of showing the result of Discover Identity USB power delivery
> command. That will not always be possible even when USB power
> - delivery is supported. If the directory exists, it will have an
> - attribute for every VDO returned by Discover Identity command.
> + delivery is supported, for example when USB power delivery
> + communication for the port is mostly handled in firmware. If the
> + directory exists, it will have an attribute file for every VDO
> + in Discover Identity command result.
>
> -What: /sys/class/typec/<port>-cable/identity/id_header
> +What: /sys/class/typec/<port>-{partner|cable}/identity/id_header
> Date: April 2017
> Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Description:
> @@ -237,7 +212,7 @@ Description:
> value will show 0 until Discover Identity command result becomes
> available. The value can be polled.
>
> -What: /sys/class/typec/<port>-cable/identity/cert_stat
> +What: /sys/class/typec/<port>-{partner|cable}/identity/cert_stat
> Date: April 2017
> Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Description:
> @@ -245,7 +220,7 @@ Description:
> value will show 0 until Discover Identity command result becomes
> available. The value can be polled.
>
> -What: /sys/class/typec/<port>-cable/identity/product
> +What: /sys/class/typec/<port>-{partner|cable}/identity/product
> Date: April 2017
> Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Description:
> --
> 2.29.2.454.gaff20da3a2-goog
>
^ permalink raw reply [flat|nested] 6+ messages in thread