[PATCH 3/3] usb: gadget: atmel: Add DM_USB_GADGET support

Marek Vasut marex at denx.de
Mon Jul 22 13:43:55 CEST 2024


On 7/22/24 10:47 AM, Zixun LI wrote:
> Add driver model support by using the uclass UCLASS_USB_GADGET_GENERIC.
> 
> Disable local usb_gadget_register_driver()/usb_gadget_unregister_driver()
> implementation which is implemented in udc-core.c when DM_USB_GADGET
> is enabled.
> 
> Compared to Linux driver only supported devices' DT bindings are included
> (sorted as Linux driver)
> 
> Signed-off-by: Zixun LI <zli at ogga.fr>
> ---
>   drivers/usb/gadget/atmel_usba_udc.c | 128 ++++++++++++++++++++++++++++
>   1 file changed, 128 insertions(+)
> 
> diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
> index 48d66d9774..664d33f525 100644
> --- a/drivers/usb/gadget/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/atmel_usba_udc.c
> @@ -8,10 +8,13 @@
>    */
>   
>   #include <clk.h>
> +#include <dm.h>
>   #include <log.h>
>   #include <malloc.h>
>   #include <asm/gpio.h>
>   #include <asm/hardware.h>
> +#include <dm/device_compat.h>
> +#include <dm/devres.h>
>   #include <linux/bitops.h>
>   #include <linux/errno.h>
>   #include <linux/list.h>
> @@ -19,6 +22,10 @@
>   #include <linux/usb/gadget.h>
>   #include <linux/usb/atmel_usba_udc.h>
>   
> +#if CONFIG_IS_ENABLED(DM_USB_GADGET)
> +#include <mach/atmel_usba_udc.h>
> +#endif /* CONFIG_IS_ENABLED(DM_USB_GADGET) */
> +
>   #include "atmel_usba_udc.h"
>   
>   static struct usba_udc *controller;
> @@ -1200,6 +1207,7 @@ int dm_usb_gadget_handle_interrupts(struct udevice *dev)
>   	return usba_udc_irq(udc);
>   }
>   
> +#if !CONFIG_IS_ENABLED(DM_USB_GADGET)
>   int usb_gadget_register_driver(struct usb_gadget_driver *driver)
>   {
>   	struct usba_udc *udc = controller;
> @@ -1245,6 +1253,49 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
>   
>   	return 0;
>   }
> +#else /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */
> +
> +static int usba_gadget_start(struct usb_gadget *g,
> +			     struct usb_gadget_driver *driver)
> +{
> +	struct usba_udc *udc = controller;
> +
> +	if (!driver || !driver->bind || !driver->setup) {
> +		log_err("bad parameter\n");

This check is unnecessary, please remove.

> +		return -EINVAL;
> +	}
> +
> +	if (udc->driver) {

This check is unnecessary, please remove.

> +		log_err("UDC already has a gadget driver\n");
> +		return -EBUSY;
> +	}
> +
> +	usba_enable(udc);
> +
> +	udc->driver = driver;
> +
> +	return 0;
> +}

The rest looks pretty good, thanks !


More information about the U-Boot mailing list