This patch adds support to the OHCI code for big-endian
controllers while maintaining the existing support for
little-endian controllers.

This is done primarily by applying the following transforms
when dealing with controller data:
        ohci_readl(p)   --> ohci_read(ohci, p)
        writel(v, p)    --> ohci_writel(ohci, v, p)
        cpu_to_le16(v)  --> cpu_to_ohci16(ohci, v)
        cpu_to_le16p(v) --> cpu_to_ohci16p(ohci, v)
        cpu_to_le32(v)  --> cpu_to_ohci32(ohci, v)
        cpu_to_le32p(v) --> cpu_to_ohci32p(ohci, v)
        le16_to_cpu(v)  --> ohci16_to_cpu(ohci, v)
        le16_to_cpup(v) --> ohci16_to_cpup(ohci, v)
        le32_to_cpu(v)  --> ohci32_to_cpu(ohci, v)
        le32_to_cpup(v) --> ohci32_to_cpup(ohci, v)

The new functions devolve to the original leXX forms if
the platform doesn't support big-endian ohci controllers.
They take on the beXX forms when only big-endian controllers
are supported.

A bit in the flags field of struct ohci_hcd, OHCI_BIG_ENDIAN,
enables the the transformed functions to support both big-endian
and little-endian controllers at runtime, when needed.

Signed-off-by: Dale Farnsworth <[EMAIL PROTECTED]>

diff -Nru a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
--- a/drivers/usb/host/ohci-dbg.c       2004-08-19 18:00:30 -07:00
+++ b/drivers/usb/host/ohci-dbg.c       2004-08-19 18:00:30 -07:00
@@ -134,13 +134,13 @@
        struct ohci_regs        *regs = controller->regs;
        u32                     temp;
 
-       temp = ohci_readl (&regs->revision) & 0xff;
+       temp = ohci_readl (controller, &regs->revision) & 0xff;
        ohci_dbg_sw (controller, next, size,
                "OHCI %d.%d, %s legacy support registers\n",
                0x03 & (temp >> 4), (temp & 0x0f),
                (temp & 0x10) ? "with" : "NO");
 
-       temp = ohci_readl (&regs->control);
+       temp = ohci_readl (controller, &regs->control);
        ohci_dbg_sw (controller, next, size,
                "control 0x%03x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n",
                temp,
@@ -155,7 +155,7 @@
                temp & OHCI_CTRL_CBSR
                );
 
-       temp = ohci_readl (&regs->cmdstatus);
+       temp = ohci_readl (controller, &regs->cmdstatus);
        ohci_dbg_sw (controller, next, size,
                "cmdstatus 0x%05x SOC=%d%s%s%s%s\n", temp,
                (temp & OHCI_SOC) >> 16,
@@ -166,26 +166,33 @@
                );
 
        ohci_dump_intr_mask (controller, "intrstatus",
-                       ohci_readl (&regs->intrstatus), next, size);
+                       ohci_readl (controller, &regs->intrstatus),
+                       next, size);
        ohci_dump_intr_mask (controller, "intrenable",
-                       ohci_readl (&regs->intrenable), next, size);
+                       ohci_readl (controller, &regs->intrenable),
+                       next, size);
        // intrdisable always same as intrenable
 
        maybe_print_eds (controller, "ed_periodcurrent",
-                       ohci_readl (&regs->ed_periodcurrent), next, size);
+                       ohci_readl (controller, &regs->ed_periodcurrent),
+                       next, size);
 
        maybe_print_eds (controller, "ed_controlhead",
-                       ohci_readl (&regs->ed_controlhead), next, size);
+                       ohci_readl (controller, &regs->ed_controlhead),
+                       next, size);
        maybe_print_eds (controller, "ed_controlcurrent",
-                       ohci_readl (&regs->ed_controlcurrent), next, size);
+                       ohci_readl (controller, &regs->ed_controlcurrent),
+                       next, size);
 
        maybe_print_eds (controller, "ed_bulkhead",
-                       ohci_readl (&regs->ed_bulkhead), next, size);
+                       ohci_readl (controller, &regs->ed_bulkhead),
+                       next, size);
        maybe_print_eds (controller, "ed_bulkcurrent",
-                       ohci_readl (&regs->ed_bulkcurrent), next, size);
+                       ohci_readl (controller, &regs->ed_bulkcurrent),
+                       next, size);
 
        maybe_print_eds (controller, "donehead",
-                       ohci_readl (&regs->donehead), next, size);
+                       ohci_readl (controller, &regs->donehead), next, size);
 }
 
 #define dbg_port_sw(hc,num,value,next,size) \
@@ -279,13 +286,13 @@
 static void ohci_dump_td (const struct ohci_hcd *ohci, const char *label,
                const struct td *td)
 {
-       u32     tmp = le32_to_cpup (&td->hwINFO);
+       u32     tmp = ohci32_to_cpup (ohci, &td->hwINFO);
 
        ohci_dbg (ohci, "%s td %p%s; urb %p index %d; hw next td %08x\n",
                label, td,
                (tmp & TD_DONE) ? " (DONE)" : "",
                td->urb, td->index,
-               le32_to_cpup (&td->hwNextTD));
+               ohci32_to_cpup (ohci, &td->hwNextTD));
        if ((tmp & TD_ISO) == 0) {
                const char      *toggle, *pid;
                u32     cbp, be;
@@ -306,8 +313,8 @@
                        TD_CC_GET(tmp), /* EC, */ toggle,
                        (tmp & TD_DI) >> 21, pid,
                        (tmp & TD_R) ? "R" : "");
