Lines Matching refs:sw
75 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role) in usb_role_switch_set_role() argument
79 if (IS_ERR_OR_NULL(sw)) in usb_role_switch_set_role()
82 if (!sw->registered) in usb_role_switch_set_role()
85 mutex_lock(&sw->lock); in usb_role_switch_set_role()
87 ret = sw->set(sw, role); in usb_role_switch_set_role()
89 sw->role = role; in usb_role_switch_set_role()
90 kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE); in usb_role_switch_set_role()
93 mutex_unlock(&sw->lock); in usb_role_switch_set_role()
106 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) in usb_role_switch_get_role() argument
110 if (IS_ERR_OR_NULL(sw) || !sw->registered) in usb_role_switch_get_role()
113 mutex_lock(&sw->lock); in usb_role_switch_get_role()
115 if (sw->get) in usb_role_switch_get_role()
116 role = sw->get(sw); in usb_role_switch_get_role()
118 role = sw->role; in usb_role_switch_get_role()
120 mutex_unlock(&sw->lock); in usb_role_switch_get_role()
164 struct usb_role_switch *sw; in usb_role_switch_get() local
166 sw = usb_role_switch_is_parent(dev_fwnode(dev)); in usb_role_switch_get()
167 if (!sw) in usb_role_switch_get()
168 sw = device_connection_find_match(dev, "usb-role-switch", NULL, in usb_role_switch_get()
171 if (!IS_ERR_OR_NULL(sw)) in usb_role_switch_get()
172 WARN_ON(!try_module_get(sw->module)); in usb_role_switch_get()
174 return sw; in usb_role_switch_get()
187 struct usb_role_switch *sw; in fwnode_usb_role_switch_get() local
189 sw = usb_role_switch_is_parent(fwnode); in fwnode_usb_role_switch_get()
190 if (!sw) in fwnode_usb_role_switch_get()
191 sw = fwnode_connection_find_match(fwnode, "usb-role-switch", in fwnode_usb_role_switch_get()
193 if (!IS_ERR_OR_NULL(sw)) in fwnode_usb_role_switch_get()
194 WARN_ON(!try_module_get(sw->module)); in fwnode_usb_role_switch_get()
196 return sw; in fwnode_usb_role_switch_get()
206 void usb_role_switch_put(struct usb_role_switch *sw) in usb_role_switch_put() argument
208 if (!IS_ERR_OR_NULL(sw)) { in usb_role_switch_put()
209 module_put(sw->module); in usb_role_switch_put()
210 put_device(&sw->dev); in usb_role_switch_put()
226 struct usb_role_switch *sw = NULL; in usb_role_switch_find_by_fwnode() local
233 sw = to_role_switch(dev); in usb_role_switch_find_by_fwnode()
234 WARN_ON(!try_module_get(sw->module)); in usb_role_switch_find_by_fwnode()
237 return sw; in usb_role_switch_find_by_fwnode()
245 struct usb_role_switch *sw = to_role_switch(dev); in usb_role_switch_is_visible() local
247 if (sw->allow_userspace_control) in usb_role_switch_is_visible()
271 struct usb_role_switch *sw = to_role_switch(dev); in role_show() local
272 enum usb_role role = usb_role_switch_get_role(sw); in role_show()
280 struct usb_role_switch *sw = to_role_switch(dev); in role_store() local
293 ret = usb_role_switch_set_role(sw, ret); in role_store()
329 struct usb_role_switch *sw = to_role_switch(dev); in usb_role_switch_release() local
331 mutex_destroy(&sw->lock); in usb_role_switch_release()
332 lockdep_unregister_key(&sw->key); in usb_role_switch_release()
333 kfree(sw); in usb_role_switch_release()
361 struct usb_role_switch *sw; in usb_role_switch_register() local
367 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in usb_role_switch_register()
368 if (!sw) in usb_role_switch_register()
371 lockdep_register_key(&sw->key); in usb_role_switch_register()
372 mutex_init_with_key(&sw->lock, &sw->key); in usb_role_switch_register()
374 sw->allow_userspace_control = desc->allow_userspace_control; in usb_role_switch_register()
375 sw->usb2_port = desc->usb2_port; in usb_role_switch_register()
376 sw->usb3_port = desc->usb3_port; in usb_role_switch_register()
377 sw->udc = desc->udc; in usb_role_switch_register()
378 sw->set = desc->set; in usb_role_switch_register()
379 sw->get = desc->get; in usb_role_switch_register()
381 sw->module = parent->driver->owner; in usb_role_switch_register()
382 sw->dev.parent = parent; in usb_role_switch_register()
383 sw->dev.fwnode = desc->fwnode; in usb_role_switch_register()
384 sw->dev.class = &role_class; in usb_role_switch_register()
385 sw->dev.type = &usb_role_dev_type; in usb_role_switch_register()
386 dev_set_drvdata(&sw->dev, desc->driver_data); in usb_role_switch_register()
387 dev_set_name(&sw->dev, "%s-role-switch", in usb_role_switch_register()
390 ret = device_register(&sw->dev); in usb_role_switch_register()
392 put_device(&sw->dev); in usb_role_switch_register()
396 if (dev_fwnode(&sw->dev)) { in usb_role_switch_register()
397 ret = component_add(&sw->dev, &connector_ops); in usb_role_switch_register()
399 dev_warn(&sw->dev, "failed to add component\n"); in usb_role_switch_register()
402 sw->registered = true; in usb_role_switch_register()
406 return sw; in usb_role_switch_register()
416 void usb_role_switch_unregister(struct usb_role_switch *sw) in usb_role_switch_unregister() argument
418 if (IS_ERR_OR_NULL(sw)) in usb_role_switch_unregister()
420 sw->registered = false; in usb_role_switch_unregister()
421 if (dev_fwnode(&sw->dev)) in usb_role_switch_unregister()
422 component_del(&sw->dev, &connector_ops); in usb_role_switch_unregister()
423 device_unregister(&sw->dev); in usb_role_switch_unregister()
432 void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data) in usb_role_switch_set_drvdata() argument
434 dev_set_drvdata(&sw->dev, data); in usb_role_switch_set_drvdata()
442 void *usb_role_switch_get_drvdata(struct usb_role_switch *sw) in usb_role_switch_get_drvdata() argument
444 return dev_get_drvdata(&sw->dev); in usb_role_switch_get_drvdata()