2 * arch/powerpc/boot/ugecon.c
4 * USB Gecko bootwrapper console.
5 * Copyright (C) 2008-2009 The GameCube Linux Team
6 * Copyright (C) 2008,2009 Albert Herranz
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
22 #define EXI_CLK_32MHZ 5
25 #define EXI_CSR_CLKMASK (0x7<<4)
26 #define EXI_CSR_CLK_32MHZ (EXI_CLK_32MHZ<<4)
27 #define EXI_CSR_CSMASK (0x7<<7)
28 #define EXI_CSR_CS_0 (0x1<<7) /* Chip Select 001 */
31 #define EXI_CR_TSTART (1<<0)
32 #define EXI_CR_WRITE (1<<2)
33 #define EXI_CR_READ_WRITE (2<<2)
34 #define EXI_CR_TLEN(len) (((len)-1)<<4)
39 /* virtual address base for input/output, retrieved from device tree */
40 static void *ug_io_base
;
43 static u32
ug_io_transaction(u32 in
)
45 u32
*csr_reg
= ug_io_base
+ EXI_CSR
;
46 u32
*data_reg
= ug_io_base
+ EXI_DATA
;
47 u32
*cr_reg
= ug_io_base
+ EXI_CR
;
51 csr
= EXI_CSR_CLK_32MHZ
| EXI_CSR_CS_0
;
52 out_be32(csr_reg
, csr
);
56 out_be32(data_reg
, data
);
57 cr
= EXI_CR_TLEN(2) | EXI_CR_READ_WRITE
| EXI_CR_TSTART
;
60 while (in_be32(cr_reg
) & EXI_CR_TSTART
)
66 data
= in_be32(data_reg
);
70 static int ug_is_txfifo_ready(void)
72 return ug_io_transaction(0xc0000000) & 0x04000000;
75 static void ug_raw_putc(char ch
)
77 ug_io_transaction(0xb0000000 | (ch
<< 20));
80 static void ug_putc(char ch
)
87 while (!ug_is_txfifo_ready() && count
--)
93 void ug_console_write(const char *buf
, int len
)
95 char *b
= (char *)buf
;
104 static int ug_is_adapter_present(void)
108 return ug_io_transaction(0x90000000) == 0x04700000;
111 static void *ug_grab_exi_io_base(void)
116 devp
= find_node_by_compatible(NULL
, "nintendo,flipper-exi");
119 if (getprop(devp
, "virtual-reg", &v
, sizeof(v
)) != sizeof(v
))
133 exi_io_base
= ug_grab_exi_io_base();
137 /* look for a usbgecko on memcard slots A and B */
138 for (i
= 0; i
< 2; i
++) {
139 ug_io_base
= exi_io_base
+ 0x14 * i
;
140 if (ug_is_adapter_present())