PP5022/PP5024-specific USB init which may fix "signal quality issues"
[kugel-rb.git] / bootloader / telechips.c
blob1e54f5d37d968f753791187ab701a6615ca62fd8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Dave Chapman
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #include "config.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include "cpu.h"
29 #include "system.h"
30 #include "lcd.h"
31 #include "kernel.h"
32 #include "thread.h"
33 #include "storage.h"
34 #include "fat.h"
35 #include "disk.h"
36 #include "font.h"
37 #include "button.h"
38 #include "adc.h"
39 #include "adc-target.h"
40 #include "backlight.h"
41 #include "backlight-target.h"
42 #include "panic.h"
43 #include "power.h"
44 #include "file.h"
45 #include "common.h"
47 /* Show the Rockbox logo - in show_logo.c */
48 extern int show_logo(void);
50 /* Address to load main Rockbox image to */
51 #define LOAD_ADDRESS 0x20000000 /* DRAM_START */
53 char version[] = APPSVERSION;
55 extern int line;
57 #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
59 /* The following function is just test/development code */
60 #ifdef CPU_TCC77X
61 void show_debug_screen(void)
63 int button;
64 int power_count = 0;
65 int count = 0;
66 bool do_power_off = false;
68 lcd_puts_scroll(0,0,"this is a very long line to test scrolling");
69 while (!do_power_off) {
70 line = 1;
71 button = button_get(false);
73 /* Power-off if POWER button has been held for a time
74 This loop is currently running at about 100 iterations/second
76 if (button & POWEROFF_BUTTON) {
77 power_count++;
78 if (power_count > 100)
79 do_power_off = true;
80 } else {
81 power_count = 0;
83 #if 0
84 if (button & BUTTON_SELECT){
85 _backlight_off();
87 else{
88 _backlight_on();
90 #endif
91 printf("Btn: 0x%08x",button);
92 #if 0
93 printf("Tick: %d",current_tick);
94 printf("GPIOA: 0x%08x",GPIOA);
95 printf("GPIOB: 0x%08x",GPIOB);
96 printf("GPIOC: 0x%08x",GPIOC);
97 printf("GPIOD: 0x%08x",GPIOD);
98 printf("GPIOE: 0x%08x",GPIOE);
99 #endif
101 #if 0
102 int i;
103 for (i = 0; i<4; i++)
105 printf("ADC%d: 0x%04x",i,adc_read(i));
107 #endif
108 count++;
109 printf("Count: %d",count);
110 sleep(HZ/10);
114 lcd_clear_display();
115 line = 0;
116 printf("POWER-OFF");
118 /* Power-off */
119 power_off();
121 printf("(NOT) POWERED OFF");
122 while (true);
125 #else /* !CPU_TCC77X */
127 void show_debug_screen(void)
129 int button;
130 int power_count = 0;
131 int count = 0;
132 bool do_power_off = false;
133 #ifdef HAVE_BUTTON_DATA
134 unsigned int data;
135 #endif
137 while(!do_power_off) {
138 line = 0;
139 printf("Hello World!");
141 #ifdef HAVE_BUTTON_DATA
142 button = button_read_device(&data);
143 #else
144 button = button_read_device();
145 #endif
147 /* Power-off if POWER button has been held for a long time
148 This loop is currently running at about 100 iterations/second
150 if (button & POWEROFF_BUTTON) {
151 power_count++;
152 if (power_count > 200)
153 do_power_off = true;
154 } else {
155 power_count = 0;
158 printf("Btn: 0x%08x",button);
160 count++;
161 printf("Count: %d",count);
164 lcd_clear_display();
165 line = 0;
166 printf("POWER-OFF");
168 /* Power-off */
169 power_off();
171 printf("(NOT) POWERED OFF");
172 while (true);
174 #endif
176 void* main(void)
178 #ifdef TCCBOOT
179 int rc;
180 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS;
181 #endif
183 system_init();
184 power_init();
185 #ifndef COWON_D2
186 /* The D2 doesn't enable threading or interrupts */
187 kernel_init();
188 enable_irq();
189 #endif
190 lcd_init();
192 adc_init();
193 button_init();
194 backlight_init();
196 font_init();
197 lcd_setfont(FONT_SYSFIXED);
199 show_logo();
201 _backlight_on();
203 /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is
204 available for loading the firmware. Otherwise display the debug screen. */
205 #ifdef TCCBOOT
206 printf("Rockbox boot loader");
207 printf("Version %s", version);
209 printf("ATA");
210 rc = storage_init();
211 if(rc)
213 reset_screen();
214 error(EATA, rc);
217 printf("mount");
218 rc = disk_mount_all();
219 if (rc<=0)
221 error(EDISK,rc);
224 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
226 if (rc < 0)
228 error(EBOOTFILE,rc);
230 else if (rc == EOK)
232 int(*kernel_entry)(void);
234 kernel_entry = (void*) loadbuffer;
235 rc = kernel_entry();
237 #else
238 show_debug_screen();
239 #endif
241 return 0;