qixis.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Copyright 2011 Freescale Semiconductor
  3. * Author: Shengzhou Liu <Shengzhou.Liu@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 QIXIS of some Freescale reference boards.
  11. *
  12. */
  13. #include <common.h>
  14. #include <command.h>
  15. #include <asm/io.h>
  16. #include <linux/time.h>
  17. #include <i2c.h>
  18. #include "qixis.h"
  19. #ifdef CONFIG_SYS_I2C_FPGA_ADDR
  20. u8 qixis_read_i2c(unsigned int reg)
  21. {
  22. return i2c_reg_read(CONFIG_SYS_I2C_FPGA_ADDR, reg);
  23. }
  24. void qixis_write_i2c(unsigned int reg, u8 value)
  25. {
  26. u8 val = value;
  27. i2c_reg_write(CONFIG_SYS_I2C_FPGA_ADDR, reg, val);
  28. }
  29. #endif
  30. u8 qixis_read(unsigned int reg)
  31. {
  32. void *p = (void *)QIXIS_BASE;
  33. return in_8(p + reg);
  34. }
  35. void qixis_write(unsigned int reg, u8 value)
  36. {
  37. void *p = (void *)QIXIS_BASE;
  38. out_8(p + reg, value);
  39. }
  40. u16 qixis_read_minor(void)
  41. {
  42. u16 minor;
  43. /* this data is in little endian */
  44. QIXIS_WRITE(tagdata, 5);
  45. minor = QIXIS_READ(tagdata);
  46. QIXIS_WRITE(tagdata, 6);
  47. minor += QIXIS_READ(tagdata) << 8;
  48. return minor;
  49. }
  50. char *qixis_read_time(char *result)
  51. {
  52. time_t time = 0;
  53. int i;
  54. /* timestamp is in 32-bit big endian */
  55. for (i = 8; i <= 11; i++) {
  56. QIXIS_WRITE(tagdata, i);
  57. time = (time << 8) + QIXIS_READ(tagdata);
  58. }
  59. return ctime_r(&time, result);
  60. }
  61. char *qixis_read_tag(char *buf)
  62. {
  63. int i;
  64. char tag, *ptr = buf;
  65. for (i = 16; i <= 63; i++) {
  66. QIXIS_WRITE(tagdata, i);
  67. tag = QIXIS_READ(tagdata);
  68. *(ptr++) = tag;
  69. if (!tag)
  70. break;
  71. }
  72. if (i > 63)
  73. *ptr = '\0';
  74. return buf;
  75. }
  76. /*
  77. * return the string of binary of u8 in the format of
  78. * 1010 10_0. The masked bit is filled as underscore.
  79. */
  80. const char *byte_to_binary_mask(u8 val, u8 mask, char *buf)
  81. {
  82. char *ptr;
  83. int i;
  84. ptr = buf;
  85. for (i = 0x80; i > 0x08 ; i >>= 1, ptr++)
  86. *ptr = (val & i) ? '1' : ((mask & i) ? '_' : '0');
  87. *(ptr++) = ' ';
  88. for (i = 0x08; i > 0 ; i >>= 1, ptr++)
  89. *ptr = (val & i) ? '1' : ((mask & i) ? '_' : '0');
  90. *ptr = '\0';
  91. return buf;
  92. }
  93. void qixis_reset(void)
  94. {
  95. QIXIS_WRITE(rst_ctl, QIXIS_RST_CTL_RESET);
  96. }
  97. void qixis_bank_reset(void)
  98. {
  99. QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_IDLE);
  100. QIXIS_WRITE(rcfg_ctl, QIXIS_RCFG_CTL_RECONFIG_START);
  101. }
  102. /* Set the boot bank to the power-on default bank */
  103. void clear_altbank(void)
  104. {
  105. u8 reg;
  106. reg = QIXIS_READ(brdcfg[0]);
  107. reg = (reg & ~QIXIS_LBMAP_MASK) | QIXIS_LBMAP_DFLTBANK;
  108. QIXIS_WRITE(brdcfg[0], reg);
  109. }
  110. /* Set the boot bank to the alternate bank */
  111. void set_altbank(void)
  112. {
  113. u8 reg;
  114. reg = QIXIS_READ(brdcfg[0]);
  115. reg = (reg & ~QIXIS_LBMAP_MASK) | QIXIS_LBMAP_ALTBANK;
  116. QIXIS_WRITE(brdcfg[0], reg);
  117. }
  118. static void qixis_dump_regs(void)
  119. {
  120. int i;
  121. printf("id = %02x\n", QIXIS_READ(id));
  122. printf("arch = %02x\n", QIXIS_READ(arch));
  123. printf("scver = %02x\n", QIXIS_READ(scver));
  124. printf("model = %02x\n", QIXIS_READ(model));
  125. printf("rst_ctl = %02x\n", QIXIS_READ(rst_ctl));
  126. printf("aux = %02x\n", QIXIS_READ(aux));
  127. for (i = 0; i < 16; i++)
  128. printf("brdcfg%02d = %02x\n", i, QIXIS_READ(brdcfg[i]));
  129. for (i = 0; i < 16; i++)
  130. printf("dutcfg%02d = %02x\n", i, QIXIS_READ(dutcfg[i]));
  131. printf("sclk = %02x%02x%02x\n", QIXIS_READ(sclk[0]),
  132. QIXIS_READ(sclk[1]), QIXIS_READ(sclk[2]));
  133. printf("dclk = %02x%02x%02x\n", QIXIS_READ(dclk[0]),
  134. QIXIS_READ(dclk[1]), QIXIS_READ(dclk[2]));
  135. printf("aux = %02x\n", QIXIS_READ(aux));
  136. printf("watch = %02x\n", QIXIS_READ(watch));
  137. printf("ctl_sys = %02x\n", QIXIS_READ(ctl_sys));
  138. printf("rcw_ctl = %02x\n", QIXIS_READ(rcw_ctl));
  139. printf("present = %02x\n", QIXIS_READ(present));
  140. printf("present2 = %02x\n", QIXIS_READ(present2));
  141. printf("clk_spd = %02x\n", QIXIS_READ(clk_spd));
  142. printf("stat_dut = %02x\n", QIXIS_READ(stat_dut));
  143. printf("stat_sys = %02x\n", QIXIS_READ(stat_sys));
  144. printf("stat_alrm = %02x\n", QIXIS_READ(stat_alrm));
  145. }
  146. static void __qixis_dump_switch(void)
  147. {
  148. puts("Reverse engineering switch is not implemented for this board\n");
  149. }
  150. void qixis_dump_switch(void)
  151. __attribute__((weak, alias("__qixis_dump_switch")));
  152. int qixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  153. {
  154. int i;
  155. if (argc <= 1) {
  156. clear_altbank();
  157. qixis_reset();
  158. } else if (strcmp(argv[1], "altbank") == 0) {
  159. set_altbank();
  160. qixis_bank_reset();
  161. } else if (strcmp(argv[1], "watchdog") == 0) {
  162. static char *period[9] = {"2s", "4s", "8s", "16s", "32s",
  163. "1min", "2min", "4min", "8min"};
  164. u8 rcfg = QIXIS_READ(rcfg_ctl);
  165. if (argv[2] == NULL) {
  166. printf("qixis watchdog <watchdog_period>\n");
  167. return 0;
  168. }
  169. for (i = 0; i < ARRAY_SIZE(period); i++) {
  170. if (strcmp(argv[2], period[i]) == 0) {
  171. /* disable watchdog */
  172. QIXIS_WRITE(rcfg_ctl,
  173. rcfg & ~QIXIS_RCFG_CTL_WATCHDOG_ENBLE);
  174. QIXIS_WRITE(watch, ((i<<2) - 1));
  175. QIXIS_WRITE(rcfg_ctl, rcfg);
  176. return 0;
  177. }
  178. }
  179. } else if (strcmp(argv[1], "dump") == 0) {
  180. qixis_dump_regs();
  181. return 0;
  182. } else if (strcmp(argv[1], "switch") == 0) {
  183. qixis_dump_switch();
  184. return 0;
  185. } else {
  186. printf("Invalid option: %s\n", argv[1]);
  187. return 1;
  188. }
  189. return 0;
  190. }
  191. U_BOOT_CMD(
  192. qixis_reset, CONFIG_SYS_MAXARGS, 1, qixis_reset_cmd,
  193. "Reset the board using the FPGA sequencer",
  194. "- hard reset to default bank\n"
  195. "qixis_reset altbank - reset to alternate bank\n"
  196. "qixis watchdog <watchdog_period> - set the watchdog period\n"
  197. " period: 1s 2s 4s 8s 16s 32s 1min 2min 4min 8min\n"
  198. "qixis_reset dump - display the QIXIS registers\n"
  199. "qixis_reset switch - display switch\n"
  200. );