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