adm5120: don't include asm/system.h in adm5120-hcd.c
[openwrt.git] / target / linux / adm5120 / files / drivers / usb / host / adm5120-hcd.c
index 30fe132..f721ec1 100644 (file)
@@ -1,21 +1,21 @@
 /*
- * OHCI HCD (Host Controller Driver) for USB.
+ * ADM5120 HCD (Host Controller Driver) for USB
  *
- * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
- * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
+ * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
  *
- * [ Initialisation is based on Linus'  ]
- * [ uhci code and gregs ahcd fragments ]
- * [ (C) Copyright 1999 Linus Torvalds  ]
- * [ (C) Copyright 1999 Gregory P. Smith]
+ * This file was derived from: drivers/usb/host/ohci-hcd.c
+ *   (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
+ *   (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
  *
+ *   [ Initialisation is based on Linus'  ]
+ *   [ uhci code and gregs ahcd fragments ]
+ *   [ (C) Copyright 1999 Linus Torvalds  ]
+ *   [ (C) Copyright 1999 Gregory P. Smith]
  *
- * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
- * interfaces (though some non-x86 Intel chips use it).  It supports
- * smarter hardware than UHCI.  A download link for the spec available
- * through the http://www.usb.org website.
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
  *
- * This file is licenced under the GPL.
  */
 
 #include <linux/module.h>
 #include <linux/list.h>
 #include <linux/usb.h>
 #include <linux/usb/otg.h>
+#include <linux/usb/hcd.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmapool.h>
-#include <linux/reboot.h>
+#include <linux/debugfs.h>
+#include <linux/io.h>
 
-#include <asm/io.h>
 #include <asm/irq.h>
-#include <asm/system.h>
 #include <asm/unaligned.h>
 #include <asm/byteorder.h>
 
-#include "../core/hcd.h"
-#include "../core/hub.h"
-
-#define DRIVER_VERSION "v0.10"
-#define DRIVER_AUTHOR  "Gabor Juhos <juhosg at openwrt.org>"
+#define DRIVER_VERSION "0.27.0"
+#define DRIVER_AUTHOR  "Gabor Juhos <juhosg@openwrt.org>"
 #define DRIVER_DESC    "ADMtek USB 1.1 Host Controller Driver"
 
 /*-------------------------------------------------------------------------*/
 #define        OHCI_CONTROL_INIT       OHCI_CTRL_CBSR
 
 #define        ADMHC_INTR_INIT \
-               ( ADMHC_INTR_MIE | ADMHC_INTR_INSM | ADMHC_INTR_FATI \
-               | ADMHC_INTR_RESI | ADMHC_INTR_TDC | ADMHC_INTR_BABI )
+               (ADMHC_INTR_MIE | ADMHC_INTR_INSM | ADMHC_INTR_FATI \
+               | ADMHC_INTR_RESI | ADMHC_INTR_TDC | ADMHC_INTR_BABI)
 
 /*-------------------------------------------------------------------------*/
 
-static const char hcd_name [] = "admhc-hcd";
+static const char hcd_name[] = "admhc-hcd";
 
 #define        STATECHANGE_DELAY       msecs_to_jiffies(300)
 
@@ -83,8 +80,8 @@ static void admhc_stop(struct usb_hcd *hcd);
 /*
  * queue up an urb for anything except the root hub
  */
-static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
-       struct urb *urb, gfp_t mem_flags)
+static int admhc_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
+               gfp_t mem_flags)
 {
        struct admhcd   *ahcd = hcd_to_admhcd(hcd);
        struct ed       *ed;
@@ -96,12 +93,12 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
 
 #ifdef ADMHC_VERBOSE_DEBUG
        spin_lock_irqsave(&ahcd->lock, flags);
-       urb_print(ahcd, urb, "ENQEUE", usb_pipein(pipe));
+       urb_print(ahcd, urb, "ENQEUE", usb_pipein(pipe), -EINPROGRESS);
        spin_unlock_irqrestore(&ahcd->lock, flags);
 #endif
 
        /* every endpoint has an ed, locate and maybe (re)initialize it */
-       ed = ed_get(ahcd, ep, urb->dev, pipe, urb->interval);
+       ed = ed_get(ahcd, urb->ep, urb->dev, pipe, urb->interval);
        if (!ed)
                return -ENOMEM;
 
@@ -116,7 +113,7 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
                td_cnt = 2;
                /* FALLTHROUGH */
        case PIPE_BULK:
-               /* one TD for every 4096 Bytes (can be upto 8K) */
+               /* one TD for every 4096 Bytes (can be up to 8K) */
                td_cnt += urb->transfer_buffer_length / TD_DATALEN_MAX;
                /* ... and for any remaining bytes ... */
                if ((urb->transfer_buffer_length % TD_DATALEN_MAX) != 0)
@@ -127,7 +124,7 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
                else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
                        && (urb->transfer_buffer_length
                                % usb_maxpacket(urb->dev, pipe,
-                                       usb_pipeout (pipe))) == 0)
+                                       usb_pipeout(pipe))) == 0)
                        td_cnt++;
                break;
        case PIPE_INTERRUPT:
