From fd0ff67425eb9f6b5cb211e50ca3b8f3a81bea4a Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Thu, 2 Mar 2017 11:37:00 -0800 Subject: [PATCH] usb: pd: Determine dual_role writeable based on PD capability Allowing 'data_role' and 'power_role' sysfs attributes to be writeable implies that they can be changed independently. This is only true if there is a PD-capable device attached, otherwise the write permission should not be set. Also make sure to call dual_role_instance_changed() at the conclusion of initiating a DR swap in order to trigger the is_writeable() callback to update the permissions. Note that the PR swap case is already handled during the call to usbpd_set_state(PE_{SRC,SNK}_READY). Change-Id: I3f4bcaa8ae32af9a124e6f0967509c784e776f7d Signed-off-by: Jack Pham --- drivers/usb/pd/policy_engine.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c index 935bd0778bfb..c76ca5a94557 100644 --- a/drivers/usb/pd/policy_engine.c +++ b/drivers/usb/pd/policy_engine.c @@ -1417,6 +1417,7 @@ static void dr_swap(struct usbpd *pd) } pd_phy_update_roles(pd->current_dr, pd->current_pr); + dual_role_instance_changed(pd->dual_role); } @@ -2656,11 +2657,17 @@ static int usbpd_dr_set_property(struct dual_role_phy_instance *dual_role, static int usbpd_dr_prop_writeable(struct dual_role_phy_instance *dual_role, enum dual_role_property prop) { + struct usbpd *pd = dual_role_get_drvdata(dual_role); + switch (prop) { case DUAL_ROLE_PROP_MODE: + return 1; case DUAL_ROLE_PROP_DR: case DUAL_ROLE_PROP_PR: - return 1; + if (pd) + return pd->current_state == PE_SNK_READY || + pd->current_state == PE_SRC_READY; + break; default: break; }