-               cbp = le32_to_cpup (&td->hwCBP);
-               be = le32_to_cpup (&td->hwBE);
+               cbp = ohci32_to_cpup (ohci, &td->hwCBP);
+               be = ohci32_to_cpup (ohci, &td->hwBE);
                ohci_dbg (ohci, "     cbp %08x be %08x (len %d)\n", cbp, be,
                        cbp ? (be + 1 - cbp) : 0);
        } else {
@@ -318,10 +325,10 @@
                        (tmp & TD_DI) >> 21,
                        tmp & 0x0000ffff);
                ohci_dbg (ohci, "  bp0 %08x be %08x\n",
-                       le32_to_cpup (&td->hwCBP) & ~0x0fff,
-                       le32_to_cpup (&td->hwBE));
+                       ohci32_to_cpup (ohci, &td->hwCBP) & ~0x0fff,
+                       ohci32_to_cpup (ohci, &td->hwBE));
                for (i = 0; i < MAXPSW; i++) {
-                       u16     psw = le16_to_cpup (&td->hwPSW [i]);
+                       u16     psw = ohci16_to_cpup (ohci, &td->hwPSW [i]);
                        int     cc = (psw >> 12) & 0x0f;
                        ohci_dbg (ohci, "    psw [%d] = %2x, CC=%x %s=%d\n", i,
                                psw, cc,
@@ -336,13 +343,13 @@
 ohci_dump_ed (const struct ohci_hcd *ohci, const char *label,
                const struct ed *ed, int verbose)
 {
-       u32     tmp = le32_to_cpu (ed->hwINFO);
+       u32     tmp = ohci32_to_cpu (ohci, ed->hwINFO);
        char    *type = "";
 
        ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x\n",
                label,
                ed, ed->state, edstring (ed->type),
-               le32_to_cpup (&ed->hwNextED));
+               ohci32_to_cpup (ohci, &ed->hwNextED));
        switch (tmp & (ED_IN|ED_OUT)) {
        case ED_OUT: type = "-OUT"; break;
        case ED_IN: type = "-IN"; break;
@@ -358,12 +365,12 @@
                0x000f & (tmp >> 7),
                type,
                0x007f & tmp);
-       tmp = le32_to_cpup (&ed->hwHeadP);
+       tmp = ohci32_to_cpup (ohci, &ed->hwHeadP);
        ohci_dbg (ohci, "  tds: head %08x %s%s tail %08x%s\n",
                tmp,
                (tmp & ED_C) ? data1 : data0,
                (tmp & ED_H) ? " HALT" : "",
-               le32_to_cpup (&ed->hwTailP),
+               ohci32_to_cpup (ohci, &ed->hwTailP),
                verbose ? "" : " (not listing)");
        if (verbose) {
                struct list_head        *tmp;
@@ -416,10 +423,10 @@
 
        /* dump a snapshot of the bulk or control schedule */
        while (ed) {
-               u32                     info = le32_to_cpu (ed->hwINFO);
-               u32                     headp = le32_to_cpu (ed->hwHeadP);
-               struct list_head        *entry;
-               struct td               *td;
+               u32             info = ohci32_to_cpu (ohci, ed->hwINFO);
+               u32             headp = ohci32_to_cpu (ohci, ed->hwHeadP);
+               struct list_head *entry;
+               struct td       *td;
 
                temp = scnprintf (buf, size,
                        "ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
@@ -440,9 +447,9 @@
                        u32             cbp, be;
 
                        td = list_entry (entry, struct td, td_list);
-                       info = le32_to_cpup (&td->hwINFO);
-                       cbp = le32_to_cpup (&td->hwCBP);
-                       be = le32_to_cpup (&td->hwBE);
+                       info = ohci32_to_cpup (ohci, &td->hwINFO);
+                       cbp = ohci32_to_cpup (ohci, &td->hwCBP);
+                       be = ohci32_to_cpup (ohci, &td->hwBE);
                        temp = scnprintf (buf, size,
                                        "\n\ttd %p %s %d cc=%x urb %p (%08x)",
                                        td,
@@ -542,7 +549,7 @@
 
                        /* show more info the first time around */
                        if (temp == seen_count) {
-                               u32     info = le32_to_cpu(ed->hwINFO);
+                               u32     info = ohci32_to_cpu(ohci, ed->hwINFO);
                                struct list_head        *entry;
                                unsigned                qlen = 0;
 
@@ -562,8 +569,9 @@
                                        0x03ff & (info >> 16),
                                        info,
                                        (info & ED_SKIP) ? " K" : "",
-                                       (ed->hwHeadP & cpu_to_le32(ED_H)) ?
-                                               " H" : "");
+                                       (ed->hwHeadP &
+                                               cpu_to_ohci32(ohci, ED_H)) ?
+                                                       " H" : "");
                                size -= temp;
                                next += temp;
 
@@ -638,7 +646,7 @@
                        "hcca frame 0x%04x\n", OHCI_FRAME_NO(ohci->hcca));
 
        /* other registers mostly affect frame timings */
-       rdata = ohci_readl (&regs->fminterval);
+       rdata = ohci_readl (ohci, &regs->fminterval);
        temp = scnprintf (next, size,
                        "fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
                        rdata, (rdata >> 31) ? " FIT" : "",
@@ -646,20 +654,20 @@
        size -= temp;
        next += temp;
 
-       rdata = ohci_readl (&regs->fmremaining);
+       rdata = ohci_readl (ohci, &regs->fmremaining);
        temp = scnprintf (next, size, "fmremaining 0x%08x %sFR=0x%04x\n",
                        rdata, (rdata >> 31) ? " FRT" : "",
                        rdata & 0x3fff);
        size -= temp;
        next += temp;
 
-       rdata = ohci_readl (&regs->periodicstart);
+       rdata = ohci_readl (ohci, &regs->periodicstart);
        temp = scnprintf (next, size, "periodicstart 0x%04x\n",
                        rdata & 0x3fff);
        size -= temp;
        next += temp;
 
-       rdata = ohci_readl (&regs->lsthresh);
+       rdata = ohci_readl (ohci, &regs->lsthresh);
        temp = scnprintf (next, size, "lsthresh 0x%04x\n",
                        rdata & 0x3fff);
        size -= temp;
diff -Nru a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
--- a/drivers/usb/host/ohci-hcd.c       2004-08-19 18:00:30 -07:00
+++ b/drivers/usb/host/ohci-hcd.c       2004-08-19 18:00:30 -07:00
@@ -398,7 +398,7 @@
 
        /* boot firmware should have set this up (5.1.1.3.1) */
        if (!ohci->fminterval) {
-               temp = ohci_readl (&ohci->regs->fminterval);
+               temp = ohci_readl (ohci, &ohci->regs->fminterval);
                if (temp & 0x3fff0000)
                        ohci->fminterval = temp;
                else
@@ -410,7 +410,7 @@
         * On PA-RISC, PDC can leave IR set incorrectly; ignore it there.
         */
 #ifndef __hppa__
-       if (ohci_readl (&ohci->regs->control) & OHCI_CTRL_IR) {
+       if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
                ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
 
                /* this timeout is arbitrary.  we make it long, so systems
@@ -419,9 +419,9 @@
                 */
                temp = 500;     /* arbitrary: five seconds */
 
-               writel (OHCI_INTR_OC, &ohci->regs->intrenable);
-               writel (OHCI_OCR, &ohci->regs->cmdstatus);
-               while (ohci_readl (&ohci->regs->control) & OHCI_CTRL_IR) {
+               ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
+               ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
+               while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
                        msleep (10);
                        if (--temp == 0) {
                                ohci_err (ohci, "USB HC TakeOver failed!\n");
@@ -432,36 +432,36 @@
 #endif
 
        /* Disable HC interrupts */
-       writel (OHCI_INTR_MIE, &ohci->regs->intrdisable);
+       ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
 
        ohci_dbg (ohci, "reset, control = 0x%x\n",
-                 ohci_readl (&ohci->regs->control));
+                 ohci_readl (ohci, &ohci->regs->control));
 
        /* Reset USB (needed by some controllers); RemoteWakeupConnected
         * saved if boot firmware (BIOS/SMM/...) told us it's connected
         * (for OHCI integrated on mainboard, it normally is)
         */
-       ohci->hc_control = ohci_readl (&ohci->regs->control);
+       ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
        ohci->hc_control &= OHCI_CTRL_RWC;      /* hcfs 0 = RESET */
        if (ohci->hc_control)
                ohci->hcd.can_wakeup = 1;
-       writel (ohci->hc_control, &ohci->regs->control);
+       ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
        if (power_switching) {
                unsigned ports = roothub_a (ohci) & RH_A_NDP; 
 
                /* power down each port */
                for (temp = 0; temp < ports; temp++)
-                       writel (RH_PS_LSDA,
+                       ohci_writel (ohci, RH_PS_LSDA,
                                &ohci->regs->roothub.portstatus [temp]);
        }
        // flush those pci writes
-       (void) ohci_readl (&ohci->regs->control);
+       (void) ohci_readl (ohci, &ohci->regs->control);
        msleep (50);
 
        /* HC Reset requires max 10 us delay */
-       writel (OHCI_HCR,  &ohci->regs->cmdstatus);
+       ohci_writel (ohci, OHCI_HCR,  &ohci->regs->cmdstatus);
        temp = 30;      /* ... allow extra time */
-       while ((ohci_readl (&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
+       while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
                if (--temp == 0) {
                        ohci_err (ohci, "USB HC reset timed out!\n");
                        return -1;
@@ -476,9 +476,9 @@
         * (SiS, OPTi ...), so reset again instead.  SiS doesn't need
         * this if we write fmInterval after we're OPERATIONAL.
         */
-       writel (ohci->hc_control, &ohci->regs->control);
+       ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
        // flush those pci writes
-       (void) ohci_readl (&ohci->regs->control);
+       (void) ohci_readl (ohci, &ohci->regs->control);
 
        return 0;
 }
@@ -499,19 +499,19 @@
 
        /* Tell the controller where the control and bulk lists are
         * The lists are empty now. */
-       writel (0, &ohci->regs->ed_controlhead);
-       writel (0, &ohci->regs->ed_bulkhead);
+       ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
+       ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
 
        /* a reset clears this */
-       writel ((u32) ohci->hcca_dma, &ohci->regs->hcca);
+       ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
 
        periodic_reinit (ohci);
 
        /* some OHCI implementations are finicky about how they init.
         * bogus values here mean not even enumeration could work.
         */
-       if ((ohci_readl (&ohci->regs->fminterval) & 0x3fff0000) == 0
-                       || !ohci_readl (&ohci->regs->periodicstart)) {
+       if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
+                       || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
                ohci_err (ohci, "init err\n");
                return -EOVERFLOW;
        }
@@ -519,7 +519,7 @@
        /* start controller operations */
        ohci->hc_control &= OHCI_CTRL_RWC;
        ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
-       writel (ohci->hc_control, &ohci->regs->control);
+       ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
        ohci->hcd.state = USB_STATE_RUNNING;
 
        /* wake on ConnectStatusChange, matching external hubs */
@@ -527,8 +527,8 @@
 
        /* Choose the interrupts we care about now, others later on demand */
        mask = OHCI_INTR_INIT;
-       writel (mask, &ohci->regs->intrstatus);
-       writel (mask, &ohci->regs->intrenable);
+       ohci_writel (ohci, mask, &ohci->regs->intrstatus);
+       ohci_writel (ohci, mask, &ohci->regs->intrenable);
 
        /* handle root hub init quirks ... */
        tmp = roothub_a (ohci);
@@ -549,11 +549,12 @@
                 */
                tmp |= RH_A_NPS;
        }
-       writel (tmp, &ohci->regs->roothub.a);
-       writel (RH_HS_LPSC, &ohci->regs->roothub.status);
-       writel (power_switching ? RH_B_PPCM : 0, &ohci->regs->roothub.b);
+       ohci_writel (ohci, tmp, &ohci->regs->roothub.a);
+       ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
+       ohci_writel (ohci, power_switching ? RH_B_PPCM : 0,
+                       &ohci->regs->roothub.b);
        // flush those pci writes
-       (void) ohci_readl (&ohci->regs->control);
+       (void) ohci_readl (ohci, &ohci->regs->control);
 
        // POTPGT delay is bits 24-31, in 2 ms units.
        mdelay ((roothub_a (ohci) >> 23) & 0x1fe);
@@ -570,7 +571,7 @@
        if (!udev) {
                disable (ohci);
                ohci->hc_control &= ~OHCI_CTRL_HCFS;
-               writel (ohci->hc_control, &ohci->regs->control);
+               ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
                return -ENOMEM;
        }
 
@@ -579,7 +580,7 @@
                usb_put_dev (udev);
                disable (ohci);
                ohci->hc_control &= ~OHCI_CTRL_HCFS;
-               writel (ohci->hc_control, &ohci->regs->control);
+               ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
                return -ENODEV;
        }
 
@@ -599,17 +600,18 @@
        /* we can eliminate a (slow) ohci_readl()
           if _only_ WDH caused this irq */
        if ((ohci->hcca->done_head != 0)
-                       && ! (le32_to_cpup (&ohci->hcca->done_head) & 0x01)) {
+                       && ! (ohci32_to_cpup (ohci, &ohci->hcca->done_head)
+                               & 0x01)) {
                ints =  OHCI_INTR_WDH;
 
        /* cardbus/... hardware gone before remove() */
-       } else if ((ints = ohci_readl (&regs->intrstatus)) == ~(u32)0) {
+       } else if ((ints = ohci_readl (ohci, &regs->intrstatus)) == ~(u32)0) {
                disable (ohci);
                ohci_dbg (ohci, "device removed!\n");
                return IRQ_HANDLED;
 
        /* interrupt for some other device? */
-       } else if ((ints &= ohci_readl (&regs->intrenable)) == 0) {
+       } else if ((ints &= ohci_readl (ohci, &regs->intrenable)) == 0) {
                return IRQ_NONE;
        } 
 
@@ -629,12 +631,12 @@
 
        if (ints & OHCI_INTR_WDH) {
                if (HCD_IS_RUNNING(hcd->state))
-                       writel (OHCI_INTR_WDH, &regs->intrdisable);     
+                       ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);  
                spin_lock (&ohci->lock);
                dl_done_list (ohci, ptregs);
                spin_unlock (&ohci->lock);
                if (HCD_IS_RUNNING(hcd->state))
-                       writel (OHCI_INTR_WDH, &regs->intrenable); 
+                       ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable); 
        }
   
        /* could track INTR_SO to reduce available PCI/... bandwidth */
@@ -648,14 +650,14 @@
                                ptregs);
        if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
                        && HCD_IS_RUNNING(ohci->hcd.state))
-               writel (OHCI_INTR_SF, &regs->intrdisable);      
+               ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);   
        spin_unlock (&ohci->lock);
 
        if (HCD_IS_RUNNING(ohci->hcd.state)) {
-               writel (ints, &regs->intrstatus);
-               writel (OHCI_INTR_MIE, &regs->intrenable);      
+               ohci_writel (ohci, ints, &regs->intrstatus);
+               ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);   
                // flush those pci writes
-               (void) ohci_readl (&ohci->regs->control);
+               (void) ohci_readl (ohci, &ohci->regs->control);
        }
 
        return IRQ_HANDLED;
@@ -730,7 +732,7 @@
                switch (ed->state) {
                case ED_OPER:
                        ed->state = ED_UNLINK;
-                       ed->hwINFO |= cpu_to_le32(ED_DEQUEUE);
+                       ed->hwINFO |= cpu_to_ohci32(ED_DEQUEUE);
                        ed_deschedule (ohci, ed);
 
                        ed->ed_next = ohci->ed_rm_list;
diff -Nru a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
--- a/drivers/usb/host/ohci-hub.c       2004-08-19 18:00:30 -07:00
+++ b/drivers/usb/host/ohci-hub.c       2004-08-19 18:00:30 -07:00
@@ -12,7 +12,7 @@
 /*
  * OHCI Root Hub ... the nonsharable stuff
  *
- * Registers don't need cpu_to_le32, that happens transparently
+ * Registers don't need cpu_to_ohci32, that happens transparently
  */
 
 /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
@@ -20,20 +20,20 @@
  * till some bits (mostly reserved) are clear; ok for all revs.
  */
 #define read_roothub(hc, register, mask) ({ \
-       u32 temp = ohci_readl (&hc->regs->roothub.register); \
+       u32 temp = ohci_readl (hc, &hc->regs->roothub.register); \
        if (temp == -1) \
                disable (hc); \
        else if (hc->flags & OHCI_QUIRK_AMD756) \
                while (temp & mask) \
-                       temp = ohci_readl (&hc->regs->roothub.register); \
+                       temp = ohci_readl (hc, &hc->regs->roothub.register); \
        temp; })
 
 static u32 roothub_a (struct ohci_hcd *hc)
        { return read_roothub (hc, a, 0xfc0fe000); }
 static inline u32 roothub_b (struct ohci_hcd *hc)
-       { return ohci_readl (&hc->regs->roothub.b); }
+       { return ohci_readl (hc, &hc->regs->roothub.b); }
 static inline u32 roothub_status (struct ohci_hcd *hc)
-       { return ohci_readl (&hc->regs->roothub.status); }
+       { return ohci_readl (hc, &hc->regs->roothub.status); }
 static u32 roothub_portstatus (struct ohci_hcd *hc, int i)
        { return read_roothub (hc, portstatus [i], 0xffe0fce0); }
 
@@ -83,14 +83,14 @@
 
        spin_lock_irq (&ohci->lock);
 
-       ohci->hc_control = ohci_readl (&ohci->regs->control);
+       ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
        switch (ohci->hc_control & OHCI_CTRL_HCFS) {
        case OHCI_USB_RESUME:
                ohci_dbg (ohci, "resume/suspend?\n");
                ohci->hc_control &= ~OHCI_CTRL_HCFS;
                ohci->hc_control |= OHCI_USB_RESET;
-               writel (ohci->hc_control, &ohci->regs->control);
-               (void) ohci_readl (&ohci->regs->control);
+               ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
+               (void) ohci_readl (ohci, &ohci->regs->control);
                /* FALL THROUGH */
        case OHCI_USB_RESET:
                status = -EBUSY;
@@ -108,9 +108,9 @@
                int             limit;
 
                ohci->hc_control &= ~OHCI_SCHED_ENABLES;
-               writel (ohci->hc_control, &ohci->regs->control);
-               ohci->hc_control = ohci_readl (&ohci->regs->control);
-               writel (OHCI_INTR_SF, &ohci->regs->intrstatus);
+               ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
+               ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
+               ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus);
 
                /* sched disables take effect on the next frame,
                 * then the last WDH could take 6+ msec
@@ -120,7 +120,8 @@
                while (limit > 0) {
                        udelay (250);
                        limit =- 250;
-                       if (ohci_readl (&ohci->regs->intrstatus) & OHCI_INTR_SF)
+                       if (ohci_readl (ohci, &ohci->regs->intrstatus)
+                                       & OHCI_INTR_SF)
                                break;
                }
                dl_done_list (ohci, NULL);
@@ -128,7 +129,8 @@
        }
        dl_done_list (ohci, NULL);
        finish_unlinks (ohci, OHCI_FRAME_NO(ohci->hcca), NULL);
-       writel (ohci_readl (&ohci->regs->intrstatus), &ohci->regs->intrstatus);
+       ohci_writel (ohci, ohci_readl (ohci, &ohci->regs->intrstatus),
+                       &ohci->regs->intrstatus);
 
        /* maybe resume can wake root hub */
        if (ohci->hcd.remote_wakeup)
@@ -139,8 +141,8 @@
        /* Suspend hub */
        ohci->hc_control &= ~OHCI_CTRL_HCFS;
        ohci->hc_control |= OHCI_USB_SUSPEND;
-       writel (ohci->hc_control, &ohci->regs->control);
-       (void) ohci_readl (&ohci->regs->control);
+       ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
+       (void) ohci_readl (ohci, &ohci->regs->control);
 
        /* no resumes until devices finish suspending */
        ohci->next_statechange = jiffies + msecs_to_jiffies (5);
@@ -179,13 +181,13 @@
                return -EAGAIN;
 
        spin_lock_irq (&ohci->lock);
-       ohci->hc_control = ohci_readl (&ohci->regs->control);
+       ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
        switch (ohci->hc_control & OHCI_CTRL_HCFS) {
        case OHCI_USB_SUSPEND:
                ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES);
                ohci->hc_control |= OHCI_USB_RESUME;
-               writel (ohci->hc_control, &ohci->regs->control);
-               (void) ohci_readl (&ohci->regs->control);
+               ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
+               (void) ohci_readl (ohci, &ohci->regs->control);
                ohci_dbg (ohci, "resume root hub\n");
                break;
        case OHCI_USB_RESUME:
@@ -210,19 +212,21 @@
        temp = roothub_a (ohci) & RH_A_NDP;
        enables = 0;
        while (temp--) {
-               u32 stat = ohci_readl (&ohci->regs->roothub.portstatus [temp]);
+               u32 stat = ohci_readl (ohci,
+                                      &ohci->regs->roothub.portstatus [temp]);
 
                /* force global, not selective, resume */
                if (!(stat & RH_PS_PSS))
                        continue;
-               writel (RH_PS_POCI, &ohci->regs->roothub.portstatus [temp]);
+               ohci_writel (ohci, RH_PS_POCI,
+                               &ohci->regs->roothub.portstatus [temp]);
        }
 
        /* Some controllers (lucent) need extra-long delays */
        ohci->hcd.state = USB_STATE_RESUMING;
        mdelay (20 /* usb 11.5.1.10 */ + 15);
 
-       temp = ohci_readl (&ohci->regs->control);
+       temp = ohci_readl (ohci, &ohci->regs->control);
        temp &= OHCI_CTRL_HCFS;
        if (temp != OHCI_USB_RESUME) {
                ohci_err (ohci, "controller won't resume\n");
@@ -230,32 +234,33 @@
        }
 
        /* disable old schedule state, reinit from scratch */
-       writel (0, &ohci->regs->ed_controlhead);
-       writel (0, &ohci->regs->ed_controlcurrent);
-       writel (0, &ohci->regs->ed_bulkhead);
-       writel (0, &ohci->regs->ed_bulkcurrent);
-       writel (0, &ohci->regs->ed_periodcurrent);
-       writel ((u32) ohci->hcca_dma, &ohci->regs->hcca);
+       ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
+       ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent);
+       ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
+       ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent);
+       ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent);
+       ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
 
        periodic_reinit (ohci);
 
        /* interrupts might have been disabled */
