blob: ff2ed0566fcbf177a45066d40ac7fc57464d6b9e [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 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26
Yuri Tikhonovc147d482008-02-04 14:10:42 +010027/* There are two tests for dsPIC currently implemented:
28 * 1. dsPIC ready test. Done in board_early_init_f(). Only result verified here.
29 * 2. dsPIC POST result test. This test gets dsPIC POST codes and version.
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
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020043#if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
Yuri Tikhonovc147d482008-02-04 14:10:42 +010044
45/* Verify that dsPIC ready test done early at hw init passed ok */
46int dspic_init_post_test(int flags)
47{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020048 if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) & CONFIG_SYS_DSPIC_TEST_MASK) {
Yuri Tikhonovc147d482008-02-04 14:10:42 +010049 post_log("dsPIC init test failed\n");
50 return 1;
51 }
52
53 return 0;
54}
55
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020056#endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */
Yuri Tikhonovc147d482008-02-04 14:10:42 +010057
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020058#if CONFIG_POST & CONFIG_SYS_POST_BSPEC2
Yuri Tikhonovc147d482008-02-04 14:10:42 +010059/* Read a register from the dsPIC. */
60int dspic_read(ushort reg)
61{
62 uchar buf[2];
63
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020064 if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2))
Yuri Tikhonovc147d482008-02-04 14:10:42 +010065 return -1;
66
67 return (uint)((buf[0] << 8) | buf[1]);
68}
69
70/* Verify error codes regs, display version */
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);
Yuri Tikhonovc147d482008-02-04 14:10:42 +010095 if (data == -1) {
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 {
99 post_log("dsPIC SYS-ERROR code: 0x%04X\n", data);
100 }
101
102 return ret;
103}
104
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105#endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */