2 mini - a Free Software replacement for the Nintendo/BroadOn IOS.
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"
17 #define gecko_printf printf
18 #define dma_addr(address) virt_to_phys(address)
21 static struct ohci_hcca hcca_oh0;
23 static void dbg_op_state() {
24 switch (read32(OHCI0_HC_CONTROL) & OHCI_CTRL_HCFS) {
25 case OHCI_USB_SUSPEND:
26 gecko_printf("ohci-- OHCI_USB_SUSPEND\n");
29 gecko_printf("ohci-- OHCI_USB_RESET\n");
32 gecko_printf("ohci-- OHCI_USB_OPER\n");
35 gecko_printf("ohci-- OHCI_USB_RESUME\n");
41 gecko_printf("ohci-- init\n");
44 /* disable hc interrupts */
45 set32(OHCI0_HC_INT_DISABLE, OHCI_INTR_MIE);
47 /* save fmInterval and calculate FSMPS */
48 #define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7))
49 #define FI 0x2edf /* 12000 bits per frame (-1) */
50 u32 fmint = read32(OHCI0_HC_FM_INTERVAL) & 0x3fff;
52 gecko_printf("ohci-- fminterval delta: %d\n", fmint - FI);
53 fmint |= FSMP (fmint) << 16;
55 /* enable interrupts of both usb host controllers */
56 set32(EHCI_CTL, EHCI_CTL_OH0INTE | EHCI_CTL_OH1INTE | 0xe0000);
59 write32(OHCI0_HC_COMMAND_STATUS, OHCI_HCR);
63 while ((read32(OHCI0_HC_COMMAND_STATUS) & OHCI_HCR) != 0) {
65 gecko_printf("ohci-- FAILED");
71 /* disable interrupts; 2ms timelimit here!
72 now we're in the SUSPEND state ... must go OPERATIONAL
73 within 2msec else HC enters RESUME */
75 u32 cookie = irq_kill();
77 /* Tell the controller where the control and bulk lists are
78 * The lists are empty now. */
79 write32(OHCI0_HC_CTRL_HEAD_ED, 0);
80 write32(OHCI0_HC_BULK_HEAD_ED, 0);
83 write32(OHCI0_HC_HCCA, dma_addr(&hcca_oh0));
85 /* set periodicstart */
87 u32 fmInterval = read32(OHCI0_HC_FM_INTERVAL) &0x3fff;
88 u32 fit = read32(OHCI0_HC_FM_INTERVAL) & FIT;
90 write32(OHCI0_HC_FM_INTERVAL, fmint | (fit ^ FIT));
91 write32(OHCI0_HC_PERIODIC_START, ((9*fmInterval)/10)&0x3fff);
94 if ((read32(OHCI0_HC_FM_INTERVAL) & 0x3fff0000) == 0 || !read32(OHCI0_HC_PERIODIC_START)) {
95 gecko_printf("ohci-- w00t, fail!! see ohci-hcd.c:669\n");
98 /* start HC operations */
99 write32(OHCI0_HC_CONTROL, OHCI_CONTROL_INIT | OHCI_USB_OPER);
101 /* wake on ConnectStatusChange, matching external hubs */
102 set32(OHCI0_HC_RH_STATUS, RH_HS_DRWE);
104 /* Choose the interrupts we care about now, others later on demand */
105 write32(OHCI0_HC_INT_STATUS, ~0);
106 write32(OHCI0_HC_INT_ENABLE, OHCI_INTR_INIT);
114 gecko_printf("ohci_irq\n");
115 write32(OHCI0_HC_INT_STATUS, ~0);