xref: /netbsd-src/sys/arch/vax/vsa/leds.c (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1 /*	$NetBSD: leds.c,v 1.2 2001/05/16 05:36:56 matt Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Gordon W. Ross and der Mouse.
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 /*
40  * Functions to flash the LEDs with some pattern.
41  */
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 #include <sys/conf.h>
47 #include <sys/buf.h>
48 #include <sys/malloc.h>
49 #include <sys/proc.h>
50 
51 #include <machine/cpu.h>
52 #include <machine/sid.h>
53 #include <machine/leds.h>
54 
55 #include "opt_cputype.h"
56 
57 static volatile u_short *diagreg = 0;
58 static u_char led_countdown = 0;
59 static u_char led_px = 0;
60 
61 /*
62  * Initial value is the default pattern set.
63  */
64 static struct led_patterns ledpat = {
65 	16,	/* divisor */
66 	12,	/* patlen */
67 	{	/* patterns */
68 		0x03, 0x06, 0x0c, 0x18,
69 		0x30, 0x60, 0xc0, 0x60,
70 		0x30, 0x18, 0x0c, 0x06,
71 	}
72 };
73 
74 void
75 ledsattach(int a)
76 {
77 	switch (vax_boardtype) {
78 #if VAX46 || VAXANY
79 	case VAX_BTYP_46: {
80 		extern struct vs_cpu *ka46_cpu;
81 		diagreg = (volatile u_short *)(&ka46_cpu->vc_diagdsp);
82 		break;
83 		}
84 #endif
85 #if VAX48 || VAXANY
86 	case VAX_BTYP_48: {
87 		extern struct vs_cpu *ka48_cpu;
88 		diagreg = (volatile u_short *)(&ka48_cpu->vc_diagdsp);
89 		break;
90 		}
91 #endif
92 #if VAX49 || VAXANY
93 	case VAX_BTYP_49:
94 		diagreg = (volatile u_short *)vax_map_physmem(0x25800000, 1);
95 		diagreg += 2;
96 		break;
97 #endif
98 	default:
99 		return;
100 	}
101 
102 	/* Turn on some lights. */
103 	leds_intr();
104 }
105 
106 /*
107  * This is called by the clock interrupt.
108  */
109 void
110 leds_intr()
111 {
112 	register u_char i;
113 
114 	if (diagreg == 0)
115 		return;
116 
117 	if (led_countdown) {
118 		led_countdown--;
119 		return;
120 	}
121 
122 	led_countdown = ledpat.divisor - 1;
123 	i = led_px;
124 
125 	*diagreg = ~ledpat.pat[i];
126 
127 	i = i+1;
128 	if (i == ledpat.patlen)
129 		i = 0;
130 	led_px = i;
131 }
132 
133 /*
134  * This is called by mem.c to handle /dev/leds
135  */
136 int
137 leds_uio(struct uio *uio)
138 {
139 	int cnt, error;
140 	int off;	/* NOT off_t */
141 	caddr_t va;
142 
143 	off = uio->uio_offset;
144 	if ((off < 0) || (off > sizeof(ledpat)))
145 		return (EIO);
146 
147 	cnt = min(uio->uio_resid, (sizeof(ledpat) - off));
148 	if (cnt == 0)
149 		return (0); /* EOF */
150 
151 	va = ((char*)(&ledpat)) + off;
152 	error = uiomove(va, cnt, uio);
153 
154 	return (error);
155 }
156 
157