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