@@ -142,10 +139,6 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
                /* number of packets from URB */
                td_cnt = urb->number_of_packets;
                break;
-       default:
-               /* paranoia */
-               admhc_err(ahcd, "bad EP type %d", ed->type);
-               return -EINVAL;
        }
 
        urb_priv = urb_priv_alloc(ahcd, td_cnt, mem_flags);
@@ -156,7 +149,7 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
 
        spin_lock_irqsave(&ahcd->lock, flags);
        /* don't submit to a dead HC */
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                ret = -ENODEV;
                goto fail;
        }
@@ -165,22 +158,17 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
                goto fail;
        }
 
-       /* in case of unlink-during-submit */
-       spin_lock(&urb->lock);
-       if (urb->status != -EINPROGRESS) {
-               spin_unlock(&urb->lock);
-               urb->hcpriv = urb_priv;
-               finish_urb(ahcd, urb);
-               ret = 0;
+       ret = usb_hcd_link_urb_to_ep(hcd, urb);
+       if (ret)
                goto fail;
-       }
 
        /* schedule the ed if needed */
        if (ed->state == ED_IDLE) {
                ret = ed_schedule(ahcd, ed);
-               if (ret < 0)
-                       goto fail0;
-
+               if (ret < 0) {
+                       usb_hcd_unlink_urb_from_ep(hcd, urb);
+                       goto fail;
+               }
                if (ed->type == PIPE_ISOCHRONOUS) {
                        u16     frame = admhc_frame_no(ahcd);
 
@@ -207,8 +195,7 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
 #ifdef ADMHC_VERBOSE_DEBUG
        admhc_dump_ed(ahcd, "admhc_urb_enqueue", urb_priv->ed, 1);
 #endif
-fail0:
-       spin_unlock(&urb->lock);
+
 fail:
        if (ret)
                urb_priv_free(ahcd, urb_priv);
@@ -218,22 +205,28 @@ fail:
 }
 
 /*
- * decouple the URB from the HC queues (TDs, urb_priv); it's
- * already marked using urb->status.  reporting is always done
+ * decouple the URB from the HC queues (TDs, urb_priv);
+ * reporting is always done
  * asynchronously, and we might be dealing with an urb that's
  * partially transferred, or an ED with other urbs being unlinked.
  */
-static int admhc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
+static int admhc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
+               int status)
 {
        struct admhcd *ahcd = hcd_to_admhcd(hcd);
        unsigned long flags;
+       int ret;
+
+       spin_lock_irqsave(&ahcd->lock, flags);
 
 #ifdef ADMHC_VERBOSE_DEBUG
-       urb_print(ahcd, urb, "DEQUEUE", 1);
+       urb_print(ahcd, urb, "DEQUEUE", 1, status);
 #endif
-
-       spin_lock_irqsave(&ahcd->lock, flags);
-       if (HC_IS_RUNNING(hcd->state)) {
+       ret = usb_hcd_check_unlink_urb(hcd, urb, status);
+       if (ret) {
+               /* Do nothing */
+               ;
+       } else if (HC_IS_RUNNING(hcd->state)) {
                struct urb_priv *urb_priv;
 
                /* Unless an IRQ completed the unlink while it was being
@@ -251,11 +244,11 @@ static int admhc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
                 * any more ... just clean up every urb's memory.
                 */
                if (urb->hcpriv)
-                       finish_urb(ahcd, urb);
+                       finish_urb(ahcd, urb, status);
        }
        spin_unlock_irqrestore(&ahcd->lock, flags);
 
-       return 0;
+       return ret;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -305,8 +298,8 @@ sanitize:
                goto rescan;
        case ED_IDLE:           /* fully unlinked */
                if (list_empty(&ed->td_list)) {
-                       td_free (ahcd, ed->dummy);
-                       ed_free (ahcd, ed);
+                       td_free(ahcd, ed->dummy);
+                       ed_free(ahcd, ed);
                        break;
                }
                /* else FALL THROUGH */
@@ -324,7 +317,6 @@ sanitize:
        ep->hcpriv = NULL;
 
        spin_unlock_irqrestore(&ahcd->lock, flags);
-       return;
 }
 
 static int admhc_get_frame_number(struct usb_hcd *hcd)
@@ -343,7 +335,7 @@ static void admhc_usb_reset(struct admhcd *ahcd)
 #else
        /* FIXME */
        ahcd->host_control = ADMHC_BUSS_RESET;
-       admhc_writel(ahcd, ahcd->host_control ,&ahcd->regs->host_control);
+       admhc_writel(ahcd, ahcd->host_control&ahcd->regs->host_control);
 #endif
 }
 