-       writel (OHCI_INTR_INIT, &ohci->regs->intrenable);
+       ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable);
        if (ohci->ed_rm_list)
-               writel (OHCI_INTR_SF, &ohci->regs->intrenable);
-       writel (ohci_readl (&ohci->regs->intrstatus), &ohci->regs->intrstatus);
+               ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
+       ohci_writel (ohci, ohci_readl (ohci, &ohci->regs->intrstatus),
+                       &ohci->regs->intrstatus);
 
        /* Then re-enable operations */
-       writel (OHCI_USB_OPER, &ohci->regs->control);
-       (void) ohci_readl (&ohci->regs->control);
+       ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control);
+       (void) ohci_readl (ohci, &ohci->regs->control);
        msleep (3);
 
        temp = OHCI_CONTROL_INIT | OHCI_USB_OPER;
        if (ohci->hcd.can_wakeup)
                temp |= OHCI_CTRL_RWC;
        ohci->hc_control = temp;
-       writel (temp, &ohci->regs->control);
-       (void) ohci_readl (&ohci->regs->control);
+       ohci_writel (ohci, temp, &ohci->regs->control);
+       (void) ohci_readl (ohci, &ohci->regs->control);
 
        /* TRSMRCY */
        msleep (10);
@@ -269,13 +274,13 @@
        temp = 0;
        if (!ohci->ed_rm_list) {
                if (ohci->ed_controltail) {
-                       writel (find_head (ohci->ed_controltail)->dma,
+                       writel (ohci, find_head (ohci->ed_controltail)->dma,
                                &ohci->regs->ed_controlhead);
                        enables |= OHCI_CTRL_CLE;
                        temp |= OHCI_CLF;
                }
                if (ohci->ed_bulktail) {
-                       writel (find_head (ohci->ed_bulktail)->dma,
+                       writel (ohci, find_head (ohci->ed_bulktail)->dma,
                                &ohci->regs->ed_bulkhead);
                        enables |= OHCI_CTRL_BLE;
                        temp |= OHCI_BLF;
@@ -287,10 +292,10 @@
        if (enables) {
                ohci_dbg (ohci, "restarting schedules ... %08x\n", enables);
                ohci->hc_control |= enables;
-               writel (ohci->hc_control, &ohci->regs->control);
+               ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
                if (temp)
-                       writel (status, &ohci->regs->cmdstatus);
-               (void) ohci_readl (&ohci->regs->control);
+                       ohci_writel (ohci, status, &ohci->regs->cmdstatus);
+               (void) ohci_readl (ohci, &ohci->regs->control);
        }
 
        ohci->hcd.state = USB_STATE_RUNNING;
@@ -331,8 +336,8 @@
        if (ports > MAX_ROOT_PORTS) {
                if (!HCD_IS_RUNNING(ohci->hcd.state))
                        return -ESHUTDOWN;
-               ohci_err (ohci, "bogus NDP=%d, rereads as NDP=%d\n",
-                       ports, ohci_readl (&ohci->regs->roothub.a) & RH_A_NDP);
+               ohci_err (ohci, "bogus NDP=%d, rereads as NDP=%d\n", ports,
+                         ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP);
                /* retry later; "should not happen" */
                return 0;
        }
@@ -421,7 +426,7 @@
            temp |= 0x0010;
        else if (rh & RH_A_OCPM)        /* per-port overcurrent reporting? */
            temp |= 0x0008;
-       desc->wHubCharacteristics = cpu_to_le16 (temp);
+       desc->wHubCharacteristics = cpu_to_ohci16 (ohci, temp);
 
        /* two bitmaps:  ports removable, and usb 1.0 legacy PortPwrCtrlMask */
        rh = roothub_b (ohci);
@@ -452,7 +457,8 @@
        case ClearHubFeature:
                switch (wValue) {
                case C_HUB_OVER_CURRENT:
-                       writel (RH_HS_OCIC, &ohci->regs->roothub.status);
+                       ohci_writel (ohci, RH_HS_OCIC,
+                                       &ohci->regs->roothub.status);
                case C_HUB_LOCAL_POWER:
                        break;
                default:
@@ -495,8 +501,9 @@
                default:
                        goto error;
                }
-               writel (temp, &ohci->regs->roothub.portstatus [wIndex]);
-               // ohci_readl (&ohci->regs->roothub.portstatus [wIndex]);
+               ohci_writel (ohci, temp,
+                               &ohci->regs->roothub.portstatus [wIndex]);
+               // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]);
                break;
        case GetHubDescriptor:
                ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf);
@@ -533,17 +540,18 @@
                wIndex--;
                switch (wValue) {
                case USB_PORT_FEAT_SUSPEND:
-                       writel (RH_PS_PSS,
+                       ohci_writel (ohci, RH_PS_PSS,
                                &ohci->regs->roothub.portstatus [wIndex]);
                        break;
                case USB_PORT_FEAT_POWER:
-                       writel (RH_PS_PPS,
+                       ohci_writel (ohci, RH_PS_PPS,
                                &ohci->regs->roothub.portstatus [wIndex]);
                        break;
                case USB_PORT_FEAT_RESET:
-                       temp = ohci_readl (&ohci->regs->roothub.portstatus [wIndex]);
+                       temp = ohci_readl (ohci,
+                                   &ohci->regs->roothub.portstatus [wIndex]);
                        if (temp & RH_PS_CCS)
-                               writel (RH_PS_PRS,
+                               ohci_writel (ohci, RH_PS_PRS,
                                    &ohci->regs->roothub.portstatus [wIndex]);
                        break;
                default:
diff -Nru a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
--- a/drivers/usb/host/ohci-mem.c       2004-08-19 18:00:30 -07:00
+++ b/drivers/usb/host/ohci-mem.c       2004-08-19 18:00:30 -07:00
@@ -104,7 +104,7 @@
        if (td) {
                /* in case hc fetches it, make it look dead */
                memset (td, 0, sizeof *td);
-               td->hwNextTD = cpu_to_le32 (dma);
+               td->hwNextTD = cpu_to_ohci32 (hc, dma);
                td->td_dma = dma;
                /* hashed in td_fill */
        }
@@ -120,7 +120,7 @@
                prev = &(*prev)->td_hash;
        if (*prev)
                *prev = td->td_hash;
-       else if ((td->hwINFO & cpu_to_le32(TD_DONE)) != 0)
+       else if ((td->hwINFO & cpu_to_ohci32(hc, TD_DONE)) != 0)
                ohci_dbg (hc, "no hash for td %p\n", td);
        dma_pool_free (hc->td_cache, td, td->td_dma);
 }
diff -Nru a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
--- a/drivers/usb/host/ohci-q.c 2004-08-19 18:00:30 -07:00
+++ b/drivers/usb/host/ohci-q.c 2004-08-19 18:00:30 -07:00
@@ -78,7 +78,7 @@
        if (hcd_to_bus (&ohci->hcd)->bandwidth_isoc_reqs == 0
                        && hcd_to_bus (&ohci->hcd)->bandwidth_int_reqs == 0) {
                ohci->hc_control &= ~(OHCI_CTRL_PLE|OHCI_CTRL_IE);
-               writel (ohci->hc_control, &ohci->regs->control);
+               ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
        }
 }
 
@@ -131,7 +131,7 @@
        unsigned        i;
 
        ohci_vdbg (ohci, "link %sed %p branch %d [%dus.], interval %d\n",
-               (ed->hwINFO & cpu_to_le32 (ED_ISO)) ? "iso " : "",
+               (ed->hwINFO & cpu_to_ohci32 (ohci, ED_ISO)) ? "iso " : "",
                ed, ed->branch, ed->load, ed->interval);
 
        for (i = ed->branch; i < NUM_INTS; i += ed->interval) {
@@ -156,7 +156,7 @@
                                ed->hwNextED = *prev_p;
                        wmb ();
                        *prev = ed;
-                       *prev_p = cpu_to_le32p (&ed->dma);
+                       *prev_p = cpu_to_ohci32p (ohci, &ed->dma);
                        wmb();
                }
                ohci->load [i] += ed->load;
@@ -193,17 +193,20 @@
        case PIPE_CONTROL:
                if (ohci->ed_controltail == NULL) {
                        WARN_ON (ohci->hc_control & OHCI_CTRL_CLE);
-                       writel (ed->dma, &ohci->regs->ed_controlhead);
+                       ohci_writel (ohci, ed->dma,
+                                       &ohci->regs->ed_controlhead);
                } else {
                        ohci->ed_controltail->ed_next = ed;
-                       ohci->ed_controltail->hwNextED = cpu_to_le32 (ed->dma);
+                       ohci->ed_controltail->hwNextED = cpu_to_ohci32 (ohci,
+                                                               ed->dma);
                }
                ed->ed_prev = ohci->ed_controltail;
                if (!ohci->ed_controltail && !ohci->ed_rm_list) {
                        wmb();
                        ohci->hc_control |= OHCI_CTRL_CLE;
-                       writel (0, &ohci->regs->ed_controlcurrent);
-                       writel (ohci->hc_control, &ohci->regs->control);
+                       ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent);
+                       ohci_writel (ohci, ohci->hc_control,
+                                       &ohci->regs->control);
                }
                ohci->ed_controltail = ed;
                break;
@@ -211,17 +214,19 @@
        case PIPE_BULK:
                if (ohci->ed_bulktail == NULL) {
                        WARN_ON (ohci->hc_control & OHCI_CTRL_BLE);
-                       writel (ed->dma, &ohci->regs->ed_bulkhead);
+                       ohci_writel (ohci, ed->dma, &ohci->regs->ed_bulkhead);
                } else {
                        ohci->ed_bulktail->ed_next = ed;
-                       ohci->ed_bulktail->hwNextED = cpu_to_le32 (ed->dma);
+                       ohci->ed_bulktail->hwNextED = cpu_to_ohci32 (ohci,
+                                                               ed->dma);
                }
                ed->ed_prev = ohci->ed_bulktail;
                if (!ohci->ed_bulktail && !ohci->ed_rm_list) {
                        wmb();
                        ohci->hc_control |= OHCI_CTRL_BLE;
-                       writel (0, &ohci->regs->ed_bulkcurrent);
-                       writel (ohci->hc_control, &ohci->regs->control);
+                       ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent);
+                       ohci_writel (ohci, ohci->hc_control,
+                                       &ohci->regs->control);
                }
                ohci->ed_bulktail = ed;
                break;
@@ -272,7 +277,7 @@
        hcd_to_bus (&ohci->hcd)->bandwidth_allocated -= ed->load / ed->interval;
 
        ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n",
-               (ed->hwINFO & cpu_to_le32 (ED_ISO)) ? "iso " : "",
+               (ed->hwINFO & cpu_to_ohci32 (ohci, ED_ISO)) ? "iso " : "",
                ed, ed->branch, ed->load, ed->interval);
 }
 
@@ -300,7 +305,7 @@
  */
 static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed) 
 {
-       ed->hwINFO |= cpu_to_le32 (ED_SKIP);
+       ed->hwINFO |= cpu_to_ohci32 (ohci, ED_SKIP);
        wmb ();
        ed->state = ED_UNLINK;
 
@@ -320,10 +325,12 @@
                if (ed->ed_prev == NULL) {
                        if (!ed->hwNextED) {
                                ohci->hc_control &= ~OHCI_CTRL_CLE;
-                               writel (ohci->hc_control, &ohci->regs->control);
+                               ohci_writel (ohci, ohci->hc_control,
+                                               &ohci->regs->control);
                                // a ohci_readl() later syncs CLE with the HC
                        } else
-                               writel (le32_to_cpup (&ed->hwNextED),
+                               ohci_writel (ohci,
+                                       ohci32_to_cpup (ohci, &ed->hwNextED),
                                        &ohci->regs->ed_controlhead);
                } else {
                        ed->ed_prev->ed_next = ed->ed_next;
@@ -344,10 +351,12 @@
                if (ed->ed_prev == NULL) {
                        if (!ed->hwNextED) {
                                ohci->hc_control &= ~OHCI_CTRL_BLE;
-                               writel (ohci->hc_control, &ohci->regs->control);
+                               ohci_writel (ohci, ohci->hc_control,
+                                               &ohci->regs->control);
                                // a ohci_readl() later syncs BLE with the HC
                        } else
-                               writel (le32_to_cpup (&ed->hwNextED),
+                               ohci_writel (ohci,
+                                       ohci32_to_cpup (ohci, &ed->hwNextED),
                                        &ohci->regs->ed_bulkhead);
                } else {
                        ed->ed_prev->ed_next = ed->ed_next;
@@ -416,7 +425,7 @@
                        goto done;
                }
                ed->dummy = td;
-               ed->hwTailP = cpu_to_le32 (td->td_dma);
+               ed->hwTailP = cpu_to_ohci32 (ohci, td->td_dma);
                ed->hwHeadP = ed->hwTailP;      /* ED_C, ED_H zeroed */
                ed->state = ED_IDLE;
                ed->type = type;
@@ -450,7 +459,7 @@
                                                / 1000;
                        }
                }
-               ed->hwINFO = cpu_to_le32(info);
+               ed->hwINFO = cpu_to_ohci32(ohci, info);
        }
 
 done:
@@ -468,7 +477,7 @@
  */
 static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed)
 {    
-       ed->hwINFO |= cpu_to_le32 (ED_DEQUEUE);
+       ed->hwINFO |= cpu_to_ohci32 (ohci, ED_DEQUEUE);
        ed_deschedule (ohci, ed);
 
        /* rm_list is just singly linked, for simplicity */
@@ -477,10 +486,10 @@
        ohci->ed_rm_list = ed;
 
        /* enable SOF interrupt */
-       writel (OHCI_INTR_SF, &ohci->regs->intrstatus);
-       writel (OHCI_INTR_SF, &ohci->regs->intrenable);
+       ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus);
+       ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
        // flush those writes, and get latest HCCA contents
