1 /* $NetBSD: ns87307.c,v 1.1 2002/02/10 01:58:06 thorpej Exp $ */ 2 3 /* 4 * Copyright 1997 5 * Digital Equipment Corporation. All rights reserved. 6 * 7 * This software is furnished under license and may be used and 8 * copied only in accordance with the following terms and conditions. 9 * Subject to these conditions, you may download, copy, install, 10 * use, modify and distribute this software in source and/or binary 11 * form. No title or ownership is transferred hereby. 12 * 13 * 1) Any source code used, modified or distributed must reproduce 14 * and retain this copyright notice and list of conditions as 15 * they appear in the source file. 16 * 17 * 2) No right is granted to use any trade name, trademark, or logo of 18 * Digital Equipment Corporation. Neither the "Digital Equipment 19 * Corporation" name nor any trademark or logo of Digital Equipment 20 * Corporation may be used to endorse or promote products derived 21 * from this software without the prior written permission of 22 * Digital Equipment Corporation. 23 * 24 * 3) This software is provided "AS-IS" and any express or implied 25 * warranties, including but not limited to, any implied warranties 26 * of merchantability, fitness for a particular purpose, or 27 * non-infringement are disclaimed. In no event shall DIGITAL be 28 * liable for any damages whatsoever, and in particular, DIGITAL 29 * shall not be liable for special, indirect, consequential, or 30 * incidental damages or damages for lost profits, loss of 31 * revenue or loss of use, whether such damages arise in contract, 32 * negligence, tort, under statute, in equity, at law or otherwise, 33 * even if advised of the possibility of such damage. 34 */ 35 36 /* 37 **++ 38 ** 39 ** FACILITY: 40 ** 41 ** ns87307 SuperIO chip configuration functions. 42 ** 43 ** ABSTRACT: 44 ** 45 ** This file contains routines to configure the National Semiconductor 46 ** PC87307VUL SuperIO chip. 47 ** 48 ** AUTHORS: 49 ** 50 ** John Court, Digital Equipment Corporation. 51 ** 52 ** CREATION DATE: 53 ** 54 ** 16/4/1997 55 ** 56 **-- 57 */ 58 59 #include "opt_ddb.h" 60 61 #include <sys/param.h> 62 #include <sys/device.h> 63 #include <sys/systm.h> 64 65 #include <machine/intr.h> 66 #include <machine/bus.h> 67 68 #include <dev/isa/isavar.h> 69 #include <shark/shark/ns87307reg.h> 70 71 72 73 74 75 76 77 78 79 /* 80 **++ 81 ** FUNCTION NAME: 82 ** 83 ** i87307KbdConfig 84 ** 85 ** FUNCTIONAL DESCRIPTION: 86 ** 87 ** This function configures the Keyboard controller logical 88 ** device on the ns87307 SuperIO hardware. It sets up the addresses 89 ** of the data and command ports and configures the irq number and 90 ** triggering for the device. It then activates the device. 91 ** 92 ** FORMAL PARAMETERS: 93 ** 94 ** iot 95 ** kbdBase 96 ** irqNum 97 ** 98 ** IMPLICIT INPUTS: 99 ** 100 ** None. 101 ** 102 ** IMPLICIT OUTPUTS: 103 ** 104 ** None. 105 ** 106 ** function value or completion codes 107 ** 108 ** TRUE configuration of the kdb device was successful. 109 ** FALSE configuration of the kdb device failed. 110 ** 111 ** SIDE EFFECTS: 112 ** 113 ** None. 114 **-- 115 */ 116 int 117 i87307KbdConfig(bus_space_tag_t iot, 118 u_int kbdBase, 119 u_int irqNum ) 120 { 121 u_int configured = FALSE; 122 bus_space_handle_t ioh; 123 124 125 if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh ))) 126 { 127 NSIO_SELECT_DEV( iot, ioh, NSIO_DEV_KBC ); 128 NSIO_DEACTIVATE_DEV( iot, ioh ); 129 NSIO_CONFIG_IRQ( iot, ioh, irqNum, NSIO_IRQ_LEVEL | NSIO_IRQ_HIGH ); 130 NSIO_CONFIG_KBCDATA( iot, ioh, kbdBase ); 131 NSIO_CONFIG_KBCCMD(iot, ioh, kbdBase+4); 132 NSIO_WRITE_REG( iot, ioh, NSIO_KBC_CFG, 0x80 ); 133 NSIO_ACTIVATE_DEV( iot, ioh ); 134 NSIO_CONFIG_KBCDEBUG( iot, ioh ); 135 136 /* unmap the space so can probe later 137 */ 138 bus_space_unmap( iot, ioh, NSIO_NPORTS ); 139 140 configured = TRUE; 141 } 142 143 return (configured); 144 } /* End i87307KbdConfig() */ 145 146 147 148 /* 149 **++ 150 ** FUNCTION NAME: 151 ** 152 ** i87307MouseConfig 153 ** 154 ** FUNCTIONAL DESCRIPTION: 155 ** 156 ** This function configures the Mouse logical device on the ns87307 157 ** SuperIO chip. It sets up only the interrupt parameters since the 158 ** mouse shares the device ports with the Keyboard. It also activates 159 ** the device. 160 ** 161 ** FORMAL PARAMETERS: 162 ** 163 ** iot 164 ** irqNum 165 ** 166 ** IMPLICIT INPUTS: 167 ** 168 ** None. 169 ** 170 ** IMPLICIT OUTPUTS: 171 ** 172 ** None. 173 ** 174 ** function value or completion codes 175 ** 176 ** TRUE configuration of the kdb device was successful. 177 ** FALSE configuration of the kdb device failed. 178 ** 179 ** SIDE EFFECTS: 180 ** 181 ** None. 182 **-- 183 */ 184 int 185 i87307MouseConfig(bus_space_tag_t iot, 186 u_int irqNum ) 187 { 188 u_int configured; 189 bus_space_handle_t ioh; 190 191 configured = FALSE; /* be a pessimist */ 192 193 if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh ))) 194 { 195 /* Now do the mouse logical device IRQ settup. 196 */ 197 NSIO_SELECT_DEV( iot, ioh, NSIO_DEV_MOUSE ); 198 NSIO_DEACTIVATE_DEV( iot, ioh ); 199 NSIO_CONFIG_IRQ( iot, ioh, irqNum, NSIO_IRQ_LEVEL | NSIO_IRQ_HIGH); 200 NSIO_ACTIVATE_DEV( iot, ioh ); 201 NSIO_CONFIG_DEBUG( iot, ioh ); 202 /* unmap the space so can probe later 203 */ 204 bus_space_unmap( iot, ioh, NSIO_NPORTS ); 205 206 configured = TRUE; 207 } 208 209 210 return (configured); 211 } /* End i87307MouseConfig() */ 212 213 214 215 /* 216 **++ 217 ** FUNCTION NAME: 218 ** 219 ** i87307PrinterConfig 220 ** 221 ** FUNCTIONAL DESCRIPTION: 222 ** 223 ** This function configures the Parrel logical device on the ns87307 224 ** SuperIO chip. 225 ** the device. 226 ** 227 ** FORMAL PARAMETERS: 228 ** 229 ** iot 230 ** irqNum 231 ** 232 ** IMPLICIT INPUTS: 233 ** 234 ** None. 235 ** 236 ** IMPLICIT OUTPUTS: 237 ** 238 ** None. 239 ** 240 ** function value or completion codes 241 ** 242 ** TRUE configuration of the kdb device was successful. 243 ** FALSE configuration of the kdb device failed. 244 ** 245 ** SIDE EFFECTS: 246 ** 247 ** None. 248 **-- 249 */ 250 int 251 i87307PrinterConfig(bus_space_tag_t iot, 252 u_int irqNum ) 253 { 254 u_int configured = FALSE; 255 bus_space_handle_t ioh; 256 257 u_char value; 258 259 if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh ))) 260 { 261 /* select the printer */ 262 NSIO_SELECT_DEV( iot, ioh, NSIO_DEV_LPT ); 263 NSIO_DEACTIVATE_DEV( iot, ioh ); 264 265 value = NSIO_LPT_TRISTATE_DISABLE | 266 NSIO_LPT_CLOCK_DISABLE | 267 NSIO_LPT_REPORT_SPP | 268 NSIO_LPT_REG403_DISABLE | 269 NSIO_LPT_SPP_EXTENDED; 270 NSIO_WRITE_REG( iot, ioh, NSIO_CFG_REG0, value); 271 272 /* set the type of interupt */ 273 value = NSIO_IRQ_HIGH | 274 NSIO_IRQ_LEVEL; 275 NSIO_CONFIG_IRQ( iot, ioh, irqNum,value); 276 277 /* activate the device */ 278 NSIO_ACTIVATE_DEV( iot, ioh ); 279 280 281 /* unmap the space so can probe later */ 282 bus_space_unmap( iot, ioh, NSIO_NPORTS ); 283 284 configured = TRUE; 285 } 286 287 288 return (configured); 289 } /* End i87307PrinterConfig() */ 290 291 292 293 /* 294 **++ 295 ** FUNCTION NAME: 296 ** 297 ** nsioConfigPrint 298 ** 299 ** FUNCTIONAL DESCRIPTION: 300 ** 301 ** This function prints out the irq, iobase etc, for the 302 ** currently selected logical device. It is intended to 303 ** be used for debugging only. 304 ** 305 ** FORMAL PARAMETERS: 306 ** 307 ** sc pointer to the nsio's softc structure 308 ** 309 ** IMPLICIT INPUTS: 310 ** 311 ** None. 312 ** 313 ** IMPLICIT OUTPUTS: 314 ** 315 ** None. 316 ** 317 ** function value or completion codes 318 ** 319 ** None 320 ** 321 ** SIDE EFFECTS: 322 ** 323 ** None. 324 ** 325 **-- 326 */ 327 //#ifdef DDB 328 void nsioConfigPrint(bus_space_tag_t nsioIot, 329 bus_space_handle_t nsioIoh ) 330 { 331 u_char dev; 332 u_char activate; 333 u_char iorange; 334 u_char iobaseh; 335 u_char iobasel; 336 u_char irq; 337 u_char irqType; 338 u_char dma1; 339 u_char dma2; 340 u_char reg0; 341 342 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_LOGDEV, dev ); 343 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_ACTIVATE, activate ); 344 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IORNGCHK, iorange ); 345 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IOBASEH, iobaseh ); 346 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IOBASEL, iobasel ); 347 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IRQ, irq ); 348 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IRQTYPE, irqType ); 349 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_DMA1, dma1 ); 350 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_DMA2, dma2 ); 351 NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_REG0, reg0 ); 352 353 printf("nsio config for logical device %d\n", dev ); 354 printf("activate: %x\n",activate); 355 printf("iorange: %x\n",iorange); 356 printf("iobase: %x\n",(iobaseh << 8) | iobasel); 357 printf("irq: %x\n",irq); 358 printf("irqtype: %x\n",irqType); 359 printf("dma1: %x\n",dma1); 360 printf("dma2: %x\n",dma2) ; 361 printf("reg0: %x\n",reg0); 362 } 363 //#endif 364