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