-       (void) ohci_readl (&ohci->regs->control);
+       (void) ohci_readl (ohci, &ohci->regs->control);
 
        /* SF interrupt might get delayed; record the frame counter value that
         * indicates when the HC isn't looking at it, so concurrent unlinks
@@ -539,19 +548,19 @@
        if (!len)
                data = 0;
 
-       td->hwINFO = cpu_to_le32 (info);
+       td->hwINFO = cpu_to_ohci32 (ohci, info);
        if (is_iso) {
-               td->hwCBP = cpu_to_le32 (data & 0xFFFFF000);
-               td->hwPSW [0] = cpu_to_le16 ((data & 0x0FFF) | 0xE000);
+               td->hwCBP = cpu_to_ohci32 (ohci, data & 0xFFFFF000);
+               td->hwPSW [0] = cpu_to_ohci16 (ohci, (data & 0x0FFF) | 0xE000);
                td->ed->last_iso = info & 0xffff;
        } else {
-               td->hwCBP = cpu_to_le32 (data); 
+               td->hwCBP = cpu_to_ohci32 (ohci, data); 
        }                       
        if (data)
-               td->hwBE = cpu_to_le32 (data + len - 1);
+               td->hwBE = cpu_to_ohci32 (ohci, data + len - 1);
        else
                td->hwBE = 0;
-       td->hwNextTD = cpu_to_le32 (td_pt->td_dma);
+       td->hwNextTD = cpu_to_ohci32 (ohci, td_pt->td_dma);
 
        /* append to queue */
        list_add_tail (&td->td_list, &td->ed->td_list);
