xref: /netbsd/sys/arch/evbarm/ixdp425/ixdp425_led.c (revision 6550d01e)
1 /*	$NetBSD: ixdp425_led.c,v 1.4 2009/10/21 14:15:51 rmind Exp $ */
2 /*
3  * Copyright (c) 2003
4  *	Ichiro FUKUHARA <ichiro@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  *
16  * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: ixdp425_led.c,v 1.4 2009/10/21 14:15:51 rmind Exp $");
30 
31 /*
32  * LED support for IXDP425
33  */
34 
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/callout.h>
38 #include <sys/device.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
41 
42 #include <machine/bus.h>
43 
44 #include <arm/xscale/ixp425_sipvar.h>
45 #include <arm/xscale/ixp425var.h>
46 
47 static int	ixdpled_match(struct device *, struct cfdata *, void *);
48 static void	ixdpled_attach(struct device *, struct device *, void *);
49 static void	ixdpled_callout(void *);
50 
51 extern void	ixp425_expbus_init(void);
52 
53 struct ixdpled_softc {
54 	struct device		sc_dev;
55 	bus_space_tag_t		sc_iot;
56 	bus_space_handle_t	sc_ioh;
57 	bus_addr_t		sc_baseaddr;
58 	bus_space_handle_t	sc_pos;
59 	struct callout		sc_co;
60 };
61 
62 CFATTACH_DECL(ixdpled, sizeof(struct ixdpled_softc),
63     ixdpled_match, ixdpled_attach, NULL, NULL);
64 
65 static int
66 ixdpled_match(struct device *parent, struct cfdata *match, void *aux)
67 {
68 	return (1);
69 }
70 
71 static void
72 ixdpled_attach(struct device *parent, struct device *self, void *aux)
73 {
74 	struct ixdpled_softc*		sc = (struct ixdpled_softc*) self;
75 	struct ixpsip_attach_args*	sa = aux;
76 
77 	printf("\n");
78 
79   	sc->sc_iot = sa->sa_iot;
80   	sc->sc_baseaddr = sa->sa_addr;
81 
82 	if(bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
83 			 &sc->sc_ioh)) {
84 		printf("%s: unable to map registers\n", self->dv_xname);
85 		return;
86 	}
87 
88 	IXPREG(IXP425_EXP_VBASE + EXP_TIMING_CS2_OFFSET) =
89 		IXP425_EXP_ADDR_T(3) | IXP425_EXP_SETUP_T(3) |
90 		IXP425_EXP_STROBE_T(15) | IXP425_EXP_HOLD_T(3) |
91 		IXP425_EXP_RECOVERY_T(15) | EXP_SZ_512 | EXP_WR_EN |
92 		IXP425_EXP_CS_EN;
93 
94 	callout_init(&sc->sc_co, 0);
95         callout_reset(&sc->sc_co, hz / 5, ixdpled_callout, sc);
96 
97 }
98 
99 static void
100 ixdpled_callout(void *arg)
101 {
102 	struct ixdpled_softc*	sc = arg;
103 
104 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0,
105 			  0x1000 + (sc->sc_pos++ % 16));
106 
107         callout_reset(&sc->sc_co, hz / 5, ixdpled_callout, sc);
108 }
109 
110