Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/processor.h> |
| 10 | #include <asm/pci.h> |
| 11 | |
| 12 | #if defined(CONFIG_CPU_32BIT) |
| 13 | #define NOCACHE_OFFSET 0x00000000 |
| 14 | #else |
| 15 | #define NOCACHE_OFFSET 0xa0000000 |
| 16 | #endif |
| 17 | #define PLD_LEDCR (0x04000008 + NOCACHE_OFFSET) |
| 18 | #define PLD_SWSR (0x0400000a + NOCACHE_OFFSET) |
| 19 | #define PLD_VERSR (0x0400000c + NOCACHE_OFFSET) |
| 20 | |
| 21 | #define SM107_DEVICEID (0x13e00060 + NOCACHE_OFFSET) |
| 22 | |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 23 | static void test_pld(void) |
| 24 | { |
| 25 | printf("PLD version = %04x\n", readb(PLD_VERSR)); |
| 26 | } |
| 27 | |
| 28 | static void test_sm107(void) |
| 29 | { |
| 30 | printf("SM107 device ID = %04x\n", readl(SM107_DEVICEID)); |
| 31 | } |
| 32 | |
| 33 | static void test_led(void) |
| 34 | { |
| 35 | printf("turn on LEDs 3, 5, 7, 9\n"); |
| 36 | writeb(0x55, PLD_LEDCR); |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 37 | mdelay(2000); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 38 | printf("turn on LEDs 4, 6, 8, 10\n"); |
| 39 | writeb(0xaa, PLD_LEDCR); |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 40 | mdelay(2000); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 41 | writeb(0x00, PLD_LEDCR); |
| 42 | } |
| 43 | |
| 44 | static void test_dipsw(void) |
| 45 | { |
| 46 | printf("Please DIPSW set = B'0101\n"); |
| 47 | while (readb(PLD_SWSR) != 0x05) { |
| 48 | if (ctrlc()) |
| 49 | return; |
| 50 | } |
| 51 | printf("Please DIPSW set = B'1010\n"); |
| 52 | while (readb(PLD_SWSR) != 0x0A) { |
| 53 | if (ctrlc()) |
| 54 | return; |
| 55 | } |
| 56 | printf("DIPSW OK\n"); |
| 57 | } |
| 58 | |
| 59 | static void test_net(void) |
| 60 | { |
| 61 | unsigned long data; |
| 62 | |
| 63 | writel(0x80000000, 0xfe0401c0); |
| 64 | data = readl(0xfe040220); |
| 65 | if (data == 0x816910ec) |
| 66 | printf("Ethernet OK\n"); |
| 67 | else |
Nobuhiro Iwamatsu | b5d10a1 | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 68 | printf("Ethernet NG, data = %08x\n", (unsigned int)data); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void test_sata(void) |
| 72 | { |
| 73 | unsigned long data; |
| 74 | |
| 75 | writel(0x80000800, 0xfe0401c0); |
| 76 | data = readl(0xfe040220); |
| 77 | if (data == 0x35121095) |
| 78 | printf("SATA OK\n"); |
| 79 | else |
Nobuhiro Iwamatsu | b5d10a1 | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 80 | printf("SATA NG, data = %08x\n", (unsigned int)data); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static void test_pci(void) |
| 84 | { |
| 85 | writel(0x80001800, 0xfe0401c0); |
| 86 | printf("PCI CN1 ID = %08x\n", readl(0xfe040220)); |
| 87 | |
| 88 | writel(0x80001000, 0xfe0401c0); |
| 89 | printf("PCI CN2 ID = %08x\n", readl(0xfe040220)); |
| 90 | } |
| 91 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 92 | 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] | 93 | { |
| 94 | char *cmd; |
| 95 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 96 | if (argc != 2) |
| 97 | return cmd_usage(cmdtp); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 98 | |
| 99 | cmd = argv[1]; |
| 100 | switch (cmd[0]) { |
| 101 | case 'a': /* all */ |
| 102 | test_pld(); |
| 103 | test_led(); |
| 104 | test_dipsw(); |
| 105 | test_sm107(); |
| 106 | test_net(); |
| 107 | test_sata(); |
| 108 | test_pci(); |
| 109 | break; |
| 110 | case 'p': /* pld or pci */ |
| 111 | if (cmd[1] == 'l') |
| 112 | test_pld(); |
| 113 | else |
| 114 | test_pci(); |
| 115 | break; |
| 116 | case 'l': /* led */ |
| 117 | test_led(); |
| 118 | break; |
| 119 | case 'd': /* dipsw */ |
| 120 | test_dipsw(); |
| 121 | break; |
| 122 | case 's': /* sm107 or sata */ |
| 123 | if (cmd[1] == 'm') |
| 124 | test_sm107(); |
| 125 | else |
| 126 | test_sata(); |
| 127 | break; |
| 128 | case 'n': /* net */ |
| 129 | test_net(); |
| 130 | break; |
| 131 | default: |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 132 | return cmd_usage(cmdtp); |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | U_BOOT_CMD( |
| 139 | hwtest, 2, 1, do_hw_test, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 140 | "hardware test for R0P7785LC0011RL board", |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 141 | "\n" |
| 142 | "hwtest all - test all hardware\n" |
| 143 | "hwtest pld - output PLD version\n" |
| 144 | "hwtest led - turn on LEDs\n" |
| 145 | "hwtest dipsw - test DIP switch\n" |
| 146 | "hwtest sm107 - output SM107 version\n" |
| 147 | "hwtest net - check RTL8110 ID\n" |
| 148 | "hwtest sata - check SiI3512 ID\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 149 | "hwtest pci - output PCI slot device ID" |
Nobuhiro Iwamatsu | 0d53a47 | 2008-08-31 22:45:08 +0900 | [diff] [blame] | 150 | ); |