blob: 953e649b9a885b3f495f4ed725bd86ba09b198f3 [file] [log] [blame]
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Linus Nielsen Feltzing4fb389f2007-02-22 21:44:12 +00008 * $Id$
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +00009 *
10 * Copyright (C) 2007 by Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22
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"
Michael Sevakis4ea4cdf2014-08-08 02:28:11 -040031#include "../kernel-internal.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000032#include "storage.h"
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +000033#include "usb.h"
34#include "disk.h"
35#include "font.h"
36#include "adc.h"
37#include "backlight.h"
38#include "backlight-target.h"
39#include "button.h"
40#include "panic.h"
41#include "power.h"
Jens Arnold839ffbf2007-08-17 06:59:05 +000042#include "powermgmt.h"
Michael Sevakisf3d60ae2014-08-29 23:36:11 -040043#include "file_internal.h"
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +000044#include "file.h"
Rafaël Carré5d236b22010-05-27 09:41:46 +000045#include "version.h"
Marcin Bukat0b296912012-03-04 15:34:29 +010046#include "loader_strerror.h"
47#include "rb-loader.h"
Rafaël Carré5d236b22010-05-27 09:41:46 +000048
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +000049
50#include "pcf50606.h"
51#include "common.h"
52
53#include <stdarg.h>
54
55/* Maximum allowed firmware image size. 10MB is more than enough */
56#define MAX_LOADSIZE (10*1024*1024)
57
58#define DRAM_START 0x31000000
59
60int usb_screen(void)
61{
62 return 0;
63}
64
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +000065/* Reset the cookie for the crt0 crash check */
66inline void __reset_cookie(void)
67{
68 asm(" move.l #0,%d0");
69 asm(" move.l %d0,0x10017ffc");
70}
71
72void start_firmware(void)
73{
Jens Arnolded3ff1b2008-03-17 23:47:38 +000074 adc_close();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +000075 asm(" move.w #0x2700,%sr");
76 __reset_cookie();
77 asm(" move.l %0,%%d0" :: "i"(DRAM_START));
78 asm(" movec.l %d0,%vbr");
79 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START));
80 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4)));
81 asm(" jmp (%a0)");
82}
83
84void shutdown(void)
85{
86 printf("Shutting down...");
87
88 /* We need to gracefully spin down the disk to prevent clicks. */
89 if (ide_powered())
90 {
91 /* Make sure ATA has been initialized. */
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000092 storage_init();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +000093
94 /* And put the disk into sleep immediately. */
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000095 storage_sleepnow();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +000096 }
97
98 sleep(HZ*2);
99
100 /* Backlight OFF */
Jens Arnoldef12b3b2007-11-12 18:49:53 +0000101 _backlight_off();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000102#ifdef HAVE_REMOTE_LCD
Jens Arnoldef12b3b2007-11-12 18:49:53 +0000103 _remote_backlight_off();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000104#endif
105
106 __reset_cookie();
107 power_off();
108}
109
110/* Print the battery voltage (and a warning message). */
111void check_battery(void)
112{
Jens Arnold0fac4922007-08-17 06:45:18 +0000113 int battery_voltage, batt_int, batt_frac;
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000114
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000115 battery_voltage = _battery_voltage();
Jens Arnold0fac4922007-08-17 06:45:18 +0000116 batt_int = battery_voltage / 1000;
117 batt_frac = (battery_voltage % 1000) / 10;
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000118
119 printf("Batt: %d.%02dV", batt_int, batt_frac);
120
Jens Arnold80ded2a2008-03-12 23:19:44 +0000121 if (battery_voltage <= 3500)
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000122 {
123 printf("WARNING! BATTERY LOW!!");
124 sleep(HZ*2);
125 }
126}
127
Jens Arnold91ce4b22011-06-19 17:23:18 +0000128#if defined(IAUDIO_M5) || defined(IAUDIO_X5)
129int initial_gpio_read;
130#endif
131
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000132void main(void)
133{
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000134 int rc;
135 bool rc_on_button = false;
136 bool on_button = false;
Jens Arnolded3ff1b2008-03-17 23:47:38 +0000137
138 /* We want to read the buttons as early as possible, before the user
139 releases the ON button */
140
141#ifdef IAUDIO_M3
142 or_l(0x80000000, &GPIO_FUNCTION); /* remote Play button */
143 and_l(~0x80000000, &GPIO_ENABLE);
144 or_l(0x00000202, &GPIO1_FUNCTION); /* main Hold & Play */
145
146 if ((GPIO1_READ & 0x000000002) == 0)
147 on_button = true;
148
149 if ((GPIO_READ & 0x80000000) == 0)
150 rc_on_button = true;
151#elif defined(IAUDIO_M5) || defined(IAUDIO_X5)
Jens Arnolded3ff1b2008-03-17 23:47:38 +0000152 or_l(0x0e000000, &GPIO_FUNCTION); /* main Hold & Power, remote Play */
153 and_l(~0x0e000000, &GPIO_ENABLE);
Jens Arnold91ce4b22011-06-19 17:23:18 +0000154
155 if ((initial_gpio_read & 0x04000000) == 0)
Jens Arnolded3ff1b2008-03-17 23:47:38 +0000156 on_button = true;
Jens Arnold91ce4b22011-06-19 17:23:18 +0000157
158 if ((initial_gpio_read & 0x02000000) == 0)
Jens Arnolded3ff1b2008-03-17 23:47:38 +0000159 rc_on_button = true;
160#endif
161
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000162 power_init();
163
164 system_init();
165 kernel_init();
166
167 set_cpu_frequency(CPUFREQ_NORMAL);
168 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
169
Michael Sevakisaf395f42008-03-26 01:50:41 +0000170 enable_irq();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000171 lcd_init();
172#ifdef HAVE_REMOTE_LCD
173 lcd_remote_init();
174#endif
175 backlight_init();
176 font_init();
177 adc_init();
178 button_init();
Jens Arnolded3ff1b2008-03-17 23:47:38 +0000179
180 if ((!on_button || button_hold())
181 && (!rc_on_button || remote_button_hold())
182 && !charger_inserted())
183 {
184 /* No need to check for USB connection here, as USB is handled
185 * in the cowon loader. */
Jens Arnoldd7009702008-03-18 00:17:21 +0000186 if (on_button || rc_on_button)
187 printf("Hold switch on");
Jens Arnolded3ff1b2008-03-17 23:47:38 +0000188 shutdown();
189 }
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000190
191 printf("Rockbox boot loader");
Michael Sevakis95a4c3a2014-08-28 10:26:45 -0400192 printf("Version %s", rbversion);
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000193
194 check_battery();
Jens Arnold80ded2a2008-03-12 23:19:44 +0000195
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000196 rc = storage_init();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000197 if(rc)
Marcin Bukat0b296912012-03-04 15:34:29 +0100198 error(EATA, rc, true);
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000199
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400200 filesystem_init();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000201
202 rc = disk_mount_all();
203 if (rc<=0)
Marcin Bukat0b296912012-03-04 15:34:29 +0100204 error(EDISK, rc, true);
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000205
206 printf("Loading firmware");
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000207
Marcin Bukat0b296912012-03-04 15:34:29 +0100208 rc = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE);
209
210 if (rc <= EFILE_EMPTY)
211 error(EBOOTFILE, rc, true);
212
213 start_firmware();
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000214}
215
216/* These functions are present in the firmware library, but we reimplement
217 them here because the originals do a lot more than we want */
218void screen_dump(void)
219{
220}