From 0355a024aa005fe9f50e268cada2fd8367e1961b Mon Sep 17 00:00:00 2001 From: Vijayavardhan Vennapusa Date: Tue, 16 May 2017 14:55:51 +0530 Subject: [PATCH] policy_engine: Don't allow MODE change if no active connection Currently driver is allowing MODE change even if there is no active cable connection and is waiting for to complete. For this MODE change to complete, driver first sets power role to none to do type C disconnect and then switch to new mode. Here disconnect won't come as there is no active cable connection. Fix this issue by returning error in case there is no active connection. Change-Id: Ie423bd8b61ab7b2624f98c84e8d8e75b6c853b00 Signed-off-by: Vijayavardhan Vennapusa --- drivers/usb/pd/policy_engine.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c index 055c6203577a..842556f33a85 100644 --- a/drivers/usb/pd/policy_engine.c +++ b/drivers/usb/pd/policy_engine.c @@ -2519,6 +2519,11 @@ static int usbpd_dr_set_property(struct dual_role_phy_instance *dual_role, case DUAL_ROLE_PROP_MODE: usbpd_dbg(&pd->dev, "Setting mode to %d\n", *val); + if (pd->current_state == PE_UNKNOWN) { + usbpd_warn(&pd->dev, "No active connection. Don't allow MODE change\n"); + return -EAGAIN; + } + /* * Forces disconnect on CC and re-establishes connection. * This does not use PD-based PR/DR swap