From c5c2ca0587c70176def2cf049d20c55d3656444b Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Thu, 27 Jul 2017 15:11:25 -0700 Subject: [PATCH] usb: dwc3: dwc3-msm: Handle floating charger PMI notification properly When floating charger is detected, driver first notifies -ETIMEDOUT to PMI after 10 sec and then stops peripheral by simulating cable disconnect. As part of disconnect it notifies PMI to draw 0ma which PMI re-interprets as a SDP in bus suspend state and reconfigures PMI for SDP. Hence send charger current notification only as part of cable disconnect simulation by checking charger type. Change-Id: Ibafe8d52fa14ff32b6cb11e9f6e15a4f3f147d7a Signed-off-by: Hemant Kumar --- drivers/usb/dwc3/dwc3-msm.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-msm.c b/drivers/usb/dwc3/dwc3-msm.c index c3077ac11709..70db070b05d8 100644 --- a/drivers/usb/dwc3/dwc3-msm.c +++ b/drivers/usb/dwc3/dwc3-msm.c @@ -2634,8 +2634,6 @@ done: static void check_for_sdp_connection(struct work_struct *w) { - int ret; - union power_supply_propval pval = {0}; struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, sdp_check.work); struct dwc3 *dwc = platform_get_drvdata(mdwc->dwc3); @@ -2646,21 +2644,6 @@ static void check_for_sdp_connection(struct work_struct *w) /* floating D+/D- lines detected */ if (dwc->gadget.state < USB_STATE_DEFAULT && dwc3_gadget_get_link_state(dwc) != DWC3_LINK_STATE_CMPLY) { - if (!mdwc->usb_psy) { - mdwc->usb_psy = power_supply_get_by_name("usb"); - if (!mdwc->usb_psy) { - dev_dbg(mdwc->dev, - "Could not get usb power_supply\n"); - return; - } - } - pval.intval = -ETIMEDOUT; - ret = power_supply_set_property(mdwc->usb_psy, - POWER_SUPPLY_PROP_CURRENT_MAX, &pval); - if (ret) - dev_dbg(mdwc->dev, - "power supply error when setting property\n"); - mdwc->vbus_active = 0; dbg_event(0xFF, "Q RW SPD CHK", mdwc->vbus_active); queue_work(mdwc->dwc3_wq, &mdwc->resume_work); @@ -3708,14 +3691,16 @@ static int dwc3_msm_gadget_vbus_draw(struct dwc3_msm *mdwc, unsigned mA) return 0; psy_type = get_psy_type(mdwc); - if (psy_type != POWER_SUPPLY_TYPE_USB && - psy_type != POWER_SUPPLY_TYPE_USB_FLOAT) + if (psy_type == POWER_SUPPLY_TYPE_USB) { + dev_info(mdwc->dev, "Avail curr from USB = %u\n", mA); + /* Set max current limit in uA */ + pval.intval = 1000 * mA; + } else if (psy_type == POWER_SUPPLY_TYPE_USB_FLOAT) { + pval.intval = -ETIMEDOUT; + } else { return 0; + } - dev_info(mdwc->dev, "Avail curr from USB = %u\n", mA); - - /* Set max current limit in uA */ - pval.intval = 1000 * mA; ret = power_supply_set_property(mdwc->usb_psy, POWER_SUPPLY_PROP_CURRENT_MAX, &pval); if (ret) { -- 2.11.0