• Home
  • Raw
  • Download

Lines Matching +full:usb +full:- +full:role +full:- +full:switch

1 // SPDX-License-Identifier: GPL-2.0
3 * USB Role Switch Support
10 #include <linux/usb/role.h>
21 enum usb_role role; member
35 * usb_role_switch_set_role - Set USB role for a switch
36 * @sw: USB role switch
37 * @role: USB role to be switched to
39 * Set USB role @role for @sw.
41 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role) in usb_role_switch_set_role() argument
48 mutex_lock(&sw->lock); in usb_role_switch_set_role()
50 ret = sw->set(sw->dev.parent, role); in usb_role_switch_set_role()
52 sw->role = role; in usb_role_switch_set_role()
54 mutex_unlock(&sw->lock); in usb_role_switch_set_role()
61 * usb_role_switch_get_role - Get the USB role for a switch
62 * @sw: USB role switch
64 * Depending on the role-switch-driver this function returns either a cached
65 * value of the last set role, or reads back the actual value from the hardware.
69 enum usb_role role; in usb_role_switch_get_role() local
74 mutex_lock(&sw->lock); in usb_role_switch_get_role()
76 if (sw->get) in usb_role_switch_get_role()
77 role = sw->get(sw->dev.parent); in usb_role_switch_get_role()
79 role = sw->role; in usb_role_switch_get_role()
81 mutex_unlock(&sw->lock); in usb_role_switch_get_role()
83 return role; in usb_role_switch_get_role()
97 dev = class_find_device(role_class, NULL, con->endpoint[ep], in usb_role_switch_match()
100 return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); in usb_role_switch_match()
104 * usb_role_switch_get - Find USB role switch linked with the caller
107 * Finds and returns role switch linked with @dev. The reference count for the
108 * found switch is incremented.
114 sw = device_connection_find_match(dev, "usb-role-switch", NULL, in usb_role_switch_get()
118 WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); in usb_role_switch_get()
125 * usb_role_switch_put - Release handle to a switch
126 * @sw: USB Role Switch
133 module_put(sw->dev.parent->driver->owner); in usb_role_switch_put()
134 put_device(&sw->dev); in usb_role_switch_put()
145 if (sw->allow_userspace_control) in usb_role_switch_is_visible()
146 return attr->mode; in usb_role_switch_is_visible()
161 enum usb_role role = usb_role_switch_get_role(sw); in role_show() local
163 return sprintf(buf, "%s\n", usb_roles[role]); in role_show()
176 /* Extra check if the user wants to disable the switch */ in role_store()
179 return -EINVAL; in role_store()
188 static DEVICE_ATTR_RW(role);
232 * usb_role_switch_register - Register USB Role Switch
233 * @parent: Parent device for the switch
234 * @desc: Description of the switch
236 * USB Role Switch is a device capable or choosing the role for USB connector.
237 * On platforms where the USB controller is dual-role capable, the controller
238 * driver will need to register the switch. On platforms where the USB host and
239 * USB device controllers behind the connector are separate, there will be a
240 * mux, and the driver for that mux will need to register the switch.
242 * Returns handle to a new role switch or ERR_PTR. The content of @desc is
252 if (!desc || !desc->set) in usb_role_switch_register()
253 return ERR_PTR(-EINVAL); in usb_role_switch_register()
257 return ERR_PTR(-ENOMEM); in usb_role_switch_register()
259 mutex_init(&sw->lock); in usb_role_switch_register()
261 sw->allow_userspace_control = desc->allow_userspace_control; in usb_role_switch_register()
262 sw->usb2_port = desc->usb2_port; in usb_role_switch_register()
263 sw->usb3_port = desc->usb3_port; in usb_role_switch_register()
264 sw->udc = desc->udc; in usb_role_switch_register()
265 sw->set = desc->set; in usb_role_switch_register()
266 sw->get = desc->get; in usb_role_switch_register()
268 sw->dev.parent = parent; in usb_role_switch_register()
269 sw->dev.class = role_class; in usb_role_switch_register()
270 sw->dev.type = &usb_role_dev_type; in usb_role_switch_register()
271 dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent)); in usb_role_switch_register()
273 ret = device_register(&sw->dev); in usb_role_switch_register()
275 put_device(&sw->dev); in usb_role_switch_register()
286 * usb_role_switch_unregister - Unregsiter USB Role Switch
287 * @sw: USB Role Switch
289 * Unregister switch that was registered with usb_role_switch_register().
294 device_unregister(&sw->dev); in usb_role_switch_unregister()
314 MODULE_DESCRIPTION("USB Role Class");