1 /*
2 * Enhanced Host Controller Interface (EHCI) driver for USB.
3 *
4 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
5 *
6 * Copyright (c) 2000-2004 by David Brownell
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <stdint.h>
24 #include <stdio.h>
25 #include <hal_osal.h>
26 //#include <aw_types.h>
27 #include <aw_list.h>
28 #include <interrupt.h>
29 #include <usb_gen_hub.h>
30 #include <sunxi_hal_common.h>
31
32 #include "ehci.h"
33
34 /*-------------------------------------------------------------------------*/
35
36 /*
37 * EHCI hc_driver implementation ... experimental, incomplete.
38 * Based on the final 1.0 register interface specification.
39 *
40 * USB 2.0 shows up in upcoming www.pcmcia.org technology.
41 * First was PCMCIA, like ISA; then CardBus, which is PCI.
42 * Next comes "CardBay", using USB 2.0 signals.
43 *
44 * Contains additional contributions by Brad Hards, Rory Bolt, and others.
45 * Special thanks to Intel and VIA for providing host controllers to
46 * test this driver on, and Cypress (including In-System Design) for
47 * providing early devices for those host controllers to talk to!
48 */
49
50 #define DRIVER_AUTHOR "David Brownell"
51 #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
52
53 static const char hcd_name [] = "ehci_hcd";
54 uint32_t le32_to_cpu(uint32_t x);
55
56
57 #undef EHCI_URB_TRACE
58
59 /* magic numbers that can affect system performance */
60 #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
61 #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
62 #define EHCI_TUNE_RL_TT 0
63 #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
64 #define EHCI_TUNE_MULT_TT 1
65 /*
66 * Some drivers think it's safe to schedule isochronous transfers more than
67 * 256 ms into the future (partly as a result of an old bug in the scheduling
68 * code). In an attempt to avoid trouble, we will use a minimum scheduling
69 * length of 512 frames instead of 256.
70 */
71 #define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
72
73 /* Initial IRQ latency: faster than hw default */
74 static int log2_irq_thresh = 0; // 0 to 6
75 //module_param (log2_irq_thresh, int, S_IRUGO);
76 //MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
77
78 /* initial park setting: slower than hw default */
79 static unsigned park = 0;
80 //module_param (park, uint, S_IRUGO);
81 //MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
82
83 /* for flakey hardware, ignore overcurrent indicators */
84 //static bool ignore_oc;
85 //module_param (ignore_oc, bool, S_IRUGO);
86 //MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
87
88 //#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
89
90 /*-------------------------------------------------------------------------*/
91
92 #include "ehci.h"
93 //#include "pci-quirks.h"
94
95 static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
96 struct ehci_tt *tt);
97
98 /*
99 * The MosChip MCS9990 controller updates its microframe counter
100 * a little before the frame counter, and occasionally we will read
101 * the invalid intermediate value. Avoid problems by checking the
102 * microframe number (the low-order 3 bits); if they are 0 then
103 * re-read the register to get the correct value.
104 */
ehci_moschip_read_frame_index(struct ehci_hcd * ehci)105 static unsigned ehci_moschip_read_frame_index(struct ehci_hcd *ehci)
106 {
107 unsigned uf;
108
109 uf = ehci_readl(ehci, &ehci->regs->frame_index);
110 if (unlikely((uf & 7) == 0))
111 uf = ehci_readl(ehci, &ehci->regs->frame_index);
112 return uf;
113 }
114
ehci_read_frame_index(struct ehci_hcd * ehci)115 static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci)
116 {
117 if (ehci->frame_index_bug)
118 return ehci_moschip_read_frame_index(ehci);
119 return ehci_readl(ehci, &ehci->regs->frame_index);
120 }
121
122 //#include "ehci-dbg.c"
123
124 /*-------------------------------------------------------------------------*/
125
126 /*
127 * ehci_handshake - spin reading hc until handshake completes or fails
128 * @ptr: address of hc register to be read
129 * @mask: bits to look at in result of read
130 * @done: value of those bits when handshake succeeds
131 * @usec: timeout in microseconds
132 *
133 * Returns negative errno, or zero on success
134 *
135 * Success happens when the "mask" bits have the specified value (hardware
136 * handshake done). There are two failure modes: "usec" have passed (major
137 * hardware flakeout), or the register reads as all-ones (hardware removed).
138 *
139 * That last failure should_only happen in cases like physical cardbus eject
140 * before driver shutdown. But it also seems to be caused by bugs in cardbus
141 * bridge shutdown: shutting down the bridge before the devices using it.
142 */
ehci_handshake(struct ehci_hcd * ehci,u32 * ptr,u32 mask,u32 done,int usec)143 int ehci_handshake(struct ehci_hcd *ehci, u32 *ptr,
144 u32 mask, u32 done, int usec)
145 {
146 u32 result;
147
148 do {
149 result = ehci_readl(ehci, ptr);
150 if (result == ~(u32)0) /* card removed */
151 return -ENODEV;
152 result &= mask;
153 if (result == done)
154 return 0;
155 udelay (1);
156 usec--;
157 } while (usec > 0);
158 return -ETIMEDOUT;
159 }
160
161 /* check TDI/ARC silicon is in host mode */
tdi_in_host_mode(struct ehci_hcd * ehci)162 static int tdi_in_host_mode (struct ehci_hcd *ehci)
163 {
164 u32 tmp;
165
166 tmp = ehci_readl(ehci, &ehci->regs->usbmode);
167 return (tmp & 3) == USBMODE_CM_HC;
168 }
169
170 /*
171 * Force HC to halt state from unknown (EHCI spec section 2.3).
172 * Must be called with interrupts enabled and the lock not held.
173 */
ehci_halt(struct ehci_hcd * ehci)174 int ehci_halt (struct ehci_hcd *ehci)
175 {
176 u32 temp;
177 uint32_t cpusr;
178
179 hal_spin_lock(&ehci->lock);
180
181 /* disable any irqs left enabled by previous code */
182 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
183
184 //if (ehci_is_TDI(ehci) && !tdi_in_host_mode(ehci)) {
185 // hal_spin_unlock_irqrestore(cpusr);
186 // return 0;
187 //}
188
189 /*
190 * This routine gets called during probe before ehci->command
191 * has been initialized, so we can't rely on its value.
192 */
193 ehci->command &= ~CMD_RUN;
194 temp = ehci_readl(ehci, &ehci->regs->command);
195 temp &= ~(CMD_RUN | CMD_IAAD);
196 ehci_writel(ehci, temp, &ehci->regs->command);
197
198 hal_spin_unlock(&ehci->lock);
199 //synchronize_irq(ehci_to_hcd(ehci)->irq);
200
201 return ehci_handshake(ehci, &ehci->regs->status,
202 STS_HALT, STS_HALT, 16 * 125);
203 }
204
205 /* put TDI/ARC silicon into EHCI mode */
tdi_reset(struct ehci_hcd * ehci)206 static void tdi_reset (struct ehci_hcd *ehci)
207 {
208 u32 tmp;
209
210 tmp = ehci_readl(ehci, &ehci->regs->usbmode);
211 tmp |= USBMODE_CM_HC;
212 /* The default byte access to MMR space is LE after
213 * controller reset. Set the required endian mode
214 * for transfer buffers to match the host microprocessor
215 */
216 if (ehci_big_endian_mmio(ehci))
217 tmp |= USBMODE_BE;
218 ehci_writel(ehci, tmp, &ehci->regs->usbmode);
219 }
220
221 /*
222 * Reset a non-running (STS_HALT == 1) controller.
223 * Must be called with interrupts enabled and the lock not held.
224 */
ehci_reset(struct ehci_hcd * ehci)225 int ehci_reset(struct ehci_hcd *ehci)
226 {
227 int retval;
228 u32 command = ehci_readl(ehci, &ehci->regs->command);
229
230 command |= CMD_RESET;
231 //dbg_cmd (ehci, "reset", command);
232 ehci_writel(ehci, command, &ehci->regs->command);
233 ehci->rh_state = EHCI_RH_HALTED;
234 //ehci->next_statechange = jiffies;
235 retval = ehci_handshake(ehci, &ehci->regs->command,
236 CMD_RESET, 0, 250 * 1000);
237
238 if (ehci->has_hostpc) {
239 ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
240 &ehci->regs->usbmode_ex);
241 ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
242 }
243 if (retval)
244 return retval;
245
246 //if (ehci_is_TDI(ehci))
247 // tdi_reset (ehci);
248
249 ehci->port_c_suspend = ehci->suspended_ports =
250 ehci->resuming_ports = 0;
251 return retval;
252 }
253
254 /*
255 * Idle the controller (turn off the schedules).
256 * Must be called with interrupts enabled and the lock not held.
257 */
ehci_quiesce(struct ehci_hcd * ehci)258 static void ehci_quiesce (struct ehci_hcd *ehci)
259 {
260 u32 temp;
261 uint32_t cpusr;
262
263 if (ehci->rh_state != EHCI_RH_RUNNING)
264 return;
265
266 /* wait for any schedule enables/disables to take effect */
267 temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
268 ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp,
269 16 * 125);
270
271 /* then disable anything that's still active */
272 hal_spin_lock(&ehci->lock);
273 ehci->command &= ~(CMD_ASE | CMD_PSE);
274 ehci_writel(ehci, ehci->command, &ehci->regs->command);
275 hal_spin_unlock(&ehci->lock);
276
277 /* hardware can take 16 microframes to turn off ... */
278 ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0,
279 16 * 125);
280 }
281
282 /*-------------------------------------------------------------------------*/
283
284 static void end_iaa_cycle(struct ehci_hcd *ehci);
285 static void end_unlink_async(struct ehci_hcd *ehci);
286 static void unlink_empty_async(struct ehci_hcd *ehci);
287 void ehci_work(struct ehci_hcd *ehci);
288 static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
289 static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
290 static int ehci_port_power(struct ehci_hcd *ehci, int portnum, bool enable);
291
292 #define EHCI_QH_COMPLETIONS_DEBUG 0
293 #if EHCI_QH_COMPLETIONS_DEBUG
294 #define EHCI_DEBUG_PRINTF(format, args...) \
295 printf("[%s:%d] " format "\n", __func__, __LINE__, ##args)
296 #else
297 #define EHCI_DEBUG_PRINTF(...)
298 #endif
299
300 #include "ehci-timer.c"
301 #include "ehci-hub.c"
302 #include "ehci-mem.c"
303 #include "ehci-q.c"
304 #include "ehci-sched.c"
305 //#include "ehci-sysfs.c"
306
307 /*-------------------------------------------------------------------------*/
308
309 /* On some systems, leaving remote wakeup enabled prevents system shutdown.
310 * The firmware seems to think that powering off is a wakeup event!
311 * This routine turns off remote wakeup and everything else, on all ports.
312 */
ehci_turn_off_all_ports(struct ehci_hcd * ehci)313 static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
314 {
315 int port = HCS_N_PORTS(ehci->hcs_params);
316
317 while (port--) {
318 hal_spin_unlock(&ehci->lock);
319 ehci_port_power(ehci, port, false);
320 hal_spin_lock(&ehci->lock);
321 ehci_writel(ehci, PORT_RWC_BITS,
322 &ehci->regs->port_status[port]);
323 }
324 }
325
326 /*
327 * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
328 * Must be called with interrupts enabled and the lock not held.
329 */
ehci_silence_controller(struct ehci_hcd * ehci)330 static void ehci_silence_controller(struct ehci_hcd *ehci)
331 {
332 ehci_halt(ehci);
333
334 hal_spin_lock(&ehci->lock);
335 ehci->rh_state = EHCI_RH_HALTED;
336 ehci_turn_off_all_ports(ehci);
337
338 /* make BIOS/etc use companion controller during reboot */
339 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
340
341 /* unblock posted writes */
342 ehci_readl(ehci, &ehci->regs->configured_flag);
343 hal_spin_unlock(&ehci->lock);
344 }
345
346 /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
347 * This forcibly disables dma and IRQs, helping kexec and other cases
348 * where the next system software may expect clean state.
349 */
ehci_shutdown(struct hc_gen_dev * hcd)350 static void ehci_shutdown(struct hc_gen_dev *hcd)
351 {
352 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
353
354 /**
355 * Protect the system from crashing at system shutdown in cases where
356 * usb host is not added yet from OTG controller driver.
357 * As ehci_setup() not done yet, so stop accessing registers or
358 * variables initialized in ehci_setup()
359 */
360 if (!ehci->sbrn)
361 return;
362
363 hal_spin_lock(&ehci->lock);
364 ehci->shutdown = true;
365 ehci->rh_state = EHCI_RH_STOPPING;
366 ehci->enabled_hrtimer_events = 0;
367 hal_spin_unlock(&ehci->lock);
368
369 ehci_silence_controller(ehci);
370
371 osal_timer_stop(ehci->hrtimer);
372 }
373
374 /*-------------------------------------------------------------------------*/
375
376 /*
377 * ehci_work is called from some interrupts, timers, and so on.
378 * it calls driver completion functions, after dropping ehci->lock.
379 */
ehci_work(struct ehci_hcd * ehci)380 void ehci_work (struct ehci_hcd *ehci)
381 {
382 /* another CPU may drop ehci->lock during a schedule scan while
383 * it reports urb completions. this flag guards against bogus
384 * attempts at re-entrant schedule scanning.
385 */
386 EHCI_DEBUG_PRINTF("ehci->scanning = %d, ehci->async_count = %u, ehci->intr_count = %u, ehci->isoc_count = %u",
387 ehci->scanning, ehci->async_count, ehci->intr_count, ehci->isoc_count);
388
389 if (ehci->scanning) {
390 ehci->need_rescan = true;
391 return;
392 }
393 ehci->scanning = true;
394
395 rescan:
396 ehci->need_rescan = false;
397 if (ehci->async_count)
398 scan_async(ehci);
399 if (ehci->intr_count > 0)
400 scan_intr(ehci);
401 if (ehci->isoc_count > 0)
402 scan_isoc(ehci);
403 if (ehci->need_rescan)
404 goto rescan;
405 ehci->scanning = false;
406
407 /* the IO watchdog guards against hardware or driver bugs that
408 * misplace IRQs, and should let us run completely without IRQs.
409 * such lossage has been observed on both VT6202 and VT8235.
410 */
411 turn_on_io_watchdog(ehci);
412 }
413
414 /*
415 * Called when the ehci_hcd module is removed.
416 */
ehci_stop(struct hc_gen_dev * hcd)417 void ehci_stop (struct hc_gen_dev *hcd)
418 {
419 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
420
421 ehci_dbg ("ehci stop\n");
422
423 /* no more interrupts ... */
424
425 //spin_lock_irq(&ehci->lock);
426 hal_spin_lock (&ehci->lock);
427 ehci->enabled_hrtimer_events = 0;
428 hal_spin_unlock (&ehci->lock);
429 //spin_unlock_irq(&ehci->lock);
430
431 ehci_quiesce(ehci);
432 ehci_silence_controller(ehci);
433 ehci_reset (ehci);
434
435 osal_timer_stop(ehci->hrtimer);
436 //hrtimer_cancel(&ehci->hrtimer);
437 //remove_sysfs_files(ehci);
438 //remove_debug_files (ehci);
439
440 /* root hub is shut down separately (first, when possible) */
441 hal_spin_lock (&ehci->lock);
442 end_free_itds(ehci);
443 hal_spin_unlock (&ehci->lock);
444 ehci_mem_cleanup (ehci);
445
446 //if (ehci->amd_pll_fix == 1)
447 // usb_amd_dev_put();
448
449 //dbg_status (ehci, "ehci_stop completed",
450 // ehci_readl(ehci, &ehci->regs->status));
451 }
452
453 /* one-time init, only for memory state */
454 //static int ehci_init(struct usb_hcd *hcd)
ehci_init(struct hc_gen_dev * hcd)455 int ehci_init(struct hc_gen_dev *hcd)
456 {
457 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
458 u32 temp;
459 int retval;
460 u32 hcc_params;
461 struct ehci_qh_hw *hw;
462
463 //spin_lock_init(&ehci->lock);
464
465 /*
466 * keep io watchdog by default, those good HCDs could turn off it later
467 */
468 //ehci->need_io_watchdog = 1;
469
470 //hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
471 //ehci->hrtimer.function = ehci_hrtimer_func;
472 //ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
473 ehci->hrtimer = osal_timer_create("hcd_hrtimer", ehci_hrtimer_func, (void*)ehci,
474 1, OSAL_TIMER_FLAG_ONE_SHOT);
475
476 if (ehci->hrtimer == NULL)
477 {
478 hal_log_err("PANIC : create timer fail");
479 }
480 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
481
482 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
483
484 /*
485 * by default set standard 80% (== 100 usec/uframe) max periodic
486 * bandwidth as required by USB 2.0
487 */
488 ehci->uframe_periodic_max = 100;
489
490 /*
491 * hw default: 1K periodic list heads, one per frame.
492 * periodic_size can shrink by USBCMD update if hcc_params allows.
493 */
494 ehci->periodic_size = DEFAULT_I_TDPS;
495 INIT_LIST_HEAD(&ehci->async_unlink);
496 INIT_LIST_HEAD(&ehci->async_idle);
497 INIT_LIST_HEAD(&ehci->intr_unlink_wait);
498 INIT_LIST_HEAD(&ehci->intr_unlink);
499 INIT_LIST_HEAD(&ehci->intr_qh_list);
500 INIT_LIST_HEAD(&ehci->cached_itd_list);
501 INIT_LIST_HEAD(&ehci->cached_sitd_list);
502 INIT_LIST_HEAD(&ehci->tt_list);
503 INIT_LIST_HEAD(&ehci->wait_free_list);
504
505 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
506 /* periodic schedule size can be smaller than default */
507 switch (EHCI_TUNE_FLS) {
508 case 0: ehci->periodic_size = 1024; break;
509 case 1: ehci->periodic_size = 512; break;
510 case 2: ehci->periodic_size = 256; break;
511 default: ; //BUG();
512 }
513 }
514 if ((retval = ehci_mem_init(ehci)) < 0)
515 return retval;
516
517 /* controllers may cache some of the periodic schedule ... */
518 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
519 ehci->i_thresh = 0;
520 else // N microframes cached
521 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
522
523 /*
524 * dedicate a qh for the async ring head, since we couldn't unlink
525 * a 'real' qh without stopping the async schedule [4.8]. use it
526 * as the 'reclamation list head' too.
527 * its dummy is used in hw_alt_next of many tds, to prevent the qh
528 * from automatically advancing to the next td after short reads.
529 */
530 ehci->async->qh_next.qh = NULL;
531 hw = ehci->async->hw;
532 hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
533 //hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
534 //hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
535 hw->hw_info1 = QH_HEAD;
536 hw->hw_token = QTD_STS_HALT;
537 hw->hw_qtd_next = EHCI_LIST_END(ehci);
538 ehci->async->qh_state = QH_STATE_LINKED;
539 //hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
540
541 /* clear interrupt enables, set irq latency */
542 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
543 log2_irq_thresh = 0;
544 temp = 1 << (16 + log2_irq_thresh);
545 if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
546 ehci->has_ppcd = 1;
547 ehci_dbg("enable per-port change event\n");
548 temp |= CMD_PPCEE;
549 }
550 if (HCC_CANPARK(hcc_params)) {
551 /* HW default park == 3, on hardware that supports it (like
552 * NVidia and ALI silicon), maximizes throughput on the async
553 * schedule by avoiding QH fetches between transfers.
554 *
555 * With fast usb storage devices and NForce2, "park" seems to
556 * make problems: throughput reduction (!), data errors...
557 */
558 if (park) {
559 park = min(park, (unsigned) 3);
560 temp |= CMD_PARK;
561 temp |= park << 8;
562 }
563 ehci_dbg("park %d\n", park);
564 }
565 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
566 /* periodic schedule size can be smaller than default */
567 temp &= ~(3 << 2);
568 temp |= (EHCI_TUNE_FLS << 2);
569 }
570 ehci->command = temp;
571 /* Accept arbitrarily long scatter-gather lists */
572 //if (!(hcd->driver->flags & HCD_LOCAL_MEM))
573 // hcd->self.sg_tablesize = ~0;
574
575 /* Prepare for unlinking active QHs */
576 ehci->old_current = ~0;
577 return 0;
578 }
579
580 /* start HC running; it's halted, ehci_init() has been run (once) */
ehci_run(struct hc_gen_dev * hcd)581 int ehci_run (struct hc_gen_dev *hcd)
582 {
583 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
584 u32 temp;
585 u32 hcc_params;
586
587 hcd->uses_new_polling = 1;
588
589 /* EHCI spec section 4.1 */
590
591 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
592 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
593
594 /*
595 * hcc_params controls whether ehci->regs->segment must (!!!)
596 * be used; it constrains QH/ITD/SITD and QTD locations.
597 * pci_pool consistent memory always uses segment zero.
598 * streaming mappings for I/O buffers, like pci_map_single(),
599 * can return segments above 4GB, if the device allows.
600 *
601 * NOTE: the dma mask is visible through dev->dma_mask, so
602 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
603 * Scsi_Host.highmem_io, and so forth. It's readonly to all
604 * host side drivers though.
605 */
606 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
607 if (HCC_64BIT_ADDR(hcc_params)) {
608 //#ifdef CONFIG_ARM64
609 // ehci_writel(ehci, ehci->periodic_dma >> 32,
610 // &ehci->regs->segment);
611 // /*
612 // * this is deeply broken on almost all architectures
613 // * but arm64 can use it so enable it
614 // */
615 // if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)))
616 // ehci_info(ehci, "enabled 64bit DMA\n");
617 //#else
618 ehci_writel(ehci, 0, &ehci->regs->segment);
619 //endif
620 }
621
622
623 // Philips, Intel, and maybe others need CMD_RUN before the
624 // root hub will detect new devices (why?); NEC doesn't
625 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
626 ehci->command |= CMD_RUN;
627 ehci_writel(ehci, ehci->command, &ehci->regs->command);
628 //dbg_cmd (ehci, "init", ehci->command);
629
630 /*
631 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
632 * are explicitly handed to companion controller(s), so no TT is
633 * involved with the root hub. (Except where one is integrated,
634 * and there's no companion controller unless maybe for USB OTG.)
635 *
636 * Turning on the CF flag will transfer ownership of all ports
637 * from the companions to the EHCI controller. If any of the
638 * companions are in the middle of a port reset at the time, it
639 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
640 * guarantees that no resets are in progress. After we set CF,
641 * a short delay lets the hardware catch up; new resets shouldn't
642 * be started before the port switching actions could complete.
643 */
644 //down_write(&ehci_cf_port_reset_rwsem);
645 ehci->rh_state = EHCI_RH_RUNNING;
646 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
647 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
648 hal_log_info("--ehci_run: cmd = 0x%x\n", ehci_readl(ehci, &ehci->regs->command));
649 hal_msleep(5);
650 //up_write(&ehci_cf_port_reset_rwsem);
651 //ehci->last_periodic_enable = ktime_get_real();
652
653 temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
654 //ehci_info ("USB %x.%x started, EHCI %x.%02x%s\n",
655 // ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
656 // temp >> 8, temp & 0xff,
657 // ignore_oc ? ", overcurrent ignored" : "");
658 hal_log_info("--ehci_run: hc_capbase = 0x%x\n", temp);
659 ehci_info ("USB %x.%x started, EHCI %x.%02x%s\n",
660 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
661 temp >> 8, temp & 0xff);
662
663 ehci_writel(ehci, INTR_MASK,
664 &ehci->regs->intr_enable); /* Turn On Interrupts */
665
666 /* GRR this is run-once init(), being done every time the HC starts.
667 * So long as they're part of class devices, we can't do it init()
668 * since the class device isn't created that early.
669 */
670 return 0;
671 }
672
ehci_setup(struct hc_gen_dev * hcd)673 int ehci_setup(struct hc_gen_dev *hcd)
674 {
675 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
676 int retval;
677
678 ehci->regs = (void *)ehci->caps +
679 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
680 //dbg_hcs_params(ehci, "reset");
681 //dbg_hcc_params(ehci, "reset");
682
683 /* cache this readonly data; minimize chip reads */
684 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
685
686 ehci->sbrn = 0x0020;//HCD_USB2;
687
688 /* data structure init */
689 retval = ehci_init(hcd);
690 if (retval)
691 return retval;
692
693 retval = ehci_halt(ehci);
694 if (retval) {
695 ehci_mem_cleanup(ehci);
696 return retval;
697 }
698
699 ehci_reset(ehci);
700
701 return 0;
702 }
703 //EXPORT_SYMBOL_GPL(ehci_setup);
704
705 /*-------------------------------------------------------------------------*/
706
707 //irqreturn_t ehci_irq (struct hc_gen_dev *hcd)
ehci_irq_handler(int dummy,void * dev)708 irqreturn_t ehci_irq_handler (int dummy, void *dev)
709 {
710 struct hc_gen_dev *hcd = (struct hc_gen_dev *)dev;
711 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
712 u32 status, masked_status, pcd_status = 0, cmd;
713 int bh;
714 unsigned long flags;
715
716 EHCI_DEBUG_PRINTF("");
717
718 /*
719 * For threadirqs option we use spin_lock_irqsave() variant to prevent
720 * deadlock with ehci hrtimer callback, because hrtimer callbacks run
721 * in interrupt context even when threadirqs is specified. We can go
722 * back to spin_lock() variant when hrtimer callbacks become threaded.
723 */
724 flags = hal_spin_lock_irqsave(&ehci->lock);
725 status = ehci_readl(ehci, &ehci->regs->status);
726
727 /* e.g. cardbus physical eject */
728 if (status == ~(u32) 0) {
729 printf("device removed\n");
730 goto dead;
731 }
732
733 /*
734 * We don't use STS_FLR, but some controllers don't like it to
735 * remain on, so mask it out along with the other status bits.
736 */
737 masked_status = status & (INTR_MASK | STS_FLR);
738
739 /* Shared IRQ? */
740 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
741 hal_spin_unlock_irqrestore(&ehci->lock, flags);
742 return IRQ_NONE;
743 }
744
745 /* clear (just) interrupts */
746 ehci_writel(ehci, masked_status, &ehci->regs->status);
747 cmd = ehci_readl(ehci, &ehci->regs->command);
748 bh = 0;
749
750 /* normal [4.15.1.2] or error [4.15.1.1] completion */
751 if (likely ((status & (STS_INT|STS_ERR)) != 0)) {
752 if (likely ((status & STS_ERR) == 0))
753 COUNT (ehci->stats.normal);
754 else {
755 COUNT (ehci->stats.error);
756 }
757 bh = 1;
758 }
759
760 /* complete the unlinking of some qh [4.15.2.3] */
761 if (status & STS_IAA) {
762
763 /* Turn off the IAA watchdog */
764 ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
765
766 /*
767 * Mild optimization: Allow another IAAD to reset the
768 * hrtimer, if one occurs before the next expiration.
769 * In theory we could always cancel the hrtimer, but
770 * tests show that about half the time it will be reset
771 * for some other event anyway.
772 */
773 if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
774 ++ehci->next_hrtimer_event;
775
776 /* guard against (alleged) silicon errata */
777 if (cmd & CMD_IAAD)
778 hal_log_info("IAA with IAAD still set?\n");
779 if (ehci->iaa_in_progress) {
780 COUNT(ehci->stats.iaa);
781 }
782
783 hal_log_info("\033[41m WARN : STS_IAA!!!! \033[0m");
784 // end_iaa_cycle(ehci);//for test
785 }
786
787 /* remote wakeup [4.3.1] */
788 if (status & STS_PCD) {
789 unsigned i = HCS_N_PORTS (ehci->hcs_params);
790 u32 ppcd = ~0;
791 {
792 int pstatus0 = 0;
793
794 pstatus0 = ehci_readl(ehci, &ehci->regs->port_status[0]);
795
796 if ((pstatus0 & PORT_CONNECT) && (pstatus0 & PORT_CSC))
797 printf("\nehci_irq: highspeed device connect \n\n");
798 else if (!(pstatus0 & PORT_CONNECT) && (pstatus0 & PORT_CSC))
799 printf("\nehci_irq: highspeed device disconnect \n\n");
800 }
801
802 /* kick root hub later */
803 pcd_status = status;
804
805 /* resume root hub? */
806 //if (ehci->rh_state == EHCI_RH_SUSPENDED)
807 // usb_hcd_resume_root_hub(hcd);
808
809 /* get per-port change detect bits */
810 if (ehci->has_ppcd)
811 ppcd = status >> 16;
812
813 while (i--) {
814 int pstatus;
815
816 /* leverage per-port change bits feature */
817 if (!(ppcd & (1 << i)))
818 continue;
819 pstatus = ehci_readl(ehci,
820 &ehci->regs->port_status[i]);
821
822 if (pstatus & PORT_OWNER)
823 continue;
824 if (!(usb_test_bit(i, (volatile uint32_t *)&ehci->suspended_ports) &&
825 ((pstatus & PORT_RESUME) ||
826 !(pstatus & PORT_SUSPEND)) &&
827 (pstatus & PORT_PE) &&
828 ehci->reset_done[i] == 0))
829 continue;
830
831 /* start USB_RESUME_TIMEOUT msec resume signaling from
832 * this port, and make hub_wq collect
833 * PORT_STAT_C_SUSPEND to stop that signaling.
834 */
835 //ehci->reset_done[i] = jiffies +
836 // msecs_to_jiffies(USB_RESUME_TIMEOUT);
837 //set_bit(i, &ehci->resuming_ports);
838 printf("port %d remote wakeup\n", i + 1);
839 usb_hcd_start_port_resume(&hcd->self, i);
840 //mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
841 }
842 }
843
844 /* PCI errors [4.15.2.4] */
845 if (unlikely ((status & STS_FATAL) != 0)) {
846 hal_log_err("fatal error\n");
847 //dbg_cmd(ehci, "fatal", cmd);
848 //dbg_status(ehci, "fatal", status);
849 dead:
850 //usb_hc_died(hcd);
851
852 /* Don't let the controller do anything more */
853 ehci->shutdown = true;
854 ehci->rh_state = EHCI_RH_STOPPING;
855 ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
856 ehci_writel(ehci, ehci->command, &ehci->regs->command);
857 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
858 ehci_handle_controller_death(ehci);
859
860 /* Handle completions when the controller stops */
861 bh = 0;
862 }
863
864 if (bh)
865 ehci_work (ehci);
866 hal_spin_unlock_irqrestore(&ehci->lock, flags);
867 if (pcd_status)
868 usb_hcd_poll_rh_status(hcd);
869 return IRQ_HANDLED;
870 }
871
872 /*-------------------------------------------------------------------------*/
873
874 /*
875 * non-error returns are a promise to giveback() the urb later
876 * we drop ownership so next owner (or urb unlink) can get it
877 *
878 * urb + dev is in hcd.self.controller.urb_list
879 * we're queueing TDs onto software and hardware lists
880 *
881 * hcd-specific init for hcpriv hasn't been done yet
882 *
883 * NOTE: control, bulk, and interrupt share the same code to append TDs
884 * to a (possibly active) QH, and the same QH scanning code.
885 */
886
887 // 从usb_submit_urb传下来的调用
888 // 实现了EHCI这一层上HCD(host controller driver)与硬件的读写接口
889 // 该函数被执行代表driver有数据要与usb交换(收或者发),driver的请求用urb传下来
890 // EHCI与CPU的数据交换方式是通过在内存中建立一块共享的内存区域,通过DMA的方式实现的
891 // 数据在usb设备和HC间传输不需要CPU的干预,但是需要CPU告诉HC共享区域的地址和长度信息(还有usb设备的信息)等
892 // 那么CPU就会把共享内存区域的地址、长度等信息构造成HC能识别的表(iTD,QH,qTD等描述符),再把这些表交给HC
893 // HC就会按这张表所记录的信息在指定的内存地址处进行数据的传输,传输完成后,以中断的方式通知CPU一次传输的完成
894
ehci_urb_enqueue(struct hc_gen_dev * hcd,struct urb * urb,unsigned mem_flags)895 int ehci_urb_enqueue (
896 struct hc_gen_dev *hcd,
897 struct urb *urb,
898 unsigned mem_flags
899 ) {
900 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
901 struct list_head qtd_list;
902
903 INIT_LIST_HEAD (&qtd_list);//用于管理EHCI中的qtd数据结构
904
905 switch (usb_pipetype (urb->pipe)) {
906 case PIPE_CONTROL:
907 /* qh_completions() code doesn't handle all the fault cases
908 * in multi-TD control transfers. Even 1KB is rare anyway.
909 */
910 if (urb->transfer_buffer_length > (16 * 1024))
911 return -EMSGSIZE;
912 /* FALLTHROUGH */
913 /* case PIPE_BULK: */
914 default:
915 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
916 return -ENOMEM;
917 return submit_async(ehci, urb, &qtd_list, mem_flags);
918
919 case PIPE_INTERRUPT:
920 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
921 return -ENOMEM;
922 return intr_submit(ehci, urb, &qtd_list, mem_flags);
923
924 case PIPE_ISOCHRONOUS:
925 if (urb->dev->speed == USB_SPEED_HIGH)
926 return itd_submit (ehci, urb, mem_flags);
927 else
928 return sitd_submit (ehci, urb, mem_flags);
929 }
930 }
931
932 /* remove from hardware lists
933 * completions normally happen asynchronously
934 */
ehci_urb_dequeue(struct hc_gen_dev * hcd,struct urb * urb)935 int ehci_urb_dequeue(struct hc_gen_dev *hcd, struct urb *urb)
936 {
937 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
938 struct ehci_qh *qh;
939 unsigned long flags;
940 int rc;
941
942 flags = hal_spin_lock_irqsave (&ehci->lock);
943 rc = usb_hcd_check_unlink_urb(hcd, urb);
944 if (rc)
945 goto done;
946
947 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
948 /*
949 * We don't expedite dequeue for isochronous URBs.
950 * Just wait until they complete normally or their
951 * time slot expires.
952 */
953 } else {
954 qh = (struct ehci_qh *) urb->hcpriv;
955 qh->unlink_reason |= QH_UNLINK_REQUESTED;
956 switch (qh->qh_state) {
957 case QH_STATE_LINKED:
958 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)
959 start_unlink_intr(ehci, qh);
960 else
961 start_unlink_async(ehci, qh);
962 break;
963 case QH_STATE_COMPLETING:
964 qh->dequeue_during_giveback = 1;
965 break;
966 case QH_STATE_UNLINK:
967 case QH_STATE_UNLINK_WAIT:
968 /* already started */
969 break;
970 case QH_STATE_IDLE:
971 /* QH might be waiting for a Clear-TT-Buffer */
972 qh_completions(ehci, qh);
973 break;
974 }
975 }
976 done:
977 hal_spin_unlock_irqrestore(&ehci->lock, flags);
978 return rc;
979 // return 0;
980 }
981
982 /*-------------------------------------------------------------------------*/
983
984 // bulk qh holds the data toggle
985
986 //ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
ehci_endpoint_disable(struct hc_gen_dev * hcd,struct usb_host_virt_endpoint * ep)987 void ehci_endpoint_disable (struct hc_gen_dev *hcd, struct usb_host_virt_endpoint *ep)
988 {
989 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
990 unsigned long flags;
991 struct ehci_qh *qh;
992
993 /* ASSERT: any requests/urbs are being unlinked */
994 /* ASSERT: nobody can be submitting urbs for this any more */
995
996 rescan:
997 flags = hal_spin_lock_irqsave (&ehci->lock);
998 qh = ep->hcpriv;
999 if (!qh)
1000 goto done;
1001
1002 /* endpoints can be iso streams. for now, we don't
1003 * accelerate iso completions ... so spin a while.
1004 */
1005 if (qh->hw == NULL) {
1006 struct ehci_iso_stream *stream = ep->hcpriv;
1007
1008 if (!list_empty(&stream->td_list))
1009 goto idle_timeout;
1010
1011 /* BUG_ON(!list_empty(&stream->free_list)); */
1012 reserve_release_iso_bandwidth(ehci, stream, -1);
1013 hal_free(stream);
1014 goto done;
1015 }
1016
1017 qh->unlink_reason |= QH_UNLINK_REQUESTED;
1018 switch (qh->qh_state) {
1019 case QH_STATE_LINKED:
1020 if (list_empty(&qh->qtd_list))
1021 qh->unlink_reason |= QH_UNLINK_QUEUE_EMPTY;
1022 //else
1023 // WARN_ON(1);
1024 if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_INT)
1025 start_unlink_async(ehci, qh);
1026 else
1027 start_unlink_intr(ehci, qh);
1028 /* FALL THROUGH */
1029 case QH_STATE_COMPLETING: /* already in unlinking */
1030 case QH_STATE_UNLINK: /* wait for hw to finish? */
1031 case QH_STATE_UNLINK_WAIT:
1032 idle_timeout:
1033 hal_spin_unlock_irqrestore(&ehci->lock, flags);
1034 //schedule_timeout_uninterruptible(1);
1035 goto rescan;
1036 case QH_STATE_IDLE: /* fully unlinked */
1037 //if (qh->clearing_tt)
1038 // goto idle_timeout;
1039 if (list_empty (&qh->qtd_list)) {
1040 if (qh->ps.bw_uperiod)
1041 reserve_release_intr_bandwidth(ehci, qh, -1);
1042 qh_destroy(ehci, qh);
1043 break;
1044 }
1045 break;
1046 /* else FALL THROUGH */
1047 default:
1048 /* caller was supposed to have unlinked any requests;
1049 * that's not our job. just leak this memory.
1050 */
1051 ehci_err ("qh %p (#%02x) state %d%s\n",
1052 qh, ep->desc.bEndpointAddress, qh->qh_state,
1053 list_empty (&qh->qtd_list) ? "" : "(has tds)");
1054 break;
1055 }
1056 done:
1057 ep->hcpriv = NULL;
1058 hal_spin_unlock_irqrestore (&ehci->lock, flags);
1059 }
1060
1061 static void
ehci_endpoint_reset(struct hc_gen_dev * hcd,struct usb_host_virt_endpoint * ep)1062 ehci_endpoint_reset(struct hc_gen_dev *hcd, struct usb_host_virt_endpoint *ep)
1063 {
1064 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1065 struct ehci_qh *qh;
1066 int eptype = usb_endpoint_type(&ep->desc);
1067 int epnum = usb_endpoint_num(&ep->desc);
1068 int is_out = usb_endpoint_dir_out(&ep->desc);
1069 unsigned long flags;
1070
1071 if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
1072 return;
1073
1074 flags = hal_spin_lock_irqsave(&ehci->lock);
1075 qh = ep->hcpriv;
1076
1077 /* For Bulk and Interrupt endpoints we maintain the toggle state
1078 * in the hardware; the toggle bits in udev aren't used at all.
1079 * When an endpoint is reset by usb_clear_halt() we must reset
1080 * the toggle bit in the QH.
1081 */
1082 if (qh) {
1083 if (!list_empty(&qh->qtd_list)) {
1084 ehci_warn("clear_halt for a busy endpoint\n");
1085 } else {
1086 /* The toggle value in the QH can't be updated
1087 * while the QH is active. Unlink it now;
1088 * re-linking will call qh_refresh().
1089 */
1090 usb_settoggle(qh->ps.udev, epnum, is_out, 0);
1091 qh->unlink_reason |= QH_UNLINK_REQUESTED;
1092 if (eptype == USB_ENDPOINT_XFER_BULK)
1093 start_unlink_async(ehci, qh);
1094 else
1095 start_unlink_intr(ehci, qh);
1096 }
1097 }
1098 hal_spin_unlock_irqrestore(&ehci->lock, flags);
1099 }
1100
ehci_get_frame(struct hc_gen_dev * hcd)1101 int ehci_get_frame (struct hc_gen_dev *hcd)
1102 {
1103 /*struct ehci_hcd *ehci = hcd_to_ehci (hcd);
1104 return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size;
1105 */
1106 ehci_warn("PANIC : hcd_ops_get_frame() not support now");
1107 return 0;
1108 }
1109
1110 /*-------------------------------------------------------------------------*/
1111
1112 /* Device addition and removal */
1113
ehci_remove_device(struct hc_gen_dev * hcd,struct usb_host_virt_dev * udev)1114 static void ehci_remove_device(struct hc_gen_dev *hcd, struct usb_host_virt_dev *udev)
1115 {
1116 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1117
1118 //hal_spin_lock(&ehci->lock);
1119 //drop_tt(udev);
1120 //hal_spin_unlock(&ehci->lock);
1121 }
1122
1123 /*-------------------------------------------------------------------------*/
1124
1125 #ifdef CONFIG_PM
1126
1127 /* suspend/resume, section 4.3 */
1128
1129 /* These routines handle the generic parts of controller suspend/resume */
1130
ehci_suspend(struct usb_hcd * hcd,bool do_wakeup)1131 int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1132 {
1133 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1134
1135 if (time_before(jiffies, ehci->next_statechange))
1136 msleep(10);
1137
1138 /*
1139 * Root hub was already suspended. Disable IRQ emission and
1140 * mark HW unaccessible. The PM and USB cores make sure that
1141 * the root hub is either suspended or stopped.
1142 */
1143 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
1144
1145 spin_lock_irq(&ehci->lock);
1146 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
1147 (void) ehci_readl(ehci, &ehci->regs->intr_enable);
1148
1149 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1150 spin_unlock_irq(&ehci->lock);
1151
1152 synchronize_irq(hcd->irq);
1153
1154 /* Check for race with a wakeup request */
1155 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
1156 ehci_resume(hcd, false);
1157 return -EBUSY;
1158 }
1159
1160 return 0;
1161 }
1162 EXPORT_SYMBOL_GPL(ehci_suspend);
1163
1164 /* Returns 0 if power was preserved, 1 if power was lost */
ehci_resume(struct usb_hcd * hcd,bool force_reset)1165 int ehci_resume(struct usb_hcd *hcd, bool force_reset)
1166 {
1167 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1168
1169 if (time_before(jiffies, ehci->next_statechange))
1170 msleep(100);
1171
1172 /* Mark hardware accessible again as we are back to full power by now */
1173 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1174
1175 if (ehci->shutdown)
1176 return 0; /* Controller is dead */
1177
1178 /*
1179 * If CF is still set and reset isn't forced
1180 * then we maintained suspend power.
1181 * Just undo the effect of ehci_suspend().
1182 */
1183 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
1184 !force_reset) {
1185 int mask = INTR_MASK;
1186
1187 ehci_prepare_ports_for_controller_resume(ehci);
1188
1189 spin_lock_irq(&ehci->lock);
1190 if (ehci->shutdown)
1191 goto skip;
1192
1193 if (!hcd->self.root_hub->do_remote_wakeup)
1194 mask &= ~STS_PCD;
1195 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
1196 ehci_readl(ehci, &ehci->regs->intr_enable);
1197 skip:
1198 spin_unlock_irq(&ehci->lock);
1199 return 0;
1200 }
1201
1202 /*
1203 * Else reset, to cope with power loss or resume from hibernation
1204 * having let the firmware kick in during reboot.
1205 */
1206 usb_root_hub_lost_power(hcd->self.root_hub);
1207 (void) ehci_halt(ehci);
1208 (void) ehci_reset(ehci);
1209
1210 spin_lock_irq(&ehci->lock);
1211 if (ehci->shutdown)
1212 goto skip;
1213
1214 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1215 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
1216 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
1217
1218 ehci->rh_state = EHCI_RH_SUSPENDED;
1219 spin_unlock_irq(&ehci->lock);
1220
1221 return 1;
1222 }
1223 EXPORT_SYMBOL_GPL(ehci_resume);
1224
1225 #endif
1226
1227 /*-------------------------------------------------------------------------*/
1228 //void ehci_init_driver(struct hc_driver *drv,
1229 // const struct ehci_driver_overrides *over)
1230 //{
1231 // /* Copy the generic table to drv and then apply the overrides */
1232 // *drv = ehci_hc_driver;
1233 //
1234 // if (over) {
1235 // drv->hcd_priv_size += over->extra_priv_size;
1236 // if (over->reset)
1237 // drv->reset = over->reset;
1238 // if (over->port_power)
1239 // drv->port_power = over->port_power;
1240 // }
1241 //}
1242 //EXPORT_SYMBOL_GPL(ehci_init_driver);
1243 //
1244 ///*-------------------------------------------------------------------------*/
1245 //
1246 //MODULE_DESCRIPTION(DRIVER_DESC);
1247 //MODULE_AUTHOR (DRIVER_AUTHOR);
1248 //MODULE_LICENSE ("GPL");
1249
1250 //static int ehci_hcd_init(void)
1251 //{
1252 // int retval = 0;
1253 //
1254 // if (usb_disabled())
1255 // return -ENODEV;
1256 //
1257 // printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
1258 // set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
1259 // if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
1260 // test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
1261 // printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"
1262 // " before uhci_hcd and ohci_hcd, not after\n");
1263 //
1264 // pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
1265 // hcd_name,
1266 // sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
1267 // sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
1268 //
1269 //#ifdef CONFIG_DYNAMIC_DEBUG
1270 // ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);
1271 // if (!ehci_debug_root) {
1272 // retval = -ENOENT;
1273 // goto err_debug;
1274 // }
1275 //#endif
1276 //
1277 //#ifdef PLATFORM_DRIVER
1278 // retval = platform_driver_register(&PLATFORM_DRIVER);
1279 // if (retval < 0)
1280 // goto clean0;
1281 //#endif
1282 //
1283 //#ifdef PS3_SYSTEM_BUS_DRIVER
1284 // retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1285 // if (retval < 0)
1286 // goto clean2;
1287 //#endif
1288 //
1289 //#ifdef OF_PLATFORM_DRIVER
1290 // retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1291 // if (retval < 0)
1292 // goto clean3;
1293 //#endif
1294 //
1295 //#ifdef XILINX_OF_PLATFORM_DRIVER
1296 // retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
1297 // if (retval < 0)
1298 // goto clean4;
1299 //#endif
1300 // return retval;
1301 //
1302 //#ifdef XILINX_OF_PLATFORM_DRIVER
1303 // /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
1304 //clean4:
1305 //#endif
1306 //#ifdef OF_PLATFORM_DRIVER
1307 // platform_driver_unregister(&OF_PLATFORM_DRIVER);
1308 //clean3:
1309 //#endif
1310 //#ifdef PS3_SYSTEM_BUS_DRIVER
1311 // ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1312 //clean2:
1313 //#endif
1314 //#ifdef PLATFORM_DRIVER
1315 // platform_driver_unregister(&PLATFORM_DRIVER);
1316 //clean0:
1317 //#endif
1318 //#ifdef CONFIG_DYNAMIC_DEBUG
1319 // debugfs_remove(ehci_debug_root);
1320 // ehci_debug_root = NULL;
1321 //err_debug:
1322 //#endif
1323 // clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
1324 // return retval;
1325 //}
1326 //module_init(ehci_hcd_init);
1327
1328 //static void ehci_hcd_cleanup(void)
1329 //{
1330 //#ifdef XILINX_OF_PLATFORM_DRIVER
1331 // platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
1332 //#endif
1333 //#ifdef OF_PLATFORM_DRIVER
1334 // platform_driver_unregister(&OF_PLATFORM_DRIVER);
1335 //#endif
1336 //#ifdef PLATFORM_DRIVER
1337 // platform_driver_unregister(&PLATFORM_DRIVER);
1338 //#endif
1339 //#ifdef PS3_SYSTEM_BUS_DRIVER
1340 // ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1341 //#endif
1342 //#ifdef CONFIG_DYNAMIC_DEBUG
1343 // debugfs_remove(ehci_debug_root);
1344 //#endif
1345 // clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
1346 //}
1347 //module_exit(ehci_hcd_cleanup);
1348