blob: 15aea98591e227a3ed16365c097339149409701e [file] [log] [blame]
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001/*
Zhang Wei4dae14c2007-06-06 10:08:14 +02002 * URB OHCI HCD (Host Controller Driver) for USB on the AT91RM9200 and PCI bus.
3 *
4 * Interrupt support is added. Now, it has been tested
5 * on ULI1575 chip and works well with USB keyboard.
6 *
7 * (C) Copyright 2007
8 * Zhang Wei, Freescale Semiconductor, Inc. <wei.zhang@freescale.com>
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02009 *
10 * (C) Copyright 2003
Detlev Zundel792a09e2009-05-13 10:54:10 +020011 * Gary Jennejohn, DENX Software Engineering <garyj@denx.de>
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020012 *
13 * Note: Much of this code has been derived from Linux 2.4
14 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
15 * (C) Copyright 2000-2002 David Brownell
16 *
17 * Modified for the MP2USB by (C) Copyright 2005 Eric Benard
18 * ebenard@eukrea.com - based on s3c24x0's driver
19 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020020 * SPDX-License-Identifier: GPL-2.0+
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020021 */
22/*
23 * IMPORTANT NOTES
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +020024 * 1 - Read doc/README.generic_usb_ohci
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020025 * 2 - this driver is intended for use with USB Mass Storage Devices
Zhang Wei4dae14c2007-06-06 10:08:14 +020026 * (BBB) and USB keyboard. There is NO support for Isochronous pipes!
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +020027 * 2 - when running on a PQFP208 AT91RM9200, define CONFIG_AT91C_PQFP_UHPBUG
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020028 * to activate workaround for bug #41 or this driver will NOT work!
29 */
30
31#include <common.h>
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +020032#include <asm/byteorder.h>
33
34#if defined(CONFIG_PCI_OHCI)
Zhang Wei4dae14c2007-06-06 10:08:14 +020035# include <pci.h>
Sergei Poselenov477434c2008-05-22 01:15:53 +020036#if !defined(CONFIG_PCI_OHCI_DEVNO)
37#define CONFIG_PCI_OHCI_DEVNO 0
38#endif
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +020039#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020040
41#include <malloc.h>
42#include <usb.h>
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020043
44#include "ohci.h"
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020045
Wolfgang Denke8da58f2007-11-19 12:59:14 +010046#ifdef CONFIG_AT91RM9200
47#include <asm/arch/hardware.h> /* needed for AT91_USB_HOST_BASE */
48#endif
49
Masahiro Yamadaf2168442014-11-06 14:59:35 +090050#if defined(CONFIG_CPU_ARM920T) || \
kevin.morfitt@fearnside-systems.co.ukac678042009-11-17 18:30:34 +090051 defined(CONFIG_S3C24X0) || \
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +010052 defined(CONFIG_440EP) || \
Zhang Wei4dae14c2007-06-06 10:08:14 +020053 defined(CONFIG_PCI_OHCI) || \
Stefan Roese2596f5b2008-03-05 12:29:32 +010054 defined(CONFIG_MPC5200) || \
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055 defined(CONFIG_SYS_OHCI_USE_NPS)
Markus Klotzbuecher24e37642006-05-23 10:33:11 +020056# define OHCI_USE_NPS /* force NoPowerSwitching mode */
57#endif
58
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020059#undef OHCI_VERBOSE_DEBUG /* not always helpful */
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +010060#undef DEBUG
61#undef SHOW_INFO
62#undef OHCI_FILL_TRACE
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020063
64/* For initializing controller (mask in an HCFS mode too) */
65#define OHCI_CONTROL_INIT \
66 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
67
Zhang Wei4dae14c2007-06-06 10:08:14 +020068#ifdef CONFIG_PCI_OHCI
69static struct pci_device_id ohci_pci_ids[] = {
70 {0x10b9, 0x5237}, /* ULI1575 PCI OHCI module ids */
David Saada97213f32007-09-17 17:04:47 +020071 {0x1033, 0x0035}, /* NEC PCI OHCI module ids */
TsiChung Liew3afac792008-01-11 20:42:58 -060072 {0x1131, 0x1561}, /* Philips 1561 PCI OHCI module ids */
Zhang Wei4dae14c2007-06-06 10:08:14 +020073 /* Please add supported PCI OHCI controller ids here */
74 {0, 0}
75};
76#endif
77
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +020078#ifdef CONFIG_PCI_EHCI_DEVNO
79static struct pci_device_id ehci_pci_ids[] = {
80 {0x1131, 0x1562}, /* Philips 1562 PCI EHCI module ids */
81 /* Please add supported PCI EHCI controller ids here */
82 {0, 0}
83};
84#endif
85
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020086#ifdef DEBUG
87#define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
88#else
Remy Bohmer6f5794a2008-09-16 14:55:43 +020089#define dbg(format, arg...) do {} while (0)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020090#endif /* DEBUG */
91#define err(format, arg...) printf("ERROR: " format "\n", ## arg)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020092#ifdef SHOW_INFO
93#define info(format, arg...) printf("INFO: " format "\n", ## arg)
94#else
Remy Bohmer6f5794a2008-09-16 14:55:43 +020095#define info(format, arg...) do {} while (0)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020096#endif
97
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098#ifdef CONFIG_SYS_OHCI_BE_CONTROLLER
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +020099# define m16_swap(x) cpu_to_be16(x)
100# define m32_swap(x) cpu_to_be32(x)
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +0100101#else
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +0200102# define m16_swap(x) cpu_to_le16(x)
103# define m32_swap(x) cpu_to_le32(x)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104#endif /* CONFIG_SYS_OHCI_BE_CONTROLLER */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200105
106/* global ohci_t */
107static ohci_t gohci;
108/* this must be aligned to a 256 byte boundary */
109struct ohci_hcca ghcca[1];
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200110
Hans de Goede6651c142015-05-05 23:56:11 +0200111/* mapping of the OHCI CC status to error codes */
112static int cc_to_error[16] = {
113 /* No Error */ 0,
114 /* CRC Error */ USB_ST_CRC_ERR,
115 /* Bit Stuff */ USB_ST_BIT_ERR,
116 /* Data Togg */ USB_ST_CRC_ERR,
117 /* Stall */ USB_ST_STALLED,
118 /* DevNotResp */ -1,
119 /* PIDCheck */ USB_ST_BIT_ERR,
120 /* UnExpPID */ USB_ST_BIT_ERR,
121 /* DataOver */ USB_ST_BUF_ERR,
122 /* DataUnder */ USB_ST_BUF_ERR,
123 /* reservd */ -1,
124 /* reservd */ -1,
125 /* BufferOver */ USB_ST_BUF_ERR,
126 /* BuffUnder */ USB_ST_BUF_ERR,
127 /* Not Access */ -1,
128 /* Not Access */ -1
129};
130
131static const char *cc_to_string[16] = {
132 "No Error",
133 "CRC: Last data packet from endpoint contained a CRC error.",
134 "BITSTUFFING: Last data packet from endpoint contained a bit " \
135 "stuffing violation",
136 "DATATOGGLEMISMATCH: Last packet from endpoint had data toggle PID\n" \
137 "that did not match the expected value.",
138 "STALL: TD was moved to the Done Queue because the endpoint returned" \
139 " a STALL PID",
140 "DEVICENOTRESPONDING: Device did not respond to token (IN) or did\n" \
141 "not provide a handshake (OUT)",
142 "PIDCHECKFAILURE: Check bits on PID from endpoint failed on data PID\n"\
143 "(IN) or handshake (OUT)",
144 "UNEXPECTEDPID: Receive PID was not valid when encountered or PID\n" \
145 "value is not defined.",
146 "DATAOVERRUN: The amount of data returned by the endpoint exceeded\n" \
147 "either the size of the maximum data packet allowed\n" \
148 "from the endpoint (found in MaximumPacketSize field\n" \
149 "of ED) or the remaining buffer size.",
150 "DATAUNDERRUN: The endpoint returned less than MaximumPacketSize\n" \
151 "and that amount was not sufficient to fill the\n" \
152 "specified buffer",
153 "reserved1",
154 "reserved2",
155 "BUFFEROVERRUN: During an IN, HC received data from endpoint faster\n" \
156 "than it could be written to system memory",
157 "BUFFERUNDERRUN: During an OUT, HC could not retrieve data from\n" \
158 "system memory fast enough to keep up with data USB " \
159 "data rate.",
160 "NOT ACCESSED: This code is set by software before the TD is placed" \
161 "on a list to be processed by the HC.(1)",
162 "NOT ACCESSED: This code is set by software before the TD is placed" \
163 "on a list to be processed by the HC.(2)",
164};
165
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200166static inline u32 roothub_a(struct ohci *hc)
Becky Brucea5496a12010-06-30 13:05:44 -0500167 { return ohci_readl(&hc->regs->roothub.a); }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200168static inline u32 roothub_b(struct ohci *hc)
Becky Brucea5496a12010-06-30 13:05:44 -0500169 { return ohci_readl(&hc->regs->roothub.b); }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200170static inline u32 roothub_status(struct ohci *hc)
Becky Brucea5496a12010-06-30 13:05:44 -0500171 { return ohci_readl(&hc->regs->roothub.status); }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200172static inline u32 roothub_portstatus(struct ohci *hc, int i)
Becky Brucea5496a12010-06-30 13:05:44 -0500173 { return ohci_readl(&hc->regs->roothub.portstatus[i]); }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200174
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200175/* forward declaration */
Hans de Goedec5613df2015-05-05 23:56:07 +0200176static int hc_interrupt(ohci_t *ohci);
177static void td_submit_job(ohci_t *ohci, struct usb_device *dev,
178 unsigned long pipe, void *buffer, int transfer_len,
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200179 struct devrequest *setup, urb_priv_t *urb,
180 int interval);
Hans de Goede6651c142015-05-05 23:56:11 +0200181static int ep_link(ohci_t * ohci, ed_t * ed);
182static int ep_unlink(ohci_t * ohci, ed_t * ed);
183static ed_t *ep_add_ed(ohci_dev_t *ohci_dev, struct usb_device *usb_dev,
184 unsigned long pipe, int interval, int load);
185
186/*-------------------------------------------------------------------------*/
187
188/* TDs ... */
189static struct td *td_alloc(ohci_dev_t *ohci_dev, struct usb_device *usb_dev)
190{
191 int i;
192 struct td *td;
193
194 td = NULL;
195 for (i = 0; i < NUM_TD; i++)
196 {
197 if (ohci_dev->tds[i].usb_dev == NULL)
198 {
199 td = &ohci_dev->tds[i];
200 td->usb_dev = usb_dev;
201 break;
202 }
203 }
204
205 return td;
206}
207
208static inline void ed_free(struct ed *ed)
209{
210 ed->usb_dev = NULL;
211}
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200212
213/*-------------------------------------------------------------------------*
214 * URB support functions
215 *-------------------------------------------------------------------------*/
216
217/* free HCD-private data associated with this URB */
218
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200219static void urb_free_priv(urb_priv_t *urb)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200220{
221 int i;
222 int last;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200223 struct td *td;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200224
225 last = urb->length - 1;
226 if (last >= 0) {
227 for (i = 0; i <= last; i++) {
228 td = urb->td[i];
229 if (td) {
230 td->usb_dev = NULL;
231 urb->td[i] = NULL;
232 }
233 }
234 }
Zhang Wei4dae14c2007-06-06 10:08:14 +0200235 free(urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200236}
237
238/*-------------------------------------------------------------------------*/
239
240#ifdef DEBUG
Hans de Goedec5613df2015-05-05 23:56:07 +0200241static int sohci_get_current_frame_number(ohci_t *ohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200242
243/* debug| print the main components of an URB
244 * small: 0) header + data packets 1) just header */
245
Hans de Goedec5613df2015-05-05 23:56:07 +0200246static void pkt_print(ohci_t *ohci, urb_priv_t *purb, struct usb_device *dev,
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200247 unsigned long pipe, void *buffer, int transfer_len,
248 struct devrequest *setup, char *str, int small)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200249{
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200250 dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200251 str,
Hans de Goedec5613df2015-05-05 23:56:07 +0200252 sohci_get_current_frame_number(ohci),
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200253 usb_pipedevice(pipe),
254 usb_pipeendpoint(pipe),
255 usb_pipeout(pipe)? 'O': 'I',
256 usb_pipetype(pipe) < 2 ? \
257 (usb_pipeint(pipe)? "INTR": "ISOC"): \
258 (usb_pipecontrol(pipe)? "CTRL": "BULK"),
Zhang Wei4dae14c2007-06-06 10:08:14 +0200259 (purb ? purb->actual_length : 0),
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200260 transfer_len, dev->status);
261#ifdef OHCI_VERBOSE_DEBUG
262 if (!small) {
263 int i, len;
264
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200265 if (usb_pipecontrol(pipe)) {
266 printf(__FILE__ ": cmd(8):");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200267 for (i = 0; i < 8 ; i++)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200268 printf(" %02x", ((__u8 *) setup) [i]);
269 printf("\n");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200270 }
271 if (transfer_len > 0 && buffer) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200272 printf(__FILE__ ": data(%d/%d):",
Zhang Wei4dae14c2007-06-06 10:08:14 +0200273 (purb ? purb->actual_length : 0),
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200274 transfer_len);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200275 len = usb_pipeout(pipe)? transfer_len:
Zhang Wei4dae14c2007-06-06 10:08:14 +0200276 (purb ? purb->actual_length : 0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200277 for (i = 0; i < 16 && i < len; i++)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200278 printf(" %02x", ((__u8 *) buffer) [i]);
279 printf("%s\n", i < len? "...": "");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200280 }
281 }
282#endif
283}
284
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200285/* just for debugging; prints non-empty branches of the int ed tree
286 * inclusive iso eds */
287void ep_print_int_eds(ohci_t *ohci, char *str)
288{
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200289 int i, j;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200290 __u32 *ed_p;
291 for (i = 0; i < 32; i++) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200292 j = 5;
293 ed_p = &(ohci->hcca->int_table [i]);
294 if (*ed_p == 0)
295 continue;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200296 printf(__FILE__ ": %s branch int %2d(%2x):", str, i, i);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200297 while (*ed_p != 0 && j--) {
298 ed_t *ed = (ed_t *)m32_swap(ed_p);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200299 printf(" ed: %4x;", ed->hwINFO);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200300 ed_p = &ed->hwNextED;
301 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200302 printf("\n");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200303 }
304}
305
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200306static void ohci_dump_intr_mask(char *label, __u32 mask)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200307{
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200308 dbg("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200309 label,
310 mask,
311 (mask & OHCI_INTR_MIE) ? " MIE" : "",
312 (mask & OHCI_INTR_OC) ? " OC" : "",
313 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
314 (mask & OHCI_INTR_FNO) ? " FNO" : "",
315 (mask & OHCI_INTR_UE) ? " UE" : "",
316 (mask & OHCI_INTR_RD) ? " RD" : "",
317 (mask & OHCI_INTR_SF) ? " SF" : "",
318 (mask & OHCI_INTR_WDH) ? " WDH" : "",
319 (mask & OHCI_INTR_SO) ? " SO" : ""
320 );
321}
322
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200323static void maybe_print_eds(char *label, __u32 value)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200324{
325 ed_t *edp = (ed_t *)value;
326
327 if (value) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200328 dbg("%s %08x", label, value);
329 dbg("%08x", edp->hwINFO);
330 dbg("%08x", edp->hwTailP);
331 dbg("%08x", edp->hwHeadP);
332 dbg("%08x", edp->hwNextED);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200333 }
334}
335
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200336static char *hcfs2string(int state)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200337{
338 switch (state) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200339 case OHCI_USB_RESET: return "reset";
340 case OHCI_USB_RESUME: return "resume";
341 case OHCI_USB_OPER: return "operational";
342 case OHCI_USB_SUSPEND: return "suspend";
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200343 }
344 return "?";
345}
346
347/* dump control and status registers */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200348static void ohci_dump_status(ohci_t *controller)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200349{
350 struct ohci_regs *regs = controller->regs;
351 __u32 temp;
352
Becky Brucea5496a12010-06-30 13:05:44 -0500353 temp = ohci_readl(&regs->revision) & 0xff;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200354 if (temp != 0x10)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200355 dbg("spec %d.%d", (temp >> 4), (temp & 0x0f));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200356
Becky Brucea5496a12010-06-30 13:05:44 -0500357 temp = ohci_readl(&regs->control);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200358 dbg("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200359 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
360 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
361 (temp & OHCI_CTRL_IR) ? " IR" : "",
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200362 hcfs2string(temp & OHCI_CTRL_HCFS),
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200363 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
364 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
365 (temp & OHCI_CTRL_IE) ? " IE" : "",
366 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
367 temp & OHCI_CTRL_CBSR
368 );
369
Becky Brucea5496a12010-06-30 13:05:44 -0500370 temp = ohci_readl(&regs->cmdstatus);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200371 dbg("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200372 (temp & OHCI_SOC) >> 16,
373 (temp & OHCI_OCR) ? " OCR" : "",
374 (temp & OHCI_BLF) ? " BLF" : "",
375 (temp & OHCI_CLF) ? " CLF" : "",
376 (temp & OHCI_HCR) ? " HCR" : ""
377 );
378
Becky Brucea5496a12010-06-30 13:05:44 -0500379 ohci_dump_intr_mask("intrstatus", ohci_readl(&regs->intrstatus));
380 ohci_dump_intr_mask("intrenable", ohci_readl(&regs->intrenable));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200381
Becky Brucea5496a12010-06-30 13:05:44 -0500382 maybe_print_eds("ed_periodcurrent",
383 ohci_readl(&regs->ed_periodcurrent));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200384
Becky Brucea5496a12010-06-30 13:05:44 -0500385 maybe_print_eds("ed_controlhead", ohci_readl(&regs->ed_controlhead));
386 maybe_print_eds("ed_controlcurrent",
387 ohci_readl(&regs->ed_controlcurrent));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200388
Becky Brucea5496a12010-06-30 13:05:44 -0500389 maybe_print_eds("ed_bulkhead", ohci_readl(&regs->ed_bulkhead));
390 maybe_print_eds("ed_bulkcurrent", ohci_readl(&regs->ed_bulkcurrent));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200391
Becky Brucea5496a12010-06-30 13:05:44 -0500392 maybe_print_eds("donehead", ohci_readl(&regs->donehead));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200393}
394
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200395static void ohci_dump_roothub(ohci_t *controller, int verbose)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200396{
397 __u32 temp, ndp, i;
398
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200399 temp = roothub_a(controller);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200400 ndp = (temp & RH_A_NDP);
401#ifdef CONFIG_AT91C_PQFP_UHPBUG
402 ndp = (ndp == 2) ? 1:0;
403#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200404 if (verbose) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200405 dbg("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200406 ((temp & RH_A_POTPGT) >> 24) & 0xff,
407 (temp & RH_A_NOCP) ? " NOCP" : "",
408 (temp & RH_A_OCPM) ? " OCPM" : "",
409 (temp & RH_A_DT) ? " DT" : "",
410 (temp & RH_A_NPS) ? " NPS" : "",
411 (temp & RH_A_PSM) ? " PSM" : "",
412 ndp
413 );
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200414 temp = roothub_b(controller);
415 dbg("roothub.b: %08x PPCM=%04x DR=%04x",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200416 temp,
417 (temp & RH_B_PPCM) >> 16,
418 (temp & RH_B_DR)
419 );
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200420 temp = roothub_status(controller);
421 dbg("roothub.status: %08x%s%s%s%s%s%s",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200422 temp,
423 (temp & RH_HS_CRWE) ? " CRWE" : "",
424 (temp & RH_HS_OCIC) ? " OCIC" : "",
425 (temp & RH_HS_LPSC) ? " LPSC" : "",
426 (temp & RH_HS_DRWE) ? " DRWE" : "",
427 (temp & RH_HS_OCI) ? " OCI" : "",
428 (temp & RH_HS_LPS) ? " LPS" : ""
429 );
430 }
431
432 for (i = 0; i < ndp; i++) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200433 temp = roothub_portstatus(controller, i);
434 dbg("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200435 i,
436 temp,
437 (temp & RH_PS_PRSC) ? " PRSC" : "",
438 (temp & RH_PS_OCIC) ? " OCIC" : "",
439 (temp & RH_PS_PSSC) ? " PSSC" : "",
440 (temp & RH_PS_PESC) ? " PESC" : "",
441 (temp & RH_PS_CSC) ? " CSC" : "",
442
443 (temp & RH_PS_LSDA) ? " LSDA" : "",
444 (temp & RH_PS_PPS) ? " PPS" : "",
445 (temp & RH_PS_PRS) ? " PRS" : "",
446 (temp & RH_PS_POCI) ? " POCI" : "",
447 (temp & RH_PS_PSS) ? " PSS" : "",
448
449 (temp & RH_PS_PES) ? " PES" : "",
450 (temp & RH_PS_CCS) ? " CCS" : ""
451 );
452 }
453}
454
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200455static void ohci_dump(ohci_t *controller, int verbose)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200456{
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200457 dbg("OHCI controller usb-%s state", controller->slot_name);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200458
459 /* dumps some of the state we know about */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200460 ohci_dump_status(controller);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200461 if (verbose)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200462 ep_print_int_eds(controller, "hcca");
463 dbg("hcca frame #%04x", controller->hcca->frame_no);
464 ohci_dump_roothub(controller, 1);
Stefan Roese2596f5b2008-03-05 12:29:32 +0100465}
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200466#endif /* DEBUG */
467
468/*-------------------------------------------------------------------------*
469 * Interface functions (URB)
470 *-------------------------------------------------------------------------*/
471
472/* get a transfer request */
473
Hans de Goede19d95d52015-05-05 23:56:08 +0200474int sohci_submit_job(ohci_t *ohci, ohci_dev_t *ohci_dev, urb_priv_t *urb,
475 struct devrequest *setup)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200476{
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200477 ed_t *ed;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200478 urb_priv_t *purb_priv = urb;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200479 int i, size = 0;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200480 struct usb_device *dev = urb->dev;
481 unsigned long pipe = urb->pipe;
482 void *buffer = urb->transfer_buffer;
483 int transfer_len = urb->transfer_buffer_length;
484 int interval = urb->interval;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200485
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200486 /* when controller's hung, permit only roothub cleanup attempts
487 * such as powering down ports */
488 if (ohci->disabled) {
489 err("sohci_submit_job: EPIPE");
490 return -1;
491 }
Markus Klotzbuecherae79f602007-03-26 11:21:05 +0200492
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200493 /* we're about to begin a new transaction here so mark the
494 * URB unfinished */
Zhang Wei4dae14c2007-06-06 10:08:14 +0200495 urb->finished = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200496
497 /* every endpoint has a ed, locate and fill it */
Hans de Goede19d95d52015-05-05 23:56:08 +0200498 ed = ep_add_ed(ohci_dev, dev, pipe, interval, 1);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200499 if (!ed) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200500 err("sohci_submit_job: ENOMEM");
501 return -1;
502 }
503
504 /* for the private part of the URB we need the number of TDs (size) */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200505 switch (usb_pipetype(pipe)) {
506 case PIPE_BULK: /* one TD for every 4096 Byte */
507 size = (transfer_len - 1) / 4096 + 1;
508 break;
509 case PIPE_CONTROL:/* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
510 size = (transfer_len == 0)? 2:
511 (transfer_len - 1) / 4096 + 3;
512 break;
513 case PIPE_INTERRUPT: /* 1 TD */
514 size = 1;
515 break;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200516 }
517
Zhang Wei4dae14c2007-06-06 10:08:14 +0200518 ed->purb = urb;
519
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200520 if (size >= (N_URB_TD - 1)) {
521 err("need %d TDs, only have %d", size, N_URB_TD);
522 return -1;
523 }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200524 purb_priv->pipe = pipe;
525
526 /* fill the private part of the URB */
527 purb_priv->length = size;
528 purb_priv->ed = ed;
529 purb_priv->actual_length = 0;
530
531 /* allocate the TDs */
532 /* note that td[0] was allocated in ep_add_ed */
533 for (i = 0; i < size; i++) {
Hans de Goede3c5497d2015-05-05 23:56:09 +0200534 purb_priv->td[i] = td_alloc(ohci_dev, dev);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200535 if (!purb_priv->td[i]) {
536 purb_priv->length = i;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200537 urb_free_priv(purb_priv);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200538 err("sohci_submit_job: ENOMEM");
539 return -1;
540 }
541 }
542
543 if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200544 urb_free_priv(purb_priv);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200545 err("sohci_submit_job: EINVAL");
546 return -1;
547 }
548
549 /* link the ed into a chain if is not already */
550 if (ed->state != ED_OPER)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200551 ep_link(ohci, ed);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200552
553 /* fill the TDs and link it to the ed */
Hans de Goedec5613df2015-05-05 23:56:07 +0200554 td_submit_job(ohci, dev, pipe, buffer, transfer_len,
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200555 setup, purb_priv, interval);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200556
557 return 0;
558}
559
Zhang Wei4dae14c2007-06-06 10:08:14 +0200560static inline int sohci_return_job(struct ohci *hc, urb_priv_t *urb)
561{
562 struct ohci_regs *regs = hc->regs;
563
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200564 switch (usb_pipetype(urb->pipe)) {
Zhang Wei4dae14c2007-06-06 10:08:14 +0200565 case PIPE_INTERRUPT:
566 /* implicitly requeued */
567 if (urb->dev->irq_handle &&
568 (urb->dev->irq_act_len = urb->actual_length)) {
Becky Brucea5496a12010-06-30 13:05:44 -0500569 ohci_writel(OHCI_INTR_WDH, &regs->intrenable);
570 ohci_readl(&regs->intrenable); /* PCI posting flush */
Zhang Wei4dae14c2007-06-06 10:08:14 +0200571 urb->dev->irq_handle(urb->dev);
Becky Brucea5496a12010-06-30 13:05:44 -0500572 ohci_writel(OHCI_INTR_WDH, &regs->intrdisable);
573 ohci_readl(&regs->intrdisable); /* PCI posting flush */
Zhang Wei4dae14c2007-06-06 10:08:14 +0200574 }
575 urb->actual_length = 0;
Hans de Goedec5613df2015-05-05 23:56:07 +0200576 td_submit_job( hc,
Zhang Wei4dae14c2007-06-06 10:08:14 +0200577 urb->dev,
578 urb->pipe,
579 urb->transfer_buffer,
580 urb->transfer_buffer_length,
581 NULL,
582 urb,
583 urb->interval);
584 break;
585 case PIPE_CONTROL:
586 case PIPE_BULK:
587 break;
588 default:
589 return 0;
590 }
591 return 1;
592}
593
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200594/*-------------------------------------------------------------------------*/
595
596#ifdef DEBUG
597/* tell us the current USB frame number */
Hans de Goedec5613df2015-05-05 23:56:07 +0200598static int sohci_get_current_frame_number(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200599{
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200600 return m16_swap(ohci->hcca->frame_no);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200601}
602#endif
603
604/*-------------------------------------------------------------------------*
605 * ED handling functions
606 *-------------------------------------------------------------------------*/
607
Zhang Wei4dae14c2007-06-06 10:08:14 +0200608/* search for the right branch to insert an interrupt ed into the int tree
609 * do some load ballancing;
610 * returns the branch and
611 * sets the interval to interval = 2^integer (ld (interval)) */
612
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200613static int ep_int_ballance(ohci_t *ohci, int interval, int load)
Zhang Wei4dae14c2007-06-06 10:08:14 +0200614{
615 int i, branch = 0;
616
617 /* search for the least loaded interrupt endpoint
618 * branch of all 32 branches
619 */
620 for (i = 0; i < 32; i++)
621 if (ohci->ohci_int_load [branch] > ohci->ohci_int_load [i])
622 branch = i;
623
624 branch = branch % interval;
625 for (i = branch; i < 32; i += interval)
626 ohci->ohci_int_load [i] += load;
627
628 return branch;
629}
630
631/*-------------------------------------------------------------------------*/
632
633/* 2^int( ld (inter)) */
634
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200635static int ep_2_n_interval(int inter)
Zhang Wei4dae14c2007-06-06 10:08:14 +0200636{
637 int i;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200638 for (i = 0; ((inter >> i) > 1) && (i < 5); i++);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200639 return 1 << i;
640}
641
642/*-------------------------------------------------------------------------*/
643
644/* the int tree is a binary tree
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200645 * in order to process it sequentially the indexes of the branches have to
646 * be mapped the mapping reverses the bits of a word of num_bits length */
647static int ep_rev(int num_bits, int word)
Zhang Wei4dae14c2007-06-06 10:08:14 +0200648{
649 int i, wout = 0;
650
651 for (i = 0; i < num_bits; i++)
652 wout |= (((word >> i) & 1) << (num_bits - i - 1));
653 return wout;
654}
655
656/*-------------------------------------------------------------------------*
657 * ED handling functions
658 *-------------------------------------------------------------------------*/
659
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200660/* link an ed into one of the HC chains */
661
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200662static int ep_link(ohci_t *ohci, ed_t *edi)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200663{
664 volatile ed_t *ed = edi;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200665 int int_branch;
666 int i;
667 int inter;
668 int interval;
669 int load;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200670 __u32 *ed_p;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200671
672 ed->state = ED_OPER;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200673 ed->int_interval = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200674
675 switch (ed->type) {
676 case PIPE_CONTROL:
677 ed->hwNextED = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200678 if (ohci->ed_controltail == NULL)
Becky Brucea5496a12010-06-30 13:05:44 -0500679 ohci_writel(ed, &ohci->regs->ed_controlhead);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200680 else
681 ohci->ed_controltail->hwNextED =
682 m32_swap((unsigned long)ed);
683
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200684 ed->ed_prev = ohci->ed_controltail;
685 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
686 !ohci->ed_rm_list[1] && !ohci->sleeping) {
687 ohci->hc_control |= OHCI_CTRL_CLE;
Becky Brucea5496a12010-06-30 13:05:44 -0500688 ohci_writel(ohci->hc_control, &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200689 }
690 ohci->ed_controltail = edi;
691 break;
692
693 case PIPE_BULK:
694 ed->hwNextED = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200695 if (ohci->ed_bulktail == NULL)
Becky Brucea5496a12010-06-30 13:05:44 -0500696 ohci_writel(ed, &ohci->regs->ed_bulkhead);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200697 else
698 ohci->ed_bulktail->hwNextED =
699 m32_swap((unsigned long)ed);
700
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200701 ed->ed_prev = ohci->ed_bulktail;
702 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
703 !ohci->ed_rm_list[1] && !ohci->sleeping) {
704 ohci->hc_control |= OHCI_CTRL_BLE;
Becky Brucea5496a12010-06-30 13:05:44 -0500705 ohci_writel(ohci->hc_control, &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200706 }
707 ohci->ed_bulktail = edi;
708 break;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200709
710 case PIPE_INTERRUPT:
711 load = ed->int_load;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200712 interval = ep_2_n_interval(ed->int_period);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200713 ed->int_interval = interval;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200714 int_branch = ep_int_ballance(ohci, interval, load);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200715 ed->int_branch = int_branch;
716
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200717 for (i = 0; i < ep_rev(6, interval); i += inter) {
Zhang Wei4dae14c2007-06-06 10:08:14 +0200718 inter = 1;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200719 for (ed_p = &(ohci->hcca->int_table[\
720 ep_rev(5, i) + int_branch]);
721 (*ed_p != 0) &&
722 (((ed_t *)ed_p)->int_interval >= interval);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200723 ed_p = &(((ed_t *)ed_p)->hwNextED))
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200724 inter = ep_rev(6,
725 ((ed_t *)ed_p)->int_interval);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200726 ed->hwNextED = *ed_p;
Martin Krause4a8527e2007-08-21 12:40:34 +0200727 *ed_p = m32_swap((unsigned long)ed);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200728 }
729 break;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200730 }
731 return 0;
732}
733
734/*-------------------------------------------------------------------------*/
735
Zhang Wei4dae14c2007-06-06 10:08:14 +0200736/* scan the periodic table to find and unlink this ED */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200737static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
738 unsigned index, unsigned period)
Zhang Wei4dae14c2007-06-06 10:08:14 +0200739{
740 for (; index < NUM_INTS; index += period) {
741 __u32 *ed_p = &ohci->hcca->int_table [index];
742
743 /* ED might have been unlinked through another path */
744 while (*ed_p != 0) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200745 if (((struct ed *)
746 m32_swap((unsigned long)ed_p)) == ed) {
Zhang Wei4dae14c2007-06-06 10:08:14 +0200747 *ed_p = ed->hwNextED;
748 break;
749 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200750 ed_p = &(((struct ed *)
751 m32_swap((unsigned long)ed_p))->hwNextED);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200752 }
753 }
754}
755
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200756/* unlink an ed from one of the HC chains.
757 * just the link to the ed is unlinked.
758 * the link from the ed still points to another operational ed or 0
759 * so the HC can eventually finish the processing of the unlinked ed */
760
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200761static int ep_unlink(ohci_t *ohci, ed_t *edi)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200762{
Markus Klotzbuecher53e336e2006-11-27 11:43:09 +0100763 volatile ed_t *ed = edi;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200764 int i;
Markus Klotzbuecher53e336e2006-11-27 11:43:09 +0100765
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200766 ed->hwINFO |= m32_swap(OHCI_ED_SKIP);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200767
768 switch (ed->type) {
769 case PIPE_CONTROL:
770 if (ed->ed_prev == NULL) {
771 if (!ed->hwNextED) {
772 ohci->hc_control &= ~OHCI_CTRL_CLE;
Becky Brucea5496a12010-06-30 13:05:44 -0500773 ohci_writel(ohci->hc_control,
774 &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200775 }
Becky Brucea5496a12010-06-30 13:05:44 -0500776 ohci_writel(m32_swap(*((__u32 *)&ed->hwNextED)),
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200777 &ohci->regs->ed_controlhead);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200778 } else {
779 ed->ed_prev->hwNextED = ed->hwNextED;
780 }
781 if (ohci->ed_controltail == ed) {
782 ohci->ed_controltail = ed->ed_prev;
783 } else {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200784 ((ed_t *)m32_swap(
785 *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200786 }
787 break;
788
789 case PIPE_BULK:
790 if (ed->ed_prev == NULL) {
791 if (!ed->hwNextED) {
792 ohci->hc_control &= ~OHCI_CTRL_BLE;
Becky Brucea5496a12010-06-30 13:05:44 -0500793 ohci_writel(ohci->hc_control,
794 &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200795 }
Becky Brucea5496a12010-06-30 13:05:44 -0500796 ohci_writel(m32_swap(*((__u32 *)&ed->hwNextED)),
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200797 &ohci->regs->ed_bulkhead);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200798 } else {
799 ed->ed_prev->hwNextED = ed->hwNextED;
800 }
801 if (ohci->ed_bulktail == ed) {
802 ohci->ed_bulktail = ed->ed_prev;
803 } else {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200804 ((ed_t *)m32_swap(
805 *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200806 }
807 break;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200808
809 case PIPE_INTERRUPT:
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200810 periodic_unlink(ohci, ed, 0, 1);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200811 for (i = ed->int_branch; i < 32; i += ed->int_interval)
812 ohci->ohci_int_load[i] -= ed->int_load;
813 break;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200814 }
815 ed->state = ED_UNLINK;
816 return 0;
817}
818
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200819/*-------------------------------------------------------------------------*/
820
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +0200821/* add/reinit an endpoint; this should be done once at the
822 * usb_set_configuration command, but the USB stack is a little bit
823 * stateless so we do it at every transaction if the state of the ed
824 * is ED_NEW then a dummy td is added and the state is changed to
825 * ED_UNLINK in all other cases the state is left unchanged the ed
826 * info fields are setted anyway even though most of them should not
827 * change
828 */
Hans de Goede19d95d52015-05-05 23:56:08 +0200829static ed_t *ep_add_ed(ohci_dev_t *ohci_dev, struct usb_device *usb_dev,
830 unsigned long pipe, int interval, int load)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200831{
832 td_t *td;
833 ed_t *ed_ret;
834 volatile ed_t *ed;
835
Hans de Goede19d95d52015-05-05 23:56:08 +0200836 ed = ed_ret = &ohci_dev->ed[(usb_pipeendpoint(pipe) << 1) |
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200837 (usb_pipecontrol(pipe)? 0: usb_pipeout(pipe))];
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200838
839 if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
840 err("ep_add_ed: pending delete");
841 /* pending delete request */
842 return NULL;
843 }
844
845 if (ed->state == ED_NEW) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200846 /* dummy td; end of td list for ed */
Hans de Goede3c5497d2015-05-05 23:56:09 +0200847 td = td_alloc(ohci_dev, usb_dev);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200848 ed->hwTailP = m32_swap((unsigned long)td);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200849 ed->hwHeadP = ed->hwTailP;
850 ed->state = ED_UNLINK;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200851 ed->type = usb_pipetype(pipe);
Hans de Goede19d95d52015-05-05 23:56:08 +0200852 ohci_dev->ed_cnt++;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200853 }
854
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200855 ed->hwINFO = m32_swap(usb_pipedevice(pipe)
856 | usb_pipeendpoint(pipe) << 7
857 | (usb_pipeisoc(pipe)? 0x8000: 0)
858 | (usb_pipecontrol(pipe)? 0: \
859 (usb_pipeout(pipe)? 0x800: 0x1000))
Ilya Yanokc60795f2012-11-06 13:48:20 +0000860 | (usb_dev->speed == USB_SPEED_LOW) << 13
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200861 | usb_maxpacket(usb_dev, pipe) << 16);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200862
Zhang Wei4dae14c2007-06-06 10:08:14 +0200863 if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) {
864 ed->int_period = interval;
865 ed->int_load = load;
866 }
867
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200868 return ed_ret;
869}
870
871/*-------------------------------------------------------------------------*
872 * TD handling functions
873 *-------------------------------------------------------------------------*/
874
875/* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
876
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200877static void td_fill(ohci_t *ohci, unsigned int info,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200878 void *data, int len,
879 struct usb_device *dev, int index, urb_priv_t *urb_priv)
880{
881 volatile td_t *td, *td_pt;
882#ifdef OHCI_FILL_TRACE
883 int i;
884#endif
885
886 if (index > urb_priv->length) {
887 err("index > length");
888 return;
889 }
890 /* use this td as the next dummy */
891 td_pt = urb_priv->td [index];
892 td_pt->hwNextTD = 0;
893
894 /* fill the old dummy TD */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200895 td = urb_priv->td [index] =
896 (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200897
898 td->ed = urb_priv->ed;
899 td->next_dl_td = NULL;
900 td->index = index;
901 td->data = (__u32)data;
902#ifdef OHCI_FILL_TRACE
Remy Bohmer48867202008-10-10 10:23:21 +0200903 if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200904 for (i = 0; i < len; i++)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200905 printf("td->data[%d] %#2x ", i, ((unsigned char *)td->data)[i]);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200906 printf("\n");
907 }
908#endif
909 if (!len)
910 data = 0;
911
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200912 td->hwINFO = m32_swap(info);
913 td->hwCBP = m32_swap((unsigned long)data);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200914 if (data)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200915 td->hwBE = m32_swap((unsigned long)(data + len - 1));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200916 else
917 td->hwBE = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200918
919 td->hwNextTD = m32_swap((unsigned long)td_pt);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200920
921 /* append to queue */
922 td->ed->hwTailP = td->hwNextTD;
923}
924
925/*-------------------------------------------------------------------------*/
926
927/* prepare all TDs of a transfer */
928
Hans de Goedec5613df2015-05-05 23:56:07 +0200929static void td_submit_job(ohci_t *ohci, struct usb_device *dev,
930 unsigned long pipe, void *buffer, int transfer_len,
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200931 struct devrequest *setup, urb_priv_t *urb,
932 int interval)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200933{
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200934 int data_len = transfer_len;
935 void *data;
936 int cnt = 0;
937 __u32 info = 0;
938 unsigned int toggle = 0;
939
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200940 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle
941 * bits for reseting */
942 if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200943 toggle = TD_T_TOGGLE;
944 } else {
945 toggle = TD_T_DATA0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200946 usb_settoggle(dev, usb_pipeendpoint(pipe),
947 usb_pipeout(pipe), 1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200948 }
949 urb->td_cnt = 0;
950 if (data_len)
951 data = buffer;
952 else
953 data = 0;
954
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200955 switch (usb_pipetype(pipe)) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200956 case PIPE_BULK:
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200957 info = usb_pipeout(pipe)?
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200958 TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200959 while (data_len > 4096) {
960 td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle),
961 data, 4096, dev, cnt, urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200962 data += 4096; data_len -= 4096; cnt++;
963 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200964 info = usb_pipeout(pipe)?
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200965 TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200966 td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), data,
967 data_len, dev, cnt, urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200968 cnt++;
969
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200970 if (!ohci->sleeping) {
971 /* start bulk list */
Becky Brucea5496a12010-06-30 13:05:44 -0500972 ohci_writel(OHCI_BLF, &ohci->regs->cmdstatus);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200973 }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200974 break;
975
976 case PIPE_CONTROL:
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200977 /* Setup phase */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200978 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200979 td_fill(ohci, info, setup, 8, dev, cnt++, urb);
980
981 /* Optional Data phase */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200982 if (data_len > 0) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200983 info = usb_pipeout(pipe)?
984 TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 :
985 TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200986 /* NOTE: mishandles transfers >8K, some >4K */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200987 td_fill(ohci, info, data, data_len, dev, cnt++, urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200988 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200989
990 /* Status phase */
991 info = usb_pipeout(pipe)?
992 TD_CC | TD_DP_IN | TD_T_DATA1:
993 TD_CC | TD_DP_OUT | TD_T_DATA1;
994 td_fill(ohci, info, data, 0, dev, cnt++, urb);
995
996 if (!ohci->sleeping) {
997 /* start Control list */
Becky Brucea5496a12010-06-30 13:05:44 -0500998 ohci_writel(OHCI_CLF, &ohci->regs->cmdstatus);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200999 }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001000 break;
Zhang Wei4dae14c2007-06-06 10:08:14 +02001001
1002 case PIPE_INTERRUPT:
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001003 info = usb_pipeout(urb->pipe)?
Zhang Wei4dae14c2007-06-06 10:08:14 +02001004 TD_CC | TD_DP_OUT | toggle:
1005 TD_CC | TD_R | TD_DP_IN | toggle;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001006 td_fill(ohci, info, data, data_len, dev, cnt++, urb);
Zhang Wei4dae14c2007-06-06 10:08:14 +02001007 break;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001008 }
1009 if (urb->length != cnt)
1010 dbg("TD LENGTH %d != CNT %d", urb->length, cnt);
1011}
1012
1013/*-------------------------------------------------------------------------*
1014 * Done List handling functions
1015 *-------------------------------------------------------------------------*/
1016
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001017/* calculate the transfer length and update the urb */
1018
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001019static void dl_transfer_length(td_t *td)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001020{
Wolfgang Denk6bc52ef2011-10-05 23:03:43 +02001021 __u32 tdBE, tdCBP;
Zhang Wei4dae14c2007-06-06 10:08:14 +02001022 urb_priv_t *lurb_priv = td->ed->purb;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001023
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001024 tdBE = m32_swap(td->hwBE);
1025 tdCBP = m32_swap(td->hwCBP);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001026
Remy Bohmer48867202008-10-10 10:23:21 +02001027 if (!(usb_pipecontrol(lurb_priv->pipe) &&
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001028 ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
1029 if (tdBE != 0) {
1030 if (td->hwCBP == 0)
1031 lurb_priv->actual_length += tdBE - td->data + 1;
1032 else
1033 lurb_priv->actual_length += tdCBP - td->data;
1034 }
1035 }
1036}
1037
1038/*-------------------------------------------------------------------------*/
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001039static void check_status(td_t *td_list)
1040{
1041 urb_priv_t *lurb_priv = td_list->ed->purb;
1042 int urb_len = lurb_priv->length;
1043 __u32 *phwHeadP = &td_list->ed->hwHeadP;
1044 int cc;
1045
1046 cc = TD_CC_GET(m32_swap(td_list->hwINFO));
1047 if (cc) {
1048 err(" USB-error: %s (%x)", cc_to_string[cc], cc);
1049
1050 if (*phwHeadP & m32_swap(0x1)) {
1051 if (lurb_priv &&
1052 ((td_list->index + 1) < urb_len)) {
1053 *phwHeadP =
1054 (lurb_priv->td[urb_len - 1]->hwNextTD &\
1055 m32_swap(0xfffffff0)) |
1056 (*phwHeadP & m32_swap(0x2));
1057
1058 lurb_priv->td_cnt += urb_len -
1059 td_list->index - 1;
1060 } else
1061 *phwHeadP &= m32_swap(0xfffffff2);
1062 }
1063#ifdef CONFIG_MPC5200
1064 td_list->hwNextTD = 0;
1065#endif
1066 }
1067}
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001068
1069/* replies to the request have to be on a FIFO basis so
1070 * we reverse the reversed done-list */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001071static td_t *dl_reverse_done_list(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001072{
1073 __u32 td_list_hc;
1074 td_t *td_rev = NULL;
1075 td_t *td_list = NULL;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001076
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001077 td_list_hc = m32_swap(ohci->hcca->done_head) & 0xfffffff0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001078 ohci->hcca->done_head = 0;
1079
1080 while (td_list_hc) {
1081 td_list = (td_t *)td_list_hc;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001082 check_status(td_list);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001083 td_list->next_dl_td = td_rev;
1084 td_rev = td_list;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001085 td_list_hc = m32_swap(td_list->hwNextTD) & 0xfffffff0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001086 }
1087 return td_list;
1088}
1089
1090/*-------------------------------------------------------------------------*/
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001091/*-------------------------------------------------------------------------*/
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001092
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001093static void finish_urb(ohci_t *ohci, urb_priv_t *urb, int status)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001094{
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001095 if ((status & (ED_OPER | ED_UNLINK)) && (urb->state != URB_DEL))
1096 urb->finished = sohci_return_job(ohci, urb);
1097 else
1098 dbg("finish_urb: strange.., ED state %x, \n", status);
1099}
1100
1101/*
1102 * Used to take back a TD from the host controller. This would normally be
1103 * called from within dl_done_list, however it may be called directly if the
1104 * HC no longer sees the TD and it has not appeared on the donelist (after
1105 * two frames). This bug has been observed on ZF Micro systems.
1106 */
1107static int takeback_td(ohci_t *ohci, td_t *td_list)
1108{
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001109 ed_t *ed;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001110 int cc;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001111 int stat = 0;
1112 /* urb_t *urb; */
1113 urb_priv_t *lurb_priv;
1114 __u32 tdINFO, edHeadP, edTailP;
1115
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001116 tdINFO = m32_swap(td_list->hwINFO);
1117
1118 ed = td_list->ed;
1119 lurb_priv = ed->purb;
1120
1121 dl_transfer_length(td_list);
1122
1123 lurb_priv->td_cnt++;
1124
1125 /* error code of transfer */
1126 cc = TD_CC_GET(tdINFO);
1127 if (cc) {
1128 err("USB-error: %s (%x)", cc_to_string[cc], cc);
1129 stat = cc_to_error[cc];
1130 }
1131
1132 /* see if this done list makes for all TD's of current URB,
1133 * and mark the URB finished if so */
1134 if (lurb_priv->td_cnt == lurb_priv->length)
1135 finish_urb(ohci, lurb_priv, ed->state);
1136
1137 dbg("dl_done_list: processing TD %x, len %x\n",
1138 lurb_priv->td_cnt, lurb_priv->length);
1139
Remy Bohmer48867202008-10-10 10:23:21 +02001140 if (ed->state != ED_NEW && (!usb_pipeint(lurb_priv->pipe))) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001141 edHeadP = m32_swap(ed->hwHeadP) & 0xfffffff0;
1142 edTailP = m32_swap(ed->hwTailP);
1143
1144 /* unlink eds if they are not busy */
1145 if ((edHeadP == edTailP) && (ed->state == ED_OPER))
1146 ep_unlink(ohci, ed);
1147 }
1148 return stat;
1149}
1150
1151static int dl_done_list(ohci_t *ohci)
1152{
1153 int stat = 0;
1154 td_t *td_list = dl_reverse_done_list(ohci);
1155
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001156 while (td_list) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001157 td_t *td_next = td_list->next_dl_td;
1158 stat = takeback_td(ohci, td_list);
1159 td_list = td_next;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001160 }
1161 return stat;
1162}
1163
1164/*-------------------------------------------------------------------------*
1165 * Virtual Root Hub
1166 *-------------------------------------------------------------------------*/
1167
Stephen Warreneb838e72014-02-13 21:15:18 -07001168#include <usbroothubdes.h>
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001169
1170/* Hub class-specific descriptor is constructed dynamically */
1171
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001172/*-------------------------------------------------------------------------*/
1173
1174#define OK(x) len = (x); break
1175#ifdef DEBUG
Becky Brucea5496a12010-06-30 13:05:44 -05001176#define WR_RH_STAT(x) {info("WR:status %#8x", (x)); ohci_writel((x), \
Hans de Goedec5613df2015-05-05 23:56:07 +02001177 &ohci->regs->roothub.status); }
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001178#define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, \
Hans de Goedec5613df2015-05-05 23:56:07 +02001179 (x)); ohci_writel((x), &ohci->regs->roothub.portstatus[wIndex-1]); }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001180#else
Hans de Goedec5613df2015-05-05 23:56:07 +02001181#define WR_RH_STAT(x) ohci_writel((x), &ohci->regs->roothub.status)
Becky Brucea5496a12010-06-30 13:05:44 -05001182#define WR_RH_PORTSTAT(x) ohci_writel((x), \
Hans de Goedec5613df2015-05-05 23:56:07 +02001183 &ohci->regs->roothub.portstatus[wIndex-1])
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001184#endif
Hans de Goedec5613df2015-05-05 23:56:07 +02001185#define RD_RH_STAT roothub_status(ohci)
1186#define RD_RH_PORTSTAT roothub_portstatus(ohci, wIndex-1)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001187
1188/* request to virtual root hub */
1189
1190int rh_check_port_status(ohci_t *controller)
1191{
1192 __u32 temp, ndp, i;
1193 int res;
1194
1195 res = -1;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001196 temp = roothub_a(controller);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001197 ndp = (temp & RH_A_NDP);
1198#ifdef CONFIG_AT91C_PQFP_UHPBUG
1199 ndp = (ndp == 2) ? 1:0;
1200#endif
1201 for (i = 0; i < ndp; i++) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001202 temp = roothub_portstatus(controller, i);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001203 /* check for a device disconnect */
1204 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
1205 (RH_PS_PESC | RH_PS_CSC)) &&
1206 ((temp & RH_PS_CCS) == 0)) {
1207 res = i;
1208 break;
1209 }
1210 }
1211 return res;
1212}
1213
Hans de Goedec5613df2015-05-05 23:56:07 +02001214static int ohci_submit_rh_msg(ohci_t *ohci, struct usb_device *dev,
1215 unsigned long pipe, void *buffer, int transfer_len,
1216 struct devrequest *cmd)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001217{
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001218 void *data = buffer;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001219 int leni = transfer_len;
1220 int len = 0;
1221 int stat = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001222 __u16 bmRType_bReq;
1223 __u16 wValue;
1224 __u16 wIndex;
1225 __u16 wLength;
Troy Kiskyf1273f12012-08-11 14:49:09 -07001226 ALLOC_ALIGN_BUFFER(__u8, databuf, 16, sizeof(u32));
Marek Vasut5f6aa032011-10-07 02:00:13 +02001227
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001228#ifdef DEBUG
Hans de Goedec5613df2015-05-05 23:56:07 +02001229pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len,
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001230 cmd, "SUB(rh)", usb_pipein(pipe));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001231#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001232 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001233#endif
Remy Bohmer48867202008-10-10 10:23:21 +02001234 if (usb_pipeint(pipe)) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001235 info("Root-Hub submit IRQ: NOT implemented");
1236 return 0;
1237 }
1238
1239 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001240 wValue = le16_to_cpu(cmd->value);
1241 wIndex = le16_to_cpu(cmd->index);
1242 wLength = le16_to_cpu(cmd->length);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001243
1244 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1245 dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
1246
1247 switch (bmRType_bReq) {
1248 /* Request Destination:
1249 without flags: Device,
1250 RH_INTERFACE: interface,
1251 RH_ENDPOINT: endpoint,
1252 RH_CLASS means HUB here,
1253 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1254 */
1255
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001256 case RH_GET_STATUS:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001257 *(u16 *)databuf = cpu_to_le16(1);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001258 OK(2);
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001259 case RH_GET_STATUS | RH_INTERFACE:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001260 *(u16 *)databuf = cpu_to_le16(0);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001261 OK(2);
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001262 case RH_GET_STATUS | RH_ENDPOINT:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001263 *(u16 *)databuf = cpu_to_le16(0);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001264 OK(2);
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001265 case RH_GET_STATUS | RH_CLASS:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001266 *(u32 *)databuf = cpu_to_le32(
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001267 RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001268 OK(4);
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001269 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001270 *(u32 *)databuf = cpu_to_le32(RD_RH_PORTSTAT);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001271 OK(4);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001272
1273 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1274 switch (wValue) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001275 case (RH_ENDPOINT_STALL):
1276 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001277 }
1278 break;
1279
1280 case RH_CLEAR_FEATURE | RH_CLASS:
1281 switch (wValue) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001282 case RH_C_HUB_LOCAL_POWER:
1283 OK(0);
1284 case (RH_C_HUB_OVER_CURRENT):
1285 WR_RH_STAT(RH_HS_OCIC);
1286 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001287 }
1288 break;
1289
1290 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1291 switch (wValue) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001292 case (RH_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_CCS); OK(0);
1293 case (RH_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_POCI); OK(0);
1294 case (RH_PORT_POWER): WR_RH_PORTSTAT(RH_PS_LSDA); OK(0);
1295 case (RH_C_PORT_CONNECTION): WR_RH_PORTSTAT(RH_PS_CSC); OK(0);
1296 case (RH_C_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_PESC); OK(0);
1297 case (RH_C_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_PSSC); OK(0);
1298 case (RH_C_PORT_OVER_CURRENT):WR_RH_PORTSTAT(RH_PS_OCIC); OK(0);
1299 case (RH_C_PORT_RESET): WR_RH_PORTSTAT(RH_PS_PRSC); OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001300 }
1301 break;
1302
1303 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1304 switch (wValue) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001305 case (RH_PORT_SUSPEND):
1306 WR_RH_PORTSTAT(RH_PS_PSS); OK(0);
1307 case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
1308 if (RD_RH_PORTSTAT & RH_PS_CCS)
1309 WR_RH_PORTSTAT(RH_PS_PRS);
1310 OK(0);
1311 case (RH_PORT_POWER):
1312 WR_RH_PORTSTAT(RH_PS_PPS);
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001313 mdelay(100);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001314 OK(0);
1315 case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
1316 if (RD_RH_PORTSTAT & RH_PS_CCS)
1317 WR_RH_PORTSTAT(RH_PS_PES);
1318 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001319 }
1320 break;
1321
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001322 case RH_SET_ADDRESS:
Hans de Goedec5613df2015-05-05 23:56:07 +02001323 ohci->rh.devnum = wValue;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001324 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001325
1326 case RH_GET_DESCRIPTOR:
1327 switch ((wValue & 0xff00) >> 8) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001328 case (0x01): /* device descriptor */
1329 len = min_t(unsigned int,
1330 leni,
1331 min_t(unsigned int,
1332 sizeof(root_hub_dev_des),
1333 wLength));
Troy Kiskyf1273f12012-08-11 14:49:09 -07001334 databuf = root_hub_dev_des; OK(len);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001335 case (0x02): /* configuration descriptor */
1336 len = min_t(unsigned int,
1337 leni,
1338 min_t(unsigned int,
1339 sizeof(root_hub_config_des),
1340 wLength));
Troy Kiskyf1273f12012-08-11 14:49:09 -07001341 databuf = root_hub_config_des; OK(len);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001342 case (0x03): /* string descriptors */
1343 if (wValue == 0x0300) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001344 len = min_t(unsigned int,
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001345 leni,
1346 min_t(unsigned int,
1347 sizeof(root_hub_str_index0),
1348 wLength));
Troy Kiskyf1273f12012-08-11 14:49:09 -07001349 databuf = root_hub_str_index0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001350 OK(len);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001351 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001352 if (wValue == 0x0301) {
1353 len = min_t(unsigned int,
1354 leni,
1355 min_t(unsigned int,
1356 sizeof(root_hub_str_index1),
1357 wLength));
Troy Kiskyf1273f12012-08-11 14:49:09 -07001358 databuf = root_hub_str_index1;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001359 OK(len);
1360 }
1361 default:
1362 stat = USB_ST_STALLED;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001363 }
1364 break;
1365
1366 case RH_GET_DESCRIPTOR | RH_CLASS:
1367 {
Hans de Goedec5613df2015-05-05 23:56:07 +02001368 __u32 temp = roothub_a(ohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001369
Troy Kiskyf1273f12012-08-11 14:49:09 -07001370 databuf[0] = 9; /* min length; */
1371 databuf[1] = 0x29;
1372 databuf[2] = temp & RH_A_NDP;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001373#ifdef CONFIG_AT91C_PQFP_UHPBUG
Troy Kiskyf1273f12012-08-11 14:49:09 -07001374 databuf[2] = (databuf[2] == 2) ? 1 : 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001375#endif
Troy Kiskyf1273f12012-08-11 14:49:09 -07001376 databuf[3] = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001377 if (temp & RH_A_PSM) /* per-port power switching? */
Troy Kiskyf1273f12012-08-11 14:49:09 -07001378 databuf[3] |= 0x1;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001379 if (temp & RH_A_NOCP) /* no overcurrent reporting? */
Troy Kiskyf1273f12012-08-11 14:49:09 -07001380 databuf[3] |= 0x10;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001381 else if (temp & RH_A_OCPM)/* per-port overcurrent reporting? */
Troy Kiskyf1273f12012-08-11 14:49:09 -07001382 databuf[3] |= 0x8;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001383
Troy Kiskyf1273f12012-08-11 14:49:09 -07001384 databuf[4] = 0;
1385 databuf[5] = (temp & RH_A_POTPGT) >> 24;
1386 databuf[6] = 0;
Hans de Goedec5613df2015-05-05 23:56:07 +02001387 temp = roothub_b(ohci);
Troy Kiskyf1273f12012-08-11 14:49:09 -07001388 databuf[7] = temp & RH_B_DR;
1389 if (databuf[2] < 7) {
1390 databuf[8] = 0xff;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001391 } else {
Troy Kiskyf1273f12012-08-11 14:49:09 -07001392 databuf[0] += 2;
1393 databuf[8] = (temp & RH_B_DR) >> 8;
1394 databuf[10] = databuf[9] = 0xff;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001395 }
1396
1397 len = min_t(unsigned int, leni,
Troy Kiskyf1273f12012-08-11 14:49:09 -07001398 min_t(unsigned int, databuf[0], wLength));
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001399 OK(len);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001400 }
1401
Marek Vasut5f6aa032011-10-07 02:00:13 +02001402 case RH_GET_CONFIGURATION:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001403 databuf[0] = 0x01;
Marek Vasut5f6aa032011-10-07 02:00:13 +02001404 OK(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001405
Marek Vasut5f6aa032011-10-07 02:00:13 +02001406 case RH_SET_CONFIGURATION:
1407 WR_RH_STAT(0x10000);
1408 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001409
1410 default:
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001411 dbg("unsupported root hub command");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001412 stat = USB_ST_STALLED;
1413 }
1414
1415#ifdef DEBUG
Hans de Goedec5613df2015-05-05 23:56:07 +02001416 ohci_dump_roothub(ohci, 1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001417#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001418 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001419#endif
1420
1421 len = min_t(int, len, leni);
Troy Kiskyf1273f12012-08-11 14:49:09 -07001422 if (data != databuf)
1423 memcpy(data, databuf, len);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001424 dev->act_len = len;
1425 dev->status = stat;
1426
1427#ifdef DEBUG
Hans de Goedec5613df2015-05-05 23:56:07 +02001428 pkt_print(ohci, NULL, dev, pipe, buffer,
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001429 transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001430#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001431 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001432#endif
1433
1434 return stat;
1435}
1436
1437/*-------------------------------------------------------------------------*/
1438
1439/* common code for handling submit messages - used for all but root hub */
1440/* accesses. */
Hans de Goedec5613df2015-05-05 23:56:07 +02001441static int submit_common_msg(ohci_t *ohci, struct usb_device *dev,
1442 unsigned long pipe, void *buffer, int transfer_len,
1443 struct devrequest *setup, int interval)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001444{
1445 int stat = 0;
1446 int maxsize = usb_maxpacket(dev, pipe);
1447 int timeout;
Zhang Wei4dae14c2007-06-06 10:08:14 +02001448 urb_priv_t *urb;
1449
1450 urb = malloc(sizeof(urb_priv_t));
1451 memset(urb, 0, sizeof(urb_priv_t));
1452
1453 urb->dev = dev;
1454 urb->pipe = pipe;
1455 urb->transfer_buffer = buffer;
1456 urb->transfer_buffer_length = transfer_len;
1457 urb->interval = interval;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001458
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001459#ifdef DEBUG
Zhang Wei4dae14c2007-06-06 10:08:14 +02001460 urb->actual_length = 0;
Hans de Goedec5613df2015-05-05 23:56:07 +02001461 pkt_print(ohci, urb, dev, pipe, buffer, transfer_len,
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001462 setup, "SUB", usb_pipein(pipe));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001463#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001464 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001465#endif
1466 if (!maxsize) {
1467 err("submit_common_message: pipesize for pipe %lx is zero",
1468 pipe);
1469 return -1;
1470 }
1471
Hans de Goede19d95d52015-05-05 23:56:08 +02001472 if (sohci_submit_job(ohci, &ohci->ohci_dev, urb, setup) < 0) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001473 err("sohci_submit_job failed");
1474 return -1;
1475 }
1476
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001477#if 0
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001478 mdelay(10);
Hans de Goedec5613df2015-05-05 23:56:07 +02001479 /* ohci_dump_status(ohci); */
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001480#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001481
Simon Glass96820a32011-02-07 14:42:16 -08001482 timeout = USB_TIMEOUT_MS(pipe);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001483
1484 /* wait for it to complete */
1485 for (;;) {
1486 /* check whether the controller is done */
Hans de Goedec5613df2015-05-05 23:56:07 +02001487 stat = hc_interrupt(ohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001488 if (stat < 0) {
1489 stat = USB_ST_CRC_ERR;
1490 break;
1491 }
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001492
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001493 /* NOTE: since we are not interrupt driven in U-Boot and always
1494 * handle only one URB at a time, we cannot assume the
1495 * transaction finished on the first successful return from
1496 * hc_interrupt().. unless the flag for current URB is set,
1497 * meaning that all TD's to/from device got actually
1498 * transferred and processed. If the current URB is not
1499 * finished we need to re-iterate this loop so as
1500 * hc_interrupt() gets called again as there needs to be some
1501 * more TD's to process still */
Zhang Wei4dae14c2007-06-06 10:08:14 +02001502 if ((stat >= 0) && (stat != 0xff) && (urb->finished)) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001503 /* 0xff is returned for an SF-interrupt */
1504 break;
1505 }
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001506
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001507 if (--timeout) {
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001508 mdelay(1);
Zhang Wei4dae14c2007-06-06 10:08:14 +02001509 if (!urb->finished)
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001510 dbg("*");
Zhang Wei4dae14c2007-06-06 10:08:14 +02001511
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001512 } else {
1513 err("CTL:TIMEOUT ");
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001514 dbg("submit_common_msg: TO status %x\n", stat);
Zhang Wei4dae14c2007-06-06 10:08:14 +02001515 urb->finished = 1;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001516 stat = USB_ST_CRC_ERR;
1517 break;
1518 }
1519 }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001520
1521 dev->status = stat;
Mateusz Kulikowski522c9562013-10-23 20:26:27 +02001522 dev->act_len = urb->actual_length;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001523
1524#ifdef DEBUG
Hans de Goedec5613df2015-05-05 23:56:07 +02001525 pkt_print(ohci, urb, dev, pipe, buffer, transfer_len,
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001526 setup, "RET(ctlr)", usb_pipein(pipe));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001527#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001528 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001529#endif
1530
1531 /* free TDs in urb_priv */
Remy Bohmer48867202008-10-10 10:23:21 +02001532 if (!usb_pipeint(pipe))
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001533 urb_free_priv(urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001534 return 0;
1535}
1536
1537/* submit routines called from usb.c */
1538int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1539 int transfer_len)
1540{
1541 info("submit_bulk_msg");
Hans de Goedec5613df2015-05-05 23:56:07 +02001542 return submit_common_msg(&gohci, dev, pipe, buffer, transfer_len,
1543 NULL, 0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001544}
1545
Hans de Goedec5613df2015-05-05 23:56:07 +02001546int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1547 int transfer_len, int interval)
1548{
1549 info("submit_int_msg");
1550 return submit_common_msg(&gohci, dev, pipe, buffer, transfer_len, NULL,
1551 interval);
1552}
1553
1554static int _ohci_submit_control_msg(ohci_t *ohci, struct usb_device *dev,
1555 unsigned long pipe, void *buffer, int transfer_len,
1556 struct devrequest *setup)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001557{
1558 int maxsize = usb_maxpacket(dev, pipe);
1559
1560 info("submit_control_msg");
1561#ifdef DEBUG
Hans de Goedec5613df2015-05-05 23:56:07 +02001562 pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len,
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001563 setup, "SUB", usb_pipein(pipe));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001564#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001565 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001566#endif
1567 if (!maxsize) {
1568 err("submit_control_message: pipesize for pipe %lx is zero",
1569 pipe);
1570 return -1;
1571 }
Hans de Goedec5613df2015-05-05 23:56:07 +02001572 if (((pipe >> 8) & 0x7f) == ohci->rh.devnum) {
1573 ohci->rh.dev = dev;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001574 /* root hub - redirect */
Hans de Goedec5613df2015-05-05 23:56:07 +02001575 return ohci_submit_rh_msg(ohci, dev, pipe, buffer,
1576 transfer_len, setup);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001577 }
1578
Hans de Goedec5613df2015-05-05 23:56:07 +02001579 return submit_common_msg(ohci, dev, pipe, buffer, transfer_len,
1580 setup, 0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001581}
1582
1583/*-------------------------------------------------------------------------*
1584 * HC functions
1585 *-------------------------------------------------------------------------*/
1586
1587/* reset the HC and BUS */
1588
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001589static int hc_reset(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001590{
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +02001591#ifdef CONFIG_PCI_EHCI_DEVNO
1592 pci_dev_t pdev;
1593#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001594 int timeout = 30;
1595 int smm_timeout = 50; /* 0,5 sec */
1596
1597 dbg("%s\n", __FUNCTION__);
1598
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +02001599#ifdef CONFIG_PCI_EHCI_DEVNO
1600 /*
1601 * Some multi-function controllers (e.g. ISP1562) allow root hub
1602 * resetting via EHCI registers only.
1603 */
1604 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVNO);
1605 if (pdev != -1) {
1606 u32 base;
1607 int timeout = 1000;
1608
1609 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base);
Becky Brucea5496a12010-06-30 13:05:44 -05001610 base += EHCI_USBCMD_OFF;
1611 ohci_writel(ohci_readl(base) | EHCI_USBCMD_HCRESET, base);
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +02001612
Becky Brucea5496a12010-06-30 13:05:44 -05001613 while (ohci_readl(base) & EHCI_USBCMD_HCRESET) {
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +02001614 if (timeout-- <= 0) {
1615 printf("USB RootHub reset timed out!");
1616 break;
1617 }
1618 udelay(1);
1619 }
1620 } else
1621 printf("No EHCI func at %d index!\n", CONFIG_PCI_EHCI_DEVNO);
1622#endif
Becky Brucea5496a12010-06-30 13:05:44 -05001623 if (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) {
1624 /* SMM owns the HC, request ownership */
1625 ohci_writel(OHCI_OCR, &ohci->regs->cmdstatus);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001626 info("USB HC TakeOver from SMM");
Becky Brucea5496a12010-06-30 13:05:44 -05001627 while (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) {
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001628 mdelay(10);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001629 if (--smm_timeout == 0) {
1630 err("USB HC TakeOver failed!");
1631 return -1;
1632 }
1633 }
1634 }
1635
1636 /* Disable HC interrupts */
Becky Brucea5496a12010-06-30 13:05:44 -05001637 ohci_writel(OHCI_INTR_MIE, &ohci->regs->intrdisable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001638
1639 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n",
1640 ohci->slot_name,
Becky Brucea5496a12010-06-30 13:05:44 -05001641 ohci_readl(&ohci->regs->control));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001642
1643 /* Reset USB (needed by some controllers) */
Markus Klotzbuecher53e336e2006-11-27 11:43:09 +01001644 ohci->hc_control = 0;
Becky Brucea5496a12010-06-30 13:05:44 -05001645 ohci_writel(ohci->hc_control, &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001646
1647 /* HC Reset requires max 10 us delay */
Becky Brucea5496a12010-06-30 13:05:44 -05001648 ohci_writel(OHCI_HCR, &ohci->regs->cmdstatus);
1649 while ((ohci_readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001650 if (--timeout == 0) {
1651 err("USB HC reset timed out!");
1652 return -1;
1653 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001654 udelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001655 }
1656 return 0;
1657}
1658
1659/*-------------------------------------------------------------------------*/
1660
1661/* Start an OHCI controller, set the BUS operational
1662 * enable interrupts
1663 * connect the virtual root hub */
1664
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001665static int hc_start(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001666{
1667 __u32 mask;
1668 unsigned int fminterval;
1669
1670 ohci->disabled = 1;
1671
1672 /* Tell the controller where the control and bulk lists are
1673 * The lists are empty now. */
1674
Becky Brucea5496a12010-06-30 13:05:44 -05001675 ohci_writel(0, &ohci->regs->ed_controlhead);
1676 ohci_writel(0, &ohci->regs->ed_bulkhead);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001677
Becky Brucea5496a12010-06-30 13:05:44 -05001678 ohci_writel((__u32)ohci->hcca,
1679 &ohci->regs->hcca); /* reset clears this */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001680
1681 fminterval = 0x2edf;
Becky Brucea5496a12010-06-30 13:05:44 -05001682 ohci_writel((fminterval * 9) / 10, &ohci->regs->periodicstart);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001683 fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
Becky Brucea5496a12010-06-30 13:05:44 -05001684 ohci_writel(fminterval, &ohci->regs->fminterval);
1685 ohci_writel(0x628, &ohci->regs->lsthresh);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001686
1687 /* start controller operations */
1688 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
1689 ohci->disabled = 0;
Becky Brucea5496a12010-06-30 13:05:44 -05001690 ohci_writel(ohci->hc_control, &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001691
1692 /* disable all interrupts */
1693 mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
1694 OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
1695 OHCI_INTR_OC | OHCI_INTR_MIE);
Becky Brucea5496a12010-06-30 13:05:44 -05001696 ohci_writel(mask, &ohci->regs->intrdisable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001697 /* clear all interrupts */
1698 mask &= ~OHCI_INTR_MIE;
Becky Brucea5496a12010-06-30 13:05:44 -05001699 ohci_writel(mask, &ohci->regs->intrstatus);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001700 /* Choose the interrupts we care about now - but w/o MIE */
1701 mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
Becky Brucea5496a12010-06-30 13:05:44 -05001702 ohci_writel(mask, &ohci->regs->intrenable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001703
1704#ifdef OHCI_USE_NPS
1705 /* required for AMD-756 and some Mac platforms */
Becky Brucea5496a12010-06-30 13:05:44 -05001706 ohci_writel((roothub_a(ohci) | RH_A_NPS) & ~RH_A_PSM,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001707 &ohci->regs->roothub.a);
Becky Brucea5496a12010-06-30 13:05:44 -05001708 ohci_writel(RH_HS_LPSC, &ohci->regs->roothub.status);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001709#endif /* OHCI_USE_NPS */
1710
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001711 /* POTPGT delay is bits 24-31, in 2 ms units. */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001712 mdelay((roothub_a(ohci) >> 23) & 0x1fe);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001713
1714 /* connect the virtual root hub */
1715 ohci->rh.devnum = 0;
1716
1717 return 0;
1718}
1719
1720/*-------------------------------------------------------------------------*/
1721
1722/* an interrupt happens */
1723
Hans de Goedec5613df2015-05-05 23:56:07 +02001724static int hc_interrupt(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001725{
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001726 struct ohci_regs *regs = ohci->regs;
1727 int ints;
1728 int stat = -1;
1729
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001730 if ((ohci->hcca->done_head != 0) &&
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001731 !(m32_swap(ohci->hcca->done_head) & 0x01)) {
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001732 ints = OHCI_INTR_WDH;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001733 } else {
Becky Brucea5496a12010-06-30 13:05:44 -05001734 ints = ohci_readl(&regs->intrstatus);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001735 if (ints == ~(u32)0) {
1736 ohci->disabled++;
1737 err("%s device removed!", ohci->slot_name);
1738 return -1;
1739 } else {
Becky Brucea5496a12010-06-30 13:05:44 -05001740 ints &= ohci_readl(&regs->intrenable);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001741 if (ints == 0) {
1742 dbg("hc_interrupt: returning..\n");
1743 return 0xff;
1744 }
1745 }
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001746 }
Markus Klotzbuecherae79f602007-03-26 11:21:05 +02001747
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001748 /* dbg("Interrupt: %x frame: %x", ints,
1749 le16_to_cpu(ohci->hcca->frame_no)); */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001750
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001751 if (ints & OHCI_INTR_RHSC)
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001752 stat = 0xff;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001753
1754 if (ints & OHCI_INTR_UE) {
1755 ohci->disabled++;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001756 err("OHCI Unrecoverable Error, controller usb-%s disabled",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001757 ohci->slot_name);
1758 /* e.g. due to PCI Master/Target Abort */
1759
1760#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001761 ohci_dump(ohci, 1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001762#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001763 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001764#endif
1765 /* FIXME: be optimistic, hope that bug won't repeat often. */
1766 /* Make some non-interrupt context restart the controller. */
1767 /* Count and limit the retries though; either hardware or */
1768 /* software errors can go forever... */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001769 hc_reset(ohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001770 return -1;
1771 }
1772
1773 if (ints & OHCI_INTR_WDH) {
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001774 mdelay(1);
Becky Brucea5496a12010-06-30 13:05:44 -05001775 ohci_writel(OHCI_INTR_WDH, &regs->intrdisable);
1776 (void)ohci_readl(&regs->intrdisable); /* flush */
Hans de Goedec5613df2015-05-05 23:56:07 +02001777 stat = dl_done_list(ohci);
Becky Brucea5496a12010-06-30 13:05:44 -05001778 ohci_writel(OHCI_INTR_WDH, &regs->intrenable);
1779 (void)ohci_readl(&regs->intrdisable); /* flush */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001780 }
1781
1782 if (ints & OHCI_INTR_SO) {
1783 dbg("USB Schedule overrun\n");
Becky Brucea5496a12010-06-30 13:05:44 -05001784 ohci_writel(OHCI_INTR_SO, &regs->intrenable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001785 stat = -1;
1786 }
1787
1788 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1789 if (ints & OHCI_INTR_SF) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001790 unsigned int frame = m16_swap(ohci->hcca->frame_no) & 1;
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001791 mdelay(1);
Becky Brucea5496a12010-06-30 13:05:44 -05001792 ohci_writel(OHCI_INTR_SF, &regs->intrdisable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001793 if (ohci->ed_rm_list[frame] != NULL)
Becky Brucea5496a12010-06-30 13:05:44 -05001794 ohci_writel(OHCI_INTR_SF, &regs->intrenable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001795 stat = 0xff;
1796 }
1797
Becky Brucea5496a12010-06-30 13:05:44 -05001798 ohci_writel(ints, &regs->intrstatus);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001799 return stat;
1800}
1801
1802/*-------------------------------------------------------------------------*/
1803
1804/*-------------------------------------------------------------------------*/
1805
1806/* De-allocate all resources.. */
1807
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001808static void hc_release_ohci(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001809{
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001810 dbg("USB HC release ohci usb-%s", ohci->slot_name);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001811
1812 if (!ohci->disabled)
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001813 hc_reset(ohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001814}
1815
1816/*-------------------------------------------------------------------------*/
1817
1818/*
1819 * low level initalisation routine, called from usb.c
1820 */
1821static char ohci_inited = 0;
1822
Troy Kisky06d513e2013-10-10 15:27:56 -07001823int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001824{
Zhang Wei4dae14c2007-06-06 10:08:14 +02001825#ifdef CONFIG_PCI_OHCI
1826 pci_dev_t pdev;
1827#endif
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001828
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001829#ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001830 /* cpu dependant init */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001831 if (usb_cpu_init())
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001832 return -1;
1833#endif
1834
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001835#ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001836 /* board dependant init */
Mateusz Zalega16297cf2013-10-04 19:22:26 +02001837 if (board_usb_init(index, USB_INIT_HOST))
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001838 return -1;
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001839#endif
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001840 memset(&gohci, 0, sizeof(ohci_t));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001841
1842 /* align the storage */
1843 if ((__u32)&ghcca[0] & 0xff) {
1844 err("HCCA not aligned!!");
1845 return -1;
1846 }
Hans de Goede26548bb2015-05-05 23:56:10 +02001847 gohci.hcca = &ghcca[0];
1848 info("aligned ghcca %p", gohci.hcca);
1849 memset(gohci.hcca, 0, sizeof(struct ohci_hcca));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001850
1851 gohci.disabled = 1;
1852 gohci.sleeping = 0;
1853 gohci.irq = -1;
Zhang Wei4dae14c2007-06-06 10:08:14 +02001854#ifdef CONFIG_PCI_OHCI
Sergei Poselenov477434c2008-05-22 01:15:53 +02001855 pdev = pci_find_devices(ohci_pci_ids, CONFIG_PCI_OHCI_DEVNO);
Zhang Wei4dae14c2007-06-06 10:08:14 +02001856
1857 if (pdev != -1) {
1858 u16 vid, did;
1859 u32 base;
1860 pci_read_config_word(pdev, PCI_VENDOR_ID, &vid);
1861 pci_read_config_word(pdev, PCI_DEVICE_ID, &did);
1862 printf("OHCI pci controller (%04x, %04x) found @(%d:%d:%d)\n",
1863 vid, did, (pdev >> 16) & 0xff,
1864 (pdev >> 11) & 0x1f, (pdev >> 8) & 0x7);
1865 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base);
1866 printf("OHCI regs address 0x%08x\n", base);
1867 gohci.regs = (struct ohci_regs *)base;
1868 } else
1869 return -1;
1870#else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001871 gohci.regs = (struct ohci_regs *)CONFIG_SYS_USB_OHCI_REGS_BASE;
Zhang Wei4dae14c2007-06-06 10:08:14 +02001872#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001873
1874 gohci.flags = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001875 gohci.slot_name = CONFIG_SYS_USB_OHCI_SLOT_NAME;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001876
1877 if (hc_reset (&gohci) < 0) {
1878 hc_release_ohci (&gohci);
1879 err ("can't reset usb-%s", gohci.slot_name);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001880#ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001881 /* board dependant cleanup */
Mateusz Zalega16297cf2013-10-04 19:22:26 +02001882 board_usb_cleanup(index, USB_INIT_HOST);
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001883#endif
1884
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001885#ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001886 /* cpu dependant cleanup */
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001887 usb_cpu_init_fail();
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001888#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001889 return -1;
1890 }
1891
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001892 if (hc_start(&gohci) < 0) {
1893 err("can't start usb-%s", gohci.slot_name);
1894 hc_release_ohci(&gohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001895 /* Initialization failed */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001896#ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001897 /* board dependant cleanup */
1898 usb_board_stop();
1899#endif
1900
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001901#ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001902 /* cpu dependant cleanup */
1903 usb_cpu_stop();
1904#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001905 return -1;
1906 }
1907
1908#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001909 ohci_dump(&gohci, 1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001910#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001911 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001912#endif
1913 ohci_inited = 1;
1914 return 0;
1915}
1916
Lucas Stachc7e3b2b2012-09-26 00:14:34 +02001917int usb_lowlevel_stop(int index)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001918{
1919 /* this gets called really early - before the controller has */
1920 /* even been initialized! */
1921 if (!ohci_inited)
1922 return 0;
1923 /* TODO release any interrupts, etc. */
1924 /* call hc_release_ohci() here ? */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001925 hc_reset(&gohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001926
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001927#ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001928 /* board dependant cleanup */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001929 if (usb_board_stop())
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001930 return -1;
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001931#endif
1932
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001933#ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001934 /* cpu dependant cleanup */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001935 if (usb_cpu_stop())
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001936 return -1;
1937#endif
Remy Bohmereba1f2f2008-08-20 11:22:02 +02001938 /* This driver is no longer initialised. It needs a new low-level
1939 * init (board/cpu) before it can be used again. */
1940 ohci_inited = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001941 return 0;
1942}
Hans de Goedec5613df2015-05-05 23:56:07 +02001943
1944int submit_control_msg(struct usb_device *dev, unsigned long pipe,
1945 void *buffer, int transfer_len, struct devrequest *setup)
1946{
1947 return _ohci_submit_control_msg(&gohci, dev, pipe, buffer,
1948 transfer_len, setup);
1949}