1/* $NetBSD: hpib.c,v 1.8 2006/07/02 11:10:28 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 48int internalhpib = IIOV(DIO_IHPIBADDR); 49 50struct hpib_softc hpib_softc[NHPIB]; 51 52void 53hpibinit(void) 54{ 55 struct hp_hw *hw; 56 struct hpib_softc *hs; 57 int i; 58 59 i = 0; 60 for (hw = sc_table; i < NHPIB && hw < &sc_table[MAXCTLRS]; hw++) { 61 if (!HW_ISHPIB(hw)) 62 continue; 63 hs = &hpib_softc[i]; 64 hs->sc_addr = hw->hw_kva; 65 if (nhpibinit(i) == 0) 66 if (fhpibinit(i) == 0) 67 continue; 68 if (howto & RB_ASKNAME) 69 printf("hpib%d at sc%d\n", i, hw->hw_sc); 70 hw->hw_pa = (void *) i; /* XXX for autoconfig */ 71 hs->sc_alive = 1; 72 i++; 73 } 74} 75 76int 77hpibalive(int unit) 78{ 79 if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0) 80 return 0; 81 return 1; 82} 83 84int 85hpibid(int unit, int slave) 86{ 87 short id; 88 int rv; 89 90 if (hpib_softc[unit].sc_type == HPIBC) 91 rv = fhpibrecv(unit, 31, slave, (uint8_t *)&id, 2); 92 else 93 rv = nhpibrecv(unit, 31, slave, (uint8_t *)&id, 2); 94 if (rv != 2) 95 return 0; 96 return id; 97} 98 99int 100hpibsend(int unit, int slave, int sec, uint8_t *buf, int cnt) 101{ 102 103 if (hpib_softc[unit].sc_type == HPIBC) 104 return (fhpibsend(unit, slave, sec, buf, cnt)); 105 return nhpibsend(unit, slave, sec, buf, cnt); 106} 107 108int 109hpibrecv(int unit, int slave, int sec, uint8_t *buf, int cnt) 110{ 111 112 if (hpib_softc[unit].sc_type == HPIBC) 113 return (fhpibrecv(unit, slave, sec, buf, cnt)); 114 return nhpibrecv(unit, slave, sec, buf, cnt); 115} 116 117int 118hpibswait(int unit, int slave) 119{ 120 int timo = 1000000; 121 int (*poll)(int); 122 123 slave = 0x80 >> slave; 124 if (hpib_softc[unit].sc_type == HPIBC) 125 poll = fhpibppoll; 126 else 127 poll = nhpibppoll; 128 while (((*poll)(unit) & slave) == 0) 129 if (--timo == 0) 130 break; 131 if (timo == 0) 132 return -1; 133 return 0; 134} 135 136void 137hpibgo(int unit, int slave, int sec, uint8_t *addr, int count, int flag) 138{ 139 140 if (hpib_softc[unit].sc_type == HPIBC) 141 if (flag == F_READ) 142 fhpibrecv(unit, slave, sec, addr, count); 143 else 144 fhpibsend(unit, slave, sec, addr, count); 145 else 146 if (flag == F_READ) 147 nhpibrecv(unit, slave, sec, addr, count); 148 else 149 nhpibsend(unit, slave, sec, addr, count); 150} 151