cpld.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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("sw_ctl_on = 0x%02x\n", CPLD_READ(sw_ctl_on));
  72. printf("por_cfg = 0x%02x\n", CPLD_READ(por_cfg));
  73. printf("switch_strobe = 0x%02x\n", CPLD_READ(switch_strobe));
  74. printf("jtag_sel = 0x%02x\n", CPLD_READ(jtag_sel));
  75. printf("sdbank1_clk = 0x%02x\n", CPLD_READ(sdbank1_clk));
  76. printf("sdbank2_clk = 0x%02x\n", CPLD_READ(sdbank2_clk));
  77. printf("fbank_sel = 0x%02x\n", CPLD_READ(fbank_sel));
  78. printf("serdes_mux = 0x%02x\n", CPLD_READ(serdes_mux));
  79. printf("SW[2] = 0x%02x\n", in_8(&CPLD_SW(2)));
  80. putc('\n');
  81. }
  82. #endif
  83. int cpld_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  84. {
  85. int rc = 0;
  86. if (argc <= 1)
  87. return cmd_usage(cmdtp);
  88. if (strcmp(argv[1], "reset") == 0) {
  89. if (strcmp(argv[2], "altbank") == 0)
  90. cpld_set_altbank();
  91. else
  92. cpld_set_defbank();
  93. } else if (strcmp(argv[1], "lane_mux") == 0) {
  94. u32 lane = simple_strtoul(argv[2], NULL, 16);
  95. u8 val = (u8)simple_strtoul(argv[3], NULL, 16);
  96. u8 reg = CPLD_READ(serdes_mux);
  97. switch (lane) {
  98. case 0x6:
  99. reg &= ~SERDES_MUX_LANE_6_MASK;
  100. reg |= val << SERDES_MUX_LANE_6_SHIFT;
  101. break;
  102. case 0xa:
  103. reg &= ~SERDES_MUX_LANE_A_MASK;
  104. reg |= val << SERDES_MUX_LANE_A_SHIFT;
  105. break;
  106. case 0xc:
  107. reg &= ~SERDES_MUX_LANE_C_MASK;
  108. reg |= val << SERDES_MUX_LANE_C_SHIFT;
  109. break;
  110. case 0xd:
  111. reg &= ~SERDES_MUX_LANE_D_MASK;
  112. reg |= val << SERDES_MUX_LANE_D_SHIFT;
  113. break;
  114. default:
  115. printf("Invalid value\n");
  116. break;
  117. }
  118. CPLD_WRITE(serdes_mux, reg);
  119. #ifdef DEBUG
  120. } else if (strcmp(argv[1], "dump") == 0) {
  121. cpld_dump_regs();
  122. #endif
  123. } else
  124. rc = cmd_usage(cmdtp);
  125. return rc;
  126. }
  127. U_BOOT_CMD(
  128. cpld_cmd, CONFIG_SYS_MAXARGS, 1, cpld_cmd,
  129. "Reset the board or pin mulexing selection using the CPLD sequencer",
  130. "reset - hard reset to default bank\n"
  131. "cpld_cmd reset altbank - reset to alternate bank\n"
  132. "cpld_cmd lane_mux <lane> <mux_value> - set multiplexed lane pin\n"
  133. " lane 6: 0 -> slot1\n"
  134. " 1 -> SGMII (Default)\n"
  135. " lane a: 0 -> slot2\n"
  136. " 1 -> AURORA (Default)\n"
  137. " lane c: 0 -> slot2\n"
  138. " 1 -> SATA0 (Default)\n"
  139. " lane d: 0 -> slot2\n"
  140. " 1 -> SATA1 (Default)\n"
  141. #ifdef DEBUG
  142. "cpld_cmd dump - display the CPLD registers\n"
  143. #endif
  144. );