1 /* $NetBSD: auxreg.c,v 1.40 2012/07/29 00:04:05 matt Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This software was developed by the Computer Systems Engineering group 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9 * contributed to Berkeley. 10 * 11 * All advertising materials mentioning features or use of this software 12 * must display the following acknowledgement: 13 * This product includes software developed by the University of 14 * California, Lawrence Berkeley Laboratory. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 19 * 1. Redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer. 21 * 2. Redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution. 24 * 3. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)auxreg.c 8.1 (Berkeley) 6/11/93 41 */ 42 43 #include <sys/cdefs.h> 44 __KERNEL_RCSID(0, "$NetBSD: auxreg.c,v 1.40 2012/07/29 00:04:05 matt Exp $"); 45 46 #include "opt_blink.h" 47 48 #include <sys/param.h> 49 #include <sys/systm.h> 50 #include <sys/callout.h> 51 #include <sys/device.h> 52 #include <sys/kernel.h> 53 54 #include <machine/autoconf.h> 55 56 #include <sparc/sparc/vaddrs.h> 57 #include <sparc/sparc/auxreg.h> 58 59 volatile u_char *auxio_reg; 60 u_char auxio_regval; 61 62 static int auxregmatch_mainbus(device_t, cfdata_t, void *); 63 static int auxregmatch_obio(device_t, cfdata_t, void *); 64 static void auxregattach_mainbus(device_t, device_t, void *); 65 static void auxregattach_obio(device_t, device_t, void *); 66 67 static void auxregattach(void); 68 69 CFATTACH_DECL_NEW(auxreg_mainbus, 0, 70 auxregmatch_mainbus, auxregattach_mainbus, NULL, NULL); 71 72 CFATTACH_DECL_NEW(auxreg_obio, 0, 73 auxregmatch_obio, auxregattach_obio, NULL, NULL); 74 75 #ifdef BLINK 76 static callout_t blink_ch; 77 78 static void blink(void *); 79 80 static void 81 blink(void *zero) 82 { 83 register int s; 84 85 s = splhigh(); 86 LED_FLIP; 87 splx(s); 88 /* 89 * Blink rate is: 90 * full cycle every second if completely idle (loadav = 0) 91 * full cycle every 2 seconds if loadav = 1 92 * full cycle every 3 seconds if loadav = 2 93 * etc. 94 */ 95 s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1)); 96 callout_reset(&blink_ch, s, blink, NULL); 97 } 98 #endif 99 100 /* 101 * The OPENPROM calls this "auxiliary-io" (sun4c) or "auxio" (sun4m). 102 */ 103 static int 104 auxregmatch_mainbus(device_t parent, cfdata_t cf, void *aux) 105 { 106 struct mainbus_attach_args *ma = aux; 107 108 return (strcmp("auxiliary-io", ma->ma_name) == 0); 109 } 110 111 static int 112 auxregmatch_obio(device_t parent, cfdata_t cf, void *aux) 113 { 114 union obio_attach_args *uoba = aux; 115 116 if (uoba->uoba_isobio4 != 0) 117 return (0); 118 119 return (strcmp("auxio", uoba->uoba_sbus.sa_name) == 0); 120 } 121 122 /* ARGSUSED */ 123 static void 124 auxregattach_mainbus(device_t parent, device_t self, void *aux) 125 { 126 struct mainbus_attach_args *ma = aux; 127 bus_space_handle_t bh; 128 129 if (bus_space_map2(ma->ma_bustag, 130 (bus_addr_t)ma->ma_paddr, 131 sizeof(long), 132 BUS_SPACE_MAP_LINEAR, 133 AUXREG_VA, 134 &bh) != 0) { 135 printf("auxregattach_mainbus: can't map register\n"); 136 return; 137 } 138 139 auxio_reg = AUXIO4C_REG; 140 auxio_regval = *AUXIO4C_REG | AUXIO4C_FEJ | AUXIO4C_MB1; 141 auxregattach(); 142 } 143 144 static void 145 auxregattach_obio(device_t parent, device_t self, void *aux) 146 { 147 union obio_attach_args *uoba = aux; 148 struct sbus_attach_args *sa = &uoba->uoba_sbus; 149 bus_space_handle_t bh; 150 151 if (bus_space_map2(sa->sa_bustag, 152 BUS_ADDR(sa->sa_slot, sa->sa_offset), 153 sizeof(long), 154 BUS_SPACE_MAP_LINEAR, 155 AUXREG_VA, &bh) != 0) { 156 printf("auxregattach_obio: can't map register\n"); 157 return; 158 } 159 160 auxio_reg = AUXIO4M_REG; 161 auxio_regval = *AUXIO4M_REG | AUXIO4M_MB1; 162 auxregattach(); 163 } 164 165 static void 166 auxregattach(void) 167 { 168 169 printf("\n"); 170 #ifdef BLINK 171 callout_init(&blink_ch, 0); 172 blink((void *)0); 173 #else 174 LED_ON; 175 #endif 176 } 177 178 unsigned int 179 auxregbisc(int bis, int bic) 180 { 181 register int s; 182 183 if (auxio_reg == 0) 184 /* 185 * Not all machines have an `aux' register; devices that 186 * depend on it should not get configured if it's absent. 187 */ 188 panic("no aux register"); 189 190 s = splhigh(); 191 auxio_regval = (auxio_regval | bis) & ~bic; 192 *auxio_reg = auxio_regval; 193 splx(s); 194 return (auxio_regval); 195 } 196