usb: typec: tcpm: Do not disconnect link for self powered devices
authorBadhri Jagan Sridharan <badhri@google.com>
Mon, 1 Oct 2018 19:45:00 +0000 (12:45 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Nov 2018 12:20:39 +0000 (13:20 +0100)
During HARD_RESET the data link is disconnected.
For self powered device, the spec is advising against doing that.

>From USB_PD_R3_0
7.1.5 Response to Hard Resets
Device operation during and after a Hard Reset is defined as follows:
Self-powered devices Should Not disconnect from USB during a Hard Reset
(see Section 9.1.2).
Bus powered devices will disconnect from USB during a Hard Reset due to the
loss of their power source.

Tackle this by letting TCPM know whether the device is self or bus powered.

This overcomes unnecessary port disconnections from hard reset.
Also, speeds up the enumeration time when connected to Type-A ports.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---------
Version history:
V3:
Rebase on top of usb-next

V2:
Based on feedback from heikki.krogerus@linux.intel.com
- self_powered added to the struct tcpm_port which is populated from
  a. "connector" node of the device tree in tcpm_fw_get_caps()
  b. "self_powered" node of the tcpc_config in tcpm_copy_caps

Based on feedbase from linux@roeck-us.net
- Code was refactored
- SRC_HARD_RESET_VBUS_OFF sets the link state to false based
  on self_powered flag

V1 located here:
https://lkml.org/lkml/2018/9/13/94
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tcpm/tcpm.c
include/linux/usb/tcpm.h

index dbbd71f754d0291600415b1a8bdb3b3206f60ccd..ba6e5cdaed2c56787090569a796b14ef1f01494c 100644 (file)
@@ -317,6 +317,9 @@ struct tcpm_port {
        /* Deadline in jiffies to exit src_try_wait state */
        unsigned long max_wait;
 
+       /* port belongs to a self powered device */
+       bool self_powered;
+
 #ifdef CONFIG_DEBUG_FS
        struct dentry *dentry;
        struct mutex logbuffer_lock;    /* log buffer access lock */
@@ -3254,7 +3257,8 @@ static void run_state_machine(struct tcpm_port *port)
        case SRC_HARD_RESET_VBUS_OFF:
                tcpm_set_vconn(port, true);
                tcpm_set_vbus(port, false);
-               tcpm_set_roles(port, false, TYPEC_SOURCE, TYPEC_HOST);
+               tcpm_set_roles(port, port->self_powered, TYPEC_SOURCE,
+                              TYPEC_HOST);
                tcpm_set_state(port, SRC_HARD_RESET_VBUS_ON, PD_T_SRC_RECOVER);
                break;
        case SRC_HARD_RESET_VBUS_ON:
@@ -3267,7 +3271,8 @@ static void run_state_machine(struct tcpm_port *port)
                memset(&port->pps_data, 0, sizeof(port->pps_data));
                tcpm_set_vconn(port, false);
                tcpm_set_charge(port, false);
-               tcpm_set_roles(port, false, TYPEC_SINK, TYPEC_DEVICE);
+               tcpm_set_roles(port, port->self_powered, TYPEC_SINK,
+                              TYPEC_DEVICE);
                /*
                 * VBUS may or may not toggle, depending on the adapter.
                 * If it doesn't toggle, transition to SNK_HARD_RESET_SINK_ON
@@ -4412,6 +4417,8 @@ sink:
                return -EINVAL;
        port->operating_snk_mw = mw / 1000;
 
+       port->self_powered = fwnode_property_read_bool(fwnode, "self-powered");
+
        return 0;
 }
 
@@ -4720,6 +4727,7 @@ static int tcpm_copy_caps(struct tcpm_port *port,
        port->typec_caps.prefer_role = tcfg->default_role;
        port->typec_caps.type = tcfg->type;
        port->typec_caps.data = tcfg->data;
+       port->self_powered = port->tcpc->config->self_powered;
 
        return 0;
 }
index 7e7fbfb84e8e311045812849e1f19ed904b101e3..50c74a77db55c435af06e83833ca1271c263d6fd 100644 (file)
@@ -89,6 +89,7 @@ struct tcpc_config {
        enum typec_port_data data;
        enum typec_role default_role;
        bool try_role_hw;       /* try.{src,snk} implemented in hardware */
+       bool self_powered;      /* port belongs to a self powered device */
 
        const struct typec_altmode_desc *alt_modes;
 };