com_ebus.c revision 1.36 1 1.36 thorpej /* $NetBSD: com_ebus.c,v 1.36 2021/08/07 16:19:05 thorpej Exp $ */
2 1.1 eeh
3 1.1 eeh /*
4 1.1 eeh * Copyright (c) 1999, 2000 Matthew R. Green
5 1.1 eeh * All rights reserved.
6 1.1 eeh *
7 1.1 eeh * Redistribution and use in source and binary forms, with or without
8 1.1 eeh * modification, are permitted provided that the following conditions
9 1.1 eeh * are met:
10 1.1 eeh * 1. Redistributions of source code must retain the above copyright
11 1.1 eeh * notice, this list of conditions and the following disclaimer.
12 1.1 eeh * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 eeh * notice, this list of conditions and the following disclaimer in the
14 1.1 eeh * documentation and/or other materials provided with the distribution.
15 1.1 eeh *
16 1.1 eeh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 eeh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 eeh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 eeh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 eeh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 eeh * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 eeh * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 eeh * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 eeh * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 eeh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 eeh * SUCH DAMAGE.
27 1.1 eeh */
28 1.1 eeh
29 1.1 eeh /*
30 1.1 eeh * NS Super I/O PC87332VLJ "com" to ebus attachment
31 1.1 eeh */
32 1.20 lukem
33 1.20 lukem #include <sys/cdefs.h>
34 1.36 thorpej __KERNEL_RCSID(0, "$NetBSD: com_ebus.c,v 1.36 2021/08/07 16:19:05 thorpej Exp $");
35 1.1 eeh
36 1.1 eeh #include <sys/types.h>
37 1.1 eeh #include <sys/param.h>
38 1.1 eeh #include <sys/systm.h>
39 1.1 eeh #include <sys/device.h>
40 1.1 eeh #include <sys/tty.h>
41 1.1 eeh #include <sys/conf.h>
42 1.1 eeh
43 1.33 dyoung #include <sys/bus.h>
44 1.1 eeh #include <machine/autoconf.h>
45 1.1 eeh #include <machine/openfirm.h>
46 1.1 eeh
47 1.8 mrg #include <dev/ebus/ebusreg.h>
48 1.11 mrg #include <dev/ebus/ebusvar.h>
49 1.1 eeh
50 1.1 eeh #include <dev/cons.h>
51 1.1 eeh #include <dev/ic/comvar.h>
52 1.1 eeh #include <dev/sun/kbd_ms_ttyvar.h>
53 1.1 eeh
54 1.1 eeh #include "kbd.h"
55 1.1 eeh #include "ms.h"
56 1.1 eeh
57 1.27 cube int com_ebus_match(device_t, cfdata_t , void *);
58 1.27 cube void com_ebus_attach(device_t, device_t, void *);
59 1.1 eeh
60 1.27 cube CFATTACH_DECL_NEW(com_ebus, sizeof(struct com_softc),
61 1.17 thorpej com_ebus_match, com_ebus_attach, NULL, NULL);
62 1.1 eeh
63 1.22 christos static const char *com_names[] = {
64 1.1 eeh "su",
65 1.1 eeh "su_pnp",
66 1.30 jdc "rsc-console",
67 1.1 eeh NULL
68 1.1 eeh };
69 1.1 eeh
70 1.1 eeh int
71 1.27 cube com_ebus_match(device_t parent, cfdata_t match, void *aux)
72 1.1 eeh {
73 1.1 eeh struct ebus_attach_args *ea = aux;
74 1.1 eeh int i;
75 1.1 eeh
76 1.21 pk for (i = 0; com_names[i]; i++)
77 1.1 eeh if (strcmp(ea->ea_name, com_names[i]) == 0)
78 1.1 eeh return (1);
79 1.1 eeh
80 1.5 eeh if (strcmp(ea->ea_name, "serial") == 0) {
81 1.21 pk char *compat;
82 1.5 eeh
83 1.5 eeh /* Could be anything. */
84 1.21 pk compat = prom_getpropstring(ea->ea_node, "compatible");
85 1.21 pk if (strcmp(compat, "su16550") == 0 ||
86 1.31 mrg strcmp(compat, "su16552") == 0 ||
87 1.32 mrg strcmp(compat, "su") == 0 ||
88 1.32 mrg strcmp(compat, "FJSV,su") == 0) {
89 1.21 pk return (1);
90 1.5 eeh }
91 1.5 eeh }
92 1.1 eeh return (0);
93 1.1 eeh }
94 1.1 eeh
95 1.1 eeh #define BAUD_BASE (1846200)
96 1.1 eeh
97 1.1 eeh void
98 1.27 cube com_ebus_attach(device_t parent, device_t self, void *aux)
99 1.1 eeh {
100 1.27 cube struct com_softc *sc = device_private(self);
101 1.1 eeh struct ebus_attach_args *ea = aux;
102 1.1 eeh struct kbd_ms_tty_attach_args kma;
103 1.1 eeh #if (NKBD > 0) || (NMS > 0)
104 1.1 eeh int maj;
105 1.14 gehenna extern const struct cdevsw com_cdevsw;
106 1.1 eeh #endif
107 1.1 eeh int i;
108 1.7 eeh int com_is_input;
109 1.7 eeh int com_is_output;
110 1.26 gdamore bus_space_handle_t ioh;
111 1.26 gdamore bus_space_tag_t iot;
112 1.26 gdamore bus_addr_t iobase;
113 1.32 mrg int node, port;
114 1.32 mrg char buf[32];
115 1.26 gdamore
116 1.27 cube sc->sc_dev = self;
117 1.26 gdamore iot = ea->ea_bustag;
118 1.26 gdamore iobase = EBUS_ADDR_FROM_REG(&ea->ea_reg[0]);
119 1.1 eeh
120 1.1 eeh /*
121 1.13 wiz * Addresses that should be supplied by the prom:
122 1.1 eeh * - normal com registers
123 1.1 eeh * - ns873xx configuration registers
124 1.1 eeh * - DMA space
125 1.1 eeh * The `com' driver does not use DMA accesses, so we can
126 1.1 eeh * ignore that for now. We should enable the com port in
127 1.1 eeh * the ns873xx registers here. XXX
128 1.1 eeh *
129 1.1 eeh * Use the prom address if there.
130 1.1 eeh */
131 1.12 eeh
132 1.11 mrg if (ea->ea_nvaddr)
133 1.26 gdamore sparc_promaddr_to_handle(iot, ea->ea_vaddr[0],
134 1.26 gdamore &ioh);
135 1.26 gdamore else if (bus_space_map(iot, iobase,
136 1.26 gdamore ea->ea_reg[0].size, 0, &ioh) != 0) {
137 1.27 cube aprint_error(": can't map register space\n");
138 1.10 eeh return;
139 1.1 eeh }
140 1.34 thorpej com_init_regs(&sc->sc_regs, iot, ioh, iobase);
141 1.26 gdamore
142 1.1 eeh sc->sc_hwflags = 0;
143 1.1 eeh sc->sc_frequency = BAUD_BASE;
144 1.1 eeh
145 1.11 mrg for (i = 0; i < ea->ea_nintr; i++)
146 1.11 mrg bus_intr_establish(ea->ea_bustag, ea->ea_intr[i],
147 1.18 pk IPL_SERIAL, comintr, sc);
148 1.1 eeh
149 1.1 eeh kma.kmta_consdev = NULL;
150 1.7 eeh
151 1.32 mrg /*
152 1.32 mrg * Figure out if we're the console.
153 1.32 mrg *
154 1.32 mrg * The Fujitsu SPARC Enterprise M4000/M5000/M8000/M9000 has a
155 1.32 mrg * serial port on each I/O board and a pseudo console that is
156 1.32 mrg * redirected to one of these serial ports. The board number
157 1.32 mrg * of the serial port in question is encoded in the "tty-port#"
158 1.32 mrg * property of the pseudo console, so we figure out what our
159 1.32 mrg * board number is by walking up the device tree, and check
160 1.32 mrg * for a match.
161 1.32 mrg */
162 1.32 mrg node = prom_instance_to_package(prom_stdin());
163 1.32 mrg com_is_input = (ea->ea_node == node);
164 1.32 mrg if (OF_getprop(node, "name", buf, sizeof(buf)) > 0 &&
165 1.32 mrg strcmp(buf, "pseudo-console") == 0) {
166 1.32 mrg port = prom_getpropint(node, "tty-port#", -1);
167 1.32 mrg node = OF_parent(OF_parent(ea->ea_node));
168 1.32 mrg com_is_input = (prom_getpropint(node, "board#", -2) == port);
169 1.32 mrg }
170 1.32 mrg
171 1.32 mrg node = prom_instance_to_package(prom_stdout());
172 1.32 mrg com_is_output = (ea->ea_node == node);
173 1.32 mrg if (OF_getprop(node, "name", buf, sizeof(buf)) > 0 &&
174 1.32 mrg strcmp(buf, "pseudo-console") == 0) {
175 1.32 mrg port = prom_getpropint(node, "tty-port#", -1);
176 1.32 mrg node = OF_parent(OF_parent(ea->ea_node));
177 1.32 mrg com_is_output = (prom_getpropint(node, "board#", -2) == port);
178 1.32 mrg }
179 1.7 eeh
180 1.7 eeh if (com_is_input || com_is_output) {
181 1.7 eeh struct consdev *cn_orig;
182 1.1 eeh
183 1.1 eeh /* Record some info to attach console. */
184 1.30 jdc if (strcmp(ea->ea_name, "rsc-console") == 0)
185 1.30 jdc kma.kmta_baud = 115200;
186 1.30 jdc else
187 1.30 jdc kma.kmta_baud = 9600;
188 1.1 eeh kma.kmta_cflag = (CREAD | CS8 | HUPCL);
189 1.5 eeh
190 1.5 eeh /* Attach com as the console. */
191 1.7 eeh cn_orig = cn_tab;
192 1.26 gdamore if (comcnattach(iot, iobase, kma.kmta_baud,
193 1.19 thorpej sc->sc_frequency, COM_TYPE_NORMAL, kma.kmta_cflag)) {
194 1.27 cube aprint_error("Error: comcnattach failed\n");
195 1.5 eeh }
196 1.7 eeh if (com_is_input) {
197 1.29 nakayama cn_orig->cn_dev = cn_tab->cn_dev;
198 1.29 nakayama cn_orig->cn_probe = cn_tab->cn_probe;
199 1.29 nakayama cn_orig->cn_init = cn_tab->cn_init;
200 1.29 nakayama cn_orig->cn_getc = cn_tab->cn_getc;
201 1.29 nakayama cn_orig->cn_pollc = cn_tab->cn_pollc;
202 1.7 eeh }
203 1.7 eeh if (com_is_output) {
204 1.29 nakayama cn_orig->cn_putc = cn_tab->cn_putc;
205 1.7 eeh }
206 1.29 nakayama cn_tab = cn_orig;
207 1.7 eeh kma.kmta_consdev = cn_tab;
208 1.1 eeh }
209 1.32 mrg
210 1.32 mrg /*
211 1.32 mrg * Apparently shoving too much data down the TX FIFO on the
212 1.32 mrg * Fujitsu SPARC Enterprise M4000/M5000 causes a hardware
213 1.32 mrg * fault. Avoid this issue by setting the FIFO depth to 1.
214 1.32 mrg * This will effectively disable the TX FIFO, but will still
215 1.32 mrg * enable the RX FIFO, which is what we really care about.
216 1.32 mrg */
217 1.32 mrg if (OF_getprop(ea->ea_node, "compatible", buf, sizeof(buf)) > 0 &&
218 1.32 mrg strcmp(buf, "FJSV,su") == 0)
219 1.32 mrg sc->sc_fifolen = 1;
220 1.32 mrg
221 1.5 eeh /* Now attach the driver */
222 1.5 eeh com_attach_subr(sc);
223 1.1 eeh
224 1.1 eeh #if (NKBD > 0) || (NMS > 0)
225 1.1 eeh kma.kmta_tp = sc->sc_tty;
226 1.1 eeh /* If we figure out we're the console we should point this to our consdev */
227 1.1 eeh
228 1.1 eeh /* locate the major number */
229 1.14 gehenna maj = cdevsw_lookup_major(&com_cdevsw);
230 1.1 eeh
231 1.27 cube kma.kmta_dev = makedev(maj, device_unit(sc->sc_dev));
232 1.1 eeh
233 1.1 eeh /* Attach 'em if we got 'em. */
234 1.1 eeh #if (NKBD > 0)
235 1.1 eeh kma.kmta_name = "keyboard";
236 1.21 pk if (prom_getproplen(ea->ea_node, kma.kmta_name) == 0) {
237 1.36 thorpej config_found(self, (void *)&kma, NULL, CFARGS_NONE);
238 1.1 eeh }
239 1.1 eeh #endif
240 1.1 eeh #if (NMS > 0)
241 1.1 eeh kma.kmta_name = "mouse";
242 1.21 pk if (prom_getproplen(ea->ea_node, kma.kmta_name) == 0) {
243 1.36 thorpej config_found(self, (void *)&kma, NULL, CFARGS_NONE);
244 1.1 eeh }
245 1.1 eeh #endif
246 1.1 eeh #endif
247 1.1 eeh if (kma.kmta_consdev) {
248 1.1 eeh /*
249 1.1 eeh * If we're the keyboard then we need the original
250 1.1 eeh * cn_tab w/prom I/O, which sunkbd copied into kma.
251 1.1 eeh * Otherwise we want conscom which we copied into
252 1.1 eeh * kma.kmta_consdev.
253 1.1 eeh */
254 1.1 eeh cn_tab = kma.kmta_consdev;
255 1.1 eeh }
256 1.1 eeh }
257