Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Heikki Krogerus and committed by
Greg Kroah-Hartman
69af044a d1c6a769

+38
+22
drivers/usb/roles/class.c
··· 329 329 sw->dev.fwnode = desc->fwnode; 330 330 sw->dev.class = role_class; 331 331 sw->dev.type = &usb_role_dev_type; 332 + dev_set_drvdata(&sw->dev, desc->driver_data); 332 333 dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent)); 333 334 334 335 ret = device_register(&sw->dev); ··· 356 355 device_unregister(&sw->dev); 357 356 } 358 357 EXPORT_SYMBOL_GPL(usb_role_switch_unregister); 358 + 359 + /** 360 + * usb_role_switch_set_drvdata - Assign private data pointer to a switch 361 + * @sw: USB Role Switch 362 + * @data: Private data pointer 363 + */ 364 + void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data) 365 + { 366 + dev_set_drvdata(&sw->dev, data); 367 + } 368 + EXPORT_SYMBOL_GPL(usb_role_switch_set_drvdata); 369 + 370 + /** 371 + * usb_role_switch_get_drvdata - Get the private data pointer of a switch 372 + * @sw: USB Role Switch 373 + */ 374 + void *usb_role_switch_get_drvdata(struct usb_role_switch *sw) 375 + { 376 + return dev_get_drvdata(&sw->dev); 377 + } 378 + EXPORT_SYMBOL_GPL(usb_role_switch_get_drvdata); 359 379 360 380 static int __init usb_roles_init(void) 361 381 {
+16
include/linux/usb/role.h
··· 25 25 * @set: Callback for setting the role 26 26 * @get: Callback for getting the role (optional) 27 27 * @allow_userspace_control: If true userspace may change the role through sysfs 28 + * @driver_data: Private data pointer 28 29 * 29 30 * @usb2_port and @usb3_port will point to the USB host port and @udc to the USB 30 31 * device controller behind the USB connector with the role switch. If ··· 41 40 usb_role_switch_set_t set; 42 41 usb_role_switch_get_t get; 43 42 bool allow_userspace_control; 43 + void *driver_data; 44 44 }; 45 45 46 46 ··· 59 57 usb_role_switch_register(struct device *parent, 60 58 const struct usb_role_switch_desc *desc); 61 59 void usb_role_switch_unregister(struct usb_role_switch *sw); 60 + 61 + void usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data); 62 + void *usb_role_switch_get_drvdata(struct usb_role_switch *sw); 62 63 #else 63 64 static inline int usb_role_switch_set_role(struct usb_role_switch *sw, 64 65 enum usb_role role) ··· 95 90 } 96 91 97 92 static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { } 93 + 94 + static inline void 95 + usb_role_switch_set_drvdata(struct usb_role_switch *sw, void *data) 96 + { 97 + } 98 + 99 + static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw) 100 + { 101 + return NULL; 102 + } 103 + 98 104 #endif 99 105 100 106 #endif /* __LINUX_USB_ROLE_H */