1 /* $NetBSD: nappi_nr.c,v 1.11 2012/10/27 17:17:48 chs 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.11 2012/10/27 17:17:48 chs 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 <sys/bus.h> 47 48 #include <arm/ixp12x0/ixpsipvar.h> 49 50 static int nappinr_match(device_t, cfdata_t, void *); 51 static void nappinr_attach(device_t, device_t, void *); 52 #if 0 53 static int nappinr_activate(device_t, enum devact); 54 #endif 55 static void nappinr_callout(void *); 56 57 struct nappinr_softc { 58 bus_space_tag_t sc_iot; 59 bus_space_handle_t sc_ioh; 60 bus_addr_t sc_baseaddr; 61 bus_space_handle_t sc_pos; 62 struct callout sc_co; 63 }; 64 65 CFATTACH_DECL_NEW(nappinr, sizeof(struct nappinr_softc), 66 nappinr_match, nappinr_attach, NULL, NULL); 67 68 static int 69 nappinr_match(device_t parent, cfdata_t match, void *aux) 70 { 71 return (1); 72 } 73 74 static void 75 nappinr_attach(device_t parent, device_t self, void *aux) 76 { 77 struct nappinr_softc* sc = device_private(self); 78 struct ixpsip_attach_args* sa = aux; 79 80 printf("\n"); 81 82 sc->sc_iot = sa->sa_iot; 83 sc->sc_baseaddr = sa->sa_addr; 84 85 if (bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0, 86 &sc->sc_ioh)) { 87 printf("%s: unable to map registers\n", device_xname(self)); 88 return; 89 } 90 91 callout_init(&sc->sc_co, 0); 92 callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc); 93 } 94 95 #if 0 96 static int 97 nappinr_activate(device_t self, enum devact act) 98 { 99 printf("nappinr_activate act=%d\n", act); 100 return 0; 101 } 102 #endif 103 104 static void 105 nappinr_callout(void *arg) 106 { 107 static const int ptn[] = { 1, 2, 4, 8, 4, 2 }; 108 struct nappinr_softc *sc = arg; 109 uint32_t v; 110 111 v = ptn[sc->sc_pos++ % 6]; 112 v |= ptn[sc->sc_pos++ % 6] << 4; 113 bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0, v); 114 callout_reset(&sc->sc_co, hz / 10, nappinr_callout, sc); 115 } 116