Skip to contentSkip to conversation

usb: typec: and platform/chrome: Add PD revision numbers

PATCH In review Benson Leung 6 participants 24 messages Jan 29, 2021 – Feb 2, 2021

Subsystems (5)
lore
Share & tools
lore

Benson Leung

author maintainer
#0 lore raw

cover usb: typec: and platform/chrome: Add PD revision numbers

USB Power Delivery has a 3 entity handshake (port, cable, partner), and as of USB PD R3.0, each entity may independently support either Revision 2 or Revision 3 signaling and protocol. In order for userspace and the kernel to properly process the data objects received from a particular SOP*, we must know to which revision of the spec each conforms.

This series adds individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/typec.

I provide as a first implementation of this, platform/chrome's cros_ec_typec driver, whose underlying status messages convey the SOP and SOP' revisions already.

Thanks,
Benson

Benson Leung (6):
usb: typec: Standardize PD Revision format with Type-C Revision
usb: typec: Provide PD Specification Revision for cable and partner
usb: typec: Add typec_partner_set_pd_revision platform/chrome: cros_ec_typec: Report SOP' PD revision from status platform/chrome: cros_ec_typec: Set Partner PD revision from status platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected

 Documentation/ABI/testing/sysfs-class-typec | 20 ++++++-
 drivers/platform/chrome/cros_ec_typec.c     | 26 +++++++--
 drivers/usb/typec/class.c                   | 59 +++++++++++++++++++--
 include/linux/usb/typec.h                   | 11 ++++
 4 files changed, 108 insertions(+), 8 deletions(-)
Signature · 1 line
2.30.0.365.g02bc693789-goog
author maintainer
#1 lore raw

PATCH 1/6 usb: typec: Standardize PD Revision format with Type-C Revision

The Type-C Revision was in a specific BCD format "0120H" for 1.2. USB PD revision numbers follow a similar pattern with "0300H" for 3.0.

Standardizes the sysfs format for usb_power_delivery_revision to align with the BCD format used for usb_typec_revision.

Example values:
- "2.0": USB Power Delivery Release 2.0
- "3.0": USB Power Delivery Release 3.0
- "3.1": USB Power Delivery Release 3.1

---
 Documentation/ABI/testing/sysfs-class-typec | 7 ++++++-
 drivers/usb/typec/class.c                   | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-class-typec +6 -1
index 8eab41e79ce6..b61480535fdc 100644
@@ -105,7 +105,12 @@ Date:		April 2017
 Contact:	Heikki Krogerus <[email protected]>
 Description:
 		Revision number of the supported USB Power Delivery
-		specification, or 0 when USB Power Delivery is not supported.
+		specification, or 0.0 when USB Power Delivery is not supported.
+
+		Example values:
+		- "2.0": USB Power Delivery Release 2.0
+		- "3.0": USB Power Delivery Release 3.0
+		- "3.1": USB Power Delivery Release 3.1
 
 What:		/sys/class/typec/<port>/usb_typec_revision
 Date:		April 2017
drivers/usb/typec/class.c +2 -1
index 8f77669f9cf4..4f60ee7ba76a 100644
@@ -1500,8 +1500,9 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev,
 						char *buf)
 {
 	struct typec_port *p = to_typec_port(dev);
+	u16 rev = p->cap->pd_revision;
 
-	return sprintf(buf, "%d\n", (p->cap->pd_revision >> 8) & 0xff);
+	return sprintf(buf, "%d.%d\n", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
 }
 static DEVICE_ATTR_RO(usb_power_delivery_revision);
 
Signature · 1 line
2.30.0.365.g02bc693789-goog
maintainer Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] usb: typec: Standardize PD Revision format with Type-C Revision

Quoted 6 lines · Benson Leung

The Type-C Revision was in a specific BCD format "0120H" for 1.2. USB PD revision numbers follow a similar pattern with "0300H" for 3.0.

Standardizes the sysfs format for usb_power_delivery_revision to align with the BCD format used for usb_typec_revision.

Quoted 6 lines

Example values:
- "2.0": USB Power Delivery Release 2.0
- "3.0": USB Power Delivery Release 3.0
- "3.1": USB Power Delivery Release 3.1

I guess it's OK to modify the ABI like this.

Quoted 40 lines
---
 Documentation/ABI/testing/sysfs-class-typec | 7 ++++++-
 drivers/usb/typec/class.c                   | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-class-typec +6 -1
index 8eab41e79ce6..b61480535fdc 100644
@@ -105,7 +105,12 @@ Date:		April 2017
 Contact:	Heikki Krogerus <[email protected]>
 Description:
 		Revision number of the supported USB Power Delivery
-		specification, or 0 when USB Power Delivery is not supported.
+		specification, or 0.0 when USB Power Delivery is not supported.
+
+		Example values:
+		- "2.0": USB Power Delivery Release 2.0
+		- "3.0": USB Power Delivery Release 3.0
+		- "3.1": USB Power Delivery Release 3.1
 
 What:		/sys/class/typec/<port>/usb_typec_revision
 Date:		April 2017
