1 /* $NetBSD: lpt_pcctwo.c,v 1.11 2008/04/28 20:23:54 martin Exp $ */
4 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Device Driver back-end for the PCCChip2's parallel printer port
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: lpt_pcctwo.c,v 1.11 2008/04/28 20:23:54 martin Exp $");
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/syslog.h>
48 #include <dev/mvme/lptvar.h>
49 #include <dev/mvme/pcctworeg.h>
50 #include <dev/mvme/pcctwovar.h>
55 int lpt_pcctwo_match(device_t
, cfdata_t
, void *);
56 void lpt_pcctwo_attach(device_t
, device_t
, void *);
58 CFATTACH_DECL_NEW(lpt_pcctwo
, sizeof(struct lpt_softc
),
59 lpt_pcctwo_match
, lpt_pcctwo_attach
, NULL
, NULL
);
61 extern struct cfdriver lpt_cd
;
64 int lpt_pcctwo_intr(void *);
65 void lpt_pcctwo_open(struct lpt_softc
*, int);
66 void lpt_pcctwo_close(struct lpt_softc
*);
67 void lpt_pcctwo_iprime(struct lpt_softc
*);
68 void lpt_pcctwo_speed(struct lpt_softc
*, int);
69 int lpt_pcctwo_notrdy(struct lpt_softc
*, int);
70 void lpt_pcctwo_wr_data(struct lpt_softc
*, u_char
);
72 struct lpt_funcs lpt_pcctwo_funcs
= {
83 lpt_pcctwo_match(device_t parent
, cfdata_t cf
, void *args
)
85 struct pcctwo_attach_args
*pa
;
89 if (strcmp(pa
->pa_name
, lpt_cd
.cd_name
))
93 if (machineid
!= MVME_167
&& machineid
!= MVME_177
)
98 if (machineid
!= MVME_187
)
102 pa
->pa_ipl
= cf
->pcctwocf_ipl
;
109 lpt_pcctwo_attach(device_t parent
, device_t self
, void *args
)
111 struct pcctwo_attach_args
*pa
;
112 struct lpt_softc
*sc
;
114 pa
= (struct pcctwo_attach_args
*) args
;
115 sc
= device_private(self
);
118 /* The printer registers are part of the PCCChip2's own registers. */
119 sc
->sc_bust
= pa
->pa_bust
;
120 bus_space_map(pa
->pa_bust
, pa
->pa_offset
, PCC2REG_SIZE
, 0,
123 sc
->sc_ipl
= pa
->pa_ipl
& PCCTWO_ICR_LEVEL_MASK
;
124 sc
->sc_laststatus
= 0;
125 sc
->sc_funcs
= &lpt_pcctwo_funcs
;
127 aprint_normal(": PCCchip2 Parallel Printer\n");
130 * Disable interrupts until device is opened
132 pcc2_reg_write(sc
, PCC2REG_PRT_ACK_ICSR
, 0);
133 pcc2_reg_write(sc
, PCC2REG_PRT_FAULT_ICSR
, 0);
134 pcc2_reg_write(sc
, PCC2REG_PRT_SEL_ICSR
, 0);
135 pcc2_reg_write(sc
, PCC2REG_PRT_PE_ICSR
, 0);
136 pcc2_reg_write(sc
, PCC2REG_PRT_BUSY_ICSR
, 0);
137 pcc2_reg_write(sc
, PCC2REG_PRT_CONTROL
, 0);
140 * Main attachment code
144 /* Register the event counter */
145 evcnt_attach_dynamic(&sc
->sc_evcnt
, EVCNT_TYPE_INTR
,
146 pcctwointr_evcnt(sc
->sc_ipl
), "printer", device_xname(sc
->sc_dev
));
149 * Hook into the printer interrupt
151 pcctwointr_establish(PCCTWOV_PRT_ACK
, lpt_pcctwo_intr
, sc
->sc_ipl
, sc
,
156 * Handle printer interrupts
159 lpt_pcctwo_intr(void *arg
)
161 struct lpt_softc
*sc
;
164 sc
= (struct lpt_softc
*) arg
;
166 /* is printer online and ready for output */
167 if (lpt_pcctwo_notrdy(sc
, 0) || lpt_pcctwo_notrdy(sc
, 1))
172 if (pcc2_reg_read(sc
, PCC2REG_PRT_INPUT_STATUS
) & PCCTWO_PRT_IN_SR_PINT
)
173 pcc2_reg_write(sc
, PCC2REG_PRT_ACK_ICSR
,
174 sc
->sc_icr
| PCCTWO_ICR_ICLR
);
180 lpt_pcctwo_open(struct lpt_softc
*sc
, int int_ena
)
184 pcc2_reg_write(sc
, PCC2REG_PRT_ACK_ICSR
,
185 PCCTWO_ICR_ICLR
| PCCTWO_ICR_EDGE
);
187 pcc2_reg_write(sc
, PCC2REG_PRT_CONTROL
,
188 pcc2_reg_read(sc
, PCC2REG_PRT_CONTROL
) | PCCTWO_PRT_CTRL_DOEN
);
192 sc
->sc_icr
= sc
->sc_ipl
| PCCTWO_ICR_EDGE
;
193 pcc2_reg_write(sc
, PCC2REG_PRT_ACK_ICSR
, sc
->sc_icr
);
199 lpt_pcctwo_close(struct lpt_softc
*sc
)
202 pcc2_reg_write(sc
, PCC2REG_PRT_ACK_ICSR
,
203 PCCTWO_ICR_ICLR
| PCCTWO_ICR_EDGE
);
204 pcc2_reg_write(sc
, PCC2REG_PRT_CONTROL
, 0);
208 lpt_pcctwo_iprime(struct lpt_softc
*sc
)
211 pcc2_reg_write(sc
, PCC2REG_PRT_CONTROL
,
212 pcc2_reg_read(sc
, PCC2REG_PRT_CONTROL
) | PCCTWO_PRT_CTRL_INP
);
216 pcc2_reg_write(sc
, PCC2REG_PRT_CONTROL
,
217 pcc2_reg_read(sc
, PCC2REG_PRT_CONTROL
) & ~PCCTWO_PRT_CTRL_INP
);
223 lpt_pcctwo_speed(struct lpt_softc
*sc
, int speed
)
227 reg
= pcc2_reg_read(sc
, PCC2REG_PRT_CONTROL
);
229 if (speed
== LPT_STROBE_FAST
)
230 reg
|= PCCTWO_PRT_CTRL_FAST
;
232 reg
&= ~PCCTWO_PRT_CTRL_FAST
;
234 pcc2_reg_write(sc
, PCC2REG_PRT_CONTROL
, reg
);
238 lpt_pcctwo_notrdy(struct lpt_softc
*sc
, int err
)
243 #define LPS_INVERT (PCCTWO_PRT_IN_SR_SEL)
244 #define LPS_MASK (PCCTWO_PRT_IN_SR_SEL | PCCTWO_PRT_IN_SR_FLT | \
245 PCCTWO_PRT_IN_SR_BSY | PCCTWO_PRT_IN_SR_PE)
247 status
= pcc2_reg_read(sc
, PCC2REG_PRT_INPUT_STATUS
) ^ LPS_INVERT
;
251 new = status
& ~sc
->sc_laststatus
;
252 sc
->sc_laststatus
= status
;
254 if (new & PCCTWO_PRT_IN_SR_SEL
)
255 log(LOG_NOTICE
, "%s: offline\n",
256 device_xname(sc
->sc_dev
));
257 else if (new & PCCTWO_PRT_IN_SR_PE
)
258 log(LOG_NOTICE
, "%s: out of paper\n",
259 device_xname(sc
->sc_dev
));
260 else if (new & PCCTWO_PRT_IN_SR_FLT
)
261 log(LOG_NOTICE
, "%s: output error\n",
262 device_xname(sc
->sc_dev
));
269 lpt_pcctwo_wr_data(struct lpt_softc
*sc
, u_char data
)
272 pcc2_reg_write16(sc
, PCC2REG_PRT_DATA
, (u_int16_t
) data
);