1 /* $NetBSD: epled.c,v 1.1 2005/11/12 05:33:23 hamajima 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.1 2005/11/12 05:33:23 hamajima 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%d is already configured\n", 78 sc->sc_dev.dv_xname, sc->sc_dev.dv_unit); 79 #endif 80 81 epgpio_out(sc->sc_gpio, sc->sc_port, sc->sc_green); 82 epgpio_out(sc->sc_gpio, sc->sc_port, sc->sc_red); 83 } 84 85 int 86 epled_red_on(void) 87 { 88 struct epled_softc *sc = the_epled_sc; 89 90 #ifdef DIAGNOSTIC 91 if (!sc) { 92 printf("epled not configured\n"); 93 return (ENXIO); 94 } 95 #endif 96 epgpio_set(sc->sc_gpio, sc->sc_port, sc->sc_red); 97 return 0; 98 } 99 100 int 101 epled_red_off(void) 102 { 103 struct epled_softc *sc = the_epled_sc; 104 105 #ifdef DIAGNOSTIC 106 if (!sc) { 107 printf("epled not configured\n"); 108 return (ENXIO); 109 } 110 #endif 111 epgpio_clear(sc->sc_gpio, sc->sc_port, sc->sc_red); 112 return 0; 113 } 114 115 int 116 epled_green_on(void) 117 { 118 struct epled_softc *sc = the_epled_sc; 119 120 #ifdef DIAGNOSTIC 121 if (!sc) { 122 printf("epled not configured\n"); 123 return (ENXIO); 124 } 125 #endif 126 epgpio_set(sc->sc_gpio, sc->sc_port, sc->sc_green); 127 return 0; 128 } 129 130 int 131 epled_green_off(void) 132 { 133 struct epled_softc *sc = the_epled_sc; 134 135 #ifdef DIAGNOSTIC 136 if (!sc) { 137 printf("epled not configured\n"); 138 return (ENXIO); 139 } 140 #endif 141 epgpio_clear(sc->sc_gpio, sc->sc_port, sc->sc_green); 142 return 0; 143 } 144