xref: /netbsd-src/sys/arch/ews4800mips/stand/common/device_test.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1 /*	$NetBSD: device_test.c,v 1.4 2008/04/28 20:23:18 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <lib/libsa/stand.h>
33 #include <lib/libkern/libkern.h>
34 
35 #include <machine/sbd.h>
36 #include <machine/gavar.h>
37 
38 #include "console.h"	/* zskbd_print_keyscan */
39 #include "cmd.h"
40 #include "local.h"
41 #include "common.h"
42 
43 struct ga ga;
44 
45 extern bool lance_test(void);
46 int fdd_test(void);
47 int i82589_test(void);
48 int picnic_test(void);
49 int beep_test(void);
50 int clut_test(int);
51 
52 int
cmd_ga_test(int argc,char * argp[],int interactive)53 cmd_ga_test(int argc, char *argp[], int interactive)
54 {
55 	int i;
56 
57 	switch (strtoul(argp[1], 0, 0)) {
58 	default:
59 		break;
60 	case 0:
61 		if (SBD_INFO->machine == MACHINE_TR2A)
62 			ga.flags = 0x0001;
63 		ga_init(&ga);
64 		break;
65 	case 1:
66 		for (i = 0; i < 256; i++)
67 			fb_clear(240, 240, 240, 240, i);
68 		break;
69 	case 2:
70 		ga_plane_mask_test(&ga);
71 		break;
72 	}
73 
74 	return 0;
75 }
76 
77 int
cmd_kbd_scancode(int argc,char * argp[],int interactive)78 cmd_kbd_scancode(int argc, char *argp[], int interactive)
79 {
80 
81 	if (argc < 2) {
82 		printf("ks on/off\n");
83 		return 1;
84 	}
85 
86 	if (argp[1][1] == 'n')
87 		zskbd_print_keyscan(1);
88 	else if (argp[1][1] == 'f')
89 		zskbd_print_keyscan(0);
90 
91 	return 0;
92 }
93 
94 int
cmd_ether_test(int argc,char * argp[],int interactive)95 cmd_ether_test(int argc, char *argp[], int interactive)
96 {
97 
98 	if (SBD_INFO->machine == MACHINE_TR2)
99 		i82589_test();
100 	if (SBD_INFO->machine == MACHINE_TR2A)
101 		lance_test();
102 
103 	return 0;
104 }
105 
106 int
i82589_test(void)107 i82589_test(void)
108 {
109 #define	SCP_ADDR	0xa0800000
110 #define	IEE_ADDR	((volatile uint32_t *)0xbb060000)
111 	volatile uint32_t cmd;
112 	volatile uint16_t u16;
113 	int i;
114 
115 	/* Board reset */
116 	*IEE_ADDR = 0;
117 	*IEE_ADDR = 0;
118 
119 	for (i = 0; i < 100; i++)
120 		;
121 
122 	/* Board self test */
123 	*(uint32_t *)(SCP_ADDR + 4) = 0xffffffff;
124 	cmd = (SCP_ADDR & 0x0ffffff0) | /* i82586-mode, A24-A31 are omitted */
125 	    0x1/*Self test */;
126 	cmd = (cmd << 16) | (cmd >> 16);
127 	printf("self test command 0x%x\n", cmd);
128 	*IEE_ADDR = cmd;
129 	*IEE_ADDR = cmd;
130 	for (i = 0; i < 0x60000; i++) 	/* 393216 */
131 		if ((u16 = *(volatile uint16_t *)(SCP_ADDR + 6)) == 0)
132 			break;
133 
134 	if (i != 0x60000) {
135 		printf("i82596 self test success. (loop %d)\n", i);
136 	} else {
137 		printf("i82586 self test failed.\n");
138 		return 1;
139 	}
140 
141 	u16 = *(uint16_t *)(SCP_ADDR + 4);
142 	printf("SCP_ADDR+4=0x%x\n", u16);
143 	if ((u16 & 0x103c) != 0) {
144 		printf("i82589 self test data error.\n");
145 		return 1;
146 	} else {
147 		printf("i82589 self test data OK.\n");
148 	}
149 
150 	return 0;
151 }
152 
153 int
picnic_test(void)154 picnic_test(void)
155 {
156 
157 	/* PICNIC test */
158 	printf("--------------------\n");
159 	printf("%x ", *(uint8_t *)0xbb000000); /* 0x00 */
160 	printf("%x ", *(uint8_t *)0xbb000004); /* 0xc0 */
161 	printf("%x ", *(uint8_t *)0xbb000008); /* 0x00 */
162 	printf("%x ", *(uint8_t *)0xbb000010); /* 0x01 */
163 	printf("\n");
164 	printf("%x ", *(uint8_t *)0xbb001000); /* 0x00 */
165 	printf("%x ", *(uint8_t *)0xbb001004); /* 0x00 */
166 	printf("%x ", *(uint8_t *)0xbb001008); /* 0x00 */
167 	printf("%x\n", *(uint8_t *)0xbb001010);/* 0x01 */
168 	printf("--------------------\n");
169 	*(uint8_t *)0xbb001010 = 0;
170 #if 0
171 	*(uint32_t *)0xbb060000 = 0;
172 #endif
173 	printf("--------------------\n");
174 	printf("%x ", *(uint8_t *)0xbb000000);
175 	printf("%x ", *(uint8_t *)0xbb000004);
176 	printf("%x ", *(uint8_t *)0xbb000008);
177 	printf("%x ", *(uint8_t *)0xbb000010);
178 	printf("\n");
179 	printf("%x ", *(uint8_t *)0xbb001000);
180 	printf("%x ", *(uint8_t *)0xbb001004);
181 	printf("%x ", *(uint8_t *)0xbb001008);
182 	printf("%x\n", *(uint8_t *)0xbb001010);
183 	printf("--------------------\n");
184 
185 	return 0;
186 }
187 
188 int
beep_test(void)189 beep_test(void)
190 {
191 
192 	/* Beep test */
193 	for (;;)
194 		*(volatile uint8_t *)0xbb007000 = 0xff;
195 
196 	return 0;
197 }
198 
199 int
fdd_test(void)200 fdd_test(void)
201 {
202 
203 	/* ROM_FDRDWR test */
204 	uint8_t buf[512];
205 	int i, err, cnt;
206 	uint32_t pos;
207 
208 	for (i = 0; i < 1989; i++) {
209 		memset(buf, 0, 512);
210 		blk_to_2d_position(i, &pos, &cnt);
211 		err = ROM_FD_RW(0, pos, cnt, buf);
212 		printf("%d err=%d\n", i, err);
213 		if (err != 0)
214 			break;
215 #if 0
216 		for (j = 0; j < 512; j++)
217 			printf("%x", buf[j]);
218 		printf("\n");
219 #else
220 		printf("%s\n", buf);
221 #endif
222 	}
223 	return 0;
224 }
225