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
41 #elif defined(MROBE_500)
43 .equ .ata_port, 0x50400000
45 /* This isn't vaild, but it does it's job, not sure what this should be */
46 #error ata_port undefined!
50 .global copy_read_sectors
51 .type copy_read_sectors,%function
53 /* Read a number of words from the ATA data port
55 * Optimised for speed; assumes wordcount >= 10
62 * r0 - current address
65 * r3..r5, r12, lr - read buffers
69 stmfd sp!, {r4, r5, lr}
71 tst r0, #1 /* 16 bit aligned? */
74 /* not 16-bit aligned */
75 sub r1, r1, #1 /* one halfword is handled unconditionally */
76 ldrh r3, [r2] /* read first halfword */
77 strb r3, [r0], #1 /* store low byte */
80 tst r0, #2 /* 32 bit aligned? */
82 ldrh r4, [r2] /* read second halfword */
83 orr r3, r3, r4, lsl #8 /* combine with old byte */
84 strh r3, [r0], #2 /* store */
86 sub r1, r1, #1 /* another halfword taken */
89 sub r1, r1, #8 /* adjust for zero-check and doing 8 halfwords/loop */
91 ldrh r4, [r2] /* Read 8 halfwords and combine them into */
92 orr r3, r3, r4, lsl #8 /* 4 words so that they're properly aligned */
93 ldrh r4, [r2] /* in memory. Bottom byte of first word is */
94 orr r3, r3, r4, lsl #24 /* the top byte from the last round. Write */
95 mov r4, r4, lsr #8 /* all 4 words at once. */
97 orr r4, r4, r5, lsl #8
99 orr r4, r4, r5, lsl #24
102 orr r5, r5, r12, lsl #8
104 orr r5, r5, r12, lsl #24
107 orr r12, r12, lr, lsl #8
109 orr r12, r12, lr, lsl #24
110 stmia r0!, {r3, r4, r5, r12}
112 subs r1, r1, #8 /* 8 or more halfwords left? */
115 /* No need to adjust the count, only checking bits from now on. */
116 tst r1, #4 /* 4 or more halfwords left? */
119 orr r3, r3, r4, lsl #8
121 orr r3, r3, r4, lsl #24
124 orr r4, r4, r5, lsl #8
126 orr r4, r4, r5, lsl #24
131 tst r1, #2 /* 2 or more halfwords left? */
134 orr r3, r3, r4, lsl #8
136 orr r3, r3, r4, lsl #24
141 tst r1, #1 /* one halfword left? */
143 orrne r3, r3, r4, lsl #8
147 strb r3, [r0], #1 /* store final byte */
149 ldmfd sp!, {r4, r5, pc}
153 tst r0, #2 /* 32 bit aligned? */
154 ldrneh r3, [r2] /* no: read first halfword */
155 strneh r3, [r0], #2 /* store */
156 subne r1, r1, #1 /* one halfword taken */
158 sub r1, r1, #8 /* adjust for zero-check and doing 8 halfwords/loop */
160 ldrh r3, [r2] /* Read 8 halfwords and combine each pair */
161 ldrh r4, [r2] /* into a word, then store all at once. */
162 orr r3, r3, r4, lsl #16
165 orr r4, r4, r5, lsl #16
168 orr r5, r5, r12, lsl #16
171 orr r12, r12, lr, lsl #16
172 stmia r0!, {r3, r4, r5, r12}
173 subs r1, r1, #8 /* 8 or more halfwords left? */
176 /* No need to adjust the count, only checking bits from now on. */
177 tst r1, #4 /* 4 or more halfwords left? */
181 orr r3, r3, r4, lsl #16
184 orr r4, r4, r5, lsl #16
188 tst r1, #2 /* 2 or more halfwords left? */
191 orrne r3, r3, r4, lsl #16
194 tst r1, #1 /* one halfword left? */
198 ldmfd sp!, {r4, r5, pc}
201 .size copy_read_sectors,.r_end-copy_read_sectors
204 .global copy_write_sectors
205 .type copy_write_sectors,%function
207 /* Write a number of words to the ATA data port
209 * Optimised for speed; assumes wordcount >= 10
212 * r0 - buffer address
216 * r0 - current address
219 * r3..r5, r12, lr - read buffers
223 stmfd sp!, {r4, r5, lr}
225 tst r0, #1 /* 16 bit aligned? */
228 /* not 16-bit aligned */
229 sub r1, r1, #1 /* one halfword is done unconditionally */
230 ldrb r3, [r0], #1 /* load 1st byte, now halfword aligned. */
232 tst r0, #2 /* 32 bit aligned? */
234 ldrh r4, [r0], #2 /* load a halfword */
235 orr r3, r3, r4, lsl #8 /* combine with old byte */
236 strh r3, [r2] /* write halfword */
238 sub r1, r1, #1 /* another halfword taken */
241 sub r1, r1, #8 /* adjust for zero-check and doing 8 halfwords/loop */
243 ldmia r0!, {r4, r5, r12, lr}
244 orr r3, r3, r4, lsl #8 /* Load 4 words at once and decompose them */
245 strh r3, [r2] /* into 8 halfwords in a way that the words */
246 mov r3, r3, lsr #16 /* are shifted by 8 bits, putting the high */
247 strh r3, [r2] /* byte of one word into the low byte of */
248 mov r4, r4, lsr #24 /* the next. High byte of last word becomes */
249 orr r4, r4, r5, lsl #8 /* low byte of next round. */
254 orr r5, r5, r12, lsl #8
258 mov r12, r12, lsr #24
259 orr r12, r12, lr, lsl #8
261 mov r12, r12, lsr #16
264 subs r1, r1, #8 /* 8 or more halfwords left? */
267 /* No need to adjust the count, only checking bits from now on. */
268 tst r1, #4 /* 4 or more halfwords left? */
271 orr r3, r3, r4, lsl #8
276 orr r4, r4, r5, lsl #8
283 tst r1, #2 /* 2 or more halfwords left? */
286 orr r3, r3, r4, lsl #8
293 tst r1, #1 /* one halfword left? */
295 orrne r3, r3, r4, lsl #8
297 movne r3, r3, lsr #16
299 ldrb r4, [r0], #1 /* load final byte */
300 orr r3, r3, r4, lsl #8
301 strh r3, [r2] /* write final halfword */
303 ldmfd sp!, {r4, r5, pc}
307 tst r0, #2 /* 32 bit aligned? */
308 ldrneh r3, [r0], #2 /* no: load first halfword */
309 strneh r3, [r2] /* write */
310 subne r1, r1, #1 /* one halfword taken */
312 sub r1, r1, #8 /* adjust for zero-check and doing 8 halfwords/loop */
314 ldmia r0!, {r3, r4, r5, r12}
315 strh r3, [r2] /* Load 4 words and decompose them into */
316 mov r3, r3, lsr #16 /* 2 halfwords each, and write those. */
325 mov r12, r12, lsr #16
327 subs r1, r1, #8 /* 8 or more halfwords left? */
330 /* No need to adjust the count, only checking bits from now on. */
331 tst r1, #4 /* 4 or more halfwords left? */
342 tst r1, #2 /* 2 or more halfwords left? */
345 movne r3, r3, lsr #16
348 tst r1, #1 /* one halfword left? */
352 ldmfd sp!, {r4, r5, pc}
355 .size copy_write_sectors,.w_end-copy_write_sectors