cpld.c 2.9 KB

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