com_ebus.c revision 1.20 1 /* $NetBSD: com_ebus.c,v 1.20 2003/07/15 03:36:04 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1999, 2000 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 /*
32 * NS Super I/O PC87332VLJ "com" to ebus attachment
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: com_ebus.c,v 1.20 2003/07/15 03:36:04 lukem Exp $");
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/tty.h>
43 #include <sys/conf.h>
44
45 #include <machine/bus.h>
46 #include <machine/autoconf.h>
47 #include <machine/openfirm.h>
48
49 #include <dev/ebus/ebusreg.h>
50 #include <dev/ebus/ebusvar.h>
51
52 #include <dev/cons.h>
53 #include <dev/ic/comvar.h>
54 #include <dev/sun/kbd_ms_ttyvar.h>
55
56 #include "kbd.h"
57 #include "ms.h"
58
59 int com_ebus_match __P((struct device *, struct cfdata *, void *));
60 void com_ebus_attach __P((struct device *, struct device *, void *));
61
62 CFATTACH_DECL(com_ebus, sizeof(struct com_softc),
63 com_ebus_match, com_ebus_attach, NULL, NULL);
64
65 static char *com_names[] = {
66 "su",
67 "su_pnp",
68 NULL
69 };
70
71 int
72 com_ebus_match(parent, match, aux)
73 struct device *parent;
74 struct cfdata *match;
75 void *aux;
76 {
77 struct ebus_attach_args *ea = aux;
78 int i;
79
80 for (i=0; com_names[i]; i++)
81 if (strcmp(ea->ea_name, com_names[i]) == 0)
82 return (1);
83
84 if (strcmp(ea->ea_name, "serial") == 0) {
85 char compat[80];
86
87 /* Could be anything. */
88 if ((i = OF_getproplen(ea->ea_node, "compatible")) &&
89 OF_getprop(ea->ea_node, "compatible", compat,
90 sizeof(compat)) == i) {
91 if (strcmp(compat, "su16550") == 0 ||
92 strcmp(compat, "su") == 0) {
93 return (1);
94 }
95 }
96 }
97 return (0);
98 }
99
100 #define BAUD_BASE (1846200)
101
102 void
103 com_ebus_attach(parent, self, aux)
104 struct device *parent, *self;
105 void *aux;
106 {
107 struct com_softc *sc = (void *)self;
108 struct ebus_attach_args *ea = aux;
109 struct kbd_ms_tty_attach_args kma;
110 #if (NKBD > 0) || (NMS > 0)
111 int maj;
112 extern const struct cdevsw com_cdevsw;
113 #endif
114 int i;
115 int com_is_input;
116 int com_is_output;
117
118 sc->sc_iot = ea->ea_bustag;
119 sc->sc_iobase = EBUS_ADDR_FROM_REG(&ea->ea_reg[0]);
120 /*
121 * Addresses that should be supplied by the prom:
122 * - normal com registers
123 * - ns873xx configuration registers
124 * - DMA space
125 * The `com' driver does not use DMA accesses, so we can
126 * ignore that for now. We should enable the com port in
127 * the ns873xx registers here. XXX
128 *
129 * Use the prom address if there.
130 */
131
132 if (ea->ea_nvaddr)
133 sparc_promaddr_to_handle(sc->sc_iot, ea->ea_vaddr[0],
134 &sc->sc_ioh);
135 else if (bus_space_map(sc->sc_iot, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
136 ea->ea_reg[0].size, 0, &sc->sc_ioh) != 0) {
137 printf(": can't map register space\n");
138 return;
139 }
140 sc->sc_hwflags = 0;
141 sc->sc_frequency = BAUD_BASE;
142
143 for (i = 0; i < ea->ea_nintr; i++)
144 bus_intr_establish(ea->ea_bustag, ea->ea_intr[i],
145 IPL_SERIAL, comintr, sc);
146
147 kma.kmta_consdev = NULL;
148
149 /* Figure out if we're the console. */
150 com_is_input = (ea->ea_node == OF_instance_to_package(OF_stdin()));
151 com_is_output = (ea->ea_node == OF_instance_to_package(OF_stdout()));
152
153 if (com_is_input || com_is_output) {
154 extern struct consdev comcons;
155 struct consdev *cn_orig;
156
157 /* Record some info to attach console. */
158 kma.kmta_baud = 9600;
159 kma.kmta_cflag = (CREAD | CS8 | HUPCL);
160
161 /* Attach com as the console. */
162 cn_orig = cn_tab;
163 if (comcnattach(sc->sc_iot, sc->sc_iobase, kma.kmta_baud,
164 sc->sc_frequency, COM_TYPE_NORMAL, kma.kmta_cflag)) {
165 printf("Error: comcnattach failed\n");
166 }
167 cn_tab = cn_orig;
168 if (com_is_input) {
169 cn_tab->cn_dev = comcons.cn_dev;
170 cn_tab->cn_probe = comcons.cn_probe;
171 cn_tab->cn_init = comcons.cn_init;
172 cn_tab->cn_getc = comcons.cn_getc;
173 cn_tab->cn_pollc = comcons.cn_pollc;
174 }
175 if (com_is_output) {
176 cn_tab->cn_putc = comcons.cn_putc;
177 }
178 kma.kmta_consdev = cn_tab;
179 }
180 /* Now attach the driver */
181 com_attach_subr(sc);
182
183 #if (NKBD > 0) || (NMS > 0)
184 kma.kmta_tp = sc->sc_tty;
185 /* If we figure out we're the console we should point this to our consdev */
186
187 /* locate the major number */
188 maj = cdevsw_lookup_major(&com_cdevsw);
189
190 kma.kmta_dev = makedev(maj, sc->sc_dev.dv_unit);
191
192 /* Attach 'em if we got 'em. */
193 #if (NKBD > 0)
194 kma.kmta_name = "keyboard";
195 if (OF_getproplen(ea->ea_node, kma.kmta_name) == 0) {
196 config_found(self, (void *)&kma, NULL);
197 }
198 #endif
199 #if (NMS > 0)
200 kma.kmta_name = "mouse";
201 if (OF_getproplen(ea->ea_node, kma.kmta_name) == 0) {
202 config_found(self, (void *)&kma, NULL);
203 }
204 #endif
205 #endif
206 if (kma.kmta_consdev) {
207 /*
208 * If we're the keyboard then we need the original
209 * cn_tab w/prom I/O, which sunkbd copied into kma.
210 * Otherwise we want conscom which we copied into
211 * kma.kmta_consdev.
212 */
213 cn_tab = kma.kmta_consdev;
214 }
215 }
216
217