Commit 0131162439508801b9f8a330fa731f04273c9337

Authored by Jean-Jacques Hiblot
Committed by Marek Vasut
1 parent d648a50c0a

dm: usb: create a new UCLASS ID for USB gadget devices

UCLASS_USB_DEV_GENERIC was meant for USB devices connected to host
controllers, not gadget devices.
Adding a new UCLASS for gadget devices alone.

Also move the generic DM code for USB gadgets in a separate file for
clarity.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

Showing 9 changed files with 68 additions and 46 deletions Side-by-side Diff

... ... @@ -663,7 +663,7 @@
663 663 struct phy phy;
664 664 int ret;
665 665  
666   - ret = uclass_get_device(UCLASS_USB_DEV_GENERIC, 0, &dev);
  666 + ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, 0, &dev);
667 667 if (ret) {
668 668 pr_err("%s: Cannot find USB device\n", __func__);
669 669 return ret;
drivers/usb/dwc3/dwc3-generic.c
... ... @@ -72,7 +72,7 @@
72 72  
73 73 U_BOOT_DRIVER(dwc3_generic_peripheral) = {
74 74 .name = "dwc3-generic-peripheral",
75   - .id = UCLASS_USB_DEV_GENERIC,
  75 + .id = UCLASS_USB_GADGET_GENERIC,
76 76 .ofdata_to_platdata = dwc3_generic_peripheral_ofdata_to_platdata,
77 77 .probe = dwc3_generic_peripheral_probe,
78 78 .remove = dwc3_generic_peripheral_remove,
drivers/usb/gadget/ether.c
... ... @@ -2671,7 +2671,7 @@
2671 2671 struct udevice *usb_dev;
2672 2672 int ret;
2673 2673  
2674   - ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &usb_dev);
  2674 + ret = uclass_first_device(UCLASS_USB_GADGET_GENERIC, &usb_dev);
2675 2675 if (!usb_dev || ret) {
2676 2676 pr_err("No USB device found\n");
2677 2677 return ret;
drivers/usb/gadget/udc/Makefile
... ... @@ -2,5 +2,9 @@
2 2 #
3 3 # USB peripheral controller drivers
4 4  
  5 +ifndef CONFIG_$(SPL_)DM_USB_GADGET
5 6 obj-$(CONFIG_USB_DWC3_GADGET) += udc-core.o
  7 +endif
  8 +
  9 +obj-$(CONFIG_$(SPL_)DM_USB_GADGET) += udc-uclass.o udc-core.o
drivers/usb/gadget/udc/udc-core.c
... ... @@ -352,45 +352,4 @@
352 352 MODULE_DESCRIPTION("UDC Framework");
353 353 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
354 354 MODULE_LICENSE("GPL v2");
355   -
356   -#if CONFIG_IS_ENABLED(DM_USB_GADGET)
357   -#define MAX_UDC_DEVICES 4
358   -static struct udevice *dev_array[MAX_UDC_DEVICES];
359   -int usb_gadget_initialize(int index)
360   -{
361   - int ret;
362   - struct udevice *dev = NULL;
363   -
364   - if (index < 0 || index >= ARRAY_SIZE(dev_array))
365   - return -EINVAL;
366   - if (dev_array[index])
367   - return 0;
368   - ret = uclass_get_device(UCLASS_USB_DEV_GENERIC, index, &dev);
369   - if (!dev || ret) {
370   - pr_err("No USB device found\n");
371   - return -ENODEV;
372   - }
373   - dev_array[index] = dev;
374   - return 0;
375   -}
376   -
377   -int usb_gadget_release(int index)
378   -{
379   - int ret;
380   -
381   - if (index < 0 || index >= ARRAY_SIZE(dev_array))
382   - return -EINVAL;
383   - ret = device_remove(dev_array[index], DM_REMOVE_NORMAL);
384   - if (!ret)
385   - dev_array[index] = NULL;
386   - return ret;
387   -}
388   -
389   -int usb_gadget_handle_interrupts(int index)
390   -{
391   - if (index < 0 || index >= ARRAY_SIZE(dev_array))
392   - return -EINVAL;
393   - return dm_usb_gadget_handle_interrupts(dev_array[index]);
394   -}
395   -#endif
drivers/usb/gadget/udc/udc-uclass.c
  1 +// SPDX-License-Identifier: GPL-2.0+
  2 +/*
  3 + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
  4 + * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <dm.h>
  9 +#include <dm/device-internal.h>
  10 +#include <linux/usb/gadget.h>
  11 +
  12 +#define MAX_UDC_DEVICES 4
  13 +static struct udevice *dev_array[MAX_UDC_DEVICES];
  14 +int usb_gadget_initialize(int index)
  15 +{
  16 + int ret;
  17 + struct udevice *dev = NULL;
  18 +
  19 + if (index < 0 || index >= ARRAY_SIZE(dev_array))
  20 + return -EINVAL;
  21 + if (dev_array[index])
  22 + return 0;
  23 + ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, index, &dev);
  24 + if (!dev || ret) {
  25 + pr_err("No USB device found\n");
  26 + return -ENODEV;
  27 + }
  28 + dev_array[index] = dev;
  29 + return 0;
  30 +}
  31 +
  32 +int usb_gadget_release(int index)
  33 +{
  34 +#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
  35 + int ret;
  36 + if (index < 0 || index >= ARRAY_SIZE(dev_array))
  37 + return -EINVAL;
  38 +
  39 + ret = device_remove(dev_array[index], DM_REMOVE_NORMAL);
  40 + if (!ret)
  41 + dev_array[index] = NULL;
  42 + return ret;
  43 +#else
  44 + return -ENOTSUPP;
  45 +#endif
  46 +}
  47 +
  48 +int usb_gadget_handle_interrupts(int index)
  49 +{
  50 + if (index < 0 || index >= ARRAY_SIZE(dev_array))
  51 + return -EINVAL;
  52 + return dm_usb_gadget_handle_interrupts(dev_array[index]);
  53 +}
  54 +
  55 +UCLASS_DRIVER(usb_gadget_generic) = {
  56 + .id = UCLASS_USB_GADGET_GENERIC,
  57 + .name = "usb_gadget_generic",
  58 +};
drivers/usb/musb-new/omap2430.c
... ... @@ -263,7 +263,7 @@
263 263 #ifdef CONFIG_USB_MUSB_HOST
264 264 .id = UCLASS_USB,
265 265 #else
266   - .id = UCLASS_USB_DEV_GENERIC,
  266 + .id = UCLASS_USB_GADGET_GENERIC,
267 267 #endif
268 268 .of_match = omap2430_musb_ids,
269 269 .ofdata_to_platdata = omap2430_musb_ofdata_to_platdata,
drivers/usb/musb-new/sunxi.c
... ... @@ -535,7 +535,7 @@
535 535 #ifdef CONFIG_USB_MUSB_HOST
536 536 .id = UCLASS_USB,
537 537 #else
538   - .id = UCLASS_USB_DEV_GENERIC,
  538 + .id = UCLASS_USB_GADGET_GENERIC,
539 539 #endif
540 540 .of_match = sunxi_musb_ids,
541 541 .probe = musb_usb_probe,
include/dm/uclass-id.h
... ... @@ -93,6 +93,7 @@
93 93 UCLASS_USB, /* USB bus */
94 94 UCLASS_USB_DEV_GENERIC, /* USB generic device */
95 95 UCLASS_USB_HUB, /* USB hub */
  96 + UCLASS_USB_GADGET_GENERIC, /* USB generic device */
96 97 UCLASS_VIDEO, /* Video or LCD device */
97 98 UCLASS_VIDEO_BRIDGE, /* Video bridge, e.g. DisplayPort to LVDS */
98 99 UCLASS_VIDEO_CONSOLE, /* Text console driver for video device */