]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/usb/musb/musb_hcd.c
usb: create common header virtual root hub descriptors
[karo-tx-uboot.git] / drivers / usb / musb / musb_hcd.c
index 555d2dc1b09a4972e9829651b16bec3daaaab3fb..f0ba8aaaa321d7ffbf12759e66c536ee5c4e5c18 100644 (file)
@@ -3,25 +3,13 @@
  *
  * Copyright (c) 2008 Texas Instruments
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  *
  * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
  */
 
 #include <common.h>
+#include <usb.h>
 #include "musb_hcd.h"
 
 /* MSC control transfers */
 #define USB_MSC_BBB_GET_MAX_LUN        0xFE
 
 /* Endpoint configuration information */
-static struct musb_epinfo epinfo[3] = {
+static const struct musb_epinfo epinfo[3] = {
        {MUSB_BULK_EP, 1, 512}, /* EP1 - Bluk Out - 512 Bytes */
        {MUSB_BULK_EP, 0, 512}, /* EP1 - Bluk In  - 512 Bytes */
        {MUSB_INTR_EP, 0, 64}   /* EP2 - Interrupt IN - 64 Bytes */
 };
 
+/* --- Virtual Root Hub ---------------------------------------------------- */
+#ifdef MUSB_NO_MULTIPOINT
+static int rh_devnum;
+static u32 port_status;
+
+#include <usbroothubdes.h>
+
+#endif
+
 /*
  * This function writes the data toggle value.
  */
@@ -44,19 +41,28 @@ static void write_toggle(struct usb_device *dev, u8 ep, u8 dir_out)
        u16 csr;
 
        if (dir_out) {
-               if (!toggle)
-                       writew(MUSB_TXCSR_CLRDATATOG, &musbr->txcsr);
-               else {
-                       csr = readw(&musbr->txcsr);
+               csr = readw(&musbr->txcsr);
+               if (!toggle) {
+                       if (csr & MUSB_TXCSR_MODE)
+                               csr = MUSB_TXCSR_CLRDATATOG;
+                       else
+                               csr = 0;
+                       writew(csr, &musbr->txcsr);
+               } else {
                        csr |= MUSB_TXCSR_H_WR_DATATOGGLE;
                        writew(csr, &musbr->txcsr);
                        csr |= (toggle << MUSB_TXCSR_H_DATATOGGLE_SHIFT);
                        writew(csr, &musbr->txcsr);
                }
        } else {
-               if (!toggle)
-                       writew(MUSB_RXCSR_CLRDATATOG, &musbr->rxcsr);
-               else {
+               if (!toggle) {
+                       csr = readw(&musbr->txcsr);
+                       if (csr & MUSB_TXCSR_MODE)
+                               csr = MUSB_RXCSR_CLRDATATOG;
+                       else
+                               csr = 0;
+                       writew(csr, &musbr->rxcsr);
+               } else {
                        csr = readw(&musbr->rxcsr);
                        csr |= MUSB_RXCSR_H_WR_DATATOGGLE;
                        writew(csr, &musbr->rxcsr);
@@ -170,7 +176,7 @@ static int wait_until_ep0_ready(struct usb_device *dev, u32 bit_mask)
 /*
  * waits until tx ep is ready. Returns 1 when ep is ready and 0 on error.
  */
-static u8 wait_until_txep_ready(struct usb_device *dev, u8 ep)
+static int wait_until_txep_ready(struct usb_device *dev, u8 ep)
 {
        u16 csr;
        int timeout = CONFIG_MUSB_TIMEOUT;
@@ -202,7 +208,7 @@ static u8 wait_until_txep_ready(struct usb_device *dev, u8 ep)
 /*
  * waits until rx ep is ready. Returns 1 when ep is ready and 0 on error.
  */
-static u8 wait_until_rxep_ready(struct usb_device *dev, u8 ep)
+static int wait_until_rxep_ready(struct usb_device *dev, u8 ep)
 {
        u16 csr;
        int timeout = CONFIG_MUSB_TIMEOUT;
@@ -320,8 +326,12 @@ static int ctrlreq_out_data_phase(struct usb_device *dev, u32 len, void *buffer)
 
                /* Set TXPKTRDY bit */
                csr = readw(&musbr->txcsr);
-               writew(csr | MUSB_CSR0_H_DIS_PING | MUSB_CSR0_TXPKTRDY,
-                                       &musbr->txcsr);
+                       
+               csr |= MUSB_CSR0_TXPKTRDY;
+#if !defined(CONFIG_SOC_DM365)
+               csr |= MUSB_CSR0_H_DIS_PING;
+#endif
+               writew(csr, &musbr->txcsr);
                result = wait_until_ep0_ready(dev, MUSB_CSR0_TXPKTRDY);
                if (result < 0)
                        break;
@@ -342,8 +352,10 @@ static int ctrlreq_out_status_phase(struct usb_device *dev)
 
        /* Set the StatusPkt bit */
        csr = readw(&musbr->txcsr);
-       csr |= (MUSB_CSR0_H_DIS_PING | MUSB_CSR0_TXPKTRDY |
-                       MUSB_CSR0_H_STATUSPKT);
+       csr |= (MUSB_CSR0_TXPKTRDY | MUSB_CSR0_H_STATUSPKT);
+#if !defined(CONFIG_SOC_DM365)
+       csr |= MUSB_CSR0_H_DIS_PING;
+#endif
        writew(csr, &musbr->txcsr);
 
        /* Wait until TXPKTRDY bit is cleared */
@@ -360,7 +372,10 @@ static int ctrlreq_in_status_phase(struct usb_device *dev)
        int result;
 
        /* Set the StatusPkt bit and ReqPkt bit */
-       csr = MUSB_CSR0_H_DIS_PING | MUSB_CSR0_H_REQPKT | MUSB_CSR0_H_STATUSPKT;
+       csr = MUSB_CSR0_H_REQPKT | MUSB_CSR0_H_STATUSPKT;
+#if !defined(CONFIG_SOC_DM365)
+       csr |= MUSB_CSR0_H_DIS_PING;
+#endif
        writew(csr, &musbr->txcsr);
        result = wait_until_ep0_ready(dev, MUSB_CSR0_H_REQPKT);
 
@@ -376,8 +391,8 @@ static int ctrlreq_in_status_phase(struct usb_device *dev)
  */
 static u8 get_dev_speed(struct usb_device *dev)
 {
-       return (dev->speed & USB_SPEED_HIGH) ? MUSB_TYPE_SPEED_HIGH :
-               ((dev->speed & USB_SPEED_LOW) ? MUSB_TYPE_SPEED_LOW :
+       return (dev->speed == USB_SPEED_HIGH) ? MUSB_TYPE_SPEED_HIGH :
+               ((dev->speed == USB_SPEED_LOW) ? MUSB_TYPE_SPEED_LOW :
                                                MUSB_TYPE_SPEED_FULL);
 }
 
@@ -402,13 +417,336 @@ static void config_hub_port(struct usb_device *dev, u8 ep)
                if (dev->parent->children[chid] == dev)
                        break;
 
+#ifndef MUSB_NO_MULTIPOINT
        /* configure the hub address and the port address */
        writeb(hub, &musbr->tar[ep].txhubaddr);
        writeb((chid + 1), &musbr->tar[ep].txhubport);
        writeb(hub, &musbr->tar[ep].rxhubaddr);
        writeb((chid + 1), &musbr->tar[ep].rxhubport);
+#endif
+}
+
+#ifdef MUSB_NO_MULTIPOINT
+
+static void musb_port_reset(int do_reset)
+{
+       u8 power = readb(&musbr->power);
+
+       if (do_reset) {
+               power &= 0xf0;
+               writeb(power | MUSB_POWER_RESET, &musbr->power);
+               port_status |= USB_PORT_STAT_RESET;
+               port_status &= ~USB_PORT_STAT_ENABLE;
+               udelay(30000);
+       } else {
+               writeb(power & ~MUSB_POWER_RESET, &musbr->power);
+
+               power = readb(&musbr->power);
+               if (power & MUSB_POWER_HSMODE)
+                       port_status |= USB_PORT_STAT_HIGH_SPEED;
+
+               port_status &= ~(USB_PORT_STAT_RESET | (USB_PORT_STAT_C_CONNECTION << 16));
+               port_status |= USB_PORT_STAT_ENABLE
+                       | (USB_PORT_STAT_C_RESET << 16)
+                       | (USB_PORT_STAT_C_ENABLE << 16);
+       }
+}
+
+/*
+ * root hub control
+ */
+static int musb_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
+                             void *buffer, int transfer_len,
+                             struct devrequest *cmd)
+{
+       int leni = transfer_len;
+       int len = 0;
+       int stat = 0;
+       u32 datab[4];
+       const u8 *data_buf = (u8 *) datab;
+       u16 bmRType_bReq;
+       u16 wValue;
+       u16 wIndex;
+       u16 wLength;
+       u16 int_usb;
+
+       if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
+               debug("Root-Hub submit IRQ: NOT implemented\n");
+               return 0;
+       }
+
+       bmRType_bReq = cmd->requesttype | (cmd->request << 8);
+       wValue = swap_16(cmd->value);
+       wIndex = swap_16(cmd->index);
+       wLength = swap_16(cmd->length);
+
+       debug("--- HUB ----------------------------------------\n");
+       debug("submit rh urb, req=%x val=%#x index=%#x len=%d\n",
+           bmRType_bReq, wValue, wIndex, wLength);
+       debug("------------------------------------------------\n");
+
+       switch (bmRType_bReq) {
+       case RH_GET_STATUS:
+               debug("RH_GET_STATUS\n");
+
+               *(__u16 *) data_buf = swap_16(1);
+               len = 2;
+               break;
+
+       case RH_GET_STATUS | RH_INTERFACE:
+               debug("RH_GET_STATUS | RH_INTERFACE\n");
+
+               *(__u16 *) data_buf = swap_16(0);
+               len = 2;
+               break;
+
+       case RH_GET_STATUS | RH_ENDPOINT:
+               debug("RH_GET_STATUS | RH_ENDPOINT\n");
+
+               *(__u16 *) data_buf = swap_16(0);
+               len = 2;
+               break;
+
+       case RH_GET_STATUS | RH_CLASS:
+               debug("RH_GET_STATUS | RH_CLASS\n");
+
+               *(__u32 *) data_buf = swap_32(0);
+               len = 4;
+               break;
+
+       case RH_GET_STATUS | RH_OTHER | RH_CLASS:
+               debug("RH_GET_STATUS | RH_OTHER | RH_CLASS\n");
+
+               int_usb = readw(&musbr->intrusb);
+               if (int_usb & MUSB_INTR_CONNECT) {
+                       port_status |= USB_PORT_STAT_CONNECTION
+                               | (USB_PORT_STAT_C_CONNECTION << 16);
+                       port_status |= USB_PORT_STAT_HIGH_SPEED
+                               | USB_PORT_STAT_ENABLE;
+               }
+
+               if (port_status & USB_PORT_STAT_RESET)
+                       musb_port_reset(0);
+
+               *(__u32 *) data_buf = swap_32(port_status);
+               len = 4;
+               break;
+
+       case RH_CLEAR_FEATURE | RH_ENDPOINT:
+               debug("RH_CLEAR_FEATURE | RH_ENDPOINT\n");
+
+               switch (wValue) {
+               case RH_ENDPOINT_STALL:
+                       debug("C_HUB_ENDPOINT_STALL\n");
+                       len = 0;
+                       break;
+               }
+               port_status &= ~(1 << wValue);
+               break;
+
+       case RH_CLEAR_FEATURE | RH_CLASS:
+               debug("RH_CLEAR_FEATURE | RH_CLASS\n");
+
+               switch (wValue) {
+               case RH_C_HUB_LOCAL_POWER:
+                       debug("C_HUB_LOCAL_POWER\n");
+                       len = 0;
+                       break;
+
+               case RH_C_HUB_OVER_CURRENT:
+                       debug("C_HUB_OVER_CURRENT\n");
+                       len = 0;
+                       break;
+               }
+               port_status &= ~(1 << wValue);
+               break;
+
+       case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
+               debug("RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS\n");
+
+               switch (wValue) {
+               case RH_PORT_ENABLE:
+                       len = 0;
+                       break;
+
+               case RH_PORT_SUSPEND:
+                       len = 0;
+                       break;
+
+               case RH_PORT_POWER:
+                       len = 0;
+                       break;
+
+               case RH_C_PORT_CONNECTION:
+                       len = 0;
+                       break;
+
+               case RH_C_PORT_ENABLE:
+                       len = 0;
+                       break;
+
+               case RH_C_PORT_SUSPEND:
+                       len = 0;
+                       break;
+
+               case RH_C_PORT_OVER_CURRENT:
+                       len = 0;
+                       break;
+
+               case RH_C_PORT_RESET:
+                       len = 0;
+                       break;
+
+               default:
+                       debug("invalid wValue\n");
+                       stat = USB_ST_STALLED;
+               }
+
+               port_status &= ~(1 << wValue);
+               break;
+
+       case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
+               debug("RH_SET_FEATURE | RH_OTHER | RH_CLASS\n");
+
+               switch (wValue) {
+               case RH_PORT_SUSPEND:
+                       len = 0;
+                       break;
+
+               case RH_PORT_RESET:
+                       musb_port_reset(1);
+                       len = 0;
+                       break;
+
+               case RH_PORT_POWER:
+                       len = 0;
+                       break;
+
+               case RH_PORT_ENABLE:
+                       len = 0;
+                       break;
+
+               default:
+                       debug("invalid wValue\n");
+                       stat = USB_ST_STALLED;
+               }
+
+               port_status |= 1 << wValue;
+               break;
+
+       case RH_SET_ADDRESS:
+               debug("RH_SET_ADDRESS\n");
+
+               rh_devnum = wValue;
+               len = 0;
+               break;
+
+       case RH_GET_DESCRIPTOR:
+               debug("RH_GET_DESCRIPTOR: %x, %d\n", wValue, wLength);
+
+               switch (wValue) {
+               case (USB_DT_DEVICE << 8):      /* device descriptor */
+                       len = min_t(unsigned int,
+                                   leni, min_t(unsigned int,
+                                               sizeof(root_hub_dev_des),
+                                               wLength));
+                       data_buf = root_hub_dev_des;
+                       break;
+
+               case (USB_DT_CONFIG << 8):      /* configuration descriptor */
+                       len = min_t(unsigned int,
+                                   leni, min_t(unsigned int,
+                                               sizeof(root_hub_config_des),
+                                               wLength));
+                       data_buf = root_hub_config_des;
+                       break;
+
+               case ((USB_DT_STRING << 8) | 0x00):     /* string 0 descriptors */
+                       len = min_t(unsigned int,
+                                   leni, min_t(unsigned int,
+                                               sizeof(root_hub_str_index0),
+                                               wLength));
+                       data_buf = root_hub_str_index0;
+                       break;
+
+               case ((USB_DT_STRING << 8) | 0x01):     /* string 1 descriptors */
+                       len = min_t(unsigned int,
+                                   leni, min_t(unsigned int,
+                                               sizeof(root_hub_str_index1),
+                                               wLength));
+                       data_buf = root_hub_str_index1;
+                       break;
+
+               default:
+                       debug("invalid wValue\n");
+                       stat = USB_ST_STALLED;
+               }
+
+               break;
+
+       case RH_GET_DESCRIPTOR | RH_CLASS: {
+               u8 *_data_buf = (u8 *) datab;
+               debug("RH_GET_DESCRIPTOR | RH_CLASS\n");
+
+               _data_buf[0] = 0x09;    /* min length; */
+               _data_buf[1] = 0x29;
+               _data_buf[2] = 0x1;     /* 1 port */
+               _data_buf[3] = 0x01;    /* per-port power switching */
+               _data_buf[3] |= 0x10;   /* no overcurrent reporting */
+
+               /* Corresponds to data_buf[4-7] */
+               _data_buf[4] = 0;
+               _data_buf[5] = 5;
+               _data_buf[6] = 0;
+               _data_buf[7] = 0x02;
+               _data_buf[8] = 0xff;
+
+               len = min_t(unsigned int, leni,
+                           min_t(unsigned int, data_buf[0], wLength));
+               break;
+       }
+
+       case RH_GET_CONFIGURATION:
+               debug("RH_GET_CONFIGURATION\n");
+
+               *(__u8 *) data_buf = 0x01;
+               len = 1;
+               break;
+
+       case RH_SET_CONFIGURATION:
+               debug("RH_SET_CONFIGURATION\n");
+
+               len = 0;
+               break;
+
+       default:
+               debug("*** *** *** unsupported root hub command *** *** ***\n");
+               stat = USB_ST_STALLED;
+       }
+
+       len = min_t(int, len, leni);
+       if (buffer != data_buf)
+               memcpy(buffer, data_buf, len);
+
+       dev->act_len = len;
+       dev->status = stat;
+       debug("dev act_len %d, status %lu\n", dev->act_len, dev->status);
+
+       return stat;
 }
 
+static void musb_rh_init(void)
+{
+       rh_devnum = 0;
+       port_status = 0;
+}
+
+#else
+
+static void musb_rh_init(void) {}
+
+#endif
+
 /*
  * do a control transfer
  */
@@ -416,16 +754,26 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
                        int len, struct devrequest *setup)
 {
        int devnum = usb_pipedevice(pipe);
-       u16 csr;
        u8  devspeed;
 
+#ifdef MUSB_NO_MULTIPOINT
+       /* Control message is for the HUB? */
+       if (devnum == rh_devnum) {
+               int stat = musb_submit_rh_msg(dev, pipe, buffer, len, setup);
+               if (stat)
+                       return stat;
+       }
+#endif
+
        /* select control endpoint */
        writeb(MUSB_CONTROL_EP, &musbr->index);
-       csr = readw(&musbr->txcsr);
+       readw(&musbr->txcsr);
 
+#ifndef MUSB_NO_MULTIPOINT
        /* target addr and (for multipoint) hub addr/port */
        writeb(devnum, &musbr->tar[MUSB_CONTROL_EP].txfuncaddr);
        writeb(devnum, &musbr->tar[MUSB_CONTROL_EP].rxfuncaddr);
+#endif
 
        /* configure the hub address and the port number as required */
        devspeed = get_dev_speed(dev);
@@ -435,10 +783,12 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
                writeb(devspeed << 6, &musbr->txtype);
        } else {
                writeb(musb_cfg.musb_speed << 6, &musbr->txtype);
+#ifndef MUSB_NO_MULTIPOINT
                writeb(0, &musbr->tar[MUSB_CONTROL_EP].txhubaddr);
                writeb(0, &musbr->tar[MUSB_CONTROL_EP].txhubport);
                writeb(0, &musbr->tar[MUSB_CONTROL_EP].rxhubaddr);
                writeb(0, &musbr->tar[MUSB_CONTROL_EP].rxhubport);
+#endif
        }
 
        /* Control transfer setup phase */
@@ -486,6 +836,13 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 
        dev->status = 0;
        dev->act_len = len;
+
+#ifdef MUSB_NO_MULTIPOINT
+       /* Set device address to USB_FADDR register */
+       if (setup->request == USB_REQ_SET_ADDRESS)
+               writeb(dev->devnum, &musbr->faddr);
+#endif
+
        return len;
 }
 
@@ -497,7 +854,9 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
 {
        int dir_out = usb_pipeout(pipe);
        int ep = usb_pipeendpoint(pipe);
+#ifndef MUSB_NO_MULTIPOINT
        int devnum = usb_pipedevice(pipe);
+#endif
        u8  type;
        u16 csr;
        u32 txlen = 0;
@@ -507,11 +866,13 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
        /* select bulk endpoint */
        writeb(MUSB_BULK_EP, &musbr->index);
 
+#ifndef MUSB_NO_MULTIPOINT
        /* write the address of the device */
        if (dir_out)
                writeb(devnum, &musbr->tar[MUSB_BULK_EP].txfuncaddr);
        else
                writeb(devnum, &musbr->tar[MUSB_BULK_EP].rxfuncaddr);
+#endif
 
        /* configure the hub address and the port number as required */
        devspeed = get_dev_speed(dev);
@@ -524,6 +885,7 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
                 */
                config_hub_port(dev, MUSB_BULK_EP);
        } else {
+#ifndef MUSB_NO_MULTIPOINT
                if (dir_out) {
                        writeb(0, &musbr->tar[MUSB_BULK_EP].txhubaddr);
                        writeb(0, &musbr->tar[MUSB_BULK_EP].txhubport);
@@ -531,6 +893,7 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
                        writeb(0, &musbr->tar[MUSB_BULK_EP].rxhubaddr);
                        writeb(0, &musbr->tar[MUSB_BULK_EP].rxhubport);
                }
+#endif
                devspeed = musb_cfg.musb_speed;
        }
 
@@ -550,6 +913,11 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
                        nextlen = ((len-txlen) < dev->epmaxpacketout[ep]) ?
                                        (len-txlen) : dev->epmaxpacketout[ep];
 
+#ifdef CONFIG_USB_BLACKFIN
+                       /* Set the transfer data size */
+                       writew(nextlen, &musbr->txcount);
+#endif
+
                        /* Write the data to the FIFO */
                        write_fifo(MUSB_BULK_EP, nextlen,
                                        (void *)(((u8 *)buffer) + txlen));
@@ -559,7 +927,7 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
                        writew(csr | MUSB_TXCSR_TXPKTRDY, &musbr->txcsr);
 
                        /* Wait until the TxPktRdy bit is cleared */
-                       if (!wait_until_txep_ready(dev, MUSB_BULK_EP)) {
+                       if (wait_until_txep_ready(dev, MUSB_BULK_EP) != 1) {
                                readw(&musbr->txcsr);
                                usb_settoggle(dev, ep, dir_out,
                                (csr >> MUSB_TXCSR_H_DATATOGGLE_SHIFT) & 1);
@@ -590,10 +958,11 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
                                        (len-txlen) : dev->epmaxpacketin[ep];
 
                        /* Set the ReqPkt bit */
-                       writew(MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
+                       csr = readw(&musbr->rxcsr);
+                       writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
 
                        /* Wait until the RxPktRdy bit is set */
-                       if (!wait_until_rxep_ready(dev, MUSB_BULK_EP)) {
+                       if (wait_until_rxep_ready(dev, MUSB_BULK_EP) != 1) {
                                csr = readw(&musbr->rxcsr);
                                usb_settoggle(dev, ep, dir_out,
                                (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
@@ -629,18 +998,19 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
 /*
  * This function initializes the usb controller module.
  */
-int usb_lowlevel_init(void)
+int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
 {
        u8  power;
        u32 timeout;
 
+       musb_rh_init();
+
        if (musb_platform_init() == -1)
                return -1;
 
        /* Configure all the endpoint FIFO's and start usb controller */
        musbr = musb_cfg.regs;
-       musb_configure_ep(&epinfo[0],
-                       sizeof(epinfo) / sizeof(struct musb_epinfo));
+       musb_configure_ep(&epinfo[0], ARRAY_SIZE(epinfo));
        musb_start();
 
        /*
@@ -648,7 +1018,7 @@ int usb_lowlevel_init(void)
         * should be a usb device connected.
         */
        timeout = musb_cfg.timeout;
-       while (timeout--)
+       while (--timeout)
                if (readb(&musbr->devctl) & MUSB_DEVCTL_HM)
                        break;
 
@@ -679,7 +1049,7 @@ int usb_lowlevel_init(void)
 /*
  * This function stops the operation of the davinci usb module.
  */
-int usb_lowlevel_stop(void)
+int usb_lowlevel_stop(int index)
 {
        /* Reset the USB module */
        musb_platform_deinit();
@@ -696,7 +1066,9 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
 {
        int dir_out = usb_pipeout(pipe);
        int ep = usb_pipeendpoint(pipe);
+#ifndef MUSB_NO_MULTIPOINT
        int devnum = usb_pipedevice(pipe);
+#endif
        u8  type;
        u16 csr;
        u32 txlen = 0;
@@ -706,11 +1078,13 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
        /* select interrupt endpoint */
        writeb(MUSB_INTR_EP, &musbr->index);
 
+#ifndef MUSB_NO_MULTIPOINT
        /* write the address of the device */
        if (dir_out)
                writeb(devnum, &musbr->tar[MUSB_INTR_EP].txfuncaddr);
        else
                writeb(devnum, &musbr->tar[MUSB_INTR_EP].rxfuncaddr);
+#endif
 
        /* configure the hub address and the port number as required */
        devspeed = get_dev_speed(dev);
@@ -723,6 +1097,7 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
                 */
                config_hub_port(dev, MUSB_INTR_EP);
        } else {
+#ifndef MUSB_NO_MULTIPOINT
                if (dir_out) {
                        writeb(0, &musbr->tar[MUSB_INTR_EP].txhubaddr);
                        writeb(0, &musbr->tar[MUSB_INTR_EP].txhubport);
@@ -730,6 +1105,7 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
                        writeb(0, &musbr->tar[MUSB_INTR_EP].rxhubaddr);
                        writeb(0, &musbr->tar[MUSB_INTR_EP].rxhubport);
                }
+#endif
                devspeed = musb_cfg.musb_speed;
        }
 
@@ -755,10 +1131,11 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
                                        (len-txlen) : dev->epmaxpacketin[ep];
 
                        /* Set the ReqPkt bit */
-                       writew(MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
+                       csr = readw(&musbr->rxcsr);
+                       writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
 
                        /* Wait until the RxPktRdy bit is set */
-                       if (!wait_until_rxep_ready(dev, MUSB_INTR_EP)) {
+                       if (wait_until_rxep_ready(dev, MUSB_INTR_EP) != 1) {
                                csr = readw(&musbr->rxcsr);
                                usb_settoggle(dev, ep, dir_out,
                                (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
@@ -793,31 +1170,3 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
        dev->act_len = len;
        return 0;
 }
-
-
-#ifdef CONFIG_SYS_USB_EVENT_POLL
-/*
- * This function polls for USB keyboard data.
- */
-void usb_event_poll()
-{
-       struct stdio_dev *dev;
-       struct usb_device *usb_kbd_dev;
-       struct usb_interface *iface;
-       struct usb_endpoint_descriptor *ep;
-       int pipe;
-       int maxp;
-
-       /* Get the pointer to USB Keyboard device pointer */
-       dev = stdio_get_by_name("usbkbd");
-       usb_kbd_dev = (struct usb_device *)dev->priv;
-       iface = &usb_kbd_dev->config.if_desc[0];
-       ep = &iface->ep_desc[0];
-       pipe = usb_rcvintpipe(usb_kbd_dev, ep->bEndpointAddress);
-
-       /* Submit a interrupt transfer request */
-       maxp = usb_maxpacket(usb_kbd_dev, pipe);
-       usb_submit_int_msg(usb_kbd_dev, pipe, &new[0],
-                       maxp > 8 ? 8 : maxp, ep->bInterval);
-}
-#endif /* CONFIG_SYS_USB_EVENT_POLL */