usb: typec: tcpm: add tcpm_port_error_recovery symbol
authorRD Babiera <rdbabiera@google.com>
Tue, 21 Nov 2023 20:38:47 +0000 (20:38 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 4 Dec 2023 13:29:51 +0000 (22:29 +0900)
Add tcpm_port_error_recovery symbol and corresponding event that runs in
tcpm_pd_event handler to set the port to the ERROR_RECOVERY state. tcpci
drivers can use the symbol to reset the port when tcpc faults affect port
functionality.

Signed-off-by: RD Babiera <rdbabiera@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20231121203845.170234-5-rdbabiera@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tcpm/tcpm.c
include/linux/usb/tcpm.h

index 50cbc52386b3886c650d38b10334c05f963cf6fb..ff67553b69323862390e72d354c67400c4a8fcb4 100644 (file)
@@ -251,6 +251,7 @@ enum frs_typec_current {
 #define TCPM_FRS_EVENT         BIT(3)
 #define TCPM_SOURCING_VBUS     BIT(4)
 #define TCPM_PORT_CLEAN                BIT(5)
+#define TCPM_PORT_ERROR                BIT(6)
 
 #define LOG_BUFFER_ENTRIES     1024
 #define LOG_BUFFER_ENTRY_SIZE  128
@@ -5487,6 +5488,10 @@ static void tcpm_pd_event_handler(struct kthread_work *work)
                                        tcpm_set_state(port, tcpm_default_state(port), 0);
                        }
                }
+               if (events & TCPM_PORT_ERROR) {
+                       tcpm_log(port, "port triggering error recovery");
+                       tcpm_set_state(port, ERROR_RECOVERY, 0);
+               }
 
                spin_lock(&port->pd_event_lock);
        }
@@ -5554,6 +5559,15 @@ bool tcpm_port_is_toggling(struct tcpm_port *port)
 }
 EXPORT_SYMBOL_GPL(tcpm_port_is_toggling);
 
+void tcpm_port_error_recovery(struct tcpm_port *port)
+{
+       spin_lock(&port->pd_event_lock);
+       port->pd_events |= TCPM_PORT_ERROR;
+       spin_unlock(&port->pd_event_lock);
+       kthread_queue_work(port->wq, &port->event_work);
+}
+EXPORT_SYMBOL_GPL(tcpm_port_error_recovery);
+
 static void tcpm_enable_frs_work(struct kthread_work *work)
 {
        struct tcpm_port *port = container_of(work, struct tcpm_port, enable_frs);
index ab7ca872950bb16b73967b458bb8fce91f421d55..65fac5e1f3178c4b11650771ded16d35b792b6a2 100644 (file)
@@ -173,5 +173,6 @@ void tcpm_pd_hard_reset(struct tcpm_port *port);
 void tcpm_tcpc_reset(struct tcpm_port *port);
 void tcpm_port_clean(struct tcpm_port *port);
 bool tcpm_port_is_toggling(struct tcpm_port *port);
+void tcpm_port_error_recovery(struct tcpm_port *port);
 
 #endif /* __LINUX_USB_TCPM_H */