cpld.c 2.5 KB

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