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