immap.c 8.1 KB

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