blob: bc17b85db5a7ca38325d3037135fa077c76f97f7 [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 *
20 * See file CREDITS for list of people who contributed to this
21 * project.
22 *
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License as
25 * published by the Free Software Foundation; either version 2 of
26 * the License, or (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jerry Van Barenae0b05d2009-02-05 22:18:02 -050030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020031 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
36 * MA 02111-1307 USA
37 *
38 */
39/*
40 * IMPORTANT NOTES
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +020041 * 1 - Read doc/README.generic_usb_ohci
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020042 * 2 - this driver is intended for use with USB Mass Storage Devices
Zhang Wei4dae14c2007-06-06 10:08:14 +020043 * (BBB) and USB keyboard. There is NO support for Isochronous pipes!
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +020044 * 2 - when running on a PQFP208 AT91RM9200, define CONFIG_AT91C_PQFP_UHPBUG
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020045 * to activate workaround for bug #41 or this driver will NOT work!
46 */
47
48#include <common.h>
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +020049#include <asm/byteorder.h>
50
51#if defined(CONFIG_PCI_OHCI)
Zhang Wei4dae14c2007-06-06 10:08:14 +020052# include <pci.h>
Sergei Poselenov477434c2008-05-22 01:15:53 +020053#if !defined(CONFIG_PCI_OHCI_DEVNO)
54#define CONFIG_PCI_OHCI_DEVNO 0
55#endif
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +020056#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020057
58#include <malloc.h>
59#include <usb.h>
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020060
61#include "ohci.h"
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020062
Wolfgang Denke8da58f2007-11-19 12:59:14 +010063#ifdef CONFIG_AT91RM9200
64#include <asm/arch/hardware.h> /* needed for AT91_USB_HOST_BASE */
65#endif
66
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +020067#if defined(CONFIG_ARM920T) || \
kevin.morfitt@fearnside-systems.co.ukac678042009-11-17 18:30:34 +090068 defined(CONFIG_S3C24X0) || \
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +010069 defined(CONFIG_440EP) || \
Zhang Wei4dae14c2007-06-06 10:08:14 +020070 defined(CONFIG_PCI_OHCI) || \
Stefan Roese2596f5b2008-03-05 12:29:32 +010071 defined(CONFIG_MPC5200) || \
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072 defined(CONFIG_SYS_OHCI_USE_NPS)
Markus Klotzbuecher24e37642006-05-23 10:33:11 +020073# define OHCI_USE_NPS /* force NoPowerSwitching mode */
74#endif
75
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020076#undef OHCI_VERBOSE_DEBUG /* not always helpful */
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +010077#undef DEBUG
78#undef SHOW_INFO
79#undef OHCI_FILL_TRACE
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020080
81/* For initializing controller (mask in an HCFS mode too) */
82#define OHCI_CONTROL_INIT \
83 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
84
Remy Bohmer6f5794a2008-09-16 14:55:43 +020085#define min_t(type, x, y) \
86 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020087
Zhang Wei4dae14c2007-06-06 10:08:14 +020088#ifdef CONFIG_PCI_OHCI
89static struct pci_device_id ohci_pci_ids[] = {
90 {0x10b9, 0x5237}, /* ULI1575 PCI OHCI module ids */
David Saada97213f32007-09-17 17:04:47 +020091 {0x1033, 0x0035}, /* NEC PCI OHCI module ids */
TsiChung Liew3afac792008-01-11 20:42:58 -060092 {0x1131, 0x1561}, /* Philips 1561 PCI OHCI module ids */
Zhang Wei4dae14c2007-06-06 10:08:14 +020093 /* Please add supported PCI OHCI controller ids here */
94 {0, 0}
95};
96#endif
97
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +020098#ifdef CONFIG_PCI_EHCI_DEVNO
99static struct pci_device_id ehci_pci_ids[] = {
100 {0x1131, 0x1562}, /* Philips 1562 PCI EHCI module ids */
101 /* Please add supported PCI EHCI controller ids here */
102 {0, 0}
103};
104#endif
105
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200106#ifdef DEBUG
107#define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
108#else
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200109#define dbg(format, arg...) do {} while (0)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200110#endif /* DEBUG */
111#define err(format, arg...) printf("ERROR: " format "\n", ## arg)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200112#ifdef SHOW_INFO
113#define info(format, arg...) printf("INFO: " format "\n", ## arg)
114#else
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200115#define info(format, arg...) do {} while (0)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200116#endif
117
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200118#ifdef CONFIG_SYS_OHCI_BE_CONTROLLER
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +0200119# define m16_swap(x) cpu_to_be16(x)
120# define m32_swap(x) cpu_to_be32(x)
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +0100121#else
Markus Klotzbuecherfc43be42007-06-06 11:49:35 +0200122# define m16_swap(x) cpu_to_le16(x)
123# define m32_swap(x) cpu_to_le32(x)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200124#endif /* CONFIG_SYS_OHCI_BE_CONTROLLER */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200125
126/* global ohci_t */
127static ohci_t gohci;
128/* this must be aligned to a 256 byte boundary */
129struct ohci_hcca ghcca[1];
130/* a pointer to the aligned storage */
131struct ohci_hcca *phcca;
132/* this allocates EDs for all possible endpoints */
133struct ohci_device ohci_dev;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200134/* device which was disconnected */
135struct usb_device *devgone;
136
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200137static inline u32 roothub_a(struct ohci *hc)
Becky Brucea5496a12010-06-30 13:05:44 -0500138 { return ohci_readl(&hc->regs->roothub.a); }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200139static inline u32 roothub_b(struct ohci *hc)
Becky Brucea5496a12010-06-30 13:05:44 -0500140 { return ohci_readl(&hc->regs->roothub.b); }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200141static inline u32 roothub_status(struct ohci *hc)
Becky Brucea5496a12010-06-30 13:05:44 -0500142 { return ohci_readl(&hc->regs->roothub.status); }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200143static inline u32 roothub_portstatus(struct ohci *hc, int i)
Becky Brucea5496a12010-06-30 13:05:44 -0500144 { return ohci_readl(&hc->regs->roothub.portstatus[i]); }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200145
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200146/* forward declaration */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200147static int hc_interrupt(void);
148static void td_submit_job(struct usb_device *dev, unsigned long pipe,
149 void *buffer, int transfer_len,
150 struct devrequest *setup, urb_priv_t *urb,
151 int interval);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200152
153/*-------------------------------------------------------------------------*
154 * URB support functions
155 *-------------------------------------------------------------------------*/
156
157/* free HCD-private data associated with this URB */
158
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200159static void urb_free_priv(urb_priv_t *urb)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200160{
161 int i;
162 int last;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200163 struct td *td;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200164
165 last = urb->length - 1;
166 if (last >= 0) {
167 for (i = 0; i <= last; i++) {
168 td = urb->td[i];
169 if (td) {
170 td->usb_dev = NULL;
171 urb->td[i] = NULL;
172 }
173 }
174 }
Zhang Wei4dae14c2007-06-06 10:08:14 +0200175 free(urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200176}
177
178/*-------------------------------------------------------------------------*/
179
180#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200181static int sohci_get_current_frame_number(struct usb_device *dev);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200182
183/* debug| print the main components of an URB
184 * small: 0) header + data packets 1) just header */
185
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200186static void pkt_print(urb_priv_t *purb, struct usb_device *dev,
187 unsigned long pipe, void *buffer, int transfer_len,
188 struct devrequest *setup, char *str, int small)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200189{
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200190 dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200191 str,
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200192 sohci_get_current_frame_number(dev),
193 usb_pipedevice(pipe),
194 usb_pipeendpoint(pipe),
195 usb_pipeout(pipe)? 'O': 'I',
196 usb_pipetype(pipe) < 2 ? \
197 (usb_pipeint(pipe)? "INTR": "ISOC"): \
198 (usb_pipecontrol(pipe)? "CTRL": "BULK"),
Zhang Wei4dae14c2007-06-06 10:08:14 +0200199 (purb ? purb->actual_length : 0),
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200200 transfer_len, dev->status);
201#ifdef OHCI_VERBOSE_DEBUG
202 if (!small) {
203 int i, len;
204
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200205 if (usb_pipecontrol(pipe)) {
206 printf(__FILE__ ": cmd(8):");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200207 for (i = 0; i < 8 ; i++)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200208 printf(" %02x", ((__u8 *) setup) [i]);
209 printf("\n");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200210 }
211 if (transfer_len > 0 && buffer) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200212 printf(__FILE__ ": data(%d/%d):",
Zhang Wei4dae14c2007-06-06 10:08:14 +0200213 (purb ? purb->actual_length : 0),
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200214 transfer_len);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200215 len = usb_pipeout(pipe)? transfer_len:
Zhang Wei4dae14c2007-06-06 10:08:14 +0200216 (purb ? purb->actual_length : 0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200217 for (i = 0; i < 16 && i < len; i++)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200218 printf(" %02x", ((__u8 *) buffer) [i]);
219 printf("%s\n", i < len? "...": "");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200220 }
221 }
222#endif
223}
224
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200225/* just for debugging; prints non-empty branches of the int ed tree
226 * inclusive iso eds */
227void ep_print_int_eds(ohci_t *ohci, char *str)
228{
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200229 int i, j;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200230 __u32 *ed_p;
231 for (i = 0; i < 32; i++) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200232 j = 5;
233 ed_p = &(ohci->hcca->int_table [i]);
234 if (*ed_p == 0)
235 continue;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200236 printf(__FILE__ ": %s branch int %2d(%2x):", str, i, i);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200237 while (*ed_p != 0 && j--) {
238 ed_t *ed = (ed_t *)m32_swap(ed_p);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200239 printf(" ed: %4x;", ed->hwINFO);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200240 ed_p = &ed->hwNextED;
241 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200242 printf("\n");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200243 }
244}
245
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200246static void ohci_dump_intr_mask(char *label, __u32 mask)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200247{
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200248 dbg("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200249 label,
250 mask,
251 (mask & OHCI_INTR_MIE) ? " MIE" : "",
252 (mask & OHCI_INTR_OC) ? " OC" : "",
253 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
254 (mask & OHCI_INTR_FNO) ? " FNO" : "",
255 (mask & OHCI_INTR_UE) ? " UE" : "",
256 (mask & OHCI_INTR_RD) ? " RD" : "",
257 (mask & OHCI_INTR_SF) ? " SF" : "",
258 (mask & OHCI_INTR_WDH) ? " WDH" : "",
259 (mask & OHCI_INTR_SO) ? " SO" : ""
260 );
261}
262
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200263static void maybe_print_eds(char *label, __u32 value)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200264{
265 ed_t *edp = (ed_t *)value;
266
267 if (value) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200268 dbg("%s %08x", label, value);
269 dbg("%08x", edp->hwINFO);
270 dbg("%08x", edp->hwTailP);
271 dbg("%08x", edp->hwHeadP);
272 dbg("%08x", edp->hwNextED);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200273 }
274}
275
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200276static char *hcfs2string(int state)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200277{
278 switch (state) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200279 case OHCI_USB_RESET: return "reset";
280 case OHCI_USB_RESUME: return "resume";
281 case OHCI_USB_OPER: return "operational";
282 case OHCI_USB_SUSPEND: return "suspend";
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200283 }
284 return "?";
285}
286
287/* dump control and status registers */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200288static void ohci_dump_status(ohci_t *controller)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200289{
290 struct ohci_regs *regs = controller->regs;
291 __u32 temp;
292
Becky Brucea5496a12010-06-30 13:05:44 -0500293 temp = ohci_readl(&regs->revision) & 0xff;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200294 if (temp != 0x10)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200295 dbg("spec %d.%d", (temp >> 4), (temp & 0x0f));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200296
Becky Brucea5496a12010-06-30 13:05:44 -0500297 temp = ohci_readl(&regs->control);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200298 dbg("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200299 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
300 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
301 (temp & OHCI_CTRL_IR) ? " IR" : "",
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200302 hcfs2string(temp & OHCI_CTRL_HCFS),
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200303 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
304 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
305 (temp & OHCI_CTRL_IE) ? " IE" : "",
306 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
307 temp & OHCI_CTRL_CBSR
308 );
309
Becky Brucea5496a12010-06-30 13:05:44 -0500310 temp = ohci_readl(&regs->cmdstatus);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200311 dbg("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200312 (temp & OHCI_SOC) >> 16,
313 (temp & OHCI_OCR) ? " OCR" : "",
314 (temp & OHCI_BLF) ? " BLF" : "",
315 (temp & OHCI_CLF) ? " CLF" : "",
316 (temp & OHCI_HCR) ? " HCR" : ""
317 );
318
Becky Brucea5496a12010-06-30 13:05:44 -0500319 ohci_dump_intr_mask("intrstatus", ohci_readl(&regs->intrstatus));
320 ohci_dump_intr_mask("intrenable", ohci_readl(&regs->intrenable));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200321
Becky Brucea5496a12010-06-30 13:05:44 -0500322 maybe_print_eds("ed_periodcurrent",
323 ohci_readl(&regs->ed_periodcurrent));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200324
Becky Brucea5496a12010-06-30 13:05:44 -0500325 maybe_print_eds("ed_controlhead", ohci_readl(&regs->ed_controlhead));
326 maybe_print_eds("ed_controlcurrent",
327 ohci_readl(&regs->ed_controlcurrent));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200328
Becky Brucea5496a12010-06-30 13:05:44 -0500329 maybe_print_eds("ed_bulkhead", ohci_readl(&regs->ed_bulkhead));
330 maybe_print_eds("ed_bulkcurrent", ohci_readl(&regs->ed_bulkcurrent));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200331
Becky Brucea5496a12010-06-30 13:05:44 -0500332 maybe_print_eds("donehead", ohci_readl(&regs->donehead));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200333}
334
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200335static void ohci_dump_roothub(ohci_t *controller, int verbose)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200336{
337 __u32 temp, ndp, i;
338
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200339 temp = roothub_a(controller);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200340 ndp = (temp & RH_A_NDP);
341#ifdef CONFIG_AT91C_PQFP_UHPBUG
342 ndp = (ndp == 2) ? 1:0;
343#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200344 if (verbose) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200345 dbg("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200346 ((temp & RH_A_POTPGT) >> 24) & 0xff,
347 (temp & RH_A_NOCP) ? " NOCP" : "",
348 (temp & RH_A_OCPM) ? " OCPM" : "",
349 (temp & RH_A_DT) ? " DT" : "",
350 (temp & RH_A_NPS) ? " NPS" : "",
351 (temp & RH_A_PSM) ? " PSM" : "",
352 ndp
353 );
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200354 temp = roothub_b(controller);
355 dbg("roothub.b: %08x PPCM=%04x DR=%04x",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200356 temp,
357 (temp & RH_B_PPCM) >> 16,
358 (temp & RH_B_DR)
359 );
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200360 temp = roothub_status(controller);
361 dbg("roothub.status: %08x%s%s%s%s%s%s",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200362 temp,
363 (temp & RH_HS_CRWE) ? " CRWE" : "",
364 (temp & RH_HS_OCIC) ? " OCIC" : "",
365 (temp & RH_HS_LPSC) ? " LPSC" : "",
366 (temp & RH_HS_DRWE) ? " DRWE" : "",
367 (temp & RH_HS_OCI) ? " OCI" : "",
368 (temp & RH_HS_LPS) ? " LPS" : ""
369 );
370 }
371
372 for (i = 0; i < ndp; i++) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200373 temp = roothub_portstatus(controller, i);
374 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 +0200375 i,
376 temp,
377 (temp & RH_PS_PRSC) ? " PRSC" : "",
378 (temp & RH_PS_OCIC) ? " OCIC" : "",
379 (temp & RH_PS_PSSC) ? " PSSC" : "",
380 (temp & RH_PS_PESC) ? " PESC" : "",
381 (temp & RH_PS_CSC) ? " CSC" : "",
382
383 (temp & RH_PS_LSDA) ? " LSDA" : "",
384 (temp & RH_PS_PPS) ? " PPS" : "",
385 (temp & RH_PS_PRS) ? " PRS" : "",
386 (temp & RH_PS_POCI) ? " POCI" : "",
387 (temp & RH_PS_PSS) ? " PSS" : "",
388
389 (temp & RH_PS_PES) ? " PES" : "",
390 (temp & RH_PS_CCS) ? " CCS" : ""
391 );
392 }
393}
394
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200395static void ohci_dump(ohci_t *controller, int verbose)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200396{
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200397 dbg("OHCI controller usb-%s state", controller->slot_name);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200398
399 /* dumps some of the state we know about */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200400 ohci_dump_status(controller);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200401 if (verbose)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200402 ep_print_int_eds(controller, "hcca");
403 dbg("hcca frame #%04x", controller->hcca->frame_no);
404 ohci_dump_roothub(controller, 1);
Stefan Roese2596f5b2008-03-05 12:29:32 +0100405}
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200406#endif /* DEBUG */
407
408/*-------------------------------------------------------------------------*
409 * Interface functions (URB)
410 *-------------------------------------------------------------------------*/
411
412/* get a transfer request */
413
Zhang Wei4dae14c2007-06-06 10:08:14 +0200414int sohci_submit_job(urb_priv_t *urb, struct devrequest *setup)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200415{
416 ohci_t *ohci;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200417 ed_t *ed;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200418 urb_priv_t *purb_priv = urb;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200419 int i, size = 0;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200420 struct usb_device *dev = urb->dev;
421 unsigned long pipe = urb->pipe;
422 void *buffer = urb->transfer_buffer;
423 int transfer_len = urb->transfer_buffer_length;
424 int interval = urb->interval;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200425
426 ohci = &gohci;
427
428 /* when controller's hung, permit only roothub cleanup attempts
429 * such as powering down ports */
430 if (ohci->disabled) {
431 err("sohci_submit_job: EPIPE");
432 return -1;
433 }
Markus Klotzbuecherae79f602007-03-26 11:21:05 +0200434
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200435 /* we're about to begin a new transaction here so mark the
436 * URB unfinished */
Zhang Wei4dae14c2007-06-06 10:08:14 +0200437 urb->finished = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200438
439 /* every endpoint has a ed, locate and fill it */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200440 ed = ep_add_ed(dev, pipe, interval, 1);
441 if (!ed) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200442 err("sohci_submit_job: ENOMEM");
443 return -1;
444 }
445
446 /* for the private part of the URB we need the number of TDs (size) */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200447 switch (usb_pipetype(pipe)) {
448 case PIPE_BULK: /* one TD for every 4096 Byte */
449 size = (transfer_len - 1) / 4096 + 1;
450 break;
451 case PIPE_CONTROL:/* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
452 size = (transfer_len == 0)? 2:
453 (transfer_len - 1) / 4096 + 3;
454 break;
455 case PIPE_INTERRUPT: /* 1 TD */
456 size = 1;
457 break;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200458 }
459
Zhang Wei4dae14c2007-06-06 10:08:14 +0200460 ed->purb = urb;
461
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200462 if (size >= (N_URB_TD - 1)) {
463 err("need %d TDs, only have %d", size, N_URB_TD);
464 return -1;
465 }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200466 purb_priv->pipe = pipe;
467
468 /* fill the private part of the URB */
469 purb_priv->length = size;
470 purb_priv->ed = ed;
471 purb_priv->actual_length = 0;
472
473 /* allocate the TDs */
474 /* note that td[0] was allocated in ep_add_ed */
475 for (i = 0; i < size; i++) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200476 purb_priv->td[i] = td_alloc(dev);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200477 if (!purb_priv->td[i]) {
478 purb_priv->length = i;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200479 urb_free_priv(purb_priv);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200480 err("sohci_submit_job: ENOMEM");
481 return -1;
482 }
483 }
484
485 if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200486 urb_free_priv(purb_priv);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200487 err("sohci_submit_job: EINVAL");
488 return -1;
489 }
490
491 /* link the ed into a chain if is not already */
492 if (ed->state != ED_OPER)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200493 ep_link(ohci, ed);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200494
495 /* fill the TDs and link it to the ed */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200496 td_submit_job(dev, pipe, buffer, transfer_len,
497 setup, purb_priv, interval);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200498
499 return 0;
500}
501
Zhang Wei4dae14c2007-06-06 10:08:14 +0200502static inline int sohci_return_job(struct ohci *hc, urb_priv_t *urb)
503{
504 struct ohci_regs *regs = hc->regs;
505
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200506 switch (usb_pipetype(urb->pipe)) {
Zhang Wei4dae14c2007-06-06 10:08:14 +0200507 case PIPE_INTERRUPT:
508 /* implicitly requeued */
509 if (urb->dev->irq_handle &&
510 (urb->dev->irq_act_len = urb->actual_length)) {
Becky Brucea5496a12010-06-30 13:05:44 -0500511 ohci_writel(OHCI_INTR_WDH, &regs->intrenable);
512 ohci_readl(&regs->intrenable); /* PCI posting flush */
Zhang Wei4dae14c2007-06-06 10:08:14 +0200513 urb->dev->irq_handle(urb->dev);
Becky Brucea5496a12010-06-30 13:05:44 -0500514 ohci_writel(OHCI_INTR_WDH, &regs->intrdisable);
515 ohci_readl(&regs->intrdisable); /* PCI posting flush */
Zhang Wei4dae14c2007-06-06 10:08:14 +0200516 }
517 urb->actual_length = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200518 td_submit_job(
Zhang Wei4dae14c2007-06-06 10:08:14 +0200519 urb->dev,
520 urb->pipe,
521 urb->transfer_buffer,
522 urb->transfer_buffer_length,
523 NULL,
524 urb,
525 urb->interval);
526 break;
527 case PIPE_CONTROL:
528 case PIPE_BULK:
529 break;
530 default:
531 return 0;
532 }
533 return 1;
534}
535
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200536/*-------------------------------------------------------------------------*/
537
538#ifdef DEBUG
539/* tell us the current USB frame number */
540
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200541static int sohci_get_current_frame_number(struct usb_device *usb_dev)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200542{
543 ohci_t *ohci = &gohci;
544
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200545 return m16_swap(ohci->hcca->frame_no);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200546}
547#endif
548
549/*-------------------------------------------------------------------------*
550 * ED handling functions
551 *-------------------------------------------------------------------------*/
552
Zhang Wei4dae14c2007-06-06 10:08:14 +0200553/* search for the right branch to insert an interrupt ed into the int tree
554 * do some load ballancing;
555 * returns the branch and
556 * sets the interval to interval = 2^integer (ld (interval)) */
557
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200558static int ep_int_ballance(ohci_t *ohci, int interval, int load)
Zhang Wei4dae14c2007-06-06 10:08:14 +0200559{
560 int i, branch = 0;
561
562 /* search for the least loaded interrupt endpoint
563 * branch of all 32 branches
564 */
565 for (i = 0; i < 32; i++)
566 if (ohci->ohci_int_load [branch] > ohci->ohci_int_load [i])
567 branch = i;
568
569 branch = branch % interval;
570 for (i = branch; i < 32; i += interval)
571 ohci->ohci_int_load [i] += load;
572
573 return branch;
574}
575
576/*-------------------------------------------------------------------------*/
577
578/* 2^int( ld (inter)) */
579
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200580static int ep_2_n_interval(int inter)
Zhang Wei4dae14c2007-06-06 10:08:14 +0200581{
582 int i;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200583 for (i = 0; ((inter >> i) > 1) && (i < 5); i++);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200584 return 1 << i;
585}
586
587/*-------------------------------------------------------------------------*/
588
589/* the int tree is a binary tree
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200590 * in order to process it sequentially the indexes of the branches have to
591 * be mapped the mapping reverses the bits of a word of num_bits length */
592static int ep_rev(int num_bits, int word)
Zhang Wei4dae14c2007-06-06 10:08:14 +0200593{
594 int i, wout = 0;
595
596 for (i = 0; i < num_bits; i++)
597 wout |= (((word >> i) & 1) << (num_bits - i - 1));
598 return wout;
599}
600
601/*-------------------------------------------------------------------------*
602 * ED handling functions
603 *-------------------------------------------------------------------------*/
604
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200605/* link an ed into one of the HC chains */
606
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200607static int ep_link(ohci_t *ohci, ed_t *edi)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200608{
609 volatile ed_t *ed = edi;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200610 int int_branch;
611 int i;
612 int inter;
613 int interval;
614 int load;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200615 __u32 *ed_p;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200616
617 ed->state = ED_OPER;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200618 ed->int_interval = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200619
620 switch (ed->type) {
621 case PIPE_CONTROL:
622 ed->hwNextED = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200623 if (ohci->ed_controltail == NULL)
Becky Brucea5496a12010-06-30 13:05:44 -0500624 ohci_writel(ed, &ohci->regs->ed_controlhead);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200625 else
626 ohci->ed_controltail->hwNextED =
627 m32_swap((unsigned long)ed);
628
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200629 ed->ed_prev = ohci->ed_controltail;
630 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
631 !ohci->ed_rm_list[1] && !ohci->sleeping) {
632 ohci->hc_control |= OHCI_CTRL_CLE;
Becky Brucea5496a12010-06-30 13:05:44 -0500633 ohci_writel(ohci->hc_control, &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200634 }
635 ohci->ed_controltail = edi;
636 break;
637
638 case PIPE_BULK:
639 ed->hwNextED = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200640 if (ohci->ed_bulktail == NULL)
Becky Brucea5496a12010-06-30 13:05:44 -0500641 ohci_writel(ed, &ohci->regs->ed_bulkhead);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200642 else
643 ohci->ed_bulktail->hwNextED =
644 m32_swap((unsigned long)ed);
645
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200646 ed->ed_prev = ohci->ed_bulktail;
647 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
648 !ohci->ed_rm_list[1] && !ohci->sleeping) {
649 ohci->hc_control |= OHCI_CTRL_BLE;
Becky Brucea5496a12010-06-30 13:05:44 -0500650 ohci_writel(ohci->hc_control, &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200651 }
652 ohci->ed_bulktail = edi;
653 break;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200654
655 case PIPE_INTERRUPT:
656 load = ed->int_load;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200657 interval = ep_2_n_interval(ed->int_period);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200658 ed->int_interval = interval;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200659 int_branch = ep_int_ballance(ohci, interval, load);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200660 ed->int_branch = int_branch;
661
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200662 for (i = 0; i < ep_rev(6, interval); i += inter) {
Zhang Wei4dae14c2007-06-06 10:08:14 +0200663 inter = 1;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200664 for (ed_p = &(ohci->hcca->int_table[\
665 ep_rev(5, i) + int_branch]);
666 (*ed_p != 0) &&
667 (((ed_t *)ed_p)->int_interval >= interval);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200668 ed_p = &(((ed_t *)ed_p)->hwNextED))
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200669 inter = ep_rev(6,
670 ((ed_t *)ed_p)->int_interval);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200671 ed->hwNextED = *ed_p;
Martin Krause4a8527e2007-08-21 12:40:34 +0200672 *ed_p = m32_swap((unsigned long)ed);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200673 }
674 break;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200675 }
676 return 0;
677}
678
679/*-------------------------------------------------------------------------*/
680
Zhang Wei4dae14c2007-06-06 10:08:14 +0200681/* scan the periodic table to find and unlink this ED */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200682static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
683 unsigned index, unsigned period)
Zhang Wei4dae14c2007-06-06 10:08:14 +0200684{
685 for (; index < NUM_INTS; index += period) {
686 __u32 *ed_p = &ohci->hcca->int_table [index];
687
688 /* ED might have been unlinked through another path */
689 while (*ed_p != 0) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200690 if (((struct ed *)
691 m32_swap((unsigned long)ed_p)) == ed) {
Zhang Wei4dae14c2007-06-06 10:08:14 +0200692 *ed_p = ed->hwNextED;
693 break;
694 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200695 ed_p = &(((struct ed *)
696 m32_swap((unsigned long)ed_p))->hwNextED);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200697 }
698 }
699}
700
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200701/* unlink an ed from one of the HC chains.
702 * just the link to the ed is unlinked.
703 * the link from the ed still points to another operational ed or 0
704 * so the HC can eventually finish the processing of the unlinked ed */
705
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200706static int ep_unlink(ohci_t *ohci, ed_t *edi)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200707{
Markus Klotzbuecher53e336e2006-11-27 11:43:09 +0100708 volatile ed_t *ed = edi;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200709 int i;
Markus Klotzbuecher53e336e2006-11-27 11:43:09 +0100710
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200711 ed->hwINFO |= m32_swap(OHCI_ED_SKIP);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200712
713 switch (ed->type) {
714 case PIPE_CONTROL:
715 if (ed->ed_prev == NULL) {
716 if (!ed->hwNextED) {
717 ohci->hc_control &= ~OHCI_CTRL_CLE;
Becky Brucea5496a12010-06-30 13:05:44 -0500718 ohci_writel(ohci->hc_control,
719 &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200720 }
Becky Brucea5496a12010-06-30 13:05:44 -0500721 ohci_writel(m32_swap(*((__u32 *)&ed->hwNextED)),
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200722 &ohci->regs->ed_controlhead);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200723 } else {
724 ed->ed_prev->hwNextED = ed->hwNextED;
725 }
726 if (ohci->ed_controltail == ed) {
727 ohci->ed_controltail = ed->ed_prev;
728 } else {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200729 ((ed_t *)m32_swap(
730 *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200731 }
732 break;
733
734 case PIPE_BULK:
735 if (ed->ed_prev == NULL) {
736 if (!ed->hwNextED) {
737 ohci->hc_control &= ~OHCI_CTRL_BLE;
Becky Brucea5496a12010-06-30 13:05:44 -0500738 ohci_writel(ohci->hc_control,
739 &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200740 }
Becky Brucea5496a12010-06-30 13:05:44 -0500741 ohci_writel(m32_swap(*((__u32 *)&ed->hwNextED)),
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200742 &ohci->regs->ed_bulkhead);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200743 } else {
744 ed->ed_prev->hwNextED = ed->hwNextED;
745 }
746 if (ohci->ed_bulktail == ed) {
747 ohci->ed_bulktail = ed->ed_prev;
748 } else {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200749 ((ed_t *)m32_swap(
750 *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200751 }
752 break;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200753
754 case PIPE_INTERRUPT:
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200755 periodic_unlink(ohci, ed, 0, 1);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200756 for (i = ed->int_branch; i < 32; i += ed->int_interval)
757 ohci->ohci_int_load[i] -= ed->int_load;
758 break;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200759 }
760 ed->state = ED_UNLINK;
761 return 0;
762}
763
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200764/*-------------------------------------------------------------------------*/
765
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +0200766/* add/reinit an endpoint; this should be done once at the
767 * usb_set_configuration command, but the USB stack is a little bit
768 * stateless so we do it at every transaction if the state of the ed
769 * is ED_NEW then a dummy td is added and the state is changed to
770 * ED_UNLINK in all other cases the state is left unchanged the ed
771 * info fields are setted anyway even though most of them should not
772 * change
773 */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200774static ed_t *ep_add_ed(struct usb_device *usb_dev, unsigned long pipe,
775 int interval, int load)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200776{
777 td_t *td;
778 ed_t *ed_ret;
779 volatile ed_t *ed;
780
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200781 ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint(pipe) << 1) |
782 (usb_pipecontrol(pipe)? 0: usb_pipeout(pipe))];
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200783
784 if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
785 err("ep_add_ed: pending delete");
786 /* pending delete request */
787 return NULL;
788 }
789
790 if (ed->state == ED_NEW) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200791 /* dummy td; end of td list for ed */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200792 td = td_alloc(usb_dev);
793 ed->hwTailP = m32_swap((unsigned long)td);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200794 ed->hwHeadP = ed->hwTailP;
795 ed->state = ED_UNLINK;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200796 ed->type = usb_pipetype(pipe);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200797 ohci_dev.ed_cnt++;
798 }
799
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200800 ed->hwINFO = m32_swap(usb_pipedevice(pipe)
801 | usb_pipeendpoint(pipe) << 7
802 | (usb_pipeisoc(pipe)? 0x8000: 0)
803 | (usb_pipecontrol(pipe)? 0: \
804 (usb_pipeout(pipe)? 0x800: 0x1000))
Ilya Yanokc60795f2012-11-06 13:48:20 +0000805 | (usb_dev->speed == USB_SPEED_LOW) << 13
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200806 | usb_maxpacket(usb_dev, pipe) << 16);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200807
Zhang Wei4dae14c2007-06-06 10:08:14 +0200808 if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) {
809 ed->int_period = interval;
810 ed->int_load = load;
811 }
812
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200813 return ed_ret;
814}
815
816/*-------------------------------------------------------------------------*
817 * TD handling functions
818 *-------------------------------------------------------------------------*/
819
820/* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
821
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200822static void td_fill(ohci_t *ohci, unsigned int info,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200823 void *data, int len,
824 struct usb_device *dev, int index, urb_priv_t *urb_priv)
825{
826 volatile td_t *td, *td_pt;
827#ifdef OHCI_FILL_TRACE
828 int i;
829#endif
830
831 if (index > urb_priv->length) {
832 err("index > length");
833 return;
834 }
835 /* use this td as the next dummy */
836 td_pt = urb_priv->td [index];
837 td_pt->hwNextTD = 0;
838
839 /* fill the old dummy TD */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200840 td = urb_priv->td [index] =
841 (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200842
843 td->ed = urb_priv->ed;
844 td->next_dl_td = NULL;
845 td->index = index;
846 td->data = (__u32)data;
847#ifdef OHCI_FILL_TRACE
Remy Bohmer48867202008-10-10 10:23:21 +0200848 if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200849 for (i = 0; i < len; i++)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200850 printf("td->data[%d] %#2x ", i, ((unsigned char *)td->data)[i]);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200851 printf("\n");
852 }
853#endif
854 if (!len)
855 data = 0;
856
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200857 td->hwINFO = m32_swap(info);
858 td->hwCBP = m32_swap((unsigned long)data);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200859 if (data)
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200860 td->hwBE = m32_swap((unsigned long)(data + len - 1));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200861 else
862 td->hwBE = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200863
864 td->hwNextTD = m32_swap((unsigned long)td_pt);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200865
866 /* append to queue */
867 td->ed->hwTailP = td->hwNextTD;
868}
869
870/*-------------------------------------------------------------------------*/
871
872/* prepare all TDs of a transfer */
873
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200874static void td_submit_job(struct usb_device *dev, unsigned long pipe,
875 void *buffer, int transfer_len,
876 struct devrequest *setup, urb_priv_t *urb,
877 int interval)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200878{
879 ohci_t *ohci = &gohci;
880 int data_len = transfer_len;
881 void *data;
882 int cnt = 0;
883 __u32 info = 0;
884 unsigned int toggle = 0;
885
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200886 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle
887 * bits for reseting */
888 if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200889 toggle = TD_T_TOGGLE;
890 } else {
891 toggle = TD_T_DATA0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200892 usb_settoggle(dev, usb_pipeendpoint(pipe),
893 usb_pipeout(pipe), 1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200894 }
895 urb->td_cnt = 0;
896 if (data_len)
897 data = buffer;
898 else
899 data = 0;
900
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200901 switch (usb_pipetype(pipe)) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200902 case PIPE_BULK:
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200903 info = usb_pipeout(pipe)?
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200904 TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200905 while (data_len > 4096) {
906 td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle),
907 data, 4096, dev, cnt, urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200908 data += 4096; data_len -= 4096; cnt++;
909 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200910 info = usb_pipeout(pipe)?
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200911 TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200912 td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), data,
913 data_len, dev, cnt, urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200914 cnt++;
915
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200916 if (!ohci->sleeping) {
917 /* start bulk list */
Becky Brucea5496a12010-06-30 13:05:44 -0500918 ohci_writel(OHCI_BLF, &ohci->regs->cmdstatus);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200919 }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200920 break;
921
922 case PIPE_CONTROL:
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200923 /* Setup phase */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200924 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200925 td_fill(ohci, info, setup, 8, dev, cnt++, urb);
926
927 /* Optional Data phase */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200928 if (data_len > 0) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200929 info = usb_pipeout(pipe)?
930 TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 :
931 TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200932 /* NOTE: mishandles transfers >8K, some >4K */
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200933 td_fill(ohci, info, data, data_len, dev, cnt++, urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200934 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200935
936 /* Status phase */
937 info = usb_pipeout(pipe)?
938 TD_CC | TD_DP_IN | TD_T_DATA1:
939 TD_CC | TD_DP_OUT | TD_T_DATA1;
940 td_fill(ohci, info, data, 0, dev, cnt++, urb);
941
942 if (!ohci->sleeping) {
943 /* start Control list */
Becky Brucea5496a12010-06-30 13:05:44 -0500944 ohci_writel(OHCI_CLF, &ohci->regs->cmdstatus);
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200945 }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200946 break;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200947
948 case PIPE_INTERRUPT:
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200949 info = usb_pipeout(urb->pipe)?
Zhang Wei4dae14c2007-06-06 10:08:14 +0200950 TD_CC | TD_DP_OUT | toggle:
951 TD_CC | TD_R | TD_DP_IN | toggle;
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200952 td_fill(ohci, info, data, data_len, dev, cnt++, urb);
Zhang Wei4dae14c2007-06-06 10:08:14 +0200953 break;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200954 }
955 if (urb->length != cnt)
956 dbg("TD LENGTH %d != CNT %d", urb->length, cnt);
957}
958
959/*-------------------------------------------------------------------------*
960 * Done List handling functions
961 *-------------------------------------------------------------------------*/
962
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200963/* calculate the transfer length and update the urb */
964
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200965static void dl_transfer_length(td_t *td)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200966{
Wolfgang Denk6bc52ef2011-10-05 23:03:43 +0200967 __u32 tdBE, tdCBP;
Zhang Wei4dae14c2007-06-06 10:08:14 +0200968 urb_priv_t *lurb_priv = td->ed->purb;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200969
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200970 tdBE = m32_swap(td->hwBE);
971 tdCBP = m32_swap(td->hwCBP);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200972
Remy Bohmer48867202008-10-10 10:23:21 +0200973 if (!(usb_pipecontrol(lurb_priv->pipe) &&
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200974 ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
975 if (tdBE != 0) {
976 if (td->hwCBP == 0)
977 lurb_priv->actual_length += tdBE - td->data + 1;
978 else
979 lurb_priv->actual_length += tdCBP - td->data;
980 }
981 }
982}
983
984/*-------------------------------------------------------------------------*/
Remy Bohmer6f5794a2008-09-16 14:55:43 +0200985static void check_status(td_t *td_list)
986{
987 urb_priv_t *lurb_priv = td_list->ed->purb;
988 int urb_len = lurb_priv->length;
989 __u32 *phwHeadP = &td_list->ed->hwHeadP;
990 int cc;
991
992 cc = TD_CC_GET(m32_swap(td_list->hwINFO));
993 if (cc) {
994 err(" USB-error: %s (%x)", cc_to_string[cc], cc);
995
996 if (*phwHeadP & m32_swap(0x1)) {
997 if (lurb_priv &&
998 ((td_list->index + 1) < urb_len)) {
999 *phwHeadP =
1000 (lurb_priv->td[urb_len - 1]->hwNextTD &\
1001 m32_swap(0xfffffff0)) |
1002 (*phwHeadP & m32_swap(0x2));
1003
1004 lurb_priv->td_cnt += urb_len -
1005 td_list->index - 1;
1006 } else
1007 *phwHeadP &= m32_swap(0xfffffff2);
1008 }
1009#ifdef CONFIG_MPC5200
1010 td_list->hwNextTD = 0;
1011#endif
1012 }
1013}
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001014
1015/* replies to the request have to be on a FIFO basis so
1016 * we reverse the reversed done-list */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001017static td_t *dl_reverse_done_list(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001018{
1019 __u32 td_list_hc;
1020 td_t *td_rev = NULL;
1021 td_t *td_list = NULL;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001022
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001023 td_list_hc = m32_swap(ohci->hcca->done_head) & 0xfffffff0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001024 ohci->hcca->done_head = 0;
1025
1026 while (td_list_hc) {
1027 td_list = (td_t *)td_list_hc;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001028 check_status(td_list);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001029 td_list->next_dl_td = td_rev;
1030 td_rev = td_list;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001031 td_list_hc = m32_swap(td_list->hwNextTD) & 0xfffffff0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001032 }
1033 return td_list;
1034}
1035
1036/*-------------------------------------------------------------------------*/
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001037/*-------------------------------------------------------------------------*/
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001038
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001039static void finish_urb(ohci_t *ohci, urb_priv_t *urb, int status)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001040{
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001041 if ((status & (ED_OPER | ED_UNLINK)) && (urb->state != URB_DEL))
1042 urb->finished = sohci_return_job(ohci, urb);
1043 else
1044 dbg("finish_urb: strange.., ED state %x, \n", status);
1045}
1046
1047/*
1048 * Used to take back a TD from the host controller. This would normally be
1049 * called from within dl_done_list, however it may be called directly if the
1050 * HC no longer sees the TD and it has not appeared on the donelist (after
1051 * two frames). This bug has been observed on ZF Micro systems.
1052 */
1053static int takeback_td(ohci_t *ohci, td_t *td_list)
1054{
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001055 ed_t *ed;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001056 int cc;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001057 int stat = 0;
1058 /* urb_t *urb; */
1059 urb_priv_t *lurb_priv;
1060 __u32 tdINFO, edHeadP, edTailP;
1061
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001062 tdINFO = m32_swap(td_list->hwINFO);
1063
1064 ed = td_list->ed;
1065 lurb_priv = ed->purb;
1066
1067 dl_transfer_length(td_list);
1068
1069 lurb_priv->td_cnt++;
1070
1071 /* error code of transfer */
1072 cc = TD_CC_GET(tdINFO);
1073 if (cc) {
1074 err("USB-error: %s (%x)", cc_to_string[cc], cc);
1075 stat = cc_to_error[cc];
1076 }
1077
1078 /* see if this done list makes for all TD's of current URB,
1079 * and mark the URB finished if so */
1080 if (lurb_priv->td_cnt == lurb_priv->length)
1081 finish_urb(ohci, lurb_priv, ed->state);
1082
1083 dbg("dl_done_list: processing TD %x, len %x\n",
1084 lurb_priv->td_cnt, lurb_priv->length);
1085
Remy Bohmer48867202008-10-10 10:23:21 +02001086 if (ed->state != ED_NEW && (!usb_pipeint(lurb_priv->pipe))) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001087 edHeadP = m32_swap(ed->hwHeadP) & 0xfffffff0;
1088 edTailP = m32_swap(ed->hwTailP);
1089
1090 /* unlink eds if they are not busy */
1091 if ((edHeadP == edTailP) && (ed->state == ED_OPER))
1092 ep_unlink(ohci, ed);
1093 }
1094 return stat;
1095}
1096
1097static int dl_done_list(ohci_t *ohci)
1098{
1099 int stat = 0;
1100 td_t *td_list = dl_reverse_done_list(ohci);
1101
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001102 while (td_list) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001103 td_t *td_next = td_list->next_dl_td;
1104 stat = takeback_td(ohci, td_list);
1105 td_list = td_next;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001106 }
1107 return stat;
1108}
1109
1110/*-------------------------------------------------------------------------*
1111 * Virtual Root Hub
1112 *-------------------------------------------------------------------------*/
1113
1114/* Device descriptor */
1115static __u8 root_hub_dev_des[] =
1116{
1117 0x12, /* __u8 bLength; */
1118 0x01, /* __u8 bDescriptorType; Device */
1119 0x10, /* __u16 bcdUSB; v1.1 */
1120 0x01,
1121 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
1122 0x00, /* __u8 bDeviceSubClass; */
1123 0x00, /* __u8 bDeviceProtocol; */
1124 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
1125 0x00, /* __u16 idVendor; */
1126 0x00,
1127 0x00, /* __u16 idProduct; */
1128 0x00,
1129 0x00, /* __u16 bcdDevice; */
1130 0x00,
1131 0x00, /* __u8 iManufacturer; */
1132 0x01, /* __u8 iProduct; */
1133 0x00, /* __u8 iSerialNumber; */
1134 0x01 /* __u8 bNumConfigurations; */
1135};
1136
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001137/* Configuration descriptor */
1138static __u8 root_hub_config_des[] =
1139{
1140 0x09, /* __u8 bLength; */
1141 0x02, /* __u8 bDescriptorType; Configuration */
1142 0x19, /* __u16 wTotalLength; */
1143 0x00,
1144 0x01, /* __u8 bNumInterfaces; */
1145 0x01, /* __u8 bConfigurationValue; */
1146 0x00, /* __u8 iConfiguration; */
1147 0x40, /* __u8 bmAttributes;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001148 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001149 0x00, /* __u8 MaxPower; */
1150
1151 /* interface */
1152 0x09, /* __u8 if_bLength; */
1153 0x04, /* __u8 if_bDescriptorType; Interface */
1154 0x00, /* __u8 if_bInterfaceNumber; */
1155 0x00, /* __u8 if_bAlternateSetting; */
1156 0x01, /* __u8 if_bNumEndpoints; */
1157 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
1158 0x00, /* __u8 if_bInterfaceSubClass; */
1159 0x00, /* __u8 if_bInterfaceProtocol; */
1160 0x00, /* __u8 if_iInterface; */
1161
1162 /* endpoint */
1163 0x07, /* __u8 ep_bLength; */
1164 0x05, /* __u8 ep_bDescriptorType; Endpoint */
1165 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
1166 0x03, /* __u8 ep_bmAttributes; Interrupt */
1167 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
1168 0x00,
1169 0xff /* __u8 ep_bInterval; 255 ms */
1170};
1171
1172static unsigned char root_hub_str_index0[] =
1173{
1174 0x04, /* __u8 bLength; */
1175 0x03, /* __u8 bDescriptorType; String-descriptor */
1176 0x09, /* __u8 lang ID */
1177 0x04, /* __u8 lang ID */
1178};
1179
1180static unsigned char root_hub_str_index1[] =
1181{
1182 28, /* __u8 bLength; */
1183 0x03, /* __u8 bDescriptorType; String-descriptor */
1184 'O', /* __u8 Unicode */
1185 0, /* __u8 Unicode */
1186 'H', /* __u8 Unicode */
1187 0, /* __u8 Unicode */
1188 'C', /* __u8 Unicode */
1189 0, /* __u8 Unicode */
1190 'I', /* __u8 Unicode */
1191 0, /* __u8 Unicode */
1192 ' ', /* __u8 Unicode */
1193 0, /* __u8 Unicode */
1194 'R', /* __u8 Unicode */
1195 0, /* __u8 Unicode */
1196 'o', /* __u8 Unicode */
1197 0, /* __u8 Unicode */
1198 'o', /* __u8 Unicode */
1199 0, /* __u8 Unicode */
1200 't', /* __u8 Unicode */
1201 0, /* __u8 Unicode */
1202 ' ', /* __u8 Unicode */
1203 0, /* __u8 Unicode */
1204 'H', /* __u8 Unicode */
1205 0, /* __u8 Unicode */
1206 'u', /* __u8 Unicode */
1207 0, /* __u8 Unicode */
1208 'b', /* __u8 Unicode */
1209 0, /* __u8 Unicode */
1210};
1211
1212/* Hub class-specific descriptor is constructed dynamically */
1213
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001214/*-------------------------------------------------------------------------*/
1215
1216#define OK(x) len = (x); break
1217#ifdef DEBUG
Becky Brucea5496a12010-06-30 13:05:44 -05001218#define WR_RH_STAT(x) {info("WR:status %#8x", (x)); ohci_writel((x), \
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001219 &gohci.regs->roothub.status); }
1220#define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, \
Becky Brucea5496a12010-06-30 13:05:44 -05001221 (x)); ohci_writel((x), &gohci.regs->roothub.portstatus[wIndex-1]); }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001222#else
Becky Brucea5496a12010-06-30 13:05:44 -05001223#define WR_RH_STAT(x) ohci_writel((x), &gohci.regs->roothub.status)
1224#define WR_RH_PORTSTAT(x) ohci_writel((x), \
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001225 &gohci.regs->roothub.portstatus[wIndex-1])
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001226#endif
1227#define RD_RH_STAT roothub_status(&gohci)
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001228#define RD_RH_PORTSTAT roothub_portstatus(&gohci, wIndex-1)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001229
1230/* request to virtual root hub */
1231
1232int rh_check_port_status(ohci_t *controller)
1233{
1234 __u32 temp, ndp, i;
1235 int res;
1236
1237 res = -1;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001238 temp = roothub_a(controller);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001239 ndp = (temp & RH_A_NDP);
1240#ifdef CONFIG_AT91C_PQFP_UHPBUG
1241 ndp = (ndp == 2) ? 1:0;
1242#endif
1243 for (i = 0; i < ndp; i++) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001244 temp = roothub_portstatus(controller, i);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001245 /* check for a device disconnect */
1246 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
1247 (RH_PS_PESC | RH_PS_CSC)) &&
1248 ((temp & RH_PS_CCS) == 0)) {
1249 res = i;
1250 break;
1251 }
1252 }
1253 return res;
1254}
1255
1256static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
1257 void *buffer, int transfer_len, struct devrequest *cmd)
1258{
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001259 void *data = buffer;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001260 int leni = transfer_len;
1261 int len = 0;
1262 int stat = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001263 __u16 bmRType_bReq;
1264 __u16 wValue;
1265 __u16 wIndex;
1266 __u16 wLength;
Troy Kiskyf1273f12012-08-11 14:49:09 -07001267 ALLOC_ALIGN_BUFFER(__u8, databuf, 16, sizeof(u32));
Marek Vasut5f6aa032011-10-07 02:00:13 +02001268
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001269#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001270pkt_print(NULL, dev, pipe, buffer, transfer_len,
1271 cmd, "SUB(rh)", usb_pipein(pipe));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001272#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001273 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001274#endif
Remy Bohmer48867202008-10-10 10:23:21 +02001275 if (usb_pipeint(pipe)) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001276 info("Root-Hub submit IRQ: NOT implemented");
1277 return 0;
1278 }
1279
1280 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001281 wValue = le16_to_cpu(cmd->value);
1282 wIndex = le16_to_cpu(cmd->index);
1283 wLength = le16_to_cpu(cmd->length);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001284
1285 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1286 dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
1287
1288 switch (bmRType_bReq) {
1289 /* Request Destination:
1290 without flags: Device,
1291 RH_INTERFACE: interface,
1292 RH_ENDPOINT: endpoint,
1293 RH_CLASS means HUB here,
1294 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1295 */
1296
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001297 case RH_GET_STATUS:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001298 *(u16 *)databuf = cpu_to_le16(1);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001299 OK(2);
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001300 case RH_GET_STATUS | RH_INTERFACE:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001301 *(u16 *)databuf = cpu_to_le16(0);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001302 OK(2);
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001303 case RH_GET_STATUS | RH_ENDPOINT:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001304 *(u16 *)databuf = cpu_to_le16(0);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001305 OK(2);
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001306 case RH_GET_STATUS | RH_CLASS:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001307 *(u32 *)databuf = cpu_to_le32(
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001308 RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001309 OK(4);
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001310 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001311 *(u32 *)databuf = cpu_to_le32(RD_RH_PORTSTAT);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001312 OK(4);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001313
1314 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1315 switch (wValue) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001316 case (RH_ENDPOINT_STALL):
1317 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001318 }
1319 break;
1320
1321 case RH_CLEAR_FEATURE | RH_CLASS:
1322 switch (wValue) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001323 case RH_C_HUB_LOCAL_POWER:
1324 OK(0);
1325 case (RH_C_HUB_OVER_CURRENT):
1326 WR_RH_STAT(RH_HS_OCIC);
1327 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001328 }
1329 break;
1330
1331 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1332 switch (wValue) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001333 case (RH_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_CCS); OK(0);
1334 case (RH_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_POCI); OK(0);
1335 case (RH_PORT_POWER): WR_RH_PORTSTAT(RH_PS_LSDA); OK(0);
1336 case (RH_C_PORT_CONNECTION): WR_RH_PORTSTAT(RH_PS_CSC); OK(0);
1337 case (RH_C_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_PESC); OK(0);
1338 case (RH_C_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_PSSC); OK(0);
1339 case (RH_C_PORT_OVER_CURRENT):WR_RH_PORTSTAT(RH_PS_OCIC); OK(0);
1340 case (RH_C_PORT_RESET): WR_RH_PORTSTAT(RH_PS_PRSC); OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001341 }
1342 break;
1343
1344 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1345 switch (wValue) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001346 case (RH_PORT_SUSPEND):
1347 WR_RH_PORTSTAT(RH_PS_PSS); OK(0);
1348 case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
1349 if (RD_RH_PORTSTAT & RH_PS_CCS)
1350 WR_RH_PORTSTAT(RH_PS_PRS);
1351 OK(0);
1352 case (RH_PORT_POWER):
1353 WR_RH_PORTSTAT(RH_PS_PPS);
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001354 mdelay(100);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001355 OK(0);
1356 case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
1357 if (RD_RH_PORTSTAT & RH_PS_CCS)
1358 WR_RH_PORTSTAT(RH_PS_PES);
1359 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001360 }
1361 break;
1362
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001363 case RH_SET_ADDRESS:
1364 gohci.rh.devnum = wValue;
1365 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001366
1367 case RH_GET_DESCRIPTOR:
1368 switch ((wValue & 0xff00) >> 8) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001369 case (0x01): /* device descriptor */
1370 len = min_t(unsigned int,
1371 leni,
1372 min_t(unsigned int,
1373 sizeof(root_hub_dev_des),
1374 wLength));
Troy Kiskyf1273f12012-08-11 14:49:09 -07001375 databuf = root_hub_dev_des; OK(len);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001376 case (0x02): /* configuration descriptor */
1377 len = min_t(unsigned int,
1378 leni,
1379 min_t(unsigned int,
1380 sizeof(root_hub_config_des),
1381 wLength));
Troy Kiskyf1273f12012-08-11 14:49:09 -07001382 databuf = root_hub_config_des; OK(len);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001383 case (0x03): /* string descriptors */
1384 if (wValue == 0x0300) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001385 len = min_t(unsigned int,
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001386 leni,
1387 min_t(unsigned int,
1388 sizeof(root_hub_str_index0),
1389 wLength));
Troy Kiskyf1273f12012-08-11 14:49:09 -07001390 databuf = root_hub_str_index0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001391 OK(len);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001392 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001393 if (wValue == 0x0301) {
1394 len = min_t(unsigned int,
1395 leni,
1396 min_t(unsigned int,
1397 sizeof(root_hub_str_index1),
1398 wLength));
Troy Kiskyf1273f12012-08-11 14:49:09 -07001399 databuf = root_hub_str_index1;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001400 OK(len);
1401 }
1402 default:
1403 stat = USB_ST_STALLED;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001404 }
1405 break;
1406
1407 case RH_GET_DESCRIPTOR | RH_CLASS:
1408 {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001409 __u32 temp = roothub_a(&gohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001410
Troy Kiskyf1273f12012-08-11 14:49:09 -07001411 databuf[0] = 9; /* min length; */
1412 databuf[1] = 0x29;
1413 databuf[2] = temp & RH_A_NDP;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001414#ifdef CONFIG_AT91C_PQFP_UHPBUG
Troy Kiskyf1273f12012-08-11 14:49:09 -07001415 databuf[2] = (databuf[2] == 2) ? 1 : 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001416#endif
Troy Kiskyf1273f12012-08-11 14:49:09 -07001417 databuf[3] = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001418 if (temp & RH_A_PSM) /* per-port power switching? */
Troy Kiskyf1273f12012-08-11 14:49:09 -07001419 databuf[3] |= 0x1;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001420 if (temp & RH_A_NOCP) /* no overcurrent reporting? */
Troy Kiskyf1273f12012-08-11 14:49:09 -07001421 databuf[3] |= 0x10;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001422 else if (temp & RH_A_OCPM)/* per-port overcurrent reporting? */
Troy Kiskyf1273f12012-08-11 14:49:09 -07001423 databuf[3] |= 0x8;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001424
Troy Kiskyf1273f12012-08-11 14:49:09 -07001425 databuf[4] = 0;
1426 databuf[5] = (temp & RH_A_POTPGT) >> 24;
1427 databuf[6] = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001428 temp = roothub_b(&gohci);
Troy Kiskyf1273f12012-08-11 14:49:09 -07001429 databuf[7] = temp & RH_B_DR;
1430 if (databuf[2] < 7) {
1431 databuf[8] = 0xff;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001432 } else {
Troy Kiskyf1273f12012-08-11 14:49:09 -07001433 databuf[0] += 2;
1434 databuf[8] = (temp & RH_B_DR) >> 8;
1435 databuf[10] = databuf[9] = 0xff;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001436 }
1437
1438 len = min_t(unsigned int, leni,
Troy Kiskyf1273f12012-08-11 14:49:09 -07001439 min_t(unsigned int, databuf[0], wLength));
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001440 OK(len);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001441 }
1442
Marek Vasut5f6aa032011-10-07 02:00:13 +02001443 case RH_GET_CONFIGURATION:
Troy Kiskyf1273f12012-08-11 14:49:09 -07001444 databuf[0] = 0x01;
Marek Vasut5f6aa032011-10-07 02:00:13 +02001445 OK(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001446
Marek Vasut5f6aa032011-10-07 02:00:13 +02001447 case RH_SET_CONFIGURATION:
1448 WR_RH_STAT(0x10000);
1449 OK(0);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001450
1451 default:
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001452 dbg("unsupported root hub command");
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001453 stat = USB_ST_STALLED;
1454 }
1455
1456#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001457 ohci_dump_roothub(&gohci, 1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001458#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001459 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001460#endif
1461
1462 len = min_t(int, len, leni);
Troy Kiskyf1273f12012-08-11 14:49:09 -07001463 if (data != databuf)
1464 memcpy(data, databuf, len);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001465 dev->act_len = len;
1466 dev->status = stat;
1467
1468#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001469 pkt_print(NULL, dev, pipe, buffer,
1470 transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001471#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001472 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001473#endif
1474
1475 return stat;
1476}
1477
1478/*-------------------------------------------------------------------------*/
1479
1480/* common code for handling submit messages - used for all but root hub */
1481/* accesses. */
1482int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1483 int transfer_len, struct devrequest *setup, int interval)
1484{
1485 int stat = 0;
1486 int maxsize = usb_maxpacket(dev, pipe);
1487 int timeout;
Zhang Wei4dae14c2007-06-06 10:08:14 +02001488 urb_priv_t *urb;
1489
1490 urb = malloc(sizeof(urb_priv_t));
1491 memset(urb, 0, sizeof(urb_priv_t));
1492
1493 urb->dev = dev;
1494 urb->pipe = pipe;
1495 urb->transfer_buffer = buffer;
1496 urb->transfer_buffer_length = transfer_len;
1497 urb->interval = interval;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001498
1499 /* device pulled? Shortcut the action. */
1500 if (devgone == dev) {
1501 dev->status = USB_ST_CRC_ERR;
1502 return 0;
1503 }
1504
1505#ifdef DEBUG
Zhang Wei4dae14c2007-06-06 10:08:14 +02001506 urb->actual_length = 0;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001507 pkt_print(urb, dev, pipe, buffer, transfer_len,
1508 setup, "SUB", usb_pipein(pipe));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001509#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001510 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001511#endif
1512 if (!maxsize) {
1513 err("submit_common_message: pipesize for pipe %lx is zero",
1514 pipe);
1515 return -1;
1516 }
1517
Zhang Wei4dae14c2007-06-06 10:08:14 +02001518 if (sohci_submit_job(urb, setup) < 0) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001519 err("sohci_submit_job failed");
1520 return -1;
1521 }
1522
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001523#if 0
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001524 mdelay(10);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001525 /* ohci_dump_status(&gohci); */
Markus Klotzbuecherae3b7702006-11-27 11:46:46 +01001526#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001527
Simon Glass96820a32011-02-07 14:42:16 -08001528 timeout = USB_TIMEOUT_MS(pipe);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001529
1530 /* wait for it to complete */
1531 for (;;) {
1532 /* check whether the controller is done */
1533 stat = hc_interrupt();
1534 if (stat < 0) {
1535 stat = USB_ST_CRC_ERR;
1536 break;
1537 }
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001538
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001539 /* NOTE: since we are not interrupt driven in U-Boot and always
1540 * handle only one URB at a time, we cannot assume the
1541 * transaction finished on the first successful return from
1542 * hc_interrupt().. unless the flag for current URB is set,
1543 * meaning that all TD's to/from device got actually
1544 * transferred and processed. If the current URB is not
1545 * finished we need to re-iterate this loop so as
1546 * hc_interrupt() gets called again as there needs to be some
1547 * more TD's to process still */
Zhang Wei4dae14c2007-06-06 10:08:14 +02001548 if ((stat >= 0) && (stat != 0xff) && (urb->finished)) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001549 /* 0xff is returned for an SF-interrupt */
1550 break;
1551 }
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001552
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001553 if (--timeout) {
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001554 mdelay(1);
Zhang Wei4dae14c2007-06-06 10:08:14 +02001555 if (!urb->finished)
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001556 dbg("*");
Zhang Wei4dae14c2007-06-06 10:08:14 +02001557
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001558 } else {
1559 err("CTL:TIMEOUT ");
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001560 dbg("submit_common_msg: TO status %x\n", stat);
Zhang Wei4dae14c2007-06-06 10:08:14 +02001561 urb->finished = 1;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001562 stat = USB_ST_CRC_ERR;
1563 break;
1564 }
1565 }
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001566
1567 dev->status = stat;
1568 dev->act_len = transfer_len;
1569
1570#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001571 pkt_print(urb, dev, pipe, buffer, transfer_len,
1572 setup, "RET(ctlr)", usb_pipein(pipe));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001573#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001574 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001575#endif
1576
1577 /* free TDs in urb_priv */
Remy Bohmer48867202008-10-10 10:23:21 +02001578 if (!usb_pipeint(pipe))
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001579 urb_free_priv(urb);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001580 return 0;
1581}
1582
1583/* submit routines called from usb.c */
1584int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1585 int transfer_len)
1586{
1587 info("submit_bulk_msg");
1588 return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0);
1589}
1590
1591int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1592 int transfer_len, struct devrequest *setup)
1593{
1594 int maxsize = usb_maxpacket(dev, pipe);
1595
1596 info("submit_control_msg");
1597#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001598 pkt_print(NULL, dev, pipe, buffer, transfer_len,
1599 setup, "SUB", usb_pipein(pipe));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001600#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001601 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001602#endif
1603 if (!maxsize) {
1604 err("submit_control_message: pipesize for pipe %lx is zero",
1605 pipe);
1606 return -1;
1607 }
1608 if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) {
1609 gohci.rh.dev = dev;
1610 /* root hub - redirect */
1611 return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len,
1612 setup);
1613 }
1614
1615 return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0);
1616}
1617
1618int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1619 int transfer_len, int interval)
1620{
1621 info("submit_int_msg");
Zhang Wei4dae14c2007-06-06 10:08:14 +02001622 return submit_common_msg(dev, pipe, buffer, transfer_len, NULL,
1623 interval);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001624}
1625
1626/*-------------------------------------------------------------------------*
1627 * HC functions
1628 *-------------------------------------------------------------------------*/
1629
1630/* reset the HC and BUS */
1631
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001632static int hc_reset(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001633{
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +02001634#ifdef CONFIG_PCI_EHCI_DEVNO
1635 pci_dev_t pdev;
1636#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001637 int timeout = 30;
1638 int smm_timeout = 50; /* 0,5 sec */
1639
1640 dbg("%s\n", __FUNCTION__);
1641
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +02001642#ifdef CONFIG_PCI_EHCI_DEVNO
1643 /*
1644 * Some multi-function controllers (e.g. ISP1562) allow root hub
1645 * resetting via EHCI registers only.
1646 */
1647 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVNO);
1648 if (pdev != -1) {
1649 u32 base;
1650 int timeout = 1000;
1651
1652 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base);
Becky Brucea5496a12010-06-30 13:05:44 -05001653 base += EHCI_USBCMD_OFF;
1654 ohci_writel(ohci_readl(base) | EHCI_USBCMD_HCRESET, base);
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +02001655
Becky Brucea5496a12010-06-30 13:05:44 -05001656 while (ohci_readl(base) & EHCI_USBCMD_HCRESET) {
Yuri Tikhonove90fb6a2008-09-04 11:19:05 +02001657 if (timeout-- <= 0) {
1658 printf("USB RootHub reset timed out!");
1659 break;
1660 }
1661 udelay(1);
1662 }
1663 } else
1664 printf("No EHCI func at %d index!\n", CONFIG_PCI_EHCI_DEVNO);
1665#endif
Becky Brucea5496a12010-06-30 13:05:44 -05001666 if (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) {
1667 /* SMM owns the HC, request ownership */
1668 ohci_writel(OHCI_OCR, &ohci->regs->cmdstatus);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001669 info("USB HC TakeOver from SMM");
Becky Brucea5496a12010-06-30 13:05:44 -05001670 while (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) {
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001671 mdelay(10);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001672 if (--smm_timeout == 0) {
1673 err("USB HC TakeOver failed!");
1674 return -1;
1675 }
1676 }
1677 }
1678
1679 /* Disable HC interrupts */
Becky Brucea5496a12010-06-30 13:05:44 -05001680 ohci_writel(OHCI_INTR_MIE, &ohci->regs->intrdisable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001681
1682 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n",
1683 ohci->slot_name,
Becky Brucea5496a12010-06-30 13:05:44 -05001684 ohci_readl(&ohci->regs->control));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001685
1686 /* Reset USB (needed by some controllers) */
Markus Klotzbuecher53e336e2006-11-27 11:43:09 +01001687 ohci->hc_control = 0;
Becky Brucea5496a12010-06-30 13:05:44 -05001688 ohci_writel(ohci->hc_control, &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001689
1690 /* HC Reset requires max 10 us delay */
Becky Brucea5496a12010-06-30 13:05:44 -05001691 ohci_writel(OHCI_HCR, &ohci->regs->cmdstatus);
1692 while ((ohci_readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001693 if (--timeout == 0) {
1694 err("USB HC reset timed out!");
1695 return -1;
1696 }
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001697 udelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001698 }
1699 return 0;
1700}
1701
1702/*-------------------------------------------------------------------------*/
1703
1704/* Start an OHCI controller, set the BUS operational
1705 * enable interrupts
1706 * connect the virtual root hub */
1707
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001708static int hc_start(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001709{
1710 __u32 mask;
1711 unsigned int fminterval;
1712
1713 ohci->disabled = 1;
1714
1715 /* Tell the controller where the control and bulk lists are
1716 * The lists are empty now. */
1717
Becky Brucea5496a12010-06-30 13:05:44 -05001718 ohci_writel(0, &ohci->regs->ed_controlhead);
1719 ohci_writel(0, &ohci->regs->ed_bulkhead);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001720
Becky Brucea5496a12010-06-30 13:05:44 -05001721 ohci_writel((__u32)ohci->hcca,
1722 &ohci->regs->hcca); /* reset clears this */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001723
1724 fminterval = 0x2edf;
Becky Brucea5496a12010-06-30 13:05:44 -05001725 ohci_writel((fminterval * 9) / 10, &ohci->regs->periodicstart);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001726 fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
Becky Brucea5496a12010-06-30 13:05:44 -05001727 ohci_writel(fminterval, &ohci->regs->fminterval);
1728 ohci_writel(0x628, &ohci->regs->lsthresh);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001729
1730 /* start controller operations */
1731 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
1732 ohci->disabled = 0;
Becky Brucea5496a12010-06-30 13:05:44 -05001733 ohci_writel(ohci->hc_control, &ohci->regs->control);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001734
1735 /* disable all interrupts */
1736 mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
1737 OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
1738 OHCI_INTR_OC | OHCI_INTR_MIE);
Becky Brucea5496a12010-06-30 13:05:44 -05001739 ohci_writel(mask, &ohci->regs->intrdisable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001740 /* clear all interrupts */
1741 mask &= ~OHCI_INTR_MIE;
Becky Brucea5496a12010-06-30 13:05:44 -05001742 ohci_writel(mask, &ohci->regs->intrstatus);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001743 /* Choose the interrupts we care about now - but w/o MIE */
1744 mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
Becky Brucea5496a12010-06-30 13:05:44 -05001745 ohci_writel(mask, &ohci->regs->intrenable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001746
1747#ifdef OHCI_USE_NPS
1748 /* required for AMD-756 and some Mac platforms */
Becky Brucea5496a12010-06-30 13:05:44 -05001749 ohci_writel((roothub_a(ohci) | RH_A_NPS) & ~RH_A_PSM,
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001750 &ohci->regs->roothub.a);
Becky Brucea5496a12010-06-30 13:05:44 -05001751 ohci_writel(RH_HS_LPSC, &ohci->regs->roothub.status);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001752#endif /* OHCI_USE_NPS */
1753
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001754 /* POTPGT delay is bits 24-31, in 2 ms units. */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001755 mdelay((roothub_a(ohci) >> 23) & 0x1fe);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001756
1757 /* connect the virtual root hub */
1758 ohci->rh.devnum = 0;
1759
1760 return 0;
1761}
1762
1763/*-------------------------------------------------------------------------*/
1764
1765/* an interrupt happens */
1766
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001767static int hc_interrupt(void)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001768{
1769 ohci_t *ohci = &gohci;
1770 struct ohci_regs *regs = ohci->regs;
1771 int ints;
1772 int stat = -1;
1773
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001774 if ((ohci->hcca->done_head != 0) &&
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001775 !(m32_swap(ohci->hcca->done_head) & 0x01)) {
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001776 ints = OHCI_INTR_WDH;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001777 } else {
Becky Brucea5496a12010-06-30 13:05:44 -05001778 ints = ohci_readl(&regs->intrstatus);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001779 if (ints == ~(u32)0) {
1780 ohci->disabled++;
1781 err("%s device removed!", ohci->slot_name);
1782 return -1;
1783 } else {
Becky Brucea5496a12010-06-30 13:05:44 -05001784 ints &= ohci_readl(&regs->intrenable);
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001785 if (ints == 0) {
1786 dbg("hc_interrupt: returning..\n");
1787 return 0xff;
1788 }
1789 }
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001790 }
Markus Klotzbuecherae79f602007-03-26 11:21:05 +02001791
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001792 /* dbg("Interrupt: %x frame: %x", ints,
1793 le16_to_cpu(ohci->hcca->frame_no)); */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001794
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001795 if (ints & OHCI_INTR_RHSC)
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001796 stat = 0xff;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001797
1798 if (ints & OHCI_INTR_UE) {
1799 ohci->disabled++;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001800 err("OHCI Unrecoverable Error, controller usb-%s disabled",
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001801 ohci->slot_name);
1802 /* e.g. due to PCI Master/Target Abort */
1803
1804#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001805 ohci_dump(ohci, 1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001806#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001807 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001808#endif
1809 /* FIXME: be optimistic, hope that bug won't repeat often. */
1810 /* Make some non-interrupt context restart the controller. */
1811 /* Count and limit the retries though; either hardware or */
1812 /* software errors can go forever... */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001813 hc_reset(ohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001814 return -1;
1815 }
1816
1817 if (ints & OHCI_INTR_WDH) {
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001818 mdelay(1);
Becky Brucea5496a12010-06-30 13:05:44 -05001819 ohci_writel(OHCI_INTR_WDH, &regs->intrdisable);
1820 (void)ohci_readl(&regs->intrdisable); /* flush */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001821 stat = dl_done_list(&gohci);
Becky Brucea5496a12010-06-30 13:05:44 -05001822 ohci_writel(OHCI_INTR_WDH, &regs->intrenable);
1823 (void)ohci_readl(&regs->intrdisable); /* flush */
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001824 }
1825
1826 if (ints & OHCI_INTR_SO) {
1827 dbg("USB Schedule overrun\n");
Becky Brucea5496a12010-06-30 13:05:44 -05001828 ohci_writel(OHCI_INTR_SO, &regs->intrenable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001829 stat = -1;
1830 }
1831
1832 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1833 if (ints & OHCI_INTR_SF) {
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001834 unsigned int frame = m16_swap(ohci->hcca->frame_no) & 1;
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001835 mdelay(1);
Becky Brucea5496a12010-06-30 13:05:44 -05001836 ohci_writel(OHCI_INTR_SF, &regs->intrdisable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001837 if (ohci->ed_rm_list[frame] != NULL)
Becky Brucea5496a12010-06-30 13:05:44 -05001838 ohci_writel(OHCI_INTR_SF, &regs->intrenable);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001839 stat = 0xff;
1840 }
1841
Becky Brucea5496a12010-06-30 13:05:44 -05001842 ohci_writel(ints, &regs->intrstatus);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001843 return stat;
1844}
1845
1846/*-------------------------------------------------------------------------*/
1847
1848/*-------------------------------------------------------------------------*/
1849
1850/* De-allocate all resources.. */
1851
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001852static void hc_release_ohci(ohci_t *ohci)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001853{
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001854 dbg("USB HC release ohci usb-%s", ohci->slot_name);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001855
1856 if (!ohci->disabled)
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001857 hc_reset(ohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001858}
1859
1860/*-------------------------------------------------------------------------*/
1861
1862/*
1863 * low level initalisation routine, called from usb.c
1864 */
1865static char ohci_inited = 0;
1866
Lucas Stachc7e3b2b2012-09-26 00:14:34 +02001867int usb_lowlevel_init(int index, void **controller)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001868{
Zhang Wei4dae14c2007-06-06 10:08:14 +02001869#ifdef CONFIG_PCI_OHCI
1870 pci_dev_t pdev;
1871#endif
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001872
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001873#ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001874 /* cpu dependant init */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001875 if (usb_cpu_init())
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001876 return -1;
1877#endif
1878
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001879#ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001880 /* board dependant init */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001881 if (usb_board_init())
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001882 return -1;
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001883#endif
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001884 memset(&gohci, 0, sizeof(ohci_t));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001885
1886 /* align the storage */
1887 if ((__u32)&ghcca[0] & 0xff) {
1888 err("HCCA not aligned!!");
1889 return -1;
1890 }
1891 phcca = &ghcca[0];
1892 info("aligned ghcca %p", phcca);
1893 memset(&ohci_dev, 0, sizeof(struct ohci_device));
1894 if ((__u32)&ohci_dev.ed[0] & 0x7) {
1895 err("EDs not aligned!!");
1896 return -1;
1897 }
1898 memset(gtd, 0, sizeof(td_t) * (NUM_TD + 1));
1899 if ((__u32)gtd & 0x7) {
1900 err("TDs not aligned!!");
1901 return -1;
1902 }
1903 ptd = gtd;
1904 gohci.hcca = phcca;
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001905 memset(phcca, 0, sizeof(struct ohci_hcca));
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001906
1907 gohci.disabled = 1;
1908 gohci.sleeping = 0;
1909 gohci.irq = -1;
Zhang Wei4dae14c2007-06-06 10:08:14 +02001910#ifdef CONFIG_PCI_OHCI
Sergei Poselenov477434c2008-05-22 01:15:53 +02001911 pdev = pci_find_devices(ohci_pci_ids, CONFIG_PCI_OHCI_DEVNO);
Zhang Wei4dae14c2007-06-06 10:08:14 +02001912
1913 if (pdev != -1) {
1914 u16 vid, did;
1915 u32 base;
1916 pci_read_config_word(pdev, PCI_VENDOR_ID, &vid);
1917 pci_read_config_word(pdev, PCI_DEVICE_ID, &did);
1918 printf("OHCI pci controller (%04x, %04x) found @(%d:%d:%d)\n",
1919 vid, did, (pdev >> 16) & 0xff,
1920 (pdev >> 11) & 0x1f, (pdev >> 8) & 0x7);
1921 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base);
1922 printf("OHCI regs address 0x%08x\n", base);
1923 gohci.regs = (struct ohci_regs *)base;
1924 } else
1925 return -1;
1926#else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001927 gohci.regs = (struct ohci_regs *)CONFIG_SYS_USB_OHCI_REGS_BASE;
Zhang Wei4dae14c2007-06-06 10:08:14 +02001928#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001929
1930 gohci.flags = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001931 gohci.slot_name = CONFIG_SYS_USB_OHCI_SLOT_NAME;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001932
1933 if (hc_reset (&gohci) < 0) {
1934 hc_release_ohci (&gohci);
1935 err ("can't reset usb-%s", gohci.slot_name);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001936#ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001937 /* board dependant cleanup */
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001938 usb_board_init_fail();
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001939#endif
1940
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001941#ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001942 /* cpu dependant cleanup */
Markus Klotzbuecherddf83a22006-05-30 16:56:14 +02001943 usb_cpu_init_fail();
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001944#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001945 return -1;
1946 }
1947
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001948 if (hc_start(&gohci) < 0) {
1949 err("can't start usb-%s", gohci.slot_name);
1950 hc_release_ohci(&gohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001951 /* Initialization failed */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001952#ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001953 /* board dependant cleanup */
1954 usb_board_stop();
1955#endif
1956
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001957#ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001958 /* cpu dependant cleanup */
1959 usb_cpu_stop();
1960#endif
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001961 return -1;
1962 }
1963
1964#ifdef DEBUG
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001965 ohci_dump(&gohci, 1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001966#else
Mike Frysinger5b84dd62012-03-05 13:47:00 +00001967 mdelay(1);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001968#endif
1969 ohci_inited = 1;
1970 return 0;
1971}
1972
Lucas Stachc7e3b2b2012-09-26 00:14:34 +02001973int usb_lowlevel_stop(int index)
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001974{
1975 /* this gets called really early - before the controller has */
1976 /* even been initialized! */
1977 if (!ohci_inited)
1978 return 0;
1979 /* TODO release any interrupts, etc. */
1980 /* call hc_release_ohci() here ? */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001981 hc_reset(&gohci);
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001982
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001983#ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001984 /* board dependant cleanup */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001985 if (usb_board_stop())
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001986 return -1;
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001987#endif
1988
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001989#ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001990 /* cpu dependant cleanup */
Remy Bohmer6f5794a2008-09-16 14:55:43 +02001991 if (usb_cpu_stop())
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02001992 return -1;
1993#endif
Remy Bohmereba1f2f2008-08-20 11:22:02 +02001994 /* This driver is no longer initialised. It needs a new low-level
1995 * init (board/cpu) before it can be used again. */
1996 ohci_inited = 0;
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001997 return 0;
1998}