blob: 443335b2ce385138819f5bf5ca35947d97986580 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * MPC8xx/MPC8260 Internal Memory Map Functions
26 */
27
28#include <common.h>
29#include <command.h>
30#include <cmd_immap.h>
31
32#if (CONFIG_COMMANDS & CFG_CMD_IMMAP) && \
33 (defined(CONFIG_8xx) || defined(CONFIG_8260))
34
35#if defined(CONFIG_8xx)
36#include <asm/8xx_immap.h>
37#include <commproc.h>
38#elif defined(CONFIG_8260)
39#include <asm/immap_8260.h>
40#include <asm/cpm_8260.h>
41#include <asm/iopin_8260.h>
42#endif
43
44static void
45unimplemented ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
46{
47 printf ("Sorry, but the '%s' command has not been implemented\n",
48 cmdtp->name);
49}
50
51int
52do_siuinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
53{
54 volatile immap_t *immap = (immap_t *) CFG_IMMR;
55
56#if defined(CONFIG_8xx)
57 volatile sysconf8xx_t *sc = &immap->im_siu_conf;
58#elif defined(CONFIG_8260)
59 volatile sysconf8260_t *sc = &immap->im_siu_conf;
60#endif
61
62 printf ("SIUMCR= %08x SYPCR = %08x\n", sc->sc_siumcr, sc->sc_sypcr);
63#if defined(CONFIG_8xx)
64 printf ("SWT = %08x\n", sc->sc_swt);
65 printf ("SIPEND= %08x SIMASK= %08x\n", sc->sc_sipend, sc->sc_simask);
66 printf ("SIEL = %08x SIVEC = %08x\n", sc->sc_siel, sc->sc_sivec);
67 printf ("TESR = %08x SDCR = %08x\n", sc->sc_tesr, sc->sc_sdcr);
68#elif defined(CONFIG_8260)
69 printf ("BCR = %08x\n", sc->sc_bcr);
70 printf ("P_ACR = %02x P_ALRH= %08x P_ALRL= %08x\n",
71 sc->sc_ppc_acr, sc->sc_ppc_alrh, sc->sc_ppc_alrl);
72 printf ("L_ACR = %02x L_ALRH= %08x L_ALRL= %08x\n",
73 sc->sc_lcl_acr, sc->sc_lcl_alrh, sc->sc_lcl_alrl);
74 printf ("PTESR1= %08x PTESR2= %08x\n", sc->sc_tescr1, sc->sc_tescr2);
75 printf ("LTESR1= %08x LTESR2= %08x\n", sc->sc_ltescr1, sc->sc_ltescr2);
76 printf ("PDTEA = %08x PDTEM = %02x\n", sc->sc_pdtea, sc->sc_pdtem);
77 printf ("LDTEA = %08x LDTEM = %02x\n", sc->sc_ldtea, sc->sc_ldtem);
78#endif
79 return 0;
80}
81
82int
83do_memcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
84{
85 volatile immap_t *immap = (immap_t *) CFG_IMMR;
86
87#if defined(CONFIG_8xx)
88 volatile memctl8xx_t *memctl = &immap->im_memctl;
89 int nbanks = 8;
90#elif defined(CONFIG_8260)
91 volatile memctl8260_t *memctl = &immap->im_memctl;
92 int nbanks = 12;
93#endif
94 volatile uint *p = &memctl->memc_br0;
95 int i;
96
97 for (i = 0; i < nbanks; i++, p += 2) {
98 if (i < 10) {
99 printf ("BR%d = %08x OR%d = %08x\n",
100 i, p[0], i, p[1]);
101 } else {
102 printf ("BR%d = %08x OR%d = %08x\n",
103 i, p[0], i, p[1]);
104 }
105 }
106
107 printf ("MAR = %08x", memctl->memc_mar);
108#if defined(CONFIG_8xx)
109 printf (" MCR = %08x\n", memctl->memc_mcr);
110#elif defined(CONFIG_8260)
111 printf ("\n");
112#endif
113 printf ("MAMR = %08x MBMR = %08x",
114 memctl->memc_mamr, memctl->memc_mbmr);
115#if defined(CONFIG_8xx)
116 printf ("\nMSTAT = %04x\n", memctl->memc_mstat);
117#elif defined(CONFIG_8260)
118 printf (" MCMR = %08x\n", memctl->memc_mcmr);
119#endif
120 printf ("MPTPR = %04x MDR = %08x\n",
121 memctl->memc_mptpr, memctl->memc_mdr);
122#if defined(CONFIG_8260)
123 printf ("PSDMR = %08x LSDMR = %08x\n",
124 memctl->memc_psdmr, memctl->memc_lsdmr);
125 printf ("PURT = %02x PSRT = %02x\n",
126 memctl->memc_purt, memctl->memc_psrt);
127 printf ("LURT = %02x LSRT = %02x\n",
128 memctl->memc_lurt, memctl->memc_lsrt);
129 printf ("IMMR = %08x\n", memctl->memc_immr);
130#endif
131 return 0;
132}
133
134int
135do_sitinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
136{
137 unimplemented (cmdtp, flag, argc, argv);
138 return 0;
139}
140
141#ifdef CONFIG_8260
142int
143do_icinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
144{
145 unimplemented (cmdtp, flag, argc, argv);
146 return 0;
147}
148#endif
149
150int
151do_carinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
152{
153 unimplemented (cmdtp, flag, argc, argv);
154 return 0;
155}
156
157static int counter;
158
159static void
160header(void)
161{
162 char *data = "\
163 -------------------------------- --------------------------------\
164 00000000001111111111222222222233 00000000001111111111222222222233\
165 01234567890123456789012345678901 01234567890123456789012345678901\
166 -------------------------------- --------------------------------\
167 ";
168 int i;
169
170 if (counter % 2)
171 putc('\n');
172 counter = 0;
173
174 for (i = 0; i < 4; i++, data += 79)
175 printf("%.79s\n", data);
176}
177
178static void binary (char *label, uint value, int nbits)
179{
180 uint mask = 1 << (nbits - 1);
181 int i, second = (counter++ % 2);
182
183 if (second)
184 putc (' ');
185 puts (label);
186 for (i = 32 + 1; i != nbits; i--)
187 putc (' ');
188
189 while (mask != 0) {
190 if (value & mask)
191 putc ('1');
192 else
193 putc ('0');
194 mask >>= 1;
195 }
196
197 if (second)
198 putc ('\n');
199}
200
201#if defined(CONFIG_8xx)
202#define PA_NBITS 16
203#define PA_NB_ODR 8
204#define PB_NBITS 18
205#define PB_NB_ODR 16
206#define PC_NBITS 12
207#define PD_NBITS 13
208#elif defined(CONFIG_8260)
209#define PA_NBITS 32
210#define PA_NB_ODR 32
211#define PB_NBITS 28
212#define PB_NB_ODR 28
213#define PC_NBITS 32
214#define PD_NBITS 28
215#endif
216
217int
218do_iopinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
219{
220 volatile immap_t *immap = (immap_t *) CFG_IMMR;
221
222#if defined(CONFIG_8xx)
223 volatile iop8xx_t *iop = &immap->im_ioport;
224 volatile ushort *l, *r;
225#elif defined(CONFIG_8260)
226 volatile iop8260_t *iop = &immap->im_ioport;
227 volatile uint *l, *r;
228#endif
229 volatile uint *R;
230
231 counter = 0;
232 header ();
233
234 /*
235 * Ports A & B
236 */
237
238#if defined(CONFIG_8xx)
239 l = &iop->iop_padir;
240 R = &immap->im_cpm.cp_pbdir;
241#elif defined(CONFIG_8260)
242 l = &iop->iop_pdira;
243 R = &iop->iop_pdirb;
244#endif
245 binary ("PA_DIR", *l++, PA_NBITS);
246 binary ("PB_DIR", *R++, PB_NBITS);
247 binary ("PA_PAR", *l++, PA_NBITS);
248 binary ("PB_PAR", *R++, PB_NBITS);
249#if defined(CONFIG_8260)
250 binary ("PA_SOR", *l++, PA_NBITS);
251 binary ("PB_SOR", *R++, PB_NBITS);
252#endif
253 binary ("PA_ODR", *l++, PA_NB_ODR);
254 binary ("PB_ODR", *R++, PB_NB_ODR);
255 binary ("PA_DAT", *l++, PA_NBITS);
256 binary ("PB_DAT", *R++, PB_NBITS);
257
258 header ();
259
260 /*
261 * Ports C & D
262 */
263
264#if defined(CONFIG_8xx)
265 l = &iop->iop_pcdir;
266 r = &iop->iop_pddir;
267#elif defined(CONFIG_8260)
268 l = &iop->iop_pdirc;
269 r = &iop->iop_pdird;
270#endif
271 binary ("PC_DIR", *l++, PC_NBITS);
272 binary ("PD_DIR", *r++, PD_NBITS);
273 binary ("PC_PAR", *l++, PC_NBITS);
274 binary ("PD_PAR", *r++, PD_NBITS);
275#if defined(CONFIG_8xx)
276 binary ("PC_SO ", *l++, PC_NBITS);
277 binary (" ", 0, 0);
278 r++;
279#elif defined(CONFIG_8260)
280 binary ("PC_SOR", *l++, PC_NBITS);
281 binary ("PD_SOR", *r++, PD_NBITS);
282 binary ("PC_ODR", *l++, PC_NBITS);
283 binary ("PD_ODR", *r++, PD_NBITS);
284#endif
285 binary ("PC_DAT", *l++, PC_NBITS);
286 binary ("PD_DAT", *r++, PD_NBITS);
287#if defined(CONFIG_8xx)
288 binary ("PC_INT", *l++, PC_NBITS);
289#endif
290
291 header ();
292 return 0;
293}
294
295/*
296 * set the io pins
297 * this needs a clean up for smaller tighter code
298 * use *uint and set the address based on cmd + port
299 */
300int
301do_iopset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
302{
303#if defined(CONFIG_8260)
304 uint rcode = 0;
305 static uint port = 0;
306 static uint pin = 0;
307 static uint value = 0;
308 static enum { DIR, PAR, SOR, ODR, DAT } cmd = DAT;
309 iopin_t iopin;
310
311 if (argc != 5) {
312 printf ("iopset PORT PIN CMD VALUE\n");
313 return 1;
314 }
315 port = argv[1][0] - 'A';
316 if (port > 3)
317 port -= 0x20;
318 if (port > 3)
319 rcode = 1;
320 pin = simple_strtol (argv[2], NULL, 10);
321 if (pin > 31)
322 rcode = 1;
323
324
325 switch (argv[3][0]) {
326 case 'd':
327 if (argv[3][1] == 'a')
328 cmd = DAT;
329 else if (argv[3][1] == 'i')
330 cmd = DIR;
331 else
332 rcode = 1;
333 break;
334 case 'p':
335 cmd = PAR;
336 break;
337 case 'o':
338 cmd = ODR;
339 break;
340 case 's':
341 cmd = SOR;
342 break;
343 default:
344 printf ("iopset: unknown command %s\n", argv[3]);
345 rcode = 1;
346 }
347 if (argv[4][0] == '1')
348 value = 1;
349 else if (argv[4][0] == '0')
350 value = 0;
351 else
352 rcode = 1;
353 if (rcode == 0) {
354 iopin.port = port;
355 iopin.pin = pin;
356 switch (cmd) {
357 case DIR:
358 if (value)
359 iopin_set_out (&iopin);
360 else
361 iopin_set_in (&iopin);
362 break;
363 case PAR:
364 if (value)
365 iopin_set_ded (&iopin);
366 else
367 iopin_set_gen (&iopin);
368 break;
369 case SOR:
370 if (value)
371 iopin_set_opt2 (&iopin);
372 else
373 iopin_set_opt1 (&iopin);
374 break;
375 case ODR:
376 if (value)
377 iopin_set_odr (&iopin);
378 else
379 iopin_set_act (&iopin);
380 break;
381 case DAT:
382 if (value)
383 iopin_set_high (&iopin);
384 else
385 iopin_set_low (&iopin);
386 break;
387 }
388
389 }
390 return rcode;
391#else
392 unimplemented (cmdtp, flag, argc, argv);
393 return 0;
394#endif
395}
396
397int
398do_dmainfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
399{
400 unimplemented (cmdtp, flag, argc, argv);
401 return 0;
402}
403
404int
405do_fccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
406{
407 unimplemented (cmdtp, flag, argc, argv);
408 return 0;
409}
410
411static void prbrg (int n, uint val)
412{
413 uint extc = (val >> 14) & 3;
414 uint cd = (val & CPM_BRG_CD_MASK) >> 1;
415 uint div16 = (val & CPM_BRG_DIV16) != 0;
416
417#if defined(CONFIG_8xx)
418 DECLARE_GLOBAL_DATA_PTR;
419 ulong clock = gd->cpu_clk;
420#elif defined(CONFIG_8260)
421 DECLARE_GLOBAL_DATA_PTR;
422 ulong clock = gd->brg_clk;
423#endif
424
425 printf ("BRG%d:", n);
426
427 if (val & CPM_BRG_RST)
428 puts (" RESET");
429 else
430 puts (" ");
431
432 if (val & CPM_BRG_EN)
433 puts (" ENABLED");
434 else
435 puts (" DISABLED");
436
437 printf (" EXTC=%d", extc);
438
439 if (val & CPM_BRG_ATB)
440 puts (" ATB");
441 else
442 puts (" ");
443
444 printf (" DIVIDER=%4d", cd);
445 if (extc == 0 && cd != 0) {
446 uint baudrate;
447
448 if (div16)
449 baudrate = (clock / 16) / (cd + 1);
450 else
451 baudrate = clock / (cd + 1);
452
453 printf ("=%6d bps", baudrate);
454 } else {
455 puts (" ");
456 }
457
458 if (val & CPM_BRG_DIV16)
459 puts (" DIV16");
460 else
461 puts (" ");
462
463 putc ('\n');
464}
465
466int
467do_brginfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
468{
469 volatile immap_t *immap = (immap_t *) CFG_IMMR;
470
471#if defined(CONFIG_8xx)
472 volatile cpm8xx_t *cp = &immap->im_cpm;
473 volatile uint *p = &cp->cp_brgc1;
474#elif defined(CONFIG_8260)
475 volatile uint *p = &immap->im_brgc1;
476#endif
477 int i = 1;
478
479 while (i <= 4)
480 prbrg (i++, *p++);
481
482#if defined(CONFIG_8260)
483 p = &immap->im_brgc5;
484 while (i <= 8)
485 prbrg (i++, *p++);
486#endif
487 return 0;
488}
489
490int
491do_i2cinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
492{
493 volatile immap_t *immap = (immap_t *) CFG_IMMR;
494
495#if defined(CONFIG_8xx)
496 volatile i2c8xx_t *i2c = &immap->im_i2c;
497 volatile cpm8xx_t *cp = &immap->im_cpm;
498 volatile iic_t *iip = (iic_t *) & cp->cp_dparam[PROFF_IIC];
499#elif defined(CONFIG_8260)
500 volatile i2c8260_t *i2c = &immap->im_i2c;
501 volatile iic_t *iip;
502 uint dpaddr;
503
504 dpaddr = *((unsigned short *) (&immap->im_dprambase[PROFF_I2C_BASE]));
505 if (dpaddr == 0)
506 iip = NULL;
507 else
508 iip = (iic_t *) & immap->im_dprambase[dpaddr];
509#endif
510
511 printf ("I2MOD = %02x I2ADD = %02x\n", i2c->i2c_i2mod, i2c->i2c_i2add);
512 printf ("I2BRG = %02x I2COM = %02x\n", i2c->i2c_i2brg, i2c->i2c_i2com);
513 printf ("I2CER = %02x I2CMR = %02x\n", i2c->i2c_i2cer, i2c->i2c_i2cmr);
514
515 if (iip == NULL)
516 printf ("i2c parameter ram not allocated\n");
517 else {
518 printf ("RBASE = %08x TBASE = %08x\n",
519 iip->iic_rbase, iip->iic_tbase);
520 printf ("RFCR = %02x TFCR = %02x\n",
521 iip->iic_rfcr, iip->iic_tfcr);
522 printf ("MRBLR = %04x\n", iip->iic_mrblr);
523 printf ("RSTATE= %08x RDP = %08x\n",
524 iip->iic_rstate, iip->iic_rdp);
525 printf ("RBPTR = %04x RBC = %04x\n",
526 iip->iic_rbptr, iip->iic_rbc);
527 printf ("RXTMP = %08x\n", iip->iic_rxtmp);
528 printf ("TSTATE= %08x TDP = %08x\n",
529 iip->iic_tstate, iip->iic_tdp);
530 printf ("TBPTR = %04x TBC = %04x\n",
531 iip->iic_tbptr, iip->iic_tbc);
532 printf ("TXTMP = %08x\n", iip->iic_txtmp);
533 }
534 return 0;
535}
536
537int
538do_sccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
539{
540 unimplemented (cmdtp, flag, argc, argv);
541 return 0;
542}
543
544int
545do_smcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
546{
547 unimplemented (cmdtp, flag, argc, argv);
548 return 0;
549}
550
551int
552do_spiinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
553{
554 unimplemented (cmdtp, flag, argc, argv);
555 return 0;
556}
557
558int
559do_muxinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
560{
561 unimplemented (cmdtp, flag, argc, argv);
562 return 0;
563}
564
565int
566do_siinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
567{
568 unimplemented (cmdtp, flag, argc, argv);
569 return 0;
570}
571
572int
573do_mccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
574{
575 unimplemented (cmdtp, flag, argc, argv);
576 return 0;
577}
578#endif /* CFG_CMD_IMMAP && (CONFIG_8xx || CONFIG_8260) */