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>
7 #define LOG_CATEGORY UCLASS_USB_GADGET_GENERIC
11 #include <dm/device-internal.h>
12 #include <linux/printk.h>
13 #include <linux/usb/gadget.h>
15 #if CONFIG_IS_ENABLED(DM_USB_GADGET)
16 int udc_device_get_by_index(int index
, struct udevice
**udev
)
18 struct udevice
*dev
= NULL
;
21 ret
= uclass_get_device_by_seq(UCLASS_USB_GADGET_GENERIC
, index
, &dev
);
27 ret
= uclass_get_device(UCLASS_USB_GADGET_GENERIC
, index
, &dev
);
33 pr_err("No USB device found\n");
37 int udc_device_put(struct udevice
*udev
)
39 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
40 return device_remove(udev
, DM_REMOVE_NORMAL
);
46 /* Backwards hardware compatibility -- switch to DM_USB_GADGET */
47 static int legacy_index
;
48 int udc_device_get_by_index(int index
, struct udevice
**udev
)
51 return board_usb_init(index
, USB_INIT_DEVICE
);
54 int udc_device_put(struct udevice
*udev
)
56 return board_usb_cleanup(legacy_index
, USB_INIT_DEVICE
);
60 #if CONFIG_IS_ENABLED(DM)
61 UCLASS_DRIVER(usb_gadget_generic
) = {
62 .id
= UCLASS_USB_GADGET_GENERIC
,
64 .flags
= DM_UC_FLAG_SEQ_ALIAS
,