leds.c revision 1.3 1 1.3 lukem /* $NetBSD: leds.c,v 1.3 2003/07/15 02:15:07 lukem Exp $ */
2 1.1 ragge
3 1.1 ragge /*-
4 1.1 ragge * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1 ragge * All rights reserved.
6 1.1 ragge *
7 1.1 ragge * This code is derived from software contributed to The NetBSD Foundation
8 1.1 ragge * by Gordon W. Ross and der Mouse.
9 1.1 ragge *
10 1.1 ragge * Redistribution and use in source and binary forms, with or without
11 1.1 ragge * modification, are permitted provided that the following conditions
12 1.1 ragge * are met:
13 1.1 ragge * 1. Redistributions of source code must retain the above copyright
14 1.1 ragge * notice, this list of conditions and the following disclaimer.
15 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ragge * notice, this list of conditions and the following disclaimer in the
17 1.1 ragge * documentation and/or other materials provided with the distribution.
18 1.1 ragge * 3. All advertising materials mentioning features or use of this software
19 1.1 ragge * must display the following acknowledgement:
20 1.1 ragge * This product includes software developed by the NetBSD
21 1.1 ragge * Foundation, Inc. and its contributors.
22 1.1 ragge * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 ragge * contributors may be used to endorse or promote products derived
24 1.1 ragge * from this software without specific prior written permission.
25 1.1 ragge *
26 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 ragge * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 ragge * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 ragge * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 ragge * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 ragge * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 ragge * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 ragge * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 ragge * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 ragge * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 ragge * POSSIBILITY OF SUCH DAMAGE.
37 1.1 ragge */
38 1.1 ragge
39 1.1 ragge /*
40 1.1 ragge * Functions to flash the LEDs with some pattern.
41 1.1 ragge */
42 1.3 lukem
43 1.3 lukem #include <sys/cdefs.h>
44 1.3 lukem __KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.3 2003/07/15 02:15:07 lukem Exp $");
45 1.1 ragge
46 1.1 ragge #include <sys/param.h>
47 1.1 ragge #include <sys/systm.h>
48 1.1 ragge #include <sys/device.h>
49 1.1 ragge #include <sys/conf.h>
50 1.1 ragge #include <sys/buf.h>
51 1.1 ragge #include <sys/malloc.h>
52 1.1 ragge #include <sys/proc.h>
53 1.1 ragge
54 1.1 ragge #include <machine/cpu.h>
55 1.1 ragge #include <machine/sid.h>
56 1.1 ragge #include <machine/leds.h>
57 1.1 ragge
58 1.1 ragge #include "opt_cputype.h"
59 1.1 ragge
60 1.1 ragge static volatile u_short *diagreg = 0;
61 1.1 ragge static u_char led_countdown = 0;
62 1.1 ragge static u_char led_px = 0;
63 1.1 ragge
64 1.1 ragge /*
65 1.1 ragge * Initial value is the default pattern set.
66 1.1 ragge */
67 1.1 ragge static struct led_patterns ledpat = {
68 1.1 ragge 16, /* divisor */
69 1.1 ragge 12, /* patlen */
70 1.1 ragge { /* patterns */
71 1.1 ragge 0x03, 0x06, 0x0c, 0x18,
72 1.1 ragge 0x30, 0x60, 0xc0, 0x60,
73 1.1 ragge 0x30, 0x18, 0x0c, 0x06,
74 1.1 ragge }
75 1.1 ragge };
76 1.1 ragge
77 1.1 ragge void
78 1.1 ragge ledsattach(int a)
79 1.1 ragge {
80 1.1 ragge switch (vax_boardtype) {
81 1.2 matt #if VAX46 || VAXANY
82 1.1 ragge case VAX_BTYP_46: {
83 1.1 ragge extern struct vs_cpu *ka46_cpu;
84 1.1 ragge diagreg = (volatile u_short *)(&ka46_cpu->vc_diagdsp);
85 1.1 ragge break;
86 1.1 ragge }
87 1.1 ragge #endif
88 1.2 matt #if VAX48 || VAXANY
89 1.1 ragge case VAX_BTYP_48: {
90 1.1 ragge extern struct vs_cpu *ka48_cpu;
91 1.1 ragge diagreg = (volatile u_short *)(&ka48_cpu->vc_diagdsp);
92 1.1 ragge break;
93 1.1 ragge }
94 1.1 ragge #endif
95 1.2 matt #if VAX49 || VAXANY
96 1.1 ragge case VAX_BTYP_49:
97 1.1 ragge diagreg = (volatile u_short *)vax_map_physmem(0x25800000, 1);
98 1.1 ragge diagreg += 2;
99 1.1 ragge break;
100 1.1 ragge #endif
101 1.1 ragge default:
102 1.1 ragge return;
103 1.1 ragge }
104 1.1 ragge
105 1.1 ragge /* Turn on some lights. */
106 1.1 ragge leds_intr();
107 1.1 ragge }
108 1.1 ragge
109 1.1 ragge /*
110 1.1 ragge * This is called by the clock interrupt.
111 1.1 ragge */
112 1.1 ragge void
113 1.1 ragge leds_intr()
114 1.1 ragge {
115 1.1 ragge register u_char i;
116 1.1 ragge
117 1.1 ragge if (diagreg == 0)
118 1.1 ragge return;
119 1.1 ragge
120 1.1 ragge if (led_countdown) {
121 1.1 ragge led_countdown--;
122 1.1 ragge return;
123 1.1 ragge }
124 1.1 ragge
125 1.1 ragge led_countdown = ledpat.divisor - 1;
126 1.1 ragge i = led_px;
127 1.1 ragge
128 1.1 ragge *diagreg = ~ledpat.pat[i];
129 1.1 ragge
130 1.1 ragge i = i+1;
131 1.1 ragge if (i == ledpat.patlen)
132 1.1 ragge i = 0;
133 1.1 ragge led_px = i;
134 1.1 ragge }
135 1.1 ragge
136 1.1 ragge /*
137 1.1 ragge * This is called by mem.c to handle /dev/leds
138 1.1 ragge */
139 1.1 ragge int
140 1.1 ragge leds_uio(struct uio *uio)
141 1.1 ragge {
142 1.1 ragge int cnt, error;
143 1.1 ragge int off; /* NOT off_t */
144 1.1 ragge caddr_t va;
145 1.1 ragge
146 1.1 ragge off = uio->uio_offset;
147 1.1 ragge if ((off < 0) || (off > sizeof(ledpat)))
148 1.1 ragge return (EIO);
149 1.1 ragge
150 1.1 ragge cnt = min(uio->uio_resid, (sizeof(ledpat) - off));
151 1.1 ragge if (cnt == 0)
152 1.1 ragge return (0); /* EOF */
153 1.1 ragge
154 1.1 ragge va = ((char*)(&ledpat)) + off;
155 1.1 ragge error = uiomove(va, cnt, uio);
156 1.1 ragge
157 1.1 ragge return (error);
158 1.1 ragge }
159 1.1 ragge
160