From: Jean-Jacques Hiblot Date: Thu, 29 Nov 2018 09:52:43 +0000 (+0100) Subject: usb: udc: implement DM versions of usb_gadget_initialize()/_release()/_handle_interrupt() X-Git-Tag: v2019.01-rc2~17^2~18 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ff8d75583487eb69bcb6f036088d979c76db3753;p=oweals%2Fu-boot.git usb: udc: implement DM versions of usb_gadget_initialize()/_release()/_handle_interrupt() When DM_USB_GADGET the platform code for the USB device must be replaced by calls to a USB device driver. usb_gadget_initialize() probes the USB device driver. usb_gadget_release() removes the USB device driver. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Lukasz Majewski --- diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index ad3a116b3e..47cc140ddf 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -22,19 +22,9 @@ #include "linux-compat.h" #if CONFIG_IS_ENABLED(DM_USB_GADGET) -int usb_gadget_handle_interrupts(int index) +int dm_usb_gadget_handle_interrupts(struct udevice *dev) { - struct dwc3 *priv; - struct udevice *dev; - int ret; - - ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev); - if (!dev || ret) { - pr_err("No USB device found\n"); - return -ENODEV; - } - - priv = dev_get_priv(dev); + struct dwc3 *priv = dev_get_priv(dev); dwc3_gadget_uboot_handle_interrupt(priv); diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index f5c30dd750..34bea27ad8 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -18,7 +18,8 @@ #include #include #include - +#include +#include #include #include @@ -351,3 +352,44 @@ EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver); MODULE_DESCRIPTION("UDC Framework"); MODULE_AUTHOR("Felipe Balbi "); MODULE_LICENSE("GPL v2"); + +#if CONFIG_IS_ENABLED(DM_USB_GADGET) +#define MAX_UDC_DEVICES 4 +static struct udevice *dev_array[MAX_UDC_DEVICES]; +int usb_gadget_initialize(int index) +{ + int ret; + struct udevice *dev = NULL; + + if (index < 0 || index >= ARRAY_SIZE(dev_array)) + return -EINVAL; + if (dev_array[index]) + return 0; + ret = uclass_get_device(UCLASS_USB_DEV_GENERIC, index, &dev); + if (!dev || ret) { + pr_err("No USB device found\n"); + return -ENODEV; + } + dev_array[index] = dev; + return 0; +} + +int usb_gadget_release(int index) +{ + int ret; + + if (index < 0 || index >= ARRAY_SIZE(dev_array)) + return -EINVAL; + ret = device_remove(dev_array[index], DM_REMOVE_NORMAL); + if (!ret) + dev_array[index] = NULL; + return ret; +} + +int usb_gadget_handle_interrupts(int index) +{ + if (index < 0 || index >= ARRAY_SIZE(dev_array)) + return -EINVAL; + return dm_usb_gadget_handle_interrupts(dev_array[index]); +} +#endif diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 40ca2d3468..497798a32a 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -927,6 +927,12 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *); extern int usb_gadget_handle_interrupts(int index); +#if CONFIG_IS_ENABLED(DM_USB_GADGET) +int usb_gadget_initialize(int index); +int usb_gadget_release(int index); +int dm_usb_gadget_handle_interrupts(struct udevice *dev); +#else +#include static inline int usb_gadget_initialize(int index) { return board_usb_init(index, USB_INIT_DEVICE); @@ -936,4 +942,6 @@ static inline int usb_gadget_release(int index) { return board_usb_cleanup(index, USB_INIT_DEVICE); } +#endif + #endif /* __LINUX_USB_GADGET_H */