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