blob: a3a3571ac4726a0393fcf31219b9c00ae8f67b44 [file] [log] [blame]
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Maurus Cuelenaere
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdio.h>
23#include <stdarg.h>
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000024#include "config.h"
25#include "jz4740.h"
26#include "backlight.h"
27#include "font.h"
28#include "lcd.h"
29#include "system.h"
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000030#include "button.h"
Maurus Cuelenaereea9d1072008-07-15 17:20:07 +000031#include "timefuncs.h"
32#include "rtc.h"
Maurus Cuelenaere975261f2008-07-16 15:25:35 +000033#include "common.h"
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +000034#include "mipsregs.h"
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000035
Maurus Cuelenaereea9d1072008-07-15 17:20:07 +000036static void audiotest(void)
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000037{
38 __i2s_internal_codec();
39 __aic_enable();
40 __aic_reset();
41 __aic_select_i2s();
42 __aic_enable_loopback();
43}
44
Maurus Cuelenaere62c4a282008-08-26 21:48:49 +000045/* CP0 hazard avoidance. */
46#define BARRIER __asm__ __volatile__(".set noreorder\n\t" \
47 "nop; nop; nop; nop; nop; nop;\n\t" \
48 ".set reorder\n\t")
49static void show_tlb(void)
50{
51#define ASID_MASK 0xFF
52
53 unsigned int old_ctx;
54 unsigned int entry;
55 unsigned int entrylo0, entrylo1, entryhi;
56 unsigned int pagemask;
57
58 cli();
59
60 /* Save old context */
61 old_ctx = (read_c0_entryhi() & 0xff);
62
63 printf("TLB content:");
64 for(entry = 0; entry < 32; entry++)
65 {
66 write_c0_index(entry);
67 BARRIER;
68 tlb_read();
69 BARRIER;
70 entryhi = read_c0_entryhi();
71 entrylo0 = read_c0_entrylo0();
72 entrylo1 = read_c0_entrylo1();
73 pagemask = read_c0_pagemask();
74 printf("%02d: ASID=%02d%s VA=0x%08x", entry, entryhi & ASID_MASK, (entrylo0 & entrylo1 & 1) ? "(G)" : " ", entryhi & ~ASID_MASK);
75 printf("PA0=0x%08x C0=%x %s%s%s", (entrylo0>>6)<<12, (entrylo0>>3) & 7, (entrylo0 & 4) ? "Dirty " : "", (entrylo0 & 2) ? "Valid " : "Invalid ", (entrylo0 & 1) ? "Global" : "");
76 printf("PA1=0x%08x C1=%x %s%s%s", (entrylo1>>6)<<12, (entrylo1>>3) & 7, (entrylo1 & 4) ? "Dirty " : "", (entrylo1 & 2) ? "Valid " : "Invalid ", (entrylo1 & 1) ? "Global" : "");
77
78 printf("pagemask=0x%08x entryhi=0x%08x", pagemask, entryhi);
79 printf("entrylo0=0x%08x entrylo1=0x%08x", entrylo0, entrylo1);
80 }
81 BARRIER;
82 write_c0_entryhi(old_ctx);
83
84 sti();
85}
86
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000087int main(void)
Maurus Cuelenaere4bf4d2b2008-08-10 21:44:48 +000088{
89 cli();
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000090 kernel_init();
91 lcd_init();
92 font_init();
93 lcd_setfont(FONT_SYSFIXED);
94 button_init();
Maurus Cuelenaereea9d1072008-07-15 17:20:07 +000095 rtc_init();
Maurus Cuelenaere62c4a282008-08-26 21:48:49 +000096 usb_init();
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000097
98 backlight_init();
99
Maurus Cuelenaere88ae9022008-08-06 20:39:02 +0000100 ata_init();
101
Maurus Cuelenaere4bf4d2b2008-08-10 21:44:48 +0000102 sti();
103
Maurus Cuelenaere88ae9022008-08-06 20:39:02 +0000104 /* To make Windows say "ding-dong".. */
Maurus Cuelenaere62c4a282008-08-26 21:48:49 +0000105 //REG8(USB_REG_POWER) &= ~USB_POWER_SOFTCONN;
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +0000106
Maurus Cuelenaereea9d1072008-07-15 17:20:07 +0000107 int touch, btn;
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000108 char datetime[30];
109 reset_screen();
Maurus Cuelenaere975261f2008-07-16 15:25:35 +0000110 printf("Rockbox bootloader v0.000001");
Maurus Cuelenaere88ae9022008-08-06 20:39:02 +0000111 printf("REG_EMC_SACR0: 0x%x", REG_EMC_SACR0);
112 printf("REG_EMC_SACR1: 0x%x", REG_EMC_SACR1);
113 printf("REG_EMC_SACR2: 0x%x", REG_EMC_SACR2);
114 printf("REG_EMC_SACR3: 0x%x", REG_EMC_SACR3);
115 printf("REG_EMC_SACR4: 0x%x", REG_EMC_SACR4);
116 printf("REG_EMC_DMAR0: 0x%x", REG_EMC_DMAR0);
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000117 unsigned int cpu_id = read_c0_prid();
Maurus Cuelenaere06efd072008-07-30 10:24:39 +0000118 printf("CPU_ID: 0x%x", cpu_id);
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000119 printf(" * Company ID: 0x%x", (cpu_id >> 16) & 7);
120 printf(" * Processor ID: 0x%x", (cpu_id >> 8) & 7);
121 printf(" * Revision ID: 0x%x", cpu_id & 7);
Maurus Cuelenaere06efd072008-07-30 10:24:39 +0000122 unsigned int config_data = read_c0_config();
123 printf("C0_CONFIG: 0x%x", config_data);
124 printf(" * Architecture type: 0x%x", (config_data >> 13) & 3);
125 printf(" * Architecture revision: 0x%x", (config_data >> 10) & 7);
126 printf(" * MMU type: 0x%x", (config_data >> 7) & 7);
127 printf("C0_CONFIG1: 0x%x", read_c0_config1());
128 if(read_c0_config1() & (1 << 0)) printf(" * FP available");
129 if(read_c0_config1() & (1 << 1)) printf(" * EJTAG available");
130 if(read_c0_config1() & (1 << 2)) printf(" * MIPS-16 available");
131 if(read_c0_config1() & (1 << 4)) printf(" * Performace counters available");
132 if(read_c0_config1() & (1 << 5)) printf(" * MDMX available");
133 if(read_c0_config1() & (1 << 6)) printf(" * CP2 available");
134 printf("C0_STATUS: 0x%x", read_c0_status());
Maurus Cuelenaere62c4a282008-08-26 21:48:49 +0000135
136#if 0
137 unsigned char testdata[4096];
Maurus Cuelenaere88ae9022008-08-06 20:39:02 +0000138 char msg[30];
139 int j = 0;
140 while(1)
141 {
142 memset(testdata, 0, 4096);
143 jz_nand_read_page(j, &testdata);
144 reset_screen();
145 printf("Page %d", j);
146 int i;
147 for(i=0; i<16; i+=8)
148 {
149 snprintf(msg, 30, "%x%x%x%x%x%x%x%x", testdata[i], testdata[i+1], testdata[i+2], testdata[i+3], testdata[i+4], testdata[i+5], testdata[i+6], testdata[i+7]);
150 printf(msg);
151 }
152 while(!((btn = button_read_device(&touch)) & (BUTTON_VOL_UP|BUTTON_VOL_DOWN)));
153 if(btn & BUTTON_VOL_UP)
154 j++;
155 if(btn & BUTTON_VOL_DOWN)
156 j--;
157 if(j<0)
158 j = 0;
Maurus Cuelenaere62c4a282008-08-26 21:48:49 +0000159 }
160#endif
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +0000161 while(1)
162 {
Maurus Cuelenaereea9d1072008-07-15 17:20:07 +0000163 btn = button_read_device(&touch);
Maurus Cuelenaere06efd072008-07-30 10:24:39 +0000164#define KNOP(x,y) lcd_set_foreground(LCD_BLACK); \
165 if(btn & x) \
166 lcd_set_foreground(LCD_WHITE); \
167 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(#x), LCD_HEIGHT-SYSFONT_HEIGHT*y, #x);
168 KNOP(BUTTON_VOL_UP, 5);
169 KNOP(BUTTON_VOL_DOWN, 6);
170 KNOP(BUTTON_MENU, 7);
171 KNOP(BUTTON_POWER, 8);
172 lcd_set_foreground(LCD_WHITE);
Maurus Cuelenaereea9d1072008-07-15 17:20:07 +0000173 if(button_hold())
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000174 {
Maurus Cuelenaere975261f2008-07-16 15:25:35 +0000175 printf("BUTTON_HOLD");
Maurus Cuelenaere62c4a282008-08-26 21:48:49 +0000176 asm("break 0x7");
177 }
178 if(btn & BUTTON_VOL_DOWN)
179 {
180 reset_screen();
181 show_tlb();
182 }
183 if(btn & BUTTON_POWER)
184 {
185 power_off();
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000186 }
Maurus Cuelenaere06efd072008-07-30 10:24:39 +0000187 if(btn & BUTTON_TOUCH)
Maurus Cuelenaere975261f2008-07-16 15:25:35 +0000188 {
189 lcd_set_foreground(LCD_RGBPACK(touch & 0xFF, (touch >> 8)&0xFF, (touch >> 16)&0xFF));
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000190 lcd_fillrect((touch>>16)-5, (touch&0xFFFF)-5, 10, 10);
Maurus Cuelenaere975261f2008-07-16 15:25:35 +0000191 lcd_update();
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000192 lcd_set_foreground(LCD_WHITE);
Maurus Cuelenaere975261f2008-07-16 15:25:35 +0000193 }
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000194 snprintf(datetime, 30, "%02d/%02d/%04d %02d:%02d:%02d", get_time()->tm_mday, get_time()->tm_mon, get_time()->tm_year,
195 get_time()->tm_hour, get_time()->tm_min, get_time()->tm_sec);
196 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(datetime), LCD_HEIGHT-SYSFONT_HEIGHT, datetime);
Maurus Cuelenaere4bf4d2b2008-08-10 21:44:48 +0000197 snprintf(datetime, 30, "%d", current_tick);
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000198 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(datetime), LCD_HEIGHT-SYSFONT_HEIGHT*2, datetime);
Maurus Cuelenaere06efd072008-07-30 10:24:39 +0000199 snprintf(datetime, 30, "X: %d Y: %d", touch>>16, touch & 0xFFFF);
200 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(datetime), LCD_HEIGHT-SYSFONT_HEIGHT*3, datetime);
Maurus Cuelenaere62c4a282008-08-26 21:48:49 +0000201 snprintf(datetime, 30, "PIN3: 0x%x", REG_GPIO_PXPIN(3));
202 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(datetime), LCD_HEIGHT-SYSFONT_HEIGHT*4, datetime);
203 snprintf(datetime, 30, "PIN2: 0x%x", REG_GPIO_PXPIN(2));
204 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(datetime), LCD_HEIGHT-SYSFONT_HEIGHT*5, datetime);
205 snprintf(datetime, 30, "PIN1: 0x%x", REG_GPIO_PXPIN(1));
206 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(datetime), LCD_HEIGHT-SYSFONT_HEIGHT*6, datetime);
207 snprintf(datetime, 30, "PIN0: 0x%x", REG_GPIO_PXPIN(0));
208 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(datetime), LCD_HEIGHT-SYSFONT_HEIGHT*7, datetime);
209 snprintf(datetime, 30, "ICSR: 0x%x", read_c0_badvaddr());
210 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*strlen(datetime), LCD_HEIGHT-SYSFONT_HEIGHT*8, datetime);
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000211 lcd_update();
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +0000212 }
213
214 return 0;
215}