cpld.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Copyright 2014 Freescale Semiconductor
  3. *
  4. * Author: Chunhe Lan <Chunhe.Lan@freescale.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. *
  8. * This file provides support for the board-specific CPLD used on some Freescale
  9. * reference boards.
  10. *
  11. * The following macros need to be defined:
  12. *
  13. * CONFIG_SYS_CPLD_BASE - The virtual address of the base of the
  14. * CPLD register map
  15. *
  16. */
  17. #include <common.h>
  18. #include <command.h>
  19. #include <asm/io.h>
  20. #include "cpld.h"
  21. u8 cpld_read(unsigned int reg)
  22. {
  23. void *p = (void *)CONFIG_SYS_CPLD_BASE;
  24. return in_8(p + reg);
  25. }
  26. void cpld_write(unsigned int reg, u8 value)
  27. {
  28. void *p = (void *)CONFIG_SYS_CPLD_BASE;
  29. out_8(p + reg, value);
  30. }
  31. /**
  32. * Set the boot bank to the alternate bank
  33. */
  34. void cpld_set_altbank(void)
  35. {
  36. u8 val, curbank, altbank, override;
  37. val = CPLD_READ(vbank);
  38. curbank = val & CPLD_BANK_SEL_MASK;
  39. switch (curbank) {
  40. case CPLD_SELECT_BANK0:
  41. altbank = CPLD_SELECT_BANK4;
  42. CPLD_WRITE(vbank, altbank);
  43. override = CPLD_READ(software_on);
  44. CPLD_WRITE(software_on, override | CPLD_BANK_SEL_EN);
  45. CPLD_WRITE(sys_reset, CPLD_SYSTEM_RESET);
  46. break;
  47. case CPLD_SELECT_BANK4:
  48. altbank = CPLD_SELECT_BANK0;
  49. CPLD_WRITE(vbank, altbank);
  50. override = CPLD_READ(software_on);
  51. CPLD_WRITE(software_on, override | CPLD_BANK_SEL_EN);
  52. CPLD_WRITE(sys_reset, CPLD_SYSTEM_RESET);
  53. break;
  54. default:
  55. printf("CPLD Altbank Fail: Invalid value!\n");
  56. return;
  57. }
  58. }
  59. /**
  60. * Set the boot bank to the default bank
  61. */
  62. void cpld_set_defbank(void)
  63. {
  64. u8 val;
  65. val = CPLD_DEFAULT_BANK;
  66. CPLD_WRITE(global_reset, val);
  67. }
  68. #ifdef DEBUG
  69. static void cpld_dump_regs(void)
  70. {
  71. printf("chip_id1 = 0x%02x\n", CPLD_READ(chip_id1));
  72. printf("chip_id2 = 0x%02x\n", CPLD_READ(chip_id2));
  73. printf("sw_maj_ver = 0x%02x\n", CPLD_READ(sw_maj_ver));
  74. printf("sw_min_ver = 0x%02x\n", CPLD_READ(sw_min_ver));
  75. printf("hw_ver = 0x%02x\n", CPLD_READ(hw_ver));
  76. printf("software_on = 0x%02x\n", CPLD_READ(software_on));
  77. printf("cfg_rcw_src = 0x%02x\n", CPLD_READ(cfg_rcw_src));
  78. printf("res0 = 0x%02x\n", CPLD_READ(res0));
  79. printf("vbank = 0x%02x\n", CPLD_READ(vbank));
  80. printf("sw1_sysclk = 0x%02x\n", CPLD_READ(sw1_sysclk));
  81. printf("sw2_status = 0x%02x\n", CPLD_READ(sw2_status));
  82. printf("sw3_status = 0x%02x\n", CPLD_READ(sw3_status));
  83. printf("sw4_status = 0x%02x\n", CPLD_READ(sw4_status));
  84. printf("sys_reset = 0x%02x\n", CPLD_READ(sys_reset));
  85. printf("global_reset = 0x%02x\n", CPLD_READ(global_reset));
  86. printf("res1 = 0x%02x\n", CPLD_READ(res1));
  87. putc('\n');
  88. }
  89. #endif
  90. #ifndef CONFIG_SPL_BUILD
  91. int do_cpld(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  92. {
  93. int rc = 0;
  94. if (argc <= 1)
  95. return cmd_usage(cmdtp);
  96. if (strcmp(argv[1], "reset") == 0) {
  97. if (strcmp(argv[2], "altbank") == 0)
  98. cpld_set_altbank();
  99. else
  100. cpld_set_defbank();
  101. #ifdef DEBUG
  102. } else if (strcmp(argv[1], "dump") == 0) {
  103. cpld_dump_regs();
  104. #endif
  105. } else
  106. rc = cmd_usage(cmdtp);
  107. return rc;
  108. }
  109. U_BOOT_CMD(
  110. cpld, CONFIG_SYS_MAXARGS, 1, do_cpld,
  111. "Reset the board or alternate bank",
  112. "reset - reset to default bank\n"
  113. "cpld reset altbank - reset to alternate bank\n"
  114. #ifdef DEBUG
  115. "cpld dump - display the CPLD registers\n"
  116. #endif
  117. );
  118. #endif