]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/usb/gadget/udc/udc-uclass.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / drivers / usb / gadget / udc / udc-uclass.c
CommitLineData
01311624
JJH
1// SPDX-License-Identifier: GPL-2.0+
2/*
a94a4071 3 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com
01311624
JJH
4 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
5 */
6
b953ec2b
PD
7#define LOG_CATEGORY UCLASS_USB_GADGET_GENERIC
8
d678a59d 9#include <common.h>
01311624
JJH
10#include <dm.h>
11#include <dm/device-internal.h>
1e94b46f 12#include <linux/printk.h>
01311624
JJH
13#include <linux/usb/gadget.h>
14
b3c518a8 15#if CONFIG_IS_ENABLED(DM_USB_GADGET)
a1fa8bbb
MV
16int udc_device_get_by_index(int index, struct udevice **udev)
17{
18 struct udevice *dev = NULL;
19 int ret;
20
21 ret = uclass_get_device_by_seq(UCLASS_USB_GADGET_GENERIC, index, &dev);
22 if (!ret && dev) {
23 *udev = dev;
24 return 0;
25 }
26
27 ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, index, &dev);
28 if (!ret && dev) {
29 *udev = dev;
30 return 0;
31 }
32
33 pr_err("No USB device found\n");
34 return -ENODEV;
35}
36
37int udc_device_put(struct udevice *udev)
38{
39#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
40 return device_remove(udev, DM_REMOVE_NORMAL);
41#else
42 return -ENOSYS;
43#endif
44}
a1fa8bbb
MV
45#else
46/* Backwards hardware compatibility -- switch to DM_USB_GADGET */
47static int legacy_index;
48int udc_device_get_by_index(int index, struct udevice **udev)
49{
50 legacy_index = index;
51 return board_usb_init(index, USB_INIT_DEVICE);
52}
53
54int udc_device_put(struct udevice *udev)
55{
56 return board_usb_cleanup(legacy_index, USB_INIT_DEVICE);
57}
b3c518a8 58#endif
01311624 59
a1fa8bbb 60#if CONFIG_IS_ENABLED(DM)
01311624
JJH
61UCLASS_DRIVER(usb_gadget_generic) = {
62 .id = UCLASS_USB_GADGET_GENERIC,
801f1fa4
JJH
63 .name = "usb",
64 .flags = DM_UC_FLAG_SEQ_ALIAS,
01311624 65};
a1fa8bbb 66#endif