usb: typec: tcpci: Implement callbacks for FRS
authorBadhri Jagan Sridharan <badhri@google.com>
Thu, 8 Oct 2020 06:15:48 +0000 (23:15 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Oct 2020 07:43:55 +0000 (09:43 +0200)
Implement tcpc.enable_frs to enable TCPC to receive
Fast role swap signal.

Additionally set the sink disconnect threshold to 4v
to prevent disconnect during Fast Role swap.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20201008061556.1402293-8-badhri@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tcpm/tcpci.c
drivers/usb/typec/tcpm/tcpci.h

index d6a6fac82d4887d50d843da4970658eed41f84a7..f9f0af64da5f01c2b62f0e65748ef5cdfed9513f 100644 (file)
@@ -268,6 +268,22 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)
                                enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0);
 }
 
+static int tcpci_enable_frs(struct tcpc_dev *dev, bool enable)
+{
+       struct tcpci *tcpci = tcpc_to_tcpci(dev);
+       int ret;
+
+       /* To prevent disconnect during FRS, set disconnect threshold to 3.5V */
+       ret = tcpci_write16(tcpci, TCPC_VBUS_SINK_DISCONNECT_THRESH, enable ? 0 : 0x8c);
+       if (ret < 0)
+               return ret;
+
+       ret = regmap_update_bits(tcpci->regmap, TCPC_POWER_CTRL, TCPC_FAST_ROLE_SWAP_EN, enable ?
+                                TCPC_FAST_ROLE_SWAP_EN : 0);
+
+       return ret;
+}
+
 static int tcpci_set_bist_data(struct tcpc_dev *tcpc, bool enable)
 {
        struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -611,6 +627,7 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)
        tcpci->tcpc.set_roles = tcpci_set_roles;
        tcpci->tcpc.pd_transmit = tcpci_pd_transmit;
        tcpci->tcpc.set_bist_data = tcpci_set_bist_data;
+       tcpci->tcpc.enable_frs = tcpci_enable_frs;
 
        err = tcpci_parse_config(tcpci);
        if (err < 0)
index 82f021a8245632093b64e67ea55e873129dc4cd8..5ef07a56d67aa3dfd3df9e98c15d984c1b236c46 100644 (file)
@@ -16,6 +16,7 @@
 #define TCPC_PD_INT_REV                        0xa
 
 #define TCPC_ALERT                     0x10
+#define TCPC_ALERT_EXTND               BIT(14)
 #define TCPC_ALERT_EXTENDED_STATUS     BIT(13)
 #define TCPC_ALERT_VBUS_DISCNCT                BIT(11)
 #define TCPC_ALERT_RX_BUF_OVF          BIT(10)
@@ -37,6 +38,9 @@
 #define TCPC_EXTENDED_STATUS_MASK              0x16
 #define TCPC_EXTENDED_STATUS_MASK_VSAFE0V      BIT(0)
 
+#define TCPC_ALERT_EXTENDED_MASK       0x17
+#define TCPC_SINK_FAST_ROLE_SWAP       BIT(0)
+
 #define TCPC_CONFIG_STD_OUTPUT         0x18
 
 #define TCPC_TCPC_CTRL                 0x19
@@ -63,6 +67,7 @@
 
 #define TCPC_POWER_CTRL                        0x1c
 #define TCPC_POWER_CTRL_VCONN_ENABLE   BIT(0)
+#define TCPC_FAST_ROLE_SWAP_EN         BIT(7)
 
 #define TCPC_CC_STATUS                 0x1d
 #define TCPC_CC_STATUS_TOGGLING                BIT(5)
 
 #define TCPC_POWER_STATUS              0x1e
 #define TCPC_POWER_STATUS_UNINIT       BIT(6)
+#define TCPC_POWER_STATUS_SOURCING_VBUS        BIT(4)
 #define TCPC_POWER_STATUS_VBUS_DET     BIT(3)
 #define TCPC_POWER_STATUS_VBUS_PRES    BIT(2)
 
 #define TCPC_FAULT_STATUS              0x1f
 
+#define TCPC_ALERT_EXTENDED            0x21
+
 #define TCPC_COMMAND                   0x23
 #define TCPC_CMD_WAKE_I2C              0x11
 #define TCPC_CMD_DISABLE_VBUS_DETECT   0x22