Home | History | Annotate | Line # | Download | only in mvme
lpt_pcctwo.c revision 1.1.2.2
      1  1.1.2.2  nathanw /*	$NetBSD: lpt_pcctwo.c,v 1.1.2.2 2002/02/28 04:13:54 nathanw Exp $	*/
      2  1.1.2.2  nathanw 
      3  1.1.2.2  nathanw /*-
      4  1.1.2.2  nathanw  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
      5  1.1.2.2  nathanw  * All rights reserved.
      6  1.1.2.2  nathanw  *
      7  1.1.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.2.2  nathanw  * by Steve C. Woodford.
      9  1.1.2.2  nathanw  *
     10  1.1.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.1.2.2  nathanw  * are met:
     13  1.1.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.1.2.2  nathanw  *    must display the following acknowledgement:
     20  1.1.2.2  nathanw  *	This product includes software developed by the NetBSD
     21  1.1.2.2  nathanw  *	Foundation, Inc. and its contributors.
     22  1.1.2.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.2.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.1.2.2  nathanw  *    from this software without specific prior written permission.
     25  1.1.2.2  nathanw  *
     26  1.1.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.2.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.2.2  nathanw  */
     38  1.1.2.2  nathanw 
     39  1.1.2.2  nathanw /*
     40  1.1.2.2  nathanw  * Device Driver back-end for the PCCChip2's parallel printer port
     41  1.1.2.2  nathanw  */
     42  1.1.2.2  nathanw 
     43  1.1.2.2  nathanw #include <sys/param.h>
     44  1.1.2.2  nathanw #include <sys/kernel.h>
     45  1.1.2.2  nathanw #include <sys/systm.h>
     46  1.1.2.2  nathanw #include <sys/device.h>
     47  1.1.2.2  nathanw #include <sys/syslog.h>
     48  1.1.2.2  nathanw 
     49  1.1.2.2  nathanw #include <machine/cpu.h>
     50  1.1.2.2  nathanw #include <machine/bus.h>
     51  1.1.2.2  nathanw 
     52  1.1.2.2  nathanw #include <dev/mvme/lptvar.h>
     53  1.1.2.2  nathanw #include <dev/mvme/pcctworeg.h>
     54  1.1.2.2  nathanw #include <dev/mvme/pcctwovar.h>
     55  1.1.2.2  nathanw 
     56  1.1.2.2  nathanw /*
     57  1.1.2.2  nathanw  * Autoconfig stuff
     58  1.1.2.2  nathanw  */
     59  1.1.2.2  nathanw int lpt_pcctwo_match __P((struct device *, struct cfdata *, void *));
     60  1.1.2.2  nathanw void lpt_pcctwo_attach __P((struct device *, struct device *, void *));
     61  1.1.2.2  nathanw 
     62  1.1.2.2  nathanw struct cfattach lpt_pcctwo_ca = {
     63  1.1.2.2  nathanw 	sizeof(struct lpt_softc), lpt_pcctwo_match, lpt_pcctwo_attach
     64  1.1.2.2  nathanw };
     65  1.1.2.2  nathanw 
     66  1.1.2.2  nathanw extern struct cfdriver lpt_cd;
     67  1.1.2.2  nathanw 
     68  1.1.2.2  nathanw 
     69  1.1.2.2  nathanw int lpt_pcctwo_intr __P((void *));
     70  1.1.2.2  nathanw void lpt_pcctwo_open __P((struct lpt_softc *, int));
     71  1.1.2.2  nathanw void lpt_pcctwo_close __P((struct lpt_softc *));
     72  1.1.2.2  nathanw void lpt_pcctwo_iprime __P((struct lpt_softc *));
     73  1.1.2.2  nathanw void lpt_pcctwo_speed __P((struct lpt_softc *, int));
     74  1.1.2.2  nathanw int lpt_pcctwo_notrdy __P((struct lpt_softc *, int));
     75  1.1.2.2  nathanw void lpt_pcctwo_wr_data __P((struct lpt_softc *, u_char));
     76  1.1.2.2  nathanw 
     77  1.1.2.2  nathanw struct lpt_funcs lpt_pcctwo_funcs = {
     78  1.1.2.2  nathanw 	lpt_pcctwo_open,
     79  1.1.2.2  nathanw 	lpt_pcctwo_close,
     80  1.1.2.2  nathanw 	lpt_pcctwo_iprime,
     81  1.1.2.2  nathanw 	lpt_pcctwo_speed,
     82  1.1.2.2  nathanw 	lpt_pcctwo_notrdy,
     83  1.1.2.2  nathanw 	lpt_pcctwo_wr_data
     84  1.1.2.2  nathanw };
     85  1.1.2.2  nathanw 
     86  1.1.2.2  nathanw /* ARGSUSED */
     87  1.1.2.2  nathanw int
     88  1.1.2.2  nathanw lpt_pcctwo_match(parent, cf, args)
     89  1.1.2.2  nathanw 	struct device *parent;
     90  1.1.2.2  nathanw 	struct cfdata *cf;
     91  1.1.2.2  nathanw 	void *args;
     92  1.1.2.2  nathanw {
     93  1.1.2.2  nathanw 	struct pcctwo_attach_args *pa;
     94  1.1.2.2  nathanw 
     95  1.1.2.2  nathanw 	pa = args;
     96  1.1.2.2  nathanw 
     97  1.1.2.2  nathanw 	if (strcmp(pa->pa_name, lpt_cd.cd_name))
     98  1.1.2.2  nathanw 		return (0);
     99  1.1.2.2  nathanw 
    100  1.1.2.2  nathanw #ifdef MVME68K
    101  1.1.2.2  nathanw 	if (machineid != MVME_167 && machineid != MVME_177)
    102  1.1.2.2  nathanw 		return (0);
    103  1.1.2.2  nathanw #endif
    104  1.1.2.2  nathanw 
    105  1.1.2.2  nathanw #ifdef MVME88K
    106  1.1.2.2  nathanw 	if (machineid != MVME_187)
    107  1.1.2.2  nathanw 		return (0);
    108  1.1.2.2  nathanw #endif
    109  1.1.2.2  nathanw 
    110  1.1.2.2  nathanw 	pa->pa_ipl = cf->pcctwocf_ipl;
    111  1.1.2.2  nathanw 
    112  1.1.2.2  nathanw 	return (1);
    113  1.1.2.2  nathanw }
    114  1.1.2.2  nathanw 
    115  1.1.2.2  nathanw /* ARGSUSED */
    116  1.1.2.2  nathanw void
    117  1.1.2.2  nathanw lpt_pcctwo_attach(parent, self, args)
    118  1.1.2.2  nathanw 	struct device *parent;
    119  1.1.2.2  nathanw 	struct device *self;
    120  1.1.2.2  nathanw 	void *args;
    121  1.1.2.2  nathanw {
    122  1.1.2.2  nathanw 	struct pcctwo_attach_args *pa;
    123  1.1.2.2  nathanw 	struct lpt_softc *sc;
    124  1.1.2.2  nathanw 
    125  1.1.2.2  nathanw 	pa = (struct pcctwo_attach_args *) args;
    126  1.1.2.2  nathanw 	sc = (struct lpt_softc *) self;
    127  1.1.2.2  nathanw 
    128  1.1.2.2  nathanw 	/* The printer registers are part of the PCCChip2's own registers. */
    129  1.1.2.2  nathanw 	sc->sc_bust = pa->pa_bust;
    130  1.1.2.2  nathanw 	bus_space_map(pa->pa_bust, pa->pa_offset, PCC2REG_SIZE, 0,
    131  1.1.2.2  nathanw 	    &sc->sc_bush);
    132  1.1.2.2  nathanw 
    133  1.1.2.2  nathanw 	sc->sc_ipl = pa->pa_ipl & PCCTWO_ICR_LEVEL_MASK;
    134  1.1.2.2  nathanw 	sc->sc_laststatus = 0;
    135  1.1.2.2  nathanw 	sc->sc_funcs = &lpt_pcctwo_funcs;
    136  1.1.2.2  nathanw 
    137  1.1.2.2  nathanw 	printf(": PCCchip2 Parallel Printer\n");
    138  1.1.2.2  nathanw 
    139  1.1.2.2  nathanw 	/*
    140  1.1.2.2  nathanw 	 * Disable interrupts until device is opened
    141  1.1.2.2  nathanw 	 */
    142  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_ACK_ICSR, 0);
    143  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_FAULT_ICSR, 0);
    144  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_SEL_ICSR, 0);
    145  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_PE_ICSR, 0);
    146  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_BUSY_ICSR, 0);
    147  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_CONTROL, 0);
    148  1.1.2.2  nathanw 
    149  1.1.2.2  nathanw 	/*
    150  1.1.2.2  nathanw 	 * Main attachment code
    151  1.1.2.2  nathanw 	 */
    152  1.1.2.2  nathanw 	lpt_attach_subr(sc);
    153  1.1.2.2  nathanw 
    154  1.1.2.2  nathanw 	/* Register the event counter */
    155  1.1.2.2  nathanw 	evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
    156  1.1.2.2  nathanw 	    pcctwointr_evcnt(sc->sc_ipl), "printer", sc->sc_dev.dv_xname);
    157  1.1.2.2  nathanw 
    158  1.1.2.2  nathanw 	/*
    159  1.1.2.2  nathanw 	 * Hook into the printer interrupt
    160  1.1.2.2  nathanw 	 */
    161  1.1.2.2  nathanw 	pcctwointr_establish(PCCTWOV_PRT_ACK, lpt_pcctwo_intr, sc->sc_ipl, sc,
    162  1.1.2.2  nathanw 	    &sc->sc_evcnt);
    163  1.1.2.2  nathanw }
    164  1.1.2.2  nathanw 
    165  1.1.2.2  nathanw /*
    166  1.1.2.2  nathanw  * Handle printer interrupts
    167  1.1.2.2  nathanw  */
    168  1.1.2.2  nathanw int
    169  1.1.2.2  nathanw lpt_pcctwo_intr(arg)
    170  1.1.2.2  nathanw 	void *arg;
    171  1.1.2.2  nathanw {
    172  1.1.2.2  nathanw 	struct lpt_softc *sc;
    173  1.1.2.2  nathanw 	int i;
    174  1.1.2.2  nathanw 
    175  1.1.2.2  nathanw 	sc = (struct lpt_softc *) arg;
    176  1.1.2.2  nathanw 
    177  1.1.2.2  nathanw 	/* is printer online and ready for output */
    178  1.1.2.2  nathanw 	if (lpt_pcctwo_notrdy(sc, 0) || lpt_pcctwo_notrdy(sc, 1))
    179  1.1.2.2  nathanw 		return (0);
    180  1.1.2.2  nathanw 
    181  1.1.2.2  nathanw 	i = lpt_intr(sc);
    182  1.1.2.2  nathanw 
    183  1.1.2.2  nathanw 	if (pcc2_reg_read(sc, PCC2REG_PRT_INPUT_STATUS) & PCCTWO_PRT_IN_SR_PINT)
    184  1.1.2.2  nathanw 		pcc2_reg_write(sc, PCC2REG_PRT_ACK_ICSR,
    185  1.1.2.2  nathanw 		    sc->sc_icr | PCCTWO_ICR_ICLR);
    186  1.1.2.2  nathanw 
    187  1.1.2.2  nathanw 	return (i);
    188  1.1.2.2  nathanw }
    189  1.1.2.2  nathanw 
    190  1.1.2.2  nathanw void
    191  1.1.2.2  nathanw lpt_pcctwo_open(sc, int_ena)
    192  1.1.2.2  nathanw 	struct lpt_softc *sc;
    193  1.1.2.2  nathanw 	int int_ena;
    194  1.1.2.2  nathanw {
    195  1.1.2.2  nathanw 	int sps;
    196  1.1.2.2  nathanw 
    197  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_ACK_ICSR,
    198  1.1.2.2  nathanw 	    PCCTWO_ICR_ICLR | PCCTWO_ICR_EDGE);
    199  1.1.2.2  nathanw 
    200  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_CONTROL,
    201  1.1.2.2  nathanw 	    pcc2_reg_read(sc, PCC2REG_PRT_CONTROL) | PCCTWO_PRT_CTRL_DOEN);
    202  1.1.2.2  nathanw 
    203  1.1.2.2  nathanw 	if (int_ena == 0) {
    204  1.1.2.2  nathanw 		sps = splhigh();
    205  1.1.2.2  nathanw 		sc->sc_icr = sc->sc_ipl | PCCTWO_ICR_EDGE;
    206  1.1.2.2  nathanw 		pcc2_reg_write(sc, PCC2REG_PRT_ACK_ICSR, sc->sc_icr);
    207  1.1.2.2  nathanw 		splx(sps);
    208  1.1.2.2  nathanw 	}
    209  1.1.2.2  nathanw }
    210  1.1.2.2  nathanw 
    211  1.1.2.2  nathanw void
    212  1.1.2.2  nathanw lpt_pcctwo_close(sc)
    213  1.1.2.2  nathanw 	struct lpt_softc *sc;
    214  1.1.2.2  nathanw {
    215  1.1.2.2  nathanw 
    216  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_ACK_ICSR,
    217  1.1.2.2  nathanw 	    PCCTWO_ICR_ICLR | PCCTWO_ICR_EDGE);
    218  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_CONTROL, 0);
    219  1.1.2.2  nathanw }
    220  1.1.2.2  nathanw 
    221  1.1.2.2  nathanw void
    222  1.1.2.2  nathanw lpt_pcctwo_iprime(sc)
    223  1.1.2.2  nathanw 	struct lpt_softc *sc;
    224  1.1.2.2  nathanw {
    225  1.1.2.2  nathanw 
    226  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_CONTROL,
    227  1.1.2.2  nathanw 	    pcc2_reg_read(sc, PCC2REG_PRT_CONTROL) | PCCTWO_PRT_CTRL_INP);
    228  1.1.2.2  nathanw 
    229  1.1.2.2  nathanw 	delay(100);
    230  1.1.2.2  nathanw 
    231  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_CONTROL,
    232  1.1.2.2  nathanw 	    pcc2_reg_read(sc, PCC2REG_PRT_CONTROL) & ~PCCTWO_PRT_CTRL_INP);
    233  1.1.2.2  nathanw 
    234  1.1.2.2  nathanw 	delay(100);
    235  1.1.2.2  nathanw }
    236  1.1.2.2  nathanw 
    237  1.1.2.2  nathanw void
    238  1.1.2.2  nathanw lpt_pcctwo_speed(sc, speed)
    239  1.1.2.2  nathanw 	struct lpt_softc *sc;
    240  1.1.2.2  nathanw 	int speed;
    241  1.1.2.2  nathanw {
    242  1.1.2.2  nathanw 	u_int8_t reg;
    243  1.1.2.2  nathanw 
    244  1.1.2.2  nathanw 	reg = pcc2_reg_read(sc, PCC2REG_PRT_CONTROL);
    245  1.1.2.2  nathanw 
    246  1.1.2.2  nathanw 	if (speed == LPT_STROBE_FAST)
    247  1.1.2.2  nathanw 		reg |= PCCTWO_PRT_CTRL_FAST;
    248  1.1.2.2  nathanw 	else
    249  1.1.2.2  nathanw 		reg &= ~PCCTWO_PRT_CTRL_FAST;
    250  1.1.2.2  nathanw 
    251  1.1.2.2  nathanw 	pcc2_reg_write(sc, PCC2REG_PRT_CONTROL, reg);
    252  1.1.2.2  nathanw }
    253  1.1.2.2  nathanw 
    254  1.1.2.2  nathanw int
    255  1.1.2.2  nathanw lpt_pcctwo_notrdy(sc, err)
    256  1.1.2.2  nathanw 	struct lpt_softc *sc;
    257  1.1.2.2  nathanw 	int err;
    258  1.1.2.2  nathanw {
    259  1.1.2.2  nathanw 	u_int8_t status;
    260  1.1.2.2  nathanw 	u_int8_t new;
    261  1.1.2.2  nathanw 
    262  1.1.2.2  nathanw #define	LPS_INVERT	(PCCTWO_PRT_IN_SR_SEL)
    263  1.1.2.2  nathanw #define	LPS_MASK	(PCCTWO_PRT_IN_SR_SEL | PCCTWO_PRT_IN_SR_FLT | \
    264  1.1.2.2  nathanw 			 PCCTWO_PRT_IN_SR_BSY | PCCTWO_PRT_IN_SR_PE)
    265  1.1.2.2  nathanw 
    266  1.1.2.2  nathanw 	status = pcc2_reg_read(sc, PCC2REG_PRT_INPUT_STATUS) ^ LPS_INVERT;
    267  1.1.2.2  nathanw 	status &= LPS_MASK;
    268  1.1.2.2  nathanw 
    269  1.1.2.2  nathanw 	if (err) {
    270  1.1.2.2  nathanw 		new = status & ~sc->sc_laststatus;
    271  1.1.2.2  nathanw 		sc->sc_laststatus = status;
    272  1.1.2.2  nathanw 
    273  1.1.2.2  nathanw 		if (new & PCCTWO_PRT_IN_SR_SEL)
    274  1.1.2.2  nathanw 			log(LOG_NOTICE, "%s: offline\n",
    275  1.1.2.2  nathanw 			    sc->sc_dev.dv_xname);
    276  1.1.2.2  nathanw 		else if (new & PCCTWO_PRT_IN_SR_PE)
    277  1.1.2.2  nathanw 			log(LOG_NOTICE, "%s: out of paper\n",
    278  1.1.2.2  nathanw 			    sc->sc_dev.dv_xname);
    279  1.1.2.2  nathanw 		else if (new & PCCTWO_PRT_IN_SR_FLT)
    280  1.1.2.2  nathanw 			log(LOG_NOTICE, "%s: output error\n",
    281  1.1.2.2  nathanw 			    sc->sc_dev.dv_xname);
    282  1.1.2.2  nathanw 	}
    283  1.1.2.2  nathanw 
    284  1.1.2.2  nathanw 	return (status);
    285  1.1.2.2  nathanw }
    286  1.1.2.2  nathanw 
    287  1.1.2.2  nathanw void
    288  1.1.2.2  nathanw lpt_pcctwo_wr_data(sc, data)
    289  1.1.2.2  nathanw 	struct lpt_softc *sc;
    290  1.1.2.2  nathanw 	u_char data;
    291  1.1.2.2  nathanw {
    292  1.1.2.2  nathanw 
    293  1.1.2.2  nathanw 	pcc2_reg_write16(sc, PCC2REG_PRT_DATA, (u_int16_t) data);
    294  1.1.2.2  nathanw }
    295