xref: /netbsd-src/sys/arch/evbarm/ixdp425/ixdp425_led.c (revision a2b8c7fb0742c36745ea1fd35822da4277b62383)
1 /*	$NetBSD: ixdp425_led.c,v 1.6 2012/10/14 14:20:58 msaitoh 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.6 2012/10/14 14:20:58 msaitoh 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 <sys/bus.h>
43 
44 #include <arm/xscale/ixp425_sipvar.h>
45 #include <arm/xscale/ixp425var.h>
46 
47 static int	ixdpled_match(device_t, cfdata_t, void *);
48 static void	ixdpled_attach(device_t, device_t, void *);
49 static void	ixdpled_callout(void *);
50 
51 extern void	ixp425_expbus_init(void);
52 
53 struct ixdpled_softc {
54 	bus_space_tag_t		sc_iot;
55 	bus_space_handle_t	sc_ioh;
56 	bus_addr_t		sc_baseaddr;
57 	bus_space_handle_t	sc_pos;
58 	struct callout		sc_co;
59 };
60 
61 CFATTACH_DECL_NEW(ixdpled, sizeof(struct ixdpled_softc),
62     ixdpled_match, ixdpled_attach, NULL, NULL);
63 
64 static int
ixdpled_match(device_t parent,cfdata_t match,void * aux)65 ixdpled_match(device_t parent, cfdata_t match, void *aux)
66 {
67 	return (1);
68 }
69 
70 static void
ixdpled_attach(device_t parent,device_t self,void * aux)71 ixdpled_attach(device_t parent, device_t self, void *aux)
72 {
73 	struct ixdpled_softc*		sc = device_private(self);
74 	struct ixpsip_attach_args*	sa = aux;
75 
76 	printf("\n");
77 
78   	sc->sc_iot = sa->sa_iot;
79   	sc->sc_baseaddr = sa->sa_addr;
80 
81 	if(bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
82 			 &sc->sc_ioh)) {
83 		printf("%s: unable to map registers\n", device_xname(self));
84 		return;
85 	}
86 
87 	IXPREG(IXP425_EXP_VBASE + EXP_TIMING_CS2_OFFSET) =
88 		IXP425_EXP_ADDR_T(3) | IXP425_EXP_SETUP_T(3) |
89 		IXP425_EXP_STROBE_T(15) | IXP425_EXP_HOLD_T(3) |
90 		IXP425_EXP_RECOVERY_T(15) | EXP_SZ_512 | EXP_WR_EN |
91 		IXP425_EXP_CS_EN;
92 
93 	callout_init(&sc->sc_co, 0);
94         callout_reset(&sc->sc_co, hz / 5, ixdpled_callout, sc);
95 
96 }
97 
98 static void
ixdpled_callout(void * arg)99 ixdpled_callout(void *arg)
100 {
101 	struct ixdpled_softc*	sc = arg;
102 
103 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0,
104 			  0x1000 + (sc->sc_pos++ % 16));
105 
106         callout_reset(&sc->sc_co, hz / 5, ixdpled_callout, sc);
107 }
108 
109