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