Gigabeat S: Implement MDMA and UDMA disk access for bootloader and main binary. Add...
[kugel-rb.git] / firmware / target / arm / imx31 / debug-imx31.c
blobad436ea231037727718b5a6215d7a6366c441552
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Michael Sevakis
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 ****************************************************************************/
21 #include "config.h"
22 #include "system.h"
23 #include "string.h"
24 #include "button.h"
25 #include "lcd.h"
26 #include "sprintf.h"
27 #include "font.h"
28 #include "debug-target.h"
29 #include "mc13783.h"
30 #include "adc.h"
31 #include "clkctl-imx31.h"
33 bool __dbg_hw_info(void)
35 char buf[50];
36 int line;
37 unsigned int pllref;
38 unsigned int mcu_pllfreq, ser_pllfreq, usb_pllfreq;
39 uint32_t mpctl, spctl, upctl;
40 unsigned int freq;
41 uint32_t regval;
43 lcd_clear_display();
44 lcd_setfont(FONT_SYSFIXED);
46 while (1)
48 line = 0;
49 snprintf(buf, sizeof (buf), "Sys Rev Code: 0x%02X",
50 iim_system_rev());
51 lcd_puts(0, line++, buf); line++;
53 mpctl = CLKCTL_MPCTL;
54 spctl = CLKCTL_SPCTL;
55 upctl = CLKCTL_UPCTL;
57 pllref = imx31_clkctl_get_pll_ref_clk();
59 mcu_pllfreq = imx31_clkctl_get_pll(PLL_MCU);
60 ser_pllfreq = imx31_clkctl_get_pll(PLL_SERIAL);
61 usb_pllfreq = imx31_clkctl_get_pll(PLL_USB);
63 snprintf(buf, sizeof (buf), "pll_ref_clk: %u", pllref);
64 lcd_puts(0, line++, buf); line++;
66 /* MCU clock domain */
67 snprintf(buf, sizeof (buf), "MPCTL: %08lX", mpctl);
68 lcd_puts(0, line++, buf);
70 snprintf(buf, sizeof (buf), " mpl_dpdgck_clk: %u", mcu_pllfreq);
71 lcd_puts(0, line++, buf); line++;
73 regval = CLKCTL_PDR0;
74 snprintf(buf, sizeof (buf), " PDR0: %08lX", regval);
75 lcd_puts(0, line++, buf);
77 freq = mcu_pllfreq / (((regval & 0x7) + 1));
78 snprintf(buf, sizeof (buf), " mcu_clk: %u", freq);
79 lcd_puts(0, line++, buf);
81 freq = mcu_pllfreq / (((regval >> 11) & 0x7) + 1);
82 snprintf(buf, sizeof (buf), " hsp_clk: %u", freq);
83 lcd_puts(0, line++, buf);
85 freq = mcu_pllfreq / (((regval >> 3) & 0x7) + 1);
86 snprintf(buf, sizeof (buf), " hclk_clk: %u", freq);
87 lcd_puts(0, line++, buf);
89 snprintf(buf, sizeof (buf), " ipg_clk: %u",
90 freq / (unsigned)(((regval >> 6) & 0x3) + 1));
91 lcd_puts(0, line++, buf);
93 snprintf(buf, sizeof (buf), " nfc_clk: %u",
94 freq / (unsigned)(((regval >> 8) & 0x7) + 1));
95 lcd_puts(0, line++, buf);
97 line++;
99 /* Serial clock domain */
100 snprintf(buf, sizeof (buf), "SPCTL: %08lX", spctl);
101 lcd_puts(0, line++, buf);
102 snprintf(buf, sizeof (buf), " spl_dpdgck_clk: %u", ser_pllfreq);
103 lcd_puts(0, line++, buf);
105 line++;
107 /* USB clock domain */
108 snprintf(buf, sizeof (buf), "UPCTL: %08lX", upctl);
109 lcd_puts(0, line++, buf);
111 snprintf(buf, sizeof (buf), " upl_dpdgck_clk: %u", usb_pllfreq);
112 lcd_puts(0, line++, buf); line++;
114 regval = CLKCTL_PDR1;
115 snprintf(buf, sizeof (buf), " PDR1: %08lX", regval);
116 lcd_puts(0, line++, buf);
118 freq = usb_pllfreq /
119 ((((regval >> 30) & 0x3) + 1) * (((regval >> 27) & 0x7) + 1));
120 snprintf(buf, sizeof (buf), " usb_clk: %u", freq);
121 lcd_puts(0, line++, buf);
123 freq = usb_pllfreq / (((CLKCTL_PDR0 >> 16) & 0x1f) + 1);
124 snprintf(buf, sizeof (buf), " ipg_per_baud: %u", freq);
125 lcd_puts(0, line++, buf);
127 lcd_update();
129 if (button_get(true) == (DEBUG_CANCEL|BUTTON_REL))
130 return false;
134 bool __dbg_ports(void)
136 char buf[50];
137 int line;
138 int i;
140 static const char pmic_regset[] =
142 MC13783_INTERRUPT_STATUS0,
143 MC13783_INTERRUPT_SENSE0,
144 MC13783_INTERRUPT_STATUS1,
145 MC13783_INTERRUPT_SENSE1,
146 MC13783_CHARGER,
147 MC13783_RTC_TIME,
148 MC13783_RTC_ALARM,
149 MC13783_RTC_DAY,
150 MC13783_RTC_DAY_ALARM,
153 static const char *pmic_regnames[ARRAYLEN(pmic_regset)] =
155 "Int Stat0 ",
156 "Int Sense0",
157 "Int Stat1 ",
158 "Int Sense1",
159 "Charger ",
160 "RTC Time ",
161 "RTC Alarm ",
162 "RTC Day ",
163 "RTC Day Al",
166 uint32_t pmic_regs[ARRAYLEN(pmic_regset)];
168 lcd_clear_display();
169 lcd_setfont(FONT_SYSFIXED);
171 while(1)
173 line = 0;
174 snprintf(buf, sizeof(buf), "[Ports and Registers]");
175 lcd_puts(0, line++, buf); line++;
177 /* GPIO1 */
178 snprintf(buf, sizeof(buf), "GPIO1: DR: %08lx GDIR: %08lx", GPIO1_DR, GPIO1_GDIR);
179 lcd_puts(0, line++, buf);
181 snprintf(buf, sizeof(buf), " PSR: %08lx ICR1: %08lx", GPIO1_PSR, GPIO1_ICR1);
182 lcd_puts(0, line++, buf);
184 snprintf(buf, sizeof(buf), " ICR2: %08lx IMR: %08lx", GPIO1_ICR2, GPIO1_IMR);
185 lcd_puts(0, line++, buf);
187 snprintf(buf, sizeof(buf), " ISR: %08lx", GPIO1_ISR);
188 lcd_puts(0, line++, buf); line++;
190 /* GPIO2 */
191 snprintf(buf, sizeof(buf), "GPIO2: DR: %08lx GDIR: %08lx", GPIO2_DR, GPIO2_GDIR);
192 lcd_puts(0, line++, buf);
194 snprintf(buf, sizeof(buf), " PSR: %08lx ICR1: %08lx", GPIO2_PSR, GPIO2_ICR1);
195 lcd_puts(0, line++, buf);
197 snprintf(buf, sizeof(buf), " ICR2: %08lx IMR: %08lx", GPIO2_ICR2, GPIO2_IMR);
198 lcd_puts(0, line++, buf);
200 snprintf(buf, sizeof(buf), " ISR: %08lx", GPIO2_ISR);
201 lcd_puts(0, line++, buf); line++;
203 /* GPIO3 */
204 snprintf(buf, sizeof(buf), "GPIO3: DR: %08lx GDIR: %08lx", GPIO3_DR, GPIO3_GDIR);
205 lcd_puts(0, line++, buf);
207 snprintf(buf, sizeof(buf), " PSR: %08lx ICR1: %08lx", GPIO3_PSR, GPIO3_ICR1);
208 lcd_puts(0, line++, buf);
210 snprintf(buf, sizeof(buf), " ICR2: %08lx IMR: %08lx", GPIO3_ICR2, GPIO3_IMR);
211 lcd_puts(0, line++, buf);
213 snprintf(buf, sizeof(buf), " ISR: %08lx", GPIO3_ISR);
214 lcd_puts(0, line++, buf); line++;
216 lcd_puts(0, line++, "PMIC Registers"); line++;
218 mc13783_read_regset(pmic_regset, pmic_regs, ARRAYLEN(pmic_regs));
220 for (i = 0; i < (int)ARRAYLEN(pmic_regs); i++)
222 snprintf(buf, sizeof(buf), "%s: %08lx", pmic_regnames[i], pmic_regs[i]);
223 lcd_puts(0, line++, buf);
226 line++;
228 lcd_puts(0, line++, "ADC"); line++;
230 for (i = 0; i < NUM_ADC_CHANNELS; i += 4)
232 snprintf(buf, sizeof(buf),
233 "CH%02d:%04u CH%02d:%04u CH%02d:%04u CH%02d:%04u",
234 i+0, adc_read(i+0),
235 i+1, adc_read(i+1),
236 i+2, adc_read(i+2),
237 i+3, adc_read(i+3));
238 lcd_puts(0, line++, buf);
241 lcd_update();
242 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
243 return false;