linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers
@ 2021-01-29  6:14 Benson Leung
  2021-01-29  6:14 ` [PATCH 1/6] usb: typec: Standardize PD Revision format with Type-C Revision Benson Leung
                   ` (7 more replies)
  0 siblings, 8 replies; 24+ messages in thread
From: Benson Leung @ 2021-01-29  6:14 UTC (permalink / raw)
  To: heikki.krogerus, enric.balletbo, pmalani, gregkh, linux-usb,
	linux-kernel
  Cc: groeck, bleung, bleung

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(-)

-- 
2.30.0.365.g02bc693789-goog


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

* [PATCH 1/6] usb: typec: Standardize PD Revision format with Type-C Revision
  2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
@ 2021-01-29  6:14 ` Benson Leung
  2021-02-01 12:38   ` Heikki Krogerus
  2021-01-29  6:14 ` [PATCH 2/6] usb: typec: Provide PD Specification Revision for cable and partner Benson Leung
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 24+ messages in thread
From: Benson Leung @ 2021-01-29  6:14 UTC (permalink / raw)
  To: heikki.krogerus, enric.balletbo, pmalani, gregkh, linux-usb,
	linux-kernel
  Cc: groeck, bleung, bleung

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

Signed-off-by: Benson Leung <bleung@chromium.org>
---
 Documentation/ABI/testing/sysfs-class-typec | 7 ++++++-
 drivers/usb/typec/class.c                   | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
index 8eab41e79ce6..b61480535fdc 100644
--- a/Documentation/ABI/testing/sysfs-class-typec
+++ b/Documentation/ABI/testing/sysfs-class-typec
@@ -105,7 +105,12 @@ Date:		April 2017
 Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
 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
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 8f77669f9cf4..4f60ee7ba76a 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -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);
 
-- 
2.30.0.365.g02bc693789-goog


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

* [PATCH 2/6] usb: typec: Provide PD Specification Revision for cable and partner
  2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
  2021-01-29  6:14 ` [PATCH 1/6] usb: typec: Standardize PD Revision format with Type-C Revision Benson Leung
