Add effective clockrate for realtime decoding to the displayed results of test_codec...
[kugel-rb.git] / bootloader / iaudio_coldfire.c
blobc1076e98ccbbe11bcfac66979c9829028e886f85
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "inttypes.h"
24 #include "string.h"
25 #include "cpu.h"
26 #include "system.h"
27 #include "lcd.h"
28 #include "lcd-remote.h"
29 #include "kernel.h"
30 #include "thread.h"
31 #include "ata.h"
32 #include "usb.h"
33 #include "disk.h"
34 #include "font.h"
35 #include "adc.h"
36 #include "backlight.h"
37 #include "backlight-target.h"
38 #include "button.h"
39 #include "panic.h"
40 #include "power.h"
41 #include "powermgmt.h"
42 #include "file.h"
44 #include "pcf50606.h"
45 #include "common.h"
47 #include <stdarg.h>
49 /* Maximum allowed firmware image size. 10MB is more than enough */
50 #define MAX_LOADSIZE (10*1024*1024)
52 #define DRAM_START 0x31000000
54 int usb_screen(void)
56 return 0;
59 char version[] = APPSVERSION;
61 /* Reset the cookie for the crt0 crash check */
62 inline void __reset_cookie(void)
64 asm(" move.l #0,%d0");
65 asm(" move.l %d0,0x10017ffc");
68 void start_firmware(void)
70 adc_close();
71 asm(" move.w #0x2700,%sr");
72 __reset_cookie();
73 asm(" move.l %0,%%d0" :: "i"(DRAM_START));
74 asm(" movec.l %d0,%vbr");
75 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START));
76 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4)));
77 asm(" jmp (%a0)");
80 void shutdown(void)
82 printf("Shutting down...");
84 /* We need to gracefully spin down the disk to prevent clicks. */
85 if (ide_powered())
87 /* Make sure ATA has been initialized. */
88 ata_init();
90 /* And put the disk into sleep immediately. */
91 ata_sleepnow();
94 sleep(HZ*2);
96 /* Backlight OFF */
97 _backlight_off();
98 #ifdef HAVE_REMOTE_LCD
99 _remote_backlight_off();
100 #endif
102 __reset_cookie();
103 power_off();
106 /* Print the battery voltage (and a warning message). */
107 void check_battery(void)
109 int battery_voltage, batt_int, batt_frac;
111 battery_voltage = battery_adc_voltage();
112 batt_int = battery_voltage / 1000;
113 batt_frac = (battery_voltage % 1000) / 10;
115 printf("Batt: %d.%02dV", batt_int, batt_frac);
117 if (battery_voltage <= 3500)
119 printf("WARNING! BATTERY LOW!!");
120 sleep(HZ*2);
124 void main(void)
126 int i;
127 int rc;
128 bool rc_on_button = false;
129 bool on_button = false;
131 /* We want to read the buttons as early as possible, before the user
132 releases the ON button */
134 #ifdef IAUDIO_M3
135 or_l(0x80000000, &GPIO_FUNCTION); /* remote Play button */
136 and_l(~0x80000000, &GPIO_ENABLE);
137 or_l(0x00000202, &GPIO1_FUNCTION); /* main Hold & Play */
139 if ((GPIO1_READ & 0x000000002) == 0)
140 on_button = true;
142 if ((GPIO_READ & 0x80000000) == 0)
143 rc_on_button = true;
144 #elif defined(IAUDIO_M5) || defined(IAUDIO_X5)
145 int data;
147 or_l(0x0e000000, &GPIO_FUNCTION); /* main Hold & Power, remote Play */
148 and_l(~0x0e000000, &GPIO_ENABLE);
150 data = GPIO_READ;
152 if ((data & 0x04000000) == 0)
153 on_button = true;
155 if ((data & 0x02000000) == 0)
156 rc_on_button = true;
157 #endif
159 power_init();
161 system_init();
162 kernel_init();
164 set_cpu_frequency(CPUFREQ_NORMAL);
165 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
167 enable_irq();
168 lcd_init();
169 #ifdef HAVE_REMOTE_LCD
170 lcd_remote_init();
171 #endif
172 backlight_init();
173 font_init();
174 adc_init();
175 button_init();
177 if ((!on_button || button_hold())
178 && (!rc_on_button || remote_button_hold())
179 && !charger_inserted())
181 /* No need to check for USB connection here, as USB is handled
182 * in the cowon loader. */
183 if (on_button || rc_on_button)
184 printf("Hold switch on");
185 shutdown();
188 printf("Rockbox boot loader");
189 printf("Version %s", version);
191 check_battery();
193 rc = ata_init();
194 if(rc)
196 printf("ATA error: %d", rc);
197 sleep(HZ*5);
198 power_off();
201 disk_init();
203 rc = disk_mount_all();
204 if (rc<=0)
206 printf("No partition found");
207 sleep(HZ*5);
208 power_off();
211 printf("Loading firmware");
212 i = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE);
213 printf("Result: %s", strerror(i));
215 if (i < EOK) {
216 printf("Error!");
217 printf("Can't load rockbox.iaudio:");
218 printf(strerror(rc));
219 sleep(HZ*3);
220 power_off();
221 } else {
222 start_firmware();
226 /* These functions are present in the firmware library, but we reimplement
227 them here because the originals do a lot more than we want */
228 void screen_dump(void)