diff options
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 | ||