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!
56 ldr pc, =start /* reset vector */
57 /* next vectors are unused, halt cpu */
67 /* These values are filled in by mkamsboot - don't move them from offset 0x20 */
69 uclunpack_end: .word 0 /* End of the ucl_unpack function */
70 uclunpack_size: .word 0 /* Size in bytes of the ucl_unpack function */
72 ucl_of_end: .word 0 /* End of the ucl-compressed OF image */
73 ucl_of_size: .word 0 /* Size in bytes of the compressed OF image */
75 ucl_rb_end: .word 0 /* End of the ucl-compressed RB image */
76 ucl_rb_size: .word 0 /* Size in bytes of the compressed RB image */
78 ucl_dest: .word 0 /* End of our destination buffer (end of memory) */
81 /* First copy the UCL unpack function to the end of RAM */
82 ldr r0, uclunpack_end /* Source */
83 ldr r1, uclunpack_size /* Source length */
84 sub r2, r0, r1 /* Source start - 1*/
86 ldr r3, ucl_dest /* Destination end */
94 /* store the new destination buffer */
97 /* enable gpio clock */
104 /* TODO : M200V4 ? */
105 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2)
107 #elif defined(SANSA_FUZE) || defined(SANSA_E200V2)
111 #ifdef USB_PIN /* TODO : remove this check when we'll have an USB driver */
115 ldr r1, [r0, #(4*(1<<USB_PIN))]
119 #if defined(SANSA_C200V2)
120 /* Instead of checking the GPIO, check the audio master IRQ_ENRD0
121 * USB_STATUS bit on C200V2 */
125 /* enable i2c audio master clock */
127 /* make sure 24MHz clk_main is selected */
132 /* disable i2c interrupts */
134 str r1, [r0, #I2C_IMR]
135 /* setup prescaler */
136 mov r1, #I2C_PRESCALER_LOW
137 str r1, [r0, #I2C_CPSR0]
138 mov r1, #I2C_PRESCALER_HIGH
139 str r1, [r0, #I2C_CPSR1]
140 /* setup i2c slave address */
141 mov r1, #(AS3514_I2C_ADDR << 1)
142 str r1, [r0, #I2C_SLAD0]
144 str r2, [r0, #I2C_CNTRL]
146 /* wait for not busy */
148 ldr r1, [r0, #I2C_SR]
152 /* start read of irq_enrd0 */
153 mov r1, #AS3514_IRQ_ENRD0
154 str r1, [r0, #I2C_SADDR]
155 orr r2, r2, #(1 << 1)
156 str r2, [r0, #I2C_CNTRL]
158 str r1, [r0, #I2C_DACNT]
160 /* wait for transfer to finish */
162 ldr r1, [r0, #I2C_DACNT]
166 /* load result and test USB_STATUS bit */
167 ldr r1, [r0, #I2C_DATA]
172 /* Here are model specific tests, for dual boot without a computer */
173 /* All models use left button */
174 /* /!\ Right button for c200v2 (left button is unkwown) */
177 .set row, (1<<5) /* enable output on C5 */
178 .set col, (1<<0) /* read keyscan column B0 */
183 str r1, [r0, #(4*row)]
188 ldr r1, [r0, #(4*col)]
192 #elif defined(SANSA_CLIPV2)
193 .set row, (1<<4) /* enable output on D4 */
194 .set col, (1<<0) /* read keyscan column D0 */
197 mov r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */
202 str r1, [r0, #(4*(1<<3))]
204 str r1, [r0, #(4*(1<<4))]
206 str r1, [r0, #(4*(1<<5))]
208 mov r1, #0 /* button row low */
209 str r1, [r0, #(4*row)]
211 mov r1, #5 /* small delay */
215 ldr r1, [r0, #(4*col)]
219 #elif defined(SANSA_E200V2) || defined(SANSA_FUZE)
223 ldr r1, [r0, #0x20] /* read pin C3 */
225 cmp r1, #0 /* C3 = #0 means button pressed */
228 #elif defined(SANSA_FUZEV2)
232 ldr r1, [r0, #0x20] /* read pin C3 */
234 cmp r1, #0 /* C3 != #0 means button pressed */
237 #elif defined(SANSA_CLIPPLUS)
240 ldr r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
243 ldr r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
245 orr r2, r2, r1 @ c3 || A1
247 cmp r2, #0 @ test input from pins
248 bne boot_of @ branch directly to OF if either pin high
251 #elif defined(SANSA_C200V2)
252 .set BUTTON_LEFT, (1<< 2)
253 .set BUTTON_DOWN, (1<< 3)
254 .set BUTTON_SELECT, (1<< 4)
255 .set BUTTON_UP, (1<< 5)
256 .set BUTTON_RIGHT, (1<< 6)
257 .set BUTTON_HOLD, (1<<12)
260 mov r1, #(1<<3) @ DBOP freq = PCLK, clock enabled
263 @ AFSEL needs to be set for this to work
266 str r1, [r2, #0x420] @ GPIOB_AFSEL
269 str r1, [r2, #0x420] @ GPIOC_AFSEL
272 @ TIMPOL doesn't matter here since we don't need
273 @ the control signals.
279 str r1, [r0, #8] @ DBOP_CTRL
281 ldr r1, =0xf0ff @ precharge
282 str r1, [r0, #0x10] @ DBOP_DOUT
284 2: ldr r1, [r0, #0xc] @ DOBP_STAT
285 ands r1, r1, #(1<<10)
286 beq 2b @ make sure fifo is empty
293 str r1, [r0, #8] @ DBOP_CTRL
295 3: ldr r1, [r0, #0xc] @ DOBP_STAT
296 ands r1, r1, #(1<<16)
297 beq 3b @ wait for valid data
299 ldrh r1, [r0, #0x14] @ DBOP_DIN
301 tst r1, #BUTTON_LEFT @ boot of?
303 #elif defined(SANSA_M200V4)
304 .set row, (1<<5) /* enable output on A5 */
305 .set col, (1<<0) /* read keyscan column A0 */
310 str r1, [r0, #(4*row)]
312 ldr r2, [r0, #(4*col)]
314 /* check value read (1 means button pressed) */
318 #error No target-specific key check defined!
321 #if defined(SANSA_CLIPPLUS) || defined(SANSA_FUZEV2)
322 /* Check for USB after buttons because I trust more the GPIO code than
324 * Also it seems we need to wait a bit before detecting USB connection
325 * on those models, but not on c200v2
331 str r1, [r0] @ fclk = 24MHz
335 /* enable i2c audio master clock */
337 /* pclk = fclk = 24MHz */
342 /* disable i2c interrupts */
344 str r1, [r0, #I2C_IMR]
345 /* setup prescaler */
346 mov r1, #I2C_PRESCALER_LOW
347 str r1, [r0, #I2C_CPSR0]
348 mov r1, #I2C_PRESCALER_HIGH
349 str r1, [r0, #I2C_CPSR1]
350 /* setup i2c slave address */
351 mov r1, #(AS3514_I2C_ADDR << 1)
352 str r1, [r0, #I2C_SLAD0]
354 str r2, [r0, #I2C_CNTRL]
356 /* wait for not busy */
358 ldr r1, [r0, #I2C_SR]
362 /* wait a bit (~100ms) else detection fails */
367 /* start read of irq_enrd0 */
368 mov r1, #AS3514_IRQ_ENRD0
369 str r1, [r0, #I2C_SADDR]
370 orr r2, r2, #(1 << 1)
371 str r2, [r0, #I2C_CNTRL]
373 str r1, [r0, #I2C_DACNT]
375 /* wait for transfer to finish */
377 ldr r1, [r0, #I2C_DACNT]
381 /* load result and test USB_STATUS bit */
382 ldr r1, [r0, #I2C_DATA]
390 /* The dualboot button was not held, so we boot rockbox */
391 ldr r0, ucl_rb_end /* Address of compressed image */
392 ldr r1, ucl_rb_size /* Compressed size */
396 ldr r0, ucl_of_end /* Address of compressed image */
397 ldr r1, ucl_of_size /* Compressed size */
402 /* r0 = source_end for UCL image to copy */
403 /* r1 = size of UCL image to copy */
406 add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
407 /* function, plus one (for thumb mode */
409 sub r4, r3, r1 /* r4 := destination_start - 1 */
414 cmp r3, r4 /* Stop when we reached dest_start-1 */
417 /* Call the ucl decompress function, which will branch to 0x0 */
419 add r0, r3, #1 /* r0 := Start of compressed image */
420 /* r1 already contains compressed size */
421 mov r2, #0 /* r2 := Destination for unpacking */
422 bx r5 /* Branch to uclunpack, switching to thumb */
424 /* never reached : uclunpack will branch to the reset vector (0x0) */