cpld.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Copyright 2014 Freescale Semiconductor
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. *
  6. * This file provides support for the board-specific CPLD used on some Freescale
  7. * reference boards.
  8. *
  9. * The following macros need to be defined:
  10. *
  11. * CONFIG_SYS_CPLD_BASE-The virtual address of the base of the CPLD register map
  12. */
  13. #include <common.h>
  14. #include <command.h>
  15. #include <asm/io.h>
  16. #include "cpld.h"
  17. u8 cpld_read(unsigned int reg)
  18. {
  19. void *p = (void *)CONFIG_SYS_CPLD_BASE;
  20. return in_8(p + reg);
  21. }
  22. void cpld_write(unsigned int reg, u8 value)
  23. {
  24. void *p = (void *)CONFIG_SYS_CPLD_BASE;
  25. out_8(p + reg, value);
  26. }
  27. /**
  28. * Set the boot bank to the alternate bank
  29. */
  30. void cpld_set_altbank(void)
  31. {
  32. u8 reg = CPLD_READ(flash_ctl_status);
  33. reg = (reg & ~CPLD_BANK_SEL_MASK) | CPLD_LBMAP_ALTBANK;
  34. CPLD_WRITE(flash_ctl_status, reg);
  35. CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET);
  36. }
  37. /**
  38. * Set the boot bank to the default bank
  39. */
  40. void cpld_set_defbank(void)
  41. {
  42. u8 reg = CPLD_READ(flash_ctl_status);
  43. reg = (reg & ~CPLD_BANK_SEL_MASK) | CPLD_LBMAP_DFLTBANK;
  44. CPLD_WRITE(flash_ctl_status, reg);
  45. CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET);
  46. }
  47. #ifdef DEBUG
  48. static void cpld_dump_regs(void)
  49. {
  50. printf("cpld_ver = 0x%02x\n", CPLD_READ(cpld_ver));
  51. printf("cpld_ver_sub = 0x%02x\n", CPLD_READ(cpld_ver_sub));
  52. printf("hw_ver = 0x%02x\n", CPLD_READ(hw_ver));
  53. printf("sw_ver = 0x%02x\n", CPLD_READ(sw_ver));
  54. printf("reset_ctl1 = 0x%02x\n", CPLD_READ(reset_ctl1));
  55. printf("reset_ctl2 = 0x%02x\n", CPLD_READ(reset_ctl2));
  56. printf("int_status = 0x%02x\n", CPLD_READ(int_status));
  57. printf("flash_ctl_status = 0x%02x\n", CPLD_READ(flash_ctl_status));
  58. printf("fan_ctl_status = 0x%02x\n", CPLD_READ(fan_ctl_status));
  59. #if defined(CONFIG_TARGET_T1040D4D4RDB) || defined(CONFIG_TARGET_T1042D4RDB)
  60. printf("int_mask = 0x%02x\n", CPLD_READ(int_mask));
  61. #else
  62. printf("led_ctl_status = 0x%02x\n", CPLD_READ(led_ctl_status));
  63. #endif
  64. printf("sfp_ctl_status = 0x%02x\n", CPLD_READ(sfp_ctl_status));
  65. printf("misc_ctl_status = 0x%02x\n", CPLD_READ(misc_ctl_status));
  66. printf("boot_override = 0x%02x\n", CPLD_READ(boot_override));
  67. printf("boot_config1 = 0x%02x\n", CPLD_READ(boot_config1));
  68. printf("boot_config2 = 0x%02x\n", CPLD_READ(boot_config2));
  69. putc('\n');
  70. }
  71. #endif
  72. int do_cpld(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  73. {
  74. int rc = 0;
  75. if (argc <= 1)
  76. return cmd_usage(cmdtp);
  77. if (strcmp(argv[1], "reset") == 0) {
  78. if (strcmp(argv[2], "altbank") == 0)
  79. cpld_set_altbank();
  80. else
  81. cpld_set_defbank();
  82. #ifdef DEBUG
  83. } else if (strcmp(argv[1], "dump") == 0) {
  84. cpld_dump_regs();
  85. #endif
  86. } else
  87. rc = cmd_usage(cmdtp);
  88. return rc;
  89. }
  90. U_BOOT_CMD(
  91. cpld, CONFIG_SYS_MAXARGS, 1, do_cpld,
  92. "Reset the board or alternate bank",
  93. "reset - hard reset to default bank\n"
  94. "cpld reset altbank - reset to alternate bank\n"
  95. #ifdef DEBUG
  96. "cpld dump - display the CPLD registers\n"
  97. #endif
  98. );