No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / vax / vsa / leds.c
blob9b891976200d5150a0174c8ee4178c8c1ed3aa82
1 /* $NetBSD: leds.c,v 1.7 2008/04/28 20:23:39 martin Exp $ */
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross and der Mouse.
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.
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.
33 * Functions to flash the LEDs with some pattern.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.7 2008/04/28 20:23:39 martin Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/conf.h>
43 #include <sys/buf.h>
44 #include <sys/malloc.h>
45 #include <sys/proc.h>
47 #include <machine/cpu.h>
48 #include <machine/sid.h>
49 #include <machine/leds.h>
51 #include "opt_cputype.h"
53 static volatile u_short *diagreg = 0;
54 static u_char led_countdown = 0;
55 static u_char led_px = 0;
58 * Initial value is the default pattern set.
60 struct led_patterns ledpat = {
61 16, /* divisor */
62 12, /* patlen */
63 { /* patterns */
64 0x03, 0x06, 0x0c, 0x18,
65 0x30, 0x60, 0xc0, 0x60,
66 0x30, 0x18, 0x0c, 0x06,
70 void
71 ledsattach(int a)
73 switch (vax_boardtype) {
74 #if VAX46 || VAXANY
75 case VAX_BTYP_46: {
76 extern struct vs_cpu *ka46_cpu;
77 diagreg = (volatile u_short *)(&ka46_cpu->vc_diagdsp);
78 break;
80 #endif
81 #if VAX48 || VAXANY
82 case VAX_BTYP_48: {
83 extern struct vs_cpu *ka48_cpu;
84 diagreg = (volatile u_short *)(&ka48_cpu->vc_diagdsp);
85 break;
87 #endif
88 #if VAX49 || VAXANY
89 case VAX_BTYP_49:
90 diagreg = (volatile u_short *)vax_map_physmem(0x25800000, 1);
91 diagreg += 2;
92 break;
93 #endif
94 default:
95 return;
98 /* Turn on some lights. */
99 leds_intr();
103 * This is called by the clock interrupt.
105 void
106 leds_intr(void)
108 register u_char i;
110 if (diagreg == 0)
111 return;
113 if (led_countdown) {
114 led_countdown--;
115 return;
118 led_countdown = ledpat.divisor - 1;
119 i = led_px;
121 *diagreg = ~ledpat.pat[i];
123 i = i+1;
124 if (i == ledpat.patlen)
125 i = 0;
126 led_px = i;
130 * This is called by mem.c to handle /dev/leds
133 leds_uio(struct uio *uio)
135 int cnt, error;
136 int off; /* NOT off_t */
137 char *va;
139 off = uio->uio_offset;
140 if ((off < 0) || (off > sizeof(ledpat)))
141 return (EIO);
143 cnt = min(uio->uio_resid, (sizeof(ledpat) - off));
144 if (cnt == 0)
145 return (0); /* EOF */
148 va = (char *)&ledpat;
149 va = va + off;
150 error = uiomove(va, cnt, uio);
152 return (error);