Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / acorn32 / mainbus / lpt_pioc.c
blob0eb71eaae1397641dfaf20ea2012480d7a0e6432
1 /* $NetBSD: lpt_pioc.c,v 1.9 2008/03/07 17:15:51 cube Exp $ */
3 /*
4 * Copyright (c) 1997 Mark Brinicombe
5 * Copyright (c) 1997 Causality Limited
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the company nor the name of the author may be used to
17 * endorse or promote products derived from this software without specific
18 * prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
34 * Device Driver for AT parallel printer port
37 #include <sys/param.h>
39 __KERNEL_RCSID(0, "$NetBSD: lpt_pioc.c,v 1.9 2008/03/07 17:15:51 cube Exp $");
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/device.h>
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46 #include <acorn32/mainbus/piocvar.h>
47 #include <dev/ic/lptreg.h>
48 #include <dev/ic/lptvar.h>
50 #include "locators.h"
52 /* Prototypes for functions */
54 static int lpt_port_test (bus_space_tag_t, bus_space_handle_t, bus_addr_t,
55 bus_size_t, u_char, u_char);
56 static int lptprobe (bus_space_tag_t, u_int);
57 static int lpt_pioc_probe (device_t, cfdata_t , void *);
58 static void lpt_pioc_attach (device_t, device_t, void *);
60 /* device attach structure */
62 CFATTACH_DECL_NEW(lpt_pioc, sizeof(struct lpt_softc),
63 lpt_pioc_probe, lpt_pioc_attach, NULL, NULL);
66 * Internal routine to lptprobe to do port tests of one byte value.
68 static int
69 lpt_port_test(bus_space_tag_t iot, bus_space_handle_t ioh,
70 bus_addr_t base, bus_size_t off, u_char data, u_char mask)
72 int timeout;
73 u_char temp;
75 data &= mask;
76 bus_space_write_1(iot, ioh, off, data);
77 timeout = 1000;
78 do {
79 delay(10);
80 temp = bus_space_read_1(iot, ioh, off) & mask;
81 } while (temp != data && --timeout);
82 return (temp == data);
86 * Logic:
87 * 1) You should be able to write to and read back the same value
88 * to the data port. Do an alternating zeros, alternating ones,
89 * walking zero, and walking one test to check for stuck bits.
91 * 2) You should be able to write to and read back the same value
92 * to the control port lower 5 bits, the upper 3 bits are reserved
93 * per the IBM PC technical reference manauls and different boards
94 * do different things with them. Do an alternating zeros, alternating
95 * ones, walking zero, and walking one test to check for stuck bits.
97 * Some printers drag the strobe line down when the are powered off
98 * so this bit has been masked out of the control port test.
100 * XXX Some printers may not like a fast pulse on init or strobe, I
101 * don't know at this point, if that becomes a problem these bits
102 * should be turned off in the mask byte for the control port test.
104 * 3) Set the data and control ports to a value of 0
106 static int
107 lptprobe(bus_space_tag_t iot, u_int iobase)
109 bus_space_handle_t ioh;
110 u_char mask, data;
111 int i, rv;
112 #ifdef DEBUG
113 #define ABORT do {printf("lptprobe: mask %x data %x failed\n", mask, data); \
114 goto out;} while (0)
115 #else
116 #define ABORT goto out
117 #endif
119 if (bus_space_map(iot, iobase, LPT_NPORTS, 0, &ioh))
120 return 0;
121 rv = 0;
122 mask = 0xff;
124 data = 0x55; /* Alternating zeros */
125 if (!lpt_port_test(iot, ioh, iobase, lpt_data, data, mask))
126 ABORT;
128 data = 0xaa; /* Alternating ones */
129 if (!lpt_port_test(iot, ioh, iobase, lpt_data, data, mask))
130 ABORT;
132 for (i = 0; i < CHAR_BIT; i++) { /* Walking zero */
133 data = ~(1 << i);
134 if (!lpt_port_test(iot, ioh, iobase, lpt_data, data, mask))
135 ABORT;
138 for (i = 0; i < CHAR_BIT; i++) { /* Walking one */
139 data = (1 << i);
140 if (!lpt_port_test(iot, ioh, iobase, lpt_data, data, mask))
141 ABORT;
144 bus_space_write_1(iot, ioh, lpt_data, 0);
145 bus_space_write_1(iot, ioh, lpt_control, 0);
147 rv = LPT_NPORTS;
149 out:
150 bus_space_unmap(iot, ioh, LPT_NPORTS);
151 return rv;
155 * int lpt_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
157 * Make sure we are trying to attach a lpt device and then
158 * probe for one.
161 static int
162 lpt_pioc_probe(device_t parent, cfdata_t match, void *aux)
164 struct pioc_attach_args *pa = aux;
165 int rv;
167 if (pa->pa_name && strcmp(pa->pa_name, "lpt") != 0)
168 return(0);
170 /* We need an offset */
171 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
172 return(0);
174 rv = lptprobe(pa->pa_iot, pa->pa_iobase + pa->pa_offset);
176 if (rv) {
177 pa->pa_iosize = rv;
178 return(1);
180 return(0);
184 * void lpt_pioc_attach(struct device *parent, struct device *self, void *aux)
186 * attach the lpt device
189 static void
190 lpt_pioc_attach(device_t parent, device_t self, void *aux)
192 struct lpt_softc *sc = device_private(self);
193 struct pioc_attach_args *pa = aux;
194 bus_space_tag_t iot;
195 bus_space_handle_t ioh;
196 u_int iobase;
198 sc->sc_dev = self;
199 if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT)
200 aprint_normal("\n");
201 else
202 aprint_normal(": polled\n");
204 iobase = pa->pa_iobase + pa->pa_offset;
206 iot = sc->sc_iot = pa->pa_iot;
207 if (bus_space_map(iot, iobase, LPT_NPORTS, 0, &ioh)) {
208 aprint_error_dev(self, "couldn't map I/O ports");
209 return;
211 sc->sc_ioh = ioh;
213 lpt_attach_subr(sc);
215 if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT)
216 sc->sc_ih = intr_claim(pa->pa_irq, IPL_TTY, "lpt",
217 lptintr, sc);
220 /* End of lpt_pioc.c */