blob: c5ed190227743acfb34dc00448c5077cfc70f8b8 [file] [log] [blame]
Yuri Tikhonovc147d482008-02-04 14:10:42 +01001/*
2 * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
3 *
4 * Developed for DENX Software Engineering GmbH
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Yuri Tikhonovc147d482008-02-04 14:10:42 +01007 */
8
9#include <common.h>
10
Yuri Tikhonovc147d482008-02-04 14:10:42 +010011/* 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
21DECLARE_GLOBAL_DATA_PTR;
22
23#define DSPIC_POST_ERROR_REG 0x800
24#define DSPIC_SYS_ERROR_REG 0x802
Sascha Laue249310a2010-08-19 09:38:56 +020025#define DSPIC_SYS_VERSION_REG 0x804
26#define DSPIC_FW_VERSION_REG 0x808
Yuri Tikhonovc147d482008-02-04 14:10:42 +010027
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020028#if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
Yuri Tikhonovc147d482008-02-04 14:10:42 +010029
30/* Verify that dsPIC ready test done early at hw init passed ok */
31int dspic_init_post_test(int flags)
32{
Sascha Laue249310a2010-08-19 09:38:56 +020033 if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) &
34 CONFIG_SYS_DSPIC_TEST_MASK) {
Yuri Tikhonovc147d482008-02-04 14:10:42 +010035 post_log("dsPIC init test failed\n");
36 return 1;
37 }
38
39 return 0;
40}
41
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042#endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */
Yuri Tikhonovc147d482008-02-04 14:10:42 +010043
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044#if CONFIG_POST & CONFIG_SYS_POST_BSPEC2
Yuri Tikhonovc147d482008-02-04 14:10:42 +010045/* Read a register from the dsPIC. */
Sascha Laue249310a2010-08-19 09:38:56 +020046int dspic_read(ushort reg, ushort *data)
Yuri Tikhonovc147d482008-02-04 14:10:42 +010047{
Sascha Laue249310a2010-08-19 09:38:56 +020048 uchar buf[sizeof(*data)];
49 int rval;
Yuri Tikhonovc147d482008-02-04 14:10:42 +010050
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020051 if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2))
Yuri Tikhonovc147d482008-02-04 14:10:42 +010052 return -1;
Sascha Laue249310a2010-08-19 09:38:56 +020053 rval = i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, sizeof(reg),
54 buf, sizeof(*data));
55 *data = (buf[0] << 8) | buf[1];
Yuri Tikhonovc147d482008-02-04 14:10:42 +010056
Sascha Laue249310a2010-08-19 09:38:56 +020057 return rval;
Yuri Tikhonovc147d482008-02-04 14:10:42 +010058}
59
60/* Verify error codes regs, display version */
61int dspic_post_test(int flags)
62{
Sascha Laue249310a2010-08-19 09:38:56 +020063 ushort data;
Yuri Tikhonovc147d482008-02-04 14:10:42 +010064 int ret = 0;
65
66 post_log("\n");
Sascha Laue249310a2010-08-19 09:38:56 +020067
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");
Yuri Tikhonovc147d482008-02-04 14:10:42 +010080 ret = 1;
81 } else {
Sascha Laue249310a2010-08-19 09:38:56 +020082 post_log("dsPIC SYS-Version: %u.%u\n",
83 (data >> 8) & 0xFF, data & 0xFF);
Yuri Tikhonovc147d482008-02-04 14:10:42 +010084 }
85
Sascha Laue249310a2010-08-19 09:38:56 +020086 /* 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;
Yuri Tikhonovc147d482008-02-04 14:10:42 +010090 } else {
Sascha Laue249310a2010-08-19 09:38:56 +020091 post_log("dsPIC POST-ERROR code: 0x%04X\n", data);
Yuri Tikhonovc147d482008-02-04 14:10:42 +010092 }
93
Sascha Laue249310a2010-08-19 09:38:56 +020094 /* read dspic SYS error code */
95 if ((data = dspic_read(DSPIC_SYS_ERROR_REG, &data))) {
96 post_log("dsPIC: failed read system error\n");
Yuri Tikhonovaacbc732008-02-04 17:09:55 +010097 ret = 1;
Yuri Tikhonovc147d482008-02-04 14:10:42 +010098 } else {
Sascha Laue249310a2010-08-19 09:38:56 +020099 post_log("dsPIC SYS-ERROR code: 0x%04X\n", data);
Yuri Tikhonovc147d482008-02-04 14:10:42 +0100100 }
101
102 return ret;
103}
104
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105#endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */