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