Yuri Tikhonov | 65b20dc | 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 | * |
| 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 Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 27 | /* 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 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
| 39 | #define DSPIC_POST_ERROR_REG 0x800 |
| 40 | #define DSPIC_SYS_ERROR_REG 0x802 |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 41 | #define DSPIC_SYS_VERSION_REG 0x804 |
| 42 | #define DSPIC_FW_VERSION_REG 0x808 |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 43 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1 |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 45 | |
| 46 | /* Verify that dsPIC ready test done early at hw init passed ok */ |
| 47 | int dspic_init_post_test(int flags) |
| 48 | { |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 49 | if (in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) & |
| 50 | CONFIG_SYS_DSPIC_TEST_MASK) { |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 51 | post_log("dsPIC init test failed\n"); |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 58 | #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC1 */ |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 59 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 60 | #if CONFIG_POST & CONFIG_SYS_POST_BSPEC2 |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 61 | /* Read a register from the dsPIC. */ |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 62 | int dspic_read(ushort reg, ushort *data) |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 63 | { |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 64 | uchar buf[sizeof(*data)]; |
| 65 | int rval; |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 66 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 67 | if (i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, 2, buf, 2)) |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 68 | return -1; |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 69 | rval = i2c_read(CONFIG_SYS_I2C_DSPIC_IO_ADDR, reg, sizeof(reg), |
| 70 | buf, sizeof(*data)); |
| 71 | *data = (buf[0] << 8) | buf[1]; |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 72 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 73 | return rval; |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /* Verify error codes regs, display version */ |
| 77 | int dspic_post_test(int flags) |
| 78 | { |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 79 | ushort data; |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 80 | int ret = 0; |
| 81 | |
| 82 | post_log("\n"); |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 83 | |
| 84 | /* read dspic FW-Version */ |
| 85 | if (dspic_read(DSPIC_FW_VERSION_REG, &data)) { |
| 86 | post_log("dsPIC: failed read FW-Version\n"); |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 87 | ret = 1; |
| 88 | } else { |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 89 | post_log("dsPIC FW-Version: %u.%u\n", |
| 90 | (data >> 8) & 0xFF, data & 0xFF); |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 91 | } |
| 92 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 93 | /* read dspic SYS-Version */ |
| 94 | if (dspic_read(DSPIC_SYS_VERSION_REG, &data)) { |
| 95 | post_log("dsPIC: failed read version\n"); |
Yuri Tikhonov | 603f194 | 2008-02-04 17:09:55 +0100 | [diff] [blame] | 96 | ret = 1; |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 97 | } else { |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 98 | post_log("dsPIC SYS-Version: %u.%u\n", |
| 99 | (data >> 8) & 0xFF, data & 0xFF); |
| 100 | } |
| 101 | |
| 102 | /* read dspic POST error code */ |
| 103 | if (dspic_read(DSPIC_POST_ERROR_REG, &data)) { |
| 104 | post_log("dsPIC: failed read POST code\n"); |
| 105 | ret = 1; |
| 106 | } else { |
| 107 | post_log("dsPIC POST-ERROR code: 0x%04X\n", data); |
| 108 | } |
| 109 | |
| 110 | /* read dspic SYS error code */ |
| 111 | if ((data = dspic_read(DSPIC_SYS_ERROR_REG, &data))) { |
| 112 | post_log("dsPIC: failed read system error\n"); |
| 113 | ret = 1; |
| 114 | } else { |
| 115 | post_log("dsPIC SYS-ERROR code: 0x%04X\n", data); |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | return ret; |
| 119 | } |
| 120 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 121 | #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC2 */ |