drivers/usb/typec/class.c +2 -1
index 8f77669f9cf4..4f60ee7ba76a 100644
@@ -1500,8 +1500,9 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev,
 						char *buf)
 {
 	struct typec_port *p = to_typec_port(dev);
+	u16 rev = p->cap->pd_revision;
 
-	return sprintf(buf, "%d\n", (p->cap->pd_revision >> 8) & 0xff);
+	return sprintf(buf, "%d.%d\n", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
 }
 static DEVICE_ATTR_RO(usb_power_delivery_revision);
 
Signature · 1 line
2.30.0.365.g02bc693789-goog

thanks,

Signature · 1 line
heikki
author maintainer
#3 lore raw

PATCH 2/6 usb: typec: Provide PD Specification Revision for cable and partner

In reply to Benson Leung

The USB Power Delivery specification Section 6.2.1.1.5 outlines revision backward compatibility requirements starting from Revision 3.0.

The Port, the Cable Plug, and the Port Partner may support either revision 2 or revision 3 independently, and communication between ports, partners, and cables of different revisions are allowed under rules that the parties agree to communicate between each other using the lowest common operating revision.

This may mean that Port-to-Partner operating revision comms may be different than Port-to-CablePlug operating revision comms. For example, it is possible for a R3.0 port to communicate with a R3.0 partner using R3.0 messages, while the R3.0 port (in the same session) must communicate with the R2.0 cable using R2.0 messages only.

Introduce individual revision number properties for cable and port partner so that the port can track them independently.

---
 Documentation/ABI/testing/sysfs-class-typec | 13 +++++++++
 drivers/usb/typec/class.c                   | 30 ++++++++++++++++++---
 include/linux/usb/typec.h                   | 10 +++++++
 3 files changed, 49 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-class-typec +13 -0
index b61480535fdc..40122d915ae1 100644
@@ -112,6 +112,19 @@ Description:
 		- "3.0": USB Power Delivery Release 3.0
 		- "3.1": USB Power Delivery Release 3.1
 
+What:		/sys/class/typec/<port>-{partner|cable}/usb_power_delivery_revision
+Date:		January 2021
+Contact:	Benson Leung <[email protected]>
+Description:
+		Revision number of the supported USB Power Delivery
+		specification of the port partner or cable, or 0.0 when USB
+		Power Delivery is not supported.
+
+		Example values:
+		- "2.0": USB Power Delivery Release 2.0
+		- "3.0": USB Power Delivery Release 3.0
+		- "3.1": USB Power Delivery Release 3.1
+
 What:		/sys/class/typec/<port>/usb_typec_revision
 Date:		April 2017
 Contact:	Heikki Krogerus <[email protected]>
drivers/usb/typec/class.c +26 -4
index 4f60ee7ba76a..b5241f4756c2 100644
@@ -27,6 +27,7 @@ struct typec_cable {
 	enum typec_plug_type		type;
 	struct usb_pd_identity		*identity;
 	unsigned int			active:1;
+	u16				pd_revision; /* 0300H = "3.0" */
 };
 
 struct typec_partner {
@@ -36,6 +37,7 @@ struct typec_partner {
 	enum typec_accessory		accessory;
 	struct ida			mode_ids;
 	int				num_altmodes;
+	u16				pd_revision; /* 0300H = "3.0" */
 };
 
 struct typec_port {
@@ -264,6 +266,11 @@ type_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR_RO(type);
 
+static ssize_t usb_power_delivery_revision_show(struct device *dev,
+						struct device_attribute *attr,
+						char *buf);
+static DEVICE_ATTR_RO(usb_power_delivery_revision);
+
 /* ------------------------------------------------------------------------- */
 /* Alternate Modes */
 
@@ -680,6 +687,7 @@ static struct attribute *typec_partner_attrs[] = {
 	&dev_attr_supports_usb_power_delivery.attr,
 	&dev_attr_number_of_alternate_modes.attr,
 	&dev_attr_type.attr,
+	&dev_attr_usb_power_delivery_revision.attr,
 	NULL
 };
 
@@ -815,6 +823,7 @@ struct typec_partner *typec_register_partner(struct typec_port *port,
 	partner->usb_pd = desc->usb_pd;
 	partner->accessory = desc->accessory;
 	partner->num_altmodes = -1;
+	partner->pd_revision = desc->pd_revision;
 
 	if (desc->identity) {
 		/*
@@ -1028,6 +1037,7 @@ static DEVICE_ATTR_RO(plug_type);
 static struct attribute *typec_cable_attrs[] = {
 	&dev_attr_type.attr,
 	&dev_attr_plug_type.attr,
+	&dev_attr_usb_power_delivery_revision.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(typec_cable);
@@ -1130,6 +1140,7 @@ struct typec_cable *typec_register_cable(struct typec_port *port,
 
 	cable->type = desc->type;
 	cable->active = desc->active;
+	cable->pd_revision = desc->pd_revision;
 
 	if (desc->identity) {
 		/*
@@ -1499,12 +1510,23 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev,
 						struct device_attribute *attr,
 						char *buf)
 {
-	struct typec_port *p = to_typec_port(dev);
-	u16 rev = p->cap->pd_revision;
+	u16 rev = 0;
 
-	return sprintf(buf, "%d.%d\n", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
+	if (is_typec_partner(dev)) {
+		struct typec_partner *partner = to_typec_partner(dev);
+
+		rev = partner->pd_revision;
+	} else if (is_typec_cable(dev)) {
+		struct typec_cable *cable = to_typec_cable(dev);
+
+		rev = cable->pd_revision;
+	} else if (is_typec_port(dev)) {
+		struct typec_port *p = to_typec_port(dev);
+
+		rev = p->cap->pd_revision;
+	}
+	return sysfs_emit(buf, "%d.%d\n", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
 }
-static DEVICE_ATTR_RO(usb_power_delivery_revision);
 
 static ssize_t orientation_show(struct device *dev,
 				   struct device_attribute *attr,
include/linux/usb/typec.h +10 -0
index 54475323f83b..42c6b7c07a99 100644
@@ -164,6 +164,7 @@ struct typec_plug_desc {
  * @type: The plug type from USB PD Cable VDO
  * @active: Is the cable active or passive
  * @identity: Result of Discover Identity command
+ * @pd_revision: USB Power Delivery Specification revision if supported
  *
  * Represents USB Type-C Cable attached to USB Type-C port.
  */
@@ -171,6 +172,8 @@ struct typec_cable_desc {
 	enum typec_plug_type	type;
 	unsigned int		active:1;
 	struct usb_pd_identity	*identity;
+	u16			pd_revision; /* 0300H = "3.0" */
+
 };
 
 /*
@@ -178,15 +181,22 @@ struct typec_cable_desc {
  * @usb_pd: USB Power Delivery support
  * @accessory: Audio, Debug or none.
  * @identity: Discover Identity command data
+ * @pd_revision: USB Power Delivery Specification Revision if supported
  *
  * Details about a partner that is attached to USB Type-C port. If @identity
  * member exists when partner is registered, a directory named "identity" is
  * created to sysfs for the partner device.
+ *
+ * @pd_revision is based on the setting of the "Specification Revision" field
+ * in the message header on the initial "Source Capabilities" message received
+ * from the partner, or a "Request" message received from the partner, depending
+ * on whether our port is a Sink or a Source.
  */
 struct typec_partner_desc {
 	unsigned int		usb_pd:1;
 	enum typec_accessory	accessory;
 	struct usb_pd_identity	*identity;
+	u16			pd_revision; /* 0300H = "3.0" */
 };
 
 /**
Signature · 1 line
2.30.0.365.g02bc693789-goog
maintainer Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] usb: typec: Provide PD Specification Revision for cable and partner

Quoted 15 lines · Benson Leung

The USB Power Delivery specification Section 6.2.1.1.5 outlines revision backward compatibility requirements starting from Revision 3.0.

The Port, the Cable Plug, and the Port Partner may support either revision 2 or revision 3 independently, and communication between ports, partners, and cables of different revisions are allowed under rules that the parties agree to communicate between each other using the lowest common operating revision.

This may mean that Port-to-Partner operating revision comms may be different than Port-to-CablePlug operating revision comms. For example, it is possible for a R3.0 port to communicate with a R3.0 partner using R3.0 messages, while the R3.0 port (in the same session) must communicate with the R2.0 cable using R2.0 messages only.

Quoted 4 lines

Introduce individual revision number properties for cable and port partner so that the port can track them independently.

Quoted 168 lines
---
 Documentation/ABI/testing/sysfs-class-typec | 13 +++++++++
 drivers/usb/typec/class.c                   | 30 ++++++++++++++++++---
 include/linux/usb/typec.h                   | 10 +++++++
 3 files changed, 49 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-class-typec +13 -0
index b61480535fdc..40122d915ae1 100644
@@ -112,6 +112,19 @@ Description:
 		- "3.0": USB Power Delivery Release 3.0
 		- "3.1": USB Power Delivery Release 3.1
 
+What:		/sys/class/typec/<port>-{partner|cable}/usb_power_delivery_revision
+Date:		January 2021
+Contact:	Benson Leung <[email protected]>
+Description:
+		Revision number of the supported USB Power Delivery
+		specification of the port partner or cable, or 0.0 when USB
+		Power Delivery is not supported.
+
+		Example values:
+		- "2.0": USB Power Delivery Release 2.0
+		- "3.0": USB Power Delivery Release 3.0
+		- "3.1": USB Power Delivery Release 3.1
+
 What:		/sys/class/typec/<port>/usb_typec_revision
 Date:		April 2017
 Contact:	Heikki Krogerus <[email protected]>
drivers/usb/typec/class.c +26 -4
index 4f60ee7ba76a..b5241f4756c2 100644
@@ -27,6 +27,7 @@ struct typec_cable {
 	enum typec_plug_type		type;
 	struct usb_pd_identity		*identity;
 	unsigned int			active:1;
+	u16				pd_revision; /* 0300H = "3.0" */
 };
 
 struct typec_partner {
@@ -36,6 +37,7 @@ struct typec_partner {
 	enum typec_accessory		accessory;
 	struct ida			mode_ids;
 	int				num_altmodes;
+	u16				pd_revision; /* 0300H = "3.0" */
 };
 
 struct typec_port {
@@ -264,6 +266,11 @@ type_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR_RO(type);
 
+static ssize_t usb_power_delivery_revision_show(struct device *dev,
+						struct device_attribute *attr,
+						char *buf);
+static DEVICE_ATTR_RO(usb_power_delivery_revision);
+
 /* ------------------------------------------------------------------------- */
 /* Alternate Modes */
 
@@ -680,6 +687,7 @@ static struct attribute *typec_partner_attrs[] = {
 	&dev_attr_supports_usb_power_delivery.attr,
 	&dev_attr_number_of_alternate_modes.attr,
 	&dev_attr_type.attr,
+	&dev_attr_usb_power_delivery_revision.attr,
 	NULL
 };
 
@@ -815,6 +823,7 @@ struct typec_partner *typec_register_partner(struct typec_port *port,
 	partner->usb_pd = desc->usb_pd;
 	partner->accessory = desc->accessory;
 	partner->num_altmodes = -1;
+	partner->pd_revision = desc->pd_revision;
 
 	if (desc->identity) {
 		/*
@@ -1028,6 +1037,7 @@ static DEVICE_ATTR_RO(plug_type);
 static struct attribute *typec_cable_attrs[] = {
 	&dev_attr_type.attr,
 	&dev_attr_plug_type.attr,
+	&dev_attr_usb_power_delivery_revision.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(typec_cable);
@@ -1130,6 +1140,7 @@ struct typec_cable *typec_register_cable(struct typec_port *port,
 
 	cable->type = desc->type;
 	cable->active = desc->active;
+	cable->pd_revision = desc->pd_revision;
 
 	if (desc->identity) {
 		/*
@@ -1499,12 +1510,23 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev,
 						struct device_attribute *attr,
 						char *buf)
 {
-	struct typec_port *p = to_typec_port(dev);
-	u16 rev = p->cap->pd_revision;
+	u16 rev = 0;
 
-	return sprintf(buf, "%d.%d\n", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
+	if (is_typec_partner(dev)) {
+		struct typec_partner *partner = to_typec_partner(dev);
+
+		rev = partner->pd_revision;
+	} else if (is_typec_cable(dev)) {
+		struct typec_cable *cable = to_typec_cable(dev);
+
+		rev = cable->pd_revision;
+	} else if (is_typec_port(dev)) {
+		struct typec_port *p = to_typec_port(dev);
+
+		rev = p->cap->pd_revision;
+	}
+	return sysfs_emit(buf, "%d.%d\n", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
 }
-static DEVICE_ATTR_RO(usb_power_delivery_revision);
 
 static ssize_t orientation_show(struct device *dev,
 				   struct device_attribute *attr,
include/linux/usb/typec.h +10 -0
index 54475323f83b..42c6b7c07a99 100644
@@ -164,6 +164,7 @@ struct typec_plug_desc {
  * @type: The plug type from USB PD Cable VDO
  * @active: Is the cable active or passive
  * @identity: Result of Discover Identity command
+ * @pd_revision: USB Power Delivery Specification revision if supported
  *
  * Represents USB Type-C Cable attached to USB Type-C port.
  */
@@ -171,6 +172,8 @@ struct typec_cable_desc {
 	enum typec_plug_type	type;
 	unsigned int		active:1;
 	struct usb_pd_identity	*identity;
+	u16			pd_revision; /* 0300H = "3.0" */
+
 };
 
 /*
@@ -178,15 +181,22 @@ struct typec_cable_desc {
  * @usb_pd: USB Power Delivery support
  * @accessory: Audio, Debug or none.
  * @identity: Discover Identity command data
+ * @pd_revision: USB Power Delivery Specification Revision if supported
  *
  * Details about a partner that is attached to USB Type-C port. If @identity
  * member exists when partner is registered, a directory named "identity" is
  * created to sysfs for the partner device.
+ *
+ * @pd_revision is based on the setting of the "Specification Revision" field
+ * in the message header on the initial "Source Capabilities" message received
+ * from the partner, or a "Request" message received from the partner, depending
+ * on whether our port is a Sink or a Source.
  */
 struct typec_partner_desc {
 	unsigned int		usb_pd:1;
 	enum typec_accessory	accessory;
 	struct usb_pd_identity	*identity;
+	u16			pd_revision; /* 0300H = "3.0" */
 };
 
 /**
Signature · 1 line
2.30.0.365.g02bc693789-goog

thanks,

Signature · 1 line
heikki
author maintainer
#5 lore raw

PATCH 3/6 usb: typec: Add typec_partner_set_pd_revision

In reply to Benson Leung

The partner's PD revision may be resolved later than the port partner registration since the port partner creation may take place once Type-C detects the port has changed state, but before PD communication is completed.

Add a setter so that the partner's PD revision can be attached to it once it becomes available.

If the revision is set to a valid version (not 0), the setter will also refresh the partner's usb_pd flag and notify on "supports_usb_power_delivery" sysfs property as well.

---
 drivers/usb/typec/class.c | 30 ++++++++++++++++++++++++++++++
 include/linux/usb/typec.h |  1 +
 2 files changed, 31 insertions(+)
drivers/usb/typec/class.c +30 -0
index b5241f4756c2..b6ceab3dc16b 100644
@@ -748,6 +748,36 @@ int typec_partner_set_identity(struct typec_partner *partner)
 }
 EXPORT_SYMBOL_GPL(typec_partner_set_identity);
 
+/**
+ * typec_partner_set_pd_revision - Set the PD revision supported by the partner
+ * @partner: The partner to be updated.
+ * @pd_revision:  USB Power Delivery Specification Revision supported by partner
+ *
+ * This routine is used to report that the PD revision of the port partner has
+ * become available.
+ *
+ * Returns 0 on success or negative error number on failure.
+ */
+int typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision)
+{
+	int ret;
+
+	if (partner->pd_revision == pd_revision)
+		return 0;
+
+	partner->pd_revision = pd_revision;
+	sysfs_notify(&partner->dev.kobj, NULL, "usb_power_delivery_revision");
+	if (pd_revision != 0 && !partner->usb_pd) {
+		partner->usb_pd = 1;
+		sysfs_notify(&partner->dev.kobj, NULL,
+			     "supports_usb_power_delivery");
+	}
+	kobject_uevent(&partner->dev.kobj, KOBJ_CHANGE);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(typec_partner_set_pd_revision);
+
 /**
  * typec_partner_set_num_altmodes - Set the number of available partner altmodes
  * @partner: The partner to be updated.
include/linux/usb/typec.h +1 -0
index 42c6b7c07a99..4946eca742d5 100644
@@ -126,6 +126,7 @@ struct typec_altmode_desc {
 	enum typec_port_data	roles;
 };
 
+int typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision);
 int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmodes);
 struct typec_altmode
 *typec_partner_register_altmode(struct typec_partner *partner,
Signature · 1 line
2.30.0.365.g02bc693789-goog
maintainer Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] usb: typec: Add typec_partner_set_pd_revision

Quoted 5 lines · Benson Leung

The partner's PD revision may be resolved later than the port partner registration since the port partner creation may take place once Type-C detects the port has changed state, but before PD communication is completed.

Quoted 8 lines

Add a setter so that the partner's PD revision can be attached to it once it becomes available.

If the revision is set to a valid version (not 0), the setter will also refresh the partner's usb_pd flag and notify on "supports_usb_power_delivery" sysfs property as well.

Quoted 60 lines
---
 drivers/usb/typec/class.c | 30 ++++++++++++++++++++++++++++++
 include/linux/usb/typec.h |  1 +
 2 files changed, 31 insertions(+)
drivers/usb/typec/class.c +30 -0
index b5241f4756c2..b6ceab3dc16b 100644
@@ -748,6 +748,36 @@ int typec_partner_set_identity(struct typec_partner *partner)
 }
 EXPORT_SYMBOL_GPL(typec_partner_set_identity);
 
+/**
+ * typec_partner_set_pd_revision - Set the PD revision supported by the partner
+ * @partner: The partner to be updated.
+ * @pd_revision:  USB Power Delivery Specification Revision supported by partner
+ *
+ * This routine is used to report that the PD revision of the port partner has
+ * become available.
+ *
+ * Returns 0 on success or negative error number on failure.
+ */
+int typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision)
+{
+	int ret;
+
+	if (partner->pd_revision == pd_revision)
+		return 0;
+
+	partner->pd_revision = pd_revision;
+	sysfs_notify(&partner->dev.kobj, NULL, "usb_power_delivery_revision");
+	if (pd_revision != 0 && !partner->usb_pd) {
+		partner->usb_pd = 1;
+		sysfs_notify(&partner->dev.kobj, NULL,
+			     "supports_usb_power_delivery");
+	}
+	kobject_uevent(&partner->dev.kobj, KOBJ_CHANGE);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(typec_partner_set_pd_revision);
+
 /**
  * typec_partner_set_num_altmodes - Set the number of available partner altmodes
  * @partner: The partner to be updated.
include/linux/usb/typec.h +1 -0
index 42c6b7c07a99..4946eca742d5 100644
@@ -126,6 +126,7 @@ struct typec_altmode_desc {
 	enum typec_port_data	roles;
 };
 
+int typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision);
 int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmodes);
 struct typec_altmode
 *typec_partner_register_altmode(struct typec_partner *partner,
Signature · 1 line
2.30.0.365.g02bc693789-goog

thanks,

Signature · 1 line
heikki
author maintainer
#7 lore raw

PATCH 4/6 platform/chrome: cros_ec_typec: Report SOP' PD revision from status

In reply to Benson Leung

cros_typec_handle_sop_prime_disc now takes the PD revision provided by the EC_CMD_TYPEC_STATUS command response for the SOP'.

Attach the properly formatted pd_revision to the cable desc before registering the cable.

---
 drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +7 -2
index e724a5eaef1c..30600e9454e1 100644
@@ -748,7 +748,7 @@ static void cros_typec_parse_pd_identity(struct usb_pd_identity *id,
 		id->vdo[i - 3] = disc->discovery_vdo[i];
 }
 
-static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num)
+static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision)
 {
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct ec_response_typec_discovery *disc = port->disc_data;
@@ -794,6 +794,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
 	}
 
 	c_desc.identity = &port->c_identity;
+	c_desc.pd_revision = pd_revision;
 
 	port->cable = typec_register_cable(port->port, &c_desc);
 	if (IS_ERR(port->cable)) {
@@ -893,7 +894,11 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 
 	if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
 	    !typec->ports[port_num]->sop_prime_disc_done) {
-		ret = cros_typec_handle_sop_prime_disc(typec, port_num);
+		u16 sop_prime_revision;
+
+		/* Convert BCD to the format preferred by the TypeC framework */
+		sop_prime_revision = (le16_to_cpu(resp.sop_prime_revision) & 0xff00) >> 4;
+		ret = cros_typec_handle_sop_prime_disc(typec, port_num, sop_prime_revision);
 		if (ret < 0)
 			dev_err(typec->dev, "Couldn't parse SOP' Disc data, port: %d\n", port_num);
 		else
Signature · 1 line
2.30.0.365.g02bc693789-goog
maintainer Acked-by on v1 4/6
#8 lore raw

Re: [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status

Quoted 7 lines · Benson Leung

cros_typec_handle_sop_prime_disc now takes the PD revision provided by the EC_CMD_TYPEC_STATUS command response for the SOP'.

Attach the properly formatted pd_revision to the cable desc before registering the cable.

Quoted 40 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +7 -2
index e724a5eaef1c..30600e9454e1 100644
@@ -748,7 +748,7 @@ static void cros_typec_parse_pd_identity(struct usb_pd_identity *id,
 		id->vdo[i - 3] = disc->discovery_vdo[i];
 }
 
-static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num)
+static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision)
 {
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct ec_response_typec_discovery *disc = port->disc_data;
@@ -794,6 +794,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
 	}
 
 	c_desc.identity = &port->c_identity;
+	c_desc.pd_revision = pd_revision;
 
 	port->cable = typec_register_cable(port->port, &c_desc);
 	if (IS_ERR(port->cable)) {
@@ -893,7 +894,11 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 
 	if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
 	    !typec->ports[port_num]->sop_prime_disc_done) {
-		ret = cros_typec_handle_sop_prime_disc(typec, port_num);
+		u16 sop_prime_revision;
+
+		/* Convert BCD to the format preferred by the TypeC framework */
+		sop_prime_revision = (le16_to_cpu(resp.sop_prime_revision) & 0xff00) >> 4;
+		ret = cros_typec_handle_sop_prime_disc(typec, port_num, sop_prime_revision);
 		if (ret < 0)
 			dev_err(typec->dev, "Couldn't parse SOP' Disc data, port: %d\n", port_num);
 		else
Signature · 1 line
2.30.0.365.g02bc693789-goog

thanks,

Signature · 1 line
heikki
Acked-by on v1 4/6
#9 lore raw

Re: [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status

In reply to Benson Leung

Hi Benson,

Quoted 7 lines · Benson Leung

cros_typec_handle_sop_prime_disc now takes the PD revision provided by the EC_CMD_TYPEC_STATUS command response for the SOP'.

Attach the properly formatted pd_revision to the cable desc before registering the cable.

Quoted 39 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +7 -2
index e724a5eaef1c..30600e9454e1 100644
@@ -748,7 +748,7 @@ static void cros_typec_parse_pd_identity(struct usb_pd_identity *id,
 		id->vdo[i - 3] = disc->discovery_vdo[i];
 }
 
-static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num)
+static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision)
 {
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct ec_response_typec_discovery *disc = port->disc_data;
@@ -794,6 +794,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
 	}
 
 	c_desc.identity = &port->c_identity;
+	c_desc.pd_revision = pd_revision;
 
 	port->cable = typec_register_cable(port->port, &c_desc);
 	if (IS_ERR(port->cable)) {
@@ -893,7 +894,11 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 
 	if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
 	    !typec->ports[port_num]->sop_prime_disc_done) {
-		ret = cros_typec_handle_sop_prime_disc(typec, port_num);
+		u16 sop_prime_revision;
+
+		/* Convert BCD to the format preferred by the TypeC framework */
+		sop_prime_revision = (le16_to_cpu(resp.sop_prime_revision) & 0xff00) >> 4;
+		ret = cros_typec_handle_sop_prime_disc(typec, port_num, sop_prime_revision);
 		if (ret < 0)
 			dev_err(typec->dev, "Couldn't parse SOP' Disc data, port: %d\n", port_num);
 		else
Reviewed-by on v1 4/6
#10 lore raw

Re: [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status

In reply to Benson Leung

Hi Benson,

Quoted 8 lines · Benson Leung

cros_typec_handle_sop_prime_disc now takes the PD revision provided by the EC_CMD_TYPEC_STATUS command response for the SOP'.

Attach the properly formatted pd_revision to the cable desc before registering the cable.

Quoted 41 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +7 -3
index e724a5eaef1c..30600e9454e1 100644
@@ -748,7 +748,7 @@ static void cros_typec_parse_pd_identity(struct usb_pd_identity *id,
                id->vdo[i - 3] = disc->discovery_vdo[i];
 }
 
-static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num)
+static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision)
 {
        struct cros_typec_port *port = typec->ports[port_num];
        struct ec_response_typec_discovery *disc = port->disc_data;
@@ -794,6 +794,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
        }
 
        c_desc.identity = &port->c_identity;
+       c_desc.pd_revision = pd_revision;
 
        port->cable = typec_register_cable(port->port, &c_desc);
        if (IS_ERR(port->cable)) {
@@ -893,7 +894,11 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 
        if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
            !typec->ports[port_num]->sop_prime_disc_done) {
-               ret = cros_typec_handle_sop_prime_disc(typec, port_num);
+               u16 sop_prime_revision;
+
+               /* Convert BCD to the format preferred by the TypeC framework */
+               sop_prime_revision = (le16_to_cpu(resp.sop_prime_revision) & 0xff00) >> 4;
+               ret = cros_typec_handle_sop_prime_disc(typec, port_num, sop_prime_revision);
                if (ret < 0)
                        dev_err(typec->dev, "Couldn't parse SOP' Disc data, port: %d\n", port_num);
                else
--

2.30.0.365.g02bc693789-goog

author maintainer
#11 lore raw

PATCH 5/6 platform/chrome: cros_ec_typec: Set Partner PD revision from status

In reply to Benson Leung

Status provides sop_revision. Process it, and set it using the new setter in the typec class.

---
 drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +12 -2
index 30600e9454e1..6bc6fafd54a4 100644
@@ -824,7 +824,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
 	return ret;
 }
 
-static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num)
+static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision)
 {
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct ec_response_typec_discovery *sop_disc = port->disc_data;
@@ -842,6 +842,12 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu
 		goto disc_exit;
 	}
 
+	ret = typec_partner_set_pd_revision(port->partner, pd_revision);
+	if (ret < 0) {
+		dev_err(typec->dev, "Failed to update partner PD revision, port: %d\n", port_num);
+		goto disc_exit;
+	}
+
 	memset(sop_disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
 	ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
 				    sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
@@ -885,7 +891,11 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 
 	/* Handle any events appropriately. */
 	if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE && !typec->ports[port_num]->sop_disc_done) {
-		ret = cros_typec_handle_sop_disc(typec, port_num);
+		u16 sop_revision;
+
+		/* Convert BCD to the format preferred by the TypeC framework */
+		sop_revision = (le16_to_cpu(resp.sop_revision) & 0xff00) >> 4;
+		ret = cros_typec_handle_sop_disc(typec, port_num, sop_revision);
 		if (ret < 0)
 			dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
 		else
Signature · 1 line
2.30.0.365.g02bc693789-goog
maintainer Acked-by on v1 5/6
#12 lore raw

Re: [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner PD revision from status

Quoted 4 lines · Benson Leung

Status provides sop_revision. Process it, and set it using the new setter in the typec class.

Quoted 45 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +12 -2
index 30600e9454e1..6bc6fafd54a4 100644
@@ -824,7 +824,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
 	return ret;
 }
 
-static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num)
+static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision)
 {
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct ec_response_typec_discovery *sop_disc = port->disc_data;
@@ -842,6 +842,12 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu
 		goto disc_exit;
 	}
 
+	ret = typec_partner_set_pd_revision(port->partner, pd_revision);
+	if (ret < 0) {
+		dev_err(typec->dev, "Failed to update partner PD revision, port: %d\n", port_num);
+		goto disc_exit;
+	}
+
 	memset(sop_disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
 	ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
 				    sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
@@ -885,7 +891,11 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 
 	/* Handle any events appropriately. */
 	if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE && !typec->ports[port_num]->sop_disc_done) {
-		ret = cros_typec_handle_sop_disc(typec, port_num);
+		u16 sop_revision;
+
+		/* Convert BCD to the format preferred by the TypeC framework */
+		sop_revision = (le16_to_cpu(resp.sop_revision) & 0xff00) >> 4;
+		ret = cros_typec_handle_sop_disc(typec, port_num, sop_revision);
 		if (ret < 0)
 			dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
 		else
Signature · 1 line
2.30.0.365.g02bc693789-goog

thanks,

Signature · 1 line
heikki
Acked-by on v1 5/6
#13 lore raw

Re: [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner PD revision from status

In reply to Benson Leung

Hi Benson,

Quoted 4 lines · Benson Leung

Status provides sop_revision. Process it, and set it using the new setter in the typec class.

Quoted 44 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +12 -2
index 30600e9454e1..6bc6fafd54a4 100644
@@ -824,7 +824,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
 	return ret;
 }
 
-static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num)
+static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision)
 {
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct ec_response_typec_discovery *sop_disc = port->disc_data;
@@ -842,6 +842,12 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu
 		goto disc_exit;
 	}
 
+	ret = typec_partner_set_pd_revision(port->partner, pd_revision);
+	if (ret < 0) {
+		dev_err(typec->dev, "Failed to update partner PD revision, port: %d\n", port_num);
+		goto disc_exit;
+	}
+
 	memset(sop_disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
 	ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
 				    sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
@@ -885,7 +891,11 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 
 	/* Handle any events appropriately. */
 	if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE && !typec->ports[port_num]->sop_disc_done) {
-		ret = cros_typec_handle_sop_disc(typec, port_num);
+		u16 sop_revision;
+
+		/* Convert BCD to the format preferred by the TypeC framework */
+		sop_revision = (le16_to_cpu(resp.sop_revision) & 0xff00) >> 4;
+		ret = cros_typec_handle_sop_disc(typec, port_num, sop_revision);
 		if (ret < 0)
 			dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
 		else
Reviewed-by on v1 5/6
#14 lore raw

Re: [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner PD revision from status

In reply to Benson Leung
Quoted 5 lines · Benson Leung

Status provides sop_revision. Process it, and set it using the new setter in the typec class.

Quoted 46 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +12 -3
index 30600e9454e1..6bc6fafd54a4 100644
@@ -824,7 +824,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
        return ret;
 }
 
-static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num)
+static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision)
 {
        struct cros_typec_port *port = typec->ports[port_num];
        struct ec_response_typec_discovery *sop_disc = port->disc_data;
@@ -842,6 +842,12 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu
                goto disc_exit;
        }
 
+       ret = typec_partner_set_pd_revision(port->partner, pd_revision);
+       if (ret < 0) {
+               dev_err(typec->dev, "Failed to update partner PD revision, port: %d\n", port_num);
+               goto disc_exit;
+       }
+
        memset(sop_disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
        ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
                                    sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
@@ -885,7 +891,11 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 
        /* Handle any events appropriately. */
        if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE && !typec->ports[port_num]->sop_disc_done) {
-               ret = cros_typec_handle_sop_disc(typec, port_num);
+               u16 sop_revision;
+
+               /* Convert BCD to the format preferred by the TypeC framework */
+               sop_revision = (le16_to_cpu(resp.sop_revision) & 0xff00) >> 4;
+               ret = cros_typec_handle_sop_disc(typec, port_num, sop_revision);
                if (ret < 0)
                        dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
                else
--

2.30.0.365.g02bc693789-goog

author maintainer
#15 lore raw

PATCH 6/6 platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected

In reply to Benson Leung

When SOP Discovery is done, set the opmode to PD if status indicates SOP is connected.

SOP connected indicates a PD contract is in place, and is a solid indication we have transitioned to PD power negotiation, either as source or sink.

---
 drivers/platform/chrome/cros_ec_typec.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/chrome/cros_ec_typec.c +3 -0
index 6bc6fafd54a4..a7778258d0a0 100644
@@ -900,6 +900,9 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 			dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
 		else
 			typec->ports[port_num]->sop_disc_done = true;
+
+		if (resp.sop_connected)
+			typec_set_pwr_opmode(typec->ports[port_num]->port, TYPEC_PWR_MODE_PD);
 	}
 
 	if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
Signature · 1 line
2.30.0.365.g02bc693789-goog
maintainer Acked-by on v1 6/6
#16 lore raw

Re: [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected

Quoted 8 lines · Benson Leung

When SOP Discovery is done, set the opmode to PD if status indicates SOP is connected.

SOP connected indicates a PD contract is in place, and is a solid indication we have transitioned to PD power negotiation, either as source or sink.

FWIW:

Quoted 20 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/chrome/cros_ec_typec.c +3 -0
index 6bc6fafd54a4..a7778258d0a0 100644
@@ -900,6 +900,9 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 			dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
 		else
 			typec->ports[port_num]->sop_disc_done = true;
+
+		if (resp.sop_connected)
+			typec_set_pwr_opmode(typec->ports[port_num]->port, TYPEC_PWR_MODE_PD);
 	}
 
 	if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
Signature · 1 line
2.30.0.365.g02bc693789-goog

thanks,

Signature · 1 line
heikki
Acked-by on v1 6/6
#17 lore raw

Re: [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected

In reply to Benson Leung

Hi Benson,

Quoted 8 lines · Benson Leung

When SOP Discovery is done, set the opmode to PD if status indicates SOP is connected.

SOP connected indicates a PD contract is in place, and is a solid indication we have transitioned to PD power negotiation, either as source or sink.

Quoted 19 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/chrome/cros_ec_typec.c +3 -0
index 6bc6fafd54a4..a7778258d0a0 100644
@@ -900,6 +900,9 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
 			dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
 		else
 			typec->ports[port_num]->sop_disc_done = true;
+
+		if (resp.sop_connected)
+			typec_set_pwr_opmode(typec->ports[port_num]->port, TYPEC_PWR_MODE_PD);
 	}
 
 	if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
Reviewed-by on v1 6/6
#18 lore raw

Re: [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected

In reply to Benson Leung
Quoted 9 lines · Benson Leung

When SOP Discovery is done, set the opmode to PD if status indicates SOP is connected.

SOP connected indicates a PD contract is in place, and is a solid indication we have transitioned to PD power negotiation, either as source or sink.

Quoted 21 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/chrome/cros_ec_typec.c +3 -1
index 6bc6fafd54a4..a7778258d0a0 100644
@@ -900,6 +900,9 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
                        dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num);
                else
                        typec->ports[port_num]->sop_disc_done = true;
+
+               if (resp.sop_connected)
+                       typec_set_pwr_opmode(typec->ports[port_num]->port, TYPEC_PWR_MODE_PD);
        }
 
        if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE &&
--

2.30.0.365.g02bc693789-goog

maintainer
#19 lore raw
In reply to Benson Leung
Quoted 6 lines · Benson Leung

USB Power Delivery has a 3 entity handshake (port, cable, partner), and as of USB PD R3.0, each entity may independently support either Revision 2 or Revision 3 signaling and protocol. In order for userspace and the kernel to properly process the data objects received from a particular SOP*, we must know to which revision of the spec each conforms.

Quoted 6 lines

This series adds individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/typec.

I provide as a first implementation of this, platform/chrome's cros_ec_typec driver, whose underlying status messages convey the SOP and SOP' revisions already.

I've taken the first 3 patches in my tree now, but the last 3 (for the chrome_ec_typec.c driver), they do not apply at all.

thanks,

greg k-h

#20 lore raw

Hi Greg,

Quoted 10 lines · Greg KH
Quoted 9 lines · Benson Leung

USB Power Delivery has a 3 entity handshake (port, cable, partner), and as of USB PD R3.0, each entity may independently support either Revision 2 or Revision 3 signaling and protocol. In order for userspace and the kernel to properly process the data objects received from a particular SOP*, we must know to which revision of the spec each conforms.

This series adds individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/typec.

Quoted 7 lines
Quoted 3 lines

I provide as a first implementation of this, platform/chrome's cros_ec_typec driver, whose underlying status messages convey the SOP and SOP' revisions already.

I've taken the first 3 patches in my tree now, but the last 3 (for the chrome_ec_typec.c driver), they do not apply at all.

Ah, that's because we have some other changes for the cros_ec_typec.c driver already in platform/chrome for our 5.12 branch.

For 5.12, the changes for cros_ec_typec driver is pretty well contained, although there is some dependence on typec subsystem changes now.

If I send you a pull request containing all of the changes for this driver we have already merged, plus these last three that depend on both of our trees would you merge it through usb for 5.12?

Thanks,
Benson

Quoted 3 lines

thanks,

greg k-h

Signature · 7 lines
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]
maintainer
#21 lore raw
Quoted 24 lines · Benson Leung

