blob: 1beed1fa40f9a5c8ac9d126f975c80786bc7db73 [file] [log] [blame]
Christophe Leroy069fa832017-07-06 10:23:22 +02001/*
2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8/*
9 * MPC8xx Internal Memory Map Functions
10 */
11
12#include <common.h>
13#include <command.h>
14
15#if defined(CONFIG_8xx)
16
17#include <asm/8xx_immap.h>
18#include <commproc.h>
19#include <asm/iopin_8xx.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
23int
24do_siuinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
25{
26 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
27
28 volatile sysconf8xx_t *sc = &immap->im_siu_conf;
29
30 printf ("SIUMCR= %08x SYPCR = %08x\n", sc->sc_siumcr, sc->sc_sypcr);
31 printf ("SWT = %08x\n", sc->sc_swt);
32 printf ("SIPEND= %08x SIMASK= %08x\n", sc->sc_sipend, sc->sc_simask);
33 printf ("SIEL = %08x SIVEC = %08x\n", sc->sc_siel, sc->sc_sivec);
34 printf ("TESR = %08x SDCR = %08x\n", sc->sc_tesr, sc->sc_sdcr);
35 return 0;
36}
37
38int
39do_memcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
40{
41 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
42
43 volatile memctl8xx_t *memctl = &immap->im_memctl;
44 int nbanks = 8;
45 volatile uint *p = &memctl->memc_br0;
46 int i;
47
48 for (i = 0; i < nbanks; i++, p += 2) {
49 if (i < 10) {
50 printf ("BR%d = %08x OR%d = %08x\n",
51 i, p[0], i, p[1]);
52 } else {
53 printf ("BR%d = %08x OR%d = %08x\n",
54 i, p[0], i, p[1]);
55 }
56 }
57
58 printf ("MAR = %08x", memctl->memc_mar);
59 printf (" MCR = %08x\n", memctl->memc_mcr);
60 printf ("MAMR = %08x MBMR = %08x",
61 memctl->memc_mamr, memctl->memc_mbmr);
62 printf ("\nMSTAT = %04x\n", memctl->memc_mstat);
63 printf ("MPTPR = %04x MDR = %08x\n",
64 memctl->memc_mptpr, memctl->memc_mdr);
65 return 0;
66}
67
68int
69do_carinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
70{
71 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
72
73 volatile car8xx_t *car = &immap->im_clkrst;
74
75 printf ("SCCR = %08x\n", car->car_sccr);
76 printf ("PLPRCR= %08x\n", car->car_plprcr);
77 printf ("RSR = %08x\n", car->car_rsr);
78 return 0;
79}
80
81static int counter;
82
83static void
84header(void)
85{
86 char *data = "\
87 -------------------------------- --------------------------------\
88 00000000001111111111222222222233 00000000001111111111222222222233\
89 01234567890123456789012345678901 01234567890123456789012345678901\
90 -------------------------------- --------------------------------\
91 ";
92 int i;
93
94 if (counter % 2)
95 putc('\n');
96 counter = 0;
97
98 for (i = 0; i < 4; i++, data += 79)
99 printf("%.79s\n", data);
100}
101
102static void binary (char *label, uint value, int nbits)
103{
104 uint mask = 1 << (nbits - 1);
105 int i, second = (counter++ % 2);
106
107 if (second)
108 putc (' ');
109 puts (label);
110 for (i = 32 + 1; i != nbits; i--)
111 putc (' ');
112
113 while (mask != 0) {
114 if (value & mask)
115 putc ('1');
116 else
117 putc ('0');
118 mask >>= 1;
119 }
120
121 if (second)
122 putc ('\n');
123}
124
125#define PA_NBITS 16
126#define PA_NB_ODR 8
127#define PB_NBITS 18
128#define PB_NB_ODR 16
129#define PC_NBITS 12
130#define PD_NBITS 13
131
132int
133do_iopinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
134{
135 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
136
137 volatile iop8xx_t *iop = &immap->im_ioport;
138 volatile ushort *l, *r;
139 volatile uint *R;
140
141 counter = 0;
142 header ();
143
144 /*
145 * Ports A & B
146 */
147
148 l = &iop->iop_padir;
149 R = &immap->im_cpm.cp_pbdir;
150 binary ("PA_DIR", *l++, PA_NBITS);
151 binary ("PB_DIR", *R++, PB_NBITS);
152 binary ("PA_PAR", *l++, PA_NBITS);
153 binary ("PB_PAR", *R++, PB_NBITS);
154 binary ("PA_ODR", *l++, PA_NB_ODR);
155 binary ("PB_ODR", *R++, PB_NB_ODR);
156 binary ("PA_DAT", *l++, PA_NBITS);
157 binary ("PB_DAT", *R++, PB_NBITS);
158
159 header ();
160
161 /*
162 * Ports C & D
163 */
164
165 l = &iop->iop_pcdir;
166 r = &iop->iop_pddir;
167 binary ("PC_DIR", *l++, PC_NBITS);
168 binary ("PD_DIR", *r++, PD_NBITS);
169 binary ("PC_PAR", *l++, PC_NBITS);
170 binary ("PD_PAR", *r++, PD_NBITS);
171 binary ("PC_SO ", *l++, PC_NBITS);
172 binary (" ", 0, 0);
173 r++;
174 binary ("PC_DAT", *l++, PC_NBITS);
175 binary ("PD_DAT", *r++, PD_NBITS);
176 binary ("PC_INT", *l++, PC_NBITS);
177
178 header ();
179 return 0;
180}
181
182/*
183 * set the io pins
184 * this needs a clean up for smaller tighter code
185 * use *uint and set the address based on cmd + port
186 */
187int
188do_iopset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
189{
190 uint rcode = 0;
191 iopin_t iopin;
192 static uint port = 0;
193 static uint pin = 0;
194 static uint value = 0;
195 static enum {
196 DIR,
197 PAR,
198 SOR,
199 ODR,
200 DAT,
201 INT
202 } cmd = DAT;
203
204 if (argc != 5) {
205 puts ("iopset PORT PIN CMD VALUE\n");
206 return 1;
207 }
208 port = argv[1][0] - 'A';
209 if (port > 3)
210 port -= 0x20;
211 if (port > 3)
212 rcode = 1;
213 pin = simple_strtol (argv[2], NULL, 10);
214 if (pin > 31)
215 rcode = 1;
216
217
218 switch (argv[3][0]) {
219 case 'd':
220 if (argv[3][1] == 'a')
221 cmd = DAT;
222 else if (argv[3][1] == 'i')
223 cmd = DIR;
224 else
225 rcode = 1;
226 break;
227 case 'p':
228 cmd = PAR;
229 break;
230 case 'o':
231 cmd = ODR;
232 break;
233 case 's':
234 cmd = SOR;
235 break;
236 case 'i':
237 cmd = INT;
238 break;
239 default:
240 printf ("iopset: unknown command %s\n", argv[3]);
241 rcode = 1;
242 }
243 if (argv[4][0] == '1')
244 value = 1;
245 else if (argv[4][0] == '0')
246 value = 0;
247 else
248 rcode = 1;
249 if (rcode == 0) {
250 iopin.port = port;
251 iopin.pin = pin;
252 iopin.flag = 0;
253 switch (cmd) {
254 case DIR:
255 if (value)
256 iopin_set_out (&iopin);
257 else
258 iopin_set_in (&iopin);
259 break;
260 case PAR:
261 if (value)
262 iopin_set_ded (&iopin);
263 else
264 iopin_set_gen (&iopin);
265 break;
266 case SOR:
267 if (value)
268 iopin_set_opt2 (&iopin);
269 else
270 iopin_set_opt1 (&iopin);
271 break;
272 case ODR:
273 if (value)
274 iopin_set_odr (&iopin);
275 else
276 iopin_set_act (&iopin);
277 break;
278 case DAT:
279 if (value)
280 iopin_set_high (&iopin);
281 else
282 iopin_set_low (&iopin);
283 break;
284 case INT:
285 if (value)
286 iopin_set_falledge (&iopin);
287 else
288 iopin_set_anyedge (&iopin);
289 break;
290 }
291
292 }
293 return rcode;
294}
295
296static void prbrg (int n, uint val)
297{
298 uint extc = (val >> 14) & 3;
299 uint cd = (val & CPM_BRG_CD_MASK) >> 1;
300 uint div16 = (val & CPM_BRG_DIV16) != 0;
301
302 ulong clock = gd->cpu_clk;
303
304 printf ("BRG%d:", n);
305
306 if (val & CPM_BRG_RST)
307 puts (" RESET");
308 else
309 puts (" ");
310
311 if (val & CPM_BRG_EN)
312 puts (" ENABLED");
313 else
314 puts (" DISABLED");
315
316 printf (" EXTC=%d", extc);
317
318 if (val & CPM_BRG_ATB)
319 puts (" ATB");
320 else
321 puts (" ");
322
323 printf (" DIVIDER=%4d", cd);
324 if (extc == 0 && cd != 0) {
325 uint baudrate;
326
327 if (div16)
328 baudrate = (clock / 16) / (cd + 1);
329 else
330 baudrate = clock / (cd + 1);
331
332 printf ("=%6d bps", baudrate);
333 } else {
334 puts (" ");
335 }
336
337 if (val & CPM_BRG_DIV16)
338 puts (" DIV16");
339 else
340 puts (" ");
341
342 putc ('\n');
343}
344
345int
346do_brginfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
347{
348 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
349
350 volatile cpm8xx_t *cp = &immap->im_cpm;
351 volatile uint *p = &cp->cp_brgc1;
352 int i = 1;
353
354 while (i <= 4)
355 prbrg (i++, *p++);
356
357 return 0;
358}
359
360/***************************************************/
361
362U_BOOT_CMD(
363 siuinfo, 1, 1, do_siuinfo,
364 "print System Interface Unit (SIU) registers",
365 ""
366);
367
368U_BOOT_CMD(
369 memcinfo, 1, 1, do_memcinfo,
370 "print Memory Controller registers",
371 ""
372);
373
374U_BOOT_CMD(
375 carinfo, 1, 1, do_carinfo,
376 "print Clocks and Reset registers",
377 ""
378);
379
380U_BOOT_CMD(
381 iopinfo, 1, 1, do_iopinfo,
382 "print I/O Port registers",
383 ""
384);
385
386U_BOOT_CMD(
387 iopset, 5, 0, do_iopset,
388 "set I/O Port registers",
389 "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1"
390);
391
392U_BOOT_CMD(
393 brginfo, 1, 1, do_brginfo,
394 "print Baud Rate Generator (BRG) registers",
395 ""
396);
397#endif