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 I2C_BASE, 0xC8070000
41 .set AS3514_I2C_ADDR, 0x46
42 .set AS3514_IRQ_ENRD0, 0x25
45 .set I2C_PRESCALER, ((PCLK + I2C_CLK -1) / I2C_CLK)
46 .set I2C_PRESCALER_LOW, (I2C_PRESCALER & 0xff)
47 .set I2C_PRESCALER_HIGH, (I2C_PRESCALER >> 8)
48 #if I2C_PRESCALER_HIGH > 3
49 #error i2c prescaler too big!
54 ldr pc, =start /* reset vector */
55 /* next vectors are unused, halt cpu */
65 /* These values are filled in by mkamsboot - don't move them from offset 0x20 */
67 uclunpack_end: .word 0 /* End of the ucl_unpack function */
68 uclunpack_size: .word 0 /* Size in bytes of the ucl_unpack function */
70 ucl_of_end: .word 0 /* End of the ucl-compressed OF image */
71 ucl_of_size: .word 0 /* Size in bytes of the compressed OF image */
73 ucl_rb_end: .word 0 /* End of the ucl-compressed RB image */
74 ucl_rb_size: .word 0 /* Size in bytes of the compressed RB image */
76 ucl_dest: .word 0 /* End of our destination buffer (end of memory) */
79 /* First copy the UCL unpack function to the end of RAM */
80 ldr r0, uclunpack_end /* Source */
81 ldr r1, uclunpack_size /* Source length */
82 sub r2, r0, r1 /* Source start - 1*/
84 ldr r3, ucl_dest /* Destination end */
92 /* store the new destination buffer */
95 /* enable gpio clock */
102 /* TODO : M200V4 ? */
103 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2)
105 #elif defined(SANSA_FUZE) || defined(SANSA_E200V2)
109 #ifdef USB_PIN /* TODO : remove this check when we'll have an USB driver */
113 ldr r1, [r0, #(4*(1<<USB_PIN))]
117 #if defined(SANSA_C200V2)
118 /* Instead of checking the GPIO, check the audio master IRQ_ENRD0
119 * USB_STATUS bit on C200V2 */
123 /* enable i2c audio master clock */
125 /* make sure 24MHz clk_main is selected */
130 /* disable i2c interrupts */
132 str r1, [r0, #I2C_IMR]
133 /* setup prescaler */
134 mov r1, #I2C_PRESCALER_LOW
135 str r1, [r0, #I2C_CPSR0]
136 mov r1, #I2C_PRESCALER_HIGH
137 str r1, [r0, #I2C_CPSR1]
138 /* setup i2c slave address */
139 mov r1, #(AS3514_I2C_ADDR << 1)
140 str r1, [r0, #I2C_SLAD0]
142 str r2, [r0, #I2C_CNTRL]
144 /* wait for not busy */
146 ldr r1, [r0, #I2C_SR]
150 /* start read of irq_enrd0 */
151 mov r1, #AS3514_IRQ_ENRD0
152 str r1, [r0, #I2C_SADDR]
153 orr r2, r2, #(1 << 1)
154 str r2, [r0, #I2C_CNTRL]
156 str r1, [r0, #I2C_DACNT]
158 /* wait for transfer to finish */
160 ldr r1, [r0, #I2C_DACNT]
164 /* load result and test USB_STATUS bit */
165 ldr r1, [r0, #I2C_DATA]
170 /* Here are model specific tests, for dual boot without a computer */
171 /* All models use left button */
172 /* /!\ Right button for c200v2 (left button is unkwown) */
175 .set row, (1<<5) /* enable output on C5 */
176 .set col, (1<<0) /* read keyscan column B0 */
181 str r1, [r0, #(4*row)]
186 ldr r1, [r0, #(4*col)]
190 #elif defined(SANSA_CLIPV2)
191 .set row, (1<<4) /* enable output on D4 */
192 .set col, (1<<0) /* read keyscan column D0 */
195 mov r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */
200 str r1, [r0, #(4*(1<<3))]
202 str r1, [r0, #(4*(1<<4))]
204 str r1, [r0, #(4*(1<<5))]
206 mov r1, #0 /* button row low */
207 str r1, [r0, #(4*row)]
209 mov r1, #5 /* small delay */
213 ldr r1, [r0, #(4*col)]
217 #elif defined(SANSA_E200V2) || defined(SANSA_FUZE)
221 ldr r1, [r0, #0x20] /* read pin C3 */
223 cmp r1, #0 /* C3 = #0 means button pressed */
226 #elif defined(SANSA_FUZEV2)
230 ldr r1, [r0, #0x20] /* read pin C3 */
232 cmp r1, #0 /* C3 != #0 means button pressed */
235 #elif defined(SANSA_CLIPPLUS)
238 ldr r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
241 ldr r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
243 orr r2, r2, r1 @ c3 || A1
245 cmp r2, #0 @ test input from pins
246 bne boot_of @ branch directly to OF if either pin high
249 #elif defined(SANSA_C200V2)
250 /* check for RIGHT on C6, should changed to LEFT as soon as it
251 * known in which pin that is in order for consistency */
254 str r1, [r0, #0x400] /* set pin to output */
256 ldr r1, [r0, #256] /* 1<<(6+2) */
257 cmp r1, #0 /* C6 low means button pressed */
259 #elif defined(SANSA_M200V4)
260 .set row, (1<<5) /* enable output on A5 */
261 .set col, (1<<0) /* read keyscan column A0 */
266 str r1, [r0, #(4*row)]
268 ldr r2, [r0, #(4*col)]
270 /* check value read (1 means button pressed) */
274 #error No target-specific key check defined!
277 #if defined(SANSA_CLIPPLUS) || defined(SANSA_FUZEV2)
278 /* Check for USB after buttons because I trust more the GPIO code than
280 * Also it seems we need to wait a bit before detecting USB connection
281 * on those models, but not on c200v2
287 str r1, [r0] @ fclk = 24MHz
291 /* enable i2c audio master clock */
293 /* pclk = fclk = 24MHz */
298 /* disable i2c interrupts */
300 str r1, [r0, #I2C_IMR]
301 /* setup prescaler */
302 mov r1, #I2C_PRESCALER_LOW
303 str r1, [r0, #I2C_CPSR0]
304 mov r1, #I2C_PRESCALER_HIGH
305 str r1, [r0, #I2C_CPSR1]
306 /* setup i2c slave address */
307 mov r1, #(AS3514_I2C_ADDR << 1)
308 str r1, [r0, #I2C_SLAD0]
310 str r2, [r0, #I2C_CNTRL]
312 /* wait for not busy */
314 ldr r1, [r0, #I2C_SR]
318 /* wait a bit (~100ms) else detection fails */
323 /* start read of irq_enrd0 */
324 mov r1, #AS3514_IRQ_ENRD0
325 str r1, [r0, #I2C_SADDR]
326 orr r2, r2, #(1 << 1)
327 str r2, [r0, #I2C_CNTRL]
329 str r1, [r0, #I2C_DACNT]
331 /* wait for transfer to finish */
333 ldr r1, [r0, #I2C_DACNT]
337 /* load result and test USB_STATUS bit */
338 ldr r1, [r0, #I2C_DATA]
346 /* The dualboot button was not held, so we boot rockbox */
347 ldr r0, ucl_rb_end /* Address of compressed image */
348 ldr r1, ucl_rb_size /* Compressed size */
352 ldr r0, ucl_of_end /* Address of compressed image */
353 ldr r1, ucl_of_size /* Compressed size */
358 /* r0 = source_end for UCL image to copy */
359 /* r1 = size of UCL image to copy */
362 add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
363 /* function, plus one (for thumb mode */
365 sub r4, r3, r1 /* r4 := destination_start - 1 */
370 cmp r3, r4 /* Stop when we reached dest_start-1 */
373 /* Call the ucl decompress function, which will branch to 0x0 */
375 add r0, r3, #1 /* r0 := Start of compressed image */
376 /* r1 already contains compressed size */
377 mov r2, #0 /* r2 := Destination for unpacking */
378 bx r5 /* Branch to uclunpack, switching to thumb */
380 /* never reached : uclunpack will branch to the reset vector (0x0) */