11.11Schs/* $NetBSD: nappi_nr.c,v 1.11 2012/10/27 17:17:48 chs 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.11Schs__KERNEL_RCSID(0, "$NetBSD: nappi_nr.c,v 1.11 2012/10/27 17:17:48 chs 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.11Schsstatic int	nappinr_match(device_t, cfdata_t, void *);
511.11Schsstatic void	nappinr_attach(device_t, device_t, void *);
521.1Sichiro#if 0
531.11Schsstatic int	nappinr_activate(device_t, enum devact);
541.1Sichiro#endif
551.1Sichirostatic void	nappinr_callout(void *);
561.1Sichiro
571.1Sichirostruct nappinr_softc {
581.1Sichiro	bus_space_tag_t		sc_iot;
591.1Sichiro	bus_space_handle_t	sc_ioh;
601.1Sichiro	bus_addr_t		sc_baseaddr;
611.1Sichiro	bus_space_handle_t	sc_pos;
621.1Sichiro	struct callout		sc_co;
631.1Sichiro};
641.1Sichiro
651.11SchsCFATTACH_DECL_NEW(nappinr, sizeof(struct nappinr_softc),
661.3Sthorpej    nappinr_match, nappinr_attach, NULL, NULL);
671.1Sichiro
681.1Sichirostatic int
691.11Schsnappinr_match(device_t parent, cfdata_t match, void *aux)
701.1Sichiro{
711.1Sichiro	return (1);
721.1Sichiro}
731.1Sichiro
741.1Sichirostatic void
751.11Schsnappinr_attach(device_t parent, device_t self, void *aux)
761.1Sichiro{
771.11Schs	struct nappinr_softc*		sc = device_private(self);
781.1Sichiro	struct ixpsip_attach_args*	sa = aux;
791.1Sichiro
801.1Sichiro	printf("\n");
811.1Sichiro
821.1Sichiro  	sc->sc_iot = sa->sa_iot;
831.1Sichiro  	sc->sc_baseaddr = sa->sa_addr;
841.1Sichiro
851.11Schs	if (bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0,
861.11Schs			  &sc->sc_ioh)) {
871.11Schs		printf("%s: unable to map registers\n", device_xname(self));
881.1Sichiro		return;
891.1Sichiro	}
901.1Sichiro
911.6She	callout_init(&sc->sc_co, 0);
921.1Sichiro	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
931.1Sichiro}
941.1Sichiro
951.1Sichiro#if 0
961.1Sichirostatic int
971.11Schsnappinr_activate(device_t self, enum devact act)
981.1Sichiro{
991.1Sichiro	printf("nappinr_activate act=%d\n", act);
1001.1Sichiro	return 0;
1011.1Sichiro}
1021.1Sichiro#endif
1031.1Sichiro
1041.1Sichirostatic void
1051.1Sichironappinr_callout(void *arg)
1061.1Sichiro{
1071.1Sichiro	static const int	ptn[] = { 1, 2, 4, 8, 4, 2 };
1081.11Schs	struct nappinr_softc	*sc = arg;
1091.10Smatt	uint32_t v;
1101.1Sichiro
1111.10Smatt	v = ptn[sc->sc_pos++ % 6];
1121.10Smatt	v |= ptn[sc->sc_pos++ % 6] << 4;
1131.10Smatt	bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0, v);
1141.1Sichiro	callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc);
1151.1Sichiro}
116