]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/usb/musb-new/musb_uboot.c
musb: Rename and wrap public functions
[karo-tx-uboot.git] / drivers / usb / musb-new / musb_uboot.c
index 6e58ddf02cc34b67b4550b9f752d5a00c2d0615c..10c7cc47084cca50345440c819aa10fec43f982b 100644 (file)
@@ -1,5 +1,8 @@
 #include <common.h>
 #include <watchdog.h>
+#ifdef CONFIG_ARCH_SUNXI
+#include <asm/arch/usb_phy.h>
+#endif
 #include <asm/errno.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
@@ -87,21 +90,20 @@ static int submit_urb(struct usb_hcd *hcd, struct urb *urb)
        return urb->status;
 }
 
-int submit_control_msg(struct usb_device *dev, unsigned long pipe,
+static int _musb_submit_control_msg(struct usb_device *dev, unsigned long pipe,
                        void *buffer, int len, struct devrequest *setup)
 {
        construct_urb(&urb, &hep, dev, USB_ENDPOINT_XFER_CONTROL, pipe,
                      buffer, len, setup, 0);
 
        /* Fix speed for non hub-attached devices */
-       if (!dev->parent)
+       if (!usb_dev_get_parent(dev))
                dev->speed = host_speed;
 
        return submit_urb(&hcd, &urb);
 }
 
-
-int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
+static int _musb_submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
                                        void *buffer, int len)
 {
        construct_urb(&urb, &hep, dev, USB_ENDPOINT_XFER_BULK, pipe,
@@ -109,7 +111,7 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
        return submit_urb(&hcd, &urb);
 }
 
-int submit_int_msg(struct usb_device *dev, unsigned long pipe,
+static int _musb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
                                void *buffer, int len, int interval)
 {
        construct_urb(&urb, &hep, dev, USB_ENDPOINT_XFER_INT, pipe,
@@ -117,8 +119,9 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
        return submit_urb(&hcd, &urb);
 }
 
-struct int_queue *create_int_queue(struct usb_device *dev, unsigned long pipe,
-       int queuesize, int elementsize, void *buffer, int interval)
+static struct int_queue *_musb_create_int_queue(struct usb_device *dev,
+                       unsigned long pipe, int queuesize, int elementsize,
+                       void *buffer, int interval)
 {
        struct int_queue *queue;
        int ret, index = usb_pipein(pipe) * 16 + usb_pipeendpoint(pipe);
@@ -151,7 +154,8 @@ struct int_queue *create_int_queue(struct usb_device *dev, unsigned long pipe,
        return queue;
 }
 
-int destroy_int_queue(struct usb_device *dev, struct int_queue *queue)
+static int _musb_destroy_int_queue(struct usb_device *dev,
+                                  struct int_queue *queue)
 {
        int index = usb_pipein(queue->urb.pipe) * 16 + 
                    usb_pipeendpoint(queue->urb.pipe);
@@ -164,7 +168,8 @@ int destroy_int_queue(struct usb_device *dev, struct int_queue *queue)
        return 0;
 }
 
-void *poll_int_queue(struct usb_device *dev, struct int_queue *queue)
+static void *_musb_poll_int_queue(struct usb_device *dev,
+                                 struct int_queue *queue)
 {
        if (queue->urb.status != -EINPROGRESS)
                return NULL; /* URB has already completed in a prev. poll */
@@ -177,7 +182,7 @@ void *poll_int_queue(struct usb_device *dev, struct int_queue *queue)
        return NULL; /* URB still pending */
 }
 
-void usb_reset_root_port(void)
+static int _musb_reset_root_port(struct usb_device *dev)
 {
        void *mbase = host->mregs;
        u8 power;
@@ -186,28 +191,45 @@ void usb_reset_root_port(void)
        power &= 0xf0;
        musb_writeb(mbase, MUSB_POWER, MUSB_POWER_RESET | power);
        mdelay(50);
+#ifdef CONFIG_ARCH_SUNXI
+       /*
+        * sunxi phy has a bug and it will wrongly detect high speed squelch
+        * when clearing reset on low-speed devices, temporary disable
+        * squelch detection to work around this.
+        */
+       sunxi_usb_phy_enable_squelch_detect(0, 0);
+#endif
        power = musb_readb(mbase, MUSB_POWER);
        musb_writeb(mbase, MUSB_POWER, ~MUSB_POWER_RESET & power);
+#ifdef CONFIG_ARCH_SUNXI
+       sunxi_usb_phy_enable_squelch_detect(0, 1);
+#endif
        host->isr(0, host);
        host_speed = (musb_readb(mbase, MUSB_POWER) & MUSB_POWER_HSMODE) ?
                        USB_SPEED_HIGH :
                        (musb_readb(mbase, MUSB_DEVCTL) & MUSB_DEVCTL_FSDEV) ?
                        USB_SPEED_FULL : USB_SPEED_LOW;
        mdelay((host_speed == USB_SPEED_LOW) ? 200 : 50);
+
+       return 0;
 }
 
-int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
+int musb_lowlevel_init(void)
 {
        void *mbase;
        /* USB spec says it may take up to 1 second for a device to connect */
        unsigned long timeout = get_timer(0) + 1000;
+       int ret;
 
        if (!host) {
                printf("MUSB host is not registered\n");
                return -ENODEV;
        }
 
-       musb_start(host);
+       ret = musb_start(host);
+       if (ret)
+               return ret;
+
        mbase = host->mregs;
        do {
                if (musb_readb(mbase, MUSB_DEVCTL) & MUSB_DEVCTL_HM)
@@ -216,7 +238,7 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
        if (get_timer(0) >= timeout)
                return -ENODEV;
 
-       usb_reset_root_port();
+       _musb_reset_root_port(NULL);
        host->is_active = 1;
        hcd.hcd_priv = host;
 
@@ -233,12 +255,58 @@ int usb_lowlevel_stop(int index)
        musb_stop(host);
        return 0;
 }
+
+int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
+                           void *buffer, int length)
+{
+       return _musb_submit_bulk_msg(dev, pipe, buffer, length);
+}
+
+int submit_control_msg(struct usb_device *dev, unsigned long pipe,
+                      void *buffer, int length, struct devrequest *setup)
+{
+       return _musb_submit_control_msg(dev, pipe, buffer, length, setup);
+}
+
+int submit_int_msg(struct usb_device *dev, unsigned long pipe,
+                  void *buffer, int length, int interval)
+{
+       return _musb_submit_int_msg(dev, pipe, buffer, length, interval);
+}
+
+struct int_queue *create_int_queue(struct usb_device *dev,
+               unsigned long pipe, int queuesize, int elementsize,
+               void *buffer, int interval)
+{
+       return _musb_create_int_queue(dev, pipe, queuesize, elementsize,
+                                     buffer, interval);
+}
+
+void *poll_int_queue(struct usb_device *dev, struct int_queue *queue)
+{
+       return _musb_poll_int_queue(dev, queue);
+}
+
+int destroy_int_queue(struct usb_device *dev, struct int_queue *queue)
+{
+       return _musb_destroy_int_queue(dev, queue);
+}
+
+int usb_reset_root_port(struct usb_device *dev)
+{
+       return _musb_reset_root_port(dev);
+}
+
+int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
+{
+       return musb_lowlevel_init();
+}
 #endif /* CONFIG_MUSB_HOST */
 
 #ifdef CONFIG_MUSB_GADGET
 static struct musb *gadget;
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
        WATCHDOG_RESET();
        if (!gadget || !gadget->isr)