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