ngpixis.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /**
  2. * Copyright 2010-2011 Freescale Semiconductor
  3. * Author: Timur Tabi <timur@freescale.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. *
  7. * This file provides support for the ngPIXIS, a board-specific FPGA used on
  8. * some Freescale reference boards.
  9. *
  10. * A "switch" is black rectangular block on the motherboard. It contains
  11. * eight "bits". The ngPIXIS has a set of memory-mapped registers (SWx) that
  12. * shadow the actual physical switches. There is also another set of
  13. * registers (ENx) that tell the ngPIXIS which bits of SWx should actually be
  14. * used to override the values of the bits in the physical switches.
  15. *
  16. * The following macros need to be defined:
  17. *
  18. * PIXIS_BASE - The virtual address of the base of the PIXIS register map
  19. *
  20. * PIXIS_LBMAP_SWITCH - The switch number (i.e. the "x" in "SWx"). This value
  21. * is used in the PIXIS_SW() macro to determine which offset in
  22. * the PIXIS register map corresponds to the physical switch that controls
  23. * the boot bank.
  24. *
  25. * PIXIS_LBMAP_MASK - A bit mask the defines which bits in SWx to use.
  26. *
  27. * PIXIS_LBMAP_SHIFT - The shift value that corresponds to PIXIS_LBMAP_MASK.
  28. *
  29. * PIXIS_LBMAP_ALTBANK - The value to program into SWx to tell the ngPIXIS to
  30. * boot from the alternate bank.
  31. */
  32. #include <common.h>
  33. #include <command.h>
  34. #include <asm/io.h>
  35. #include "ngpixis.h"
  36. static u8 __pixis_read(unsigned int reg)
  37. {
  38. void *p = (void *)PIXIS_BASE;
  39. return in_8(p + reg);
  40. }
  41. u8 pixis_read(unsigned int reg) __attribute__((weak, alias("__pixis_read")));
  42. static void __pixis_write(unsigned int reg, u8 value)
  43. {
  44. void *p = (void *)PIXIS_BASE;
  45. out_8(p + reg, value);
  46. }
  47. void pixis_write(unsigned int reg, u8 value)
  48. __attribute__((weak, alias("__pixis_write")));
  49. /*
  50. * Reset the board. This ignores the ENx registers.
  51. */
  52. void __pixis_reset(void)
  53. {
  54. PIXIS_WRITE(rst, 0);
  55. while (1);
  56. }
  57. void pixis_reset(void) __attribute__((weak, alias("__pixis_reset")));
  58. /*
  59. * Reset the board. Like pixis_reset(), but it honors the ENx registers.
  60. */
  61. void __pixis_bank_reset(void)
  62. {
  63. PIXIS_WRITE(vctl, 0);
  64. PIXIS_WRITE(vctl, 1);
  65. while (1);
  66. }
  67. void pixis_bank_reset(void) __attribute__((weak, alias("__pixis_bank_reset")));
  68. /**
  69. * Set the boot bank to the power-on default bank
  70. */
  71. void __clear_altbank(void)
  72. {
  73. u8 reg;
  74. /* Tell the ngPIXIS to use this the bits in the physical switch for the
  75. * boot bank value, instead of the SWx register. We need to be careful
  76. * only to set the bits in SWx that correspond to the boot bank.
  77. */
  78. reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en);
  79. reg &= ~PIXIS_LBMAP_MASK;
  80. PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg);
  81. }
  82. void clear_altbank(void) __attribute__((weak, alias("__clear_altbank")));
  83. /**
  84. * Set the boot bank to the alternate bank
  85. */
  86. void __set_altbank(void)
  87. {
  88. u8 reg;
  89. /* Program the alternate bank number into the SWx register.
  90. */
  91. reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].sw);
  92. reg = (reg & ~PIXIS_LBMAP_MASK) | PIXIS_LBMAP_ALTBANK;
  93. PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].sw, reg);
  94. /* Tell the ngPIXIS to use this the bits in the SWx register for the
  95. * boot bank value, instead of the physical switch. We need to be
  96. * careful only to set the bits in SWx that correspond to the boot bank.
  97. */
  98. reg = PIXIS_READ(s[PIXIS_LBMAP_SWITCH - 1].en);
  99. reg |= PIXIS_LBMAP_MASK;
  100. PIXIS_WRITE(s[PIXIS_LBMAP_SWITCH - 1].en, reg);
  101. }
  102. void set_altbank(void) __attribute__((weak, alias("__set_altbank")));
  103. #ifdef DEBUG
  104. static void pixis_dump_regs(void)
  105. {
  106. unsigned int i;
  107. printf("id=%02x\n", PIXIS_READ(id));
  108. printf("arch=%02x\n", PIXIS_READ(arch));
  109. printf("scver=%02x\n", PIXIS_READ(scver));
  110. printf("csr=%02x\n", PIXIS_READ(csr));
  111. printf("rst=%02x\n", PIXIS_READ(rst));
  112. printf("aux=%02x\n", PIXIS_READ(aux));
  113. printf("spd=%02x\n", PIXIS_READ(spd));
  114. printf("brdcfg0=%02x\n", PIXIS_READ(brdcfg0));
  115. printf("brdcfg1=%02x\n", PIXIS_READ(brdcfg1));
  116. printf("addr=%02x\n", PIXIS_READ(addr));
  117. printf("data=%02x\n", PIXIS_READ(data));
  118. printf("led=%02x\n", PIXIS_READ(led));
  119. printf("vctl=%02x\n", PIXIS_READ(vctl));
  120. printf("vstat=%02x\n", PIXIS_READ(vstat));
  121. printf("vcfgen0=%02x\n", PIXIS_READ(vcfgen0));
  122. printf("ocmcsr=%02x\n", PIXIS_READ(ocmcsr));
  123. printf("ocmmsg=%02x\n", PIXIS_READ(ocmmsg));
  124. printf("gmdbg=%02x\n", PIXIS_READ(gmdbg));
  125. printf("sclk=%02x%02x%02x\n",
  126. PIXIS_READ(sclk[0]), PIXIS_READ(sclk[1]), PIXIS_READ(sclk[2]));
  127. printf("dclk=%02x%02x%02x\n",
  128. PIXIS_READ(dclk[0]), PIXIS_READ(dclk[1]), PIXIS_READ(dclk[2]));
  129. printf("watch=%02x\n", PIXIS_READ(watch));
  130. for (i = 0; i < 8; i++) {
  131. printf("SW%u=%02x/%02x ", i + 1,
  132. PIXIS_READ(s[i].sw), PIXIS_READ(s[i].en));
  133. }
  134. putc('\n');
  135. }
  136. #endif
  137. void pixis_sysclk_set(unsigned long sysclk)
  138. {
  139. unsigned long freq_word;
  140. u8 sclk0, sclk1, sclk2;
  141. freq_word = ics307_sysclk_calculator(sysclk);
  142. sclk2 = freq_word & 0xff;
  143. sclk1 = (freq_word >> 8) & 0xff;
  144. sclk0 = (freq_word >> 16) & 0xff;
  145. /* set SYSCLK enable bit */
  146. PIXIS_WRITE(vcfgen0, 0x01);
  147. /* SYSCLK to required frequency */
  148. PIXIS_WRITE(sclk[0], sclk0);
  149. PIXIS_WRITE(sclk[1], sclk1);
  150. PIXIS_WRITE(sclk[2], sclk2);
  151. }
  152. int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  153. {
  154. unsigned int i;
  155. unsigned long sysclk;
  156. char *p_altbank = NULL;
  157. #ifdef DEBUG
  158. char *p_dump = NULL;
  159. #endif
  160. char *unknown_param = NULL;
  161. /* No args is a simple reset request.
  162. */
  163. if (argc <= 1)
  164. pixis_reset();
  165. for (i = 1; i < argc; i++) {
  166. if (strcmp(argv[i], "altbank") == 0) {
  167. p_altbank = argv[i];
  168. continue;
  169. }
  170. #ifdef DEBUG
  171. if (strcmp(argv[i], "dump") == 0) {
  172. p_dump = argv[i];
  173. continue;
  174. }
  175. #endif
  176. if (strcmp(argv[i], "sysclk") == 0) {
  177. sysclk = simple_strtoul(argv[i + 1], NULL, 0);
  178. i += 1;
  179. pixis_sysclk_set(sysclk);
  180. continue;
  181. }
  182. unknown_param = argv[i];
  183. }
  184. if (unknown_param) {
  185. printf("Invalid option: %s\n", unknown_param);
  186. return 1;
  187. }
  188. #ifdef DEBUG
  189. if (p_dump) {
  190. pixis_dump_regs();
  191. /* 'dump' ignores other commands */
  192. return 0;
  193. }
  194. #endif
  195. if (p_altbank)
  196. set_altbank();
  197. else
  198. clear_altbank();
  199. pixis_bank_reset();
  200. /* Shouldn't be reached. */
  201. return 0;
  202. }
  203. #ifdef CONFIG_SYS_LONGHELP
  204. static char pixis_help_text[] =
  205. "- hard reset to default bank\n"
  206. "pixis_reset altbank - reset to alternate bank\n"
  207. #ifdef DEBUG
  208. "pixis_reset dump - display the PIXIS registers\n"
  209. #endif
  210. "pixis_reset sysclk <SYSCLK_freq> - reset with SYSCLK frequency(KHz)\n";
  211. #endif
  212. U_BOOT_CMD(
  213. pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
  214. "Reset the board using the FPGA sequencer", pixis_help_text
  215. );