leds.c revision 1.8 1 1.8 jklos /* $NetBSD: leds.c,v 1.8 2008/05/04 00:10:42 jklos 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 *
19 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 ragge * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 ragge * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 ragge * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 ragge * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 ragge * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 ragge * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 ragge * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 ragge * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 ragge * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 ragge * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ragge */
31 1.1 ragge
32 1.1 ragge /*
33 1.1 ragge * Functions to flash the LEDs with some pattern.
34 1.1 ragge */
35 1.3 lukem
36 1.3 lukem #include <sys/cdefs.h>
37 1.8 jklos __KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.8 2008/05/04 00:10:42 jklos Exp $");
38 1.1 ragge
39 1.1 ragge #include <sys/param.h>
40 1.1 ragge #include <sys/systm.h>
41 1.1 ragge #include <sys/device.h>
42 1.1 ragge #include <sys/conf.h>
43 1.1 ragge #include <sys/buf.h>
44 1.1 ragge #include <sys/malloc.h>
45 1.1 ragge #include <sys/proc.h>
46 1.1 ragge
47 1.1 ragge #include <machine/cpu.h>
48 1.1 ragge #include <machine/sid.h>
49 1.1 ragge #include <machine/leds.h>
50 1.1 ragge
51 1.1 ragge #include "opt_cputype.h"
52 1.1 ragge
53 1.1 ragge static volatile u_short *diagreg = 0;
54 1.1 ragge static u_char led_countdown = 0;
55 1.1 ragge static u_char led_px = 0;
56 1.1 ragge
57 1.1 ragge /*
58 1.1 ragge * Initial value is the default pattern set.
59 1.1 ragge */
60 1.8 jklos struct led_patterns ledpat = {
61 1.1 ragge 16, /* divisor */
62 1.1 ragge 12, /* patlen */
63 1.1 ragge { /* patterns */
64 1.1 ragge 0x03, 0x06, 0x0c, 0x18,
65 1.1 ragge 0x30, 0x60, 0xc0, 0x60,
66 1.1 ragge 0x30, 0x18, 0x0c, 0x06,
67 1.1 ragge }
68 1.1 ragge };
69 1.1 ragge
70 1.1 ragge void
71 1.1 ragge ledsattach(int a)
72 1.1 ragge {
73 1.1 ragge switch (vax_boardtype) {
74 1.2 matt #if VAX46 || VAXANY
75 1.1 ragge case VAX_BTYP_46: {
76 1.1 ragge extern struct vs_cpu *ka46_cpu;
77 1.1 ragge diagreg = (volatile u_short *)(&ka46_cpu->vc_diagdsp);
78 1.1 ragge break;
79 1.1 ragge }
80 1.1 ragge #endif
81 1.2 matt #if VAX48 || VAXANY
82 1.1 ragge case VAX_BTYP_48: {
83 1.1 ragge extern struct vs_cpu *ka48_cpu;
84 1.1 ragge diagreg = (volatile u_short *)(&ka48_cpu->vc_diagdsp);
85 1.1 ragge break;
86 1.1 ragge }
87 1.1 ragge #endif
88 1.2 matt #if VAX49 || VAXANY
89 1.1 ragge case VAX_BTYP_49:
90 1.1 ragge diagreg = (volatile u_short *)vax_map_physmem(0x25800000, 1);
91 1.1 ragge diagreg += 2;
92 1.1 ragge break;
93 1.1 ragge #endif
94 1.1 ragge default:
95 1.1 ragge return;
96 1.1 ragge }
97 1.1 ragge
98 1.1 ragge /* Turn on some lights. */
99 1.1 ragge leds_intr();
100 1.1 ragge }
101 1.1 ragge
102 1.1 ragge /*
103 1.1 ragge * This is called by the clock interrupt.
104 1.1 ragge */
105 1.1 ragge void
106 1.6 matt leds_intr(void)
107 1.1 ragge {
108 1.1 ragge register u_char i;
109 1.1 ragge
110 1.1 ragge if (diagreg == 0)
111 1.1 ragge return;
112 1.1 ragge
113 1.1 ragge if (led_countdown) {
114 1.1 ragge led_countdown--;
115 1.1 ragge return;
116 1.1 ragge }
117 1.1 ragge
118 1.1 ragge led_countdown = ledpat.divisor - 1;
119 1.1 ragge i = led_px;
120 1.1 ragge
121 1.1 ragge *diagreg = ~ledpat.pat[i];
122 1.1 ragge
123 1.1 ragge i = i+1;
124 1.1 ragge if (i == ledpat.patlen)
125 1.1 ragge i = 0;
126 1.1 ragge led_px = i;
127 1.1 ragge }
128 1.1 ragge
129 1.1 ragge /*
130 1.1 ragge * This is called by mem.c to handle /dev/leds
131 1.1 ragge */
132 1.1 ragge int
133 1.1 ragge leds_uio(struct uio *uio)
134 1.1 ragge {
135 1.1 ragge int cnt, error;
136 1.1 ragge int off; /* NOT off_t */
137 1.8 jklos char *va;
138 1.1 ragge
139 1.1 ragge off = uio->uio_offset;
140 1.1 ragge if ((off < 0) || (off > sizeof(ledpat)))
141 1.1 ragge return (EIO);
142 1.1 ragge
143 1.1 ragge cnt = min(uio->uio_resid, (sizeof(ledpat) - off));
144 1.1 ragge if (cnt == 0)
145 1.1 ragge return (0); /* EOF */
146 1.1 ragge
147 1.8 jklos
148 1.8 jklos va = (char *)&ledpat;
149 1.8 jklos va = va + off;
150 1.1 ragge error = uiomove(va, cnt, uio);
151 1.1 ragge
152 1.1 ragge return (error);
153 1.1 ragge }
154 1.1 ragge
155