Home | History | Annotate | Line # | Download | only in dev
obsled.c revision 1.1.2.1
      1  1.1.2.1   yamt /*	$NetBSD: obsled.c,v 1.1.2.1 2005/03/19 08:32:58 yamt Exp $	*/
      2      1.1  shige 
      3      1.1  shige /*
      4      1.1  shige  * Copyright (c) 2004 Shigeyuki Fukushima.
      5      1.1  shige  * All rights reserved.
      6      1.1  shige  *
      7      1.1  shige  * Redistribution and use in source and binary forms, with or without
      8      1.1  shige  * modification, are permitted provided that the following conditions
      9      1.1  shige  * are met:
     10      1.1  shige  * 1. Redistributions of source code must retain the above copyright
     11      1.1  shige  *    notice, this list of conditions and the following disclaimer.
     12      1.1  shige  * 2. Redistributions in binary form must reproduce the above
     13      1.1  shige  *    copyright notice, this list of conditions and the following
     14      1.1  shige  *    disclaimer in the documentation and/or other materials provided
     15      1.1  shige  *    with the distribution.
     16      1.1  shige  * 3. The name of the author may not be used to endorse or promote
     17      1.1  shige  *    products derived from this software without specific prior
     18      1.1  shige  *    written permission.
     19      1.1  shige  *
     20      1.1  shige  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     21      1.1  shige  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22      1.1  shige  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23      1.1  shige  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     24      1.1  shige  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25      1.1  shige  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     26      1.1  shige  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27      1.1  shige  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     28      1.1  shige  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     29      1.1  shige  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     30      1.1  shige  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31      1.1  shige  */
     32      1.1  shige 
     33      1.1  shige #include <sys/cdefs.h>
     34  1.1.2.1   yamt __KERNEL_RCSID(0, "$NetBSD: obsled.c,v 1.1.2.1 2005/03/19 08:32:58 yamt Exp $");
     35      1.1  shige 
     36      1.1  shige #include <sys/param.h>
     37      1.1  shige #include <sys/device.h>
     38      1.1  shige #include <sys/queue.h>
     39      1.1  shige #include <sys/systm.h>
     40      1.1  shige 
     41  1.1.2.1   yamt #include <machine/obs266.h>
     42      1.1  shige 
     43      1.1  shige #include <powerpc/ibm4xx/dev/gpiovar.h>
     44      1.1  shige 
     45      1.1  shige struct obsled_softc {
     46      1.1  shige         struct device sc_dev;
     47      1.1  shige 	gpio_tag_t sc_tag;
     48      1.1  shige         int sc_addr;
     49      1.1  shige };
     50      1.1  shige 
     51      1.1  shige static void	obsled_attach(struct device *, struct device *, void *);
     52      1.1  shige static int	obsled_match(struct device *, struct cfdata *, void *);
     53      1.1  shige 
     54      1.1  shige CFATTACH_DECL(obsled, sizeof(struct obsled_softc),
     55      1.1  shige 	obsled_match, obsled_attach, NULL, NULL);
     56      1.1  shige 
     57      1.1  shige static int
     58      1.1  shige obsled_match(struct device *parent, struct cfdata *cf, void *aux)
     59      1.1  shige {
     60      1.1  shige         struct gpio_attach_args *ga = aux;
     61      1.1  shige 
     62      1.1  shige 	/* XXX: support only OpenBlockS266 LED */
     63  1.1.2.1   yamt         if (ga->ga_addr == OBS266_GPIO_LED1)
     64      1.1  shige                 return (1);
     65  1.1.2.1   yamt         else if (ga->ga_addr == OBS266_GPIO_LED2)
     66      1.1  shige                 return (1);
     67  1.1.2.1   yamt         else if (ga->ga_addr == OBS266_GPIO_LED4)
     68      1.1  shige                 return (1);
     69      1.1  shige 
     70      1.1  shige         return (0);
     71      1.1  shige }
     72      1.1  shige 
     73      1.1  shige static void
     74      1.1  shige obsled_attach(struct device *parent, struct device *self, void *aux)
     75      1.1  shige {
     76      1.1  shige         struct obsled_softc *sc = (struct obsled_softc *)self;
     77      1.1  shige         struct gpio_attach_args *ga = aux;
     78      1.1  shige 	int led = (1 << sc->sc_dev.dv_unit);
     79      1.1  shige 
     80      1.1  shige         aprint_naive(": OpenBlockS LED%d\n", led);
     81      1.1  shige         aprint_normal(": OpenBlockS LED%d\n", led);
     82      1.1  shige 
     83      1.1  shige         sc->sc_tag = ga->ga_tag;
     84      1.1  shige         sc->sc_addr = ga->ga_addr;
     85      1.1  shige 
     86  1.1.2.1   yamt 	obs266_led_set(OBS266_LED_OFF);
     87      1.1  shige #if 0
     88      1.1  shige 	{
     89      1.1  shige 		gpio_tag_t tag = sc->sc_tag;
     90      1.1  shige 	 	(*(tag)->io_or_write)((tag)->cookie, sc->sc_addr, 0);
     91      1.1  shige 	}
     92      1.1  shige #endif
     93      1.1  shige }
     94      1.1  shige 
     95      1.1  shige void
     96  1.1.2.1   yamt obs266_led_set(int led)
     97      1.1  shige {
     98      1.1  shige 	struct device *dp = NULL;
     99      1.1  shige 	struct devicelist *dlp = &alldevs;
    100      1.1  shige 
    101      1.1  shige         for (dp = TAILQ_FIRST(dlp); dp != NULL; dp = TAILQ_NEXT(dp, dv_list)) {
    102      1.1  shige 		if (dp->dv_cfdata != NULL
    103      1.1  shige 			&& strcmp(dp->dv_cfdata->cf_name, "obsled") == 0) {
    104      1.1  shige 			struct obsled_softc *sc = (struct obsled_softc *)dp;
    105      1.1  shige 			gpio_tag_t tag = sc->sc_tag;
    106      1.1  shige 			int bit = (led & (1 << dp->dv_unit)) >> dp->dv_unit;
    107      1.1  shige 	 		(*(tag)->io_or_write)((tag)->cookie,
    108      1.1  shige 					sc->sc_addr, (~bit & 1));
    109      1.1  shige 		}
    110      1.1  shige 	}
    111      1.1  shige }
    112