Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / u-boot / post / board / lwmon5 / dspic.c
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
9 #include <common.h>
10
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.
14  */
15
16 #include <post.h>
17
18 #include <i2c.h>
19 #include <asm/io.h>
20
21 DECLARE_GLOBAL_DATA_PTR;
22
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
27
28 #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
29
30 /* Verify that dsPIC ready test done early at hw init passed ok */
31 int dspic_init_post_test(int flags)
32 {
33         if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) &
34             CONFIG_SYS_DSPIC_TEST_MASK) {
35                 post_log("dsPIC init test failed\n");
36                 return 1;
37         }
38
39         return 0;
40 }
41
42 #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */
43
44 #if CONFIG_POST & CONFIG_SYS_POST_BSPEC2
45 /* Read a register from the dsPIC. */
46 int dspic_read(ushort reg, ushort *data)
47 {
48         uchar buf[sizeof(*data)];
49         int rval;
50
51         if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2))
52                 return -1;
53         rval = i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, sizeof(reg),
54                         buf, sizeof(*data));
55         *data = (buf[0] << 8) | buf[1];
56
57         return rval;
58 }
59
60 /* Verify error codes regs, display version */
61 int dspic_post_test(int flags)
62 {
63         ushort data;
64         int ret = 0;
65
66         post_log("\n");
67
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
77         /* read dspic SYS-Version */
78         if (dspic_read(DSPIC_SYS_VERSION_REG, &data)) {
79                 post_log("dsPIC: failed read version\n");
80                 ret = 1;
81         } else {
82                 post_log("dsPIC SYS-Version: %u.%u\n",
83                          (data >> 8) & 0xFF, data & 0xFF);
84         }
85
86         /* read dspic POST error code */
87         if (dspic_read(DSPIC_POST_ERROR_REG, &data)) {
88                 post_log("dsPIC: failed read POST code\n");
89                 ret = 1;
90         } else {
91                 post_log("dsPIC POST-ERROR   code:  0x%04X\n", data);
92         }
93
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");
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 /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */