soc: qcom: pmic_glink_altmode: handle safe mode when disconnect
authorNeil Armstrong <neil.armstrong@linaro.org>
Mon, 19 Jun 2023 08:07:13 +0000 (10:07 +0200)
committerBjorn Andersson <andersson@kernel.org>
Mon, 31 Jul 2023 21:19:06 +0000 (14:19 -0700)
On some Qcom SoCs, the Altmode event mode is set to 0xff when
the Type-C port is disconnected.

Handle this specific mode and translate it as the SAFE mode.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://lore.kernel.org/r/20230601-topic-sm8550-upstream-type-c-v5-1-9221cd300903@linaro.org
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
drivers/soc/qcom/pmic_glink_altmode.c

index 1dedacc..297d582 100644 (file)
@@ -174,6 +174,20 @@ static void pmic_glink_altmode_enable_usb(struct pmic_glink_altmode *altmode,
                dev_err(altmode->dev, "failed to switch mux to USB\n");
 }
 
+static void pmic_glink_altmode_safe(struct pmic_glink_altmode *altmode,
+                                   struct pmic_glink_altmode_port *port)
+{
+       int ret;
+
+       port->state.alt = NULL;
+       port->state.data = NULL;
+       port->state.mode = TYPEC_STATE_SAFE;
+
+       ret = typec_mux_set(port->typec_mux, &port->state);
+       if (ret)
+               dev_err(altmode->dev, "failed to switch mux to safe mode\n");
+}
+
 static void pmic_glink_altmode_worker(struct work_struct *work)
 {
        struct pmic_glink_altmode_port *alt_port = work_to_altmode_port(work);
@@ -181,7 +195,9 @@ static void pmic_glink_altmode_worker(struct work_struct *work)
 
        typec_switch_set(alt_port->typec_switch, alt_port->orientation);
 
-       if (alt_port->svid == USB_TYPEC_DP_SID)
+       if (alt_port->svid == USB_TYPEC_DP_SID && alt_port->mode == 0xff)
+               pmic_glink_altmode_safe(altmode, alt_port);
+       else if (alt_port->svid == USB_TYPEC_DP_SID)
                pmic_glink_altmode_enable_dp(altmode, alt_port, alt_port->mode,
                                             alt_port->hpd_state, alt_port->hpd_irq);
        else