Replace bitfield for tagcache tag sets with array of char on SH.
[kugel-rb.git] / bootloader / iaudio_coldfire.c
bloba3b318bbbc54fb58c86a0b1bb00be4d53bf52d5c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Linus Nielsen Feltzing
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include "inttypes.h"
26 #include "string.h"
27 #include "cpu.h"
28 #include "system.h"
29 #include "lcd.h"
30 #include "lcd-remote.h"
31 #include "kernel.h"
32 #include "thread.h"
33 #include "storage.h"
34 #include "usb.h"
35 #include "disk.h"
36 #include "font.h"
37 #include "adc.h"
38 #include "backlight.h"
39 #include "backlight-target.h"
40 #include "button.h"
41 #include "panic.h"
42 #include "power.h"
43 #include "powermgmt.h"
44 #include "file.h"
46 #include "pcf50606.h"
47 #include "common.h"
49 #include <stdarg.h>
51 /* Maximum allowed firmware image size. 10MB is more than enough */
52 #define MAX_LOADSIZE (10*1024*1024)
54 #define DRAM_START 0x31000000
56 int usb_screen(void)
58 return 0;
61 char version[] = APPSVERSION;
63 /* Reset the cookie for the crt0 crash check */
64 inline void __reset_cookie(void)
66 asm(" move.l #0,%d0");
67 asm(" move.l %d0,0x10017ffc");
70 void start_firmware(void)
72 adc_close();
73 asm(" move.w #0x2700,%sr");
74 __reset_cookie();
75 asm(" move.l %0,%%d0" :: "i"(DRAM_START));
76 asm(" movec.l %d0,%vbr");
77 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START));
78 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4)));
79 asm(" jmp (%a0)");
82 void shutdown(void)
84 printf("Shutting down...");
86 /* We need to gracefully spin down the disk to prevent clicks. */
87 if (ide_powered())
89 /* Make sure ATA has been initialized. */
90 storage_init();
92 /* And put the disk into sleep immediately. */
93 storage_sleepnow();
96 sleep(HZ*2);
98 /* Backlight OFF */
99 _backlight_off();
100 #ifdef HAVE_REMOTE_LCD
101 _remote_backlight_off();
102 #endif
104 __reset_cookie();
105 power_off();
108 /* Print the battery voltage (and a warning message). */
109 void check_battery(void)
111 int battery_voltage, batt_int, batt_frac;
113 battery_voltage = battery_adc_voltage();
114 batt_int = battery_voltage / 1000;
115 batt_frac = (battery_voltage % 1000) / 10;
117 printf("Batt: %d.%02dV", batt_int, batt_frac);
119 if (battery_voltage <= 3500)
121 printf("WARNING! BATTERY LOW!!");
122 sleep(HZ*2);
126 void main(void)
128 int i;
129 int rc;
130 bool rc_on_button = false;
131 bool on_button = false;
133 /* We want to read the buttons as early as possible, before the user
134 releases the ON button */
136 #ifdef IAUDIO_M3
137 or_l(0x80000000, &GPIO_FUNCTION); /* remote Play button */
138 and_l(~0x80000000, &GPIO_ENABLE);
139 or_l(0x00000202, &GPIO1_FUNCTION); /* main Hold & Play */
141 if ((GPIO1_READ & 0x000000002) == 0)
142 on_button = true;
144 if ((GPIO_READ & 0x80000000) == 0)
145 rc_on_button = true;
146 #elif defined(IAUDIO_M5) || defined(IAUDIO_X5)
147 int data;
149 or_l(0x0e000000, &GPIO_FUNCTION); /* main Hold & Power, remote Play */
150 and_l(~0x0e000000, &GPIO_ENABLE);
152 data = GPIO_READ;
154 if ((data & 0x04000000) == 0)
155 on_button = true;
157 if ((data & 0x02000000) == 0)
158 rc_on_button = true;
159 #endif
161 power_init();
163 system_init();
164 kernel_init();
166 set_cpu_frequency(CPUFREQ_NORMAL);
167 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
169 enable_irq();
170 lcd_init();
171 #ifdef HAVE_REMOTE_LCD
172 lcd_remote_init();
173 #endif
174 backlight_init();
175 font_init();
176 adc_init();
177 button_init();
179 if ((!on_button || button_hold())
180 && (!rc_on_button || remote_button_hold())
181 && !charger_inserted())
183 /* No need to check for USB connection here, as USB is handled
184 * in the cowon loader. */
185 if (on_button || rc_on_button)
186 printf("Hold switch on");
187 shutdown();
190 printf("Rockbox boot loader");
191 printf("Version %s", version);
193 check_battery();
195 rc = storage_init();
196 if(rc)
198 printf("ATA error: %d", rc);
199 sleep(HZ*5);
200 power_off();
203 disk_init();
205 rc = disk_mount_all();
206 if (rc<=0)
208 printf("No partition found");
209 sleep(HZ*5);
210 power_off();
213 printf("Loading firmware");
214 i = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE);
215 printf("Result: %s", strerror(i));
217 if (i < EOK) {
218 printf("Error!");
219 printf("Can't load " BOOTFILE ": ");
220 printf(strerror(rc));
221 sleep(HZ*3);
222 power_off();
223 } else {
224 start_firmware();
228 /* These functions are present in the firmware library, but we reimplement
229 them here because the originals do a lot more than we want */
230 void screen_dump(void)