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