Commit 69af044a authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Greg Kroah-Hartman

usb: roles: Leave the private driver data pointer to the drivers

Adding usb_role_switch_get/set_drvdata() functions that the
switch drivers can use for setting and getting private data
pointer that is associated with the switch.
Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20200302135353.56659-5-heikki.krogerus@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d1c6a769
...@@ -329,6 +329,7 @@ usb_role_switch_register(struct device *parent, ...@@ -329,6 +329,7 @@ usb_role_switch_register(struct device *parent,
sw->dev.fwnode = desc->fwnode; sw->dev.fwnode = desc->fwnode;
sw->dev.class = role_class; sw->dev.class = role_class;
sw->dev.type = &usb_role_dev_type; sw->dev.type = &usb_role_dev_type;
dev_set_drvdata(&sw->dev, desc->driver_data);
dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent)); dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent));
ret = device_register(&sw->dev); ret = device_register(&sw->dev);
...@@ -356,6 +357,27 @@ void usb_role_switch_unregister(struct usb_role_switch *sw) ...@@ -356,6 +357,27 @@ void usb_role_switch_unregister(struct usb_role_switch *sw)
} }
EXPORT_SYMBOL_GPL(usb_role_switch_unregister); EXPORT_SYMBOL_GPL(usb_role_switch_unregister);
/**
* usb_role_switch_set_drvdata - Assign private data pointer to a switch
* @sw: USB Role Switch
* @data: Private data pointer
*/
void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
{
dev_set_drvdata(&sw->dev, data);
}
EXPORT_SYMBOL_GPL(usb_role_switch_set_drvdata);
/**
* usb_role_switch_get_drvdata - Get the private data pointer of a switch
* @sw: USB Role Switch
*/
void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
{
return dev_get_drvdata(&sw->dev);
}
EXPORT_SYMBOL_GPL(usb_role_switch_get_drvdata);
static int __init usb_roles_init(void) static int __init usb_roles_init(void)
{ {
role_class = class_create(THIS_MODULE, "usb_role"); role_class = class_create(THIS_MODULE, "usb_role");
......
...@@ -25,6 +25,7 @@ typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev); ...@@ -25,6 +25,7 @@ typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev);
* @set: Callback for setting the role * @set: Callback for setting the role
* @get: Callback for getting the role (optional) * @get: Callback for getting the role (optional)
* @allow_userspace_control: If true userspace may change the role through sysfs * @allow_userspace_control: If true userspace may change the role through sysfs
* @driver_data: Private data pointer
* *
* @usb2_port and @usb3_port will point to the USB host port and @udc to the USB * @usb2_port and @usb3_port will point to the USB host port and @udc to the USB
* device controller behind the USB connector with the role switch. If * device controller behind the USB connector with the role switch. If
...@@ -40,6 +41,7 @@ struct usb_role_switch_desc { ...@@ -40,6 +41,7 @@ struct usb_role_switch_desc {
usb_role_switch_set_t set; usb_role_switch_set_t set;
usb_role_switch_get_t get; usb_role_switch_get_t get;
bool allow_userspace_control; bool allow_userspace_control;
void *driver_data;
}; };
...@@ -57,6 +59,9 @@ struct usb_role_switch * ...@@ -57,6 +59,9 @@ struct usb_role_switch *
usb_role_switch_register(struct device *parent, usb_role_switch_register(struct device *parent,
const struct usb_role_switch_desc *desc); const struct usb_role_switch_desc *desc);
void usb_role_switch_unregister(struct usb_role_switch *sw); void usb_role_switch_unregister(struct usb_role_switch *sw);
void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data);
void *usb_role_switch_get_drvdata(struct usb_role_switch *sw);
#else #else
static inline int usb_role_switch_set_role(struct usb_role_switch *sw, static inline int usb_role_switch_set_role(struct usb_role_switch *sw,
enum usb_role role) enum usb_role role)
...@@ -90,6 +95,17 @@ usb_role_switch_register(struct device *parent, ...@@ -90,6 +95,17 @@ usb_role_switch_register(struct device *parent,
} }
static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { } static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }
static inline void
usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
{
}
static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
{
return NULL;
}
#endif #endif
#endif /* __LINUX_USB_ROLE_H */ #endif /* __LINUX_USB_ROLE_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment