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_PERI, 0xC80F0014
30 .set I2C_BASE, 0xC8070000
40 .set AS3514_I2C_ADDR, 0x46
41 .set AS3514_IRQ_ENRD0, 0x25
44 .set I2C_PRESCALER, ((PCLK + I2C_CLK -1) / I2C_CLK)
45 .set I2C_PRESCALER_LOW, (I2C_PRESCALER & 0xff)
46 .set I2C_PRESCALER_HIGH, (I2C_PRESCALER >> 8)
47 #if I2C_PRESCALER_HIGH > 3
48 #error i2c prescaler too big!
53 ldr pc, =start /* reset vector */
54 /* next vectors are unused, halt cpu */
64 /* These values are filled in by mkamsboot - don't move them from offset 0x20 */
66 uclunpack_end: .word 0 /* End of the ucl_unpack function */
67 uclunpack_size: .word 0 /* Size in bytes of the ucl_unpack function */
69 ucl_of_end: .word 0 /* End of the ucl-compressed OF image */
70 ucl_of_size: .word 0 /* Size in bytes of the compressed OF image */
72 ucl_rb_end: .word 0 /* End of the ucl-compressed RB image */
73 ucl_rb_size: .word 0 /* Size in bytes of the compressed RB image */
75 ucl_dest: .word 0 /* End of our destination buffer (end of memory) */
78 /* First copy the UCL unpack function to the end of RAM */
79 ldr r0, uclunpack_end /* Source */
80 ldr r1, uclunpack_size /* Source length */
81 sub r2, r0, r1 /* Source start - 1*/
83 ldr r3, ucl_dest /* Destination end */
91 /* store the new destination buffer */
94 /* enable gpio clock */
101 /* TODO : M200V4 ? */
102 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2)
104 #elif defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_FUZEV2)
108 #ifdef USB_PIN /* TODO : remove this check when we'll have an USB driver */
112 ldr r1, [r0, #(4*(1<<USB_PIN))]
116 #if defined(SANSA_C200V2)
117 /* Instead of checking the GPIO, check the audio master IRQ_ENRD0
118 * USB_STATUS bit on C200V2 */
122 /* enable i2c audio master clock */
124 /* make sure 24MHz clk_main is selected */
129 /* disable i2c interrupts */
131 str r1, [r0, #I2C_IMR]
132 /* setup prescaler */
133 mov r1, #I2C_PRESCALER_LOW
134 str r1, [r0, #I2C_CPSR0]
135 mov r1, #I2C_PRESCALER_HIGH
136 str r1, [r0, #I2C_CPSR1]
137 /* setup i2c slave address */
138 mov r1, #(AS3514_I2C_ADDR << 1)
139 str r1, [r0, #I2C_SLAD0]
141 str r2, [r0, #I2C_CNTRL]
143 /* wait for not busy */
145 ldr r1, [r0, #I2C_SR]
149 /* start read of irq_enrd0 */
150 mov r1, #AS3514_IRQ_ENRD0
151 str r1, [r0, #I2C_SADDR]
152 orr r2, r2, #(1 << 1)
153 str r2, [r0, #I2C_CNTRL]
155 str r1, [r0, #I2C_DACNT]
157 /* wait for transfer to finish */
159 ldr r1, [r0, #I2C_DACNT]
163 /* load result and test USB_STATUS bit */
164 ldr r1, [r0, #I2C_DATA]
169 /* Here are model specific tests, for dual boot without a computer */
170 /* All models use left button */
171 /* /!\ Right button for c200v2 (left button is unkwown) */
174 .set row, (1<<5) /* enable output on C5 */
175 .set col, (1<<0) /* read keyscan column B0 */
180 str r1, [r0, #(4*row)]
185 ldr r1, [r0, #(4*col)]
189 #elif defined(SANSA_CLIPV2)
190 .set row, (1<<4) /* enable output on D4 */
191 .set col, (1<<0) /* read keyscan column D0 */
194 mov r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */
199 str r1, [r0, #(4*(1<<3))]
201 str r1, [r0, #(4*(1<<4))]
203 str r1, [r0, #(4*(1<<5))]
205 mov r1, #0 /* button row low */
206 str r1, [r0, #(4*row)]
208 mov r1, #5 /* small delay */
212 ldr r1, [r0, #(4*col)]
216 #elif defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_FUZEV2)
220 ldr r1, [r0, #0x20] /* read pin C3 */
222 cmp r1, #0 /* C3 = #0 means button pressed */
224 /* the logic is reversed on the fuzev2 */
228 #endif /* SANSA_FUZEV2 */
230 #elif defined(SANSA_CLIPPLUS)
233 ldr r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
236 ldr r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
238 orr r2, r2, r1 @ c3 || A1
240 cmp r2, #0 @ test input from pins
241 bne boot_of @ branch directly to OF if either pin high
242 #elif defined(SANSA_C200V2)
243 /* check for RIGHT on C6, should changed to LEFT as soon as it
244 * known in which pin that is in order for consistency */
247 str r1, [r0, #0x400] /* set pin to output */
249 ldr r1, [r0, #256] /* 1<<(6+2) */
250 cmp r1, #0 /* C6 low means button pressed */
252 #elif defined(SANSA_M200V4)
253 .set row, (1<<5) /* enable output on A5 */
254 .set col, (1<<0) /* read keyscan column A0 */
259 str r1, [r0, #(4*row)]
261 ldr r2, [r0, #(4*col)]
263 /* check value read (1 means button pressed) */
267 #error No target-specific key check defined!
271 /* The dualboot button was not held, so we boot rockbox */
272 ldr r0, ucl_rb_end /* Address of compressed image */
273 ldr r1, ucl_rb_size /* Compressed size */
277 ldr r0, ucl_of_end /* Address of compressed image */
278 ldr r1, ucl_of_size /* Compressed size */
283 /* r0 = source_end for UCL image to copy */
284 /* r1 = size of UCL image to copy */
287 add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
288 /* function, plus one (for thumb mode */
290 sub r4, r3, r1 /* r4 := destination_start - 1 */
295 cmp r3, r4 /* Stop when we reached dest_start-1 */
298 /* Call the ucl decompress function, which will branch to 0x0 */
300 add r0, r3, #1 /* r0 := Start of compressed image */
301 /* r1 already contains compressed size */
302 mov r2, #0 /* r2 := Destination for unpacking */
303 bx r5 /* Branch to uclunpack, switching to thumb */
305 /* never reached : uclunpack will branch to the reset vector (0x0) */