Home | History | Annotate | Line # | Download | only in shark
      1 /*	$NetBSD: ns87307.c,v 1.7 2016/07/07 06:55:38 msaitoh 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 <sys/cdefs.h>
     60 __KERNEL_RCSID(0, "$NetBSD: ns87307.c,v 1.7 2016/07/07 06:55:38 msaitoh Exp $");
     61 
     62 #include "opt_ddb.h"
     63 
     64 #include <sys/param.h>
     65 #include <sys/device.h>
     66 #include <sys/systm.h>
     67 #include <sys/bus.h>
     68 
     69 #include <machine/intr.h>
     70 
     71 #include <dev/isa/isavar.h>
     72 #include <shark/shark/ns87307reg.h>
     73 
     74 
     75 
     76 
     77 
     78 
     79 
     80 
     81 
     82 /*
     84 **++
     85 **  FUNCTION NAME:
     86 **
     87 **      i87307KbdConfig
     88 **
     89 **  FUNCTIONAL DESCRIPTION:
     90 **
     91 **     This function configures the Keyboard controller logical
     92 **     device on the ns87307 SuperIO hardware.  It sets up the addresses
     93 **     of the data and command ports and configures the irq number and
     94 **     triggering for the device.  It then activates the device.
     95 **
     96 **  FORMAL PARAMETERS:
     97 **
     98 **       iot
     99 **       kbdBase
    100 **       irqNum
    101 **
    102 **  IMPLICIT INPUTS:
    103 **
    104 **      None.
    105 **
    106 **  IMPLICIT OUTPUTS:
    107 **
    108 **      None.
    109 **
    110 **  function value or completion codes
    111 **
    112 **      true    configuration of the kdb device was successful.
    113 **      false   configuration of the kdb device failed.
    114 **
    115 **  SIDE EFFECTS:
    116 **
    117 **      None.
    118 **--
    119 */
    120 int
    121 i87307KbdConfig(bus_space_tag_t iot,
    122 		u_int           kbdBase,
    123 		u_int           irqNum )
    124 {
    125     u_int                configured = false;
    126     bus_space_handle_t   ioh;
    127 
    128 
    129     if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh )))
    130     {
    131 	NSIO_SELECT_DEV( iot, ioh,  NSIO_DEV_KBC );
    132 	NSIO_DEACTIVATE_DEV( iot, ioh );
    133 	NSIO_CONFIG_IRQ( iot, ioh, irqNum, NSIO_IRQ_LEVEL | NSIO_IRQ_HIGH );
    134 	NSIO_CONFIG_KBCDATA( iot, ioh, kbdBase );
    135 	NSIO_CONFIG_KBCCMD(iot, ioh, kbdBase+4);
    136 	NSIO_WRITE_REG( iot, ioh, NSIO_KBC_CFG, 0x80 );
    137 	NSIO_ACTIVATE_DEV( iot, ioh );
    138 	NSIO_CONFIG_KBCDEBUG( iot, ioh );
    139 
    140 	/* unmap the space so can probe later
    141 	*/
    142 	bus_space_unmap( iot, ioh, NSIO_NPORTS );
    143 
    144 	configured = true;
    145     }
    146 
    147     return (configured);
    148 } /* End i87307KbdConfig() */
    149 
    150 
    151 
    152 /*
    154 **++
    155 **  FUNCTION NAME:
    156 **
    157 **      i87307MouseConfig
    158 **
    159 **  FUNCTIONAL DESCRIPTION:
    160 **
    161 **     This function configures the Mouse logical device on the ns87307
    162 **     SuperIO chip. It sets up only the interrupt parameters since the
    163 **     mouse shares the device ports with the Keyboard. It also activates
    164 **     the device.
    165 **
    166 **  FORMAL PARAMETERS:
    167 **
    168 **       iot
    169 **       irqNum
    170 **
    171 **  IMPLICIT INPUTS:
    172 **
    173 **      None.
    174 **
    175 **  IMPLICIT OUTPUTS:
    176 **
    177 **      None.
    178 **
    179 **  function value or completion codes
    180 **
    181 **      true    configuration of the kdb device was successful.
    182 **      false   configuration of the kdb device failed.
    183 **
    184 **  SIDE EFFECTS:
    185 **
    186 **      None.
    187 **--
    188 */
    189 int
    190 i87307MouseConfig(bus_space_tag_t iot,
    191 		  u_int           irqNum )
    192 {
    193     u_int                configured;
    194     bus_space_handle_t   ioh;
    195 
    196     configured = false; /* be a pessimist */
    197 
    198     if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh )))
    199     {
    200 	/* Now do the mouse logical device IRQ settup.
    201 	*/
    202 	NSIO_SELECT_DEV( iot, ioh, NSIO_DEV_MOUSE );
    203 	NSIO_DEACTIVATE_DEV( iot, ioh );
    204 	NSIO_CONFIG_IRQ( iot, ioh, irqNum, NSIO_IRQ_LEVEL | NSIO_IRQ_HIGH);
    205 	NSIO_ACTIVATE_DEV( iot, ioh );
    206 	NSIO_CONFIG_DEBUG( iot, ioh );
    207 	/* unmap the space so can probe later
    208 	*/
    209 	bus_space_unmap( iot, ioh, NSIO_NPORTS );
    210 
    211 	configured = true;
    212     }
    213 
    214 
    215     return (configured);
    216 } /* End i87307MouseConfig() */
    217 
    218 
    219 
    220 /*
    221 **++
    222 **  FUNCTION NAME:
    223 **
    224 **      i87307PrinterConfig
    225 **
    226 **  FUNCTIONAL DESCRIPTION:
    227 **
    228 **     This function configures the Parrel logical device on the ns87307
    229 **     SuperIO chip.
    230 **     the device.
    231 **
    232 **  FORMAL PARAMETERS:
    233 **
    234 **       iot
    235 **       irqNum
    236 **
    237 **  IMPLICIT INPUTS:
    238 **
    239 **      None.
    240 **
    241 **  IMPLICIT OUTPUTS:
    242 **
    243 **      None.
    244 **
    245 **  function value or completion codes
    246 **
    247 **      true    configuration of the kdb device was successful.
    248 **      false   configuration of the kdb device failed.
    249 **
    250 **  SIDE EFFECTS:
    251 **
    252 **      None.
    253 **--
    254 */
    255 int
    256 i87307PrinterConfig(bus_space_tag_t iot,
    257 		  u_int           irqNum )
    258 {
    259     u_int                configured = false;
    260     bus_space_handle_t   ioh;
    261 
    262     u_char value;
    263 
    264     if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh )))
    265     {
    266         /* select the printer */
    267         NSIO_SELECT_DEV( iot, ioh,  NSIO_DEV_LPT );
    268     	NSIO_DEACTIVATE_DEV( iot, ioh );
    269 
    270         value = NSIO_LPT_TRISTATE_DISABLE |
    271                 NSIO_LPT_CLOCK_DISABLE    |
    272                 NSIO_LPT_REPORT_SPP       |
    273                 NSIO_LPT_REG403_DISABLE   |
    274                 NSIO_LPT_SPP_EXTENDED;
    275     	NSIO_WRITE_REG( iot, ioh, NSIO_CFG_REG0, value);
    276 
    277         /* set the type of interrupt */
    278         value = NSIO_IRQ_HIGH |
    279                 NSIO_IRQ_LEVEL;
    280         NSIO_CONFIG_IRQ( iot, ioh, irqNum,value);
    281 
    282     	/* activate the device */
    283     	NSIO_ACTIVATE_DEV( iot, ioh );
    284 
    285 
    286         /* unmap the space so can probe later */
    287     	bus_space_unmap( iot, ioh, NSIO_NPORTS );
    288 
    289     	configured = true;
    290     }
    291 
    292 
    293     return (configured);
    294 } /* End i87307PrinterConfig() */
    295 
    296 
    297 
    298 /*
    299 **++
    300 **  FUNCTION NAME:
    301 **
    302 **      nsioConfigPrint
    303 **
    304 **  FUNCTIONAL DESCRIPTION:
    305 **
    306 **     This function prints out the irq, iobase etc, for the
    307 **     currently selected logical device.  It is intended to
    308 **     be used for debugging only.
    309 **
    310 **  FORMAL PARAMETERS:
    311 **
    312 **       sc     pointer to the nsio's softc structure
    313 **
    314 **  IMPLICIT INPUTS:
    315 **
    316 **      None.
    317 **
    318 **  IMPLICIT OUTPUTS:
    319 **
    320 **      None.
    321 **
    322 **  function value or completion codes
    323 **
    324 **      None
    325 **
    326 **  SIDE EFFECTS:
    327 **
    328 **      None.
    329 **
    330 **--
    331 */
    332 //#ifdef DDB
    333 void nsioConfigPrint(bus_space_tag_t nsioIot,
    334                      bus_space_handle_t  nsioIoh )
    335 {
    336     u_char     dev;
    337     u_char     activate;
    338     u_char     iorange;
    339     u_char     iobaseh;
    340     u_char     iobasel;
    341     u_char     irq;
    342     u_char     irqType;
    343     u_char     dma1;
    344     u_char     dma2;
    345     u_char     reg0;
    346 
    347     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_LOGDEV, dev );
    348     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_ACTIVATE, activate );
    349     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IORNGCHK, iorange );
    350     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IOBASEH, iobaseh );
    351     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IOBASEL, iobasel );
    352     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IRQ, irq );
    353     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IRQTYPE, irqType );
    354     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_DMA1, dma1 );
    355     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_DMA2, dma2 );
    356     NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_REG0, reg0 );
    357 
    358     printf("nsio config for logical device %d\n", dev );
    359     printf("activate:   %x\n",activate);
    360     printf("iorange:    %x\n",iorange);
    361     printf("iobase:     %x\n",(iobaseh << 8) | iobasel);
    362     printf("irq:        %x\n",irq);
    363     printf("irqtype:    %x\n",irqType);
    364     printf("dma1:       %x\n",dma1);
    365     printf("dma2:       %x\n",dma2) ;
    366     printf("reg0:       %x\n",reg0);
    367 }
    368 //#endif
    369