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) || defined(SANSA_FUZEV2)
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) || defined(SANSA_FUZEV2)
221 ldr r1, [r0, #0x20] /* read pin C3 */
223 cmp r1, #0 /* C3 = #0 means button pressed */
225 /* the logic is reversed on the fuzev2 */
229 #endif /* SANSA_FUZEV2 */
231 #elif defined(SANSA_CLIPPLUS)
234 ldr r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
237 ldr r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
239 orr r2, r2, r1 @ c3 || A1
241 cmp r2, #0 @ test input from pins
242 bne boot_of @ branch directly to OF if either pin high
245 @ check USB connection
249 str r1, [r0] @ fclk = 24MHz
253 /* enable i2c audio master clock */
255 /* pclk = fclk = 24MHz */
260 /* disable i2c interrupts */
262 str r1, [r0, #I2C_IMR]
263 /* setup prescaler */
264 mov r1, #I2C_PRESCALER_LOW
265 str r1, [r0, #I2C_CPSR0]
266 mov r1, #I2C_PRESCALER_HIGH
267 str r1, [r0, #I2C_CPSR1]
268 /* setup i2c slave address */
269 mov r1, #(AS3514_I2C_ADDR << 1)
270 str r1, [r0, #I2C_SLAD0]
272 str r2, [r0, #I2C_CNTRL]
274 /* wait for not busy */
276 ldr r1, [r0, #I2C_SR]
280 /* wait a bit (~100ms) else detection fails */
285 /* start read of irq_enrd0 */
286 mov r1, #AS3514_IRQ_ENRD0
287 str r1, [r0, #I2C_SADDR]
288 orr r2, r2, #(1 << 1)
289 str r2, [r0, #I2C_CNTRL]
291 str r1, [r0, #I2C_DACNT]
293 /* wait for transfer to finish */
295 ldr r1, [r0, #I2C_DACNT]
299 /* load result and test USB_STATUS bit */
300 ldr r1, [r0, #I2C_DATA]
305 #elif defined(SANSA_C200V2)
306 /* check for RIGHT on C6, should changed to LEFT as soon as it
307 * known in which pin that is in order for consistency */
310 str r1, [r0, #0x400] /* set pin to output */
312 ldr r1, [r0, #256] /* 1<<(6+2) */
313 cmp r1, #0 /* C6 low means button pressed */
315 #elif defined(SANSA_M200V4)
316 .set row, (1<<5) /* enable output on A5 */
317 .set col, (1<<0) /* read keyscan column A0 */
322 str r1, [r0, #(4*row)]
324 ldr r2, [r0, #(4*col)]
326 /* check value read (1 means button pressed) */
330 #error No target-specific key check defined!
334 /* The dualboot button was not held, so we boot rockbox */
335 ldr r0, ucl_rb_end /* Address of compressed image */
336 ldr r1, ucl_rb_size /* Compressed size */
340 ldr r0, ucl_of_end /* Address of compressed image */
341 ldr r1, ucl_of_size /* Compressed size */
346 /* r0 = source_end for UCL image to copy */
347 /* r1 = size of UCL image to copy */
350 add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
351 /* function, plus one (for thumb mode */
353 sub r4, r3, r1 /* r4 := destination_start - 1 */
358 cmp r3, r4 /* Stop when we reached dest_start-1 */
361 /* Call the ucl decompress function, which will branch to 0x0 */
363 add r0, r3, #1 /* r0 := Start of compressed image */
364 /* r1 already contains compressed size */
365 mov r2, #0 /* r2 := Destination for unpacking */
366 bx r5 /* Branch to uclunpack, switching to thumb */
368 /* never reached : uclunpack will branch to the reset vector (0x0) */