1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <common.h>
26
27
28
29
30
31
32#include <post.h>
33
34#include <i2c.h>
35#include <asm/io.h>
36
37DECLARE_GLOBAL_DATA_PTR;
38
39#define DSPIC_POST_ERROR_REG 0x800
40#define DSPIC_SYS_ERROR_REG 0x802
41#define DSPIC_VERSION_REG 0x804
42
43#if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
44
45
46int dspic_init_post_test(int flags)
47{
48 if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) & CONFIG_SYS_DSPIC_TEST_MASK) {
49 post_log("dsPIC init test failed\n");
50 return 1;
51 }
52
53 return 0;
54}
55
56#endif
57
58#if CONFIG_POST & CONFIG_SYS_POST_BSPEC2
59
60int dspic_read(ushort reg)
61{
62 uchar buf[2];
63
64 if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2))
65 return -1;
66
67 return (uint)((buf[0] << 8) | buf[1]);
68}
69
70
71int dspic_post_test(int flags)
72{
73 int data;
74 int ret = 0;
75
76 post_log("\n");
77 data = dspic_read(DSPIC_VERSION_REG);
78 if (data == -1) {
79 post_log("dsPIC : failed read version\n");
80 ret = 1;
81 } else {
82 post_log("dsPIC version: %u.%u\n",
83 (data >> 8) & 0xFF, data & 0xFF);
84 }
85
86 data = dspic_read(DSPIC_POST_ERROR_REG);
87 if (data != 0) ret = 1;
88 if (data == -1) {
89 post_log("dsPIC : failed read POST code\n");
90 } else {
91 post_log("dsPIC POST code 0x%04X\n", data);
92 }
93
94 data = dspic_read(DSPIC_SYS_ERROR_REG);
95 if (data == -1) {
96 post_log("dsPIC : failed read system error\n");
97 ret = 1;
98 } else {
99 post_log("dsPIC SYS-ERROR code: 0x%04X\n", data);
100 }
101
102 return ret;
103}
104
105#endif
106