i.MX31/Gigabeat S: Actually enable DPTC which can set optimal voltage for 528MHz...
[kugel-rb.git] / firmware / target / arm / imx31 / debug-imx31.c
blob2c4f8b4023fed630bba55f2dae390e0d48d336b9
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 "ccm-imx31.h"
32 #include "dvfs_dptc-imx31.h"
34 bool __dbg_hw_info(void)
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 extern volatile unsigned int dvfs_nr_dn, dvfs_nr_up, dvfs_nr_pnc;
44 extern volatile unsigned int dptc_nr_dn, dptc_nr_up, dptc_nr_pnc;
46 lcd_clear_display();
47 lcd_setfont(FONT_SYSFIXED);
49 while (1)
51 line = 0;
52 lcd_putsf(0, line++, "Sys Rev Code: 0x%02X", iim_system_rev());
53 line++;
55 mpctl = CCM_MPCTL;
56 spctl = CCM_SPCTL;
57 upctl = CCM_UPCTL;
59 pllref = ccm_get_pll_ref_clk_rate();
61 mcu_pllfreq = ccm_calc_pll_rate(pllref, mpctl);
62 ser_pllfreq = ccm_calc_pll_rate(pllref, spctl);
63 usb_pllfreq = ccm_calc_pll_rate(pllref, upctl);
65 lcd_putsf(0, line++, "pll_ref_clk: %u", pllref);
66 line++;
68 /* MCU clock domain */
69 lcd_putsf(0, line++, "MPCTL: %08lX", mpctl);
71 lcd_putsf(0, line++, " mpl_dpdgck_clk: %u", mcu_pllfreq);
72 line++;
74 regval = CCM_PDR0;
75 lcd_putsf(0, line++, " PDR0: %08lX", regval);
77 freq = mcu_pllfreq / (((regval & 0x7) + 1));
78 lcd_putsf(0, line++, " mcu_clk: %u", freq);
80 freq = mcu_pllfreq / (((regval >> 11) & 0x7) + 1);
81 lcd_putsf(0, line++, " hsp_clk: %u", freq);
83 freq = mcu_pllfreq / (((regval >> 3) & 0x7) + 1);
84 lcd_putsf(0, line++, " hclk_clk: %u", freq);
86 lcd_putsf(0, line++, " ipg_clk: %u",
87 freq / (unsigned)(((regval >> 6) & 0x3) + 1));
89 lcd_putsf(0, line++, " nfc_clk: %u",
90 freq / (unsigned)(((regval >> 8) & 0x7) + 1));
92 line++;
94 /* Serial clock domain */
95 lcd_putsf(0, line++, "SPCTL: %08lX", spctl);
96 lcd_putsf(0, line++, " spl_dpdgck_clk: %u", ser_pllfreq);
98 line++;
100 /* USB clock domain */
101 lcd_putsf(0, line++, "UPCTL: %08lX", upctl);
103 lcd_putsf(0, line++, " upl_dpdgck_clk: %u", usb_pllfreq);
105 regval = CCM_PDR1;
106 lcd_putsf(0, line++, " PDR1: %08lX", regval);
108 freq = usb_pllfreq /
109 ((((regval >> 30) & 0x3) + 1) * (((regval >> 27) & 0x7) + 1));
110 lcd_putsf(0, line++, " usb_clk: %u", freq);
112 freq = usb_pllfreq / (((CCM_PDR0 >> 16) & 0x1f) + 1);
113 lcd_putsf(0, line++, " ipg_per_baud: %u", freq);
115 line++;
116 lcd_putsf(0, line++, "PMCR0: %08lX", CCM_PMCR0);
118 line++;
119 lcd_putsf(0, line++, "cpu_frequency: %ld Hz", cpu_frequency);
121 lcd_putsf(0, line++, "dvfs_level: %u", dvfs_get_level());
122 lcd_putsf(0, line++, "dvfs d|u|p: %u %u %u", dvfs_nr_dn, dvfs_nr_up, dvfs_nr_pnc);
123 regval = dvfs_dptc_get_voltage();
124 lcd_putsf(0, line++, "cpu_voltage: %d.%03d V", regval / 1000,
125 regval % 1000);
127 lcd_putsf(0, line++, "dptc_wp: %u", dptc_get_wp());
128 lcd_putsf(0, line++, "dptc d|u|p: %u %u %u", dptc_nr_dn, dptc_nr_up, dptc_nr_pnc);
129 lcd_putsf(0, line++, "DVCR0,1: %08lX %08lX", CCM_DCVR0, CCM_DCVR1);
130 lcd_putsf(0, line++, "DVCR2,3: %08lX %08lX", CCM_DCVR2, CCM_DCVR3);
131 lcd_putsf(0, line++, "SWITCHERS0: %08lX", mc13783_read(MC13783_SWITCHERS0));
132 lcd_putsf(0, line++, "SWITCHERS1: %08lX", mc13783_read(MC13783_SWITCHERS1));
134 lcd_update();
136 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
137 return false;
141 bool __dbg_ports(void)
143 int line;
144 int i;
146 static const char pmic_regset[] =
148 MC13783_INTERRUPT_STATUS0,
149 MC13783_INTERRUPT_SENSE0,
150 MC13783_INTERRUPT_STATUS1,
151 MC13783_INTERRUPT_SENSE1,
152 MC13783_CHARGER,
153 MC13783_RTC_TIME,
154 MC13783_RTC_ALARM,
155 MC13783_RTC_DAY,
156 MC13783_RTC_DAY_ALARM,
159 static const char *pmic_regnames[ARRAYLEN(pmic_regset)] =
161 "Int Stat0 ",
162 "Int Sense0",
163 "Int Stat1 ",
164 "Int Sense1",
165 "Charger ",
166 "RTC Time ",
167 "RTC Alarm ",
168 "RTC Day ",
169 "RTC Day Al",
172 uint32_t pmic_regs[ARRAYLEN(pmic_regset)];
174 lcd_clear_display();
175 lcd_setfont(FONT_SYSFIXED);
177 while(1)
179 line = 0;
180 lcd_puts(0, line++, "[Ports and Registers]");
181 line++;
183 /* GPIO1 */
184 lcd_putsf(0, line++, "GPIO1: DR: %08lx GDIR: %08lx", GPIO1_DR, GPIO1_GDIR);
186 lcd_putsf(0, line++, " PSR: %08lx ICR1: %08lx", GPIO1_PSR, GPIO1_ICR1);
188 lcd_putsf(0, line++, " ICR2: %08lx IMR: %08lx", GPIO1_ICR2, GPIO1_IMR);
190 lcd_putsf(0, line++, " ISR: %08lx", GPIO1_ISR);
191 line++;
193 /* GPIO2 */
194 lcd_putsf(0, line++, "GPIO2: DR: %08lx GDIR: %08lx", GPIO2_DR, GPIO2_GDIR);
196 lcd_putsf(0, line++, " PSR: %08lx ICR1: %08lx", GPIO2_PSR, GPIO2_ICR1);
198 lcd_putsf(0, line++, " ICR2: %08lx IMR: %08lx", GPIO2_ICR2, GPIO2_IMR);
200 lcd_putsf(0, line++, " ISR: %08lx", GPIO2_ISR);
201 line++;
203 /* GPIO3 */
204 lcd_putsf(0, line++, "GPIO3: DR: %08lx GDIR: %08lx", GPIO3_DR, GPIO3_GDIR);
206 lcd_putsf(0, line++, " PSR: %08lx ICR1: %08lx", GPIO3_PSR, GPIO3_ICR1);
208 lcd_putsf(0, line++, " ICR2: %08lx IMR: %08lx", GPIO3_ICR2, GPIO3_IMR);
210 lcd_putsf(0, line++, " ISR: %08lx", GPIO3_ISR);
211 line++;
213 lcd_puts(0, line++, "PMIC Registers");
214 line++;
216 mc13783_read_regs(pmic_regset, pmic_regs, ARRAYLEN(pmic_regs));
218 for (i = 0; i < (int)ARRAYLEN(pmic_regs); i++)
220 lcd_putsf(0, line++, "%s: %08lx", pmic_regnames[i], pmic_regs[i]);
223 line++;
225 lcd_puts(0, line++, "ADC");
226 line++;
228 for (i = 0; i < NUM_ADC_CHANNELS; i += 4)
230 lcd_putsf(0, line++,
231 "CH%02d:%04u CH%02d:%04u CH%02d:%04u CH%02d:%04u",
232 i+0, adc_read(i+0),
233 i+1, adc_read(i+1),
234 i+2, adc_read(i+2),
235 i+3, adc_read(i+3));
238 lcd_update();
239 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
240 return false;