Home | History | Annotate | Line # | Download | only in pci
cyber.c revision 1.2
      1  1.2  fredb /*	$NetBSD: cyber.c,v 1.2 2004/02/04 01:58:44 fredb Exp $	*/
      2  1.1  fredb 
      3  1.1  fredb /*-
      4  1.1  fredb  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5  1.1  fredb  * All rights reserved.
      6  1.1  fredb  *
      7  1.1  fredb  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  fredb  * by Frederick S. Bruckman.
      9  1.1  fredb  *
     10  1.1  fredb  * Redistribution and use in source and binary forms, with or without
     11  1.1  fredb  * modification, are permitted provided that the following conditions
     12  1.1  fredb  * are met:
     13  1.1  fredb  * 1. Redistributions of source code must retain the above copyright
     14  1.1  fredb  *    notice, this list of conditions and the following disclaimer.
     15  1.1  fredb  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  fredb  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  fredb  *    documentation and/or other materials provided with the distribution.
     18  1.1  fredb  * 3. All advertising materials mentioning features or use of this software
     19  1.1  fredb  *    must display the following acknowledgement:
     20  1.1  fredb  *        This product includes software developed by the NetBSD
     21  1.1  fredb  *        Foundation, Inc. and its contributors.
     22  1.1  fredb  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  fredb  *    contributors may be used to endorse or promote products derived
     24  1.1  fredb  *    from this software without specific prior written permission.
     25  1.1  fredb  *
     26  1.1  fredb  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  fredb  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  fredb  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  fredb  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  fredb  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  fredb  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  fredb  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  fredb  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  fredb  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  fredb  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  fredb  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  fredb  */
     38  1.1  fredb 
     39  1.1  fredb /* Store one "Usr" register on an SIIG Cyberserial multiport PCI card. */
     40  1.1  fredb 
     41  1.1  fredb #include <sys/cdefs.h>
     42  1.2  fredb __KERNEL_RCSID(0, "$NetBSD: cyber.c,v 1.2 2004/02/04 01:58:44 fredb Exp $");
     43  1.1  fredb 
     44  1.1  fredb #include <sys/param.h>
     45  1.1  fredb #include <sys/device.h>
     46  1.1  fredb #include <sys/termios.h> /* XXX for tcflag_t in comvar.h */
     47  1.1  fredb 
     48  1.1  fredb #include <machine/bus.h>
     49  1.1  fredb 
     50  1.1  fredb #include <dev/pci/cyberreg.h>
     51  1.1  fredb #include <dev/pci/cybervar.h>
     52  1.1  fredb 
     53  1.1  fredb void
     54  1.1  fredb write_siig10x_usrreg(pci_chipset_tag_t pc, pcitag_t tag, int usrregno,
     55  1.1  fredb     int high_speed)
     56  1.1  fredb {
     57  1.2  fredb 	pcireg_t curregs, newregs;
     58  1.1  fredb 
     59  1.1  fredb 	newregs = curregs = pci_conf_read(pc, tag, SIIG10x_USR_BASE);
     60  1.1  fredb 
     61  1.1  fredb 	if (high_speed)					/* Clear bit. */
     62  1.1  fredb 		switch (usrregno) {
     63  1.1  fredb 		case 0:
     64  1.1  fredb 			newregs &= ~SIIG10x_USR0_MASK;
     65  1.1  fredb 			break;
     66  1.1  fredb 		case 1:
     67  1.1  fredb 			newregs &= ~SIIG10x_USR1_MASK;
     68  1.1  fredb 			break;
     69  1.1  fredb 		case 2:
     70  1.1  fredb 			newregs &= ~SIIG10x_USR2_MASK;
     71  1.1  fredb 			break;
     72  1.1  fredb 		case 3:
     73  1.1  fredb 			newregs &= ~SIIG10x_USR3_MASK;
     74  1.1  fredb 		}
     75  1.1  fredb 	else /* if (!high_speed) */			/* Set bit. */
     76  1.1  fredb 		switch (usrregno) {
     77  1.1  fredb 		case 0:
     78  1.1  fredb 			newregs |= SIIG10x_USR0_MASK;
     79  1.1  fredb 			break;
     80  1.1  fredb 		case 1:
     81  1.1  fredb 			newregs |= SIIG10x_USR1_MASK;
     82  1.1  fredb 			break;
     83  1.1  fredb 		case 2:
     84  1.1  fredb 			newregs |= SIIG10x_USR2_MASK;
     85  1.1  fredb 			break;
     86  1.1  fredb 		case 3:
     87  1.1  fredb 			newregs |= SIIG10x_USR3_MASK;
     88  1.1  fredb 		}
     89  1.1  fredb 
     90  1.1  fredb 	if (newregs != curregs)
     91  1.1  fredb 		pci_conf_write(pc, tag, SIIG10x_USR_BASE, newregs);
     92  1.1  fredb }
     93  1.1  fredb 
     94  1.1  fredb void
     95  1.1  fredb write_siig20x_usrreg(pci_chipset_tag_t pc, pcitag_t tag, int usrregno,
     96  1.1  fredb     int high_speed)
     97  1.1  fredb {
     98  1.2  fredb 	pcireg_t curreg, newreg;
     99  1.1  fredb 	int offset;
    100  1.1  fredb 
    101  1.1  fredb 	switch (usrregno) {
    102  1.1  fredb 		case 0:
    103  1.1  fredb 			offset = SIIG20x_USR0;
    104  1.1  fredb 			break;
    105  1.1  fredb 		case 1:
    106  1.1  fredb 			offset = SIIG20x_USR1;
    107  1.1  fredb 			break;
    108  1.1  fredb 		default:
    109  1.1  fredb 			return;
    110  1.1  fredb 	}
    111  1.1  fredb 
    112  1.1  fredb 	newreg = curreg = pci_conf_read(pc, tag, offset);
    113  1.1  fredb 
    114  1.1  fredb 	if (high_speed)					/* Clear bit. */
    115  1.1  fredb 		newreg &= ~SIIG20x_USR_MASK;
    116  1.1  fredb 	else /* if (!high_speed) */			/* Set bit. */
    117  1.1  fredb 		newreg |= SIIG20x_USR_MASK;
    118  1.1  fredb 
    119  1.1  fredb 	if (newreg != curreg)
    120  1.1  fredb 		pci_conf_write(pc, tag, offset, newreg);
    121  1.1  fredb }
    122