cpld.c 3.4 KB

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