2 * Copyright (c) 2012 Robert N. M. Watson
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
37 #include <sys/mutex.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
43 #include <dev/led/led.h>
44 #include <dev/terasic/de4led/terasic_de4led.h>
46 devclass_t terasic_de4led_devclass;
49 terasic_de4led_update(struct terasic_de4led_softc *sc)
52 TERASIC_DE4LED_LOCK_ASSERT(sc);
54 bus_write_1(sc->tdl_res, TERASIC_DE4LED_OFF_LED, sc->tdl_bits);
58 led_update(struct terasic_de4led_softc *sc, int bit, int onoff)
61 TERASIC_DE4LED_LOCK(sc);
62 TERASIC_DE4LED_SETLED(sc, bit, onoff);
63 terasic_de4led_update(sc);
64 TERASIC_DE4LED_UNLOCK(sc);
68 led_0(void *arg, int onoff)
71 led_update(arg, 0, onoff);
75 led_1(void *arg, int onoff)
78 led_update(arg, 1, onoff);
82 led_2(void *arg, int onoff)
85 led_update(arg, 2, onoff);
89 led_3(void *arg, int onoff)
92 led_update(arg, 3, onoff);
96 led_4(void *arg, int onoff)
99 led_update(arg, 4, onoff);
103 led_5(void *arg, int onoff)
106 led_update(arg, 5, onoff);
110 led_6(void *arg, int onoff)
113 led_update(arg, 6, onoff);
117 led_7(void *arg, int onoff)
120 led_update(arg, 7, onoff);
124 terasic_de4led_attach(struct terasic_de4led_softc *sc)
128 TERASIC_DE4LED_LOCK_INIT(sc);
131 * Clear the LED array before we start.
133 TERASIC_DE4LED_LOCK(sc);
134 TERASIC_DE4LED_CLEARBAR(sc);
135 terasic_de4led_update(sc);
136 TERASIC_DE4LED_UNLOCK(sc);
139 * Register the LED array with led(4).
141 sc->tdl_leds[0] = led_create(led_0, sc, "de4led_0");
142 sc->tdl_leds[1] = led_create(led_1, sc, "de4led_1");
143 sc->tdl_leds[2] = led_create(led_2, sc, "de4led_2");
144 sc->tdl_leds[3] = led_create(led_3, sc, "de4led_3");
145 sc->tdl_leds[4] = led_create(led_4, sc, "de4led_4");
146 sc->tdl_leds[5] = led_create(led_5, sc, "de4led_5");
147 sc->tdl_leds[6] = led_create(led_6, sc, "de4led_6");
148 sc->tdl_leds[7] = led_create(led_7, sc, "de4led_7");
150 if (resource_string_value(device_get_name(sc->tdl_dev),
151 sc->tdl_unit, "de4led_0_cmd", &cmd) == 0)
152 led_set("de4led_0", cmd);
153 if (resource_string_value(device_get_name(sc->tdl_dev),
154 sc->tdl_unit, "de4led_1_cmd", &cmd) == 0)
155 led_set("de4led_1", cmd);
156 if (resource_string_value(device_get_name(sc->tdl_dev),
157 sc->tdl_unit, "de4led_2_cmd", &cmd) == 0)
158 led_set("de4led_2", cmd);
159 if (resource_string_value(device_get_name(sc->tdl_dev),
160 sc->tdl_unit, "de4led_3_cmd", &cmd) == 0)
161 led_set("de4led_3", cmd);
162 if (resource_string_value(device_get_name(sc->tdl_dev),
163 sc->tdl_unit, "de4led_4_cmd", &cmd) == 0)
164 led_set("de4led_4", cmd);
165 if (resource_string_value(device_get_name(sc->tdl_dev),
166 sc->tdl_unit, "de4led_5_cmd", &cmd) == 0)
167 led_set("de4led_5", cmd);
168 if (resource_string_value(device_get_name(sc->tdl_dev),
169 sc->tdl_unit, "de4led_6_cmd", &cmd) == 0)
170 led_set("de4led_6", cmd);
171 if (resource_string_value(device_get_name(sc->tdl_dev),
172 sc->tdl_unit, "de4led_7_cmd", &cmd) == 0)
173 led_set("de4led_7", cmd);
177 terasic_de4led_detach(struct terasic_de4led_softc *sc)
181 for (i = 0; i < 8; i++) {
182 led_destroy(sc->tdl_leds[i]);
183 sc->tdl_leds[i] = NULL;
185 TERASIC_DE4LED_LOCK(sc);
186 TERASIC_DE4LED_CLEARBAR(sc);
187 terasic_de4led_update(sc);
188 TERASIC_DE4LED_UNLOCK(sc);
189 TERASIC_DE4LED_LOCK_DESTROY(sc);