Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation; either version 2 of |
| 7 | * the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 17 | * MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | #include <common.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/processor.h> |
| 23 | #include <asm/pci.h> |
| 24 | |
| 25 | #if defined(CONFIG_CPU_32BIT) |
| 26 | #define NOCACHE_OFFSET 0x00000000 |
| 27 | #else |
| 28 | #define NOCACHE_OFFSET 0xa0000000 |
| 29 | #endif |
| 30 | #define PLD_LEDCR (0x04000008 + NOCACHE_OFFSET) |
| 31 | #define PLD_SWSR (0x0400000a + NOCACHE_OFFSET) |
| 32 | #define PLD_VERSR (0x0400000c + NOCACHE_OFFSET) |
| 33 | |
| 34 | #define SM107_DEVICEID (0x13e00060 + NOCACHE_OFFSET) |
| 35 | |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 36 | static void test_pld(void) |
| 37 | { |
| 38 | printf("PLD version = %04x\n", readb(PLD_VERSR)); |
| 39 | } |
| 40 | |
| 41 | static void test_sm107(void) |
| 42 | { |
| 43 | printf("SM107 device ID = %04x\n", readl(SM107_DEVICEID)); |
| 44 | } |
| 45 | |
| 46 | static void test_led(void) |
| 47 | { |
| 48 | printf("turn on LEDs 3, 5, 7, 9\n"); |
| 49 | writeb(0x55, PLD_LEDCR); |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame^] | 50 | mdelay(2000); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 51 | printf("turn on LEDs 4, 6, 8, 10\n"); |
| 52 | writeb(0xaa, PLD_LEDCR); |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame^] | 53 | mdelay(2000); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 54 | writeb(0x00, PLD_LEDCR); |
| 55 | } |
| 56 | |
| 57 | static void test_dipsw(void) |
| 58 | { |
| 59 | printf("Please DIPSW set = B'0101\n"); |
| 60 | while (readb(PLD_SWSR) != 0x05) { |
| 61 | if (ctrlc()) |
| 62 | return; |
| 63 | } |
| 64 | printf("Please DIPSW set = B'1010\n"); |
| 65 | while (readb(PLD_SWSR) != 0x0A) { |
| 66 | if (ctrlc()) |
| 67 | return; |
| 68 | } |
| 69 | printf("DIPSW OK\n"); |
| 70 | } |
| 71 | |
| 72 | static void test_net(void) |
| 73 | { |
| 74 | unsigned long data; |
| 75 | |
| 76 | writel(0x80000000, 0xfe0401c0); |
| 77 | data = readl(0xfe040220); |
| 78 | if (data == 0x816910ec) |
| 79 | printf("Ethernet OK\n"); |
| 80 | else |
Nobuhiro Iwamatsu | b5d10a1 | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 81 | printf("Ethernet NG, data = %08x\n", (unsigned int)data); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static void test_sata(void) |
| 85 | { |
| 86 | unsigned long data; |
| 87 | |
| 88 | writel(0x80000800, 0xfe0401c0); |
| 89 | data = readl(0xfe040220); |
| 90 | if (data == 0x35121095) |
| 91 | printf("SATA OK\n"); |
| 92 | else |
Nobuhiro Iwamatsu | b5d10a1 | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 93 | printf("SATA NG, data = %08x\n", (unsigned int)data); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static void test_pci(void) |
| 97 | { |
| 98 | writel(0x80001800, 0xfe0401c0); |
| 99 | printf("PCI CN1 ID = %08x\n", readl(0xfe040220)); |
| 100 | |
| 101 | writel(0x80001000, 0xfe0401c0); |
| 102 | printf("PCI CN2 ID = %08x\n", readl(0xfe040220)); |
| 103 | } |
| 104 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 105 | int do_hw_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 106 | { |
| 107 | char *cmd; |
| 108 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 109 | if (argc != 2) |
| 110 | return cmd_usage(cmdtp); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 111 | |
| 112 | cmd = argv[1]; |
| 113 | switch (cmd[0]) { |
| 114 | case 'a': /* all */ |
| 115 | test_pld(); |
| 116 | test_led(); |
| 117 | test_dipsw(); |
| 118 | test_sm107(); |
| 119 | test_net(); |
| 120 | test_sata(); |
| 121 | test_pci(); |
| 122 | break; |
| 123 | case 'p': /* pld or pci */ |
| 124 | if (cmd[1] == 'l') |
| 125 | test_pld(); |
| 126 | else |
| 127 | test_pci(); |
| 128 | break; |
| 129 | case 'l': /* led */ |
| 130 | test_led(); |
| 131 | break; |
| 132 | case 'd': /* dipsw */ |
| 133 | test_dipsw(); |
| 134 | break; |
| 135 | case 's': /* sm107 or sata */ |
| 136 | if (cmd[1] == 'm') |
| 137 | test_sm107(); |
| 138 | else |
| 139 | test_sata(); |
| 140 | break; |
| 141 | case 'n': /* net */ |
| 142 | test_net(); |
| 143 | break; |
| 144 | default: |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 145 | return cmd_usage(cmdtp); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | U_BOOT_CMD( |
| 152 | hwtest, 2, 1, do_hw_test, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 153 | "hardware test for R0P7785LC0011RL board", |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 154 | "\n" |
| 155 | "hwtest all - test all hardware\n" |
| 156 | "hwtest pld - output PLD version\n" |
| 157 | "hwtest led - turn on LEDs\n" |
| 158 | "hwtest dipsw - test DIP switch\n" |
| 159 | "hwtest sm107 - output SM107 version\n" |
| 160 | "hwtest net - check RTL8110 ID\n" |
| 161 | "hwtest sata - check SiI3512 ID\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 162 | "hwtest pci - output PCI slot device ID" |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 163 | ); |