ngpixis.c 6.6 KB

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