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
|
/*-
* Copyright (c) 2012 Robert N. M. Watson
* All rights reserved.
*
* This software was developed by SRI International and the University of
* Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
* ("CTSRD"), as part of the DARPA CRASH research programme.
*
* 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 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 AUTHOR 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/rman.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <dev/led/led.h>
#include <dev/terasic/de4led/terasic_de4led.h>
devclass_t terasic_de4led_devclass;
static void
terasic_de4led_update(struct terasic_de4led_softc *sc)
{
TERASIC_DE4LED_LOCK_ASSERT(sc);
bus_write_1(sc->tdl_res, TERASIC_DE4LED_OFF_LED, sc->tdl_bits);
}
static void
led_update(struct terasic_de4led_softc *sc, int bit, int onoff)
{
TERASIC_DE4LED_LOCK(sc);
TERASIC_DE4LED_SETLED(sc, bit, onoff);
terasic_de4led_update(sc);
TERASIC_DE4LED_UNLOCK(sc);
}
static void
led_0(void *arg, int onoff)
{
led_update(arg, 0, onoff);
}
static void
led_1(void *arg, int onoff)
{
led_update(arg, 1, onoff);
}
static void
led_2(void *arg, int onoff)
{
led_update(arg, 2, onoff);
}
static void
led_3(void *arg, int onoff)
{
led_update(arg, 3, onoff);
}
static void
led_4(void *arg, int onoff)
{
led_update(arg, 4, onoff);
}
static void
led_5(void *arg, int onoff)
{
led_update(arg, 5, onoff);
}
static void
led_6(void *arg, int onoff)
{
led_update(arg, 6, onoff);
}
static void
led_7(void *arg, int onoff)
{
led_update(arg, 7, onoff);
}
void
terasic_de4led_attach(struct terasic_de4led_softc *sc)
{
const char *cmd;
TERASIC_DE4LED_LOCK_INIT(sc);
/*
* Clear the LED array before we start.
*/
TERASIC_DE4LED_LOCK(sc);
TERASIC_DE4LED_CLEARBAR(sc);
terasic_de4led_update(sc);
TERASIC_DE4LED_UNLOCK(sc);
/*
* Register the LED array with led(4).
*/
sc->tdl_leds[0] = led_create(led_0, sc, "de4led_0");
sc->tdl_leds[1] = led_create(led_1, sc, "de4led_1");
sc->tdl_leds[2] = led_create(led_2, sc, "de4led_2");
sc->tdl_leds[3] = led_create(led_3, sc, "de4led_3");
sc->tdl_leds[4] = led_create(led_4, sc, "de4led_4");
sc->tdl_leds[5] = led_create(led_5, sc, "de4led_5");
sc->tdl_leds[6] = led_create(led_6, sc, "de4led_6");
sc->tdl_leds[7] = led_create(led_7, sc, "de4led_7");
if (resource_string_value(device_get_name(sc->tdl_dev),
sc->tdl_unit, "de4led_0_cmd", &cmd) == 0)
led_set("de4led_0", cmd);
if (resource_string_value(device_get_name(sc->tdl_dev),
sc->tdl_unit, "de4led_1_cmd", &cmd) == 0)
led_set("de4led_1", cmd);
if (resource_string_value(device_get_name(sc->tdl_dev),
sc->tdl_unit, "de4led_2_cmd", &cmd) == 0)
led_set("de4led_2", cmd);
if (resource_string_value(device_get_name(sc->tdl_dev),
sc->tdl_unit, "de4led_3_cmd", &cmd) == 0)
led_set("de4led_3", cmd);
if (resource_string_value(device_get_name(sc->tdl_dev),
sc->tdl_unit, "de4led_4_cmd", &cmd) == 0)
led_set("de4led_4", cmd);
if (resource_string_value(device_get_name(sc->tdl_dev),
sc->tdl_unit, "de4led_5_cmd", &cmd) == 0)
led_set("de4led_5", cmd);
if (resource_string_value(device_get_name(sc->tdl_dev),
sc->tdl_unit, "de4led_6_cmd", &cmd) == 0)
led_set("de4led_6", cmd);
if (resource_string_value(device_get_name(sc->tdl_dev),
sc->tdl_unit, "de4led_7_cmd", &cmd) == 0)
led_set("de4led_7", cmd);
}
void
terasic_de4led_detach(struct terasic_de4led_softc *sc)
{
int i;
for (i = 0; i < 8; i++) {
led_destroy(sc->tdl_leds[i]);
sc->tdl_leds[i] = NULL;
}
TERASIC_DE4LED_LOCK(sc);
TERASIC_DE4LED_CLEARBAR(sc);
terasic_de4led_update(sc);
TERASIC_DE4LED_UNLOCK(sc);
TERASIC_DE4LED_LOCK_DESTROY(sc);
}
|