2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012 Robert N. M. Watson
7 * This software was developed by SRI International and the University of
8 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
9 * ("CTSRD"), as part of the DARPA CRASH research programme.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
39 #include <sys/mutex.h>
42 #include <machine/bus.h>
43 #include <machine/resource.h>
45 #include <dev/led/led.h>
46 #include <dev/terasic/de4led/terasic_de4led.h>
48 devclass_t terasic_de4led_devclass;
51 terasic_de4led_update(struct terasic_de4led_softc *sc)
54 TERASIC_DE4LED_LOCK_ASSERT(sc);
56 bus_write_1(sc->tdl_res, TERASIC_DE4LED_OFF_LED, sc->tdl_bits);
60 led_update(struct terasic_de4led_softc *sc, int bit, int onoff)
63 TERASIC_DE4LED_LOCK(sc);
64 TERASIC_DE4LED_SETLED(sc, bit, onoff);
65 terasic_de4led_update(sc);
66 TERASIC_DE4LED_UNLOCK(sc);
70 led_0(void *arg, int onoff)
73 led_update(arg, 0, onoff);
77 led_1(void *arg, int onoff)
80 led_update(arg, 1, onoff);
84 led_2(void *arg, int onoff)
87 led_update(arg, 2, onoff);
91 led_3(void *arg, int onoff)
94 led_update(arg, 3, onoff);
98 led_4(void *arg, int onoff)
101 led_update(arg, 4, onoff);
105 led_5(void *arg, int onoff)
108 led_update(arg, 5, onoff);
112 led_6(void *arg, int onoff)
115 led_update(arg, 6, onoff);
119 led_7(void *arg, int onoff)
122 led_update(arg, 7, onoff);
126 terasic_de4led_attach(struct terasic_de4led_softc *sc)
130 TERASIC_DE4LED_LOCK_INIT(sc);
133 * Clear the LED array before we start.
135 TERASIC_DE4LED_LOCK(sc);
136 TERASIC_DE4LED_CLEARBAR(sc);
137 terasic_de4led_update(sc);
138 TERASIC_DE4LED_UNLOCK(sc);
141 * Register the LED array with led(4).
143 sc->tdl_leds[0] = led_create(led_0, sc, "de4led_0");
144 sc->tdl_leds[1] = led_create(led_1, sc, "de4led_1");
145 sc->tdl_leds[2] = led_create(led_2, sc, "de4led_2");
146 sc->tdl_leds[3] = led_create(led_3, sc, "de4led_3");
147 sc->tdl_leds[4] = led_create(led_4, sc, "de4led_4");
148 sc->tdl_leds[5] = led_create(led_5, sc, "de4led_5");
149 sc->tdl_leds[6] = led_create(led_6, sc, "de4led_6");
150 sc->tdl_leds[7] = led_create(led_7, sc, "de4led_7");
152 if (resource_string_value(device_get_name(sc->tdl_dev),
153 sc->tdl_unit, "de4led_0_cmd", &cmd) == 0)
154 led_set("de4led_0", cmd);
155 if (resource_string_value(device_get_name(sc->tdl_dev),
156 sc->tdl_unit, "de4led_1_cmd", &cmd) == 0)
157 led_set("de4led_1", cmd);
158 if (resource_string_value(device_get_name(sc->tdl_dev),
159 sc->tdl_unit, "de4led_2_cmd", &cmd) == 0)
160 led_set("de4led_2", cmd);
161 if (resource_string_value(device_get_name(sc->tdl_dev),
162 sc->tdl_unit, "de4led_3_cmd", &cmd) == 0)
163 led_set("de4led_3", cmd);
164 if (resource_string_value(device_get_name(sc->tdl_dev),
165 sc->tdl_unit, "de4led_4_cmd", &cmd) == 0)
166 led_set("de4led_4", cmd);
167 if (resource_string_value(device_get_name(sc->tdl_dev),
168 sc->tdl_unit, "de4led_5_cmd", &cmd) == 0)
169 led_set("de4led_5", cmd);
170 if (resource_string_value(device_get_name(sc->tdl_dev),
171 sc->tdl_unit, "de4led_6_cmd", &cmd) == 0)
172 led_set("de4led_6", cmd);
173 if (resource_string_value(device_get_name(sc->tdl_dev),
174 sc->tdl_unit, "de4led_7_cmd", &cmd) == 0)
175 led_set("de4led_7", cmd);
179 terasic_de4led_detach(struct terasic_de4led_softc *sc)
183 for (i = 0; i < 8; i++) {
184 led_destroy(sc->tdl_leds[i]);
185 sc->tdl_leds[i] = NULL;
187 TERASIC_DE4LED_LOCK(sc);
188 TERASIC_DE4LED_CLEARBAR(sc);
189 terasic_de4led_update(sc);
190 TERASIC_DE4LED_UNLOCK(sc);
191 TERASIC_DE4LED_LOCK_DESTROY(sc);