diff options
author | Chunfeng Yun <chunfeng.yun@mediatek.com> | 2019-08-29 05:22:35 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-09-03 12:00:43 -0400 |
commit | 6fadd72943b80ff5bef175aacc2458c8a9ee3dbc (patch) | |
tree | 19b5753f2de321129aa05c3c5e8ea5eb6a563a70 /drivers/usb/roles/class.c | |
parent | c5c0283a9db1c7ba5881f956a1faf2ebc3dfe70e (diff) |
usb: roles: get usb-role-switch from parent
when the USB host controller is the parent of the connector,
usually type-B, sometimes don't need the graph, so we should
check whether it's parent registers usb-role-switch or not
firstly, and get it if exists.
Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Link: https://lore.kernel.org/r/1567070558-29417-9-git-send-email-chunfeng.yun@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/roles/class.c')
-rw-r--r-- | drivers/usb/roles/class.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index 2abb6fe384ca..94b4e7db2b94 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c | |||
@@ -102,6 +102,19 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, | |||
102 | return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); | 102 | return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); |
103 | } | 103 | } |
104 | 104 | ||
105 | static struct usb_role_switch * | ||
106 | usb_role_switch_is_parent(struct fwnode_handle *fwnode) | ||
107 | { | ||
108 | struct fwnode_handle *parent = fwnode_get_parent(fwnode); | ||
109 | struct device *dev; | ||
110 | |||
111 | if (!parent || !fwnode_property_present(parent, "usb-role-switch")) | ||
112 | return NULL; | ||
113 | |||
114 | dev = class_find_device_by_fwnode(role_class, parent); | ||
115 | return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); | ||
116 | } | ||
117 | |||
105 | /** | 118 | /** |
106 | * usb_role_switch_get - Find USB role switch linked with the caller | 119 | * usb_role_switch_get - Find USB role switch linked with the caller |
107 | * @dev: The caller device | 120 | * @dev: The caller device |
@@ -113,8 +126,10 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev) | |||
113 | { | 126 | { |
114 | struct usb_role_switch *sw; | 127 | struct usb_role_switch *sw; |
115 | 128 | ||
116 | sw = device_connection_find_match(dev, "usb-role-switch", NULL, | 129 | sw = usb_role_switch_is_parent(dev_fwnode(dev)); |
117 | usb_role_switch_match); | 130 | if (!sw) |
131 | sw = device_connection_find_match(dev, "usb-role-switch", NULL, | ||
132 | usb_role_switch_match); | ||
118 | 133 | ||
119 | if (!IS_ERR_OR_NULL(sw)) | 134 | if (!IS_ERR_OR_NULL(sw)) |
120 | WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); | 135 | WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); |
@@ -134,8 +149,10 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode) | |||
134 | { | 149 | { |
135 | struct usb_role_switch *sw; | 150 | struct usb_role_switch *sw; |
136 | 151 | ||
137 | sw = fwnode_connection_find_match(fwnode, "usb-role-switch", NULL, | 152 | sw = usb_role_switch_is_parent(fwnode); |
138 | usb_role_switch_match); | 153 | if (!sw) |
154 | sw = fwnode_connection_find_match(fwnode, "usb-role-switch", | ||
155 | NULL, usb_role_switch_match); | ||
139 | if (!IS_ERR_OR_NULL(sw)) | 156 | if (!IS_ERR_OR_NULL(sw)) |
140 | WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); | 157 | WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); |
141 | 158 | ||