Added battery profile change to correct file, removed unused powermgmt-as3525.c
[kugel-rb.git] / firmware / target / arm / as3525 / debug-as3525.c
blob06c22c027c89d0e5a166cb57b090f5150ab3f2c5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright © 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 ****************************************************************************/
22 #include <stdbool.h>
23 #include "debug-target.h"
24 #include "button.h"
25 #include "lcd.h"
26 #include "font.h"
27 #include "system.h"
28 #include "sprintf.h"
29 #include "cpu.h"
30 #include "pl180.h"
31 #include "ascodec-target.h"
32 #include "adc.h"
33 #include "storage.h"
35 #define ON "Enabled"
36 #define OFF "Disabled"
38 #define CP15_MMU (1<<0) /* mmu off/on */
39 #define CP15_DC (1<<2) /* dcache off/on */
40 #define CP15_IC (1<<12) /* icache off/on */
42 #define CLK_MAIN 24000000 /* 24 MHz */
44 #define CLK_PLLA 0
45 #define CLK_PLLB 1
46 #define CLK_PROC 2
47 #define CLK_FCLK 3
48 #define CLK_EXTMEM 4
49 #define CLK_PCLK 5
50 #define CLK_IDE 6
51 #define CLK_I2C 7
52 #define CLK_I2SI 8
53 #define CLK_I2SO 9
54 #define CLK_DBOP 10
55 #define CLK_SD_MCLK_NAND 11
56 #define CLK_SD_MCLK_MSD 12
57 #define CLK_USB 13
59 #define I2C2_CPSR0 *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x1C))
60 #define I2C2_CPSR1 *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x20))
61 #define MCI_NAND *((volatile unsigned long *)(NAND_FLASH_BASE + 0x04))
62 #define MCI_SD *((volatile unsigned long *)(SD_MCI_BASE + 0x04))
64 extern bool sd_enabled;
66 /* FIXME: target tree is including ./debug-target.h rather than the one in
67 * sansa-fuze/, even though deps contains the correct one
68 * if I put the below into a sansa-fuze/debug-target.h, it doesn't work*/
69 #if defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_C200V2)
70 #define DEBUG_DBOP
71 #include "dbop-as3525.h"
72 #endif
74 static inline unsigned read_cp15 (void)
76 unsigned cp15_value;
77 asm volatile (
78 "mrc p15, 0, %0, c1, c0, 0 @ read control reg\n" : "=r"(cp15_value));
79 return (cp15_value);
82 static int calc_freq(int clk)
84 unsigned int prediv = ((unsigned int)CGU_PROC>>2) & 0x3;
85 unsigned int postdiv = ((unsigned int)CGU_PROC>>4) & 0xf;
86 #if CONFIG_CPU == AS3525
87 int out_div;
89 switch(clk) {
90 /* clk_main = clk_int = 24MHz oscillator */
91 case CLK_PLLA:
92 if(CGU_PLLASUP & (1<<3))
93 return 0;
95 /*assume 24MHz oscillator only input available */
96 out_div = ((CGU_PLLA>>13) & 0x3); /* bits 13:14 */
97 if (out_div == 3) /* for 11 NO=4 */
98 out_div=4;
99 if(out_div) /* NO = 0 not allowed */
100 return ((2 * (CGU_PLLA & 0xff))*CLK_MAIN)/
101 (((CGU_PLLA>>8) & 0x1f)*out_div);
102 return 0;
103 case CLK_PLLB:
104 if(CGU_PLLBSUP & (1<<3))
105 return 0;
107 /*assume 24MHz oscillator only input available */
108 out_div = ((CGU_PLLB>>13) & 0x3); /* bits 13:14 */
109 if (out_div == 3) /* for 11 NO=4 */
110 out_div=4;
111 if(out_div) /* NO = 0 not allowed */
112 return ((2 * (CGU_PLLB & 0xff))*CLK_MAIN)/
113 (((CGU_PLLB>>8) & 0x1f)*out_div);
114 return 0;
115 #else
116 /* AS3525v2 */
117 switch(clk) {
118 /* we're using a known setting for PLLA = 240 MHz and PLLB inop */
119 case CLK_PLLA:
120 return 240000000;
122 case CLK_PLLB:
123 return 0;
124 #endif
125 case CLK_PROC:
126 #if CONFIG_CPU == AS3525 /* not in arm926-ejs */
127 if (!(read_cp15()>>30)) /* fastbus */
128 return calc_freq(CLK_PCLK);
129 else /* Synch or Asynch bus*/
130 #endif /* CONFIG_CPU == AS3525 */
131 return calc_freq(CLK_FCLK);
132 case CLK_FCLK:
133 switch(CGU_PROC & 3) {
134 case 0:
135 return (CLK_MAIN * (8 - prediv)) / (8 * (postdiv + 1));
136 case 1:
137 return (calc_freq(CLK_PLLA) * (8 - prediv)) /
138 (8 * (postdiv + 1));
139 case 2:
140 return (calc_freq(CLK_PLLB) * (8 - prediv)) /
141 (8 * (postdiv + 1));
142 default:
143 return 0;
145 case CLK_EXTMEM:
146 #if CONFIG_CPU == AS3525
147 switch(CGU_PERI & 3) {
148 #else
149 /* bits 1:0 of CGU_PERI always read as 0 and source = FCLK */
150 switch(3) {
151 #endif
152 case 0:
153 return CLK_MAIN/(((CGU_PERI>>2)& 0xf)+1);
154 case 1:
155 return calc_freq(CLK_PLLA)/(((CGU_PERI>>2)& 0xf)+1);
156 case 2:
157 return calc_freq(CLK_PLLB)/(((CGU_PERI>>2)& 0xf)+1);
158 case 3:
159 default:
160 return calc_freq(CLK_FCLK)/(((CGU_PERI>>2)& 0xf)+1);
162 case CLK_PCLK:
163 return calc_freq(CLK_EXTMEM)/(((CGU_PERI>>6)& 0x1)+1);
164 case CLK_IDE:
165 switch(CGU_IDE & 3) {
166 case 0:
167 return CLK_MAIN/(((CGU_IDE>>2)& 0xf)+1);
168 case 1:
169 return calc_freq(CLK_PLLA)/(((CGU_IDE>>2)& 0xf)+1);
170 case 2:
171 return calc_freq(CLK_PLLB)/(((CGU_IDE>>2)& 0xf)+1);
172 default:
173 return 0;
175 case CLK_I2C:
176 return calc_freq(CLK_PCLK)/AS3525_I2C_PRESCALER;
177 case CLK_I2SI:
178 switch((CGU_AUDIO>>12) & 3) {
179 case 0:
180 return CLK_MAIN/(((CGU_AUDIO>>14) & 0x1ff)+1);
181 case 1:
182 return calc_freq(CLK_PLLA)/(((CGU_AUDIO>>14) & 0x1ff)+1);
183 case 2:
184 return calc_freq(CLK_PLLB)/(((CGU_AUDIO>>14) & 0x1ff)+1);
185 default:
186 return 0;
188 case CLK_I2SO:
189 switch(CGU_AUDIO & 3) {
190 case 0:
191 return CLK_MAIN/(((CGU_AUDIO>>2) & 0x1ff)+1);
192 case 1:
193 return calc_freq(CLK_PLLA)/(((CGU_AUDIO>>2) & 0x1ff)+1);
194 case 2:
195 return calc_freq(CLK_PLLB)/(((CGU_AUDIO>>2) & 0x1ff)+1);
196 default:
197 return 0;
199 case CLK_DBOP:
200 return calc_freq(CLK_PCLK)/((CGU_DBOP & 7)+1);
201 #if CONFIG_CPU == AS3525
202 case CLK_SD_MCLK_NAND:
203 if(!(MCI_NAND & (1<<8)))
204 return 0;
205 else if(MCI_NAND & (1<<10))
206 return calc_freq(CLK_IDE);
207 else
208 return calc_freq(CLK_IDE)/(((MCI_NAND & 0xff)+1)*2);
209 case CLK_SD_MCLK_MSD:
210 if(!(MCI_SD & (1<<8)))
211 return 0;
212 else if(MCI_SD & (1<<10))
213 return calc_freq(CLK_PCLK);
214 else
215 return calc_freq(CLK_PCLK)/(((MCI_SD & 0xff)+1)*2);
216 #endif
217 case CLK_USB:
218 switch(CGU_USB & 3) { /* 0-> div=1 other->div=1/(2*n) */
219 case 0:
220 if (!((CGU_USB>>2) & 0x7))
221 return CLK_MAIN;
222 else
223 return CLK_MAIN/(2*((CGU_USB>>2) & 0x7));
224 case 1:
225 if (!((CGU_USB>>2) & 0x7))
226 return calc_freq(CLK_PLLA);
227 else
228 return calc_freq(CLK_PLLA)/(2*((CGU_USB>>2) & 0x7));
229 case 2:
230 if (!((CGU_USB>>2) & 0x7))
231 return calc_freq(CLK_PLLB);
232 else
233 return calc_freq(CLK_PLLB)/(2*((CGU_USB>>2) & 0x7));
234 default:
235 return 0;
237 default:
238 return 0;
242 bool __dbg_hw_info(void)
244 int line;
245 #if CONFIG_CPU == AS3525
246 int last_nand = 0;
247 #ifdef HAVE_MULTIDRIVE
248 int last_sd = 0;
249 #endif
250 #endif /* CONFIG_CPU == AS3525 */
252 lcd_clear_display();
253 lcd_setfont(FONT_SYSFIXED);
255 while(1)
257 while(1)
259 #ifdef SANSA_C200V2
260 lcd_clear_display();
261 line = 0;
262 lcd_puts(0, line++, "[Submodel:]");
263 lcd_putsf(0, line++, "C200v2 variant %d", c200v2_variant);
264 lcd_update();
265 int btn = button_get(1);
266 if(btn == (DEBUG_CANCEL|BUTTON_REL))
267 goto end;
268 else if(btn == (BUTTON_DOWN|BUTTON_REL))
269 break;
271 while(1)
273 #endif
274 lcd_clear_display();
275 line = 0;
276 lcd_puts(0, line++, "[Clock Frequencies:]");
277 lcd_puts(0, line++, " SET ACTUAL");
278 #if CONFIG_CPU == AS3525
279 lcd_putsf(0, line++, "922T:%s %3dMHz",
280 (!(read_cp15()>>30)) ? "FAST " :
281 (read_cp15()>>31) ? "ASYNC" : "SYNC ",
282 #else
283 lcd_putsf(0, line++, "926ejs: %3dMHz",
284 #endif
285 calc_freq(CLK_PROC)/1000000);
286 lcd_putsf(0, line++, "PLLA:%3dMHz %3dMHz", AS3525_PLLA_FREQ/1000000,
287 calc_freq(CLK_PLLA)/1000000);
288 lcd_putsf(0, line++, "PLLB: %3dMHz", calc_freq(CLK_PLLB)/1000000);
289 lcd_putsf(0, line++, "FCLK: %3dMHz", calc_freq(CLK_FCLK)/1000000);
290 lcd_putsf(0, line++, "DRAM:%3dMHz %3dMHz", AS3525_PCLK_FREQ/1000000,
291 calc_freq(CLK_EXTMEM)/1000000);
292 lcd_putsf(0, line++, "PCLK:%3dMHz %3dMHz", AS3525_PCLK_FREQ/1000000,
293 calc_freq(CLK_PCLK)/1000000);
295 #if LCD_HEIGHT < 176 /* clip */
296 lcd_update();
297 int btn = button_get_w_tmo(HZ/10);
298 if(btn == (DEBUG_CANCEL|BUTTON_REL))
299 goto end;
300 else if(btn == (BUTTON_DOWN|BUTTON_REL))
301 break;
303 while(1)
305 lcd_clear_display();
306 line = 0;
307 #endif /* LCD_HEIGHT < 176 */
309 lcd_putsf(0, line++, "IDE :%3dMHz %3dMHz", AS3525_IDE_FREQ/1000000,
310 calc_freq(CLK_IDE)/1000000);
311 lcd_putsf(0, line++, "DBOP:%3dMHz %3dMHz", AS3525_DBOP_FREQ/1000000,
312 calc_freq(CLK_DBOP)/1000000);
313 lcd_putsf(0, line++, "I2C :%3dkHz %3dkHz", AS3525_I2C_FREQ/1000,
314 calc_freq(CLK_I2C)/1000);
315 lcd_putsf(0, line++, "I2SI: %s %3dMHz", (CGU_AUDIO & (1<<23)) ?
316 "on " : "off" , calc_freq(CLK_I2SI)/1000000);
317 lcd_putsf(0, line++, "I2SO: %s %3dMHz", (CGU_AUDIO & (1<<11)) ?
318 "on " : "off", calc_freq(CLK_I2SO)/1000000);
319 #if CONFIG_CPU == AS3525
320 /* If disabled, enable SD cards so we can read the registers */
321 if(sd_enabled == false)
323 sd_enable(true);
324 last_nand = MCI_NAND;
325 #ifdef HAVE_MULTIDRIVE
326 last_sd = MCI_SD;
327 #endif
328 sd_enable(false);
331 lcd_putsf(0, line++, "SD :%3dMHz %3dMHz",
332 ((AS3525_IDE_FREQ/ 1000000) /
333 ((last_nand & MCI_CLOCK_BYPASS)? 1:(((last_nand & 0xff)+1) * 2))),
334 calc_freq(CLK_SD_MCLK_NAND)/1000000);
335 #ifdef HAVE_MULTIDRIVE
336 lcd_putsf(0, line++, "uSD :%3dMHz %3dMHz",
337 ((AS3525_PCLK_FREQ/ 1000000) /
338 ((last_sd & MCI_CLOCK_BYPASS) ? 1: (((last_sd & 0xff) + 1) * 2))),
339 calc_freq(CLK_SD_MCLK_MSD)/1000000);
340 #endif
341 #endif /* CONFIG_CPU == AS3525 */
342 lcd_putsf(0, line++, "USB : %3dMHz", calc_freq(CLK_USB)/1000000);
344 #if LCD_HEIGHT < 176 /* clip */
345 lcd_update();
346 int btn = button_get_w_tmo(HZ/10);
347 if(btn == (DEBUG_CANCEL|BUTTON_REL))
348 goto end;
349 else if(btn == (BUTTON_DOWN|BUTTON_REL))
350 break;
352 while(1)
354 lcd_clear_display();
355 line = 0;
356 #endif /* LCD_HEIGHT < 176 */
358 lcd_putsf(0, line++, "MMU : %s CVDDP:%4d", (read_cp15() & CP15_MMU) ?
359 " on" : "off", adc_read(ADC_CVDD) * 25);
360 lcd_putsf(0, line++, "Icache:%s Dcache:%s",
361 (read_cp15() & CP15_IC) ? " on" : "off",
362 (read_cp15() & CP15_DC) ? " on" : "off");
364 lcd_update();
365 int btn = button_get_w_tmo(HZ/10);
366 if(btn == (DEBUG_CANCEL|BUTTON_REL))
367 goto end;
368 else if(btn == (BUTTON_DOWN|BUTTON_REL))
369 break;
371 while(1)
373 lcd_clear_display();
374 line = 0;
376 lcd_putsf(0, line++, "CGU_PLLA :%8x", (unsigned int)(CGU_PLLA));
377 lcd_putsf(0, line++, "CGU_PLLB :%8x", (unsigned int)(CGU_PLLB));
378 lcd_putsf(0, line++, "CGU_PROC :%8x", (unsigned int)(CGU_PROC));
379 lcd_putsf(0, line++, "CGU_PERI :%8x", (unsigned int)(CGU_PERI));
380 lcd_putsf(0, line++, "CGU_IDE :%8x", (unsigned int)(CGU_IDE));
381 lcd_putsf(0, line++, "CGU_DBOP :%8x", (unsigned int)(CGU_DBOP));
382 lcd_putsf(0, line++, "CGU_AUDIO :%8x", (unsigned int)(CGU_AUDIO));
383 lcd_putsf(0, line++, "CGU_USB :%8x", (unsigned int)(CGU_USB));
385 #if LCD_HEIGHT < 176 /* clip */
386 lcd_update();
387 int btn = button_get_w_tmo(HZ/10);
388 if(btn == (DEBUG_CANCEL|BUTTON_REL))
389 goto end;
390 else if(btn == (BUTTON_DOWN|BUTTON_REL))
391 break;
393 while(1)
395 lcd_clear_display();
396 line = 0;
397 #endif /* LCD_HEIGHT < 176 */
399 lcd_putsf(0, line++, "I2C2_CPSR :%8x", (unsigned int)(I2C2_CPSR1<<8 |
400 I2C2_CPSR0));
401 #if CONFIG_CPU == AS3525
402 lcd_putsf(0, line++, "MCI_NAND :%8x", (unsigned int)(MCI_NAND));
403 lcd_putsf(0, line++, "MCI_SD :%8x", (unsigned int)(MCI_SD));
404 #else
405 lcd_putsf(0, line++, "CGU_MEMSTK:%8x", (unsigned int)(CGU_MEMSTICK));
406 lcd_putsf(0, line++, "CGU_SDSLOT:%8x", (unsigned int)(CGU_SDSLOT));
407 #endif
409 lcd_update();
410 int btn = button_get_w_tmo(HZ/10);
411 if(btn == (DEBUG_CANCEL|BUTTON_REL))
412 goto end;
413 else if(btn == (BUTTON_DOWN|BUTTON_REL))
414 break;
418 end:
419 lcd_setfont(FONT_UI);
420 return false;
423 bool __dbg_ports(void)
425 int line;
427 lcd_clear_display();
428 lcd_setfont(FONT_SYSFIXED);
430 while(1)
432 line = 0;
433 lcd_puts(0, line++, "[GPIO Values and Directions]");
434 lcd_putsf(0, line++, "GPIOA: %2x DIR: %2x", GPIOA_DATA, GPIOA_DIR);
435 lcd_putsf(0, line++, "GPIOB: %2x DIR: %2x", GPIOB_DATA, GPIOB_DIR);
436 lcd_putsf(0, line++, "GPIOC: %2x DIR: %2x", GPIOC_DATA, GPIOC_DIR);
437 lcd_putsf(0, line++, "GPIOD: %2x DIR: %2x", GPIOD_DATA, GPIOD_DIR);
438 #ifdef DEBUG_DBOP
439 line++;
440 lcd_puts(0, line++, "[DBOP_DIN]");
441 lcd_putsf(0, line++, "DBOP_DIN: %4x", dbop_debug());
442 #endif
443 line++;
444 lcd_puts(0, line++, "[CP15]");
445 lcd_putsf(0, line++, "CP15: 0x%8x", read_cp15());
446 lcd_update();
447 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
448 break;
450 lcd_setfont(FONT_UI);
451 return false;