cpld.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * Copyright 2011 Freescale Semiconductor
  3. * Author: Mingkai Hu <Mingkai.hu@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 board-specific CPLD used on some Freescale
  11. * reference boards.
  12. *
  13. * The following macros need to be defined:
  14. *
  15. * CPLD_BASE - The virtual address of the base of the CPLD register map
  16. *
  17. */
  18. #include <common.h>
  19. #include <command.h>
  20. #include <asm/io.h>
  21. #include "cpld.h"
  22. static u8 __cpld_read(unsigned int reg)
  23. {
  24. void *p = (void *)CPLD_BASE;
  25. return in_8(p + reg);
  26. }
  27. u8 cpld_read(unsigned int reg) __attribute__((weak, alias("__cpld_read")));
  28. static void __cpld_write(unsigned int reg, u8 value)
  29. {
  30. void *p = (void *)CPLD_BASE;
  31. out_8(p + reg, value);
  32. }
  33. void cpld_write(unsigned int reg, u8 value)
  34. __attribute__((weak, alias("__cpld_write")));
  35. /*
  36. * Reset the board. This honors the por_cfg registers.
  37. */
  38. void __cpld_reset(void)
  39. {
  40. CPLD_WRITE(system_rst, 1);
  41. }
  42. void cpld_reset(void) __attribute__((weak, alias("__cpld_reset")));
  43. /**
  44. * Set the boot bank to the alternate bank
  45. */
  46. void __cpld_set_altbank(void)
  47. {
  48. CPLD_WRITE(fbank_sel, 1);
  49. }
  50. void cpld_set_altbank(void)
  51. __attribute__((weak, alias("__cpld_set_altbank")));
  52. /**
  53. * Set the boot bank to the default bank
  54. */
  55. void __cpld_clear_altbank(void)
  56. {
  57. CPLD_WRITE(fbank_sel, 0);
  58. }
  59. void cpld_clear_altbank(void)
  60. __attribute__((weak, alias("__cpld_clear_altbank")));
  61. #ifdef DEBUG
  62. static void cpld_dump_regs(void)
  63. {
  64. printf("cpld_ver = 0x%02x\n", CPLD_READ(cpld_ver));
  65. printf("cpld_ver_sub = 0x%02x\n", CPLD_READ(cpld_ver_sub));
  66. printf("pcba_ver = 0x%02x\n", CPLD_READ(pcba_ver));
  67. printf("system_rst = 0x%02x\n", CPLD_READ(system_rst));
  68. printf("wd_cfg = 0x%02x\n", CPLD_READ(wd_cfg));
  69. printf("sw_ctl_on = 0x%02x\n", CPLD_READ(sw_ctl_on));
  70. printf("por_cfg = 0x%02x\n", CPLD_READ(por_cfg));
  71. printf("switch_strobe = 0x%02x\n", CPLD_READ(switch_strobe));
  72. printf("jtag_sel = 0x%02x\n", CPLD_READ(jtag_sel));
  73. printf("sdbank1_clk = 0x%02x\n", CPLD_READ(sdbank1_clk));
  74. printf("sdbank2_clk = 0x%02x\n", CPLD_READ(sdbank2_clk));
  75. printf("fbank_sel = 0x%02x\n", CPLD_READ(fbank_sel));
  76. printf("serdes_mux = 0x%02x\n", CPLD_READ(serdes_mux));
  77. printf("SW[2] = 0x%02x\n", in_8(&CPLD_SW(2)));
  78. putc('\n');
  79. }
  80. #endif
  81. int cpld_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  82. {
  83. int rc = 0;
  84. unsigned int i;
  85. if (argc <= 1)
  86. return cmd_usage(cmdtp);
  87. if (strcmp(argv[1], "reset") == 0) {
  88. if (strcmp(argv[2], "altbank") == 0)
  89. cpld_set_altbank();
  90. else
  91. cpld_clear_altbank();
  92. cpld_reset();
  93. } else if (strcmp(argv[1], "watchdog") == 0) {
  94. static char *period[8] = {"1ms", "10ms", "30ms", "disable",
  95. "100ms", "1s", "10s", "60s"};
  96. for (i = 0; i < ARRAY_SIZE(period); i++) {
  97. if (strcmp(argv[2], period[i]) == 0)
  98. CPLD_WRITE(wd_cfg, i);
  99. }
  100. } else if (strcmp(argv[1], "lane_mux") == 0) {
  101. u32 lane = simple_strtoul(argv[2], NULL, 16);
  102. u8 val = (u8)simple_strtoul(argv[3], NULL, 16);
  103. u8 reg = CPLD_READ(serdes_mux);
  104. switch (lane) {
  105. case 0x6:
  106. reg &= ~SERDES_MUX_LANE_6_MASK;
  107. reg |= val << SERDES_MUX_LANE_6_SHIFT;
  108. break;
  109. case 0xa:
  110. reg &= ~SERDES_MUX_LANE_A_MASK;
  111. reg |= val << SERDES_MUX_LANE_A_SHIFT;
  112. break;
  113. case 0xc:
  114. reg &= ~SERDES_MUX_LANE_C_MASK;
  115. reg |= val << SERDES_MUX_LANE_C_SHIFT;
  116. break;
  117. case 0xd:
  118. reg &= ~SERDES_MUX_LANE_D_MASK;
  119. reg |= val << SERDES_MUX_LANE_D_SHIFT;
  120. break;
  121. default:
  122. printf("Invalid value\n");
  123. break;
  124. }
  125. CPLD_WRITE(serdes_mux, reg);
  126. #ifdef DEBUG
  127. } else if (strcmp(argv[1], "dump") == 0) {
  128. cpld_dump_regs();
  129. #endif
  130. } else
  131. rc = cmd_usage(cmdtp);
  132. return rc;
  133. }
  134. U_BOOT_CMD(
  135. cpld_cmd, CONFIG_SYS_MAXARGS, 1, cpld_cmd,
  136. "Reset the board or pin mulexing selection using the CPLD sequencer",
  137. "reset - hard reset to default bank\n"
  138. "cpld_cmd reset altbank - reset to alternate bank\n"
  139. "cpld_cmd watchdog <watchdog_period> - set the watchdog period\n"
  140. " period: 1ms 10ms 30ms 100ms 1s 10s 60s disable\n"
  141. "cpld_cmd lane_mux <lane> <mux_value> - set multiplexed lane pin\n"
  142. " lane 6: 0 -> slot1 (Default)\n"
  143. " 1 -> SGMII\n"
  144. " lane a: 0 -> slot2 (Default)\n"
  145. " 1 -> AURORA\n"
  146. " lane c: 0 -> slot2 (Default)\n"
  147. " 1 -> SATA0\n"
  148. " lane d: 0 -> slot2 (Default)\n"
  149. " 1 -> SATA1\n"
  150. #ifdef DEBUG
  151. "cpld_cmd dump - display the CPLD registers\n"
  152. #endif
  153. );