1995-12-02 21:21:49 +03:00
|
|
|
/* $NetBSD: hpib.c,v 1.7 1995/12/02 18:22:01 thorpej Exp $ */
|
1994-10-26 10:22:45 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
1994-05-23 09:58:16 +04:00
|
|
|
* Copyright (c) 1982, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-05-13 17:56:20 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-10-26 10:22:45 +03:00
|
|
|
* @(#)hpib.c 8.2 (Berkeley) 1/12/94
|
1993-05-13 17:56:20 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HPIB driver
|
|
|
|
*/
|
|
|
|
#include "hpib.h"
|
|
|
|
#if NHPIB > 0
|
|
|
|
|
1994-05-23 09:58:16 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1994-05-23 09:58:16 +04:00
|
|
|
#include <hp300/dev/device.h>
|
|
|
|
#include <hp300/dev/hpibvar.h>
|
|
|
|
#include <hp300/dev/dmavar.h>
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <hp300/hp300/isr.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1995-12-02 21:21:49 +03:00
|
|
|
int hpibmatch __P((struct hp_ctlr *));
|
|
|
|
void hpibattach __P((struct hp_ctlr *));
|
1995-11-19 20:57:15 +03:00
|
|
|
void hpibstart __P((int));
|
|
|
|
void hpibgo __P((int, int, int, void *, int, int, int));
|
|
|
|
void hpibdone __P((int));
|
|
|
|
int hpibintr __P((int));
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
struct driver hpibdriver = {
|
1995-12-02 21:21:49 +03:00
|
|
|
hpibmatch,
|
|
|
|
hpibattach,
|
1995-11-19 20:57:15 +03:00
|
|
|
"hpib",
|
|
|
|
(int(*)())hpibstart, /* XXX */
|
|
|
|
(int(*)())hpibgo, /* XXX */
|
|
|
|
hpibintr,
|
|
|
|
(int(*)())hpibdone, /* XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hpib_softc hpib_softc[NHPIB];
|
|
|
|
struct isr hpib_isr[NHPIB];
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
extern int nhpibtype __P((struct hp_ctlr *)); /* XXX */
|
|
|
|
extern int fhpibtype __P((struct hp_ctlr *)); /* XXX */
|
1995-12-02 21:21:49 +03:00
|
|
|
extern void nhpibattach __P((struct hp_ctlr *)); /* XXX */
|
|
|
|
extern void fhpibattach __P((struct hp_ctlr *)); /* XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
int hpibtimeout = 100000; /* # of status tests before we give up */
|
1994-05-23 09:58:16 +04:00
|
|
|
int hpibidtimeout = 10000; /* # of status tests for hpibid() calls */
|
1993-05-13 17:56:20 +04:00
|
|
|
int hpibdmathresh = 3; /* byte count beyond which to attempt dma */
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1995-12-02 21:21:49 +03:00
|
|
|
hpibmatch(hc)
|
1993-05-13 17:56:20 +04:00
|
|
|
register struct hp_ctlr *hc;
|
|
|
|
{
|
1995-12-02 21:21:49 +03:00
|
|
|
struct hp_hw *hw = hc->hp_args;
|
|
|
|
extern caddr_t internalhpib;
|
|
|
|
|
|
|
|
/* Special case for internal HP-IB. */
|
|
|
|
if ((hw->hw_sc == 7) && internalhpib)
|
|
|
|
goto hwid_ok;
|
|
|
|
|
|
|
|
switch (hw->hw_id) {
|
|
|
|
case 8: /* 98625B */
|
|
|
|
case 128: /* 98624A */
|
|
|
|
hwid_ok:
|
|
|
|
if (nhpibtype(hc) || fhpibtype(hc))
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hpibattach(hc)
|
|
|
|
struct hp_ctlr *hc;
|
|
|
|
{
|
|
|
|
struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the appropriate "attach" routine for this controller.
|
|
|
|
* The type is set in the "type" routine.
|
|
|
|
*/
|
|
|
|
switch (hs->sc_type) {
|
|
|
|
case HPIBA:
|
|
|
|
case HPIBB:
|
|
|
|
nhpibattach(hc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HPIBC:
|
|
|
|
fhpibattach(hc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("hpibattach: unknown type 0x%x", hs->sc_type);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1995-11-19 20:57:15 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
hs->sc_hc = hc;
|
|
|
|
hs->sc_dq.dq_unit = hc->hp_unit;
|
|
|
|
hs->sc_dq.dq_driver = &hpibdriver;
|
|
|
|
hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq;
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
/* Establish the interrupt handler. */
|
1993-05-13 17:56:20 +04:00
|
|
|
hpib_isr[hc->hp_unit].isr_intr = hpibintr;
|
|
|
|
hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl;
|
|
|
|
hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit;
|
|
|
|
isrlink(&hpib_isr[hc->hp_unit]);
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
/* Reset the controller, display what we've seen, and we're done. */
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibreset(hc->hp_unit);
|
1995-12-02 21:21:49 +03:00
|
|
|
printf(": %s\n", hs->sc_descrip);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibreset(unit)
|
|
|
|
register int unit;
|
|
|
|
{
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
(hpib_softc[unit].sc_controller->hpib_reset)(unit);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibreq(dq)
|
|
|
|
register struct devqueue *dq;
|
|
|
|
{
|
|
|
|
register struct devqueue *hq;
|
|
|
|
|
|
|
|
hq = &hpib_softc[dq->dq_ctlr].sc_sq;
|
|
|
|
insque(dq, hq->dq_back);
|
|
|
|
if (dq->dq_back == hq)
|
|
|
|
return(1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibfree(dq)
|
|
|
|
register struct devqueue *dq;
|
|
|
|
{
|
|
|
|
register struct devqueue *hq;
|
|
|
|
|
|
|
|
hq = &hpib_softc[dq->dq_ctlr].sc_sq;
|
|
|
|
remque(dq);
|
|
|
|
if ((dq = hq->dq_forw) != hq)
|
|
|
|
(dq->dq_driver->d_start)(dq->dq_unit);
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibid(unit, slave)
|
1994-05-23 09:58:16 +04:00
|
|
|
int unit, slave;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
short id;
|
|
|
|
int ohpibtimeout;
|
|
|
|
|
|
|
|
/*
|
1994-05-23 09:58:16 +04:00
|
|
|
* XXX shorten timeout value so autoconfig doesn't
|
|
|
|
* take forever on slow CPUs.
|
1993-05-13 17:56:20 +04:00
|
|
|
*/
|
|
|
|
ohpibtimeout = hpibtimeout;
|
1994-05-23 09:58:16 +04:00
|
|
|
hpibtimeout = hpibidtimeout * cpuspeed;
|
1993-05-13 17:56:20 +04:00
|
|
|
if (hpibrecv(unit, 31, slave, &id, 2) != 2)
|
|
|
|
id = 0;
|
|
|
|
hpibtimeout = ohpibtimeout;
|
|
|
|
return(id);
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibsend(unit, slave, sec, addr, cnt)
|
1995-11-19 20:57:15 +03:00
|
|
|
int unit, slave, sec, cnt;
|
|
|
|
void *addr;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
return ((hpib_softc[unit].sc_controller->hpib_send)(unit, slave,
|
|
|
|
sec, addr, cnt));
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibrecv(unit, slave, sec, addr, cnt)
|
1995-11-19 20:57:15 +03:00
|
|
|
int unit, slave, sec, cnt;
|
|
|
|
void *addr;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
return ((hpib_softc[unit].sc_controller->hpib_recv)(unit, slave,
|
|
|
|
sec, addr, cnt));
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibpptest(unit, slave)
|
|
|
|
register int unit;
|
1994-05-23 09:58:16 +04:00
|
|
|
int slave;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
return ((hpib_softc[unit].sc_controller->hpib_ppoll)(unit) &
|
|
|
|
(0x80 >> slave));
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1995-01-07 13:30:10 +03:00
|
|
|
hpibppclear(unit)
|
|
|
|
int unit;
|
|
|
|
{
|
|
|
|
hpib_softc[unit].sc_flags &= ~HPIBF_PPOLL;
|
|
|
|
}
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibawait(unit)
|
1994-05-23 09:58:16 +04:00
|
|
|
int unit;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
register struct hpib_softc *hs = &hpib_softc[unit];
|
|
|
|
|
|
|
|
hs->sc_flags |= HPIBF_PPOLL;
|
1995-11-19 20:57:15 +03:00
|
|
|
(hs->sc_controller->hpib_ppwatch)((void *)unit);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibswait(unit, slave)
|
|
|
|
register int unit;
|
1994-05-23 09:58:16 +04:00
|
|
|
int slave;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
register int timo = hpibtimeout;
|
1995-11-19 20:57:15 +03:00
|
|
|
register int mask, (*ppoll) __P((int));
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
ppoll = hpib_softc[unit].sc_controller->hpib_ppoll;
|
1993-05-13 17:56:20 +04:00
|
|
|
mask = 0x80 >> slave;
|
|
|
|
while (((ppoll)(unit) & mask) == 0)
|
|
|
|
if (--timo == 0) {
|
1995-12-02 21:21:49 +03:00
|
|
|
printf("%s: swait timeout\n",
|
|
|
|
hpib_softc[unit].sc_hc->hp_xname);
|
1993-05-13 17:56:20 +04:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibustart(unit)
|
1994-05-23 09:58:16 +04:00
|
|
|
int unit;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
register struct hpib_softc *hs = &hpib_softc[unit];
|
|
|
|
|
|
|
|
if (hs->sc_type == HPIBA)
|
|
|
|
hs->sc_dq.dq_ctlr = DMA0;
|
|
|
|
else
|
|
|
|
hs->sc_dq.dq_ctlr = DMA0 | DMA1;
|
|
|
|
if (dmareq(&hs->sc_dq))
|
|
|
|
return(1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibstart(unit)
|
1994-05-23 09:58:16 +04:00
|
|
|
int unit;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
register struct devqueue *dq;
|
|
|
|
|
|
|
|
dq = hpib_softc[unit].sc_sq.dq_forw;
|
|
|
|
(dq->dq_driver->d_go)(dq->dq_unit);
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1995-01-07 13:30:10 +03:00
|
|
|
hpibgo(unit, slave, sec, addr, count, rw, timo)
|
1995-11-19 20:57:15 +03:00
|
|
|
int unit, slave, sec, count, rw, timo;
|
|
|
|
void *addr;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
(hpib_softc[unit].sc_controller->hpib_go)(unit, slave, sec,
|
|
|
|
addr, count, rw, timo);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibdone(unit)
|
|
|
|
register int unit;
|
|
|
|
{
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
(hpib_softc[unit].sc_controller->hpib_done)(unit);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
hpibintr(unit)
|
|
|
|
register int unit;
|
|
|
|
{
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
return ((hpib_softc[unit].sc_controller->hpib_intr)(unit));
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
1995-11-19 20:57:15 +03:00
|
|
|
#endif /* NHPIB > 0 */
|