No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / ep93xx / epled.c
blobe1a5785d31a4b4277f1ac1952a187a37d17b85a0
1 /* $NetBSD: epled.c,v 1.1 2005/11/12 05:33:23 hamajima Exp $ */
3 /*
4 * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
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.
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.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: epled.c,v 1.1 2005/11/12 05:33:23 hamajima Exp $");
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>
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;
47 static int epled_match(struct device *, struct cfdata *, void *);
48 static void epled_attach(struct device *, struct device *, void *);
50 CFATTACH_DECL(epled, sizeof(struct epled_softc),
51 epled_match, epled_attach, NULL, NULL);
53 static struct epled_softc *the_epled_sc = 0;
55 int
56 epled_match(struct device *parent, struct cfdata *cf, void *aux)
58 return 1;
61 void
62 epled_attach(struct device *parent, struct device *self, void *aux)
64 struct epled_softc *sc = (struct epled_softc *)self;
65 struct epgpio_attach_args *ga = aux;
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");
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
80 epgpio_out(sc->sc_gpio, sc->sc_port, sc->sc_green);
81 epgpio_out(sc->sc_gpio, sc->sc_port, sc->sc_red);
84 int
85 epled_red_on(void)
87 struct epled_softc *sc = the_epled_sc;
89 #ifdef DIAGNOSTIC
90 if (!sc) {
91 printf("epled not configured\n");
92 return (ENXIO);
94 #endif
95 epgpio_set(sc->sc_gpio, sc->sc_port, sc->sc_red);
96 return 0;
99 int
100 epled_red_off(void)
102 struct epled_softc *sc = the_epled_sc;
104 #ifdef DIAGNOSTIC
105 if (!sc) {
106 printf("epled not configured\n");
107 return (ENXIO);
109 #endif
110 epgpio_clear(sc->sc_gpio, sc->sc_port, sc->sc_red);
111 return 0;
115 epled_green_on(void)
117 struct epled_softc *sc = the_epled_sc;
119 #ifdef DIAGNOSTIC
120 if (!sc) {
121 printf("epled not configured\n");
122 return (ENXIO);
124 #endif
125 epgpio_set(sc->sc_gpio, sc->sc_port, sc->sc_green);
126 return 0;
130 epled_green_off(void)
132 struct epled_softc *sc = the_epled_sc;
134 #ifdef DIAGNOSTIC
135 if (!sc) {
136 printf("epled not configured\n");
137 return (ENXIO);
139 #endif
140 epgpio_clear(sc->sc_gpio, sc->sc_port, sc->sc_green);
141 return 0;