summaryrefslogtreecommitdiffstats
path: root/sys/arch/vax/vax/led.c
blob: e04f06e2d5c665cde68c40df5db61ae3fbe2ef7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*	$OpenBSD: led.c,v 1.4 2006/08/27 16:55:41 miod Exp $	*/
/*	$NetBSD: leds.c,v 1.4 2005/12/11 12:19:37 christos Exp $	*/

/*
 * Copyright (c) 1998 Jason L. Wright (jason@thought.net)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
/*-
 * Copyright (c) 1997 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Gordon W. Ross and der Mouse.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the NetBSD
 *	Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Functions to flash the LEDs with some pattern.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/timeout.h>

#include <machine/cpu.h>
#include <machine/nexus.h>
#include <machine/sid.h>

struct led_softc {
	struct device	sc_dev;
	struct timeout	sc_tmo;
	volatile u_short *sc_reg;
	const u_int8_t	*sc_pat, *sc_patpos;
};

/*
 * Patterns for 8 and 4 led displays.
 */
static const u_int8_t led_pattern8[] = {
	0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f,
	0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0x00
};
static const u_int8_t led_pattern4[] = {
	0x0e, 0x0d, 0x0b, 0x07, 0x0b, 0x0d, 0x00
};

int	ledmatch(struct device *, void *, void *);
void	ledattach(struct device *, struct device *, void *);
void	led_blink(void *);

struct cfattach led_ca = {
	sizeof(struct led_softc), ledmatch, ledattach
};

struct cfdriver led_cd = {
	NULL, "led", DV_DULL
};

int
ledmatch(struct device *parent, void *cf, void *aux)
{
	struct mainbus_attach_args *maa = aux;

	if (maa->maa_bustype != VAX_LEDS)
		return (0);
	
	switch (vax_boardtype) {
#if VAX46 || VAX48 || VAX49 || VAX53 || VXT
#if VAX46
	case VAX_BTYP_46:
#endif
#if VAX48
	case VAX_BTYP_48:
#endif
#if VAX49
	case VAX_BTYP_49:
#endif
#if VAX53
	case VAX_BTYP_1303:
#endif
#if VXT
	case VAX_BTYP_VXT:
#endif
		return (1);
#endif
	default:
		return (0);
	}
}

void
ledattach(struct device *parent, struct device *self, void *aux)
{
	struct led_softc *sc = (void *)self;
#if VAX49 || VAX53 || VXT
	vaddr_t pgva;
#endif

	printf("\n");

	switch (vax_boardtype) {
#if VAX46
	case VAX_BTYP_46:
	{
		extern struct vs_cpu *ka46_cpu;
		sc->sc_reg = (volatile u_short *)(&ka46_cpu->vc_diagdsp);
		sc->sc_pat = led_pattern8;
	}
		break;
#endif
#if VAX48
	case VAX_BTYP_48:
	{
		extern struct vs_cpu *ka48_cpu;
		sc->sc_reg = (volatile u_short *)(&ka48_cpu->vc_diagdsp);
		sc->sc_pat = led_pattern8;
	}
		break;
#endif
#if VAX49
	case VAX_BTYP_49:
		pgva = vax_map_physmem(0x25800000, 1);
		sc->sc_reg = (volatile u_short *)(pgva + 4);
		sc->sc_pat = led_pattern8;
		break;
#endif
#if VAX53
	case VAX_BTYP_1303:
		pgva = vax_map_physmem(0x20140000, 1);
		sc->sc_reg = (volatile u_short *)(pgva + 0x30);
		sc->sc_pat = led_pattern4;
		break;
#endif
#if VXT
	case VAX_BTYP_VXT:
		pgva = vax_map_physmem(0x200c1000, 1);
		sc->sc_reg = (volatile u_short *)pgva;
		sc->sc_pat = led_pattern8;
		break;
#endif
	}

	sc->sc_patpos = sc->sc_pat;
	timeout_set(&sc->sc_tmo, led_blink, sc);
	led_blink(sc);
}

void
led_blink(void *v)
{
	struct led_softc *sc = v;
	extern int vax_led_blink;

	if (sc == NULL) {
		/* find our softc if we come from cpu_sysctl */
		if (led_cd.cd_ndevs != 0)
			sc = (struct led_softc *)led_cd.cd_devs[0];
		if (sc == NULL)
			return;
	}

	if (vax_led_blink == 0) {
		*sc->sc_reg = 0xff;
		return;
	}

	*sc->sc_reg = *sc->sc_patpos++;
	if (*sc->sc_patpos == 0)
		sc->sc_patpos = sc->sc_pat;

	timeout_add(&sc->sc_tmo,
	    (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 3)));
}