Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1 | /* |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 2 | * URB OHCI HCD (Host Controller Driver) for USB on the PPC440EP. |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 3 | * |
| 4 | * (C) Copyright 2003-2004 |
Detlev Zundel | 792a09e | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 5 | * Gary Jennejohn, DENX Software Engineering <garyj@denx.de> |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 6 | * |
| 7 | * (C) Copyright 2004 |
| 8 | * Pierre Aubert, Staubli Faverges <p.aubert@staubli.com> |
| 9 | * |
| 10 | * Note: Much of this code has been derived from Linux 2.4 |
| 11 | * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> |
| 12 | * (C) Copyright 2000-2002 David Brownell |
| 13 | * |
| 14 | * See file CREDITS for list of people who contributed to this |
| 15 | * project. |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or |
| 18 | * modify it under the terms of the GNU General Public License as |
| 19 | * published by the Free Software Foundation; either version 2 of |
| 20 | * the License, or (at your option) any later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, write to the Free Software |
| 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 30 | * MA 02111-1307 USA |
| 31 | * |
| 32 | */ |
| 33 | /* |
| 34 | * IMPORTANT NOTES |
| 35 | * 1 - this driver is intended for use with USB Mass Storage Devices |
| 36 | * (BBB) ONLY. There is NO support for Interrupt or Isochronous pipes! |
| 37 | */ |
| 38 | |
| 39 | #include <common.h> |
| 40 | |
| 41 | #ifdef CONFIG_USB_OHCI |
| 42 | |
| 43 | #include <malloc.h> |
| 44 | #include <usb.h> |
| 45 | #include "usb_ohci.h" |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 46 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 47 | #include "usbdev.h" |
| 48 | |
| 49 | #define OHCI_USE_NPS /* force NoPowerSwitching mode */ |
| 50 | #undef OHCI_VERBOSE_DEBUG /* not always helpful */ |
| 51 | #undef DEBUG |
| 52 | #undef SHOW_INFO |
| 53 | #undef OHCI_FILL_TRACE |
| 54 | |
| 55 | /* For initializing controller (mask in an HCFS mode too) */ |
| 56 | #define OHCI_CONTROL_INIT \ |
| 57 | (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE |
| 58 | |
Wolfgang Denk | d00ce09 | 2008-04-25 12:44:08 +0200 | [diff] [blame] | 59 | #define readl(a) (*((volatile u32 *)(a))) |
| 60 | #define writel(a, b) (*((volatile u32 *)(b)) = ((volatile u32)a)) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 61 | |
| 62 | #define min_t(type,x,y) ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) |
| 63 | |
| 64 | #ifdef DEBUG |
| 65 | #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg) |
| 66 | #else |
| 67 | #define dbg(format, arg...) do {} while(0) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 68 | #endif /* DEBUG */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 69 | #define err(format, arg...) printf("ERROR: " format "\n", ## arg) |
| 70 | #ifdef SHOW_INFO |
| 71 | #define info(format, arg...) printf("INFO: " format "\n", ## arg) |
| 72 | #else |
| 73 | #define info(format, arg...) do {} while(0) |
| 74 | #endif |
| 75 | |
| 76 | #define m16_swap(x) swap_16(x) |
| 77 | #define m32_swap(x) swap_32(x) |
| 78 | |
Stefan Roese | e01bd21 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 79 | #if defined(CONFIG_405EZ) || defined(CONFIG_440EP) || defined(CONFIG_440EPX) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 80 | #define ohci_cpu_to_le16(x) (x) |
| 81 | #define ohci_cpu_to_le32(x) (x) |
| 82 | #else |
| 83 | #define ohci_cpu_to_le16(x) swap_16(x) |
| 84 | #define ohci_cpu_to_le32(x) swap_32(x) |
| 85 | #endif |
| 86 | |
| 87 | /* global ohci_t */ |
| 88 | static ohci_t gohci; |
| 89 | /* this must be aligned to a 256 byte boundary */ |
| 90 | struct ohci_hcca ghcca[1]; |
| 91 | /* a pointer to the aligned storage */ |
| 92 | struct ohci_hcca *phcca; |
| 93 | /* this allocates EDs for all possible endpoints */ |
| 94 | struct ohci_device ohci_dev; |
| 95 | /* urb_priv */ |
| 96 | urb_priv_t urb_priv; |
| 97 | /* RHSC flag */ |
| 98 | int got_rhsc; |
| 99 | /* device which was disconnected */ |
| 100 | struct usb_device *devgone; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 101 | /* flag guarding URB transation */ |
| 102 | int urb_finished = 0; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 103 | |
| 104 | /*-------------------------------------------------------------------------*/ |
| 105 | |
| 106 | /* AMD-756 (D2 rev) reports corrupt register contents in some cases. |
| 107 | * The erratum (#4) description is incorrect. AMD's workaround waits |
| 108 | * till some bits (mostly reserved) are clear; ok for all revs. |
| 109 | */ |
| 110 | #define OHCI_QUIRK_AMD756 0xabcd |
| 111 | #define read_roothub(hc, register, mask) ({ \ |
| 112 | u32 temp = readl (&hc->regs->roothub.register); \ |
| 113 | if (hc->flags & OHCI_QUIRK_AMD756) \ |
| 114 | while (temp & mask) \ |
| 115 | temp = readl (&hc->regs->roothub.register); \ |
| 116 | temp; }) |
| 117 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 118 | static u32 roothub_a (struct ohci *hc) |
| 119 | { return read_roothub (hc, a, 0xfc0fe000); } |
| 120 | static inline u32 roothub_b (struct ohci *hc) |
| 121 | { return readl (&hc->regs->roothub.b); } |
| 122 | static inline u32 roothub_status (struct ohci *hc) |
| 123 | { return readl (&hc->regs->roothub.status); } |
| 124 | static u32 roothub_portstatus (struct ohci *hc, int i) |
| 125 | { return read_roothub (hc, portstatus [i], 0xffe0fce0); } |
| 126 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 127 | |
| 128 | /* forward declaration */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 129 | static int hc_interrupt (void); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 130 | static void |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 131 | td_submit_job (struct usb_device * dev, unsigned long pipe, void * buffer, |
| 132 | int transfer_len, struct devrequest * setup, urb_priv_t * urb, int interval); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 133 | |
| 134 | /*-------------------------------------------------------------------------* |
| 135 | * URB support functions |
| 136 | *-------------------------------------------------------------------------*/ |
| 137 | |
| 138 | /* free HCD-private data associated with this URB */ |
| 139 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 140 | static void urb_free_priv (urb_priv_t * urb) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 141 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 142 | int i; |
| 143 | int last; |
| 144 | struct td * td; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 145 | |
| 146 | last = urb->length - 1; |
| 147 | if (last >= 0) { |
| 148 | for (i = 0; i <= last; i++) { |
| 149 | td = urb->td[i]; |
| 150 | if (td) { |
| 151 | td->usb_dev = NULL; |
| 152 | urb->td[i] = NULL; |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /*-------------------------------------------------------------------------*/ |
| 159 | |
| 160 | #ifdef DEBUG |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 161 | static int sohci_get_current_frame_number (struct usb_device * dev); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 162 | |
| 163 | /* debug| print the main components of an URB |
| 164 | * small: 0) header + data packets 1) just header */ |
| 165 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 166 | static void pkt_print (struct usb_device * dev, unsigned long pipe, void * buffer, |
| 167 | int transfer_len, struct devrequest * setup, char * str, int small) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 168 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 169 | urb_priv_t * purb = &urb_priv; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 170 | |
| 171 | dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx", |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 172 | str, |
| 173 | sohci_get_current_frame_number (dev), |
| 174 | usb_pipedevice (pipe), |
| 175 | usb_pipeendpoint (pipe), |
| 176 | usb_pipeout (pipe)? 'O': 'I', |
| 177 | usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"): |
| 178 | (usb_pipecontrol (pipe)? "CTRL": "BULK"), |
| 179 | purb->actual_length, |
| 180 | transfer_len, dev->status); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 181 | #ifdef OHCI_VERBOSE_DEBUG |
| 182 | if (!small) { |
| 183 | int i, len; |
| 184 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 185 | if (usb_pipecontrol (pipe)) { |
| 186 | printf (__FILE__ ": cmd(8):"); |
| 187 | for (i = 0; i < 8 ; i++) |
| 188 | printf (" %02x", ((__u8 *) setup) [i]); |
| 189 | printf ("\n"); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 190 | } |
| 191 | if (transfer_len > 0 && buffer) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 192 | printf (__FILE__ ": data(%d/%d):", |
| 193 | purb->actual_length, |
| 194 | transfer_len); |
| 195 | len = usb_pipeout (pipe)? |
| 196 | transfer_len: purb->actual_length; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 197 | for (i = 0; i < 16 && i < len; i++) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 198 | printf (" %02x", ((__u8 *) buffer) [i]); |
| 199 | printf ("%s\n", i < len? "...": ""); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | #endif |
| 203 | } |
| 204 | |
| 205 | /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 206 | void ep_print_int_eds (ohci_t *ohci, char * str) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 207 | int i, j; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 208 | __u32 * ed_p; |
| 209 | for (i= 0; i < 32; i++) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 210 | j = 5; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 211 | ed_p = &(ohci->hcca->int_table [i]); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 212 | if (*ed_p == 0) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 213 | continue; |
| 214 | printf (__FILE__ ": %s branch int %2d(%2x):", str, i, i); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 215 | while (*ed_p != 0 && j--) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 216 | ed_t *ed = (ed_t *)ohci_cpu_to_le32(ed_p); |
| 217 | printf (" ed: %4x;", ed->hwINFO); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 218 | ed_p = &ed->hwNextED; |
| 219 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 220 | printf ("\n"); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 224 | static void ohci_dump_intr_mask (char *label, __u32 mask) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 225 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 226 | dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s", |
| 227 | label, |
| 228 | mask, |
| 229 | (mask & OHCI_INTR_MIE) ? " MIE" : "", |
| 230 | (mask & OHCI_INTR_OC) ? " OC" : "", |
| 231 | (mask & OHCI_INTR_RHSC) ? " RHSC" : "", |
| 232 | (mask & OHCI_INTR_FNO) ? " FNO" : "", |
| 233 | (mask & OHCI_INTR_UE) ? " UE" : "", |
| 234 | (mask & OHCI_INTR_RD) ? " RD" : "", |
| 235 | (mask & OHCI_INTR_SF) ? " SF" : "", |
| 236 | (mask & OHCI_INTR_WDH) ? " WDH" : "", |
| 237 | (mask & OHCI_INTR_SO) ? " SO" : "" |
| 238 | ); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 241 | static void maybe_print_eds (char *label, __u32 value) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 242 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 243 | ed_t *edp = (ed_t *)value; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 244 | |
| 245 | if (value) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 246 | dbg ("%s %08x", label, value); |
| 247 | dbg ("%08x", edp->hwINFO); |
| 248 | dbg ("%08x", edp->hwTailP); |
| 249 | dbg ("%08x", edp->hwHeadP); |
| 250 | dbg ("%08x", edp->hwNextED); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 254 | static char * hcfs2string (int state) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 255 | { |
| 256 | switch (state) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 257 | case OHCI_USB_RESET: return "reset"; |
| 258 | case OHCI_USB_RESUME: return "resume"; |
| 259 | case OHCI_USB_OPER: return "operational"; |
| 260 | case OHCI_USB_SUSPEND: return "suspend"; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 261 | } |
| 262 | return "?"; |
| 263 | } |
| 264 | |
| 265 | /* dump control and status registers */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 266 | static void ohci_dump_status (ohci_t *controller) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 267 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 268 | struct ohci_regs *regs = controller->regs; |
| 269 | __u32 temp; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 270 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 271 | temp = readl (®s->revision) & 0xff; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 272 | if (temp != 0x10) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 273 | dbg ("spec %d.%d", (temp >> 4), (temp & 0x0f)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 274 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 275 | temp = readl (®s->control); |
| 276 | dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp, |
| 277 | (temp & OHCI_CTRL_RWE) ? " RWE" : "", |
| 278 | (temp & OHCI_CTRL_RWC) ? " RWC" : "", |
| 279 | (temp & OHCI_CTRL_IR) ? " IR" : "", |
| 280 | hcfs2string (temp & OHCI_CTRL_HCFS), |
| 281 | (temp & OHCI_CTRL_BLE) ? " BLE" : "", |
| 282 | (temp & OHCI_CTRL_CLE) ? " CLE" : "", |
| 283 | (temp & OHCI_CTRL_IE) ? " IE" : "", |
| 284 | (temp & OHCI_CTRL_PLE) ? " PLE" : "", |
| 285 | temp & OHCI_CTRL_CBSR |
| 286 | ); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 287 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 288 | temp = readl (®s->cmdstatus); |
| 289 | dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp, |
| 290 | (temp & OHCI_SOC) >> 16, |
| 291 | (temp & OHCI_OCR) ? " OCR" : "", |
| 292 | (temp & OHCI_BLF) ? " BLF" : "", |
| 293 | (temp & OHCI_CLF) ? " CLF" : "", |
| 294 | (temp & OHCI_HCR) ? " HCR" : "" |
| 295 | ); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 296 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 297 | ohci_dump_intr_mask ("intrstatus", readl (®s->intrstatus)); |
| 298 | ohci_dump_intr_mask ("intrenable", readl (®s->intrenable)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 299 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 300 | maybe_print_eds ("ed_periodcurrent", readl (®s->ed_periodcurrent)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 301 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 302 | maybe_print_eds ("ed_controlhead", readl (®s->ed_controlhead)); |
| 303 | maybe_print_eds ("ed_controlcurrent", readl (®s->ed_controlcurrent)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 304 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 305 | maybe_print_eds ("ed_bulkhead", readl (®s->ed_bulkhead)); |
| 306 | maybe_print_eds ("ed_bulkcurrent", readl (®s->ed_bulkcurrent)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 307 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 308 | maybe_print_eds ("donehead", readl (®s->donehead)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 311 | static void ohci_dump_roothub (ohci_t *controller, int verbose) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 312 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 313 | __u32 temp, ndp, i; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 314 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 315 | temp = roothub_a (controller); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 316 | ndp = (temp & RH_A_NDP); |
| 317 | |
| 318 | if (verbose) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 319 | dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp, |
| 320 | ((temp & RH_A_POTPGT) >> 24) & 0xff, |
| 321 | (temp & RH_A_NOCP) ? " NOCP" : "", |
| 322 | (temp & RH_A_OCPM) ? " OCPM" : "", |
| 323 | (temp & RH_A_DT) ? " DT" : "", |
| 324 | (temp & RH_A_NPS) ? " NPS" : "", |
| 325 | (temp & RH_A_PSM) ? " PSM" : "", |
| 326 | ndp |
| 327 | ); |
| 328 | temp = roothub_b (controller); |
| 329 | dbg ("roothub.b: %08x PPCM=%04x DR=%04x", |
| 330 | temp, |
| 331 | (temp & RH_B_PPCM) >> 16, |
| 332 | (temp & RH_B_DR) |
| 333 | ); |
| 334 | temp = roothub_status (controller); |
| 335 | dbg ("roothub.status: %08x%s%s%s%s%s%s", |
| 336 | temp, |
| 337 | (temp & RH_HS_CRWE) ? " CRWE" : "", |
| 338 | (temp & RH_HS_OCIC) ? " OCIC" : "", |
| 339 | (temp & RH_HS_LPSC) ? " LPSC" : "", |
| 340 | (temp & RH_HS_DRWE) ? " DRWE" : "", |
| 341 | (temp & RH_HS_OCI) ? " OCI" : "", |
| 342 | (temp & RH_HS_LPS) ? " LPS" : "" |
| 343 | ); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | for (i = 0; i < ndp; i++) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 347 | temp = roothub_portstatus (controller, i); |
| 348 | dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s", |
| 349 | i, |
| 350 | temp, |
| 351 | (temp & RH_PS_PRSC) ? " PRSC" : "", |
| 352 | (temp & RH_PS_OCIC) ? " OCIC" : "", |
| 353 | (temp & RH_PS_PSSC) ? " PSSC" : "", |
| 354 | (temp & RH_PS_PESC) ? " PESC" : "", |
| 355 | (temp & RH_PS_CSC) ? " CSC" : "", |
| 356 | |
| 357 | (temp & RH_PS_LSDA) ? " LSDA" : "", |
| 358 | (temp & RH_PS_PPS) ? " PPS" : "", |
| 359 | (temp & RH_PS_PRS) ? " PRS" : "", |
| 360 | (temp & RH_PS_POCI) ? " POCI" : "", |
| 361 | (temp & RH_PS_PSS) ? " PSS" : "", |
| 362 | |
| 363 | (temp & RH_PS_PES) ? " PES" : "", |
| 364 | (temp & RH_PS_CCS) ? " CCS" : "" |
| 365 | ); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 369 | static void ohci_dump (ohci_t *controller, int verbose) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 370 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 371 | dbg ("OHCI controller usb-%s state", controller->slot_name); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 372 | |
| 373 | /* dumps some of the state we know about */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 374 | ohci_dump_status (controller); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 375 | if (verbose) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 376 | ep_print_int_eds (controller, "hcca"); |
| 377 | dbg ("hcca frame #%04x", controller->hcca->frame_no); |
| 378 | ohci_dump_roothub (controller, 1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 379 | } |
| 380 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 381 | |
| 382 | #endif /* DEBUG */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 383 | |
| 384 | /*-------------------------------------------------------------------------* |
| 385 | * Interface functions (URB) |
| 386 | *-------------------------------------------------------------------------*/ |
| 387 | |
| 388 | /* get a transfer request */ |
| 389 | |
| 390 | int sohci_submit_job(struct usb_device *dev, unsigned long pipe, void *buffer, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 391 | int transfer_len, struct devrequest *setup, int interval) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 392 | { |
| 393 | ohci_t *ohci; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 394 | ed_t * ed; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 395 | urb_priv_t *purb_priv; |
| 396 | int i, size = 0; |
| 397 | |
| 398 | ohci = &gohci; |
| 399 | |
| 400 | /* when controller's hung, permit only roothub cleanup attempts |
| 401 | * such as powering down ports */ |
| 402 | if (ohci->disabled) { |
| 403 | err("sohci_submit_job: EPIPE"); |
| 404 | return -1; |
| 405 | } |
| 406 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 407 | /* if we have an unfinished URB from previous transaction let's |
| 408 | * fail and scream as quickly as possible so as not to corrupt |
| 409 | * further communication */ |
| 410 | if (!urb_finished) { |
| 411 | err("sohci_submit_job: URB NOT FINISHED"); |
| 412 | return -1; |
| 413 | } |
| 414 | /* we're about to begin a new transaction here so mark the URB unfinished */ |
| 415 | urb_finished = 0; |
| 416 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 417 | /* every endpoint has a ed, locate and fill it */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 418 | if (!(ed = ep_add_ed (dev, pipe))) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 419 | err("sohci_submit_job: ENOMEM"); |
| 420 | return -1; |
| 421 | } |
| 422 | |
| 423 | /* for the private part of the URB we need the number of TDs (size) */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 424 | switch (usb_pipetype (pipe)) { |
| 425 | case PIPE_BULK: /* one TD for every 4096 Byte */ |
| 426 | size = (transfer_len - 1) / 4096 + 1; |
| 427 | break; |
| 428 | case PIPE_CONTROL: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */ |
| 429 | size = (transfer_len == 0)? 2: |
| 430 | (transfer_len - 1) / 4096 + 3; |
| 431 | break; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | if (size >= (N_URB_TD - 1)) { |
| 435 | err("need %d TDs, only have %d", size, N_URB_TD); |
| 436 | return -1; |
| 437 | } |
| 438 | purb_priv = &urb_priv; |
| 439 | purb_priv->pipe = pipe; |
| 440 | |
| 441 | /* fill the private part of the URB */ |
| 442 | purb_priv->length = size; |
| 443 | purb_priv->ed = ed; |
| 444 | purb_priv->actual_length = 0; |
| 445 | |
| 446 | /* allocate the TDs */ |
| 447 | /* note that td[0] was allocated in ep_add_ed */ |
| 448 | for (i = 0; i < size; i++) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 449 | purb_priv->td[i] = td_alloc (dev); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 450 | if (!purb_priv->td[i]) { |
| 451 | purb_priv->length = i; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 452 | urb_free_priv (purb_priv); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 453 | err("sohci_submit_job: ENOMEM"); |
| 454 | return -1; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | if (ed->state == ED_NEW || (ed->state & ED_DEL)) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 459 | urb_free_priv (purb_priv); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 460 | err("sohci_submit_job: EINVAL"); |
| 461 | return -1; |
| 462 | } |
| 463 | |
| 464 | /* link the ed into a chain if is not already */ |
| 465 | if (ed->state != ED_OPER) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 466 | ep_link (ohci, ed); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 467 | |
| 468 | /* fill the TDs and link it to the ed */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 469 | td_submit_job(dev, pipe, buffer, transfer_len, setup, purb_priv, interval); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | /*-------------------------------------------------------------------------*/ |
| 475 | |
| 476 | #ifdef DEBUG |
| 477 | /* tell us the current USB frame number */ |
| 478 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 479 | static int sohci_get_current_frame_number (struct usb_device *usb_dev) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 480 | { |
| 481 | ohci_t *ohci = &gohci; |
| 482 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 483 | return ohci_cpu_to_le16 (ohci->hcca->frame_no); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 484 | } |
| 485 | #endif |
| 486 | |
| 487 | /*-------------------------------------------------------------------------* |
| 488 | * ED handling functions |
| 489 | *-------------------------------------------------------------------------*/ |
| 490 | |
| 491 | /* link an ed into one of the HC chains */ |
| 492 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 493 | static int ep_link (ohci_t *ohci, ed_t *edi) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 494 | { |
| 495 | volatile ed_t *ed = edi; |
| 496 | |
| 497 | ed->state = ED_OPER; |
| 498 | |
| 499 | switch (ed->type) { |
| 500 | case PIPE_CONTROL: |
| 501 | ed->hwNextED = 0; |
| 502 | if (ohci->ed_controltail == NULL) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 503 | writel (ed, &ohci->regs->ed_controlhead); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 504 | } else { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 505 | ohci->ed_controltail->hwNextED = ohci_cpu_to_le32 ((unsigned long)ed); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 506 | } |
| 507 | ed->ed_prev = ohci->ed_controltail; |
| 508 | if (!ohci->ed_controltail && !ohci->ed_rm_list[0] && |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 509 | !ohci->ed_rm_list[1] && !ohci->sleeping) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 510 | ohci->hc_control |= OHCI_CTRL_CLE; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 511 | writel (ohci->hc_control, &ohci->regs->control); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 512 | } |
| 513 | ohci->ed_controltail = edi; |
| 514 | break; |
| 515 | |
| 516 | case PIPE_BULK: |
| 517 | ed->hwNextED = 0; |
| 518 | if (ohci->ed_bulktail == NULL) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 519 | writel (ed, &ohci->regs->ed_bulkhead); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 520 | } else { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 521 | ohci->ed_bulktail->hwNextED = ohci_cpu_to_le32 ((unsigned long)ed); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 522 | } |
| 523 | ed->ed_prev = ohci->ed_bulktail; |
| 524 | if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] && |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 525 | !ohci->ed_rm_list[1] && !ohci->sleeping) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 526 | ohci->hc_control |= OHCI_CTRL_BLE; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 527 | writel (ohci->hc_control, &ohci->regs->control); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 528 | } |
| 529 | ohci->ed_bulktail = edi; |
| 530 | break; |
| 531 | } |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | /*-------------------------------------------------------------------------*/ |
| 536 | |
| 537 | /* unlink an ed from one of the HC chains. |
| 538 | * just the link to the ed is unlinked. |
| 539 | * the link from the ed still points to another operational ed or 0 |
| 540 | * so the HC can eventually finish the processing of the unlinked ed */ |
| 541 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 542 | static int ep_unlink (ohci_t *ohci, ed_t *edi) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 543 | { |
| 544 | volatile ed_t *ed = edi; |
| 545 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 546 | ed->hwINFO |= ohci_cpu_to_le32 (OHCI_ED_SKIP); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 547 | |
| 548 | switch (ed->type) { |
| 549 | case PIPE_CONTROL: |
| 550 | if (ed->ed_prev == NULL) { |
| 551 | if (!ed->hwNextED) { |
| 552 | ohci->hc_control &= ~OHCI_CTRL_CLE; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 553 | writel (ohci->hc_control, &ohci->regs->control); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 554 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 555 | writel (ohci_cpu_to_le32 (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_controlhead); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 556 | } else { |
| 557 | ed->ed_prev->hwNextED = ed->hwNextED; |
| 558 | } |
| 559 | if (ohci->ed_controltail == ed) { |
| 560 | ohci->ed_controltail = ed->ed_prev; |
| 561 | } else { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 562 | ((ed_t *)ohci_cpu_to_le32 (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 563 | } |
| 564 | break; |
| 565 | |
| 566 | case PIPE_BULK: |
| 567 | if (ed->ed_prev == NULL) { |
| 568 | if (!ed->hwNextED) { |
| 569 | ohci->hc_control &= ~OHCI_CTRL_BLE; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 570 | writel (ohci->hc_control, &ohci->regs->control); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 571 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 572 | writel (ohci_cpu_to_le32 (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_bulkhead); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 573 | } else { |
| 574 | ed->ed_prev->hwNextED = ed->hwNextED; |
| 575 | } |
| 576 | if (ohci->ed_bulktail == ed) { |
| 577 | ohci->ed_bulktail = ed->ed_prev; |
| 578 | } else { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 579 | ((ed_t *)ohci_cpu_to_le32 (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 580 | } |
| 581 | break; |
| 582 | } |
| 583 | ed->state = ED_UNLINK; |
| 584 | return 0; |
| 585 | } |
| 586 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 587 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 588 | /*-------------------------------------------------------------------------*/ |
| 589 | |
| 590 | /* add/reinit an endpoint; this should be done once at the usb_set_configuration command, |
| 591 | * but the USB stack is a little bit stateless so we do it at every transaction |
| 592 | * if the state of the ed is ED_NEW then a dummy td is added and the state is changed to ED_UNLINK |
| 593 | * in all other cases the state is left unchanged |
| 594 | * the ed info fields are setted anyway even though most of them should not change */ |
| 595 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 596 | static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 597 | { |
| 598 | td_t *td; |
| 599 | ed_t *ed_ret; |
| 600 | volatile ed_t *ed; |
| 601 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 602 | ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint (pipe) << 1) | |
| 603 | (usb_pipecontrol (pipe)? 0: usb_pipeout (pipe))]; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 604 | |
| 605 | if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) { |
| 606 | err("ep_add_ed: pending delete"); |
| 607 | /* pending delete request */ |
| 608 | return NULL; |
| 609 | } |
| 610 | |
| 611 | if (ed->state == ED_NEW) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 612 | ed->hwINFO = ohci_cpu_to_le32 (OHCI_ED_SKIP); /* skip ed */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 613 | /* dummy td; end of td list for ed */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 614 | td = td_alloc (usb_dev); |
| 615 | ed->hwTailP = ohci_cpu_to_le32 ((unsigned long)td); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 616 | ed->hwHeadP = ed->hwTailP; |
| 617 | ed->state = ED_UNLINK; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 618 | ed->type = usb_pipetype (pipe); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 619 | ohci_dev.ed_cnt++; |
| 620 | } |
| 621 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 622 | ed->hwINFO = ohci_cpu_to_le32 (usb_pipedevice (pipe) |
| 623 | | usb_pipeendpoint (pipe) << 7 |
| 624 | | (usb_pipeisoc (pipe)? 0x8000: 0) |
| 625 | | (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000)) |
| 626 | | usb_pipeslow (pipe) << 13 |
| 627 | | usb_maxpacket (usb_dev, pipe) << 16); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 628 | |
| 629 | return ed_ret; |
| 630 | } |
| 631 | |
| 632 | /*-------------------------------------------------------------------------* |
| 633 | * TD handling functions |
| 634 | *-------------------------------------------------------------------------*/ |
| 635 | |
| 636 | /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */ |
| 637 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 638 | static void td_fill (ohci_t *ohci, unsigned int info, |
| 639 | void *data, int len, |
| 640 | struct usb_device *dev, int index, urb_priv_t *urb_priv) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 641 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 642 | volatile td_t *td, *td_pt; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 643 | #ifdef OHCI_FILL_TRACE |
| 644 | int i; |
| 645 | #endif |
| 646 | |
| 647 | if (index > urb_priv->length) { |
| 648 | err("index > length"); |
| 649 | return; |
| 650 | } |
| 651 | /* use this td as the next dummy */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 652 | td_pt = urb_priv->td [index]; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 653 | td_pt->hwNextTD = 0; |
| 654 | |
| 655 | /* fill the old dummy TD */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 656 | td = urb_priv->td [index] = (td_t *)(ohci_cpu_to_le32 (urb_priv->ed->hwTailP) & ~0xf); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 657 | |
| 658 | td->ed = urb_priv->ed; |
| 659 | td->next_dl_td = NULL; |
| 660 | td->index = index; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 661 | td->data = (__u32)data; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 662 | #ifdef OHCI_FILL_TRACE |
Remy Bohmer | 9dbc366 | 2008-10-10 10:23:22 +0200 | [diff] [blame] | 663 | if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 664 | for (i = 0; i < len; i++) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 665 | printf("td->data[%d] %#2x ",i, ((unsigned char *)td->data)[i]); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 666 | printf("\n"); |
| 667 | } |
| 668 | #endif |
| 669 | if (!len) |
| 670 | data = 0; |
| 671 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 672 | td->hwINFO = ohci_cpu_to_le32 (info); |
| 673 | td->hwCBP = ohci_cpu_to_le32 ((unsigned long)data); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 674 | if (data) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 675 | td->hwBE = ohci_cpu_to_le32 ((unsigned long)(data + len - 1)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 676 | else |
| 677 | td->hwBE = 0; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 678 | td->hwNextTD = ohci_cpu_to_le32 ((unsigned long)td_pt); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 679 | |
| 680 | /* append to queue */ |
| 681 | td->ed->hwTailP = td->hwNextTD; |
| 682 | } |
| 683 | |
| 684 | /*-------------------------------------------------------------------------*/ |
| 685 | |
| 686 | /* prepare all TDs of a transfer */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 687 | static void td_submit_job (struct usb_device *dev, unsigned long pipe, void *buffer, |
| 688 | int transfer_len, struct devrequest *setup, urb_priv_t *urb, int interval) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 689 | { |
| 690 | ohci_t *ohci = &gohci; |
| 691 | int data_len = transfer_len; |
| 692 | void *data; |
| 693 | int cnt = 0; |
| 694 | __u32 info = 0; |
| 695 | unsigned int toggle = 0; |
| 696 | |
| 697 | /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 698 | if(usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 699 | toggle = TD_T_TOGGLE; |
| 700 | } else { |
| 701 | toggle = TD_T_DATA0; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 702 | usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 703 | } |
| 704 | urb->td_cnt = 0; |
| 705 | if (data_len) |
| 706 | data = buffer; |
| 707 | else |
| 708 | data = 0; |
| 709 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 710 | switch (usb_pipetype (pipe)) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 711 | case PIPE_BULK: |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 712 | info = usb_pipeout (pipe)? |
| 713 | TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ; |
| 714 | while(data_len > 4096) { |
| 715 | td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, 4096, dev, cnt, urb); |
| 716 | data += 4096; data_len -= 4096; cnt++; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 717 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 718 | info = usb_pipeout (pipe)? |
| 719 | TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ; |
| 720 | td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, data_len, dev, cnt, urb); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 721 | cnt++; |
| 722 | |
| 723 | if (!ohci->sleeping) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 724 | writel (OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 725 | break; |
| 726 | |
| 727 | case PIPE_CONTROL: |
| 728 | info = TD_CC | TD_DP_SETUP | TD_T_DATA0; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 729 | td_fill (ohci, info, setup, 8, dev, cnt++, urb); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 730 | if (data_len > 0) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 731 | info = usb_pipeout (pipe)? |
| 732 | TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 733 | /* NOTE: mishandles transfers >8K, some >4K */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 734 | td_fill (ohci, info, data, data_len, dev, cnt++, urb); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 735 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 736 | info = usb_pipeout (pipe)? |
| 737 | TD_CC | TD_DP_IN | TD_T_DATA1: TD_CC | TD_DP_OUT | TD_T_DATA1; |
| 738 | td_fill (ohci, info, data, 0, dev, cnt++, urb); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 739 | if (!ohci->sleeping) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 740 | writel (OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 741 | break; |
| 742 | } |
| 743 | if (urb->length != cnt) |
| 744 | dbg("TD LENGTH %d != CNT %d", urb->length, cnt); |
| 745 | } |
| 746 | |
| 747 | /*-------------------------------------------------------------------------* |
| 748 | * Done List handling functions |
| 749 | *-------------------------------------------------------------------------*/ |
| 750 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 751 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 752 | /* calculate the transfer length and update the urb */ |
| 753 | |
| 754 | static void dl_transfer_length(td_t * td) |
| 755 | { |
Stefan Roese | af0af52 | 2011-11-15 08:01:45 +0000 | [diff] [blame^] | 756 | __u32 tdBE, tdCBP; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 757 | urb_priv_t *lurb_priv = &urb_priv; |
| 758 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 759 | tdBE = ohci_cpu_to_le32 (td->hwBE); |
| 760 | tdCBP = ohci_cpu_to_le32 (td->hwCBP); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 761 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 762 | |
Remy Bohmer | 9dbc366 | 2008-10-10 10:23:22 +0200 | [diff] [blame] | 763 | if (!(usb_pipecontrol(lurb_priv->pipe) && |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 764 | ((td->index == 0) || (td->index == lurb_priv->length - 1)))) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 765 | if (tdBE != 0) { |
| 766 | if (td->hwCBP == 0) |
| 767 | lurb_priv->actual_length += tdBE - td->data + 1; |
| 768 | else |
| 769 | lurb_priv->actual_length += tdCBP - td->data; |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | /*-------------------------------------------------------------------------*/ |
| 775 | |
| 776 | /* replies to the request have to be on a FIFO basis so |
| 777 | * we reverse the reversed done-list */ |
| 778 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 779 | static td_t * dl_reverse_done_list (ohci_t *ohci) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 780 | { |
| 781 | __u32 td_list_hc; |
| 782 | td_t *td_rev = NULL; |
| 783 | td_t *td_list = NULL; |
| 784 | urb_priv_t *lurb_priv = NULL; |
| 785 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 786 | td_list_hc = ohci_cpu_to_le32 (ohci->hcca->done_head) & 0xfffffff0; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 787 | ohci->hcca->done_head = 0; |
| 788 | |
| 789 | while (td_list_hc) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 790 | td_list = (td_t *)td_list_hc; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 791 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 792 | if (TD_CC_GET (ohci_cpu_to_le32 (td_list->hwINFO))) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 793 | lurb_priv = &urb_priv; |
| 794 | dbg(" USB-error/status: %x : %p", |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 795 | TD_CC_GET (ohci_cpu_to_le32 (td_list->hwINFO)), td_list); |
| 796 | if (td_list->ed->hwHeadP & ohci_cpu_to_le32 (0x1)) { |
| 797 | if (lurb_priv && ((td_list->index + 1) < lurb_priv->length)) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 798 | td_list->ed->hwHeadP = |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 799 | (lurb_priv->td[lurb_priv->length - 1]->hwNextTD & ohci_cpu_to_le32 (0xfffffff0)) | |
| 800 | (td_list->ed->hwHeadP & ohci_cpu_to_le32 (0x2)); |
| 801 | lurb_priv->td_cnt += lurb_priv->length - td_list->index - 1; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 802 | } else |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 803 | td_list->ed->hwHeadP &= ohci_cpu_to_le32 (0xfffffff2); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 804 | } |
| 805 | #ifdef CONFIG_MPC5200 |
| 806 | td_list->hwNextTD = 0; |
| 807 | #endif |
| 808 | } |
| 809 | |
| 810 | td_list->next_dl_td = td_rev; |
| 811 | td_rev = td_list; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 812 | td_list_hc = ohci_cpu_to_le32 (td_list->hwNextTD) & 0xfffffff0; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 813 | } |
| 814 | return td_list; |
| 815 | } |
| 816 | |
| 817 | /*-------------------------------------------------------------------------*/ |
| 818 | |
| 819 | /* td done list */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 820 | static int dl_done_list (ohci_t *ohci, td_t *td_list) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 821 | { |
| 822 | td_t *td_list_next = NULL; |
| 823 | ed_t *ed; |
| 824 | int cc = 0; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 825 | int stat = 0; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 826 | /* urb_t *urb; */ |
| 827 | urb_priv_t *lurb_priv; |
| 828 | __u32 tdINFO, edHeadP, edTailP; |
| 829 | |
| 830 | while (td_list) { |
| 831 | td_list_next = td_list->next_dl_td; |
| 832 | |
| 833 | lurb_priv = &urb_priv; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 834 | tdINFO = ohci_cpu_to_le32 (td_list->hwINFO); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 835 | |
| 836 | ed = td_list->ed; |
| 837 | |
| 838 | dl_transfer_length(td_list); |
| 839 | |
| 840 | /* error code of transfer */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 841 | cc = TD_CC_GET (tdINFO); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 842 | if (++(lurb_priv->td_cnt) == lurb_priv->length) { |
| 843 | if ((ed->state & (ED_OPER | ED_UNLINK)) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 844 | && (lurb_priv->state != URB_DEL)) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 845 | dbg("ConditionCode %#x", cc); |
| 846 | stat = cc_to_error[cc]; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 847 | urb_finished = 1; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
| 851 | if (ed->state != ED_NEW) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 852 | edHeadP = ohci_cpu_to_le32 (ed->hwHeadP) & 0xfffffff0; |
| 853 | edTailP = ohci_cpu_to_le32 (ed->hwTailP); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 854 | |
| 855 | /* unlink eds if they are not busy */ |
| 856 | if ((edHeadP == edTailP) && (ed->state == ED_OPER)) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 857 | ep_unlink (ohci, ed); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | td_list = td_list_next; |
| 861 | } |
| 862 | return stat; |
| 863 | } |
| 864 | |
| 865 | /*-------------------------------------------------------------------------* |
| 866 | * Virtual Root Hub |
| 867 | *-------------------------------------------------------------------------*/ |
| 868 | |
| 869 | /* Device descriptor */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 870 | static __u8 root_hub_dev_des[] = |
| 871 | { |
| 872 | 0x12, /* __u8 bLength; */ |
| 873 | 0x01, /* __u8 bDescriptorType; Device */ |
| 874 | 0x10, /* __u16 bcdUSB; v1.1 */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 875 | 0x01, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 876 | 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ |
| 877 | 0x00, /* __u8 bDeviceSubClass; */ |
| 878 | 0x00, /* __u8 bDeviceProtocol; */ |
| 879 | 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */ |
| 880 | 0x00, /* __u16 idVendor; */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 881 | 0x00, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 882 | 0x00, /* __u16 idProduct; */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 883 | 0x00, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 884 | 0x00, /* __u16 bcdDevice; */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 885 | 0x00, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 886 | 0x00, /* __u8 iManufacturer; */ |
| 887 | 0x01, /* __u8 iProduct; */ |
| 888 | 0x00, /* __u8 iSerialNumber; */ |
| 889 | 0x01 /* __u8 bNumConfigurations; */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 890 | }; |
| 891 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 892 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 893 | /* Configuration descriptor */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 894 | static __u8 root_hub_config_des[] = |
| 895 | { |
| 896 | 0x09, /* __u8 bLength; */ |
| 897 | 0x02, /* __u8 bDescriptorType; Configuration */ |
| 898 | 0x19, /* __u16 wTotalLength; */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 899 | 0x00, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 900 | 0x01, /* __u8 bNumInterfaces; */ |
| 901 | 0x01, /* __u8 bConfigurationValue; */ |
| 902 | 0x00, /* __u8 iConfiguration; */ |
| 903 | 0x40, /* __u8 bmAttributes; |
| 904 | Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */ |
| 905 | 0x00, /* __u8 MaxPower; */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 906 | |
| 907 | /* interface */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 908 | 0x09, /* __u8 if_bLength; */ |
| 909 | 0x04, /* __u8 if_bDescriptorType; Interface */ |
| 910 | 0x00, /* __u8 if_bInterfaceNumber; */ |
| 911 | 0x00, /* __u8 if_bAlternateSetting; */ |
| 912 | 0x01, /* __u8 if_bNumEndpoints; */ |
| 913 | 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */ |
| 914 | 0x00, /* __u8 if_bInterfaceSubClass; */ |
| 915 | 0x00, /* __u8 if_bInterfaceProtocol; */ |
| 916 | 0x00, /* __u8 if_iInterface; */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 917 | |
| 918 | /* endpoint */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 919 | 0x07, /* __u8 ep_bLength; */ |
| 920 | 0x05, /* __u8 ep_bDescriptorType; Endpoint */ |
| 921 | 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ |
| 922 | 0x03, /* __u8 ep_bmAttributes; Interrupt */ |
| 923 | 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 924 | 0x00, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 925 | 0xff /* __u8 ep_bInterval; 255 ms */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 926 | }; |
| 927 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 928 | static unsigned char root_hub_str_index0[] = |
| 929 | { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 930 | 0x04, /* __u8 bLength; */ |
| 931 | 0x03, /* __u8 bDescriptorType; String-descriptor */ |
| 932 | 0x09, /* __u8 lang ID */ |
| 933 | 0x04, /* __u8 lang ID */ |
| 934 | }; |
| 935 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 936 | static unsigned char root_hub_str_index1[] = |
| 937 | { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 938 | 28, /* __u8 bLength; */ |
| 939 | 0x03, /* __u8 bDescriptorType; String-descriptor */ |
| 940 | 'O', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 941 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 942 | 'H', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 943 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 944 | 'C', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 945 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 946 | 'I', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 947 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 948 | ' ', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 949 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 950 | 'R', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 951 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 952 | 'o', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 953 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 954 | 'o', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 955 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 956 | 't', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 957 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 958 | ' ', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 959 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 960 | 'H', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 961 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 962 | 'u', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 963 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 964 | 'b', /* __u8 Unicode */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 965 | 0, /* __u8 Unicode */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 966 | }; |
| 967 | |
| 968 | /* Hub class-specific descriptor is constructed dynamically */ |
| 969 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 970 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 971 | /*-------------------------------------------------------------------------*/ |
| 972 | |
| 973 | #define OK(x) len = (x); break |
| 974 | #ifdef DEBUG |
| 975 | #define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);} |
| 976 | #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);} |
| 977 | #else |
| 978 | #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status) |
| 979 | #define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1]) |
| 980 | #endif |
| 981 | #define RD_RH_STAT roothub_status(&gohci) |
| 982 | #define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1) |
| 983 | |
| 984 | /* request to virtual root hub */ |
| 985 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 986 | int rh_check_port_status(ohci_t *controller) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 987 | { |
| 988 | __u32 temp, ndp, i; |
| 989 | int res; |
| 990 | |
| 991 | res = -1; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 992 | temp = roothub_a (controller); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 993 | ndp = (temp & RH_A_NDP); |
| 994 | for (i = 0; i < ndp; i++) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 995 | temp = roothub_portstatus (controller, i); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 996 | /* check for a device disconnect */ |
| 997 | if (((temp & (RH_PS_PESC | RH_PS_CSC)) == |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 998 | (RH_PS_PESC | RH_PS_CSC)) && |
| 999 | ((temp & RH_PS_CCS) == 0)) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1000 | res = i; |
| 1001 | break; |
| 1002 | } |
| 1003 | } |
| 1004 | return res; |
| 1005 | } |
| 1006 | |
| 1007 | static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1008 | void *buffer, int transfer_len, struct devrequest *cmd) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1009 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1010 | void * data = buffer; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1011 | int leni = transfer_len; |
| 1012 | int len = 0; |
| 1013 | int stat = 0; |
| 1014 | __u32 datab[4]; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1015 | __u8 *data_buf = (__u8 *)datab; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1016 | __u16 bmRType_bReq; |
| 1017 | __u16 wValue; |
| 1018 | __u16 wIndex; |
| 1019 | __u16 wLength; |
| 1020 | |
| 1021 | #ifdef DEBUG |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1022 | urb_priv.actual_length = 0; |
| 1023 | pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1024 | #endif |
Remy Bohmer | 9dbc366 | 2008-10-10 10:23:22 +0200 | [diff] [blame] | 1025 | if (usb_pipeint(pipe)) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1026 | info("Root-Hub submit IRQ: NOT implemented"); |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1030 | bmRType_bReq = cmd->requesttype | (cmd->request << 8); |
| 1031 | wValue = m16_swap (cmd->value); |
| 1032 | wIndex = m16_swap (cmd->index); |
| 1033 | wLength = m16_swap (cmd->length); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1034 | |
| 1035 | info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x", |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1036 | dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1037 | |
| 1038 | switch (bmRType_bReq) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1039 | /* Request Destination: |
| 1040 | without flags: Device, |
| 1041 | RH_INTERFACE: interface, |
| 1042 | RH_ENDPOINT: endpoint, |
| 1043 | RH_CLASS means HUB here, |
| 1044 | RH_OTHER | RH_CLASS almost ever means HUB_PORT here |
| 1045 | */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1046 | |
| 1047 | case RH_GET_STATUS: |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1048 | *(__u16 *) data_buf = m16_swap (1); OK (2); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1049 | case RH_GET_STATUS | RH_INTERFACE: |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1050 | *(__u16 *) data_buf = m16_swap (0); OK (2); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1051 | case RH_GET_STATUS | RH_ENDPOINT: |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1052 | *(__u16 *) data_buf = m16_swap (0); OK (2); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1053 | case RH_GET_STATUS | RH_CLASS: |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1054 | *(__u32 *) data_buf = m32_swap ( |
| 1055 | RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE)); |
| 1056 | OK (4); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1057 | case RH_GET_STATUS | RH_OTHER | RH_CLASS: |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1058 | *(__u32 *) data_buf = m32_swap (RD_RH_PORTSTAT); OK (4); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1059 | |
| 1060 | case RH_CLEAR_FEATURE | RH_ENDPOINT: |
| 1061 | switch (wValue) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1062 | case (RH_ENDPOINT_STALL): OK (0); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1063 | } |
| 1064 | break; |
| 1065 | |
| 1066 | case RH_CLEAR_FEATURE | RH_CLASS: |
| 1067 | switch (wValue) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1068 | case RH_C_HUB_LOCAL_POWER: |
| 1069 | OK(0); |
| 1070 | case (RH_C_HUB_OVER_CURRENT): |
| 1071 | WR_RH_STAT(RH_HS_OCIC); OK (0); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1072 | } |
| 1073 | break; |
| 1074 | |
| 1075 | case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS: |
| 1076 | switch (wValue) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1077 | case (RH_PORT_ENABLE): |
| 1078 | WR_RH_PORTSTAT (RH_PS_CCS ); OK (0); |
| 1079 | case (RH_PORT_SUSPEND): |
| 1080 | WR_RH_PORTSTAT (RH_PS_POCI); OK (0); |
| 1081 | case (RH_PORT_POWER): |
| 1082 | WR_RH_PORTSTAT (RH_PS_LSDA); OK (0); |
| 1083 | case (RH_C_PORT_CONNECTION): |
| 1084 | WR_RH_PORTSTAT (RH_PS_CSC ); OK (0); |
| 1085 | case (RH_C_PORT_ENABLE): |
| 1086 | WR_RH_PORTSTAT (RH_PS_PESC); OK (0); |
| 1087 | case (RH_C_PORT_SUSPEND): |
| 1088 | WR_RH_PORTSTAT (RH_PS_PSSC); OK (0); |
| 1089 | case (RH_C_PORT_OVER_CURRENT): |
| 1090 | WR_RH_PORTSTAT (RH_PS_OCIC); OK (0); |
| 1091 | case (RH_C_PORT_RESET): |
| 1092 | WR_RH_PORTSTAT (RH_PS_PRSC); OK (0); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1093 | } |
| 1094 | break; |
| 1095 | |
| 1096 | case RH_SET_FEATURE | RH_OTHER | RH_CLASS: |
| 1097 | switch (wValue) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1098 | case (RH_PORT_SUSPEND): |
| 1099 | WR_RH_PORTSTAT (RH_PS_PSS ); OK (0); |
| 1100 | case (RH_PORT_RESET): /* BUG IN HUP CODE *********/ |
| 1101 | if (RD_RH_PORTSTAT & RH_PS_CCS) |
| 1102 | WR_RH_PORTSTAT (RH_PS_PRS); |
| 1103 | OK (0); |
| 1104 | case (RH_PORT_POWER): |
| 1105 | WR_RH_PORTSTAT (RH_PS_PPS ); OK (0); |
| 1106 | case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/ |
| 1107 | if (RD_RH_PORTSTAT & RH_PS_CCS) |
| 1108 | WR_RH_PORTSTAT (RH_PS_PES ); |
| 1109 | OK (0); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1110 | } |
| 1111 | break; |
| 1112 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1113 | case RH_SET_ADDRESS: gohci.rh.devnum = wValue; OK(0); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1114 | |
| 1115 | case RH_GET_DESCRIPTOR: |
| 1116 | switch ((wValue & 0xff00) >> 8) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1117 | case (0x01): /* device descriptor */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1118 | len = min_t(unsigned int, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1119 | leni, |
| 1120 | min_t(unsigned int, |
| 1121 | sizeof (root_hub_dev_des), |
| 1122 | wLength)); |
| 1123 | data_buf = root_hub_dev_des; OK(len); |
| 1124 | case (0x02): /* configuration descriptor */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1125 | len = min_t(unsigned int, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1126 | leni, |
| 1127 | min_t(unsigned int, |
| 1128 | sizeof (root_hub_config_des), |
| 1129 | wLength)); |
| 1130 | data_buf = root_hub_config_des; OK(len); |
| 1131 | case (0x03): /* string descriptors */ |
| 1132 | if(wValue==0x0300) { |
| 1133 | len = min_t(unsigned int, |
| 1134 | leni, |
| 1135 | min_t(unsigned int, |
| 1136 | sizeof (root_hub_str_index0), |
| 1137 | wLength)); |
| 1138 | data_buf = root_hub_str_index0; |
| 1139 | OK(len); |
| 1140 | } |
| 1141 | if(wValue==0x0301) { |
| 1142 | len = min_t(unsigned int, |
| 1143 | leni, |
| 1144 | min_t(unsigned int, |
| 1145 | sizeof (root_hub_str_index1), |
| 1146 | wLength)); |
| 1147 | data_buf = root_hub_str_index1; |
| 1148 | OK(len); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1149 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1150 | default: |
| 1151 | stat = USB_ST_STALLED; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1152 | } |
| 1153 | break; |
| 1154 | |
| 1155 | case RH_GET_DESCRIPTOR | RH_CLASS: |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1156 | { |
| 1157 | __u32 temp = roothub_a (&gohci); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1158 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1159 | data_buf [0] = 9; /* min length; */ |
| 1160 | data_buf [1] = 0x29; |
| 1161 | data_buf [2] = temp & RH_A_NDP; |
| 1162 | data_buf [3] = 0; |
| 1163 | if (temp & RH_A_PSM) /* per-port power switching? */ |
| 1164 | data_buf [3] |= 0x1; |
| 1165 | if (temp & RH_A_NOCP) /* no overcurrent reporting? */ |
| 1166 | data_buf [3] |= 0x10; |
| 1167 | else if (temp & RH_A_OCPM) /* per-port overcurrent reporting? */ |
| 1168 | data_buf [3] |= 0x8; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1169 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1170 | /* corresponds to data_buf[4-7] */ |
| 1171 | datab [1] = 0; |
| 1172 | data_buf [5] = (temp & RH_A_POTPGT) >> 24; |
| 1173 | temp = roothub_b (&gohci); |
| 1174 | data_buf [7] = temp & RH_B_DR; |
| 1175 | if (data_buf [2] < 7) { |
| 1176 | data_buf [8] = 0xff; |
| 1177 | } else { |
| 1178 | data_buf [0] += 2; |
| 1179 | data_buf [8] = (temp & RH_B_DR) >> 8; |
| 1180 | data_buf [10] = data_buf [9] = 0xff; |
| 1181 | } |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1182 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1183 | len = min_t(unsigned int, leni, |
| 1184 | min_t(unsigned int, data_buf [0], wLength)); |
| 1185 | OK (len); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1186 | } |
| 1187 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1188 | case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK (1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1189 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1190 | case RH_SET_CONFIGURATION: WR_RH_STAT (0x10000); OK (0); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1191 | |
| 1192 | default: |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1193 | dbg ("unsupported root hub command"); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1194 | stat = USB_ST_STALLED; |
| 1195 | } |
| 1196 | |
| 1197 | #ifdef DEBUG |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1198 | ohci_dump_roothub (&gohci, 1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1199 | #endif |
| 1200 | |
| 1201 | len = min_t(int, len, leni); |
| 1202 | if (data != data_buf) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1203 | memcpy (data, data_buf, len); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1204 | dev->act_len = len; |
| 1205 | dev->status = stat; |
| 1206 | |
| 1207 | #ifdef DEBUG |
| 1208 | if (transfer_len) |
| 1209 | urb_priv.actual_length = transfer_len; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1210 | pkt_print(dev, pipe, buffer, transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1211 | #endif |
| 1212 | |
| 1213 | return stat; |
| 1214 | } |
| 1215 | |
| 1216 | /*-------------------------------------------------------------------------*/ |
| 1217 | |
| 1218 | /* common code for handling submit messages - used for all but root hub */ |
| 1219 | /* accesses. */ |
| 1220 | int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1221 | int transfer_len, struct devrequest *setup, int interval) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1222 | { |
| 1223 | int stat = 0; |
| 1224 | int maxsize = usb_maxpacket(dev, pipe); |
| 1225 | int timeout; |
| 1226 | |
| 1227 | /* device pulled? Shortcut the action. */ |
| 1228 | if (devgone == dev) { |
| 1229 | dev->status = USB_ST_CRC_ERR; |
| 1230 | return 0; |
| 1231 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1232 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1233 | #ifdef DEBUG |
| 1234 | urb_priv.actual_length = 0; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1235 | pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1236 | #endif |
| 1237 | if (!maxsize) { |
| 1238 | err("submit_common_message: pipesize for pipe %lx is zero", |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1239 | pipe); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1240 | return -1; |
| 1241 | } |
| 1242 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1243 | if (sohci_submit_job(dev, pipe, buffer, transfer_len, setup, interval) < 0) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1244 | err("sohci_submit_job failed"); |
| 1245 | return -1; |
| 1246 | } |
| 1247 | |
| 1248 | /* allow more time for a BULK device to react - some are slow */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1249 | #define BULK_TO 5000 /* timeout in milliseconds */ |
Remy Bohmer | 9dbc366 | 2008-10-10 10:23:22 +0200 | [diff] [blame] | 1250 | if (usb_pipebulk(pipe)) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1251 | timeout = BULK_TO; |
| 1252 | else |
| 1253 | timeout = 100; |
| 1254 | |
| 1255 | /* wait for it to complete */ |
| 1256 | for (;;) { |
| 1257 | /* check whether the controller is done */ |
| 1258 | stat = hc_interrupt(); |
| 1259 | if (stat < 0) { |
| 1260 | stat = USB_ST_CRC_ERR; |
| 1261 | break; |
| 1262 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1263 | |
| 1264 | /* NOTE: since we are not interrupt driven in U-Boot and always |
| 1265 | * handle only one URB at a time, we cannot assume the |
| 1266 | * transaction finished on the first successful return from |
| 1267 | * hc_interrupt().. unless the flag for current URB is set, |
| 1268 | * meaning that all TD's to/from device got actually |
| 1269 | * transferred and processed. If the current URB is not |
| 1270 | * finished we need to re-iterate this loop so as |
| 1271 | * hc_interrupt() gets called again as there needs to be some |
| 1272 | * more TD's to process still */ |
| 1273 | if ((stat >= 0) && (stat != 0xff) && (urb_finished)) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1274 | /* 0xff is returned for an SF-interrupt */ |
| 1275 | break; |
| 1276 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1277 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1278 | if (--timeout) { |
| 1279 | wait_ms(1); |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1280 | if (!urb_finished) |
| 1281 | dbg("\%"); |
| 1282 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1283 | } else { |
| 1284 | err("CTL:TIMEOUT "); |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1285 | dbg("submit_common_msg: TO status %x\n", stat); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1286 | stat = USB_ST_CRC_ERR; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1287 | urb_finished = 1; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1288 | break; |
| 1289 | } |
| 1290 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1291 | #if 0 |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1292 | /* we got an Root Hub Status Change interrupt */ |
| 1293 | if (got_rhsc) { |
| 1294 | #ifdef DEBUG |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1295 | ohci_dump_roothub (&gohci, 1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1296 | #endif |
| 1297 | got_rhsc = 0; |
| 1298 | /* abuse timeout */ |
| 1299 | timeout = rh_check_port_status(&gohci); |
| 1300 | if (timeout >= 0) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1301 | #if 0 /* this does nothing useful, but leave it here in case that changes */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1302 | /* the called routine adds 1 to the passed value */ |
| 1303 | usb_hub_port_connect_change(gohci.rh.dev, timeout - 1); |
| 1304 | #endif |
| 1305 | /* |
| 1306 | * XXX |
| 1307 | * This is potentially dangerous because it assumes |
| 1308 | * that only one device is ever plugged in! |
| 1309 | */ |
| 1310 | devgone = dev; |
| 1311 | } |
| 1312 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1313 | #endif |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1314 | |
| 1315 | dev->status = stat; |
| 1316 | dev->act_len = transfer_len; |
| 1317 | |
| 1318 | #ifdef DEBUG |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1319 | pkt_print(dev, pipe, buffer, transfer_len, setup, "RET(ctlr)", usb_pipein(pipe)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1320 | #endif |
| 1321 | |
| 1322 | /* free TDs in urb_priv */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1323 | urb_free_priv (&urb_priv); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | /* submit routines called from usb.c */ |
| 1328 | int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1329 | int transfer_len) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1330 | { |
| 1331 | info("submit_bulk_msg"); |
| 1332 | return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0); |
| 1333 | } |
| 1334 | |
| 1335 | int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1336 | int transfer_len, struct devrequest *setup) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1337 | { |
| 1338 | int maxsize = usb_maxpacket(dev, pipe); |
| 1339 | |
| 1340 | info("submit_control_msg"); |
| 1341 | #ifdef DEBUG |
| 1342 | urb_priv.actual_length = 0; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1343 | pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1344 | #endif |
| 1345 | if (!maxsize) { |
| 1346 | err("submit_control_message: pipesize for pipe %lx is zero", |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1347 | pipe); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1348 | return -1; |
| 1349 | } |
| 1350 | if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) { |
| 1351 | gohci.rh.dev = dev; |
| 1352 | /* root hub - redirect */ |
| 1353 | return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1354 | setup); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0); |
| 1358 | } |
| 1359 | |
| 1360 | int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1361 | int transfer_len, int interval) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1362 | { |
| 1363 | info("submit_int_msg"); |
| 1364 | return -1; |
| 1365 | } |
| 1366 | |
| 1367 | /*-------------------------------------------------------------------------* |
| 1368 | * HC functions |
| 1369 | *-------------------------------------------------------------------------*/ |
| 1370 | |
| 1371 | /* reset the HC and BUS */ |
| 1372 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1373 | static int hc_reset (ohci_t *ohci) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1374 | { |
| 1375 | int timeout = 30; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1376 | int smm_timeout = 50; /* 0,5 sec */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1377 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1378 | if (readl (&ohci->regs->control) & OHCI_CTRL_IR) { /* SMM owns the HC */ |
| 1379 | writel (OHCI_OCR, &ohci->regs->cmdstatus); /* request ownership */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1380 | info("USB HC TakeOver from SMM"); |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1381 | while (readl (&ohci->regs->control) & OHCI_CTRL_IR) { |
| 1382 | wait_ms (10); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1383 | if (--smm_timeout == 0) { |
| 1384 | err("USB HC TakeOver failed!"); |
| 1385 | return -1; |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | /* Disable HC interrupts */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1391 | writel (OHCI_INTR_MIE, &ohci->regs->intrdisable); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1392 | |
| 1393 | dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;", |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1394 | ohci->slot_name, |
| 1395 | readl (&ohci->regs->control)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1396 | |
| 1397 | /* Reset USB (needed by some controllers) */ |
| 1398 | ohci->hc_control = 0; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1399 | writel (ohci->hc_control, &ohci->regs->control); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1400 | |
| 1401 | /* HC Reset requires max 10 us delay */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1402 | writel (OHCI_HCR, &ohci->regs->cmdstatus); |
| 1403 | while ((readl (&ohci->regs->cmdstatus) & OHCI_HCR) != 0) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1404 | if (--timeout == 0) { |
| 1405 | err("USB HC reset timed out!"); |
| 1406 | return -1; |
| 1407 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1408 | udelay (1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1409 | } |
| 1410 | return 0; |
| 1411 | } |
| 1412 | |
| 1413 | /*-------------------------------------------------------------------------*/ |
| 1414 | |
| 1415 | /* Start an OHCI controller, set the BUS operational |
| 1416 | * enable interrupts |
| 1417 | * connect the virtual root hub */ |
| 1418 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1419 | static int hc_start (ohci_t * ohci) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1420 | { |
| 1421 | __u32 mask; |
| 1422 | unsigned int fminterval; |
| 1423 | |
| 1424 | ohci->disabled = 1; |
| 1425 | |
| 1426 | /* Tell the controller where the control and bulk lists are |
| 1427 | * The lists are empty now. */ |
| 1428 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1429 | writel (0, &ohci->regs->ed_controlhead); |
| 1430 | writel (0, &ohci->regs->ed_bulkhead); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1431 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1432 | writel ((__u32)ohci->hcca, &ohci->regs->hcca); /* a reset clears this */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1433 | |
| 1434 | fminterval = 0x2edf; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1435 | writel ((fminterval * 9) / 10, &ohci->regs->periodicstart); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1436 | fminterval |= ((((fminterval - 210) * 6) / 7) << 16); |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1437 | writel (fminterval, &ohci->regs->fminterval); |
| 1438 | writel (0x628, &ohci->regs->lsthresh); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1439 | |
| 1440 | /* start controller operations */ |
| 1441 | ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER; |
| 1442 | ohci->disabled = 0; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1443 | writel (ohci->hc_control, &ohci->regs->control); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1444 | |
| 1445 | /* disable all interrupts */ |
| 1446 | mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1447 | OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC | |
| 1448 | OHCI_INTR_OC | OHCI_INTR_MIE); |
| 1449 | writel (mask, &ohci->regs->intrdisable); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1450 | /* clear all interrupts */ |
| 1451 | mask &= ~OHCI_INTR_MIE; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1452 | writel (mask, &ohci->regs->intrstatus); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1453 | /* Choose the interrupts we care about now - but w/o MIE */ |
| 1454 | mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1455 | writel (mask, &ohci->regs->intrenable); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1456 | |
| 1457 | #ifdef OHCI_USE_NPS |
| 1458 | /* required for AMD-756 and some Mac platforms */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1459 | writel ((roothub_a (ohci) | RH_A_NPS) & ~RH_A_PSM, |
| 1460 | &ohci->regs->roothub.a); |
| 1461 | writel (RH_HS_LPSC, &ohci->regs->roothub.status); |
| 1462 | #endif /* OHCI_USE_NPS */ |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1463 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1464 | /* POTPGT delay is bits 24-31, in 2 ms units. */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1465 | mdelay ((roothub_a (ohci) >> 23) & 0x1fe); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1466 | |
| 1467 | /* connect the virtual root hub */ |
| 1468 | ohci->rh.devnum = 0; |
| 1469 | |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | /*-------------------------------------------------------------------------*/ |
| 1474 | |
| 1475 | /* an interrupt happens */ |
| 1476 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1477 | static int |
| 1478 | hc_interrupt (void) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1479 | { |
| 1480 | ohci_t *ohci = &gohci; |
| 1481 | struct ohci_regs *regs = ohci->regs; |
| 1482 | int ints; |
| 1483 | int stat = -1; |
| 1484 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1485 | if ((ohci->hcca->done_head != 0) && |
| 1486 | !(ohci_cpu_to_le32(ohci->hcca->done_head) & 0x01)) { |
| 1487 | |
| 1488 | ints = OHCI_INTR_WDH; |
| 1489 | |
| 1490 | } else if ((ints = readl (®s->intrstatus)) == ~(u32)0) { |
| 1491 | ohci->disabled++; |
| 1492 | err ("%s device removed!", ohci->slot_name); |
| 1493 | return -1; |
| 1494 | |
| 1495 | } else if ((ints &= readl (®s->intrenable)) == 0) { |
| 1496 | dbg("hc_interrupt: returning..\n"); |
| 1497 | return 0xff; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */ |
| 1501 | |
| 1502 | if (ints & OHCI_INTR_RHSC) { |
| 1503 | got_rhsc = 1; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1504 | stat = 0xff; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | if (ints & OHCI_INTR_UE) { |
| 1508 | ohci->disabled++; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1509 | err ("OHCI Unrecoverable Error, controller usb-%s disabled", |
| 1510 | ohci->slot_name); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1511 | /* e.g. due to PCI Master/Target Abort */ |
| 1512 | |
| 1513 | #ifdef DEBUG |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1514 | ohci_dump (ohci, 1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1515 | #endif |
| 1516 | /* FIXME: be optimistic, hope that bug won't repeat often. */ |
| 1517 | /* Make some non-interrupt context restart the controller. */ |
| 1518 | /* Count and limit the retries though; either hardware or */ |
| 1519 | /* software errors can go forever... */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1520 | hc_reset (ohci); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1521 | return -1; |
| 1522 | } |
| 1523 | |
| 1524 | if (ints & OHCI_INTR_WDH) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1525 | writel (OHCI_INTR_WDH, ®s->intrdisable); |
| 1526 | stat = dl_done_list (&gohci, dl_reverse_done_list (&gohci)); |
| 1527 | writel (OHCI_INTR_WDH, ®s->intrenable); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | if (ints & OHCI_INTR_SO) { |
| 1531 | dbg("USB Schedule overrun\n"); |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1532 | writel (OHCI_INTR_SO, ®s->intrenable); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1533 | stat = -1; |
| 1534 | } |
| 1535 | |
| 1536 | /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */ |
| 1537 | if (ints & OHCI_INTR_SF) { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1538 | unsigned int frame = ohci_cpu_to_le16 (ohci->hcca->frame_no) & 1; |
| 1539 | wait_ms(1); |
| 1540 | writel (OHCI_INTR_SF, ®s->intrdisable); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1541 | if (ohci->ed_rm_list[frame] != NULL) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1542 | writel (OHCI_INTR_SF, ®s->intrenable); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1543 | stat = 0xff; |
| 1544 | } |
| 1545 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1546 | writel (ints, ®s->intrstatus); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1547 | return stat; |
| 1548 | } |
| 1549 | |
| 1550 | /*-------------------------------------------------------------------------*/ |
| 1551 | |
| 1552 | /*-------------------------------------------------------------------------*/ |
| 1553 | |
| 1554 | /* De-allocate all resources.. */ |
| 1555 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1556 | static void hc_release_ohci (ohci_t *ohci) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1557 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1558 | dbg ("USB HC release ohci usb-%s", ohci->slot_name); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1559 | |
| 1560 | if (!ohci->disabled) |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1561 | hc_reset (ohci); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | /*-------------------------------------------------------------------------*/ |
| 1565 | |
| 1566 | /* |
| 1567 | * low level initalisation routine, called from usb.c |
| 1568 | */ |
| 1569 | static char ohci_inited = 0; |
| 1570 | |
| 1571 | int usb_lowlevel_init(void) |
| 1572 | { |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1573 | memset (&gohci, 0, sizeof (ohci_t)); |
| 1574 | memset (&urb_priv, 0, sizeof (urb_priv_t)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1575 | |
| 1576 | /* align the storage */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1577 | if ((__u32)&ghcca[0] & 0xff) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1578 | err("HCCA not aligned!!"); |
| 1579 | return -1; |
| 1580 | } |
| 1581 | phcca = &ghcca[0]; |
| 1582 | info("aligned ghcca %p", phcca); |
| 1583 | memset(&ohci_dev, 0, sizeof(struct ohci_device)); |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1584 | if ((__u32)&ohci_dev.ed[0] & 0x7) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1585 | err("EDs not aligned!!"); |
| 1586 | return -1; |
| 1587 | } |
| 1588 | memset(gtd, 0, sizeof(td_t) * (NUM_TD + 1)); |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1589 | if ((__u32)gtd & 0x7) { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1590 | err("TDs not aligned!!"); |
| 1591 | return -1; |
| 1592 | } |
| 1593 | ptd = gtd; |
| 1594 | gohci.hcca = phcca; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1595 | memset (phcca, 0, sizeof (struct ohci_hcca)); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1596 | |
| 1597 | gohci.disabled = 1; |
| 1598 | gohci.sleeping = 0; |
| 1599 | gohci.irq = -1; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1600 | #if defined(CONFIG_440EP) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1601 | gohci.regs = (struct ohci_regs *)(CONFIG_SYS_PERIPHERAL_BASE | 0x1000); |
| 1602 | #elif defined(CONFIG_440EPX) || defined(CONFIG_SYS_USB_HOST) |
| 1603 | gohci.regs = (struct ohci_regs *)(CONFIG_SYS_USB_HOST); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1604 | #endif |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1605 | |
| 1606 | gohci.flags = 0; |
| 1607 | gohci.slot_name = "ppc440"; |
| 1608 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1609 | if (hc_reset (&gohci) < 0) { |
| 1610 | hc_release_ohci (&gohci); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1611 | return -1; |
| 1612 | } |
| 1613 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1614 | if (hc_start (&gohci) < 0) { |
| 1615 | err ("can't start usb-%s", gohci.slot_name); |
| 1616 | hc_release_ohci (&gohci); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1617 | return -1; |
| 1618 | } |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1619 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1620 | #ifdef DEBUG |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1621 | ohci_dump (&gohci, 1); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1622 | #endif |
| 1623 | ohci_inited = 1; |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1624 | urb_finished = 1; |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1625 | |
Stefan Roese | e01bd21 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 1626 | #if defined(CONFIG_440EP) || defined(CONFIG_440EPX) |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1627 | /* init the device driver */ |
| 1628 | usb_dev_init(); |
Stefan Roese | e01bd21 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 1629 | #endif |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1630 | |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
| 1634 | int usb_lowlevel_stop(void) |
| 1635 | { |
| 1636 | /* this gets called really early - before the controller has */ |
| 1637 | /* even been initialized! */ |
| 1638 | if (!ohci_inited) |
| 1639 | return 0; |
| 1640 | /* TODO release any interrupts, etc. */ |
| 1641 | /* call hc_release_ohci() here ? */ |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1642 | hc_reset (&gohci); |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 1643 | return 0; |
| 1644 | } |
| 1645 | |
Stefan Roese | 7770ce4 | 2005-08-02 10:05:21 +0200 | [diff] [blame] | 1646 | #endif /* CONFIG_USB_OHCI */ |