immap.c 7.6 KB

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