Merge tag 'u-boot-rockchip-20200501' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / drivers / usb / gadget / ether.c
index 90ef1f0..8533abf 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <common.h>
 #include <console.h>
-#include <environment.h>
+#include <env.h>
 #include <linux/errno.h>
 #include <linux/netdevice.h>
 #include <linux/usb/ch9.h>
@@ -100,9 +100,6 @@ struct eth_dev {
        struct usb_gadget       *gadget;
        struct usb_request      *req;           /* for control responses */
        struct usb_request      *stat_req;      /* for cdc & rndis status */
-#ifdef CONFIG_DM_USB
-       struct udevice          *usb_udev;
-#endif
 
        u8                      config;
        struct usb_ep           *in_ep, *out_ep, *status_ep;
@@ -2336,40 +2333,19 @@ fail:
 }
 
 /*-------------------------------------------------------------------------*/
-
-#ifdef CONFIG_DM_USB
-int dm_usb_init(struct eth_dev *e_dev)
-{
-       struct udevice *dev = NULL;
-       int ret;
-
-       ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev);
-       if (!dev || ret) {
-               pr_err("No USB device found\n");
-               return -ENODEV;
-       }
-
-       e_dev->usb_udev = dev;
-
-       return ret;
-}
-#endif
+static void _usb_eth_halt(struct ether_priv *priv);
 
 static int _usb_eth_init(struct ether_priv *priv)
 {
        struct eth_dev *dev = &priv->ethdev;
        struct usb_gadget *gadget;
        unsigned long ts;
+       int ret;
        unsigned long timeout = USB_CONNECT_TIMEOUT;
 
-#ifdef CONFIG_DM_USB
-       if (dm_usb_init(dev)) {
-               pr_err("USB ether not found\n");
-               return -ENODEV;
-       }
-#else
-       board_usb_init(0, USB_INIT_DEVICE);
-#endif
+       ret = usb_gadget_initialize(0);
+       if (ret)
+               return ret;
 
        /* Configure default mac-addresses for the USB ethernet device */
 #ifdef CONFIG_USBNET_DEV_ADDR
@@ -2432,6 +2408,7 @@ static int _usb_eth_init(struct ether_priv *priv)
        rx_submit(dev, dev->rx_req, 0);
        return 0;
 fail:
+       _usb_eth_halt(priv);
        return -1;
 }
 
@@ -2495,8 +2472,7 @@ static int _usb_eth_send(struct ether_priv *priv, void *packet, int length)
                }
                usb_gadget_handle_interrupts(0);
        }
-       if (rndis_pkt)
-               free(rndis_pkt);
+       free(rndis_pkt);
 
        return 0;
 drop:
@@ -2511,7 +2487,7 @@ static int _usb_eth_recv(struct ether_priv *priv)
        return 0;
 }
 
-void _usb_eth_halt(struct ether_priv *priv)
+static void _usb_eth_halt(struct ether_priv *priv)
 {
        struct eth_dev *dev = &priv->ethdev;
 
@@ -2541,9 +2517,7 @@ void _usb_eth_halt(struct ether_priv *priv)
        }
 
        usb_gadget_unregister_driver(&priv->eth_driver);
-#ifndef CONFIG_DM_USB
-       board_usb_cleanup(0, USB_INIT_DEVICE);
-#endif
+       usb_gadget_release(0);
 }
 
 #ifndef CONFIG_DM_ETH
@@ -2607,9 +2581,6 @@ int usb_eth_initialize(bd_t *bi)
        netdev->halt = usb_eth_halt;
        netdev->priv = l_priv;
 
-#ifdef CONFIG_MCAST_TFTP
-  #error not supported
-#endif
        eth_register(netdev);
        return 0;
 }
@@ -2699,7 +2670,7 @@ int usb_ether_init(void)
        struct udevice *usb_dev;
        int ret;
 
-       ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &usb_dev);
+       ret = uclass_first_device(UCLASS_USB_GADGET_GENERIC, &usb_dev);
        if (!usb_dev || ret) {
                pr_err("No USB device found\n");
                return ret;