Home | History | Annotate | Line # | Download | only in sbus
bpp.c revision 1.3.2.1
      1  1.3.2.1  minoura /*	$NetBSD: bpp.c,v 1.3.2.1 2000/06/22 17:08:06 minoura Exp $ */
      2      1.1       pk 
      3      1.1       pk /*-
      4      1.1       pk  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5      1.1       pk  * All rights reserved.
      6      1.1       pk  *
      7      1.1       pk  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1       pk  * by Paul Kranenburg.
      9      1.1       pk  *
     10      1.1       pk  * Redistribution and use in source and binary forms, with or without
     11      1.1       pk  * modification, are permitted provided that the following conditions
     12      1.1       pk  * are met:
     13      1.1       pk  * 1. Redistributions of source code must retain the above copyright
     14      1.1       pk  *    notice, this list of conditions and the following disclaimer.
     15      1.1       pk  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1       pk  *    notice, this list of conditions and the following disclaimer in the
     17      1.1       pk  *    documentation and/or other materials provided with the distribution.
     18      1.1       pk  * 3. All advertising materials mentioning features or use of this software
     19      1.1       pk  *    must display the following acknowledgement:
     20      1.1       pk  *        This product includes software developed by the NetBSD
     21      1.1       pk  *        Foundation, Inc. and its contributors.
     22      1.1       pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1       pk  *    contributors may be used to endorse or promote products derived
     24      1.1       pk  *    from this software without specific prior written permission.
     25      1.1       pk  *
     26      1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1       pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1       pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1       pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1       pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1       pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1       pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1       pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1       pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1       pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1       pk  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1       pk  */
     38      1.1       pk 
     39      1.1       pk #include <sys/param.h>
     40      1.1       pk #include <sys/ioctl.h>
     41      1.1       pk #include <sys/fcntl.h>
     42      1.1       pk #include <sys/systm.h>
     43      1.1       pk #include <sys/kernel.h>
     44      1.1       pk #include <sys/vnode.h>
     45      1.1       pk #include <sys/poll.h>
     46      1.1       pk #include <sys/select.h>
     47      1.1       pk #include <sys/malloc.h>
     48      1.1       pk #include <sys/proc.h>
     49      1.1       pk #include <sys/signalvar.h>
     50      1.1       pk #include <sys/conf.h>
     51      1.1       pk #include <sys/errno.h>
     52      1.1       pk #include <sys/device.h>
     53      1.1       pk 
     54      1.1       pk #include <machine/conf.h>
     55      1.1       pk #include <machine/bus.h>
     56      1.1       pk #include <machine/autoconf.h>
     57      1.1       pk 
     58      1.1       pk #include <dev/ic/lsi64854reg.h>
     59      1.1       pk #include <dev/ic/lsi64854var.h>
     60      1.1       pk 
     61      1.1       pk #include <dev/sbus/sbusvar.h>
     62      1.1       pk #include <dev/sbus/bppreg.h>
     63      1.1       pk 
     64      1.1       pk #define splbpp()	spltty()	/* XXX */
     65      1.1       pk 
     66      1.1       pk #if 0
     67      1.1       pk struct bpp_param {
     68      1.1       pk 	int	bpp_dss;		/* data setup to strobe */
     69      1.1       pk 	int	bpp_dsw;		/* data strobe width */
     70      1.1       pk 	int	bpp_outputpins;		/* Select/Autofeed/Init pins */
     71      1.1       pk 	int	bpp_inputpins;		/* Error/Select/Paperout pins */
     72      1.1       pk };
     73      1.1       pk #endif
     74      1.1       pk 
     75      1.1       pk struct hwstate {
     76      1.1       pk 	u_int16_t	hw_hcr;		/* Hardware config register */
     77      1.1       pk 	u_int16_t	hw_ocr;		/* Operation config register */
     78      1.1       pk 	u_int8_t	hw_tcr;		/* Transfer Control register */
     79      1.1       pk 	u_int8_t	hw_or;		/* Output register */
     80      1.1       pk 	u_int16_t	hw_irq;		/* IRQ; polarity bits only */
     81      1.1       pk };
     82      1.1       pk 
     83      1.1       pk struct bpp_softc {
     84      1.1       pk 	struct lsi64854_softc	sc_lsi64854;	/* base device */
     85      1.1       pk 	struct sbusdev	sc_sd;			/* sbus device */
     86      1.1       pk 
     87      1.1       pk 	size_t		sc_bufsz;		/* temp buffer */
     88      1.1       pk 	caddr_t		sc_buf;
     89      1.1       pk 
     90      1.1       pk 	int		sc_error;		/* bottom-half error */
     91      1.1       pk 	int		sc_flags;
     92      1.1       pk #define BPP_OPEN	0x01		/* Device is open */
     93      1.1       pk #define BPP_XCLUDE	0x02		/* Exclusive-open mode */
     94      1.1       pk #define BPP_ASYNC	0x04		/* Asynchronous I/O mode */
     95      1.1       pk #define BPP_LOCKED	0x08		/* DMA in progress */
     96      1.1       pk #define BPP_WANT	0x10		/* Waiting for DMA */
     97      1.1       pk 
     98      1.1       pk 	struct selinfo	sc_rsel;
     99      1.1       pk 	struct selinfo	sc_wsel;
    100      1.1       pk 	struct proc	*sc_asyncproc;	/* Process to notify if async */
    101      1.1       pk 
    102      1.1       pk 	/* Hardware state */
    103      1.1       pk 	struct hwstate		sc_hwdefault;
    104      1.1       pk 	struct hwstate		sc_hwcurrent;
    105      1.1       pk };
    106      1.1       pk 
    107      1.1       pk static int	bppmatch	__P((struct device *, struct cfdata *, void *));
    108      1.1       pk static void	bppattach	__P((struct device *, struct device *, void *));
    109      1.1       pk static int	bppintr		__P((void *));
    110      1.1       pk static void	bpp_setparams	__P((struct bpp_softc *, struct hwstate *));
    111      1.1       pk 
    112      1.1       pk struct cfattach bpp_ca = {
    113      1.1       pk 	sizeof(struct bpp_softc), bppmatch, bppattach
    114      1.1       pk };
    115      1.1       pk 
    116      1.1       pk extern struct cfdriver bpp_cd;
    117      1.1       pk #define BPPUNIT(dev)	(minor(dev))
    118      1.1       pk 
    119      1.1       pk 
    120      1.1       pk int
    121      1.1       pk bppmatch(parent, cf, aux)
    122      1.1       pk 	struct device *parent;
    123      1.1       pk 	struct cfdata *cf;
    124      1.1       pk 	void *aux;
    125      1.1       pk {
    126      1.1       pk 	struct sbus_attach_args *sa = aux;
    127      1.1       pk 
    128      1.1       pk 	return (strcmp("SUNW,bpp", sa->sa_name) == 0);
    129      1.1       pk }
    130      1.1       pk 
    131      1.1       pk void
    132      1.1       pk bppattach(parent, self, aux)
    133      1.1       pk 	struct device *parent, *self;
    134      1.1       pk 	void *aux;
    135      1.1       pk {
    136      1.1       pk 	struct sbus_attach_args *sa = aux;
    137      1.1       pk 	struct bpp_softc *dsc = (void *)self;
    138      1.1       pk 	struct lsi64854_softc *sc = &dsc->sc_lsi64854;
    139      1.1       pk 	int burst, sbusburst;
    140      1.1       pk 	int node;
    141      1.1       pk 
    142      1.1       pk 	sc->sc_bustag = sa->sa_bustag;
    143      1.1       pk 	sc->sc_dmatag = sa->sa_dmatag;
    144      1.1       pk 	node = sa->sa_node;
    145      1.1       pk 
    146      1.1       pk 	/* Map device registers */
    147      1.1       pk 	if (bus_space_map2(sa->sa_bustag,
    148      1.1       pk 			   sa->sa_slot,
    149      1.1       pk 			   sa->sa_offset,
    150      1.1       pk 			   sa->sa_size,
    151      1.1       pk 			   BUS_SPACE_MAP_LINEAR,
    152      1.1       pk 			   0, &sc->sc_regs) != 0) {
    153      1.1       pk 		printf("%s: cannot map registers\n", self->dv_xname);
    154      1.1       pk 		return;
    155      1.1       pk 	}
    156      1.1       pk 
    157      1.1       pk 	/*
    158      1.1       pk 	 * Get transfer burst size from PROM and plug it into the
    159      1.1       pk 	 * controller registers. This is needed on the Sun4m; do
    160      1.1       pk 	 * others need it too?
    161      1.1       pk 	 */
    162      1.1       pk 	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
    163      1.1       pk 	if (sbusburst == 0)
    164      1.1       pk 		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
    165      1.1       pk 
    166      1.1       pk 	burst = getpropint(node, "burst-sizes", -1);
    167      1.1       pk 	if (burst == -1)
    168      1.1       pk 		/* take SBus burst sizes */
    169      1.1       pk 		burst = sbusburst;
    170      1.1       pk 
    171      1.1       pk 	/* Clamp at parent's burst sizes */
    172      1.1       pk 	burst &= sbusburst;
    173      1.1       pk 	sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
    174      1.1       pk 		       (burst & SBUS_BURST_16) ? 16 : 0;
    175      1.1       pk 
    176      1.1       pk 	/* Join the Sbus device family */
    177      1.1       pk 	dsc->sc_sd.sd_reset = (void *)0;
    178      1.1       pk 	sbus_establish(&dsc->sc_sd, self);
    179      1.1       pk 
    180      1.1       pk 	/* Initialize the DMA channel */
    181      1.1       pk 	sc->sc_channel = L64854_CHANNEL_PP;
    182      1.1       pk 	lsi64854_attach(sc);
    183      1.1       pk 
    184      1.3       pk 	/* Establish interrupt handler */
    185      1.3       pk 	if (sa->sa_nintr) {
    186      1.3       pk 		sc->sc_intrchain = bppintr;
    187      1.3       pk 		sc->sc_intrchainarg = dsc;
    188      1.3       pk 		(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, 0,
    189      1.3       pk 					 lsi64854_pp_intr, sc);
    190      1.3       pk 	}
    191      1.1       pk 
    192      1.1       pk 	/* Allocate buffer XXX - should actually use dmamap_uio() */
    193      1.1       pk 	dsc->sc_bufsz = 1024;
    194      1.1       pk 	dsc->sc_buf = malloc(dsc->sc_bufsz, M_DEVBUF, M_NOWAIT);
    195      1.1       pk 
    196      1.1       pk 	/* XXX read default state */
    197      1.1       pk 	{
    198      1.1       pk 	bus_space_handle_t h = sc->sc_regs;
    199      1.1       pk 	struct hwstate *hw = &dsc->sc_hwdefault;
    200      1.1       pk 	hw->hw_hcr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_HCR);
    201      1.1       pk 	hw->hw_ocr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_OCR);
    202      1.1       pk 	hw->hw_tcr = bus_space_read_1(sc->sc_bustag, h, L64854_REG_TCR);
    203      1.1       pk 	hw->hw_or = bus_space_read_1(sc->sc_bustag, h, L64854_REG_OR);
    204      1.1       pk 	}
    205      1.1       pk }
    206      1.1       pk 
    207      1.1       pk void
    208      1.1       pk bpp_setparams(sc, hw)
    209      1.1       pk 	struct bpp_softc *sc;
    210      1.1       pk 	struct hwstate *hw;
    211      1.1       pk {
    212      1.1       pk 	u_int16_t irq;
    213      1.1       pk 	bus_space_tag_t t = sc->sc_lsi64854.sc_bustag;
    214      1.1       pk 	bus_space_handle_t h = sc->sc_lsi64854.sc_regs;
    215      1.1       pk 
    216      1.1       pk 	bus_space_write_2(t, h, L64854_REG_HCR, hw->hw_hcr);
    217      1.1       pk 	bus_space_write_2(t, h, L64854_REG_OCR, hw->hw_ocr);
    218      1.1       pk 	bus_space_write_1(t, h, L64854_REG_TCR, hw->hw_tcr);
    219      1.1       pk 	bus_space_write_1(t, h, L64854_REG_OR, hw->hw_or);
    220      1.1       pk 
    221      1.1       pk 	/* Only change IRP settings in interrupt status register */
    222      1.1       pk 	irq = bus_space_read_2(t, h, L64854_REG_ICR);
    223      1.1       pk 	irq &= ~BPP_ALLIRP;
    224      1.1       pk 	irq |= (hw->hw_irq & BPP_ALLIRP);
    225      1.1       pk 	bus_space_write_2(t, h, L64854_REG_ICR, irq);
    226      1.1       pk }
    227      1.1       pk 
    228      1.1       pk int
    229      1.1       pk bppopen(dev, flags, mode, p)
    230      1.1       pk 	dev_t dev;
    231      1.1       pk 	int flags, mode;
    232      1.1       pk 	struct proc *p;
    233      1.1       pk {
    234      1.1       pk 	int unit = BPPUNIT(dev);
    235      1.1       pk 	struct bpp_softc *sc;
    236      1.1       pk 	struct lsi64854_softc *lsi;
    237      1.1       pk 	u_int16_t irq;
    238      1.1       pk 	int s;
    239      1.1       pk 
    240      1.1       pk 	if (unit >= bpp_cd.cd_ndevs)
    241      1.1       pk 		return (ENXIO);
    242      1.1       pk 	sc = bpp_cd.cd_devs[unit];
    243      1.1       pk 
    244      1.1       pk 	if ((sc->sc_flags & (BPP_OPEN|BPP_XCLUDE)) == (BPP_OPEN|BPP_XCLUDE))
    245      1.1       pk 		return (EBUSY);
    246      1.1       pk 
    247      1.1       pk 	lsi = &sc->sc_lsi64854;
    248      1.1       pk 
    249      1.1       pk 	/* Set default parameters */
    250      1.1       pk 	sc->sc_hwcurrent = sc->sc_hwdefault;
    251      1.1       pk 	s = splbpp();
    252      1.1       pk 	bpp_setparams(sc, &sc->sc_hwdefault);
    253      1.1       pk 	splx(s);
    254      1.1       pk 
    255      1.1       pk 	/* Enable interrupts */
    256      1.1       pk 	irq = BPP_ALLEN;
    257      1.1       pk 	irq |= sc->sc_hwdefault.hw_irq;
    258      1.1       pk 	bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
    259      1.1       pk 	return (0);
    260      1.1       pk }
    261      1.1       pk 
    262      1.1       pk int
    263      1.1       pk bppclose(dev, flags, mode, p)
    264      1.1       pk 	dev_t dev;
    265      1.1       pk 	int flags, mode;
    266      1.1       pk 	struct proc *p;
    267      1.1       pk {
    268      1.1       pk 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    269      1.1       pk 	struct lsi64854_softc *lsi = &sc->sc_lsi64854;
    270      1.1       pk 	u_int16_t irq;
    271      1.1       pk 
    272      1.1       pk 	/* Turn off all interrupt enables */
    273      1.1       pk 	irq = sc->sc_hwdefault.hw_irq | BPP_ALLIRQ;
    274      1.1       pk 	irq &= ~BPP_ALLEN;
    275      1.1       pk 	bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
    276      1.1       pk 
    277      1.1       pk 	sc->sc_asyncproc = NULL;
    278      1.1       pk 	sc->sc_flags = 0;
    279      1.1       pk 	return (0);
    280      1.1       pk }
    281      1.1       pk 
    282      1.1       pk int
    283      1.1       pk bppread(dev, uio, flags)
    284      1.1       pk 	dev_t dev;
    285      1.1       pk 	struct uio *uio;
    286      1.1       pk 	int flags;
    287      1.1       pk {
    288      1.1       pk 
    289      1.1       pk 	return (ENXIO);
    290      1.1       pk }
    291      1.1       pk 
    292      1.1       pk int
    293      1.1       pk bppwrite(dev, uio, flags)
    294      1.1       pk 	dev_t dev;
    295      1.1       pk 	struct uio *uio;
    296      1.1       pk 	int flags;
    297      1.1       pk {
    298      1.1       pk 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    299      1.1       pk 	struct lsi64854_softc *lsi = &sc->sc_lsi64854;
    300      1.1       pk 	int error = 0;
    301      1.1       pk 	int s;
    302      1.1       pk 
    303      1.1       pk 	/*
    304  1.3.2.1  minoura 	 * Wait until the DMA engine is free.
    305      1.1       pk 	 */
    306      1.1       pk 	s = splbpp();
    307      1.1       pk 	while ((sc->sc_flags & BPP_LOCKED) != 0) {
    308      1.1       pk 		if ((flags & IO_NDELAY) != 0) {
    309      1.1       pk 			splx(s);
    310      1.1       pk 			return (EWOULDBLOCK);
    311      1.1       pk 		}
    312      1.1       pk 
    313      1.1       pk 		sc->sc_flags |= BPP_WANT;
    314      1.1       pk 		error = tsleep(sc->sc_buf, PZERO|PCATCH, "bppwrite", 0);
    315      1.1       pk 		if (error != 0) {
    316      1.1       pk 			splx(s);
    317      1.1       pk 			return (error);
    318      1.1       pk 		}
    319      1.1       pk 	}
    320      1.1       pk 	sc->sc_flags |= BPP_LOCKED;
    321      1.1       pk 	splx(s);
    322      1.1       pk 
    323      1.1       pk 	/*
    324      1.1       pk 	 * Move data from user space into our private buffer
    325      1.1       pk 	 * and start DMA.
    326      1.1       pk 	 */
    327      1.1       pk 	while (uio->uio_resid > 0) {
    328      1.1       pk 		caddr_t bp = sc->sc_buf;
    329      1.1       pk 		size_t len = min(sc->sc_bufsz, uio->uio_resid);
    330      1.1       pk 
    331      1.1       pk 		if ((error = uiomove(bp, len, uio)) != 0)
    332      1.1       pk 			break;
    333      1.1       pk 
    334      1.1       pk 		while (len > 0) {
    335      1.1       pk 			u_int8_t tcr;
    336      1.1       pk 			size_t size = len;
    337      1.1       pk 			DMA_SETUP(lsi, &bp, &len, 0, &size);
    338      1.1       pk 
    339      1.1       pk 			/* Clear direction control bit */
    340      1.1       pk 			tcr = bus_space_read_1(lsi->sc_bustag, lsi->sc_regs,
    341      1.1       pk 						L64854_REG_TCR);
    342      1.1       pk 			tcr &= ~BPP_TCR_DIR;
    343      1.2       pk 			bus_space_write_1(lsi->sc_bustag, lsi->sc_regs,
    344      1.2       pk 					  L64854_REG_TCR, tcr);
    345      1.1       pk 
    346      1.1       pk 			/* Enable DMA */
    347  1.3.2.1  minoura 			s = splbpp();
    348      1.1       pk 			DMA_GO(lsi);
    349      1.1       pk 			error = tsleep(sc, PZERO|PCATCH, "bppdma", 0);
    350  1.3.2.1  minoura 			splx(s);
    351      1.1       pk 			if (error != 0)
    352      1.1       pk 				goto out;
    353      1.1       pk 
    354      1.1       pk 			/* Bail out if bottom half reported an error */
    355      1.1       pk 			if ((error = sc->sc_error) != 0)
    356      1.1       pk 				goto out;
    357  1.3.2.1  minoura 
    358  1.3.2.1  minoura 			len -= size;
    359      1.1       pk 		}
    360      1.1       pk 	}
    361      1.1       pk 
    362      1.1       pk out:
    363      1.1       pk 	s = splbpp();
    364      1.1       pk 	sc->sc_flags &= ~BPP_LOCKED;
    365      1.1       pk 	if ((sc->sc_flags & BPP_WANT) != 0) {
    366      1.1       pk 		sc->sc_flags &= ~BPP_WANT;
    367      1.1       pk 		wakeup(sc->sc_buf);
    368      1.1       pk 	}
    369      1.1       pk 	splx(s);
    370      1.1       pk 	return (error);
    371      1.1       pk }
    372      1.1       pk 
    373      1.1       pk /* move to header: */
    374      1.1       pk #define BPPIOCSPARAM	_IOW('P', 0x1, struct hwstate)
    375      1.1       pk #define BPPIOCGPARAM	_IOR('P', 0x2, struct hwstate)
    376      1.1       pk 
    377      1.1       pk int
    378      1.1       pk bppioctl(dev, cmd, data, flag, p)
    379      1.1       pk 	dev_t	dev;
    380      1.1       pk 	u_long	cmd;
    381      1.1       pk 	caddr_t	data;
    382      1.1       pk 	int	flag;
    383      1.1       pk 	struct	proc *p;
    384      1.1       pk {
    385      1.1       pk 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    386      1.1       pk 	struct hwstate *hw, *chw;
    387      1.1       pk 	int error = 0;
    388      1.1       pk 	int s;
    389      1.1       pk 
    390      1.1       pk 	switch(cmd) {
    391      1.1       pk 	case BPPIOCSPARAM:
    392      1.1       pk 		chw = &sc->sc_hwcurrent;
    393      1.1       pk 		hw = (struct hwstate *)data;
    394      1.1       pk 
    395      1.1       pk 		/*
    396      1.1       pk 		 * Extract and store user-settable bits.
    397      1.1       pk 		 */
    398      1.1       pk #define _bpp_set(reg,mask) do {		\
    399      1.1       pk 	chw->reg &= ~(mask);		\
    400      1.1       pk 	chw->reg |= (hw->reg & (mask));	\
    401      1.1       pk } while (0)
    402      1.1       pk 		_bpp_set(hw_hcr, BPP_HCR_DSS_MASK|BPP_HCR_DSW_MASK);
    403      1.1       pk 		_bpp_set(hw_ocr, BPP_OCR_USER);
    404      1.1       pk 		_bpp_set(hw_tcr, BPP_TCR_USER);
    405      1.1       pk 		_bpp_set(hw_or,  BPP_OR_USER);
    406      1.1       pk 		_bpp_set(hw_irq, BPP_IRQ_USER);
    407      1.1       pk #undef _bpp_set
    408      1.1       pk 
    409      1.1       pk 		/* Apply settings */
    410      1.1       pk 		s = splbpp();
    411      1.1       pk 		bpp_setparams(sc, chw);
    412      1.1       pk 		splx(s);
    413      1.1       pk 		break;
    414      1.1       pk 	case BPPIOCGPARAM:
    415      1.1       pk 		*((struct hwstate *)data) = sc->sc_hwcurrent;
    416      1.1       pk 		break;
    417      1.1       pk 	case TIOCEXCL:
    418      1.1       pk 		s = splbpp();
    419      1.1       pk 		sc->sc_flags |= BPP_XCLUDE;
    420      1.1       pk 		splx(s);
    421      1.1       pk 		break;
    422      1.1       pk 	case TIOCNXCL:
    423      1.1       pk 		s = splbpp();
    424      1.1       pk 		sc->sc_flags &= ~BPP_XCLUDE;
    425      1.1       pk 		splx(s);
    426      1.1       pk 		break;
    427      1.1       pk 	case FIOASYNC:
    428      1.1       pk 		s = splbpp();
    429      1.1       pk 		if (*(int *)data) {
    430      1.1       pk 			if (sc->sc_asyncproc != NULL)
    431      1.1       pk 				error = EBUSY;
    432      1.1       pk 			else
    433      1.1       pk 				sc->sc_asyncproc = p;
    434      1.1       pk 		} else
    435      1.1       pk 			sc->sc_asyncproc = NULL;
    436      1.1       pk 		splx(s);
    437      1.1       pk 		break;
    438      1.1       pk 	default:
    439      1.1       pk 		break;
    440      1.1       pk 	}
    441      1.1       pk 
    442      1.1       pk 	return (error);
    443      1.1       pk }
    444      1.1       pk 
    445      1.1       pk int
    446      1.1       pk bpppoll(dev, events, p)
    447      1.1       pk 	dev_t dev;
    448      1.1       pk 	int events;
    449      1.1       pk 	struct proc *p;
    450      1.1       pk {
    451      1.1       pk 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    452      1.1       pk 	int revents = 0;
    453      1.1       pk 
    454      1.1       pk 	if (events & (POLLIN | POLLRDNORM)) {
    455      1.1       pk 		/* read is not yet implemented */
    456      1.1       pk 	}
    457      1.1       pk 
    458      1.1       pk 	if (events & (POLLOUT | POLLWRNORM)) {
    459      1.1       pk 		if ((sc->sc_flags & BPP_LOCKED) == 0)
    460      1.1       pk 			revents |= (POLLOUT | POLLWRNORM);
    461      1.1       pk 	}
    462      1.1       pk 
    463      1.1       pk 	if (revents == 0) {
    464      1.1       pk 		if (events & (POLLIN | POLLRDNORM))
    465      1.1       pk 			selrecord(p, &sc->sc_rsel);
    466      1.1       pk 		if (events & (POLLOUT | POLLWRNORM))
    467      1.1       pk 			selrecord(p, &sc->sc_wsel);
    468      1.1       pk 	}
    469      1.1       pk 
    470      1.1       pk 	return (revents);
    471      1.1       pk }
    472      1.1       pk 
    473      1.1       pk int
    474      1.1       pk bppintr(arg)
    475      1.1       pk 	void *arg;
    476      1.1       pk {
    477      1.1       pk 	struct bpp_softc *sc = arg;
    478      1.1       pk 	struct lsi64854_softc *lsi = &sc->sc_lsi64854;
    479      1.1       pk 	u_int16_t irq;
    480      1.1       pk 
    481      1.1       pk 	irq = bus_space_read_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR);
    482      1.1       pk 	/* Ack all interrupts */
    483      1.1       pk 	bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR,
    484      1.1       pk 			  irq | BPP_ALLIRQ);
    485      1.1       pk 
    486      1.1       pk 	/* Did our device interrupt? */
    487      1.1       pk 	if ((irq & BPP_ALLIRQ) == 0)
    488      1.1       pk 		return (0);
    489      1.1       pk 
    490      1.1       pk 	if ((sc->sc_flags & BPP_LOCKED) != 0)
    491      1.1       pk 		wakeup(sc);
    492      1.1       pk 	else if ((sc->sc_flags & BPP_WANT) != 0) {
    493      1.1       pk 		sc->sc_flags &= ~BPP_WANT;
    494      1.1       pk 		wakeup(sc->sc_buf);
    495      1.1       pk 	} else {
    496      1.1       pk 		selwakeup(&sc->sc_wsel);
    497      1.1       pk 		if (sc->sc_asyncproc != NULL)
    498      1.1       pk 			psignal(sc->sc_asyncproc, SIGIO);
    499      1.1       pk 	}
    500      1.1       pk 	return (1);
    501      1.1       pk }
    502