@@ -491,7 +483,7 @@ err:
  */
 static int admhc_run(struct admhcd *ahcd)
 {
-       u32                     temp;
+       u32                     val;
        int                     first = ahcd->fminterval == 0;
        struct usb_hcd          *hcd = admhcd_to_hcd(ahcd);
 
@@ -499,8 +491,8 @@ static int admhc_run(struct admhcd *ahcd)
 
        /* boot firmware should have set this up (5.1.1.3.1) */
        if (first) {
-               temp = admhc_readl(ahcd, &ahcd->regs->fminterval);
-               ahcd->fminterval = temp & ADMHC_SFI_FI_MASK;
+               val = admhc_readl(ahcd, &ahcd->regs->fminterval);
+               ahcd->fminterval = val & ADMHC_SFI_FI_MASK;
                if (ahcd->fminterval != FI)
                        admhc_dbg(ahcd, "fminterval delta %d\n",
                                ahcd->fminterval - FI);
@@ -510,30 +502,30 @@ static int admhc_run(struct admhcd *ahcd)
        }
 
 #if 0  /* TODO: not applicable */
-       /* Reset USB nearly "by the book".  RemoteWakeupConnected was
-        * saved if boot firmware (BIOS/SMM/...) told us it's connected,
-        * or if bus glue did the same (e.g. for PCI add-in cards with
-        * PCI PM support).
+       /* Reset USB nearly "by the book".  RemoteWakeupConnected has
+        * to be checked in case boot firmware (BIOS/SMM/...) has set up
+        * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
+        * If the bus glue detected wakeup capability then it should
+        * already be enabled; if so we'll just enable it again.
         */
-       if ((ahcd->hc_control & OHCI_CTRL_RWC) != 0
-                       && !device_may_wakeup(hcd->self.controller))
-               device_init_wakeup(hcd->self.controller, 1);
+       if ((ahcd->hc_control & OHCI_CTRL_RWC) != 0)
+               device_set_wakeup_capable(hcd->self.controller, 1);
 #endif
 
        switch (ahcd->host_control & ADMHC_HC_BUSS) {
        case ADMHC_BUSS_OPER:
-               temp = 0;
+               val = 0;
                break;
        case ADMHC_BUSS_SUSPEND:
                /* FALLTHROUGH ? */
        case ADMHC_BUSS_RESUME:
                ahcd->host_control = ADMHC_BUSS_RESUME;
-               temp = 10 /* msec wait */;
+               val = 10 /* msec wait */;
                break;
        /* case ADMHC_BUSS_RESET: */
        default:
                ahcd->host_control = ADMHC_BUSS_RESET;
-               temp = 50 /* msec wait */;
+               val = 50 /* msec wait */;
                break;
        }
        admhc_writel(ahcd, ahcd->host_control, &ahcd->regs->host_control);
@@ -541,12 +533,12 @@ static int admhc_run(struct admhcd *ahcd)
        /* flush the writes */
        admhc_writel_flush(ahcd);
 
-       msleep(temp);
-       temp = admhc_read_rhdesc(ahcd);
-       if (!(temp & ADMHC_RH_NPS)) {
+       msleep(val);
+       val = admhc_read_rhdesc(ahcd);
+       if (!(val & ADMHC_RH_NPS)) {
                /* power down each port */
-               for (temp = 0; temp < ahcd->num_ports; temp++)
-                       admhc_write_portstatus(ahcd, temp, ADMHC_PS_CPP);
+               for (val = 0; val < ahcd->num_ports; val++)
+                       admhc_write_portstatus(ahcd, val, ADMHC_PS_CPP);
        }
        /* flush those writes */
        admhc_writel_flush(ahcd);
@@ -555,9 +547,9 @@ static int admhc_run(struct admhcd *ahcd)
        spin_lock_irq(&ahcd->lock);
 
        admhc_writel(ahcd, ADMHC_CTRL_SR,  &ahcd->regs->gencontrol);
-       temp = 30;      /* ... allow extra time */
+       val = 30;       /* ... allow extra time */
        while ((admhc_readl(ahcd, &ahcd->regs->gencontrol) & ADMHC_CTRL_SR) != 0) {
-               if (--temp == 0) {
+               if (--val == 0) {
                        spin_unlock_irq(&ahcd->lock);
                        admhc_err(ahcd, "USB HC reset timed out!\n");
                        return -1;
@@ -574,7 +566,7 @@ static int admhc_run(struct admhcd *ahcd)
        periodic_reinit(ahcd);
 
        /* use rhsc irqs after khubd is fully initialized */
-       hcd->poll_rh = 1;
+       set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
        hcd->uses_new_polling = 1;
 
 #if 0
@@ -597,10 +589,10 @@ static int admhc_run(struct admhcd *ahcd)
        ahcd->host_control = ADMHC_BUSS_OPER;
        admhc_writel(ahcd, ahcd->host_control, &ahcd->regs->host_control);
 
-       temp = 20;
+       val = 20;
        while ((admhc_readl(ahcd, &ahcd->regs->host_control)
                        & ADMHC_HC_BUSS) != ADMHC_BUSS_OPER) {
-               if (--temp == 0) {
+               if (--val == 0) {
                        spin_unlock_irq(&ahcd->lock);
                        admhc_err(ahcd, "unable to setup operational mode!\n");
                        return -1;
@@ -616,10 +608,10 @@ static int admhc_run(struct admhcd *ahcd)
        /* FIXME: enabling DMA is always failed here for an unknown reason */
        admhc_dma_enable(ahcd);
 
-       temp = 200;
+       val = 200;
        while ((admhc_readl(ahcd, &ahcd->regs->host_control)
                        & ADMHC_HC_DMAE) != ADMHC_HC_DMAE) {
-               if (--temp == 0) {
+               if (--val == 0) {
                        spin_unlock_irq(&ahcd->lock);
                        admhc_err(ahcd, "unable to enable DMA!\n");
                        admhc_dump(ahcd, 1);
@@ -645,7 +637,7 @@ static irqreturn_t admhc_irq(struct usb_hcd *hcd)
 {
        struct admhcd *ahcd = hcd_to_admhcd(hcd);
        struct admhcd_regs __iomem *regs = ahcd->regs;
-       u32 ints;
+       u32 ints;
 
        ints = admhc_readl(ahcd, &regs->int_status);
        if ((ints & ADMHC_INTR_INTA) == 0) {
@@ -691,7 +683,7 @@ static irqreturn_t admhc_irq(struct usb_hcd *hcd)
                 */
                admhc_vdbg(ahcd, "Resume Detect\n");
                admhc_intr_ack(ahcd, ADMHC_INTR_RESI);
-               hcd->poll_rh = 1;
+               set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
                if (ahcd->autostop) {
                        spin_lock(&ahcd->lock);
                        admhc_rh_resume(ahcd);
@@ -781,7 +773,7 @@ static void admhc_stop(struct usb_hcd *hcd)
 
 /*-------------------------------------------------------------------------*/
 
-#ifdef CONFIG_MIPS_ADM5120
+#ifdef CONFIG_ADM5120
 #include "adm5120-drv.c"
 #define PLATFORM_DRIVER                usb_hcd_adm5120_driver
 #endif
@@ -790,7 +782,7 @@ static void admhc_stop(struct usb_hcd *hcd)
 #error "missing bus glue for admhc-hcd"
 #endif
 
-#define DRIVER_INFO DRIVER_DESC " " DRIVER_VERSION
+#define DRIVER_INFO DRIVER_DESC " version " DRIVER_VERSION
 
 static int __init admhc_hcd_mod_init(void)
 {
@@ -801,7 +793,16 @@ static int __init admhc_hcd_mod_init(void)
 
        pr_info("%s: " DRIVER_INFO "\n", hcd_name);
        pr_info("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
-               sizeof (struct ed), sizeof (struct td));
+               sizeof(struct ed), sizeof(struct td));
+       set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
+
+#ifdef DEBUG
+       admhc_debug_root = debugfs_create_dir("admhc", usb_debug_root);
+       if (!admhc_debug_root) {
+               ret = -ENOENT;
+               goto error_debug;
+       }
+#endif
 
 #ifdef PLATFORM_DRIVER
        ret = platform_driver_register(&PLATFORM_DRIVER);
@@ -815,6 +816,13 @@ static int __init admhc_hcd_mod_init(void)
        platform_driver_unregister(&PLATFORM_DRIVER);
 error_platform:
 #endif
+
+#ifdef DEBUG
+       debugfs_remove(admhc_debug_root);
+       admhc_debug_root = NULL;
+error_debug:
+#endif
+       clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
        return ret;
 }
 module_init(admhc_hcd_mod_init);
@@ -822,9 +830,14 @@ module_init(admhc_hcd_mod_init);
 static void __exit admhc_hcd_mod_exit(void)
 {
        platform_driver_unregister(&PLATFORM_DRIVER);
+#ifdef DEBUG
+       debugfs_remove(admhc_debug_root);
+#endif
+       clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
 }
 module_exit(admhc_hcd_mod_exit);
 
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_INFO);
-MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_LICENSE("GPL v2");