lpt_gsc.c revision 1.1.6.2 1 1.1.6.2 yamt /* $NetBSD: lpt_gsc.c,v 1.1.6.2 2014/05/22 11:39:50 yamt Exp $ */
2 1.1.6.2 yamt
3 1.1.6.2 yamt /* $OpenBSD: lpt_gsc.c,v 1.6 2000/07/21 17:41:06 mickey Exp $ */
4 1.1.6.2 yamt
5 1.1.6.2 yamt /*
6 1.1.6.2 yamt * Copyright (c) 1998 Michael Shalayeff
7 1.1.6.2 yamt * Copyright (c) 1993, 1994 Charles Hannum.
8 1.1.6.2 yamt * Copyright (c) 1990 William F. Jolitz, TeleMuse
9 1.1.6.2 yamt * All rights reserved.
10 1.1.6.2 yamt *
11 1.1.6.2 yamt * Redistribution and use in source and binary forms, with or without
12 1.1.6.2 yamt * modification, are permitted provided that the following conditions
13 1.1.6.2 yamt * are met:
14 1.1.6.2 yamt * 1. Redistributions of source code must retain the above copyright
15 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer.
16 1.1.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer in the
18 1.1.6.2 yamt * documentation and/or other materials provided with the distribution.
19 1.1.6.2 yamt * 3. All advertising materials mentioning features or use of this software
20 1.1.6.2 yamt * must display the following acknowledgement:
21 1.1.6.2 yamt * This software is a component of "386BSD" developed by
22 1.1.6.2 yamt * William F. Jolitz, TeleMuse.
23 1.1.6.2 yamt * 4. Neither the name of the developer nor the name "386BSD"
24 1.1.6.2 yamt * may be used to endorse or promote products derived from this software
25 1.1.6.2 yamt * without specific prior written permission.
26 1.1.6.2 yamt *
27 1.1.6.2 yamt * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
28 1.1.6.2 yamt * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
29 1.1.6.2 yamt * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
30 1.1.6.2 yamt * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
31 1.1.6.2 yamt * NOT MAKE USE OF THIS WORK.
32 1.1.6.2 yamt *
33 1.1.6.2 yamt * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
34 1.1.6.2 yamt * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
35 1.1.6.2 yamt * REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES
36 1.1.6.2 yamt * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
37 1.1.6.2 yamt * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
38 1.1.6.2 yamt * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
39 1.1.6.2 yamt * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
40 1.1.6.2 yamt * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
41 1.1.6.2 yamt *
42 1.1.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
43 1.1.6.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 1.1.6.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 1.1.6.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
46 1.1.6.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 1.1.6.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 1.1.6.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 1.1.6.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 1.1.6.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 1.1.6.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 1.1.6.2 yamt * SUCH DAMAGE.
53 1.1.6.2 yamt */
54 1.1.6.2 yamt
55 1.1.6.2 yamt #include <sys/cdefs.h>
56 1.1.6.2 yamt __KERNEL_RCSID(0, "$NetBSD: lpt_gsc.c,v 1.1.6.2 2014/05/22 11:39:50 yamt Exp $");
57 1.1.6.2 yamt
58 1.1.6.2 yamt #include <sys/param.h>
59 1.1.6.2 yamt #include <sys/systm.h>
60 1.1.6.2 yamt #include <sys/device.h>
61 1.1.6.2 yamt
62 1.1.6.2 yamt #include <sys/bus.h>
63 1.1.6.2 yamt #include <machine/intr.h>
64 1.1.6.2 yamt #include <machine/iomod.h>
65 1.1.6.2 yamt #include <machine/autoconf.h>
66 1.1.6.2 yamt
67 1.1.6.2 yamt #include <dev/ic/lptreg.h>
68 1.1.6.2 yamt #include <dev/ic/lptvar.h>
69 1.1.6.2 yamt
70 1.1.6.2 yamt #include <hppa/dev/cpudevs.h>
71 1.1.6.2 yamt
72 1.1.6.2 yamt #include <hppa/gsc/gscbusvar.h>
73 1.1.6.2 yamt
74 1.1.6.2 yamt #define LPTGSC_OFFSET 0x800
75 1.1.6.2 yamt
76 1.1.6.2 yamt #ifndef LPTDEBUG
77 1.1.6.2 yamt #define LPRINTF(a)
78 1.1.6.2 yamt #else
79 1.1.6.2 yamt #define LPRINTF(a) if (lpt_isa_debug) printf a
80 1.1.6.2 yamt int lpt_isa_debug = 0;
81 1.1.6.2 yamt #endif
82 1.1.6.2 yamt
83 1.1.6.2 yamt int lpt_gsc_probe(device_t, cfdata_t , void *);
84 1.1.6.2 yamt void lpt_gsc_attach(device_t, device_t, void *);
85 1.1.6.2 yamt
86 1.1.6.2 yamt CFATTACH_DECL_NEW(lpt_gsc, sizeof(struct lpt_softc),
87 1.1.6.2 yamt lpt_gsc_probe, lpt_gsc_attach, NULL, NULL);
88 1.1.6.2 yamt
89 1.1.6.2 yamt int lpt_port_test(bus_space_tag_t, bus_space_handle_t, bus_addr_t,
90 1.1.6.2 yamt bus_size_t, u_char, u_char);
91 1.1.6.2 yamt
92 1.1.6.2 yamt /*
93 1.1.6.2 yamt * Internal routine to lptprobe to do port tests of one byte value.
94 1.1.6.2 yamt */
95 1.1.6.2 yamt int
96 1.1.6.2 yamt lpt_port_test(bus_space_tag_t iot, bus_space_handle_t ioh, bus_addr_t base,
97 1.1.6.2 yamt bus_size_t off, u_char data, u_char mask)
98 1.1.6.2 yamt {
99 1.1.6.2 yamt int timeout;
100 1.1.6.2 yamt u_char temp;
101 1.1.6.2 yamt
102 1.1.6.2 yamt data &= mask;
103 1.1.6.2 yamt bus_space_write_1(iot, ioh, off, data);
104 1.1.6.2 yamt timeout = 1000;
105 1.1.6.2 yamt do {
106 1.1.6.2 yamt delay(10);
107 1.1.6.2 yamt temp = bus_space_read_1(iot, ioh, off) & mask;
108 1.1.6.2 yamt } while (temp != data && --timeout);
109 1.1.6.2 yamt LPRINTF(("lpt: port=0x%x out=0x%x in=0x%x timeout=%d\n",
110 1.1.6.2 yamt (unsigned)(base + off), (unsigned)data, (unsigned)temp, timeout));
111 1.1.6.2 yamt return (temp == data);
112 1.1.6.2 yamt }
113 1.1.6.2 yamt
114 1.1.6.2 yamt /*
115 1.1.6.2 yamt * Logic:
116 1.1.6.2 yamt * 1) You should be able to write to and read back the same value
117 1.1.6.2 yamt * to the data port. Do an alternating zeros, alternating ones,
118 1.1.6.2 yamt * walking zero, and walking one test to check for stuck bits.
119 1.1.6.2 yamt *
120 1.1.6.2 yamt * 2) You should be able to write to and read back the same value
121 1.1.6.2 yamt * to the control port lower 5 bits, the upper 3 bits are reserved
122 1.1.6.2 yamt * per the IBM PC technical reference manauls and different boards
123 1.1.6.2 yamt * do different things with them. Do an alternating zeros, alternating
124 1.1.6.2 yamt * ones, walking zero, and walking one test to check for stuck bits.
125 1.1.6.2 yamt *
126 1.1.6.2 yamt * Some printers drag the strobe line down when the are powered off
127 1.1.6.2 yamt * so this bit has been masked out of the control port test.
128 1.1.6.2 yamt *
129 1.1.6.2 yamt * XXX Some printers may not like a fast pulse on init or strobe, I
130 1.1.6.2 yamt * don't know at this point, if that becomes a problem these bits
131 1.1.6.2 yamt * should be turned off in the mask byte for the control port test.
132 1.1.6.2 yamt *
133 1.1.6.2 yamt * 3) Set the data and control ports to a value of 0
134 1.1.6.2 yamt */
135 1.1.6.2 yamt int
136 1.1.6.2 yamt lpt_gsc_probe(device_t parent, cfdata_t match, void *aux)
137 1.1.6.2 yamt {
138 1.1.6.2 yamt struct gsc_attach_args *ga = aux;
139 1.1.6.2 yamt bus_space_handle_t ioh;
140 1.1.6.2 yamt bus_addr_t base;
141 1.1.6.2 yamt uint8_t mask, data;
142 1.1.6.2 yamt int i;
143 1.1.6.2 yamt
144 1.1.6.2 yamt if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
145 1.1.6.2 yamt ga->ga_type.iodc_sv_model != HPPA_FIO_CENT)
146 1.1.6.2 yamt return 0;
147 1.1.6.2 yamt
148 1.1.6.2 yamt #ifdef DEBUG
149 1.1.6.2 yamt #define ABORT \
150 1.1.6.2 yamt do { \
151 1.1.6.2 yamt printf("lpt_gsc_probe: mask %x data %x failed\n", mask, \
152 1.1.6.2 yamt data); \
153 1.1.6.2 yamt bus_space_unmap(ga->ga_iot, ioh, LPT_NPORTS); \
154 1.1.6.2 yamt return 0; \
155 1.1.6.2 yamt } while (0)
156 1.1.6.2 yamt #else
157 1.1.6.2 yamt #define ABORT \
158 1.1.6.2 yamt do { \
159 1.1.6.2 yamt bus_space_unmap(ga->ga_iot, ioh, LPT_NPORTS); \
160 1.1.6.2 yamt return 0; \
161 1.1.6.2 yamt } while (0)
162 1.1.6.2 yamt #endif
163 1.1.6.2 yamt
164 1.1.6.2 yamt base = ga->ga_hpa + LPTGSC_OFFSET;
165 1.1.6.2 yamt if (bus_space_map(ga->ga_iot, base, LPT_NPORTS, 0, &ioh))
166 1.1.6.2 yamt return 0;
167 1.1.6.2 yamt
168 1.1.6.2 yamt mask = 0xff;
169 1.1.6.2 yamt
170 1.1.6.2 yamt data = 0x55; /* Alternating zeros */
171 1.1.6.2 yamt if (!lpt_port_test(ga->ga_iot, ioh, base, lpt_data, data, mask))
172 1.1.6.2 yamt ABORT;
173 1.1.6.2 yamt
174 1.1.6.2 yamt data = 0xaa; /* Alternating ones */
175 1.1.6.2 yamt if (!lpt_port_test(ga->ga_iot, ioh, base, lpt_data, data, mask))
176 1.1.6.2 yamt ABORT;
177 1.1.6.2 yamt
178 1.1.6.2 yamt for (i = 0; i < CHAR_BIT; i++) { /* Walking zero */
179 1.1.6.2 yamt data = ~(1 << i);
180 1.1.6.2 yamt if (!lpt_port_test(ga->ga_iot, ioh, base, lpt_data, data, mask))
181 1.1.6.2 yamt ABORT;
182 1.1.6.2 yamt }
183 1.1.6.2 yamt
184 1.1.6.2 yamt for (i = 0; i < CHAR_BIT; i++) { /* Walking one */
185 1.1.6.2 yamt data = (1 << i);
186 1.1.6.2 yamt if (!lpt_port_test(ga->ga_iot, ioh, base, lpt_data, data, mask))
187 1.1.6.2 yamt ABORT;
188 1.1.6.2 yamt }
189 1.1.6.2 yamt
190 1.1.6.2 yamt bus_space_write_1(ga->ga_iot, ioh, lpt_data, 0);
191 1.1.6.2 yamt bus_space_write_1(ga->ga_iot, ioh, lpt_control, 0);
192 1.1.6.2 yamt bus_space_unmap(ga->ga_iot, ioh, LPT_NPORTS);
193 1.1.6.2 yamt
194 1.1.6.2 yamt return 1;
195 1.1.6.2 yamt }
196 1.1.6.2 yamt
197 1.1.6.2 yamt void
198 1.1.6.2 yamt lpt_gsc_attach(device_t parent, device_t self, void *aux)
199 1.1.6.2 yamt {
200 1.1.6.2 yamt struct lpt_softc *sc = device_private(self);
201 1.1.6.2 yamt struct gsc_attach_args *ga = aux;
202 1.1.6.2 yamt
203 1.1.6.2 yamt /* sc->sc_flags |= LPT_POLLED; */
204 1.1.6.2 yamt
205 1.1.6.2 yamt sc->sc_dev = self;
206 1.1.6.2 yamt sc->sc_state = 0;
207 1.1.6.2 yamt sc->sc_iot = ga->ga_iot;
208 1.1.6.2 yamt if (bus_space_map(sc->sc_iot, ga->ga_hpa + LPTGSC_OFFSET,
209 1.1.6.2 yamt LPT_NPORTS, 0, &sc->sc_ioh)) {
210 1.1.6.2 yamt aprint_error(": can't map i/o ports\n");
211 1.1.6.2 yamt return;
212 1.1.6.2 yamt }
213 1.1.6.2 yamt
214 1.1.6.2 yamt lpt_attach_subr(sc);
215 1.1.6.2 yamt
216 1.1.6.2 yamt sc->sc_ih = hppa_intr_establish(IPL_TTY, lptintr, sc, ga->ga_ir,
217 1.1.6.2 yamt ga->ga_irq);
218 1.1.6.2 yamt aprint_normal("\n");
219 1.1.6.2 yamt }
220