@@ -592,7 +601,7 @@
        if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
                usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
                        is_out, 1);
-               urb_priv->ed->hwHeadP &= ~cpu_to_le32 (ED_C);
+               urb_priv->ed->hwHeadP &= ~cpu_to_ohci32 (ohci, ED_C);
        }
 
        urb_priv->td_cnt = 0;
@@ -641,7 +650,7 @@
                /* maybe kickstart bulk list */
                if (urb_priv->ed->type == PIPE_BULK) {
                        wmb ();
-                       writel (OHCI_BLF, &ohci->regs->cmdstatus);
+                       ohci_writel (ohci, OHCI_BLF, &ohci->regs->cmdstatus);
                }
                break;
 
@@ -663,7 +672,7 @@
                td_fill (ohci, info, data, 0, urb, cnt++);
                /* maybe kickstart control list */
                wmb ();
-               writel (OHCI_CLF, &ohci->regs->cmdstatus);
+               ohci_writel (ohci, OHCI_CLF, &ohci->regs->cmdstatus);
                break;
 
        /* ISO has no retransmit, so no toggle; and it uses special TDs.
@@ -692,7 +701,7 @@
        if (periodic) {
                wmb ();
                ohci->hc_control |= OHCI_CTRL_PLE|OHCI_CTRL_IE;
-               writel (ohci->hc_control, &ohci->regs->control);
+               ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
        }
 
        // ASSERT (urb_priv->length == cnt);
@@ -707,14 +716,14 @@
  */
 static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
 {
-       u32     tdINFO = le32_to_cpup (&td->hwINFO);
+       u32     tdINFO = ohci32_to_cpup (ohci, &td->hwINFO);
        int     cc = 0;
 
        list_del (&td->td_list);
 
        /* ISO ... drivers see per-TD length/status */
        if (tdINFO & TD_ISO) {
-               u16     tdPSW = le16_to_cpu (td->hwPSW [0]);
+               u16     tdPSW = ohci16_to_cpu (ohci, td->hwPSW [0]);
                int     dlen = 0;
 
                /* NOTE:  assumes FC in tdINFO == 0 (and MAXPSW == 1) */
@@ -746,7 +755,7 @@
         */
        } else {
                int     type = usb_pipetype (urb->pipe);
-               u32     tdBE = le32_to_cpup (&td->hwBE);
+               u32     tdBE = ohci32_to_cpup (ohci, &td->hwBE);
 
                cc = TD_CC_GET (tdINFO);
 
@@ -773,7 +782,7 @@
                                urb->actual_length += tdBE - td->data_dma + 1;
                        else
                                urb->actual_length +=
-                                         le32_to_cpup (&td->hwCBP)
+                                         ohci32_to_cpup (ohci, &td->hwCBP)
                                        - td->data_dma;
                }
 
@@ -791,17 +800,17 @@
 static inline struct td *
 ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
 {
-       struct urb              *urb = td->urb;
-       struct ed               *ed = td->ed;
-       struct list_head        *tmp = td->td_list.next;
-       u32                     toggle = ed->hwHeadP & cpu_to_le32 (ED_C);
+       struct urb      *urb = td->urb;
+       struct ed       *ed = td->ed;
+       struct list_head *tmp = td->td_list.next;
+       u32             toggle = ed->hwHeadP & cpu_to_ohci32 (ohci, ED_C);
 
        /* clear ed halt; this is the td that caused it, but keep it inactive
         * until its urb->complete() has a chance to clean up.
         */
-       ed->hwINFO |= cpu_to_le32 (ED_SKIP);
+       ed->hwINFO |= cpu_to_ohci32 (ohci, ED_SKIP);
        wmb ();
-       ed->hwHeadP &= ~cpu_to_le32 (ED_H); 
+       ed->hwHeadP &= ~cpu_to_ohci32 (ohci, ED_H); 
 
        /* put any later tds from this urb onto the donelist, after 'td',
         * order won't matter here: no errors, and nothing was transferred.
@@ -825,8 +834,8 @@
                 * and clear ED_SKIP.
                 */
                info = next->hwINFO;
-               info |= cpu_to_le32 (TD_DONE);
-               info &= ~cpu_to_le32 (TD_CC);
+               info |= cpu_to_ohci32 (ohci, TD_DONE);
+               info &= ~cpu_to_ohci32 (ohci, TD_CC);
                next->hwINFO = info;
 
                next->next_dl_td = rev; 
@@ -854,7 +863,7 @@
                        urb, urb->dev->devpath,
                        usb_pipeendpoint (urb->pipe),
                        usb_pipein (urb->pipe) ? "in" : "out",
-                       le32_to_cpu (td->hwINFO),
+                       ohci32_to_cpu (ohci, td->hwINFO),
                        cc, cc_to_error [cc]);
        }
 
