Home | History | Annotate | Line # | Download | only in ixdp425
ixdp425_led.c revision 1.1
      1 /*	$NetBSD: ixdp425_led.c,v 1.1 2003/05/31 01:16:32 ichiro Exp $ */
      2 /*
      3  * Copyright (c) 2003
      4  *	Ichiro FUKUHARA <ichiro (at) ichiro.org>.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Ichiro FUKUHARA.
     18  * 4. The name of the company nor the name of the author may be used to
     19  *    endorse or promote products derived from this software without specific
     20  *    prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
     26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: ixdp425_led.c,v 1.1 2003/05/31 01:16:32 ichiro Exp $");
     36 
     37 /*
     38  * LED support for IXDP425
     39  */
     40 
     41 #include <sys/param.h>
     42 #include <sys/types.h>
     43 #include <sys/callout.h>
     44 #include <sys/device.h>
     45 #include <sys/kernel.h>
     46 #include <sys/systm.h>
     47 
     48 #include <machine/bus.h>
     49 
     50 #include <arm/xscale/ixp425_sipvar.h>
     51 #include <arm/xscale/ixp425var.h>
     52 
     53 static int	ixdpled_match(struct device *, struct cfdata *, void *);
     54 static void	ixdpled_attach(struct device *, struct device *, void *);
     55 static void	ixdpled_callout(void *);
     56 
     57 extern void	ixp425_expbus_init(void);
     58 
     59 struct ixdpled_softc {
     60 	struct device		sc_dev;
     61 	bus_space_tag_t		sc_iot;
     62 	bus_space_handle_t	sc_ioh;
     63 	bus_addr_t		sc_baseaddr;
     64 	bus_space_handle_t	sc_pos;
     65 	struct callout		sc_co;
     66 };
     67 
     68 CFATTACH_DECL(ixdpled, sizeof(struct ixdpled_softc),
     69     ixdpled_match, ixdpled_attach, NULL, NULL);
     70 
     71 static int
     72 ixdpled_match(struct device *parent, struct cfdata *match, void *aux)
     73 {
     74 	return (1);
     75 }
     76 
     77 static void
     78 ixdpled_attach(struct device *parent, struct device *self, void *aux)
     79 {
     80 	struct ixdpled_softc*		sc = (struct ixdpled_softc*) self;
     81 	struct ixpsip_attach_args*	sa = aux;
     82 
     83 	printf("\n");
     84 
     85   	sc->sc_iot = sa->sa_iot;
     86   	sc->sc_baseaddr = sa->sa_addr;
     87 
     88 	if(bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
     89 			 &sc->sc_ioh)) {
     90 		printf("%s: unable to map registers\n", self->dv_xname);
     91 		return;
     92 	}
     93 
     94 	IXPREG(IXP425_EXP_VBASE + EXP_TIMING_CS2_OFFSET) =
     95 		IXP425_EXP_ADDR_T(3) | IXP425_EXP_SETUP_T(3) |
     96 		IXP425_EXP_STROBE_T(15) | IXP425_EXP_HOLD_T(3) |
     97 		IXP425_EXP_RECOVERY_T(15) | EXP_SZ_512 | EXP_WR_EN |
     98 		IXP425_EXP_CS_EN;
     99 
    100 	callout_init(&sc->sc_co);
    101         callout_reset(&sc->sc_co, hz / 5, ixdpled_callout, sc);
    102 
    103 }
    104 
    105 static void
    106 ixdpled_callout(void *arg)
    107 {
    108 	struct ixdpled_softc*	sc = arg;
    109 
    110 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0,
    111 			  0x1000 + (sc->sc_pos++ % 16));
    112 
    113         callout_reset(&sc->sc_co, hz / 5, ixdpled_callout, sc);
    114 }
    115 
    116