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 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 int do_memcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
41 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
42 memctl8xx_t __iomem *memctl = &immap->im_memctl;
44 uint __iomem *p = &memctl->memc_br0;
47 for (i = 0; i < nbanks; i++, p += 2)
48 printf("BR%-2d = %08x OR%-2d = %08x\n",
49 i, in_be32(p), i, in_be32(p + 1));
51 printf("MAR = %08x", in_be32(&memctl->memc_mar));
52 printf(" MCR = %08x\n", in_be32(&memctl->memc_mcr));
53 printf("MAMR = %08x MBMR = %08x",
54 in_be32(&memctl->memc_mamr), in_be32(&memctl->memc_mbmr));
55 printf("\nMSTAT = %04x\n", in_be16(&memctl->memc_mstat));
56 printf("MPTPR = %04x MDR = %08x\n",
57 in_be16(&memctl->memc_mptpr), in_be32(&memctl->memc_mdr));
61 int do_carinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
63 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
64 car8xx_t __iomem *car = &immap->im_clkrst;
66 printf("SCCR = %08x\n", in_be32(&car->car_sccr));
67 printf("PLPRCR= %08x\n", in_be32(&car->car_plprcr));
68 printf("RSR = %08x\n", in_be32(&car->car_rsr));
74 static void header(void)
77 -------------------------------- --------------------------------\
78 00000000001111111111222222222233 00000000001111111111222222222233\
79 01234567890123456789012345678901 01234567890123456789012345678901\
80 -------------------------------- --------------------------------\
88 for (i = 0; i < 4; i++, data += 79)
89 printf("%.79s\n", data);
92 static void binary(char *label, uint value, int nbits)
94 uint mask = 1 << (nbits - 1);
95 int i, second = (counter++ % 2);
100 for (i = 32 + 1; i != nbits; i--)
122 int do_iopinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
124 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
125 iop8xx_t __iomem *iop = &immap->im_ioport;
126 ushort __iomem *l, *r;
137 R = &immap->im_cpm.cp_pbdir;
138 binary("PA_DIR", in_be16(l++), PA_NBITS);
139 binary("PB_DIR", in_be32(R++), PB_NBITS);
140 binary("PA_PAR", in_be16(l++), PA_NBITS);
141 binary("PB_PAR", in_be32(R++), PB_NBITS);
142 binary("PA_ODR", in_be16(l++), PA_NB_ODR);
143 binary("PB_ODR", in_be32(R++), PB_NB_ODR);
144 binary("PA_DAT", in_be16(l++), PA_NBITS);
145 binary("PB_DAT", in_be32(R++), PB_NBITS);
155 binary("PC_DIR", in_be16(l++), PC_NBITS);
156 binary("PD_DIR", in_be16(r++), PD_NBITS);
157 binary("PC_PAR", in_be16(l++), PC_NBITS);
158 binary("PD_PAR", in_be16(r++), PD_NBITS);
159 binary("PC_SO ", in_be16(l++), PC_NBITS);
162 binary("PC_DAT", in_be16(l++), PC_NBITS);
163 binary("PD_DAT", in_be16(r++), PD_NBITS);
164 binary("PC_INT", in_be16(l++), PC_NBITS);
172 * this needs a clean up for smaller tighter code
173 * use *uint and set the address based on cmd + port
175 int do_iopset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
192 puts("iopset PORT PIN CMD VALUE\n");
195 port = argv[1][0] - 'A';
200 pin = simple_strtol(argv[2], NULL, 10);
205 switch (argv[3][0]) {
207 if (argv[3][1] == 'a')
209 else if (argv[3][1] == 'i')
227 printf("iopset: unknown command %s\n", argv[3]);
230 if (argv[4][0] == '1')
232 else if (argv[4][0] == '0')
243 iopin_set_out(&iopin);
245 iopin_set_in(&iopin);
249 iopin_set_ded(&iopin);
251 iopin_set_gen(&iopin);
255 iopin_set_opt2(&iopin);
257 iopin_set_opt1(&iopin);
261 iopin_set_odr(&iopin);
263 iopin_set_act(&iopin);
267 iopin_set_high(&iopin);
269 iopin_set_low(&iopin);
273 iopin_set_falledge(&iopin);
275 iopin_set_anyedge(&iopin);
282 static void prbrg(int n, uint val)
284 uint extc = (val >> 14) & 3;
285 uint cd = (val & CPM_BRG_CD_MASK) >> 1;
286 uint div16 = (val & CPM_BRG_DIV16) != 0;
288 ulong clock = gd->cpu_clk;
292 if (val & CPM_BRG_RST)
297 if (val & CPM_BRG_EN)
302 printf(" EXTC=%d", extc);
304 if (val & CPM_BRG_ATB)
309 printf(" DIVIDER=%4d", cd);
310 if (extc == 0 && cd != 0) {
314 baudrate = (clock / 16) / (cd + 1);
316 baudrate = clock / (cd + 1);
318 printf("=%6d bps", baudrate);
323 if (val & CPM_BRG_DIV16)
331 int do_brginfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
333 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
334 cpm8xx_t __iomem *cp = &immap->im_cpm;
335 uint __iomem *p = &cp->cp_brgc1;
339 prbrg(i++, in_be32(p++));
344 /***************************************************/
347 siuinfo, 1, 1, do_siuinfo,
348 "print System Interface Unit (SIU) registers",
353 memcinfo, 1, 1, do_memcinfo,
354 "print Memory Controller registers",
359 carinfo, 1, 1, do_carinfo,
360 "print Clocks and Reset registers",
365 iopinfo, 1, 1, do_iopinfo,
366 "print I/O Port registers",
371 iopset, 5, 0, do_iopset,
372 "set I/O Port registers",
373 "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1"
377 brginfo, 1, 1, do_brginfo,
378 "print Baud Rate Generator (BRG) registers",