2 ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
5 Copyright (C) 2009 Bernhard Urban <lewurm@gmx.net>
6 Copyright (C) 2009 Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
8 # This code is licensed to you under the terms of the GNU GPL, version 2;
9 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
12 #include "bootmii_ppc.h"
13 #include "hollywood.h"
18 static struct ohci_hcca hcca_oh0;
20 static void dbg_op_state() {
21 switch (read32(OHCI0_HC_CONTROL) & OHCI_CTRL_HCFS) {
22 case OHCI_USB_SUSPEND:
23 printf("ohci-- OHCI_USB_SUSPEND\n");
26 printf("ohci-- OHCI_USB_RESET\n");
29 printf("ohci-- OHCI_USB_OPER\n");
32 printf("ohci-- OHCI_USB_RESUME\n");
38 printf("ohci-- init\n");
41 /* disable hc interrupts */
42 set32(OHCI0_HC_INT_DISABLE, OHCI_INTR_MIE);
44 /* save fmInterval and calculate FSMPS */
45 #define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7))
46 #define FI 0x2edf /* 12000 bits per frame (-1) */
47 u32 fmint = read32(OHCI0_HC_FM_INTERVAL) & 0x3fff;
49 printf("ohci-- fminterval delta: %d\n", fmint - FI);
50 fmint |= FSMP (fmint) << 16;
52 /* enable interrupts of both usb host controllers */
53 set32(EHCI_CTL, EHCI_CTL_OH0INTE | EHCI_CTL_OH1INTE | 0xe0000);
56 write32(OHCI0_HC_COMMAND_STATUS, OHCI_HCR);
60 while ((read32(OHCI0_HC_COMMAND_STATUS) & OHCI_HCR) != 0) {
62 printf("ohci-- FAILED");
68 /* disable interrupts; 2ms timelimit here!
69 now we're in the SUSPEND state ... must go OPERATIONAL
70 within 2msec else HC enters RESUME */
72 u32 cookie = irq_kill();
74 /* Tell the controller where the control and bulk lists are
75 * The lists are empty now. */
76 write32(OHCI0_HC_CTRL_HEAD_ED, 0);
77 write32(OHCI0_HC_BULK_HEAD_ED, 0);
80 sync_after_write(&hcca_oh0, 256);
81 write32(OHCI0_HC_HCCA, virt_to_phys(&hcca_oh0));
83 /* set periodicstart */
85 u32 fmInterval = read32(OHCI0_HC_FM_INTERVAL) &0x3fff;
86 u32 fit = read32(OHCI0_HC_FM_INTERVAL) & FIT;
88 write32(OHCI0_HC_FM_INTERVAL, fmint | (fit ^ FIT));
89 write32(OHCI0_HC_PERIODIC_START, ((9*fmInterval)/10)&0x3fff);
92 if ((read32(OHCI0_HC_FM_INTERVAL) & 0x3fff0000) == 0 || !read32(OHCI0_HC_PERIODIC_START)) {
93 printf("ohci-- w00t, fail!! see ohci-hcd.c:669\n");
96 /* start HC operations */
97 write32(OHCI0_HC_CONTROL, OHCI_CONTROL_INIT | OHCI_USB_OPER);
99 /* wake on ConnectStatusChange, matching external hubs */
100 set32(OHCI0_HC_RH_STATUS, RH_HS_DRWE);
102 /* Choose the interrupts we care about now, others later on demand */
103 write32(OHCI0_HC_INT_STATUS, ~0);
104 write32(OHCI0_HC_INT_ENABLE, OHCI_INTR_INIT);
112 write32(OHCI0_HC_INT_STATUS, ~0);
113 printf("ohci_irq\n");