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