Hi Greg,

Quoted 10 lines · Greg KH
Quoted 9 lines · Benson Leung

USB Power Delivery has a 3 entity handshake (port, cable, partner), and as of USB PD R3.0, each entity may independently support either Revision 2 or Revision 3 signaling and protocol. In order for userspace and the kernel to properly process the data objects received from a particular SOP*, we must know to which revision of the spec each conforms.

This series adds individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/typec.

Quoted 7 lines
Quoted 3 lines

I provide as a first implementation of this, platform/chrome's cros_ec_typec driver, whose underlying status messages convey the SOP and SOP' revisions already.

I've taken the first 3 patches in my tree now, but the last 3 (for the chrome_ec_typec.c driver), they do not apply at all.

Ah, that's because we have some other changes for the cros_ec_typec.c driver already in platform/chrome for our 5.12 branch.

Quoted 6 lines

For 5.12, the changes for cros_ec_typec driver is pretty well contained, although there is some dependence on typec subsystem changes now.

If I send you a pull request containing all of the changes for this driver we have already merged, plus these last three that depend on both of our trees would you merge it through usb for 5.12?

If the subsystem maintainer says it is ok, yes, I will be glad to take a stable git tag to pull from into my usb-next branch.

thanks,

greg k-h

#22 lore raw
In reply to Benson Leung

