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