1 /* $NetBSD: auxiotwo.c,v 1.11 2012/07/29 00:04:05 matt Exp $ */ 2 3 /* 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Julian Coleman. 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 /* 33 * Based on software developed by the Computer Systems Engineering group 34 * at Lawrence Berkeley Laboratory. 35 */ 36 37 #include <sys/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: auxiotwo.c,v 1.11 2012/07/29 00:04:05 matt Exp $"); 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/device.h> 43 #include <sys/kernel.h> 44 45 #include <machine/autoconf.h> 46 47 #include <sparc/include/tctrl.h> 48 #include <sparc/sparc/auxiotwo.h> 49 #include <sparc/sparc/vaddrs.h> 50 51 volatile u_char *auxiotwo_reg; 52 u_char auxiotwo_regval; 53 54 static int serial_refcount; 55 static int serial_power; 56 57 static int auxiotwomatch(device_t, cfdata_t, void *); 58 static void auxiotwoattach(device_t, device_t, void *); 59 60 CFATTACH_DECL_NEW(auxiotwo_obio, 0, 61 auxiotwomatch, auxiotwoattach, NULL, NULL); 62 63 /* 64 * The OPENPROM calls this "auxio2". 65 */ 66 static int 67 auxiotwomatch(device_t parent, cfdata_t cf, void *aux) 68 { 69 union obio_attach_args *uoba = aux; 70 71 if (uoba->uoba_isobio4 != 0) 72 return (0); 73 74 return (strcmp("auxio2", uoba->uoba_sbus.sa_name) == 0); 75 } 76 77 static void 78 auxiotwoattach(device_t parent, device_t self, void *aux) 79 { 80 union obio_attach_args *uoba = aux; 81 struct sbus_attach_args *sa = &uoba->uoba_sbus; 82 bus_space_handle_t bh; 83 84 if (sbus_bus_map(sa->sa_bustag, 85 sa->sa_slot, sa->sa_offset, 86 sizeof(long), 87 BUS_SPACE_MAP_LINEAR, &bh) != 0) { 88 printf("auxiotwoattach: can't map register\n"); 89 return; 90 } 91 92 auxiotwo_reg = (volatile u_char *)bh; 93 auxiotwo_regval = *auxiotwo_reg; 94 serial_refcount = 0; 95 serial_power = PORT_PWR_STANDBY; 96 printf("\n"); 97 } 98 99 unsigned int 100 auxiotwobisc(int bis, int bic) 101 { 102 register int s; 103 104 if (auxiotwo_reg == 0) 105 /* 106 * Most machines do not have an `aux2' register; devices that 107 * depend on it should not get configured if it's absent. 108 */ 109 panic("no aux2 register"); 110 111 s = splhigh(); 112 auxiotwo_regval = (auxiotwo_regval | bis) & ~bic; 113 *auxiotwo_reg = auxiotwo_regval; 114 splx(s); 115 return (auxiotwo_regval); 116 } 117 118 /* 119 * Serial port state - called from zs_enable()/zs_disable() 120 */ 121 void 122 auxiotwoserialendis(int state) 123 { 124 switch (state) { 125 126 case ZS_ENABLE: 127 /* Power on the serial ports? */ 128 serial_refcount++; 129 if (serial_refcount == 1 && serial_power == PORT_PWR_STANDBY) 130 auxiotwobisc(AUXIOTWO_SON, 0); 131 break; 132 case ZS_DISABLE: 133 /* Power off the serial ports? */ 134 serial_refcount--; 135 if (!serial_refcount && serial_power == PORT_PWR_STANDBY) 136 auxiotwobisc(AUXIOTWO_SOF, 1); 137 break; 138 } 139 } 140 141 /* 142 * Set power management - called by tctrl 143 */ 144 void 145 auxiotwoserialsetapm(int state) 146 { 147 switch (state) { 148 149 case PORT_PWR_ON: 150 /* Change to: power always on */ 151 if (serial_power == PORT_PWR_OFF || 152 (serial_power == PORT_PWR_STANDBY && !serial_refcount)) 153 auxiotwobisc(AUXIOTWO_SON, 0); 154 serial_power = PORT_PWR_ON; 155 break; 156 157 case PORT_PWR_STANDBY: 158 /* Change to: power on if open */ 159 if (serial_power == PORT_PWR_ON && !serial_refcount) 160 auxiotwobisc(AUXIOTWO_SOF, 1); 161 if (serial_power == PORT_PWR_OFF && serial_refcount) 162 auxiotwobisc(AUXIOTWO_SON, 0); 163 serial_power = PORT_PWR_STANDBY; 164 break; 165 166 case PORT_PWR_OFF: 167 /* Change to: power always off */ 168 if (serial_power == PORT_PWR_ON || 169 (serial_power == PORT_PWR_STANDBY && serial_refcount)) 170 auxiotwobisc(AUXIOTWO_SOF, 1); 171 serial_power = PORT_PWR_OFF; 172 break; 173 } 174 } 175 176 /* 177 * Get power management - called by tctrl 178 */ 179 int 180 auxiotwoserialgetapm (void) 181 { 182 183 return (serial_power); 184 } 185