Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com |
| 3 | * |
| 4 | * Developed for DENX Software Engineering GmbH |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 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 |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 25 | #define DSPIC_SYS_VERSION_REG 0x804 |
| 26 | #define DSPIC_FW_VERSION_REG 0x808 |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 27 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 28 | #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1 |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 29 | |
| 30 | /* Verify that dsPIC ready test done early at hw init passed ok */ |
| 31 | int dspic_init_post_test(int flags) |
| 32 | { |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 33 | if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) & |
| 34 | CONFIG_SYS_DSPIC_TEST_MASK) { |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 35 | post_log("dsPIC init test failed\n"); |
| 36 | return 1; |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */ |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 43 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | #if CONFIG_POST & CONFIG_SYS_POST_BSPEC2 |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 45 | /* Read a register from the dsPIC. */ |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 46 | int dspic_read(ushort reg, ushort *data) |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 47 | { |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 48 | uchar buf[sizeof(*data)]; |
| 49 | int rval; |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 50 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 51 | if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2)) |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 52 | return -1; |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 53 | rval = i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, sizeof(reg), |
| 54 | buf, sizeof(*data)); |
| 55 | *data = (buf[0] << 8) | buf[1]; |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 56 | |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 57 | return rval; |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* Verify error codes regs, display version */ |
| 61 | int dspic_post_test(int flags) |
| 62 | { |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 63 | ushort data; |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 64 | int ret = 0; |
| 65 | |
| 66 | post_log("\n"); |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 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"); |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 80 | ret = 1; |
| 81 | } else { |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 82 | post_log("dsPIC SYS-Version: %u.%u\n", |
| 83 | (data >> 8) & 0xFF, data & 0xFF); |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 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; |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 90 | } else { |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 91 | post_log("dsPIC POST-ERROR code: 0x%04X\n", data); |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 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"); |
Yuri Tikhonov | aacbc73 | 2008-02-04 17:09:55 +0100 | [diff] [blame] | 97 | ret = 1; |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 98 | } else { |
Sascha Laue | 249310a | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 99 | post_log("dsPIC SYS-ERROR code: 0x%04X\n", data); |
Yuri Tikhonov | c147d48 | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | return ret; |
| 103 | } |
| 104 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 105 | #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */ |