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 #include <asm/io.h> 19 20 DECLARE_GLOBAL_DATA_PTR; 21 22 static int do_siuinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 23 { 24 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; 25 sysconf8xx_t __iomem *sc = &immap->im_siu_conf; 26 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)); 36 return 0; 37 } 38 39 static int do_memcinfo(cmd_tbl_t *cmdtp, int flag, int argc, 40 char * const argv[]) 41 { 42 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; 43 memctl8xx_t __iomem *memctl = &immap->im_memctl; 44 int nbanks = 8; 45 uint __iomem *p = &memctl->memc_br0; 46 int i; 47 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)); 51 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)); 59 return 0; 60 } 61 62 static int do_carinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 63 { 64 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; 65 car8xx_t __iomem *car = &immap->im_clkrst; 66 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)); 70 return 0; 71 } 72 73 static int counter; 74 75 static void header(void) 76 { 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 93 static void binary(char *label, uint value, int nbits) 94 { 95 uint mask = 1 << (nbits - 1); 96 int i, second = (counter++ % 2); 97 98 if (second) 99 putc(' '); 100 puts(label); 101 for (i = 32 + 1; i != nbits; i--) 102 putc(' '); 103 104 while (mask != 0) { 105 if (value & mask) 106 putc('1'); 107 else 108 putc('0'); 109 mask >>= 1; 110 } 111 112 if (second) 113 putc('\n'); 114 } 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 123 static int do_iopinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 124 { 125 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; 129 130 counter = 0; 131 header(); 132 133 /* 134 * Ports A & B 135 */ 136 137 l = &iop->iop_padir; 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); 147 148 header(); 149 150 /* 151 * Ports C & D 152 */ 153 154 l = &iop->iop_pcdir; 155 r = &iop->iop_pddir; 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); 161 binary(" ", 0, 0); 162 r++; 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); 166 167 header(); 168 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 */ 176 static int do_iopset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 177 { 178 uint rcode = 0; 179 iopin_t iopin; 180 static uint port; 181 static uint pin; 182 static uint value; 183 static enum { 184 DIR, 185 PAR, 186 SOR, 187 ODR, 188 DAT, 189 INT 190 } cmd = DAT; 191 192 if (argc != 5) { 193 puts("iopset PORT PIN CMD VALUE\n"); 194 return 1; 195 } 196 port = argv[1][0] - 'A'; 197 if (port > 3) 198 port -= 0x20; 199 if (port > 3) 200 rcode = 1; 201 pin = simple_strtol(argv[2], NULL, 10); 202 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: 228 printf("iopset: unknown command %s\n", argv[3]); 229 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) 244 iopin_set_out(&iopin); 245 else 246 iopin_set_in(&iopin); 247 break; 248 case PAR: 249 if (value) 250 iopin_set_ded(&iopin); 251 else 252 iopin_set_gen(&iopin); 253 break; 254 case SOR: 255 if (value) 256 iopin_set_opt2(&iopin); 257 else 258 iopin_set_opt1(&iopin); 259 break; 260 case ODR: 261 if (value) 262 iopin_set_odr(&iopin); 263 else 264 iopin_set_act(&iopin); 265 break; 266 case DAT: 267 if (value) 268 iopin_set_high(&iopin); 269 else 270 iopin_set_low(&iopin); 271 break; 272 case INT: 273 if (value) 274 iopin_set_falledge(&iopin); 275 else 276 iopin_set_anyedge(&iopin); 277 break; 278 } 279 } 280 return rcode; 281 } 282 283 static void prbrg(int n, uint val) 284 { 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 291 printf("BRG%d:", n); 292 293 if (val & CPM_BRG_RST) 294 puts(" RESET"); 295 else 296 puts(" "); 297 298 if (val & CPM_BRG_EN) 299 puts(" ENABLED"); 300 else 301 puts(" DISABLED"); 302 303 printf(" EXTC=%d", extc); 304 305 if (val & CPM_BRG_ATB) 306 puts(" ATB"); 307 else 308 puts(" "); 309 310 printf(" DIVIDER=%4d", cd); 311 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 319 printf("=%6d bps", baudrate); 320 } else { 321 puts(" "); 322 } 323 324 if (val & CPM_BRG_DIV16) 325 puts(" DIV16"); 326 else 327 puts(" "); 328 329 putc('\n'); 330 } 331 332 static int do_brginfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 333 { 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; 337 int i = 1; 338 339 while (i <= 4) 340 prbrg(i++, in_be32(p++)); 341 342 return 0; 343 } 344 345 /***************************************************/ 346 347 U_BOOT_CMD( 348 siuinfo, 1, 1, do_siuinfo, 349 "print System Interface Unit (SIU) registers", 350 "" 351 ); 352 353 U_BOOT_CMD( 354 memcinfo, 1, 1, do_memcinfo, 355 "print Memory Controller registers", 356 "" 357 ); 358 359 U_BOOT_CMD( 360 carinfo, 1, 1, do_carinfo, 361 "print Clocks and Reset registers", 362 "" 363 ); 364 365 U_BOOT_CMD( 366 iopinfo, 1, 1, do_iopinfo, 367 "print I/O Port registers", 368 "" 369 ); 370 371 U_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 377 U_BOOT_CMD( 378 brginfo, 1, 1, do_brginfo, 379 "print Baud Rate Generator (BRG) registers", 380 "" 381 ); 382