cpld.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /**
  3. * Copyright 2013 Freescale Semiconductor
  4. * Author: Mingkai Hu <Mingkai.hu@freescale.com>
  5. * Po Liu <Po.Liu@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. /**
  21. * Set the boot bank to the alternate bank
  22. */
  23. void cpld_set_altbank(u8 banksel)
  24. {
  25. struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
  26. u8 reg11;
  27. reg11 = in_8(&cpld_data->flhcsr);
  28. switch (banksel) {
  29. case 1:
  30. out_8(&cpld_data->flhcsr, (reg11 & CPLD_BANKSEL_MASK)
  31. | CPLD_BANKSEL_EN | CPLD_SELECT_BANK1);
  32. break;
  33. case 2:
  34. out_8(&cpld_data->flhcsr, (reg11 & CPLD_BANKSEL_MASK)
  35. | CPLD_BANKSEL_EN | CPLD_SELECT_BANK2);
  36. break;
  37. case 3:
  38. out_8(&cpld_data->flhcsr, (reg11 & CPLD_BANKSEL_MASK)
  39. | CPLD_BANKSEL_EN | CPLD_SELECT_BANK3);
  40. break;
  41. case 4:
  42. out_8(&cpld_data->flhcsr, (reg11 & CPLD_BANKSEL_MASK)
  43. | CPLD_BANKSEL_EN | CPLD_SELECT_BANK4);
  44. break;
  45. default:
  46. printf("Invalid value! [1-4]\n");
  47. return;
  48. }
  49. udelay(100);
  50. do_reset(NULL, 0, 0, NULL);
  51. }
  52. /**
  53. * Set the boot bank to the default bank
  54. */
  55. void cpld_set_defbank(void)
  56. {
  57. cpld_set_altbank(4);
  58. }
  59. #ifdef DEBUG
  60. static void cpld_dump_regs(void)
  61. {
  62. struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
  63. printf("chipid1 = 0x%02x\n", in_8(&cpld_data->chipid1));
  64. printf("chipid2 = 0x%02x\n", in_8(&cpld_data->chipid2));
  65. printf("hwver = 0x%02x\n", in_8(&cpld_data->hwver));
  66. printf("cpldver = 0x%02x\n", in_8(&cpld_data->cpldver));
  67. printf("rstcon = 0x%02x\n", in_8(&cpld_data->rstcon));
  68. printf("flhcsr = 0x%02x\n", in_8(&cpld_data->flhcsr));
  69. printf("wdcsr = 0x%02x\n", in_8(&cpld_data->wdcsr));
  70. printf("wdkick = 0x%02x\n", in_8(&cpld_data->wdkick));
  71. printf("fancsr = 0x%02x\n", in_8(&cpld_data->fancsr));
  72. printf("ledcsr = 0x%02x\n", in_8(&cpld_data->ledcsr));
  73. printf("misc = 0x%02x\n", in_8(&cpld_data->misccsr));
  74. printf("bootor = 0x%02x\n", in_8(&cpld_data->bootor));
  75. printf("bootcfg1 = 0x%02x\n", in_8(&cpld_data->bootcfg1));
  76. printf("bootcfg2 = 0x%02x\n", in_8(&cpld_data->bootcfg2));
  77. printf("bootcfg3 = 0x%02x\n", in_8(&cpld_data->bootcfg3));
  78. printf("bootcfg4 = 0x%02x\n", in_8(&cpld_data->bootcfg4));
  79. putc('\n');
  80. }
  81. #endif
  82. #ifndef CONFIG_SPL_BUILD
  83. int cpld_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  84. {
  85. int rc = 0;
  86. unsigned char value;
  87. if (argc <= 1)
  88. return cmd_usage(cmdtp);
  89. if (strcmp(argv[1], "reset") == 0) {
  90. if (!strcmp(argv[2], "altbank") && argv[3]) {
  91. value = (u8)simple_strtoul(argv[3], NULL, 16);
  92. cpld_set_altbank(value);
  93. } else if (!argv[2])
  94. cpld_set_defbank();
  95. else
  96. cmd_usage(cmdtp);
  97. #ifdef DEBUG
  98. } else if (strcmp(argv[1], "dump") == 0) {
  99. cpld_dump_regs();
  100. #endif
  101. } else
  102. rc = cmd_usage(cmdtp);
  103. return rc;
  104. }
  105. U_BOOT_CMD(
  106. cpld_cmd, CONFIG_SYS_MAXARGS, 1, cpld_cmd,
  107. "Reset the board using the CPLD sequencer",
  108. "reset - hard reset to default bank 4\n"
  109. "cpld_cmd reset altbank [bank]- reset to alternate bank\n"
  110. " - [bank] bank value select 1-4\n"
  111. " - bank 1 on the flash 0x0000000~0x0ffffff\n"
  112. " - bank 2 on the flash 0x1000000~0x1ffffff\n"
  113. " - bank 3 on the flash 0x2000000~0x2ffffff\n"
  114. " - bank 4 on the flash 0x3000000~0x3ffffff\n"
  115. #ifdef DEBUG
  116. "cpld_cmd dump - display the CPLD registers\n"
  117. #endif
  118. );
  119. #endif