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