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