summaryrefslogtreecommitdiff
path: root/drivers/usb
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2016-08-13 04:51:55 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2016-08-13 04:51:55 -0700
commitc174c683da7c983ba94ee15aa091d67d903aa130 (patch)
tree5d1bc39370788125e0d124ebca73465462d7f1a4 /drivers/usb
parent1aad9d6149b10dfd9f71719016a59341c732f22c (diff)
parent9a2bd8b7b87e96c6346e683ea3079604addf2932 (diff)
Merge "usb: pd: Only request current amount for explicit contract"
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/dwc3/dwc3-msm.c54
-rw-r--r--drivers/usb/pd/policy_engine.c11
2 files changed, 26 insertions, 39 deletions
diff --git a/drivers/usb/dwc3/dwc3-msm.c b/drivers/usb/dwc3/dwc3-msm.c
index ef0a793e5bec..aa05e6256852 100644
--- a/drivers/usb/dwc3/dwc3-msm.c
+++ b/drivers/usb/dwc3/dwc3-msm.c
@@ -187,6 +187,7 @@ struct dwc3_msm {
u32 bus_perf_client;
struct msm_bus_scale_pdata *bus_scale_table;
struct power_supply *usb_psy;
+ struct work_struct vbus_draw_work;
bool in_host_mode;
unsigned int tx_fifo_size;
bool vbus_active;
@@ -1595,6 +1596,15 @@ static void dwc3_msm_qscratch_reg_init(struct dwc3_msm *mdwc)
}
+static void dwc3_msm_vbus_draw_work(struct work_struct *w)
+{
+ struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm,
+ vbus_draw_work);
+ struct dwc3 *dwc = platform_get_drvdata(mdwc->dwc3);
+
+ dwc3_msm_gadget_vbus_draw(mdwc, dwc->vbus_draw);
+}
+
static void dwc3_msm_notify_event(struct dwc3 *dwc, unsigned event)
{
struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent);
@@ -1680,7 +1690,7 @@ static void dwc3_msm_notify_event(struct dwc3 *dwc, unsigned event)
break;
case DWC3_CONTROLLER_SET_CURRENT_DRAW_EVENT:
dev_dbg(mdwc->dev, "DWC3_CONTROLLER_SET_CURRENT_DRAW_EVENT received\n");
- dwc3_msm_gadget_vbus_draw(mdwc, dwc->vbus_draw);
+ schedule_work(&mdwc->vbus_draw_work);
break;
case DWC3_CONTROLLER_RESTART_USB_SESSION:
dev_dbg(mdwc->dev, "DWC3_CONTROLLER_RESTART_USB_SESSION received\n");
@@ -2591,6 +2601,7 @@ static int dwc3_msm_probe(struct platform_device *pdev)
INIT_WORK(&mdwc->resume_work, dwc3_resume_work);
INIT_WORK(&mdwc->restart_usb_work, dwc3_restart_usb_work);
INIT_WORK(&mdwc->bus_vote_w, dwc3_msm_bus_vote_w);
+ INIT_WORK(&mdwc->vbus_draw_work, dwc3_msm_vbus_draw_work);
INIT_DELAYED_WORK(&mdwc->sm_work, dwc3_otg_sm_work);
mdwc->dwc3_wq = alloc_ordered_workqueue("dwc3_wq", 0);
@@ -3174,7 +3185,8 @@ static int dwc3_otg_start_peripheral(struct dwc3_msm *mdwc, int on)
static int dwc3_msm_gadget_vbus_draw(struct dwc3_msm *mdwc, unsigned mA)
{
- union power_supply_propval pval = {0,};
+ union power_supply_propval pval = {1000 * mA};
+ int ret;
if (mdwc->charging_disabled)
return 0;
@@ -3192,42 +3204,16 @@ static int dwc3_msm_gadget_vbus_draw(struct dwc3_msm *mdwc, unsigned mA)
dev_info(mdwc->dev, "Avail curr from USB = %u\n", mA);
- if (mdwc->max_power <= 2 && mA > 2) {
- /* Enable Charging */
- pval.intval = true;
- if (power_supply_set_property(mdwc->usb_psy,
- POWER_SUPPLY_PROP_ONLINE, &pval))
- goto psy_error;
- pval.intval = 1000 * mA;
- if (power_supply_set_property(mdwc->usb_psy,
- POWER_SUPPLY_PROP_CURRENT_MAX, &pval))
- goto psy_error;
- } else if (mdwc->max_power > 0 && (mA == 0 || mA == 2)) {
- /* Disable charging */
- pval.intval = false;
- if (power_supply_set_property(mdwc->usb_psy,
- POWER_SUPPLY_PROP_ONLINE, &pval))
- goto psy_error;
- } else {
- /* Enable charging */
- pval.intval = true;
- if (power_supply_set_property(mdwc->usb_psy,
- POWER_SUPPLY_PROP_ONLINE, &pval))
- goto psy_error;
- }
-
/* Set max current limit in uA */
- pval.intval = 1000 * mA;
- if (power_supply_set_property(mdwc->usb_psy,
- POWER_SUPPLY_PROP_CURRENT_MAX, &pval))
- goto psy_error;
+ 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");
+ return ret;
+ }
mdwc->max_power = mA;
return 0;
-
-psy_error:
- dev_dbg(mdwc->dev, "power supply error when setting property\n");
- return -ENXIO;
}
diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c
index f29c275c490b..7bc6b5340dd7 100644
--- a/drivers/usb/pd/policy_engine.c
+++ b/drivers/usb/pd/policy_engine.c
@@ -849,10 +849,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state)
POWER_SUPPLY_PROP_VOLTAGE_MAX, &val);
pd->current_voltage = pd->requested_voltage;
- val.intval = pd->requested_current * 1000; /* mA->uA */
- power_supply_set_property(pd->usb_psy,
- POWER_SUPPLY_PROP_CURRENT_MAX, &val);
-
/* recursive call; go back to beginning state */
usbpd_set_state(pd, PE_SNK_STARTUP);
break;
@@ -1615,7 +1611,12 @@ static void usbpd_sm(struct work_struct *w)
POWER_SUPPLY_PROP_PD_ACTIVE, &val);
pd->requested_voltage = 5000000;
- pd->requested_current = max_sink_current;
+
+ if (pd->requested_current) {
+ val.intval = pd->requested_current = 0;
+ power_supply_set_property(pd->usb_psy,
+ POWER_SUPPLY_PROP_CURRENT_MAX, &val);
+ }
val.intval = pd->requested_voltage;
power_supply_set_property(pd->usb_psy,