Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / firmware / target / arm / imx31 / debug-imx31.c
blob07f9453b29ac0a5b4d66f935d33015db3b576811
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 "font.h"
27 #include "debug-target.h"
28 #include "mc13783.h"
29 #include "adc.h"
30 #include "ccm-imx31.h"
31 #include "dvfs_dptc-imx31.h"
33 bool __dbg_hw_info(void)
35 int line;
36 unsigned int pllref;
37 unsigned int mcu_pllfreq, ser_pllfreq, usb_pllfreq;
38 uint32_t mpctl, spctl, upctl;
39 unsigned int freq;
40 uint32_t regval;
42 extern volatile unsigned int dvfs_nr_dn, dvfs_nr_up,
43 dvfs_nr_pnc, dvfs_nr_no;
44 extern volatile unsigned int dptc_nr_dn, dptc_nr_up,
45 dptc_nr_pnc, dptc_nr_no;
47 lcd_clear_display();
48 lcd_setfont(FONT_SYSFIXED);
50 while (1)
52 line = 0;
53 lcd_putsf(0, line++, "Sys Rev Code: 0x%02X", iim_system_rev());
54 line++;
56 mpctl = CCM_MPCTL;
57 spctl = CCM_SPCTL;
58 upctl = CCM_UPCTL;
60 pllref = ccm_get_pll_ref_clk_rate();
62 mcu_pllfreq = ccm_calc_pll_rate(pllref, mpctl);
63 ser_pllfreq = ccm_calc_pll_rate(pllref, spctl);
64 usb_pllfreq = ccm_calc_pll_rate(pllref, upctl);
66 lcd_putsf(0, line++, "pll_ref_clk: %u", pllref);
67 line++;
69 /* MCU clock domain */
70 lcd_putsf(0, line++, "MPCTL: %08lX", mpctl);
72 lcd_putsf(0, line++, " mpl_dpdgck_clk: %u", mcu_pllfreq);
73 line++;
75 regval = CCM_PDR0;
76 lcd_putsf(0, line++, " PDR0: %08lX", regval);
78 freq = mcu_pllfreq / (((regval & 0x7) + 1));
79 lcd_putsf(0, line++, " mcu_clk: %u", freq);
81 freq = mcu_pllfreq / (((regval >> 11) & 0x7) + 1);
82 lcd_putsf(0, line++, " hsp_clk: %u", freq);
84 freq = mcu_pllfreq / (((regval >> 3) & 0x7) + 1);
85 lcd_putsf(0, line++, " hclk_clk: %u", freq);
87 lcd_putsf(0, line++, " ipg_clk: %u",
88 freq / (unsigned)(((regval >> 6) & 0x3) + 1));
90 lcd_putsf(0, line++, " nfc_clk: %u",
91 freq / (unsigned)(((regval >> 8) & 0x7) + 1));
93 line++;
95 /* Serial clock domain */
96 lcd_putsf(0, line++, "SPCTL: %08lX", spctl);
97 lcd_putsf(0, line++, " spl_dpdgck_clk: %u", ser_pllfreq);
99 line++;
101 /* USB clock domain */
102 lcd_putsf(0, line++, "UPCTL: %08lX", upctl);
104 lcd_putsf(0, line++, " upl_dpdgck_clk: %u", usb_pllfreq);
106 regval = CCM_PDR1;
107 lcd_putsf(0, line++, " PDR1: %08lX", regval);
109 freq = usb_pllfreq /
110 ((((regval >> 30) & 0x3) + 1) * (((regval >> 27) & 0x7) + 1));
111 lcd_putsf(0, line++, " usb_clk: %u", freq);
113 freq = usb_pllfreq / (((CCM_PDR0 >> 16) & 0x1f) + 1);
114 lcd_putsf(0, line++, " ipg_per_baud: %u", freq);
116 line++;
117 lcd_putsf(0, line++, "PMCR0: %08lX", CCM_PMCR0);
119 line++;
120 lcd_putsf(0, line++, "cpu_frequency: %ld Hz", cpu_frequency);
122 lcd_putsf(0, line++, "dvfs_level: %u", dvfs_get_level());
123 lcd_putsf(0, line++, "dvfs d|u|p|n: %u %u %u %u",
124 dvfs_nr_dn, dvfs_nr_up, dvfs_nr_pnc, dvfs_nr_no);
125 regval = dvfs_dptc_get_voltage();
126 lcd_putsf(0, line++, "cpu_voltage: %d.%03d V", regval / 1000,
127 regval % 1000);
129 lcd_putsf(0, line++, "dptc_wp: %u", dptc_get_wp());
130 lcd_putsf(0, line++, "dptc d|u|p|n: %u %u %u %u",
131 dptc_nr_dn, dptc_nr_up, dptc_nr_pnc, dptc_nr_no);
132 lcd_putsf(0, line++, "DVCR0,1: %08lX %08lX", CCM_DCVR0, CCM_DCVR1);
133 lcd_putsf(0, line++, "DVCR2,3: %08lX %08lX", CCM_DCVR2, CCM_DCVR3);
134 lcd_putsf(0, line++, "SWITCHERS0: %08lX", mc13783_read(MC13783_SWITCHERS0));
135 lcd_putsf(0, line++, "SWITCHERS1: %08lX", mc13783_read(MC13783_SWITCHERS1));
137 lcd_update();
139 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
140 return false;
144 bool __dbg_ports(void)
146 int line;
147 int i;
149 static const char pmic_regset[] =
151 MC13783_INTERRUPT_STATUS0,
152 MC13783_INTERRUPT_SENSE0,
153 MC13783_INTERRUPT_STATUS1,
154 MC13783_INTERRUPT_SENSE1,
155 MC13783_CHARGER,
156 MC13783_RTC_TIME,
157 MC13783_RTC_ALARM,
158 MC13783_RTC_DAY,
159 MC13783_RTC_DAY_ALARM,
162 static const char *pmic_regnames[ARRAYLEN(pmic_regset)] =
164 "Int Stat0 ",
165 "Int Sense0",
166 "Int Stat1 ",
167 "Int Sense1",
168 "Charger ",
169 "RTC Time ",
170 "RTC Alarm ",
171 "RTC Day ",
172 "RTC Day Al",
175 uint32_t pmic_regs[ARRAYLEN(pmic_regset)];
177 lcd_clear_display();
178 lcd_setfont(FONT_SYSFIXED);
180 while(1)
182 line = 0;
183 lcd_puts(0, line++, "[Ports and Registers]");
184 line++;
186 /* GPIO1 */
187 lcd_putsf(0, line++, "GPIO1: DR: %08lx GDIR: %08lx", GPIO1_DR, GPIO1_GDIR);
189 lcd_putsf(0, line++, " PSR: %08lx ICR1: %08lx", GPIO1_PSR, GPIO1_ICR1);
191 lcd_putsf(0, line++, " ICR2: %08lx IMR: %08lx", GPIO1_ICR2, GPIO1_IMR);
193 lcd_putsf(0, line++, " ISR: %08lx", GPIO1_ISR);
194 line++;
196 /* GPIO2 */
197 lcd_putsf(0, line++, "GPIO2: DR: %08lx GDIR: %08lx", GPIO2_DR, GPIO2_GDIR);
199 lcd_putsf(0, line++, " PSR: %08lx ICR1: %08lx", GPIO2_PSR, GPIO2_ICR1);
201 lcd_putsf(0, line++, " ICR2: %08lx IMR: %08lx", GPIO2_ICR2, GPIO2_IMR);
203 lcd_putsf(0, line++, " ISR: %08lx", GPIO2_ISR);
204 line++;
206 /* GPIO3 */
207 lcd_putsf(0, line++, "GPIO3: DR: %08lx GDIR: %08lx", GPIO3_DR, GPIO3_GDIR);
209 lcd_putsf(0, line++, " PSR: %08lx ICR1: %08lx", GPIO3_PSR, GPIO3_ICR1);
211 lcd_putsf(0, line++, " ICR2: %08lx IMR: %08lx", GPIO3_ICR2, GPIO3_IMR);
213 lcd_putsf(0, line++, " ISR: %08lx", GPIO3_ISR);
214 line++;
216 lcd_puts(0, line++, "PMIC Registers");
217 line++;
219 mc13783_read_regs(pmic_regset, pmic_regs, ARRAYLEN(pmic_regs));
221 for (i = 0; i < (int)ARRAYLEN(pmic_regs); i++)
223 lcd_putsf(0, line++, "%s: %08lx", pmic_regnames[i], pmic_regs[i]);
226 line++;
228 lcd_puts(0, line++, "ADC");
229 line++;
231 for (i = 0; i < NUM_ADC_CHANNELS; i += 4)
233 lcd_putsf(0, line++,
234 "CH%02d:%04u CH%02d:%04u CH%02d:%04u CH%02d:%04u",
235 i+0, adc_read(i+0),
236 i+1, adc_read(i+1),
237 i+2, adc_read(i+2),
238 i+3, adc_read(i+3));
241 lcd_update();
242 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
243 return false;