1 /* $NetBSD: epled.c,v 1.4 2012/10/27 17:17:37 chs 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.4 2012/10/27 17:17:37 chs Exp $"); 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/kernel.h> 34 #include <sys/device.h> 35 #include <sys/bus.h> 36 #include <arm/ep93xx/epgpiovar.h> 37 #include <arm/ep93xx/epledvar.h> 38 39 struct epled_softc { 40 int sc_port; 41 int sc_green; 42 int sc_red; 43 struct epgpio_softc *sc_gpio; 44 }; 45 46 static int epled_match(device_t, cfdata_t, void *); 47 static void epled_attach(device_t, device_t, void *); 48 49 CFATTACH_DECL_NEW(epled, sizeof(struct epled_softc), 50 epled_match, epled_attach, NULL, NULL); 51 52 static struct epled_softc *the_epled_sc = 0; 53 54 int 55 epled_match(device_t parent, cfdata_t cf, void *aux) 56 { 57 return 1; 58 } 59 60 void 61 epled_attach(device_t parent, device_t self, void *aux) 62 { 63 struct epled_softc *sc = device_private(self); 64 struct epgpio_attach_args *ga = aux; 65 66 sc->sc_port = ga->ga_port; 67 sc->sc_green = ga->ga_bit1; 68 sc->sc_red = ga->ga_bit2; 69 sc->sc_gpio = (struct epgpio_softc *)parent; 70 printf("\n"); 71 72 if (!the_epled_sc) 73 the_epled_sc = sc; 74 #ifdef DIAGNOSTIC 75 else 76 printf("%s is already configured\n", device_xname(self)); 77 #endif 78 79 epgpio_out(sc->sc_gpio, sc->sc_port, sc->sc_green); 80 epgpio_out(sc->sc_gpio, sc->sc_port, sc->sc_red); 81 } 82 83 int 84 epled_red_on(void) 85 { 86 struct epled_softc *sc = the_epled_sc; 87 88 #ifdef DIAGNOSTIC 89 if (!sc) { 90 printf("epled not configured\n"); 91 return (ENXIO); 92 } 93 #endif 94 epgpio_set(sc->sc_gpio, sc->sc_port, sc->sc_red); 95 return 0; 96 } 97 98 int 99 epled_red_off(void) 100 { 101 struct epled_softc *sc = the_epled_sc; 102 103 #ifdef DIAGNOSTIC 104 if (!sc) { 105 printf("epled not configured\n"); 106 return (ENXIO); 107 } 108 #endif 109 epgpio_clear(sc->sc_gpio, sc->sc_port, sc->sc_red); 110 return 0; 111 } 112 113 int 114 epled_green_on(void) 115 { 116 struct epled_softc *sc = the_epled_sc; 117 118 #ifdef DIAGNOSTIC 119 if (!sc) { 120 printf("epled not configured\n"); 121 return (ENXIO); 122 } 123 #endif 124 epgpio_set(sc->sc_gpio, sc->sc_port, sc->sc_green); 125 return 0; 126 } 127 128 int 129 epled_green_off(void) 130 { 131 struct epled_softc *sc = the_epled_sc; 132 133 #ifdef DIAGNOSTIC 134 if (!sc) { 135 printf("epled not configured\n"); 136 return (ENXIO); 137 } 138 #endif 139 epgpio_clear(sc->sc_gpio, sc->sc_port, sc->sc_green); 140 return 0; 141 } 142