Skip to contentSkip to conversation

usb: typec: ucsi: Recover from CrOS EC sysjump

PATCH In review Jameson Thies 4 participants 8 messages Feb 4, 2025 – Feb 5, 2025

Subsystems (4)
lore
Share & tools
lore

Jameson Thies

author maintainer
#0 lore raw

cover usb: typec: ucsi: Recover from CrOS EC sysjump

An EC sysjump can break communication with the cros_ec_ucsi driver by clearing any previously enabled notifications. This updates the cros_ec_ucsi driver to monitor for PD initialization events from the EC and re-enable notifications by treating the init event as a system resume.

Jameson Thies (2):
platform/chrome: add PD_EVENT_INIT bit definition
usb: typec: ucsi: resume work after EC init

 drivers/usb/typec/ucsi/cros_ec_ucsi.c          | 17 ++++++++++++-----
 include/linux/platform_data/cros_ec_commands.h |  1 +
 2 files changed, 13 insertions(+), 5 deletions(-)

base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b

Signature · 1 line
2.48.1.362.g079036d154-goog
author maintainer
#1 lore raw

PATCH 1/2 platform/chrome: add PD_EVENT_INIT bit definition

Update cros_ec_commands.h to include a definition for PD_EVENT_INIT. On platforms supporting UCSI, this host event type is sent when the PPM initializes.

---
 include/linux/platform_data/cros_ec_commands.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/platform_data/cros_ec_commands.h +1 -0
