No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arc / jazz / lpt_jazzio.c
blob1366f3e1e6767e6ca54eb587413cbac05470800e
1 /* $NetBSD: lpt_jazzio.c,v 1.7 2005/12/11 12:16:39 christos Exp $ */
2 /* $OpenBSD: lpt_lbus.c,v 1.3 1997/04/10 16:29:17 pefo Exp $ */
4 /*
5 * Copyright (c) 1993, 1994 Charles M. Hannum.
6 * Copyright (c) 1990 William F. Jolitz, TeleMuse
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This software is a component of "386BSD" developed by
20 * William F. Jolitz, TeleMuse.
21 * 4. Neither the name of the developer nor the name "386BSD"
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
26 * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
27 * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
28 * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
29 * NOT MAKE USE OF THIS WORK.
31 * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
32 * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
33 * REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES
34 * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
35 * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
36 * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
37 * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
38 * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
40 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
54 * Device Driver for AT parallel printer port
57 #include <sys/cdefs.h>
58 __KERNEL_RCSID(0, "$NetBSD: lpt_jazzio.c,v 1.7 2005/12/11 12:16:39 christos Exp $");
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/device.h>
64 #include <machine/autoconf.h>
65 #include <machine/bus.h>
66 #include <machine/intr.h>
68 #include <dev/ic/lptreg.h>
69 #include <dev/ic/lptvar.h>
71 #include <arc/jazz/jazziovar.h>
73 int lpt_jazzio_probe(device_t, cfdata_t , void *);
74 void lpt_jazzio_attach(device_t, device_t, void *);
76 CFATTACH_DECL_NEW(lpt_jazzio, sizeof(struct lpt_softc),
77 lpt_jazzio_probe, lpt_jazzio_attach, NULL, NULL);
80 * XXX - copied from lpt_isa.c
81 * sys/arch/arm32/mainbus/lpt_pioc.c also copies this.
82 * sys/arch/amiga/dev/lpt_supio.c doesn't.
84 static int lpt_port_test(bus_space_tag_t, bus_space_handle_t, bus_addr_t,
85 bus_size_t, u_char, u_char);
87 * Internal routine to lptprobe to do port tests of one byte value.
89 static int
90 lpt_port_test(bus_space_tag_t iot, bus_space_handle_t ioh, bus_addr_t base,
91 bus_size_t off, u_char data, u_char mask)
93 int timeout;
94 u_char temp;
96 data &= mask;
97 bus_space_write_1(iot, ioh, off, data);
98 timeout = 1000;
99 do {
100 delay(10);
101 temp = bus_space_read_1(iot, ioh, off) & mask;
102 } while (temp != data && --timeout);
103 return temp == data;
107 lpt_jazzio_probe(device_t parent, cfdata_t match, void *aux)
109 struct jazzio_attach_args *ja = aux;
110 bus_space_tag_t iot;
111 bus_space_handle_t ioh;
112 bus_addr_t base;
113 uint8_t mask, data;
114 int i, rv;
116 #ifdef DEBUG
117 #define ABORT \
118 do { \
119 printf("lpt_jazzio_probe: mask %x data %x failed\n", mask, \
120 data); \
121 goto out; \
122 } while (0)
123 #else
124 #define ABORT goto out
125 #endif
127 if (strcmp(ja->ja_name, "LPT1") != 0)
128 return (0);
130 iot = ja->ja_bust;
131 base = ja->ja_addr;
132 if (bus_space_map(iot, base, LPT_NPORTS, 0, &ioh))
133 return 0;
135 rv = 0;
136 mask = 0xff;
138 data = 0x55; /* Alternating zeros */
139 if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
140 ABORT;
142 data = 0xaa; /* Alternating ones */
143 if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
144 ABORT;
146 for (i = 0; i < CHAR_BIT; i++) { /* Walking zero */
147 data = ~(1 << i);
148 if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
149 ABORT;
152 for (i = 0; i < CHAR_BIT; i++) { /* Walking one */
153 data = (1 << i);
154 if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask))
155 ABORT;
158 bus_space_write_1(iot, ioh, lpt_data, 0);
159 bus_space_write_1(iot, ioh, lpt_control, 0);
161 rv = 1;
163 out:
164 bus_space_unmap(iot, ioh, LPT_NPORTS);
165 return rv;
168 void
169 lpt_jazzio_attach(device_t parent, device_t self, void *aux)
171 struct lpt_softc *sc = device_private(self);
172 struct jazzio_attach_args *ja = aux;
173 bus_space_tag_t iot;
174 bus_space_handle_t ioh;
176 aprint_normal("\n");
178 sc->sc_dev = self;
179 sc->sc_state = 0;
180 iot = sc->sc_iot = ja->ja_bust;
181 if (bus_space_map(iot, ja->ja_addr, LPT_NPORTS, 0, &ioh)) {
182 aprint_error_dev(self, "can't map i/o space\n");
183 return;
185 sc->sc_ioh = ioh;
187 bus_space_write_1(iot, ioh, lpt_control, LPC_NINIT);
189 jazzio_intr_establish(ja->ja_intr, lptintr, sc);