Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1 | /* |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 2 | * URB OHCI HCD (Host Controller Driver) for USB on the AT91RM9200 and PCI bus. |
| 3 | * |
| 4 | * Interrupt support is added. Now, it has been tested |
| 5 | * on ULI1575 chip and works well with USB keyboard. |
| 6 | * |
| 7 | * (C) Copyright 2007 |
| 8 | * Zhang Wei, Freescale Semiconductor, Inc. <wei.zhang@freescale.com> |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 9 | * |
| 10 | * (C) Copyright 2003 |
Detlev Zundel | 792a09e | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 11 | * Gary Jennejohn, DENX Software Engineering <garyj@denx.de> |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 12 | * |
| 13 | * Note: Much of this code has been derived from Linux 2.4 |
| 14 | * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> |
| 15 | * (C) Copyright 2000-2002 David Brownell |
| 16 | * |
| 17 | * Modified for the MP2USB by (C) Copyright 2005 Eric Benard |
| 18 | * ebenard@eukrea.com - based on s3c24x0's driver |
| 19 | * |
| 20 | * See file CREDITS for list of people who contributed to this |
| 21 | * project. |
| 22 | * |
| 23 | * This program is free software; you can redistribute it and/or |
| 24 | * modify it under the terms of the GNU General Public License as |
| 25 | * published by the Free Software Foundation; either version 2 of |
| 26 | * the License, or (at your option) any later version. |
| 27 | * |
| 28 | * This program is distributed in the hope that it will be useful, |
| 29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Jerry Van Baren | ae0b05d | 2009-02-05 22:18:02 -0500 | [diff] [blame] | 30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 31 | * GNU General Public License for more details. |
| 32 | * |
| 33 | * You should have received a copy of the GNU General Public License |
| 34 | * along with this program; if not, write to the Free Software |
| 35 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 36 | * MA 02111-1307 USA |
| 37 | * |
| 38 | */ |
| 39 | /* |
| 40 | * IMPORTANT NOTES |
Markus Klotzbuecher | fc43be4 | 2007-06-06 11:49:35 +0200 | [diff] [blame] | 41 | * 1 - Read doc/README.generic_usb_ohci |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 42 | * 2 - this driver is intended for use with USB Mass Storage Devices |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 43 | * (BBB) and USB keyboard. There is NO support for Isochronous pipes! |
Markus Klotzbuecher | fc43be4 | 2007-06-06 11:49:35 +0200 | [diff] [blame] | 44 | * 2 - when running on a PQFP208 AT91RM9200, define CONFIG_AT91C_PQFP_UHPBUG |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 45 | * to activate workaround for bug #41 or this driver will NOT work! |
| 46 | */ |
| 47 | |
| 48 | #include <common.h> |
Markus Klotzbuecher | fc43be4 | 2007-06-06 11:49:35 +0200 | [diff] [blame] | 49 | #include <asm/byteorder.h> |
| 50 | |
| 51 | #if defined(CONFIG_PCI_OHCI) |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 52 | # include <pci.h> |
Sergei Poselenov | 477434c | 2008-05-22 01:15:53 +0200 | [diff] [blame] | 53 | #if !defined(CONFIG_PCI_OHCI_DEVNO) |
| 54 | #define CONFIG_PCI_OHCI_DEVNO 0 |
| 55 | #endif |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 56 | #endif |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 57 | |
| 58 | #include <malloc.h> |
| 59 | #include <usb.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2731b9a | 2009-04-03 12:46:58 +0200 | [diff] [blame] | 60 | |
| 61 | #include "ohci.h" |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 62 | |
Wolfgang Denk | e8da58f | 2007-11-19 12:59:14 +0100 | [diff] [blame] | 63 | #ifdef CONFIG_AT91RM9200 |
| 64 | #include <asm/arch/hardware.h> /* needed for AT91_USB_HOST_BASE */ |
| 65 | #endif |
| 66 | |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 67 | #if defined(CONFIG_ARM920T) || \ |
kevin.morfitt@fearnside-systems.co.uk | ac67804 | 2009-11-17 18:30:34 +0900 | [diff] [blame] | 68 | defined(CONFIG_S3C24X0) || \ |
Guennadi Liakhovetski | 8262813 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 69 | defined(CONFIG_S3C6400) || \ |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 70 | defined(CONFIG_440EP) || \ |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 71 | defined(CONFIG_PCI_OHCI) || \ |
Stefan Roese | 2596f5b | 2008-03-05 12:29:32 +0100 | [diff] [blame] | 72 | defined(CONFIG_MPC5200) || \ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | defined(CONFIG_SYS_OHCI_USE_NPS) |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 74 | # define OHCI_USE_NPS /* force NoPowerSwitching mode */ |
| 75 | #endif |
| 76 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 77 | #undef OHCI_VERBOSE_DEBUG /* not always helpful */ |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 78 | #undef DEBUG |
| 79 | #undef SHOW_INFO |
| 80 | #undef OHCI_FILL_TRACE |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 81 | |
| 82 | /* For initializing controller (mask in an HCFS mode too) */ |
| 83 | #define OHCI_CONTROL_INIT \ |
| 84 | (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE |
| 85 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 86 | #define min_t(type, x, y) \ |
| 87 | ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 88 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_PCI_OHCI |
| 90 | static struct pci_device_id ohci_pci_ids[] = { |
| 91 | {0x10b9, 0x5237}, /* ULI1575 PCI OHCI module ids */ |
David Saada | 97213f3 | 2007-09-17 17:04:47 +0200 | [diff] [blame] | 92 | {0x1033, 0x0035}, /* NEC PCI OHCI module ids */ |
TsiChung Liew | 3afac79 | 2008-01-11 20:42:58 -0600 | [diff] [blame] | 93 | {0x1131, 0x1561}, /* Philips 1561 PCI OHCI module ids */ |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 94 | /* Please add supported PCI OHCI controller ids here */ |
| 95 | {0, 0} |
| 96 | }; |
| 97 | #endif |
| 98 | |
Yuri Tikhonov | e90fb6a | 2008-09-04 11:19:05 +0200 | [diff] [blame] | 99 | #ifdef CONFIG_PCI_EHCI_DEVNO |
| 100 | static struct pci_device_id ehci_pci_ids[] = { |
| 101 | {0x1131, 0x1562}, /* Philips 1562 PCI EHCI module ids */ |
| 102 | /* Please add supported PCI EHCI controller ids here */ |
| 103 | {0, 0} |
| 104 | }; |
| 105 | #endif |
| 106 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 107 | #ifdef DEBUG |
| 108 | #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg) |
| 109 | #else |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 110 | #define dbg(format, arg...) do {} while (0) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 111 | #endif /* DEBUG */ |
| 112 | #define err(format, arg...) printf("ERROR: " format "\n", ## arg) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 113 | #ifdef SHOW_INFO |
| 114 | #define info(format, arg...) printf("INFO: " format "\n", ## arg) |
| 115 | #else |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 116 | #define info(format, arg...) do {} while (0) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 117 | #endif |
| 118 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 119 | #ifdef CONFIG_SYS_OHCI_BE_CONTROLLER |
Markus Klotzbuecher | fc43be4 | 2007-06-06 11:49:35 +0200 | [diff] [blame] | 120 | # define m16_swap(x) cpu_to_be16(x) |
| 121 | # define m32_swap(x) cpu_to_be32(x) |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 122 | #else |
Markus Klotzbuecher | fc43be4 | 2007-06-06 11:49:35 +0200 | [diff] [blame] | 123 | # define m16_swap(x) cpu_to_le16(x) |
| 124 | # define m32_swap(x) cpu_to_le32(x) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | #endif /* CONFIG_SYS_OHCI_BE_CONTROLLER */ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 126 | |
| 127 | /* global ohci_t */ |
| 128 | static ohci_t gohci; |
| 129 | /* this must be aligned to a 256 byte boundary */ |
| 130 | struct ohci_hcca ghcca[1]; |
| 131 | /* a pointer to the aligned storage */ |
| 132 | struct ohci_hcca *phcca; |
| 133 | /* this allocates EDs for all possible endpoints */ |
| 134 | struct ohci_device ohci_dev; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 135 | /* device which was disconnected */ |
| 136 | struct usb_device *devgone; |
| 137 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 138 | static inline u32 roothub_a(struct ohci *hc) |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 139 | { return ohci_readl(&hc->regs->roothub.a); } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 140 | static inline u32 roothub_b(struct ohci *hc) |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 141 | { return ohci_readl(&hc->regs->roothub.b); } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 142 | static inline u32 roothub_status(struct ohci *hc) |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 143 | { return ohci_readl(&hc->regs->roothub.status); } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 144 | static inline u32 roothub_portstatus(struct ohci *hc, int i) |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 145 | { return ohci_readl(&hc->regs->roothub.portstatus[i]); } |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 146 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 147 | /* forward declaration */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 148 | static int hc_interrupt(void); |
| 149 | static void td_submit_job(struct usb_device *dev, unsigned long pipe, |
| 150 | void *buffer, int transfer_len, |
| 151 | struct devrequest *setup, urb_priv_t *urb, |
| 152 | int interval); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 153 | |
| 154 | /*-------------------------------------------------------------------------* |
| 155 | * URB support functions |
| 156 | *-------------------------------------------------------------------------*/ |
| 157 | |
| 158 | /* free HCD-private data associated with this URB */ |
| 159 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 160 | static void urb_free_priv(urb_priv_t *urb) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 161 | { |
| 162 | int i; |
| 163 | int last; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 164 | struct td *td; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 165 | |
| 166 | last = urb->length - 1; |
| 167 | if (last >= 0) { |
| 168 | for (i = 0; i <= last; i++) { |
| 169 | td = urb->td[i]; |
| 170 | if (td) { |
| 171 | td->usb_dev = NULL; |
| 172 | urb->td[i] = NULL; |
| 173 | } |
| 174 | } |
| 175 | } |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 176 | free(urb); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /*-------------------------------------------------------------------------*/ |
| 180 | |
| 181 | #ifdef DEBUG |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 182 | static int sohci_get_current_frame_number(struct usb_device *dev); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 183 | |
| 184 | /* debug| print the main components of an URB |
| 185 | * small: 0) header + data packets 1) just header */ |
| 186 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 187 | static void pkt_print(urb_priv_t *purb, struct usb_device *dev, |
| 188 | unsigned long pipe, void *buffer, int transfer_len, |
| 189 | struct devrequest *setup, char *str, int small) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 190 | { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 191 | dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx", |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 192 | str, |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 193 | sohci_get_current_frame_number(dev), |
| 194 | usb_pipedevice(pipe), |
| 195 | usb_pipeendpoint(pipe), |
| 196 | usb_pipeout(pipe)? 'O': 'I', |
| 197 | usb_pipetype(pipe) < 2 ? \ |
| 198 | (usb_pipeint(pipe)? "INTR": "ISOC"): \ |
| 199 | (usb_pipecontrol(pipe)? "CTRL": "BULK"), |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 200 | (purb ? purb->actual_length : 0), |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 201 | transfer_len, dev->status); |
| 202 | #ifdef OHCI_VERBOSE_DEBUG |
| 203 | if (!small) { |
| 204 | int i, len; |
| 205 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 206 | if (usb_pipecontrol(pipe)) { |
| 207 | printf(__FILE__ ": cmd(8):"); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 208 | for (i = 0; i < 8 ; i++) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 209 | printf(" %02x", ((__u8 *) setup) [i]); |
| 210 | printf("\n"); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 211 | } |
| 212 | if (transfer_len > 0 && buffer) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 213 | printf(__FILE__ ": data(%d/%d):", |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 214 | (purb ? purb->actual_length : 0), |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 215 | transfer_len); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 216 | len = usb_pipeout(pipe)? transfer_len: |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 217 | (purb ? purb->actual_length : 0); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 218 | for (i = 0; i < 16 && i < len; i++) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 219 | printf(" %02x", ((__u8 *) buffer) [i]); |
| 220 | printf("%s\n", i < len? "...": ""); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | #endif |
| 224 | } |
| 225 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 226 | /* just for debugging; prints non-empty branches of the int ed tree |
| 227 | * inclusive iso eds */ |
| 228 | void ep_print_int_eds(ohci_t *ohci, char *str) |
| 229 | { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 230 | int i, j; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 231 | __u32 *ed_p; |
| 232 | for (i = 0; i < 32; i++) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 233 | j = 5; |
| 234 | ed_p = &(ohci->hcca->int_table [i]); |
| 235 | if (*ed_p == 0) |
| 236 | continue; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 237 | printf(__FILE__ ": %s branch int %2d(%2x):", str, i, i); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 238 | while (*ed_p != 0 && j--) { |
| 239 | ed_t *ed = (ed_t *)m32_swap(ed_p); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 240 | printf(" ed: %4x;", ed->hwINFO); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 241 | ed_p = &ed->hwNextED; |
| 242 | } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 243 | printf("\n"); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 247 | static void ohci_dump_intr_mask(char *label, __u32 mask) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 248 | { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 249 | dbg("%s: 0x%08x%s%s%s%s%s%s%s%s%s", |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 250 | label, |
| 251 | mask, |
| 252 | (mask & OHCI_INTR_MIE) ? " MIE" : "", |
| 253 | (mask & OHCI_INTR_OC) ? " OC" : "", |
| 254 | (mask & OHCI_INTR_RHSC) ? " RHSC" : "", |
| 255 | (mask & OHCI_INTR_FNO) ? " FNO" : "", |
| 256 | (mask & OHCI_INTR_UE) ? " UE" : "", |
| 257 | (mask & OHCI_INTR_RD) ? " RD" : "", |
| 258 | (mask & OHCI_INTR_SF) ? " SF" : "", |
| 259 | (mask & OHCI_INTR_WDH) ? " WDH" : "", |
| 260 | (mask & OHCI_INTR_SO) ? " SO" : "" |
| 261 | ); |
| 262 | } |
| 263 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 264 | static void maybe_print_eds(char *label, __u32 value) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 265 | { |
| 266 | ed_t *edp = (ed_t *)value; |
| 267 | |
| 268 | if (value) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 269 | dbg("%s %08x", label, value); |
| 270 | dbg("%08x", edp->hwINFO); |
| 271 | dbg("%08x", edp->hwTailP); |
| 272 | dbg("%08x", edp->hwHeadP); |
| 273 | dbg("%08x", edp->hwNextED); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 277 | static char *hcfs2string(int state) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 278 | { |
| 279 | switch (state) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 280 | case OHCI_USB_RESET: return "reset"; |
| 281 | case OHCI_USB_RESUME: return "resume"; |
| 282 | case OHCI_USB_OPER: return "operational"; |
| 283 | case OHCI_USB_SUSPEND: return "suspend"; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 284 | } |
| 285 | return "?"; |
| 286 | } |
| 287 | |
| 288 | /* dump control and status registers */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 289 | static void ohci_dump_status(ohci_t *controller) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 290 | { |
| 291 | struct ohci_regs *regs = controller->regs; |
| 292 | __u32 temp; |
| 293 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 294 | temp = ohci_readl(®s->revision) & 0xff; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 295 | if (temp != 0x10) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 296 | dbg("spec %d.%d", (temp >> 4), (temp & 0x0f)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 297 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 298 | temp = ohci_readl(®s->control); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 299 | dbg("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp, |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 300 | (temp & OHCI_CTRL_RWE) ? " RWE" : "", |
| 301 | (temp & OHCI_CTRL_RWC) ? " RWC" : "", |
| 302 | (temp & OHCI_CTRL_IR) ? " IR" : "", |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 303 | hcfs2string(temp & OHCI_CTRL_HCFS), |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 304 | (temp & OHCI_CTRL_BLE) ? " BLE" : "", |
| 305 | (temp & OHCI_CTRL_CLE) ? " CLE" : "", |
| 306 | (temp & OHCI_CTRL_IE) ? " IE" : "", |
| 307 | (temp & OHCI_CTRL_PLE) ? " PLE" : "", |
| 308 | temp & OHCI_CTRL_CBSR |
| 309 | ); |
| 310 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 311 | temp = ohci_readl(®s->cmdstatus); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 312 | dbg("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp, |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 313 | (temp & OHCI_SOC) >> 16, |
| 314 | (temp & OHCI_OCR) ? " OCR" : "", |
| 315 | (temp & OHCI_BLF) ? " BLF" : "", |
| 316 | (temp & OHCI_CLF) ? " CLF" : "", |
| 317 | (temp & OHCI_HCR) ? " HCR" : "" |
| 318 | ); |
| 319 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 320 | ohci_dump_intr_mask("intrstatus", ohci_readl(®s->intrstatus)); |
| 321 | ohci_dump_intr_mask("intrenable", ohci_readl(®s->intrenable)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 322 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 323 | maybe_print_eds("ed_periodcurrent", |
| 324 | ohci_readl(®s->ed_periodcurrent)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 325 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 326 | maybe_print_eds("ed_controlhead", ohci_readl(®s->ed_controlhead)); |
| 327 | maybe_print_eds("ed_controlcurrent", |
| 328 | ohci_readl(®s->ed_controlcurrent)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 329 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 330 | maybe_print_eds("ed_bulkhead", ohci_readl(®s->ed_bulkhead)); |
| 331 | maybe_print_eds("ed_bulkcurrent", ohci_readl(®s->ed_bulkcurrent)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 332 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 333 | maybe_print_eds("donehead", ohci_readl(®s->donehead)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 334 | } |
| 335 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 336 | static void ohci_dump_roothub(ohci_t *controller, int verbose) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 337 | { |
| 338 | __u32 temp, ndp, i; |
| 339 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 340 | temp = roothub_a(controller); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 341 | ndp = (temp & RH_A_NDP); |
| 342 | #ifdef CONFIG_AT91C_PQFP_UHPBUG |
| 343 | ndp = (ndp == 2) ? 1:0; |
| 344 | #endif |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 345 | if (verbose) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 346 | dbg("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp, |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 347 | ((temp & RH_A_POTPGT) >> 24) & 0xff, |
| 348 | (temp & RH_A_NOCP) ? " NOCP" : "", |
| 349 | (temp & RH_A_OCPM) ? " OCPM" : "", |
| 350 | (temp & RH_A_DT) ? " DT" : "", |
| 351 | (temp & RH_A_NPS) ? " NPS" : "", |
| 352 | (temp & RH_A_PSM) ? " PSM" : "", |
| 353 | ndp |
| 354 | ); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 355 | temp = roothub_b(controller); |
| 356 | dbg("roothub.b: %08x PPCM=%04x DR=%04x", |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 357 | temp, |
| 358 | (temp & RH_B_PPCM) >> 16, |
| 359 | (temp & RH_B_DR) |
| 360 | ); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 361 | temp = roothub_status(controller); |
| 362 | dbg("roothub.status: %08x%s%s%s%s%s%s", |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 363 | temp, |
| 364 | (temp & RH_HS_CRWE) ? " CRWE" : "", |
| 365 | (temp & RH_HS_OCIC) ? " OCIC" : "", |
| 366 | (temp & RH_HS_LPSC) ? " LPSC" : "", |
| 367 | (temp & RH_HS_DRWE) ? " DRWE" : "", |
| 368 | (temp & RH_HS_OCI) ? " OCI" : "", |
| 369 | (temp & RH_HS_LPS) ? " LPS" : "" |
| 370 | ); |
| 371 | } |
| 372 | |
| 373 | for (i = 0; i < ndp; i++) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 374 | temp = roothub_portstatus(controller, i); |
| 375 | dbg("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s", |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 376 | i, |
| 377 | temp, |
| 378 | (temp & RH_PS_PRSC) ? " PRSC" : "", |
| 379 | (temp & RH_PS_OCIC) ? " OCIC" : "", |
| 380 | (temp & RH_PS_PSSC) ? " PSSC" : "", |
| 381 | (temp & RH_PS_PESC) ? " PESC" : "", |
| 382 | (temp & RH_PS_CSC) ? " CSC" : "", |
| 383 | |
| 384 | (temp & RH_PS_LSDA) ? " LSDA" : "", |
| 385 | (temp & RH_PS_PPS) ? " PPS" : "", |
| 386 | (temp & RH_PS_PRS) ? " PRS" : "", |
| 387 | (temp & RH_PS_POCI) ? " POCI" : "", |
| 388 | (temp & RH_PS_PSS) ? " PSS" : "", |
| 389 | |
| 390 | (temp & RH_PS_PES) ? " PES" : "", |
| 391 | (temp & RH_PS_CCS) ? " CCS" : "" |
| 392 | ); |
| 393 | } |
| 394 | } |
| 395 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 396 | static void ohci_dump(ohci_t *controller, int verbose) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 397 | { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 398 | dbg("OHCI controller usb-%s state", controller->slot_name); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 399 | |
| 400 | /* dumps some of the state we know about */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 401 | ohci_dump_status(controller); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 402 | if (verbose) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 403 | ep_print_int_eds(controller, "hcca"); |
| 404 | dbg("hcca frame #%04x", controller->hcca->frame_no); |
| 405 | ohci_dump_roothub(controller, 1); |
Stefan Roese | 2596f5b | 2008-03-05 12:29:32 +0100 | [diff] [blame] | 406 | } |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 407 | #endif /* DEBUG */ |
| 408 | |
| 409 | /*-------------------------------------------------------------------------* |
| 410 | * Interface functions (URB) |
| 411 | *-------------------------------------------------------------------------*/ |
| 412 | |
| 413 | /* get a transfer request */ |
| 414 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 415 | int sohci_submit_job(urb_priv_t *urb, struct devrequest *setup) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 416 | { |
| 417 | ohci_t *ohci; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 418 | ed_t *ed; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 419 | urb_priv_t *purb_priv = urb; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 420 | int i, size = 0; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 421 | struct usb_device *dev = urb->dev; |
| 422 | unsigned long pipe = urb->pipe; |
| 423 | void *buffer = urb->transfer_buffer; |
| 424 | int transfer_len = urb->transfer_buffer_length; |
| 425 | int interval = urb->interval; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 426 | |
| 427 | ohci = &gohci; |
| 428 | |
| 429 | /* when controller's hung, permit only roothub cleanup attempts |
| 430 | * such as powering down ports */ |
| 431 | if (ohci->disabled) { |
| 432 | err("sohci_submit_job: EPIPE"); |
| 433 | return -1; |
| 434 | } |
Markus Klotzbuecher | ae79f60 | 2007-03-26 11:21:05 +0200 | [diff] [blame] | 435 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 436 | /* we're about to begin a new transaction here so mark the |
| 437 | * URB unfinished */ |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 438 | urb->finished = 0; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 439 | |
| 440 | /* every endpoint has a ed, locate and fill it */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 441 | ed = ep_add_ed(dev, pipe, interval, 1); |
| 442 | if (!ed) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 443 | err("sohci_submit_job: ENOMEM"); |
| 444 | return -1; |
| 445 | } |
| 446 | |
| 447 | /* for the private part of the URB we need the number of TDs (size) */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 448 | switch (usb_pipetype(pipe)) { |
| 449 | case PIPE_BULK: /* one TD for every 4096 Byte */ |
| 450 | size = (transfer_len - 1) / 4096 + 1; |
| 451 | break; |
| 452 | case PIPE_CONTROL:/* 1 TD for setup, 1 for ACK and 1 for every 4096 B */ |
| 453 | size = (transfer_len == 0)? 2: |
| 454 | (transfer_len - 1) / 4096 + 3; |
| 455 | break; |
| 456 | case PIPE_INTERRUPT: /* 1 TD */ |
| 457 | size = 1; |
| 458 | break; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 459 | } |
| 460 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 461 | ed->purb = urb; |
| 462 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 463 | if (size >= (N_URB_TD - 1)) { |
| 464 | err("need %d TDs, only have %d", size, N_URB_TD); |
| 465 | return -1; |
| 466 | } |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 467 | purb_priv->pipe = pipe; |
| 468 | |
| 469 | /* fill the private part of the URB */ |
| 470 | purb_priv->length = size; |
| 471 | purb_priv->ed = ed; |
| 472 | purb_priv->actual_length = 0; |
| 473 | |
| 474 | /* allocate the TDs */ |
| 475 | /* note that td[0] was allocated in ep_add_ed */ |
| 476 | for (i = 0; i < size; i++) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 477 | purb_priv->td[i] = td_alloc(dev); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 478 | if (!purb_priv->td[i]) { |
| 479 | purb_priv->length = i; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 480 | urb_free_priv(purb_priv); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 481 | err("sohci_submit_job: ENOMEM"); |
| 482 | return -1; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | if (ed->state == ED_NEW || (ed->state & ED_DEL)) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 487 | urb_free_priv(purb_priv); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 488 | err("sohci_submit_job: EINVAL"); |
| 489 | return -1; |
| 490 | } |
| 491 | |
| 492 | /* link the ed into a chain if is not already */ |
| 493 | if (ed->state != ED_OPER) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 494 | ep_link(ohci, ed); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 495 | |
| 496 | /* fill the TDs and link it to the ed */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 497 | td_submit_job(dev, pipe, buffer, transfer_len, |
| 498 | setup, purb_priv, interval); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 503 | static inline int sohci_return_job(struct ohci *hc, urb_priv_t *urb) |
| 504 | { |
| 505 | struct ohci_regs *regs = hc->regs; |
| 506 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 507 | switch (usb_pipetype(urb->pipe)) { |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 508 | case PIPE_INTERRUPT: |
| 509 | /* implicitly requeued */ |
| 510 | if (urb->dev->irq_handle && |
| 511 | (urb->dev->irq_act_len = urb->actual_length)) { |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 512 | ohci_writel(OHCI_INTR_WDH, ®s->intrenable); |
| 513 | ohci_readl(®s->intrenable); /* PCI posting flush */ |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 514 | urb->dev->irq_handle(urb->dev); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 515 | ohci_writel(OHCI_INTR_WDH, ®s->intrdisable); |
| 516 | ohci_readl(®s->intrdisable); /* PCI posting flush */ |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 517 | } |
| 518 | urb->actual_length = 0; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 519 | td_submit_job( |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 520 | urb->dev, |
| 521 | urb->pipe, |
| 522 | urb->transfer_buffer, |
| 523 | urb->transfer_buffer_length, |
| 524 | NULL, |
| 525 | urb, |
| 526 | urb->interval); |
| 527 | break; |
| 528 | case PIPE_CONTROL: |
| 529 | case PIPE_BULK: |
| 530 | break; |
| 531 | default: |
| 532 | return 0; |
| 533 | } |
| 534 | return 1; |
| 535 | } |
| 536 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 537 | /*-------------------------------------------------------------------------*/ |
| 538 | |
| 539 | #ifdef DEBUG |
| 540 | /* tell us the current USB frame number */ |
| 541 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 542 | static int sohci_get_current_frame_number(struct usb_device *usb_dev) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 543 | { |
| 544 | ohci_t *ohci = &gohci; |
| 545 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 546 | return m16_swap(ohci->hcca->frame_no); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 547 | } |
| 548 | #endif |
| 549 | |
| 550 | /*-------------------------------------------------------------------------* |
| 551 | * ED handling functions |
| 552 | *-------------------------------------------------------------------------*/ |
| 553 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 554 | /* search for the right branch to insert an interrupt ed into the int tree |
| 555 | * do some load ballancing; |
| 556 | * returns the branch and |
| 557 | * sets the interval to interval = 2^integer (ld (interval)) */ |
| 558 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 559 | static int ep_int_ballance(ohci_t *ohci, int interval, int load) |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 560 | { |
| 561 | int i, branch = 0; |
| 562 | |
| 563 | /* search for the least loaded interrupt endpoint |
| 564 | * branch of all 32 branches |
| 565 | */ |
| 566 | for (i = 0; i < 32; i++) |
| 567 | if (ohci->ohci_int_load [branch] > ohci->ohci_int_load [i]) |
| 568 | branch = i; |
| 569 | |
| 570 | branch = branch % interval; |
| 571 | for (i = branch; i < 32; i += interval) |
| 572 | ohci->ohci_int_load [i] += load; |
| 573 | |
| 574 | return branch; |
| 575 | } |
| 576 | |
| 577 | /*-------------------------------------------------------------------------*/ |
| 578 | |
| 579 | /* 2^int( ld (inter)) */ |
| 580 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 581 | static int ep_2_n_interval(int inter) |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 582 | { |
| 583 | int i; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 584 | for (i = 0; ((inter >> i) > 1) && (i < 5); i++); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 585 | return 1 << i; |
| 586 | } |
| 587 | |
| 588 | /*-------------------------------------------------------------------------*/ |
| 589 | |
| 590 | /* the int tree is a binary tree |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 591 | * in order to process it sequentially the indexes of the branches have to |
| 592 | * be mapped the mapping reverses the bits of a word of num_bits length */ |
| 593 | static int ep_rev(int num_bits, int word) |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 594 | { |
| 595 | int i, wout = 0; |
| 596 | |
| 597 | for (i = 0; i < num_bits; i++) |
| 598 | wout |= (((word >> i) & 1) << (num_bits - i - 1)); |
| 599 | return wout; |
| 600 | } |
| 601 | |
| 602 | /*-------------------------------------------------------------------------* |
| 603 | * ED handling functions |
| 604 | *-------------------------------------------------------------------------*/ |
| 605 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 606 | /* link an ed into one of the HC chains */ |
| 607 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 608 | static int ep_link(ohci_t *ohci, ed_t *edi) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 609 | { |
| 610 | volatile ed_t *ed = edi; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 611 | int int_branch; |
| 612 | int i; |
| 613 | int inter; |
| 614 | int interval; |
| 615 | int load; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 616 | __u32 *ed_p; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 617 | |
| 618 | ed->state = ED_OPER; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 619 | ed->int_interval = 0; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 620 | |
| 621 | switch (ed->type) { |
| 622 | case PIPE_CONTROL: |
| 623 | ed->hwNextED = 0; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 624 | if (ohci->ed_controltail == NULL) |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 625 | ohci_writel(ed, &ohci->regs->ed_controlhead); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 626 | else |
| 627 | ohci->ed_controltail->hwNextED = |
| 628 | m32_swap((unsigned long)ed); |
| 629 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 630 | ed->ed_prev = ohci->ed_controltail; |
| 631 | if (!ohci->ed_controltail && !ohci->ed_rm_list[0] && |
| 632 | !ohci->ed_rm_list[1] && !ohci->sleeping) { |
| 633 | ohci->hc_control |= OHCI_CTRL_CLE; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 634 | ohci_writel(ohci->hc_control, &ohci->regs->control); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 635 | } |
| 636 | ohci->ed_controltail = edi; |
| 637 | break; |
| 638 | |
| 639 | case PIPE_BULK: |
| 640 | ed->hwNextED = 0; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 641 | if (ohci->ed_bulktail == NULL) |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 642 | ohci_writel(ed, &ohci->regs->ed_bulkhead); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 643 | else |
| 644 | ohci->ed_bulktail->hwNextED = |
| 645 | m32_swap((unsigned long)ed); |
| 646 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 647 | ed->ed_prev = ohci->ed_bulktail; |
| 648 | if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] && |
| 649 | !ohci->ed_rm_list[1] && !ohci->sleeping) { |
| 650 | ohci->hc_control |= OHCI_CTRL_BLE; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 651 | ohci_writel(ohci->hc_control, &ohci->regs->control); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 652 | } |
| 653 | ohci->ed_bulktail = edi; |
| 654 | break; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 655 | |
| 656 | case PIPE_INTERRUPT: |
| 657 | load = ed->int_load; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 658 | interval = ep_2_n_interval(ed->int_period); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 659 | ed->int_interval = interval; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 660 | int_branch = ep_int_ballance(ohci, interval, load); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 661 | ed->int_branch = int_branch; |
| 662 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 663 | for (i = 0; i < ep_rev(6, interval); i += inter) { |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 664 | inter = 1; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 665 | for (ed_p = &(ohci->hcca->int_table[\ |
| 666 | ep_rev(5, i) + int_branch]); |
| 667 | (*ed_p != 0) && |
| 668 | (((ed_t *)ed_p)->int_interval >= interval); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 669 | ed_p = &(((ed_t *)ed_p)->hwNextED)) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 670 | inter = ep_rev(6, |
| 671 | ((ed_t *)ed_p)->int_interval); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 672 | ed->hwNextED = *ed_p; |
Martin Krause | 4a8527e | 2007-08-21 12:40:34 +0200 | [diff] [blame] | 673 | *ed_p = m32_swap((unsigned long)ed); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 674 | } |
| 675 | break; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 676 | } |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | /*-------------------------------------------------------------------------*/ |
| 681 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 682 | /* scan the periodic table to find and unlink this ED */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 683 | static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed, |
| 684 | unsigned index, unsigned period) |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 685 | { |
| 686 | for (; index < NUM_INTS; index += period) { |
| 687 | __u32 *ed_p = &ohci->hcca->int_table [index]; |
| 688 | |
| 689 | /* ED might have been unlinked through another path */ |
| 690 | while (*ed_p != 0) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 691 | if (((struct ed *) |
| 692 | m32_swap((unsigned long)ed_p)) == ed) { |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 693 | *ed_p = ed->hwNextED; |
| 694 | break; |
| 695 | } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 696 | ed_p = &(((struct ed *) |
| 697 | m32_swap((unsigned long)ed_p))->hwNextED); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 702 | /* unlink an ed from one of the HC chains. |
| 703 | * just the link to the ed is unlinked. |
| 704 | * the link from the ed still points to another operational ed or 0 |
| 705 | * so the HC can eventually finish the processing of the unlinked ed */ |
| 706 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 707 | static int ep_unlink(ohci_t *ohci, ed_t *edi) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 708 | { |
Markus Klotzbuecher | 53e336e | 2006-11-27 11:43:09 +0100 | [diff] [blame] | 709 | volatile ed_t *ed = edi; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 710 | int i; |
Markus Klotzbuecher | 53e336e | 2006-11-27 11:43:09 +0100 | [diff] [blame] | 711 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 712 | ed->hwINFO |= m32_swap(OHCI_ED_SKIP); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 713 | |
| 714 | switch (ed->type) { |
| 715 | case PIPE_CONTROL: |
| 716 | if (ed->ed_prev == NULL) { |
| 717 | if (!ed->hwNextED) { |
| 718 | ohci->hc_control &= ~OHCI_CTRL_CLE; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 719 | ohci_writel(ohci->hc_control, |
| 720 | &ohci->regs->control); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 721 | } |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 722 | ohci_writel(m32_swap(*((__u32 *)&ed->hwNextED)), |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 723 | &ohci->regs->ed_controlhead); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 724 | } else { |
| 725 | ed->ed_prev->hwNextED = ed->hwNextED; |
| 726 | } |
| 727 | if (ohci->ed_controltail == ed) { |
| 728 | ohci->ed_controltail = ed->ed_prev; |
| 729 | } else { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 730 | ((ed_t *)m32_swap( |
| 731 | *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 732 | } |
| 733 | break; |
| 734 | |
| 735 | case PIPE_BULK: |
| 736 | if (ed->ed_prev == NULL) { |
| 737 | if (!ed->hwNextED) { |
| 738 | ohci->hc_control &= ~OHCI_CTRL_BLE; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 739 | ohci_writel(ohci->hc_control, |
| 740 | &ohci->regs->control); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 741 | } |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 742 | ohci_writel(m32_swap(*((__u32 *)&ed->hwNextED)), |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 743 | &ohci->regs->ed_bulkhead); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 744 | } else { |
| 745 | ed->ed_prev->hwNextED = ed->hwNextED; |
| 746 | } |
| 747 | if (ohci->ed_bulktail == ed) { |
| 748 | ohci->ed_bulktail = ed->ed_prev; |
| 749 | } else { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 750 | ((ed_t *)m32_swap( |
| 751 | *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 752 | } |
| 753 | break; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 754 | |
| 755 | case PIPE_INTERRUPT: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 756 | periodic_unlink(ohci, ed, 0, 1); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 757 | for (i = ed->int_branch; i < 32; i += ed->int_interval) |
| 758 | ohci->ohci_int_load[i] -= ed->int_load; |
| 759 | break; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 760 | } |
| 761 | ed->state = ED_UNLINK; |
| 762 | return 0; |
| 763 | } |
| 764 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 765 | /*-------------------------------------------------------------------------*/ |
| 766 | |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 767 | /* add/reinit an endpoint; this should be done once at the |
| 768 | * usb_set_configuration command, but the USB stack is a little bit |
| 769 | * stateless so we do it at every transaction if the state of the ed |
| 770 | * is ED_NEW then a dummy td is added and the state is changed to |
| 771 | * ED_UNLINK in all other cases the state is left unchanged the ed |
| 772 | * info fields are setted anyway even though most of them should not |
| 773 | * change |
| 774 | */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 775 | static ed_t *ep_add_ed(struct usb_device *usb_dev, unsigned long pipe, |
| 776 | int interval, int load) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 777 | { |
| 778 | td_t *td; |
| 779 | ed_t *ed_ret; |
| 780 | volatile ed_t *ed; |
| 781 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 782 | ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint(pipe) << 1) | |
| 783 | (usb_pipecontrol(pipe)? 0: usb_pipeout(pipe))]; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 784 | |
| 785 | if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) { |
| 786 | err("ep_add_ed: pending delete"); |
| 787 | /* pending delete request */ |
| 788 | return NULL; |
| 789 | } |
| 790 | |
| 791 | if (ed->state == ED_NEW) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 792 | /* dummy td; end of td list for ed */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 793 | td = td_alloc(usb_dev); |
| 794 | ed->hwTailP = m32_swap((unsigned long)td); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 795 | ed->hwHeadP = ed->hwTailP; |
| 796 | ed->state = ED_UNLINK; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 797 | ed->type = usb_pipetype(pipe); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 798 | ohci_dev.ed_cnt++; |
| 799 | } |
| 800 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 801 | ed->hwINFO = m32_swap(usb_pipedevice(pipe) |
| 802 | | usb_pipeendpoint(pipe) << 7 |
| 803 | | (usb_pipeisoc(pipe)? 0x8000: 0) |
| 804 | | (usb_pipecontrol(pipe)? 0: \ |
| 805 | (usb_pipeout(pipe)? 0x800: 0x1000)) |
| 806 | | usb_pipeslow(pipe) << 13 |
| 807 | | usb_maxpacket(usb_dev, pipe) << 16); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 808 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 809 | if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) { |
| 810 | ed->int_period = interval; |
| 811 | ed->int_load = load; |
| 812 | } |
| 813 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 814 | return ed_ret; |
| 815 | } |
| 816 | |
| 817 | /*-------------------------------------------------------------------------* |
| 818 | * TD handling functions |
| 819 | *-------------------------------------------------------------------------*/ |
| 820 | |
| 821 | /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */ |
| 822 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 823 | static void td_fill(ohci_t *ohci, unsigned int info, |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 824 | void *data, int len, |
| 825 | struct usb_device *dev, int index, urb_priv_t *urb_priv) |
| 826 | { |
| 827 | volatile td_t *td, *td_pt; |
| 828 | #ifdef OHCI_FILL_TRACE |
| 829 | int i; |
| 830 | #endif |
| 831 | |
| 832 | if (index > urb_priv->length) { |
| 833 | err("index > length"); |
| 834 | return; |
| 835 | } |
| 836 | /* use this td as the next dummy */ |
| 837 | td_pt = urb_priv->td [index]; |
| 838 | td_pt->hwNextTD = 0; |
| 839 | |
| 840 | /* fill the old dummy TD */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 841 | td = urb_priv->td [index] = |
| 842 | (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 843 | |
| 844 | td->ed = urb_priv->ed; |
| 845 | td->next_dl_td = NULL; |
| 846 | td->index = index; |
| 847 | td->data = (__u32)data; |
| 848 | #ifdef OHCI_FILL_TRACE |
Remy Bohmer | 4886720 | 2008-10-10 10:23:21 +0200 | [diff] [blame] | 849 | if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 850 | for (i = 0; i < len; i++) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 851 | printf("td->data[%d] %#2x ", i, ((unsigned char *)td->data)[i]); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 852 | printf("\n"); |
| 853 | } |
| 854 | #endif |
| 855 | if (!len) |
| 856 | data = 0; |
| 857 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 858 | td->hwINFO = m32_swap(info); |
| 859 | td->hwCBP = m32_swap((unsigned long)data); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 860 | if (data) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 861 | td->hwBE = m32_swap((unsigned long)(data + len - 1)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 862 | else |
| 863 | td->hwBE = 0; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 864 | |
| 865 | td->hwNextTD = m32_swap((unsigned long)td_pt); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 866 | |
| 867 | /* append to queue */ |
| 868 | td->ed->hwTailP = td->hwNextTD; |
| 869 | } |
| 870 | |
| 871 | /*-------------------------------------------------------------------------*/ |
| 872 | |
| 873 | /* prepare all TDs of a transfer */ |
| 874 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 875 | static void td_submit_job(struct usb_device *dev, unsigned long pipe, |
| 876 | void *buffer, int transfer_len, |
| 877 | struct devrequest *setup, urb_priv_t *urb, |
| 878 | int interval) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 879 | { |
| 880 | ohci_t *ohci = &gohci; |
| 881 | int data_len = transfer_len; |
| 882 | void *data; |
| 883 | int cnt = 0; |
| 884 | __u32 info = 0; |
| 885 | unsigned int toggle = 0; |
| 886 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 887 | /* OHCI handles the DATA-toggles itself, we just use the USB-toggle |
| 888 | * bits for reseting */ |
| 889 | if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 890 | toggle = TD_T_TOGGLE; |
| 891 | } else { |
| 892 | toggle = TD_T_DATA0; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 893 | usb_settoggle(dev, usb_pipeendpoint(pipe), |
| 894 | usb_pipeout(pipe), 1); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 895 | } |
| 896 | urb->td_cnt = 0; |
| 897 | if (data_len) |
| 898 | data = buffer; |
| 899 | else |
| 900 | data = 0; |
| 901 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 902 | switch (usb_pipetype(pipe)) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 903 | case PIPE_BULK: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 904 | info = usb_pipeout(pipe)? |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 905 | TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 906 | while (data_len > 4096) { |
| 907 | td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), |
| 908 | data, 4096, dev, cnt, urb); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 909 | data += 4096; data_len -= 4096; cnt++; |
| 910 | } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 911 | info = usb_pipeout(pipe)? |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 912 | TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 913 | td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), data, |
| 914 | data_len, dev, cnt, urb); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 915 | cnt++; |
| 916 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 917 | if (!ohci->sleeping) { |
| 918 | /* start bulk list */ |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 919 | ohci_writel(OHCI_BLF, &ohci->regs->cmdstatus); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 920 | } |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 921 | break; |
| 922 | |
| 923 | case PIPE_CONTROL: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 924 | /* Setup phase */ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 925 | info = TD_CC | TD_DP_SETUP | TD_T_DATA0; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 926 | td_fill(ohci, info, setup, 8, dev, cnt++, urb); |
| 927 | |
| 928 | /* Optional Data phase */ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 929 | if (data_len > 0) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 930 | info = usb_pipeout(pipe)? |
| 931 | TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : |
| 932 | TD_CC | TD_R | TD_DP_IN | TD_T_DATA1; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 933 | /* NOTE: mishandles transfers >8K, some >4K */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 934 | td_fill(ohci, info, data, data_len, dev, cnt++, urb); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 935 | } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 936 | |
| 937 | /* Status phase */ |
| 938 | info = usb_pipeout(pipe)? |
| 939 | TD_CC | TD_DP_IN | TD_T_DATA1: |
| 940 | TD_CC | TD_DP_OUT | TD_T_DATA1; |
| 941 | td_fill(ohci, info, data, 0, dev, cnt++, urb); |
| 942 | |
| 943 | if (!ohci->sleeping) { |
| 944 | /* start Control list */ |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 945 | ohci_writel(OHCI_CLF, &ohci->regs->cmdstatus); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 946 | } |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 947 | break; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 948 | |
| 949 | case PIPE_INTERRUPT: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 950 | info = usb_pipeout(urb->pipe)? |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 951 | TD_CC | TD_DP_OUT | toggle: |
| 952 | TD_CC | TD_R | TD_DP_IN | toggle; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 953 | td_fill(ohci, info, data, data_len, dev, cnt++, urb); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 954 | break; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 955 | } |
| 956 | if (urb->length != cnt) |
| 957 | dbg("TD LENGTH %d != CNT %d", urb->length, cnt); |
| 958 | } |
| 959 | |
| 960 | /*-------------------------------------------------------------------------* |
| 961 | * Done List handling functions |
| 962 | *-------------------------------------------------------------------------*/ |
| 963 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 964 | /* calculate the transfer length and update the urb */ |
| 965 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 966 | static void dl_transfer_length(td_t *td) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 967 | { |
| 968 | __u32 tdINFO, tdBE, tdCBP; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 969 | urb_priv_t *lurb_priv = td->ed->purb; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 970 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 971 | tdINFO = m32_swap(td->hwINFO); |
| 972 | tdBE = m32_swap(td->hwBE); |
| 973 | tdCBP = m32_swap(td->hwCBP); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 974 | |
Remy Bohmer | 4886720 | 2008-10-10 10:23:21 +0200 | [diff] [blame] | 975 | if (!(usb_pipecontrol(lurb_priv->pipe) && |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 976 | ((td->index == 0) || (td->index == lurb_priv->length - 1)))) { |
| 977 | if (tdBE != 0) { |
| 978 | if (td->hwCBP == 0) |
| 979 | lurb_priv->actual_length += tdBE - td->data + 1; |
| 980 | else |
| 981 | lurb_priv->actual_length += tdCBP - td->data; |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | /*-------------------------------------------------------------------------*/ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 987 | static void check_status(td_t *td_list) |
| 988 | { |
| 989 | urb_priv_t *lurb_priv = td_list->ed->purb; |
| 990 | int urb_len = lurb_priv->length; |
| 991 | __u32 *phwHeadP = &td_list->ed->hwHeadP; |
| 992 | int cc; |
| 993 | |
| 994 | cc = TD_CC_GET(m32_swap(td_list->hwINFO)); |
| 995 | if (cc) { |
| 996 | err(" USB-error: %s (%x)", cc_to_string[cc], cc); |
| 997 | |
| 998 | if (*phwHeadP & m32_swap(0x1)) { |
| 999 | if (lurb_priv && |
| 1000 | ((td_list->index + 1) < urb_len)) { |
| 1001 | *phwHeadP = |
| 1002 | (lurb_priv->td[urb_len - 1]->hwNextTD &\ |
| 1003 | m32_swap(0xfffffff0)) | |
| 1004 | (*phwHeadP & m32_swap(0x2)); |
| 1005 | |
| 1006 | lurb_priv->td_cnt += urb_len - |
| 1007 | td_list->index - 1; |
| 1008 | } else |
| 1009 | *phwHeadP &= m32_swap(0xfffffff2); |
| 1010 | } |
| 1011 | #ifdef CONFIG_MPC5200 |
| 1012 | td_list->hwNextTD = 0; |
| 1013 | #endif |
| 1014 | } |
| 1015 | } |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1016 | |
| 1017 | /* replies to the request have to be on a FIFO basis so |
| 1018 | * we reverse the reversed done-list */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1019 | static td_t *dl_reverse_done_list(ohci_t *ohci) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1020 | { |
| 1021 | __u32 td_list_hc; |
| 1022 | td_t *td_rev = NULL; |
| 1023 | td_t *td_list = NULL; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1024 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1025 | td_list_hc = m32_swap(ohci->hcca->done_head) & 0xfffffff0; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1026 | ohci->hcca->done_head = 0; |
| 1027 | |
| 1028 | while (td_list_hc) { |
| 1029 | td_list = (td_t *)td_list_hc; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1030 | check_status(td_list); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1031 | td_list->next_dl_td = td_rev; |
| 1032 | td_rev = td_list; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1033 | td_list_hc = m32_swap(td_list->hwNextTD) & 0xfffffff0; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1034 | } |
| 1035 | return td_list; |
| 1036 | } |
| 1037 | |
| 1038 | /*-------------------------------------------------------------------------*/ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1039 | /*-------------------------------------------------------------------------*/ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1040 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1041 | static void finish_urb(ohci_t *ohci, urb_priv_t *urb, int status) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1042 | { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1043 | if ((status & (ED_OPER | ED_UNLINK)) && (urb->state != URB_DEL)) |
| 1044 | urb->finished = sohci_return_job(ohci, urb); |
| 1045 | else |
| 1046 | dbg("finish_urb: strange.., ED state %x, \n", status); |
| 1047 | } |
| 1048 | |
| 1049 | /* |
| 1050 | * Used to take back a TD from the host controller. This would normally be |
| 1051 | * called from within dl_done_list, however it may be called directly if the |
| 1052 | * HC no longer sees the TD and it has not appeared on the donelist (after |
| 1053 | * two frames). This bug has been observed on ZF Micro systems. |
| 1054 | */ |
| 1055 | static int takeback_td(ohci_t *ohci, td_t *td_list) |
| 1056 | { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1057 | ed_t *ed; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1058 | int cc; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1059 | int stat = 0; |
| 1060 | /* urb_t *urb; */ |
| 1061 | urb_priv_t *lurb_priv; |
| 1062 | __u32 tdINFO, edHeadP, edTailP; |
| 1063 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1064 | tdINFO = m32_swap(td_list->hwINFO); |
| 1065 | |
| 1066 | ed = td_list->ed; |
| 1067 | lurb_priv = ed->purb; |
| 1068 | |
| 1069 | dl_transfer_length(td_list); |
| 1070 | |
| 1071 | lurb_priv->td_cnt++; |
| 1072 | |
| 1073 | /* error code of transfer */ |
| 1074 | cc = TD_CC_GET(tdINFO); |
| 1075 | if (cc) { |
| 1076 | err("USB-error: %s (%x)", cc_to_string[cc], cc); |
| 1077 | stat = cc_to_error[cc]; |
| 1078 | } |
| 1079 | |
| 1080 | /* see if this done list makes for all TD's of current URB, |
| 1081 | * and mark the URB finished if so */ |
| 1082 | if (lurb_priv->td_cnt == lurb_priv->length) |
| 1083 | finish_urb(ohci, lurb_priv, ed->state); |
| 1084 | |
| 1085 | dbg("dl_done_list: processing TD %x, len %x\n", |
| 1086 | lurb_priv->td_cnt, lurb_priv->length); |
| 1087 | |
Remy Bohmer | 4886720 | 2008-10-10 10:23:21 +0200 | [diff] [blame] | 1088 | if (ed->state != ED_NEW && (!usb_pipeint(lurb_priv->pipe))) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1089 | edHeadP = m32_swap(ed->hwHeadP) & 0xfffffff0; |
| 1090 | edTailP = m32_swap(ed->hwTailP); |
| 1091 | |
| 1092 | /* unlink eds if they are not busy */ |
| 1093 | if ((edHeadP == edTailP) && (ed->state == ED_OPER)) |
| 1094 | ep_unlink(ohci, ed); |
| 1095 | } |
| 1096 | return stat; |
| 1097 | } |
| 1098 | |
| 1099 | static int dl_done_list(ohci_t *ohci) |
| 1100 | { |
| 1101 | int stat = 0; |
| 1102 | td_t *td_list = dl_reverse_done_list(ohci); |
| 1103 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1104 | while (td_list) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1105 | td_t *td_next = td_list->next_dl_td; |
| 1106 | stat = takeback_td(ohci, td_list); |
| 1107 | td_list = td_next; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1108 | } |
| 1109 | return stat; |
| 1110 | } |
| 1111 | |
| 1112 | /*-------------------------------------------------------------------------* |
| 1113 | * Virtual Root Hub |
| 1114 | *-------------------------------------------------------------------------*/ |
| 1115 | |
| 1116 | /* Device descriptor */ |
| 1117 | static __u8 root_hub_dev_des[] = |
| 1118 | { |
| 1119 | 0x12, /* __u8 bLength; */ |
| 1120 | 0x01, /* __u8 bDescriptorType; Device */ |
| 1121 | 0x10, /* __u16 bcdUSB; v1.1 */ |
| 1122 | 0x01, |
| 1123 | 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ |
| 1124 | 0x00, /* __u8 bDeviceSubClass; */ |
| 1125 | 0x00, /* __u8 bDeviceProtocol; */ |
| 1126 | 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */ |
| 1127 | 0x00, /* __u16 idVendor; */ |
| 1128 | 0x00, |
| 1129 | 0x00, /* __u16 idProduct; */ |
| 1130 | 0x00, |
| 1131 | 0x00, /* __u16 bcdDevice; */ |
| 1132 | 0x00, |
| 1133 | 0x00, /* __u8 iManufacturer; */ |
| 1134 | 0x01, /* __u8 iProduct; */ |
| 1135 | 0x00, /* __u8 iSerialNumber; */ |
| 1136 | 0x01 /* __u8 bNumConfigurations; */ |
| 1137 | }; |
| 1138 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1139 | /* Configuration descriptor */ |
| 1140 | static __u8 root_hub_config_des[] = |
| 1141 | { |
| 1142 | 0x09, /* __u8 bLength; */ |
| 1143 | 0x02, /* __u8 bDescriptorType; Configuration */ |
| 1144 | 0x19, /* __u16 wTotalLength; */ |
| 1145 | 0x00, |
| 1146 | 0x01, /* __u8 bNumInterfaces; */ |
| 1147 | 0x01, /* __u8 bConfigurationValue; */ |
| 1148 | 0x00, /* __u8 iConfiguration; */ |
| 1149 | 0x40, /* __u8 bmAttributes; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1150 | Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1151 | 0x00, /* __u8 MaxPower; */ |
| 1152 | |
| 1153 | /* interface */ |
| 1154 | 0x09, /* __u8 if_bLength; */ |
| 1155 | 0x04, /* __u8 if_bDescriptorType; Interface */ |
| 1156 | 0x00, /* __u8 if_bInterfaceNumber; */ |
| 1157 | 0x00, /* __u8 if_bAlternateSetting; */ |
| 1158 | 0x01, /* __u8 if_bNumEndpoints; */ |
| 1159 | 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */ |
| 1160 | 0x00, /* __u8 if_bInterfaceSubClass; */ |
| 1161 | 0x00, /* __u8 if_bInterfaceProtocol; */ |
| 1162 | 0x00, /* __u8 if_iInterface; */ |
| 1163 | |
| 1164 | /* endpoint */ |
| 1165 | 0x07, /* __u8 ep_bLength; */ |
| 1166 | 0x05, /* __u8 ep_bDescriptorType; Endpoint */ |
| 1167 | 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ |
| 1168 | 0x03, /* __u8 ep_bmAttributes; Interrupt */ |
| 1169 | 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */ |
| 1170 | 0x00, |
| 1171 | 0xff /* __u8 ep_bInterval; 255 ms */ |
| 1172 | }; |
| 1173 | |
| 1174 | static unsigned char root_hub_str_index0[] = |
| 1175 | { |
| 1176 | 0x04, /* __u8 bLength; */ |
| 1177 | 0x03, /* __u8 bDescriptorType; String-descriptor */ |
| 1178 | 0x09, /* __u8 lang ID */ |
| 1179 | 0x04, /* __u8 lang ID */ |
| 1180 | }; |
| 1181 | |
| 1182 | static unsigned char root_hub_str_index1[] = |
| 1183 | { |
| 1184 | 28, /* __u8 bLength; */ |
| 1185 | 0x03, /* __u8 bDescriptorType; String-descriptor */ |
| 1186 | 'O', /* __u8 Unicode */ |
| 1187 | 0, /* __u8 Unicode */ |
| 1188 | 'H', /* __u8 Unicode */ |
| 1189 | 0, /* __u8 Unicode */ |
| 1190 | 'C', /* __u8 Unicode */ |
| 1191 | 0, /* __u8 Unicode */ |
| 1192 | 'I', /* __u8 Unicode */ |
| 1193 | 0, /* __u8 Unicode */ |
| 1194 | ' ', /* __u8 Unicode */ |
| 1195 | 0, /* __u8 Unicode */ |
| 1196 | 'R', /* __u8 Unicode */ |
| 1197 | 0, /* __u8 Unicode */ |
| 1198 | 'o', /* __u8 Unicode */ |
| 1199 | 0, /* __u8 Unicode */ |
| 1200 | 'o', /* __u8 Unicode */ |
| 1201 | 0, /* __u8 Unicode */ |
| 1202 | 't', /* __u8 Unicode */ |
| 1203 | 0, /* __u8 Unicode */ |
| 1204 | ' ', /* __u8 Unicode */ |
| 1205 | 0, /* __u8 Unicode */ |
| 1206 | 'H', /* __u8 Unicode */ |
| 1207 | 0, /* __u8 Unicode */ |
| 1208 | 'u', /* __u8 Unicode */ |
| 1209 | 0, /* __u8 Unicode */ |
| 1210 | 'b', /* __u8 Unicode */ |
| 1211 | 0, /* __u8 Unicode */ |
| 1212 | }; |
| 1213 | |
| 1214 | /* Hub class-specific descriptor is constructed dynamically */ |
| 1215 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1216 | /*-------------------------------------------------------------------------*/ |
| 1217 | |
| 1218 | #define OK(x) len = (x); break |
| 1219 | #ifdef DEBUG |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1220 | #define WR_RH_STAT(x) {info("WR:status %#8x", (x)); ohci_writel((x), \ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1221 | &gohci.regs->roothub.status); } |
| 1222 | #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, \ |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1223 | (x)); ohci_writel((x), &gohci.regs->roothub.portstatus[wIndex-1]); } |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1224 | #else |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1225 | #define WR_RH_STAT(x) ohci_writel((x), &gohci.regs->roothub.status) |
| 1226 | #define WR_RH_PORTSTAT(x) ohci_writel((x), \ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1227 | &gohci.regs->roothub.portstatus[wIndex-1]) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1228 | #endif |
| 1229 | #define RD_RH_STAT roothub_status(&gohci) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1230 | #define RD_RH_PORTSTAT roothub_portstatus(&gohci, wIndex-1) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1231 | |
| 1232 | /* request to virtual root hub */ |
| 1233 | |
| 1234 | int rh_check_port_status(ohci_t *controller) |
| 1235 | { |
| 1236 | __u32 temp, ndp, i; |
| 1237 | int res; |
| 1238 | |
| 1239 | res = -1; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1240 | temp = roothub_a(controller); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1241 | ndp = (temp & RH_A_NDP); |
| 1242 | #ifdef CONFIG_AT91C_PQFP_UHPBUG |
| 1243 | ndp = (ndp == 2) ? 1:0; |
| 1244 | #endif |
| 1245 | for (i = 0; i < ndp; i++) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1246 | temp = roothub_portstatus(controller, i); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1247 | /* check for a device disconnect */ |
| 1248 | if (((temp & (RH_PS_PESC | RH_PS_CSC)) == |
| 1249 | (RH_PS_PESC | RH_PS_CSC)) && |
| 1250 | ((temp & RH_PS_CCS) == 0)) { |
| 1251 | res = i; |
| 1252 | break; |
| 1253 | } |
| 1254 | } |
| 1255 | return res; |
| 1256 | } |
| 1257 | |
| 1258 | static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe, |
| 1259 | void *buffer, int transfer_len, struct devrequest *cmd) |
| 1260 | { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1261 | void *data = buffer; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1262 | int leni = transfer_len; |
| 1263 | int len = 0; |
| 1264 | int stat = 0; |
| 1265 | __u32 datab[4]; |
| 1266 | __u8 *data_buf = (__u8 *)datab; |
| 1267 | __u16 bmRType_bReq; |
| 1268 | __u16 wValue; |
| 1269 | __u16 wIndex; |
| 1270 | __u16 wLength; |
| 1271 | |
| 1272 | #ifdef DEBUG |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1273 | pkt_print(NULL, dev, pipe, buffer, transfer_len, |
| 1274 | cmd, "SUB(rh)", usb_pipein(pipe)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1275 | #else |
| 1276 | wait_ms(1); |
| 1277 | #endif |
Remy Bohmer | 4886720 | 2008-10-10 10:23:21 +0200 | [diff] [blame] | 1278 | if (usb_pipeint(pipe)) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1279 | info("Root-Hub submit IRQ: NOT implemented"); |
| 1280 | return 0; |
| 1281 | } |
| 1282 | |
| 1283 | bmRType_bReq = cmd->requesttype | (cmd->request << 8); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1284 | wValue = le16_to_cpu(cmd->value); |
| 1285 | wIndex = le16_to_cpu(cmd->index); |
| 1286 | wLength = le16_to_cpu(cmd->length); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1287 | |
| 1288 | info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x", |
| 1289 | dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength); |
| 1290 | |
| 1291 | switch (bmRType_bReq) { |
| 1292 | /* Request Destination: |
| 1293 | without flags: Device, |
| 1294 | RH_INTERFACE: interface, |
| 1295 | RH_ENDPOINT: endpoint, |
| 1296 | RH_CLASS means HUB here, |
| 1297 | RH_OTHER | RH_CLASS almost ever means HUB_PORT here |
| 1298 | */ |
| 1299 | |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 1300 | case RH_GET_STATUS: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1301 | *(__u16 *) data_buf = cpu_to_le16(1); |
| 1302 | OK(2); |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 1303 | case RH_GET_STATUS | RH_INTERFACE: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1304 | *(__u16 *) data_buf = cpu_to_le16(0); |
| 1305 | OK(2); |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 1306 | case RH_GET_STATUS | RH_ENDPOINT: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1307 | *(__u16 *) data_buf = cpu_to_le16(0); |
| 1308 | OK(2); |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 1309 | case RH_GET_STATUS | RH_CLASS: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1310 | *(__u32 *) data_buf = cpu_to_le32( |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 1311 | RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE)); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1312 | OK(4); |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 1313 | case RH_GET_STATUS | RH_OTHER | RH_CLASS: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1314 | *(__u32 *) data_buf = cpu_to_le32(RD_RH_PORTSTAT); |
| 1315 | OK(4); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1316 | |
| 1317 | case RH_CLEAR_FEATURE | RH_ENDPOINT: |
| 1318 | switch (wValue) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1319 | case (RH_ENDPOINT_STALL): |
| 1320 | OK(0); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1321 | } |
| 1322 | break; |
| 1323 | |
| 1324 | case RH_CLEAR_FEATURE | RH_CLASS: |
| 1325 | switch (wValue) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1326 | case RH_C_HUB_LOCAL_POWER: |
| 1327 | OK(0); |
| 1328 | case (RH_C_HUB_OVER_CURRENT): |
| 1329 | WR_RH_STAT(RH_HS_OCIC); |
| 1330 | OK(0); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1331 | } |
| 1332 | break; |
| 1333 | |
| 1334 | case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS: |
| 1335 | switch (wValue) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1336 | case (RH_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_CCS); OK(0); |
| 1337 | case (RH_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_POCI); OK(0); |
| 1338 | case (RH_PORT_POWER): WR_RH_PORTSTAT(RH_PS_LSDA); OK(0); |
| 1339 | case (RH_C_PORT_CONNECTION): WR_RH_PORTSTAT(RH_PS_CSC); OK(0); |
| 1340 | case (RH_C_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_PESC); OK(0); |
| 1341 | case (RH_C_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_PSSC); OK(0); |
| 1342 | case (RH_C_PORT_OVER_CURRENT):WR_RH_PORTSTAT(RH_PS_OCIC); OK(0); |
| 1343 | case (RH_C_PORT_RESET): WR_RH_PORTSTAT(RH_PS_PRSC); OK(0); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1344 | } |
| 1345 | break; |
| 1346 | |
| 1347 | case RH_SET_FEATURE | RH_OTHER | RH_CLASS: |
| 1348 | switch (wValue) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1349 | case (RH_PORT_SUSPEND): |
| 1350 | WR_RH_PORTSTAT(RH_PS_PSS); OK(0); |
| 1351 | case (RH_PORT_RESET): /* BUG IN HUP CODE *********/ |
| 1352 | if (RD_RH_PORTSTAT & RH_PS_CCS) |
| 1353 | WR_RH_PORTSTAT(RH_PS_PRS); |
| 1354 | OK(0); |
| 1355 | case (RH_PORT_POWER): |
| 1356 | WR_RH_PORTSTAT(RH_PS_PPS); |
| 1357 | wait_ms(100); |
| 1358 | OK(0); |
| 1359 | case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/ |
| 1360 | if (RD_RH_PORTSTAT & RH_PS_CCS) |
| 1361 | WR_RH_PORTSTAT(RH_PS_PES); |
| 1362 | OK(0); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1363 | } |
| 1364 | break; |
| 1365 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1366 | case RH_SET_ADDRESS: |
| 1367 | gohci.rh.devnum = wValue; |
| 1368 | OK(0); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1369 | |
| 1370 | case RH_GET_DESCRIPTOR: |
| 1371 | switch ((wValue & 0xff00) >> 8) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1372 | case (0x01): /* device descriptor */ |
| 1373 | len = min_t(unsigned int, |
| 1374 | leni, |
| 1375 | min_t(unsigned int, |
| 1376 | sizeof(root_hub_dev_des), |
| 1377 | wLength)); |
| 1378 | data_buf = root_hub_dev_des; OK(len); |
| 1379 | case (0x02): /* configuration descriptor */ |
| 1380 | len = min_t(unsigned int, |
| 1381 | leni, |
| 1382 | min_t(unsigned int, |
| 1383 | sizeof(root_hub_config_des), |
| 1384 | wLength)); |
| 1385 | data_buf = root_hub_config_des; OK(len); |
| 1386 | case (0x03): /* string descriptors */ |
| 1387 | if (wValue == 0x0300) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1388 | len = min_t(unsigned int, |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1389 | leni, |
| 1390 | min_t(unsigned int, |
| 1391 | sizeof(root_hub_str_index0), |
| 1392 | wLength)); |
| 1393 | data_buf = root_hub_str_index0; |
| 1394 | OK(len); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1395 | } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1396 | if (wValue == 0x0301) { |
| 1397 | len = min_t(unsigned int, |
| 1398 | leni, |
| 1399 | min_t(unsigned int, |
| 1400 | sizeof(root_hub_str_index1), |
| 1401 | wLength)); |
| 1402 | data_buf = root_hub_str_index1; |
| 1403 | OK(len); |
| 1404 | } |
| 1405 | default: |
| 1406 | stat = USB_ST_STALLED; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1407 | } |
| 1408 | break; |
| 1409 | |
| 1410 | case RH_GET_DESCRIPTOR | RH_CLASS: |
| 1411 | { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1412 | __u32 temp = roothub_a(&gohci); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1413 | |
| 1414 | data_buf [0] = 9; /* min length; */ |
| 1415 | data_buf [1] = 0x29; |
| 1416 | data_buf [2] = temp & RH_A_NDP; |
| 1417 | #ifdef CONFIG_AT91C_PQFP_UHPBUG |
| 1418 | data_buf [2] = (data_buf [2] == 2) ? 1:0; |
| 1419 | #endif |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1420 | data_buf [3] = 0; |
| 1421 | if (temp & RH_A_PSM) /* per-port power switching? */ |
| 1422 | data_buf [3] |= 0x1; |
| 1423 | if (temp & RH_A_NOCP) /* no overcurrent reporting? */ |
| 1424 | data_buf [3] |= 0x10; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1425 | else if (temp & RH_A_OCPM)/* per-port overcurrent reporting? */ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1426 | data_buf [3] |= 0x8; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1427 | |
| 1428 | /* corresponds to data_buf[4-7] */ |
| 1429 | datab [1] = 0; |
| 1430 | data_buf [5] = (temp & RH_A_POTPGT) >> 24; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1431 | temp = roothub_b(&gohci); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1432 | data_buf [7] = temp & RH_B_DR; |
| 1433 | if (data_buf [2] < 7) { |
| 1434 | data_buf [8] = 0xff; |
| 1435 | } else { |
| 1436 | data_buf [0] += 2; |
| 1437 | data_buf [8] = (temp & RH_B_DR) >> 8; |
| 1438 | data_buf [10] = data_buf [9] = 0xff; |
| 1439 | } |
| 1440 | |
| 1441 | len = min_t(unsigned int, leni, |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1442 | min_t(unsigned int, data_buf [0], wLength)); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1443 | OK(len); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1444 | } |
| 1445 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1446 | case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK(1); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1447 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1448 | case RH_SET_CONFIGURATION: WR_RH_STAT(0x10000); OK(0); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1449 | |
| 1450 | default: |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1451 | dbg("unsupported root hub command"); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1452 | stat = USB_ST_STALLED; |
| 1453 | } |
| 1454 | |
| 1455 | #ifdef DEBUG |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1456 | ohci_dump_roothub(&gohci, 1); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1457 | #else |
| 1458 | wait_ms(1); |
| 1459 | #endif |
| 1460 | |
| 1461 | len = min_t(int, len, leni); |
| 1462 | if (data != data_buf) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1463 | memcpy(data, data_buf, len); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1464 | dev->act_len = len; |
| 1465 | dev->status = stat; |
| 1466 | |
| 1467 | #ifdef DEBUG |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1468 | pkt_print(NULL, dev, pipe, buffer, |
| 1469 | transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1470 | #else |
| 1471 | wait_ms(1); |
| 1472 | #endif |
| 1473 | |
| 1474 | return stat; |
| 1475 | } |
| 1476 | |
| 1477 | /*-------------------------------------------------------------------------*/ |
| 1478 | |
| 1479 | /* common code for handling submit messages - used for all but root hub */ |
| 1480 | /* accesses. */ |
| 1481 | int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 1482 | int transfer_len, struct devrequest *setup, int interval) |
| 1483 | { |
| 1484 | int stat = 0; |
| 1485 | int maxsize = usb_maxpacket(dev, pipe); |
| 1486 | int timeout; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1487 | urb_priv_t *urb; |
| 1488 | |
| 1489 | urb = malloc(sizeof(urb_priv_t)); |
| 1490 | memset(urb, 0, sizeof(urb_priv_t)); |
| 1491 | |
| 1492 | urb->dev = dev; |
| 1493 | urb->pipe = pipe; |
| 1494 | urb->transfer_buffer = buffer; |
| 1495 | urb->transfer_buffer_length = transfer_len; |
| 1496 | urb->interval = interval; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1497 | |
| 1498 | /* device pulled? Shortcut the action. */ |
| 1499 | if (devgone == dev) { |
| 1500 | dev->status = USB_ST_CRC_ERR; |
| 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | #ifdef DEBUG |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1505 | urb->actual_length = 0; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1506 | pkt_print(urb, dev, pipe, buffer, transfer_len, |
| 1507 | setup, "SUB", usb_pipein(pipe)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1508 | #else |
| 1509 | wait_ms(1); |
| 1510 | #endif |
| 1511 | if (!maxsize) { |
| 1512 | err("submit_common_message: pipesize for pipe %lx is zero", |
| 1513 | pipe); |
| 1514 | return -1; |
| 1515 | } |
| 1516 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1517 | if (sohci_submit_job(urb, setup) < 0) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1518 | err("sohci_submit_job failed"); |
| 1519 | return -1; |
| 1520 | } |
| 1521 | |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 1522 | #if 0 |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1523 | wait_ms(10); |
| 1524 | /* ohci_dump_status(&gohci); */ |
Markus Klotzbuecher | ae3b770 | 2006-11-27 11:46:46 +0100 | [diff] [blame] | 1525 | #endif |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1526 | |
| 1527 | /* allow more time for a BULK device to react - some are slow */ |
| 1528 | #define BULK_TO 5000 /* timeout in milliseconds */ |
Remy Bohmer | 4886720 | 2008-10-10 10:23:21 +0200 | [diff] [blame] | 1529 | if (usb_pipebulk(pipe)) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1530 | timeout = BULK_TO; |
| 1531 | else |
Marek Vasut | f2443d1 | 2010-09-20 03:57:25 +0200 | [diff] [blame] | 1532 | timeout = 1000; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1533 | |
| 1534 | /* wait for it to complete */ |
| 1535 | for (;;) { |
| 1536 | /* check whether the controller is done */ |
| 1537 | stat = hc_interrupt(); |
| 1538 | if (stat < 0) { |
| 1539 | stat = USB_ST_CRC_ERR; |
| 1540 | break; |
| 1541 | } |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1542 | |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1543 | /* NOTE: since we are not interrupt driven in U-Boot and always |
| 1544 | * handle only one URB at a time, we cannot assume the |
| 1545 | * transaction finished on the first successful return from |
| 1546 | * hc_interrupt().. unless the flag for current URB is set, |
| 1547 | * meaning that all TD's to/from device got actually |
| 1548 | * transferred and processed. If the current URB is not |
| 1549 | * finished we need to re-iterate this loop so as |
| 1550 | * hc_interrupt() gets called again as there needs to be some |
| 1551 | * more TD's to process still */ |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1552 | if ((stat >= 0) && (stat != 0xff) && (urb->finished)) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1553 | /* 0xff is returned for an SF-interrupt */ |
| 1554 | break; |
| 1555 | } |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1556 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1557 | if (--timeout) { |
| 1558 | wait_ms(1); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1559 | if (!urb->finished) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1560 | dbg("*"); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1561 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1562 | } else { |
| 1563 | err("CTL:TIMEOUT "); |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1564 | dbg("submit_common_msg: TO status %x\n", stat); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1565 | urb->finished = 1; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1566 | stat = USB_ST_CRC_ERR; |
| 1567 | break; |
| 1568 | } |
| 1569 | } |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1570 | |
| 1571 | dev->status = stat; |
| 1572 | dev->act_len = transfer_len; |
| 1573 | |
| 1574 | #ifdef DEBUG |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1575 | pkt_print(urb, dev, pipe, buffer, transfer_len, |
| 1576 | setup, "RET(ctlr)", usb_pipein(pipe)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1577 | #else |
| 1578 | wait_ms(1); |
| 1579 | #endif |
| 1580 | |
| 1581 | /* free TDs in urb_priv */ |
Remy Bohmer | 4886720 | 2008-10-10 10:23:21 +0200 | [diff] [blame] | 1582 | if (!usb_pipeint(pipe)) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1583 | urb_free_priv(urb); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1584 | return 0; |
| 1585 | } |
| 1586 | |
| 1587 | /* submit routines called from usb.c */ |
| 1588 | int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 1589 | int transfer_len) |
| 1590 | { |
| 1591 | info("submit_bulk_msg"); |
| 1592 | return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0); |
| 1593 | } |
| 1594 | |
| 1595 | int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 1596 | int transfer_len, struct devrequest *setup) |
| 1597 | { |
| 1598 | int maxsize = usb_maxpacket(dev, pipe); |
| 1599 | |
| 1600 | info("submit_control_msg"); |
| 1601 | #ifdef DEBUG |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1602 | pkt_print(NULL, dev, pipe, buffer, transfer_len, |
| 1603 | setup, "SUB", usb_pipein(pipe)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1604 | #else |
| 1605 | wait_ms(1); |
| 1606 | #endif |
| 1607 | if (!maxsize) { |
| 1608 | err("submit_control_message: pipesize for pipe %lx is zero", |
| 1609 | pipe); |
| 1610 | return -1; |
| 1611 | } |
| 1612 | if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) { |
| 1613 | gohci.rh.dev = dev; |
| 1614 | /* root hub - redirect */ |
| 1615 | return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len, |
| 1616 | setup); |
| 1617 | } |
| 1618 | |
| 1619 | return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0); |
| 1620 | } |
| 1621 | |
| 1622 | int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 1623 | int transfer_len, int interval) |
| 1624 | { |
| 1625 | info("submit_int_msg"); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1626 | return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, |
| 1627 | interval); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | /*-------------------------------------------------------------------------* |
| 1631 | * HC functions |
| 1632 | *-------------------------------------------------------------------------*/ |
| 1633 | |
| 1634 | /* reset the HC and BUS */ |
| 1635 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1636 | static int hc_reset(ohci_t *ohci) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1637 | { |
Yuri Tikhonov | e90fb6a | 2008-09-04 11:19:05 +0200 | [diff] [blame] | 1638 | #ifdef CONFIG_PCI_EHCI_DEVNO |
| 1639 | pci_dev_t pdev; |
| 1640 | #endif |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1641 | int timeout = 30; |
| 1642 | int smm_timeout = 50; /* 0,5 sec */ |
| 1643 | |
| 1644 | dbg("%s\n", __FUNCTION__); |
| 1645 | |
Yuri Tikhonov | e90fb6a | 2008-09-04 11:19:05 +0200 | [diff] [blame] | 1646 | #ifdef CONFIG_PCI_EHCI_DEVNO |
| 1647 | /* |
| 1648 | * Some multi-function controllers (e.g. ISP1562) allow root hub |
| 1649 | * resetting via EHCI registers only. |
| 1650 | */ |
| 1651 | pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVNO); |
| 1652 | if (pdev != -1) { |
| 1653 | u32 base; |
| 1654 | int timeout = 1000; |
| 1655 | |
| 1656 | pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1657 | base += EHCI_USBCMD_OFF; |
| 1658 | ohci_writel(ohci_readl(base) | EHCI_USBCMD_HCRESET, base); |
Yuri Tikhonov | e90fb6a | 2008-09-04 11:19:05 +0200 | [diff] [blame] | 1659 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1660 | while (ohci_readl(base) & EHCI_USBCMD_HCRESET) { |
Yuri Tikhonov | e90fb6a | 2008-09-04 11:19:05 +0200 | [diff] [blame] | 1661 | if (timeout-- <= 0) { |
| 1662 | printf("USB RootHub reset timed out!"); |
| 1663 | break; |
| 1664 | } |
| 1665 | udelay(1); |
| 1666 | } |
| 1667 | } else |
| 1668 | printf("No EHCI func at %d index!\n", CONFIG_PCI_EHCI_DEVNO); |
| 1669 | #endif |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1670 | if (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) { |
| 1671 | /* SMM owns the HC, request ownership */ |
| 1672 | ohci_writel(OHCI_OCR, &ohci->regs->cmdstatus); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1673 | info("USB HC TakeOver from SMM"); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1674 | while (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1675 | wait_ms(10); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1676 | if (--smm_timeout == 0) { |
| 1677 | err("USB HC TakeOver failed!"); |
| 1678 | return -1; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | /* Disable HC interrupts */ |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1684 | ohci_writel(OHCI_INTR_MIE, &ohci->regs->intrdisable); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1685 | |
| 1686 | dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n", |
| 1687 | ohci->slot_name, |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1688 | ohci_readl(&ohci->regs->control)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1689 | |
| 1690 | /* Reset USB (needed by some controllers) */ |
Markus Klotzbuecher | 53e336e | 2006-11-27 11:43:09 +0100 | [diff] [blame] | 1691 | ohci->hc_control = 0; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1692 | ohci_writel(ohci->hc_control, &ohci->regs->control); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1693 | |
| 1694 | /* HC Reset requires max 10 us delay */ |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1695 | ohci_writel(OHCI_HCR, &ohci->regs->cmdstatus); |
| 1696 | while ((ohci_readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) { |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1697 | if (--timeout == 0) { |
| 1698 | err("USB HC reset timed out!"); |
| 1699 | return -1; |
| 1700 | } |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1701 | udelay(1); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1702 | } |
| 1703 | return 0; |
| 1704 | } |
| 1705 | |
| 1706 | /*-------------------------------------------------------------------------*/ |
| 1707 | |
| 1708 | /* Start an OHCI controller, set the BUS operational |
| 1709 | * enable interrupts |
| 1710 | * connect the virtual root hub */ |
| 1711 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1712 | static int hc_start(ohci_t *ohci) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1713 | { |
| 1714 | __u32 mask; |
| 1715 | unsigned int fminterval; |
| 1716 | |
| 1717 | ohci->disabled = 1; |
| 1718 | |
| 1719 | /* Tell the controller where the control and bulk lists are |
| 1720 | * The lists are empty now. */ |
| 1721 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1722 | ohci_writel(0, &ohci->regs->ed_controlhead); |
| 1723 | ohci_writel(0, &ohci->regs->ed_bulkhead); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1724 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1725 | ohci_writel((__u32)ohci->hcca, |
| 1726 | &ohci->regs->hcca); /* reset clears this */ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1727 | |
| 1728 | fminterval = 0x2edf; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1729 | ohci_writel((fminterval * 9) / 10, &ohci->regs->periodicstart); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1730 | fminterval |= ((((fminterval - 210) * 6) / 7) << 16); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1731 | ohci_writel(fminterval, &ohci->regs->fminterval); |
| 1732 | ohci_writel(0x628, &ohci->regs->lsthresh); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1733 | |
| 1734 | /* start controller operations */ |
| 1735 | ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER; |
| 1736 | ohci->disabled = 0; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1737 | ohci_writel(ohci->hc_control, &ohci->regs->control); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1738 | |
| 1739 | /* disable all interrupts */ |
| 1740 | mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD | |
| 1741 | OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC | |
| 1742 | OHCI_INTR_OC | OHCI_INTR_MIE); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1743 | ohci_writel(mask, &ohci->regs->intrdisable); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1744 | /* clear all interrupts */ |
| 1745 | mask &= ~OHCI_INTR_MIE; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1746 | ohci_writel(mask, &ohci->regs->intrstatus); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1747 | /* Choose the interrupts we care about now - but w/o MIE */ |
| 1748 | mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO; |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1749 | ohci_writel(mask, &ohci->regs->intrenable); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1750 | |
| 1751 | #ifdef OHCI_USE_NPS |
| 1752 | /* required for AMD-756 and some Mac platforms */ |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1753 | ohci_writel((roothub_a(ohci) | RH_A_NPS) & ~RH_A_PSM, |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1754 | &ohci->regs->roothub.a); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1755 | ohci_writel(RH_HS_LPSC, &ohci->regs->roothub.status); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1756 | #endif /* OHCI_USE_NPS */ |
| 1757 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1758 | #define mdelay(n) ({unsigned long msec = (n); while (msec--) udelay(1000); }) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1759 | /* POTPGT delay is bits 24-31, in 2 ms units. */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1760 | mdelay((roothub_a(ohci) >> 23) & 0x1fe); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1761 | |
| 1762 | /* connect the virtual root hub */ |
| 1763 | ohci->rh.devnum = 0; |
| 1764 | |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
| 1768 | /*-------------------------------------------------------------------------*/ |
| 1769 | |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1770 | /* Poll USB interrupt. */ |
| 1771 | void usb_event_poll(void) |
| 1772 | { |
| 1773 | hc_interrupt(); |
| 1774 | } |
| 1775 | |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1776 | /* an interrupt happens */ |
| 1777 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1778 | static int hc_interrupt(void) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1779 | { |
| 1780 | ohci_t *ohci = &gohci; |
| 1781 | struct ohci_regs *regs = ohci->regs; |
| 1782 | int ints; |
| 1783 | int stat = -1; |
| 1784 | |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1785 | if ((ohci->hcca->done_head != 0) && |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1786 | !(m32_swap(ohci->hcca->done_head) & 0x01)) { |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1787 | ints = OHCI_INTR_WDH; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1788 | } else { |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1789 | ints = ohci_readl(®s->intrstatus); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1790 | if (ints == ~(u32)0) { |
| 1791 | ohci->disabled++; |
| 1792 | err("%s device removed!", ohci->slot_name); |
| 1793 | return -1; |
| 1794 | } else { |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1795 | ints &= ohci_readl(®s->intrenable); |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1796 | if (ints == 0) { |
| 1797 | dbg("hc_interrupt: returning..\n"); |
| 1798 | return 0xff; |
| 1799 | } |
| 1800 | } |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1801 | } |
Markus Klotzbuecher | ae79f60 | 2007-03-26 11:21:05 +0200 | [diff] [blame] | 1802 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1803 | /* dbg("Interrupt: %x frame: %x", ints, |
| 1804 | le16_to_cpu(ohci->hcca->frame_no)); */ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1805 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1806 | if (ints & OHCI_INTR_RHSC) |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1807 | stat = 0xff; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1808 | |
| 1809 | if (ints & OHCI_INTR_UE) { |
| 1810 | ohci->disabled++; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1811 | err("OHCI Unrecoverable Error, controller usb-%s disabled", |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1812 | ohci->slot_name); |
| 1813 | /* e.g. due to PCI Master/Target Abort */ |
| 1814 | |
| 1815 | #ifdef DEBUG |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1816 | ohci_dump(ohci, 1); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1817 | #else |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1818 | wait_ms(1); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1819 | #endif |
| 1820 | /* FIXME: be optimistic, hope that bug won't repeat often. */ |
| 1821 | /* Make some non-interrupt context restart the controller. */ |
| 1822 | /* Count and limit the retries though; either hardware or */ |
| 1823 | /* software errors can go forever... */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1824 | hc_reset(ohci); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1825 | return -1; |
| 1826 | } |
| 1827 | |
| 1828 | if (ints & OHCI_INTR_WDH) { |
| 1829 | wait_ms(1); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1830 | ohci_writel(OHCI_INTR_WDH, ®s->intrdisable); |
| 1831 | (void)ohci_readl(®s->intrdisable); /* flush */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1832 | stat = dl_done_list(&gohci); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1833 | ohci_writel(OHCI_INTR_WDH, ®s->intrenable); |
| 1834 | (void)ohci_readl(®s->intrdisable); /* flush */ |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | if (ints & OHCI_INTR_SO) { |
| 1838 | dbg("USB Schedule overrun\n"); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1839 | ohci_writel(OHCI_INTR_SO, ®s->intrenable); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1840 | stat = -1; |
| 1841 | } |
| 1842 | |
| 1843 | /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */ |
| 1844 | if (ints & OHCI_INTR_SF) { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1845 | unsigned int frame = m16_swap(ohci->hcca->frame_no) & 1; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1846 | wait_ms(1); |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1847 | ohci_writel(OHCI_INTR_SF, ®s->intrdisable); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1848 | if (ohci->ed_rm_list[frame] != NULL) |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1849 | ohci_writel(OHCI_INTR_SF, ®s->intrenable); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1850 | stat = 0xff; |
| 1851 | } |
| 1852 | |
Becky Bruce | a5496a1 | 2010-06-30 13:05:44 -0500 | [diff] [blame] | 1853 | ohci_writel(ints, ®s->intrstatus); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1854 | return stat; |
| 1855 | } |
| 1856 | |
| 1857 | /*-------------------------------------------------------------------------*/ |
| 1858 | |
| 1859 | /*-------------------------------------------------------------------------*/ |
| 1860 | |
| 1861 | /* De-allocate all resources.. */ |
| 1862 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1863 | static void hc_release_ohci(ohci_t *ohci) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1864 | { |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1865 | dbg("USB HC release ohci usb-%s", ohci->slot_name); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1866 | |
| 1867 | if (!ohci->disabled) |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1868 | hc_reset(ohci); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | /*-------------------------------------------------------------------------*/ |
| 1872 | |
| 1873 | /* |
| 1874 | * low level initalisation routine, called from usb.c |
| 1875 | */ |
| 1876 | static char ohci_inited = 0; |
| 1877 | |
| 1878 | int usb_lowlevel_init(void) |
| 1879 | { |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1880 | #ifdef CONFIG_PCI_OHCI |
| 1881 | pci_dev_t pdev; |
| 1882 | #endif |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1883 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1884 | #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1885 | /* cpu dependant init */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1886 | if (usb_cpu_init()) |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1887 | return -1; |
| 1888 | #endif |
| 1889 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1890 | #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1891 | /* board dependant init */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1892 | if (usb_board_init()) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1893 | return -1; |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1894 | #endif |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1895 | memset(&gohci, 0, sizeof(ohci_t)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1896 | |
| 1897 | /* align the storage */ |
| 1898 | if ((__u32)&ghcca[0] & 0xff) { |
| 1899 | err("HCCA not aligned!!"); |
| 1900 | return -1; |
| 1901 | } |
| 1902 | phcca = &ghcca[0]; |
| 1903 | info("aligned ghcca %p", phcca); |
| 1904 | memset(&ohci_dev, 0, sizeof(struct ohci_device)); |
| 1905 | if ((__u32)&ohci_dev.ed[0] & 0x7) { |
| 1906 | err("EDs not aligned!!"); |
| 1907 | return -1; |
| 1908 | } |
| 1909 | memset(gtd, 0, sizeof(td_t) * (NUM_TD + 1)); |
| 1910 | if ((__u32)gtd & 0x7) { |
| 1911 | err("TDs not aligned!!"); |
| 1912 | return -1; |
| 1913 | } |
| 1914 | ptd = gtd; |
| 1915 | gohci.hcca = phcca; |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1916 | memset(phcca, 0, sizeof(struct ohci_hcca)); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1917 | |
| 1918 | gohci.disabled = 1; |
| 1919 | gohci.sleeping = 0; |
| 1920 | gohci.irq = -1; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1921 | #ifdef CONFIG_PCI_OHCI |
Sergei Poselenov | 477434c | 2008-05-22 01:15:53 +0200 | [diff] [blame] | 1922 | pdev = pci_find_devices(ohci_pci_ids, CONFIG_PCI_OHCI_DEVNO); |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1923 | |
| 1924 | if (pdev != -1) { |
| 1925 | u16 vid, did; |
| 1926 | u32 base; |
| 1927 | pci_read_config_word(pdev, PCI_VENDOR_ID, &vid); |
| 1928 | pci_read_config_word(pdev, PCI_DEVICE_ID, &did); |
| 1929 | printf("OHCI pci controller (%04x, %04x) found @(%d:%d:%d)\n", |
| 1930 | vid, did, (pdev >> 16) & 0xff, |
| 1931 | (pdev >> 11) & 0x1f, (pdev >> 8) & 0x7); |
| 1932 | pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base); |
| 1933 | printf("OHCI regs address 0x%08x\n", base); |
| 1934 | gohci.regs = (struct ohci_regs *)base; |
| 1935 | } else |
| 1936 | return -1; |
| 1937 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1938 | gohci.regs = (struct ohci_regs *)CONFIG_SYS_USB_OHCI_REGS_BASE; |
Zhang Wei | 4dae14c | 2007-06-06 10:08:14 +0200 | [diff] [blame] | 1939 | #endif |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1940 | |
| 1941 | gohci.flags = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1942 | gohci.slot_name = CONFIG_SYS_USB_OHCI_SLOT_NAME; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1943 | |
| 1944 | if (hc_reset (&gohci) < 0) { |
| 1945 | hc_release_ohci (&gohci); |
| 1946 | err ("can't reset usb-%s", gohci.slot_name); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1947 | #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1948 | /* board dependant cleanup */ |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1949 | usb_board_init_fail(); |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1950 | #endif |
| 1951 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1952 | #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1953 | /* cpu dependant cleanup */ |
Markus Klotzbuecher | ddf83a2 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 1954 | usb_cpu_init_fail(); |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1955 | #endif |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1956 | return -1; |
| 1957 | } |
| 1958 | |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1959 | if (hc_start(&gohci) < 0) { |
| 1960 | err("can't start usb-%s", gohci.slot_name); |
| 1961 | hc_release_ohci(&gohci); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1962 | /* Initialization failed */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1963 | #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1964 | /* board dependant cleanup */ |
| 1965 | usb_board_stop(); |
| 1966 | #endif |
| 1967 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1968 | #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1969 | /* cpu dependant cleanup */ |
| 1970 | usb_cpu_stop(); |
| 1971 | #endif |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1972 | return -1; |
| 1973 | } |
| 1974 | |
| 1975 | #ifdef DEBUG |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1976 | ohci_dump(&gohci, 1); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1977 | #else |
| 1978 | wait_ms(1); |
| 1979 | #endif |
| 1980 | ohci_inited = 1; |
| 1981 | return 0; |
| 1982 | } |
| 1983 | |
| 1984 | int usb_lowlevel_stop(void) |
| 1985 | { |
| 1986 | /* this gets called really early - before the controller has */ |
| 1987 | /* even been initialized! */ |
| 1988 | if (!ohci_inited) |
| 1989 | return 0; |
| 1990 | /* TODO release any interrupts, etc. */ |
| 1991 | /* call hc_release_ohci() here ? */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1992 | hc_reset(&gohci); |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1993 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1994 | #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1995 | /* board dependant cleanup */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 1996 | if (usb_board_stop()) |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 1997 | return -1; |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 1998 | #endif |
| 1999 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 2000 | #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 2001 | /* cpu dependant cleanup */ |
Remy Bohmer | 6f5794a | 2008-09-16 14:55:43 +0200 | [diff] [blame] | 2002 | if (usb_cpu_stop()) |
Markus Klotzbuecher | 24e3764 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 2003 | return -1; |
| 2004 | #endif |
Remy Bohmer | eba1f2f | 2008-08-20 11:22:02 +0200 | [diff] [blame] | 2005 | /* This driver is no longer initialised. It needs a new low-level |
| 2006 | * init (board/cpu) before it can be used again. */ |
| 2007 | ohci_inited = 0; |
Markus Klotzbuecher | 3e326ec | 2006-05-22 16:33:54 +0200 | [diff] [blame] | 2008 | return 0; |
| 2009 | } |