Lines Matching refs:sw
42 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role) in usb_role_switch_set_role() argument
46 if (IS_ERR_OR_NULL(sw)) in usb_role_switch_set_role()
49 mutex_lock(&sw->lock); in usb_role_switch_set_role()
51 ret = sw->set(sw->dev.parent, role); in usb_role_switch_set_role()
53 sw->role = role; in usb_role_switch_set_role()
55 mutex_unlock(&sw->lock); in usb_role_switch_set_role()
68 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) in usb_role_switch_get_role() argument
72 if (IS_ERR_OR_NULL(sw)) in usb_role_switch_get_role()
75 mutex_lock(&sw->lock); in usb_role_switch_get_role()
77 if (sw->get) in usb_role_switch_get_role()
78 role = sw->get(sw->dev.parent); in usb_role_switch_get_role()
80 role = sw->role; in usb_role_switch_get_role()
82 mutex_unlock(&sw->lock); in usb_role_switch_get_role()
127 struct usb_role_switch *sw; in usb_role_switch_get() local
129 sw = usb_role_switch_is_parent(dev_fwnode(dev)); in usb_role_switch_get()
130 if (!sw) in usb_role_switch_get()
131 sw = device_connection_find_match(dev, "usb-role-switch", NULL, in usb_role_switch_get()
134 if (!IS_ERR_OR_NULL(sw)) in usb_role_switch_get()
135 WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); in usb_role_switch_get()
137 return sw; in usb_role_switch_get()
150 struct usb_role_switch *sw; in fwnode_usb_role_switch_get() local
152 sw = usb_role_switch_is_parent(fwnode); in fwnode_usb_role_switch_get()
153 if (!sw) in fwnode_usb_role_switch_get()
154 sw = fwnode_connection_find_match(fwnode, "usb-role-switch", in fwnode_usb_role_switch_get()
156 if (!IS_ERR_OR_NULL(sw)) in fwnode_usb_role_switch_get()
157 WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); in fwnode_usb_role_switch_get()
159 return sw; in fwnode_usb_role_switch_get()
169 void usb_role_switch_put(struct usb_role_switch *sw) in usb_role_switch_put() argument
171 if (!IS_ERR_OR_NULL(sw)) { in usb_role_switch_put()
172 put_device(&sw->dev); in usb_role_switch_put()
173 module_put(sw->dev.parent->driver->owner); in usb_role_switch_put()
182 struct usb_role_switch *sw = to_role_switch(dev); in usb_role_switch_is_visible() local
184 if (sw->allow_userspace_control) in usb_role_switch_is_visible()
199 struct usb_role_switch *sw = to_role_switch(dev); in role_show() local
200 enum usb_role role = usb_role_switch_get_role(sw); in role_show()
208 struct usb_role_switch *sw = to_role_switch(dev); in role_store() local
221 ret = usb_role_switch_set_role(sw, ret); in role_store()
258 struct usb_role_switch *sw = to_role_switch(dev); in usb_role_switch_release() local
260 kfree(sw); in usb_role_switch_release()
288 struct usb_role_switch *sw; in usb_role_switch_register() local
294 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in usb_role_switch_register()
295 if (!sw) in usb_role_switch_register()
298 mutex_init(&sw->lock); in usb_role_switch_register()
300 sw->allow_userspace_control = desc->allow_userspace_control; in usb_role_switch_register()
301 sw->usb2_port = desc->usb2_port; in usb_role_switch_register()
302 sw->usb3_port = desc->usb3_port; in usb_role_switch_register()
303 sw->udc = desc->udc; in usb_role_switch_register()
304 sw->set = desc->set; in usb_role_switch_register()
305 sw->get = desc->get; in usb_role_switch_register()
307 sw->dev.parent = parent; in usb_role_switch_register()
308 sw->dev.fwnode = desc->fwnode; in usb_role_switch_register()
309 sw->dev.class = role_class; in usb_role_switch_register()
310 sw->dev.type = &usb_role_dev_type; in usb_role_switch_register()
311 dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent)); in usb_role_switch_register()
313 ret = device_register(&sw->dev); in usb_role_switch_register()
315 put_device(&sw->dev); in usb_role_switch_register()
321 return sw; in usb_role_switch_register()
331 void usb_role_switch_unregister(struct usb_role_switch *sw) in usb_role_switch_unregister() argument
333 if (!IS_ERR_OR_NULL(sw)) in usb_role_switch_unregister()
334 device_unregister(&sw->dev); in usb_role_switch_unregister()