Lines Matching full:sw
37 * @sw: USB role switch
40 * Set USB role @role for @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, role); in usb_role_switch_set_role()
53 sw->role = role; in usb_role_switch_set_role()
54 kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE); in usb_role_switch_set_role()
57 mutex_unlock(&sw->lock); in usb_role_switch_set_role()
65 * @sw: USB role switch
70 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) in usb_role_switch_get_role() argument
74 if (IS_ERR_OR_NULL(sw)) in usb_role_switch_get_role()
77 mutex_lock(&sw->lock); in usb_role_switch_get_role()
79 if (sw->get) in usb_role_switch_get_role()
80 role = sw->get(sw); in usb_role_switch_get_role()
82 role = sw->role; in usb_role_switch_get_role()
84 mutex_unlock(&sw->lock); in usb_role_switch_get_role()
125 struct usb_role_switch *sw; in usb_role_switch_get() local
127 sw = usb_role_switch_is_parent(dev_fwnode(dev)); in usb_role_switch_get()
128 if (!sw) in usb_role_switch_get()
129 sw = device_connection_find_match(dev, "usb-role-switch", NULL, in usb_role_switch_get()
132 if (!IS_ERR_OR_NULL(sw)) in usb_role_switch_get()
133 WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); in usb_role_switch_get()
135 return sw; in usb_role_switch_get()
148 struct usb_role_switch *sw; in fwnode_usb_role_switch_get() local
150 sw = usb_role_switch_is_parent(fwnode); in fwnode_usb_role_switch_get()
151 if (!sw) in fwnode_usb_role_switch_get()
152 sw = fwnode_connection_find_match(fwnode, "usb-role-switch", in fwnode_usb_role_switch_get()
154 if (!IS_ERR_OR_NULL(sw)) in fwnode_usb_role_switch_get()
155 WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); in fwnode_usb_role_switch_get()
157 return sw; in fwnode_usb_role_switch_get()
163 * @sw: USB Role Switch
165 * Decrement reference count for @sw.
167 void usb_role_switch_put(struct usb_role_switch *sw) in usb_role_switch_put() argument
169 if (!IS_ERR_OR_NULL(sw)) { in usb_role_switch_put()
170 module_put(sw->dev.parent->driver->owner); in usb_role_switch_put()
171 put_device(&sw->dev); in usb_role_switch_put()
203 struct usb_role_switch *sw = to_role_switch(dev); in usb_role_switch_is_visible() local
205 if (sw->allow_userspace_control) in usb_role_switch_is_visible()
229 struct usb_role_switch *sw = to_role_switch(dev); in role_show() local
230 enum usb_role role = usb_role_switch_get_role(sw); in role_show()
238 struct usb_role_switch *sw = to_role_switch(dev); in role_store() local
251 ret = usb_role_switch_set_role(sw, ret); in role_store()
288 struct usb_role_switch *sw = to_role_switch(dev); in usb_role_switch_release() local
290 kfree(sw); in usb_role_switch_release()
318 struct usb_role_switch *sw; in usb_role_switch_register() local
324 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in usb_role_switch_register()
325 if (!sw) in usb_role_switch_register()
328 mutex_init(&sw->lock); in usb_role_switch_register()
330 sw->allow_userspace_control = desc->allow_userspace_control; in usb_role_switch_register()
331 sw->usb2_port = desc->usb2_port; in usb_role_switch_register()
332 sw->usb3_port = desc->usb3_port; in usb_role_switch_register()
333 sw->udc = desc->udc; in usb_role_switch_register()
334 sw->set = desc->set; in usb_role_switch_register()
335 sw->get = desc->get; in usb_role_switch_register()
337 sw->dev.parent = parent; in usb_role_switch_register()
338 sw->dev.fwnode = desc->fwnode; in usb_role_switch_register()
339 sw->dev.class = role_class; in usb_role_switch_register()
340 sw->dev.type = &usb_role_dev_type; in usb_role_switch_register()
341 dev_set_drvdata(&sw->dev, desc->driver_data); in usb_role_switch_register()
342 dev_set_name(&sw->dev, "%s-role-switch", in usb_role_switch_register()
345 ret = device_register(&sw->dev); in usb_role_switch_register()
347 put_device(&sw->dev); in usb_role_switch_register()
353 return sw; in usb_role_switch_register()
359 * @sw: USB Role Switch
363 void usb_role_switch_unregister(struct usb_role_switch *sw) in usb_role_switch_unregister() argument
365 if (!IS_ERR_OR_NULL(sw)) in usb_role_switch_unregister()
366 device_unregister(&sw->dev); in usb_role_switch_unregister()
372 * @sw: USB Role Switch
375 void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data) in usb_role_switch_set_drvdata() argument
377 dev_set_drvdata(&sw->dev, data); in usb_role_switch_set_drvdata()
383 * @sw: USB Role Switch
385 void *usb_role_switch_get_drvdata(struct usb_role_switch *sw) in usb_role_switch_get_drvdata() argument
387 return dev_get_drvdata(&sw->dev); in usb_role_switch_get_drvdata()