blob: 1cee158b0189f798d6ed8ac3c82df4d935890b44 [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>
michaeldb632992008-12-10 17:55:19 +010024#include <asm/byteorder.h>
Michael Trimarchiaaf098c2008-11-28 13:20:46 +010025#include <usb.h>
26#include <asm/io.h>
michaeldb632992008-12-10 17:55:19 +010027#include <malloc.h>
Stefan Roese67333f72010-11-26 15:43:28 +010028#include <watchdog.h>
Marek Vasut7555d5e2011-09-25 21:07:56 +020029#ifdef CONFIG_USB_KEYBOARD
30#include <stdio_dev.h>
31extern unsigned char new[];
32#endif
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020033
34#include "ehci.h"
Michael Trimarchiaaf098c2008-11-28 13:20:46 +010035
36int rootdev;
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +010037struct ehci_hccr *hccr; /* R/O registers, not need for volatile */
Michael Trimarchiaaf098c2008-11-28 13:20:46 +010038volatile struct ehci_hcor *hcor;
39
40static uint16_t portreset;
41static struct QH qh_list __attribute__((aligned(32)));
42
michaeldb632992008-12-10 17:55:19 +010043static struct descriptor {
44 struct usb_hub_descriptor hub;
45 struct usb_device_descriptor device;
46 struct usb_linux_config_descriptor config;
47 struct usb_linux_interface_descriptor interface;
48 struct usb_endpoint_descriptor endpoint;
49} __attribute__ ((packed)) descriptor = {
50 {
51 0x8, /* bDescLength */
52 0x29, /* bDescriptorType: hub descriptor */
53 2, /* bNrPorts -- runtime modified */
54 0, /* wHubCharacteristics */
Vincent Palatin5f4b4f22011-12-05 14:52:22 -080055 10, /* bPwrOn2PwrGood */
michaeldb632992008-12-10 17:55:19 +010056 0, /* bHubCntrCurrent */
57 {}, /* Device removable */
58 {} /* at most 7 ports! XXX */
59 },
60 {
61 0x12, /* bLength */
62 1, /* bDescriptorType: UDESC_DEVICE */
Sergei Shtylyov6d313c82010-02-27 21:29:42 +030063 cpu_to_le16(0x0200), /* bcdUSB: v2.0 */
michaeldb632992008-12-10 17:55:19 +010064 9, /* bDeviceClass: UDCLASS_HUB */
65 0, /* bDeviceSubClass: UDSUBCLASS_HUB */
66 1, /* bDeviceProtocol: UDPROTO_HSHUBSTT */
67 64, /* bMaxPacketSize: 64 bytes */
68 0x0000, /* idVendor */
69 0x0000, /* idProduct */
Sergei Shtylyov6d313c82010-02-27 21:29:42 +030070 cpu_to_le16(0x0100), /* bcdDevice */
michaeldb632992008-12-10 17:55:19 +010071 1, /* iManufacturer */
72 2, /* iProduct */
73 0, /* iSerialNumber */
74 1 /* bNumConfigurations: 1 */
75 },
76 {
77 0x9,
78 2, /* bDescriptorType: UDESC_CONFIG */
79 cpu_to_le16(0x19),
80 1, /* bNumInterface */
81 1, /* bConfigurationValue */
82 0, /* iConfiguration */
83 0x40, /* bmAttributes: UC_SELF_POWER */
84 0 /* bMaxPower */
85 },
86 {
87 0x9, /* bLength */
88 4, /* bDescriptorType: UDESC_INTERFACE */
89 0, /* bInterfaceNumber */
90 0, /* bAlternateSetting */
91 1, /* bNumEndpoints */
92 9, /* bInterfaceClass: UICLASS_HUB */
93 0, /* bInterfaceSubClass: UISUBCLASS_HUB */
94 0, /* bInterfaceProtocol: UIPROTO_HSHUBSTT */
95 0 /* iInterface */
96 },
97 {
98 0x7, /* bLength */
99 5, /* bDescriptorType: UDESC_ENDPOINT */
100 0x81, /* bEndpointAddress:
101 * UE_DIR_IN | EHCI_INTR_ENDPT
102 */
103 3, /* bmAttributes: UE_INTERRUPT */
Tom Rix8f8bd562009-10-31 12:37:38 -0500104 8, /* wMaxPacketSize */
michaeldb632992008-12-10 17:55:19 +0100105 255 /* bInterval */
106 },
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100107};
108
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100109#if defined(CONFIG_EHCI_IS_TDI)
110#define ehci_is_TDI() (1)
111#else
112#define ehci_is_TDI() (0)
113#endif
114
Stefan Roesedaa2daf2009-01-21 17:12:19 +0100115#if defined(CONFIG_EHCI_DCACHE)
116/*
117 * Routines to handle (flush/invalidate) the dcache for the QH and qTD
118 * structures and data buffers. This is needed on platforms using this
119 * EHCI support with dcache enabled.
120 */
121static void flush_invalidate(u32 addr, int size, int flush)
122{
123 if (flush)
124 flush_dcache_range(addr, addr + size);
125 else
126 invalidate_dcache_range(addr, addr + size);
127}
128
129static void cache_qtd(struct qTD *qtd, int flush)
130{
131 u32 *ptr = (u32 *)qtd->qt_buffer[0];
132 int len = (qtd->qt_token & 0x7fff0000) >> 16;
133
134 flush_invalidate((u32)qtd, sizeof(struct qTD), flush);
135 if (ptr && len)
136 flush_invalidate((u32)ptr, len, flush);
137}
138
139
140static inline struct QH *qh_addr(struct QH *qh)
141{
142 return (struct QH *)((u32)qh & 0xffffffe0);
143}
144
145static void cache_qh(struct QH *qh, int flush)
146{
147 struct qTD *qtd;
148 struct qTD *next;
149 static struct qTD *first_qtd;
150
151 /*
152 * Walk the QH list and flush/invalidate all entries
153 */
154 while (1) {
155 flush_invalidate((u32)qh_addr(qh), sizeof(struct QH), flush);
156 if ((u32)qh & QH_LINK_TYPE_QH)
157 break;
158 qh = qh_addr(qh);
159 qh = (struct QH *)qh->qh_link;
160 }
161 qh = qh_addr(qh);
162
163 /*
164 * Save first qTD pointer, needed for invalidating pass on this QH
165 */
166 if (flush)
167 first_qtd = qtd = (struct qTD *)(*(u32 *)&qh->qh_overlay &
168 0xffffffe0);
169 else
170 qtd = first_qtd;
171
172 /*
173 * Walk the qTD list and flush/invalidate all entries
174 */
175 while (1) {
176 if (qtd == NULL)
177 break;
178 cache_qtd(qtd, flush);
179 next = (struct qTD *)((u32)qtd->qt_next & 0xffffffe0);
180 if (next == qtd)
181 break;
182 qtd = next;
183 }
184}
185
186static inline void ehci_flush_dcache(struct QH *qh)
187{
188 cache_qh(qh, 1);
189}
190
191static inline void ehci_invalidate_dcache(struct QH *qh)
192{
193 cache_qh(qh, 0);
194}
195#else /* CONFIG_EHCI_DCACHE */
196/*
197 *
198 */
199static inline void ehci_flush_dcache(struct QH *qh)
200{
201}
202
203static inline void ehci_invalidate_dcache(struct QH *qh)
204{
205}
206#endif /* CONFIG_EHCI_DCACHE */
207
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100208static int handshake(uint32_t *ptr, uint32_t mask, uint32_t done, int usec)
michaeldb632992008-12-10 17:55:19 +0100209{
michael51ab1422008-12-11 13:43:55 +0100210 uint32_t result;
211 do {
212 result = ehci_readl(ptr);
Wolfgang Denk09c83a42010-10-22 14:23:00 +0200213 udelay(5);
michael51ab1422008-12-11 13:43:55 +0100214 if (result == ~(uint32_t)0)
215 return -1;
216 result &= mask;
217 if (result == done)
218 return 0;
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100219 usec--;
220 } while (usec > 0);
michael51ab1422008-12-11 13:43:55 +0100221 return -1;
222}
223
224static void ehci_free(void *p, size_t sz)
225{
226
227}
228
229static int ehci_reset(void)
230{
231 uint32_t cmd;
232 uint32_t tmp;
233 uint32_t *reg_ptr;
234 int ret = 0;
235
236 cmd = ehci_readl(&hcor->or_usbcmd);
Stefan Roese273d7202010-11-26 15:44:00 +0100237 cmd = (cmd & ~CMD_RUN) | CMD_RESET;
michael51ab1422008-12-11 13:43:55 +0100238 ehci_writel(&hcor->or_usbcmd, cmd);
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100239 ret = handshake((uint32_t *)&hcor->or_usbcmd, CMD_RESET, 0, 250 * 1000);
michael51ab1422008-12-11 13:43:55 +0100240 if (ret < 0) {
241 printf("EHCI fail to reset\n");
242 goto out;
243 }
244
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100245 if (ehci_is_TDI()) {
246 reg_ptr = (uint32_t *)((u8 *)hcor + USBMODE);
247 tmp = ehci_readl(reg_ptr);
248 tmp |= USBMODE_CM_HC;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100249#if defined(CONFIG_EHCI_MMIO_BIG_ENDIAN)
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100250 tmp |= USBMODE_BE;
michael51ab1422008-12-11 13:43:55 +0100251#endif
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100252 ehci_writel(reg_ptr, tmp);
253 }
michael51ab1422008-12-11 13:43:55 +0100254out:
255 return ret;
michaeldb632992008-12-10 17:55:19 +0100256}
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100257
258static void *ehci_alloc(size_t sz, size_t align)
259{
260 static struct QH qh __attribute__((aligned(32)));
261 static struct qTD td[3] __attribute__((aligned (32)));
262 static int ntds;
263 void *p;
264
265 switch (sz) {
266 case sizeof(struct QH):
267 p = &qh;
268 ntds = 0;
269 break;
270 case sizeof(struct qTD):
271 if (ntds == 3) {
michaeldb632992008-12-10 17:55:19 +0100272 debug("out of TDs\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100273 return NULL;
274 }
275 p = &td[ntds];
276 ntds++;
277 break;
278 default:
michaeldb632992008-12-10 17:55:19 +0100279 debug("unknown allocation size\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100280 return NULL;
281 }
282
Sergei Shtylyov9fb3b502010-06-28 22:44:49 +0400283 memset(p, 0, sz);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100284 return p;
285}
286
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100287static int ehci_td_buffer(struct qTD *td, void *buf, size_t sz)
288{
289 uint32_t addr, delta, next;
290 int idx;
291
292 addr = (uint32_t) buf;
293 idx = 0;
294 while (idx < 5) {
michaeldb632992008-12-10 17:55:19 +0100295 td->qt_buffer[idx] = cpu_to_hc32(addr);
Wolfgang Denk3ed16072010-10-19 16:13:15 +0200296 td->qt_buffer_hi[idx] = 0;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100297 next = (addr + 4096) & ~4095;
298 delta = next - addr;
299 if (delta >= sz)
300 break;
301 sz -= delta;
302 addr = next;
303 idx++;
304 }
305
306 if (idx == 5) {
michaeldb632992008-12-10 17:55:19 +0100307 debug("out of buffer pointers (%u bytes left)\n", sz);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100308 return -1;
309 }
310
311 return 0;
312}
313
314static int
315ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
316 int length, struct devrequest *req)
317{
318 struct QH *qh;
319 struct qTD *td;
320 volatile struct qTD *vtd;
321 unsigned long ts;
322 uint32_t *tdp;
323 uint32_t endpt, token, usbsts;
324 uint32_t c, toggle;
michaeldb632992008-12-10 17:55:19 +0100325 uint32_t cmd;
Simon Glass96820a32011-02-07 14:42:16 -0800326 int timeout;
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100327 int ret = 0;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100328
michaeldb632992008-12-10 17:55:19 +0100329 debug("dev=%p, pipe=%lx, buffer=%p, length=%d, req=%p\n", dev, pipe,
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100330 buffer, length, req);
331 if (req != NULL)
michaeldb632992008-12-10 17:55:19 +0100332 debug("req=%u (%#x), type=%u (%#x), value=%u (%#x), index=%u\n",
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100333 req->request, req->request,
334 req->requesttype, req->requesttype,
335 le16_to_cpu(req->value), le16_to_cpu(req->value),
michaeldb632992008-12-10 17:55:19 +0100336 le16_to_cpu(req->index));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100337
338 qh = ehci_alloc(sizeof(struct QH), 32);
339 if (qh == NULL) {
michaeldb632992008-12-10 17:55:19 +0100340 debug("unable to allocate QH\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100341 return -1;
342 }
michaeldb632992008-12-10 17:55:19 +0100343 qh->qh_link = cpu_to_hc32((uint32_t)&qh_list | QH_LINK_TYPE_QH);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100344 c = (usb_pipespeed(pipe) != USB_SPEED_HIGH &&
345 usb_pipeendpoint(pipe) == 0) ? 1 : 0;
346 endpt = (8 << 28) |
347 (c << 27) |
348 (usb_maxpacket(dev, pipe) << 16) |
349 (0 << 15) |
350 (1 << 14) |
351 (usb_pipespeed(pipe) << 12) |
352 (usb_pipeendpoint(pipe) << 8) |
353 (0 << 7) | (usb_pipedevice(pipe) << 0);
michaeldb632992008-12-10 17:55:19 +0100354 qh->qh_endpt1 = cpu_to_hc32(endpt);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100355 endpt = (1 << 30) |
356 (dev->portnr << 23) |
357 (dev->parent->devnum << 16) | (0 << 8) | (0 << 0);
michaeldb632992008-12-10 17:55:19 +0100358 qh->qh_endpt2 = cpu_to_hc32(endpt);
359 qh->qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100360
361 td = NULL;
362 tdp = &qh->qh_overlay.qt_next;
363
364 toggle =
365 usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe));
366
367 if (req != NULL) {
368 td = ehci_alloc(sizeof(struct qTD), 32);
369 if (td == NULL) {
michaeldb632992008-12-10 17:55:19 +0100370 debug("unable to allocate SETUP td\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100371 goto fail;
372 }
michaeldb632992008-12-10 17:55:19 +0100373 td->qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
374 td->qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100375 token = (0 << 31) |
376 (sizeof(*req) << 16) |
377 (0 << 15) | (0 << 12) | (3 << 10) | (2 << 8) | (0x80 << 0);
michaeldb632992008-12-10 17:55:19 +0100378 td->qt_token = cpu_to_hc32(token);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100379 if (ehci_td_buffer(td, req, sizeof(*req)) != 0) {
michaeldb632992008-12-10 17:55:19 +0100380 debug("unable construct SETUP td\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100381 ehci_free(td, sizeof(*td));
382 goto fail;
383 }
michaeldb632992008-12-10 17:55:19 +0100384 *tdp = cpu_to_hc32((uint32_t) td);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100385 tdp = &td->qt_next;
386 toggle = 1;
387 }
388
389 if (length > 0 || req == NULL) {
390 td = ehci_alloc(sizeof(struct qTD), 32);
391 if (td == NULL) {
michaeldb632992008-12-10 17:55:19 +0100392 debug("unable to allocate DATA td\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100393 goto fail;
394 }
michaeldb632992008-12-10 17:55:19 +0100395 td->qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
396 td->qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100397 token = (toggle << 31) |
398 (length << 16) |
399 ((req == NULL ? 1 : 0) << 15) |
400 (0 << 12) |
401 (3 << 10) |
402 ((usb_pipein(pipe) ? 1 : 0) << 8) | (0x80 << 0);
michaeldb632992008-12-10 17:55:19 +0100403 td->qt_token = cpu_to_hc32(token);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100404 if (ehci_td_buffer(td, buffer, length) != 0) {
michaeldb632992008-12-10 17:55:19 +0100405 debug("unable construct DATA td\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100406 ehci_free(td, sizeof(*td));
407 goto fail;
408 }
michaeldb632992008-12-10 17:55:19 +0100409 *tdp = cpu_to_hc32((uint32_t) td);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100410 tdp = &td->qt_next;
411 }
412
413 if (req != NULL) {
414 td = ehci_alloc(sizeof(struct qTD), 32);
415 if (td == NULL) {
michaeldb632992008-12-10 17:55:19 +0100416 debug("unable to allocate ACK td\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100417 goto fail;
418 }
michaeldb632992008-12-10 17:55:19 +0100419 td->qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
420 td->qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100421 token = (toggle << 31) |
422 (0 << 16) |
423 (1 << 15) |
424 (0 << 12) |
425 (3 << 10) |
426 ((usb_pipein(pipe) ? 0 : 1) << 8) | (0x80 << 0);
michaeldb632992008-12-10 17:55:19 +0100427 td->qt_token = cpu_to_hc32(token);
428 *tdp = cpu_to_hc32((uint32_t) td);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100429 tdp = &td->qt_next;
430 }
431
michaeldb632992008-12-10 17:55:19 +0100432 qh_list.qh_link = cpu_to_hc32((uint32_t) qh | QH_LINK_TYPE_QH);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100433
Stefan Roesedaa2daf2009-01-21 17:12:19 +0100434 /* Flush dcache */
435 ehci_flush_dcache(&qh_list);
436
michael51ab1422008-12-11 13:43:55 +0100437 usbsts = ehci_readl(&hcor->or_usbsts);
438 ehci_writel(&hcor->or_usbsts, (usbsts & 0x3f));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100439
440 /* Enable async. schedule. */
michael51ab1422008-12-11 13:43:55 +0100441 cmd = ehci_readl(&hcor->or_usbcmd);
442 cmd |= CMD_ASE;
443 ehci_writel(&hcor->or_usbcmd, cmd);
michaeldb632992008-12-10 17:55:19 +0100444
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100445 ret = handshake((uint32_t *)&hcor->or_usbsts, STD_ASS, STD_ASS,
446 100 * 1000);
447 if (ret < 0) {
448 printf("EHCI fail timeout STD_ASS set\n");
449 goto fail;
michael51ab1422008-12-11 13:43:55 +0100450 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100451
452 /* Wait for TDs to be processed. */
453 ts = get_timer(0);
454 vtd = td;
Simon Glass96820a32011-02-07 14:42:16 -0800455 timeout = USB_TIMEOUT_MS(pipe);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100456 do {
Stefan Roesedaa2daf2009-01-21 17:12:19 +0100457 /* Invalidate dcache */
458 ehci_invalidate_dcache(&qh_list);
michaeldb632992008-12-10 17:55:19 +0100459 token = hc32_to_cpu(vtd->qt_token);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100460 if (!(token & 0x80))
461 break;
Stefan Roese67333f72010-11-26 15:43:28 +0100462 WATCHDOG_RESET();
Simon Glass96820a32011-02-07 14:42:16 -0800463 } while (get_timer(ts) < timeout);
464
465 /* Check that the TD processing happened */
466 if (token & 0x80) {
467 printf("EHCI timed out on TD - token=%#x\n", token);
Simon Glass96820a32011-02-07 14:42:16 -0800468 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100469
470 /* Disable async schedule. */
michael51ab1422008-12-11 13:43:55 +0100471 cmd = ehci_readl(&hcor->or_usbcmd);
michaeldb632992008-12-10 17:55:19 +0100472 cmd &= ~CMD_ASE;
michael51ab1422008-12-11 13:43:55 +0100473 ehci_writel(&hcor->or_usbcmd, cmd);
474
Michael Trimarchi1ed9f9a2008-12-31 10:33:22 +0100475 ret = handshake((uint32_t *)&hcor->or_usbsts, STD_ASS, 0,
476 100 * 1000);
477 if (ret < 0) {
478 printf("EHCI fail timeout STD_ASS reset\n");
479 goto fail;
michael51ab1422008-12-11 13:43:55 +0100480 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100481
michaeldb632992008-12-10 17:55:19 +0100482 qh_list.qh_link = cpu_to_hc32((uint32_t)&qh_list | QH_LINK_TYPE_QH);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100483
michaeldb632992008-12-10 17:55:19 +0100484 token = hc32_to_cpu(qh->qh_overlay.qt_token);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100485 if (!(token & 0x80)) {
michaeldb632992008-12-10 17:55:19 +0100486 debug("TOKEN=%#x\n", token);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100487 switch (token & 0xfc) {
488 case 0:
489 toggle = token >> 31;
490 usb_settoggle(dev, usb_pipeendpoint(pipe),
491 usb_pipeout(pipe), toggle);
492 dev->status = 0;
493 break;
494 case 0x40:
495 dev->status = USB_ST_STALLED;
496 break;
497 case 0xa0:
498 case 0x20:
499 dev->status = USB_ST_BUF_ERR;
500 break;
501 case 0x50:
502 case 0x10:
503 dev->status = USB_ST_BABBLE_DET;
504 break;
505 default:
506 dev->status = USB_ST_CRC_ERR;
Anatolij Gustschin222d6df2010-11-02 11:47:29 +0100507 if ((token & 0x40) == 0x40)
508 dev->status |= USB_ST_STALLED;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100509 break;
510 }
511 dev->act_len = length - ((token >> 16) & 0x7fff);
512 } else {
513 dev->act_len = 0;
michaeldb632992008-12-10 17:55:19 +0100514 debug("dev=%u, usbsts=%#x, p[1]=%#x, p[2]=%#x\n",
michael51ab1422008-12-11 13:43:55 +0100515 dev->devnum, ehci_readl(&hcor->or_usbsts),
516 ehci_readl(&hcor->or_portsc[0]),
517 ehci_readl(&hcor->or_portsc[1]));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100518 }
519
520 return (dev->status != USB_ST_NOT_PROC) ? 0 : -1;
521
522fail:
michaeldb632992008-12-10 17:55:19 +0100523 td = (void *)hc32_to_cpu(qh->qh_overlay.qt_next);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100524 while (td != (void *)QT_NEXT_TERMINATE) {
525 qh->qh_overlay.qt_next = td->qt_next;
526 ehci_free(td, sizeof(*td));
michaeldb632992008-12-10 17:55:19 +0100527 td = (void *)hc32_to_cpu(qh->qh_overlay.qt_next);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100528 }
529 ehci_free(qh, sizeof(*qh));
530 return -1;
531}
532
533static inline int min3(int a, int b, int c)
534{
535
536 if (b < a)
537 a = b;
538 if (c < a)
539 a = c;
540 return a;
541}
542
michaeldb632992008-12-10 17:55:19 +0100543int
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100544ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer,
545 int length, struct devrequest *req)
546{
547 uint8_t tmpbuf[4];
548 u16 typeReq;
michaeldb632992008-12-10 17:55:19 +0100549 void *srcptr = NULL;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100550 int len, srclen;
551 uint32_t reg;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100552 uint32_t *status_reg;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100553
Sergei Shtylyove06a0552010-02-27 21:32:17 +0300554 if (le16_to_cpu(req->index) > CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS) {
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100555 printf("The request port(%d) is not configured\n",
556 le16_to_cpu(req->index) - 1);
557 return -1;
558 }
559 status_reg = (uint32_t *)&hcor->or_portsc[
560 le16_to_cpu(req->index) - 1];
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100561 srclen = 0;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100562
michaeldb632992008-12-10 17:55:19 +0100563 debug("req=%u (%#x), type=%u (%#x), value=%u, index=%u\n",
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100564 req->request, req->request,
565 req->requesttype, req->requesttype,
566 le16_to_cpu(req->value), le16_to_cpu(req->index));
567
Prafulla Wadaskar44259bb2009-07-17 19:56:30 +0530568 typeReq = req->request | req->requesttype << 8;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100569
Prafulla Wadaskar44259bb2009-07-17 19:56:30 +0530570 switch (typeReq) {
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100571 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
572 switch (le16_to_cpu(req->value) >> 8) {
573 case USB_DT_DEVICE:
michaeldb632992008-12-10 17:55:19 +0100574 debug("USB_DT_DEVICE request\n");
575 srcptr = &descriptor.device;
576 srclen = 0x12;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100577 break;
578 case USB_DT_CONFIG:
michaeldb632992008-12-10 17:55:19 +0100579 debug("USB_DT_CONFIG config\n");
580 srcptr = &descriptor.config;
581 srclen = 0x19;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100582 break;
583 case USB_DT_STRING:
michaeldb632992008-12-10 17:55:19 +0100584 debug("USB_DT_STRING config\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100585 switch (le16_to_cpu(req->value) & 0xff) {
586 case 0: /* Language */
587 srcptr = "\4\3\1\0";
588 srclen = 4;
589 break;
590 case 1: /* Vendor */
591 srcptr = "\16\3u\0-\0b\0o\0o\0t\0";
592 srclen = 14;
593 break;
594 case 2: /* Product */
595 srcptr = "\52\3E\0H\0C\0I\0 "
596 "\0H\0o\0s\0t\0 "
597 "\0C\0o\0n\0t\0r\0o\0l\0l\0e\0r\0";
598 srclen = 42;
599 break;
600 default:
michaeldb632992008-12-10 17:55:19 +0100601 debug("unknown value DT_STRING %x\n",
602 le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100603 goto unknown;
604 }
605 break;
606 default:
michaeldb632992008-12-10 17:55:19 +0100607 debug("unknown value %x\n", le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100608 goto unknown;
609 }
610 break;
611 case USB_REQ_GET_DESCRIPTOR | ((USB_DIR_IN | USB_RT_HUB) << 8):
612 switch (le16_to_cpu(req->value) >> 8) {
613 case USB_DT_HUB:
michaeldb632992008-12-10 17:55:19 +0100614 debug("USB_DT_HUB config\n");
615 srcptr = &descriptor.hub;
616 srclen = 0x8;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100617 break;
618 default:
michaeldb632992008-12-10 17:55:19 +0100619 debug("unknown value %x\n", le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100620 goto unknown;
621 }
622 break;
623 case USB_REQ_SET_ADDRESS | (USB_RECIP_DEVICE << 8):
michaeldb632992008-12-10 17:55:19 +0100624 debug("USB_REQ_SET_ADDRESS\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100625 rootdev = le16_to_cpu(req->value);
626 break;
627 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
michaeldb632992008-12-10 17:55:19 +0100628 debug("USB_REQ_SET_CONFIGURATION\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100629 /* Nothing to do */
630 break;
631 case USB_REQ_GET_STATUS | ((USB_DIR_IN | USB_RT_HUB) << 8):
632 tmpbuf[0] = 1; /* USB_STATUS_SELFPOWERED */
633 tmpbuf[1] = 0;
634 srcptr = tmpbuf;
635 srclen = 2;
636 break;
michaeldb632992008-12-10 17:55:19 +0100637 case USB_REQ_GET_STATUS | ((USB_RT_PORT | USB_DIR_IN) << 8):
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100638 memset(tmpbuf, 0, 4);
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100639 reg = ehci_readl(status_reg);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100640 if (reg & EHCI_PS_CS)
641 tmpbuf[0] |= USB_PORT_STAT_CONNECTION;
642 if (reg & EHCI_PS_PE)
643 tmpbuf[0] |= USB_PORT_STAT_ENABLE;
644 if (reg & EHCI_PS_SUSP)
645 tmpbuf[0] |= USB_PORT_STAT_SUSPEND;
646 if (reg & EHCI_PS_OCA)
647 tmpbuf[0] |= USB_PORT_STAT_OVERCURRENT;
Sergei Shtylyovc8b2d1d2010-02-27 21:33:21 +0300648 if (reg & EHCI_PS_PR)
649 tmpbuf[0] |= USB_PORT_STAT_RESET;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100650 if (reg & EHCI_PS_PP)
651 tmpbuf[1] |= USB_PORT_STAT_POWER >> 8;
Stefan Roese597eb282009-01-21 17:12:01 +0100652
653 if (ehci_is_TDI()) {
654 switch ((reg >> 26) & 3) {
655 case 0:
656 break;
657 case 1:
658 tmpbuf[1] |= USB_PORT_STAT_LOW_SPEED >> 8;
659 break;
660 case 2:
661 default:
662 tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8;
663 break;
664 }
665 } else {
666 tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8;
667 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100668
669 if (reg & EHCI_PS_CSC)
670 tmpbuf[2] |= USB_PORT_STAT_C_CONNECTION;
671 if (reg & EHCI_PS_PEC)
672 tmpbuf[2] |= USB_PORT_STAT_C_ENABLE;
673 if (reg & EHCI_PS_OCC)
674 tmpbuf[2] |= USB_PORT_STAT_C_OVERCURRENT;
675 if (portreset & (1 << le16_to_cpu(req->index)))
676 tmpbuf[2] |= USB_PORT_STAT_C_RESET;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100677
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100678 srcptr = tmpbuf;
679 srclen = 4;
680 break;
michaeldb632992008-12-10 17:55:19 +0100681 case USB_REQ_SET_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8):
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100682 reg = ehci_readl(status_reg);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100683 reg &= ~EHCI_PS_CLEAR;
684 switch (le16_to_cpu(req->value)) {
michael51ab1422008-12-11 13:43:55 +0100685 case USB_PORT_FEAT_ENABLE:
686 reg |= EHCI_PS_PE;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100687 ehci_writel(status_reg, reg);
michael51ab1422008-12-11 13:43:55 +0100688 break;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100689 case USB_PORT_FEAT_POWER:
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100690 if (HCS_PPC(ehci_readl(&hccr->cr_hcsparams))) {
691 reg |= EHCI_PS_PP;
692 ehci_writel(status_reg, reg);
693 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100694 break;
695 case USB_PORT_FEAT_RESET:
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100696 if ((reg & (EHCI_PS_PE | EHCI_PS_CS)) == EHCI_PS_CS &&
697 !ehci_is_TDI() &&
698 EHCI_PS_IS_LOWSPEED(reg)) {
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100699 /* Low speed device, give up ownership. */
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100700 debug("port %d low speed --> companion\n",
701 req->index - 1);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100702 reg |= EHCI_PS_PO;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100703 ehci_writel(status_reg, reg);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100704 break;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100705 } else {
Sergei Shtylyovc8b2d1d2010-02-27 21:33:21 +0300706 int ret;
707
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100708 reg |= EHCI_PS_PR;
709 reg &= ~EHCI_PS_PE;
710 ehci_writel(status_reg, reg);
711 /*
712 * caller must wait, then call GetPortStatus
713 * usb 2.0 specification say 50 ms resets on
714 * root
715 */
716 wait_ms(50);
Chris Zhangb4161912010-01-06 13:34:04 -0800717 /* terminate the reset */
718 ehci_writel(status_reg, reg & ~EHCI_PS_PR);
Sergei Shtylyovc8b2d1d2010-02-27 21:33:21 +0300719 /*
720 * A host controller must terminate the reset
721 * and stabilize the state of the port within
722 * 2 milliseconds
723 */
724 ret = handshake(status_reg, EHCI_PS_PR, 0,
725 2 * 1000);
726 if (!ret)
727 portreset |=
728 1 << le16_to_cpu(req->index);
729 else
730 printf("port(%d) reset error\n",
731 le16_to_cpu(req->index) - 1);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100732 }
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100733 break;
734 default:
michaeldb632992008-12-10 17:55:19 +0100735 debug("unknown feature %x\n", le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100736 goto unknown;
737 }
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100738 /* unblock posted writes */
Kumar Gala50243e32009-07-07 15:48:58 -0500739 (void) ehci_readl(&hcor->or_usbcmd);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100740 break;
michaeldb632992008-12-10 17:55:19 +0100741 case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8):
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100742 reg = ehci_readl(status_reg);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100743 switch (le16_to_cpu(req->value)) {
744 case USB_PORT_FEAT_ENABLE:
745 reg &= ~EHCI_PS_PE;
746 break;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100747 case USB_PORT_FEAT_C_ENABLE:
748 reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_PE;
749 break;
750 case USB_PORT_FEAT_POWER:
751 if (HCS_PPC(ehci_readl(&hccr->cr_hcsparams)))
752 reg = reg & ~(EHCI_PS_CLEAR | EHCI_PS_PP);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100753 case USB_PORT_FEAT_C_CONNECTION:
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100754 reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_CSC;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100755 break;
michael51ab1422008-12-11 13:43:55 +0100756 case USB_PORT_FEAT_OVER_CURRENT:
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100757 reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_OCC;
michael51ab1422008-12-11 13:43:55 +0100758 break;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100759 case USB_PORT_FEAT_C_RESET:
760 portreset &= ~(1 << le16_to_cpu(req->index));
761 break;
762 default:
michaeldb632992008-12-10 17:55:19 +0100763 debug("unknown feature %x\n", le16_to_cpu(req->value));
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100764 goto unknown;
765 }
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100766 ehci_writel(status_reg, reg);
767 /* unblock posted write */
Kumar Gala50243e32009-07-07 15:48:58 -0500768 (void) ehci_readl(&hcor->or_usbcmd);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100769 break;
770 default:
michaeldb632992008-12-10 17:55:19 +0100771 debug("Unknown request\n");
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100772 goto unknown;
773 }
774
michaeldb632992008-12-10 17:55:19 +0100775 wait_ms(1);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100776 len = min3(srclen, le16_to_cpu(req->length), length);
777 if (srcptr != NULL && len > 0)
778 memcpy(buffer, srcptr, len);
michaeldb632992008-12-10 17:55:19 +0100779 else
780 debug("Len is 0\n");
781
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100782 dev->act_len = len;
783 dev->status = 0;
784 return 0;
785
786unknown:
michaeldb632992008-12-10 17:55:19 +0100787 debug("requesttype=%x, request=%x, value=%x, index=%x, length=%x\n",
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100788 req->requesttype, req->request, le16_to_cpu(req->value),
789 le16_to_cpu(req->index), le16_to_cpu(req->length));
790
791 dev->act_len = 0;
792 dev->status = USB_ST_STALLED;
793 return -1;
794}
795
796int usb_lowlevel_stop(void)
797{
798 return ehci_hcd_stop();
799}
800
801int usb_lowlevel_init(void)
802{
803 uint32_t reg;
michaeldb632992008-12-10 17:55:19 +0100804 uint32_t cmd;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100805
806 if (ehci_hcd_init() != 0)
807 return -1;
808
michael51ab1422008-12-11 13:43:55 +0100809 /* EHCI spec section 4.1 */
810 if (ehci_reset() != 0)
811 return -1;
812
Stefan Roese832e6142009-01-21 17:12:10 +0100813#if defined(CONFIG_EHCI_HCD_INIT_AFTER_RESET)
814 if (ehci_hcd_init() != 0)
815 return -1;
816#endif
817
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100818 /* Set head of reclaim list */
819 memset(&qh_list, 0, sizeof(qh_list));
michaeldb632992008-12-10 17:55:19 +0100820 qh_list.qh_link = cpu_to_hc32((uint32_t)&qh_list | QH_LINK_TYPE_QH);
821 qh_list.qh_endpt1 = cpu_to_hc32((1 << 15) | (USB_SPEED_HIGH << 12));
822 qh_list.qh_curtd = cpu_to_hc32(QT_NEXT_TERMINATE);
823 qh_list.qh_overlay.qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
824 qh_list.qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
825 qh_list.qh_overlay.qt_token = cpu_to_hc32(0x40);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100826
827 /* Set async. queue head pointer. */
michael51ab1422008-12-11 13:43:55 +0100828 ehci_writel(&hcor->or_asynclistaddr, (uint32_t)&qh_list);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100829
michael51ab1422008-12-11 13:43:55 +0100830 reg = ehci_readl(&hccr->cr_hcsparams);
831 descriptor.hub.bNbrPorts = HCS_N_PORTS(reg);
832 printf("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts);
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100833 /* Port Indicators */
834 if (HCS_INDICATOR(reg))
michaeldb632992008-12-10 17:55:19 +0100835 descriptor.hub.wHubCharacteristics |= 0x80;
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100836 /* Port Power Control */
837 if (HCS_PPC(reg))
michaeldb632992008-12-10 17:55:19 +0100838 descriptor.hub.wHubCharacteristics |= 0x01;
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100839
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100840 /* Start the host controller. */
michael51ab1422008-12-11 13:43:55 +0100841 cmd = ehci_readl(&hcor->or_usbcmd);
Wolfgang Denkf15c6512009-02-12 00:08:39 +0100842 /*
843 * Philips, Intel, and maybe others need CMD_RUN before the
844 * root hub will detect new devices (why?); NEC doesn't
845 */
michael51ab1422008-12-11 13:43:55 +0100846 cmd &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
847 cmd |= CMD_RUN;
848 ehci_writel(&hcor->or_usbcmd, cmd);
849
850 /* take control over the ports */
851 cmd = ehci_readl(&hcor->or_configflag);
852 cmd |= FLAG_CF;
853 ehci_writel(&hcor->or_configflag, cmd);
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100854 /* unblock posted write */
michael51ab1422008-12-11 13:43:55 +0100855 cmd = ehci_readl(&hcor->or_usbcmd);
856 wait_ms(5);
Remy Böhmerc0d722f2008-12-13 22:51:58 +0100857 reg = HC_VERSION(ehci_readl(&hccr->cr_capbase));
858 printf("USB EHCI %x.%02x\n", reg >> 8, reg & 0xff);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100859
860 rootdev = 0;
861
862 return 0;
863}
864
865int
866submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
867 int length)
868{
869
870 if (usb_pipetype(pipe) != PIPE_BULK) {
871 debug("non-bulk pipe (type=%lu)", usb_pipetype(pipe));
872 return -1;
873 }
874 return ehci_submit_async(dev, pipe, buffer, length, NULL);
875}
876
877int
878submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
879 int length, struct devrequest *setup)
880{
881
882 if (usb_pipetype(pipe) != PIPE_CONTROL) {
883 debug("non-control pipe (type=%lu)", usb_pipetype(pipe));
884 return -1;
885 }
886
887 if (usb_pipedevice(pipe) == rootdev) {
888 if (rootdev == 0)
889 dev->speed = USB_SPEED_HIGH;
890 return ehci_submit_root(dev, pipe, buffer, length, setup);
891 }
892 return ehci_submit_async(dev, pipe, buffer, length, setup);
893}
894
895int
896submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
897 int length, int interval)
898{
899
900 debug("dev=%p, pipe=%lu, buffer=%p, length=%d, interval=%d",
901 dev, pipe, buffer, length, interval);
Marek Vasut7555d5e2011-09-25 21:07:56 +0200902 return ehci_submit_async(dev, pipe, buffer, length, NULL);
Michael Trimarchiaaf098c2008-11-28 13:20:46 +0100903}
Marek Vasut7555d5e2011-09-25 21:07:56 +0200904
905#ifdef CONFIG_SYS_USB_EVENT_POLL
906/*
907 * This function polls for USB keyboard data.
908 */
909void usb_event_poll()
910{
911 struct stdio_dev *dev;
912 struct usb_device *usb_kbd_dev;
913 struct usb_interface *iface;
914 struct usb_endpoint_descriptor *ep;
915 int pipe;
916 int maxp;
917
918 /* Get the pointer to USB Keyboard device pointer */
919 dev = stdio_get_by_name("usbkbd");
920 usb_kbd_dev = (struct usb_device *)dev->priv;
921 iface = &usb_kbd_dev->config.if_desc[0];
922 ep = &iface->ep_desc[0];
923 pipe = usb_rcvintpipe(usb_kbd_dev, ep->bEndpointAddress);
924
925 /* Submit a interrupt transfer request */
926 maxp = usb_maxpacket(usb_kbd_dev, pipe);
927 usb_submit_int_msg(usb_kbd_dev, pipe, &new[0],
928 maxp > 8 ? 8 : maxp, ep->bInterval);
929}
930#endif /* CONFIG_SYS_USB_EVENT_POLL */