diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2010-04-26 21:40:16 +0000 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2010-04-26 21:40:16 +0000 |
commit | 28d54c6016459ffe93c0be2efea7de27c38d783c (patch) | |
tree | 9a7a71481f0a82599616a3e9f4e5bdad9fee8d6c /firmware/target | |
parent | b09d3aec392538ca0934644ff6357c41aaa4c323 (diff) | |
download | rockbox-28d54c6016459ffe93c0be2efea7de27c38d783c.tar.gz rockbox-28d54c6016459ffe93c0be2efea7de27c38d783c.zip |
Add MPIO HD200 port - new files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25725 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target')
22 files changed, 2566 insertions, 0 deletions
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 | } | ||