Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2007-2008, Juniper Networks, Inc. |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 3 | * Copyright (c) 2008, Excito Elektronik i Skåne AB |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 4 | * Copyright (c) 2008, Michael Trimarchi <trimarchimichael@yahoo.it> |
| 5 | * |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation version 2 of |
| 11 | * the License. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 23 | #include <common.h> |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 24 | #include <errno.h> |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 25 | #include <asm/byteorder.h> |
Lucas Stach | 93ad908 | 2012-09-06 08:00:13 +0200 | [diff] [blame] | 26 | #include <asm/unaligned.h> |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 27 | #include <usb.h> |
| 28 | #include <asm/io.h> |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 29 | #include <malloc.h> |
Stefan Roese | 67333f7 | 2010-11-26 15:43:28 +0100 | [diff] [blame] | 30 | #include <watchdog.h> |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 31 | #include <linux/compiler.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2731b9a | 2009-04-03 12:46:58 +0200 | [diff] [blame] | 32 | |
| 33 | #include "ehci.h" |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 34 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 35 | #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT |
| 36 | #define CONFIG_USB_MAX_CONTROLLER_COUNT 1 |
| 37 | #endif |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 38 | |
Julius Werner | 5077f96 | 2013-09-24 10:53:07 -0700 | [diff] [blame] | 39 | /* |
| 40 | * EHCI spec page 20 says that the HC may take up to 16 uFrames (= 4ms) to halt. |
| 41 | * Let's time out after 8 to have a little safety margin on top of that. |
| 42 | */ |
| 43 | #define HCHALT_TIMEOUT (8 * 1000) |
| 44 | |
Marek Vasut | b959655 | 2013-07-10 03:16:31 +0200 | [diff] [blame] | 45 | static struct ehci_ctrl ehcic[CONFIG_USB_MAX_CONTROLLER_COUNT]; |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 46 | |
| 47 | #define ALIGN_END_ADDR(type, ptr, size) \ |
| 48 | ((uint32_t)(ptr) + roundup((size) * sizeof(type), USB_DMA_MINALIGN)) |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 49 | |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 50 | static struct descriptor { |
| 51 | struct usb_hub_descriptor hub; |
| 52 | struct usb_device_descriptor device; |
| 53 | struct usb_linux_config_descriptor config; |
| 54 | struct usb_linux_interface_descriptor interface; |
| 55 | struct usb_endpoint_descriptor endpoint; |
| 56 | } __attribute__ ((packed)) descriptor = { |
| 57 | { |
| 58 | 0x8, /* bDescLength */ |
| 59 | 0x29, /* bDescriptorType: hub descriptor */ |
| 60 | 2, /* bNrPorts -- runtime modified */ |
| 61 | 0, /* wHubCharacteristics */ |
Vincent Palatin | 5f4b4f2 | 2011-12-05 14:52:22 -0800 | [diff] [blame] | 62 | 10, /* bPwrOn2PwrGood */ |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 63 | 0, /* bHubCntrCurrent */ |
| 64 | {}, /* Device removable */ |
| 65 | {} /* at most 7 ports! XXX */ |
| 66 | }, |
| 67 | { |
| 68 | 0x12, /* bLength */ |
| 69 | 1, /* bDescriptorType: UDESC_DEVICE */ |
Sergei Shtylyov | 6d313c8 | 2010-02-27 21:29:42 +0300 | [diff] [blame] | 70 | cpu_to_le16(0x0200), /* bcdUSB: v2.0 */ |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 71 | 9, /* bDeviceClass: UDCLASS_HUB */ |
| 72 | 0, /* bDeviceSubClass: UDSUBCLASS_HUB */ |
| 73 | 1, /* bDeviceProtocol: UDPROTO_HSHUBSTT */ |
| 74 | 64, /* bMaxPacketSize: 64 bytes */ |
| 75 | 0x0000, /* idVendor */ |
| 76 | 0x0000, /* idProduct */ |
Sergei Shtylyov | 6d313c8 | 2010-02-27 21:29:42 +0300 | [diff] [blame] | 77 | cpu_to_le16(0x0100), /* bcdDevice */ |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 78 | 1, /* iManufacturer */ |
| 79 | 2, /* iProduct */ |
| 80 | 0, /* iSerialNumber */ |
| 81 | 1 /* bNumConfigurations: 1 */ |
| 82 | }, |
| 83 | { |
| 84 | 0x9, |
| 85 | 2, /* bDescriptorType: UDESC_CONFIG */ |
| 86 | cpu_to_le16(0x19), |
| 87 | 1, /* bNumInterface */ |
| 88 | 1, /* bConfigurationValue */ |
| 89 | 0, /* iConfiguration */ |
| 90 | 0x40, /* bmAttributes: UC_SELF_POWER */ |
| 91 | 0 /* bMaxPower */ |
| 92 | }, |
| 93 | { |
| 94 | 0x9, /* bLength */ |
| 95 | 4, /* bDescriptorType: UDESC_INTERFACE */ |
| 96 | 0, /* bInterfaceNumber */ |
| 97 | 0, /* bAlternateSetting */ |
| 98 | 1, /* bNumEndpoints */ |
| 99 | 9, /* bInterfaceClass: UICLASS_HUB */ |
| 100 | 0, /* bInterfaceSubClass: UISUBCLASS_HUB */ |
| 101 | 0, /* bInterfaceProtocol: UIPROTO_HSHUBSTT */ |
| 102 | 0 /* iInterface */ |
| 103 | }, |
| 104 | { |
| 105 | 0x7, /* bLength */ |
| 106 | 5, /* bDescriptorType: UDESC_ENDPOINT */ |
| 107 | 0x81, /* bEndpointAddress: |
| 108 | * UE_DIR_IN | EHCI_INTR_ENDPT |
| 109 | */ |
| 110 | 3, /* bmAttributes: UE_INTERRUPT */ |
Tom Rix | 8f8bd56 | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 111 | 8, /* wMaxPacketSize */ |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 112 | 255 /* bInterval */ |
| 113 | }, |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 114 | }; |
| 115 | |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 116 | #if defined(CONFIG_EHCI_IS_TDI) |
| 117 | #define ehci_is_TDI() (1) |
| 118 | #else |
| 119 | #define ehci_is_TDI() (0) |
| 120 | #endif |
| 121 | |
Jim Lin | b068deb | 2013-03-27 00:52:32 +0000 | [diff] [blame] | 122 | int __ehci_get_port_speed(struct ehci_hcor *hcor, uint32_t reg) |
| 123 | { |
| 124 | return PORTSC_PSPD(reg); |
| 125 | } |
| 126 | |
| 127 | int ehci_get_port_speed(struct ehci_hcor *hcor, uint32_t reg) |
| 128 | __attribute__((weak, alias("__ehci_get_port_speed"))); |
| 129 | |
| 130 | void __ehci_set_usbmode(int index) |
| 131 | { |
| 132 | uint32_t tmp; |
| 133 | uint32_t *reg_ptr; |
| 134 | |
| 135 | reg_ptr = (uint32_t *)((u8 *)&ehcic[index].hcor->or_usbcmd + USBMODE); |
| 136 | tmp = ehci_readl(reg_ptr); |
| 137 | tmp |= USBMODE_CM_HC; |
| 138 | #if defined(CONFIG_EHCI_MMIO_BIG_ENDIAN) |
| 139 | tmp |= USBMODE_BE; |
| 140 | #endif |
| 141 | ehci_writel(reg_ptr, tmp); |
| 142 | } |
| 143 | |
| 144 | void ehci_set_usbmode(int index) |
| 145 | __attribute__((weak, alias("__ehci_set_usbmode"))); |
| 146 | |
Marek Vasut | 3874b6d | 2011-07-11 02:37:01 +0200 | [diff] [blame] | 147 | void __ehci_powerup_fixup(uint32_t *status_reg, uint32_t *reg) |
| 148 | { |
| 149 | mdelay(50); |
| 150 | } |
| 151 | |
| 152 | void ehci_powerup_fixup(uint32_t *status_reg, uint32_t *reg) |
| 153 | __attribute__((weak, alias("__ehci_powerup_fixup"))); |
| 154 | |
Michael Trimarchi | 1ed9f9a | 2008-12-31 10:33:22 +0100 | [diff] [blame] | 155 | static int handshake(uint32_t *ptr, uint32_t mask, uint32_t done, int usec) |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 156 | { |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 157 | uint32_t result; |
| 158 | do { |
| 159 | result = ehci_readl(ptr); |
Wolfgang Denk | 09c83a4 | 2010-10-22 14:23:00 +0200 | [diff] [blame] | 160 | udelay(5); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 161 | if (result == ~(uint32_t)0) |
| 162 | return -1; |
| 163 | result &= mask; |
| 164 | if (result == done) |
| 165 | return 0; |
Michael Trimarchi | 1ed9f9a | 2008-12-31 10:33:22 +0100 | [diff] [blame] | 166 | usec--; |
| 167 | } while (usec > 0); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 168 | return -1; |
| 169 | } |
| 170 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 171 | static int ehci_reset(int index) |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 172 | { |
| 173 | uint32_t cmd; |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 174 | int ret = 0; |
| 175 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 176 | cmd = ehci_readl(&ehcic[index].hcor->or_usbcmd); |
Stefan Roese | 273d720 | 2010-11-26 15:44:00 +0100 | [diff] [blame] | 177 | cmd = (cmd & ~CMD_RUN) | CMD_RESET; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 178 | ehci_writel(&ehcic[index].hcor->or_usbcmd, cmd); |
| 179 | ret = handshake((uint32_t *)&ehcic[index].hcor->or_usbcmd, |
| 180 | CMD_RESET, 0, 250 * 1000); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 181 | if (ret < 0) { |
| 182 | printf("EHCI fail to reset\n"); |
| 183 | goto out; |
| 184 | } |
| 185 | |
Jim Lin | b068deb | 2013-03-27 00:52:32 +0000 | [diff] [blame] | 186 | if (ehci_is_TDI()) |
| 187 | ehci_set_usbmode(index); |
Simon Glass | 9ab4ce2 | 2012-02-27 10:52:47 +0000 | [diff] [blame] | 188 | |
| 189 | #ifdef CONFIG_USB_EHCI_TXFIFO_THRESH |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 190 | cmd = ehci_readl(&ehcic[index].hcor->or_txfilltuning); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 191 | cmd &= ~TXFIFO_THRESH_MASK; |
Simon Glass | 9ab4ce2 | 2012-02-27 10:52:47 +0000 | [diff] [blame] | 192 | cmd |= TXFIFO_THRESH(CONFIG_USB_EHCI_TXFIFO_THRESH); |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 193 | ehci_writel(&ehcic[index].hcor->or_txfilltuning, cmd); |
Simon Glass | 9ab4ce2 | 2012-02-27 10:52:47 +0000 | [diff] [blame] | 194 | #endif |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 195 | out: |
| 196 | return ret; |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 197 | } |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 198 | |
Julius Werner | 5077f96 | 2013-09-24 10:53:07 -0700 | [diff] [blame] | 199 | static int ehci_shutdown(struct ehci_ctrl *ctrl) |
| 200 | { |
| 201 | int i, ret = 0; |
| 202 | uint32_t cmd, reg; |
| 203 | |
Marek Vasut | 1e1be6d | 2013-12-14 02:03:11 +0100 | [diff] [blame] | 204 | if (!ctrl || !ctrl->hcor) |
| 205 | return -EINVAL; |
| 206 | |
Julius Werner | 5077f96 | 2013-09-24 10:53:07 -0700 | [diff] [blame] | 207 | cmd = ehci_readl(&ctrl->hcor->or_usbcmd); |
| 208 | cmd &= ~(CMD_PSE | CMD_ASE); |
| 209 | ehci_writel(&ctrl->hcor->or_usbcmd, cmd); |
| 210 | ret = handshake(&ctrl->hcor->or_usbsts, STS_ASS | STS_PSS, 0, |
| 211 | 100 * 1000); |
| 212 | |
| 213 | if (!ret) { |
| 214 | for (i = 0; i < CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS; i++) { |
| 215 | reg = ehci_readl(&ctrl->hcor->or_portsc[i]); |
| 216 | reg |= EHCI_PS_SUSP; |
| 217 | ehci_writel(&ctrl->hcor->or_portsc[i], reg); |
| 218 | } |
| 219 | |
| 220 | cmd &= ~CMD_RUN; |
| 221 | ehci_writel(&ctrl->hcor->or_usbcmd, cmd); |
| 222 | ret = handshake(&ctrl->hcor->or_usbsts, STS_HALT, STS_HALT, |
| 223 | HCHALT_TIMEOUT); |
| 224 | } |
| 225 | |
| 226 | if (ret) |
| 227 | puts("EHCI failed to shut down host controller.\n"); |
| 228 | |
| 229 | return ret; |
| 230 | } |
| 231 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 232 | static int ehci_td_buffer(struct qTD *td, void *buf, size_t sz) |
| 233 | { |
Marek Vasut | b8adb12 | 2012-04-09 04:07:46 +0200 | [diff] [blame] | 234 | uint32_t delta, next; |
| 235 | uint32_t addr = (uint32_t)buf; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 236 | int idx; |
| 237 | |
Ilya Yanok | 189a695 | 2012-07-15 04:43:49 +0000 | [diff] [blame] | 238 | if (addr != ALIGN(addr, ARCH_DMA_MINALIGN)) |
Marek Vasut | b8adb12 | 2012-04-09 04:07:46 +0200 | [diff] [blame] | 239 | debug("EHCI-HCD: Misaligned buffer address (%p)\n", buf); |
| 240 | |
Ilya Yanok | 189a695 | 2012-07-15 04:43:49 +0000 | [diff] [blame] | 241 | flush_dcache_range(addr, ALIGN(addr + sz, ARCH_DMA_MINALIGN)); |
| 242 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 243 | idx = 0; |
Benoît Thébaudeau | cdeb916 | 2012-07-19 22:16:38 +0200 | [diff] [blame] | 244 | while (idx < QT_BUFFER_CNT) { |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 245 | td->qt_buffer[idx] = cpu_to_hc32(addr); |
Wolfgang Denk | 3ed1607 | 2010-10-19 16:13:15 +0200 | [diff] [blame] | 246 | td->qt_buffer_hi[idx] = 0; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 247 | next = (addr + EHCI_PAGE_SIZE) & ~(EHCI_PAGE_SIZE - 1); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 248 | delta = next - addr; |
| 249 | if (delta >= sz) |
| 250 | break; |
| 251 | sz -= delta; |
| 252 | addr = next; |
| 253 | idx++; |
| 254 | } |
| 255 | |
Benoît Thébaudeau | cdeb916 | 2012-07-19 22:16:38 +0200 | [diff] [blame] | 256 | if (idx == QT_BUFFER_CNT) { |
Ilya Yanok | 2af16f8 | 2012-07-15 04:43:52 +0000 | [diff] [blame] | 257 | printf("out of buffer pointers (%u bytes left)\n", sz); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 258 | return -1; |
| 259 | } |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
Ilya Yanok | c60795f | 2012-11-06 13:48:20 +0000 | [diff] [blame] | 264 | static inline u8 ehci_encode_speed(enum usb_device_speed speed) |
| 265 | { |
| 266 | #define QH_HIGH_SPEED 2 |
| 267 | #define QH_FULL_SPEED 0 |
| 268 | #define QH_LOW_SPEED 1 |
| 269 | if (speed == USB_SPEED_HIGH) |
| 270 | return QH_HIGH_SPEED; |
| 271 | if (speed == USB_SPEED_LOW) |
| 272 | return QH_LOW_SPEED; |
| 273 | return QH_FULL_SPEED; |
| 274 | } |
| 275 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 276 | static int |
| 277 | ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 278 | int length, struct devrequest *req) |
| 279 | { |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 280 | ALLOC_ALIGN_BUFFER(struct QH, qh, 1, USB_DMA_MINALIGN); |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 281 | struct qTD *qtd; |
| 282 | int qtd_count = 0; |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 283 | int qtd_counter = 0; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 284 | volatile struct qTD *vtd; |
| 285 | unsigned long ts; |
| 286 | uint32_t *tdp; |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 287 | uint32_t endpt, maxpacket, token, usbsts; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 288 | uint32_t c, toggle; |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 289 | uint32_t cmd; |
Simon Glass | 96820a3 | 2011-02-07 14:42:16 -0800 | [diff] [blame] | 290 | int timeout; |
Michael Trimarchi | 1ed9f9a | 2008-12-31 10:33:22 +0100 | [diff] [blame] | 291 | int ret = 0; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 292 | struct ehci_ctrl *ctrl = dev->controller; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 293 | |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 294 | debug("dev=%p, pipe=%lx, buffer=%p, length=%d, req=%p\n", dev, pipe, |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 295 | buffer, length, req); |
| 296 | if (req != NULL) |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 297 | debug("req=%u (%#x), type=%u (%#x), value=%u (%#x), index=%u\n", |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 298 | req->request, req->request, |
| 299 | req->requesttype, req->requesttype, |
| 300 | le16_to_cpu(req->value), le16_to_cpu(req->value), |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 301 | le16_to_cpu(req->index)); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 302 | |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 303 | #define PKT_ALIGN 512 |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 304 | /* |
| 305 | * The USB transfer is split into qTD transfers. Eeach qTD transfer is |
| 306 | * described by a transfer descriptor (the qTD). The qTDs form a linked |
| 307 | * list with a queue head (QH). |
| 308 | * |
| 309 | * Each qTD transfer starts with a new USB packet, i.e. a packet cannot |
| 310 | * have its beginning in a qTD transfer and its end in the following |
| 311 | * one, so the qTD transfer lengths have to be chosen accordingly. |
| 312 | * |
| 313 | * Each qTD transfer uses up to QT_BUFFER_CNT data buffers, mapped to |
| 314 | * single pages. The first data buffer can start at any offset within a |
| 315 | * page (not considering the cache-line alignment issues), while the |
| 316 | * following buffers must be page-aligned. There is no alignment |
| 317 | * constraint on the size of a qTD transfer. |
| 318 | */ |
| 319 | if (req != NULL) |
| 320 | /* 1 qTD will be needed for SETUP, and 1 for ACK. */ |
| 321 | qtd_count += 1 + 1; |
| 322 | if (length > 0 || req == NULL) { |
| 323 | /* |
| 324 | * Determine the qTD transfer size that will be used for the |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 325 | * data payload (not considering the first qTD transfer, which |
| 326 | * may be longer or shorter, and the final one, which may be |
| 327 | * shorter). |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 328 | * |
| 329 | * In order to keep each packet within a qTD transfer, the qTD |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 330 | * transfer size is aligned to PKT_ALIGN, which is a multiple of |
| 331 | * wMaxPacketSize (except in some cases for interrupt transfers, |
| 332 | * see comment in submit_int_msg()). |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 333 | * |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 334 | * By default, i.e. if the input buffer is aligned to PKT_ALIGN, |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 335 | * QT_BUFFER_CNT full pages will be used. |
| 336 | */ |
| 337 | int xfr_sz = QT_BUFFER_CNT; |
| 338 | /* |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 339 | * However, if the input buffer is not aligned to PKT_ALIGN, the |
| 340 | * qTD transfer size will be one page shorter, and the first qTD |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 341 | * data buffer of each transfer will be page-unaligned. |
| 342 | */ |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 343 | if ((uint32_t)buffer & (PKT_ALIGN - 1)) |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 344 | xfr_sz--; |
| 345 | /* Convert the qTD transfer size to bytes. */ |
| 346 | xfr_sz *= EHCI_PAGE_SIZE; |
| 347 | /* |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 348 | * Approximate by excess the number of qTDs that will be |
| 349 | * required for the data payload. The exact formula is way more |
| 350 | * complicated and saves at most 2 qTDs, i.e. a total of 128 |
| 351 | * bytes. |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 352 | */ |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 353 | qtd_count += 2 + length / xfr_sz; |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 354 | } |
| 355 | /* |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 356 | * Threshold value based on the worst-case total size of the allocated qTDs for |
| 357 | * a mass-storage transfer of 65535 blocks of 512 bytes. |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 358 | */ |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 359 | #if CONFIG_SYS_MALLOC_LEN <= 64 + 128 * 1024 |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 360 | #warning CONFIG_SYS_MALLOC_LEN may be too small for EHCI |
| 361 | #endif |
| 362 | qtd = memalign(USB_DMA_MINALIGN, qtd_count * sizeof(struct qTD)); |
| 363 | if (qtd == NULL) { |
| 364 | printf("unable to allocate TDs\n"); |
| 365 | return -1; |
| 366 | } |
| 367 | |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 368 | memset(qh, 0, sizeof(struct QH)); |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 369 | memset(qtd, 0, qtd_count * sizeof(*qtd)); |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 370 | |
Marek Vasut | b8adb12 | 2012-04-09 04:07:46 +0200 | [diff] [blame] | 371 | toggle = usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)); |
| 372 | |
Marek Vasut | 41b1f0a | 2012-04-09 04:13:00 +0200 | [diff] [blame] | 373 | /* |
| 374 | * Setup QH (3.6 in ehci-r10.pdf) |
| 375 | * |
| 376 | * qh_link ................. 03-00 H |
| 377 | * qh_endpt1 ............... 07-04 H |
| 378 | * qh_endpt2 ............... 0B-08 H |
| 379 | * - qh_curtd |
| 380 | * qh_overlay.qt_next ...... 13-10 H |
| 381 | * - qh_overlay.qt_altnext |
| 382 | */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 383 | qh->qh_link = cpu_to_hc32((uint32_t)&ctrl->qh_list | QH_LINK_TYPE_QH); |
Ilya Yanok | c60795f | 2012-11-06 13:48:20 +0000 | [diff] [blame] | 384 | c = (dev->speed != USB_SPEED_HIGH) && !usb_pipeendpoint(pipe); |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 385 | maxpacket = usb_maxpacket(dev, pipe); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 386 | endpt = QH_ENDPT1_RL(8) | QH_ENDPT1_C(c) | |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 387 | QH_ENDPT1_MAXPKTLEN(maxpacket) | QH_ENDPT1_H(0) | |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 388 | QH_ENDPT1_DTC(QH_ENDPT1_DTC_DT_FROM_QTD) | |
Ilya Yanok | c60795f | 2012-11-06 13:48:20 +0000 | [diff] [blame] | 389 | QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)) | |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 390 | QH_ENDPT1_ENDPT(usb_pipeendpoint(pipe)) | QH_ENDPT1_I(0) | |
| 391 | QH_ENDPT1_DEVADDR(usb_pipedevice(pipe)); |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 392 | qh->qh_endpt1 = cpu_to_hc32(endpt); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 393 | endpt = QH_ENDPT2_MULT(1) | QH_ENDPT2_PORTNUM(dev->portnr) | |
| 394 | QH_ENDPT2_HUBADDR(dev->parent->devnum) | |
| 395 | QH_ENDPT2_UFCMASK(0) | QH_ENDPT2_UFSMASK(0); |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 396 | qh->qh_endpt2 = cpu_to_hc32(endpt); |
| 397 | qh->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); |
Stephen Warren | 2456b97 | 2014-02-07 09:53:50 -0700 | [diff] [blame] | 398 | qh->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 399 | |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 400 | tdp = &qh->qh_overlay.qt_next; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 401 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 402 | if (req != NULL) { |
Marek Vasut | 41b1f0a | 2012-04-09 04:13:00 +0200 | [diff] [blame] | 403 | /* |
| 404 | * Setup request qTD (3.5 in ehci-r10.pdf) |
| 405 | * |
| 406 | * qt_next ................ 03-00 H |
| 407 | * qt_altnext ............. 07-04 H |
| 408 | * qt_token ............... 0B-08 H |
| 409 | * |
| 410 | * [ buffer, buffer_hi ] loaded with "req". |
| 411 | */ |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 412 | qtd[qtd_counter].qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); |
| 413 | qtd[qtd_counter].qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 414 | token = QT_TOKEN_DT(0) | QT_TOKEN_TOTALBYTES(sizeof(*req)) | |
| 415 | QT_TOKEN_IOC(0) | QT_TOKEN_CPAGE(0) | QT_TOKEN_CERR(3) | |
| 416 | QT_TOKEN_PID(QT_TOKEN_PID_SETUP) | |
| 417 | QT_TOKEN_STATUS(QT_TOKEN_STATUS_ACTIVE); |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 418 | qtd[qtd_counter].qt_token = cpu_to_hc32(token); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 419 | if (ehci_td_buffer(&qtd[qtd_counter], req, sizeof(*req))) { |
| 420 | printf("unable to construct SETUP TD\n"); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 421 | goto fail; |
| 422 | } |
Marek Vasut | 41b1f0a | 2012-04-09 04:13:00 +0200 | [diff] [blame] | 423 | /* Update previous qTD! */ |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 424 | *tdp = cpu_to_hc32((uint32_t)&qtd[qtd_counter]); |
| 425 | tdp = &qtd[qtd_counter++].qt_next; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 426 | toggle = 1; |
| 427 | } |
| 428 | |
| 429 | if (length > 0 || req == NULL) { |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 430 | uint8_t *buf_ptr = buffer; |
| 431 | int left_length = length; |
| 432 | |
| 433 | do { |
| 434 | /* |
| 435 | * Determine the size of this qTD transfer. By default, |
| 436 | * QT_BUFFER_CNT full pages can be used. |
| 437 | */ |
| 438 | int xfr_bytes = QT_BUFFER_CNT * EHCI_PAGE_SIZE; |
| 439 | /* |
| 440 | * However, if the input buffer is not page-aligned, the |
| 441 | * portion of the first page before the buffer start |
| 442 | * offset within that page is unusable. |
| 443 | */ |
| 444 | xfr_bytes -= (uint32_t)buf_ptr & (EHCI_PAGE_SIZE - 1); |
| 445 | /* |
| 446 | * In order to keep each packet within a qTD transfer, |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 447 | * align the qTD transfer size to PKT_ALIGN. |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 448 | */ |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 449 | xfr_bytes &= ~(PKT_ALIGN - 1); |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 450 | /* |
| 451 | * This transfer may be shorter than the available qTD |
| 452 | * transfer size that has just been computed. |
| 453 | */ |
| 454 | xfr_bytes = min(xfr_bytes, left_length); |
| 455 | |
| 456 | /* |
| 457 | * Setup request qTD (3.5 in ehci-r10.pdf) |
| 458 | * |
| 459 | * qt_next ................ 03-00 H |
| 460 | * qt_altnext ............. 07-04 H |
| 461 | * qt_token ............... 0B-08 H |
| 462 | * |
| 463 | * [ buffer, buffer_hi ] loaded with "buffer". |
| 464 | */ |
| 465 | qtd[qtd_counter].qt_next = |
| 466 | cpu_to_hc32(QT_NEXT_TERMINATE); |
| 467 | qtd[qtd_counter].qt_altnext = |
| 468 | cpu_to_hc32(QT_NEXT_TERMINATE); |
| 469 | token = QT_TOKEN_DT(toggle) | |
| 470 | QT_TOKEN_TOTALBYTES(xfr_bytes) | |
| 471 | QT_TOKEN_IOC(req == NULL) | QT_TOKEN_CPAGE(0) | |
| 472 | QT_TOKEN_CERR(3) | |
| 473 | QT_TOKEN_PID(usb_pipein(pipe) ? |
| 474 | QT_TOKEN_PID_IN : QT_TOKEN_PID_OUT) | |
| 475 | QT_TOKEN_STATUS(QT_TOKEN_STATUS_ACTIVE); |
| 476 | qtd[qtd_counter].qt_token = cpu_to_hc32(token); |
| 477 | if (ehci_td_buffer(&qtd[qtd_counter], buf_ptr, |
| 478 | xfr_bytes)) { |
| 479 | printf("unable to construct DATA TD\n"); |
| 480 | goto fail; |
| 481 | } |
| 482 | /* Update previous qTD! */ |
| 483 | *tdp = cpu_to_hc32((uint32_t)&qtd[qtd_counter]); |
| 484 | tdp = &qtd[qtd_counter++].qt_next; |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 485 | /* |
| 486 | * Data toggle has to be adjusted since the qTD transfer |
| 487 | * size is not always an even multiple of |
| 488 | * wMaxPacketSize. |
| 489 | */ |
| 490 | if ((xfr_bytes / maxpacket) & 1) |
| 491 | toggle ^= 1; |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 492 | buf_ptr += xfr_bytes; |
| 493 | left_length -= xfr_bytes; |
| 494 | } while (left_length > 0); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | if (req != NULL) { |
Marek Vasut | 41b1f0a | 2012-04-09 04:13:00 +0200 | [diff] [blame] | 498 | /* |
| 499 | * Setup request qTD (3.5 in ehci-r10.pdf) |
| 500 | * |
| 501 | * qt_next ................ 03-00 H |
| 502 | * qt_altnext ............. 07-04 H |
| 503 | * qt_token ............... 0B-08 H |
| 504 | */ |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 505 | qtd[qtd_counter].qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); |
| 506 | qtd[qtd_counter].qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 507 | token = QT_TOKEN_DT(1) | QT_TOKEN_TOTALBYTES(0) | |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 508 | QT_TOKEN_IOC(1) | QT_TOKEN_CPAGE(0) | QT_TOKEN_CERR(3) | |
| 509 | QT_TOKEN_PID(usb_pipein(pipe) ? |
| 510 | QT_TOKEN_PID_OUT : QT_TOKEN_PID_IN) | |
| 511 | QT_TOKEN_STATUS(QT_TOKEN_STATUS_ACTIVE); |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 512 | qtd[qtd_counter].qt_token = cpu_to_hc32(token); |
Marek Vasut | 41b1f0a | 2012-04-09 04:13:00 +0200 | [diff] [blame] | 513 | /* Update previous qTD! */ |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 514 | *tdp = cpu_to_hc32((uint32_t)&qtd[qtd_counter]); |
| 515 | tdp = &qtd[qtd_counter++].qt_next; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 518 | ctrl->qh_list.qh_link = cpu_to_hc32((uint32_t)qh | QH_LINK_TYPE_QH); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 519 | |
Stefan Roese | daa2daf | 2009-01-21 17:12:19 +0100 | [diff] [blame] | 520 | /* Flush dcache */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 521 | flush_dcache_range((uint32_t)&ctrl->qh_list, |
| 522 | ALIGN_END_ADDR(struct QH, &ctrl->qh_list, 1)); |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 523 | flush_dcache_range((uint32_t)qh, ALIGN_END_ADDR(struct QH, qh, 1)); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 524 | flush_dcache_range((uint32_t)qtd, |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 525 | ALIGN_END_ADDR(struct qTD, qtd, qtd_count)); |
Stefan Roese | daa2daf | 2009-01-21 17:12:19 +0100 | [diff] [blame] | 526 | |
Ilya Yanok | c7701af | 2012-07-15 22:12:08 +0000 | [diff] [blame] | 527 | /* Set async. queue head pointer. */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 528 | ehci_writel(&ctrl->hcor->or_asynclistaddr, (uint32_t)&ctrl->qh_list); |
Ilya Yanok | c7701af | 2012-07-15 22:12:08 +0000 | [diff] [blame] | 529 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 530 | usbsts = ehci_readl(&ctrl->hcor->or_usbsts); |
| 531 | ehci_writel(&ctrl->hcor->or_usbsts, (usbsts & 0x3f)); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 532 | |
| 533 | /* Enable async. schedule. */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 534 | cmd = ehci_readl(&ctrl->hcor->or_usbcmd); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 535 | cmd |= CMD_ASE; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 536 | ehci_writel(&ctrl->hcor->or_usbcmd, cmd); |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 537 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 538 | ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, STS_ASS, |
Michael Trimarchi | 1ed9f9a | 2008-12-31 10:33:22 +0100 | [diff] [blame] | 539 | 100 * 1000); |
| 540 | if (ret < 0) { |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 541 | printf("EHCI fail timeout STS_ASS set\n"); |
Michael Trimarchi | 1ed9f9a | 2008-12-31 10:33:22 +0100 | [diff] [blame] | 542 | goto fail; |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 543 | } |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 544 | |
| 545 | /* Wait for TDs to be processed. */ |
| 546 | ts = get_timer(0); |
Marek Vasut | de98e8b | 2012-04-08 23:32:05 +0200 | [diff] [blame] | 547 | vtd = &qtd[qtd_counter - 1]; |
Simon Glass | 96820a3 | 2011-02-07 14:42:16 -0800 | [diff] [blame] | 548 | timeout = USB_TIMEOUT_MS(pipe); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 549 | do { |
Stefan Roese | daa2daf | 2009-01-21 17:12:19 +0100 | [diff] [blame] | 550 | /* Invalidate dcache */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 551 | invalidate_dcache_range((uint32_t)&ctrl->qh_list, |
| 552 | ALIGN_END_ADDR(struct QH, &ctrl->qh_list, 1)); |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 553 | invalidate_dcache_range((uint32_t)qh, |
| 554 | ALIGN_END_ADDR(struct QH, qh, 1)); |
Marek Vasut | b8adb12 | 2012-04-09 04:07:46 +0200 | [diff] [blame] | 555 | invalidate_dcache_range((uint32_t)qtd, |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 556 | ALIGN_END_ADDR(struct qTD, qtd, qtd_count)); |
Marek Vasut | b8adb12 | 2012-04-09 04:07:46 +0200 | [diff] [blame] | 557 | |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 558 | token = hc32_to_cpu(vtd->qt_token); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 559 | if (!(QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE)) |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 560 | break; |
Stefan Roese | 67333f7 | 2010-11-26 15:43:28 +0100 | [diff] [blame] | 561 | WATCHDOG_RESET(); |
Simon Glass | 96820a3 | 2011-02-07 14:42:16 -0800 | [diff] [blame] | 562 | } while (get_timer(ts) < timeout); |
| 563 | |
Ilya Yanok | 189a695 | 2012-07-15 04:43:49 +0000 | [diff] [blame] | 564 | /* |
| 565 | * Invalidate the memory area occupied by buffer |
| 566 | * Don't try to fix the buffer alignment, if it isn't properly |
| 567 | * aligned it's upper layer's fault so let invalidate_dcache_range() |
| 568 | * vow about it. But we have to fix the length as it's actual |
| 569 | * transfer length and can be unaligned. This is potentially |
| 570 | * dangerous operation, it's responsibility of the calling |
| 571 | * code to make sure enough space is reserved. |
| 572 | */ |
| 573 | invalidate_dcache_range((uint32_t)buffer, |
| 574 | ALIGN((uint32_t)buffer + length, ARCH_DMA_MINALIGN)); |
Marek Vasut | b8adb12 | 2012-04-09 04:07:46 +0200 | [diff] [blame] | 575 | |
Simon Glass | 96820a3 | 2011-02-07 14:42:16 -0800 | [diff] [blame] | 576 | /* Check that the TD processing happened */ |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 577 | if (QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE) |
Simon Glass | 96820a3 | 2011-02-07 14:42:16 -0800 | [diff] [blame] | 578 | printf("EHCI timed out on TD - token=%#x\n", token); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 579 | |
| 580 | /* Disable async schedule. */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 581 | cmd = ehci_readl(&ctrl->hcor->or_usbcmd); |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 582 | cmd &= ~CMD_ASE; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 583 | ehci_writel(&ctrl->hcor->or_usbcmd, cmd); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 584 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 585 | ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, 0, |
Michael Trimarchi | 1ed9f9a | 2008-12-31 10:33:22 +0100 | [diff] [blame] | 586 | 100 * 1000); |
| 587 | if (ret < 0) { |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 588 | printf("EHCI fail timeout STS_ASS reset\n"); |
Michael Trimarchi | 1ed9f9a | 2008-12-31 10:33:22 +0100 | [diff] [blame] | 589 | goto fail; |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 590 | } |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 591 | |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 592 | token = hc32_to_cpu(qh->qh_overlay.qt_token); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 593 | if (!(QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE)) { |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 594 | debug("TOKEN=%#x\n", token); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 595 | switch (QT_TOKEN_GET_STATUS(token) & |
| 596 | ~(QT_TOKEN_STATUS_SPLITXSTATE | QT_TOKEN_STATUS_PERR)) { |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 597 | case 0: |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 598 | toggle = QT_TOKEN_GET_DT(token); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 599 | usb_settoggle(dev, usb_pipeendpoint(pipe), |
| 600 | usb_pipeout(pipe), toggle); |
| 601 | dev->status = 0; |
| 602 | break; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 603 | case QT_TOKEN_STATUS_HALTED: |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 604 | dev->status = USB_ST_STALLED; |
| 605 | break; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 606 | case QT_TOKEN_STATUS_ACTIVE | QT_TOKEN_STATUS_DATBUFERR: |
| 607 | case QT_TOKEN_STATUS_DATBUFERR: |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 608 | dev->status = USB_ST_BUF_ERR; |
| 609 | break; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 610 | case QT_TOKEN_STATUS_HALTED | QT_TOKEN_STATUS_BABBLEDET: |
| 611 | case QT_TOKEN_STATUS_BABBLEDET: |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 612 | dev->status = USB_ST_BABBLE_DET; |
| 613 | break; |
| 614 | default: |
| 615 | dev->status = USB_ST_CRC_ERR; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 616 | if (QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_HALTED) |
Anatolij Gustschin | 222d6df | 2010-11-02 11:47:29 +0100 | [diff] [blame] | 617 | dev->status |= USB_ST_STALLED; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 618 | break; |
| 619 | } |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 620 | dev->act_len = length - QT_TOKEN_GET_TOTALBYTES(token); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 621 | } else { |
| 622 | dev->act_len = 0; |
Kuo-Jung Su | e82a316 | 2013-05-15 15:29:23 +0800 | [diff] [blame] | 623 | #ifndef CONFIG_USB_EHCI_FARADAY |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 624 | debug("dev=%u, usbsts=%#x, p[1]=%#x, p[2]=%#x\n", |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 625 | dev->devnum, ehci_readl(&ctrl->hcor->or_usbsts), |
| 626 | ehci_readl(&ctrl->hcor->or_portsc[0]), |
| 627 | ehci_readl(&ctrl->hcor->or_portsc[1])); |
Kuo-Jung Su | e82a316 | 2013-05-15 15:29:23 +0800 | [diff] [blame] | 628 | #endif |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 629 | } |
| 630 | |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 631 | free(qtd); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 632 | return (dev->status != USB_ST_NOT_PROC) ? 0 : -1; |
| 633 | |
| 634 | fail: |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 635 | free(qtd); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 636 | return -1; |
| 637 | } |
| 638 | |
Kuo-Jung Su | 1dde142 | 2013-05-15 15:29:21 +0800 | [diff] [blame] | 639 | __weak uint32_t *ehci_get_portsc_register(struct ehci_hcor *hcor, int port) |
| 640 | { |
| 641 | if (port < 0 || port >= CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS) { |
| 642 | /* Printing the message would cause a scan failure! */ |
| 643 | debug("The request port(%u) is not configured\n", port); |
| 644 | return NULL; |
| 645 | } |
| 646 | |
| 647 | return (uint32_t *)&hcor->or_portsc[port]; |
| 648 | } |
| 649 | |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 650 | int |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 651 | ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 652 | int length, struct devrequest *req) |
| 653 | { |
| 654 | uint8_t tmpbuf[4]; |
| 655 | u16 typeReq; |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 656 | void *srcptr = NULL; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 657 | int len, srclen; |
| 658 | uint32_t reg; |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 659 | uint32_t *status_reg; |
Julius Werner | 7d9aa8f | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 660 | int port = le16_to_cpu(req->index) & 0xff; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 661 | struct ehci_ctrl *ctrl = dev->controller; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 662 | |
| 663 | srclen = 0; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 664 | |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 665 | debug("req=%u (%#x), type=%u (%#x), value=%u, index=%u\n", |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 666 | req->request, req->request, |
| 667 | req->requesttype, req->requesttype, |
| 668 | le16_to_cpu(req->value), le16_to_cpu(req->index)); |
| 669 | |
Prafulla Wadaskar | 44259bb | 2009-07-17 19:56:30 +0530 | [diff] [blame] | 670 | typeReq = req->request | req->requesttype << 8; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 671 | |
Prafulla Wadaskar | 44259bb | 2009-07-17 19:56:30 +0530 | [diff] [blame] | 672 | switch (typeReq) { |
Kuo-Jung Su | 9c6a9d7 | 2013-05-15 15:29:20 +0800 | [diff] [blame] | 673 | case USB_REQ_GET_STATUS | ((USB_RT_PORT | USB_DIR_IN) << 8): |
| 674 | case USB_REQ_SET_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): |
| 675 | case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): |
Kuo-Jung Su | 1dde142 | 2013-05-15 15:29:21 +0800 | [diff] [blame] | 676 | status_reg = ehci_get_portsc_register(ctrl->hcor, port - 1); |
| 677 | if (!status_reg) |
Kuo-Jung Su | 9c6a9d7 | 2013-05-15 15:29:20 +0800 | [diff] [blame] | 678 | return -1; |
Kuo-Jung Su | 9c6a9d7 | 2013-05-15 15:29:20 +0800 | [diff] [blame] | 679 | break; |
| 680 | default: |
| 681 | status_reg = NULL; |
| 682 | break; |
| 683 | } |
| 684 | |
| 685 | switch (typeReq) { |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 686 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: |
| 687 | switch (le16_to_cpu(req->value) >> 8) { |
| 688 | case USB_DT_DEVICE: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 689 | debug("USB_DT_DEVICE request\n"); |
| 690 | srcptr = &descriptor.device; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 691 | srclen = descriptor.device.bLength; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 692 | break; |
| 693 | case USB_DT_CONFIG: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 694 | debug("USB_DT_CONFIG config\n"); |
| 695 | srcptr = &descriptor.config; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 696 | srclen = descriptor.config.bLength + |
| 697 | descriptor.interface.bLength + |
| 698 | descriptor.endpoint.bLength; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 699 | break; |
| 700 | case USB_DT_STRING: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 701 | debug("USB_DT_STRING config\n"); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 702 | switch (le16_to_cpu(req->value) & 0xff) { |
| 703 | case 0: /* Language */ |
| 704 | srcptr = "\4\3\1\0"; |
| 705 | srclen = 4; |
| 706 | break; |
| 707 | case 1: /* Vendor */ |
| 708 | srcptr = "\16\3u\0-\0b\0o\0o\0t\0"; |
| 709 | srclen = 14; |
| 710 | break; |
| 711 | case 2: /* Product */ |
| 712 | srcptr = "\52\3E\0H\0C\0I\0 " |
| 713 | "\0H\0o\0s\0t\0 " |
| 714 | "\0C\0o\0n\0t\0r\0o\0l\0l\0e\0r\0"; |
| 715 | srclen = 42; |
| 716 | break; |
| 717 | default: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 718 | debug("unknown value DT_STRING %x\n", |
| 719 | le16_to_cpu(req->value)); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 720 | goto unknown; |
| 721 | } |
| 722 | break; |
| 723 | default: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 724 | debug("unknown value %x\n", le16_to_cpu(req->value)); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 725 | goto unknown; |
| 726 | } |
| 727 | break; |
| 728 | case USB_REQ_GET_DESCRIPTOR | ((USB_DIR_IN | USB_RT_HUB) << 8): |
| 729 | switch (le16_to_cpu(req->value) >> 8) { |
| 730 | case USB_DT_HUB: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 731 | debug("USB_DT_HUB config\n"); |
| 732 | srcptr = &descriptor.hub; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 733 | srclen = descriptor.hub.bLength; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 734 | break; |
| 735 | default: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 736 | debug("unknown value %x\n", le16_to_cpu(req->value)); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 737 | goto unknown; |
| 738 | } |
| 739 | break; |
| 740 | case USB_REQ_SET_ADDRESS | (USB_RECIP_DEVICE << 8): |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 741 | debug("USB_REQ_SET_ADDRESS\n"); |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 742 | ctrl->rootdev = le16_to_cpu(req->value); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 743 | break; |
| 744 | case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 745 | debug("USB_REQ_SET_CONFIGURATION\n"); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 746 | /* Nothing to do */ |
| 747 | break; |
| 748 | case USB_REQ_GET_STATUS | ((USB_DIR_IN | USB_RT_HUB) << 8): |
| 749 | tmpbuf[0] = 1; /* USB_STATUS_SELFPOWERED */ |
| 750 | tmpbuf[1] = 0; |
| 751 | srcptr = tmpbuf; |
| 752 | srclen = 2; |
| 753 | break; |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 754 | case USB_REQ_GET_STATUS | ((USB_RT_PORT | USB_DIR_IN) << 8): |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 755 | memset(tmpbuf, 0, 4); |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 756 | reg = ehci_readl(status_reg); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 757 | if (reg & EHCI_PS_CS) |
| 758 | tmpbuf[0] |= USB_PORT_STAT_CONNECTION; |
| 759 | if (reg & EHCI_PS_PE) |
| 760 | tmpbuf[0] |= USB_PORT_STAT_ENABLE; |
| 761 | if (reg & EHCI_PS_SUSP) |
| 762 | tmpbuf[0] |= USB_PORT_STAT_SUSPEND; |
| 763 | if (reg & EHCI_PS_OCA) |
| 764 | tmpbuf[0] |= USB_PORT_STAT_OVERCURRENT; |
Sergei Shtylyov | c8b2d1d | 2010-02-27 21:33:21 +0300 | [diff] [blame] | 765 | if (reg & EHCI_PS_PR) |
| 766 | tmpbuf[0] |= USB_PORT_STAT_RESET; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 767 | if (reg & EHCI_PS_PP) |
| 768 | tmpbuf[1] |= USB_PORT_STAT_POWER >> 8; |
Stefan Roese | 597eb28 | 2009-01-21 17:12:01 +0100 | [diff] [blame] | 769 | |
| 770 | if (ehci_is_TDI()) { |
Jim Lin | b068deb | 2013-03-27 00:52:32 +0000 | [diff] [blame] | 771 | switch (ehci_get_port_speed(ctrl->hcor, reg)) { |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 772 | case PORTSC_PSPD_FS: |
Stefan Roese | 597eb28 | 2009-01-21 17:12:01 +0100 | [diff] [blame] | 773 | break; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 774 | case PORTSC_PSPD_LS: |
Stefan Roese | 597eb28 | 2009-01-21 17:12:01 +0100 | [diff] [blame] | 775 | tmpbuf[1] |= USB_PORT_STAT_LOW_SPEED >> 8; |
| 776 | break; |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 777 | case PORTSC_PSPD_HS: |
Stefan Roese | 597eb28 | 2009-01-21 17:12:01 +0100 | [diff] [blame] | 778 | default: |
| 779 | tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8; |
| 780 | break; |
| 781 | } |
| 782 | } else { |
| 783 | tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8; |
| 784 | } |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 785 | |
| 786 | if (reg & EHCI_PS_CSC) |
| 787 | tmpbuf[2] |= USB_PORT_STAT_C_CONNECTION; |
| 788 | if (reg & EHCI_PS_PEC) |
| 789 | tmpbuf[2] |= USB_PORT_STAT_C_ENABLE; |
| 790 | if (reg & EHCI_PS_OCC) |
| 791 | tmpbuf[2] |= USB_PORT_STAT_C_OVERCURRENT; |
Julius Werner | 7d9aa8f | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 792 | if (ctrl->portreset & (1 << port)) |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 793 | tmpbuf[2] |= USB_PORT_STAT_C_RESET; |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 794 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 795 | srcptr = tmpbuf; |
| 796 | srclen = 4; |
| 797 | break; |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 798 | case USB_REQ_SET_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 799 | reg = ehci_readl(status_reg); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 800 | reg &= ~EHCI_PS_CLEAR; |
| 801 | switch (le16_to_cpu(req->value)) { |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 802 | case USB_PORT_FEAT_ENABLE: |
| 803 | reg |= EHCI_PS_PE; |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 804 | ehci_writel(status_reg, reg); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 805 | break; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 806 | case USB_PORT_FEAT_POWER: |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 807 | if (HCS_PPC(ehci_readl(&ctrl->hccr->cr_hcsparams))) { |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 808 | reg |= EHCI_PS_PP; |
| 809 | ehci_writel(status_reg, reg); |
| 810 | } |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 811 | break; |
| 812 | case USB_PORT_FEAT_RESET: |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 813 | if ((reg & (EHCI_PS_PE | EHCI_PS_CS)) == EHCI_PS_CS && |
| 814 | !ehci_is_TDI() && |
| 815 | EHCI_PS_IS_LOWSPEED(reg)) { |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 816 | /* Low speed device, give up ownership. */ |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 817 | debug("port %d low speed --> companion\n", |
Julius Werner | 7d9aa8f | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 818 | port - 1); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 819 | reg |= EHCI_PS_PO; |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 820 | ehci_writel(status_reg, reg); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 821 | break; |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 822 | } else { |
Sergei Shtylyov | c8b2d1d | 2010-02-27 21:33:21 +0300 | [diff] [blame] | 823 | int ret; |
| 824 | |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 825 | reg |= EHCI_PS_PR; |
| 826 | reg &= ~EHCI_PS_PE; |
| 827 | ehci_writel(status_reg, reg); |
| 828 | /* |
| 829 | * caller must wait, then call GetPortStatus |
| 830 | * usb 2.0 specification say 50 ms resets on |
| 831 | * root |
| 832 | */ |
Marek Vasut | 3874b6d | 2011-07-11 02:37:01 +0200 | [diff] [blame] | 833 | ehci_powerup_fixup(status_reg, ®); |
| 834 | |
Chris Zhang | b416191 | 2010-01-06 13:34:04 -0800 | [diff] [blame] | 835 | ehci_writel(status_reg, reg & ~EHCI_PS_PR); |
Sergei Shtylyov | c8b2d1d | 2010-02-27 21:33:21 +0300 | [diff] [blame] | 836 | /* |
| 837 | * A host controller must terminate the reset |
| 838 | * and stabilize the state of the port within |
| 839 | * 2 milliseconds |
| 840 | */ |
| 841 | ret = handshake(status_reg, EHCI_PS_PR, 0, |
| 842 | 2 * 1000); |
| 843 | if (!ret) |
Julius Werner | 7d9aa8f | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 844 | ctrl->portreset |= 1 << port; |
Sergei Shtylyov | c8b2d1d | 2010-02-27 21:33:21 +0300 | [diff] [blame] | 845 | else |
| 846 | printf("port(%d) reset error\n", |
Julius Werner | 7d9aa8f | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 847 | port - 1); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 848 | } |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 849 | break; |
Julius Werner | 7d9aa8f | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 850 | case USB_PORT_FEAT_TEST: |
Julius Werner | 5077f96 | 2013-09-24 10:53:07 -0700 | [diff] [blame] | 851 | ehci_shutdown(ctrl); |
Julius Werner | 7d9aa8f | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 852 | reg &= ~(0xf << 16); |
| 853 | reg |= ((le16_to_cpu(req->index) >> 8) & 0xf) << 16; |
| 854 | ehci_writel(status_reg, reg); |
| 855 | break; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 856 | default: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 857 | debug("unknown feature %x\n", le16_to_cpu(req->value)); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 858 | goto unknown; |
| 859 | } |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 860 | /* unblock posted writes */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 861 | (void) ehci_readl(&ctrl->hcor->or_usbcmd); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 862 | break; |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 863 | case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 864 | reg = ehci_readl(status_reg); |
Simon Glass | ed10e66 | 2013-05-10 19:49:00 -0700 | [diff] [blame] | 865 | reg &= ~EHCI_PS_CLEAR; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 866 | switch (le16_to_cpu(req->value)) { |
| 867 | case USB_PORT_FEAT_ENABLE: |
| 868 | reg &= ~EHCI_PS_PE; |
| 869 | break; |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 870 | case USB_PORT_FEAT_C_ENABLE: |
Simon Glass | ed10e66 | 2013-05-10 19:49:00 -0700 | [diff] [blame] | 871 | reg |= EHCI_PS_PE; |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 872 | break; |
| 873 | case USB_PORT_FEAT_POWER: |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 874 | if (HCS_PPC(ehci_readl(&ctrl->hccr->cr_hcsparams))) |
Simon Glass | ed10e66 | 2013-05-10 19:49:00 -0700 | [diff] [blame] | 875 | reg &= ~EHCI_PS_PP; |
| 876 | break; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 877 | case USB_PORT_FEAT_C_CONNECTION: |
Simon Glass | ed10e66 | 2013-05-10 19:49:00 -0700 | [diff] [blame] | 878 | reg |= EHCI_PS_CSC; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 879 | break; |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 880 | case USB_PORT_FEAT_OVER_CURRENT: |
Simon Glass | ed10e66 | 2013-05-10 19:49:00 -0700 | [diff] [blame] | 881 | reg |= EHCI_PS_OCC; |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 882 | break; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 883 | case USB_PORT_FEAT_C_RESET: |
Julius Werner | 7d9aa8f | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 884 | ctrl->portreset &= ~(1 << port); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 885 | break; |
| 886 | default: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 887 | debug("unknown feature %x\n", le16_to_cpu(req->value)); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 888 | goto unknown; |
| 889 | } |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 890 | ehci_writel(status_reg, reg); |
| 891 | /* unblock posted write */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 892 | (void) ehci_readl(&ctrl->hcor->or_usbcmd); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 893 | break; |
| 894 | default: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 895 | debug("Unknown request\n"); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 896 | goto unknown; |
| 897 | } |
| 898 | |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 899 | mdelay(1); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 900 | len = min3(srclen, le16_to_cpu(req->length), length); |
| 901 | if (srcptr != NULL && len > 0) |
| 902 | memcpy(buffer, srcptr, len); |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 903 | else |
| 904 | debug("Len is 0\n"); |
| 905 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 906 | dev->act_len = len; |
| 907 | dev->status = 0; |
| 908 | return 0; |
| 909 | |
| 910 | unknown: |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 911 | debug("requesttype=%x, request=%x, value=%x, index=%x, length=%x\n", |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 912 | req->requesttype, req->request, le16_to_cpu(req->value), |
| 913 | le16_to_cpu(req->index), le16_to_cpu(req->length)); |
| 914 | |
| 915 | dev->act_len = 0; |
| 916 | dev->status = USB_ST_STALLED; |
| 917 | return -1; |
| 918 | } |
| 919 | |
Lucas Stach | c7e3b2b | 2012-09-26 00:14:34 +0200 | [diff] [blame] | 920 | int usb_lowlevel_stop(int index) |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 921 | { |
Julius Werner | 5077f96 | 2013-09-24 10:53:07 -0700 | [diff] [blame] | 922 | ehci_shutdown(&ehcic[index]); |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 923 | return ehci_hcd_stop(index); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 924 | } |
| 925 | |
Troy Kisky | 06d513e | 2013-10-10 15:27:56 -0700 | [diff] [blame] | 926 | int usb_lowlevel_init(int index, enum usb_init_type init, void **controller) |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 927 | { |
| 928 | uint32_t reg; |
michael | db63299 | 2008-12-10 17:55:19 +0100 | [diff] [blame] | 929 | uint32_t cmd; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 930 | struct QH *qh_list; |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 931 | struct QH *periodic; |
| 932 | int i; |
Troy Kisky | 127efc4 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 933 | int rc; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 934 | |
Troy Kisky | 127efc4 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 935 | rc = ehci_hcd_init(index, init, &ehcic[index].hccr, &ehcic[index].hcor); |
| 936 | if (rc) |
| 937 | return rc; |
| 938 | if (init == USB_INIT_DEVICE) |
| 939 | goto done; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 940 | |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 941 | /* EHCI spec section 4.1 */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 942 | if (ehci_reset(index)) |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 943 | return -1; |
| 944 | |
Stefan Roese | 832e614 | 2009-01-21 17:12:10 +0100 | [diff] [blame] | 945 | #if defined(CONFIG_EHCI_HCD_INIT_AFTER_RESET) |
Troy Kisky | 127efc4 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 946 | rc = ehci_hcd_init(index, init, &ehcic[index].hccr, &ehcic[index].hcor); |
| 947 | if (rc) |
| 948 | return rc; |
Stefan Roese | 832e614 | 2009-01-21 17:12:10 +0100 | [diff] [blame] | 949 | #endif |
Vincent Palatin | 2982837 | 2012-12-12 17:55:22 -0800 | [diff] [blame] | 950 | /* Set the high address word (aka segment) for 64-bit controller */ |
| 951 | if (ehci_readl(&ehcic[index].hccr->cr_hccparams) & 1) |
Marek Vasut | eb63218 | 2013-12-14 02:04:52 +0100 | [diff] [blame] | 952 | ehci_writel(&ehcic[index].hcor->or_ctrldssegment, 0); |
Stefan Roese | 832e614 | 2009-01-21 17:12:10 +0100 | [diff] [blame] | 953 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 954 | qh_list = &ehcic[index].qh_list; |
| 955 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 956 | /* Set head of reclaim list */ |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 957 | memset(qh_list, 0, sizeof(*qh_list)); |
| 958 | qh_list->qh_link = cpu_to_hc32((uint32_t)qh_list | QH_LINK_TYPE_QH); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 959 | qh_list->qh_endpt1 = cpu_to_hc32(QH_ENDPT1_H(1) | |
| 960 | QH_ENDPT1_EPS(USB_SPEED_HIGH)); |
Tom Rini | 71c5de4 | 2012-07-15 22:14:24 +0000 | [diff] [blame] | 961 | qh_list->qh_curtd = cpu_to_hc32(QT_NEXT_TERMINATE); |
| 962 | qh_list->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); |
| 963 | qh_list->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); |
Benoît Thébaudeau | 14eb79b | 2012-08-10 18:22:11 +0200 | [diff] [blame] | 964 | qh_list->qh_overlay.qt_token = |
| 965 | cpu_to_hc32(QT_TOKEN_STATUS(QT_TOKEN_STATUS_HALTED)); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 966 | |
Stephen Warren | d3e0747 | 2013-05-24 15:03:17 -0600 | [diff] [blame] | 967 | flush_dcache_range((uint32_t)qh_list, |
| 968 | ALIGN_END_ADDR(struct QH, qh_list, 1)); |
| 969 | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 970 | /* Set async. queue head pointer. */ |
| 971 | ehci_writel(&ehcic[index].hcor->or_asynclistaddr, (uint32_t)qh_list); |
| 972 | |
| 973 | /* |
| 974 | * Set up periodic list |
| 975 | * Step 1: Parent QH for all periodic transfers. |
| 976 | */ |
| 977 | periodic = &ehcic[index].periodic_queue; |
| 978 | memset(periodic, 0, sizeof(*periodic)); |
| 979 | periodic->qh_link = cpu_to_hc32(QH_LINK_TERMINATE); |
| 980 | periodic->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); |
| 981 | periodic->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); |
| 982 | |
Stephen Warren | d3e0747 | 2013-05-24 15:03:17 -0600 | [diff] [blame] | 983 | flush_dcache_range((uint32_t)periodic, |
| 984 | ALIGN_END_ADDR(struct QH, periodic, 1)); |
| 985 | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 986 | /* |
| 987 | * Step 2: Setup frame-list: Every microframe, USB tries the same list. |
| 988 | * In particular, device specifications on polling frequency |
| 989 | * are disregarded. Keyboards seem to send NAK/NYet reliably |
| 990 | * when polled with an empty buffer. |
| 991 | * |
| 992 | * Split Transactions will be spread across microframes using |
| 993 | * S-mask and C-mask. |
| 994 | */ |
Nikita Kiryanov | 8bc3603 | 2013-07-29 13:27:40 +0300 | [diff] [blame] | 995 | if (ehcic[index].periodic_list == NULL) |
| 996 | ehcic[index].periodic_list = memalign(4096, 1024 * 4); |
| 997 | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 998 | if (!ehcic[index].periodic_list) |
| 999 | return -ENOMEM; |
| 1000 | for (i = 0; i < 1024; i++) { |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1001 | ehcic[index].periodic_list[i] = cpu_to_hc32((uint32_t)periodic |
| 1002 | | QH_LINK_TYPE_QH); |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Stephen Warren | d3e0747 | 2013-05-24 15:03:17 -0600 | [diff] [blame] | 1005 | flush_dcache_range((uint32_t)ehcic[index].periodic_list, |
| 1006 | ALIGN_END_ADDR(uint32_t, ehcic[index].periodic_list, |
| 1007 | 1024)); |
| 1008 | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1009 | /* Set periodic list base address */ |
| 1010 | ehci_writel(&ehcic[index].hcor->or_periodiclistbase, |
| 1011 | (uint32_t)ehcic[index].periodic_list); |
| 1012 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1013 | reg = ehci_readl(&ehcic[index].hccr->cr_hcsparams); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 1014 | descriptor.hub.bNbrPorts = HCS_N_PORTS(reg); |
Lucas Stach | 7a46b2c | 2012-09-28 00:26:19 +0200 | [diff] [blame] | 1015 | debug("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts); |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 1016 | /* Port Indicators */ |
| 1017 | if (HCS_INDICATOR(reg)) |
Lucas Stach | 93ad908 | 2012-09-06 08:00:13 +0200 | [diff] [blame] | 1018 | put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics) |
| 1019 | | 0x80, &descriptor.hub.wHubCharacteristics); |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 1020 | /* Port Power Control */ |
| 1021 | if (HCS_PPC(reg)) |
Lucas Stach | 93ad908 | 2012-09-06 08:00:13 +0200 | [diff] [blame] | 1022 | put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics) |
| 1023 | | 0x01, &descriptor.hub.wHubCharacteristics); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1024 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1025 | /* Start the host controller. */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1026 | cmd = ehci_readl(&ehcic[index].hcor->or_usbcmd); |
Wolfgang Denk | f15c651 | 2009-02-12 00:08:39 +0100 | [diff] [blame] | 1027 | /* |
| 1028 | * Philips, Intel, and maybe others need CMD_RUN before the |
| 1029 | * root hub will detect new devices (why?); NEC doesn't |
| 1030 | */ |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 1031 | cmd &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); |
| 1032 | cmd |= CMD_RUN; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1033 | ehci_writel(&ehcic[index].hcor->or_usbcmd, cmd); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 1034 | |
Kuo-Jung Su | e82a316 | 2013-05-15 15:29:23 +0800 | [diff] [blame] | 1035 | #ifndef CONFIG_USB_EHCI_FARADAY |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 1036 | /* take control over the ports */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1037 | cmd = ehci_readl(&ehcic[index].hcor->or_configflag); |
michael | 51ab142 | 2008-12-11 13:43:55 +0100 | [diff] [blame] | 1038 | cmd |= FLAG_CF; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1039 | ehci_writel(&ehcic[index].hcor->or_configflag, cmd); |
Kuo-Jung Su | e82a316 | 2013-05-15 15:29:23 +0800 | [diff] [blame] | 1040 | #endif |
| 1041 | |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 1042 | /* unblock posted write */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1043 | cmd = ehci_readl(&ehcic[index].hcor->or_usbcmd); |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 1044 | mdelay(5); |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1045 | reg = HC_VERSION(ehci_readl(&ehcic[index].hccr->cr_capbase)); |
Remy Böhmer | c0d722f | 2008-12-13 22:51:58 +0100 | [diff] [blame] | 1046 | printf("USB EHCI %x.%02x\n", reg >> 8, reg & 0xff); |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1047 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1048 | ehcic[index].rootdev = 0; |
Troy Kisky | 127efc4 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 1049 | done: |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1050 | *controller = &ehcic[index]; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | int |
| 1055 | submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 1056 | int length) |
| 1057 | { |
| 1058 | |
| 1059 | if (usb_pipetype(pipe) != PIPE_BULK) { |
| 1060 | debug("non-bulk pipe (type=%lu)", usb_pipetype(pipe)); |
| 1061 | return -1; |
| 1062 | } |
| 1063 | return ehci_submit_async(dev, pipe, buffer, length, NULL); |
| 1064 | } |
| 1065 | |
| 1066 | int |
| 1067 | submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 1068 | int length, struct devrequest *setup) |
| 1069 | { |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1070 | struct ehci_ctrl *ctrl = dev->controller; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1071 | |
| 1072 | if (usb_pipetype(pipe) != PIPE_CONTROL) { |
| 1073 | debug("non-control pipe (type=%lu)", usb_pipetype(pipe)); |
| 1074 | return -1; |
| 1075 | } |
| 1076 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 1077 | if (usb_pipedevice(pipe) == ctrl->rootdev) { |
| 1078 | if (!ctrl->rootdev) |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1079 | dev->speed = USB_SPEED_HIGH; |
| 1080 | return ehci_submit_root(dev, pipe, buffer, length, setup); |
| 1081 | } |
| 1082 | return ehci_submit_async(dev, pipe, buffer, length, setup); |
| 1083 | } |
| 1084 | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1085 | struct int_queue { |
| 1086 | struct QH *first; |
| 1087 | struct QH *current; |
| 1088 | struct QH *last; |
| 1089 | struct qTD *tds; |
| 1090 | }; |
| 1091 | |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1092 | #define NEXT_QH(qh) (struct QH *)(hc32_to_cpu((qh)->qh_link) & ~0x1f) |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1093 | |
| 1094 | static int |
| 1095 | enable_periodic(struct ehci_ctrl *ctrl) |
| 1096 | { |
| 1097 | uint32_t cmd; |
| 1098 | struct ehci_hcor *hcor = ctrl->hcor; |
| 1099 | int ret; |
| 1100 | |
| 1101 | cmd = ehci_readl(&hcor->or_usbcmd); |
| 1102 | cmd |= CMD_PSE; |
| 1103 | ehci_writel(&hcor->or_usbcmd, cmd); |
| 1104 | |
| 1105 | ret = handshake((uint32_t *)&hcor->or_usbsts, |
| 1106 | STS_PSS, STS_PSS, 100 * 1000); |
| 1107 | if (ret < 0) { |
| 1108 | printf("EHCI failed: timeout when enabling periodic list\n"); |
| 1109 | return -ETIMEDOUT; |
| 1110 | } |
| 1111 | udelay(1000); |
| 1112 | return 0; |
| 1113 | } |
| 1114 | |
| 1115 | static int |
| 1116 | disable_periodic(struct ehci_ctrl *ctrl) |
| 1117 | { |
| 1118 | uint32_t cmd; |
| 1119 | struct ehci_hcor *hcor = ctrl->hcor; |
| 1120 | int ret; |
| 1121 | |
| 1122 | cmd = ehci_readl(&hcor->or_usbcmd); |
| 1123 | cmd &= ~CMD_PSE; |
| 1124 | ehci_writel(&hcor->or_usbcmd, cmd); |
| 1125 | |
| 1126 | ret = handshake((uint32_t *)&hcor->or_usbsts, |
| 1127 | STS_PSS, 0, 100 * 1000); |
| 1128 | if (ret < 0) { |
| 1129 | printf("EHCI failed: timeout when disabling periodic list\n"); |
| 1130 | return -ETIMEDOUT; |
| 1131 | } |
| 1132 | return 0; |
| 1133 | } |
| 1134 | |
| 1135 | static int periodic_schedules; |
| 1136 | |
| 1137 | struct int_queue * |
| 1138 | create_int_queue(struct usb_device *dev, unsigned long pipe, int queuesize, |
| 1139 | int elementsize, void *buffer) |
| 1140 | { |
| 1141 | struct ehci_ctrl *ctrl = dev->controller; |
| 1142 | struct int_queue *result = NULL; |
| 1143 | int i; |
| 1144 | |
| 1145 | debug("Enter create_int_queue\n"); |
| 1146 | if (usb_pipetype(pipe) != PIPE_INTERRUPT) { |
| 1147 | debug("non-interrupt pipe (type=%lu)", usb_pipetype(pipe)); |
| 1148 | return NULL; |
| 1149 | } |
| 1150 | |
| 1151 | /* limit to 4 full pages worth of data - |
| 1152 | * we can safely fit them in a single TD, |
| 1153 | * no matter the alignment |
| 1154 | */ |
| 1155 | if (elementsize >= 16384) { |
| 1156 | debug("too large elements for interrupt transfers\n"); |
| 1157 | return NULL; |
| 1158 | } |
| 1159 | |
| 1160 | result = malloc(sizeof(*result)); |
| 1161 | if (!result) { |
| 1162 | debug("ehci intr queue: out of memory\n"); |
| 1163 | goto fail1; |
| 1164 | } |
Stephen Warren | 8165e34 | 2014-02-06 13:13:06 -0700 | [diff] [blame] | 1165 | result->first = memalign(USB_DMA_MINALIGN, |
| 1166 | sizeof(struct QH) * queuesize); |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1167 | if (!result->first) { |
| 1168 | debug("ehci intr queue: out of memory\n"); |
| 1169 | goto fail2; |
| 1170 | } |
| 1171 | result->current = result->first; |
| 1172 | result->last = result->first + queuesize - 1; |
Stephen Warren | 8165e34 | 2014-02-06 13:13:06 -0700 | [diff] [blame] | 1173 | result->tds = memalign(USB_DMA_MINALIGN, |
| 1174 | sizeof(struct qTD) * queuesize); |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1175 | if (!result->tds) { |
| 1176 | debug("ehci intr queue: out of memory\n"); |
| 1177 | goto fail3; |
| 1178 | } |
| 1179 | memset(result->first, 0, sizeof(struct QH) * queuesize); |
| 1180 | memset(result->tds, 0, sizeof(struct qTD) * queuesize); |
| 1181 | |
| 1182 | for (i = 0; i < queuesize; i++) { |
| 1183 | struct QH *qh = result->first + i; |
| 1184 | struct qTD *td = result->tds + i; |
| 1185 | void **buf = &qh->buffer; |
| 1186 | |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1187 | qh->qh_link = cpu_to_hc32((uint32_t)(qh+1) | QH_LINK_TYPE_QH); |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1188 | if (i == queuesize - 1) |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1189 | qh->qh_link = cpu_to_hc32(QH_LINK_TERMINATE); |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1190 | |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1191 | qh->qh_overlay.qt_next = cpu_to_hc32((uint32_t)td); |
| 1192 | qh->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); |
| 1193 | qh->qh_endpt1 = |
| 1194 | cpu_to_hc32((0 << 28) | /* No NAK reload (ehci 4.9) */ |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1195 | (usb_maxpacket(dev, pipe) << 16) | /* MPS */ |
| 1196 | (1 << 14) | |
| 1197 | QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)) | |
| 1198 | (usb_pipeendpoint(pipe) << 8) | /* Endpoint Number */ |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1199 | (usb_pipedevice(pipe) << 0)); |
| 1200 | qh->qh_endpt2 = cpu_to_hc32((1 << 30) | /* 1 Tx per mframe */ |
| 1201 | (1 << 0)); /* S-mask: microframe 0 */ |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1202 | if (dev->speed == USB_SPEED_LOW || |
| 1203 | dev->speed == USB_SPEED_FULL) { |
| 1204 | debug("TT: port: %d, hub address: %d\n", |
| 1205 | dev->portnr, dev->parent->devnum); |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1206 | qh->qh_endpt2 |= cpu_to_hc32((dev->portnr << 23) | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1207 | (dev->parent->devnum << 16) | |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1208 | (0x1c << 8)); /* C-mask: microframes 2-4 */ |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1211 | td->qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); |
| 1212 | td->qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1213 | debug("communication direction is '%s'\n", |
| 1214 | usb_pipein(pipe) ? "in" : "out"); |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1215 | td->qt_token = cpu_to_hc32((elementsize << 16) | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1216 | ((usb_pipein(pipe) ? 1 : 0) << 8) | /* IN/OUT token */ |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1217 | 0x80); /* active */ |
| 1218 | td->qt_buffer[0] = |
| 1219 | cpu_to_hc32((uint32_t)buffer + i * elementsize); |
| 1220 | td->qt_buffer[1] = |
| 1221 | cpu_to_hc32((td->qt_buffer[0] + 0x1000) & ~0xfff); |
| 1222 | td->qt_buffer[2] = |
| 1223 | cpu_to_hc32((td->qt_buffer[0] + 0x2000) & ~0xfff); |
| 1224 | td->qt_buffer[3] = |
| 1225 | cpu_to_hc32((td->qt_buffer[0] + 0x3000) & ~0xfff); |
| 1226 | td->qt_buffer[4] = |
| 1227 | cpu_to_hc32((td->qt_buffer[0] + 0x4000) & ~0xfff); |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1228 | |
| 1229 | *buf = buffer + i * elementsize; |
| 1230 | } |
| 1231 | |
Stephen Warren | d3e0747 | 2013-05-24 15:03:17 -0600 | [diff] [blame] | 1232 | flush_dcache_range((uint32_t)buffer, |
| 1233 | ALIGN_END_ADDR(char, buffer, |
| 1234 | queuesize * elementsize)); |
| 1235 | flush_dcache_range((uint32_t)result->first, |
| 1236 | ALIGN_END_ADDR(struct QH, result->first, |
| 1237 | queuesize)); |
| 1238 | flush_dcache_range((uint32_t)result->tds, |
| 1239 | ALIGN_END_ADDR(struct qTD, result->tds, |
| 1240 | queuesize)); |
| 1241 | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1242 | if (disable_periodic(ctrl) < 0) { |
| 1243 | debug("FATAL: periodic should never fail, but did"); |
| 1244 | goto fail3; |
| 1245 | } |
| 1246 | |
| 1247 | /* hook up to periodic list */ |
| 1248 | struct QH *list = &ctrl->periodic_queue; |
| 1249 | result->last->qh_link = list->qh_link; |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1250 | list->qh_link = cpu_to_hc32((uint32_t)result->first | QH_LINK_TYPE_QH); |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1251 | |
Stephen Warren | d3e0747 | 2013-05-24 15:03:17 -0600 | [diff] [blame] | 1252 | flush_dcache_range((uint32_t)result->last, |
| 1253 | ALIGN_END_ADDR(struct QH, result->last, 1)); |
| 1254 | flush_dcache_range((uint32_t)list, |
| 1255 | ALIGN_END_ADDR(struct QH, list, 1)); |
| 1256 | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1257 | if (enable_periodic(ctrl) < 0) { |
| 1258 | debug("FATAL: periodic should never fail, but did"); |
| 1259 | goto fail3; |
| 1260 | } |
| 1261 | periodic_schedules++; |
| 1262 | |
| 1263 | debug("Exit create_int_queue\n"); |
| 1264 | return result; |
| 1265 | fail3: |
| 1266 | if (result->tds) |
| 1267 | free(result->tds); |
| 1268 | fail2: |
| 1269 | if (result->first) |
| 1270 | free(result->first); |
| 1271 | if (result) |
| 1272 | free(result); |
| 1273 | fail1: |
| 1274 | return NULL; |
| 1275 | } |
| 1276 | |
| 1277 | void *poll_int_queue(struct usb_device *dev, struct int_queue *queue) |
| 1278 | { |
| 1279 | struct QH *cur = queue->current; |
| 1280 | |
| 1281 | /* depleted queue */ |
| 1282 | if (cur == NULL) { |
| 1283 | debug("Exit poll_int_queue with completed queue\n"); |
| 1284 | return NULL; |
| 1285 | } |
| 1286 | /* still active */ |
Stephen Warren | d3e0747 | 2013-05-24 15:03:17 -0600 | [diff] [blame] | 1287 | invalidate_dcache_range((uint32_t)cur, |
| 1288 | ALIGN_END_ADDR(struct QH, cur, 1)); |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1289 | if (cur->qh_overlay.qt_token & cpu_to_hc32(0x80)) { |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1290 | debug("Exit poll_int_queue with no completed intr transfer. " |
| 1291 | "token is %x\n", cur->qh_overlay.qt_token); |
| 1292 | return NULL; |
| 1293 | } |
| 1294 | if (!(cur->qh_link & QH_LINK_TERMINATE)) |
| 1295 | queue->current++; |
| 1296 | else |
| 1297 | queue->current = NULL; |
| 1298 | debug("Exit poll_int_queue with completed intr transfer. " |
| 1299 | "token is %x at %p (first at %p)\n", cur->qh_overlay.qt_token, |
| 1300 | &cur->qh_overlay.qt_token, queue->first); |
| 1301 | return cur->buffer; |
| 1302 | } |
| 1303 | |
| 1304 | /* Do not free buffers associated with QHs, they're owned by someone else */ |
| 1305 | int |
| 1306 | destroy_int_queue(struct usb_device *dev, struct int_queue *queue) |
| 1307 | { |
| 1308 | struct ehci_ctrl *ctrl = dev->controller; |
| 1309 | int result = -1; |
| 1310 | unsigned long timeout; |
| 1311 | |
| 1312 | if (disable_periodic(ctrl) < 0) { |
| 1313 | debug("FATAL: periodic should never fail, but did"); |
| 1314 | goto out; |
| 1315 | } |
| 1316 | periodic_schedules--; |
| 1317 | |
| 1318 | struct QH *cur = &ctrl->periodic_queue; |
| 1319 | timeout = get_timer(0) + 500; /* abort after 500ms */ |
Adrian Cox | ea42777 | 2014-04-10 13:29:45 +0100 | [diff] [blame^] | 1320 | while (!(cur->qh_link & cpu_to_hc32(QH_LINK_TERMINATE))) { |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1321 | debug("considering %p, with qh_link %x\n", cur, cur->qh_link); |
| 1322 | if (NEXT_QH(cur) == queue->first) { |
| 1323 | debug("found candidate. removing from chain\n"); |
| 1324 | cur->qh_link = queue->last->qh_link; |
| 1325 | result = 0; |
| 1326 | break; |
| 1327 | } |
| 1328 | cur = NEXT_QH(cur); |
| 1329 | if (get_timer(0) > timeout) { |
| 1330 | printf("Timeout destroying interrupt endpoint queue\n"); |
| 1331 | result = -1; |
| 1332 | goto out; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | if (periodic_schedules > 0) { |
| 1337 | result = enable_periodic(ctrl); |
| 1338 | if (result < 0) |
| 1339 | debug("FATAL: periodic should never fail, but did"); |
| 1340 | } |
| 1341 | |
| 1342 | out: |
| 1343 | free(queue->tds); |
| 1344 | free(queue->first); |
| 1345 | free(queue); |
| 1346 | |
| 1347 | return result; |
| 1348 | } |
| 1349 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1350 | int |
| 1351 | submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
| 1352 | int length, int interval) |
| 1353 | { |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1354 | void *backbuffer; |
| 1355 | struct int_queue *queue; |
| 1356 | unsigned long timeout; |
| 1357 | int result = 0, ret; |
| 1358 | |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1359 | debug("dev=%p, pipe=%lu, buffer=%p, length=%d, interval=%d", |
| 1360 | dev, pipe, buffer, length, interval); |
Benoît Thébaudeau | 44ae0be | 2012-08-09 23:50:44 +0200 | [diff] [blame] | 1361 | |
| 1362 | /* |
| 1363 | * Interrupt transfers requiring several transactions are not supported |
| 1364 | * because bInterval is ignored. |
Benoît Thébaudeau | 5cec214 | 2012-08-10 18:22:32 +0200 | [diff] [blame] | 1365 | * |
| 1366 | * Also, ehci_submit_async() relies on wMaxPacketSize being a power of 2 |
Benoît Thébaudeau | db19134 | 2012-08-10 18:27:23 +0200 | [diff] [blame] | 1367 | * <= PKT_ALIGN if several qTDs are required, while the USB |
| 1368 | * specification does not constrain this for interrupt transfers. That |
| 1369 | * means that ehci_submit_async() would support interrupt transfers |
| 1370 | * requiring several transactions only as long as the transfer size does |
| 1371 | * not require more than a single qTD. |
Benoît Thébaudeau | 44ae0be | 2012-08-09 23:50:44 +0200 | [diff] [blame] | 1372 | */ |
| 1373 | if (length > usb_maxpacket(dev, pipe)) { |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1374 | printf("%s: Interrupt transfers requiring several " |
| 1375 | "transactions are not supported.\n", __func__); |
Benoît Thébaudeau | 44ae0be | 2012-08-09 23:50:44 +0200 | [diff] [blame] | 1376 | return -1; |
| 1377 | } |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1378 | |
| 1379 | queue = create_int_queue(dev, pipe, 1, length, buffer); |
| 1380 | |
| 1381 | timeout = get_timer(0) + USB_TIMEOUT_MS(pipe); |
| 1382 | while ((backbuffer = poll_int_queue(dev, queue)) == NULL) |
| 1383 | if (get_timer(0) > timeout) { |
| 1384 | printf("Timeout poll on interrupt endpoint\n"); |
| 1385 | result = -ETIMEDOUT; |
| 1386 | break; |
| 1387 | } |
| 1388 | |
| 1389 | if (backbuffer != buffer) { |
| 1390 | debug("got wrong buffer back (%x instead of %x)\n", |
| 1391 | (uint32_t)backbuffer, (uint32_t)buffer); |
| 1392 | return -EINVAL; |
| 1393 | } |
| 1394 | |
Stephen Warren | d3e0747 | 2013-05-24 15:03:17 -0600 | [diff] [blame] | 1395 | invalidate_dcache_range((uint32_t)buffer, |
| 1396 | ALIGN_END_ADDR(char, buffer, length)); |
| 1397 | |
Patrick Georgi | 8f62ca6 | 2013-03-06 14:08:31 +0000 | [diff] [blame] | 1398 | ret = destroy_int_queue(dev, queue); |
| 1399 | if (ret < 0) |
| 1400 | return ret; |
| 1401 | |
| 1402 | /* everything worked out fine */ |
| 1403 | return result; |
Michael Trimarchi | aaf098c | 2008-11-28 13:20:46 +0100 | [diff] [blame] | 1404 | } |