1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
4 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
9 #include <dm/device-internal.h>
10 #include <linux/usb/gadget.h>
12 #if CONFIG_IS_ENABLED(DM_USB_GADGET)
13 #define MAX_UDC_DEVICES 4
14 static struct udevice *dev_array[MAX_UDC_DEVICES];
15 int usb_gadget_initialize(int index)
18 struct udevice *dev = NULL;
20 if (index < 0 || index >= ARRAY_SIZE(dev_array))
24 ret = uclass_get_device_by_seq(UCLASS_USB_GADGET_GENERIC, index, &dev);
26 pr_err("No USB device found\n");
29 dev_array[index] = dev;
33 int usb_gadget_release(int index)
35 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
37 if (index < 0 || index >= ARRAY_SIZE(dev_array))
40 ret = device_remove(dev_array[index], DM_REMOVE_NORMAL);
42 dev_array[index] = NULL;
49 int usb_gadget_handle_interrupts(int index)
51 if (index < 0 || index >= ARRAY_SIZE(dev_array))
53 return dm_usb_gadget_handle_interrupts(dev_array[index]);
57 UCLASS_DRIVER(usb_gadget_generic) = {
58 .id = UCLASS_USB_GADGET_GENERIC,
60 .flags = DM_UC_FLAG_SEQ_ALIAS,