blob: 9a6cdab9ee5b633d2bdf6b7ec0d90fa5cc1c3724 [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>
Simon Glass24b852a2015-11-08 23:47:45 -07008#include <console.h>
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +09009#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 Iwamatsu0d53a472008-08-31 22:45:08 +090024static void test_pld(void)
25{
26 printf("PLD version = %04x\n", readb(PLD_VERSR));
27}
28
29static void test_sm107(void)
30{
31 printf("SM107 device ID = %04x\n", readl(SM107_DEVICEID));
32}
33
34static void test_led(void)
35{
36 printf("turn on LEDs 3, 5, 7, 9\n");
37 writeb(0x55, PLD_LEDCR);
Mike Frysinger5b84dd62012-03-05 13:47:00 +000038 mdelay(2000);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090039 printf("turn on LEDs 4, 6, 8, 10\n");
40 writeb(0xaa, PLD_LEDCR);
Mike Frysinger5b84dd62012-03-05 13:47:00 +000041 mdelay(2000);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090042 writeb(0x00, PLD_LEDCR);
43}
44
45static 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
60static 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 Iwamatsub5d10a12008-09-18 19:34:36 +090069 printf("Ethernet NG, data = %08x\n", (unsigned int)data);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090070}
71
72static 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 Iwamatsub5d10a12008-09-18 19:34:36 +090081 printf("SATA NG, data = %08x\n", (unsigned int)data);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090082}
83
84static 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 Denk54841ab2010-06-28 22:00:46 +020093int do_hw_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090094{
95 char *cmd;
96
Wolfgang Denk47e26b12010-07-17 01:06:04 +020097 if (argc != 2)
98 return cmd_usage(cmdtp);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +090099
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 Denk47e26b12010-07-17 01:06:04 +0200133 return cmd_usage(cmdtp);
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +0900134 }
135
136 return 0;
137}
138
139U_BOOT_CMD(
140 hwtest, 2, 1, do_hw_test,
Peter Tyser2fb26042009-01-27 18:03:12 -0600141 "hardware test for R0P7785LC0011RL board",
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +0900142 "\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 Denka89c33d2009-05-24 17:06:54 +0200150 "hwtest pci - output PCI slot device ID"
Nobuhiro Iwamatsu0d53a472008-08-31 22:45:08 +0900151);