blob: 020c5c8ff5a3f4ab1d6649e4964e4de99fd2f7f7 [file] [log] [blame]
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001/*-
2 * Copyright (c) 2007-2008, Juniper Networks, Inc.
michaeldb632992008-12-10 17:55:19 +01003 * Copyright (c) 2008, Excito Elektronik i Skåne AB
Remy Böhmerc0d722f2008-12-13 22:51:58 +01004 * Copyright (c) 2008, Michael Trimarchi <trimarchimichael@yahoo.it>
5 *
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01006 * 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 Trimarchiaaf098c2008-11-28 13:20:46 +010023#include <common.h>
Patrick Georgi8f62ca62013-03-06 14:08:31 +000024#include <errno.h>
michaeldb632992008-12-10 17:55:19 +010025#include <asm/byteorder.h>
Lucas Stach93ad9082012-09-06 08:00:13 +020026#include <asm/unaligned.h>
Michael Trimarchiaaf098c2008-11-28 13:20:46 +010027#include <usb.h>
28#include <asm/io.h>
michaeldb632992008-12-10 17:55:19 +010029#include <malloc.h>
Stefan Roese67333f72010-11-26 15:43:28 +010030#include <watchdog.h>
Patrick Georgi8f62ca62013-03-06 14:08:31 +000031#include <linux/compiler.h>
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020032
33#include "ehci.h"
Michael Trimarchiaaf098c2008-11-28 13:20:46 +010034
Lucas Stach676ae062012-09-26 00:14:35 +020035#ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
36#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
37#endif
Michael Trimarchiaaf098c2008-11-28 13:20:46 +010038
Julius Werner5077f962013-09-24 10:53:07 -070039/*
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 Vasutb9596552013-07-10 03:16:31 +020045static struct ehci_ctrl ehcic[CONFIG_USB_MAX_CONTROLLER_COUNT];
Tom Rini71c5de42012-07-15 22:14:24 +000046
47#define ALIGN_END_ADDR(type, ptr, size) \
Rob Herring98ae8402015-03-17 15:46:37 -050048 ((unsigned long)(ptr) + roundup((size) * sizeof(type), USB_DMA_MINALIGN))
Michael Trimarchiaaf098c2008-11-28 13:20:46 +010049
michaeldb632992008-12-10 17:55:19 +010050static 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 Palatin5f4b4f22011-12-05 14:52:22 -080062 10, /* bPwrOn2PwrGood */
michaeldb632992008-12-10 17:55:19 +010063 0, /* bHubCntrCurrent */
64 {}, /* Device removable */
65 {} /* at most 7 ports! XXX */
66 },
67 {
68 0x12, /* bLength */
69 1, /* bDescriptorType: UDESC_DEVICE */
Sergei Shtylyov6d313c82010-02-27 21:29:42 +030070 cpu_to_le16(0x0200), /* bcdUSB: v2.0 */
michaeldb632992008-12-10 17:55:19 +010071 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 Shtylyov6d313c82010-02-27 21:29:42 +030077 cpu_to_le16(0x0100), /* bcdDevice */
michaeldb632992008-12-10 17:55:19 +010078 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 Rix8f8bd562009-10-31 12:37:38 -0500111 8, /* wMaxPacketSize */
michaeldb632992008-12-10 17:55:19 +0100112 255 /* bInterval */
113 },
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100114};
115
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100116#if defined(CONFIG_EHCI_IS_TDI)
117#define ehci_is_TDI() (1)
118#else
119#define ehci_is_TDI() (0)
120#endif
121
Simon Glass24ed8942015-03-25 12:22:25 -0600122static struct ehci_ctrl *ehci_get_ctrl(struct usb_device *udev)
123{
124 return udev->controller;
125}
126
Simon Glass73382872015-03-25 12:22:18 -0600127__weak int ehci_get_port_speed(struct ehci_ctrl *ctrl, uint32_t reg)
Jim Linb068deb2013-03-27 00:52:32 +0000128{
129 return PORTSC_PSPD(reg);
130}
131
Simon Glass11d18a12015-03-25 12:22:23 -0600132__weak void ehci_set_usbmode(struct ehci_ctrl *ctrl)
Jim Linb068deb2013-03-27 00:52:32 +0000133{
134 uint32_t tmp;
135 uint32_t *reg_ptr;
136
Simon Glass11d18a12015-03-25 12:22:23 -0600137 reg_ptr = (uint32_t *)((u8 *)&ctrl->hcor->or_usbcmd + USBMODE);
Jim Linb068deb2013-03-27 00:52:32 +0000138 tmp = ehci_readl(reg_ptr);
139 tmp |= USBMODE_CM_HC;
140#if defined(CONFIG_EHCI_MMIO_BIG_ENDIAN)
141 tmp |= USBMODE_BE;
142#endif
143 ehci_writel(reg_ptr, tmp);
144}
145
Simon Glass727fce32015-03-25 12:22:21 -0600146__weak void ehci_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg,
147 uint32_t *reg)
Marek Vasut3874b6d2011-07-11 02:37:01 +0200148{
149 mdelay(50);
150}
151
Simon Glass6a1a8162015-03-25 12:22:24 -0600152__weak uint32_t *ehci_get_portsc_register(struct ehci_ctrl *ctrl, int port)
Simon Glassaac064f2015-03-25 12:22:17 -0600153{
154 if (port < 0 || port >= CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS) {
155 /* Printing the message would cause a scan failure! */
156 debug("The request port(%u) is not configured\n", port);
157 return NULL;
158 }
159
Simon Glass6a1a8162015-03-25 12:22:24 -0600160 return (uint32_t *)&ctrl->hcor->or_portsc[port];
Simon Glassaac064f2015-03-25 12:22:17 -0600161}
162
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100163static int handshake(uint32_t *ptr, uint32_t mask, uint32_t done, int usec)
michaeldb632992008-12-10 17:55:19 +0100164{
michael51ab1422008-12-11 13:43:55 +0100165 uint32_t result;
166 do {
167 result = ehci_readl(ptr);
Wolfgang Denk09c83a42010-10-22 14:23:00 +0200168 udelay(5);
michael51ab1422008-12-11 13:43:55 +0100169 if (result == ~(uint32_t)0)
170 return -1;
171 result &= mask;
172 if (result == done)
173 return 0;
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100174 usec--;
175 } while (usec > 0);
michael51ab1422008-12-11 13:43:55 +0100176 return -1;
177}
178
Lucas Stach676ae062012-09-26 00:14:35 +0200179static int ehci_reset(int index)
michael51ab1422008-12-11 13:43:55 +0100180{
181 uint32_t cmd;
michael51ab1422008-12-11 13:43:55 +0100182 int ret = 0;
183
Lucas Stach676ae062012-09-26 00:14:35 +0200184 cmd = ehci_readl(&ehcic[index].hcor->or_usbcmd);
Stefan Roese273d7202010-11-26 15:44:00 +0100185 cmd = (cmd & ~CMD_RUN) | CMD_RESET;
Lucas Stach676ae062012-09-26 00:14:35 +0200186 ehci_writel(&ehcic[index].hcor->or_usbcmd, cmd);
187 ret = handshake((uint32_t *)&ehcic[index].hcor->or_usbcmd,
188 CMD_RESET, 0, 250 * 1000);
michael51ab1422008-12-11 13:43:55 +0100189 if (ret < 0) {
190 printf("EHCI fail to reset\n");
191 goto out;
192 }
193
Jim Linb068deb2013-03-27 00:52:32 +0000194 if (ehci_is_TDI())
Simon Glass11d18a12015-03-25 12:22:23 -0600195 ehci_set_usbmode(&ehcic[index]);
Simon Glass9ab4ce22012-02-27 10:52:47 +0000196
197#ifdef CONFIG_USB_EHCI_TXFIFO_THRESH
Lucas Stach676ae062012-09-26 00:14:35 +0200198 cmd = ehci_readl(&ehcic[index].hcor->or_txfilltuning);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200199 cmd &= ~TXFIFO_THRESH_MASK;
Simon Glass9ab4ce22012-02-27 10:52:47 +0000200 cmd |= TXFIFO_THRESH(CONFIG_USB_EHCI_TXFIFO_THRESH);
Lucas Stach676ae062012-09-26 00:14:35 +0200201 ehci_writel(&ehcic[index].hcor->or_txfilltuning, cmd);
Simon Glass9ab4ce22012-02-27 10:52:47 +0000202#endif
michael51ab1422008-12-11 13:43:55 +0100203out:
204 return ret;
michaeldb632992008-12-10 17:55:19 +0100205}
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100206
Julius Werner5077f962013-09-24 10:53:07 -0700207static int ehci_shutdown(struct ehci_ctrl *ctrl)
208{
209 int i, ret = 0;
210 uint32_t cmd, reg;
211
Marek Vasut1e1be6d2013-12-14 02:03:11 +0100212 if (!ctrl || !ctrl->hcor)
213 return -EINVAL;
214
Julius Werner5077f962013-09-24 10:53:07 -0700215 cmd = ehci_readl(&ctrl->hcor->or_usbcmd);
216 cmd &= ~(CMD_PSE | CMD_ASE);
217 ehci_writel(&ctrl->hcor->or_usbcmd, cmd);
218 ret = handshake(&ctrl->hcor->or_usbsts, STS_ASS | STS_PSS, 0,
219 100 * 1000);
220
221 if (!ret) {
222 for (i = 0; i < CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS; i++) {
223 reg = ehci_readl(&ctrl->hcor->or_portsc[i]);
224 reg |= EHCI_PS_SUSP;
225 ehci_writel(&ctrl->hcor->or_portsc[i], reg);
226 }
227
228 cmd &= ~CMD_RUN;
229 ehci_writel(&ctrl->hcor->or_usbcmd, cmd);
230 ret = handshake(&ctrl->hcor->or_usbsts, STS_HALT, STS_HALT,
231 HCHALT_TIMEOUT);
232 }
233
234 if (ret)
235 puts("EHCI failed to shut down host controller.\n");
236
237 return ret;
238}
239
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100240static int ehci_td_buffer(struct qTD *td, void *buf, size_t sz)
241{
Marek Vasutb8adb122012-04-09 04:07:46 +0200242 uint32_t delta, next;
Rob Herring98ae8402015-03-17 15:46:37 -0500243 uint32_t addr = (unsigned long)buf;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100244 int idx;
245
Ilya Yanok189a6952012-07-15 04:43:49 +0000246 if (addr != ALIGN(addr, ARCH_DMA_MINALIGN))
Marek Vasutb8adb122012-04-09 04:07:46 +0200247 debug("EHCI-HCD: Misaligned buffer address (%p)\n", buf);
248
Ilya Yanok189a6952012-07-15 04:43:49 +0000249 flush_dcache_range(addr, ALIGN(addr + sz, ARCH_DMA_MINALIGN));
250
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100251 idx = 0;
Benoît Thébaudeaucdeb9162012-07-19 22:16:38 +0200252 while (idx < QT_BUFFER_CNT) {
michaeldb632992008-12-10 17:55:19 +0100253 td->qt_buffer[idx] = cpu_to_hc32(addr);
Wolfgang Denk3ed16072010-10-19 16:13:15 +0200254 td->qt_buffer_hi[idx] = 0;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200255 next = (addr + EHCI_PAGE_SIZE) & ~(EHCI_PAGE_SIZE - 1);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100256 delta = next - addr;
257 if (delta >= sz)
258 break;
259 sz -= delta;
260 addr = next;
261 idx++;
262 }
263
Benoît Thébaudeaucdeb9162012-07-19 22:16:38 +0200264 if (idx == QT_BUFFER_CNT) {
Rob Herring98ae8402015-03-17 15:46:37 -0500265 printf("out of buffer pointers (%zu bytes left)\n", sz);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100266 return -1;
267 }
268
269 return 0;
270}
271
Ilya Yanokc60795f2012-11-06 13:48:20 +0000272static inline u8 ehci_encode_speed(enum usb_device_speed speed)
273{
274 #define QH_HIGH_SPEED 2
275 #define QH_FULL_SPEED 0
276 #define QH_LOW_SPEED 1
277 if (speed == USB_SPEED_HIGH)
278 return QH_HIGH_SPEED;
279 if (speed == USB_SPEED_LOW)
280 return QH_LOW_SPEED;
281 return QH_FULL_SPEED;
282}
283
Hans de Goede4e2c4ad2014-09-20 16:51:22 +0200284static void ehci_update_endpt2_dev_n_port(struct usb_device *dev,
285 struct QH *qh)
286{
287 struct usb_device *ttdev;
288
289 if (dev->speed != USB_SPEED_LOW && dev->speed != USB_SPEED_FULL)
290 return;
291
292 /*
293 * For full / low speed devices we need to get the devnum and portnr of
294 * the tt, so of the first upstream usb-2 hub, there may be usb-1 hubs
295 * in the tree before that one!
296 */
297 ttdev = dev;
298 while (ttdev->parent && ttdev->parent->speed != USB_SPEED_HIGH)
299 ttdev = ttdev->parent;
300 if (!ttdev->parent)
301 return;
302
303 qh->qh_endpt2 |= cpu_to_hc32(QH_ENDPT2_PORTNUM(ttdev->portnr) |
304 QH_ENDPT2_HUBADDR(ttdev->parent->devnum));
305}
306
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100307static int
308ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
309 int length, struct devrequest *req)
310{
Tom Rini71c5de42012-07-15 22:14:24 +0000311 ALLOC_ALIGN_BUFFER(struct QH, qh, 1, USB_DMA_MINALIGN);
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200312 struct qTD *qtd;
313 int qtd_count = 0;
Marek Vasutde98e8b2012-04-08 23:32:05 +0200314 int qtd_counter = 0;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100315 volatile struct qTD *vtd;
316 unsigned long ts;
317 uint32_t *tdp;
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200318 uint32_t endpt, maxpacket, token, usbsts;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100319 uint32_t c, toggle;
michaeldb632992008-12-10 17:55:19 +0100320 uint32_t cmd;
Simon Glass96820a32011-02-07 14:42:16 -0800321 int timeout;
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100322 int ret = 0;
Simon Glass24ed8942015-03-25 12:22:25 -0600323 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100324
michaeldb632992008-12-10 17:55:19 +0100325 debug("dev=%p, pipe=%lx, buffer=%p, length=%d, req=%p\n", dev, pipe,
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100326 buffer, length, req);
327 if (req != NULL)
michaeldb632992008-12-10 17:55:19 +0100328 debug("req=%u (%#x), type=%u (%#x), value=%u (%#x), index=%u\n",
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100329 req->request, req->request,
330 req->requesttype, req->requesttype,
331 le16_to_cpu(req->value), le16_to_cpu(req->value),
michaeldb632992008-12-10 17:55:19 +0100332 le16_to_cpu(req->index));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100333
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200334#define PKT_ALIGN 512
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200335 /*
336 * The USB transfer is split into qTD transfers. Eeach qTD transfer is
337 * described by a transfer descriptor (the qTD). The qTDs form a linked
338 * list with a queue head (QH).
339 *
340 * Each qTD transfer starts with a new USB packet, i.e. a packet cannot
341 * have its beginning in a qTD transfer and its end in the following
342 * one, so the qTD transfer lengths have to be chosen accordingly.
343 *
344 * Each qTD transfer uses up to QT_BUFFER_CNT data buffers, mapped to
345 * single pages. The first data buffer can start at any offset within a
346 * page (not considering the cache-line alignment issues), while the
347 * following buffers must be page-aligned. There is no alignment
348 * constraint on the size of a qTD transfer.
349 */
350 if (req != NULL)
351 /* 1 qTD will be needed for SETUP, and 1 for ACK. */
352 qtd_count += 1 + 1;
353 if (length > 0 || req == NULL) {
354 /*
355 * Determine the qTD transfer size that will be used for the
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200356 * data payload (not considering the first qTD transfer, which
357 * may be longer or shorter, and the final one, which may be
358 * shorter).
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200359 *
360 * In order to keep each packet within a qTD transfer, the qTD
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200361 * transfer size is aligned to PKT_ALIGN, which is a multiple of
362 * wMaxPacketSize (except in some cases for interrupt transfers,
363 * see comment in submit_int_msg()).
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200364 *
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200365 * By default, i.e. if the input buffer is aligned to PKT_ALIGN,
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200366 * QT_BUFFER_CNT full pages will be used.
367 */
368 int xfr_sz = QT_BUFFER_CNT;
369 /*
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200370 * However, if the input buffer is not aligned to PKT_ALIGN, the
371 * qTD transfer size will be one page shorter, and the first qTD
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200372 * data buffer of each transfer will be page-unaligned.
373 */
Rob Herring98ae8402015-03-17 15:46:37 -0500374 if ((unsigned long)buffer & (PKT_ALIGN - 1))
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200375 xfr_sz--;
376 /* Convert the qTD transfer size to bytes. */
377 xfr_sz *= EHCI_PAGE_SIZE;
378 /*
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200379 * Approximate by excess the number of qTDs that will be
380 * required for the data payload. The exact formula is way more
381 * complicated and saves at most 2 qTDs, i.e. a total of 128
382 * bytes.
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200383 */
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200384 qtd_count += 2 + length / xfr_sz;
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200385 }
386/*
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200387 * Threshold value based on the worst-case total size of the allocated qTDs for
388 * a mass-storage transfer of 65535 blocks of 512 bytes.
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200389 */
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200390#if CONFIG_SYS_MALLOC_LEN <= 64 + 128 * 1024
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200391#warning CONFIG_SYS_MALLOC_LEN may be too small for EHCI
392#endif
393 qtd = memalign(USB_DMA_MINALIGN, qtd_count * sizeof(struct qTD));
394 if (qtd == NULL) {
395 printf("unable to allocate TDs\n");
396 return -1;
397 }
398
Tom Rini71c5de42012-07-15 22:14:24 +0000399 memset(qh, 0, sizeof(struct QH));
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200400 memset(qtd, 0, qtd_count * sizeof(*qtd));
Marek Vasutde98e8b2012-04-08 23:32:05 +0200401
Marek Vasutb8adb122012-04-09 04:07:46 +0200402 toggle = usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe));
403
Marek Vasut41b1f0a2012-04-09 04:13:00 +0200404 /*
405 * Setup QH (3.6 in ehci-r10.pdf)
406 *
407 * qh_link ................. 03-00 H
408 * qh_endpt1 ............... 07-04 H
409 * qh_endpt2 ............... 0B-08 H
410 * - qh_curtd
411 * qh_overlay.qt_next ...... 13-10 H
412 * - qh_overlay.qt_altnext
413 */
Rob Herring98ae8402015-03-17 15:46:37 -0500414 qh->qh_link = cpu_to_hc32((unsigned long)&ctrl->qh_list | QH_LINK_TYPE_QH);
Ilya Yanokc60795f2012-11-06 13:48:20 +0000415 c = (dev->speed != USB_SPEED_HIGH) && !usb_pipeendpoint(pipe);
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200416 maxpacket = usb_maxpacket(dev, pipe);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200417 endpt = QH_ENDPT1_RL(8) | QH_ENDPT1_C(c) |
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200418 QH_ENDPT1_MAXPKTLEN(maxpacket) | QH_ENDPT1_H(0) |
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200419 QH_ENDPT1_DTC(QH_ENDPT1_DTC_DT_FROM_QTD) |
Ilya Yanokc60795f2012-11-06 13:48:20 +0000420 QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)) |
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200421 QH_ENDPT1_ENDPT(usb_pipeendpoint(pipe)) | QH_ENDPT1_I(0) |
422 QH_ENDPT1_DEVADDR(usb_pipedevice(pipe));
Tom Rini71c5de42012-07-15 22:14:24 +0000423 qh->qh_endpt1 = cpu_to_hc32(endpt);
Hans de Goede4e2c4ad2014-09-20 16:51:22 +0200424 endpt = QH_ENDPT2_MULT(1) | QH_ENDPT2_UFCMASK(0) | QH_ENDPT2_UFSMASK(0);
Tom Rini71c5de42012-07-15 22:14:24 +0000425 qh->qh_endpt2 = cpu_to_hc32(endpt);
Hans de Goede4e2c4ad2014-09-20 16:51:22 +0200426 ehci_update_endpt2_dev_n_port(dev, qh);
Tom Rini71c5de42012-07-15 22:14:24 +0000427 qh->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
Stephen Warren2456b972014-02-07 09:53:50 -0700428 qh->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100429
Tom Rini71c5de42012-07-15 22:14:24 +0000430 tdp = &qh->qh_overlay.qt_next;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100431
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100432 if (req != NULL) {
Marek Vasut41b1f0a2012-04-09 04:13:00 +0200433 /*
434 * Setup request qTD (3.5 in ehci-r10.pdf)
435 *
436 * qt_next ................ 03-00 H
437 * qt_altnext ............. 07-04 H
438 * qt_token ............... 0B-08 H
439 *
440 * [ buffer, buffer_hi ] loaded with "req".
441 */
Marek Vasutde98e8b2012-04-08 23:32:05 +0200442 qtd[qtd_counter].qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
443 qtd[qtd_counter].qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200444 token = QT_TOKEN_DT(0) | QT_TOKEN_TOTALBYTES(sizeof(*req)) |
445 QT_TOKEN_IOC(0) | QT_TOKEN_CPAGE(0) | QT_TOKEN_CERR(3) |
446 QT_TOKEN_PID(QT_TOKEN_PID_SETUP) |
447 QT_TOKEN_STATUS(QT_TOKEN_STATUS_ACTIVE);
Marek Vasutde98e8b2012-04-08 23:32:05 +0200448 qtd[qtd_counter].qt_token = cpu_to_hc32(token);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200449 if (ehci_td_buffer(&qtd[qtd_counter], req, sizeof(*req))) {
450 printf("unable to construct SETUP TD\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100451 goto fail;
452 }
Marek Vasut41b1f0a2012-04-09 04:13:00 +0200453 /* Update previous qTD! */
Rob Herring98ae8402015-03-17 15:46:37 -0500454 *tdp = cpu_to_hc32((unsigned long)&qtd[qtd_counter]);
Marek Vasutde98e8b2012-04-08 23:32:05 +0200455 tdp = &qtd[qtd_counter++].qt_next;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100456 toggle = 1;
457 }
458
459 if (length > 0 || req == NULL) {
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200460 uint8_t *buf_ptr = buffer;
461 int left_length = length;
462
463 do {
464 /*
465 * Determine the size of this qTD transfer. By default,
466 * QT_BUFFER_CNT full pages can be used.
467 */
468 int xfr_bytes = QT_BUFFER_CNT * EHCI_PAGE_SIZE;
469 /*
470 * However, if the input buffer is not page-aligned, the
471 * portion of the first page before the buffer start
472 * offset within that page is unusable.
473 */
Rob Herring98ae8402015-03-17 15:46:37 -0500474 xfr_bytes -= (unsigned long)buf_ptr & (EHCI_PAGE_SIZE - 1);
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200475 /*
476 * In order to keep each packet within a qTD transfer,
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200477 * align the qTD transfer size to PKT_ALIGN.
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200478 */
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200479 xfr_bytes &= ~(PKT_ALIGN - 1);
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200480 /*
481 * This transfer may be shorter than the available qTD
482 * transfer size that has just been computed.
483 */
484 xfr_bytes = min(xfr_bytes, left_length);
485
486 /*
487 * Setup request qTD (3.5 in ehci-r10.pdf)
488 *
489 * qt_next ................ 03-00 H
490 * qt_altnext ............. 07-04 H
491 * qt_token ............... 0B-08 H
492 *
493 * [ buffer, buffer_hi ] loaded with "buffer".
494 */
495 qtd[qtd_counter].qt_next =
496 cpu_to_hc32(QT_NEXT_TERMINATE);
497 qtd[qtd_counter].qt_altnext =
498 cpu_to_hc32(QT_NEXT_TERMINATE);
499 token = QT_TOKEN_DT(toggle) |
500 QT_TOKEN_TOTALBYTES(xfr_bytes) |
501 QT_TOKEN_IOC(req == NULL) | QT_TOKEN_CPAGE(0) |
502 QT_TOKEN_CERR(3) |
503 QT_TOKEN_PID(usb_pipein(pipe) ?
504 QT_TOKEN_PID_IN : QT_TOKEN_PID_OUT) |
505 QT_TOKEN_STATUS(QT_TOKEN_STATUS_ACTIVE);
506 qtd[qtd_counter].qt_token = cpu_to_hc32(token);
507 if (ehci_td_buffer(&qtd[qtd_counter], buf_ptr,
508 xfr_bytes)) {
509 printf("unable to construct DATA TD\n");
510 goto fail;
511 }
512 /* Update previous qTD! */
Rob Herring98ae8402015-03-17 15:46:37 -0500513 *tdp = cpu_to_hc32((unsigned long)&qtd[qtd_counter]);
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200514 tdp = &qtd[qtd_counter++].qt_next;
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200515 /*
516 * Data toggle has to be adjusted since the qTD transfer
517 * size is not always an even multiple of
518 * wMaxPacketSize.
519 */
520 if ((xfr_bytes / maxpacket) & 1)
521 toggle ^= 1;
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200522 buf_ptr += xfr_bytes;
523 left_length -= xfr_bytes;
524 } while (left_length > 0);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100525 }
526
527 if (req != NULL) {
Marek Vasut41b1f0a2012-04-09 04:13:00 +0200528 /*
529 * Setup request qTD (3.5 in ehci-r10.pdf)
530 *
531 * qt_next ................ 03-00 H
532 * qt_altnext ............. 07-04 H
533 * qt_token ............... 0B-08 H
534 */
Marek Vasutde98e8b2012-04-08 23:32:05 +0200535 qtd[qtd_counter].qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
536 qtd[qtd_counter].qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
Benoît Thébaudeaudb191342012-08-10 18:27:23 +0200537 token = QT_TOKEN_DT(1) | QT_TOKEN_TOTALBYTES(0) |
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200538 QT_TOKEN_IOC(1) | QT_TOKEN_CPAGE(0) | QT_TOKEN_CERR(3) |
539 QT_TOKEN_PID(usb_pipein(pipe) ?
540 QT_TOKEN_PID_OUT : QT_TOKEN_PID_IN) |
541 QT_TOKEN_STATUS(QT_TOKEN_STATUS_ACTIVE);
Marek Vasutde98e8b2012-04-08 23:32:05 +0200542 qtd[qtd_counter].qt_token = cpu_to_hc32(token);
Marek Vasut41b1f0a2012-04-09 04:13:00 +0200543 /* Update previous qTD! */
Rob Herring98ae8402015-03-17 15:46:37 -0500544 *tdp = cpu_to_hc32((unsigned long)&qtd[qtd_counter]);
Marek Vasutde98e8b2012-04-08 23:32:05 +0200545 tdp = &qtd[qtd_counter++].qt_next;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100546 }
547
Rob Herring98ae8402015-03-17 15:46:37 -0500548 ctrl->qh_list.qh_link = cpu_to_hc32((unsigned long)qh | QH_LINK_TYPE_QH);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100549
Stefan Roesedaa2daf2009-01-21 17:12:19 +0100550 /* Flush dcache */
Rob Herring98ae8402015-03-17 15:46:37 -0500551 flush_dcache_range((unsigned long)&ctrl->qh_list,
Lucas Stach676ae062012-09-26 00:14:35 +0200552 ALIGN_END_ADDR(struct QH, &ctrl->qh_list, 1));
Rob Herring98ae8402015-03-17 15:46:37 -0500553 flush_dcache_range((unsigned long)qh, ALIGN_END_ADDR(struct QH, qh, 1));
554 flush_dcache_range((unsigned long)qtd,
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200555 ALIGN_END_ADDR(struct qTD, qtd, qtd_count));
Stefan Roesedaa2daf2009-01-21 17:12:19 +0100556
Ilya Yanokc7701af2012-07-15 22:12:08 +0000557 /* Set async. queue head pointer. */
Rob Herring98ae8402015-03-17 15:46:37 -0500558 ehci_writel(&ctrl->hcor->or_asynclistaddr, (unsigned long)&ctrl->qh_list);
Ilya Yanokc7701af2012-07-15 22:12:08 +0000559
Lucas Stach676ae062012-09-26 00:14:35 +0200560 usbsts = ehci_readl(&ctrl->hcor->or_usbsts);
561 ehci_writel(&ctrl->hcor->or_usbsts, (usbsts & 0x3f));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100562
563 /* Enable async. schedule. */
Lucas Stach676ae062012-09-26 00:14:35 +0200564 cmd = ehci_readl(&ctrl->hcor->or_usbcmd);
michael51ab1422008-12-11 13:43:55 +0100565 cmd |= CMD_ASE;
Lucas Stach676ae062012-09-26 00:14:35 +0200566 ehci_writel(&ctrl->hcor->or_usbcmd, cmd);
michaeldb632992008-12-10 17:55:19 +0100567
Lucas Stach676ae062012-09-26 00:14:35 +0200568 ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, STS_ASS,
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100569 100 * 1000);
570 if (ret < 0) {
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200571 printf("EHCI fail timeout STS_ASS set\n");
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100572 goto fail;
michael51ab1422008-12-11 13:43:55 +0100573 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100574
575 /* Wait for TDs to be processed. */
576 ts = get_timer(0);
Marek Vasutde98e8b2012-04-08 23:32:05 +0200577 vtd = &qtd[qtd_counter - 1];
Simon Glass96820a32011-02-07 14:42:16 -0800578 timeout = USB_TIMEOUT_MS(pipe);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100579 do {
Stefan Roesedaa2daf2009-01-21 17:12:19 +0100580 /* Invalidate dcache */
Rob Herring98ae8402015-03-17 15:46:37 -0500581 invalidate_dcache_range((unsigned long)&ctrl->qh_list,
Lucas Stach676ae062012-09-26 00:14:35 +0200582 ALIGN_END_ADDR(struct QH, &ctrl->qh_list, 1));
Rob Herring98ae8402015-03-17 15:46:37 -0500583 invalidate_dcache_range((unsigned long)qh,
Tom Rini71c5de42012-07-15 22:14:24 +0000584 ALIGN_END_ADDR(struct QH, qh, 1));
Rob Herring98ae8402015-03-17 15:46:37 -0500585 invalidate_dcache_range((unsigned long)qtd,
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200586 ALIGN_END_ADDR(struct qTD, qtd, qtd_count));
Marek Vasutb8adb122012-04-09 04:07:46 +0200587
michaeldb632992008-12-10 17:55:19 +0100588 token = hc32_to_cpu(vtd->qt_token);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200589 if (!(QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE))
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100590 break;
Stefan Roese67333f72010-11-26 15:43:28 +0100591 WATCHDOG_RESET();
Simon Glass96820a32011-02-07 14:42:16 -0800592 } while (get_timer(ts) < timeout);
593
Ilya Yanok189a6952012-07-15 04:43:49 +0000594 /*
595 * Invalidate the memory area occupied by buffer
596 * Don't try to fix the buffer alignment, if it isn't properly
597 * aligned it's upper layer's fault so let invalidate_dcache_range()
598 * vow about it. But we have to fix the length as it's actual
599 * transfer length and can be unaligned. This is potentially
600 * dangerous operation, it's responsibility of the calling
601 * code to make sure enough space is reserved.
602 */
Rob Herring98ae8402015-03-17 15:46:37 -0500603 invalidate_dcache_range((unsigned long)buffer,
604 ALIGN((unsigned long)buffer + length, ARCH_DMA_MINALIGN));
Marek Vasutb8adb122012-04-09 04:07:46 +0200605
Simon Glass96820a32011-02-07 14:42:16 -0800606 /* Check that the TD processing happened */
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200607 if (QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE)
Simon Glass96820a32011-02-07 14:42:16 -0800608 printf("EHCI timed out on TD - token=%#x\n", token);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100609
610 /* Disable async schedule. */
Lucas Stach676ae062012-09-26 00:14:35 +0200611 cmd = ehci_readl(&ctrl->hcor->or_usbcmd);
michaeldb632992008-12-10 17:55:19 +0100612 cmd &= ~CMD_ASE;
Lucas Stach676ae062012-09-26 00:14:35 +0200613 ehci_writel(&ctrl->hcor->or_usbcmd, cmd);
michael51ab1422008-12-11 13:43:55 +0100614
Lucas Stach676ae062012-09-26 00:14:35 +0200615 ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, 0,
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100616 100 * 1000);
617 if (ret < 0) {
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200618 printf("EHCI fail timeout STS_ASS reset\n");
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100619 goto fail;
michael51ab1422008-12-11 13:43:55 +0100620 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100621
Tom Rini71c5de42012-07-15 22:14:24 +0000622 token = hc32_to_cpu(qh->qh_overlay.qt_token);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200623 if (!(QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE)) {
michaeldb632992008-12-10 17:55:19 +0100624 debug("TOKEN=%#x\n", token);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200625 switch (QT_TOKEN_GET_STATUS(token) &
626 ~(QT_TOKEN_STATUS_SPLITXSTATE | QT_TOKEN_STATUS_PERR)) {
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100627 case 0:
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200628 toggle = QT_TOKEN_GET_DT(token);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100629 usb_settoggle(dev, usb_pipeendpoint(pipe),
630 usb_pipeout(pipe), toggle);
631 dev->status = 0;
632 break;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200633 case QT_TOKEN_STATUS_HALTED:
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100634 dev->status = USB_ST_STALLED;
635 break;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200636 case QT_TOKEN_STATUS_ACTIVE | QT_TOKEN_STATUS_DATBUFERR:
637 case QT_TOKEN_STATUS_DATBUFERR:
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100638 dev->status = USB_ST_BUF_ERR;
639 break;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200640 case QT_TOKEN_STATUS_HALTED | QT_TOKEN_STATUS_BABBLEDET:
641 case QT_TOKEN_STATUS_BABBLEDET:
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100642 dev->status = USB_ST_BABBLE_DET;
643 break;
644 default:
645 dev->status = USB_ST_CRC_ERR;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200646 if (QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_HALTED)
Anatolij Gustschin222d6df2010-11-02 11:47:29 +0100647 dev->status |= USB_ST_STALLED;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100648 break;
649 }
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200650 dev->act_len = length - QT_TOKEN_GET_TOTALBYTES(token);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100651 } else {
652 dev->act_len = 0;
Kuo-Jung Sue82a3162013-05-15 15:29:23 +0800653#ifndef CONFIG_USB_EHCI_FARADAY
michaeldb632992008-12-10 17:55:19 +0100654 debug("dev=%u, usbsts=%#x, p[1]=%#x, p[2]=%#x\n",
Lucas Stach676ae062012-09-26 00:14:35 +0200655 dev->devnum, ehci_readl(&ctrl->hcor->or_usbsts),
656 ehci_readl(&ctrl->hcor->or_portsc[0]),
657 ehci_readl(&ctrl->hcor->or_portsc[1]));
Kuo-Jung Sue82a3162013-05-15 15:29:23 +0800658#endif
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100659 }
660
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200661 free(qtd);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100662 return (dev->status != USB_ST_NOT_PROC) ? 0 : -1;
663
664fail:
Benoît Thébaudeau5cec2142012-08-10 18:22:32 +0200665 free(qtd);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100666 return -1;
667}
668
Simon Glass24ed8942015-03-25 12:22:25 -0600669static int ehci_submit_root(struct usb_device *dev, unsigned long pipe,
670 void *buffer, int length, struct devrequest *req)
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100671{
672 uint8_t tmpbuf[4];
673 u16 typeReq;
michaeldb632992008-12-10 17:55:19 +0100674 void *srcptr = NULL;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100675 int len, srclen;
676 uint32_t reg;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100677 uint32_t *status_reg;
Julius Werner7d9aa8f2013-02-28 18:08:40 +0000678 int port = le16_to_cpu(req->index) & 0xff;
Simon Glass24ed8942015-03-25 12:22:25 -0600679 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100680
681 srclen = 0;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100682
michaeldb632992008-12-10 17:55:19 +0100683 debug("req=%u (%#x), type=%u (%#x), value=%u, index=%u\n",
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100684 req->request, req->request,
685 req->requesttype, req->requesttype,
686 le16_to_cpu(req->value), le16_to_cpu(req->index));
687
Prafulla Wadaskar44259bb2009-07-17 19:56:30 +0530688 typeReq = req->request | req->requesttype << 8;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100689
Prafulla Wadaskar44259bb2009-07-17 19:56:30 +0530690 switch (typeReq) {
Kuo-Jung Su9c6a9d72013-05-15 15:29:20 +0800691 case USB_REQ_GET_STATUS | ((USB_RT_PORT | USB_DIR_IN) << 8):
692 case USB_REQ_SET_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8):
693 case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8):
Simon Glass6a1a8162015-03-25 12:22:24 -0600694 status_reg = ehci_get_portsc_register(ctrl, port - 1);
Kuo-Jung Su1dde1422013-05-15 15:29:21 +0800695 if (!status_reg)
Kuo-Jung Su9c6a9d72013-05-15 15:29:20 +0800696 return -1;
Kuo-Jung Su9c6a9d72013-05-15 15:29:20 +0800697 break;
698 default:
699 status_reg = NULL;
700 break;
701 }
702
703 switch (typeReq) {
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100704 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
705 switch (le16_to_cpu(req->value) >> 8) {
706 case USB_DT_DEVICE:
michaeldb632992008-12-10 17:55:19 +0100707 debug("USB_DT_DEVICE request\n");
708 srcptr = &descriptor.device;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200709 srclen = descriptor.device.bLength;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100710 break;
711 case USB_DT_CONFIG:
michaeldb632992008-12-10 17:55:19 +0100712 debug("USB_DT_CONFIG config\n");
713 srcptr = &descriptor.config;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200714 srclen = descriptor.config.bLength +
715 descriptor.interface.bLength +
716 descriptor.endpoint.bLength;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100717 break;
718 case USB_DT_STRING:
michaeldb632992008-12-10 17:55:19 +0100719 debug("USB_DT_STRING config\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100720 switch (le16_to_cpu(req->value) & 0xff) {
721 case 0: /* Language */
722 srcptr = "\4\3\1\0";
723 srclen = 4;
724 break;
725 case 1: /* Vendor */
726 srcptr = "\16\3u\0-\0b\0o\0o\0t\0";
727 srclen = 14;
728 break;
729 case 2: /* Product */
730 srcptr = "\52\3E\0H\0C\0I\0 "
731 "\0H\0o\0s\0t\0 "
732 "\0C\0o\0n\0t\0r\0o\0l\0l\0e\0r\0";
733 srclen = 42;
734 break;
735 default:
michaeldb632992008-12-10 17:55:19 +0100736 debug("unknown value DT_STRING %x\n",
737 le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100738 goto unknown;
739 }
740 break;
741 default:
michaeldb632992008-12-10 17:55:19 +0100742 debug("unknown value %x\n", le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100743 goto unknown;
744 }
745 break;
746 case USB_REQ_GET_DESCRIPTOR | ((USB_DIR_IN | USB_RT_HUB) << 8):
747 switch (le16_to_cpu(req->value) >> 8) {
748 case USB_DT_HUB:
michaeldb632992008-12-10 17:55:19 +0100749 debug("USB_DT_HUB config\n");
750 srcptr = &descriptor.hub;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200751 srclen = descriptor.hub.bLength;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100752 break;
753 default:
michaeldb632992008-12-10 17:55:19 +0100754 debug("unknown value %x\n", le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100755 goto unknown;
756 }
757 break;
758 case USB_REQ_SET_ADDRESS | (USB_RECIP_DEVICE << 8):
michaeldb632992008-12-10 17:55:19 +0100759 debug("USB_REQ_SET_ADDRESS\n");
Lucas Stach676ae062012-09-26 00:14:35 +0200760 ctrl->rootdev = le16_to_cpu(req->value);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100761 break;
762 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
michaeldb632992008-12-10 17:55:19 +0100763 debug("USB_REQ_SET_CONFIGURATION\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100764 /* Nothing to do */
765 break;
766 case USB_REQ_GET_STATUS | ((USB_DIR_IN | USB_RT_HUB) << 8):
767 tmpbuf[0] = 1; /* USB_STATUS_SELFPOWERED */
768 tmpbuf[1] = 0;
769 srcptr = tmpbuf;
770 srclen = 2;
771 break;
michaeldb632992008-12-10 17:55:19 +0100772 case USB_REQ_GET_STATUS | ((USB_RT_PORT | USB_DIR_IN) << 8):
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100773 memset(tmpbuf, 0, 4);
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100774 reg = ehci_readl(status_reg);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100775 if (reg & EHCI_PS_CS)
776 tmpbuf[0] |= USB_PORT_STAT_CONNECTION;
777 if (reg & EHCI_PS_PE)
778 tmpbuf[0] |= USB_PORT_STAT_ENABLE;
779 if (reg & EHCI_PS_SUSP)
780 tmpbuf[0] |= USB_PORT_STAT_SUSPEND;
781 if (reg & EHCI_PS_OCA)
782 tmpbuf[0] |= USB_PORT_STAT_OVERCURRENT;
Sergei Shtylyovc8b2d1d2010-02-27 21:33:21 +0300783 if (reg & EHCI_PS_PR)
784 tmpbuf[0] |= USB_PORT_STAT_RESET;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100785 if (reg & EHCI_PS_PP)
786 tmpbuf[1] |= USB_PORT_STAT_POWER >> 8;
Stefan Roese597eb282009-01-21 17:12:01 +0100787
788 if (ehci_is_TDI()) {
Simon Glass73382872015-03-25 12:22:18 -0600789 switch (ehci_get_port_speed(ctrl, reg)) {
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200790 case PORTSC_PSPD_FS:
Stefan Roese597eb282009-01-21 17:12:01 +0100791 break;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200792 case PORTSC_PSPD_LS:
Stefan Roese597eb282009-01-21 17:12:01 +0100793 tmpbuf[1] |= USB_PORT_STAT_LOW_SPEED >> 8;
794 break;
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200795 case PORTSC_PSPD_HS:
Stefan Roese597eb282009-01-21 17:12:01 +0100796 default:
797 tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8;
798 break;
799 }
800 } else {
801 tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8;
802 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100803
804 if (reg & EHCI_PS_CSC)
805 tmpbuf[2] |= USB_PORT_STAT_C_CONNECTION;
806 if (reg & EHCI_PS_PEC)
807 tmpbuf[2] |= USB_PORT_STAT_C_ENABLE;
808 if (reg & EHCI_PS_OCC)
809 tmpbuf[2] |= USB_PORT_STAT_C_OVERCURRENT;
Julius Werner7d9aa8f2013-02-28 18:08:40 +0000810 if (ctrl->portreset & (1 << port))
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100811 tmpbuf[2] |= USB_PORT_STAT_C_RESET;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100812
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100813 srcptr = tmpbuf;
814 srclen = 4;
815 break;
michaeldb632992008-12-10 17:55:19 +0100816 case USB_REQ_SET_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8):
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100817 reg = ehci_readl(status_reg);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100818 reg &= ~EHCI_PS_CLEAR;
819 switch (le16_to_cpu(req->value)) {
michael51ab1422008-12-11 13:43:55 +0100820 case USB_PORT_FEAT_ENABLE:
821 reg |= EHCI_PS_PE;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100822 ehci_writel(status_reg, reg);
michael51ab1422008-12-11 13:43:55 +0100823 break;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100824 case USB_PORT_FEAT_POWER:
Lucas Stach676ae062012-09-26 00:14:35 +0200825 if (HCS_PPC(ehci_readl(&ctrl->hccr->cr_hcsparams))) {
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100826 reg |= EHCI_PS_PP;
827 ehci_writel(status_reg, reg);
828 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100829 break;
830 case USB_PORT_FEAT_RESET:
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100831 if ((reg & (EHCI_PS_PE | EHCI_PS_CS)) == EHCI_PS_CS &&
832 !ehci_is_TDI() &&
833 EHCI_PS_IS_LOWSPEED(reg)) {
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100834 /* Low speed device, give up ownership. */
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100835 debug("port %d low speed --> companion\n",
Julius Werner7d9aa8f2013-02-28 18:08:40 +0000836 port - 1);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100837 reg |= EHCI_PS_PO;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100838 ehci_writel(status_reg, reg);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100839 break;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100840 } else {
Sergei Shtylyovc8b2d1d2010-02-27 21:33:21 +0300841 int ret;
842
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100843 reg |= EHCI_PS_PR;
844 reg &= ~EHCI_PS_PE;
845 ehci_writel(status_reg, reg);
846 /*
847 * caller must wait, then call GetPortStatus
848 * usb 2.0 specification say 50 ms resets on
849 * root
850 */
Simon Glass727fce32015-03-25 12:22:21 -0600851 ehci_powerup_fixup(ctrl, status_reg, &reg);
Marek Vasut3874b6d2011-07-11 02:37:01 +0200852
Chris Zhangb4161912010-01-06 13:34:04 -0800853 ehci_writel(status_reg, reg & ~EHCI_PS_PR);
Sergei Shtylyovc8b2d1d2010-02-27 21:33:21 +0300854 /*
855 * A host controller must terminate the reset
856 * and stabilize the state of the port within
857 * 2 milliseconds
858 */
859 ret = handshake(status_reg, EHCI_PS_PR, 0,
860 2 * 1000);
861 if (!ret)
Julius Werner7d9aa8f2013-02-28 18:08:40 +0000862 ctrl->portreset |= 1 << port;
Sergei Shtylyovc8b2d1d2010-02-27 21:33:21 +0300863 else
864 printf("port(%d) reset error\n",
Julius Werner7d9aa8f2013-02-28 18:08:40 +0000865 port - 1);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100866 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100867 break;
Julius Werner7d9aa8f2013-02-28 18:08:40 +0000868 case USB_PORT_FEAT_TEST:
Julius Werner5077f962013-09-24 10:53:07 -0700869 ehci_shutdown(ctrl);
Julius Werner7d9aa8f2013-02-28 18:08:40 +0000870 reg &= ~(0xf << 16);
871 reg |= ((le16_to_cpu(req->index) >> 8) & 0xf) << 16;
872 ehci_writel(status_reg, reg);
873 break;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100874 default:
michaeldb632992008-12-10 17:55:19 +0100875 debug("unknown feature %x\n", le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100876 goto unknown;
877 }
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100878 /* unblock posted writes */
Lucas Stach676ae062012-09-26 00:14:35 +0200879 (void) ehci_readl(&ctrl->hcor->or_usbcmd);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100880 break;
michaeldb632992008-12-10 17:55:19 +0100881 case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8):
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100882 reg = ehci_readl(status_reg);
Simon Glassed10e662013-05-10 19:49:00 -0700883 reg &= ~EHCI_PS_CLEAR;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100884 switch (le16_to_cpu(req->value)) {
885 case USB_PORT_FEAT_ENABLE:
886 reg &= ~EHCI_PS_PE;
887 break;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100888 case USB_PORT_FEAT_C_ENABLE:
Simon Glassed10e662013-05-10 19:49:00 -0700889 reg |= EHCI_PS_PE;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100890 break;
891 case USB_PORT_FEAT_POWER:
Lucas Stach676ae062012-09-26 00:14:35 +0200892 if (HCS_PPC(ehci_readl(&ctrl->hccr->cr_hcsparams)))
Simon Glassed10e662013-05-10 19:49:00 -0700893 reg &= ~EHCI_PS_PP;
894 break;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100895 case USB_PORT_FEAT_C_CONNECTION:
Simon Glassed10e662013-05-10 19:49:00 -0700896 reg |= EHCI_PS_CSC;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100897 break;
michael51ab1422008-12-11 13:43:55 +0100898 case USB_PORT_FEAT_OVER_CURRENT:
Simon Glassed10e662013-05-10 19:49:00 -0700899 reg |= EHCI_PS_OCC;
michael51ab1422008-12-11 13:43:55 +0100900 break;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100901 case USB_PORT_FEAT_C_RESET:
Julius Werner7d9aa8f2013-02-28 18:08:40 +0000902 ctrl->portreset &= ~(1 << port);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100903 break;
904 default:
michaeldb632992008-12-10 17:55:19 +0100905 debug("unknown feature %x\n", le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100906 goto unknown;
907 }
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100908 ehci_writel(status_reg, reg);
909 /* unblock posted write */
Lucas Stach676ae062012-09-26 00:14:35 +0200910 (void) ehci_readl(&ctrl->hcor->or_usbcmd);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100911 break;
912 default:
michaeldb632992008-12-10 17:55:19 +0100913 debug("Unknown request\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100914 goto unknown;
915 }
916
Mike Frysinger5b84dd62012-03-05 13:47:00 +0000917 mdelay(1);
Masahiro Yamadab4141192014-11-07 03:03:31 +0900918 len = min3(srclen, (int)le16_to_cpu(req->length), length);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100919 if (srcptr != NULL && len > 0)
920 memcpy(buffer, srcptr, len);
michaeldb632992008-12-10 17:55:19 +0100921 else
922 debug("Len is 0\n");
923
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100924 dev->act_len = len;
925 dev->status = 0;
926 return 0;
927
928unknown:
michaeldb632992008-12-10 17:55:19 +0100929 debug("requesttype=%x, request=%x, value=%x, index=%x, length=%x\n",
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100930 req->requesttype, req->request, le16_to_cpu(req->value),
931 le16_to_cpu(req->index), le16_to_cpu(req->length));
932
933 dev->act_len = 0;
934 dev->status = USB_ST_STALLED;
935 return -1;
936}
937
Simon Glassc4a31412015-03-25 12:22:19 -0600938void ehci_set_controller_priv(int index, void *priv)
939{
940 ehcic[index].priv = priv;
941}
942
943void *ehci_get_controller_priv(int index)
944{
945 return ehcic[index].priv;
946}
947
Lucas Stachc7e3b2b2012-09-26 00:14:34 +0200948int usb_lowlevel_stop(int index)
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100949{
Julius Werner5077f962013-09-24 10:53:07 -0700950 ehci_shutdown(&ehcic[index]);
Lucas Stach676ae062012-09-26 00:14:35 +0200951 return ehci_hcd_stop(index);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100952}
953
Troy Kisky06d513e2013-10-10 15:27:56 -0700954int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100955{
956 uint32_t reg;
michaeldb632992008-12-10 17:55:19 +0100957 uint32_t cmd;
Lucas Stach676ae062012-09-26 00:14:35 +0200958 struct QH *qh_list;
Patrick Georgi8f62ca62013-03-06 14:08:31 +0000959 struct QH *periodic;
960 int i;
Troy Kisky127efc42013-10-10 15:27:57 -0700961 int rc;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100962
Troy Kisky127efc42013-10-10 15:27:57 -0700963 rc = ehci_hcd_init(index, init, &ehcic[index].hccr, &ehcic[index].hcor);
964 if (rc)
965 return rc;
966 if (init == USB_INIT_DEVICE)
967 goto done;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100968
michael51ab1422008-12-11 13:43:55 +0100969 /* EHCI spec section 4.1 */
Lucas Stach676ae062012-09-26 00:14:35 +0200970 if (ehci_reset(index))
michael51ab1422008-12-11 13:43:55 +0100971 return -1;
972
Stefan Roese832e6142009-01-21 17:12:10 +0100973#if defined(CONFIG_EHCI_HCD_INIT_AFTER_RESET)
Troy Kisky127efc42013-10-10 15:27:57 -0700974 rc = ehci_hcd_init(index, init, &ehcic[index].hccr, &ehcic[index].hcor);
975 if (rc)
976 return rc;
Stefan Roese832e6142009-01-21 17:12:10 +0100977#endif
Vincent Palatin29828372012-12-12 17:55:22 -0800978 /* Set the high address word (aka segment) for 64-bit controller */
979 if (ehci_readl(&ehcic[index].hccr->cr_hccparams) & 1)
Marek Vasuteb632182013-12-14 02:04:52 +0100980 ehci_writel(&ehcic[index].hcor->or_ctrldssegment, 0);
Stefan Roese832e6142009-01-21 17:12:10 +0100981
Lucas Stach676ae062012-09-26 00:14:35 +0200982 qh_list = &ehcic[index].qh_list;
983
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100984 /* Set head of reclaim list */
Tom Rini71c5de42012-07-15 22:14:24 +0000985 memset(qh_list, 0, sizeof(*qh_list));
Rob Herring98ae8402015-03-17 15:46:37 -0500986 qh_list->qh_link = cpu_to_hc32((unsigned long)qh_list | QH_LINK_TYPE_QH);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200987 qh_list->qh_endpt1 = cpu_to_hc32(QH_ENDPT1_H(1) |
988 QH_ENDPT1_EPS(USB_SPEED_HIGH));
Tom Rini71c5de42012-07-15 22:14:24 +0000989 qh_list->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
990 qh_list->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
Benoît Thébaudeau14eb79b2012-08-10 18:22:11 +0200991 qh_list->qh_overlay.qt_token =
992 cpu_to_hc32(QT_TOKEN_STATUS(QT_TOKEN_STATUS_HALTED));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100993
Rob Herring98ae8402015-03-17 15:46:37 -0500994 flush_dcache_range((unsigned long)qh_list,
Stephen Warrend3e07472013-05-24 15:03:17 -0600995 ALIGN_END_ADDR(struct QH, qh_list, 1));
996
Patrick Georgi8f62ca62013-03-06 14:08:31 +0000997 /* Set async. queue head pointer. */
Rob Herring98ae8402015-03-17 15:46:37 -0500998 ehci_writel(&ehcic[index].hcor->or_asynclistaddr, (unsigned long)qh_list);
Patrick Georgi8f62ca62013-03-06 14:08:31 +0000999
1000 /*
1001 * Set up periodic list
1002 * Step 1: Parent QH for all periodic transfers.
1003 */
Hans de Goede36b73102014-09-20 16:51:25 +02001004 ehcic[index].periodic_schedules = 0;
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001005 periodic = &ehcic[index].periodic_queue;
1006 memset(periodic, 0, sizeof(*periodic));
1007 periodic->qh_link = cpu_to_hc32(QH_LINK_TERMINATE);
1008 periodic->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
1009 periodic->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
1010
Rob Herring98ae8402015-03-17 15:46:37 -05001011 flush_dcache_range((unsigned long)periodic,
Stephen Warrend3e07472013-05-24 15:03:17 -06001012 ALIGN_END_ADDR(struct QH, periodic, 1));
1013
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001014 /*
1015 * Step 2: Setup frame-list: Every microframe, USB tries the same list.
1016 * In particular, device specifications on polling frequency
1017 * are disregarded. Keyboards seem to send NAK/NYet reliably
1018 * when polled with an empty buffer.
1019 *
1020 * Split Transactions will be spread across microframes using
1021 * S-mask and C-mask.
1022 */
Nikita Kiryanov8bc36032013-07-29 13:27:40 +03001023 if (ehcic[index].periodic_list == NULL)
1024 ehcic[index].periodic_list = memalign(4096, 1024 * 4);
1025
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001026 if (!ehcic[index].periodic_list)
1027 return -ENOMEM;
1028 for (i = 0; i < 1024; i++) {
Rob Herring98ae8402015-03-17 15:46:37 -05001029 ehcic[index].periodic_list[i] = cpu_to_hc32((unsigned long)periodic
Adrian Coxea427772014-04-10 13:29:45 +01001030 | QH_LINK_TYPE_QH);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001031 }
1032
Rob Herring98ae8402015-03-17 15:46:37 -05001033 flush_dcache_range((unsigned long)ehcic[index].periodic_list,
Stephen Warrend3e07472013-05-24 15:03:17 -06001034 ALIGN_END_ADDR(uint32_t, ehcic[index].periodic_list,
1035 1024));
1036
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001037 /* Set periodic list base address */
1038 ehci_writel(&ehcic[index].hcor->or_periodiclistbase,
Rob Herring98ae8402015-03-17 15:46:37 -05001039 (unsigned long)ehcic[index].periodic_list);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001040
Lucas Stach676ae062012-09-26 00:14:35 +02001041 reg = ehci_readl(&ehcic[index].hccr->cr_hcsparams);
michael51ab1422008-12-11 13:43:55 +01001042 descriptor.hub.bNbrPorts = HCS_N_PORTS(reg);
Lucas Stach7a46b2c2012-09-28 00:26:19 +02001043 debug("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts);
Remy Böhmerc0d722f2008-12-13 22:51:58 +01001044 /* Port Indicators */
1045 if (HCS_INDICATOR(reg))
Lucas Stach93ad9082012-09-06 08:00:13 +02001046 put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics)
1047 | 0x80, &descriptor.hub.wHubCharacteristics);
Remy Böhmerc0d722f2008-12-13 22:51:58 +01001048 /* Port Power Control */
1049 if (HCS_PPC(reg))
Lucas Stach93ad9082012-09-06 08:00:13 +02001050 put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics)
1051 | 0x01, &descriptor.hub.wHubCharacteristics);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001052
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001053 /* Start the host controller. */
Lucas Stach676ae062012-09-26 00:14:35 +02001054 cmd = ehci_readl(&ehcic[index].hcor->or_usbcmd);
Wolfgang Denkf15c6512009-02-12 00:08:39 +01001055 /*
1056 * Philips, Intel, and maybe others need CMD_RUN before the
1057 * root hub will detect new devices (why?); NEC doesn't
1058 */
michael51ab1422008-12-11 13:43:55 +01001059 cmd &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
1060 cmd |= CMD_RUN;
Lucas Stach676ae062012-09-26 00:14:35 +02001061 ehci_writel(&ehcic[index].hcor->or_usbcmd, cmd);
michael51ab1422008-12-11 13:43:55 +01001062
Kuo-Jung Sue82a3162013-05-15 15:29:23 +08001063#ifndef CONFIG_USB_EHCI_FARADAY
michael51ab1422008-12-11 13:43:55 +01001064 /* take control over the ports */
Lucas Stach676ae062012-09-26 00:14:35 +02001065 cmd = ehci_readl(&ehcic[index].hcor->or_configflag);
michael51ab1422008-12-11 13:43:55 +01001066 cmd |= FLAG_CF;
Lucas Stach676ae062012-09-26 00:14:35 +02001067 ehci_writel(&ehcic[index].hcor->or_configflag, cmd);
Kuo-Jung Sue82a3162013-05-15 15:29:23 +08001068#endif
1069
Remy Böhmerc0d722f2008-12-13 22:51:58 +01001070 /* unblock posted write */
Lucas Stach676ae062012-09-26 00:14:35 +02001071 cmd = ehci_readl(&ehcic[index].hcor->or_usbcmd);
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001072 mdelay(5);
Lucas Stach676ae062012-09-26 00:14:35 +02001073 reg = HC_VERSION(ehci_readl(&ehcic[index].hccr->cr_capbase));
Remy Böhmerc0d722f2008-12-13 22:51:58 +01001074 printf("USB EHCI %x.%02x\n", reg >> 8, reg & 0xff);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001075
Lucas Stach676ae062012-09-26 00:14:35 +02001076 ehcic[index].rootdev = 0;
Troy Kisky127efc42013-10-10 15:27:57 -07001077done:
Lucas Stach676ae062012-09-26 00:14:35 +02001078 *controller = &ehcic[index];
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001079 return 0;
1080}
1081
Simon Glass24ed8942015-03-25 12:22:25 -06001082static int _ehci_submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
1083 void *buffer, int length)
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001084{
1085
1086 if (usb_pipetype(pipe) != PIPE_BULK) {
1087 debug("non-bulk pipe (type=%lu)", usb_pipetype(pipe));
1088 return -1;
1089 }
1090 return ehci_submit_async(dev, pipe, buffer, length, NULL);
1091}
1092
Simon Glass24ed8942015-03-25 12:22:25 -06001093static int _ehci_submit_control_msg(struct usb_device *dev, unsigned long pipe,
1094 void *buffer, int length,
1095 struct devrequest *setup)
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001096{
Simon Glass24ed8942015-03-25 12:22:25 -06001097 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001098
1099 if (usb_pipetype(pipe) != PIPE_CONTROL) {
1100 debug("non-control pipe (type=%lu)", usb_pipetype(pipe));
1101 return -1;
1102 }
1103
Lucas Stach676ae062012-09-26 00:14:35 +02001104 if (usb_pipedevice(pipe) == ctrl->rootdev) {
1105 if (!ctrl->rootdev)
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001106 dev->speed = USB_SPEED_HIGH;
1107 return ehci_submit_root(dev, pipe, buffer, length, setup);
1108 }
1109 return ehci_submit_async(dev, pipe, buffer, length, setup);
1110}
1111
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001112struct int_queue {
Hans de Goede8aa26b82014-09-24 14:06:05 +02001113 int elementsize;
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001114 struct QH *first;
1115 struct QH *current;
1116 struct QH *last;
1117 struct qTD *tds;
1118};
1119
Rob Herring98ae8402015-03-17 15:46:37 -05001120#define NEXT_QH(qh) (struct QH *)((unsigned long)hc32_to_cpu((qh)->qh_link) & ~0x1f)
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001121
1122static int
1123enable_periodic(struct ehci_ctrl *ctrl)
1124{
1125 uint32_t cmd;
1126 struct ehci_hcor *hcor = ctrl->hcor;
1127 int ret;
1128
1129 cmd = ehci_readl(&hcor->or_usbcmd);
1130 cmd |= CMD_PSE;
1131 ehci_writel(&hcor->or_usbcmd, cmd);
1132
1133 ret = handshake((uint32_t *)&hcor->or_usbsts,
1134 STS_PSS, STS_PSS, 100 * 1000);
1135 if (ret < 0) {
1136 printf("EHCI failed: timeout when enabling periodic list\n");
1137 return -ETIMEDOUT;
1138 }
1139 udelay(1000);
1140 return 0;
1141}
1142
1143static int
1144disable_periodic(struct ehci_ctrl *ctrl)
1145{
1146 uint32_t cmd;
1147 struct ehci_hcor *hcor = ctrl->hcor;
1148 int ret;
1149
1150 cmd = ehci_readl(&hcor->or_usbcmd);
1151 cmd &= ~CMD_PSE;
1152 ehci_writel(&hcor->or_usbcmd, cmd);
1153
1154 ret = handshake((uint32_t *)&hcor->or_usbsts,
1155 STS_PSS, 0, 100 * 1000);
1156 if (ret < 0) {
1157 printf("EHCI failed: timeout when disabling periodic list\n");
1158 return -ETIMEDOUT;
1159 }
1160 return 0;
1161}
1162
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001163struct int_queue *
1164create_int_queue(struct usb_device *dev, unsigned long pipe, int queuesize,
Hans de Goede8bb6c1d2015-01-11 20:38:28 +01001165 int elementsize, void *buffer, int interval)
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001166{
Simon Glass24ed8942015-03-25 12:22:25 -06001167 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001168 struct int_queue *result = NULL;
1169 int i;
1170
Hans de Goedebd818d82014-09-24 14:06:04 +02001171 /*
1172 * Interrupt transfers requiring several transactions are not supported
1173 * because bInterval is ignored.
1174 *
1175 * Also, ehci_submit_async() relies on wMaxPacketSize being a power of 2
1176 * <= PKT_ALIGN if several qTDs are required, while the USB
1177 * specification does not constrain this for interrupt transfers. That
1178 * means that ehci_submit_async() would support interrupt transfers
1179 * requiring several transactions only as long as the transfer size does
1180 * not require more than a single qTD.
1181 */
1182 if (elementsize > usb_maxpacket(dev, pipe)) {
1183 printf("%s: xfers requiring several transactions are not supported.\n",
1184 __func__);
1185 return NULL;
1186 }
1187
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001188 debug("Enter create_int_queue\n");
1189 if (usb_pipetype(pipe) != PIPE_INTERRUPT) {
1190 debug("non-interrupt pipe (type=%lu)", usb_pipetype(pipe));
1191 return NULL;
1192 }
1193
1194 /* limit to 4 full pages worth of data -
1195 * we can safely fit them in a single TD,
1196 * no matter the alignment
1197 */
1198 if (elementsize >= 16384) {
1199 debug("too large elements for interrupt transfers\n");
1200 return NULL;
1201 }
1202
1203 result = malloc(sizeof(*result));
1204 if (!result) {
1205 debug("ehci intr queue: out of memory\n");
1206 goto fail1;
1207 }
Hans de Goede8aa26b82014-09-24 14:06:05 +02001208 result->elementsize = elementsize;
Stephen Warren8165e342014-02-06 13:13:06 -07001209 result->first = memalign(USB_DMA_MINALIGN,
1210 sizeof(struct QH) * queuesize);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001211 if (!result->first) {
1212 debug("ehci intr queue: out of memory\n");
1213 goto fail2;
1214 }
1215 result->current = result->first;
1216 result->last = result->first + queuesize - 1;
Stephen Warren8165e342014-02-06 13:13:06 -07001217 result->tds = memalign(USB_DMA_MINALIGN,
1218 sizeof(struct qTD) * queuesize);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001219 if (!result->tds) {
1220 debug("ehci intr queue: out of memory\n");
1221 goto fail3;
1222 }
1223 memset(result->first, 0, sizeof(struct QH) * queuesize);
1224 memset(result->tds, 0, sizeof(struct qTD) * queuesize);
1225
1226 for (i = 0; i < queuesize; i++) {
1227 struct QH *qh = result->first + i;
1228 struct qTD *td = result->tds + i;
1229 void **buf = &qh->buffer;
1230
Rob Herring98ae8402015-03-17 15:46:37 -05001231 qh->qh_link = cpu_to_hc32((unsigned long)(qh+1) | QH_LINK_TYPE_QH);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001232 if (i == queuesize - 1)
Adrian Coxea427772014-04-10 13:29:45 +01001233 qh->qh_link = cpu_to_hc32(QH_LINK_TERMINATE);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001234
Rob Herring98ae8402015-03-17 15:46:37 -05001235 qh->qh_overlay.qt_next = cpu_to_hc32((unsigned long)td);
Adrian Coxea427772014-04-10 13:29:45 +01001236 qh->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
1237 qh->qh_endpt1 =
1238 cpu_to_hc32((0 << 28) | /* No NAK reload (ehci 4.9) */
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001239 (usb_maxpacket(dev, pipe) << 16) | /* MPS */
1240 (1 << 14) |
1241 QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)) |
1242 (usb_pipeendpoint(pipe) << 8) | /* Endpoint Number */
Adrian Coxea427772014-04-10 13:29:45 +01001243 (usb_pipedevice(pipe) << 0));
1244 qh->qh_endpt2 = cpu_to_hc32((1 << 30) | /* 1 Tx per mframe */
1245 (1 << 0)); /* S-mask: microframe 0 */
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001246 if (dev->speed == USB_SPEED_LOW ||
1247 dev->speed == USB_SPEED_FULL) {
Hans de Goede4e2c4ad2014-09-20 16:51:22 +02001248 /* C-mask: microframes 2-4 */
1249 qh->qh_endpt2 |= cpu_to_hc32((0x1c << 8));
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001250 }
Hans de Goede4e2c4ad2014-09-20 16:51:22 +02001251 ehci_update_endpt2_dev_n_port(dev, qh);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001252
Adrian Coxea427772014-04-10 13:29:45 +01001253 td->qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
1254 td->qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001255 debug("communication direction is '%s'\n",
1256 usb_pipein(pipe) ? "in" : "out");
Adrian Coxea427772014-04-10 13:29:45 +01001257 td->qt_token = cpu_to_hc32((elementsize << 16) |
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001258 ((usb_pipein(pipe) ? 1 : 0) << 8) | /* IN/OUT token */
Adrian Coxea427772014-04-10 13:29:45 +01001259 0x80); /* active */
1260 td->qt_buffer[0] =
Rob Herring98ae8402015-03-17 15:46:37 -05001261 cpu_to_hc32((unsigned long)buffer + i * elementsize);
Adrian Coxea427772014-04-10 13:29:45 +01001262 td->qt_buffer[1] =
1263 cpu_to_hc32((td->qt_buffer[0] + 0x1000) & ~0xfff);
1264 td->qt_buffer[2] =
1265 cpu_to_hc32((td->qt_buffer[0] + 0x2000) & ~0xfff);
1266 td->qt_buffer[3] =
1267 cpu_to_hc32((td->qt_buffer[0] + 0x3000) & ~0xfff);
1268 td->qt_buffer[4] =
1269 cpu_to_hc32((td->qt_buffer[0] + 0x4000) & ~0xfff);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001270
1271 *buf = buffer + i * elementsize;
1272 }
1273
Rob Herring98ae8402015-03-17 15:46:37 -05001274 flush_dcache_range((unsigned long)buffer,
Stephen Warrend3e07472013-05-24 15:03:17 -06001275 ALIGN_END_ADDR(char, buffer,
1276 queuesize * elementsize));
Rob Herring98ae8402015-03-17 15:46:37 -05001277 flush_dcache_range((unsigned long)result->first,
Stephen Warrend3e07472013-05-24 15:03:17 -06001278 ALIGN_END_ADDR(struct QH, result->first,
1279 queuesize));
Rob Herring98ae8402015-03-17 15:46:37 -05001280 flush_dcache_range((unsigned long)result->tds,
Stephen Warrend3e07472013-05-24 15:03:17 -06001281 ALIGN_END_ADDR(struct qTD, result->tds,
1282 queuesize));
1283
Hans de Goede32f2eac2014-09-24 14:06:03 +02001284 if (ctrl->periodic_schedules > 0) {
1285 if (disable_periodic(ctrl) < 0) {
1286 debug("FATAL: periodic should never fail, but did");
1287 goto fail3;
1288 }
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001289 }
1290
1291 /* hook up to periodic list */
1292 struct QH *list = &ctrl->periodic_queue;
1293 result->last->qh_link = list->qh_link;
Rob Herring98ae8402015-03-17 15:46:37 -05001294 list->qh_link = cpu_to_hc32((unsigned long)result->first | QH_LINK_TYPE_QH);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001295
Rob Herring98ae8402015-03-17 15:46:37 -05001296 flush_dcache_range((unsigned long)result->last,
Stephen Warrend3e07472013-05-24 15:03:17 -06001297 ALIGN_END_ADDR(struct QH, result->last, 1));
Rob Herring98ae8402015-03-17 15:46:37 -05001298 flush_dcache_range((unsigned long)list,
Stephen Warrend3e07472013-05-24 15:03:17 -06001299 ALIGN_END_ADDR(struct QH, list, 1));
1300
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001301 if (enable_periodic(ctrl) < 0) {
1302 debug("FATAL: periodic should never fail, but did");
1303 goto fail3;
1304 }
Hans de Goede36b73102014-09-20 16:51:25 +02001305 ctrl->periodic_schedules++;
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001306
1307 debug("Exit create_int_queue\n");
1308 return result;
1309fail3:
1310 if (result->tds)
1311 free(result->tds);
1312fail2:
1313 if (result->first)
1314 free(result->first);
1315 if (result)
1316 free(result);
1317fail1:
1318 return NULL;
1319}
1320
1321void *poll_int_queue(struct usb_device *dev, struct int_queue *queue)
1322{
1323 struct QH *cur = queue->current;
Hans de Goede415548d2014-09-20 16:51:24 +02001324 struct qTD *cur_td;
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001325
1326 /* depleted queue */
1327 if (cur == NULL) {
1328 debug("Exit poll_int_queue with completed queue\n");
1329 return NULL;
1330 }
1331 /* still active */
Hans de Goede415548d2014-09-20 16:51:24 +02001332 cur_td = &queue->tds[queue->current - queue->first];
Rob Herring98ae8402015-03-17 15:46:37 -05001333 invalidate_dcache_range((unsigned long)cur_td,
Hans de Goede415548d2014-09-20 16:51:24 +02001334 ALIGN_END_ADDR(struct qTD, cur_td, 1));
1335 if (QT_TOKEN_GET_STATUS(hc32_to_cpu(cur_td->qt_token)) &
1336 QT_TOKEN_STATUS_ACTIVE) {
1337 debug("Exit poll_int_queue with no completed intr transfer. token is %x\n",
1338 hc32_to_cpu(cur_td->qt_token));
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001339 return NULL;
1340 }
1341 if (!(cur->qh_link & QH_LINK_TERMINATE))
1342 queue->current++;
1343 else
1344 queue->current = NULL;
Hans de Goede8aa26b82014-09-24 14:06:05 +02001345
Rob Herring98ae8402015-03-17 15:46:37 -05001346 invalidate_dcache_range((unsigned long)cur->buffer,
Hans de Goede8aa26b82014-09-24 14:06:05 +02001347 ALIGN_END_ADDR(char, cur->buffer,
1348 queue->elementsize));
1349
Hans de Goede415548d2014-09-20 16:51:24 +02001350 debug("Exit poll_int_queue with completed intr transfer. token is %x at %p (first at %p)\n",
1351 hc32_to_cpu(cur_td->qt_token), cur, queue->first);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001352 return cur->buffer;
1353}
1354
1355/* Do not free buffers associated with QHs, they're owned by someone else */
Hans de Goede8460b892014-09-24 14:06:06 +02001356int
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001357destroy_int_queue(struct usb_device *dev, struct int_queue *queue)
1358{
Simon Glass24ed8942015-03-25 12:22:25 -06001359 struct ehci_ctrl *ctrl = ehci_get_ctrl(dev);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001360 int result = -1;
1361 unsigned long timeout;
1362
1363 if (disable_periodic(ctrl) < 0) {
1364 debug("FATAL: periodic should never fail, but did");
1365 goto out;
1366 }
Hans de Goede36b73102014-09-20 16:51:25 +02001367 ctrl->periodic_schedules--;
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001368
1369 struct QH *cur = &ctrl->periodic_queue;
1370 timeout = get_timer(0) + 500; /* abort after 500ms */
Adrian Coxea427772014-04-10 13:29:45 +01001371 while (!(cur->qh_link & cpu_to_hc32(QH_LINK_TERMINATE))) {
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001372 debug("considering %p, with qh_link %x\n", cur, cur->qh_link);
1373 if (NEXT_QH(cur) == queue->first) {
1374 debug("found candidate. removing from chain\n");
1375 cur->qh_link = queue->last->qh_link;
Rob Herring98ae8402015-03-17 15:46:37 -05001376 flush_dcache_range((unsigned long)cur,
Hans de Goedeea7b30c2014-09-20 16:51:23 +02001377 ALIGN_END_ADDR(struct QH, cur, 1));
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001378 result = 0;
1379 break;
1380 }
1381 cur = NEXT_QH(cur);
1382 if (get_timer(0) > timeout) {
1383 printf("Timeout destroying interrupt endpoint queue\n");
1384 result = -1;
1385 goto out;
1386 }
1387 }
1388
Hans de Goede36b73102014-09-20 16:51:25 +02001389 if (ctrl->periodic_schedules > 0) {
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001390 result = enable_periodic(ctrl);
1391 if (result < 0)
1392 debug("FATAL: periodic should never fail, but did");
1393 }
1394
1395out:
1396 free(queue->tds);
1397 free(queue->first);
1398 free(queue);
1399
1400 return result;
1401}
1402
Simon Glass24ed8942015-03-25 12:22:25 -06001403static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe,
1404 void *buffer, int length, int interval)
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001405{
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001406 void *backbuffer;
1407 struct int_queue *queue;
1408 unsigned long timeout;
1409 int result = 0, ret;
1410
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001411 debug("dev=%p, pipe=%lu, buffer=%p, length=%d, interval=%d",
1412 dev, pipe, buffer, length, interval);
Benoît Thébaudeau44ae0be2012-08-09 23:50:44 +02001413
Hans de Goede8bb6c1d2015-01-11 20:38:28 +01001414 queue = create_int_queue(dev, pipe, 1, length, buffer, interval);
Hans de Goedebd818d82014-09-24 14:06:04 +02001415 if (!queue)
1416 return -1;
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001417
1418 timeout = get_timer(0) + USB_TIMEOUT_MS(pipe);
1419 while ((backbuffer = poll_int_queue(dev, queue)) == NULL)
1420 if (get_timer(0) > timeout) {
1421 printf("Timeout poll on interrupt endpoint\n");
1422 result = -ETIMEDOUT;
1423 break;
1424 }
1425
1426 if (backbuffer != buffer) {
Rob Herring98ae8402015-03-17 15:46:37 -05001427 debug("got wrong buffer back (%p instead of %p)\n",
1428 backbuffer, buffer);
Patrick Georgi8f62ca62013-03-06 14:08:31 +00001429 return -EINVAL;
1430 }
1431
1432 ret = destroy_int_queue(dev, queue);
1433 if (ret < 0)
1434 return ret;
1435
1436 /* everything worked out fine */
1437 return result;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +01001438}
Simon Glass24ed8942015-03-25 12:22:25 -06001439
1440int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
1441 void *buffer, int length)
1442{
1443 return _ehci_submit_bulk_msg(dev, pipe, buffer, length);
1444}
1445
1446int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1447 int length, struct devrequest *setup)
1448{
1449 return _ehci_submit_control_msg(dev, pipe, buffer, length, setup);
1450}
1451
1452int submit_int_msg(struct usb_device *dev, unsigned long pipe,
1453 void *buffer, int length, int interval)
1454{
1455 return _ehci_submit_int_msg(dev, pipe, buffer, length, interval);
1456}