2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 * MPC8xx Internal Memory Map Functions
15 #include <asm/8xx_immap.h>
17 #include <asm/iopin_8xx.h>
20 DECLARE_GLOBAL_DATA_PTR;
22 static int do_siuinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
24 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
25 sysconf8xx_t __iomem *sc = &immap->im_siu_conf;
27 printf("SIUMCR= %08x SYPCR = %08x\n",
28 in_be32(&sc->sc_siumcr), in_be32(&sc->sc_sypcr));
29 printf("SWT = %08x\n", in_be32(&sc->sc_swt));
30 printf("SIPEND= %08x SIMASK= %08x\n",
31 in_be32(&sc->sc_sipend), in_be32(&sc->sc_simask));
32 printf("SIEL = %08x SIVEC = %08x\n",
33 in_be32(&sc->sc_siel), in_be32(&sc->sc_sivec));
34 printf("TESR = %08x SDCR = %08x\n",
35 in_be32(&sc->sc_tesr), in_be32(&sc->sc_sdcr));
39 static int do_memcinfo(cmd_tbl_t *cmdtp, int flag, int argc,
42 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
43 memctl8xx_t __iomem *memctl = &immap->im_memctl;
45 uint __iomem *p = &memctl->memc_br0;
48 for (i = 0; i < nbanks; i++, p += 2)
49 printf("BR%-2d = %08x OR%-2d = %08x\n",
50 i, in_be32(p), i, in_be32(p + 1));
52 printf("MAR = %08x", in_be32(&memctl->memc_mar));
53 printf(" MCR = %08x\n", in_be32(&memctl->memc_mcr));
54 printf("MAMR = %08x MBMR = %08x",
55 in_be32(&memctl->memc_mamr), in_be32(&memctl->memc_mbmr));
56 printf("\nMSTAT = %04x\n", in_be16(&memctl->memc_mstat));
57 printf("MPTPR = %04x MDR = %08x\n",
58 in_be16(&memctl->memc_mptpr), in_be32(&memctl->memc_mdr));
62 static int do_carinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
64 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
65 car8xx_t __iomem *car = &immap->im_clkrst;
67 printf("SCCR = %08x\n", in_be32(&car->car_sccr));
68 printf("PLPRCR= %08x\n", in_be32(&car->car_plprcr));
69 printf("RSR = %08x\n", in_be32(&car->car_rsr));
75 static void header(void)
78 -------------------------------- --------------------------------\
79 00000000001111111111222222222233 00000000001111111111222222222233\
80 01234567890123456789012345678901 01234567890123456789012345678901\
81 -------------------------------- --------------------------------\
89 for (i = 0; i < 4; i++, data += 79)
90 printf("%.79s\n", data);
93 static void binary(char *label, uint value, int nbits)
95 uint mask = 1 << (nbits - 1);
96 int i, second = (counter++ % 2);
101 for (i = 32 + 1; i != nbits; i--)
123 static int do_iopinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
125 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
126 iop8xx_t __iomem *iop = &immap->im_ioport;
127 ushort __iomem *l, *r;
138 R = &immap->im_cpm.cp_pbdir;
139 binary("PA_DIR", in_be16(l++), PA_NBITS);
140 binary("PB_DIR", in_be32(R++), PB_NBITS);
141 binary("PA_PAR", in_be16(l++), PA_NBITS);
142 binary("PB_PAR", in_be32(R++), PB_NBITS);
143 binary("PA_ODR", in_be16(l++), PA_NB_ODR);
144 binary("PB_ODR", in_be32(R++), PB_NB_ODR);
145 binary("PA_DAT", in_be16(l++), PA_NBITS);
146 binary("PB_DAT", in_be32(R++), PB_NBITS);
156 binary("PC_DIR", in_be16(l++), PC_NBITS);
157 binary("PD_DIR", in_be16(r++), PD_NBITS);
158 binary("PC_PAR", in_be16(l++), PC_NBITS);
159 binary("PD_PAR", in_be16(r++), PD_NBITS);
160 binary("PC_SO ", in_be16(l++), PC_NBITS);
163 binary("PC_DAT", in_be16(l++), PC_NBITS);
164 binary("PD_DAT", in_be16(r++), PD_NBITS);
165 binary("PC_INT", in_be16(l++), PC_NBITS);
173 * this needs a clean up for smaller tighter code
174 * use *uint and set the address based on cmd + port
176 static int do_iopset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
193 puts("iopset PORT PIN CMD VALUE\n");
196 port = argv[1][0] - 'A';
201 pin = simple_strtol(argv[2], NULL, 10);
206 switch (argv[3][0]) {
208 if (argv[3][1] == 'a')
210 else if (argv[3][1] == 'i')
228 printf("iopset: unknown command %s\n", argv[3]);
231 if (argv[4][0] == '1')
233 else if (argv[4][0] == '0')
244 iopin_set_out(&iopin);
246 iopin_set_in(&iopin);
250 iopin_set_ded(&iopin);
252 iopin_set_gen(&iopin);
256 iopin_set_opt2(&iopin);
258 iopin_set_opt1(&iopin);
262 iopin_set_odr(&iopin);
264 iopin_set_act(&iopin);
268 iopin_set_high(&iopin);
270 iopin_set_low(&iopin);
274 iopin_set_falledge(&iopin);
276 iopin_set_anyedge(&iopin);
283 static void prbrg(int n, uint val)
285 uint extc = (val >> 14) & 3;
286 uint cd = (val & CPM_BRG_CD_MASK) >> 1;
287 uint div16 = (val & CPM_BRG_DIV16) != 0;
289 ulong clock = gd->cpu_clk;
293 if (val & CPM_BRG_RST)
298 if (val & CPM_BRG_EN)
303 printf(" EXTC=%d", extc);
305 if (val & CPM_BRG_ATB)
310 printf(" DIVIDER=%4d", cd);
311 if (extc == 0 && cd != 0) {
315 baudrate = (clock / 16) / (cd + 1);
317 baudrate = clock / (cd + 1);
319 printf("=%6d bps", baudrate);
324 if (val & CPM_BRG_DIV16)
332 static int do_brginfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
334 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
335 cpm8xx_t __iomem *cp = &immap->im_cpm;
336 uint __iomem *p = &cp->cp_brgc1;
340 prbrg(i++, in_be32(p++));
345 /***************************************************/
348 siuinfo, 1, 1, do_siuinfo,
349 "print System Interface Unit (SIU) registers",
354 memcinfo, 1, 1, do_memcinfo,
355 "print Memory Controller registers",
360 carinfo, 1, 1, do_carinfo,
361 "print Clocks and Reset registers",
366 iopinfo, 1, 1, do_iopinfo,
367 "print I/O Port registers",
372 iopset, 5, 0, do_iopset,
373 "set I/O Port registers",
374 "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1"
378 brginfo, 1, 1, do_brginfo,
379 "print Baud Rate Generator (BRG) registers",