Lines Matching refs:sw
38 * @sw: USB role switch
41 * Set USB role @role for @sw.
43 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role)
47 if (IS_ERR_OR_NULL(sw))
50 mutex_lock(&sw->lock);
52 ret = sw->set(sw, role);
54 sw->role = role;
55 kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE);
58 mutex_unlock(&sw->lock);
66 * @sw: USB role switch
71 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
75 if (IS_ERR_OR_NULL(sw))
78 mutex_lock(&sw->lock);
80 if (sw->get)
81 role = sw->get(sw);
83 role = sw->role;
85 mutex_unlock(&sw->lock);
129 struct usb_role_switch *sw;
131 sw = usb_role_switch_is_parent(dev_fwnode(dev));
132 if (!sw)
133 sw = device_connection_find_match(dev, "usb-role-switch", NULL,
136 if (!IS_ERR_OR_NULL(sw))
137 WARN_ON(!try_module_get(sw->module));
139 return sw;
152 struct usb_role_switch *sw;
154 sw = usb_role_switch_is_parent(fwnode);
155 if (!sw)
156 sw = fwnode_connection_find_match(fwnode, "usb-role-switch",
158 if (!IS_ERR_OR_NULL(sw))
159 WARN_ON(!try_module_get(sw->module));
161 return sw;
167 * @sw: USB Role Switch
169 * Decrement reference count for @sw.
171 void usb_role_switch_put(struct usb_role_switch *sw)
173 if (!IS_ERR_OR_NULL(sw)) {
174 module_put(sw->module);
175 put_device(&sw->dev);
191 struct usb_role_switch *sw = NULL;
198 sw = to_role_switch(dev);
199 WARN_ON(!try_module_get(sw->module));
202 return sw;
210 struct usb_role_switch *sw = to_role_switch(dev);
212 if (sw->allow_userspace_control)
227 struct usb_role_switch *sw = to_role_switch(dev);
228 enum usb_role role = usb_role_switch_get_role(sw);
236 struct usb_role_switch *sw = to_role_switch(dev);
249 ret = usb_role_switch_set_role(sw, ret);
286 struct usb_role_switch *sw = to_role_switch(dev);
288 kfree(sw);
316 struct usb_role_switch *sw;
322 sw = kzalloc(sizeof(*sw), GFP_KERNEL);
323 if (!sw)
326 mutex_init(&sw->lock);
328 sw->allow_userspace_control = desc->allow_userspace_control;
329 sw->usb2_port = desc->usb2_port;
330 sw->usb3_port = desc->usb3_port;
331 sw->udc = desc->udc;
332 sw->set = desc->set;
333 sw->get = desc->get;
335 sw->module = parent->driver->owner;
336 sw->dev.parent = parent;
337 sw->dev.fwnode = desc->fwnode;
338 sw->dev.class = role_class;
339 sw->dev.type = &usb_role_dev_type;
340 dev_set_drvdata(&sw->dev, desc->driver_data);
341 dev_set_name(&sw->dev, "%s-role-switch",
344 ret = device_register(&sw->dev);
346 put_device(&sw->dev);
352 return sw;
358 * @sw: USB Role Switch
362 void usb_role_switch_unregister(struct usb_role_switch *sw)
364 if (!IS_ERR_OR_NULL(sw))
365 device_unregister(&sw->dev);
371 * @sw: USB Role Switch
374 void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
376 dev_set_drvdata(&sw->dev, data);
382 * @sw: USB Role Switch
384 void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
386 return dev_get_drvdata(&sw->dev);