blob: e5b62e9f4acff75c65a192877c207b5f728d9cb7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroy069fa832017-07-06 10:23:22 +02002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Christophe Leroy069fa832017-07-06 10:23:22 +02005 */
6
7/*
8 * MPC8xx Internal Memory Map Functions
9 */
10
11#include <common.h>
12#include <command.h>
13
Christophe Leroyb3510fb2018-03-16 17:20:41 +010014#include <asm/immap_8xx.h>
Christophe Leroy10ff63a2018-03-16 17:20:43 +010015#include <asm/cpm_8xx.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020016#include <asm/iopin_8xx.h>
Christophe Leroy394f9b32017-07-06 10:33:13 +020017#include <asm/io.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020018
19DECLARE_GLOBAL_DATA_PTR;
20
Simon Glassed38aef2020-05-10 11:40:03 -060021static int do_siuinfo(struct cmd_tbl *cmdtp, int flag, int argc,
22 char *const argv[])
Christophe Leroy069fa832017-07-06 10:23:22 +020023{
Christophe Leroy394f9b32017-07-06 10:33:13 +020024 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
25 sysconf8xx_t __iomem *sc = &immap->im_siu_conf;
Christophe Leroy069fa832017-07-06 10:23:22 +020026
Christophe Leroy394f9b32017-07-06 10:33:13 +020027 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));
Christophe Leroy069fa832017-07-06 10:23:22 +020036 return 0;
37}
38
Simon Glassed38aef2020-05-10 11:40:03 -060039static int do_memcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
40 char *const argv[])
Christophe Leroy069fa832017-07-06 10:23:22 +020041{
Christophe Leroy394f9b32017-07-06 10:33:13 +020042 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
43 memctl8xx_t __iomem *memctl = &immap->im_memctl;
Christophe Leroy069fa832017-07-06 10:23:22 +020044 int nbanks = 8;
Christophe Leroy394f9b32017-07-06 10:33:13 +020045 uint __iomem *p = &memctl->memc_br0;
Christophe Leroy069fa832017-07-06 10:23:22 +020046 int i;
47
Christophe Leroy394f9b32017-07-06 10:33:13 +020048 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));
Christophe Leroy069fa832017-07-06 10:23:22 +020051
Christophe Leroy394f9b32017-07-06 10:33:13 +020052 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));
Christophe Leroy069fa832017-07-06 10:23:22 +020059 return 0;
60}
61
Simon Glassed38aef2020-05-10 11:40:03 -060062static int do_carinfo(struct cmd_tbl *cmdtp, int flag, int argc,
63 char *const argv[])
Christophe Leroy069fa832017-07-06 10:23:22 +020064{
Christophe Leroy394f9b32017-07-06 10:33:13 +020065 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
66 car8xx_t __iomem *car = &immap->im_clkrst;
Christophe Leroy069fa832017-07-06 10:23:22 +020067
Christophe Leroy394f9b32017-07-06 10:33:13 +020068 printf("SCCR = %08x\n", in_be32(&car->car_sccr));
69 printf("PLPRCR= %08x\n", in_be32(&car->car_plprcr));
70 printf("RSR = %08x\n", in_be32(&car->car_rsr));
Christophe Leroy069fa832017-07-06 10:23:22 +020071 return 0;
72}
73
74static int counter;
75
Christophe Leroy48f896d2017-07-06 10:33:17 +020076static void header(void)
Christophe Leroy069fa832017-07-06 10:23:22 +020077{
78 char *data = "\
79 -------------------------------- --------------------------------\
80 00000000001111111111222222222233 00000000001111111111222222222233\
81 01234567890123456789012345678901 01234567890123456789012345678901\
82 -------------------------------- --------------------------------\
83 ";
84 int i;
85
86 if (counter % 2)
87 putc('\n');
88 counter = 0;
89
90 for (i = 0; i < 4; i++, data += 79)
91 printf("%.79s\n", data);
92}
93
Christophe Leroy48f896d2017-07-06 10:33:17 +020094static void binary(char *label, uint value, int nbits)
Christophe Leroy069fa832017-07-06 10:23:22 +020095{
96 uint mask = 1 << (nbits - 1);
97 int i, second = (counter++ % 2);
98
99 if (second)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200100 putc(' ');
101 puts(label);
Christophe Leroy069fa832017-07-06 10:23:22 +0200102 for (i = 32 + 1; i != nbits; i--)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200103 putc(' ');
Christophe Leroy069fa832017-07-06 10:23:22 +0200104
105 while (mask != 0) {
106 if (value & mask)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200107 putc('1');
Christophe Leroy069fa832017-07-06 10:23:22 +0200108 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200109 putc('0');
Christophe Leroy069fa832017-07-06 10:23:22 +0200110 mask >>= 1;
111 }
112
113 if (second)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200114 putc('\n');
Christophe Leroy069fa832017-07-06 10:23:22 +0200115}
116
117#define PA_NBITS 16
118#define PA_NB_ODR 8
119#define PB_NBITS 18
120#define PB_NB_ODR 16
121#define PC_NBITS 12
122#define PD_NBITS 13
123
Simon Glassed38aef2020-05-10 11:40:03 -0600124static int do_iopinfo(struct cmd_tbl *cmdtp, int flag, int argc,
125 char *const argv[])
Christophe Leroy069fa832017-07-06 10:23:22 +0200126{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200127 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
128 iop8xx_t __iomem *iop = &immap->im_ioport;
129 ushort __iomem *l, *r;
130 uint __iomem *R;
Christophe Leroy069fa832017-07-06 10:23:22 +0200131
132 counter = 0;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200133 header();
Christophe Leroy069fa832017-07-06 10:23:22 +0200134
135 /*
136 * Ports A & B
137 */
138
139 l = &iop->iop_padir;
140 R = &immap->im_cpm.cp_pbdir;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200141 binary("PA_DIR", in_be16(l++), PA_NBITS);
142 binary("PB_DIR", in_be32(R++), PB_NBITS);
143 binary("PA_PAR", in_be16(l++), PA_NBITS);
144 binary("PB_PAR", in_be32(R++), PB_NBITS);
145 binary("PA_ODR", in_be16(l++), PA_NB_ODR);
146 binary("PB_ODR", in_be32(R++), PB_NB_ODR);
147 binary("PA_DAT", in_be16(l++), PA_NBITS);
148 binary("PB_DAT", in_be32(R++), PB_NBITS);
Christophe Leroy069fa832017-07-06 10:23:22 +0200149
Christophe Leroy48f896d2017-07-06 10:33:17 +0200150 header();
Christophe Leroy069fa832017-07-06 10:23:22 +0200151
152 /*
153 * Ports C & D
154 */
155
156 l = &iop->iop_pcdir;
157 r = &iop->iop_pddir;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200158 binary("PC_DIR", in_be16(l++), PC_NBITS);
159 binary("PD_DIR", in_be16(r++), PD_NBITS);
160 binary("PC_PAR", in_be16(l++), PC_NBITS);
161 binary("PD_PAR", in_be16(r++), PD_NBITS);
162 binary("PC_SO ", in_be16(l++), PC_NBITS);
163 binary(" ", 0, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200164 r++;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200165 binary("PC_DAT", in_be16(l++), PC_NBITS);
166 binary("PD_DAT", in_be16(r++), PD_NBITS);
167 binary("PC_INT", in_be16(l++), PC_NBITS);
Christophe Leroy069fa832017-07-06 10:23:22 +0200168
Christophe Leroy48f896d2017-07-06 10:33:17 +0200169 header();
Christophe Leroy069fa832017-07-06 10:23:22 +0200170 return 0;
171}
172
173/*
174 * set the io pins
175 * this needs a clean up for smaller tighter code
176 * use *uint and set the address based on cmd + port
177 */
Simon Glassed38aef2020-05-10 11:40:03 -0600178static int do_iopset(struct cmd_tbl *cmdtp, int flag, int argc,
179 char *const argv[])
Christophe Leroy069fa832017-07-06 10:23:22 +0200180{
181 uint rcode = 0;
182 iopin_t iopin;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200183 static uint port;
184 static uint pin;
185 static uint value;
Christophe Leroy069fa832017-07-06 10:23:22 +0200186 static enum {
187 DIR,
188 PAR,
189 SOR,
190 ODR,
191 DAT,
192 INT
193 } cmd = DAT;
194
195 if (argc != 5) {
Christophe Leroy48f896d2017-07-06 10:33:17 +0200196 puts("iopset PORT PIN CMD VALUE\n");
Christophe Leroy069fa832017-07-06 10:23:22 +0200197 return 1;
198 }
199 port = argv[1][0] - 'A';
200 if (port > 3)
201 port -= 0x20;
202 if (port > 3)
203 rcode = 1;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200204 pin = simple_strtol(argv[2], NULL, 10);
Christophe Leroy069fa832017-07-06 10:23:22 +0200205 if (pin > 31)
206 rcode = 1;
207
208
209 switch (argv[3][0]) {
210 case 'd':
211 if (argv[3][1] == 'a')
212 cmd = DAT;
213 else if (argv[3][1] == 'i')
214 cmd = DIR;
215 else
216 rcode = 1;
217 break;
218 case 'p':
219 cmd = PAR;
220 break;
221 case 'o':
222 cmd = ODR;
223 break;
224 case 's':
225 cmd = SOR;
226 break;
227 case 'i':
228 cmd = INT;
229 break;
230 default:
Christophe Leroy48f896d2017-07-06 10:33:17 +0200231 printf("iopset: unknown command %s\n", argv[3]);
Christophe Leroy069fa832017-07-06 10:23:22 +0200232 rcode = 1;
233 }
234 if (argv[4][0] == '1')
235 value = 1;
236 else if (argv[4][0] == '0')
237 value = 0;
238 else
239 rcode = 1;
240 if (rcode == 0) {
241 iopin.port = port;
242 iopin.pin = pin;
243 iopin.flag = 0;
244 switch (cmd) {
245 case DIR:
246 if (value)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200247 iopin_set_out(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200248 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200249 iopin_set_in(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200250 break;
251 case PAR:
252 if (value)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200253 iopin_set_ded(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200254 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200255 iopin_set_gen(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200256 break;
257 case SOR:
258 if (value)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200259 iopin_set_opt2(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200260 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200261 iopin_set_opt1(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200262 break;
263 case ODR:
264 if (value)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200265 iopin_set_odr(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200266 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200267 iopin_set_act(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200268 break;
269 case DAT:
270 if (value)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200271 iopin_set_high(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200272 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200273 iopin_set_low(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200274 break;
275 case INT:
276 if (value)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200277 iopin_set_falledge(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200278 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200279 iopin_set_anyedge(&iopin);
Christophe Leroy069fa832017-07-06 10:23:22 +0200280 break;
281 }
Christophe Leroy069fa832017-07-06 10:23:22 +0200282 }
283 return rcode;
284}
285
Christophe Leroy48f896d2017-07-06 10:33:17 +0200286static void prbrg(int n, uint val)
Christophe Leroy069fa832017-07-06 10:23:22 +0200287{
288 uint extc = (val >> 14) & 3;
289 uint cd = (val & CPM_BRG_CD_MASK) >> 1;
290 uint div16 = (val & CPM_BRG_DIV16) != 0;
291
292 ulong clock = gd->cpu_clk;
293
Christophe Leroy48f896d2017-07-06 10:33:17 +0200294 printf("BRG%d:", n);
Christophe Leroy069fa832017-07-06 10:23:22 +0200295
296 if (val & CPM_BRG_RST)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200297 puts(" RESET");
Christophe Leroy069fa832017-07-06 10:23:22 +0200298 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200299 puts(" ");
Christophe Leroy069fa832017-07-06 10:23:22 +0200300
301 if (val & CPM_BRG_EN)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200302 puts(" ENABLED");
Christophe Leroy069fa832017-07-06 10:23:22 +0200303 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200304 puts(" DISABLED");
Christophe Leroy069fa832017-07-06 10:23:22 +0200305
Christophe Leroy48f896d2017-07-06 10:33:17 +0200306 printf(" EXTC=%d", extc);
Christophe Leroy069fa832017-07-06 10:23:22 +0200307
308 if (val & CPM_BRG_ATB)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200309 puts(" ATB");
Christophe Leroy069fa832017-07-06 10:23:22 +0200310 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200311 puts(" ");
Christophe Leroy069fa832017-07-06 10:23:22 +0200312
Christophe Leroy48f896d2017-07-06 10:33:17 +0200313 printf(" DIVIDER=%4d", cd);
Christophe Leroy069fa832017-07-06 10:23:22 +0200314 if (extc == 0 && cd != 0) {
315 uint baudrate;
316
317 if (div16)
318 baudrate = (clock / 16) / (cd + 1);
319 else
320 baudrate = clock / (cd + 1);
321
Christophe Leroy48f896d2017-07-06 10:33:17 +0200322 printf("=%6d bps", baudrate);
Christophe Leroy069fa832017-07-06 10:23:22 +0200323 } else {
Christophe Leroy48f896d2017-07-06 10:33:17 +0200324 puts(" ");
Christophe Leroy069fa832017-07-06 10:23:22 +0200325 }
326
327 if (val & CPM_BRG_DIV16)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200328 puts(" DIV16");
Christophe Leroy069fa832017-07-06 10:23:22 +0200329 else
Christophe Leroy48f896d2017-07-06 10:33:17 +0200330 puts(" ");
Christophe Leroy069fa832017-07-06 10:23:22 +0200331
Christophe Leroy48f896d2017-07-06 10:33:17 +0200332 putc('\n');
Christophe Leroy069fa832017-07-06 10:23:22 +0200333}
334
Simon Glassed38aef2020-05-10 11:40:03 -0600335static int do_brginfo(struct cmd_tbl *cmdtp, int flag, int argc,
336 char *const argv[])
Christophe Leroy069fa832017-07-06 10:23:22 +0200337{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200338 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
339 cpm8xx_t __iomem *cp = &immap->im_cpm;
340 uint __iomem *p = &cp->cp_brgc1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200341 int i = 1;
342
343 while (i <= 4)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200344 prbrg(i++, in_be32(p++));
Christophe Leroy069fa832017-07-06 10:23:22 +0200345
346 return 0;
347}
348
Christophe Leroyb4ebefa2018-03-16 17:20:57 +0100349#ifdef CONFIG_CMD_REGINFO
350void print_reginfo(void)
351{
352 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
353 sit8xx_t __iomem *timers = &immap->im_sit;
354
355 printf("\nSystem Configuration registers\n"
356 "\tIMMR\t0x%08X\n", get_immr());
357 do_siuinfo(NULL, 0, 0, NULL);
358
359 printf("Memory Controller Registers\n");
360 do_memcinfo(NULL, 0, 0, NULL);
361
362 printf("\nSystem Integration Timers\n");
363 printf("\tTBSCR\t0x%04X\tRTCSC\t0x%04X\n",
364 in_be16(&timers->sit_tbscr), in_be16(&timers->sit_rtcsc));
365 printf("\tPISCR\t0x%04X\n", in_be16(&timers->sit_piscr));
366}
367#endif
368
Christophe Leroy069fa832017-07-06 10:23:22 +0200369/***************************************************/
370
371U_BOOT_CMD(
372 siuinfo, 1, 1, do_siuinfo,
373 "print System Interface Unit (SIU) registers",
374 ""
375);
376
377U_BOOT_CMD(
378 memcinfo, 1, 1, do_memcinfo,
379 "print Memory Controller registers",
380 ""
381);
382
383U_BOOT_CMD(
384 carinfo, 1, 1, do_carinfo,
385 "print Clocks and Reset registers",
386 ""
387);
388
389U_BOOT_CMD(
390 iopinfo, 1, 1, do_iopinfo,
391 "print I/O Port registers",
392 ""
393);
394
395U_BOOT_CMD(
396 iopset, 5, 0, do_iopset,
397 "set I/O Port registers",
398 "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1"
399);
400
401U_BOOT_CMD(
402 brginfo, 1, 1, do_brginfo,
403 "print Baud Rate Generator (BRG) registers",
404 ""
405);