blob: d5207507037163cdb6ec0768046528d5abad824c [file] [log] [blame]
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +09001/*
2 * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +09005 */
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 Iwamatsu0d53a472008-08-31 22:45:08 +090023static void test_pld(void)
24{
25 printf("PLD version = %04x\n", readb(PLD_VERSR));
26}
27
28static void test_sm107(void)
29{
30 printf("SM107 device ID = %04x\n", readl(SM107_DEVICEID));
31}
32
33static void test_led(void)
34{
35 printf("turn on LEDs 3, 5, 7, 9\n");
36 writeb(0x55, PLD_LEDCR);
Mike Frysinger5b84dd62012-03-05 13:47:00 +000037 mdelay(2000);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090038 printf("turn on LEDs 4, 6, 8, 10\n");
39 writeb(0xaa, PLD_LEDCR);
Mike Frysinger5b84dd62012-03-05 13:47:00 +000040 mdelay(2000);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090041 writeb(0x00, PLD_LEDCR);
42}
43
44static 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
59static 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 Iwamatsub5d10a12008-09-18 19:34:36 +090068 printf("Ethernet NG, data = %08x\n", (unsigned int)data);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090069}
70
71static 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 Iwamatsub5d10a12008-09-18 19:34:36 +090080 printf("SATA NG, data = %08x\n", (unsigned int)data);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090081}
82
83static 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 Denk54841ab2010-06-28 22:00:46 +020092int do_hw_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090093{
94 char *cmd;
95
Wolfgang Denk47e26b12010-07-17 01:06:04 +020096 if (argc != 2)
97 return cmd_usage(cmdtp);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090098
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 Denk47e26b12010-07-17 01:06:04 +0200132 return cmd_usage(cmdtp);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +0900133 }
134
135 return 0;
136}
137
138U_BOOT_CMD(
139 hwtest, 2, 1, do_hw_test,
Peter Tyser2fb26042009-01-27 18:03:12 -0600140 "hardware test for R0P7785LC0011RL board",
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +0900141 "\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 Denka89c33d2009-05-24 17:06:54 +0200149 "hwtest pci - output PCI slot device ID"
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +0900150);