2 * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
4 * Developed for DENX Software Engineering GmbH
6 * SPDX-License-Identifier: GPL-2.0+
11 /* There are two tests for dsPIC currently implemented:
12 * 1. dsPIC ready test. Done in board_early_init_f(). Only result verified here.
13 * 2. dsPIC POST result test. This test gets dsPIC POST codes and version.
21 DECLARE_GLOBAL_DATA_PTR
;
23 #define DSPIC_POST_ERROR_REG 0x800
24 #define DSPIC_SYS_ERROR_REG 0x802
25 #define DSPIC_SYS_VERSION_REG 0x804
26 #define DSPIC_FW_VERSION_REG 0x808
28 #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
30 /* Verify that dsPIC ready test done early at hw init passed ok */
31 int dspic_init_post_test(int flags
)
33 if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR
) &
34 CONFIG_SYS_DSPIC_TEST_MASK
) {
35 post_log("dsPIC init test failed\n");
42 #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */
44 #if CONFIG_POST & CONFIG_SYS_POST_BSPEC2
45 /* Read a register from the dsPIC. */
46 int dspic_read(ushort reg
, ushort
*data
)
48 uchar buf
[sizeof(*data
)];
51 if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR
, reg
, 2, buf
, 2))
53 rval
= i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR
, reg
, sizeof(reg
),
55 *data
= (buf
[0] << 8) | buf
[1];
60 /* Verify error codes regs, display version */
61 int dspic_post_test(int flags
)
68 /* read dspic FW-Version */
69 if (dspic_read(DSPIC_FW_VERSION_REG
, &data
)) {
70 post_log("dsPIC: failed read FW-Version\n");
73 post_log("dsPIC FW-Version: %u.%u\n",
74 (data
>> 8) & 0xFF, data
& 0xFF);
77 /* read dspic SYS-Version */
78 if (dspic_read(DSPIC_SYS_VERSION_REG
, &data
)) {
79 post_log("dsPIC: failed read version\n");
82 post_log("dsPIC SYS-Version: %u.%u\n",
83 (data
>> 8) & 0xFF, data
& 0xFF);
86 /* read dspic POST error code */
87 if (dspic_read(DSPIC_POST_ERROR_REG
, &data
)) {
88 post_log("dsPIC: failed read POST code\n");
91 post_log("dsPIC POST-ERROR code: 0x%04X\n", data
);
94 /* read dspic SYS error code */
95 if ((data
= dspic_read(DSPIC_SYS_ERROR_REG
, &data
))) {
96 post_log("dsPIC: failed read system error\n");
99 post_log("dsPIC SYS-ERROR code: 0x%04X\n", data
);
105 #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */