blob: df2489eafb22919c4ab2801eb78382f276bfb7fa [file] [log] [blame]
Michael Sevakis57742e02008-04-11 15:49:48 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Michael Sevakis
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Michael Sevakis57742e02008-04-11 15:49:48 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
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"
Michael Sevakisa7af9e42008-04-12 16:56:45 +000029#include "mc13783.h"
Michael Sevakisb12c69b2008-04-13 20:03:08 +000030#include "adc.h"
Michael Sevakisbe0c7d02008-05-05 10:53:06 +000031#include "clkctl-imx31.h"
Michael Sevakis5df44052008-05-03 15:14:52 +000032
Michael Sevakis57742e02008-04-11 15:49:48 +000033bool __dbg_hw_info(void)
34{
Michael Sevakis5df44052008-05-03 15:14:52 +000035 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;
42
Michael Sevakis5df44052008-05-03 15:14:52 +000043 lcd_clear_display();
44 lcd_setfont(FONT_SYSFIXED);
45
46 while (1)
47 {
48 line = 0;
49 mpctl = CLKCTL_MPCTL;
50 spctl = CLKCTL_SPCTL;
51 upctl = CLKCTL_UPCTL;
52
Michael Sevakisbe0c7d02008-05-05 10:53:06 +000053 pllref = imx31_clkctl_get_pll_ref_clk();
Michael Sevakis5df44052008-05-03 15:14:52 +000054
Michael Sevakisbe0c7d02008-05-05 10:53:06 +000055 mcu_pllfreq = imx31_clkctl_get_pll(PLL_MCU);
56 ser_pllfreq = imx31_clkctl_get_pll(PLL_SERIAL);
57 usb_pllfreq = imx31_clkctl_get_pll(PLL_USB);
Michael Sevakis5df44052008-05-03 15:14:52 +000058
59 snprintf(buf, sizeof (buf), "pll_ref_clk: %u", pllref);
60 lcd_puts(0, line++, buf); line++;
61
62 /* MCU clock domain */
63 snprintf(buf, sizeof (buf), "MPCTL: %08lX", mpctl);
64 lcd_puts(0, line++, buf);
65
66 snprintf(buf, sizeof (buf), " mpl_dpdgck_clk: %u", mcu_pllfreq);
67 lcd_puts(0, line++, buf); line++;
68
69 regval = CLKCTL_PDR0;
70 snprintf(buf, sizeof (buf), " PDR0: %08lX", regval);
71 lcd_puts(0, line++, buf);
72
73 freq = mcu_pllfreq / (((regval & 0x7) + 1));
74 snprintf(buf, sizeof (buf), " mcu_clk: %u", freq);
75 lcd_puts(0, line++, buf);
76
77 freq = mcu_pllfreq / (((regval >> 11) & 0x7) + 1);
78 snprintf(buf, sizeof (buf), " hsp_clk: %u", freq);
79 lcd_puts(0, line++, buf);
80
81 freq = mcu_pllfreq / (((regval >> 3) & 0x7) + 1);
82 snprintf(buf, sizeof (buf), " hclk_clk: %u", freq);
83 lcd_puts(0, line++, buf);
84
85 snprintf(buf, sizeof (buf), " ipg_clk: %u",
86 freq / (unsigned)(((regval >> 6) & 0x3) + 1));
87 lcd_puts(0, line++, buf);
88
89 snprintf(buf, sizeof (buf), " nfc_clk: %u",
90 freq / (unsigned)(((regval >> 8) & 0x7) + 1));
91 lcd_puts(0, line++, buf);
92
93 line++;
94
95 /* Serial clock domain */
96 snprintf(buf, sizeof (buf), "SPCTL: %08lX", spctl);
97 lcd_puts(0, line++, buf);
98 snprintf(buf, sizeof (buf), " spl_dpdgck_clk: %u", ser_pllfreq);
99 lcd_puts(0, line++, buf);
100
101 line++;
102
103 /* USB clock domain */
104 snprintf(buf, sizeof (buf), "UPCTL: %08lX", upctl);
105 lcd_puts(0, line++, buf);
106
107 snprintf(buf, sizeof (buf), " upl_dpdgck_clk: %u", usb_pllfreq);
108 lcd_puts(0, line++, buf); line++;
109
110 regval = CLKCTL_PDR1;
111 snprintf(buf, sizeof (buf), " PDR1: %08lX", regval);
112 lcd_puts(0, line++, buf);
113
114 freq = usb_pllfreq /
115 ((((regval >> 30) & 0x3) + 1) * (((regval >> 27) & 0x7) + 1));
116 snprintf(buf, sizeof (buf), " usb_clk: %u", freq);
117 lcd_puts(0, line++, buf);
118
119 freq = usb_pllfreq / (((CLKCTL_PDR0 >> 16) & 0x1f) + 1);
120 snprintf(buf, sizeof (buf), " ipg_per_baud: %u", freq);
121 lcd_puts(0, line++, buf);
122
123 lcd_update();
124
125 if (button_get(true) == (DEBUG_CANCEL|BUTTON_REL))
126 return false;
127 }
Michael Sevakis57742e02008-04-11 15:49:48 +0000128}
129
130bool __dbg_ports(void)
131{
132 char buf[50];
133 int line;
Michael Sevakisa7af9e42008-04-12 16:56:45 +0000134 int i;
135
136 static const char pmic_regset[] =
137 {
138 MC13783_INTERRUPT_STATUS0,
139 MC13783_INTERRUPT_SENSE0,
140 MC13783_INTERRUPT_STATUS1,
141 MC13783_INTERRUPT_SENSE1,
142 MC13783_RTC_TIME,
143 MC13783_RTC_ALARM,
144 MC13783_RTC_DAY,
145 MC13783_RTC_DAY_ALARM,
Michael Sevakisa7af9e42008-04-12 16:56:45 +0000146 };
147
148 static const char *pmic_regnames[ARRAYLEN(pmic_regset)] =
149 {
150 "Int Stat0 ",
151 "Int Sense0",
152 "Int Stat1 ",
153 "Int Sense1",
154 "RTC Time ",
155 "RTC Alarm ",
156 "RTC Day ",
157 "RTC Day Al",
Michael Sevakisa7af9e42008-04-12 16:56:45 +0000158 };
159
160 uint32_t pmic_regs[ARRAYLEN(pmic_regset)];
Michael Sevakis57742e02008-04-11 15:49:48 +0000161
Michael Sevakis57742e02008-04-11 15:49:48 +0000162 lcd_clear_display();
163 lcd_setfont(FONT_SYSFIXED);
164
165 while(1)
166 {
167 line = 0;
168 snprintf(buf, sizeof(buf), "[Ports and Registers]");
169 lcd_puts(0, line++, buf); line++;
170
171 /* GPIO1 */
172 snprintf(buf, sizeof(buf), "GPIO1: DR: %08lx GDIR: %08lx", GPIO1_DR, GPIO1_GDIR);
173 lcd_puts(0, line++, buf);
174
175 snprintf(buf, sizeof(buf), " PSR: %08lx ICR1: %08lx", GPIO1_PSR, GPIO1_ICR1);
176 lcd_puts(0, line++, buf);
177
178 snprintf(buf, sizeof(buf), " ICR2: %08lx IMR: %08lx", GPIO1_ICR2, GPIO1_IMR);
179 lcd_puts(0, line++, buf);
180
181 snprintf(buf, sizeof(buf), " ISR: %08lx", GPIO1_ISR);
182 lcd_puts(0, line++, buf); line++;
183
184 /* GPIO2 */
185 snprintf(buf, sizeof(buf), "GPIO2: DR: %08lx GDIR: %08lx", GPIO2_DR, GPIO2_GDIR);
186 lcd_puts(0, line++, buf);
187
188 snprintf(buf, sizeof(buf), " PSR: %08lx ICR1: %08lx", GPIO2_PSR, GPIO2_ICR1);
189 lcd_puts(0, line++, buf);
190
191 snprintf(buf, sizeof(buf), " ICR2: %08lx IMR: %08lx", GPIO2_ICR2, GPIO2_IMR);
192 lcd_puts(0, line++, buf);
193
194 snprintf(buf, sizeof(buf), " ISR: %08lx", GPIO2_ISR);
195 lcd_puts(0, line++, buf); line++;
196
197 /* GPIO3 */
198 snprintf(buf, sizeof(buf), "GPIO3: DR: %08lx GDIR: %08lx", GPIO3_DR, GPIO3_GDIR);
199 lcd_puts(0, line++, buf);
200
201 snprintf(buf, sizeof(buf), " PSR: %08lx ICR1: %08lx", GPIO3_PSR, GPIO3_ICR1);
202 lcd_puts(0, line++, buf);
203
204 snprintf(buf, sizeof(buf), " ICR2: %08lx IMR: %08lx", GPIO3_ICR2, GPIO3_IMR);
205 lcd_puts(0, line++, buf);
206
207 snprintf(buf, sizeof(buf), " ISR: %08lx", GPIO3_ISR);
208 lcd_puts(0, line++, buf); line++;
209
Michael Sevakisa7af9e42008-04-12 16:56:45 +0000210 lcd_puts(0, line++, "PMIC Registers"); line++;
211
212 mc13783_read_regset(pmic_regset, pmic_regs, ARRAYLEN(pmic_regs));
213
214 for (i = 0; i < (int)ARRAYLEN(pmic_regs); i++)
215 {
216 snprintf(buf, sizeof(buf), "%s: %08lx", pmic_regnames[i], pmic_regs[i]);
217 lcd_puts(0, line++, buf);
218 }
219
Michael Sevakisb12c69b2008-04-13 20:03:08 +0000220 line++;
221
222 lcd_puts(0, line++, "ADC"); line++;
223
224 for (i = 0; i < NUM_ADC_CHANNELS; i += 4)
225 {
226 snprintf(buf, sizeof(buf),
227 "CH%02d:%04u CH%02d:%04u CH%02d:%04u CH%02d:%04u",
228 i+0, adc_read(i+0),
229 i+1, adc_read(i+1),
230 i+2, adc_read(i+2),
231 i+3, adc_read(i+3));
232 lcd_puts(0, line++, buf);
233 }
234
Michael Sevakis57742e02008-04-11 15:49:48 +0000235 lcd_update();
236 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
237 return false;
238 }
239}