@@ -870,7 +879,7 @@
        struct td       *td_rev = NULL;
        struct td       *td = NULL;
 
-       td_dma = le32_to_cpup (&ohci->hcca->done_head);
+       td_dma = ohci32_to_cpup (ohci, &ohci->hcca->done_head);
        ohci->hcca->done_head = 0;
        wmb();
 
@@ -886,20 +895,20 @@
                        break;
                }
 
-               td->hwINFO |= cpu_to_le32 (TD_DONE);
-               cc = TD_CC_GET (le32_to_cpup (&td->hwINFO));
+               td->hwINFO |= cpu_to_ohci32 (ohci, TD_DONE);
+               cc = TD_CC_GET (ohci32_to_cpup (ohci, &td->hwINFO));
 
                /* Non-iso endpoints can halt on error; un-halt,
                 * and dequeue any other TDs from this urb.
                 * No other TD could have caused the halt.
                 */
                if (cc != TD_CC_NOERROR &&
-                               (td->ed->hwHeadP & cpu_to_le32 (ED_H)))
+                               (td->ed->hwHeadP & cpu_to_ohci32 (ohci, ED_H)))
                        td_rev = ed_halted (ohci, td, cc, td_rev);
 
                td->next_dl_td = td_rev;        
                td_rev = td;
