Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / mvme / lpt_pcctwo.c
blob23921fcac56590ee2d69ee4ac96d0ce43860a440
1 /* $NetBSD: lpt_pcctwo.c,v 1.11 2008/04/28 20:23:54 martin Exp $ */
3 /*-
4 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
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.
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>
45 #include <sys/cpu.h>
46 #include <sys/bus.h>
48 #include <dev/mvme/lptvar.h>
49 #include <dev/mvme/pcctworeg.h>
50 #include <dev/mvme/pcctwovar.h>
53 * Autoconfig stuff
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 = {
73 lpt_pcctwo_open,
74 lpt_pcctwo_close,
75 lpt_pcctwo_iprime,
76 lpt_pcctwo_speed,
77 lpt_pcctwo_notrdy,
78 lpt_pcctwo_wr_data
81 /* ARGSUSED */
82 int
83 lpt_pcctwo_match(device_t parent, cfdata_t cf, void *args)
85 struct pcctwo_attach_args *pa;
87 pa = args;
89 if (strcmp(pa->pa_name, lpt_cd.cd_name))
90 return (0);
92 #ifdef MVME68K
93 if (machineid != MVME_167 && machineid != MVME_177)
94 return (0);
95 #endif
97 #ifdef MVME88K
98 if (machineid != MVME_187)
99 return (0);
100 #endif
102 pa->pa_ipl = cf->pcctwocf_ipl;
104 return (1);
107 /* ARGSUSED */
108 void
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);
116 sc->sc_dev = 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,
121 &sc->sc_bush);
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
142 lpt_attach_subr(sc);
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,
152 &sc->sc_evcnt);
156 * Handle printer interrupts
159 lpt_pcctwo_intr(void *arg)
161 struct lpt_softc *sc;
162 int i;
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))
168 return (0);
170 i = lpt_intr(sc);
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);
176 return (i);
179 void
180 lpt_pcctwo_open(struct lpt_softc *sc, int int_ena)
182 int sps;
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);
190 if (int_ena == 0) {
191 sps = splhigh();
192 sc->sc_icr = sc->sc_ipl | PCCTWO_ICR_EDGE;
193 pcc2_reg_write(sc, PCC2REG_PRT_ACK_ICSR, sc->sc_icr);
194 splx(sps);
198 void
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);
207 void
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);
214 delay(100);
216 pcc2_reg_write(sc, PCC2REG_PRT_CONTROL,
217 pcc2_reg_read(sc, PCC2REG_PRT_CONTROL) & ~PCCTWO_PRT_CTRL_INP);
219 delay(100);
222 void
223 lpt_pcctwo_speed(struct lpt_softc *sc, int speed)
225 u_int8_t reg;
227 reg = pcc2_reg_read(sc, PCC2REG_PRT_CONTROL);
229 if (speed == LPT_STROBE_FAST)
230 reg |= PCCTWO_PRT_CTRL_FAST;
231 else
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)
240 u_int8_t status;
241 u_int8_t new;
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;
248 status &= LPS_MASK;
250 if (err) {
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));
265 return (status);
268 void
269 lpt_pcctwo_wr_data(struct lpt_softc *sc, u_char data)
272 pcc2_reg_write16(sc, PCC2REG_PRT_DATA, (u_int16_t) data);