1 /* 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 15 #include <asm/8xx_immap.h> 16 #include <commproc.h> 17 #include <asm/iopin_8xx.h> 18 19 DECLARE_GLOBAL_DATA_PTR; 20 21 int 22 do_siuinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 23 { 24 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 25 26 volatile sysconf8xx_t *sc = &immap->im_siu_conf; 27 28 printf ("SIUMCR= %08x SYPCR = %08x\n", sc->sc_siumcr, sc->sc_sypcr); 29 printf ("SWT = %08x\n", sc->sc_swt); 30 printf ("SIPEND= %08x SIMASK= %08x\n", sc->sc_sipend, sc->sc_simask); 31 printf ("SIEL = %08x SIVEC = %08x\n", sc->sc_siel, sc->sc_sivec); 32 printf ("TESR = %08x SDCR = %08x\n", sc->sc_tesr, sc->sc_sdcr); 33 return 0; 34 } 35 36 int 37 do_memcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 38 { 39 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 40 41 volatile memctl8xx_t *memctl = &immap->im_memctl; 42 int nbanks = 8; 43 volatile uint *p = &memctl->memc_br0; 44 int i; 45 46 for (i = 0; i < nbanks; i++, p += 2) { 47 if (i < 10) { 48 printf ("BR%d = %08x OR%d = %08x\n", 49 i, p[0], i, p[1]); 50 } else { 51 printf ("BR%d = %08x OR%d = %08x\n", 52 i, p[0], i, p[1]); 53 } 54 } 55 56 printf ("MAR = %08x", memctl->memc_mar); 57 printf (" MCR = %08x\n", memctl->memc_mcr); 58 printf ("MAMR = %08x MBMR = %08x", 59 memctl->memc_mamr, memctl->memc_mbmr); 60 printf ("\nMSTAT = %04x\n", memctl->memc_mstat); 61 printf ("MPTPR = %04x MDR = %08x\n", 62 memctl->memc_mptpr, memctl->memc_mdr); 63 return 0; 64 } 65 66 int 67 do_carinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 68 { 69 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 70 71 volatile car8xx_t *car = &immap->im_clkrst; 72 73 printf ("SCCR = %08x\n", car->car_sccr); 74 printf ("PLPRCR= %08x\n", car->car_plprcr); 75 printf ("RSR = %08x\n", car->car_rsr); 76 return 0; 77 } 78 79 static int counter; 80 81 static void 82 header(void) 83 { 84 char *data = "\ 85 -------------------------------- --------------------------------\ 86 00000000001111111111222222222233 00000000001111111111222222222233\ 87 01234567890123456789012345678901 01234567890123456789012345678901\ 88 -------------------------------- --------------------------------\ 89 "; 90 int i; 91 92 if (counter % 2) 93 putc('\n'); 94 counter = 0; 95 96 for (i = 0; i < 4; i++, data += 79) 97 printf("%.79s\n", data); 98 } 99 100 static void binary (char *label, uint value, int nbits) 101 { 102 uint mask = 1 << (nbits - 1); 103 int i, second = (counter++ % 2); 104 105 if (second) 106 putc (' '); 107 puts (label); 108 for (i = 32 + 1; i != nbits; i--) 109 putc (' '); 110 111 while (mask != 0) { 112 if (value & mask) 113 putc ('1'); 114 else 115 putc ('0'); 116 mask >>= 1; 117 } 118 119 if (second) 120 putc ('\n'); 121 } 122 123 #define PA_NBITS 16 124 #define PA_NB_ODR 8 125 #define PB_NBITS 18 126 #define PB_NB_ODR 16 127 #define PC_NBITS 12 128 #define PD_NBITS 13 129 130 int 131 do_iopinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 132 { 133 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 134 135 volatile iop8xx_t *iop = &immap->im_ioport; 136 volatile ushort *l, *r; 137 volatile uint *R; 138 139 counter = 0; 140 header (); 141 142 /* 143 * Ports A & B 144 */ 145 146 l = &iop->iop_padir; 147 R = &immap->im_cpm.cp_pbdir; 148 binary ("PA_DIR", *l++, PA_NBITS); 149 binary ("PB_DIR", *R++, PB_NBITS); 150 binary ("PA_PAR", *l++, PA_NBITS); 151 binary ("PB_PAR", *R++, PB_NBITS); 152 binary ("PA_ODR", *l++, PA_NB_ODR); 153 binary ("PB_ODR", *R++, PB_NB_ODR); 154 binary ("PA_DAT", *l++, PA_NBITS); 155 binary ("PB_DAT", *R++, PB_NBITS); 156 157 header (); 158 159 /* 160 * Ports C & D 161 */ 162 163 l = &iop->iop_pcdir; 164 r = &iop->iop_pddir; 165 binary ("PC_DIR", *l++, PC_NBITS); 166 binary ("PD_DIR", *r++, PD_NBITS); 167 binary ("PC_PAR", *l++, PC_NBITS); 168 binary ("PD_PAR", *r++, PD_NBITS); 169 binary ("PC_SO ", *l++, PC_NBITS); 170 binary (" ", 0, 0); 171 r++; 172 binary ("PC_DAT", *l++, PC_NBITS); 173 binary ("PD_DAT", *r++, PD_NBITS); 174 binary ("PC_INT", *l++, PC_NBITS); 175 176 header (); 177 return 0; 178 } 179 180 /* 181 * set the io pins 182 * this needs a clean up for smaller tighter code 183 * use *uint and set the address based on cmd + port 184 */ 185 int 186 do_iopset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 187 { 188 uint rcode = 0; 189 iopin_t iopin; 190 static uint port = 0; 191 static uint pin = 0; 192 static uint value = 0; 193 static enum { 194 DIR, 195 PAR, 196 SOR, 197 ODR, 198 DAT, 199 INT 200 } cmd = DAT; 201 202 if (argc != 5) { 203 puts ("iopset PORT PIN CMD VALUE\n"); 204 return 1; 205 } 206 port = argv[1][0] - 'A'; 207 if (port > 3) 208 port -= 0x20; 209 if (port > 3) 210 rcode = 1; 211 pin = simple_strtol (argv[2], NULL, 10); 212 if (pin > 31) 213 rcode = 1; 214 215 216 switch (argv[3][0]) { 217 case 'd': 218 if (argv[3][1] == 'a') 219 cmd = DAT; 220 else if (argv[3][1] == 'i') 221 cmd = DIR; 222 else 223 rcode = 1; 224 break; 225 case 'p': 226 cmd = PAR; 227 break; 228 case 'o': 229 cmd = ODR; 230 break; 231 case 's': 232 cmd = SOR; 233 break; 234 case 'i': 235 cmd = INT; 236 break; 237 default: 238 printf ("iopset: unknown command %s\n", argv[3]); 239 rcode = 1; 240 } 241 if (argv[4][0] == '1') 242 value = 1; 243 else if (argv[4][0] == '0') 244 value = 0; 245 else 246 rcode = 1; 247 if (rcode == 0) { 248 iopin.port = port; 249 iopin.pin = pin; 250 iopin.flag = 0; 251 switch (cmd) { 252 case DIR: 253 if (value) 254 iopin_set_out (&iopin); 255 else 256 iopin_set_in (&iopin); 257 break; 258 case PAR: 259 if (value) 260 iopin_set_ded (&iopin); 261 else 262 iopin_set_gen (&iopin); 263 break; 264 case SOR: 265 if (value) 266 iopin_set_opt2 (&iopin); 267 else 268 iopin_set_opt1 (&iopin); 269 break; 270 case ODR: 271 if (value) 272 iopin_set_odr (&iopin); 273 else 274 iopin_set_act (&iopin); 275 break; 276 case DAT: 277 if (value) 278 iopin_set_high (&iopin); 279 else 280 iopin_set_low (&iopin); 281 break; 282 case INT: 283 if (value) 284 iopin_set_falledge (&iopin); 285 else 286 iopin_set_anyedge (&iopin); 287 break; 288 } 289 290 } 291 return rcode; 292 } 293 294 static void prbrg (int n, uint val) 295 { 296 uint extc = (val >> 14) & 3; 297 uint cd = (val & CPM_BRG_CD_MASK) >> 1; 298 uint div16 = (val & CPM_BRG_DIV16) != 0; 299 300 ulong clock = gd->cpu_clk; 301 302 printf ("BRG%d:", n); 303 304 if (val & CPM_BRG_RST) 305 puts (" RESET"); 306 else 307 puts (" "); 308 309 if (val & CPM_BRG_EN) 310 puts (" ENABLED"); 311 else 312 puts (" DISABLED"); 313 314 printf (" EXTC=%d", extc); 315 316 if (val & CPM_BRG_ATB) 317 puts (" ATB"); 318 else 319 puts (" "); 320 321 printf (" DIVIDER=%4d", cd); 322 if (extc == 0 && cd != 0) { 323 uint baudrate; 324 325 if (div16) 326 baudrate = (clock / 16) / (cd + 1); 327 else 328 baudrate = clock / (cd + 1); 329 330 printf ("=%6d bps", baudrate); 331 } else { 332 puts (" "); 333 } 334 335 if (val & CPM_BRG_DIV16) 336 puts (" DIV16"); 337 else 338 puts (" "); 339 340 putc ('\n'); 341 } 342 343 int 344 do_brginfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 345 { 346 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 347 348 volatile cpm8xx_t *cp = &immap->im_cpm; 349 volatile uint *p = &cp->cp_brgc1; 350 int i = 1; 351 352 while (i <= 4) 353 prbrg (i++, *p++); 354 355 return 0; 356 } 357 358 /***************************************************/ 359 360 U_BOOT_CMD( 361 siuinfo, 1, 1, do_siuinfo, 362 "print System Interface Unit (SIU) registers", 363 "" 364 ); 365 366 U_BOOT_CMD( 367 memcinfo, 1, 1, do_memcinfo, 368 "print Memory Controller registers", 369 "" 370 ); 371 372 U_BOOT_CMD( 373 carinfo, 1, 1, do_carinfo, 374 "print Clocks and Reset registers", 375 "" 376 ); 377 378 U_BOOT_CMD( 379 iopinfo, 1, 1, do_iopinfo, 380 "print I/O Port registers", 381 "" 382 ); 383 384 U_BOOT_CMD( 385 iopset, 5, 0, do_iopset, 386 "set I/O Port registers", 387 "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1" 388 ); 389 390 U_BOOT_CMD( 391 brginfo, 1, 1, do_brginfo, 392 "print Baud Rate Generator (BRG) registers", 393 "" 394 ); 395