blob: 2284979dd6539335f719861946824b23219dbad9 [file] [log] [blame]
Christophe Leroy907208c2017-07-06 10:23:22 +02001/*
2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8/*
9 * MPC8xx Internal Memory Map Functions
10 */
11
12#include <common.h>
13#include <command.h>
14
Christophe Leroy907208c2017-07-06 10:23:22 +020015#include <asm/8xx_immap.h>
16#include <commproc.h>
17#include <asm/iopin_8xx.h>
Christophe Leroyba3da732017-07-06 10:33:13 +020018#include <asm/io.h>
Christophe Leroy907208c2017-07-06 10:23:22 +020019
20DECLARE_GLOBAL_DATA_PTR;
21
Christophe Leroy08dd9882017-07-13 15:10:08 +020022static int do_siuinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Christophe Leroy907208c2017-07-06 10:23:22 +020023{
Christophe Leroyba3da732017-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 Leroy907208c2017-07-06 10:23:22 +020026
Christophe Leroyba3da732017-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 Leroy907208c2017-07-06 10:23:22 +020036 return 0;
37}
38
Christophe Leroy08dd9882017-07-13 15:10:08 +020039static int do_memcinfo(cmd_tbl_t *cmdtp, int flag, int argc,
40 char * const argv[])
Christophe Leroy907208c2017-07-06 10:23:22 +020041{
Christophe Leroyba3da732017-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 Leroy907208c2017-07-06 10:23:22 +020044 int nbanks = 8;
Christophe Leroyba3da732017-07-06 10:33:13 +020045 uint __iomem *p = &memctl->memc_br0;
Christophe Leroy907208c2017-07-06 10:23:22 +020046 int i;
47
Christophe Leroyba3da732017-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 Leroy907208c2017-07-06 10:23:22 +020051
Christophe Leroyba3da732017-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 Leroy907208c2017-07-06 10:23:22 +020059 return 0;
60}
61
Christophe Leroy08dd9882017-07-13 15:10:08 +020062static int do_carinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Christophe Leroy907208c2017-07-06 10:23:22 +020063{
Christophe Leroyba3da732017-07-06 10:33:13 +020064 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
65 car8xx_t __iomem *car = &immap->im_clkrst;
Christophe Leroy907208c2017-07-06 10:23:22 +020066
Christophe Leroyba3da732017-07-06 10:33:13 +020067 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));
Christophe Leroy907208c2017-07-06 10:23:22 +020070 return 0;
71}
72
73static int counter;
74
Christophe Leroy70fd0712017-07-06 10:33:17 +020075static void header(void)
Christophe Leroy907208c2017-07-06 10:23:22 +020076{
77 char *data = "\
78 -------------------------------- --------------------------------\
79 00000000001111111111222222222233 00000000001111111111222222222233\
80 01234567890123456789012345678901 01234567890123456789012345678901\
81 -------------------------------- --------------------------------\
82 ";
83 int i;
84
85 if (counter % 2)
86 putc('\n');
87 counter = 0;
88
89 for (i = 0; i < 4; i++, data += 79)
90 printf("%.79s\n", data);
91}
92
Christophe Leroy70fd0712017-07-06 10:33:17 +020093static void binary(char *label, uint value, int nbits)
Christophe Leroy907208c2017-07-06 10:23:22 +020094{
95 uint mask = 1 << (nbits - 1);
96 int i, second = (counter++ % 2);
97
98 if (second)
Christophe Leroy70fd0712017-07-06 10:33:17 +020099 putc(' ');
100 puts(label);
Christophe Leroy907208c2017-07-06 10:23:22 +0200101 for (i = 32 + 1; i != nbits; i--)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200102 putc(' ');
Christophe Leroy907208c2017-07-06 10:23:22 +0200103
104 while (mask != 0) {
105 if (value & mask)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200106 putc('1');
Christophe Leroy907208c2017-07-06 10:23:22 +0200107 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200108 putc('0');
Christophe Leroy907208c2017-07-06 10:23:22 +0200109 mask >>= 1;
110 }
111
112 if (second)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200113 putc('\n');
Christophe Leroy907208c2017-07-06 10:23:22 +0200114}
115
116#define PA_NBITS 16
117#define PA_NB_ODR 8
118#define PB_NBITS 18
119#define PB_NB_ODR 16
120#define PC_NBITS 12
121#define PD_NBITS 13
122
Christophe Leroy08dd9882017-07-13 15:10:08 +0200123static int do_iopinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Christophe Leroy907208c2017-07-06 10:23:22 +0200124{
Christophe Leroyba3da732017-07-06 10:33:13 +0200125 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
126 iop8xx_t __iomem *iop = &immap->im_ioport;
127 ushort __iomem *l, *r;
128 uint __iomem *R;
Christophe Leroy907208c2017-07-06 10:23:22 +0200129
130 counter = 0;
Christophe Leroy70fd0712017-07-06 10:33:17 +0200131 header();
Christophe Leroy907208c2017-07-06 10:23:22 +0200132
133 /*
134 * Ports A & B
135 */
136
137 l = &iop->iop_padir;
138 R = &immap->im_cpm.cp_pbdir;
Christophe Leroyba3da732017-07-06 10:33:13 +0200139 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);
Christophe Leroy907208c2017-07-06 10:23:22 +0200147
Christophe Leroy70fd0712017-07-06 10:33:17 +0200148 header();
Christophe Leroy907208c2017-07-06 10:23:22 +0200149
150 /*
151 * Ports C & D
152 */
153
154 l = &iop->iop_pcdir;
155 r = &iop->iop_pddir;
Christophe Leroyba3da732017-07-06 10:33:13 +0200156 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);
161 binary(" ", 0, 0);
Christophe Leroy907208c2017-07-06 10:23:22 +0200162 r++;
Christophe Leroyba3da732017-07-06 10:33:13 +0200163 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);
Christophe Leroy907208c2017-07-06 10:23:22 +0200166
Christophe Leroy70fd0712017-07-06 10:33:17 +0200167 header();
Christophe Leroy907208c2017-07-06 10:23:22 +0200168 return 0;
169}
170
171/*
172 * set the io pins
173 * this needs a clean up for smaller tighter code
174 * use *uint and set the address based on cmd + port
175 */
Christophe Leroy08dd9882017-07-13 15:10:08 +0200176static int do_iopset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Christophe Leroy907208c2017-07-06 10:23:22 +0200177{
178 uint rcode = 0;
179 iopin_t iopin;
Christophe Leroy70fd0712017-07-06 10:33:17 +0200180 static uint port;
181 static uint pin;
182 static uint value;
Christophe Leroy907208c2017-07-06 10:23:22 +0200183 static enum {
184 DIR,
185 PAR,
186 SOR,
187 ODR,
188 DAT,
189 INT
190 } cmd = DAT;
191
192 if (argc != 5) {
Christophe Leroy70fd0712017-07-06 10:33:17 +0200193 puts("iopset PORT PIN CMD VALUE\n");
Christophe Leroy907208c2017-07-06 10:23:22 +0200194 return 1;
195 }
196 port = argv[1][0] - 'A';
197 if (port > 3)
198 port -= 0x20;
199 if (port > 3)
200 rcode = 1;
Christophe Leroy70fd0712017-07-06 10:33:17 +0200201 pin = simple_strtol(argv[2], NULL, 10);
Christophe Leroy907208c2017-07-06 10:23:22 +0200202 if (pin > 31)
203 rcode = 1;
204
205
206 switch (argv[3][0]) {
207 case 'd':
208 if (argv[3][1] == 'a')
209 cmd = DAT;
210 else if (argv[3][1] == 'i')
211 cmd = DIR;
212 else
213 rcode = 1;
214 break;
215 case 'p':
216 cmd = PAR;
217 break;
218 case 'o':
219 cmd = ODR;
220 break;
221 case 's':
222 cmd = SOR;
223 break;
224 case 'i':
225 cmd = INT;
226 break;
227 default:
Christophe Leroy70fd0712017-07-06 10:33:17 +0200228 printf("iopset: unknown command %s\n", argv[3]);
Christophe Leroy907208c2017-07-06 10:23:22 +0200229 rcode = 1;
230 }
231 if (argv[4][0] == '1')
232 value = 1;
233 else if (argv[4][0] == '0')
234 value = 0;
235 else
236 rcode = 1;
237 if (rcode == 0) {
238 iopin.port = port;
239 iopin.pin = pin;
240 iopin.flag = 0;
241 switch (cmd) {
242 case DIR:
243 if (value)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200244 iopin_set_out(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200245 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200246 iopin_set_in(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200247 break;
248 case PAR:
249 if (value)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200250 iopin_set_ded(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200251 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200252 iopin_set_gen(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200253 break;
254 case SOR:
255 if (value)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200256 iopin_set_opt2(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200257 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200258 iopin_set_opt1(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200259 break;
260 case ODR:
261 if (value)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200262 iopin_set_odr(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200263 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200264 iopin_set_act(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200265 break;
266 case DAT:
267 if (value)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200268 iopin_set_high(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200269 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200270 iopin_set_low(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200271 break;
272 case INT:
273 if (value)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200274 iopin_set_falledge(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200275 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200276 iopin_set_anyedge(&iopin);
Christophe Leroy907208c2017-07-06 10:23:22 +0200277 break;
278 }
Christophe Leroy907208c2017-07-06 10:23:22 +0200279 }
280 return rcode;
281}
282
Christophe Leroy70fd0712017-07-06 10:33:17 +0200283static void prbrg(int n, uint val)
Christophe Leroy907208c2017-07-06 10:23:22 +0200284{
285 uint extc = (val >> 14) & 3;
286 uint cd = (val & CPM_BRG_CD_MASK) >> 1;
287 uint div16 = (val & CPM_BRG_DIV16) != 0;
288
289 ulong clock = gd->cpu_clk;
290
Christophe Leroy70fd0712017-07-06 10:33:17 +0200291 printf("BRG%d:", n);
Christophe Leroy907208c2017-07-06 10:23:22 +0200292
293 if (val & CPM_BRG_RST)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200294 puts(" RESET");
Christophe Leroy907208c2017-07-06 10:23:22 +0200295 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200296 puts(" ");
Christophe Leroy907208c2017-07-06 10:23:22 +0200297
298 if (val & CPM_BRG_EN)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200299 puts(" ENABLED");
Christophe Leroy907208c2017-07-06 10:23:22 +0200300 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200301 puts(" DISABLED");
Christophe Leroy907208c2017-07-06 10:23:22 +0200302
Christophe Leroy70fd0712017-07-06 10:33:17 +0200303 printf(" EXTC=%d", extc);
Christophe Leroy907208c2017-07-06 10:23:22 +0200304
305 if (val & CPM_BRG_ATB)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200306 puts(" ATB");
Christophe Leroy907208c2017-07-06 10:23:22 +0200307 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200308 puts(" ");
Christophe Leroy907208c2017-07-06 10:23:22 +0200309
Christophe Leroy70fd0712017-07-06 10:33:17 +0200310 printf(" DIVIDER=%4d", cd);
Christophe Leroy907208c2017-07-06 10:23:22 +0200311 if (extc == 0 && cd != 0) {
312 uint baudrate;
313
314 if (div16)
315 baudrate = (clock / 16) / (cd + 1);
316 else
317 baudrate = clock / (cd + 1);
318
Christophe Leroy70fd0712017-07-06 10:33:17 +0200319 printf("=%6d bps", baudrate);
Christophe Leroy907208c2017-07-06 10:23:22 +0200320 } else {
Christophe Leroy70fd0712017-07-06 10:33:17 +0200321 puts(" ");
Christophe Leroy907208c2017-07-06 10:23:22 +0200322 }
323
324 if (val & CPM_BRG_DIV16)
Christophe Leroy70fd0712017-07-06 10:33:17 +0200325 puts(" DIV16");
Christophe Leroy907208c2017-07-06 10:23:22 +0200326 else
Christophe Leroy70fd0712017-07-06 10:33:17 +0200327 puts(" ");
Christophe Leroy907208c2017-07-06 10:23:22 +0200328
Christophe Leroy70fd0712017-07-06 10:33:17 +0200329 putc('\n');
Christophe Leroy907208c2017-07-06 10:23:22 +0200330}
331
Christophe Leroy08dd9882017-07-13 15:10:08 +0200332static int do_brginfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Christophe Leroy907208c2017-07-06 10:23:22 +0200333{
Christophe Leroyba3da732017-07-06 10:33:13 +0200334 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;
Christophe Leroy907208c2017-07-06 10:23:22 +0200337 int i = 1;
338
339 while (i <= 4)
Christophe Leroyba3da732017-07-06 10:33:13 +0200340 prbrg(i++, in_be32(p++));
Christophe Leroy907208c2017-07-06 10:23:22 +0200341
342 return 0;
343}
344
345/***************************************************/
346
347U_BOOT_CMD(
348 siuinfo, 1, 1, do_siuinfo,
349 "print System Interface Unit (SIU) registers",
350 ""
351);
352
353U_BOOT_CMD(
354 memcinfo, 1, 1, do_memcinfo,
355 "print Memory Controller registers",
356 ""
357);
358
359U_BOOT_CMD(
360 carinfo, 1, 1, do_carinfo,
361 "print Clocks and Reset registers",
362 ""
363);
364
365U_BOOT_CMD(
366 iopinfo, 1, 1, do_iopinfo,
367 "print I/O Port registers",
368 ""
369);
370
371U_BOOT_CMD(
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"
375);
376
377U_BOOT_CMD(
378 brginfo, 1, 1, do_brginfo,
379 "print Baud Rate Generator (BRG) registers",
380 ""
381);