]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: typec: tcpci: Prevent Sink disconnection before vPpsShutdown in SPR PPS
authorKyle Tso <kyletso@google.com>
Tue, 14 Jan 2025 14:24:35 +0000 (22:24 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:50:16 +0000 (12:50 +0100)
commit 4d27afbf256028a1f54363367f30efc8854433c3 upstream.

The Source can drop its output voltage to the minimum of the requested
PPS APDO voltage range when it is in Current Limit Mode. If this voltage
falls within the range of vPpsShutdown, the Source initiates a Hard
Reset and discharges Vbus. However, currently the Sink may disconnect
before the voltage reaches vPpsShutdown, leading to unexpected behavior.

Prevent premature disconnection by setting the Sink's disconnect
threshold to the minimum vPpsShutdown value. Additionally, consider the
voltage drop due to IR drop when calculating the appropriate threshold.
This ensures a robust and reliable interaction between the Source and
Sink during SPR PPS Current Limit Mode operation.

Fixes: 4288debeaa4e ("usb: typec: tcpci: Fix up sink disconnect thresholds for PD")
Cc: stable <stable@kernel.org>
Signed-off-by: Kyle Tso <kyletso@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>
Link: https://lore.kernel.org/r/20250114142435.2093857-1-kyletso@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tcpm/tcpci.c
drivers/usb/typec/tcpm/tcpm.c
include/linux/usb/tcpm.h

index e047a15e67347b2225735f0b7baffdb86b90619b..ba899aa1ec941e550a7913655eacbc5320e1db18 100644 (file)
@@ -26,6 +26,7 @@
 #define        VPPS_NEW_MIN_PERCENT                    95
 #define        VPPS_VALID_MIN_MV                       100
 #define        VSINKDISCONNECT_PD_MIN_PERCENT          90
+#define        VPPS_SHUTDOWN_MIN_PERCENT               85
 
 #define tcpc_presenting_rd(reg, cc) \
        (!(TCPC_ROLE_CTRL_DRP & (reg)) && \
@@ -358,7 +359,8 @@ static int tcpci_enable_auto_vbus_discharge(struct tcpc_dev *dev, bool enable)
 }
 
 static int tcpci_set_auto_vbus_discharge_threshold(struct tcpc_dev *dev, enum typec_pwr_opmode mode,
-                                                  bool pps_active, u32 requested_vbus_voltage_mv)
+                                                  bool pps_active, u32 requested_vbus_voltage_mv,
+                                                  u32 apdo_min_voltage_mv)
 {
        struct tcpci *tcpci = tcpc_to_tcpci(dev);
        unsigned int pwr_ctrl, threshold = 0;
@@ -380,9 +382,12 @@ static int tcpci_set_auto_vbus_discharge_threshold(struct tcpc_dev *dev, enum ty
                threshold = AUTO_DISCHARGE_DEFAULT_THRESHOLD_MV;
        } else if (mode == TYPEC_PWR_MODE_PD) {
                if (pps_active)
-                       threshold = ((VPPS_NEW_MIN_PERCENT * requested_vbus_voltage_mv / 100) -
-                                    VSINKPD_MIN_IR_DROP_MV - VPPS_VALID_MIN_MV) *
-                                    VSINKDISCONNECT_PD_MIN_PERCENT / 100;
+                       /*
+                        * To prevent disconnect when the source is in Current Limit Mode.
+                        * Set the threshold to the lowest possible voltage vPpsShutdown (min)
+                        */
+                       threshold = VPPS_SHUTDOWN_MIN_PERCENT * apdo_min_voltage_mv / 100 -
+                                   VSINKPD_MIN_IR_DROP_MV;
                else
                        threshold = ((VSRC_NEW_MIN_PERCENT * requested_vbus_voltage_mv / 100) -
                                     VSINKPD_MIN_IR_DROP_MV - VSRC_VALID_MIN_MV) *
index 55898fd7def8961c2a3e1bc892978949fac021e1..b645bbc0c57353c8035d76234c081b26a34b9e6f 100644 (file)
@@ -2312,10 +2312,12 @@ static int tcpm_set_auto_vbus_discharge_threshold(struct tcpm_port *port,
                return 0;
 
        ret = port->tcpc->set_auto_vbus_discharge_threshold(port->tcpc, mode, pps_active,
-                                                           requested_vbus_voltage);
+                                                           requested_vbus_voltage,
+                                                           port->pps_data.min_volt);
        tcpm_log_force(port,
-                      "set_auto_vbus_discharge_threshold mode:%d pps_active:%c vbus:%u ret:%d",
-                      mode, pps_active ? 'y' : 'n', requested_vbus_voltage, ret);
+                      "set_auto_vbus_discharge_threshold mode:%d pps_active:%c vbus:%u pps_apdo_min_volt:%u ret:%d",
+                      mode, pps_active ? 'y' : 'n', requested_vbus_voltage,
+                      port->pps_data.min_volt, ret);
 
        return ret;
 }
index bffc8d3e14ad64a702be8b0644ed2208057017f4..0af213187e9fc7a51220009c62de755daa2857a8 100644 (file)
@@ -145,7 +145,8 @@ struct tcpc_dev {
        void (*frs_sourcing_vbus)(struct tcpc_dev *dev);
        int (*enable_auto_vbus_discharge)(struct tcpc_dev *dev, bool enable);
        int (*set_auto_vbus_discharge_threshold)(struct tcpc_dev *dev, enum typec_pwr_opmode mode,
-                                                bool pps_active, u32 requested_vbus_voltage);
+                                                bool pps_active, u32 requested_vbus_voltage,
+                                                u32 pps_apdo_min_voltage);
        bool (*is_vbus_vsafe0v)(struct tcpc_dev *dev);
        void (*set_partner_usb_comm_capable)(struct tcpc_dev *dev, bool enable);
 };