Home | History | Annotate | Line # | Download | only in common
hpib.c revision 1.4
      1 /*	$NetBSD: hpib.c,v 1.4 2003/11/14 16:52:40 tsutsui Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1990, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)hpib.c	8.1 (Berkeley) 6/10/93
     32  */
     33 
     34 /*
     35  * HPIB driver
     36  */
     37 #include <sys/param.h>
     38 #include <sys/reboot.h>
     39 
     40 #include <lib/libsa/stand.h>
     41 
     42 #include <hp300/stand/common/device.h>
     43 #include <hp300/stand/common/hpibvar.h>
     44 #include <hp300/stand/common/samachdep.h>
     45 
     46 #include <hp300/dev/dioreg.h>
     47 
     48 int	internalhpib = IIOV(DIO_IHPIBADDR);
     49 
     50 struct	hpib_softc hpib_softc[NHPIB];
     51 
     52 void
     53 hpibinit()
     54 {
     55 	extern struct hp_hw sc_table[];
     56 	struct hp_hw *hw;
     57 	struct hpib_softc *hs;
     58 	int i;
     59 
     60 	i = 0;
     61 	for (hw = sc_table; i < NHPIB && hw < &sc_table[MAXCTLRS]; hw++) {
     62 		if (!HW_ISHPIB(hw))
     63 			continue;
     64 		hs = &hpib_softc[i];
     65 		hs->sc_addr = hw->hw_kva;
     66 		if (nhpibinit(i) == 0)
     67 			if (fhpibinit(i) == 0)
     68 				continue;
     69 		if (howto & RB_ASKNAME)
     70 			printf("hpib%d at sc%d\n", i, hw->hw_sc);
     71 		hw->hw_pa = (caddr_t) i;	/* XXX for autoconfig */
     72 		hs->sc_alive = 1;
     73 		i++;
     74 	}
     75 }
     76 
     77 int
     78 hpibalive(unit)
     79 	int unit;
     80 {
     81 	if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0)
     82 		return 0;
     83 	return 1;
     84 }
     85 
     86 int
     87 hpibid(unit, slave)
     88 	int unit, slave;
     89 {
     90 	short id;
     91 	int rv;
     92 
     93 	if (hpib_softc[unit].sc_type == HPIBC)
     94 		rv = fhpibrecv(unit, 31, slave, (char *)&id, 2);
     95 	else
     96 		rv = nhpibrecv(unit, 31, slave, (char *)&id, 2);
     97 	if (rv != 2)
     98 		return 0;
     99 	return id;
    100 }
    101 
    102 int
    103 hpibsend(unit, slave, sec, buf, cnt)
    104 	int unit, slave, sec;
    105 	char *buf;
    106 	int cnt;
    107 {
    108 	if (hpib_softc[unit].sc_type == HPIBC)
    109 		return (fhpibsend(unit, slave, sec, buf, cnt));
    110 	return nhpibsend(unit, slave, sec, buf, cnt);
    111 }
    112 
    113 int
    114 hpibrecv(unit, slave, sec, buf, cnt)
    115 	int unit, slave, sec;
    116 	char *buf;
    117 	int cnt;
    118 {
    119 	if (hpib_softc[unit].sc_type == HPIBC)
    120 		return (fhpibrecv(unit, slave, sec, buf, cnt));
    121 	return nhpibrecv(unit, slave, sec, buf, cnt);
    122 }
    123 
    124 int
    125 hpibswait(unit, slave)
    126 	int unit, slave;
    127 {
    128 	int timo = 1000000;
    129 	int (*poll)(int);
    130 
    131 	slave = 0x80 >> slave;
    132 	if (hpib_softc[unit].sc_type == HPIBC)
    133 		poll = fhpibppoll;
    134 	else
    135 		poll = nhpibppoll;
    136 	while (((*poll)(unit) & slave) == 0)
    137 		if (--timo == 0)
    138 			break;
    139 	if (timo == 0)
    140 		return -1;
    141 	return 0;
    142 }
    143 
    144 void
    145 hpibgo(unit, slave, sec, addr, count, flag)
    146 	int unit, slave, sec;
    147 	char *addr;
    148 	int count, flag;
    149 {
    150 
    151 	if (hpib_softc[unit].sc_type == HPIBC)
    152 		if (flag == F_READ)
    153 			fhpibrecv(unit, slave, sec, addr, count);
    154 		else
    155 			fhpibsend(unit, slave, sec, addr, count);
    156 	else
    157 		if (flag == F_READ)
    158 			nhpibrecv(unit, slave, sec, addr, count);
    159 		else
    160 			nhpibsend(unit, slave, sec, addr, count);
    161 }
    162