xref: /netbsd-src/sys/arch/arm/ep93xx/epled.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: epled.c,v 1.2 2006/03/26 04:38:52 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: epled.c,v 1.2 2006/03/26 04:38:52 thorpej Exp $");
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/device.h>
35 #include <machine/bus.h>
36 #include <arm/ep93xx/epgpiovar.h>
37 #include <arm/ep93xx/epledvar.h>
38 
39 struct epled_softc {
40 	struct device		sc_dev;
41 	int			sc_port;
42 	int			sc_green;
43 	int			sc_red;
44 	struct epgpio_softc	*sc_gpio;
45 };
46 
47 static int epled_match(struct device *, struct cfdata *, void *);
48 static void epled_attach(struct device *, struct device *, void *);
49 
50 CFATTACH_DECL(epled, sizeof(struct epled_softc),
51 	      epled_match, epled_attach, NULL, NULL);
52 
53 static struct epled_softc *the_epled_sc = 0;
54 
55 int
56 epled_match(struct device *parent, struct cfdata *cf, void *aux)
57 {
58 	return 1;
59 }
60 
61 void
62 epled_attach(struct device *parent, struct device *self, void *aux)
63 {
64 	struct epled_softc *sc = (struct epled_softc *)self;
65 	struct epgpio_attach_args *ga = aux;
66 
67 	sc->sc_port = ga->ga_port;
68 	sc->sc_green = ga->ga_bit1;
69 	sc->sc_red = ga->ga_bit2;
70 	sc->sc_gpio = (struct epgpio_softc *)parent;
71 	printf("\n");
72 
73 	if (!the_epled_sc)
74 		the_epled_sc = sc;
75 #ifdef DIAGNOSTIC
76 	else
77 		printf("%s is already configured\n", sc->sc_dev.dv_xname);
78 #endif
79 
80 	epgpio_out(sc->sc_gpio, sc->sc_port, sc->sc_green);
81 	epgpio_out(sc->sc_gpio, sc->sc_port, sc->sc_red);
82 }
83 
84 int
85 epled_red_on(void)
86 {
87 	struct epled_softc *sc = the_epled_sc;
88 
89 #ifdef DIAGNOSTIC
90 	if (!sc) {
91 		printf("epled not configured\n");
92 		return (ENXIO);
93 	}
94 #endif
95 	epgpio_set(sc->sc_gpio, sc->sc_port, sc->sc_red);
96 	return 0;
97 }
98 
99 int
100 epled_red_off(void)
101 {
102 	struct epled_softc *sc = the_epled_sc;
103 
104 #ifdef DIAGNOSTIC
105 	if (!sc) {
106 		printf("epled not configured\n");
107 		return (ENXIO);
108 	}
109 #endif
110 	epgpio_clear(sc->sc_gpio, sc->sc_port, sc->sc_red);
111 	return 0;
112 }
113 
114 int
115 epled_green_on(void)
116 {
117 	struct epled_softc *sc = the_epled_sc;
118 
119 #ifdef DIAGNOSTIC
120 	if (!sc) {
121 		printf("epled not configured\n");
122 		return (ENXIO);
123 	}
124 #endif
125 	epgpio_set(sc->sc_gpio, sc->sc_port, sc->sc_green);
126 	return 0;
127 }
128 
129 int
130 epled_green_off(void)
131 {
132 	struct epled_softc *sc = the_epled_sc;
133 
134 #ifdef DIAGNOSTIC
135 	if (!sc) {
136 		printf("epled not configured\n");
137 		return (ENXIO);
138 	}
139 #endif
140 	epgpio_clear(sc->sc_gpio, sc->sc_port, sc->sc_green);
141 	return 0;
142 }
143