@ 2021-01-29  6:14 ` Benson Leung
  2021-02-01 12:40   ` Heikki Krogerus
  2021-01-29  6:14 ` [PATCH 3/6] usb: typec: Add typec_partner_set_pd_revision Benson Leung
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 24+ messages in thread
From: Benson Leung @ 2021-01-29  6:14 UTC (permalink / raw)
  To: heikki.krogerus, enric.balletbo, pmalani, gregkh, linux-usb,
	linux-kernel
  Cc: groeck, bleung, bleung

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.

Signed-off-by: Benson Leung <bleung@chromium.org>
---
 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(-)

diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
index b61480535fdc..40122d915ae1 100644
--- a/Documentation/ABI/testing/sysfs-class-typec
+++ b/Documentation/ABI/testing/sysfs-class-typec
@@ -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 <bleung@chromium.org>
+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 <heikki.krogerus@linux.intel.com>
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 4f60ee7ba76a..b5241f4756c2 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -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,
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 54475323f83b..42c6b7c07a99 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -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" */
 };
 
 /**
-- 
2.30.0.365.g02bc693789-goog


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

* [PATCH 3/6] usb: typec: Add typec_partner_set_pd_revision
  2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
  2021-01-29  6:14 ` [PATCH 1/6] usb: typec: Standardize PD Revision format with Type-C Revision Benson Leung
  2021-01-29  6:14 ` [PATCH 2/6] usb: typec: Provide PD Specification Revision for cable and partner Benson Leung
@ 2021-01-29  6:14 ` Benson Leung
  2021-02-01 12:41   ` Heikki Krogerus
  2021-01-29  6:14 ` [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status Benson Leung
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 24+ messages in thread
From: Benson Leung @ 2021-01-29  6:14 UTC (permalink / raw)
  To: heikki.krogerus, enric.balletbo, pmalani, gregkh, linux-usb,
	linux-kernel
  Cc: groeck, bleung, bleung

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.

Signed-off-by: Benson Leung <bleung@chromium.org>
---
 drivers/usb/typec/class.c | 30 ++++++++++++++++++++++++++++++
 include/linux/usb/typec.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index b5241f4756c2..b6ceab3dc16b 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -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.
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 42c6b7c07a99..4946eca742d5 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -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,
-- 
2.30.0.365.g02bc693789-goog


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

* [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status
  2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
                   ` (2 preceding siblings ...)
  2021-01-29  6:14 ` [PATCH 3/6] usb: typec: Add typec_partner_set_pd_revision Benson Leung
@ 2021-01-29  6:14 ` Benson Leung
  2021-02-01 12:51   ` Heikki Krogerus
                     ` (2 more replies)
  2021-01-29  6:14 ` [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner " Benson Leung
                   ` (3 subsequent siblings)
  7 siblings, 3 replies; 24+ messages in thread
From: Benson Leung @ 2021-01-29  6:14 UTC (permalink / raw)
  To: heikki.krogerus, enric.balletbo, pmalani, gregkh, linux-usb,
	linux-kernel
  Cc: groeck, bleung, bleung

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.

Signed-off-by: Benson Leung <bleung@chromium.org>
---
 drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index e724a5eaef1c..30600e9454e1 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -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


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

* [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner PD revision from status
  2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
                   ` (3 preceding siblings ...)
  2021-01-29  6:14 ` [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status Benson Leung
@ 2021-01-29  6:14 ` Benson Leung
  2021-02-01 12:52   ` Heikki Krogerus
                     ` (2 more replies)
  2021-01-29  6:14 ` [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected Benson Leung
                   ` (2 subsequent siblings)
  7 siblings, 3 replies; 24+ messages in thread
From: Benson Leung @ 2021-01-29  6:14 UTC (permalink / raw)
  To: heikki.krogerus, enric.balletbo, pmalani, gregkh, linux-usb,
	linux-kernel
  Cc: groeck, bleung, bleung

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

Signed-off-by: Benson Leung <bleung@chromium.org>
---
 drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 30600e9454e1..6bc6fafd54a4 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -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


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

* [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected
  2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
                   ` (4 preceding siblings ...)
  2021-01-29  6:14 ` [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner " Benson Leung
@ 2021-01-29  6:14 ` Benson Leung
  2021-02-01 12:55   ` Heikki Krogerus
                     ` (2 more replies)
  2021-02-01 14:32 ` [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Greg KH
  2021-02-01 14:37 ` Enric Balletbo i Serra
  7 siblings, 3 replies; 24+ messages in thread
From: Benson Leung @ 2021-01-29  6:14 UTC (permalink / raw)
  To: heikki.krogerus, enric.balletbo, pmalani, gregkh, linux-usb,
	linux-kernel
  Cc: groeck, bleung, bleung

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.

Signed-off-by: Benson Leung <bleung@chromium.org>
---
 drivers/platform/chrome/cros_ec_typec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 6bc6fafd54a4..a7778258d0a0 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -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


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

* Re: [PATCH 1/6] usb: typec: Standardize PD Revision format with Type-C Revision
  2021-01-29  6:14 ` [PATCH 1/6] usb: typec: Standardize PD Revision format with Type-C Revision Benson Leung
@ 2021-02-01 12:38   ` Heikki Krogerus
  0 siblings, 0 replies; 24+ messages in thread
From: Heikki Krogerus @ 2021-02-01 12:38 UTC (permalink / raw)
  To: Benson Leung
  Cc: enric.balletbo, pmalani, gregkh, linux-usb, linux-kernel, groeck, bleung

On Thu, Jan 28, 2021 at 10:14:01PM -0800, Benson Leung wrote:
> 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
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

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

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  Documentation/ABI/testing/sysfs-class-typec | 7 ++++++-
>  drivers/usb/typec/class.c                   | 3 ++-
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
> index 8eab41e79ce6..b61480535fdc 100644
> --- a/Documentation/ABI/testing/sysfs-class-typec
> +++ b/Documentation/ABI/testing/sysfs-class-typec
> @@ -105,7 +105,12 @@ Date:		April 2017
>  Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
>  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
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 8f77669f9cf4..4f60ee7ba76a 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -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);
>  
> -- 
> 2.30.0.365.g02bc693789-goog

thanks,

-- 
heikki

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

* Re: [PATCH 2/6] usb: typec: Provide PD Specification Revision for cable and partner
  2021-01-29  6:14 ` [PATCH 2/6] usb: typec: Provide PD Specification Revision for cable and partner Benson Leung
@ 2021-02-01 12:40   ` Heikki Krogerus
  0 siblings, 0 replies; 24+ messages in thread
From: Heikki Krogerus @ 2021-02-01 12:40 UTC (permalink / raw)
  To: Benson Leung
  Cc: enric.balletbo, pmalani, gregkh, linux-usb, linux-kernel, groeck, bleung

On Thu, Jan 28, 2021 at 10:14:02PM -0800, Benson Leung wrote:
> 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.
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  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(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
> index b61480535fdc..40122d915ae1 100644
> --- a/Documentation/ABI/testing/sysfs-class-typec
> +++ b/Documentation/ABI/testing/sysfs-class-typec
> @@ -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 <bleung@chromium.org>
> +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 <heikki.krogerus@linux.intel.com>
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 4f60ee7ba76a..b5241f4756c2 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -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,
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index 54475323f83b..42c6b7c07a99 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -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" */
>  };
>  
>  /**
> -- 
> 2.30.0.365.g02bc693789-goog

thanks,

-- 
heikki

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

* Re: [PATCH 3/6] usb: typec: Add typec_partner_set_pd_revision
  2021-01-29  6:14 ` [PATCH 3/6] usb: typec: Add typec_partner_set_pd_revision Benson Leung
@ 2021-02-01 12:41   ` Heikki Krogerus
  0 siblings, 0 replies; 24+ messages in thread
From: Heikki Krogerus @ 2021-02-01 12:41 UTC (permalink / raw)
  To: Benson Leung
  Cc: enric.balletbo, pmalani, gregkh, linux-usb, linux-kernel, groeck, bleung

On Thu, Jan 28, 2021 at 10:14:03PM -0800, Benson Leung wrote:
> 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.
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/class.c | 30 ++++++++++++++++++++++++++++++
>  include/linux/usb/typec.h |  1 +
>  2 files changed, 31 insertions(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index b5241f4756c2..b6ceab3dc16b 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -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.
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index 42c6b7c07a99..4946eca742d5 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -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,
> -- 
> 2.30.0.365.g02bc693789-goog

thanks,

-- 
heikki

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

* Re: [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status
  2021-01-29  6:14 ` [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status Benson Leung
@ 2021-02-01 12:51   ` Heikki Krogerus
  2021-02-01 14:33   ` Enric Balletbo i Serra
  2021-02-01 18:12   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Heikki Krogerus @ 2021-02-01 12:51 UTC (permalink / raw)
  To: Benson Leung
  Cc: enric.balletbo, pmalani, gregkh, linux-usb, linux-kernel, groeck, bleung

On Thu, Jan 28, 2021 at 10:14:04PM -0800, Benson Leung wrote:
> 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.
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index e724a5eaef1c..30600e9454e1 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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

thanks,

-- 
heikki

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

* Re: [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner PD revision from status
  2021-01-29  6:14 ` [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner " Benson Leung
@ 2021-02-01 12:52   ` Heikki Krogerus
  2021-02-01 14:33   ` Enric Balletbo i Serra
  2021-02-01 18:13   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Heikki Krogerus @ 2021-02-01 12:52 UTC (permalink / raw)
  To: Benson Leung
  Cc: enric.balletbo, pmalani, gregkh, linux-usb, linux-kernel, groeck, bleung

On Thu, Jan 28, 2021 at 10:14:05PM -0800, Benson Leung wrote:
> Status provides sop_revision. Process it, and set it using the new
> setter in the typec class.
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 30600e9454e1..6bc6fafd54a4 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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

thanks,

-- 
heikki

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

* Re: [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected
  2021-01-29  6:14 ` [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected Benson Leung
@ 2021-02-01 12:55   ` Heikki Krogerus
  2021-02-01 14:33   ` Enric Balletbo i Serra
  2021-02-01 18:15   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Heikki Krogerus @ 2021-02-01 12:55 UTC (permalink / raw)
  To: Benson Leung
  Cc: enric.balletbo, pmalani, gregkh, linux-usb, linux-kernel, groeck, bleung

On Thu, Jan 28, 2021 at 10:14:06PM -0800, Benson Leung wrote:
> 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.
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

FWIW:

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 6bc6fafd54a4..a7778258d0a0 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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

thanks,

-- 
heikki

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

* Re: [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers
  2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
                   ` (5 preceding siblings ...)
  2021-01-29  6:14 ` [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected Benson Leung
@ 2021-02-01 14:32 ` Greg KH
  2021-02-02  7:04   ` Benson Leung
  2021-02-01 14:37 ` Enric Balletbo i Serra
  7 siblings, 1 reply; 24+ messages in thread
From: Greg KH @ 2021-02-01 14:32 UTC (permalink / raw)
  To: Benson Leung
  Cc: heikki.krogerus, enric.balletbo, pmalani, linux-usb,
	linux-kernel, groeck, bleung

On Thu, Jan 28, 2021 at 10:14:00PM -0800, Benson Leung wrote:
> 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.

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

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

* Re: [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status
  2021-01-29  6:14 ` [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status Benson Leung
  2021-02-01 12:51   ` Heikki Krogerus
@ 2021-02-01 14:33   ` Enric Balletbo i Serra
  2021-02-01 18:12   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Enric Balletbo i Serra @ 2021-02-01 14:33 UTC (permalink / raw)
  To: Benson Leung, heikki.krogerus, pmalani, gregkh, linux-usb, linux-kernel
  Cc: groeck, bleung

Hi Benson,

On 29/1/21 7:14, Benson Leung wrote:
> 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.
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index e724a5eaef1c..30600e9454e1 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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
> 

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

* Re: [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner PD revision from status
  2021-01-29  6:14 ` [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner " Benson Leung
  2021-02-01 12:52   ` Heikki Krogerus
@ 2021-02-01 14:33   ` Enric Balletbo i Serra
  2021-02-01 18:13   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Enric Balletbo i Serra @ 2021-02-01 14:33 UTC (permalink / raw)
  To: Benson Leung, heikki.krogerus, pmalani, gregkh, linux-usb, linux-kernel
  Cc: groeck, bleung

Hi Benson,

On 29/1/21 7:14, Benson Leung wrote:
> Status provides sop_revision. Process it, and set it using the new
> setter in the typec class.
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 30600e9454e1..6bc6fafd54a4 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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
> 

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

* Re: [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected
  2021-01-29  6:14 ` [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected Benson Leung
  2021-02-01 12:55   ` Heikki Krogerus
@ 2021-02-01 14:33   ` Enric Balletbo i Serra
  2021-02-01 18:15   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Enric Balletbo i Serra @ 2021-02-01 14:33 UTC (permalink / raw)
  To: Benson Leung, heikki.krogerus, pmalani, gregkh, linux-usb, linux-kernel
  Cc: groeck, bleung

Hi Benson,

On 29/1/21 7:14, Benson Leung wrote:
> 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.
> 
> Signed-off-by: Benson Leung <bleung@chromium.org>

Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 6bc6fafd54a4..a7778258d0a0 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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 &&
> 

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

* Re: [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers
  2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
                   ` (6 preceding siblings ...)
  2021-02-01 14:32 ` [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Greg KH
@ 2021-02-01 14:37 ` Enric Balletbo i Serra
  2021-02-01 14:43   ` Enric Balletbo i Serra
  7 siblings, 1 reply; 24+ messages in thread
From: Enric Balletbo i Serra @ 2021-02-01 14:37 UTC (permalink / raw)
  To: Benson Leung, heikki.krogerus, pmalani, gregkh, linux-usb, linux-kernel
  Cc: groeck, bleung

Hi all,

On 29/1/21 7:14, Benson Leung wrote:
> 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
> 

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

>  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(-)
> 

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

* Re: [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers
  2021-02-01 14:37 ` Enric Balletbo i Serra
@ 2021-02-01 14:43   ` Enric Balletbo i Serra
  0 siblings, 0 replies; 24+ messages in thread
From: Enric Balletbo i Serra @ 2021-02-01 14:43 UTC (permalink / raw)
  To: Benson Leung, heikki.krogerus, pmalani, gregkh, linux-usb, linux-kernel
  Cc: groeck, bleung

Hi all,

On 1/2/21 15:37, Enric Balletbo i Serra wrote:
> Hi all,
> 
> On 29/1/21 7:14, Benson Leung wrote:
>> 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
>>
> 
> 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


> Thanks,
>   Enric
> 
>>  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(-)
>>

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

* Re: [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status
  2021-01-29  6:14 ` [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status Benson Leung
  2021-02-01 12:51   ` Heikki Krogerus
  2021-02-01 14:33   ` Enric Balletbo i Serra
@ 2021-02-01 18:12   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Prashant Malani @ 2021-02-01 18:12 UTC (permalink / raw)
  To: Benson Leung
  Cc: Heikki Krogerus, Enric Balletbo i Serra, Greg Kroah-Hartman,
	open list:USB NETWORKING DRIVERS, Linux Kernel Mailing List,
	Guenter Roeck, Benson Leung

Hi Benson,

On Thu, Jan 28, 2021 at 10:14 PM Benson Leung <bleung@chromium.org> wrote:
>
> 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.
>
> Signed-off-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Prashant Malani <pmalani@chromium.org>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index e724a5eaef1c..30600e9454e1 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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
>

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

* Re: [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner PD revision from status
  2021-01-29  6:14 ` [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner " Benson Leung
  2021-02-01 12:52   ` Heikki Krogerus
  2021-02-01 14:33   ` Enric Balletbo i Serra
@ 2021-02-01 18:13   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Prashant Malani @ 2021-02-01 18:13 UTC (permalink / raw)
  To: Benson Leung
  Cc: Heikki Krogerus, Enric Balletbo i Serra, Greg Kroah-Hartman,
	open list:USB NETWORKING DRIVERS, Linux Kernel Mailing List,
	Guenter Roeck, Benson Leung

On Thu, Jan 28, 2021 at 10:14 PM Benson Leung <bleung@chromium.org> wrote:
>
> Status provides sop_revision. Process it, and set it using the new
> setter in the typec class.
>
> Signed-off-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Prashant Malani <pmalani@chomium.org>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 30600e9454e1..6bc6fafd54a4 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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
>

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

* Re: [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected
  2021-01-29  6:14 ` [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected Benson Leung
  2021-02-01 12:55   ` Heikki Krogerus
  2021-02-01 14:33   ` Enric Balletbo i Serra
@ 2021-02-01 18:15   ` Prashant Malani
  2 siblings, 0 replies; 24+ messages in thread
From: Prashant Malani @ 2021-02-01 18:15 UTC (permalink / raw)
  To: Benson Leung
  Cc: Heikki Krogerus, Enric Balletbo i Serra, Greg Kroah-Hartman,
	open list:USB NETWORKING DRIVERS, Linux Kernel Mailing List,
	Guenter Roeck, Benson Leung

On Thu, Jan 28, 2021 at 10:14 PM Benson Leung <bleung@chromium.org> wrote:
>
> 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.
>
> Signed-off-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Prashant Malani <pmalani@chromium.org>

> ---
>  drivers/platform/chrome/cros_ec_typec.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 6bc6fafd54a4..a7778258d0a0 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -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
>

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

* Re: [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers
  2021-02-01 14:32 ` [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Greg KH
@ 2021-02-02  7:04   ` Benson Leung
  2021-02-02  7:32     ` Greg KH
  0 siblings, 1 reply; 24+ messages in thread
From: Benson Leung @ 2021-02-02  7:04 UTC (permalink / raw)
  To: Greg KH
  Cc: Benson Leung, heikki.krogerus, enric.balletbo, pmalani,
	linux-usb, linux-kernel, groeck

[-- Attachment #1: Type: text/plain, Size: 1643 bytes --]

Hi Greg,

On Mon, Feb 01, 2021 at 03:32:47PM +0100, Greg KH wrote:
> On Thu, Jan 28, 2021 at 10:14:00PM -0800, Benson Leung wrote:
> > 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.
> 
> 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

> thanks,
> 
> greg k-h

-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
bleung@google.com
Chromium OS Project
bleung@chromium.org

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers
  2021-02-02  7:04   ` Benson Leung
@ 2021-02-02  7:32     ` Greg KH
  0 siblings, 0 replies; 24+ messages in thread
From: Greg KH @ 2021-02-02  7:32 UTC (permalink / raw)
  To: Benson Leung
  Cc: Benson Leung, heikki.krogerus, enric.balletbo, pmalani,
	linux-usb, linux-kernel, groeck

On Mon, Feb 01, 2021 at 11:04:15PM -0800, Benson Leung wrote:
> Hi Greg,
> 
> On Mon, Feb 01, 2021 at 03:32:47PM +0100, Greg KH wrote:
> > On Thu, Jan 28, 2021 at 10:14:00PM -0800, Benson Leung wrote:
> > > 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.
> > 
> > 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?

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

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

end of thread, other threads:[~2021-02-02  7:33 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29  6:14 [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Benson Leung
2021-01-29  6:14 ` [PATCH 1/6] usb: typec: Standardize PD Revision format with Type-C Revision Benson Leung
2021-02-01 12:38   ` Heikki Krogerus
2021-01-29  6:14 ` [PATCH 2/6] usb: typec: Provide PD Specification Revision for cable and partner Benson Leung
2021-02-01 12:40   ` Heikki Krogerus
2021-01-29  6:14 ` [PATCH 3/6] usb: typec: Add typec_partner_set_pd_revision Benson Leung
2021-02-01 12:41   ` Heikki Krogerus
2021-01-29  6:14 ` [PATCH 4/6] platform/chrome: cros_ec_typec: Report SOP' PD revision from status Benson Leung
2021-02-01 12:51   ` Heikki Krogerus
2021-02-01 14:33   ` Enric Balletbo i Serra
2021-02-01 18:12   ` Prashant Malani
2021-01-29  6:14 ` [PATCH 5/6] platform/chrome: cros_ec_typec: Set Partner " Benson Leung
2021-02-01 12:52   ` Heikki Krogerus
2021-02-01 14:33   ` Enric Balletbo i Serra
2021-02-01 18:13   ` Prashant Malani
2021-01-29  6:14 ` [PATCH 6/6] platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected Benson Leung
2021-02-01 12:55   ` Heikki Krogerus
2021-02-01 14:33   ` Enric Balletbo i Serra
2021-02-01 18:15   ` Prashant Malani
2021-02-01 14:32 ` [PATCH 0/6] usb: typec: and platform/chrome: Add PD revision numbers Greg KH
2021-02-02  7:04   ` Benson Leung
2021-02-02  7:32     ` Greg KH
2021-02-01 14:37 ` Enric Balletbo i Serra
2021-02-01 14:43   ` Enric Balletbo i Serra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).