Yuri Tikhonov | 8f15d4a | 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 | |
| 27 | #ifdef CONFIG_POST |
| 28 | |
| 29 | /* There are two tests for dsPIC currently implemented: |
| 30 | * 1. dsPIC ready test. Done in board_early_init_f(). Only result verified here. |
| 31 | * 2. dsPIC POST result test. This test gets dsPIC POST codes and version. |
| 32 | */ |
| 33 | |
| 34 | #include <post.h> |
| 35 | |
| 36 | #include <i2c.h> |
| 37 | #include <asm/io.h> |
| 38 | |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
| 41 | #define DSPIC_POST_ERROR_REG 0x800 |
| 42 | #define DSPIC_SYS_ERROR_REG 0x802 |
| 43 | #define DSPIC_VERSION_REG 0x804 |
| 44 | |
| 45 | #if CONFIG_POST & CFG_POST_BSPEC1 |
| 46 | |
| 47 | /* Verify that dsPIC ready test done early at hw init passed ok */ |
| 48 | int dspic_init_post_test(int flags) |
| 49 | { |
| 50 | if (in_be32((void *)CFG_DSPIC_TEST_ADDR) & CFG_DSPIC_TEST_MASK) { |
| 51 | post_log("dsPIC init test failed\n"); |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | #endif /* CONFIG_POST & CFG_POST_BSPEC1 */ |
| 59 | |
| 60 | #if CONFIG_POST & CFG_POST_BSPEC2 |
| 61 | /* Read a register from the dsPIC. */ |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 62 | int dspic_read(ushort reg, ushort *data) |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 63 | { |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 64 | uchar buf[sizeof(*data)]; |
| 65 | int rval; |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 66 | |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 67 | rval = i2c_read(CFG_I2C_DSPIC_IO_ADDR, reg, sizeof(reg), |
| 68 | buf, sizeof(*data)); |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 69 | |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 70 | *data = (buf[0] << 8) | buf[1]; |
| 71 | |
| 72 | return rval; |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /* Verify error codes regs, display version */ |
| 76 | int dspic_post_test(int flags) |
| 77 | { |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 78 | ushort data; |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 79 | int ret = 0; |
| 80 | |
| 81 | post_log("\n"); |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 82 | if (dspic_read(DSPIC_VERSION_REG, &data)) { |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 83 | post_log("dsPIC : failed read version\n"); |
| 84 | ret = 1; |
| 85 | } else { |
| 86 | post_log("dsPIC version: %u.%u\n", |
| 87 | (data >> 8) & 0xFF, data & 0xFF); |
| 88 | } |
| 89 | |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 90 | if (dspic_read(DSPIC_POST_ERROR_REG, &data)) { |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 91 | post_log("dsPIC : failed read POST code\n"); |
| 92 | } else { |
| 93 | post_log("dsPIC POST code 0x%04X\n", data); |
| 94 | } |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 95 | if (data != 0) |
| 96 | ret = 1; |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 97 | |
Yuri Tikhonov | ff2bdfb | 2008-03-24 11:29:14 +0100 | [diff] [blame^] | 98 | if (dspic_read(DSPIC_SYS_ERROR_REG, &data)) { |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 99 | post_log("dsPIC : failed read system error\n"); |
Yuri Tikhonov | f694e32 | 2008-02-04 17:09:55 +0100 | [diff] [blame] | 100 | ret = 1; |
Yuri Tikhonov | 86aea3e | 2008-03-21 09:18:40 +0100 | [diff] [blame] | 101 | } else if (data != 0) { |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 102 | post_log("dsPIC SYS-ERROR code: 0x%04X\n", data); |
Yuri Tikhonov | 86aea3e | 2008-03-21 09:18:40 +0100 | [diff] [blame] | 103 | ret = 1; |
Yuri Tikhonov | 8f15d4a | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | #endif /* CONFIG_POST & CFG_POST_BSPEC2 */ |
| 110 | #endif /* CONFIG_POST */ |