-               td_dma = le32_to_cpup (&td->hwNextTD);
+               td_dma = ohci32_to_cpup (ohci, &td->hwNextTD);
        }       
        return td_rev;
 }
@@ -937,7 +946,8 @@
 
                                td = list_entry (ed->td_list.next, struct td,
                                                        td_list);
-                               head = cpu_to_le32 (ed->hwHeadP) & TD_MASK;
+                               head = ohci32_to_cpu (ohci, ed->hwHeadP) &
+                                                               TD_MASK;
 
                                /* INTR_WDH may need to clean up first */
                                if (td->td_dma != head)
@@ -980,7 +990,7 @@
                        }
 
                        /* patch pointer hc uses */
-                       savebits = *prev & ~cpu_to_le32 (TD_MASK);
+                       savebits = *prev & ~cpu_to_ohci32 (ohci, TD_MASK);
                        *prev = td->hwNextTD | savebits;
 
                        /* HC may have partly processed this TD */
@@ -998,10 +1008,10 @@
 
                /* ED's now officially unlinked, hc doesn't see */
                ed->state = ED_IDLE;
-               ed->hwHeadP &= ~cpu_to_le32(ED_H);
+               ed->hwHeadP &= ~cpu_to_ohci32(ohci, ED_H);
                ed->hwNextED = 0;
                wmb ();
-               ed->hwINFO &= ~cpu_to_le32 (ED_SKIP | ED_DEQUEUE);
+               ed->hwINFO &= ~cpu_to_ohci32 (ohci, ED_SKIP | ED_DEQUEUE);
 
                /* but if there's work queued, reschedule */
                if (!list_empty (&ed->td_list)) {
@@ -1023,24 +1033,27 @@
                        command |= OHCI_CLF;
                        if (!(ohci->hc_control & OHCI_CTRL_CLE)) {
                                control |= OHCI_CTRL_CLE;
-                               writel (0, &ohci->regs->ed_controlcurrent);
+                               ohci_writel (ohci, 0,
+                                       &ohci->regs->ed_controlcurrent);
                        }
                }
                if (ohci->ed_bulktail) {
                        command |= OHCI_BLF;
                        if (!(ohci->hc_control & OHCI_CTRL_BLE)) {
                                control |= OHCI_CTRL_BLE;
-                               writel (0, &ohci->regs->ed_bulkcurrent);
+                               ohci_writel (ohci, 0,
+                                       &ohci->regs->ed_bulkcurrent);
                        }
                }
                
                /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */
                if (control) {
                        ohci->hc_control |= control;
-                       writel (ohci->hc_control, &ohci->regs->control);   
+                       ohci_writel (ohci, ohci->hc_control,
+                                       &ohci->regs->control);   
                }
                if (command)
-                       writel (command, &ohci->regs->cmdstatus);   
+                       ohci_writel (ohci, command, &ohci->regs->cmdstatus);   
        }
 }
 
@@ -1080,18 +1093,18 @@
                                start_ed_unlink (ohci, ed);
 
                /* ... reenabling halted EDs only after fault cleanup */
