OSDN Git Service

qcom-charger: Don't automatically set USB_PD type when PD_ACTIVE=1
authorJack Pham <jackp@codeaurora.org>
Mon, 23 May 2016 18:15:15 +0000 (11:15 -0700)
committerKyle Yan <kyan@codeaurora.org>
Thu, 26 May 2016 22:27:09 +0000 (15:27 -0700)
The POWER_SUPPLY_PROP_PD_ACTIVE property is intended to be a flag
set whenever the PD PHY is in use. But this includes attempts to
establish communication, which may involve trying to perform a hard
reset to see if the port partner responds. Thus updating the
psy_desc.type field to 'USB_PD' right when PD_ACTIVE=1 is premature
as the port partner may not be PD-capable and it could be un-set.
Instead allow the PD driver to directly update POWER_SUPPLY_PROP_TYPE
only after it is sure PD communication has succeeded.

Change-Id: Iae6804bcb3121e0852ec5d14d0939623b97a6e67
Signed-off-by: Jack Pham <jackp@codeaurora.org>
drivers/power/qcom-charger/qpnp-smb2.c
drivers/power/qcom-charger/smb-lib.c

index 7d5b03b..ab4ab0c 100644 (file)
@@ -209,6 +209,14 @@ static int smb2_usb_set_prop(struct power_supply *psy,
        case POWER_SUPPLY_PROP_CURRENT_MAX:
                rc = smblib_set_prop_usb_current_max(chg, val);
                break;
+       case POWER_SUPPLY_PROP_TYPE:
+               if (chg->pd_active && val->intval == POWER_SUPPLY_TYPE_USB_PD) {
+                       chg->usb_psy_desc.type = val->intval;
+               } else {
+                       pr_err("set type %d not allowed\n", val->intval);
+                       rc = -EINVAL;
+               }
+               break;
        case POWER_SUPPLY_PROP_TYPEC_POWER_ROLE:
                rc = smblib_set_prop_typec_power_role(chg, val);
                break;
index 1e66507..ebbc8e1 100644 (file)
@@ -256,10 +256,9 @@ static int smblib_update_usb_type(struct smb_charger *chg)
        int rc = 0;
        const struct apsd_result *apsd_result;
 
-       if (chg->pd_active) {
-               chg->usb_psy_desc.type = POWER_SUPPLY_TYPE_USB_PD;
+       /* if PD is active, APSD is disabled so won't have a valid result */
+       if (chg->pd_active)
                return rc;
-       }
 
        apsd_result = smblib_get_apsd_result(chg);
        chg->usb_psy_desc.type = apsd_result->pst;
@@ -271,12 +270,7 @@ static int smblib_detach_usb(struct smb_charger *chg)
        int rc;
 
        cancel_delayed_work_sync(&chg->hvdcp_detect_work);
-
-       rc = smblib_update_usb_type(chg);
-       if (rc < 0) {
-               dev_err(chg->dev, "Couldn't update usb type rc=%d\n", rc);
-               return rc;
-       }
+       chg->usb_psy_desc.type = POWER_SUPPLY_TYPE_UNKNOWN;
 
        /* reconfigure allowed voltage for HVDCP */
        rc = smblib_write(chg, USBIN_ADAPTER_ALLOW_CFG_REG,