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