A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Linus Nielsen Feltzing
11 *
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.
16 *
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"
31#include "../kernel-internal.h"
32#include "storage.h"
33#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"
42#include "powermgmt.h"
43#include "file_internal.h"
44#include "file.h"
45#include "version.h"
46#include "loader_strerror.h"
47#include "rb-loader.h"
48
49
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
65/* Reset the cookie for the crt0 crash check */
66static inline void __reset_cookie(void)
67{
68 asm(" move.l #0,%d0");
69 asm(" move.l %d0,0x10017ffc");
70}
71
72void start_firmware(void)
73{
74 adc_close();
75 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. */
92 storage_init();
93
94 /* And put the disk into sleep immediately. */
95 storage_sleepnow();
96 }
97
98 sleep(HZ*2);
99
100 /* Backlight OFF */
101 backlight_hw_off();
102#ifdef HAVE_REMOTE_LCD
103 remote_backlight_hw_off();
104#endif
105
106 __reset_cookie();
107 power_off();
108}
109
110/* Print the battery voltage (and a warning message). */
111void check_battery(void)
112{
113 int battery_voltage, batt_int, batt_frac;
114
115 battery_voltage = _battery_voltage();
116 batt_int = battery_voltage / 1000;
117 batt_frac = (battery_voltage % 1000) / 10;
118
119 printf("Batt: %d.%02dV", batt_int, batt_frac);
120
121 if (battery_voltage <= 3500)
122 {
123 printf("WARNING! BATTERY LOW!!");
124 sleep(HZ*2);
125 }
126}
127
128#if defined(IAUDIO_M5) || defined(IAUDIO_X5)
129int initial_gpio_read;
130#endif
131
132void main(void)
133{
134 int rc;
135 bool rc_on_button = false;
136 bool on_button = false;
137
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)
152 or_l(0x0e000000, &GPIO_FUNCTION); /* main Hold & Power, remote Play */
153 and_l(~0x0e000000, &GPIO_ENABLE);
154
155 if ((initial_gpio_read & 0x04000000) == 0)
156 on_button = true;
157
158 if ((initial_gpio_read & 0x02000000) == 0)
159 rc_on_button = true;
160#endif
161
162 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
170 enable_irq();
171 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();
179
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. */
186 if (on_button || rc_on_button)
187 printf("Hold switch on");
188 shutdown();
189 }
190
191 printf("Rockbox boot loader");
192 printf("Version %s", rbversion);
193
194 check_battery();
195
196 rc = storage_init();
197 if(rc)
198 error(EATA, rc, true);
199
200 filesystem_init();
201
202 rc = disk_mount_all();
203 if (rc<=0)
204 error(EDISK, rc, true);
205
206 printf("Loading firmware");
207
208 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();
214}