From: Albert Herranz <albert_herranz@yahoo.es>
To: linuxppc-dev@lists.ozlabs.org
Cc: Albert Herranz <albert_herranz@yahoo.es>
Subject: [PATCH v2 01/22] powerpc: gamecube/wii: usbgecko bootwrapper console support
Date: Sat, 12 Dec 2009 17:31:34 +0100 [thread overview]
Message-ID: <1260635515-7478-2-git-send-email-albert_herranz@yahoo.es> (raw)
In-Reply-To: <1260635515-7478-1-git-send-email-albert_herranz@yahoo.es>
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>
---
arch/powerpc/boot/Makefile | 2 +-
arch/powerpc/boot/ugecon.c | 147 ++++++++++++++++++++++++++++++++++++++++++++
arch/powerpc/boot/ugecon.h | 24 +++++++
3 files changed, 172 insertions(+), 1 deletions(-)
create mode 100644 arch/powerpc/boot/ugecon.c
create mode 100644 arch/powerpc/boot/ugecon.h
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 7bfc8ad..44bce21 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -66,7 +66,7 @@ src-wlib := string.S crt0.S crtsavres.S stdio.c main.c \
gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \
4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \
cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \
- fsl-soc.c mpc8xx.c pq2.c
+ fsl-soc.c mpc8xx.c pq2.c ugecon.c
src-plat := of.c cuboot-52xx.c cuboot-824x.c cuboot-83xx.c cuboot-85xx.c holly.c \
cuboot-ebony.c cuboot-hotfoot.c treeboot-ebony.c prpmc2800.c \
ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \
diff --git a/arch/powerpc/boot/ugecon.c b/arch/powerpc/boot/ugecon.c
new file mode 100644
index 0000000..50609ea
--- /dev/null
+++ b/arch/powerpc/boot/ugecon.c
@@ -0,0 +1,147 @@
+/*
+ * arch/powerpc/boot/ugecon.c
+ *
+ * USB Gecko bootwrapper console.
+ * Copyright (C) 2008-2009 The GameCube Linux Team
+ * Copyright (C) 2008,2009 Albert Herranz
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#include <stddef.h>
+#include "stdio.h"
+#include "types.h"
+#include "io.h"
+#include "ops.h"
+
+
+#define EXI_CLK_32MHZ 5
+
+#define EXI_CSR 0x00
+#define EXI_CSR_CLKMASK (0x7<<4)
+#define EXI_CSR_CLK_32MHZ (EXI_CLK_32MHZ<<4)
+#define EXI_CSR_CSMASK (0x7<<7)
+#define EXI_CSR_CS_0 (0x1<<7) /* Chip Select 001 */
+
+#define EXI_CR 0x0c
+#define EXI_CR_TSTART (1<<0)
+#define EXI_CR_WRITE (1<<2)
+#define EXI_CR_READ_WRITE (2<<2)
+#define EXI_CR_TLEN(len) (((len)-1)<<4)
+
+#define EXI_DATA 0x10
+
+
+/* virtual address base for input/output, retrieved from device tree */
+static void *ug_io_base;
+
+
+static u32 ug_io_transaction(u32 in)
+{
+ u32 *csr_reg = ug_io_base + EXI_CSR;
+ u32 *data_reg = ug_io_base + EXI_DATA;
+ u32 *cr_reg = ug_io_base + EXI_CR;
+ u32 csr, data, cr;
+
+ /* select */
+ csr = EXI_CSR_CLK_32MHZ | EXI_CSR_CS_0;
+ out_be32(csr_reg, csr);
+
+ /* read/write */
+ data = in;
+ out_be32(data_reg, data);
+ cr = EXI_CR_TLEN(2) | EXI_CR_READ_WRITE | EXI_CR_TSTART;
+ out_be32(cr_reg, cr);
+
+ while (in_be32(cr_reg) & EXI_CR_TSTART)
+ barrier();
+
+ /* deselect */
+ out_be32(csr_reg, 0);
+
+ data = in_be32(data_reg);
+ return data;
+}
+
+static int ug_is_txfifo_ready(void)
+{
+ return ug_io_transaction(0xc0000000) & 0x04000000;
+}
+
+static void ug_raw_putc(char ch)
+{
+ ug_io_transaction(0xb0000000 | (ch << 20));
+}
+
+static void ug_putc(char ch)
+{
+ int count = 16;
+
+ if (!ug_io_base)
+ return;
+
+ while (!ug_is_txfifo_ready() && count--)
+ barrier();
+ if (count)
+ ug_raw_putc(ch);
+}
+
+void ug_console_write(const char *buf, int len)
+{
+ char *b = (char *)buf;
+
+ while (len--) {
+ if (*b == '\n')
+ ug_putc('\r');
+ ug_putc(*b++);
+ }
+}
+
+static int ug_is_adapter_present(void)
+{
+ if (!ug_io_base)
+ return 0;
+ return ug_io_transaction(0x90000000) == 0x04700000;
+}
+
+static void *ug_grab_exi_io_base(void)
+{
+ u32 v;
+ void *devp;
+
+ devp = find_node_by_compatible(NULL, "nintendo,flipper-exi");
+ if (devp == NULL)
+ goto err_out;
+ if (getprop(devp, "virtual-reg", &v, sizeof(v)) != sizeof(v))
+ goto err_out;
+
+ return (void *)v;
+
+err_out:
+ return NULL;
+}
+
+void *ug_probe(void)
+{
+ void *exi_io_base;
+ int i;
+
+ exi_io_base = ug_grab_exi_io_base();
+ if (!exi_io_base)
+ return NULL;
+
+ /* look for a usbgecko on memcard slots A and B */
+ for (i = 0; i < 2; i++) {
+ ug_io_base = exi_io_base + 0x14 * i;
+ if (ug_is_adapter_present())
+ break;
+ }
+ if (i == 2)
+ ug_io_base = NULL;
+ return ug_io_base;
+}
+
diff --git a/arch/powerpc/boot/ugecon.h b/arch/powerpc/boot/ugecon.h
new file mode 100644
index 0000000..4373753
--- /dev/null
+++ b/arch/powerpc/boot/ugecon.h
@@ -0,0 +1,24 @@
+/*
+ * arch/powerpc/boot/ugecon.h
+ *
+ * USB Gecko early bootwrapper console.
+ * Copyright (C) 2008-2009 The GameCube Linux Team
+ * Copyright (C) 2008,2009 Albert Herranz
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef __UGECON_H
+#define __UGECON_H
+
+extern void *ug_probe(void);
+
+extern void ug_putc(char ch);
+extern void ug_console_write(const char *buf, int len);
+
+#endif /* __UGECON_H */
+
--
1.6.3.3
next prev parent reply other threads:[~2009-12-12 16:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-12 16:31 [PATCH v2 00/22] powerpc: nintendo gamecube and wii support Albert Herranz
2009-12-12 16:31 ` Albert Herranz [this message]
2009-12-12 16:31 ` [PATCH v2 02/22] powerpc: gamecube: device tree Albert Herranz
2009-12-12 16:31 ` [PATCH v2 03/22] powerpc: gamecube: bootwrapper bits Albert Herranz
2009-12-12 16:31 ` [PATCH v2 04/22] powerpc: gamecube/wii: introduce GAMECUBE_COMMON Albert Herranz
2009-12-12 16:31 ` [PATCH v2 05/22] powerpc: gamecube/wii: declare as non-coherent platforms Albert Herranz
2009-12-12 16:31 ` [PATCH v2 06/22] powerpc: gamecube/wii: do not include PCI support Albert Herranz
2009-12-12 16:31 ` [PATCH v2 07/22] powerpc: gamecube/wii: udbg support for usbgecko Albert Herranz
2009-12-12 16:31 ` [PATCH v2 08/22] powerpc: gamecube/wii: flipper interrupt controller support Albert Herranz
2009-12-12 16:31 ` [PATCH v2 09/22] powerpc: gamecube: platform support Albert Herranz
2009-12-12 16:31 ` [PATCH v2 10/22] powerpc: gamecube: default config Albert Herranz
2009-12-12 16:31 ` [PATCH v2 11/22] powerpc: wii: device tree Albert Herranz
2009-12-12 16:31 ` [PATCH v2 12/22] powerpc: wii: bootwrapper bits Albert Herranz
2009-12-12 16:31 ` [PATCH v2 13/22] powerpc: broadway processor support Albert Herranz
2009-12-12 16:31 ` [PATCH v2 14/22] powerpc: wii: hollywood interrupt controller support Albert Herranz
2009-12-12 16:31 ` [PATCH v2 15/22] powerpc: wii: platform support Albert Herranz
2009-12-12 16:31 ` [PATCH v2 16/22] powerpc: wii: default config Albert Herranz
2009-12-12 16:31 ` [PATCH v2 17/22] powerpc: reserve fixmap entries for early debug Albert Herranz
2009-12-12 16:31 ` [PATCH v2 18/22] powerpc: gamecube/wii: early debugging using usbgecko Albert Herranz
2009-12-12 16:31 ` [PATCH v2 19/22] wii: bootwrapper: add fixup to calc useable mem2 Albert Herranz
2009-12-12 16:31 ` [PATCH v2 20/22] wii: use both mem1 and mem2 as ram Albert Herranz
2009-12-12 16:31 ` [PATCH v2 21/22] powerpc: allow ioremap within reserved memory regions Albert Herranz
2009-12-12 16:31 ` [PATCH v2 22/22] powerpc: wii: allow ioremap within the memory hole Albert Herranz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1260635515-7478-2-git-send-email-albert_herranz@yahoo.es \
--to=albert_herranz@yahoo.es \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).