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