OSDN Git Service

usb: pd: Update power_supply type to USB_PD after PD is established
authorJack Pham <jackp@codeaurora.org>
Wed, 25 May 2016 17:03:17 +0000 (10:03 -0700)
committerKyle Yan <kyan@codeaurora.org>
Thu, 26 May 2016 22:27:20 +0000 (15:27 -0700)
The USB power_supply now allows PROP_TYPE to be modified. Update it
to 'USB_PD' only after PD communication has been established. This
can happen only in a couple places:

   - in sink mode, when a source capabilities message is received

   - in source mode, when GoodCRC is received after sending the
     source capabilities message successfully

Since PD_ACTIVE=1 is required to be set, also update it in source
mode prior to sending out the capabilities, and clear it if all the
attempts fail. Remove the unreachable/dead code found there as well.

Change-Id: I77c5875ee8514395a82fac0109b7cff1d507250b
Signed-off-by: Jack Pham <jackp@codeaurora.org>
drivers/usb/pd/policy_engine.c

index 6b636a4..de0d06e 100644 (file)
@@ -516,6 +516,10 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state)
                        pd->pd_phy_opened = true;
                }
 
+               val.intval = 1;
+               power_supply_set_property(pd->usb_psy,
+                               POWER_SUPPLY_PROP_PD_ACTIVE, &val);
+
                pd->in_pr_swap = false;
                pd->current_state = PE_SRC_SEND_CAPABILITIES;
                dev_dbg(&pd->dev, "Enter %s\n",
@@ -526,16 +530,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state)
                queue_delayed_work(pd->wq, &pd->sm_work, 0);
                break;
 
-               /* reset counters */
-               pd->hard_reset_count = 0;
-               pd->caps_count = 0;
-               pd->pd_connected = true; /* we know peer is PD capable */
-
-               /* wait for REQUEST */
-               queue_delayed_work(pd->wq, &pd->sm_work,
-                               msecs_to_jiffies(SENDER_RESPONSE_TIME * 3));
-               break;
-
        case PE_SRC_NEGOTIATE_CAPABILITY:
                if (PD_RDO_OBJ_POS(pd->rdo) != 1) {
                        /* send Reject */
@@ -917,6 +911,11 @@ static void usbpd_sm(struct work_struct *w)
                        } else if (pd->caps_count >= PD_CAPS_COUNT) {
                                dev_dbg(&pd->dev, "Src CapsCounter exceeded, disabling PD\n");
                                usbpd_set_state(pd, PE_SRC_DISABLED);
+
+                               val.intval = 0;
+                               power_supply_set_property(pd->usb_psy,
+                                               POWER_SUPPLY_PROP_PD_ACTIVE,
+                                               &val);
                                break;
                        }
 
@@ -928,6 +927,11 @@ static void usbpd_sm(struct work_struct *w)
                /* transmit was successful if GoodCRC was received */
                pd->caps_count = 0;
                pd->hard_reset_count = 0;
+               pd->pd_connected = true; /* we know peer is PD capable */
+
+               val.intval = POWER_SUPPLY_TYPE_USB_PD;
+               power_supply_set_property(pd->usb_psy,
+                               POWER_SUPPLY_PROP_TYPE, &val);
 
                /* wait for REQUEST */
                pd->current_state = PE_SRC_SEND_CAPABILITIES_WAIT;
@@ -1021,6 +1025,11 @@ static void usbpd_sm(struct work_struct *w)
                        val.intval = 1;
                        power_supply_set_property(pd->usb_psy,
                                        POWER_SUPPLY_PROP_PD_ACTIVE, &val);
+
+                       val.intval = POWER_SUPPLY_TYPE_USB_PD;
+                       power_supply_set_property(pd->usb_psy,
+                                       POWER_SUPPLY_PROP_TYPE, &val);
+
                        usbpd_set_state(pd, PE_SNK_EVALUATE_CAPABILITY);
                } else if (pd->hard_reset_count < 3) {
                        usbpd_set_state(pd, PE_SNK_HARD_RESET);