index ecf290a0c98f..1f4e4f2b89bb 100644
@@ -5046,6 +5046,7 @@ struct ec_response_pd_status {
 #define PD_EVENT_DATA_SWAP         BIT(3)
 #define PD_EVENT_TYPEC             BIT(4)
 #define PD_EVENT_PPM               BIT(5)
+#define PD_EVENT_INIT              BIT(6)
 
 struct ec_response_host_event_status {
 	uint32_t status; /* PD MCU host event status */
Signature · 1 line
2.48.1.362.g079036d154-goog
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] platform/chrome: add PD_EVENT_INIT bit definition

Hi Jameson,

Quoted 5 lines · Jameson Thies

Update cros_ec_commands.h to include a definition for PD_EVENT_INIT. On platforms supporting UCSI, this host event type is sent when the PPM initializes.

Quoted 19 lines
---
 include/linux/platform_data/cros_ec_commands.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/platform_data/cros_ec_commands.h +1 -0
index ecf290a0c98f..1f4e4f2b89bb 100644
@@ -5046,6 +5046,7 @@ struct ec_response_pd_status {
 #define PD_EVENT_DATA_SWAP         BIT(3)
 #define PD_EVENT_TYPEC             BIT(4)
 #define PD_EVENT_PPM               BIT(5)
+#define PD_EVENT_INIT              BIT(6)
 
 struct ec_response_host_event_status {
 	uint32_t status; /* PD MCU host event status */
Signature · 1 line
2.48.1.362.g079036d154-goog
maintainer Reviewed-by
#3 lore raw

Re: [PATCH v1 1/2] platform/chrome: add PD_EVENT_INIT bit definition

Quoted 12 lines · Benson Leung

Hi Jameson,

Quoted 5 lines · Jameson Thies

Update cros_ec_commands.h to include a definition for PD_EVENT_INIT. On platforms supporting UCSI, this host event type is sent when the PPM initializes.

Quoted 19 lines
Quoted 19 lines
---
 include/linux/platform_data/cros_ec_commands.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/platform_data/cros_ec_commands.h +1 -1
index ecf290a0c98f..1f4e4f2b89bb 100644
@@ -5046,6 +5046,7 @@ struct ec_response_pd_status {
 #define PD_EVENT_DATA_SWAP         BIT(3)
 #define PD_EVENT_TYPEC             BIT(4)
 #define PD_EVENT_PPM               BIT(5)
+#define PD_EVENT_INIT              BIT(6)
 
 struct ec_response_host_event_status {
      uint32_t status; /* PD MCU host event status */
--

2.48.1.362.g079036d154-goog

author maintainer
#5 lore raw

PATCH 2/2 usb: typec: ucsi: resume work after EC init

In reply to Jameson Thies

A manual EC sysjump will restart the PPM and break communication with the UCSI driver by disabling notifications in the initial PPM state. Update cros_ec_ucsi to listen for PPM init events and treat them as a system resume to re-establish communication with the PPM (ChromeOS EC).

---
 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +12 -5
index c605c8616726..5f17fcbda059 100644
@@ -205,12 +205,19 @@ static int cros_ucsi_event(struct notifier_block *nb,
 {
 	struct cros_ucsi_data *udata = container_of(nb, struct cros_ucsi_data, nb);
 
-	if (!(host_event & PD_EVENT_PPM))
-		return NOTIFY_OK;
+	if (host_event & PD_EVENT_INIT) {
+		/* Late init event received from ChromeOS EC. Treat this as a
+		 * system resume to re-enable communication with the PPM.
+		 */
+		dev_dbg(udata->dev, "Late PD init received\n");
+		ucsi_resume(udata->ucsi);
+	}
 
-	dev_dbg(udata->dev, "UCSI notification received\n");
-	flush_work(&udata->work);
-	schedule_work(&udata->work);
+	if (host_event & PD_EVENT_PPM) {
+		dev_dbg(udata->dev, "UCSI notification received\n");
+		flush_work(&udata->work);
+		schedule_work(&udata->work);
+	}
 
 	return NOTIFY_OK;
 }
Signature · 1 line
2.48.1.362.g079036d154-goog
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH v1 2/2] usb: typec: ucsi: resume work after EC init

Hi Jameson,

Quoted 6 lines · Jameson Thies

A manual EC sysjump will restart the PPM and break communication with the UCSI driver by disabling notifications in the initial PPM state. Update cros_ec_ucsi to listen for PPM init events and treat them as a system resume to re-establish communication with the PPM (ChromeOS EC).

Quoted 36 lines
---
 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +12 -5
index c605c8616726..5f17fcbda059 100644
@@ -205,12 +205,19 @@ static int cros_ucsi_event(struct notifier_block *nb,
 {
 	struct cros_ucsi_data *udata = container_of(nb, struct cros_ucsi_data, nb);
 
-	if (!(host_event & PD_EVENT_PPM))
-		return NOTIFY_OK;
+	if (host_event & PD_EVENT_INIT) {
+		/* Late init event received from ChromeOS EC. Treat this as a
+		 * system resume to re-enable communication with the PPM.
+		 */
+		dev_dbg(udata->dev, "Late PD init received\n");
+		ucsi_resume(udata->ucsi);
+	}
 
-	dev_dbg(udata->dev, "UCSI notification received\n");
-	flush_work(&udata->work);
-	schedule_work(&udata->work);
+	if (host_event & PD_EVENT_PPM) {
+		dev_dbg(udata->dev, "UCSI notification received\n");
+		flush_work(&udata->work);
+		schedule_work(&udata->work);
+	}
 
 	return NOTIFY_OK;
 }
Signature · 1 line
2.48.1.362.g079036d154-goog
maintainer Reviewed-by
#7 lore raw

Re: [PATCH v1 2/2] usb: typec: ucsi: resume work after EC init

Quoted 4 lines · Benson Leung

Hi Jameson,

On Tue, Feb 04, 2025 at 02:45:59AM +0000, Jameson Thies wrote:

Quoted 9 lines
Quoted 6 lines

A manual EC sysjump will restart the PPM and break communication with the UCSI driver by disabling notifications in the initial PPM state. Update cros_ec_ucsi to listen for PPM init events and treat them as a system resume to re-establish communication with the PPM (ChromeOS EC).

Quoted 36 lines
Quoted 36 lines
---
 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +12 -6
index c605c8616726..5f17fcbda059 100644
@@ -205,12 +205,19 @@ static int cros_ucsi_event(struct notifier_block *nb,
 {
      struct cros_ucsi_data *udata = container_of(nb, struct cros_ucsi_data, nb);
 
-     if (!(host_event & PD_EVENT_PPM))
-             return NOTIFY_OK;
+     if (host_event & PD_EVENT_INIT) {
+             /* Late init event received from ChromeOS EC. Treat this as a
+              * system resume to re-enable communication with the PPM.
+              */
+             dev_dbg(udata->dev, "Late PD init received\n");
+             ucsi_resume(udata->ucsi);
+     }
 
-     dev_dbg(udata->dev, "UCSI notification received\n");
-     flush_work(&udata->work);
-     schedule_work(&udata->work);
+     if (host_event & PD_EVENT_PPM) {
+             dev_dbg(udata->dev, "UCSI notification received\n");
+             flush_work(&udata->work);
+             schedule_work(&udata->work);
+     }
 
      return NOTIFY_OK;
 }
--

2.48.1.362.g079036d154-goog