nappi_nr.c revision 1.5
11.5Sigy/* $NetBSD: nappi_nr.c,v 1.5 2003/03/25 06:53:16 igy 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.5Sigy
391.5Sigy#include <sys/cdefs.h>
401.5Sigy__KERNEL_RCSID(0, "$NetBSD: nappi_nr.c,v 1.5 2003/03/25 06:53:16 igy Exp $");
411.1Sichiro
421.1Sichiro/*
431.1Sichiro * LED support for NAPPI.
441.1Sichiro */
451.1Sichiro
461.1Sichiro#include <sys/param.h>
471.1Sichiro#include <sys/types.h>
481.1Sichiro#include <sys/callout.h>
491.1Sichiro#include <sys/device.h>
501.1Sichiro#include <sys/kernel.h>
511.1Sichiro#include <sys/systm.h>
521.1Sichiro
531.1Sichiro#include <machine/bus.h>
541.1Sichiro
551.1Sichiro#include <arm/ixp12x0/ixpsipvar.h>
561.1Sichiro
571.1Sichirostatic int	nappinr_match(struct device *, struct cfdata *, void *);
581.1Sichirostatic void	nappinr_attach(struct device *, struct device *, void *);
591.1Sichiro#if 0
601.1Sichirostatic int	nappinr_activate(struct device *, enum devact);
611.1Sichiro#endif
621.1Sichirostatic void	nappinr_callout(void *);
631.1Sichiro
641.1Sichirostruct nappinr_softc {
651.1Sichiro	struct device		sc_dev;
661.1Sichiro	bus_space_tag_t		sc_iot;
671.1Sichiro	bus_space_handle_t	sc_ioh;
681.1Sichiro	bus_addr_t		sc_baseaddr;
691.1Sichiro	bus_space_handle_t	sc_pos;
701.1Sichiro	struct callout		sc_co;
711.1Sichiro};
721.1Sichiro
731.3SthorpejCFATTACH_DECL(nappinr, sizeof(struct nappinr_softc),
741.3Sthorpej    nappinr_match, nappinr_attach, NULL, NULL);
751.1Sichiro
761.1Sichirostatic int
771.1Sichironappinr_match(struct device *parent, struct cfdata *match, void *aux)
781.1Sichiro{
791.1Sichiro	return (1);
801.1Sichiro}
811.1Sichiro
821.1Sichirostatic void
831.1Sichironappinr_attach(struct device *parent, struct device *self, void *aux)
841.1Sichiro{
851.1Sichiro	struct nappinr_softc*		sc = (struct nappinr_softc*) self;
861.1Sichiro	struct ixpsip_attach_args*	sa = aux;
871.1Sichiro
881.1Sichiro	printf("\n");
891.1Sichiro
901.1Sichiro  	sc->sc_iot = sa->sa_iot;
911.1Sichiro  	sc->sc_baseaddr = sa->sa_addr;
921.1Sichiro
931.1Sichiro	if(bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0,
941.1Sichiro			 &sc->sc_ioh)) {
951.1Sichiro		printf("%s: unable to map registers\n", self->dv_xname);
961.1Sichiro		return;
971.1Sichiro	}
981.1Sichiro
991.1Sichiro	callout_init(&sc->sc_co);
1001.1Sichiro	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
1011.1Sichiro}
1021.1Sichiro
1031.1Sichiro#if 0
1041.1Sichirostatic int
1051.1Sichironappinr_activate(struct device *self, enum devact act)
1061.1Sichiro{
1071.1Sichiro	printf("nappinr_activate act=%d\n", act);
1081.1Sichiro	return 0;
1091.1Sichiro}
1101.1Sichiro#endif
1111.1Sichiro
1121.1Sichirostatic void
1131.1Sichironappinr_callout(void *arg)
1141.1Sichiro{
1151.1Sichiro	static const int	ptn[] = { 1, 2, 4, 8, 4, 2 };
1161.1Sichiro	struct nappinr_softc*	sc = arg;
1171.1Sichiro
1181.4Sichiro	bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0,
1191.4Sichiro			  ptn[sc->sc_pos++ % 6] | ptn[sc->sc_pos++ % 6]<< 4);
1201.1Sichiro	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
1211.1Sichiro}
122