blob: c5ed190227743acfb34dc00448c5077cfc70f8b8 [file] [log] [blame]
Yuri Tikhonov65b20dc2008-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 Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +01007 */
8
9#include <common.h>
10
Yuri Tikhonov65b20dc2008-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 Lauef14ae412010-08-19 09:38:56 +020025#define DSPIC_SYS_VERSION_REG 0x804
26#define DSPIC_FW_VERSION_REG 0x808
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010027
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020028#if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
Yuri Tikhonov65b20dc2008-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 Lauef14ae412010-08-19 09:38:56 +020033 if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) &
34 CONFIG_SYS_DSPIC_TEST_MASK) {
Yuri Tikhonov65b20dc2008-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020042#endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010043
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020044#if CONFIG_POST & CONFIG_SYS_POST_BSPEC2
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010045/* Read a register from the dsPIC. */
Sascha Lauef14ae412010-08-19 09:38:56 +020046int dspic_read(ushort reg, ushort *data)
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010047{
Sascha Lauef14ae412010-08-19 09:38:56 +020048 uchar buf[sizeof(*data)];
49 int rval;
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010050
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020051 if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2))
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010052 return -1;
Sascha Lauef14ae412010-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 Tikhonov65b20dc2008-02-04 14:10:42 +010056
Sascha Lauef14ae412010-08-19 09:38:56 +020057 return rval;
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010058}
59
60/* Verify error codes regs, display version */
61int dspic_post_test(int flags)
62{
Sascha Lauef14ae412010-08-19 09:38:56 +020063 ushort data;
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010064 int ret = 0;
65
66 post_log("\n");
Sascha Lauef14ae412010-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");
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010071 ret = 1;
72 } else {
Sascha Lauef14ae412010-08-19 09:38:56 +020073 post_log("dsPIC FW-Version: %u.%u\n",
74 (data >> 8) & 0xFF, data & 0xFF);
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010075 }
76
Sascha Lauef14ae412010-08-19 09:38:56 +020077 /* read dspic SYS-Version */
78 if (dspic_read(DSPIC_SYS_VERSION_REG, &data)) {
79 post_log("dsPIC: failed read version\n");
Yuri Tikhonov603f1942008-02-04 17:09:55 +010080 ret = 1;
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +010081 } else {
Sascha Lauef14ae412010-08-19 09:38:56 +020082 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);
Yuri Tikhonov65b20dc2008-02-04 14:10:42 +0100100 }
101
102 return ret;
103}
104
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200105#endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */