USB: UDC: Expand device model API interface
RFC PATCH 2/4 USB: UDC: Expand device model API interface
The routines used by the UDC core to interface with the kernel's device model, namely usb_add_gadget_udc(), usb_add_gadget_udc_release(), and usb_del_gadget_udc(), provide access to only a subset of the device model's full API. They include functionality equivalent to device_register() and device_unregister() for gadgets, but they omit device_initialize(), device_add(), device_del(), get_device(), and put_device().
This patch expands the UDC API by adding usb_initialize_gadget(), usb_add_gadget(), usb_del_gadget(), usb_get_gadget(), and usb_put_gadget() to fill in the gap. It rewrites the existing routines to call the new ones.
The next patches in this series fix longstanding problems in the net2280 and net2272 UDC drivers by making use of the expanded API.
---
drivers/usb/gadget/udc/core.c | 78 +++++++++++++++++++++++++++++++++--------- include/linux/usb/gadget.h | 27 +++++++++++--- 2 files changed, 84 insertions(+), 21 deletions(-)
include/linux/usb/gadget.h +21 -6
@@ -435,6 +435,7 @@ struct usb_gadget { };#define work_to_gadget (w) (container_of((w), struct usb_gadget, work)) +/* Interface to the device model */ static inline void set_gadget_data (struct usb_gadget *gadget,void *data) {dev_set_drvdata (&gadget->dev, data); }static inline void *get_gadget_data (struct usb_gadget *gadget)
@@ -443,6 +444,26 @@ static inline struct usb_gadget *dev_to_ { return container_of(dev, struct usb_gadget, dev); } +static inline struct usb_gadget *usb_get_gadget (struct usb_gadget *gadget) +{ +get_device (&gadget->dev); +return gadget; +} +static inline void usb_put_gadget (struct usb_gadget *gadget) +{ +put_device (&gadget->dev); +} +extern void usb_initialize_gadget (struct device *parent, +struct usb_gadget *gadget,void (*release)(struct device *dev)); +extern int usb_add_gadget (struct usb_gadget *gadget); +extern void usb_del_gadget (struct usb_gadget *gadget); + +/* Legacy device-model interface */ +extern int usb_add_gadget_udc_release (struct device *parent, +struct usb_gadget *gadget,void (*release)(struct device *dev)); +extern int usb_add_gadget_udc (struct device *parent,struct usb_gadget *gadget); +extern void usb_del_gadget_udc (struct usb_gadget *gadget); +extern char *usb_get_gadget_udc_name (void );/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ #define gadget_for_each_ep (tmp, gadget) \
@@ -734,12 +755,6 @@ int usb_gadget_probe_driver(struct usb_g*/ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver); -extern int usb_add_gadget_udc_release (struct device *parent, -struct usb_gadget *gadget,void (*release)(struct device *dev)); -extern int usb_add_gadget_udc (struct device *parent,struct usb_gadget *gadget); -extern void usb_del_gadget_udc (struct usb_gadget *gadget); -extern char *usb_get_gadget_udc_name (void ); -/*-------------------------------------------------------------------------*/ /* utility to simplify dealing with string descriptors */
drivers/usb/gadget/udc/core.c +63 -15
129 lines not on this page · raw message