1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Jens Arnold
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #if CONFIG_CPU == PP5002
26 /* Causes ATA retries on iPod G3 probably related to improper controller
27 * setup. Needs investigation. */
28 .section .icode,"ax",%progbits
29 .equ .ata_port, 0xc00031e0
30 #elif defined CPU_PP502x
31 /* Verified working on (PP5020, PP5022) targets */
32 .section .icode,"ax",%progbits
33 .equ .ata_port, 0xc30001e0
34 #elif CONFIG_CPU == S3C2440
37 .equ .ata_port, 0x18000000
38 #elif defined(CREATIVE_ZVx) /* Zen Vision could have an other address */
40 .equ .ata_port, 0x50FEE000
44 .global copy_read_sectors
45 .type copy_read_sectors,%function
47 /* Read a number of words from the ATA data port
49 * Optimised for speed; assumes wordcount >= 10
56 * r0 - current address
59 * r3..r6, lr - read buffers
63 stmfd sp!, {r4, r5, r6, lr}
65 tst r0, #1 /* 16 bit aligned? */
68 /* not 16-bit aligned */
69 sub r1, r1, #1 /* one halfword is handled unconditionally */
70 ldrh r3, [r2] /* read first halfword */
71 strb r3, [r0], #1 /* store low byte */
74 tst r0, #2 /* 32 bit aligned? */
76 ldrh r4, [r2] /* read second halfword */
77 orr r3, r3, r4, lsl #8 /* combine with old byte */
78 strh r3, [r0], #2 /* store */
80 sub r1, r1, #1 /* another halfword taken */
83 sub r1, r1, #8 /* adjust for zero-check and doing 8 halfwords/loop */
85 ldrh r4, [r2] /* Read 8 halfwords and combine them into */
86 orr r3, r3, r4, lsl #8 /* 4 words so that they're properly aligned */
87 ldrh r4, [r2] /* in memory. Bottom byte of first word is */
88 orr r3, r3, r4, lsl #24 /* the top byte from the last round. Write */
89 mov r4, r4, lsr #8 /* all 4 words at once. */
91 orr r4, r4, r5, lsl #8
93 orr r4, r4, r5, lsl #24
96 orr r5, r5, r6, lsl #8
98 orr r5, r5, r6, lsl #24
101 orr r6, r6, lr, lsl #8
103 orr r6, r6, lr, lsl #24
104 stmia r0!, {r3, r4, r5, r6}
106 subs r1, r1, #8 /* 8 or more halfwords left? */
109 /* No need to adjust the count, only checking bits from now on. */
110 tst r1, #4 /* 4 or more halfwords left? */
113 orr r3, r3, r4, lsl #8
115 orr r3, r3, r4, lsl #24
118 orr r4, r4, r5, lsl #8
120 orr r4, r4, r5, lsl #24
125 tst r1, #2 /* 2 or more halfwords left? */
128 orr r3, r3, r4, lsl #8
130 orr r3, r3, r4, lsl #24
135 tst r1, #1 /* one halfword left? */
137 orrne r3, r3, r4, lsl #8
141 strb r3, [r0], #1 /* store final byte */
143 ldmfd sp!, {r4, r5, r6, pc}
147 tst r0, #2 /* 32 bit aligned? */
148 ldrneh r3, [r2] /* no: read first halfword */
149 strneh r3, [r0], #2 /* store */
150 subne r1, r1, #1 /* one halfword taken */
152 sub r1, r1, #8 /* adjust for zero-check and doing 8 halfwords/loop */
154 ldrh r3, [r2] /* Read 8 halfwords and combine each pair */
155 ldrh r4, [r2] /* into a word, then store all at once. */
156 orr r3, r3, r4, lsl #16
159 orr r4, r4, r5, lsl #16
162 orr r5, r5, r6, lsl #16
165 orr r6, r6, lr, lsl #16
166 stmia r0!, {r3, r4, r5, r6}
167 subs r1, r1, #8 /* 8 or more halfwords left? */
170 /* No need to adjust the count, only checking bits from now on. */
171 tst r1, #4 /* 4 or more halfwords left? */
175 orr r3, r3, r4, lsl #16
178 orr r4, r4, r5, lsl #16
182 tst r1, #2 /* 2 or more halfwords left? */
185 orrne r3, r3, r4, lsl #16
188 tst r1, #1 /* one halfword left? */
192 ldmfd sp!, {r4, r5, r6, pc}
195 .size copy_read_sectors,.r_end-copy_read_sectors
198 .global copy_write_sectors
199 .type copy_write_sectors,%function
201 /* Write a number of words to the ATA data port
203 * Optimised for speed; assumes wordcount >= 10
206 * r0 - buffer address
210 * r0 - current address
213 * r3..r6, lr - read buffers
217 stmfd sp!, {r4, r5, r6, lr}
219 tst r0, #1 /* 16 bit aligned? */
222 /* not 16-bit aligned */
223 sub r1, r1, #1 /* one halfword is done unconditionally */
224 ldrb r3, [r0], #1 /* load 1st byte, now halfword aligned. */
226 tst r0, #2 /* 32 bit aligned? */
228 ldrh r4, [r0], #2 /* load a halfword */
229 orr r3, r3, r4, lsl #8 /* combine with old byte */
230 strh r3, [r2] /* write halfword */
232 sub r1, r1, #1 /* another halfword taken */
235 sub r1, r1, #8 /* adjust for zero-check and doing 8 halfwords/loop */
237 ldmia r0!, {r4, r5, r6, lr}
238 orr r3, r3, r4, lsl #8 /* Load 4 words at once and decompose them */
239 strh r3, [r2] /* into 8 halfwords in a way that the words */
240 mov r3, r3, lsr #16 /* are shifted by 8 bits, putting the high */
241 strh r3, [r2] /* byte of one word into the low byte of */
242 mov r4, r4, lsr #24 /* the next. High byte of last word becomes */
243 orr r4, r4, r5, lsl #8 /* low byte of next round. */
248 orr r5, r5, r6, lsl #8
253 orr r6, r6, lr, lsl #8
258 subs r1, r1, #8 /* 8 or more halfwords left? */
261 /* No need to adjust the count, only checking bits from now on. */
262 tst r1, #4 /* 4 or more halfwords left? */
265 orr r3, r3, r4, lsl #8
270 orr r4, r4, r5, lsl #8
277 tst r1, #2 /* 2 or more halfwords left? */
280 orr r3, r3, r4, lsl #8
287 tst r1, #1 /* one halfword left? */
289 orrne r3, r3, r4, lsl #8
291 movne r3, r3, lsr #16
293 ldrb r4, [r0], #1 /* load final byte */
294 orr r3, r3, r4, lsl #8
295 strh r3, [r2] /* write final halfword */
297 ldmfd sp!, {r4, r5, r6, pc}
301 tst r0, #2 /* 32 bit aligned? */
302 ldrneh r3, [r0], #2 /* no: load first halfword */
303 strneh r3, [r2] /* write */
304 subne r1, r1, #1 /* one halfword taken */
306 sub r1, r1, #8 /* adjust for zero-check and doing 8 halfwords/loop */
308 ldmia r0!, {r3, r4, r5, r6}
309 strh r3, [r2] /* Load 4 words and decompose them into */
310 mov r3, r3, lsr #16 /* 2 halfwords each, and write those. */
321 subs r1, r1, #8 /* 8 or more halfwords left? */
324 /* No need to adjust the count, only checking bits from now on. */
325 tst r1, #4 /* 4 or more halfwords left? */
336 tst r1, #2 /* 2 or more halfwords left? */
339 movne r3, r3, lsr #16
342 tst r1, #1 /* one halfword left? */
346 ldmfd sp!, {r4, r5, r6, pc}
349 .size copy_write_sectors,.w_end-copy_write_sectors