History

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.

Heikki Krogerus committed 6 years ago

Commit 69af0441 parent d1c6a762 files · +38 −0Browse files

Unified · Split

2 files
  1. drivers/usb/roles/class.c +22 −0
  2. include/linux/usb/role.h +16 −0
drivers/usb/roles/class.c+22−0
@@ -329,6 +329,7 @@ usb_role_switch_register(struct device *parent, · 328 unmodified lines
329 sw->dev.fwnode = desc->fwnode;329 sw->dev.fwnode = desc->fwnode;
330 sw->dev.class = role_class;330 sw->dev.class = role_class;
331 sw->dev.type = &usb_role_dev_type;331 sw->dev.type = &usb_role_dev_type;
332 dev_set_drvdata(&sw->dev, desc->driver_data);
332 dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent));333 dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent));
333 334
334 ret = device_register(&sw->dev);335 ret = device_register(&sw->dev);
@@ -356,6 +357,27 @@ void usb_role_switch_unregister(struct usb_role_switch *sw) · 21 unmodified lines
356}357}
357EXPORT_SYMBOL_GPL(usb_role_switch_unregister);358EXPORT_SYMBOL_GPL(usb_role_switch_unregister);
358 359
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 */
365void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
366{
367 dev_set_drvdata(&sw->dev, data);
368}
369EXPORT_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 */
375void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
376{
377 return dev_get_drvdata(&sw->dev);
378}
379EXPORT_SYMBOL_GPL(usb_role_switch_get_drvdata);
380
359static int __init usb_roles_init(void)381static int __init usb_roles_init(void)
360{382{
361 role_class = class_create(THIS_MODULE, "usb_role");383 role_class = class_create(THIS_MODULE, "usb_role");
include/linux/usb/role.h+16−0
@@ -25,6 +25,7 @@ typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev); · 24 unmodified lines
25 * @set: Callback for setting the role25 * @set: Callback for setting the role
26 * @get: Callback for getting the role (optional)26 * @get: Callback for getting the role (optional)
27 * @allow_userspace_control: If true userspace may change the role through sysfs27 * @allow_userspace_control: If true userspace may change the role through sysfs
28 * @driver_data: Private data pointer
28 *29 *
29 * @usb2_port and @usb3_port will point to the USB host port and @udc to the USB30 * @usb2_port and @usb3_port will point to the USB host port and @udc to the USB
30 * device controller behind the USB connector with the role switch. If31 * device controller behind the USB connector with the role switch. If
@@ -40,6 +41,7 @@ struct usb_role_switch_desc { · 9 unmodified lines
40 usb_role_switch_set_t set;41 usb_role_switch_set_t set;
41 usb_role_switch_get_t get;42 usb_role_switch_get_t get;
42 bool allow_userspace_control;43 bool allow_userspace_control;
44 void *driver_data;
43};45};
44 46
45 47
@@ -57,6 +59,9 @@ struct usb_role_switch * · 11 unmodified lines
57usb_role_switch_register(struct device *parent,59usb_role_switch_register(struct device *parent,
58 const struct usb_role_switch_desc *desc);60 const struct usb_role_switch_desc *desc);
59void usb_role_switch_unregister(struct usb_role_switch *sw);61void usb_role_switch_unregister(struct usb_role_switch *sw);
62
63void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data);
64void *usb_role_switch_get_drvdata(struct usb_role_switch *sw);
60#else65#else
61static inline int usb_role_switch_set_role(struct usb_role_switch *sw,66static inline int usb_role_switch_set_role(struct usb_role_switch *sw,
62 enum usb_role role)67 enum usb_role role)
@@ -90,6 +95,17 @@ usb_role_switch_register(struct device *parent, · 27 unmodified lines
90}95}
91 96
92static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }97static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }
98
99static inline void
100usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data)
101{
102}
103
104static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)
105{
106 return NULL;
107}
108
93#endif109#endif
94 110
95#endif /* __LINUX_USB_ROLE_H */111#endif /* __LINUX_USB_ROLE_H */