Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Linus Nielsen Feltzing | 4fb389f | 2007-02-22 21:44:12 +0000 | [diff] [blame] | 8 | * $Id$ |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 9 | * |
| 10 | * Copyright (C) 2007 by Linus Nielsen Feltzing |
| 11 | * |
| 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. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | #include "config.h" |
| 20 | |
| 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" |
Jens Arnold | 839ffbf | 2007-08-17 06:59:05 +0000 | [diff] [blame] | 41 | #include "powermgmt.h" |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 42 | #include "file.h" |
| 43 | |
| 44 | #include "pcf50606.h" |
| 45 | #include "common.h" |
| 46 | |
| 47 | #include <stdarg.h> |
| 48 | |
| 49 | /* Maximum allowed firmware image size. 10MB is more than enough */ |
| 50 | #define MAX_LOADSIZE (10*1024*1024) |
| 51 | |
| 52 | #define DRAM_START 0x31000000 |
| 53 | |
| 54 | int usb_screen(void) |
| 55 | { |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | char version[] = APPSVERSION; |
| 60 | |
| 61 | /* Reset the cookie for the crt0 crash check */ |
| 62 | inline void __reset_cookie(void) |
| 63 | { |
| 64 | asm(" move.l #0,%d0"); |
| 65 | asm(" move.l %d0,0x10017ffc"); |
| 66 | } |
| 67 | |
| 68 | void start_firmware(void) |
| 69 | { |
| 70 | asm(" move.w #0x2700,%sr"); |
| 71 | __reset_cookie(); |
| 72 | asm(" move.l %0,%%d0" :: "i"(DRAM_START)); |
| 73 | asm(" movec.l %d0,%vbr"); |
| 74 | asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START)); |
| 75 | asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4))); |
| 76 | asm(" jmp (%a0)"); |
| 77 | } |
| 78 | |
| 79 | void shutdown(void) |
| 80 | { |
| 81 | printf("Shutting down..."); |
| 82 | |
| 83 | /* We need to gracefully spin down the disk to prevent clicks. */ |
| 84 | if (ide_powered()) |
| 85 | { |
| 86 | /* Make sure ATA has been initialized. */ |
| 87 | ata_init(); |
| 88 | |
| 89 | /* And put the disk into sleep immediately. */ |
| 90 | ata_sleepnow(); |
| 91 | } |
| 92 | |
| 93 | sleep(HZ*2); |
| 94 | |
| 95 | /* Backlight OFF */ |
Jens Arnold | ef12b3b | 2007-11-12 18:49:53 +0000 | [diff] [blame] | 96 | _backlight_off(); |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 97 | #ifdef HAVE_REMOTE_LCD |
Jens Arnold | ef12b3b | 2007-11-12 18:49:53 +0000 | [diff] [blame] | 98 | _remote_backlight_off(); |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 99 | #endif |
| 100 | |
| 101 | __reset_cookie(); |
| 102 | power_off(); |
| 103 | } |
| 104 | |
| 105 | /* Print the battery voltage (and a warning message). */ |
| 106 | void check_battery(void) |
| 107 | { |
Jens Arnold | 0fac492 | 2007-08-17 06:45:18 +0000 | [diff] [blame] | 108 | int battery_voltage, batt_int, batt_frac; |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 109 | |
Jens Arnold | 0fac492 | 2007-08-17 06:45:18 +0000 | [diff] [blame] | 110 | battery_voltage = battery_adc_voltage(); |
| 111 | batt_int = battery_voltage / 1000; |
| 112 | batt_frac = (battery_voltage % 1000) / 10; |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 113 | |
| 114 | printf("Batt: %d.%02dV", batt_int, batt_frac); |
| 115 | |
Jens Arnold | 80ded2a | 2008-03-12 23:19:44 +0000 | [diff] [blame] | 116 | if (battery_voltage <= 3500) |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 117 | { |
| 118 | printf("WARNING! BATTERY LOW!!"); |
| 119 | sleep(HZ*2); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | void main(void) |
| 124 | { |
| 125 | int i; |
| 126 | int rc; |
| 127 | bool rc_on_button = false; |
| 128 | bool on_button = false; |
| 129 | bool rec_button = false; |
| 130 | bool hold_status = false; |
| 131 | int data; |
| 132 | |
| 133 | (void)rc_on_button; |
| 134 | (void)on_button; |
| 135 | (void)rec_button; |
| 136 | (void)hold_status; |
| 137 | (void)data; |
Jens Arnold | 80ded2a | 2008-03-12 23:19:44 +0000 | [diff] [blame] | 138 | |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 139 | power_init(); |
| 140 | |
| 141 | system_init(); |
| 142 | kernel_init(); |
| 143 | |
| 144 | set_cpu_frequency(CPUFREQ_NORMAL); |
| 145 | coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS); |
| 146 | |
| 147 | set_irq_level(0); |
| 148 | lcd_init(); |
| 149 | #ifdef HAVE_REMOTE_LCD |
| 150 | lcd_remote_init(); |
| 151 | #endif |
| 152 | backlight_init(); |
| 153 | font_init(); |
| 154 | adc_init(); |
| 155 | button_init(); |
| 156 | |
| 157 | printf("Rockbox boot loader"); |
| 158 | printf("Version %s", version); |
| 159 | |
| 160 | check_battery(); |
Jens Arnold | 80ded2a | 2008-03-12 23:19:44 +0000 | [diff] [blame] | 161 | |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 162 | rc = ata_init(); |
| 163 | if(rc) |
| 164 | { |
| 165 | printf("ATA error: %d", rc); |
| 166 | sleep(HZ*5); |
| 167 | power_off(); |
| 168 | } |
| 169 | |
| 170 | disk_init(); |
| 171 | |
| 172 | rc = disk_mount_all(); |
| 173 | if (rc<=0) |
| 174 | { |
| 175 | printf("No partition found"); |
| 176 | sleep(HZ*5); |
| 177 | power_off(); |
| 178 | } |
| 179 | |
| 180 | printf("Loading firmware"); |
| 181 | i = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE); |
| 182 | printf("Result: %s", strerror(i)); |
| 183 | |
| 184 | if (i < EOK) { |
| 185 | printf("Error!"); |
Jens Arnold | f8ffca4 | 2007-03-05 00:14:14 +0000 | [diff] [blame] | 186 | printf("Can't load rockbox.iaudio:"); |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 187 | printf(strerror(rc)); |
| 188 | sleep(HZ*3); |
| 189 | power_off(); |
| 190 | } else { |
| 191 | start_firmware(); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /* These functions are present in the firmware library, but we reimplement |
| 196 | them here because the originals do a lot more than we want */ |
| 197 | void screen_dump(void) |
| 198 | { |
| 199 | } |