xref: /netbsd-src/sys/arch/sun2/sun2/leds.c (revision 5e4c038a45edbc7d63b7c2daa76e29f88b64a4e3)
1 /*	$NetBSD: leds.c,v 1.2 2001/11/30 18:06:55 fredette 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  * All other Sun2 machines have an 8-position LED
42  * array in which some pattern is animated.
43  */
44 
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 #include <sys/conf.h>
49 #include <sys/buf.h>
50 #include <sys/malloc.h>
51 #include <sys/proc.h>
52 
53 #include <machine/autoconf.h>
54 #include <machine/idprom.h>
55 #include <machine/leds.h>
56 
57 #include <sun2/sun2/machdep.h>
58 #include <sun2/sun2/control.h>
59 
60 static u_char led_countdown = 0;
61 static u_char led_px = 0;
62 
63 /*
64  * Initial value is the default pattern set.
65  */
66 static struct led_patterns ledpat = {
67 	8,	/* divisor */
68 	8,	/* patlen */
69 	{	/* patterns */
70 		0x0F, 0x1E, 0x3C, 0x78,
71 		0xF0, 0xE1, 0xC3, 0x87,
72 	}
73 };
74 
75 /*
76  * This is called early during startup to find the
77  * diag register (LEDs) and turn on the light(s).
78  */
79 void
80 leds_init()
81 {
82 
83 	/* Turn on some lights. */
84 	leds_intr();
85 }
86 
87 /*
88  * This is called by the clock interrupt.
89  */
90 void
91 leds_intr()
92 {
93 	u_char i;
94 
95 	if (led_countdown) {
96 		led_countdown--;
97 		return;
98 	}
99 
100 	led_countdown = ledpat.divisor - 1;
101 	i = led_px;
102 
103 	set_control_byte(DIAG_REG, ledpat.pat[i]);
104 
105 	i = i+1;
106 	if (i == ledpat.patlen)
107 		i = 0;
108 	led_px = i;
109 }
110 
111 /*
112  * This is called by mem.c to handle /dev/leds
113  */
114 int
115 leds_uio(struct uio *uio)
116 {
117 	int cnt, error;
118 	int off;	/* NOT off_t */
119 	caddr_t va;
120 
121 	off = uio->uio_offset;
122 	if ((off < 0) || (off > sizeof(ledpat)))
123 		return (EIO);
124 
125 	cnt = min(uio->uio_resid, (sizeof(ledpat) - off));
126 	if (cnt == 0)
127 		return (0); /* EOF */
128 
129 	va = ((char*)(&ledpat)) + off;
130 	error = uiomove(va, cnt, uio);
131 
132 	return (error);
133 }
134