nappi_nr.c revision 1.10
11.10Smatt/* $NetBSD: nappi_nr.c,v 1.10 2012/07/30 23:35:05 matt 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 *
191.1Sichiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Sichiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Sichiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Sichiro * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Sichiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Sichiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Sichiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Sichiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Sichiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Sichiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Sichiro * POSSIBILITY OF SUCH DAMAGE.
301.1Sichiro */
311.5Sigy
321.5Sigy#include <sys/cdefs.h>
331.10Smatt__KERNEL_RCSID(0, "$NetBSD: nappi_nr.c,v 1.10 2012/07/30 23:35:05 matt Exp $");
341.1Sichiro
351.1Sichiro/*
361.1Sichiro * LED support for NAPPI.
371.1Sichiro */
381.1Sichiro
391.1Sichiro#include <sys/param.h>
401.1Sichiro#include <sys/types.h>
411.1Sichiro#include <sys/callout.h>
421.1Sichiro#include <sys/device.h>
431.1Sichiro#include <sys/kernel.h>
441.1Sichiro#include <sys/systm.h>
451.1Sichiro
461.9Sdyoung#include <sys/bus.h>
471.1Sichiro
481.1Sichiro#include <arm/ixp12x0/ixpsipvar.h>
491.1Sichiro
501.1Sichirostatic int	nappinr_match(struct device *, struct cfdata *, void *);
511.1Sichirostatic void	nappinr_attach(struct device *, struct device *, void *);
521.1Sichiro#if 0
531.1Sichirostatic int	nappinr_activate(struct device *, enum devact);
541.1Sichiro#endif
551.1Sichirostatic void	nappinr_callout(void *);
561.1Sichiro
571.1Sichirostruct nappinr_softc {
581.1Sichiro	struct device		sc_dev;
591.1Sichiro	bus_space_tag_t		sc_iot;
601.1Sichiro	bus_space_handle_t	sc_ioh;
611.1Sichiro	bus_addr_t		sc_baseaddr;
621.1Sichiro	bus_space_handle_t	sc_pos;
631.1Sichiro	struct callout		sc_co;
641.1Sichiro};
651.1Sichiro
661.3SthorpejCFATTACH_DECL(nappinr, sizeof(struct nappinr_softc),
671.3Sthorpej    nappinr_match, nappinr_attach, NULL, NULL);
681.1Sichiro
691.1Sichirostatic int
701.1Sichironappinr_match(struct device *parent, struct cfdata *match, void *aux)
711.1Sichiro{
721.1Sichiro	return (1);
731.1Sichiro}
741.1Sichiro
751.1Sichirostatic void
761.1Sichironappinr_attach(struct device *parent, struct device *self, void *aux)
771.1Sichiro{
781.1Sichiro	struct nappinr_softc*		sc = (struct nappinr_softc*) self;
791.1Sichiro	struct ixpsip_attach_args*	sa = aux;
801.1Sichiro
811.1Sichiro	printf("\n");
821.1Sichiro
831.1Sichiro  	sc->sc_iot = sa->sa_iot;
841.1Sichiro  	sc->sc_baseaddr = sa->sa_addr;
851.1Sichiro
861.1Sichiro	if(bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0,
871.1Sichiro			 &sc->sc_ioh)) {
881.1Sichiro		printf("%s: unable to map registers\n", self->dv_xname);
891.1Sichiro		return;
901.1Sichiro	}
911.1Sichiro
921.6She	callout_init(&sc->sc_co, 0);
931.1Sichiro	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
941.1Sichiro}
951.1Sichiro
961.1Sichiro#if 0
971.1Sichirostatic int
981.1Sichironappinr_activate(struct device *self, enum devact act)
991.1Sichiro{
1001.1Sichiro	printf("nappinr_activate act=%d\n", act);
1011.1Sichiro	return 0;
1021.1Sichiro}
1031.1Sichiro#endif
1041.1Sichiro
1051.1Sichirostatic void
1061.1Sichironappinr_callout(void *arg)
1071.1Sichiro{
1081.1Sichiro	static const int	ptn[] = { 1, 2, 4, 8, 4, 2 };
1091.1Sichiro	struct nappinr_softc*	sc = arg;
1101.10Smatt	uint32_t v;
1111.1Sichiro
1121.10Smatt	v = ptn[sc->sc_pos++ % 6];
1131.10Smatt	v |= ptn[sc->sc_pos++ % 6] << 4;
1141.10Smatt	bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0, v);
1151.1Sichiro	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
1161.1Sichiro}
117