]> git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_immap.c
Merge with /home/wd/git/u-boot/custodian/u-boot-mpc83xx
[people/ms/u-boot.git] / common / cmd_immap.c
1 /*
2 * (C) Copyright 2000-2003
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
31 #if (CONFIG_COMMANDS & CFG_CMD_IMMAP) && \
32 (defined(CONFIG_8xx) || defined(CONFIG_8260))
33
34 #if defined(CONFIG_8xx)
35 #include <asm/8xx_immap.h>
36 #include <commproc.h>
37 #include <asm/iopin_8xx.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
44 #if defined(CONFIG_8xx) || defined(CONFIG_8260)
45 DECLARE_GLOBAL_DATA_PTR;
46 #endif
47
48 static void
49 unimplemented ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
50 {
51 printf ("Sorry, but the '%s' command has not been implemented\n",
52 cmdtp->name);
53 }
54
55 int
56 do_siuinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
57 {
58 volatile immap_t *immap = (immap_t *) CFG_IMMR;
59
60 #if defined(CONFIG_8xx)
61 volatile sysconf8xx_t *sc = &immap->im_siu_conf;
62 #elif defined(CONFIG_8260)
63 volatile sysconf8260_t *sc = &immap->im_siu_conf;
64 #endif
65
66 printf ("SIUMCR= %08x SYPCR = %08x\n", sc->sc_siumcr, sc->sc_sypcr);
67 #if defined(CONFIG_8xx)
68 printf ("SWT = %08x\n", sc->sc_swt);
69 printf ("SIPEND= %08x SIMASK= %08x\n", sc->sc_sipend, sc->sc_simask);
70 printf ("SIEL = %08x SIVEC = %08x\n", sc->sc_siel, sc->sc_sivec);
71 printf ("TESR = %08x SDCR = %08x\n", sc->sc_tesr, sc->sc_sdcr);
72 #elif defined(CONFIG_8260)
73 printf ("BCR = %08x\n", sc->sc_bcr);
74 printf ("P_ACR = %02x P_ALRH= %08x P_ALRL= %08x\n",
75 sc->sc_ppc_acr, sc->sc_ppc_alrh, sc->sc_ppc_alrl);
76 printf ("L_ACR = %02x L_ALRH= %08x L_ALRL= %08x\n",
77 sc->sc_lcl_acr, sc->sc_lcl_alrh, sc->sc_lcl_alrl);
78 printf ("PTESR1= %08x PTESR2= %08x\n", sc->sc_tescr1, sc->sc_tescr2);
79 printf ("LTESR1= %08x LTESR2= %08x\n", sc->sc_ltescr1, sc->sc_ltescr2);
80 printf ("PDTEA = %08x PDTEM = %02x\n", sc->sc_pdtea, sc->sc_pdtem);
81 printf ("LDTEA = %08x LDTEM = %02x\n", sc->sc_ldtea, sc->sc_ldtem);
82 #endif
83 return 0;
84 }
85
86 int
87 do_memcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
88 {
89 volatile immap_t *immap = (immap_t *) CFG_IMMR;
90
91 #if defined(CONFIG_8xx)
92 volatile memctl8xx_t *memctl = &immap->im_memctl;
93 int nbanks = 8;
94 #elif defined(CONFIG_8260)
95 volatile memctl8260_t *memctl = &immap->im_memctl;
96 int nbanks = 12;
97 #endif
98 volatile uint *p = &memctl->memc_br0;
99 int i;
100
101 for (i = 0; i < nbanks; i++, p += 2) {
102 if (i < 10) {
103 printf ("BR%d = %08x OR%d = %08x\n",
104 i, p[0], i, p[1]);
105 } else {
106 printf ("BR%d = %08x OR%d = %08x\n",
107 i, p[0], i, p[1]);
108 }
109 }
110
111 printf ("MAR = %08x", memctl->memc_mar);
112 #if defined(CONFIG_8xx)
113 printf (" MCR = %08x\n", memctl->memc_mcr);
114 #elif defined(CONFIG_8260)
115 putc ('\n');
116 #endif
117 printf ("MAMR = %08x MBMR = %08x",
118 memctl->memc_mamr, memctl->memc_mbmr);
119 #if defined(CONFIG_8xx)
120 printf ("\nMSTAT = %04x\n", memctl->memc_mstat);
121 #elif defined(CONFIG_8260)
122 printf (" MCMR = %08x\n", memctl->memc_mcmr);
123 #endif
124 printf ("MPTPR = %04x MDR = %08x\n",
125 memctl->memc_mptpr, memctl->memc_mdr);
126 #if defined(CONFIG_8260)
127 printf ("PSDMR = %08x LSDMR = %08x\n",
128 memctl->memc_psdmr, memctl->memc_lsdmr);
129 printf ("PURT = %02x PSRT = %02x\n",
130 memctl->memc_purt, memctl->memc_psrt);
131 printf ("LURT = %02x LSRT = %02x\n",
132 memctl->memc_lurt, memctl->memc_lsrt);
133 printf ("IMMR = %08x\n", memctl->memc_immr);
134 #endif
135 return 0;
136 }
137
138 int
139 do_sitinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
140 {
141 unimplemented (cmdtp, flag, argc, argv);
142 return 0;
143 }
144
145 #ifdef CONFIG_8260
146 int
147 do_icinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
148 {
149 unimplemented (cmdtp, flag, argc, argv);
150 return 0;
151 }
152 #endif
153
154 int
155 do_carinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
156 {
157 volatile immap_t *immap = (immap_t *) CFG_IMMR;
158
159 #if defined(CONFIG_8xx)
160 volatile car8xx_t *car = &immap->im_clkrst;
161 #elif defined(CONFIG_8260)
162 volatile car8260_t *car = &immap->im_clkrst;
163 #endif
164
165 #if defined(CONFIG_8xx)
166 printf ("SCCR = %08x\n", car->car_sccr);
167 printf ("PLPRCR= %08x\n", car->car_plprcr);
168 printf ("RSR = %08x\n", car->car_rsr);
169 #elif defined(CONFIG_8260)
170 printf ("SCCR = %08x\n", car->car_sccr);
171 printf ("SCMR = %08x\n", car->car_scmr);
172 printf ("RSR = %08x\n", car->car_rsr);
173 printf ("RMR = %08x\n", car->car_rmr);
174 #endif
175 return 0;
176 }
177
178 static int counter;
179
180 static void
181 header(void)
182 {
183 char *data = "\
184 -------------------------------- --------------------------------\
185 00000000001111111111222222222233 00000000001111111111222222222233\
186 01234567890123456789012345678901 01234567890123456789012345678901\
187 -------------------------------- --------------------------------\
188 ";
189 int i;
190
191 if (counter % 2)
192 putc('\n');
193 counter = 0;
194
195 for (i = 0; i < 4; i++, data += 79)
196 printf("%.79s\n", data);
197 }
198
199 static void binary (char *label, uint value, int nbits)
200 {
201 uint mask = 1 << (nbits - 1);
202 int i, second = (counter++ % 2);
203
204 if (second)
205 putc (' ');
206 puts (label);
207 for (i = 32 + 1; i != nbits; i--)
208 putc (' ');
209
210 while (mask != 0) {
211 if (value & mask)
212 putc ('1');
213 else
214 putc ('0');
215 mask >>= 1;
216 }
217
218 if (second)
219 putc ('\n');
220 }
221
222 #if defined(CONFIG_8xx)
223 #define PA_NBITS 16
224 #define PA_NB_ODR 8
225 #define PB_NBITS 18
226 #define PB_NB_ODR 16
227 #define PC_NBITS 12
228 #define PD_NBITS 13
229 #elif defined(CONFIG_8260)
230 #define PA_NBITS 32
231 #define PA_NB_ODR 32
232 #define PB_NBITS 28
233 #define PB_NB_ODR 28
234 #define PC_NBITS 32
235 #define PD_NBITS 28
236 #endif
237
238 int
239 do_iopinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
240 {
241 volatile immap_t *immap = (immap_t *) CFG_IMMR;
242
243 #if defined(CONFIG_8xx)
244 volatile iop8xx_t *iop = &immap->im_ioport;
245 volatile ushort *l, *r;
246 #elif defined(CONFIG_8260)
247 volatile iop8260_t *iop = &immap->im_ioport;
248 volatile uint *l, *r;
249 #endif
250 volatile uint *R;
251
252 counter = 0;
253 header ();
254
255 /*
256 * Ports A & B
257 */
258
259 #if defined(CONFIG_8xx)
260 l = &iop->iop_padir;
261 R = &immap->im_cpm.cp_pbdir;
262 #elif defined(CONFIG_8260)
263 l = &iop->iop_pdira;
264 R = &iop->iop_pdirb;
265 #endif
266 binary ("PA_DIR", *l++, PA_NBITS);
267 binary ("PB_DIR", *R++, PB_NBITS);
268 binary ("PA_PAR", *l++, PA_NBITS);
269 binary ("PB_PAR", *R++, PB_NBITS);
270 #if defined(CONFIG_8260)
271 binary ("PA_SOR", *l++, PA_NBITS);
272 binary ("PB_SOR", *R++, PB_NBITS);
273 #endif
274 binary ("PA_ODR", *l++, PA_NB_ODR);
275 binary ("PB_ODR", *R++, PB_NB_ODR);
276 binary ("PA_DAT", *l++, PA_NBITS);
277 binary ("PB_DAT", *R++, PB_NBITS);
278
279 header ();
280
281 /*
282 * Ports C & D
283 */
284
285 #if defined(CONFIG_8xx)
286 l = &iop->iop_pcdir;
287 r = &iop->iop_pddir;
288 #elif defined(CONFIG_8260)
289 l = &iop->iop_pdirc;
290 r = &iop->iop_pdird;
291 #endif
292 binary ("PC_DIR", *l++, PC_NBITS);
293 binary ("PD_DIR", *r++, PD_NBITS);
294 binary ("PC_PAR", *l++, PC_NBITS);
295 binary ("PD_PAR", *r++, PD_NBITS);
296 #if defined(CONFIG_8xx)
297 binary ("PC_SO ", *l++, PC_NBITS);
298 binary (" ", 0, 0);
299 r++;
300 #elif defined(CONFIG_8260)
301 binary ("PC_SOR", *l++, PC_NBITS);
302 binary ("PD_SOR", *r++, PD_NBITS);
303 binary ("PC_ODR", *l++, PC_NBITS);
304 binary ("PD_ODR", *r++, PD_NBITS);
305 #endif
306 binary ("PC_DAT", *l++, PC_NBITS);
307 binary ("PD_DAT", *r++, PD_NBITS);
308 #if defined(CONFIG_8xx)
309 binary ("PC_INT", *l++, PC_NBITS);
310 #endif
311
312 header ();
313 return 0;
314 }
315
316 /*
317 * set the io pins
318 * this needs a clean up for smaller tighter code
319 * use *uint and set the address based on cmd + port
320 */
321 int
322 do_iopset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
323 {
324 uint rcode = 0;
325 iopin_t iopin;
326 static uint port = 0;
327 static uint pin = 0;
328 static uint value = 0;
329 static enum {
330 DIR,
331 PAR,
332 SOR,
333 ODR,
334 DAT,
335 #if defined(CONFIG_8xx)
336 INT
337 #endif
338 } cmd = DAT;
339
340 if (argc != 5) {
341 puts ("iopset PORT PIN CMD VALUE\n");
342 return 1;
343 }
344 port = argv[1][0] - 'A';
345 if (port > 3)
346 port -= 0x20;
347 if (port > 3)
348 rcode = 1;
349 pin = simple_strtol (argv[2], NULL, 10);
350 if (pin > 31)
351 rcode = 1;
352
353
354 switch (argv[3][0]) {
355 case 'd':
356 if (argv[3][1] == 'a')
357 cmd = DAT;
358 else if (argv[3][1] == 'i')
359 cmd = DIR;
360 else
361 rcode = 1;
362 break;
363 case 'p':
364 cmd = PAR;
365 break;
366 case 'o':
367 cmd = ODR;
368 break;
369 case 's':
370 cmd = SOR;
371 break;
372 #if defined(CONFIG_8xx)
373 case 'i':
374 cmd = INT;
375 break;
376 #endif
377 default:
378 printf ("iopset: unknown command %s\n", argv[3]);
379 rcode = 1;
380 }
381 if (argv[4][0] == '1')
382 value = 1;
383 else if (argv[4][0] == '0')
384 value = 0;
385 else
386 rcode = 1;
387 if (rcode == 0) {
388 iopin.port = port;
389 iopin.pin = pin;
390 iopin.flag = 0;
391 switch (cmd) {
392 case DIR:
393 if (value)
394 iopin_set_out (&iopin);
395 else
396 iopin_set_in (&iopin);
397 break;
398 case PAR:
399 if (value)
400 iopin_set_ded (&iopin);
401 else
402 iopin_set_gen (&iopin);
403 break;
404 case SOR:
405 if (value)
406 iopin_set_opt2 (&iopin);
407 else
408 iopin_set_opt1 (&iopin);
409 break;
410 case ODR:
411 if (value)
412 iopin_set_odr (&iopin);
413 else
414 iopin_set_act (&iopin);
415 break;
416 case DAT:
417 if (value)
418 iopin_set_high (&iopin);
419 else
420 iopin_set_low (&iopin);
421 break;
422 #if defined(CONFIG_8xx)
423 case INT:
424 if (value)
425 iopin_set_falledge (&iopin);
426 else
427 iopin_set_anyedge (&iopin);
428 break;
429 #endif
430 }
431
432 }
433 return rcode;
434 }
435
436 int
437 do_dmainfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
438 {
439 unimplemented (cmdtp, flag, argc, argv);
440 return 0;
441 }
442
443 int
444 do_fccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
445 {
446 unimplemented (cmdtp, flag, argc, argv);
447 return 0;
448 }
449
450 static void prbrg (int n, uint val)
451 {
452 uint extc = (val >> 14) & 3;
453 uint cd = (val & CPM_BRG_CD_MASK) >> 1;
454 uint div16 = (val & CPM_BRG_DIV16) != 0;
455
456 #if defined(CONFIG_8xx)
457 ulong clock = gd->cpu_clk;
458 #elif defined(CONFIG_8260)
459 ulong clock = gd->brg_clk;
460 #endif
461
462 printf ("BRG%d:", n);
463
464 if (val & CPM_BRG_RST)
465 puts (" RESET");
466 else
467 puts (" ");
468
469 if (val & CPM_BRG_EN)
470 puts (" ENABLED");
471 else
472 puts (" DISABLED");
473
474 printf (" EXTC=%d", extc);
475
476 if (val & CPM_BRG_ATB)
477 puts (" ATB");
478 else
479 puts (" ");
480
481 printf (" DIVIDER=%4d", cd);
482 if (extc == 0 && cd != 0) {
483 uint baudrate;
484
485 if (div16)
486 baudrate = (clock / 16) / (cd + 1);
487 else
488 baudrate = clock / (cd + 1);
489
490 printf ("=%6d bps", baudrate);
491 } else {
492 puts (" ");
493 }
494
495 if (val & CPM_BRG_DIV16)
496 puts (" DIV16");
497 else
498 puts (" ");
499
500 putc ('\n');
501 }
502
503 int
504 do_brginfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
505 {
506 volatile immap_t *immap = (immap_t *) CFG_IMMR;
507
508 #if defined(CONFIG_8xx)
509 volatile cpm8xx_t *cp = &immap->im_cpm;
510 volatile uint *p = &cp->cp_brgc1;
511 #elif defined(CONFIG_8260)
512 volatile uint *p = &immap->im_brgc1;
513 #endif
514 int i = 1;
515
516 while (i <= 4)
517 prbrg (i++, *p++);
518
519 #if defined(CONFIG_8260)
520 p = &immap->im_brgc5;
521 while (i <= 8)
522 prbrg (i++, *p++);
523 #endif
524 return 0;
525 }
526
527 int
528 do_i2cinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
529 {
530 volatile immap_t *immap = (immap_t *) CFG_IMMR;
531
532 #if defined(CONFIG_8xx)
533 volatile i2c8xx_t *i2c = &immap->im_i2c;
534 volatile cpm8xx_t *cp = &immap->im_cpm;
535 volatile iic_t *iip = (iic_t *) & cp->cp_dparam[PROFF_IIC];
536 #elif defined(CONFIG_8260)
537 volatile i2c8260_t *i2c = &immap->im_i2c;
538 volatile iic_t *iip;
539 uint dpaddr;
540
541 dpaddr = *((unsigned short *) (&immap->im_dprambase[PROFF_I2C_BASE]));
542 if (dpaddr == 0)
543 iip = NULL;
544 else
545 iip = (iic_t *) & immap->im_dprambase[dpaddr];
546 #endif
547
548 printf ("I2MOD = %02x I2ADD = %02x\n", i2c->i2c_i2mod, i2c->i2c_i2add);
549 printf ("I2BRG = %02x I2COM = %02x\n", i2c->i2c_i2brg, i2c->i2c_i2com);
550 printf ("I2CER = %02x I2CMR = %02x\n", i2c->i2c_i2cer, i2c->i2c_i2cmr);
551
552 if (iip == NULL)
553 puts ("i2c parameter ram not allocated\n");
554 else {
555 printf ("RBASE = %08x TBASE = %08x\n",
556 iip->iic_rbase, iip->iic_tbase);
557 printf ("RFCR = %02x TFCR = %02x\n",
558 iip->iic_rfcr, iip->iic_tfcr);
559 printf ("MRBLR = %04x\n", iip->iic_mrblr);
560 printf ("RSTATE= %08x RDP = %08x\n",
561 iip->iic_rstate, iip->iic_rdp);
562 printf ("RBPTR = %04x RBC = %04x\n",
563 iip->iic_rbptr, iip->iic_rbc);
564 printf ("RXTMP = %08x\n", iip->iic_rxtmp);
565 printf ("TSTATE= %08x TDP = %08x\n",
566 iip->iic_tstate, iip->iic_tdp);
567 printf ("TBPTR = %04x TBC = %04x\n",
568 iip->iic_tbptr, iip->iic_tbc);
569 printf ("TXTMP = %08x\n", iip->iic_txtmp);
570 }
571 return 0;
572 }
573
574 int
575 do_sccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
576 {
577 unimplemented (cmdtp, flag, argc, argv);
578 return 0;
579 }
580
581 int
582 do_smcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
583 {
584 unimplemented (cmdtp, flag, argc, argv);
585 return 0;
586 }
587
588 int
589 do_spiinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
590 {
591 unimplemented (cmdtp, flag, argc, argv);
592 return 0;
593 }
594
595 int
596 do_muxinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
597 {
598 unimplemented (cmdtp, flag, argc, argv);
599 return 0;
600 }
601
602 int
603 do_siinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
604 {
605 unimplemented (cmdtp, flag, argc, argv);
606 return 0;
607 }
608
609 int
610 do_mccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
611 {
612 unimplemented (cmdtp, flag, argc, argv);
613 return 0;
614 }
615
616 /***************************************************/
617
618 U_BOOT_CMD(
619 siuinfo, 1, 1, do_siuinfo,
620 "siuinfo - print System Interface Unit (SIU) registers\n",
621 NULL
622 );
623
624 U_BOOT_CMD(
625 memcinfo, 1, 1, do_memcinfo,
626 "memcinfo- print Memory Controller registers\n",
627 NULL
628 );
629
630 U_BOOT_CMD(
631 sitinfo, 1, 1, do_sitinfo,
632 "sitinfo - print System Integration Timers (SIT) registers\n",
633 NULL
634 );
635
636 #ifdef CONFIG_8260
637 U_BOOT_CMD(
638 icinfo, 1, 1, do_icinfo,
639 "icinfo - print Interrupt Controller registers\n",
640 NULL
641 );
642 #endif
643
644 U_BOOT_CMD(
645 carinfo, 1, 1, do_carinfo,
646 "carinfo - print Clocks and Reset registers\n",
647 NULL
648 );
649
650 U_BOOT_CMD(
651 iopinfo, 1, 1, do_iopinfo,
652 "iopinfo - print I/O Port registers\n",
653 NULL
654 );
655
656 U_BOOT_CMD(
657 iopset, 5, 0, do_iopset,
658 "iopset - set I/O Port registers\n",
659 "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1"
660 );
661
662 U_BOOT_CMD(
663 dmainfo, 1, 1, do_dmainfo,
664 "dmainfo - print SDMA/IDMA registers\n",
665 NULL
666 );
667
668 U_BOOT_CMD(
669 fccinfo, 1, 1, do_fccinfo,
670 "fccinfo - print FCC registers\n",
671 NULL
672 );
673
674 U_BOOT_CMD(
675 brginfo, 1, 1, do_brginfo,
676 "brginfo - print Baud Rate Generator (BRG) registers\n",
677 NULL
678 );
679
680 U_BOOT_CMD(
681 i2cinfo, 1, 1, do_i2cinfo,
682 "i2cinfo - print I2C registers\n",
683 NULL
684 );
685
686 U_BOOT_CMD(
687 sccinfo, 1, 1, do_sccinfo,
688 "sccinfo - print SCC registers\n",
689 NULL
690 );
691
692 U_BOOT_CMD(
693 smcinfo, 1, 1, do_smcinfo,
694 "smcinfo - print SMC registers\n",
695 NULL
696 );
697
698 U_BOOT_CMD(
699 spiinfo, 1, 1, do_spiinfo,
700 "spiinfo - print Serial Peripheral Interface (SPI) registers\n",
701 NULL
702 );
703
704 U_BOOT_CMD(
705 muxinfo, 1, 1, do_muxinfo,
706 "muxinfo - print CPM Multiplexing registers\n",
707 NULL
708 );
709
710 U_BOOT_CMD(
711 siinfo, 1, 1, do_siinfo,
712 "siinfo - print Serial Interface (SI) registers\n",
713 NULL
714 );
715
716 U_BOOT_CMD(
717 mccinfo, 1, 1, do_mccinfo,
718 "mccinfo - print MCC registers\n",
719 NULL
720 );
721
722
723 #endif /* CFG_CMD_IMMAP && (CONFIG_8xx || CONFIG_8260) */