1 /* $NetBSD: nappi_nr.c,v 1.7 2007/10/17 19:54:13 garbled Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ichiro FUKUHARA and Naoto Shimazaki.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: nappi_nr.c,v 1.7 2007/10/17 19:54:13 garbled Exp $");
36 * LED support for NAPPI.
39 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/callout.h>
42 #include <sys/device.h>
43 #include <sys/kernel.h>
44 #include <sys/systm.h>
46 #include <machine/bus.h>
48 #include <arm/ixp12x0/ixpsipvar.h>
50 static int nappinr_match(struct device
*, struct cfdata
*, void *);
51 static void nappinr_attach(struct device
*, struct device
*, void *);
53 static int nappinr_activate(struct device
*, enum devact
);
55 static void nappinr_callout(void *);
57 struct nappinr_softc
{
59 bus_space_tag_t sc_iot
;
60 bus_space_handle_t sc_ioh
;
61 bus_addr_t sc_baseaddr
;
62 bus_space_handle_t sc_pos
;
66 CFATTACH_DECL(nappinr
, sizeof(struct nappinr_softc
),
67 nappinr_match
, nappinr_attach
, NULL
, NULL
);
70 nappinr_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
76 nappinr_attach(struct device
*parent
, struct device
*self
, void *aux
)
78 struct nappinr_softc
* sc
= (struct nappinr_softc
*) self
;
79 struct ixpsip_attach_args
* sa
= aux
;
83 sc
->sc_iot
= sa
->sa_iot
;
84 sc
->sc_baseaddr
= sa
->sa_addr
;
86 if(bus_space_map(sa
->sa_iot
, sa
->sa_addr
, sa
->sa_size
, 0,
88 printf("%s: unable to map registers\n", self
->dv_xname
);
92 callout_init(&sc
->sc_co
, 0);
93 callout_reset(&sc
->sc_co
, hz
/ 10, nappinr_callout
, sc
);
98 nappinr_activate(struct device
*self
, enum devact act
)
100 printf("nappinr_activate act=%d\n", act
);
106 nappinr_callout(void *arg
)
108 static const int ptn
[] = { 1, 2, 4, 8, 4, 2 };
109 struct nappinr_softc
* sc
= arg
;
111 bus_space_write_4(sc
->sc_iot
, sc
->sc_ioh
, 0,
112 ptn
[sc
->sc_pos
++ % 6] | ptn
[sc
->sc_pos
++ % 6]<< 4);
113 callout_reset(&sc
->sc_co
, hz
/ 10, nappinr_callout
, sc
);