1 // Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
2 // This code is licensed to you under the terms of the GNU GPL, version 2;
3 // see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
6 // Copyright (c) 2008 - Nuke - <wiinuke@gmail.com>
11 static void exi_write(u32 addr, u32 x)
13 write32(0x0d006800 + addr, x);
16 static u32 exi_read(u32 addr)
18 return read32(0x0d006800 + addr);
21 #define EXI_CH1_STATUS 0x14
22 #define EXI_CH1_CONTROL 0x20
23 #define EXI_CH1_DATA 0x24
26 static void usbgecko_deselect_device(void)
28 exi_write(EXI_CH1_STATUS, 0);
31 static void usbgecko_select_device(void)
34 exi_write(EXI_CH1_STATUS, 0xc0);
37 static void usbgecko_wait_for_transfer_complete(void)
39 while (exi_read(EXI_CH1_CONTROL) & 1)
44 u8 usbgecko_flash_read8(u32 offset)
48 usbgecko_deselect_device();
50 usbgecko_select_device();
51 exi_write(EXI_CH1_DATA, 0xf0000000 | (offset << 9));
52 exi_write(EXI_CH1_CONTROL, 0x35); // 4 bytes immediate write
53 usbgecko_wait_for_transfer_complete();
55 usbgecko_select_device();
56 exi_write(EXI_CH1_CONTROL, 0x39); // 4 bytes immediate read/write
57 usbgecko_wait_for_transfer_complete();
59 x = exi_read(EXI_CH1_DATA) >> 23;
61 usbgecko_deselect_device();
66 u32 usbgecko_flash_read32(u32 offset)
71 for (i = 0; i < 4; i++)
72 x = (x << 8) | usbgecko_flash_read8(offset++);
79 static int usbgecko_console_enabled = 0;
81 static u32 usbgecko_command(u32 command)
85 usbgecko_select_device();
86 exi_write(EXI_CH1_DATA, command);
87 exi_write(EXI_CH1_CONTROL, 0x19); // 2 bytes immediate read/write
88 usbgecko_wait_for_transfer_complete();
90 x = exi_read(EXI_CH1_DATA);
92 usbgecko_deselect_device();
97 int usbgecko_checkgecko(void)
99 return usbgecko_command(0x90000000) == 0x04700000;
102 void usbgecko_console_putc(u8 c)
106 if (!usbgecko_console_enabled)
110 usbgecko_console_putc('\r');
112 x = usbgecko_command(0xb0000000 | (c << 20));
115 static void usbgecko_flush(void)
120 x = usbgecko_command(0xa0000000);
121 } while (x & 0x08000000);
124 void usbgecko_init(void)
126 if (!usbgecko_checkgecko())
129 usbgecko_console_enabled = 1;