com_arbus.c revision 1.1.14.5 1 1.1.14.5 yamt /* $Id: com_arbus.c,v 1.1.14.5 2008/03/17 09:14:21 yamt Exp $ */
2 1.1.14.2 yamt /*-
3 1.1.14.2 yamt * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
4 1.1.14.2 yamt * Copyright (c) 2006 Garrett D'Amore.
5 1.1.14.2 yamt * All rights reserved.
6 1.1.14.2 yamt *
7 1.1.14.2 yamt * Portions of this code were written by Garrett D'Amore for the
8 1.1.14.2 yamt * Champaign-Urbana Community Wireless Network Project.
9 1.1.14.2 yamt *
10 1.1.14.2 yamt * Redistribution and use in source and binary forms, with or
11 1.1.14.2 yamt * without modification, are permitted provided that the following
12 1.1.14.2 yamt * conditions are met:
13 1.1.14.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.14.2 yamt * 2. Redistributions in binary form must reproduce the above
16 1.1.14.2 yamt * copyright notice, this list of conditions and the following
17 1.1.14.2 yamt * disclaimer in the documentation and/or other materials provided
18 1.1.14.2 yamt * with the distribution.
19 1.1.14.2 yamt * 3. All advertising materials mentioning features or use of this
20 1.1.14.2 yamt * software must display the following acknowledgements:
21 1.1.14.2 yamt * This product includes software developed by the Urbana-Champaign
22 1.1.14.2 yamt * Independent Media Center.
23 1.1.14.2 yamt * This product includes software developed by Garrett D'Amore.
24 1.1.14.2 yamt * 4. Urbana-Champaign Independent Media Center's name and Garrett
25 1.1.14.2 yamt * D'Amore's name may not be used to endorse or promote products
26 1.1.14.2 yamt * derived from this software without specific prior written permission.
27 1.1.14.2 yamt *
28 1.1.14.2 yamt * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
29 1.1.14.2 yamt * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
30 1.1.14.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 1.1.14.2 yamt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.1.14.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
33 1.1.14.2 yamt * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
34 1.1.14.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 1.1.14.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 1.1.14.2 yamt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 1.1.14.2 yamt * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 1.1.14.2 yamt * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 1.1.14.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40 1.1.14.2 yamt * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 1.1.14.2 yamt */
42 1.1.14.2 yamt
43 1.1.14.2 yamt /*-
44 1.1.14.2 yamt * Copyright (c) 1998 The NetBSD Foundation, Inc.
45 1.1.14.2 yamt * All rights reserved.
46 1.1.14.2 yamt *
47 1.1.14.2 yamt * This code is derived from software contributed to The NetBSD Foundation
48 1.1.14.2 yamt * by Charles M. Hannum.
49 1.1.14.2 yamt *
50 1.1.14.2 yamt * Redistribution and use in source and binary forms, with or without
51 1.1.14.2 yamt * modification, are permitted provided that the following conditions
52 1.1.14.2 yamt * are met:
53 1.1.14.2 yamt * 1. Redistributions of source code must retain the above copyright
54 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer.
55 1.1.14.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
56 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer in the
57 1.1.14.2 yamt * documentation and/or other materials provided with the distribution.
58 1.1.14.2 yamt * 3. All advertising materials mentioning features or use of this software
59 1.1.14.2 yamt * must display the following acknowledgement:
60 1.1.14.2 yamt * This product includes software developed by the NetBSD
61 1.1.14.2 yamt * Foundation, Inc. and its contributors.
62 1.1.14.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
63 1.1.14.2 yamt * contributors may be used to endorse or promote products derived
64 1.1.14.2 yamt * from this software without specific prior written permission.
65 1.1.14.2 yamt *
66 1.1.14.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
67 1.1.14.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
68 1.1.14.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69 1.1.14.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
70 1.1.14.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
71 1.1.14.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
72 1.1.14.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
73 1.1.14.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
74 1.1.14.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
75 1.1.14.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
76 1.1.14.2 yamt * POSSIBILITY OF SUCH DAMAGE.
77 1.1.14.2 yamt */
78 1.1.14.2 yamt
79 1.1.14.2 yamt /*-
80 1.1.14.2 yamt * Copyright (c) 1991 The Regents of the University of California.
81 1.1.14.2 yamt * All rights reserved.
82 1.1.14.2 yamt *
83 1.1.14.2 yamt * Redistribution and use in source and binary forms, with or without
84 1.1.14.2 yamt * modification, are permitted provided that the following conditions
85 1.1.14.2 yamt * are met:
86 1.1.14.2 yamt * 1. Redistributions of source code must retain the above copyright
87 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer.
88 1.1.14.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
89 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer in the
90 1.1.14.2 yamt * documentation and/or other materials provided with the distribution.
91 1.1.14.2 yamt * 3. Neither the name of the University nor the names of its contributors
92 1.1.14.2 yamt * may be used to endorse or promote products derived from this software
93 1.1.14.2 yamt * without specific prior written permission.
94 1.1.14.2 yamt *
95 1.1.14.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
96 1.1.14.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
97 1.1.14.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98 1.1.14.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
99 1.1.14.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
100 1.1.14.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
101 1.1.14.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
102 1.1.14.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
103 1.1.14.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
104 1.1.14.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
105 1.1.14.2 yamt * SUCH DAMAGE.
106 1.1.14.2 yamt *
107 1.1.14.2 yamt * @(#)com.c 7.5 (Berkeley) 5/16/91
108 1.1.14.2 yamt */
109 1.1.14.2 yamt
110 1.1.14.2 yamt #include <sys/cdefs.h>
111 1.1.14.5 yamt __KERNEL_RCSID(0, "$NetBSD: com_arbus.c,v 1.1.14.5 2008/03/17 09:14:21 yamt Exp $");
112 1.1.14.2 yamt
113 1.1.14.2 yamt #include <sys/param.h>
114 1.1.14.2 yamt #include <sys/systm.h>
115 1.1.14.2 yamt #include <sys/device.h>
116 1.1.14.3 yamt #include <sys/kernel.h>
117 1.1.14.2 yamt #include <sys/termios.h>
118 1.1.14.2 yamt #include <sys/ttydefaults.h>
119 1.1.14.2 yamt #include <sys/types.h>
120 1.1.14.2 yamt
121 1.1.14.2 yamt #include <machine/bus.h>
122 1.1.14.2 yamt
123 1.1.14.2 yamt #include <dev/cons.h>
124 1.1.14.2 yamt #include <dev/ic/comreg.h>
125 1.1.14.2 yamt #include <dev/ic/comvar.h>
126 1.1.14.2 yamt
127 1.1.14.2 yamt #include <mips/cpuregs.h>
128 1.1.14.2 yamt #include <mips/atheros/include/arbusvar.h>
129 1.1.14.3 yamt #include <mips/atheros/include/ar531xvar.h>
130 1.1.14.2 yamt
131 1.1.14.4 yamt #include "opt_com.h"
132 1.1.14.4 yamt
133 1.1.14.2 yamt struct com_arbus_softc {
134 1.1.14.2 yamt struct com_softc sc_com;
135 1.1.14.2 yamt };
136 1.1.14.2 yamt
137 1.1.14.3 yamt static void com_arbus_initmap(struct com_regs *);
138 1.1.14.3 yamt //static bus_space_tag_t com_arbus_get_bus_space_tag(void);
139 1.1.14.5 yamt static int com_arbus_match(device_t, cfdata_t , void *);
140 1.1.14.5 yamt static void com_arbus_attach(device_t, device_t, void *);
141 1.1.14.2 yamt
142 1.1.14.5 yamt CFATTACH_DECL_NEW(com_arbus, sizeof(struct com_arbus_softc),
143 1.1.14.2 yamt com_arbus_match, com_arbus_attach, NULL, NULL);
144 1.1.14.2 yamt
145 1.1.14.2 yamt #if 0
146 1.1.14.2 yamt #ifdef TTYDEF_SPEED
147 1.1.14.2 yamt #define COM_ARBUS_BAUD TTYDEF_SPEED
148 1.1.14.2 yamt #else
149 1.1.14.2 yamt #define COM_ARBUS_BAUD 115200
150 1.1.14.2 yamt #endif
151 1.1.14.2 yamt #endif
152 1.1.14.4 yamt
153 1.1.14.4 yamt #ifndef COM_ARBUS_BAUD
154 1.1.14.2 yamt #define COM_ARBUS_BAUD 115200
155 1.1.14.4 yamt #endif
156 1.1.14.2 yamt
157 1.1.14.2 yamt int com_arbus_baud = COM_ARBUS_BAUD;
158 1.1.14.2 yamt
159 1.1.14.2 yamt #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
160 1.1.14.2 yamt
161 1.1.14.3 yamt #ifndef COM_REGMAP
162 1.1.14.3 yamt #error COM_REGMAP not defined!
163 1.1.14.3 yamt #endif
164 1.1.14.3 yamt
165 1.1.14.2 yamt int
166 1.1.14.5 yamt com_arbus_match(device_t parent, cfdata_t cf, void *aux)
167 1.1.14.2 yamt {
168 1.1.14.2 yamt struct arbus_attach_args *aa = aux;
169 1.1.14.3 yamt struct com_regs regs;
170 1.1.14.2 yamt int rv;
171 1.1.14.2 yamt
172 1.1.14.3 yamt if (strcmp(aa->aa_name, cf->cf_name) != 0)
173 1.1.14.3 yamt return 0;
174 1.1.14.3 yamt
175 1.1.14.3 yamt if (com_is_console(aa->aa_bst, aa->aa_addr, ®s.cr_ioh))
176 1.1.14.2 yamt return 1;
177 1.1.14.2 yamt
178 1.1.14.2 yamt if (bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size,
179 1.1.14.3 yamt 0, ®s.cr_ioh))
180 1.1.14.2 yamt return 0;
181 1.1.14.2 yamt
182 1.1.14.3 yamt regs.cr_iot = aa->aa_bst;
183 1.1.14.3 yamt regs.cr_iobase = aa->aa_addr;
184 1.1.14.3 yamt regs.cr_nports = aa->aa_size;
185 1.1.14.3 yamt com_arbus_initmap(®s);
186 1.1.14.3 yamt
187 1.1.14.3 yamt rv = com_probe_subr(®s);
188 1.1.14.3 yamt
189 1.1.14.3 yamt bus_space_unmap(aa->aa_bst, regs.cr_ioh, aa->aa_size);
190 1.1.14.2 yamt
191 1.1.14.2 yamt return rv;
192 1.1.14.2 yamt }
193 1.1.14.2 yamt
194 1.1.14.2 yamt void
195 1.1.14.5 yamt com_arbus_attach(device_t parent, device_t self, void *aux)
196 1.1.14.2 yamt {
197 1.1.14.5 yamt struct com_arbus_softc *arsc = device_private(self);
198 1.1.14.2 yamt struct com_softc *sc = &arsc->sc_com;
199 1.1.14.2 yamt struct arbus_attach_args *aa = aux;
200 1.1.14.3 yamt prop_number_t prop;
201 1.1.14.3 yamt bus_space_handle_t ioh;
202 1.1.14.2 yamt
203 1.1.14.5 yamt sc->sc_dev = self;
204 1.1.14.5 yamt
205 1.1.14.5 yamt prop = prop_dictionary_get(device_properties(sc->sc_dev),
206 1.1.14.3 yamt "frequency");
207 1.1.14.3 yamt if (prop == NULL) {
208 1.1.14.5 yamt aprint_error(": unable to get frequency property\n");
209 1.1.14.2 yamt return;
210 1.1.14.2 yamt }
211 1.1.14.3 yamt KASSERT(prop_object_type(prop) == PROP_TYPE_NUMBER);
212 1.1.14.2 yamt
213 1.1.14.3 yamt sc->sc_frequency = (int)prop_number_integer_value(prop);
214 1.1.14.2 yamt
215 1.1.14.3 yamt if (!com_is_console(aa->aa_bst, aa->aa_addr, &ioh) &&
216 1.1.14.3 yamt bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0,
217 1.1.14.3 yamt &ioh) != 0) {
218 1.1.14.5 yamt aprint_error(": can't map registers\n");
219 1.1.14.3 yamt return;
220 1.1.14.2 yamt }
221 1.1.14.2 yamt
222 1.1.14.3 yamt COM_INIT_REGS(sc->sc_regs, aa->aa_bst, ioh, aa->aa_addr);
223 1.1.14.3 yamt sc->sc_regs.cr_nports = aa->aa_size;
224 1.1.14.3 yamt com_arbus_initmap(&sc->sc_regs);
225 1.1.14.2 yamt
226 1.1.14.3 yamt com_attach_subr(sc);
227 1.1.14.2 yamt
228 1.1.14.3 yamt arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, comintr, sc);
229 1.1.14.2 yamt }
230 1.1.14.2 yamt
231 1.1.14.3 yamt void
232 1.1.14.3 yamt com_arbus_initmap(struct com_regs *regsp)
233 1.1.14.2 yamt {
234 1.1.14.3 yamt int i;
235 1.1.14.2 yamt
236 1.1.14.3 yamt /* rewrite the map to shift for alignment */
237 1.1.14.3 yamt for (i = 0;
238 1.1.14.3 yamt i < (sizeof (regsp->cr_map) / sizeof (regsp->cr_map[0])); i++) {
239 1.1.14.3 yamt regsp->cr_map[i] = (com_std_map[i] * 4) + 3;
240 1.1.14.2 yamt }
241 1.1.14.2 yamt }
242 1.1.14.2 yamt
243 1.1.14.2 yamt void
244 1.1.14.3 yamt com_arbus_cnattach(bus_addr_t addr, uint32_t freq)
245 1.1.14.2 yamt {
246 1.1.14.3 yamt struct com_regs regs;
247 1.1.14.2 yamt
248 1.1.14.3 yamt regs.cr_iot = arbus_get_bus_space_tag();
249 1.1.14.3 yamt regs.cr_iobase = addr;
250 1.1.14.3 yamt regs.cr_nports = 0x1000;
251 1.1.14.3 yamt com_arbus_initmap(®s);
252 1.1.14.2 yamt
253 1.1.14.3 yamt if (bus_space_map(regs.cr_iot, regs.cr_iobase, regs.cr_nports, 0,
254 1.1.14.3 yamt ®s.cr_ioh))
255 1.1.14.3 yamt return;
256 1.1.14.2 yamt
257 1.1.14.3 yamt comcnattach1(®s, com_arbus_baud, freq, COM_TYPE_NORMAL, CONMODE);
258 1.1.14.2 yamt }
259 1.1.14.2 yamt
260