diff options
29 files changed, 3756 insertions, 0 deletions
diff --git a/apps/keymaps/keymap-mpio-hd200.c b/apps/keymaps/keymap-mpio-hd200.c new file mode 100644 index 0000000000..95dec41d85 --- /dev/null +++ b/apps/keymaps/keymap-mpio-hd200.c | |||
@@ -0,0 +1,172 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | #include "action.h" | ||
23 | #include "button.h" | ||
24 | #include "settings.h" | ||
25 | |||
26 | /* | ||
27 | * The format of the list is as follows | ||
28 | * { Action Code, Button code, Prereq button code } | ||
29 | * if there's no need to check the previous button's value, use BUTTON_NONE | ||
30 | * Insert LAST_ITEM_IN_LIST at the end of each mapping | ||
31 | */ | ||
32 | |||
33 | /* CONTEXT_CUSTOM's used in this file... | ||
34 | |||
35 | CONTEXT_CUSTOM|CONTEXT_TREE = the standard list/tree defines (without directions) | ||
36 | |||
37 | |||
38 | */ | ||
39 | |||
40 | static const struct button_mapping button_context_standard[] = { | ||
41 | { ACTION_STD_PREV, BUTTON_PREV, BUTTON_NONE }, | ||
42 | { ACTION_STD_PREVREPEAT, BUTTON_PREV|BUTTON_REPEAT, BUTTON_NONE }, | ||
43 | { ACTION_STD_NEXT, BUTTON_NEXT, BUTTON_NONE }, | ||
44 | { ACTION_STD_NEXTREPEAT, BUTTON_NEXT|BUTTON_REPEAT, BUTTON_NONE }, | ||
45 | { ACTION_STD_CANCEL, BUTTON_REC|BUTTON_REL, BUTTON_REC }, | ||
46 | { ACTION_STD_OK, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT }, | ||
47 | { ACTION_STD_MENU, BUTTON_REC|BUTTON_REPEAT, BUTTON_REC }, | ||
48 | { ACTION_STD_QUICKSCREEN, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_PLAY }, | ||
49 | { ACTION_STD_CONTEXT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT }, | ||
50 | |||
51 | LAST_ITEM_IN_LIST | ||
52 | }; /* button_context_standard */ | ||
53 | |||
54 | static const struct button_mapping button_context_tree[] = { | ||
55 | { ACTION_TREE_WPS, BUTTON_PLAY|BUTTON_REL, BUTTON_PLAY }, | ||
56 | { ACTION_TREE_STOP, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_PLAY }, | ||
57 | |||
58 | LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) | ||
59 | }; /* button_context_tree */ | ||
60 | |||
61 | static const struct button_mapping button_context_tree_scroll_lr[] = { | ||
62 | { ACTION_NONE, BUTTON_PREV, BUTTON_NONE }, | ||
63 | { ACTION_STD_CANCEL, BUTTON_PREV|BUTTON_REL, BUTTON_PREV }, | ||
64 | { ACTION_TREE_ROOT_INIT, BUTTON_PREV|BUTTON_REPEAT, BUTTON_PREV }, | ||
65 | { ACTION_TREE_PGLEFT, BUTTON_PREV|BUTTON_REPEAT, BUTTON_NONE }, | ||
66 | { ACTION_TREE_PGLEFT, BUTTON_PREV|BUTTON_REL, BUTTON_PREV|BUTTON_REPEAT }, | ||
67 | { ACTION_NONE, BUTTON_NEXT, BUTTON_NONE }, | ||
68 | { ACTION_STD_OK, BUTTON_NEXT|BUTTON_REL, BUTTON_NEXT }, | ||
69 | { ACTION_TREE_PGRIGHT, BUTTON_NEXT|BUTTON_REPEAT, BUTTON_NONE }, | ||
70 | { ACTION_TREE_PGRIGHT, BUTTON_NEXT|BUTTON_REL, BUTTON_NEXT|BUTTON_REPEAT }, | ||
71 | LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE), | ||
72 | }; /* button_context_tree_scroll_lr */ | ||
73 | |||
74 | static const struct button_mapping button_context_wps[] = { | ||
75 | { ACTION_WPS_PLAY, BUTTON_PLAY|BUTTON_REL, BUTTON_PLAY }, | ||
76 | { ACTION_WPS_STOP, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_PLAY }, | ||
77 | { ACTION_WPS_SKIPPREV, BUTTON_PREV|BUTTON_REL, BUTTON_PREV }, | ||
78 | { ACTION_WPS_SEEKBACK, BUTTON_PREV|BUTTON_REPEAT, BUTTON_NONE }, | ||
79 | { ACTION_WPS_STOPSEEK, BUTTON_PREV|BUTTON_REL, BUTTON_PREV|BUTTON_REPEAT }, | ||
80 | { ACTION_WPS_SKIPNEXT, BUTTON_NEXT|BUTTON_REL, BUTTON_NEXT }, | ||
81 | { ACTION_WPS_SEEKFWD, BUTTON_NEXT|BUTTON_REPEAT, BUTTON_NONE }, | ||
82 | { ACTION_WPS_STOPSEEK, BUTTON_NEXT|BUTTON_REL, BUTTON_NEXT|BUTTON_REPEAT }, | ||
83 | { ACTION_WPS_VOLDOWN, BUTTON_VOL_DOWN, BUTTON_NONE }, | ||
84 | { ACTION_WPS_VOLDOWN, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, | ||
85 | { ACTION_WPS_VOLUP, BUTTON_VOL_UP, BUTTON_NONE }, | ||
86 | { ACTION_WPS_VOLUP, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, | ||
87 | { ACTION_WPS_BROWSE, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT }, | ||
88 | { ACTION_WPS_CONTEXT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT }, | ||
89 | { ACTION_WPS_MENU, BUTTON_REC|BUTTON_REL, BUTTON_REC }, | ||
90 | { ACTION_WPS_QUICKSCREEN, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT }, | ||
91 | |||
92 | LAST_ITEM_IN_LIST, | ||
93 | }; /* button_context_wps */ | ||
94 | |||
95 | static const struct button_mapping button_context_settings[] = { | ||
96 | { ACTION_SETTINGS_INC, BUTTON_VOL_UP, BUTTON_NONE }, | ||
97 | { ACTION_SETTINGS_INCREPEAT, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, | ||
98 | { ACTION_SETTINGS_DEC, BUTTON_VOL_DOWN, BUTTON_NONE }, | ||
99 | { ACTION_SETTINGS_DECREPEAT, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, | ||
100 | { ACTION_STD_PREV, BUTTON_PREV, BUTTON_NONE }, | ||
101 | { ACTION_STD_PREVREPEAT, BUTTON_PREV|BUTTON_REPEAT, BUTTON_NONE }, | ||
102 | { ACTION_STD_NEXT, BUTTON_NEXT, BUTTON_NONE }, | ||
103 | { ACTION_STD_NEXTREPEAT, BUTTON_NEXT|BUTTON_REPEAT, BUTTON_NONE }, | ||
104 | { ACTION_STD_OK, BUTTON_SELECT|BUTTON_REL, BUTTON_NONE }, | ||
105 | { ACTION_STD_CANCEL, BUTTON_REC|BUTTON_REL, BUTTON_REC }, | ||
106 | |||
107 | LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) | ||
108 | }; /* button_context_settings */ | ||
109 | |||
110 | static const struct button_mapping button_context_yesno[] = { | ||
111 | { ACTION_YESNO_ACCEPT, BUTTON_SELECT, BUTTON_NONE }, | ||
112 | LAST_ITEM_IN_LIST | ||
113 | }; /* button_context_yesno */ | ||
114 | |||
115 | static const struct button_mapping button_context_bmark[] = { | ||
116 | { ACTION_BMS_DELETE, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT }, | ||
117 | LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST), | ||
118 | }; /* button_context_bmark */ | ||
119 | |||
120 | static const struct button_mapping button_context_quickscreen[] = { | ||
121 | { ACTION_QS_TOP, BUTTON_SELECT, BUTTON_NONE }, | ||
122 | { ACTION_QS_TOP, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE }, | ||
123 | { ACTION_QS_DOWN, BUTTON_PLAY, BUTTON_NONE }, | ||
124 | { ACTION_QS_DOWN, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_NONE }, | ||
125 | { ACTION_QS_LEFT, BUTTON_PREV, BUTTON_NONE }, | ||
126 | { ACTION_QS_LEFT, BUTTON_PREV|BUTTON_REPEAT, BUTTON_NONE }, | ||
127 | { ACTION_QS_RIGHT, BUTTON_NEXT, BUTTON_NONE }, | ||
128 | { ACTION_QS_RIGHT, BUTTON_NEXT|BUTTON_REPEAT, BUTTON_NONE }, | ||
129 | { ACTION_STD_CANCEL, BUTTON_REC, BUTTON_NONE }, | ||
130 | |||
131 | LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) | ||
132 | }; /* button_context_quickscreen */ | ||
133 | |||
134 | static const struct button_mapping button_context_pitchscreen[] = { | ||
135 | { ACTION_PS_INC_SMALL, BUTTON_VOL_UP, BUTTON_NONE }, | ||
136 | { ACTION_PS_INC_BIG, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, | ||
137 | { ACTION_PS_DEC_SMALL, BUTTON_VOL_DOWN, BUTTON_NONE }, | ||
138 | { ACTION_PS_DEC_BIG, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, | ||
139 | { ACTION_PS_NUDGE_LEFT, BUTTON_PREV, BUTTON_NONE }, | ||
140 | { ACTION_PS_NUDGE_LEFTOFF, BUTTON_PREV|BUTTON_REL, BUTTON_NONE }, | ||
141 | { ACTION_PS_NUDGE_RIGHT, BUTTON_NEXT, BUTTON_NONE }, | ||
142 | { ACTION_PS_NUDGE_RIGHTOFF, BUTTON_NEXT|BUTTON_REL, BUTTON_NONE }, | ||
143 | { ACTION_PS_TOGGLE_MODE, BUTTON_PLAY, BUTTON_NONE }, | ||
144 | { ACTION_PS_RESET, BUTTON_SELECT, BUTTON_NONE }, | ||
145 | { ACTION_PS_EXIT, BUTTON_REC, BUTTON_NONE }, | ||
146 | { ACTION_PS_SLOWER, BUTTON_PREV|BUTTON_REPEAT, BUTTON_NONE }, | ||
147 | { ACTION_PS_FASTER, BUTTON_NEXT|BUTTON_REPEAT, BUTTON_NONE }, | ||
148 | |||
149 | LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) | ||
150 | }; /* button_context_pitchscreen */ | ||
151 | |||
152 | const struct button_mapping* get_context_mapping(int context) | ||
153 | { | ||
154 | switch (context) | ||
155 | { | ||
156 | case CONTEXT_STD: | ||
157 | return button_context_standard; | ||
158 | case CONTEXT_WPS: | ||
159 | return button_context_wps; | ||
160 | |||
161 | case CONTEXT_TREE: | ||
162 | case CONTEXT_LIST: | ||
163 | case CONTEXT_MAINMENU: | ||
164 | |||
165 | case CONTEXT_SETTINGS: | ||
166 | case CONTEXT_SETTINGS|CONTEXT_REMOTE: | ||
167 | default: | ||
168 | return button_context_standard; | ||
169 | } | ||
170 | return button_context_standard; | ||
171 | } | ||
172 | |||
diff --git a/bootloader/mpio_hd200.c b/bootloader/mpio_hd200.c new file mode 100644 index 0000000000..68152f3c2d --- /dev/null +++ b/bootloader/mpio_hd200.c | |||
@@ -0,0 +1,459 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 "kernel.h" | ||
31 | #include "thread.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.h" | ||
44 | |||
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 | #define BOOTMENU_TIMEOUT (10*HZ) | ||
55 | #define BOOTMENU_OPTIONS 3 | ||
56 | |||
57 | /* From common.c */ | ||
58 | extern int line; | ||
59 | static const char *bootmenu_options[] = { | ||
60 | "Boot rockbox", | ||
61 | "Boot MPIO firmware", | ||
62 | "Shutdown" | ||
63 | }; | ||
64 | |||
65 | enum option_t { | ||
66 | rockbox, | ||
67 | mpio_firmware, | ||
68 | shutdown | ||
69 | }; | ||
70 | |||
71 | int usb_screen(void) | ||
72 | { | ||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | char version[] = APPSVERSION; | ||
77 | |||
78 | bool _charger_inserted(void) | ||
79 | { | ||
80 | return (GPIO1_READ & (1<<14)) ? false : true; | ||
81 | } | ||
82 | |||
83 | bool _battery_full(void) | ||
84 | { | ||
85 | return (GPIO_READ & (1<<30)) ? true : false; | ||
86 | } | ||
87 | |||
88 | /* Reset the cookie for the crt0 crash check */ | ||
89 | inline void __reset_cookie(void) | ||
90 | { | ||
91 | asm(" move.l #0,%d0"); | ||
92 | asm(" move.l %d0,0x10017ffc"); | ||
93 | } | ||
94 | |||
95 | void start_rockbox(void) | ||
96 | { | ||
97 | adc_close(); | ||
98 | asm(" move.w #0x2700,%sr"); | ||
99 | __reset_cookie(); | ||
100 | asm(" move.l %0,%%d0" :: "i"(DRAM_START)); | ||
101 | asm(" movec.l %d0,%vbr"); | ||
102 | asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START)); | ||
103 | asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4))); | ||
104 | asm(" jmp (%a0)"); | ||
105 | } | ||
106 | |||
107 | void start_mpio_firmware(void) | ||
108 | { | ||
109 | asm(" move.w #0x2700,%sr"); | ||
110 | __reset_cookie(); | ||
111 | asm(" movec.l %d0,%vbr"); | ||
112 | asm(" move.l 0,%sp"); | ||
113 | asm(" jmp 8"); | ||
114 | } | ||
115 | |||
116 | void __reset(void) | ||
117 | { | ||
118 | asm(" move.w #0x2700,%sr"); | ||
119 | __reset_cookie(); | ||
120 | asm(" movec.l %d0,%vbr"); | ||
121 | asm(" move.l (0), %sp"); | ||
122 | asm(" movea.l (4),%a0"); | ||
123 | asm(" jmp (%a0)"); | ||
124 | } | ||
125 | |||
126 | void __shutdown(void) | ||
127 | { | ||
128 | /* We need to gracefully spin down the disk to prevent clicks. */ | ||
129 | if (ide_powered()) | ||
130 | { | ||
131 | /* Make sure ATA has been initialized. */ | ||
132 | storage_init(); | ||
133 | |||
134 | /* And put the disk into sleep immediately. */ | ||
135 | storage_sleepnow(); | ||
136 | } | ||
137 | |||
138 | /* Backlight OFF */ | ||
139 | _backlight_off(); | ||
140 | __reset_cookie(); | ||
141 | |||
142 | if (_charger_inserted()) | ||
143 | { | ||
144 | /* reset instead of power_off() */ | ||
145 | __reset(); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | power_off(); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | /* Print the battery voltage (and a warning message). */ | ||
154 | void check_battery(void) | ||
155 | { | ||
156 | |||
157 | int battery_voltage, batt_int, batt_frac; | ||
158 | |||
159 | battery_voltage = battery_adc_voltage(); | ||
160 | batt_int = battery_voltage / 1000; | ||
161 | batt_frac = (battery_voltage % 1000) / 10; | ||
162 | |||
163 | printf("Battery: %d.%02dV", batt_int, batt_frac); | ||
164 | |||
165 | if (battery_voltage <= 3500) | ||
166 | { | ||
167 | printf("WARNING! BATTERY LOW!!"); | ||
168 | sleep(HZ*2); | ||
169 | } | ||
170 | |||
171 | } | ||
172 | |||
173 | |||
174 | void lcd_putstring_centered(const char *string) | ||
175 | { | ||
176 | int w,h; | ||
177 | font_getstringsize(string, &w, &h, FONT_SYSFIXED); | ||
178 | lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, string); | ||
179 | } | ||
180 | |||
181 | void bootmenu(void) | ||
182 | { | ||
183 | int rc; | ||
184 | enum option_t i; | ||
185 | enum option_t option = rockbox; | ||
186 | int button; | ||
187 | const char select[] = "->"; | ||
188 | long start_tick = current_tick; | ||
189 | |||
190 | /* backbone of menu */ | ||
191 | /* run the loader */ | ||
192 | printf("Rockbox boot loader"); | ||
193 | printf("Ver: %s", version); | ||
194 | |||
195 | check_battery(); | ||
196 | |||
197 | printf(""); | ||
198 | printf("========================="); | ||
199 | |||
200 | line += BOOTMENU_OPTIONS+2; /* skip lines */ | ||
201 | |||
202 | printf("========================="); | ||
203 | printf(""); | ||
204 | printf(" [FF] [PREV] to move "); | ||
205 | printf(" [PLAY] to confirm "); | ||
206 | |||
207 | /* content of menu and keys handling */ | ||
208 | while (TIME_BEFORE(current_tick,start_tick + BOOTMENU_TIMEOUT)) | ||
209 | { | ||
210 | /* Draw the menu. */ | ||
211 | line = 6; /* move below header */ | ||
212 | |||
213 | for (i=0;i<BOOTMENU_OPTIONS;i++) | ||
214 | { | ||
215 | if (i != option) | ||
216 | printf(" %s",bootmenu_options[i]); | ||
217 | else | ||
218 | printf("%s %s",select,bootmenu_options[i]); | ||
219 | } | ||
220 | |||
221 | line = 15; | ||
222 | |||
223 | printf("Time left: %ds",(BOOTMENU_TIMEOUT - | ||
224 | (current_tick - start_tick))/HZ); | ||
225 | |||
226 | lcd_update(); | ||
227 | |||
228 | button = button_get_w_tmo(HZ); | ||
229 | |||
230 | switch (button) | ||
231 | { | ||
232 | case BUTTON_PREV: | ||
233 | if (option > rockbox) | ||
234 | option--; | ||
235 | else | ||
236 | option = shutdown; | ||
237 | break; | ||
238 | |||
239 | case BUTTON_NEXT: | ||
240 | if (option < shutdown) | ||
241 | option++; | ||
242 | else | ||
243 | option = rockbox; | ||
244 | break; | ||
245 | |||
246 | case BUTTON_PLAY: | ||
247 | case (BUTTON_PLAY|BUTTON_REC): | ||
248 | reset_screen(); | ||
249 | |||
250 | switch (option) | ||
251 | { | ||
252 | case rockbox: | ||
253 | rc = storage_init(); | ||
254 | if(rc) | ||
255 | { | ||
256 | printf("ATA error: %d", rc); | ||
257 | sleep(HZ*5); | ||
258 | __shutdown(); | ||
259 | } | ||
260 | |||
261 | disk_init(); | ||
262 | |||
263 | rc = disk_mount_all(); | ||
264 | if (rc<=0) | ||
265 | { | ||
266 | printf("No partition found"); | ||
267 | sleep(HZ*5); | ||
268 | __shutdown(); | ||
269 | } | ||
270 | |||
271 | printf("Loading firmware"); | ||
272 | rc = load_firmware((unsigned char *)DRAM_START, | ||
273 | BOOTFILE, MAX_LOADSIZE); | ||
274 | printf("Result: %s", strerror(rc)); | ||
275 | |||
276 | if (rc < EOK) | ||
277 | { | ||
278 | printf("Error!"); | ||
279 | printf("Can't load " BOOTFILE ": "); | ||
280 | printf(strerror(rc)); | ||
281 | sleep(HZ*5); | ||
282 | __shutdown(); | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | start_rockbox(); | ||
287 | } | ||
288 | |||
289 | break; | ||
290 | |||
291 | case mpio_firmware: | ||
292 | start_mpio_firmware(); | ||
293 | break; | ||
294 | |||
295 | default: | ||
296 | __shutdown(); | ||
297 | break; | ||
298 | } | ||
299 | } | ||
300 | } | ||
301 | /* timeout */ | ||
302 | __shutdown(); | ||
303 | } | ||
304 | |||
305 | void main(void) | ||
306 | { | ||
307 | /* messages */ | ||
308 | const char usb_connect_msg[] = "Bootloader USB mode"; | ||
309 | const char charging_msg[] = "Charging..."; | ||
310 | const char complete_msg[] = "Charging complete"; | ||
311 | const char hold_msg[] = "Hold switch on"; | ||
312 | const char shutdown_msg[] = "Shutting down..."; | ||
313 | |||
314 | /* helper variables for messages */ | ||
315 | bool blink_toggle = false; | ||
316 | const char *msg; | ||
317 | |||
318 | bool on_button = false; | ||
319 | int button; | ||
320 | |||
321 | /* We want to read the buttons as early as possible, before the user | ||
322 | releases the ON button */ | ||
323 | |||
324 | or_l( ((1<<24)|(1<<4)), &GPIO1_FUNCTION); /* main Hold & Play */ | ||
325 | and_l( ~((1<<24)|(1<<4)), &GPIO1_ENABLE); /* HiZ */ | ||
326 | |||
327 | if (GPIO1_READ & (1<<24)) | ||
328 | on_button = true; | ||
329 | |||
330 | power_init(); | ||
331 | |||
332 | system_init(); | ||
333 | kernel_init(); | ||
334 | |||
335 | set_cpu_frequency(CPUFREQ_NORMAL); | ||
336 | coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS); | ||
337 | |||
338 | enable_irq(); | ||
339 | lcd_init(); | ||
340 | |||
341 | backlight_init(); | ||
342 | font_init(); | ||
343 | lcd_setfont(FONT_SYSFIXED); | ||
344 | |||
345 | adc_init(); | ||
346 | button_init(); | ||
347 | usb_init(); | ||
348 | |||
349 | /* handle charging */ | ||
350 | if( _charger_inserted()) | ||
351 | { | ||
352 | or_l((1<<15),&GPIO_OUT); | ||
353 | |||
354 | cpu_idle_mode(true); | ||
355 | |||
356 | while( _charger_inserted() && | ||
357 | usb_detect() != USB_INSERTED && | ||
358 | !on_button) | ||
359 | { | ||
360 | button = button_get_w_tmo(HZ); | ||
361 | |||
362 | switch(button) | ||
363 | { | ||
364 | case BUTTON_ON: | ||
365 | on_button = true; | ||
366 | reset_screen(); | ||
367 | break; | ||
368 | |||
369 | case BUTTON_NONE: /* Timeout */ | ||
370 | |||
371 | if(!_battery_full()) | ||
372 | { | ||
373 | /* To be replaced with a nice animation */ | ||
374 | blink_toggle = !blink_toggle; | ||
375 | msg = charging_msg; | ||
376 | } | ||
377 | else | ||
378 | { | ||
379 | blink_toggle = true; | ||
380 | msg = complete_msg; | ||
381 | } | ||
382 | |||
383 | reset_screen(); | ||
384 | if(blink_toggle) | ||
385 | lcd_putstring_centered(msg); | ||
386 | |||
387 | check_battery(); | ||
388 | break; | ||
389 | } | ||
390 | |||
391 | } | ||
392 | cpu_idle_mode(false); | ||
393 | } | ||
394 | |||
395 | /* handle USB in bootloader */ | ||
396 | if (usb_detect() == USB_INSERTED) | ||
397 | { | ||
398 | ide_power_enable(true); | ||
399 | sleep(HZ/20); | ||
400 | usb_enable(true); | ||
401 | cpu_idle_mode(true); | ||
402 | |||
403 | while (usb_detect() == USB_INSERTED) | ||
404 | { | ||
405 | line = 0; | ||
406 | |||
407 | reset_screen(); | ||
408 | |||
409 | if(blink_toggle) | ||
410 | { | ||
411 | lcd_putstring_centered(usb_connect_msg); | ||
412 | } | ||
413 | |||
414 | check_battery(); | ||
415 | blink_toggle = !blink_toggle; | ||
416 | |||
417 | storage_spin(); /* Prevent the drive from spinning down */ | ||
418 | sleep(HZ); | ||
419 | } | ||
420 | |||
421 | cpu_idle_mode(false); | ||
422 | usb_enable(false); | ||
423 | |||
424 | sleep(HZ); | ||
425 | reset_screen(); | ||
426 | lcd_update(); | ||
427 | } | ||
428 | |||
429 | /* handle ON button press */ | ||
430 | if (on_button) | ||
431 | { | ||
432 | if (button_hold() && | ||
433 | !_charger_inserted() && | ||
434 | usb_detect() != USB_INSERTED) | ||
435 | { | ||
436 | lcd_putstring_centered(hold_msg); | ||
437 | lcd_update(); | ||
438 | sleep(HZ*3); | ||
439 | __shutdown(); | ||
440 | } | ||
441 | |||
442 | } | ||
443 | else | ||
444 | { | ||
445 | lcd_putstring_centered(shutdown_msg); | ||
446 | lcd_update(); | ||
447 | sleep(HZ*3); | ||
448 | __shutdown(); | ||
449 | } | ||
450 | |||
451 | |||
452 | bootmenu(); | ||
453 | } | ||
454 | |||
455 | /* These functions are present in the firmware library, but we reimplement | ||
456 | them here because the originals do a lot more than we want */ | ||
457 | void screen_dump(void) | ||
458 | { | ||
459 | } | ||
diff --git a/firmware/export/config/mpiohd200.h b/firmware/export/config/mpiohd200.h new file mode 100644 index 0000000000..369f443cb2 --- /dev/null +++ b/firmware/export/config/mpiohd200.h | |||
@@ -0,0 +1,191 @@ | |||
1 | /* | ||
2 | * This config file is for MPIO HD200 | ||
3 | */ | ||
4 | #define TARGET_TREE /* this target is using the target tree system */ | ||
5 | |||
6 | /* For Rolo and boot loader */ | ||
7 | #define MODEL_NUMBER 69 | ||
8 | |||
9 | #define MODEL_NAME "MPIO HD200" | ||
10 | |||
11 | /* define this if you use an ATA controller */ | ||
12 | #define CONFIG_STORAGE STORAGE_ATA | ||
13 | #define HAVE_LBA48 | ||
14 | |||
15 | /* define this if you have recording possibility */ | ||
16 | /* not implemented yet | ||
17 | * #define HAVE_RECORDING | ||
18 | */ | ||
19 | |||
20 | |||
21 | /* Define bitmask of input sources - recordable bitmask can be defined | ||
22 | * explicitly if different | ||
23 | * not implemented yet | ||
24 | */ | ||
25 | |||
26 | #define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN | SRC_CAP_FMRADIO) | ||
27 | |||
28 | |||
29 | /* define the bitmask of hardware sample rates */ | ||
30 | #define HW_SAMPR_CAPS (SAMPR_CAP_88 | SAMPR_CAP_44 | SAMPR_CAP_22 | SAMPR_CAP_11) | ||
31 | |||
32 | /* define the bitmask of recording sample rates | ||
33 | * not implemented yet | ||
34 | *#define REC_SAMPR_CAPS (SAMPR_CAP_88 | SAMPR_CAP_44 | SAMPR_CAP_22 | SAMPR_CAP_11) | ||
35 | */ | ||
36 | |||
37 | /* define this if you have a bitmap LCD display */ | ||
38 | #define HAVE_LCD_BITMAP | ||
39 | |||
40 | /* define this if you want album art for this target */ | ||
41 | #define HAVE_ALBUMART | ||
42 | |||
43 | /* define this to enable bitmap scaling */ | ||
44 | #define HAVE_BMP_SCALING | ||
45 | |||
46 | /* define this to enable JPEG decoding */ | ||
47 | #define HAVE_JPEG | ||
48 | |||
49 | /* define this if you can flip your LCD */ | ||
50 | #define HAVE_LCD_FLIP | ||
51 | |||
52 | /* define this if you can invert the colours on your LCD */ | ||
53 | #define HAVE_LCD_INVERT | ||
54 | |||
55 | /* define this if you have access to the quickscreen */ | ||
56 | #define HAVE_QUICKSCREEN | ||
57 | |||
58 | /* define this if you have access to the pitchscreen */ | ||
59 | #define HAVE_PITCHSCREEN | ||
60 | |||
61 | /* define this if you would like tagcache to build on this target */ | ||
62 | #define HAVE_TAGCACHE | ||
63 | |||
64 | /* LCD dimensions */ | ||
65 | #define LCD_WIDTH 128 | ||
66 | #define LCD_HEIGHT 128 | ||
67 | #define LCD_DEPTH 2 | ||
68 | |||
69 | #define LCD_PIXELFORMAT VERTICAL_INTERLEAVED | ||
70 | |||
71 | /* Display colours, for screenshots and sim (0xRRGGBB) */ | ||
72 | #define LCD_DARKCOLOR 0x000000 | ||
73 | #define LCD_BRIGHTCOLOR 0x5a915a | ||
74 | #define LCD_BL_DARKCOLOR 0x000000 | ||
75 | #define LCD_BL_BRIGHTCOLOR 0x82b4fa | ||
76 | |||
77 | #define CONFIG_KEYPAD MPIO_HD200_PAD | ||
78 | |||
79 | #define AB_REPEAT_ENABLE 1 | ||
80 | #define ACTION_WPSAB_SINGLE ACTION_WPS_BROWSE | ||
81 | |||
82 | /* Define this if you do software codec */ | ||
83 | #define CONFIG_CODEC SWCODEC | ||
84 | |||
85 | #define CONFIG_LCD LCD_TL0350A | ||
86 | #define HAVE_LCD_SHUTDOWN | ||
87 | |||
88 | /* Define this for LCD backlight available */ | ||
89 | #define HAVE_BACKLIGHT | ||
90 | #define HAVE_BACKLIGHT_BRIGHTNESS | ||
91 | #define MIN_BRIGHTNESS_SETTING 0 | ||
92 | #define MAX_BRIGHTNESS_SETTING 31 | ||
93 | #define DEFAULT_BRIGHTNESS_SETTING 20 | ||
94 | |||
95 | |||
96 | /* define this if you have a disk storage, i.e. something | ||
97 | that needs spinups and can cause skips when shaked */ | ||
98 | #define HAVE_DISK_STORAGE | ||
99 | |||
100 | /* Define this if you have a software controlled poweroff */ | ||
101 | #define HAVE_SW_POWEROFF | ||
102 | |||
103 | /* The number of bytes reserved for loadable codecs */ | ||
104 | #define CODEC_SIZE 0x100000 | ||
105 | |||
106 | /* The number of bytes reserved for loadable plugins */ | ||
107 | #define PLUGIN_BUFFER_SIZE 0x80000 | ||
108 | |||
109 | /* FM Tuner | ||
110 | * turn off for now | ||
111 | */ | ||
112 | #define CONFIG_TUNER TEA5767 | ||
113 | #define CONFIG_TUNER_XTAL 32768 | ||
114 | |||
115 | |||
116 | /* we have WM8750 codec in I2S slave mode */ | ||
117 | #define HAVE_WM8750 | ||
118 | #define CODEC_SLAVE | ||
119 | |||
120 | #define BATTERY_CAPACITY_DEFAULT 950 /* default battery capacity */ | ||
121 | #define BATTERY_CAPACITY_MIN 950 /* min. capacity selectable */ | ||
122 | #define BATTERY_CAPACITY_MAX 2250 /* max. capacity selectable */ | ||
123 | #define BATTERY_CAPACITY_INC 50 /* capacity increment */ | ||
124 | #define BATTERY_TYPES_COUNT 1 /* only one type */ | ||
125 | |||
126 | #define CONFIG_CHARGING CHARGING_MONITOR | ||
127 | |||
128 | /* define current usage levels */ | ||
129 | /* additional current when remote connected */ | ||
130 | /* | ||
131 | #define CURRENT_REMOTE 8 | ||
132 | */ | ||
133 | #ifndef SIMULATOR | ||
134 | |||
135 | /* Define this if your LCD can set contrast */ | ||
136 | #define HAVE_LCD_CONTRAST | ||
137 | |||
138 | /* Define this if you have a Motorola SCF5249 */ | ||
139 | #define CONFIG_CPU MCF5249 | ||
140 | |||
141 | /* Define this if you want to use coldfire's i2c interface */ | ||
142 | #define CONFIG_I2C I2C_COLDFIRE | ||
143 | |||
144 | /* OF resets device instead of poweroff while charging | ||
145 | * this triggers bootloader code which takes care of charging. | ||
146 | * I have feeling that powering off while charging may cause | ||
147 | * partition table corruption I am experiencing from time to time | ||
148 | */ | ||
149 | |||
150 | /* define this if the hardware can be powered off while charging */ | ||
151 | /* #define HAVE_POWEROFF_WHILE_CHARGING */ | ||
152 | |||
153 | /* The size of the flash ROM */ | ||
154 | #define FLASH_SIZE 0x200000 | ||
155 | |||
156 | /* Define this to the CPU frequency */ | ||
157 | #define CPU_FREQ 11289600 | ||
158 | |||
159 | /* Define this if you have ATA power-off control */ | ||
160 | #define HAVE_ATA_POWER_OFF | ||
161 | |||
162 | /* Offset ( in the firmware file's header ) to the file length */ | ||
163 | #define FIRMWARE_OFFSET_FILE_LENGTH 0 | ||
164 | |||
165 | /* Offset ( in the firmware file's header ) to the file CRC */ | ||
166 | #define FIRMWARE_OFFSET_FILE_CRC 0 | ||
167 | |||
168 | /* Offset ( in the firmware file's header ) to the real data */ | ||
169 | #define FIRMWARE_OFFSET_FILE_DATA 8 | ||
170 | |||
171 | /* Define this if you have adjustable CPU frequency */ | ||
172 | #define HAVE_ADJUSTABLE_CPU_FREQ | ||
173 | |||
174 | #define BOOTFILE_EXT "mpio" | ||
175 | #define BOOTFILE "rockbox." BOOTFILE_EXT | ||
176 | #define BOOTDIR "/.rockbox" | ||
177 | |||
178 | #define BOOTLOADER_ENTRYPOINT 0x001F0000 | ||
179 | #define FLASH_ENTRYPOINT 0x00001000 | ||
180 | #define FLASH_MAGIC 0xfbfbfbf1 | ||
181 | |||
182 | #endif /* SIMULATOR */ | ||
183 | |||
184 | /** Port-specific settings **/ | ||
185 | |||
186 | /* Main LCD contrast range and defaults taken from OF*/ | ||
187 | #define MIN_CONTRAST_SETTING 24 | ||
188 | #define MAX_CONTRAST_SETTING 63 | ||
189 | #define DEFAULT_CONTRAST_SETTING 27 /* 0x1B */ | ||
190 | |||
191 | #define IRAM_LCDFRAMEBUFFER IBSS_ATTR /* put the lcd frame buffer in IRAM */ | ||
diff --git a/firmware/target/coldfire/mpio/app.lds b/firmware/target/coldfire/mpio/app.lds new file mode 100644 index 0000000000..d087f997c8 --- /dev/null +++ b/firmware/target/coldfire/mpio/app.lds | |||
@@ -0,0 +1,145 @@ | |||
1 | #include "config.h" | ||
2 | |||
3 | ENTRY(start) | ||
4 | |||
5 | OUTPUT_FORMAT(elf32-m68k) | ||
6 | STARTUP(target/coldfire/crt0.o) | ||
7 | |||
8 | #define PLUGINSIZE PLUGIN_BUFFER_SIZE | ||
9 | #define CODECSIZE CODEC_SIZE | ||
10 | |||
11 | #ifdef DEBUG | ||
12 | #define STUBOFFSET 0x10000 | ||
13 | #else | ||
14 | #define STUBOFFSET 0 | ||
15 | #endif | ||
16 | |||
17 | #define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - STUBOFFSET - CODECSIZE | ||
18 | |||
19 | #define DRAMORIG 0x31000000 + STUBOFFSET | ||
20 | #define IRAMORIG 0x10000000 | ||
21 | #define IRAMSIZE 0xc000 | ||
22 | |||
23 | /* End of the audio buffer, where the codec buffer starts */ | ||
24 | #define ENDAUDIOADDR (DRAMORIG + DRAMSIZE) | ||
25 | |||
26 | /* Where the codec buffer ends, and the plugin buffer starts */ | ||
27 | #define ENDADDR (ENDAUDIOADDR + CODECSIZE) | ||
28 | |||
29 | MEMORY | ||
30 | { | ||
31 | DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE | ||
32 | IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE | ||
33 | } | ||
34 | |||
35 | SECTIONS | ||
36 | { | ||
37 | .vectors : | ||
38 | { | ||
39 | loadaddress = .; | ||
40 | _loadaddress = .; | ||
41 | KEEP(*(.resetvectors)); | ||
42 | *(.resetvectors); | ||
43 | KEEP(*(.vectors)); | ||
44 | *(.vectors); | ||
45 | } > DRAM | ||
46 | |||
47 | .text : | ||
48 | { | ||
49 | . = ALIGN(0x200); | ||
50 | *(.init.text) | ||
51 | *(.text*) | ||
52 | . = ALIGN(0x4); | ||
53 | } > DRAM | ||
54 | |||
55 | .rodata : | ||
56 | { | ||
57 | *(.rodata) /* problems without this, dunno why */ | ||
58 | *(.rodata*) | ||
59 | *(.rodata.str1.1) | ||
60 | *(.rodata.str1.4) | ||
61 | . = ALIGN(0x4); | ||
62 | |||
63 | /* Pseudo-allocate the copies of the data sections */ | ||
64 | _datacopy = .; | ||
65 | } > DRAM | ||
66 | |||
67 | /* TRICK ALERT! For RAM execution, we put the .data section at the | ||
68 | same load address as the copy. Thus, we don't waste extra RAM | ||
69 | when we don't actually need the copy. */ | ||
70 | .data : AT ( _datacopy ) | ||
71 | { | ||
72 | _datastart = .; | ||
73 | *(.data*) | ||
74 | . = ALIGN(0x4); | ||
75 | _dataend = .; | ||
76 | } > DRAM | ||
77 | |||
78 | /DISCARD/ : | ||
79 | { | ||
80 | *(.eh_frame) | ||
81 | } | ||
82 | |||
83 | .iram IRAMORIG : | ||
84 | { | ||
85 | _iramstart = .; | ||
86 | *(.icode) | ||
87 | *(.irodata) | ||
88 | *(.idata) | ||
89 | _iramend = .; | ||
90 | } > IRAM AT> DRAM | ||
91 | |||
92 | _iramcopy = LOADADDR(.iram); | ||
93 | _noloaddram = LOADADDR(.iram); | ||
94 | |||
95 | .ibss (NOLOAD) : | ||
96 | { | ||
97 | _iedata = .; | ||
98 | *(.ibss) | ||
99 | . = ALIGN(0x4); | ||
100 | _iend = .; | ||
101 | } > IRAM | ||
102 | |||
103 | .stack (NOLOAD) : | ||
104 | { | ||
105 | *(.stack) | ||
106 | stackbegin = .; | ||
107 | . += 0x2000; | ||
108 | stackend = .; | ||
109 | } > IRAM | ||
110 | |||
111 | .bss _noloaddram (NOLOAD) : | ||
112 | { | ||
113 | _edata = .; | ||
114 | *(.bss*) | ||
115 | *(COMMON) | ||
116 | . = ALIGN(0x4); | ||
117 | _end = .; | ||
118 | } > DRAM | ||
119 | |||
120 | .audiobuf (NOLOAD) : | ||
121 | { | ||
122 | . = ALIGN(4); | ||
123 | _audiobuffer = .; | ||
124 | audiobuffer = .; | ||
125 | } > DRAM | ||
126 | |||
127 | .audiobufend ENDAUDIOADDR (NOLOAD) : | ||
128 | { | ||
129 | audiobufend = .; | ||
130 | _audiobufend = .; | ||
131 | } > DRAM | ||
132 | |||
133 | .codec ENDAUDIOADDR (NOLOAD) : | ||
134 | { | ||
135 | codecbuf = .; | ||
136 | _codecbuf = .; | ||
137 | } | ||
138 | |||
139 | .plugin ENDADDR (NOLOAD) : | ||
140 | { | ||
141 | _pluginbuf = .; | ||
142 | pluginbuf = .; | ||
143 | } | ||
144 | } | ||
145 | |||
diff --git a/firmware/target/coldfire/mpio/ata-as-mpio.S b/firmware/target/coldfire/mpio/ata-as-mpio.S new file mode 100644 index 0000000000..4a6bd3e613 --- /dev/null +++ b/firmware/target/coldfire/mpio/ata-as-mpio.S | |||
@@ -0,0 +1,757 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: ata-as-coldfire.S 17847 2008-06-28 18:10:04Z bagder $ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Jens Arnold | ||
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 | |||
22 | .section .icode,"ax",@progbits | ||
23 | |||
24 | .equ .ata_port, 0x20000020 | ||
25 | .equ .swapmask, 0x00FF00FF | ||
26 | .align 2 | ||
27 | .global copy_read_sectors | ||
28 | .type copy_read_sectors,@function | ||
29 | |||
30 | /* Read a number of words from the ATA data port | ||
31 | * | ||
32 | * Utilises line bursts, assumes there is at least one full line to copy. | ||
33 | * | ||
34 | * Arguments: | ||
35 | * (4,%sp) - buffer address | ||
36 | * (8,%sp) - word count | ||
37 | * | ||
38 | * Register usage: | ||
39 | * %a0 - current address | ||
40 | * %a1 - end address | ||
41 | * %a2 - ata port | ||
42 | * %d0 - scratch | ||
43 | * %d1 - shift count | ||
44 | * %d2-%d6 - read buffers | ||
45 | * | ||
46 | * %d7 - byte swap scrach register | ||
47 | * %a3 - byte swap mask | ||
48 | */ | ||
49 | |||
50 | copy_read_sectors: | ||
51 | lea.l (-32, %sp), %sp | ||
52 | movem.l %d2-%d7/%a2-%a3, (%sp) | ||
53 | movem.l (36, %sp), %a0-%a1 | ||
54 | add.l %a1, %a1 | ||
55 | add.l %a0, %a1 | ||
56 | lea.l .ata_port, %a2 | ||
57 | lea.l .swapmask, %a3 | ||
58 | |||
59 | move.l %a0, %d0 | ||
60 | btst.l #0, %d0 /* 16-bit aligned? */ | ||
61 | jeq .r_aligned /* yes, do word copy */ | ||
62 | |||
63 | /* not 16-bit aligned */ | ||
64 | subq.l #1, %a1 /* last byte is done unconditionally */ | ||
65 | moveq.l #24, %d1 /* preload shift count */ | ||
66 | |||
67 | move.w (%a2), %d2 /* load initial word */ | ||
68 | move.b %d2, (%a0)+ /* write high byte of it, aligns dest addr */ | ||
69 | /* we have byte swapped */ | ||
70 | |||
71 | btst.l #1, %d0 /* longword aligned? (testing old d0 value!) */ | ||
72 | bne.b .r_end_u_w1 /* yes, skip leading word handling */ | ||
73 | |||
74 | swap %d2 /* move initial word up */ | ||
75 | move.w (%a2), %d2 /* combine with second word */ | ||
76 | |||
77 | /* byte swap d2 */ | ||
78 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
79 | and.l %d2, %d7 /* d7 = .B.D */ | ||
80 | eor.l %d7, %d2 /* d2 = A.C. */ | ||
81 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
82 | lsr.l #8, %d2 /* d2 = .A.C */ | ||
83 | or.l %d7, %d2 /* d2 = BADC */ | ||
84 | |||
85 | move.l %d2, %d3 | ||
86 | lsr.l #8, %d3 | ||
87 | move.w %d3, (%a0)+ /* write bytes 2 and 3 as word */ | ||
88 | |||
89 | .r_end_u_w1: | ||
90 | moveq.l #12, %d0 | ||
91 | add.l %a0, %d0 | ||
92 | and.l #0xFFFFFFF0,%d0 /* d0 == first line bound */ | ||
93 | cmp.l %a0, %d0 /* any leading longwords? */ | ||
94 | bls.b .r_end_u_l1 /* no: skip loop */ | ||
95 | |||
96 | .r_loop_u_l1: | ||
97 | move.w (%a2), %d3 /* load first word */ | ||
98 | swap %d3 /* move to upper 16 bit */ | ||
99 | move.w (%a2), %d3 /* load second word */ | ||
100 | |||
101 | /* byte swap d3 */ | ||
102 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
103 | and.l %d3, %d7 /* d7 = .B.D */ | ||
104 | eor.l %d7, %d3 /* d3 = A.C. */ | ||
105 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
106 | lsr.l #8, %d3 /* d3 = .A.C */ | ||
107 | or.l %d7, %d3 /* d3 = BADC */ | ||
108 | |||
109 | move.l %d3, %d4 | ||
110 | lsl.l %d1, %d2 | ||
111 | lsr.l #8, %d3 | ||
112 | or.l %d3, %d2 /* combine old low byte with new top 3 bytes */ | ||
113 | move.l %d2, (%a0)+ /* store as long */ | ||
114 | move.l %d4, %d2 | ||
115 | cmp.l %a0, %d0 /* run up to first line bound */ | ||
116 | bhi.b .r_loop_u_l1 | ||
117 | |||
118 | .r_end_u_l1: | ||
119 | lea.l (-14, %a1), %a1 /* adjust end addr. to 16 bytes/pass */ | ||
120 | |||
121 | .r_loop_u_line: | ||
122 | move.w (%a2), %d3 /* load 1st word */ | ||
123 | swap %d3 /* move to upper 16 bit */ | ||
124 | move.w (%a2), %d3 /* load 2nd word */ | ||
125 | |||
126 | /* byte swap d3 */ | ||
127 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
128 | and.l %d3, %d7 /* d7 = .B.D */ | ||
129 | eor.l %d7, %d3 /* d3 = A.C. */ | ||
130 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
131 | lsr.l #8, %d3 /* d3 = .A.C */ | ||
132 | or.l %d7, %d3 /* d3 = BADC */ | ||
133 | |||
134 | move.l %d3, %d0 | ||
135 | lsl.l %d1, %d2 | ||
136 | lsr.l #8, %d0 | ||
137 | or.l %d0, %d2 /* combine old low byte with new top 3 bytes */ | ||
138 | move.w (%a2), %d4 /* load 3rd word */ | ||
139 | swap %d4 /* move to upper 16 bit */ | ||
140 | move.w (%a2), %d4 /* load 4th word */ | ||
141 | |||
142 | /* byte swap d4 */ | ||
143 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
144 | and.l %d4, %d7 /* d7 = .B.D */ | ||
145 | eor.l %d7, %d4 /* d4 = A.C. */ | ||
146 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
147 | lsr.l #8, %d4 /* d4 = .A.C */ | ||
148 | or.l %d7, %d4 /* d4 = BADC */ | ||
149 | |||
150 | move.l %d4, %d0 | ||
151 | lsl.l %d1, %d3 | ||
152 | lsr.l #8, %d0 | ||
153 | or.l %d0, %d3 /* combine old low byte with new top 3 bytes */ | ||
154 | move.w (%a2), %d5 /* load 5th word */ | ||
155 | swap %d5 /* move to upper 16 bit */ | ||
156 | move.w (%a2), %d5 /* load 6th word */ | ||
157 | |||
158 | /* byte swap d5 */ | ||
159 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
160 | and.l %d5, %d7 /* d7 = .B.D */ | ||
161 | eor.l %d7, %d5 /* d5 = A.C. */ | ||
162 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
163 | lsr.l #8, %d5 /* d5 = .A.C */ | ||
164 | or.l %d7, %d5 /* d5 = BADC */ | ||
165 | |||
166 | move.l %d5, %d0 | ||
167 | lsl.l %d1, %d4 | ||
168 | lsr.l #8, %d0 | ||
169 | or.l %d0, %d4 /* combine old low byte with new top 3 bytes */ | ||
170 | move.w (%a2), %d6 /* load 7th word */ | ||
171 | swap %d6 /* move to upper 16 bit */ | ||
172 | move.w (%a2), %d6 /* load 8th word */ | ||
173 | |||
174 | /* byte swap d6 */ | ||
175 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
176 | and.l %d6, %d7 /* d7 = .B.D */ | ||
177 | eor.l %d7, %d6 /* d6 = A.C. */ | ||
178 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
179 | lsr.l #8, %d6 /* d6 = .A.C */ | ||
180 | or.l %d7, %d6 /* d6 = BADC */ | ||
181 | |||
182 | move.l %d6, %d0 | ||
183 | lsl.l %d1, %d5 | ||
184 | lsr.l #8, %d0 | ||
185 | or.l %d0, %d5 /* combine old low byte with new top 3 bytes */ | ||
186 | movem.l %d2-%d5, (%a0) /* store line */ | ||
187 | lea.l (16, %a0), %a0 | ||
188 | move.l %d6, %d2 | ||
189 | cmp.l %a0, %a1 /* run up to last line bound */ | ||
190 | bhi.b .r_loop_u_line | ||
191 | |||
192 | lea.l (12, %a1), %a1 /* readjust for longword loop */ | ||
193 | cmp.l %a0, %a1 /* any trailing longwords? */ | ||
194 | bls.b .r_end_u_l2 /* no: skip loop */ | ||
195 | |||
196 | .r_loop_u_l2: | ||
197 | move.w (%a2), %d3 /* load first word */ | ||
198 | swap %d3 /* move to upper 16 bit */ | ||
199 | move.w (%a2), %d3 /* load second word */ | ||
200 | |||
201 | /* byte swap d3 */ | ||
202 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
203 | and.l %d3, %d7 /* d7 = .B.D */ | ||
204 | eor.l %d7, %d3 /* d3 = A.C. */ | ||
205 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
206 | lsr.l #8, %d3 /* d3 = .A.C */ | ||
207 | or.l %d7, %d3 /* d3 = BADC */ | ||
208 | |||
209 | move.l %d3, %d4 | ||
210 | lsl.l %d1, %d2 | ||
211 | lsr.l #8, %d3 | ||
212 | or.l %d3, %d2 /* combine old low byte with new top 3 bytes */ | ||
213 | move.l %d2, (%a0)+ /* store as long */ | ||
214 | move.l %d4, %d2 | ||
215 | cmp.l %a0, %a1 /* run up to last long bound */ | ||
216 | bhi.b .r_loop_u_l2 | ||
217 | |||
218 | .r_end_u_l2: | ||
219 | addq.l #2, %a1 /* back to final end address */ | ||
220 | cmp.l %a0, %a1 /* one word left? */ | ||
221 | bls.b .r_end_u_w2 | ||
222 | |||
223 | swap %d2 /* move old word to upper 16 bits */ | ||
224 | move.w (%a2), %d2 /* load final word */ | ||
225 | |||
226 | /* byte swap d2 */ | ||
227 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
228 | and.l %d2, %d7 /* d7 = .B.D */ | ||
229 | eor.l %d7, %d2 /* d2 = A.C. */ | ||
230 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
231 | lsr.l #8, %d2 /* d2 = .A.C */ | ||
232 | or.l %d7, %d2 /* d2 = BADC */ | ||
233 | |||
234 | move.l %d2, %d3 | ||
235 | lsr.l #8, %d3 | ||
236 | move.w %d3, (%a0)+ /* write bytes 2 and 3 as word */ | ||
237 | |||
238 | .r_end_u_w2: | ||
239 | move.b %d2, (%a0)+ /* store final byte */ | ||
240 | bra.w .r_exit | ||
241 | |||
242 | /* 16-bit aligned */ | ||
243 | .r_aligned: | ||
244 | btst.l #1, %d0 /* longword aligned? */ | ||
245 | beq.b .r_end_a_w1 /* yes, skip leading word handling */ | ||
246 | |||
247 | /* copy initial word */ | ||
248 | /* initial word has to be swapped */ | ||
249 | move.w (%a2), %d7 | ||
250 | move.b %d7, (%a0)+ | ||
251 | lsr.l #8, %d7 | ||
252 | move.b %d7, (%a0)+ | ||
253 | |||
254 | .r_end_a_w1: | ||
255 | moveq.l #12, %d0 | ||
256 | add.l %a0, %d0 | ||
257 | and.l #0xFFFFFFF0,%d0 /* d0 == first line bound */ | ||
258 | cmp.l %a0, %d0 /* any leading longwords? */ | ||
259 | bls.b .r_end_a_l1 /* no: skip loop */ | ||
260 | |||
261 | .r_loop_a_l1: | ||
262 | move.w (%a2), %d1 /* load first word */ | ||
263 | swap %d1 /* move it to upper 16 bits */ | ||
264 | move.w (%a2), %d1 /* load second word */ | ||
265 | |||
266 | /* byte swap d1 */ | ||
267 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
268 | and.l %d1, %d7 /* d7 = .B.D */ | ||
269 | eor.l %d7, %d1 /* d1 = A.C. */ | ||
270 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
271 | lsr.l #8, %d1 /* d1 = .A.C */ | ||
272 | or.l %d7, %d1 /* d1 = BADC */ | ||
273 | |||
274 | move.l %d1, (%a0)+ /* store as long */ | ||
275 | cmp.l %a0, %d0 /* run up to first line bound */ | ||
276 | bhi.b .r_loop_a_l1 | ||
277 | |||
278 | .r_end_a_l1: | ||
279 | lea.l (-14, %a1), %a1 /* adjust end addr. to 16 bytes/pass */ | ||
280 | |||
281 | .r_loop_a_line: | ||
282 | move.w (%a2), %d0 /* load 1st word */ | ||
283 | swap %d0 /* move it to upper 16 bits */ | ||
284 | move.w (%a2), %d0 /* load 2nd word */ | ||
285 | |||
286 | /* byte swap d0 */ | ||
287 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
288 | and.l %d0, %d7 /* d7 = .B.D */ | ||
289 | eor.l %d7, %d0 /* d0 = A.C. */ | ||
290 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
291 | lsr.l #8, %d0 /* d0 = .A.C */ | ||
292 | or.l %d7, %d0 /* d0 = BADC */ | ||
293 | |||
294 | move.w (%a2), %d1 /* load 3rd word */ | ||
295 | swap %d1 /* move it to upper 16 bits */ | ||
296 | move.w (%a2), %d1 /* load 4th word */ | ||
297 | |||
298 | /* byte swap d1 */ | ||
299 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
300 | and.l %d1, %d7 /* d7 = .B.D */ | ||
301 | eor.l %d7, %d1 /* d1 = A.C. */ | ||
302 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
303 | lsr.l #8, %d1 /* d1 = .A.C */ | ||
304 | or.l %d7, %d1 /* d1 = BADC */ | ||
305 | |||
306 | move.w (%a2), %d2 /* load 5th word */ | ||
307 | swap %d2 /* move it to upper 16 bits */ | ||
308 | move.w (%a2), %d2 /* load 6th word */ | ||
309 | |||
310 | /* byte swap d2 */ | ||
311 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
312 | and.l %d2, %d7 /* d7 = .B.D */ | ||
313 | eor.l %d7, %d2 /* d2 = A.C. */ | ||
314 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
315 | lsr.l #8, %d2 /* d2 = .A.C */ | ||
316 | or.l %d7, %d2 /* d2 = BADC */ | ||
317 | |||
318 | move.w (%a2), %d3 /* load 7th word */ | ||
319 | swap %d3 /* move it to upper 16 bits */ | ||
320 | move.w (%a2), %d3 /* load 8th word */ | ||
321 | |||
322 | /* byte swap d3 */ | ||
323 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
324 | and.l %d3, %d7 /* d7 = .B.D */ | ||
325 | eor.l %d7, %d3 /* d3 = A.C. */ | ||
326 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
327 | lsr.l #8, %d3 /* d3 = .A.C */ | ||
328 | or.l %d7, %d3 /* d3 = BADC */ | ||
329 | |||
330 | movem.l %d0-%d3, (%a0) /* store line */ | ||
331 | lea.l (16, %a0), %a0 | ||
332 | cmp.l %a0, %a1 /* run up to last line bound */ | ||
333 | bhi.b .r_loop_a_line | ||
334 | |||
335 | lea.l (12, %a1), %a1 /* readjust for longword loop */ | ||
336 | cmp.l %a0, %a1 /* any trailing longwords? */ | ||
337 | bls.b .r_end_a_l2 /* no: skip loop */ | ||
338 | |||
339 | .r_loop_a_l2: | ||
340 | move.w (%a2), %d1 /* read first word */ | ||
341 | swap %d1 /* move it to upper 16 bits */ | ||
342 | move.w (%a2), %d1 /* read second word */ | ||
343 | |||
344 | /* byte swap d1 */ | ||
345 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
346 | and.l %d1, %d7 /* d7 = .B.D */ | ||
347 | eor.l %d7, %d1 /* d1 = A.C. */ | ||
348 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
349 | lsr.l #8, %d1 /* d1 = .A.C */ | ||
350 | or.l %d7, %d1 /* d1 = BADC */ | ||
351 | |||
352 | move.l %d1, (%a0)+ /* store as long */ | ||
353 | cmp.l %a0, %a1 /* run up to last long bound */ | ||
354 | bhi.b .r_loop_a_l2 | ||
355 | |||
356 | .r_end_a_l2: | ||
357 | addq.l #2, %a1 /* back to final end address */ | ||
358 | cmp.l %a0, %a1 /* one word left? */ | ||
359 | bls.b .r_end_a_w2 | ||
360 | |||
361 | /* copy final word */ | ||
362 | /* final word has to be swapped */ | ||
363 | move.w (%a2), %d7 | ||
364 | move.b %d7, (%a0)+ | ||
365 | lsr.l #8, %d7 | ||
366 | move.b %d7, (%a0)+ | ||
367 | |||
368 | .r_end_a_w2: | ||
369 | |||
370 | .r_exit: | ||
371 | movem.l (%sp), %d2-%d7/%a2-%a3 | ||
372 | lea.l (32, %sp), %sp | ||
373 | rts | ||
374 | |||
375 | .r_end: | ||
376 | .size copy_read_sectors,.r_end-copy_read_sectors | ||
377 | |||
378 | .align 2 | ||
379 | .global copy_write_sectors | ||
380 | .type copy_write_sectors,@function | ||
381 | |||
382 | #if 0 | ||
383 | /* Write a number of words to the ATA data port | ||
384 | * | ||
385 | * Utilises line bursts, assumes there is at least one full line to copy. | ||
386 | * | ||
387 | * Arguments: | ||
388 | * (4,%sp) - buffer address | ||
389 | * (8,%sp) - word count | ||
390 | * | ||
391 | * Register usage: | ||
392 | * %a0 - current address | ||
393 | * %a1 - end address | ||
394 | * %a2 - ata port | ||
395 | * %d0 - scratch | ||
396 | * %d1 - shift count | ||
397 | * %d2-%d6 - read buffers | ||
398 | * | ||
399 | * %d7 - swap scrach | ||
400 | * %a3 - swap mask | ||
401 | */ | ||
402 | |||
403 | copy_write_sectors: | ||
404 | lea.l (-32, %sp), %sp | ||
405 | movem.l %d2-%d7/%a2-%a3, (%sp) | ||
406 | movem.l (36, %sp), %a0-%a1 | ||
407 | add.l %a1, %a1 | ||
408 | add.l %a0, %a1 | ||
409 | lea.l .ata_port, %a2 | ||
410 | lea.l .swapmask, %a3 | ||
411 | |||
412 | move.l %a0, %d0 | ||
413 | btst.l #0, %d0 /* 16-bit aligned? */ | ||
414 | beq .w_aligned /* yes, do word copy */ | ||
415 | |||
416 | /* not 16-bit aligned */ | ||
417 | subq.l #1, %a1 /* last byte is done unconditionally */ | ||
418 | moveq.l #24, %d1 /* preload shift count */ | ||
419 | |||
420 | move.b (%a0)+, %d2 | ||
421 | |||
422 | btst.l #1, %d0 /* longword aligned? (testing old d0 value!) */ | ||
423 | bne.b .w_end_u_w1 /* yes, skip leading word handling */ | ||
424 | |||
425 | swap %d2 | ||
426 | move.w (%a0)+, %d2 | ||
427 | move.l %d2, %d3 | ||
428 | lsr.l #8, %d3 | ||
429 | |||
430 | /* low word of %d3 has to be byte swaped */ | ||
431 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
432 | and.l %d3, %d7 /* d7 = .B.D */ | ||
433 | eor.l %d7, %d3 /* d3 = A.C. */ | ||
434 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
435 | lsr.l #8, %d3 /* d3 = .A.C */ | ||
436 | or.l %d7, %d3 /* d3 = BADC */ | ||
437 | |||
438 | move.w %d3, (%a2) | ||
439 | |||
440 | .w_end_u_w1: | ||
441 | moveq.l #12, %d0 | ||
442 | add.l %a0, %d0 | ||
443 | and.l #0xFFFFFFF0,%d0 /* d0 == first line bound */ | ||
444 | cmp.l %a0, %d0 /* any leading longwords? */ | ||
445 | bls.b .w_end_u_l1 /* no: skip loop */ | ||
446 | |||
447 | .w_loop_u_l1: | ||
448 | move.l (%a0)+, %d3 | ||
449 | move.l %d3, %d4 | ||
450 | lsl.l %d1, %d2 | ||
451 | lsr.l #8, %d3 | ||
452 | or.l %d3, %d2 | ||
453 | |||
454 | /* byte swap d2 */ | ||
455 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
456 | and.l %d2, %d7 /* d7 = .B.D */ | ||
457 | eor.l %d7, %d2 /* d2 = A.C. */ | ||
458 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
459 | lsr.l #8, %d2 /* d2 = .A.C */ | ||
460 | or.l %d7, %d2 /* d2 = BADC */ | ||
461 | |||
462 | swap %d2 | ||
463 | move.w %d2, (%a2) | ||
464 | swap %d2 | ||
465 | move.w %d2, (%a2) | ||
466 | move.l %d4, %d2 | ||
467 | cmp.l %a0, %d0 /* run up to first line bound */ | ||
468 | bhi.b .w_loop_u_l1 | ||
469 | |||
470 | .w_end_u_l1: | ||
471 | lea.l (-14, %a1), %a1 /* adjust end addr. to 16 bytes/pass */ | ||
472 | |||
473 | .w_loop_u_line: | ||
474 | movem.l (%a0), %d3-%d6 | ||
475 | lea.l (16, %a0), %a0 | ||
476 | move.l %d3, %d0 | ||
477 | lsl.l %d1, %d2 | ||
478 | lsr.l #8, %d0 | ||
479 | or.l %d0, %d2 | ||
480 | |||
481 | /* byte swap d2 */ | ||
482 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
483 | and.l %d2, %d7 /* d7 = .B.D */ | ||
484 | eor.l %d7, %d2 /* d2 = A.C. */ | ||
485 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
486 | lsr.l #8, %d2 /* d2 = .A.C */ | ||
487 | or.l %d7, %d2 /* d2 = BADC */ | ||
488 | |||
489 | swap %d2 | ||
490 | move.w %d2, (%a2) | ||
491 | swap %d2 | ||
492 | move.w %d2, (%a2) | ||
493 | move.l %d4, %d0 | ||
494 | lsl.l %d1, %d3 | ||
495 | lsr.l #8, %d0 | ||
496 | or.l %d0, %d3 | ||
497 | |||
498 | /* byte swap d3 */ | ||
499 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
500 | and.l %d3, %d7 /* d7 = .B.D */ | ||
501 | eor.l %d7, %d3 /* d3 = A.C. */ | ||
502 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
503 | lsr.l #8, %d3 /* d3 = .A.C */ | ||
504 | or.l %d7, %d3 /* d3 = BADC */ | ||
505 | |||
506 | swap %d3 | ||
507 | move.w %d3, (%a2) | ||
508 | swap %d3 | ||
509 | move.w %d3, (%a2) | ||
510 | move.l %d5, %d0 | ||
511 | lsl.l %d1, %d4 | ||
512 | lsr.l #8, %d0 | ||
513 | or.l %d0, %d4 | ||
514 | |||
515 | /* byte swap d4 */ | ||
516 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
517 | and.l %d4, %d7 /* d7 = .B.D */ | ||
518 | eor.l %d7, %d4 /* d4 = A.C. */ | ||
519 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
520 | lsr.l #8, %d4 /* d4 = .A.C */ | ||
521 | or.l %d7, %d4 /* d4 = BADC */ | ||
522 | |||
523 | swap %d4 | ||
524 | move.w %d4, (%a2) | ||
525 | swap %d4 | ||
526 | move.w %d4, (%a2) | ||
527 | move.l %d6, %d0 | ||
528 | lsl.l %d1, %d5 | ||
529 | lsr.l #8, %d0 | ||
530 | or.l %d0, %d5 | ||
531 | |||
532 | /* byte swap d5 */ | ||
533 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
534 | and.l %d5, %d7 /* d7 = .B.D */ | ||
535 | eor.l %d7, %d5 /* d5 = A.C. */ | ||
536 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
537 | lsr.l #8, %d5 /* d5 = .A.C */ | ||
538 | or.l %d7, %d5 /* d5 = BADC */ | ||
539 | |||
540 | swap %d5 | ||
541 | move.w %d5, (%a2) | ||
542 | swap %d5 | ||
543 | move.w %d5, (%a2) | ||
544 | move.l %d6, %d2 | ||
545 | cmp.l %a0, %a1 /* run up to last line bound */ | ||
546 | bhi.b .w_loop_u_line | ||
547 | |||
548 | lea.l (12, %a1), %a1 /* readjust for longword loop */ | ||
549 | cmp.l %a0, %a1 /* any trailing longwords? */ | ||
550 | bls.b .w_end_u_l2 /* no: skip loop */ | ||
551 | |||
552 | .w_loop_u_l2: | ||
553 | move.l (%a0)+, %d3 | ||
554 | move.l %d3, %d4 | ||
555 | lsl.l %d1, %d2 | ||
556 | lsr.l #8, %d3 | ||
557 | or.l %d3, %d2 | ||
558 | |||
559 | /* byte swap d2 */ | ||
560 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
561 | and.l %d2, %d7 /* d7 = .B.D */ | ||
562 | eor.l %d7, %d2 /* d2 = A.C. */ | ||
563 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
564 | lsr.l #8, %d2 /* d2 = .A.C */ | ||
565 | or.l %d7, %d2 /* d2 = BADC */ | ||
566 | |||
567 | swap %d2 | ||
568 | move.w %d2, (%a2) | ||
569 | swap %d2 | ||
570 | move.w %d2, (%a2) | ||
571 | move.l %d4, %d2 | ||
572 | cmp.l %a0, %a1 /* run up to first line bound */ | ||
573 | bhi.b .w_loop_u_l2 | ||
574 | |||
575 | .w_end_u_l2: | ||
576 | addq.l #2, %a1 /* back to final end address */ | ||
577 | cmp.l %a0, %a1 /* one word left? */ | ||
578 | bls.b .w_end_u_w2 | ||
579 | |||
580 | swap %d2 | ||
581 | move.w (%a0)+, %d2 | ||
582 | move.l %d2, %d3 | ||
583 | lsr.l #8, %d3 | ||
584 | |||
585 | /* byte swap d3 */ | ||
586 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
587 | and.l %d3, %d7 /* d7 = .B.D */ | ||
588 | eor.l %d7, %d3 /* d3 = A.C. */ | ||
589 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
590 | lsr.l #8, %d3 /* d3 = .A.C */ | ||
591 | or.l %d7, %d3 /* d3 = BADC */ | ||
592 | |||
593 | move.w %d3, (%a2) | ||
594 | |||
595 | .w_end_u_w2: | ||
596 | lsl.l #8, %d2 | ||
597 | move.b (%a0)+, %d2 | ||
598 | |||
599 | /* byte swap d2 */ | ||
600 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
601 | and.l %d2, %d7 /* d7 = .B.D */ | ||
602 | eor.l %d7, %d2 /* d2 = A.C. */ | ||
603 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
604 | lsr.l #8, %d2 /* d2 = .A.C */ | ||
605 | or.l %d7, %d2 /* d2 = BADC */ | ||
606 | |||
607 | move.w %d2, (%a2) | ||
608 | bra.w .w_exit | ||
609 | |||
610 | /* 16-bit aligned */ | ||
611 | .w_aligned: | ||
612 | btst.l #1, %d0 | ||
613 | beq.b .w_end_a_w1 | ||
614 | |||
615 | /* this has to be byte swaped */ | ||
616 | /* copy initial word */ | ||
617 | move.w (%a0)+, %d1 | ||
618 | |||
619 | /* byte swap d1 */ | ||
620 | move.l %a3, %d7 /* d7 = $00FF00FF */ | ||
621 | and.l %d1, %d7 /* d7 = .B.D */ | ||
622 | eor.l %d7, %d1 /* d1 = A.C. */ | ||
623 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
624 | lsr.l #8, %d1 /* d1 = .A.C */ | ||
625 | or.l %d7, %d1 /* d1 = BADC */ | ||
626 | |||
627 | move.w %d1, (%a2) | ||
628 | |||
629 | |||
630 | .w_end_a_w1: | ||
631 | moveq.l #12, %d0 | ||
632 | add.l %a0, %d0 | ||
633 | and.l #0xFFFFFFF0,%d0 /* d0 == first line bound */ | ||
634 | cmp.l %a0, %d0 /* any leading longwords? */ | ||
635 | bls.b .w_end_a_l1 /* no: skip loop */ | ||
636 | |||
637 | .w_loop_a_l1: | ||
638 | move.l (%a0)+, %d1 | ||
639 | |||
640 | /* byte swap d1 */ | ||
641 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
642 | and.l %d1, %d7 /* d7 = .B.D */ | ||
643 | eor.l %d7, %d1 /* d1 = A.C. */ | ||
644 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
645 | lsr.l #8, %d1 /* d1 = .A.C */ | ||
646 | or.l %d7, %d1 /* d1 = BADC */ | ||
647 | |||
648 | swap %d1 | ||
649 | move.w %d1, (%a2) | ||
650 | swap %d1 | ||
651 | move.w %d1, (%a2) | ||
652 | cmp.l %a0, %d0 /* run up to first line bound */ | ||
653 | bhi.b .w_loop_a_l1 | ||
654 | |||
655 | .w_end_a_l1: | ||
656 | lea.l (-14, %a1), %a1 /* adjust end addr. to 16 bytes/pass */ | ||
657 | |||
658 | .w_loop_a_line: | ||
659 | movem.l (%a0), %d0-%d3 | ||
660 | |||
661 | /* byte swap d0-d3 */ | ||
662 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
663 | and.l %d0, %d7 /* d7 = .B.D */ | ||
664 | eor.l %d7, %d0 /* d0 = A.C. */ | ||
665 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
666 | lsr.l #8, %d0 /* d0 = .A.C */ | ||
667 | or.l %d7, %d0 /* d0 = BADC */ | ||
668 | |||
669 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
670 | and.l %d1, %d7 /* d7 = .B.D */ | ||
671 | eor.l %d7, %d1 /* d1 = A.C. */ | ||
672 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
673 | lsr.l #8, %d1 /* d1 = .A.C */ | ||
674 | or.l %d7, %d1 /* d1 = BADC */ | ||
675 | |||
676 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
677 | and.l %d2, %d7 /* d7 = .B.D */ | ||
678 | eor.l %d7, %d2 /* d2 = A.C. */ | ||
679 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
680 | lsr.l #8, %d2 /* d2 = .A.C */ | ||
681 | or.l %d7, %d2 /* d2 = BADC */ | ||
682 | |||
683 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
684 | and.l %d3, %d7 /* d7 = .B.D */ | ||
685 | eor.l %d7, %d3 /* d3 = A.C. */ | ||
686 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
687 | lsr.l #8, %d3 /* d3 = .A.C */ | ||
688 | or.l %d7, %d3 /* d3 = BADC */ | ||
689 | |||
690 | lea.l (16, %a0), %a0 | ||
691 | swap %d0 | ||
692 | move.w %d0, (%a2) | ||
693 | swap %d0 | ||
694 | move.w %d0, (%a2) | ||
695 | swap %d1 | ||
696 | move.w %d1, (%a2) | ||
697 | swap %d1 | ||
698 | move.w %d1, (%a2) | ||
699 | swap %d2 | ||
700 | move.w %d2, (%a2) | ||
701 | swap %d2 | ||
702 | move.w %d2, (%a2) | ||
703 | swap %d3 | ||
704 | move.w %d3, (%a2) | ||
705 | swap %d3 | ||
706 | move.w %d3, (%a2) | ||
707 | cmp.l %a0, %a1 /* run up to last line bound */ | ||
708 | bhi.b .w_loop_a_line | ||
709 | |||
710 | lea.l (12, %a1), %a1 /* readjust for longword loop */ | ||
711 | cmp.l %a0, %a1 /* any trailing longwords? */ | ||
712 | bls.b .w_end_a_l2 /* no: skip loop */ | ||
713 | |||
714 | .w_loop_a_l2: | ||
715 | move.l (%a0)+, %d1 | ||
716 | |||
717 | /* byte swap d1 */ | ||
718 | move.l %a3, %d7 /* d7 = 0x00FF00FF */ | ||
719 | and.l %d1, %d7 /* d7 = .B.D */ | ||
720 | eor.l %d7, %d1 /* d1 = A.C. */ | ||
721 | lsl.l #8, %d7 /* d7 = B.D. */ | ||
722 | lsr.l #8, %d1 /* d1 = .A.C */ | ||
723 | or.l %d7, %d1 /* d1 = BADC */ | ||
724 | |||
725 | swap %d1 | ||
726 | move.w %d1, (%a2) | ||
727 | swap %d1 | ||
728 | move.w %d1, (%a2) | ||
729 | cmp.l %a0, %a1 /* run up to first line bound */ | ||
730 | bhi.b .w_loop_a_l2 | ||
731 | |||
732 | .w_end_a_l2: | ||
733 | addq.l #2, %a1 /* back to final end address */ | ||
734 | cmp.l %a0, %a1 /* one word left? */ | ||
735 | bls.b .w_end_a_w2 | ||
736 | |||
737 | /* this has to be byte swaped */ | ||
738 | /* copy final word */ | ||
739 | move.w (%a0)+, %d0 | ||
740 | move.l %a3, %d7 | ||
741 | and.l %d0, %d7 | ||
742 | eor.l %d7, %d0 | ||
743 | lsl.l #8, %d7 | ||
744 | lsr.l #8, %d0 | ||
745 | or.l %d7, %d0 | ||
746 | move.w %d0, (%a2) | ||
747 | |||
748 | .w_end_a_w2: | ||
749 | |||
750 | .w_exit: | ||
751 | movem.l (%sp), %d2-%d7/%a2-%a3 | ||
752 | lea.l (32, %sp), %sp | ||
753 | rts | ||
754 | |||
755 | .w_end: | ||
756 | .size copy_write_sectors,.w_end-copy_write_sectors | ||
757 | #endif | ||
diff --git a/firmware/target/coldfire/mpio/ata-mpio.c b/firmware/target/coldfire/mpio/ata-mpio.c new file mode 100644 index 0000000000..ca1c9b1bc6 --- /dev/null +++ b/firmware/target/coldfire/mpio/ata-mpio.c | |||
@@ -0,0 +1,57 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include <stdbool.h> | ||
25 | #include "kernel.h" | ||
26 | #include "system.h" | ||
27 | #include "power.h" | ||
28 | #include "ata-target.h" | ||
29 | |||
30 | void ata_reset(void) | ||
31 | { | ||
32 | /* GPIO19 */ | ||
33 | and_l(~(1<<19), &GPIO_OUT); | ||
34 | sleep(1); /* > 25us */ | ||
35 | |||
36 | or_l((1<<19), &GPIO_OUT); | ||
37 | sleep(1); /* > 25us */ | ||
38 | } | ||
39 | |||
40 | void ata_enable(bool on) | ||
41 | { | ||
42 | (void)on; | ||
43 | } | ||
44 | |||
45 | /* to be fixed */ | ||
46 | bool ata_is_coldstart(void) | ||
47 | { | ||
48 | return true; | ||
49 | } | ||
50 | |||
51 | void ata_device_init(void) | ||
52 | { | ||
53 | /* ATA reset line config */ | ||
54 | or_l((1<<19), &GPIO_OUT); | ||
55 | or_l((1<<19), &GPIO_ENABLE); | ||
56 | or_l((1<<19), &GPIO_FUNCTION); | ||
57 | } | ||
diff --git a/firmware/target/coldfire/mpio/ata-target.h b/firmware/target/coldfire/mpio/ata-target.h new file mode 100644 index 0000000000..1fa4c5af41 --- /dev/null +++ b/firmware/target/coldfire/mpio/ata-target.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | #ifndef ATA_TARGET_H | ||
22 | #define ATA_TARGET_H | ||
23 | |||
24 | /* asm optimised read & write loops - we skip this for now*/ | ||
25 | #define ATA_OPTIMIZED_READING | ||
26 | //#define ATA_OPTIMIZED_WRITING | ||
27 | |||
28 | #define SWAP_WORDS | ||
29 | |||
30 | #define ATA_IOBASE 0x20000000 | ||
31 | #define ATA_DATA (*((volatile unsigned short*)(ATA_IOBASE + 0x20))) | ||
32 | #define ATA_CONTROL (*((volatile unsigned short*)(ATA_IOBASE + 0x1c))) | ||
33 | |||
34 | #define ATA_ERROR (*((volatile unsigned short*)(ATA_IOBASE + 0x22))) | ||
35 | #define ATA_NSECTOR (*((volatile unsigned short*)(ATA_IOBASE + 0x24))) | ||
36 | #define ATA_SECTOR (*((volatile unsigned short*)(ATA_IOBASE + 0x26))) | ||
37 | #define ATA_LCYL (*((volatile unsigned short*)(ATA_IOBASE + 0x28))) | ||
38 | #define ATA_HCYL (*((volatile unsigned short*)(ATA_IOBASE + 0x2a))) | ||
39 | #define ATA_SELECT (*((volatile unsigned short*)(ATA_IOBASE + 0x2c))) | ||
40 | #define ATA_COMMAND (*((volatile unsigned short*)(ATA_IOBASE + 0x2e))) | ||
41 | |||
42 | |||
43 | #define STATUS_BSY 0x80 | ||
44 | #define STATUS_RDY 0x40 | ||
45 | #define STATUS_DF 0x20 | ||
46 | #define STATUS_DRQ 0x08 | ||
47 | #define STATUS_ERR 0x01 | ||
48 | |||
49 | #define ERROR_ABRT 0x04 | ||
50 | #define ERROR_IDNF 0x10 | ||
51 | |||
52 | #define WRITE_PATTERN1 0xa5 | ||
53 | #define WRITE_PATTERN2 0x5a | ||
54 | #define WRITE_PATTERN3 0xaa | ||
55 | #define WRITE_PATTERN4 0x55 | ||
56 | |||
57 | #define READ_PATTERN1 0xa5 | ||
58 | #define READ_PATTERN2 0x5a | ||
59 | #define READ_PATTERN3 0xaa | ||
60 | #define READ_PATTERN4 0x55 | ||
61 | |||
62 | #define READ_PATTERN1_MASK 0xff | ||
63 | #define READ_PATTERN2_MASK 0xff | ||
64 | #define READ_PATTERN3_MASK 0xff | ||
65 | #define READ_PATTERN4_MASK 0xff | ||
66 | |||
67 | #define SET_REG(reg,val) reg = (val) | ||
68 | #define SET_16BITREG(reg,val) reg = (val) | ||
69 | |||
70 | void ata_reset(void); | ||
71 | void ata_enable(bool on); | ||
72 | void ata_device_init(void); | ||
73 | bool ata_is_coldstart(void); | ||
74 | |||
75 | void copy_read_sectors(unsigned char* buf, int wordcount); | ||
76 | //void copy_write_sectors(const unsigned char* buf, int wordcount); | ||
77 | #endif | ||
diff --git a/firmware/target/coldfire/mpio/audio-mpio.c b/firmware/target/coldfire/mpio/audio-mpio.c new file mode 100644 index 0000000000..28c6419171 --- /dev/null +++ b/firmware/target/coldfire/mpio/audio-mpio.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 "system.h" | ||
22 | #include "cpu.h" | ||
23 | #include "audio.h" | ||
24 | #include "sound.h" | ||
25 | |||
26 | void audio_set_output_source(int source) | ||
27 | { | ||
28 | |||
29 | (void)source; | ||
30 | int level = set_irq_level(DMA_IRQ_LEVEL); | ||
31 | |||
32 | /* PDOR3 */ | ||
33 | IIS2CONFIG = (IIS2CONFIG & ~(7 << 8)) | (3 << 8); | ||
34 | |||
35 | restore_irq(level); | ||
36 | } | ||
37 | |||
38 | void audio_input_mux(int source, unsigned flags) | ||
39 | { | ||
40 | (void)source; | ||
41 | (void)flags; | ||
42 | |||
43 | switch(source) | ||
44 | { | ||
45 | case AUDIO_SRC_FMRADIO: | ||
46 | break; | ||
47 | } | ||
48 | /* empty stub */ | ||
49 | } | ||
diff --git a/firmware/target/coldfire/mpio/boot.lds b/firmware/target/coldfire/mpio/boot.lds new file mode 100644 index 0000000000..2b086586ad --- /dev/null +++ b/firmware/target/coldfire/mpio/boot.lds | |||
@@ -0,0 +1,81 @@ | |||
1 | #include "config.h" | ||
2 | |||
3 | ENTRY(start) | ||
4 | OUTPUT_FORMAT(elf32-m68k) | ||
5 | STARTUP(target/coldfire/crt0.o) | ||
6 | |||
7 | #define DRAMSIZE (MEMORYSIZE * 0x100000) | ||
8 | |||
9 | #define DRAMORIG 0x31000000 | ||
10 | #define IRAMORIG 0x10000000 | ||
11 | #define IRAMSIZE 0x18000 | ||
12 | #define FLASHORIG 0x000e0000 | ||
13 | #define FLASHSIZE 0x1f800 | ||
14 | |||
15 | MEMORY | ||
16 | { | ||
17 | DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE | ||
18 | IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE | ||
19 | FLASH : ORIGIN = FLASHORIG, LENGTH = FLASHSIZE | ||
20 | } | ||
21 | |||
22 | SECTIONS | ||
23 | { | ||
24 | .vectors : | ||
25 | { | ||
26 | _datacopy = .; | ||
27 | } > FLASH | ||
28 | |||
29 | .data : AT ( _datacopy ) | ||
30 | { | ||
31 | _datastart = .; | ||
32 | KEEP(*(.resetvectors)); | ||
33 | *(.resetvectors); | ||
34 | KEEP(*(.vectors)); | ||
35 | *(.vectors); | ||
36 | . = ALIGN(0x200); | ||
37 | *(.icode) | ||
38 | *(.irodata) | ||
39 | *(.idata) | ||
40 | *(.data*) | ||
41 | . = ALIGN(0x4); | ||
42 | _dataend = .; | ||
43 | . = ALIGN(0x10); /* Maintain proper alignment for .text section */ | ||
44 | } > IRAM | ||
45 | |||
46 | /* TRICK ALERT! Newer versions of the linker don't allow output sections | ||
47 | to overlap even if one of them is empty, so advance the location pointer | ||
48 | "by hand" */ | ||
49 | .text LOADADDR(.data) + SIZEOF(.data) : | ||
50 | { | ||
51 | *(.init.text) | ||
52 | *(.text*) | ||
53 | . = ALIGN(0x4); | ||
54 | } > FLASH | ||
55 | |||
56 | .rodata : | ||
57 | { | ||
58 | *(.rodata*) | ||
59 | . = ALIGN(0x4); | ||
60 | _iramcopy = .; | ||
61 | } > FLASH | ||
62 | |||
63 | .stack : | ||
64 | { | ||
65 | *(.stack) | ||
66 | _stackbegin = .; | ||
67 | stackbegin = .; | ||
68 | . += 0x2000; | ||
69 | _stackend = .; | ||
70 | stackend = .; | ||
71 | } > IRAM | ||
72 | |||
73 | .bss DRAMORIG+0x800000: | ||
74 | { | ||
75 | _edata = .; | ||
76 | *(.ibss) | ||
77 | *(.bss*) | ||
78 | *(COMMON) | ||
79 | _end = .; | ||
80 | } > DRAM | ||
81 | } | ||
diff --git a/firmware/target/coldfire/mpio/boot.lds.flash b/firmware/target/coldfire/mpio/boot.lds.flash new file mode 100644 index 0000000000..2b086586ad --- /dev/null +++ b/firmware/target/coldfire/mpio/boot.lds.flash | |||
@@ -0,0 +1,81 @@ | |||
1 | #include "config.h" | ||
2 | |||
3 | ENTRY(start) | ||
4 | OUTPUT_FORMAT(elf32-m68k) | ||
5 | STARTUP(target/coldfire/crt0.o) | ||
6 | |||
7 | #define DRAMSIZE (MEMORYSIZE * 0x100000) | ||
8 | |||
9 | #define DRAMORIG 0x31000000 | ||
10 | #define IRAMORIG 0x10000000 | ||
11 | #define IRAMSIZE 0x18000 | ||
12 | #define FLASHORIG 0x000e0000 | ||
13 | #define FLASHSIZE 0x1f800 | ||
14 | |||
15 | MEMORY | ||
16 | { | ||
17 | DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE | ||
18 | IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE | ||
19 | FLASH : ORIGIN = FLASHORIG, LENGTH = FLASHSIZE | ||
20 | } | ||
21 | |||
22 | SECTIONS | ||
23 | { | ||
24 | .vectors : | ||
25 | { | ||
26 | _datacopy = .; | ||
27 | } > FLASH | ||
28 | |||
29 | .data : AT ( _datacopy ) | ||
30 | { | ||
31 | _datastart = .; | ||
32 | KEEP(*(.resetvectors)); | ||
33 | *(.resetvectors); | ||
34 | KEEP(*(.vectors)); | ||
35 | *(.vectors); | ||
36 | . = ALIGN(0x200); | ||
37 | *(.icode) | ||
38 | *(.irodata) | ||
39 | *(.idata) | ||
40 | *(.data*) | ||
41 | . = ALIGN(0x4); | ||
42 | _dataend = .; | ||
43 | . = ALIGN(0x10); /* Maintain proper alignment for .text section */ | ||
44 | } > IRAM | ||
45 | |||
46 | /* TRICK ALERT! Newer versions of the linker don't allow output sections | ||
47 | to overlap even if one of them is empty, so advance the location pointer | ||
48 | "by hand" */ | ||
49 | .text LOADADDR(.data) + SIZEOF(.data) : | ||
50 | { | ||
51 | *(.init.text) | ||
52 | *(.text*) | ||
53 | . = ALIGN(0x4); | ||
54 | } > FLASH | ||
55 | |||
56 | .rodata : | ||
57 | { | ||
58 | *(.rodata*) | ||
59 | . = ALIGN(0x4); | ||
60 | _iramcopy = .; | ||
61 | } > FLASH | ||
62 | |||
63 | .stack : | ||
64 | { | ||
65 | *(.stack) | ||
66 | _stackbegin = .; | ||
67 | stackbegin = .; | ||
68 | . += 0x2000; | ||
69 | _stackend = .; | ||
70 | stackend = .; | ||
71 | } > IRAM | ||
72 | |||
73 | .bss DRAMORIG+0x800000: | ||
74 | { | ||
75 | _edata = .; | ||
76 | *(.ibss) | ||
77 | *(.bss*) | ||
78 | *(COMMON) | ||
79 | _end = .; | ||
80 | } > DRAM | ||
81 | } | ||
diff --git a/firmware/target/coldfire/mpio/boot.lds.iram b/firmware/target/coldfire/mpio/boot.lds.iram new file mode 100644 index 0000000000..769e1027ab --- /dev/null +++ b/firmware/target/coldfire/mpio/boot.lds.iram | |||
@@ -0,0 +1,81 @@ | |||
1 | #include "config.h" | ||
2 | |||
3 | ENTRY(start) | ||
4 | OUTPUT_FORMAT(elf32-m68k) | ||
5 | STARTUP(target/coldfire/crt0.o) | ||
6 | |||
7 | #define DRAMSIZE (MEMORYSIZE * 0x100000) | ||
8 | |||
9 | #define DRAMORIG 0x31000000 | ||
10 | #define IRAMORIG 0x10000000 | ||
11 | #define IRAMSIZE 0x18000 | ||
12 | #define FLASHORIG 0x000e0000 | ||
13 | #define FLASHSIZE 0x1f800 | ||
14 | |||
15 | MEMORY | ||
16 | { | ||
17 | DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE | ||
18 | IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE | ||
19 | FLASH : ORIGIN = FLASHORIG, LENGTH = FLASHSIZE | ||
20 | } | ||
21 | |||
22 | SECTIONS | ||
23 | { | ||
24 | .vectors : | ||
25 | { | ||
26 | _datacopy = .; | ||
27 | } > IRAM | ||
28 | |||
29 | .data : AT ( _datacopy ) | ||
30 | { | ||
31 | _datastart = .; | ||
32 | KEEP(*(.resetvectors)); | ||
33 | *(.resetvectors); | ||
34 | KEEP(*(.vectors)); | ||
35 | *(.vectors); | ||
36 | . = ALIGN(0x200); | ||
37 | *(.icode) | ||
38 | *(.irodata) | ||
39 | *(.idata) | ||
40 | *(.data*) | ||
41 | . = ALIGN(0x4); | ||
42 | _dataend = .; | ||
43 | . = ALIGN(0x10); /* Maintain proper alignment for .text section */ | ||
44 | } > IRAM | ||
45 | |||
46 | /* TRICK ALERT! Newer versions of the linker don't allow output sections | ||
47 | to overlap even if one of them is empty, so advance the location pointer | ||
48 | "by hand" */ | ||
49 | .text LOADADDR(.data) + SIZEOF(.data) : | ||
50 | { | ||
51 | *(.init.text) | ||
52 | *(.text*) | ||
53 | . = ALIGN(0x4); | ||
54 | } > IRAM | ||
55 | |||
56 | .rodata : | ||
57 | { | ||
58 | *(.rodata*) | ||
59 | . = ALIGN(0x4); | ||
60 | _iramcopy = .; | ||
61 | } > IRAM | ||
62 | |||
63 | .stack : | ||
64 | { | ||
65 | *(.stack) | ||
66 | _stackbegin = .; | ||
67 | stackbegin = .; | ||
68 | . += 0x2000; | ||
69 | _stackend = .; | ||
70 | stackend = .; | ||
71 | } > IRAM | ||
72 | |||
73 | .bss DRAMORIG+0x800000: | ||
74 | { | ||
75 | _edata = .; | ||
76 | *(.ibss) | ||
77 | *(.bss*) | ||
78 | *(COMMON) | ||
79 | _end = .; | ||
80 | } > DRAM | ||
81 | } | ||
diff --git a/firmware/target/coldfire/mpio/button-target.h b/firmware/target/coldfire/mpio/button-target.h new file mode 100644 index 0000000000..ae55612e56 --- /dev/null +++ b/firmware/target/coldfire/mpio/button-target.h | |||
@@ -0,0 +1,55 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | #ifndef _BUTTON_TARGET_H_ | ||
22 | #define _BUTTON_TARGET_H_ | ||
23 | |||
24 | #include <stdbool.h> | ||
25 | #include "config.h" | ||
26 | |||
27 | #define HAS_BUTTON_HOLD | ||
28 | |||
29 | bool button_hold(void); | ||
30 | void button_init_device(void); | ||
31 | int button_read_device(void); | ||
32 | |||
33 | /* HD200 specific button codes */ | ||
34 | /* Main unit's buttons - flags as in original firmware*/ | ||
35 | #define BUTTON_PLAY 0x00000001 | ||
36 | |||
37 | #define BUTTON_PREV 0x00000004 | ||
38 | #define BUTTON_NEXT 0x00000002 | ||
39 | #define BUTTON_VOL_UP 0x00000008 | ||
40 | #define BUTTON_VOL_DOWN 0x00000010 | ||
41 | #define BUTTON_REC 0x00000020 | ||
42 | #define BUTTON_SELECT 0x00002000 | ||
43 | |||
44 | #define BUTTON_LEFT BUTTON_PREV | ||
45 | #define BUTTON_RIGHT BUTTON_NEXT | ||
46 | #define BUTTON_ON BUTTON_PLAY | ||
47 | #define BUTTON_REMOTE 0x0 | ||
48 | |||
49 | #define BUTTON_MAIN (BUTTON_PLAY|BUTTON_PREV|BUTTON_NEXT|BUTTON_VOL_UP|\ | ||
50 | BUTTON_VOL_DOWN|BUTTON_REC|BUTTON_SELECT) | ||
51 | |||
52 | #define POWEROFF_BUTTON BUTTON_PLAY | ||
53 | #define POWEROFF_COUNT 30 | ||
54 | |||
55 | #endif /* _BUTTON_TARGET_H_ */ | ||
diff --git a/firmware/target/coldfire/mpio/fmradio_i2c-mpio.c b/firmware/target/coldfire/mpio/fmradio_i2c-mpio.c new file mode 100644 index 0000000000..a687c13200 --- /dev/null +++ b/firmware/target/coldfire/mpio/fmradio_i2c-mpio.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * Physical interface of the Philips TEA5767 in iAudio M3 | ||
10 | * | ||
11 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | #include "config.h" | ||
23 | |||
24 | #if (CONFIG_TUNER & TEA5767) | ||
25 | |||
26 | #include "i2c-coldfire.h" | ||
27 | #include "fmradio_i2c.h" | ||
28 | |||
29 | int fmradio_i2c_write(unsigned char address, const unsigned char* buf, | ||
30 | int count) | ||
31 | { | ||
32 | return i2c_write(I2C_IFACE_1, address, buf, count); | ||
33 | } | ||
34 | |||
35 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) | ||
36 | { | ||
37 | return i2c_read(I2C_IFACE_1, address, buf, count); | ||
38 | } | ||
39 | |||
40 | #endif | ||
diff --git a/firmware/target/coldfire/mpio/hd200/adc-hd200.c b/firmware/target/coldfire/mpio/hd200/adc-hd200.c new file mode 100644 index 0000000000..8bf96436bf --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/adc-hd200.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "thread.h" | ||
27 | #include "adc.h" | ||
28 | |||
29 | volatile unsigned short adc_data[NUM_ADC_CHANNELS] IBSS_ATTR; | ||
30 | |||
31 | /* Reading takes 4096 adclk ticks | ||
32 | * We do read one channel at once | ||
33 | * | ||
34 | * state FCPU Fbus Fadc bus/Fadc Fchannelread | ||
35 | * default 11.2896 MHz 5.6448 MHz 5.6448 MHz 2 172.2656 Hz | ||
36 | * normal 45.1584 MHz 22.5792 MHz 2.8224 MHz 8 172.2656 Hz | ||
37 | * max 124.1856 MHz 62.0928 MHz 1.9404 MHz 32 118.4326 Hz | ||
38 | */ | ||
39 | |||
40 | void ADC(void) __attribute__ ((interrupt_handler,section(".icode"))); | ||
41 | void ADC(void) | ||
42 | { | ||
43 | static unsigned char channel; | ||
44 | /* read current value */ | ||
45 | adc_data[(channel & 0x03)] = ADVALUE; | ||
46 | |||
47 | /* switch channel | ||
48 | * | ||
49 | * set source remark | ||
50 | * ADCONFIG is 16bit wide so we have to shift data by 16bits left | ||
51 | * thats why we shift <<24 instead of <<8 | ||
52 | */ | ||
53 | |||
54 | channel++; | ||
55 | |||
56 | and_l(~(3<<24),&ADCONFIG); | ||
57 | or_l( (((channel & 0x03) << 8 )|(1<<7))<<16, &ADCONFIG); | ||
58 | |||
59 | } | ||
60 | |||
61 | unsigned short adc_scan(int channel) | ||
62 | { | ||
63 | /* maybe we can drop &0x03 part */ | ||
64 | return adc_data[(channel&0x03)]; | ||
65 | } | ||
66 | |||
67 | void adc_init(void) | ||
68 | { | ||
69 | /* GPIO38 GPIO39 */ | ||
70 | and_l(~((1<<6)|(1<<7)), &GPIO1_FUNCTION); | ||
71 | |||
72 | /* ADOUT_SEL = 01 | ||
73 | * SOURCE SELECT = 000 | ||
74 | * CLEAR INTERRUPT FLAG | ||
75 | * ENABLE INTERRUPT = 1 | ||
76 | * ADOUT_DRIVE = 00 | ||
77 | * ADCLK_SEL = 011 (busclk/8) | ||
78 | */ | ||
79 | |||
80 | ADCONFIG = (1<<10)|(1<<7)|(1<<6)|(1<<1)|(1<<0); | ||
81 | |||
82 | /* ADC interrupt level 4.0 */ | ||
83 | or_l((4<<28), &INTPRI8); | ||
84 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/adc-target.h b/firmware/target/coldfire/mpio/hd200/adc-target.h new file mode 100644 index 0000000000..2e61065695 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/adc-target.h | |||
@@ -0,0 +1,41 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #ifndef _ADC_TARGET_H_ | ||
23 | #define _ADC_TARGET_H_ | ||
24 | |||
25 | #define NUM_ADC_CHANNELS 4 | ||
26 | |||
27 | #define ADC_BUTTONS 1 | ||
28 | #define ADC_REMOTE 0 | ||
29 | #define ADC_BATTERY 2 | ||
30 | #define ADC_REMOTEDETECT 3 | ||
31 | #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ | ||
32 | |||
33 | /* Force a scan now */ | ||
34 | unsigned short adc_scan(int channel); | ||
35 | |||
36 | static inline unsigned short adc_read(int channel) | ||
37 | { | ||
38 | return adc_scan(channel); | ||
39 | } | ||
40 | |||
41 | #endif /* _ADC_TARGET_H_ */ | ||
diff --git a/firmware/target/coldfire/mpio/hd200/backlight-hd200.c b/firmware/target/coldfire/mpio/hd200/backlight-hd200.c new file mode 100644 index 0000000000..783376c91e --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/backlight-hd200.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include "kernel.h" | ||
25 | #include "system.h" | ||
26 | #include "backlight.h" | ||
27 | #include "backlight-target.h" | ||
28 | #include "lcd.h" | ||
29 | |||
30 | static bool _backlight_on = false; | ||
31 | static int _brightness = DEFAULT_BRIGHTNESS_SETTING; | ||
32 | |||
33 | /* Returns the current state of the backlight (true=ON, false=OFF). */ | ||
34 | bool _backlight_init(void) | ||
35 | { | ||
36 | and_l(~(1<<28),&GPIO_OUT); | ||
37 | or_l((1<<28),&GPIO_FUNCTION); | ||
38 | or_l((1<<28),&GPIO_ENABLE); | ||
39 | return true; | ||
40 | } | ||
41 | |||
42 | void _backlight_hw_on(void) | ||
43 | { | ||
44 | |||
45 | if (_backlight_on) | ||
46 | return; | ||
47 | |||
48 | _backlight_set_brightness(_brightness); | ||
49 | _backlight_on = true; | ||
50 | |||
51 | } | ||
52 | |||
53 | void _backlight_hw_off(void) | ||
54 | { | ||
55 | /* GPIO28 low */ | ||
56 | and_l(~(1<<28),&GPIO_OUT); | ||
57 | _backlight_on = false; | ||
58 | } | ||
59 | |||
60 | void _backlight_set_brightness(int val) | ||
61 | { | ||
62 | unsigned char i; | ||
63 | |||
64 | and_l(~(1<<28),&GPIO_OUT); | ||
65 | sleep(4); | ||
66 | |||
67 | for (i=0;i<val;i++) | ||
68 | { | ||
69 | or_l((1<<28),&GPIO_OUT); | ||
70 | and_l(~(1<<28),&GPIO_OUT); | ||
71 | } | ||
72 | |||
73 | or_l((1<<28),&GPIO_OUT); | ||
74 | |||
75 | _brightness = val; | ||
76 | } | ||
77 | |||
78 | void _remote_backlight_on(void) | ||
79 | { | ||
80 | /* I don't have remote to play with */ | ||
81 | } | ||
82 | |||
83 | void _remote_backlight_off(void) | ||
84 | { | ||
85 | /* I don't have remote to play with */ | ||
86 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/backlight-target.h b/firmware/target/coldfire/mpio/hd200/backlight-target.h new file mode 100644 index 0000000000..0080ccac08 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/backlight-target.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | #ifndef BACKLIGHT_TARGET_H | ||
22 | #define BACKLIGHT_TARGET_H | ||
23 | |||
24 | bool _backlight_init(void); /* Returns backlight current state (true=ON). */ | ||
25 | void _backlight_hw_on(void); | ||
26 | void _backlight_hw_off(void); | ||
27 | void _backlight_set_brightness(int val); | ||
28 | |||
29 | #define _backlight_on() _backlight_hw_on() | ||
30 | #define _backlight_off() _backlight_hw_off() | ||
31 | #define _backlight_on_isr() _backlight_hw_on() | ||
32 | #define _backlight_off_isr() _backlight_hw_off() | ||
33 | #define _backlight_on_normal() _backlight_hw_on() | ||
34 | #define _backlight_off_normal() _backlight_hw_off() | ||
35 | #endif | ||
diff --git a/firmware/target/coldfire/mpio/hd200/button-hd200.c b/firmware/target/coldfire/mpio/hd200/button-hd200.c new file mode 100644 index 0000000000..b40c3324e1 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/button-hd200.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "button.h" | ||
26 | #include "backlight.h" | ||
27 | #include "adc.h" | ||
28 | |||
29 | void button_init_device(void) | ||
30 | { | ||
31 | /* Set GPIO36, GPIO56 as general purpose inputs */ | ||
32 | or_l((1<<4)|(1<<24),&GPIO1_FUNCTION); | ||
33 | and_l(~((1<<4)|(1<<24)),&GPIO1_ENABLE); | ||
34 | } | ||
35 | |||
36 | bool button_hold(void) | ||
37 | { | ||
38 | /* GPIO36 active high */ | ||
39 | return (GPIO1_READ & (1<<4))?true:false; | ||
40 | } | ||
41 | |||
42 | |||
43 | /* | ||
44 | * Get button pressed from hardware | ||
45 | */ | ||
46 | int button_read_device(void) | ||
47 | { | ||
48 | int btn = BUTTON_NONE; | ||
49 | int data = 0; | ||
50 | static bool hold_button = false; | ||
51 | |||
52 | /* for moving average filter */ | ||
53 | static unsigned short button_filter[4]; | ||
54 | static unsigned char index; | ||
55 | |||
56 | bool hold_button_old; | ||
57 | |||
58 | /* normal buttons */ | ||
59 | hold_button_old = hold_button; | ||
60 | hold_button = button_hold(); | ||
61 | |||
62 | |||
63 | #ifndef BOOTLOADER | ||
64 | if (hold_button != hold_button_old) | ||
65 | backlight_hold_changed(hold_button); | ||
66 | #endif | ||
67 | |||
68 | if (!hold_button) | ||
69 | { | ||
70 | |||
71 | /* simple moving average filter with 4 item window */ | ||
72 | button_filter[index&0x03] = adc_scan(ADC_BUTTONS); | ||
73 | index++; | ||
74 | |||
75 | data = (button_filter[0]+button_filter[1] \ | ||
76 | +button_filter[2]+button_filter[3])>>2; | ||
77 | |||
78 | |||
79 | if (data < 2250) // valid button | ||
80 | { | ||
81 | if (data < 900) /* middle */ | ||
82 | { | ||
83 | if (data < 500) | ||
84 | { | ||
85 | if (data > 200) | ||
86 | /* 200 - 500 */ | ||
87 | btn = BUTTON_REC; | ||
88 | } | ||
89 | else /* 900 - 500 */ | ||
90 | btn = BUTTON_VOL_DOWN; | ||
91 | } | ||
92 | else /* 2250 - 900 */ | ||
93 | { | ||
94 | if (data < 1600) | ||
95 | { | ||
96 | /* 1600 - 900 */ | ||
97 | if (data < 1200) | ||
98 | /* 1200 - 900 */ | ||
99 | btn = BUTTON_VOL_UP; | ||
100 | else /* 1600 - 1200 */ | ||
101 | btn = BUTTON_NEXT; | ||
102 | } | ||
103 | else /* 1600 - 2250 */ | ||
104 | { | ||
105 | if (data < 1900) | ||
106 | /* 1900 - 1600 */ | ||
107 | btn = BUTTON_PREV; | ||
108 | else /* 1900 - 2250 */ | ||
109 | btn = BUTTON_SELECT; | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | |||
115 | |||
116 | data = GPIO1_READ; | ||
117 | |||
118 | /* GPIO56 active high main PLAY/PAUSE/ON */ | ||
119 | if (!hold_button && ((data & (1<<24)))) | ||
120 | btn |= BUTTON_PLAY; | ||
121 | |||
122 | return btn; | ||
123 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/lcd-as-hd200.S b/firmware/target/coldfire/mpio/hd200/lcd-as-hd200.S new file mode 100644 index 0000000000..add9f694de --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/lcd-as-hd200.S | |||
@@ -0,0 +1,103 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | |||
25 | |||
26 | #define LCD_BASE_ADDRESS 0xf0000000 | ||
27 | |||
28 | .section .icode,"ax",@progbits | ||
29 | |||
30 | .align 2 | ||
31 | .global lcd_write_command | ||
32 | .type lcd_write_command,@function | ||
33 | |||
34 | lcd_write_command: | ||
35 | move.l (4, %sp), %d0 | ||
36 | move.w %d0, LCD_BASE_ADDRESS /* data is 1byte but CF uses word | ||
37 | * transfers only */ | ||
38 | rts | ||
39 | .wc_end: | ||
40 | .size lcd_write_command,.wc_end-lcd_write_command | ||
41 | |||
42 | |||
43 | .align 2 | ||
44 | .global lcd_write_command_e | ||
45 | .type lcd_write_command_e,@function | ||
46 | |||
47 | lcd_write_command_e: | ||
48 | lea.l LCD_BASE_ADDRESS, %a0 | ||
49 | |||
50 | move.l (4, %sp), %d0 /* Command */ | ||
51 | move.w %d0, (%a0) | ||
52 | move.l (8, %sp), %d0 /* Data */ | ||
53 | move.w %d0, (%a0) /* Write to LCD */ | ||
54 | |||
55 | rts | ||
56 | .wce_end: | ||
57 | .size lcd_write_command_e,.wce_end-lcd_write_command_e | ||
58 | |||
59 | |||
60 | .align 2 | ||
61 | .global lcd_write_data | ||
62 | .type lcd_write_data,@function | ||
63 | |||
64 | /* PIXELFORMAT = VERTICAL_INTERLEAVED | ||
65 | * this means that data is packed verticaly in 8 pixels columns | ||
66 | * first byte is lsb of 2bit color in column | ||
67 | * second byte is msb of 2bit color in column | ||
68 | * so one word of data equals 8 pixels i 2bits color depth packed | ||
69 | * verticaly | ||
70 | */ | ||
71 | lcd_write_data: | ||
72 | movem.l (4, %sp), %a0 /* Data pointer */ | ||
73 | move.l (8, %sp), %d0 /* Length i in words */ | ||
74 | lea LCD_BASE_ADDRESS+2, %a1 /* LCD data port address */ | ||
75 | |||
76 | btst #0, %d0 /* longwords multiply? */ | ||
77 | beq .l_write | ||
78 | |||
79 | .w_write: | ||
80 | move.w (%a0)+, %d1 /* load data 3 cycles*/ | ||
81 | move.w %d1, (%a1) /* first byte 1 cycle*/ | ||
82 | lsr.l #8, %d1 /* load second byte 1 cycle*/ | ||
83 | move.w %d1, (%a1) /* transfer 1 cycle*/ | ||
84 | subq.l #1, %d0 /* decrement counter 1 cycle*/ | ||
85 | beq .write_end | ||
86 | |||
87 | .l_write: | ||
88 | move.l (%a0)+, %d1 /* load data 2 cycles*/ | ||
89 | swap %d1 /* 1 cycle */ | ||
90 | move.w %d1, (%a1) /* first byte 1 cycle*/ | ||
91 | lsr.l #8, %d1 /* 1 cycle */ | ||
92 | move.w %d1, (%a1) /* second byte 1 cycle*/ | ||
93 | lsr.l #8, %d1 /* 1 cycle */ | ||
94 | move.w %d1, (%a1) /* third byte 1 cycle*/ | ||
95 | lsr.l #8, %d1 /* 1 cycle */ | ||
96 | move.w %d1, (%a1) /* forth byte 1 cycle*/ | ||
97 | subq.l #2, %d0 /* decrement counter 1 cycle*/ | ||
98 | bne .l_write | ||
99 | |||
100 | .write_end: | ||
101 | rts | ||
102 | .size lcd_write_data,.wd_end-lcd_write_data | ||
103 | |||
diff --git a/firmware/target/coldfire/mpio/hd200/lcd-hd200.c b/firmware/target/coldfire/mpio/hd200/lcd-hd200.c new file mode 100644 index 0000000000..8cb9e8e087 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/lcd-hd200.c | |||
@@ -0,0 +1,241 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #include "config.h" | ||
23 | |||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "lcd.h" | ||
27 | |||
28 | /*** definitions ***/ | ||
29 | /* TOMATO LSI 0350 - definitions and slightly tweaked functions | ||
30 | * taken from lcd-remote-iaudio.c | ||
31 | */ | ||
32 | |||
33 | #define LCD_SET_DUTY_RATIO 0x48 | ||
34 | #define LCD_SELECT_ADC 0xa0 | ||
35 | #define LCD_SELECT_SHL 0xc0 | ||
36 | #define LCD_SET_COM0 0x44 | ||
37 | #define LCD_OSC_ON 0xab | ||
38 | #define LCD_SELECT_DCDC 0x64 | ||
39 | #define LCD_SELECT_RES 0x20 | ||
40 | #define LCD_SET_VOLUME 0x81 | ||
41 | #define LCD_SET_BIAS 0x50 | ||
42 | #define LCD_CONTROL_POWER 0x28 | ||
43 | #define LCD_DISPLAY_ON 0xae | ||
44 | #define LCD_SET_INITLINE 0x40 | ||
45 | #define LCD_SET_COLUMN 0x10 | ||
46 | #define LCD_SET_PAGE 0xb0 | ||
47 | #define LCD_SET_GRAY 0x88 | ||
48 | #define LCD_SET_PWM_FRC 0x90 | ||
49 | #define LCD_SET_POWER_SAVE 0xa8 | ||
50 | #define LCD_REVERSE 0xa6 | ||
51 | #define LCD_RESET 0xe2 | ||
52 | |||
53 | /* cached settings */ | ||
54 | static bool cached_invert = false; | ||
55 | static bool cached_flip = false; | ||
56 | static int cached_contrast = DEFAULT_CONTRAST_SETTING; | ||
57 | bool lcd_initialized = false; | ||
58 | |||
59 | /*** hardware configuration ***/ | ||
60 | int lcd_default_contrast(void) | ||
61 | { | ||
62 | return DEFAULT_CONTRAST_SETTING; | ||
63 | } | ||
64 | |||
65 | void lcd_powersave(bool on) | ||
66 | { | ||
67 | /* What is the point of having else construct here? */ | ||
68 | if(lcd_initialized) { | ||
69 | if (on) | ||
70 | lcd_write_command(LCD_SET_POWER_SAVE | 1); | ||
71 | else | ||
72 | lcd_write_command(LCD_SET_POWER_SAVE | 1); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | void lcd_set_contrast(int val) | ||
77 | { | ||
78 | if (val < MIN_CONTRAST_SETTING) | ||
79 | val = MIN_CONTRAST_SETTING; | ||
80 | else if (val > MAX_CONTRAST_SETTING) | ||
81 | val = MAX_CONTRAST_SETTING; | ||
82 | |||
83 | cached_contrast = val; | ||
84 | if(lcd_initialized) | ||
85 | lcd_write_command_e(LCD_SET_VOLUME, val); | ||
86 | } | ||
87 | |||
88 | void lcd_set_invert_display(bool yesno) | ||
89 | { | ||
90 | cached_invert = yesno; | ||
91 | if(lcd_initialized) | ||
92 | lcd_write_command(LCD_REVERSE | yesno); | ||
93 | |||
94 | } | ||
95 | |||
96 | /* turn the display upside down (call lcd_update() afterwards) */ | ||
97 | void lcd_set_flip(bool yesno) | ||
98 | { | ||
99 | cached_flip = yesno; | ||
100 | if(lcd_initialized) | ||
101 | { | ||
102 | if(yesno) | ||
103 | { | ||
104 | lcd_write_command(LCD_SELECT_ADC | 1); | ||
105 | lcd_write_command(LCD_SELECT_SHL | 0); | ||
106 | lcd_write_command_e(LCD_SET_COM0, 0); | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | lcd_write_command(LCD_SELECT_ADC | 0); | ||
111 | lcd_write_command(LCD_SELECT_SHL | 8); | ||
112 | lcd_write_command_e(LCD_SET_COM0, 0); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | } | ||
117 | |||
118 | void lcd_shutdown(void) | ||
119 | { | ||
120 | /* Set power save -> Power OFF (VDD - VSS) .. that's it */ | ||
121 | if (lcd_initialized) | ||
122 | lcd_write_command(LCD_SET_POWER_SAVE | 1); | ||
123 | } | ||
124 | |||
125 | void lcd_init_device(void) | ||
126 | { | ||
127 | and_l(~0x00000800, &GPIO_FUNCTION); /* CS3 line */ | ||
128 | |||
129 | /* LCD Reset GPO34 */ | ||
130 | or_l(0x00000004, &GPIO1_ENABLE); /* set as output */ | ||
131 | or_l(0x00000004, &GPIO1_FUNCTION); /* switch to secondary function - GPIO */ | ||
132 | |||
133 | and_l(~0x00000004, &GPIO1_OUT); /* RESET low */ | ||
134 | sleep(1); /* delay at least 1000 ns */ | ||
135 | or_l(0x00000004, &GPIO1_OUT); /* RESET high */ | ||
136 | sleep(1); | ||
137 | |||
138 | /* parameters setup taken from original firmware */ | ||
139 | lcd_write_command(LCD_RESET); | ||
140 | lcd_write_command_e(LCD_SET_DUTY_RATIO,0x80); /* 1/128 */ | ||
141 | lcd_write_command(LCD_OSC_ON); | ||
142 | lcd_write_command(LCD_SELECT_DCDC | 3); /* DC/DC 6xboost */ | ||
143 | lcd_write_command(LCD_SELECT_RES | 7); /* Regulator resistor: 7.2 */ | ||
144 | lcd_write_command(LCD_SET_BIAS | 6); /* 1/11 */ | ||
145 | lcd_write_command(LCD_SET_PWM_FRC | 6); /* 3FRC + 12PWM */ | ||
146 | lcd_write_command_e(LCD_SET_GRAY | 0, 0x00); | ||
147 | lcd_write_command_e(LCD_SET_GRAY | 1, 0x00); | ||
148 | lcd_write_command_e(LCD_SET_GRAY | 2, 0x0c); | ||
149 | lcd_write_command_e(LCD_SET_GRAY | 3, 0x00); | ||
150 | lcd_write_command_e(LCD_SET_GRAY | 4, 0xc4); | ||
151 | lcd_write_command_e(LCD_SET_GRAY | 5, 0x00); | ||
152 | lcd_write_command_e(LCD_SET_GRAY | 6, 0xcc); | ||
153 | lcd_write_command_e(LCD_SET_GRAY | 7, 0x00); | ||
154 | |||
155 | lcd_write_command(LCD_CONTROL_POWER | 7); /* All circuits ON */ | ||
156 | lcd_write_command(LCD_DISPLAY_ON | 1); /* display on */ | ||
157 | |||
158 | /* Ok we are ready */ | ||
159 | lcd_initialized = true; | ||
160 | |||
161 | lcd_set_flip(cached_flip); | ||
162 | lcd_set_contrast(cached_contrast); | ||
163 | lcd_set_invert_display(cached_invert); | ||
164 | |||
165 | lcd_update(); | ||
166 | } | ||
167 | |||
168 | /* Update the display. | ||
169 | This must be called after all other LCD functions that change the display. */ | ||
170 | void lcd_update(void) ICODE_ATTR; | ||
171 | void lcd_update(void) | ||
172 | { | ||
173 | int y; | ||
174 | if(!lcd_initialized) | ||
175 | return; | ||
176 | |||
177 | for(y = 0;y < LCD_FBHEIGHT;y++) | ||
178 | { | ||
179 | lcd_write_command(LCD_SET_PAGE | y); | ||
180 | lcd_write_command_e(LCD_SET_COLUMN, 0); | ||
181 | lcd_write_data(lcd_framebuffer[y], LCD_WIDTH); | ||
182 | } | ||
183 | |||
184 | |||
185 | } | ||
186 | |||
187 | /* Update a fraction of the display. */ | ||
188 | void lcd_update_rect(int, int, int, int) ICODE_ATTR; | ||
189 | void lcd_update_rect(int x, int y, int width, int height) | ||
190 | { | ||
191 | int ymax; | ||
192 | |||
193 | if (!lcd_initialized) | ||
194 | return; | ||
195 | |||
196 | |||
197 | /* The Y coordinates have to work on even 8 pixel rows */ | ||
198 | ymax = (y + height-1) >> 3; | ||
199 | y >>= 3; | ||
200 | |||
201 | if(x + width > LCD_WIDTH) | ||
202 | width = LCD_WIDTH - x; | ||
203 | if (width <= 0) | ||
204 | return; /* nothing left to do, 0 is harmful to lcd_write_data() */ | ||
205 | if(ymax >= LCD_FBHEIGHT) | ||
206 | ymax = LCD_FBHEIGHT-1; | ||
207 | |||
208 | /* Copy specified rectange bitmap to hardware */ | ||
209 | for (; y <= ymax; y++) | ||
210 | { | ||
211 | lcd_write_command(LCD_SET_PAGE | y ); | ||
212 | lcd_write_command_e(LCD_SET_COLUMN | ((x >> 4) & 0xf), x & 0x0f); | ||
213 | lcd_write_data (&lcd_framebuffer[y][x], width); | ||
214 | } | ||
215 | |||
216 | } | ||
217 | |||
218 | void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, | ||
219 | int x, int by, int width, int bheight, int stride) | ||
220 | { | ||
221 | (void)values; | ||
222 | (void)phases; | ||
223 | (void)x; | ||
224 | (void)by; | ||
225 | (void)width; | ||
226 | (void)bheight; | ||
227 | (void)stride; | ||
228 | /* empty stub */ | ||
229 | } | ||
230 | |||
231 | void lcd_blit_mono(const unsigned char *data, int x, int by, int width, | ||
232 | int bheight, int stride) | ||
233 | { | ||
234 | (void)data; | ||
235 | (void)x; | ||
236 | (void)by; | ||
237 | (void)width; | ||
238 | (void)bheight; | ||
239 | (void)stride; | ||
240 | /* empty stub */ | ||
241 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/power-hd200.c b/firmware/target/coldfire/mpio/hd200/power-hd200.c new file mode 100644 index 0000000000..dd8576b9e4 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/power-hd200.c | |||
@@ -0,0 +1,113 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include <stdbool.h> | ||
25 | #include "kernel.h" | ||
26 | #include "system.h" | ||
27 | #include "lcd.h" | ||
28 | #include "power.h" | ||
29 | |||
30 | #if CONFIG_TUNER | ||
31 | bool tuner_power(bool status) | ||
32 | { | ||
33 | (void)status; | ||
34 | if (status) | ||
35 | { | ||
36 | and_l(~(1<<17), &GPIO1_OUT); | ||
37 | } | ||
38 | else | ||
39 | { | ||
40 | or_l((1<<17), &GPIO1_OUT); | ||
41 | } | ||
42 | |||
43 | return status; | ||
44 | } | ||
45 | #endif /* #if CONFIG_TUNER */ | ||
46 | |||
47 | void power_init(void) | ||
48 | { | ||
49 | /* GPIO53 has to be high - low resets device */ | ||
50 | /* GPIO49 is FM related */ | ||
51 | or_l((1<<21)|(1<<17), &GPIO1_OUT); | ||
52 | or_l((1<<21)|(1<<17), &GPIO1_ENABLE); | ||
53 | or_l((1<<21)|(1<<17)|(1<<14), &GPIO1_FUNCTION); | ||
54 | |||
55 | and_l(~(1<<15), &GPIO_OUT); | ||
56 | or_l((1<<15),&GPIO_ENABLE); | ||
57 | or_l((1<<15),&GPIO_FUNCTION); | ||
58 | |||
59 | or_l((1<<23), &GPIO_OUT); | ||
60 | and_l(~(1<<23), &GPIO_ENABLE); | ||
61 | or_l((1<<23), &GPIO_FUNCTION); | ||
62 | |||
63 | #ifndef BOOTLOADER | ||
64 | /* The boot loader controls the power */ | ||
65 | ide_power_enable(true); | ||
66 | #endif | ||
67 | } | ||
68 | |||
69 | unsigned int power_input_status(void) | ||
70 | { | ||
71 | unsigned int status = POWER_INPUT_NONE; | ||
72 | /* GPIO46 is AC plug detect (low = AC plugged) */ | ||
73 | if (!(GPIO1_READ & (1<<14))) | ||
74 | status |= POWER_INPUT_MAIN_CHARGER; | ||
75 | |||
76 | return status; | ||
77 | } | ||
78 | |||
79 | /* Returns true if the unit is charging the batteries. */ | ||
80 | bool charging_state(void) | ||
81 | { | ||
82 | if (!(GPIO1_READ & (1<<14))) | ||
83 | return (GPIO_READ & (1<<30) )?false:true; | ||
84 | else | ||
85 | return false; | ||
86 | } | ||
87 | |||
88 | void ide_power_enable(bool on) | ||
89 | { | ||
90 | (void)on; | ||
91 | if (on) | ||
92 | and_l(~(1<<31),&GPIO_OUT); | ||
93 | else | ||
94 | or_l((1<<31),&GPIO_OUT); | ||
95 | |||
96 | or_l((1<<31),&GPIO_ENABLE); | ||
97 | or_l((1<<31),&GPIO_FUNCTION); | ||
98 | |||
99 | } | ||
100 | |||
101 | bool ide_powered(void) | ||
102 | { | ||
103 | return true; | ||
104 | } | ||
105 | |||
106 | void power_off(void) | ||
107 | { | ||
108 | lcd_shutdown(); | ||
109 | set_irq_level(DISABLE_INTERRUPTS); | ||
110 | and_l(~(1<<21), &GPIO1_OUT); /* pull KEEPACT low */ | ||
111 | asm("halt"); | ||
112 | while(1); | ||
113 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c b/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c new file mode 100644 index 0000000000..23a0bac927 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | |||
22 | #include "config.h" | ||
23 | #include "adc.h" | ||
24 | #include "powermgmt.h" | ||
25 | |||
26 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
27 | { | ||
28 | 3700 | ||
29 | }; | ||
30 | |||
31 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
32 | { | ||
33 | 3650 | ||
34 | }; | ||
35 | |||
36 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
37 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | ||
38 | { | ||
39 | /* from OF and measurements voltage range is 3.7-4.1 V */ | ||
40 | { 3700, 3740, 3780, 3820, 3860, 3900, 3940, 3980, 4020, 4060, 4100 } | ||
41 | }; | ||
42 | |||
43 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | ||
44 | const unsigned short percent_to_volt_charge[11] = | ||
45 | { | ||
46 | /* values measured over one full charging cycle */ | ||
47 | 3540, 3860, 3930, 3980, 4000, 4020, 4040, 4080, 4130, 4180, 4230 /* LiPo */ | ||
48 | }; | ||
49 | |||
50 | /* 3.33V as reference */ | ||
51 | #define BATTERY_SCALE_FACTOR 3330 | ||
52 | |||
53 | |||
54 | /* Returns battery voltage from ADC [millivolts] */ | ||
55 | unsigned int battery_adc_voltage(void) | ||
56 | { | ||
57 | return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 11; | ||
58 | } | ||
59 | |||
diff --git a/firmware/target/coldfire/mpio/hd200/system-hd200.c b/firmware/target/coldfire/mpio/hd200/system-hd200.c new file mode 100644 index 0000000000..06628c0835 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/system-hd200.c | |||
@@ -0,0 +1,125 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | #include "cpu.h" | ||
23 | #include "kernel.h" | ||
24 | #include "system.h" | ||
25 | #include "power.h" | ||
26 | #include "timer.h" | ||
27 | |||
28 | /* Settings for all possible clock frequencies (with properly working timers) | ||
29 | * | ||
30 | * xxx_REFRESH_TIMER below | ||
31 | * system.h, CPUFREQ_xxx_MULT | | ||
32 | * | | | ||
33 | * V V | ||
34 | * PLLCR & Rftim. IDECONFIG1/IDECONFIG2 | ||
35 | * CPUCLK/Hz MULT ~0x70c00000 16MB CSCR0 CSCR1 CS2Pre CS2Post CS2Wait | ||
36 | * ------------------------------------------------------------------------- | ||
37 | * 11289600 1 0x00000200 4 0x0180 0x0180 1 1 0 | ||
38 | * 22579200 2 0x05028049 10 0x0180 0x0180 1 1 0 | ||
39 | * 33868800 3 0x03024049 15 0x0180 0x0180 1 1 0 | ||
40 | * 45158400 4 0x05028045 21 0x0180 0x0180 1 1 0 | ||
41 | * 56448000 5 0x02028049 26 0x0580 0x0580 2 1 0 | ||
42 | * 67737600 6 0x03024045 32 0x0580 0x0980 2 1 0 | ||
43 | * 79027200 7 0x0302a045 37 0x0580 0x0d80 2 1 0 | ||
44 | * 90316800 8 0x03030045 43 0x0980 0x0d80 2 1 0 | ||
45 | * 101606400 9 0x01024049 48 0x0980 0x1180 2 1 0 | ||
46 | * 112896000 10 0x01028049 54 0x0980 0x1580 3 1 0 | ||
47 | * 124185600 11 0x0102c049 59 0x0980 0x1180 3 1 1 | ||
48 | */ | ||
49 | |||
50 | #define MAX_REFRESH_TIMER 59 | ||
51 | #define NORMAL_REFRESH_TIMER 21 | ||
52 | #define DEFAULT_REFRESH_TIMER 4 | ||
53 | |||
54 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
55 | void set_cpu_frequency (long) __attribute__ ((section (".icode"))); | ||
56 | void set_cpu_frequency(long frequency) | ||
57 | #else | ||
58 | void cf_set_cpu_frequency (long) __attribute__ ((section (".icode"))); | ||
59 | void cf_set_cpu_frequency(long frequency) | ||
60 | #endif | ||
61 | { | ||
62 | switch(frequency) | ||
63 | { | ||
64 | case CPUFREQ_MAX: | ||
65 | DCR = (0x8200 | DEFAULT_REFRESH_TIMER); | ||
66 | /* Refresh timer for bypass frequency */ | ||
67 | PLLCR &= ~1; /* Bypass mode */ | ||
68 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); | ||
69 | PLLCR = 0x0102c049 | (PLLCR & 0x70C00000); | ||
70 | CSCR0 = 0x00001180; /* Flash: 4 wait states */ | ||
71 | CSCR3 = 0x00001180; /* LCD: 4 wait states */ | ||
72 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. | ||
73 | This may take up to 10ms! */ | ||
74 | timers_adjust_prescale(CPUFREQ_MAX_MULT, true); | ||
75 | DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ | ||
76 | cpu_frequency = CPUFREQ_MAX; | ||
77 | IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(3<<10); | ||
78 | /* BUFEN2 enable on /CS2 | CS2Post 1 clock| CS2Pre 3 clocks*/ | ||
79 | IDECONFIG2 = (1<<18)|(1<<16)|(1<<8)|(1<<0); /* TA /CS2 enable + CS2wait */ | ||
80 | |||
81 | and_l(~(0x07<<16), &ADCONFIG); | ||
82 | or_l(((1<<7)|(1<<2)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/32 */ | ||
83 | |||
84 | break; | ||
85 | |||
86 | case CPUFREQ_NORMAL: | ||
87 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; | ||
88 | /* Refresh timer for bypass frequency */ | ||
89 | PLLCR &= ~1; /* Bypass mode */ | ||
90 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); | ||
91 | PLLCR = 0x05028045 | (PLLCR & 0x70C00000); | ||
92 | CSCR0 = 0x00000580; /* Flash: 1 wait state */ | ||
93 | CSCR3 = 0x00000980; /* LCD: 0 wait states */ | ||
94 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. | ||
95 | This may take up to 10ms! */ | ||
96 | timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); | ||
97 | DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ | ||
98 | cpu_frequency = CPUFREQ_NORMAL; | ||
99 | IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10); | ||
100 | IDECONFIG2 = (1<<18)|(1<<16); | ||
101 | |||
102 | and_l(~(0x07<<16), &ADCONFIG); | ||
103 | or_l(((1<<7)|(1<<1)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/8 */ | ||
104 | |||
105 | break; | ||
106 | default: | ||
107 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; | ||
108 | /* Refresh timer for bypass frequency */ | ||
109 | PLLCR &= ~1; /* Bypass mode */ | ||
110 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); | ||
111 | /* Power down PLL, but keep CLSEL and CRSEL */ | ||
112 | PLLCR = 0x00000200 | (PLLCR & 0x70C00000); | ||
113 | CSCR0 = 0x00000180; /* Flash: 0 wait states */ | ||
114 | CSCR3 = 0x00000980; /* LCD: 0 wait states */ | ||
115 | DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ | ||
116 | cpu_frequency = CPUFREQ_DEFAULT; | ||
117 | IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10); | ||
118 | IDECONFIG2 = (1<<18)|(1<<16); | ||
119 | |||
120 | and_l(~(0x07<<16), &ADCONFIG); | ||
121 | or_l(((1<<7)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/2 */ | ||
122 | |||
123 | break; | ||
124 | } | ||
125 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/usb-hd200.c b/firmware/target/coldfire/mpio/hd200/usb-hd200.c new file mode 100644 index 0000000000..8f348b8038 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/usb-hd200.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
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 | #include <stdbool.h> | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "usb.h" | ||
27 | |||
28 | void usb_init_device(void) | ||
29 | { | ||
30 | /* GPIO42 is USB detect input | ||
31 | * but it also serves as MCLK2 for DAC | ||
32 | */ | ||
33 | and_l(~(1<<4), &GPIO1_OUT); | ||
34 | or_l((1<<4)|(1<<18), &GPIO1_ENABLE); /* GPIO36 GPIO50 */ | ||
35 | or_l((1<<4)|(1<<18), &GPIO1_FUNCTION); | ||
36 | |||
37 | /* GPIO22 GPIO30*/ | ||
38 | /* GPIO31 has to be low to ATA work */ | ||
39 | or_l((1<<22)|(1<<30), &GPIO_OUT); | ||
40 | or_l((1<<22)|(1<<30)|(1<<31), &GPIO_ENABLE); | ||
41 | or_l((1<<22)|(1<<30)|(1<<31), &GPIO_FUNCTION); | ||
42 | } | ||
43 | |||
44 | int usb_detect(void) | ||
45 | { | ||
46 | /* GPIO42 active low*/ | ||
47 | return (GPIO1_READ & (1<<10)) ? USB_EXTRACTED : USB_INSERTED; | ||
48 | } | ||
49 | |||
50 | void usb_enable(bool on) | ||
51 | { | ||
52 | |||
53 | if(on) | ||
54 | { | ||
55 | or_l((1<<18),&GPIO1_OUT); /* GPIO50 high */ | ||
56 | |||
57 | and_l(~(1<<30),&GPIO_OUT); /* GPIO30 low */ | ||
58 | /* GPIO36 low delay GPIO36 high delay */ | ||
59 | and_l(~(1<<4),&GPIO1_OUT); | ||
60 | or_l((1<<4),&GPIO1_OUT); | ||
61 | |||
62 | and_l(~(1<<18),&GPIO1_OUT); /* GPIO50 low */ | ||
63 | sleep(HZ/5); /* delay 200 ms */ | ||
64 | and_l(~(1<<22),&GPIO_OUT); /* GPIO22 low */ | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | /* GPIO36 low delay GPIO36 high delay */ | ||
69 | and_l(~(1<<4),&GPIO1_OUT); | ||
70 | sleep(HZ/100); | ||
71 | or_l((1<<4),&GPIO1_OUT); | ||
72 | sleep(HZ/100); | ||
73 | |||
74 | or_l((1<<22),&GPIO_OUT); /* GPIO22 high */ | ||
75 | or_l((1<<30),&GPIO_OUT); /* GPIO30 high */ | ||
76 | |||
77 | and_l(~(1<<4),&GPIO1_OUT); /* GPIO36 low */ | ||
78 | |||
79 | //or_l((1<<18),&GPIO1_OUT); /* GPIO50 high */ | ||
80 | } | ||
81 | } | ||
diff --git a/firmware/target/coldfire/wmcodec-coldfire.c b/firmware/target/coldfire/wmcodec-coldfire.c new file mode 100644 index 0000000000..4403b9a2a2 --- /dev/null +++ b/firmware/target/coldfire/wmcodec-coldfire.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Coldfire specific code for Wolfson audio codecs based on | ||
11 | * wmcodec-pp.c | ||
12 | * | ||
13 | * Based on code from the ipodlinux project - http://ipodlinux.org/ | ||
14 | * Adapted for Rockbox in December 2005 | ||
15 | * | ||
16 | * Original file: linux/arch/armnommu/mach-ipod/audio.c | ||
17 | * | ||
18 | * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org) | ||
19 | * | ||
20 | * This program is free software; you can redistribute it and/or | ||
21 | * modify it under the terms of the GNU General Public License | ||
22 | * as published by the Free Software Foundation; either version 2 | ||
23 | * of the License, or (at your option) any later version. | ||
24 | * | ||
25 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
26 | * KIND, either express or implied. | ||
27 | * | ||
28 | ****************************************************************************/ | ||
29 | #include "system.h" | ||
30 | #include "audiohw.h" | ||
31 | #include "i2c-coldfire.h" | ||
32 | #include "i2s.h" | ||
33 | #include "wmcodec.h" | ||
34 | |||
35 | #if defined(MPIO_HD200) | ||
36 | #define I2C_CODEC_ADDRESS 0x34 | ||
37 | #define I2C_IFACE I2C_IFACE_1 | ||
38 | #endif | ||
39 | |||
40 | void audiohw_init(void) | ||
41 | { | ||
42 | audiohw_preinit(); | ||
43 | } | ||
44 | |||
45 | void wmcodec_write(int reg, int data) | ||
46 | { | ||
47 | unsigned char wmdata[2]; | ||
48 | wmdata[0] = (reg << 1) | ((data & 0x100)>>8); | ||
49 | wmdata[1] = data & 0xff; | ||
50 | i2c_write(I2C_IFACE,I2C_CODEC_ADDRESS,wmdata,2); | ||
51 | return; | ||
52 | } | ||
diff --git a/rbutil/mkmpioboot/Makefile b/rbutil/mkmpioboot/Makefile new file mode 100644 index 0000000000..f50392793e --- /dev/null +++ b/rbutil/mkmpioboot/Makefile | |||
@@ -0,0 +1,94 @@ | |||
1 | |||
2 | #change for releases | ||
3 | ifndef APPVERSION | ||
4 | APPVERSION=`../../tools/version.sh ../../` | ||
5 | endif | ||
6 | |||
7 | # We use the UCL code available in the Rockbox tools/ directory | ||
8 | CFLAGS=-I../../tools/ucl/include -Wall -DVERSION=\"$(APPVERSION)\" | ||
9 | |||
10 | ifndef V | ||
11 | SILENT = @ | ||
12 | endif | ||
13 | |||
14 | ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) | ||
15 | OUTPUT=mkmpioboot.exe | ||
16 | CFLAGS+=-mno-cygwin | ||
17 | else | ||
18 | ifeq ($(findstring MINGW,$(shell uname)),MINGW) | ||
19 | OUTPUT=mkmpioboot.exe | ||
20 | else | ||
21 | ifeq ($(findstring mingw,$(CC)),mingw) | ||
22 | OUTPUT=mkmpioboot.exe | ||
23 | else | ||
24 | OUTPUT=mkmpioboot | ||
25 | endif | ||
26 | endif | ||
27 | endif | ||
28 | |||
29 | ifdef RBARCH | ||
30 | CFLAGS += -arch $(RBARCH) | ||
31 | OBJDIR = $(RBARCH)/ | ||
32 | endif | ||
33 | |||
34 | |||
35 | all: $(OUTPUT) | ||
36 | |||
37 | # inputs | ||
38 | LIBSOURCES := mkmpioboot.c | ||
39 | SOURCES := $(LIBSOURCES) main.c | ||
40 | OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(SOURCES))) | ||
41 | LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(LIBSOURCES))) | ||
42 | EXTRADEPS := $(LIBUCL) | ||
43 | |||
44 | # explicit dependencies | ||
45 | $(OBJDIR)mkmpioboot.o: mkmpioboot.c mkmpioboot.h | ||
46 | $(OBJDIR)main.o: main.c | ||
47 | |||
48 | $(OBJDIR)%.o: %.c | ||
49 | @echo CC $< $ | ||
50 | $(SILENT)mkdir -p $(dir $@) | ||
51 | $(SILENT)$(CC) $(CFLAGS) -c -o $@ $< | ||
52 | |||
53 | libmkamsboot$(RBARCH).a: $(LIBOBJS) | ||
54 | @echo AR $@ | ||
55 | $(SILENT)$(AR) ruc $(TARGET_DIR)$@ $^ | ||
56 | |||
57 | # building the standalone executable | ||
58 | $(OUTPUT): $(OBJS) $(EXTRADEPS) | ||
59 | @echo LD $@ | ||
60 | $(SILENT)$(CC) $(CFLAGS) -o $(OUTPUT) $(OBJS) $(EXTRADEPS) | ||
61 | |||
62 | # some trickery to build ppc and i386 from a single call | ||
63 | ifeq ($(RBARCH),) | ||
64 | $(TARGET_DIR)libmkmpiobooti386.a: | ||
65 | make RBARCH=i386 TARGET_DIR=$(TARGET_DIR) libmkmpiobooti386.a | ||
66 | |||
67 | $(TARGET_DIR)libmkmpiobootppc.a: | ||
68 | make RBARCH=ppc TARGET_DIR=$(TARGET_DIR) libmkmpiobootppc.a | ||
69 | endif | ||
70 | |||
71 | libmkmpioboot-universal: $(TARGET_DIR)libmkmpiobooti386.a $(TARGET_DIR)libmkmpiobootppc.a | ||
72 | @echo lipo $(TARGET_DIR)libmkmpioboot.a | ||
73 | $(SILENT) rm -f $(TARGET_DIR)libmkmpioboot.a | ||
74 | $(SILENT)lipo -create $(TARGET_DIR)libmkmpiobootppc.a $(TARGET_DIR)libmkmpiobooti386.a -output $(TARGET_DIR)libmkmpioboot.a | ||
75 | |||
76 | clean: | ||
77 | rm -f $(OBJS) $(OUTPUT) libmkmpioboot.o $(TARGET_DIR)libmkmpioboot*.a mkmpioboot.dmg | ||
78 | rm -rf mkmpioboot-* i386 ppc $(OBJDIR) | ||
79 | |||
80 | mkmpioboot-i386: | ||
81 | $(MAKE) RBARCH=i386 | ||
82 | mv mkmpioboot mkmpioboot-i386 | ||
83 | |||
84 | mkmpioboot-ppc: | ||
85 | $(MAKE) RBARCH=ppc | ||
86 | mv mkmpioboot mkmpioboot-ppc | ||
87 | |||
88 | mkmpioboot-mac: mkmpioboot-i386 mkmpioboot-ppc | ||
89 | $(SILENT)lipo -create mkmpioboot-ppc mkmpioboot-i386 -output mkmpioboot-mac | ||
90 | |||
91 | mkmpioboot.dmg: mkmpioboot-mac | ||
92 | mkdir -p mkmpioboot-dmg | ||
93 | cp -p mkmpioboot-mac mkmpioboot-dmg | ||
94 | hdiutil create -srcfolder mkmpioboot-dmg mkmpioboot.dmg | ||
diff --git a/rbutil/mkmpioboot/main.c b/rbutil/mkmpioboot/main.c new file mode 100644 index 0000000000..38e6d25288 --- /dev/null +++ b/rbutil/mkmpioboot/main.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 by Marcin Bukat | ||
11 | * | ||
12 | * code taken mostly from mkboot.c | ||
13 | * Copyright (C) 2005 by Linus Nielsen Feltzing | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * as published by the Free Software Foundation; either version 2 | ||
18 | * of the License, or (at your option) any later version. | ||
19 | * | ||
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
21 | * KIND, either express or implied. | ||
22 | * | ||
23 | ****************************************************************************/ | ||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include "mkmpioboot.h" | ||
28 | |||
29 | static void usage(void) | ||
30 | { | ||
31 | printf("usage: mkmpioboot <firmware file> <boot file> <output file>\n"); | ||
32 | exit(1); | ||
33 | } | ||
34 | |||
35 | int main(int argc, char *argv[]) | ||
36 | { | ||
37 | char *infile, *bootfile, *outfile; | ||
38 | int origin = 0xe0000; /* MPIO HD200 bootloader address */ | ||
39 | |||
40 | if(argc < 3) { | ||
41 | usage(); | ||
42 | } | ||
43 | |||
44 | infile = argv[1]; | ||
45 | bootfile = argv[2]; | ||
46 | outfile = argv[3]; | ||
47 | |||
48 | return mkmpioboot(infile, bootfile, outfile, origin); | ||
49 | } | ||
diff --git a/rbutil/mkmpioboot/mkmpioboot.c b/rbutil/mkmpioboot/mkmpioboot.c new file mode 100644 index 0000000000..6d52e53f09 --- /dev/null +++ b/rbutil/mkmpioboot/mkmpioboot.c | |||
@@ -0,0 +1,188 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 by Marcin Bukat | ||
11 | * | ||
12 | * code taken mostly from mkboot.c | ||
13 | * Copyright (C) 2005 by Linus Nielsen Feltzing | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * as published by the Free Software Foundation; either version 2 | ||
18 | * of the License, or (at your option) any later version. | ||
19 | * | ||
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
21 | * KIND, either express or implied. | ||
22 | * | ||
23 | ****************************************************************************/ | ||
24 | #include <stdio.h> | ||
25 | #include <stdlib.h> | ||
26 | #include <string.h> | ||
27 | #include "mkmpioboot.h" | ||
28 | |||
29 | #define OF_FIRMWARE_LEN 0x100000 /* size of HD200_UPG.SYS file */ | ||
30 | #define MPIO_STRING_OFFSET 0xfffe0 | ||
31 | |||
32 | /* We support only 1.30.05 version of OF for now */ | ||
33 | static char *mpio_string = "HD200 HDD Audio Ver113005"; | ||
34 | |||
35 | /* MPIO HD200 firmware is plain binary image | ||
36 | * 4 bytes of initial SP (loaded on reset) | ||
37 | * 4 bytes of initial PC (loaded on reset) | ||
38 | * binary image with entry point 0x00000008 | ||
39 | * | ||
40 | * We put our bootloader code at 0x000e0000 | ||
41 | * and patch reset vector to jump directly | ||
42 | * into our code on reset | ||
43 | */ | ||
44 | |||
45 | static unsigned char image[OF_FIRMWARE_LEN]; | ||
46 | |||
47 | static unsigned int get_uint32be(unsigned char* p) | ||
48 | { | ||
49 | return ((p[0] << 24) | (p[1] << 16) | (p[2]<<8) | p[3]); | ||
50 | } | ||
51 | |||
52 | static long checksum(unsigned char* buf, unsigned long length) | ||
53 | { | ||
54 | unsigned long chksum = 69; /* MPIO HD200 model number */ | ||
55 | unsigned long i; | ||
56 | |||
57 | if(buf == NULL) | ||
58 | return -1; | ||
59 | |||
60 | for (i = 0; i < length; i++) | ||
61 | { | ||
62 | chksum += *buf++; | ||
63 | } | ||
64 | |||
65 | return chksum; | ||
66 | } | ||
67 | |||
68 | int mkmpioboot(const char* infile, const char* bootfile, const char* outfile, int origin) | ||
69 | { | ||
70 | FILE *f; | ||
71 | int i; | ||
72 | int len; | ||
73 | unsigned long file_checksum; | ||
74 | unsigned char header_checksum[4]; | ||
75 | |||
76 | memset(image, 0xff, sizeof(image)); | ||
77 | |||
78 | /* First, read the mpio original firmware into the image */ | ||
79 | f = fopen(infile, "rb"); | ||
80 | if(!f) { | ||
81 | perror(infile); | ||
82 | return -1; | ||
83 | } | ||
84 | |||
85 | i = fread(image, 1, OF_FIRMWARE_LEN, f); | ||
86 | if(i < OF_FIRMWARE_LEN) { | ||
87 | perror(infile); | ||
88 | fclose(f); | ||
89 | return -2; | ||
90 | } | ||
91 | |||
92 | fclose(f); | ||
93 | |||
94 | /* Now check if we have OF file loaded based on presence | ||
95 | * of the version string in firmware | ||
96 | */ | ||
97 | |||
98 | if (strcmp((char*)(image + MPIO_STRING_OFFSET),mpio_string) != 0) | ||
99 | { | ||
100 | perror("Loaded firmware file does not look like MPIO OF file!"); | ||
101 | return -3; | ||
102 | } | ||
103 | |||
104 | /* Now, read the boot loader into the image */ | ||
105 | f = fopen(bootfile, "rb"); | ||
106 | if(!f) { | ||
107 | perror(bootfile); | ||
108 | fclose(f); | ||
109 | return -4; | ||
110 | } | ||
111 | |||
112 | /* get bootloader size | ||
113 | * excluding header | ||
114 | */ | ||
115 | fseek(f, 0, SEEK_END); | ||
116 | len = ftell(f) - 8; | ||
117 | |||
118 | /* Now check if the place we want to put | ||
119 | * our bootloader is free | ||
120 | */ | ||
121 | for(i=0;i<len;i++) | ||
122 | { | ||
123 | if (image[origin+i] != 0) | ||
124 | { | ||
125 | perror("Place for bootloader in OF file not empty"); | ||
126 | return -5; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | fseek(f, 0, SEEK_SET); | ||
131 | |||
132 | /* get bootloader checksum from the header*/ | ||
133 | fread(header_checksum,1,4,f); | ||
134 | |||
135 | /* omit header */ | ||
136 | fseek(f, 8, SEEK_SET); | ||
137 | |||
138 | i = fread(image + origin, 1, len, f); | ||
139 | if(i < len) { | ||
140 | perror(bootfile); | ||
141 | fclose(f); | ||
142 | return -6; | ||
143 | } | ||
144 | |||
145 | fclose(f); | ||
146 | |||
147 | /* calculate checksum and compare with data | ||
148 | * from header | ||
149 | */ | ||
150 | file_checksum = checksum(image + origin, len); | ||
151 | |||
152 | if ( file_checksum != get_uint32be(header_checksum) ) | ||
153 | { | ||
154 | printf("Bootloader checksum error\n"); | ||
155 | return -7; | ||
156 | } | ||
157 | |||
158 | f = fopen(outfile, "wb"); | ||
159 | if(!f) { | ||
160 | perror(outfile); | ||
161 | return -8; | ||
162 | } | ||
163 | |||
164 | /* Patch the stack pointer address */ | ||
165 | image[0] = image[origin + 0]; | ||
166 | image[1] = image[origin + 1]; | ||
167 | image[2] = image[origin + 2]; | ||
168 | image[3] = image[origin + 3]; | ||
169 | |||
170 | /* Patch the reset vector to start the boot loader */ | ||
171 | image[4] = image[origin + 4]; | ||
172 | image[5] = image[origin + 5]; | ||
173 | image[6] = image[origin + 6]; | ||
174 | image[7] = image[origin + 7]; | ||
175 | |||
176 | i = fwrite(image, 1, OF_FIRMWARE_LEN, f); | ||
177 | if(i < OF_FIRMWARE_LEN) { | ||
178 | perror(outfile); | ||
179 | fclose(f); | ||
180 | return -9; | ||
181 | } | ||
182 | |||
183 | printf("Wrote 0x%x bytes in %s\n", OF_FIRMWARE_LEN, outfile); | ||
184 | |||
185 | fclose(f); | ||
186 | |||
187 | return 0; | ||
188 | } | ||
diff --git a/rbutil/mkmpioboot/mkmpioboot.h b/rbutil/mkmpioboot/mkmpioboot.h new file mode 100644 index 0000000000..794f9df765 --- /dev/null +++ b/rbutil/mkmpioboot/mkmpioboot.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 by Marcin Bukat | ||
11 | * code based mainly on mkboot.h | ||
12 | * Copyright (C) 2008 by Dominik Riebeling | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
20 | * KIND, either express or implied. | ||
21 | * | ||
22 | ****************************************************************************/ | ||
23 | |||
24 | #ifndef MKMPIOBOOT_H | ||
25 | #define MKMPIOBOOT_H | ||
26 | |||
27 | #ifdef __cplusplus | ||
28 | extern "C" { | ||
29 | #endif | ||
30 | |||
31 | int mkmpioboot(const char* infile, const char* bootfile, const char* outfile, int origin); | ||
32 | |||
33 | #ifdef __cplusplus | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||