-               } else if ((ed->hwINFO & cpu_to_le32 (ED_SKIP | ED_DEQUEUE)) == 
cpu_to_le32 (ED_SKIP)) {
+               } else if ((ed->hwINFO & cpu_to_ohci32 (ohci, ED_SKIP | ED_DEQUEUE)) 
== cpu_to_ohci32 (ohci, ED_SKIP)) {
                        td = list_entry (ed->td_list.next, struct td, td_list);
-                       if (!(td->hwINFO & cpu_to_le32 (TD_DONE))) {
-                               ed->hwINFO &= ~cpu_to_le32 (ED_SKIP);
+                       if (!(td->hwINFO & cpu_to_ohci32 (ohci, TD_DONE))) {
+                               ed->hwINFO &= ~cpu_to_ohci32 (ohci, ED_SKIP);
                                /* ... hc may need waking-up */
                                switch (ed->type) {
                                case PIPE_CONTROL:
-                                       writel (OHCI_CLF,
+                                       ohci_writel (ohci, OHCI_CLF,
                                                &ohci->regs->cmdstatus);   
                                        break;
                                case PIPE_BULK:
-                                       writel (OHCI_BLF,
+                                       ohci_writel (ohci, OHCI_BLF,
                                                &ohci->regs->cmdstatus);   
                                        break;
                                }
diff -Nru a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
--- a/drivers/usb/host/ohci.h   2004-08-19 18:00:30 -07:00
+++ b/drivers/usb/host/ohci.h   2004-08-19 18:00:30 -07:00
@@ -377,9 +377,10 @@
 
        struct work_struct      rh_resume;
 
-       unsigned long           flags;          /* for HC bugs */
+       unsigned long           flags;          /* for HC bugs (features?) */
 #define        OHCI_QUIRK_AMD756       0x01                    /* erratum #4 */
 #define        OHCI_QUIRK_SUPERIO      0x02                    /* natsemi */
+#define        OHCI_BIG_ENDIAN         0x04                    /* big endian HC */
        // there are also chip quirks/bugs in init logic
 
        /*
@@ -392,24 +393,6 @@
 
 /*-------------------------------------------------------------------------*/
 
-static inline void disable (struct ohci_hcd *ohci)
-{
-       ohci->hcd.state = USB_STATE_HALT;
-}
-
-#define        FI                      0x2edf          /* 12000 bits per frame (-1) */
-#define        DEFAULT_FMINTERVAL      ((((6 * (FI - 210)) / 7) << 16) | FI)
-#define LSTHRESH               0x628           /* lowspeed bit threshold */
-
-static inline void periodic_reinit (struct ohci_hcd *ohci)
-{
-       writel (ohci->fminterval, &ohci->regs->fminterval);
-       writel (((9 * FI) / 10) & 0x3fff, &ohci->regs->periodicstart);
-       writel (LSTHRESH, &ohci->regs->lsthresh);
-}
-
-/*-------------------------------------------------------------------------*/
-
 #ifndef DEBUG
 #define STUB_DEBUG_FILES
 #endif /* DEBUG */
@@ -429,13 +412,32 @@
 #      define ohci_vdbg(ohci, fmt, args...) do { } while (0)
 #endif
 
+/*
+ * While most USB host controllers implement their registers and
+ * in-memory communication descriptors in little-endian format,
+ * a minority (notably the IBM STB04XXX and the Motorola MPC5200
+ * processors) implement them in big endian format.  This file
+ * attempts to support either format at compile time without a
+ * runtime penalty, or both formats with the additional overhead
+ * of checking an endian flag bit.
+ */
+
+#if !defined(CONFIG_USB_OHCI_BIG_ENDIAN)
+#define big_endian(ohci)       0               /* only little endian */
+#elif !defined(CONFIG_USB_OHCI_LITTLE_ENDIAN)
+#define big_endian(ohci)       1               /* only big endian */
+#else
+#define big_endian(ohci)       (ohci->flags & OHCI_BIG_ENDIAN)
+#endif
+
 #ifdef CONFIG_ARCH_LH7A404
        /* Marc Singer: at the time this code was written, the LH7A404
         * had a problem reading the USB host registers.  This
         * implementation of the ohci_readl function performs the read
         * twice as a work-around.
         */
-static inline unsigned int ohci_readl (void* regs)
+static inline unsigned int ohci_readl (const struct ohci_hcd *ohci,
+                                      const void* regs)
 {
        *(volatile unsigned int*) regs;
        return *(volatile unsigned int*) regs;
@@ -443,8 +445,85 @@
 #else
        /* Standard version of ohci_readl uses standard, platform
         * specific implementation. */
-static inline unsigned int ohci_readl (void* regs)
+static inline unsigned int ohci_readl (const struct ohci_hcd *ohci,
+                                      const void* regs)
 {
-       return readl (regs);
+       return big_endian(ohci) ? in_be32((void *)regs) : readl(regs);
 }
 #endif
+
+static inline void ohci_writel (const struct ohci_hcd *ohci,
+                               const unsigned int val, void *regs)
+{
+       return big_endian(ohci) ?  out_be32(regs, val) : writel(val, regs);
+}
+
+/* cpu to ohci */
+static inline __u16 cpu_to_ohci16 (const struct ohci_hcd *ohci,
+                                  const __u16 x)
+{
+       return big_endian(ohci) ? cpu_to_be16(x) : cpu_to_le16(x);
+}
+
+static inline __u16 cpu_to_ohci16p (const struct ohci_hcd *ohci, 
+                                   const __u16 *x)
+{
+       return big_endian(ohci) ? cpu_to_be16p(x) : cpu_to_le16p(x);
+}
+
+static inline __u32 cpu_to_ohci32 (const struct ohci_hcd *ohci,
+                                  const __u32 x)
+{
+       return big_endian(ohci) ? cpu_to_be32(x) : cpu_to_le32(x);
+}
+
+static inline __u32 cpu_to_ohci32p (const struct ohci_hcd *ohci,
+                                   const __u32 *x)
+{
+       return big_endian(ohci) ? cpu_to_be32p(x) : cpu_to_le32p(x);
+}
+
+/* ohci to cpu */
+static inline __u16 ohci16_to_cpu (const struct ohci_hcd *ohci,
+                                  const __u16 x)
+{
+       return big_endian(ohci) ? be16_to_cpu(x) : le16_to_cpu(x);
+}
+
+static inline __u16 ohci16_to_cpup (const struct ohci_hcd *ohci,
+                                   const __u16 *x)
+{
+       return big_endian(ohci) ? be16_to_cpup(x) : le16_to_cpup(x);
+}
+
+static inline __u32 ohci32_to_cpu (const struct ohci_hcd *ohci,
+                                  const __u32 x)
+{
+       return big_endian(ohci) ? be32_to_cpu(x) : le32_to_cpu(x);
+}
+
+static inline __u32 ohci32_to_cpup (const struct ohci_hcd *ohci,
+                                   const __u32 *x)
+{
+       return big_endian(ohci) ? be32_to_cpup(x) : le32_to_cpup(x);
+}
+
+/*-------------------------------------------------------------------------*/
+
+static inline void disable (struct ohci_hcd *ohci)
+{
+       ohci->hcd.state = USB_STATE_HALT;
+}
+
+#define        FI                      0x2edf          /* 12000 bits per frame (-1) */
+#define        DEFAULT_FMINTERVAL      ((((6 * (FI - 210)) / 7) << 16) | FI)
+#define LSTHRESH               0x628           /* lowspeed bit threshold */
+
+
+static inline void periodic_reinit (struct ohci_hcd *ohci)
+{
+       ohci_writel (ohci, ohci->fminterval, &ohci->regs->fminterval);
+       ohci_writel (ohci, ((9 * FI) / 10) & 0x3fff,
+                       &ohci->regs->periodicstart);
+       ohci_writel (ohci, LSTHRESH, &ohci->regs->lsthresh);
+}



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to