cpld.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. u8 reg5 = CPLD_READ(sw_ctl_on);
  49. CPLD_WRITE(sw_ctl_on, reg5 | CPLD_SWITCH_BANK_ENABLE);
  50. CPLD_WRITE(fbank_sel, 1);
  51. CPLD_WRITE(system_rst, 1);
  52. }
  53. void cpld_set_altbank(void)
  54. __attribute__((weak, alias("__cpld_set_altbank")));
  55. /**
  56. * Set the boot bank to the default bank
  57. */
  58. void __cpld_set_defbank(void)
  59. {
  60. CPLD_WRITE(system_rst_default, 1);
  61. }
  62. void cpld_set_defbank(void)
  63. __attribute__((weak, alias("__cpld_set_defbank")));
  64. #ifdef DEBUG
  65. static void cpld_dump_regs(void)
  66. {
  67. printf("cpld_ver = 0x%02x\n", CPLD_READ(cpld_ver));
  68. printf("cpld_ver_sub = 0x%02x\n", CPLD_READ(cpld_ver_sub));
  69. printf("pcba_ver = 0x%02x\n", CPLD_READ(pcba_ver));
  70. printf("system_rst = 0x%02x\n", CPLD_READ(system_rst));
  71. printf("wd_cfg = 0x%02x\n", CPLD_READ(wd_cfg));
  72. printf("sw_ctl_on = 0x%02x\n", CPLD_READ(sw_ctl_on));
  73. printf("por_cfg = 0x%02x\n", CPLD_READ(por_cfg));
  74. printf("switch_strobe = 0x%02x\n", CPLD_READ(switch_strobe));
  75. printf("jtag_sel = 0x%02x\n", CPLD_READ(jtag_sel));
  76. printf("sdbank1_clk = 0x%02x\n", CPLD_READ(sdbank1_clk));
  77. printf("sdbank2_clk = 0x%02x\n", CPLD_READ(sdbank2_clk));
  78. printf("fbank_sel = 0x%02x\n", CPLD_READ(fbank_sel));
  79. printf("serdes_mux = 0x%02x\n", CPLD_READ(serdes_mux));
  80. printf("SW[2] = 0x%02x\n", in_8(&CPLD_SW(2)));
  81. putc('\n');
  82. }
  83. #endif
  84. int cpld_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  85. {
  86. int rc = 0;
  87. unsigned int i;
  88. if (argc <= 1)
  89. return cmd_usage(cmdtp);
  90. if (strcmp(argv[1], "reset") == 0) {
  91. if (strcmp(argv[2], "altbank") == 0)
  92. cpld_set_altbank();
  93. else
  94. cpld_set_defbank();
  95. } else if (strcmp(argv[1], "watchdog") == 0) {
  96. static char *period[8] = {"1ms", "10ms", "30ms", "disable",
  97. "100ms", "1s", "10s", "60s"};
  98. for (i = 0; i < ARRAY_SIZE(period); i++) {
  99. if (strcmp(argv[2], period[i]) == 0)
  100. CPLD_WRITE(wd_cfg, i);
  101. }
  102. } else if (strcmp(argv[1], "lane_mux") == 0) {
  103. u32 lane = simple_strtoul(argv[2], NULL, 16);
  104. u8 val = (u8)simple_strtoul(argv[3], NULL, 16);
  105. u8 reg = CPLD_READ(serdes_mux);
  106. switch (lane) {
  107. case 0x6:
  108. reg &= ~SERDES_MUX_LANE_6_MASK;
  109. reg |= val << SERDES_MUX_LANE_6_SHIFT;
  110. break;
  111. case 0xa:
  112. reg &= ~SERDES_MUX_LANE_A_MASK;
  113. reg |= val << SERDES_MUX_LANE_A_SHIFT;
  114. break;
  115. case 0xc:
  116. reg &= ~SERDES_MUX_LANE_C_MASK;
  117. reg |= val << SERDES_MUX_LANE_C_SHIFT;
  118. break;
  119. case 0xd:
  120. reg &= ~SERDES_MUX_LANE_D_MASK;
  121. reg |= val << SERDES_MUX_LANE_D_SHIFT;
  122. break;
  123. default:
  124. printf("Invalid value\n");
  125. break;
  126. }
  127. CPLD_WRITE(serdes_mux, reg);
  128. #ifdef DEBUG
  129. } else if (strcmp(argv[1], "dump") == 0) {
  130. cpld_dump_regs();
  131. #endif
  132. } else
  133. rc = cmd_usage(cmdtp);
  134. return rc;
  135. }
  136. U_BOOT_CMD(
  137. cpld_cmd, CONFIG_SYS_MAXARGS, 1, cpld_cmd,
  138. "Reset the board or pin mulexing selection using the CPLD sequencer",
  139. "reset - hard reset to default bank\n"
  140. "cpld_cmd reset altbank - reset to alternate bank\n"
  141. "cpld_cmd watchdog <watchdog_period> - set the watchdog period\n"
  142. " period: 1ms 10ms 30ms 100ms 1s 10s 60s disable\n"
  143. "cpld_cmd lane_mux <lane> <mux_value> - set multiplexed lane pin\n"
  144. " lane 6: 0 -> slot1\n"
  145. " 1 -> SGMII (Default)\n"
  146. " lane a: 0 -> slot2\n"
  147. " 1 -> AURORA (Default)\n"
  148. " lane c: 0 -> slot2\n"
  149. " 1 -> SATA0 (Default)\n"
  150. " lane d: 0 -> slot2\n"
  151. " 1 -> SATA1 (Default)\n"
  152. #ifdef DEBUG
  153. "cpld_cmd dump - display the CPLD registers\n"
  154. #endif
  155. );