Hi all,

Quoted 16 lines · Benson Leung

USB Power Delivery has a 3 entity handshake (port, cable, partner), and as of USB PD R3.0, each entity may independently support either Revision 2 or Revision 3 signaling and protocol. In order for userspace and the kernel to properly process the data objects received from a particular SOP*, we must know to which revision of the spec each conforms.

This series adds individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/typec.

I provide as a first implementation of this, platform/chrome's cros_ec_typec driver, whose underlying status messages convey the SOP and SOP' revisions already.

Thanks,
Benson

Quoted 8 lines

Benson Leung (6):
usb: typec: Standardize PD Revision format with Type-C Revision
usb: typec: Provide PD Specification Revision for cable and partner
usb: typec: Add typec_partner_set_pd_revision platform/chrome: cros_ec_typec: Report SOP' PD revision from status platform/chrome: cros_ec_typec: Set Partner PD revision from status platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected

I acked the above chrome/platform patches in case Greg wants to pick up the full series through his usb tree, I think is what makes more sense. They look good to me from the chrome/platform side.

Thanks,
Enric

Quoted 6 lines
 Documentation/ABI/testing/sysfs-class-typec | 20 ++++++-
 drivers/platform/chrome/cros_ec_typec.c     | 26 +++++++--
 drivers/usb/typec/class.c                   | 59 +++++++++++++++++++--
 include/linux/usb/typec.h                   | 11 ++++
 4 files changed, 108 insertions(+), 8 deletions(-)
