Home | History | Annotate | Line # | Download | only in dev
hpib.c revision 1.6
      1  1.6  thorpej /*	$NetBSD: hpib.c,v 1.6 1995/11/19 17:57:17 thorpej Exp $	*/
      2  1.4      cgd 
      3  1.1      cgd /*
      4  1.3  mycroft  * Copyright (c) 1982, 1990, 1993
      5  1.3  mycroft  *	The Regents of the University of California.  All rights reserved.
      6  1.1      cgd  *
      7  1.1      cgd  * Redistribution and use in source and binary forms, with or without
      8  1.1      cgd  * modification, are permitted provided that the following conditions
      9  1.1      cgd  * are met:
     10  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     11  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     12  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     14  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     15  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     16  1.1      cgd  *    must display the following acknowledgement:
     17  1.1      cgd  *	This product includes software developed by the University of
     18  1.1      cgd  *	California, Berkeley and its contributors.
     19  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     20  1.1      cgd  *    may be used to endorse or promote products derived from this software
     21  1.1      cgd  *    without specific prior written permission.
     22  1.1      cgd  *
     23  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1      cgd  * SUCH DAMAGE.
     34  1.1      cgd  *
     35  1.4      cgd  *	@(#)hpib.c	8.2 (Berkeley) 1/12/94
     36  1.1      cgd  */
     37  1.1      cgd 
     38  1.1      cgd /*
     39  1.1      cgd  * HPIB driver
     40  1.1      cgd  */
     41  1.1      cgd #include "hpib.h"
     42  1.1      cgd #if NHPIB > 0
     43  1.1      cgd 
     44  1.3  mycroft #include <sys/param.h>
     45  1.3  mycroft #include <sys/systm.h>
     46  1.3  mycroft #include <sys/buf.h>
     47  1.3  mycroft 
     48  1.3  mycroft #include <hp300/dev/device.h>
     49  1.3  mycroft #include <hp300/dev/hpibvar.h>
     50  1.3  mycroft #include <hp300/dev/dmavar.h>
     51  1.1      cgd 
     52  1.3  mycroft #include <machine/cpu.h>
     53  1.3  mycroft #include <hp300/hp300/isr.h>
     54  1.1      cgd 
     55  1.6  thorpej int	hpibinit __P((struct hp_ctlr *));
     56  1.6  thorpej void	hpibstart __P((int));
     57  1.6  thorpej void	hpibgo __P((int, int, int, void *, int, int, int));
     58  1.6  thorpej void	hpibdone __P((int));
     59  1.6  thorpej int	hpibintr __P((int));
     60  1.6  thorpej 
     61  1.1      cgd struct	driver hpibdriver = {
     62  1.6  thorpej 	hpibinit,
     63  1.6  thorpej 	"hpib",
     64  1.6  thorpej 	(int(*)())hpibstart,			/* XXX */
     65  1.6  thorpej 	(int(*)())hpibgo,			/* XXX */
     66  1.6  thorpej 	hpibintr,
     67  1.6  thorpej 	(int(*)())hpibdone,			/* XXX */
     68  1.1      cgd };
     69  1.1      cgd 
     70  1.1      cgd struct	hpib_softc hpib_softc[NHPIB];
     71  1.1      cgd struct	isr hpib_isr[NHPIB];
     72  1.6  thorpej 
     73  1.6  thorpej extern	int nhpibtype __P((struct hp_ctlr *));	/* XXX */
     74  1.6  thorpej extern	int fhpibtype __P((struct hp_ctlr *));	/* XXX */
     75  1.1      cgd 
     76  1.1      cgd int	hpibtimeout = 100000;	/* # of status tests before we give up */
     77  1.3  mycroft int	hpibidtimeout = 10000;	/* # of status tests for hpibid() calls */
     78  1.1      cgd int	hpibdmathresh = 3;	/* byte count beyond which to attempt dma */
     79  1.1      cgd 
     80  1.6  thorpej int
     81  1.1      cgd hpibinit(hc)
     82  1.1      cgd 	register struct hp_ctlr *hc;
     83  1.1      cgd {
     84  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
     85  1.1      cgd 
     86  1.6  thorpej 	if ((nhpibtype(hc) == 0) && (fhpibtype(hc) == 0))
     87  1.1      cgd 		return(0);
     88  1.6  thorpej 
     89  1.1      cgd 	hs->sc_hc = hc;
     90  1.1      cgd 	hs->sc_dq.dq_unit = hc->hp_unit;
     91  1.1      cgd 	hs->sc_dq.dq_driver = &hpibdriver;
     92  1.1      cgd 	hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq;
     93  1.6  thorpej 
     94  1.6  thorpej 	/* Establish the interrupt handler. */
     95  1.1      cgd 	hpib_isr[hc->hp_unit].isr_intr = hpibintr;
     96  1.1      cgd 	hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl;
     97  1.1      cgd 	hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit;
     98  1.1      cgd 	isrlink(&hpib_isr[hc->hp_unit]);
     99  1.6  thorpej 
    100  1.6  thorpej 	/* Reset the controller, display what we've seen, and we're done. */
    101  1.1      cgd 	hpibreset(hc->hp_unit);
    102  1.6  thorpej 	printf("hpib%d: %s\n", hc->hp_unit, hs->sc_descrip);
    103  1.1      cgd 	return(1);
    104  1.1      cgd }
    105  1.1      cgd 
    106  1.6  thorpej void
    107  1.1      cgd hpibreset(unit)
    108  1.1      cgd 	register int unit;
    109  1.1      cgd {
    110  1.6  thorpej 
    111  1.6  thorpej 	(hpib_softc[unit].sc_controller->hpib_reset)(unit);
    112  1.1      cgd }
    113  1.1      cgd 
    114  1.6  thorpej int
    115  1.1      cgd hpibreq(dq)
    116  1.1      cgd 	register struct devqueue *dq;
    117  1.1      cgd {
    118  1.1      cgd 	register struct devqueue *hq;
    119  1.1      cgd 
    120  1.1      cgd 	hq = &hpib_softc[dq->dq_ctlr].sc_sq;
    121  1.1      cgd 	insque(dq, hq->dq_back);
    122  1.1      cgd 	if (dq->dq_back == hq)
    123  1.1      cgd 		return(1);
    124  1.1      cgd 	return(0);
    125  1.1      cgd }
    126  1.1      cgd 
    127  1.6  thorpej void
    128  1.1      cgd hpibfree(dq)
    129  1.1      cgd 	register struct devqueue *dq;
    130  1.1      cgd {
    131  1.1      cgd 	register struct devqueue *hq;
    132  1.1      cgd 
    133  1.1      cgd 	hq = &hpib_softc[dq->dq_ctlr].sc_sq;
    134  1.1      cgd 	remque(dq);
    135  1.1      cgd 	if ((dq = hq->dq_forw) != hq)
    136  1.1      cgd 		(dq->dq_driver->d_start)(dq->dq_unit);
    137  1.1      cgd }
    138  1.1      cgd 
    139  1.6  thorpej int
    140  1.1      cgd hpibid(unit, slave)
    141  1.3  mycroft 	int unit, slave;
    142  1.1      cgd {
    143  1.1      cgd 	short id;
    144  1.1      cgd 	int ohpibtimeout;
    145  1.1      cgd 
    146  1.1      cgd 	/*
    147  1.3  mycroft 	 * XXX shorten timeout value so autoconfig doesn't
    148  1.3  mycroft 	 * take forever on slow CPUs.
    149  1.1      cgd 	 */
    150  1.1      cgd 	ohpibtimeout = hpibtimeout;
    151  1.3  mycroft 	hpibtimeout = hpibidtimeout * cpuspeed;
    152  1.1      cgd 	if (hpibrecv(unit, 31, slave, &id, 2) != 2)
    153  1.1      cgd 		id = 0;
    154  1.1      cgd 	hpibtimeout = ohpibtimeout;
    155  1.1      cgd 	return(id);
    156  1.1      cgd }
    157  1.1      cgd 
    158  1.6  thorpej int
    159  1.1      cgd hpibsend(unit, slave, sec, addr, cnt)
    160  1.6  thorpej 	int unit, slave, sec, cnt;
    161  1.6  thorpej 	void *addr;
    162  1.1      cgd {
    163  1.6  thorpej 
    164  1.6  thorpej 	return ((hpib_softc[unit].sc_controller->hpib_send)(unit, slave,
    165  1.6  thorpej 	    sec, addr, cnt));
    166  1.1      cgd }
    167  1.1      cgd 
    168  1.6  thorpej int
    169  1.1      cgd hpibrecv(unit, slave, sec, addr, cnt)
    170  1.6  thorpej 	int unit, slave, sec, cnt;
    171  1.6  thorpej 	void *addr;
    172  1.1      cgd {
    173  1.6  thorpej 
    174  1.6  thorpej 	return ((hpib_softc[unit].sc_controller->hpib_recv)(unit, slave,
    175  1.6  thorpej 	    sec, addr, cnt));
    176  1.1      cgd }
    177  1.1      cgd 
    178  1.6  thorpej int
    179  1.1      cgd hpibpptest(unit, slave)
    180  1.1      cgd 	register int unit;
    181  1.3  mycroft 	int slave;
    182  1.1      cgd {
    183  1.1      cgd 
    184  1.6  thorpej 	return ((hpib_softc[unit].sc_controller->hpib_ppoll)(unit) &
    185  1.6  thorpej 	    (0x80 >> slave));
    186  1.1      cgd }
    187  1.1      cgd 
    188  1.6  thorpej void
    189  1.5  mycroft hpibppclear(unit)
    190  1.5  mycroft 	int unit;
    191  1.5  mycroft {
    192  1.5  mycroft 	hpib_softc[unit].sc_flags &= ~HPIBF_PPOLL;
    193  1.5  mycroft }
    194  1.5  mycroft 
    195  1.1      cgd hpibawait(unit)
    196  1.3  mycroft 	int unit;
    197  1.1      cgd {
    198  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    199  1.1      cgd 
    200  1.1      cgd 	hs->sc_flags |= HPIBF_PPOLL;
    201  1.6  thorpej 	(hs->sc_controller->hpib_ppwatch)((void *)unit);
    202  1.1      cgd }
    203  1.1      cgd 
    204  1.6  thorpej int
    205  1.1      cgd hpibswait(unit, slave)
    206  1.1      cgd 	register int unit;
    207  1.3  mycroft 	int slave;
    208  1.1      cgd {
    209  1.1      cgd 	register int timo = hpibtimeout;
    210  1.6  thorpej 	register int mask, (*ppoll) __P((int));
    211  1.1      cgd 
    212  1.6  thorpej 	ppoll = hpib_softc[unit].sc_controller->hpib_ppoll;
    213  1.1      cgd 	mask = 0x80 >> slave;
    214  1.1      cgd 	while (((ppoll)(unit) & mask) == 0)
    215  1.1      cgd 		if (--timo == 0) {
    216  1.1      cgd 			printf("hpib%d: swait timeout\n", unit);
    217  1.1      cgd 			return(-1);
    218  1.1      cgd 		}
    219  1.1      cgd 	return(0);
    220  1.1      cgd }
    221  1.1      cgd 
    222  1.6  thorpej int
    223  1.1      cgd hpibustart(unit)
    224  1.3  mycroft 	int unit;
    225  1.1      cgd {
    226  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    227  1.1      cgd 
    228  1.1      cgd 	if (hs->sc_type == HPIBA)
    229  1.1      cgd 		hs->sc_dq.dq_ctlr = DMA0;
    230  1.1      cgd 	else
    231  1.1      cgd 		hs->sc_dq.dq_ctlr = DMA0 | DMA1;
    232  1.1      cgd 	if (dmareq(&hs->sc_dq))
    233  1.1      cgd 		return(1);
    234  1.1      cgd 	return(0);
    235  1.1      cgd }
    236  1.1      cgd 
    237  1.6  thorpej void
    238  1.1      cgd hpibstart(unit)
    239  1.3  mycroft 	int unit;
    240  1.1      cgd {
    241  1.1      cgd 	register struct devqueue *dq;
    242  1.1      cgd 
    243  1.1      cgd 	dq = hpib_softc[unit].sc_sq.dq_forw;
    244  1.1      cgd 	(dq->dq_driver->d_go)(dq->dq_unit);
    245  1.1      cgd }
    246  1.1      cgd 
    247  1.6  thorpej void
    248  1.5  mycroft hpibgo(unit, slave, sec, addr, count, rw, timo)
    249  1.6  thorpej 	int unit, slave, sec, count, rw, timo;
    250  1.6  thorpej 	void *addr;
    251  1.1      cgd {
    252  1.6  thorpej 
    253  1.6  thorpej 	(hpib_softc[unit].sc_controller->hpib_go)(unit, slave, sec,
    254  1.6  thorpej 	    addr, count, rw, timo);
    255  1.1      cgd }
    256  1.1      cgd 
    257  1.6  thorpej void
    258  1.1      cgd hpibdone(unit)
    259  1.1      cgd 	register int unit;
    260  1.1      cgd {
    261  1.6  thorpej 
    262  1.6  thorpej 	(hpib_softc[unit].sc_controller->hpib_done)(unit);
    263  1.1      cgd }
    264  1.1      cgd 
    265  1.6  thorpej int
    266  1.1      cgd hpibintr(unit)
    267  1.1      cgd 	register int unit;
    268  1.1      cgd {
    269  1.1      cgd 
    270  1.6  thorpej 	return ((hpib_softc[unit].sc_controller->hpib_intr)(unit));
    271  1.1      cgd }
    272  1.6  thorpej #endif /* NHPIB > 0 */
    273