1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 Rafaël Carré
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 ****************************************************************************/
24 /* AS3525 hardware registers */
25 .set GPIOA, 0xC80B0000
26 .set GPIOB, 0xC80C0000
27 .set GPIOC, 0xC80D0000
28 .set GPIOD, 0xC80E0000
29 .set CGU_PROC, 0xC80F0010
30 .set CGU_PERI, 0xC80F0014
31 .set CGU_DBOP, 0xC80F0038
32 .set CCU_IO, 0xC810000C
34 .set I2C_BASE, 0xC8070000
44 .set AS3514_I2C_ADDR, 0x46
45 .set AS3514_IRQ_ENRD0, 0x25
48 .set I2C_PRESCALER, ((PCLK + I2C_CLK -1) / I2C_CLK)
49 .set I2C_PRESCALER_LOW, (I2C_PRESCALER & 0xff)
50 .set I2C_PRESCALER_HIGH, (I2C_PRESCALER >> 8)
51 #if I2C_PRESCALER_HIGH > 3
52 #error i2c prescaler too big!
55 b start @ skip our data
57 /* These values are filled in by mkamsboot - don't move them from offset 0x4 */
59 uclunpack_end: .word 0 /* End of the ucl_unpack function */
60 uclunpack_size: .word 0 /* Size in bytes of the ucl_unpack function */
62 ucl_of_end: .word 0 /* End of the ucl-compressed OF image */
63 ucl_of_size: .word 0 /* Size in bytes of the compressed OF image */
65 ucl_rb_end: .word 0 /* End of the ucl-compressed RB image */
66 ucl_rb_size: .word 0 /* Size in bytes of the compressed RB image */
68 ucl_dest: .word 0 /* End of our destination buffer (end of memory) */
71 /* First copy the UCL unpack function to the end of RAM */
72 ldr r0, uclunpack_end /* Source */
73 ldr r1, uclunpack_size /* Source length */
74 sub r2, r0, r1 /* Source start - 1*/
76 ldr r3, ucl_dest /* Destination end */
84 /* store the new destination buffer */
87 /* enable gpio clock */
93 /* Here are model specific tests for dual boot (test left button) */
96 .set row, (1<<5) /* enable output on C5 */
97 .set col, (1<<0) /* read keyscan column B0 */
102 str r1, [r0, #(4*row)]
107 ldr r1, [r0, #(4*col)]
111 #elif defined(SANSA_CLIPV2)
112 .set row, (1<<4) /* enable output on D4 */
113 .set col, (1<<0) /* read keyscan column D0 */
117 bic r1, r1, #(3<<2) @ XPD works as general purpose IO
121 mov r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */
126 str r1, [r0, #(4*(1<<3))]
128 str r1, [r0, #(4*(1<<4))]
130 str r1, [r0, #(4*(1<<5))]
132 mov r1, #0 /* button row low */
133 str r1, [r0, #(4*row)]
135 mov r1, #5 /* small delay */
139 ldr r1, [r0, #(4*col)]
143 #elif defined(SANSA_E200V2) || defined(SANSA_FUZE)
147 ldr r1, [r0, #0x20] /* read pin C3 */
149 cmp r1, #0 /* C3 = #0 means button pressed */
152 #elif defined(SANSA_FUZEV2)
156 ldr r1, [r0, #0x20] /* read pin C3 */
158 cmp r1, #0 /* C3 != #0 means button pressed */
161 #elif defined(SANSA_CLIPPLUS)
164 ldr r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
167 ldr r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
169 orr r2, r2, r1 @ c3 || A1
171 cmp r2, #0 @ test input from pins
172 bne boot_of @ branch directly to OF if either pin high
174 #elif defined(SANSA_CLIPZIP)
177 ldr r1, [r0, #4*(1<<6)] @ read GPIO A6 "vol-"
179 cmp r1, #0 @ test input from pins
180 bne boot_of @ branch directly to OF if either pin high
185 orr r1, r1, #((1<<1)|(1<<2)) @ output
186 bic r1, r1, #(1<<5) @ input
190 str r1, [r0, #4*(1<<1)] @ zero C1
192 str r1, [r0, #4*(1<<2)] @ set C2
194 mov r1, #50 /* small delay */
198 ldr r1, [r0, #4*(1<<5)] @ read C5 = left
203 #elif defined(SANSA_C200V2)
204 .set BUTTON_LEFT, (1<< 2)
205 .set BUTTON_DOWN, (1<< 3)
206 .set BUTTON_SELECT, (1<< 4)
207 .set BUTTON_UP, (1<< 5)
208 .set BUTTON_RIGHT, (1<< 6)
209 .set BUTTON_HOLD, (1<<12)
212 mov r1, #(1<<3) @ DBOP freq = PCLK, clock enabled
215 @ AFSEL needs to be set for this to work
218 str r1, [r2, #0x420] @ GPIOB_AFSEL
221 str r1, [r2, #0x420] @ GPIOC_AFSEL
224 @ TIMPOL doesn't matter here since we don't need
225 @ the control signals.
231 str r1, [r0, #8] @ DBOP_CTRL
233 ldr r1, =0xf0ff @ precharge
234 str r1, [r0, #0x10] @ DBOP_DOUT
236 2: ldr r1, [r0, #0xc] @ DOBP_STAT
237 ands r1, r1, #(1<<10)
238 beq 2b @ make sure fifo is empty
245 str r1, [r0, #8] @ DBOP_CTRL
247 3: ldr r1, [r0, #0xc] @ DOBP_STAT
248 ands r1, r1, #(1<<16)
249 beq 3b @ wait for valid data
251 ldrh r1, [r0, #0x14] @ DBOP_DIN
253 tst r1, #BUTTON_LEFT @ boot of?
255 #elif defined(SANSA_M200V4)
256 .set row, (1<<5) /* enable output on A5 */
257 .set col, (1<<0) /* read keyscan column A0 */
262 str r1, [r0, #(4*row)]
264 ldr r2, [r0, #(4*col)]
266 /* check value read (1 means button pressed) */
270 #error No target-specific key check defined!
273 /* The dualboot button was not held, so we boot rockbox */
274 ldr r0, ucl_rb_end /* Address of compressed image */
275 ldr r1, ucl_rb_size /* Compressed size */
279 ldr r0, ucl_of_end /* Address of compressed image */
280 ldr r1, ucl_of_size /* Compressed size */
285 /* r0 = source_end for UCL image to copy */
286 /* r1 = size of UCL image to copy */
289 add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
290 /* function, plus one (for thumb mode */
292 sub r4, r3, r1 /* r4 := destination_start - 1 */
297 cmp r3, r4 /* Stop when we reached dest_start-1 */
300 /* Call the ucl decompress function, which will branch to 0x0 */
302 add r0, r3, #1 /* r0 := Start of compressed image */
303 /* r1 already contains compressed size */
304 mov r2, #0 /* r2 := Destination for unpacking */
305 bx r5 /* Branch to uclunpack, switching to thumb */
307 /* never reached : uclunpack will branch to the reset vector (0x0) */