#23 lore raw

Hi all,

Quoted 28 lines · Enric Balletbo i Serra

Hi all,

Quoted 16 lines · Benson Leung

USB Power Delivery has a 3 entity handshake (port, cable, partner), and as of USB PD R3.0, each entity may independently support either Revision 2 or Revision 3 signaling and protocol. In order for userspace and the kernel to properly process the data objects received from a particular SOP*, we must know to which revision of the spec each conforms.

This series adds individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/typec.

I provide as a first implementation of this, platform/chrome's cros_ec_typec driver, whose underlying status messages convey the SOP and SOP' revisions already.

Thanks,
Benson

Quoted 8 lines

Benson Leung (6):
usb: typec: Standardize PD Revision format with Type-C Revision
usb: typec: Provide PD Specification Revision for cable and partner
usb: typec: Add typec_partner_set_pd_revision platform/chrome: cros_ec_typec: Report SOP' PD revision from status platform/chrome: cros_ec_typec: Set Partner PD revision from status platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected

Quoted 4 lines

I acked the above chrome/platform patches in case Greg wants to pick up the full series through his usb tree, I think is what makes more sense. They look good to me from the chrome/platform side.

Sorry, just noticed that the platform/chrome patches depends on some patches that we have already queued for 5.12. So we will pick up these patches and take care to not merge before the specific usb type-c bits. So forget about the above.

Thanks,
Enric

Quoted 9 lines

Thanks,
Enric

Quoted 6 lines
 Documentation/ABI/testing/sysfs-class-typec | 20 ++++++-
 drivers/platform/chrome/cros_ec_typec.c     | 26 +++++++--
 drivers/usb/typec/class.c                   | 59 +++++++++++++++++++--
 include/linux/usb/typec.h                   | 11 ++++
 4 files changed, 108 insertions(+), 8 deletions(-)