dspic.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
  3. *
  4. * Developed for DENX Software Engineering GmbH
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. /* There are two tests for dsPIC currently implemented:
  10. * 1. dsPIC ready test. Done in board_early_init_f(). Only result verified here.
  11. * 2. dsPIC POST result test. This test gets dsPIC POST codes and version.
  12. */
  13. #include <post.h>
  14. #include <i2c.h>
  15. #include <asm/io.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. #define DSPIC_POST_ERROR_REG 0x800
  18. #define DSPIC_SYS_ERROR_REG 0x802
  19. #define DSPIC_SYS_VERSION_REG 0x804
  20. #define DSPIC_FW_VERSION_REG 0x808
  21. #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
  22. /* Verify that dsPIC ready test done early at hw init passed ok */
  23. int dspic_init_post_test(int flags)
  24. {
  25. if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) &
  26. CONFIG_SYS_DSPIC_TEST_MASK) {
  27. post_log("dsPIC init test failed\n");
  28. return 1;
  29. }
  30. return 0;
  31. }
  32. #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */
  33. #if CONFIG_POST & CONFIG_SYS_POST_BSPEC2
  34. /* Read a register from the dsPIC. */
  35. int dspic_read(ushort reg, ushort *data)
  36. {
  37. uchar buf[sizeof(*data)];
  38. int rval;
  39. if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2))
  40. return -1;
  41. rval = i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, sizeof(reg),
  42. buf, sizeof(*data));
  43. *data = (buf[0] << 8) | buf[1];
  44. return rval;
  45. }
  46. /* Verify error codes regs, display version */
  47. int dspic_post_test(int flags)
  48. {
  49. ushort data;
  50. int ret = 0;
  51. post_log("\n");
  52. /* read dspic FW-Version */
  53. if (dspic_read(DSPIC_FW_VERSION_REG, &data)) {
  54. post_log("dsPIC: failed read FW-Version\n");
  55. ret = 1;
  56. } else {
  57. post_log("dsPIC FW-Version: %u.%u\n",
  58. (data >> 8) & 0xFF, data & 0xFF);
  59. }
  60. /* read dspic SYS-Version */
  61. if (dspic_read(DSPIC_SYS_VERSION_REG, &data)) {
  62. post_log("dsPIC: failed read version\n");
  63. ret = 1;
  64. } else {
  65. post_log("dsPIC SYS-Version: %u.%u\n",
  66. (data >> 8) & 0xFF, data & 0xFF);
  67. }
  68. /* read dspic POST error code */
  69. if (dspic_read(DSPIC_POST_ERROR_REG, &data)) {
  70. post_log("dsPIC: failed read POST code\n");
  71. ret = 1;
  72. } else {
  73. post_log("dsPIC POST-ERROR code: 0x%04X\n", data);
  74. }
  75. /* read dspic SYS error code */
  76. if ((data = dspic_read(DSPIC_SYS_ERROR_REG, &data))) {
  77. post_log("dsPIC: failed read system error\n");
  78. ret = 1;
  79. } else {
  80. post_log("dsPIC SYS-ERROR code: 0x%04X\n", data);
  81. }
  82. return ret;
  83. }
  84. #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */