nappi_nr.c revision 1.8
1/* $NetBSD: nappi_nr.c,v 1.8 2008/04/28 20:23:17 martin Exp $ */
2
3/*
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ichiro FUKUHARA and Naoto Shimazaki.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 *
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.
30 */
31
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: nappi_nr.c,v 1.8 2008/04/28 20:23:17 martin Exp $");
34
35/*
36 * LED support for NAPPI.
37 */
38
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>
45
46#include <machine/bus.h>
47
48#include <arm/ixp12x0/ixpsipvar.h>
49
50static int	nappinr_match(struct device *, struct cfdata *, void *);
51static void	nappinr_attach(struct device *, struct device *, void *);
52#if 0
53static int	nappinr_activate(struct device *, enum devact);
54#endif
55static void	nappinr_callout(void *);
56
57struct nappinr_softc {
58	struct device		sc_dev;
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;
63	struct callout		sc_co;
64};
65
66CFATTACH_DECL(nappinr, sizeof(struct nappinr_softc),
67    nappinr_match, nappinr_attach, NULL, NULL);
68
69static int
70nappinr_match(struct device *parent, struct cfdata *match, void *aux)
71{
72	return (1);
73}
74
75static void
76nappinr_attach(struct device *parent, struct device *self, void *aux)
77{
78	struct nappinr_softc*		sc = (struct nappinr_softc*) self;
79	struct ixpsip_attach_args*	sa = aux;
80
81	printf("\n");
82
83  	sc->sc_iot = sa->sa_iot;
84  	sc->sc_baseaddr = sa->sa_addr;
85
86	if(bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0,
87			 &sc->sc_ioh)) {
88		printf("%s: unable to map registers\n", self->dv_xname);
89		return;
90	}
91
92	callout_init(&sc->sc_co, 0);
93	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
94}
95
96#if 0
97static int
98nappinr_activate(struct device *self, enum devact act)
99{
100	printf("nappinr_activate act=%d\n", act);
101	return 0;
102}
103#endif
104
105static void
106nappinr_callout(void *arg)
107{
108	static const int	ptn[] = { 1, 2, 4, 8, 4, 2 };
109	struct nappinr_softc*	sc = arg;
110
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);
114}
115