1239709Srwatson/*-
2239709Srwatson * Copyright (c) 2012 Robert N. M. Watson
3239709Srwatson * All rights reserved.
4239709Srwatson *
5239709Srwatson * This software was developed by SRI International and the University of
6239709Srwatson * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7239709Srwatson * ("CTSRD"), as part of the DARPA CRASH research programme.
8239709Srwatson *
9239709Srwatson * Redistribution and use in source and binary forms, with or without
10239709Srwatson * modification, are permitted provided that the following conditions
11239709Srwatson * are met:
12239709Srwatson * 1. Redistributions of source code must retain the above copyright
13239709Srwatson *    notice, this list of conditions and the following disclaimer.
14239709Srwatson * 2. Redistributions in binary form must reproduce the above copyright
15239709Srwatson *    notice, this list of conditions and the following disclaimer in the
16239709Srwatson *    documentation and/or other materials provided with the distribution.
17239709Srwatson *
18239709Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19239709Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20239709Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21239709Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22239709Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23239709Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24239709Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25239709Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26239709Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27239709Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28239709Srwatson * SUCH DAMAGE.
29239709Srwatson *
30239709Srwatson * $FreeBSD$
31239709Srwatson */
32239709Srwatson
33239709Srwatson#ifndef _DEV_TERASIC_DE4LED_H_
34239709Srwatson#define	_DEV_TERASIC_DE4LED_H_
35239709Srwatson
36239709Srwatson#define	TERASIC_DE4LED_NUMLEDS	8
37239709Srwatsonstruct terasic_de4led_softc {
38239709Srwatson	device_t	 tdl_dev;
39239709Srwatson	int		 tdl_unit;
40239709Srwatson	struct resource	*tdl_res;
41239709Srwatson	int		 tdl_rid;
42239709Srwatson	struct mtx	 tdl_lock;
43239709Srwatson	uint8_t		 tdl_bits;
44239709Srwatson	struct cdev	*tdl_leds[TERASIC_DE4LED_NUMLEDS];
45239709Srwatson};
46239709Srwatson
47239709Srwatson#define	TERASIC_DE4LED_LOCK(sc)		mtx_lock(&(sc)->tdl_lock)
48239709Srwatson#define	TERASIC_DE4LED_LOCK_ASSERT(sc)	mtx_assert(&(sc)->tdl_lock, MA_OWNED)
49239709Srwatson#define	TERASIC_DE4LED_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->tdl_lock)
50239709Srwatson#define	TERASIC_DE4LED_LOCK_INIT(sc)	mtx_init(&(sc)->tdl_lock,	\
51239709Srwatson					    "terasic_de4led", NULL, MTX_DEF)
52239709Srwatson#define	TERASIC_DE4LED_UNLOCK(sc)	mtx_unlock(&(sc)->tdl_lock)
53239709Srwatson
54239709Srwatson/*
55239709Srwatson * Setting and clearing LEDs.  tdl_bits is in the bit order preferred for I/O.
56239709Srwatson * The LED elements are labelled 1..8 on the DE-4, so bit 0 is LED 1, and so
57239709Srwatson * on.
58239709Srwatson */
59239709Srwatson#define	TERASIC_DE4LED_CLEARBAR(sc) do {				\
60239709Srwatson	(sc)->tdl_bits = 0;						\
61239709Srwatson} while (0)
62239709Srwatson#define	TERASIC_DE4LED_SETLED(sc, led, onoff) do {			\
63239709Srwatson	(sc)->tdl_bits &= ~(1 << (led));				\
64239709Srwatson	(sc)->tdl_bits |= ((onoff != 0) ? 1 : 0) << (led);		\
65239709Srwatson} while (0)
66239709Srwatson
67239709Srwatson/*
68239709Srwatson * Only one offset matters for this device -- 0.
69239709Srwatson */
70239709Srwatson#define	TERASIC_DE4LED_OFF_LED		0
71239709Srwatson
72239709Srwatsonvoid	terasic_de4led_attach(struct terasic_de4led_softc *sc);
73239709Srwatsonvoid	terasic_de4led_detach(struct terasic_de4led_softc *sc);
74239709Srwatson
75245380Srwatsonextern devclass_t	terasic_de4led_devclass;
76245380Srwatson
77239709Srwatson#endif /* _DEV_TERASIC_DE4LED_H_ */
78