nappi_nr.c revision 1.3
11.3Sthorpej/* $NetBSD: nappi_nr.c,v 1.3 2002/10/02 05:10:36 thorpej Exp $ */
21.1Sichiro
31.1Sichiro/*
41.1Sichiro * Copyright (c) 2002 The NetBSD Foundation, Inc.
51.1Sichiro * All rights reserved.
61.1Sichiro *
71.1Sichiro * This code is derived from software contributed to The NetBSD Foundation
81.1Sichiro * by Ichiro FUKUHARA and Naoto Shimazaki.
91.1Sichiro *
101.1Sichiro * Redistribution and use in source and binary forms, with or without
111.1Sichiro * modification, are permitted provided that the following conditions
121.1Sichiro * are met:
131.1Sichiro * 1. Redistributions of source code must retain the above copyright
141.1Sichiro *    notice, this list of conditions and the following disclaimer.
151.1Sichiro * 2. Redistributions in binary form must reproduce the above copyright
161.1Sichiro *    notice, this list of conditions and the following disclaimer in the
171.1Sichiro *    documentation and/or other materials provided with the distribution.
181.1Sichiro * 3. All advertising materials mentioning features or use of this software
191.1Sichiro *    must display the following acknowledgement:
201.1Sichiro *        This product includes software developed by the NetBSD
211.1Sichiro *        Foundation, Inc. and its contributors.
221.1Sichiro * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Sichiro *    contributors may be used to endorse or promote products derived
241.1Sichiro *    from this software without specific prior written permission.
251.1Sichiro *
261.1Sichiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Sichiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Sichiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Sichiro * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Sichiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Sichiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Sichiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Sichiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Sichiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Sichiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Sichiro * POSSIBILITY OF SUCH DAMAGE.
371.1Sichiro */
381.1Sichiro
391.1Sichiro/*
401.1Sichiro * LED support for NAPPI.
411.1Sichiro */
421.1Sichiro
431.1Sichiro#include <sys/param.h>
441.1Sichiro#include <sys/types.h>
451.1Sichiro#include <sys/callout.h>
461.1Sichiro#include <sys/device.h>
471.1Sichiro#include <sys/kernel.h>
481.1Sichiro#include <sys/systm.h>
491.1Sichiro
501.1Sichiro#include <machine/bus.h>
511.1Sichiro
521.1Sichiro#include <arm/ixp12x0/ixpsipvar.h>
531.1Sichiro
541.1Sichirostatic int	nappinr_match(struct device *, struct cfdata *, void *);
551.1Sichirostatic void	nappinr_attach(struct device *, struct device *, void *);
561.1Sichiro#if 0
571.1Sichirostatic int	nappinr_activate(struct device *, enum devact);
581.1Sichiro#endif
591.1Sichirostatic void	nappinr_callout(void *);
601.1Sichiro
611.1Sichirostruct nappinr_softc {
621.1Sichiro	struct device		sc_dev;
631.1Sichiro	bus_space_tag_t		sc_iot;
641.1Sichiro	bus_space_handle_t	sc_ioh;
651.1Sichiro	bus_addr_t		sc_baseaddr;
661.1Sichiro	bus_space_handle_t	sc_pos;
671.1Sichiro	struct callout		sc_co;
681.1Sichiro};
691.1Sichiro
701.3SthorpejCFATTACH_DECL(nappinr, sizeof(struct nappinr_softc),
711.3Sthorpej    nappinr_match, nappinr_attach, NULL, NULL);
721.1Sichiro
731.1Sichirostatic int
741.1Sichironappinr_match(struct device *parent, struct cfdata *match, void *aux)
751.1Sichiro{
761.1Sichiro	return (1);
771.1Sichiro}
781.1Sichiro
791.1Sichirostatic void
801.1Sichironappinr_attach(struct device *parent, struct device *self, void *aux)
811.1Sichiro{
821.1Sichiro	struct nappinr_softc*		sc = (struct nappinr_softc*) self;
831.1Sichiro	struct ixpsip_attach_args*	sa = aux;
841.1Sichiro
851.1Sichiro	printf("\n");
861.1Sichiro
871.1Sichiro  	sc->sc_iot = sa->sa_iot;
881.1Sichiro  	sc->sc_baseaddr = sa->sa_addr;
891.1Sichiro
901.1Sichiro	if(bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0,
911.1Sichiro			 &sc->sc_ioh)) {
921.1Sichiro		printf("%s: unable to map registers\n", self->dv_xname);
931.1Sichiro		return;
941.1Sichiro	}
951.1Sichiro
961.1Sichiro	callout_init(&sc->sc_co);
971.1Sichiro	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
981.1Sichiro}
991.1Sichiro
1001.1Sichiro#if 0
1011.1Sichirostatic int
1021.1Sichironappinr_activate(struct device *self, enum devact act)
1031.1Sichiro{
1041.1Sichiro	printf("nappinr_activate act=%d\n", act);
1051.1Sichiro	return 0;
1061.1Sichiro}
1071.1Sichiro#endif
1081.1Sichiro
1091.1Sichirostatic void
1101.1Sichironappinr_callout(void *arg)
1111.1Sichiro{
1121.1Sichiro	static const int	ptn[] = { 1, 2, 4, 8, 4, 2 };
1131.1Sichiro	struct nappinr_softc*	sc = arg;
1141.1Sichiro
1151.1Sichiro	bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0, ptn[sc->sc_pos++ % 6]);
1161.1Sichiro	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
1171.1Sichiro}
118