dspic.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
  3. *
  4. * Developed for DENX Software Engineering GmbH
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. /* There are two tests for dsPIC currently implemented:
  26. * 1. dsPIC ready test. Done in board_early_init_f(). Only result verified here.
  27. * 2. dsPIC POST result test. This test gets dsPIC POST codes and version.
  28. */
  29. #include <post.h>
  30. #include <i2c.h>
  31. #include <asm/io.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #define DSPIC_POST_ERROR_REG 0x800
  34. #define DSPIC_SYS_ERROR_REG 0x802
  35. #define DSPIC_SYS_VERSION_REG 0x804
  36. #define DSPIC_FW_VERSION_REG 0x808
  37. #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
  38. /* Verify that dsPIC ready test done early at hw init passed ok */
  39. int dspic_init_post_test(int flags)
  40. {
  41. if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) &
  42. CONFIG_SYS_DSPIC_TEST_MASK) {
  43. post_log("dsPIC init test failed\n");
  44. return 1;
  45. }
  46. return 0;
  47. }
  48. #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */
  49. #if CONFIG_POST & CONFIG_SYS_POST_BSPEC2
  50. /* Read a register from the dsPIC. */
  51. int dspic_read(ushort reg, ushort *data)
  52. {
  53. uchar buf[sizeof(*data)];
  54. int rval;
  55. if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2))
  56. return -1;
  57. rval = i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, sizeof(reg),
  58. buf, sizeof(*data));
  59. *data = (buf[0] << 8) | buf[1];
  60. return rval;
  61. }
  62. /* Verify error codes regs, display version */
  63. int dspic_post_test(int flags)
  64. {
  65. ushort data;
  66. int ret = 0;
  67. post_log("\n");
  68. /* read dspic FW-Version */
  69. if (dspic_read(DSPIC_FW_VERSION_REG, &data)) {
  70. post_log("dsPIC: failed read FW-Version\n");
  71. ret = 1;
  72. } else {
  73. post_log("dsPIC FW-Version: %u.%u\n",
  74. (data >> 8) & 0xFF, data & 0xFF);
  75. }
  76. /* read dspic SYS-Version */
  77. if (dspic_read(DSPIC_SYS_VERSION_REG, &data)) {
  78. post_log("dsPIC: failed read version\n");
  79. ret = 1;
  80. } else {
  81. post_log("dsPIC SYS-Version: %u.%u\n",
  82. (data >> 8) & 0xFF, data & 0xFF);
  83. }
  84. /* read dspic POST error code */
  85. if (dspic_read(DSPIC_POST_ERROR_REG, &data)) {
  86. post_log("dsPIC: failed read POST code\n");
  87. ret = 1;
  88. } else {
  89. post_log("dsPIC POST-ERROR code: 0x%04X\n", data);
  90. }
  91. /* read dspic SYS error code */
  92. if ((data = dspic_read(DSPIC_SYS_ERROR_REG, &data))) {
  93. post_log("dsPIC: failed read system error\n");
  94. ret = 1;
  95. } else {
  96. post_log("dsPIC SYS-ERROR code: 0x%04X\n", data);
  97. }
  98. return ret;
  99. }
  100. #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */