Skip to content

Commit 69af044

Browse files
Heikki Krogerusgregkh
authored andcommitted
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: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20200302135353.56659-5-heikki.krogerus@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d1c6a76 commit 69af044

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎drivers/usb/roles/class.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ usb_role_switch_register(struct device *parent,
329329
sw->dev.fwnode = desc->fwnode;
330330
sw->dev.class = role_class;
331331
sw->dev.type = &usb_role_dev_type;
332+
dev_set_drvdata(&sw->dev, desc->driver_data);
332333
dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent));
333334

334335
ret = device_register(&sw->dev);
@@ -356,6 +357,27 @@ void usb_role_switch_unregister(struct usb_role_switch *sw)
356357
}
357358
EXPORT_SYMBOL_GPL(usb_role_switch_unregister);
358359

360+
/**
361+
* usb_role_switch_set_drvdata - Assign private data pointer to a switch
362+
* @sw: USB Role Switch
363+
* @data: Private data pointer
364+
*/
365+
void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
366+
{
367+
dev_set_drvdata(&sw->dev, data);
368+
}
369+
EXPORT_SYMBOL_GPL(usb_role_switch_set_drvdata);
370+
371+
/**
372+
* usb_role_switch_get_drvdata - Get the private data pointer of a switch
373+
* @sw: USB Role Switch
374+
*/
375+
void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
376+
{
377+
return dev_get_drvdata(&sw->dev);
378+
}
379+
EXPORT_SYMBOL_GPL(usb_role_switch_get_drvdata);
380+
359381
static int __init usb_roles_init(void)
360382
{
361383
role_class = class_create(THIS_MODULE, "usb_role");

‎include/linux/usb/role.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev);
2525
* @set: Callback for setting the role
2626
* @get: Callback for getting the role (optional)
2727
* @allow_userspace_control: If true userspace may change the role through sysfs
28+
* @driver_data: Private data pointer
2829
*
2930
* @usb2_port and @usb3_port will point to the USB host port and @udc to the USB
3031
* device controller behind the USB connector with the role switch. If
@@ -40,6 +41,7 @@ struct usb_role_switch_desc {
4041
usb_role_switch_set_t set;
4142
usb_role_switch_get_t get;
4243
bool allow_userspace_control;
44+
void *driver_data;
4345
};
4446

4547

@@ -57,6 +59,9 @@ struct usb_role_switch *
5759
usb_role_switch_register(struct device *parent,
5860
const struct usb_role_switch_desc *desc);
5961
void usb_role_switch_unregister(struct usb_role_switch *sw);
62+
63+
void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data);
64+
void *usb_role_switch_get_drvdata(struct usb_role_switch *sw);
6065
#else
6166
static inline int usb_role_switch_set_role(struct usb_role_switch *sw,
6267
enum usb_role role)
@@ -90,6 +95,17 @@ usb_role_switch_register(struct device *parent,
9095
}
9196

9297
static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }
98+
99+
static inline void
100+
usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
101+
{
102+
}
103+
104+
static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
105+
{
106+
return NULL;
107+
}
108+
93109
#endif
94110

95111
#endif /* __LINUX_USB_ROLE_H */

0 commit comments

Comments
 (0)