com_arbus.c revision 1.1.8.2 1 1.1.8.2 simonb /* $Id: com_arbus.c,v 1.1.8.2 2006/04/22 11:37:42 simonb Exp $ */
2 1.1.8.2 simonb /*-
3 1.1.8.2 simonb * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
4 1.1.8.2 simonb * Copyright (c) 2006 Garrett D'Amore.
5 1.1.8.2 simonb * All rights reserved.
6 1.1.8.2 simonb *
7 1.1.8.2 simonb * Portions of this code were written by Garrett D'Amore for the
8 1.1.8.2 simonb * Champaign-Urbana Community Wireless Network Project.
9 1.1.8.2 simonb *
10 1.1.8.2 simonb * Redistribution and use in source and binary forms, with or
11 1.1.8.2 simonb * without modification, are permitted provided that the following
12 1.1.8.2 simonb * conditions are met:
13 1.1.8.2 simonb * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 simonb * 2. Redistributions in binary form must reproduce the above
16 1.1.8.2 simonb * copyright notice, this list of conditions and the following
17 1.1.8.2 simonb * disclaimer in the documentation and/or other materials provided
18 1.1.8.2 simonb * with the distribution.
19 1.1.8.2 simonb * 3. All advertising materials mentioning features or use of this
20 1.1.8.2 simonb * software must display the following acknowledgements:
21 1.1.8.2 simonb * This product includes software developed by the Urbana-Champaign
22 1.1.8.2 simonb * Independent Media Center.
23 1.1.8.2 simonb * This product includes software developed by Garrett D'Amore.
24 1.1.8.2 simonb * 4. Urbana-Champaign Independent Media Center's name and Garrett
25 1.1.8.2 simonb * D'Amore's name may not be used to endorse or promote products
26 1.1.8.2 simonb * derived from this software without specific prior written permission.
27 1.1.8.2 simonb *
28 1.1.8.2 simonb * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
29 1.1.8.2 simonb * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
30 1.1.8.2 simonb * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 1.1.8.2 simonb * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.1.8.2 simonb * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
33 1.1.8.2 simonb * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
34 1.1.8.2 simonb * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 1.1.8.2 simonb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 1.1.8.2 simonb * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 1.1.8.2 simonb * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 1.1.8.2 simonb * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 1.1.8.2 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40 1.1.8.2 simonb * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 1.1.8.2 simonb */
42 1.1.8.2 simonb
43 1.1.8.2 simonb /*-
44 1.1.8.2 simonb * Copyright (c) 1998 The NetBSD Foundation, Inc.
45 1.1.8.2 simonb * All rights reserved.
46 1.1.8.2 simonb *
47 1.1.8.2 simonb * This code is derived from software contributed to The NetBSD Foundation
48 1.1.8.2 simonb * by Charles M. Hannum.
49 1.1.8.2 simonb *
50 1.1.8.2 simonb * Redistribution and use in source and binary forms, with or without
51 1.1.8.2 simonb * modification, are permitted provided that the following conditions
52 1.1.8.2 simonb * are met:
53 1.1.8.2 simonb * 1. Redistributions of source code must retain the above copyright
54 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer.
55 1.1.8.2 simonb * 2. Redistributions in binary form must reproduce the above copyright
56 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer in the
57 1.1.8.2 simonb * documentation and/or other materials provided with the distribution.
58 1.1.8.2 simonb * 3. All advertising materials mentioning features or use of this software
59 1.1.8.2 simonb * must display the following acknowledgement:
60 1.1.8.2 simonb * This product includes software developed by the NetBSD
61 1.1.8.2 simonb * Foundation, Inc. and its contributors.
62 1.1.8.2 simonb * 4. Neither the name of The NetBSD Foundation nor the names of its
63 1.1.8.2 simonb * contributors may be used to endorse or promote products derived
64 1.1.8.2 simonb * from this software without specific prior written permission.
65 1.1.8.2 simonb *
66 1.1.8.2 simonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
67 1.1.8.2 simonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
68 1.1.8.2 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69 1.1.8.2 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
70 1.1.8.2 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
71 1.1.8.2 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
72 1.1.8.2 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
73 1.1.8.2 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
74 1.1.8.2 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
75 1.1.8.2 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
76 1.1.8.2 simonb * POSSIBILITY OF SUCH DAMAGE.
77 1.1.8.2 simonb */
78 1.1.8.2 simonb
79 1.1.8.2 simonb /*-
80 1.1.8.2 simonb * Copyright (c) 1991 The Regents of the University of California.
81 1.1.8.2 simonb * All rights reserved.
82 1.1.8.2 simonb *
83 1.1.8.2 simonb * Redistribution and use in source and binary forms, with or without
84 1.1.8.2 simonb * modification, are permitted provided that the following conditions
85 1.1.8.2 simonb * are met:
86 1.1.8.2 simonb * 1. Redistributions of source code must retain the above copyright
87 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer.
88 1.1.8.2 simonb * 2. Redistributions in binary form must reproduce the above copyright
89 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer in the
90 1.1.8.2 simonb * documentation and/or other materials provided with the distribution.
91 1.1.8.2 simonb * 3. Neither the name of the University nor the names of its contributors
92 1.1.8.2 simonb * may be used to endorse or promote products derived from this software
93 1.1.8.2 simonb * without specific prior written permission.
94 1.1.8.2 simonb *
95 1.1.8.2 simonb * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
96 1.1.8.2 simonb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
97 1.1.8.2 simonb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98 1.1.8.2 simonb * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
99 1.1.8.2 simonb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
100 1.1.8.2 simonb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
101 1.1.8.2 simonb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
102 1.1.8.2 simonb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
103 1.1.8.2 simonb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
104 1.1.8.2 simonb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
105 1.1.8.2 simonb * SUCH DAMAGE.
106 1.1.8.2 simonb *
107 1.1.8.2 simonb * @(#)com.c 7.5 (Berkeley) 5/16/91
108 1.1.8.2 simonb */
109 1.1.8.2 simonb
110 1.1.8.2 simonb #include <sys/cdefs.h>
111 1.1.8.2 simonb __KERNEL_RCSID(0, "$NetBSD: com_arbus.c,v 1.1.8.2 2006/04/22 11:37:42 simonb Exp $");
112 1.1.8.2 simonb
113 1.1.8.2 simonb #include <sys/param.h>
114 1.1.8.2 simonb #include <sys/systm.h>
115 1.1.8.2 simonb #include <sys/device.h>
116 1.1.8.2 simonb #include <sys/termios.h>
117 1.1.8.2 simonb #include <sys/ttydefaults.h>
118 1.1.8.2 simonb #include <sys/types.h>
119 1.1.8.2 simonb
120 1.1.8.2 simonb #include <machine/bus.h>
121 1.1.8.2 simonb
122 1.1.8.2 simonb #include <dev/cons.h>
123 1.1.8.2 simonb #include <dev/ic/comreg.h>
124 1.1.8.2 simonb #include <dev/ic/comvar.h>
125 1.1.8.2 simonb
126 1.1.8.2 simonb #include <mips/cpuregs.h>
127 1.1.8.2 simonb #include <mips/atheros/include/arbusvar.h>
128 1.1.8.2 simonb #include <mips/atheros/include/ar531xreg.h>
129 1.1.8.2 simonb
130 1.1.8.2 simonb struct com_arbus_softc {
131 1.1.8.2 simonb struct com_softc sc_com;
132 1.1.8.2 simonb };
133 1.1.8.2 simonb
134 1.1.8.2 simonb static bus_space_tag_t com_arbus_get_bus_space_tag(void);
135 1.1.8.2 simonb static int com_arbus_match(struct device *, struct cfdata *, void *);
136 1.1.8.2 simonb static void com_arbus_attach(struct device *, struct device *, void *);
137 1.1.8.2 simonb
138 1.1.8.2 simonb CFATTACH_DECL(com_arbus, sizeof(struct com_arbus_softc),
139 1.1.8.2 simonb com_arbus_match, com_arbus_attach, NULL, NULL);
140 1.1.8.2 simonb
141 1.1.8.2 simonb #if 0
142 1.1.8.2 simonb #ifdef TTYDEF_SPEED
143 1.1.8.2 simonb #define COM_ARBUS_BAUD TTYDEF_SPEED
144 1.1.8.2 simonb #else
145 1.1.8.2 simonb #define COM_ARBUS_BAUD 115200
146 1.1.8.2 simonb #endif
147 1.1.8.2 simonb #endif
148 1.1.8.2 simonb #define COM_ARBUS_BAUD 115200
149 1.1.8.2 simonb
150 1.1.8.2 simonb int com_arbus_baud = COM_ARBUS_BAUD;
151 1.1.8.2 simonb
152 1.1.8.2 simonb #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
153 1.1.8.2 simonb
154 1.1.8.2 simonb int
155 1.1.8.2 simonb com_arbus_match(struct device *parent, struct cfdata *cf, void *aux)
156 1.1.8.2 simonb {
157 1.1.8.2 simonb struct arbus_attach_args *aa = aux;
158 1.1.8.2 simonb bus_space_handle_t bsh;
159 1.1.8.2 simonb int rv;
160 1.1.8.2 simonb
161 1.1.8.2 simonb if (com_is_console(com_arbus_get_bus_space_tag(), aa->aa_addr, NULL)) {
162 1.1.8.2 simonb return 1;
163 1.1.8.2 simonb }
164 1.1.8.2 simonb
165 1.1.8.2 simonb if (bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size,
166 1.1.8.2 simonb 0, &bsh))
167 1.1.8.2 simonb return 0;
168 1.1.8.2 simonb
169 1.1.8.2 simonb rv = comprobe1(aa->aa_bst, bsh);
170 1.1.8.2 simonb bus_space_unmap(aa->aa_bst, bsh, aa->aa_size);
171 1.1.8.2 simonb
172 1.1.8.2 simonb return rv;
173 1.1.8.2 simonb }
174 1.1.8.2 simonb
175 1.1.8.2 simonb void
176 1.1.8.2 simonb com_arbus_attach(struct device *parent, struct device *self, void *aux)
177 1.1.8.2 simonb {
178 1.1.8.2 simonb struct com_arbus_softc *arsc = (void *)self;
179 1.1.8.2 simonb struct com_softc *sc = &arsc->sc_com;
180 1.1.8.2 simonb struct arbus_attach_args *aa = aux;
181 1.1.8.2 simonb
182 1.1.8.2 simonb sc->sc_iot = com_arbus_get_bus_space_tag();
183 1.1.8.2 simonb sc->sc_iobase = aa->aa_addr;
184 1.1.8.2 simonb sc->sc_frequency = curcpu()->ci_cpu_freq / 4;
185 1.1.8.2 simonb
186 1.1.8.2 simonb if (!com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) &&
187 1.1.8.2 simonb bus_space_map(sc->sc_iot, sc->sc_iobase, aa->aa_size, 0,
188 1.1.8.2 simonb &sc->sc_ioh) != 0) {
189 1.1.8.2 simonb printf(": can't map registers\n");
190 1.1.8.2 simonb return;
191 1.1.8.2 simonb }
192 1.1.8.2 simonb
193 1.1.8.2 simonb com_attach_subr(sc);
194 1.1.8.2 simonb
195 1.1.8.2 simonb if (aa->aa_irq >= 0) {
196 1.1.8.2 simonb arbus_intr_establish(aa->aa_irq, comintr, sc);
197 1.1.8.2 simonb }
198 1.1.8.2 simonb }
199 1.1.8.2 simonb
200 1.1.8.2 simonb /*
201 1.1.8.2 simonb * This hideousness is to cope with the fact that the 16550 registers need
202 1.1.8.2 simonb * a stride. Yech!
203 1.1.8.2 simonb */
204 1.1.8.2 simonb static struct mips_bus_space com_arbus_space;
205 1.1.8.2 simonb
206 1.1.8.2 simonb static void
207 1.1.8.2 simonb com_arbus_write_1(void *v, bus_space_handle_t h, bus_size_t off, uint8_t val)
208 1.1.8.2 simonb {
209 1.1.8.2 simonb bus_space_write_1((bus_space_tag_t)v, h, (off * 4) + 3, val);
210 1.1.8.2 simonb }
211 1.1.8.2 simonb
212 1.1.8.2 simonb static uint8_t
213 1.1.8.2 simonb com_arbus_read_1(void *v, bus_space_handle_t h, bus_size_t off)
214 1.1.8.2 simonb {
215 1.1.8.2 simonb return bus_space_read_1((bus_space_tag_t)v, h, (off * 4) + 3);
216 1.1.8.2 simonb }
217 1.1.8.2 simonb
218 1.1.8.2 simonb static void
219 1.1.8.2 simonb com_arbus_read_multi_1(void *v, bus_space_handle_t h, bus_size_t off,
220 1.1.8.2 simonb uint8_t *data, bus_size_t cnt)
221 1.1.8.2 simonb {
222 1.1.8.2 simonb while (cnt-- > 0) {
223 1.1.8.2 simonb *data++ = com_arbus_read_1(v, h, off);
224 1.1.8.2 simonb }
225 1.1.8.2 simonb }
226 1.1.8.2 simonb
227 1.1.8.2 simonb static void
228 1.1.8.2 simonb com_arbus_write_multi_1(void *v, bus_space_handle_t h, bus_size_t off,
229 1.1.8.2 simonb const uint8_t *data, bus_size_t cnt)
230 1.1.8.2 simonb {
231 1.1.8.2 simonb while (cnt-- > 0) {
232 1.1.8.2 simonb com_arbus_write_1(v, h, off, *data++);
233 1.1.8.2 simonb }
234 1.1.8.2 simonb }
235 1.1.8.2 simonb
236 1.1.8.2 simonb static void
237 1.1.8.2 simonb com_arbus_barrier(void *v, bus_space_handle_t h, bus_size_t o, bus_size_t l,
238 1.1.8.2 simonb int f)
239 1.1.8.2 simonb {
240 1.1.8.2 simonb bus_space_barrier((bus_space_tag_t)v, h, o, l, f);
241 1.1.8.2 simonb }
242 1.1.8.2 simonb
243 1.1.8.2 simonb static int
244 1.1.8.2 simonb com_arbus_map(void *v, bus_addr_t addr, bus_size_t size, int flag,
245 1.1.8.2 simonb bus_space_handle_t *bshp, int acct)
246 1.1.8.2 simonb {
247 1.1.8.2 simonb return bus_space_map((bus_space_tag_t)v, addr, size, flag, bshp);
248 1.1.8.2 simonb }
249 1.1.8.2 simonb
250 1.1.8.2 simonb static void
251 1.1.8.2 simonb com_arbus_unmap(void *v, bus_space_handle_t bsh, bus_size_t size, int acct)
252 1.1.8.2 simonb {
253 1.1.8.2 simonb bus_space_unmap((bus_space_tag_t)v, bsh, size);
254 1.1.8.2 simonb }
255 1.1.8.2 simonb
256 1.1.8.2 simonb bus_space_tag_t
257 1.1.8.2 simonb com_arbus_get_bus_space_tag(void)
258 1.1.8.2 simonb {
259 1.1.8.2 simonb static int done = 0;
260 1.1.8.2 simonb if (!done) {
261 1.1.8.2 simonb com_arbus_space.bs_cookie = arbus_get_bus_space_tag();
262 1.1.8.2 simonb com_arbus_space.bs_w_1 = com_arbus_write_1;
263 1.1.8.2 simonb com_arbus_space.bs_r_1 = com_arbus_read_1;
264 1.1.8.2 simonb com_arbus_space.bs_wm_1 = com_arbus_write_multi_1;
265 1.1.8.2 simonb com_arbus_space.bs_rm_1 = com_arbus_read_multi_1;
266 1.1.8.2 simonb com_arbus_space.bs_barrier = com_arbus_barrier;
267 1.1.8.2 simonb com_arbus_space.bs_map = com_arbus_map;
268 1.1.8.2 simonb com_arbus_space.bs_unmap = com_arbus_unmap;
269 1.1.8.2 simonb done++;
270 1.1.8.2 simonb }
271 1.1.8.2 simonb return &com_arbus_space;
272 1.1.8.2 simonb }
273 1.1.8.2 simonb
274 1.1.8.2 simonb void
275 1.1.8.2 simonb com_arbus_cnattach(bus_addr_t addr)
276 1.1.8.2 simonb {
277 1.1.8.2 simonb bus_space_tag_t bst;
278 1.1.8.2 simonb bus_space_handle_t bsh;
279 1.1.8.2 simonb uint32_t sysfreq;
280 1.1.8.2 simonb extern void mdputs(const char *);
281 1.1.8.2 simonb
282 1.1.8.2 simonb bst = com_arbus_get_bus_space_tag();
283 1.1.8.2 simonb if (bus_space_map(bst, addr, 0x1000, 0, &bsh))
284 1.1.8.2 simonb return;
285 1.1.8.2 simonb
286 1.1.8.2 simonb sysfreq = curcpu()->ci_cpu_freq / 4;
287 1.1.8.2 simonb
288 1.1.8.2 simonb comcnattach(bst, addr, com_arbus_baud, sysfreq,
289 1.1.8.2 simonb COM_TYPE_NORMAL, CONMODE);
290 1.1.8.2 simonb }
291 1.1.8.2 simonb
292