leds.c revision 1.7
1/*	$NetBSD: leds.c,v 1.7 2008/04/28 20:23:39 martin 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 */
35
36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.7 2008/04/28 20:23:39 martin Exp $");
38
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>
46
47#include <machine/cpu.h>
48#include <machine/sid.h>
49#include <machine/leds.h>
50
51#include "opt_cputype.h"
52
53static volatile u_short *diagreg = 0;
54static u_char led_countdown = 0;
55static u_char led_px = 0;
56
57/*
58 * Initial value is the default pattern set.
59 */
60static const 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,
67	}
68};
69
70void
71ledsattach(int a)
72{
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;
79		}
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;
86		}
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;
96	}
97
98	/* Turn on some lights. */
99	leds_intr();
100}
101
102/*
103 * This is called by the clock interrupt.
104 */
105void
106leds_intr(void)
107{
108	register u_char i;
109
110	if (diagreg == 0)
111		return;
112
113	if (led_countdown) {
114		led_countdown--;
115		return;
116	}
117
118	led_countdown = ledpat.divisor - 1;
119	i = led_px;
120
121	*diagreg = ~ledpat.pat[i];
122
123	i = i+1;
124	if (i == ledpat.patlen)
125		i = 0;
126	led_px = i;
127}
128
129/*
130 * This is called by mem.c to handle /dev/leds
131 */
132int
133leds_uio(struct uio *uio)
134{
135	int cnt, error;
136	int off;	/* NOT off_t */
137	void *va;
138
139	off = uio->uio_offset;
140	if ((off < 0) || (off > sizeof(ledpat)))
141		return (EIO);
142
143	cnt = min(uio->uio_resid, (sizeof(ledpat) - off));
144	if (cnt == 0)
145		return (0); /* EOF */
146
147	va = ((char*)(&ledpat)) + off;
148	error = uiomove(va, cnt, uio);
149
150	return (error);
151}
152
153