Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: gamecube/wii: usbgecko bootwrapper console support

Add support for using the USB Gecko adapter as a bootwrapper console on
the Nintendo GameCube and Wii video game consoles.
The USB Gecko is a 3rd party memory card interface adapter that provides
a EXI (External Interface) to USB serial converter.

Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>
Acked-by: Segher Boessenkool <segher@kernel.crashing.org>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Albert Herranz and committed by
Grant Likely
26054c95 22763c5c

+172 -1
+1 -1
arch/powerpc/boot/Makefile
··· 66 66 gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ 67 67 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \ 68 68 cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \ 69 - fsl-soc.c mpc8xx.c pq2.c 69 + fsl-soc.c mpc8xx.c pq2.c ugecon.c 70 70 src-plat := of.c cuboot-52xx.c cuboot-824x.c cuboot-83xx.c cuboot-85xx.c holly.c \ 71 71 cuboot-ebony.c cuboot-hotfoot.c treeboot-ebony.c prpmc2800.c \ 72 72 ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \
+147
arch/powerpc/boot/ugecon.c
··· 1 + /* 2 + * arch/powerpc/boot/ugecon.c 3 + * 4 + * USB Gecko bootwrapper console. 5 + * Copyright (C) 2008-2009 The GameCube Linux Team 6 + * Copyright (C) 2008,2009 Albert Herranz 7 + * 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. 12 + * 13 + */ 14 + 15 + #include <stddef.h> 16 + #include "stdio.h" 17 + #include "types.h" 18 + #include "io.h" 19 + #include "ops.h" 20 + 21 + 22 + #define EXI_CLK_32MHZ 5 23 + 24 + #define EXI_CSR 0x00 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 */ 29 + 30 + #define EXI_CR 0x0c 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) 35 + 36 + #define EXI_DATA 0x10 37 + 38 + 39 + /* virtual address base for input/output, retrieved from device tree */ 40 + static void *ug_io_base; 41 + 42 + 43 + static u32 ug_io_transaction(u32 in) 44 + { 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; 48 + u32 csr, data, cr; 49 + 50 + /* select */ 51 + csr = EXI_CSR_CLK_32MHZ | EXI_CSR_CS_0; 52 + out_be32(csr_reg, csr); 53 + 54 + /* read/write */ 55 + data = in; 56 + out_be32(data_reg, data); 57 + cr = EXI_CR_TLEN(2) | EXI_CR_READ_WRITE | EXI_CR_TSTART; 58 + out_be32(cr_reg, cr); 59 + 60 + while (in_be32(cr_reg) & EXI_CR_TSTART) 61 + barrier(); 62 + 63 + /* deselect */ 64 + out_be32(csr_reg, 0); 65 + 66 + data = in_be32(data_reg); 67 + return data; 68 + } 69 + 70 + static int ug_is_txfifo_ready(void) 71 + { 72 + return ug_io_transaction(0xc0000000) & 0x04000000; 73 + } 74 + 75 + static void ug_raw_putc(char ch) 76 + { 77 + ug_io_transaction(0xb0000000 | (ch << 20)); 78 + } 79 + 80 + static void ug_putc(char ch) 81 + { 82 + int count = 16; 83 + 84 + if (!ug_io_base) 85 + return; 86 + 87 + while (!ug_is_txfifo_ready() && count--) 88 + barrier(); 89 + if (count) 90 + ug_raw_putc(ch); 91 + } 92 + 93 + void ug_console_write(const char *buf, int len) 94 + { 95 + char *b = (char *)buf; 96 + 97 + while (len--) { 98 + if (*b == '\n') 99 + ug_putc('\r'); 100 + ug_putc(*b++); 101 + } 102 + } 103 + 104 + static int ug_is_adapter_present(void) 105 + { 106 + if (!ug_io_base) 107 + return 0; 108 + return ug_io_transaction(0x90000000) == 0x04700000; 109 + } 110 + 111 + static void *ug_grab_exi_io_base(void) 112 + { 113 + u32 v; 114 + void *devp; 115 + 116 + devp = find_node_by_compatible(NULL, "nintendo,flipper-exi"); 117 + if (devp == NULL) 118 + goto err_out; 119 + if (getprop(devp, "virtual-reg", &v, sizeof(v)) != sizeof(v)) 120 + goto err_out; 121 + 122 + return (void *)v; 123 + 124 + err_out: 125 + return NULL; 126 + } 127 + 128 + void *ug_probe(void) 129 + { 130 + void *exi_io_base; 131 + int i; 132 + 133 + exi_io_base = ug_grab_exi_io_base(); 134 + if (!exi_io_base) 135 + return NULL; 136 + 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()) 141 + break; 142 + } 143 + if (i == 2) 144 + ug_io_base = NULL; 145 + return ug_io_base; 146 + } 147 +
+24
arch/powerpc/boot/ugecon.h
··· 1 + /* 2 + * arch/powerpc/boot/ugecon.h 3 + * 4 + * USB Gecko early bootwrapper console. 5 + * Copyright (C) 2008-2009 The GameCube Linux Team 6 + * Copyright (C) 2008,2009 Albert Herranz 7 + * 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. 12 + * 13 + */ 14 + 15 + #ifndef __UGECON_H 16 + #define __UGECON_H 17 + 18 + extern void *ug_probe(void); 19 + 20 + extern void ug_putc(char ch); 21 + extern void ug_console_write(const char *buf, int len); 22 + 23 + #endif /* __UGECON_H */ 24 +