1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * arch/powerpc/boot/ugecon.c
5 * USB Gecko bootwrapper console.
6 * Copyright (C) 2008-2009 The GameCube Linux Team
7 * Copyright (C) 2008,2009 Albert Herranz
17 #define EXI_CLK_32MHZ 5
20 #define EXI_CSR_CLKMASK (0x7<<4)
21 #define EXI_CSR_CLK_32MHZ (EXI_CLK_32MHZ<<4)
22 #define EXI_CSR_CSMASK (0x7<<7)
23 #define EXI_CSR_CS_0 (0x1<<7) /* Chip Select 001 */
26 #define EXI_CR_TSTART (1<<0)
27 #define EXI_CR_WRITE (1<<2)
28 #define EXI_CR_READ_WRITE (2<<2)
29 #define EXI_CR_TLEN(len) (((len)-1)<<4)
34 /* virtual address base for input/output, retrieved from device tree */
35 static void *ug_io_base
;
38 static u32
ug_io_transaction(u32 in
)
40 u32
*csr_reg
= ug_io_base
+ EXI_CSR
;
41 u32
*data_reg
= ug_io_base
+ EXI_DATA
;
42 u32
*cr_reg
= ug_io_base
+ EXI_CR
;
46 csr
= EXI_CSR_CLK_32MHZ
| EXI_CSR_CS_0
;
47 out_be32(csr_reg
, csr
);
51 out_be32(data_reg
, data
);
52 cr
= EXI_CR_TLEN(2) | EXI_CR_READ_WRITE
| EXI_CR_TSTART
;
55 while (in_be32(cr_reg
) & EXI_CR_TSTART
)
61 data
= in_be32(data_reg
);
65 static int ug_is_txfifo_ready(void)
67 return ug_io_transaction(0xc0000000) & 0x04000000;
70 static void ug_raw_putc(char ch
)
72 ug_io_transaction(0xb0000000 | (ch
<< 20));
75 static void ug_putc(char ch
)
82 while (!ug_is_txfifo_ready() && count
--)
88 void ug_console_write(const char *buf
, int len
)
90 char *b
= (char *)buf
;
99 static int ug_is_adapter_present(void)
103 return ug_io_transaction(0x90000000) == 0x04700000;
106 static void *ug_grab_exi_io_base(void)
111 devp
= find_node_by_compatible(NULL
, "nintendo,flipper-exi");
114 if (getprop(devp
, "virtual-reg", &v
, sizeof(v
)) != sizeof(v
))
128 exi_io_base
= ug_grab_exi_io_base();
132 /* look for a usbgecko on memcard slots A and B */
133 for (i
= 0; i
< 2; i
++) {
134 ug_io_base
= exi_io_base
+ 0x14 * i
;
135 if (ug_is_adapter_present())