summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorVijayavardhan Vennapusa <vvreddy@codeaurora.org>2017-05-30 16:11:04 +0530
committerVijayavardhan Vennapusa <vvreddy@codeaurora.org>2017-06-08 11:18:23 +0530
commita64cc72e05e306c3b97559a00fb5cc8ab94c62a2 (patch)
treef8ee2d7989f04854db4fcd9959f502ba68ed1adf /drivers
parentace73576d2eb567f552a699109b32d0917fccdbd (diff)
PD: policy_engine: Add timeout for mode change through sysfs
Currently USB driver tries to set power role as none and waits for disconnect notification to set new mode. But there is a chance that it might fail and stuck in infinite loop if other device is not dual-role capable. Fix it by having timeout and bail out in case timeout happens. Change-Id: I569356ee445c53950ed8fdd3f9994d4ae0e86131 Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/pd/policy_engine.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c
index 7d893c5815e2..9d58619adfe5 100644
--- a/drivers/usb/pd/policy_engine.c
+++ b/drivers/usb/pd/policy_engine.c
@@ -2514,6 +2514,7 @@ static int usbpd_dr_set_property(struct dual_role_phy_instance *dual_role,
{
struct usbpd *pd = dual_role_get_drvdata(dual_role);
bool do_swap = false;
+ int wait_count = 5;
if (!pd)
return -ENODEV;
@@ -2540,9 +2541,15 @@ static int usbpd_dr_set_property(struct dual_role_phy_instance *dual_role,
set_power_role(pd, PR_NONE);
/* wait until it takes effect */
- while (pd->forced_pr != POWER_SUPPLY_TYPEC_PR_NONE)
+ while (pd->forced_pr != POWER_SUPPLY_TYPEC_PR_NONE &&
+ --wait_count)
msleep(20);
+ if (!wait_count) {
+ usbpd_err(&pd->dev, "setting mode timed out\n");
+ return -ETIMEDOUT;
+ }
+
break;
case DUAL_ROLE_PROP_DR: