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
33 .set I2C_BASE, 0xC8070000
43 .set AS3514_I2C_ADDR, 0x46
44 .set AS3514_IRQ_ENRD0, 0x25
47 .set I2C_PRESCALER, ((PCLK + I2C_CLK -1) / I2C_CLK)
48 .set I2C_PRESCALER_LOW, (I2C_PRESCALER & 0xff)
49 .set I2C_PRESCALER_HIGH, (I2C_PRESCALER >> 8)
50 #if I2C_PRESCALER_HIGH > 3
51 #error i2c prescaler too big!
54 b start @ skip our data
56 /* These values are filled in by mkamsboot - don't move them from offset 0x4 */
58 uclunpack_end: .word 0 /* End of the ucl_unpack function */
59 uclunpack_size: .word 0 /* Size in bytes of the ucl_unpack function */
61 ucl_of_end: .word 0 /* End of the ucl-compressed OF image */
62 ucl_of_size: .word 0 /* Size in bytes of the compressed OF image */
64 ucl_rb_end: .word 0 /* End of the ucl-compressed RB image */
65 ucl_rb_size: .word 0 /* Size in bytes of the compressed RB image */
67 ucl_dest: .word 0 /* End of our destination buffer (end of memory) */
70 /* First copy the UCL unpack function to the end of RAM */
71 ldr r0, uclunpack_end /* Source */
72 ldr r1, uclunpack_size /* Source length */
73 sub r2, r0, r1 /* Source start - 1*/
75 ldr r3, ucl_dest /* Destination end */
83 /* store the new destination buffer */
86 /* enable gpio clock */
93 #ifdef SANSA_CLIPV2 /* TODO : remove this check when we'll have an USB driver */
97 ldr r1, [r0, #(4*(1<<6))]
101 /* Here are model specific tests for dual boot */
102 /* All models but c200v2 use left button */
103 /* TODO: Left button for c200v2 too (needs DBOP code) */
106 .set row, (1<<5) /* enable output on C5 */
107 .set col, (1<<0) /* read keyscan column B0 */
112 str r1, [r0, #(4*row)]
117 ldr r1, [r0, #(4*col)]
121 #elif defined(SANSA_CLIPV2)
122 .set row, (1<<4) /* enable output on D4 */
123 .set col, (1<<0) /* read keyscan column D0 */
126 mov r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */
131 str r1, [r0, #(4*(1<<3))]
133 str r1, [r0, #(4*(1<<4))]
135 str r1, [r0, #(4*(1<<5))]
137 mov r1, #0 /* button row low */
138 str r1, [r0, #(4*row)]
140 mov r1, #5 /* small delay */
144 ldr r1, [r0, #(4*col)]
148 #elif defined(SANSA_E200V2) || defined(SANSA_FUZE)
152 ldr r1, [r0, #0x20] /* read pin C3 */
154 cmp r1, #0 /* C3 = #0 means button pressed */
157 #elif defined(SANSA_FUZEV2)
161 ldr r1, [r0, #0x20] /* read pin C3 */
163 cmp r1, #0 /* C3 != #0 means button pressed */
166 #elif defined(SANSA_CLIPPLUS)
169 ldr r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
172 ldr r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
174 orr r2, r2, r1 @ c3 || A1
176 cmp r2, #0 @ test input from pins
177 bne boot_of @ branch directly to OF if either pin high
180 #elif defined(SANSA_C200V2)
181 .set BUTTON_LEFT, (1<< 2)
182 .set BUTTON_DOWN, (1<< 3)
183 .set BUTTON_SELECT, (1<< 4)
184 .set BUTTON_UP, (1<< 5)
185 .set BUTTON_RIGHT, (1<< 6)
186 .set BUTTON_HOLD, (1<<12)
189 mov r1, #(1<<3) @ DBOP freq = PCLK, clock enabled
192 @ AFSEL needs to be set for this to work
195 str r1, [r2, #0x420] @ GPIOB_AFSEL
198 str r1, [r2, #0x420] @ GPIOC_AFSEL
201 @ TIMPOL doesn't matter here since we don't need
202 @ the control signals.
208 str r1, [r0, #8] @ DBOP_CTRL
210 ldr r1, =0xf0ff @ precharge
211 str r1, [r0, #0x10] @ DBOP_DOUT
213 2: ldr r1, [r0, #0xc] @ DOBP_STAT
214 ands r1, r1, #(1<<10)
215 beq 2b @ make sure fifo is empty
222 str r1, [r0, #8] @ DBOP_CTRL
224 3: ldr r1, [r0, #0xc] @ DOBP_STAT
225 ands r1, r1, #(1<<16)
226 beq 3b @ wait for valid data
228 ldrh r1, [r0, #0x14] @ DBOP_DIN
230 tst r1, #BUTTON_LEFT @ boot of?
232 #elif defined(SANSA_M200V4)
233 .set row, (1<<5) /* enable output on A5 */
234 .set col, (1<<0) /* read keyscan column A0 */
239 str r1, [r0, #(4*row)]
241 ldr r2, [r0, #(4*col)]
243 /* check value read (1 means button pressed) */
247 #error No target-specific key check defined!
250 #if defined(SANSA_CLIPPLUS) || defined(SANSA_FUZEV2)
251 /* Check for USB after buttons because I trust more the GPIO code than
253 * Also it seems we need to wait a bit before detecting USB connection
254 * on those models, but not on c200v2
260 str r1, [r0] @ fclk = 24MHz
264 /* enable i2c audio master clock */
266 /* pclk = fclk = 24MHz */
271 /* disable i2c interrupts */
273 str r1, [r0, #I2C_IMR]
274 /* setup prescaler */
275 mov r1, #I2C_PRESCALER_LOW
276 str r1, [r0, #I2C_CPSR0]
277 mov r1, #I2C_PRESCALER_HIGH
278 str r1, [r0, #I2C_CPSR1]
279 /* setup i2c slave address */
280 mov r1, #(AS3514_I2C_ADDR << 1)
281 str r1, [r0, #I2C_SLAD0]
283 str r2, [r0, #I2C_CNTRL]
285 /* wait for not busy */
287 ldr r1, [r0, #I2C_SR]
291 /* wait a bit (~100ms) else detection fails */
296 /* start read of irq_enrd0 */
297 mov r1, #AS3514_IRQ_ENRD0
298 str r1, [r0, #I2C_SADDR]
299 orr r2, r2, #(1 << 1)
300 str r2, [r0, #I2C_CNTRL]
302 str r1, [r0, #I2C_DACNT]
304 /* wait for transfer to finish */
306 ldr r1, [r0, #I2C_DACNT]
310 /* load result and test USB_STATUS bit */
311 ldr r1, [r0, #I2C_DATA]
319 /* The dualboot button was not held, so we boot rockbox */
320 ldr r0, ucl_rb_end /* Address of compressed image */
321 ldr r1, ucl_rb_size /* Compressed size */
325 ldr r0, ucl_of_end /* Address of compressed image */
326 ldr r1, ucl_of_size /* Compressed size */
331 /* r0 = source_end for UCL image to copy */
332 /* r1 = size of UCL image to copy */
335 add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
336 /* function, plus one (for thumb mode */
338 sub r4, r3, r1 /* r4 := destination_start - 1 */
343 cmp r3, r4 /* Stop when we reached dest_start-1 */
346 /* Call the ucl decompress function, which will branch to 0x0 */
348 add r0, r3, #1 /* r0 := Start of compressed image */
349 /* r1 already contains compressed size */
350 mov r2, #0 /* r2 := Destination for unpacking */
351 bx r5 /* Branch to uclunpack, switching to thumb */
353 /* never reached : uclunpack will branch to the reset vector (0x0) */