MLK-16013-20 staging: typec: Add bist test mode support
authorLi Jun <jun.li@nxp.com>
Thu, 27 Jul 2017 13:38:13 +0000 (21:38 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:36:19 +0000 (15:36 -0500)
BIST(Built In Self-Test – Power Delivery testing mechanism for
the PHY Layer), see PD 3.0 spec 5.9 Built in Self-Test (BIST), is
added to support BIST message handling in PD compliance test.

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
drivers/staging/typec/tcpci.c
drivers/staging/typec/tcpci.h
drivers/staging/typec/tcpm.c
drivers/staging/typec/tcpm.h

index cfd80a2..a047b33 100644 (file)
@@ -426,6 +426,15 @@ static int tcpci_vbus_detect(struct tcpc_dev *tcpc, bool enable)
        return 0;
 }
 
+static void tcpci_bist_mode(struct tcpc_dev *tcpc, bool enable)
+{
+       struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+
+       regmap_update_bits(tcpci->regmap, TCPC_TCPC_CTRL,
+                          TCPC_TCPC_CTRL_BIST_MODE,
+                          enable ? TCPC_TCPC_CTRL_BIST_MODE : 0);
+}
+
 static int tcpci_init(struct tcpc_dev *tcpc)
 {
        struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -602,6 +611,7 @@ static int tcpci_probe(struct i2c_client *client,
        tcpci->tcpc.vbus_detect = tcpci_vbus_detect;
        tcpci->tcpc.vbus_discharge = tcpci_vbus_force_discharge;
        tcpci->tcpc.get_vbus_vol = tcpci_get_vbus_vol;
+       tcpci->tcpc.bist_mode = tcpci_bist_mode;
 
        tcpci->tcpc.set_pd_rx = tcpci_set_pd_rx;
        tcpci->tcpc.set_roles = tcpci_set_roles;
index d74423f..75a9666 100644 (file)
@@ -45,6 +45,7 @@
 #define TCPC_CONFIG_STD_OUTPUT         0x18
 
 #define TCPC_TCPC_CTRL                 0x19
+#define TCPC_TCPC_CTRL_BIST_MODE       BIT(1)
 #define TCPC_TCPC_CTRL_ORIENTATION     BIT(0)
 
 #define TCPC_ROLE_CTRL                 0x1a
index b4e77b2..73a9e36 100644 (file)
@@ -1893,6 +1893,13 @@ static void tcpm_typec_connect(struct tcpm_port *port)
        }
 }
 
+static void tcpm_bist_handle(struct tcpm_port *port, bool enable)
+{
+       /* Enable or disable BIST test mode */
+       if (port->tcpc && port->tcpc->bist_mode)
+               port->tcpc->bist_mode(port->tcpc, enable);
+}
+
 static int tcpm_src_attach(struct tcpm_port *port)
 {
        enum typec_cc_polarity polarity =
@@ -1980,6 +1987,7 @@ static void tcpm_reset_port(struct tcpm_port *port)
        port->attached = false;
        port->pd_capable = false;
 
+       tcpm_bist_handle(port, false);
        port->tcpc->set_pd_rx(port->tcpc, false);
        tcpm_init_vbus(port);   /* also disables charging */
        tcpm_init_vconn(port);
@@ -2676,6 +2684,7 @@ static void run_state_machine(struct tcpm_port *port)
                break;
 
        case BIST_RX:
+               tcpm_bist_handle(port, true);
                switch (BDO_MODE_MASK(port->bist_request)) {
                case BDO_MODE_CARRIER2:
                        tcpm_pd_transmit(port, TCPC_TX_BIST_MODE_2, NULL);
index 08f103d..b8a5742 100644 (file)
@@ -128,6 +128,7 @@ struct tcpc_dev {
                           const struct pd_message *msg);
        int (*vbus_detect)(struct tcpc_dev *dev, bool enable);
        int (*vbus_discharge)(struct tcpc_dev *tcpc, bool enable);
+       void (*bist_mode)(struct tcpc_dev *tcpc, bool enable);
 
        struct tcpc_mux_dev *mux;
 };