footbridge_com.c revision 1.2.6.6 1 1.2.6.6 nathanw /* $NetBSD: footbridge_com.c,v 1.2.6.6 2002/10/18 02:35:24 nathanw Exp $ */
2 1.2.6.2 nathanw
3 1.2.6.2 nathanw /*-
4 1.2.6.2 nathanw * Copyright (c) 1997 Mark Brinicombe
5 1.2.6.2 nathanw * Copyright (c) 1997 Causality Limited
6 1.2.6.2 nathanw *
7 1.2.6.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.2.6.2 nathanw * modification, are permitted provided that the following conditions
9 1.2.6.2 nathanw * are met:
10 1.2.6.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.2.6.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.2.6.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.6.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.2.6.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.2.6.2 nathanw * 3. All advertising materials mentioning features or use of this software
16 1.2.6.2 nathanw * must display the following acknowledgement:
17 1.2.6.2 nathanw * This product includes software developed by Mark Brinicombe
18 1.2.6.2 nathanw * for the NetBSD Project.
19 1.2.6.2 nathanw * 4. The name of the author may not be used to endorse or promote products
20 1.2.6.2 nathanw * derived from this software without specific prior written permission.
21 1.2.6.2 nathanw *
22 1.2.6.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.2.6.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.2.6.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.2.6.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.2.6.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.2.6.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.2.6.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.2.6.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.2.6.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.2.6.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.2.6.2 nathanw */
33 1.2.6.2 nathanw
34 1.2.6.2 nathanw /*
35 1.2.6.2 nathanw * COM driver, using the footbridge UART
36 1.2.6.2 nathanw */
37 1.2.6.2 nathanw
38 1.2.6.2 nathanw #include "opt_ddb.h"
39 1.2.6.2 nathanw
40 1.2.6.2 nathanw #include <sys/param.h>
41 1.2.6.2 nathanw #include <sys/systm.h>
42 1.2.6.2 nathanw #include <sys/ioctl.h>
43 1.2.6.2 nathanw #include <sys/select.h>
44 1.2.6.2 nathanw #include <sys/tty.h>
45 1.2.6.2 nathanw #include <sys/proc.h>
46 1.2.6.2 nathanw #include <sys/conf.h>
47 1.2.6.2 nathanw #include <sys/syslog.h>
48 1.2.6.2 nathanw #include <sys/device.h>
49 1.2.6.2 nathanw #include <sys/malloc.h>
50 1.2.6.2 nathanw #include <sys/termios.h>
51 1.2.6.2 nathanw #include <machine/bus.h>
52 1.2.6.2 nathanw #include <machine/intr.h>
53 1.2.6.2 nathanw #include <arm/footbridge/dc21285mem.h>
54 1.2.6.2 nathanw #include <arm/footbridge/dc21285reg.h>
55 1.2.6.2 nathanw #include <arm/footbridge/footbridgevar.h>
56 1.2.6.2 nathanw #include <arm/footbridge/footbridge.h>
57 1.2.6.2 nathanw
58 1.2.6.2 nathanw #include <dev/cons.h>
59 1.2.6.2 nathanw
60 1.2.6.2 nathanw #include "fcom.h"
61 1.2.6.2 nathanw
62 1.2.6.2 nathanw extern u_int dc21285_fclk;
63 1.2.6.2 nathanw
64 1.2.6.2 nathanw
65 1.2.6.2 nathanw #ifdef DDB
66 1.2.6.2 nathanw /*
67 1.2.6.2 nathanw * Define the keycode recognised as a request to call the debugger
68 1.2.6.2 nathanw * A value of 0 disables the feature when DDB is built in
69 1.2.6.2 nathanw */
70 1.2.6.2 nathanw #ifndef DDB_KEYCODE
71 1.2.6.2 nathanw #define DDB_KEYCODE 0
72 1.2.6.2 nathanw #endif /* DDB_KEYCODE */
73 1.2.6.2 nathanw #endif /* DDB */
74 1.2.6.2 nathanw
75 1.2.6.2 nathanw struct fcom_softc {
76 1.2.6.2 nathanw struct device sc_dev;
77 1.2.6.2 nathanw bus_space_tag_t sc_iot;
78 1.2.6.2 nathanw bus_space_handle_t sc_ioh;
79 1.2.6.2 nathanw void *sc_ih;
80 1.2.6.2 nathanw struct callout sc_softintr_ch;
81 1.2.6.2 nathanw int sc_rx_irq;
82 1.2.6.2 nathanw int sc_tx_irq;
83 1.2.6.2 nathanw int sc_hwflags;
84 1.2.6.2 nathanw #define HW_FLAG_CONSOLE 0x01
85 1.2.6.2 nathanw int sc_swflags;
86 1.2.6.2 nathanw int sc_l_ubrlcr;
87 1.2.6.2 nathanw int sc_m_ubrlcr;
88 1.2.6.2 nathanw int sc_h_ubrlcr;
89 1.2.6.2 nathanw char *sc_rxbuffer[2];
90 1.2.6.2 nathanw char *sc_rxbuf;
91 1.2.6.2 nathanw int sc_rxpos;
92 1.2.6.2 nathanw int sc_rxcur;
93 1.2.6.2 nathanw struct tty *sc_tty;
94 1.2.6.2 nathanw };
95 1.2.6.2 nathanw
96 1.2.6.2 nathanw #define RX_BUFFER_SIZE 0x100
97 1.2.6.2 nathanw
98 1.2.6.2 nathanw /* Macros to clear/set/test flags. */
99 1.2.6.2 nathanw #define SET(t, f) (t) |= (f)
100 1.2.6.2 nathanw #define CLR(t, f) (t) &= ~(f)
101 1.2.6.2 nathanw #define ISSET(t, f) ((t) & (f))
102 1.2.6.2 nathanw
103 1.2.6.2 nathanw static int fcom_probe __P((struct device *, struct cfdata *, void *));
104 1.2.6.2 nathanw static void fcom_attach __P((struct device *, struct device *, void *));
105 1.2.6.2 nathanw static void fcom_softintr __P((void *));
106 1.2.6.2 nathanw
107 1.2.6.2 nathanw static int fcom_rxintr __P((void *));
108 1.2.6.2 nathanw /*static int fcom_txintr __P((void *));*/
109 1.2.6.2 nathanw
110 1.2.6.2 nathanw /*struct consdev;*/
111 1.2.6.2 nathanw /*void fcomcnprobe __P((struct consdev *));
112 1.2.6.2 nathanw void fcomcninit __P((struct consdev *));*/
113 1.2.6.2 nathanw int fcomcngetc __P((dev_t));
114 1.2.6.2 nathanw void fcomcnputc __P((dev_t, int));
115 1.2.6.2 nathanw void fcomcnpollc __P((dev_t, int));
116 1.2.6.2 nathanw
117 1.2.6.6 nathanw CFATTACH_DECL(fcom, sizeof(struct fcom_softc),
118 1.2.6.6 nathanw fcom_probe, fcom_attach, NULL, NULL);
119 1.2.6.2 nathanw
120 1.2.6.2 nathanw extern struct cfdriver fcom_cd;
121 1.2.6.2 nathanw
122 1.2.6.5 nathanw dev_type_open(fcomopen);
123 1.2.6.5 nathanw dev_type_close(fcomclose);
124 1.2.6.5 nathanw dev_type_read(fcomread);
125 1.2.6.5 nathanw dev_type_write(fcomwrite);
126 1.2.6.5 nathanw dev_type_ioctl(fcomioctl);
127 1.2.6.5 nathanw dev_type_tty(fcomtty);
128 1.2.6.5 nathanw dev_type_poll(fcompoll);
129 1.2.6.5 nathanw
130 1.2.6.5 nathanw const struct cdevsw fcom_cdevsw = {
131 1.2.6.5 nathanw fcomopen, fcomclose, fcomread, fcomwrite, fcomioctl,
132 1.2.6.5 nathanw nostop, fcomtty, fcompoll, nommap, D_TTY
133 1.2.6.5 nathanw };
134 1.2.6.5 nathanw
135 1.2.6.2 nathanw void fcominit __P((bus_space_tag_t, bus_space_handle_t, int, int));
136 1.2.6.2 nathanw void fcominitcons __P((bus_space_tag_t, bus_space_handle_t));
137 1.2.6.2 nathanw
138 1.2.6.2 nathanw bus_space_tag_t fcomconstag;
139 1.2.6.2 nathanw bus_space_handle_t fcomconsioh;
140 1.2.6.2 nathanw extern int comcnmode;
141 1.2.6.2 nathanw extern int comcnspeed;
142 1.2.6.2 nathanw
143 1.2.6.2 nathanw #define COMUNIT(x) (minor(x))
144 1.2.6.2 nathanw #ifndef CONUNIT
145 1.2.6.2 nathanw #define CONUNIT 0
146 1.2.6.2 nathanw #endif
147 1.2.6.2 nathanw
148 1.2.6.2 nathanw /*
149 1.2.6.2 nathanw * The console is set up at init time, well in advance of the reset of the
150 1.2.6.2 nathanw * system and thus we have a private bus space tag for the console.
151 1.2.6.2 nathanw *
152 1.2.6.2 nathanw * The tag is provided by fcom_io.c and fcom_io_asm.S
153 1.2.6.2 nathanw */
154 1.2.6.2 nathanw extern struct bus_space fcomcons_bs_tag;
155 1.2.6.2 nathanw
156 1.2.6.2 nathanw /*
157 1.2.6.2 nathanw * int fcom_probe(struct device *parent, struct cfdata *cf, void *aux)
158 1.2.6.2 nathanw *
159 1.2.6.2 nathanw * Make sure we are trying to attach a com device and then
160 1.2.6.2 nathanw * probe for one.
161 1.2.6.2 nathanw */
162 1.2.6.2 nathanw
163 1.2.6.2 nathanw static int
164 1.2.6.2 nathanw fcom_probe(parent, cf, aux)
165 1.2.6.2 nathanw struct device *parent;
166 1.2.6.2 nathanw struct cfdata *cf;
167 1.2.6.2 nathanw void *aux;
168 1.2.6.2 nathanw {
169 1.2.6.2 nathanw union footbridge_attach_args *fba = aux;
170 1.2.6.2 nathanw
171 1.2.6.2 nathanw if (strcmp(fba->fba_name, "fcom") == 0)
172 1.2.6.2 nathanw return(1);
173 1.2.6.2 nathanw return(0);
174 1.2.6.2 nathanw }
175 1.2.6.2 nathanw
176 1.2.6.2 nathanw /*
177 1.2.6.2 nathanw * void fcom_attach(struct device *parent, struct device *self, void *aux)
178 1.2.6.2 nathanw *
179 1.2.6.2 nathanw * attach the com device
180 1.2.6.2 nathanw */
181 1.2.6.2 nathanw
182 1.2.6.2 nathanw static void
183 1.2.6.2 nathanw fcom_attach(parent, self, aux)
184 1.2.6.2 nathanw struct device *parent, *self;
185 1.2.6.2 nathanw void *aux;
186 1.2.6.2 nathanw {
187 1.2.6.2 nathanw union footbridge_attach_args *fba = aux;
188 1.2.6.2 nathanw struct fcom_softc *sc = (struct fcom_softc *)self;
189 1.2.6.2 nathanw
190 1.2.6.2 nathanw /* Set up the softc */
191 1.2.6.2 nathanw sc->sc_iot = fba->fba_fca.fca_iot;
192 1.2.6.2 nathanw sc->sc_ioh = fba->fba_fca.fca_ioh;
193 1.2.6.2 nathanw callout_init(&sc->sc_softintr_ch);
194 1.2.6.2 nathanw sc->sc_rx_irq = fba->fba_fca.fca_rx_irq;
195 1.2.6.2 nathanw sc->sc_tx_irq = fba->fba_fca.fca_tx_irq;
196 1.2.6.2 nathanw sc->sc_hwflags = 0;
197 1.2.6.2 nathanw sc->sc_swflags = 0;
198 1.2.6.2 nathanw
199 1.2.6.2 nathanw /* If we have a console tag then make a note of it */
200 1.2.6.2 nathanw if (fcomconstag)
201 1.2.6.2 nathanw sc->sc_hwflags |= HW_FLAG_CONSOLE;
202 1.2.6.2 nathanw
203 1.2.6.2 nathanw if (sc->sc_hwflags & HW_FLAG_CONSOLE) {
204 1.2.6.2 nathanw int major;
205 1.2.6.2 nathanw
206 1.2.6.2 nathanw /* locate the major number */
207 1.2.6.5 nathanw major = cdevsw_lookup_major(&fcom_cdevsw);
208 1.2.6.2 nathanw
209 1.2.6.2 nathanw cn_tab->cn_dev = makedev(major, sc->sc_dev.dv_unit);
210 1.2.6.2 nathanw printf(": console");
211 1.2.6.2 nathanw }
212 1.2.6.2 nathanw printf("\n");
213 1.2.6.2 nathanw
214 1.2.6.2 nathanw sc->sc_ih = intr_claim(sc->sc_rx_irq, IPL_SERIAL, "serial rx",
215 1.2.6.2 nathanw fcom_rxintr, sc);
216 1.2.6.2 nathanw if (sc->sc_ih == NULL)
217 1.2.6.6 nathanw panic("%s: Cannot install rx interrupt handler",
218 1.2.6.2 nathanw sc->sc_dev.dv_xname);
219 1.2.6.2 nathanw }
220 1.2.6.2 nathanw
221 1.2.6.2 nathanw static void fcomstart __P((struct tty *));
222 1.2.6.2 nathanw static int fcomparam __P((struct tty *, struct termios *));
223 1.2.6.2 nathanw
224 1.2.6.2 nathanw int
225 1.2.6.2 nathanw fcomopen(dev, flag, mode, p)
226 1.2.6.2 nathanw dev_t dev;
227 1.2.6.2 nathanw int flag, mode;
228 1.2.6.2 nathanw struct proc *p;
229 1.2.6.2 nathanw {
230 1.2.6.2 nathanw struct fcom_softc *sc;
231 1.2.6.2 nathanw int unit = minor(dev);
232 1.2.6.2 nathanw struct tty *tp;
233 1.2.6.2 nathanw
234 1.2.6.2 nathanw if (unit >= fcom_cd.cd_ndevs)
235 1.2.6.2 nathanw return ENXIO;
236 1.2.6.2 nathanw sc = fcom_cd.cd_devs[unit];
237 1.2.6.2 nathanw if (!sc)
238 1.2.6.2 nathanw return ENXIO;
239 1.2.6.2 nathanw if (!(tp = sc->sc_tty))
240 1.2.6.2 nathanw sc->sc_tty = tp = ttymalloc();
241 1.2.6.2 nathanw if (!sc->sc_rxbuffer[0]) {
242 1.2.6.2 nathanw sc->sc_rxbuffer[0] = malloc(RX_BUFFER_SIZE, M_DEVBUF, M_WAITOK);
243 1.2.6.2 nathanw sc->sc_rxbuffer[1] = malloc(RX_BUFFER_SIZE, M_DEVBUF, M_WAITOK);
244 1.2.6.2 nathanw sc->sc_rxpos = 0;
245 1.2.6.2 nathanw sc->sc_rxcur = 0;
246 1.2.6.2 nathanw sc->sc_rxbuf = sc->sc_rxbuffer[sc->sc_rxcur];
247 1.2.6.2 nathanw if (!sc->sc_rxbuf)
248 1.2.6.2 nathanw panic("%s: Cannot allocate rx buffer memory",
249 1.2.6.2 nathanw sc->sc_dev.dv_xname);
250 1.2.6.2 nathanw }
251 1.2.6.2 nathanw tp->t_oproc = fcomstart;
252 1.2.6.2 nathanw tp->t_param = fcomparam;
253 1.2.6.2 nathanw tp->t_dev = dev;
254 1.2.6.2 nathanw if (!(tp->t_state & TS_ISOPEN && tp->t_wopen == 0)) {
255 1.2.6.2 nathanw ttychars(tp);
256 1.2.6.2 nathanw tp->t_cflag = TTYDEF_CFLAG;
257 1.2.6.2 nathanw tp->t_iflag = TTYDEF_IFLAG;
258 1.2.6.2 nathanw tp->t_oflag = TTYDEF_OFLAG;
259 1.2.6.2 nathanw tp->t_lflag = TTYDEF_LFLAG;
260 1.2.6.2 nathanw
261 1.2.6.2 nathanw /*
262 1.2.6.2 nathanw * Initialize the termios status to the defaults. Add in the
263 1.2.6.2 nathanw * sticky bits from TIOCSFLAGS.
264 1.2.6.2 nathanw */
265 1.2.6.2 nathanw tp->t_ispeed = 0;
266 1.2.6.2 nathanw if (ISSET(sc->sc_hwflags, HW_FLAG_CONSOLE))
267 1.2.6.2 nathanw tp->t_ospeed = comcnspeed;
268 1.2.6.2 nathanw else
269 1.2.6.2 nathanw tp->t_ospeed = TTYDEF_SPEED;
270 1.2.6.2 nathanw
271 1.2.6.2 nathanw fcomparam(tp, &tp->t_termios);
272 1.2.6.2 nathanw ttsetwater(tp);
273 1.2.6.2 nathanw } else if ((tp->t_state&TS_XCLUDE) && suser(p->p_ucred, &p->p_acflag))
274 1.2.6.2 nathanw return EBUSY;
275 1.2.6.2 nathanw tp->t_state |= TS_CARR_ON;
276 1.2.6.2 nathanw
277 1.2.6.2 nathanw return (*tp->t_linesw->l_open)(dev, tp);
278 1.2.6.2 nathanw }
279 1.2.6.2 nathanw
280 1.2.6.2 nathanw int
281 1.2.6.2 nathanw fcomclose(dev, flag, mode, p)
282 1.2.6.2 nathanw dev_t dev;
283 1.2.6.2 nathanw int flag, mode;
284 1.2.6.2 nathanw struct proc *p;
285 1.2.6.2 nathanw {
286 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
287 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
288 1.2.6.2 nathanw /* XXX This is for cons.c. */
289 1.2.6.2 nathanw if (!ISSET(tp->t_state, TS_ISOPEN))
290 1.2.6.2 nathanw return (0);
291 1.2.6.2 nathanw
292 1.2.6.2 nathanw (*tp->t_linesw->l_close)(tp, flag);
293 1.2.6.2 nathanw ttyclose(tp);
294 1.2.6.2 nathanw #ifdef DIAGNOSTIC
295 1.2.6.2 nathanw if (sc->sc_rxbuffer[0] == NULL)
296 1.2.6.6 nathanw panic("fcomclose: rx buffers not allocated");
297 1.2.6.2 nathanw #endif /* DIAGNOSTIC */
298 1.2.6.2 nathanw free(sc->sc_rxbuffer[0], M_DEVBUF);
299 1.2.6.2 nathanw free(sc->sc_rxbuffer[1], M_DEVBUF);
300 1.2.6.2 nathanw sc->sc_rxbuffer[0] = NULL;
301 1.2.6.2 nathanw sc->sc_rxbuffer[1] = NULL;
302 1.2.6.2 nathanw
303 1.2.6.2 nathanw return 0;
304 1.2.6.2 nathanw }
305 1.2.6.2 nathanw
306 1.2.6.2 nathanw int
307 1.2.6.2 nathanw fcomread(dev, uio, flag)
308 1.2.6.2 nathanw dev_t dev;
309 1.2.6.2 nathanw struct uio *uio;
310 1.2.6.2 nathanw int flag;
311 1.2.6.2 nathanw {
312 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
313 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
314 1.2.6.2 nathanw
315 1.2.6.2 nathanw return (*tp->t_linesw->l_read)(tp, uio, flag);
316 1.2.6.2 nathanw }
317 1.2.6.2 nathanw
318 1.2.6.2 nathanw int
319 1.2.6.2 nathanw fcomwrite(dev, uio, flag)
320 1.2.6.2 nathanw dev_t dev;
321 1.2.6.2 nathanw struct uio *uio;
322 1.2.6.2 nathanw int flag;
323 1.2.6.2 nathanw {
324 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
325 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
326 1.2.6.2 nathanw
327 1.2.6.2 nathanw return (*tp->t_linesw->l_write)(tp, uio, flag);
328 1.2.6.2 nathanw }
329 1.2.6.2 nathanw
330 1.2.6.2 nathanw int
331 1.2.6.2 nathanw fcompoll(dev, events, p)
332 1.2.6.2 nathanw dev_t dev;
333 1.2.6.2 nathanw int events;
334 1.2.6.2 nathanw struct proc *p;
335 1.2.6.2 nathanw {
336 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
337 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
338 1.2.6.2 nathanw
339 1.2.6.2 nathanw return ((*tp->t_linesw->l_poll)(tp, events, p));
340 1.2.6.2 nathanw }
341 1.2.6.2 nathanw
342 1.2.6.2 nathanw int
343 1.2.6.2 nathanw fcomioctl(dev, cmd, data, flag, p)
344 1.2.6.2 nathanw dev_t dev;
345 1.2.6.2 nathanw u_long cmd;
346 1.2.6.2 nathanw caddr_t data;
347 1.2.6.2 nathanw int flag;
348 1.2.6.2 nathanw struct proc *p;
349 1.2.6.2 nathanw {
350 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
351 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
352 1.2.6.2 nathanw int error;
353 1.2.6.2 nathanw
354 1.2.6.4 nathanw if ((error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p)) !=
355 1.2.6.4 nathanw EPASSTHROUGH)
356 1.2.6.2 nathanw return error;
357 1.2.6.4 nathanw if ((error = ttioctl(tp, cmd, data, flag, p)) != EPASSTHROUGH)
358 1.2.6.2 nathanw return error;
359 1.2.6.2 nathanw
360 1.2.6.2 nathanw switch (cmd) {
361 1.2.6.2 nathanw case TIOCGFLAGS:
362 1.2.6.2 nathanw *(int *)data = sc->sc_swflags;
363 1.2.6.2 nathanw break;
364 1.2.6.2 nathanw
365 1.2.6.2 nathanw case TIOCSFLAGS:
366 1.2.6.2 nathanw error = suser(p->p_ucred, &p->p_acflag);
367 1.2.6.2 nathanw if (error)
368 1.2.6.2 nathanw return (error);
369 1.2.6.2 nathanw sc->sc_swflags = *(int *)data;
370 1.2.6.2 nathanw break;
371 1.2.6.2 nathanw }
372 1.2.6.2 nathanw
373 1.2.6.4 nathanw return EPASSTHROUGH;
374 1.2.6.2 nathanw }
375 1.2.6.2 nathanw
376 1.2.6.2 nathanw struct tty *
377 1.2.6.2 nathanw fcomtty(dev)
378 1.2.6.2 nathanw dev_t dev;
379 1.2.6.2 nathanw {
380 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
381 1.2.6.2 nathanw
382 1.2.6.2 nathanw return sc->sc_tty;
383 1.2.6.2 nathanw }
384 1.2.6.2 nathanw
385 1.2.6.2 nathanw static void
386 1.2.6.2 nathanw fcomstart(tp)
387 1.2.6.2 nathanw struct tty *tp;
388 1.2.6.2 nathanw {
389 1.2.6.2 nathanw struct clist *cl;
390 1.2.6.2 nathanw int s, len;
391 1.2.6.2 nathanw u_char buf[64];
392 1.2.6.2 nathanw int loop;
393 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(tp->t_dev)];
394 1.2.6.2 nathanw bus_space_tag_t iot = sc->sc_iot;
395 1.2.6.2 nathanw bus_space_handle_t ioh = sc->sc_ioh;
396 1.2.6.2 nathanw int timo;
397 1.2.6.2 nathanw
398 1.2.6.2 nathanw s = spltty();
399 1.2.6.2 nathanw if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
400 1.2.6.2 nathanw (void)splx(s);
401 1.2.6.2 nathanw return;
402 1.2.6.2 nathanw }
403 1.2.6.2 nathanw tp->t_state |= TS_BUSY;
404 1.2.6.2 nathanw (void)splx(s);
405 1.2.6.2 nathanw
406 1.2.6.2 nathanw /* s = splserial();*/
407 1.2.6.2 nathanw /* wait for any pending transmission to finish */
408 1.2.6.2 nathanw timo = 100000;
409 1.2.6.2 nathanw while ((bus_space_read_4(iot, ioh, UART_FLAGS) & UART_TX_BUSY) && --timo)
410 1.2.6.2 nathanw ;
411 1.2.6.2 nathanw
412 1.2.6.2 nathanw s = splserial();
413 1.2.6.2 nathanw if (bus_space_read_4(iot, ioh, UART_FLAGS) & UART_TX_BUSY) {
414 1.2.6.2 nathanw tp->t_state |= TS_TIMEOUT;
415 1.2.6.2 nathanw callout_reset(&tp->t_rstrt_ch, 1, ttrstrt, tp);
416 1.2.6.2 nathanw (void)splx(s);
417 1.2.6.2 nathanw return;
418 1.2.6.2 nathanw }
419 1.2.6.2 nathanw
420 1.2.6.2 nathanw (void)splx(s);
421 1.2.6.2 nathanw
422 1.2.6.2 nathanw cl = &tp->t_outq;
423 1.2.6.2 nathanw len = q_to_b(cl, buf, 64);
424 1.2.6.2 nathanw for (loop = 0; loop < len; ++loop) {
425 1.2.6.2 nathanw /* s = splserial();*/
426 1.2.6.2 nathanw
427 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_DATA, buf[loop]);
428 1.2.6.2 nathanw
429 1.2.6.2 nathanw /* wait for this transmission to complete */
430 1.2.6.2 nathanw timo = 100000;
431 1.2.6.2 nathanw while ((bus_space_read_4(iot, ioh, UART_FLAGS) & UART_TX_BUSY) && --timo)
432 1.2.6.2 nathanw ;
433 1.2.6.2 nathanw /* (void)splx(s);*/
434 1.2.6.2 nathanw }
435 1.2.6.2 nathanw s = spltty();
436 1.2.6.2 nathanw tp->t_state &= ~TS_BUSY;
437 1.2.6.2 nathanw if (cl->c_cc) {
438 1.2.6.2 nathanw tp->t_state |= TS_TIMEOUT;
439 1.2.6.2 nathanw callout_reset(&tp->t_rstrt_ch, 1, ttrstrt, tp);
440 1.2.6.2 nathanw }
441 1.2.6.2 nathanw if (cl->c_cc <= tp->t_lowat) {
442 1.2.6.2 nathanw if (tp->t_state & TS_ASLEEP) {
443 1.2.6.2 nathanw tp->t_state &= ~TS_ASLEEP;
444 1.2.6.2 nathanw wakeup(cl);
445 1.2.6.2 nathanw }
446 1.2.6.2 nathanw selwakeup(&tp->t_wsel);
447 1.2.6.2 nathanw }
448 1.2.6.2 nathanw (void)splx(s);
449 1.2.6.2 nathanw }
450 1.2.6.2 nathanw
451 1.2.6.2 nathanw static int
452 1.2.6.2 nathanw fcomparam(tp, t)
453 1.2.6.2 nathanw struct tty *tp;
454 1.2.6.2 nathanw struct termios *t;
455 1.2.6.2 nathanw {
456 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(tp->t_dev)];
457 1.2.6.2 nathanw bus_space_tag_t iot = sc->sc_iot;
458 1.2.6.2 nathanw bus_space_handle_t ioh = sc->sc_ioh;
459 1.2.6.2 nathanw int baudrate;
460 1.2.6.2 nathanw int h_ubrlcr;
461 1.2.6.2 nathanw int m_ubrlcr;
462 1.2.6.2 nathanw int l_ubrlcr;
463 1.2.6.2 nathanw int s;
464 1.2.6.2 nathanw
465 1.2.6.2 nathanw /* check requested parameters */
466 1.2.6.2 nathanw if (t->c_ospeed < 0)
467 1.2.6.2 nathanw return (EINVAL);
468 1.2.6.2 nathanw if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
469 1.2.6.2 nathanw return (EINVAL);
470 1.2.6.2 nathanw
471 1.2.6.2 nathanw switch (t->c_ospeed) {
472 1.2.6.2 nathanw case B1200:
473 1.2.6.2 nathanw case B2400:
474 1.2.6.2 nathanw case B4800:
475 1.2.6.2 nathanw case B9600:
476 1.2.6.2 nathanw case B19200:
477 1.2.6.2 nathanw case B38400:
478 1.2.6.2 nathanw baudrate = UART_BRD(dc21285_fclk, t->c_ospeed);
479 1.2.6.2 nathanw break;
480 1.2.6.2 nathanw default:
481 1.2.6.2 nathanw baudrate = UART_BRD(dc21285_fclk, 9600);
482 1.2.6.2 nathanw break;
483 1.2.6.2 nathanw }
484 1.2.6.2 nathanw
485 1.2.6.2 nathanw l_ubrlcr = baudrate & 0xff;
486 1.2.6.2 nathanw m_ubrlcr = (baudrate >> 8) & 0xf;
487 1.2.6.2 nathanw h_ubrlcr = 0;
488 1.2.6.2 nathanw
489 1.2.6.2 nathanw switch (ISSET(t->c_cflag, CSIZE)) {
490 1.2.6.2 nathanw case CS5:
491 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_5;
492 1.2.6.2 nathanw break;
493 1.2.6.2 nathanw case CS6:
494 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_6;
495 1.2.6.2 nathanw break;
496 1.2.6.2 nathanw case CS7:
497 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_7;
498 1.2.6.2 nathanw break;
499 1.2.6.2 nathanw case CS8:
500 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_8;
501 1.2.6.2 nathanw break;
502 1.2.6.2 nathanw }
503 1.2.6.2 nathanw
504 1.2.6.2 nathanw if (ISSET(t->c_cflag, PARENB)) {
505 1.2.6.2 nathanw h_ubrlcr |= UART_PARITY_ENABLE;
506 1.2.6.2 nathanw if (ISSET(t->c_cflag, PARODD))
507 1.2.6.2 nathanw h_ubrlcr |= UART_ODD_PARITY;
508 1.2.6.2 nathanw else
509 1.2.6.2 nathanw h_ubrlcr |= UART_EVEN_PARITY;
510 1.2.6.2 nathanw }
511 1.2.6.2 nathanw
512 1.2.6.2 nathanw if (ISSET(t->c_cflag, CSTOPB))
513 1.2.6.2 nathanw h_ubrlcr |= UART_STOP_BITS_2;
514 1.2.6.2 nathanw
515 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_L_UBRLCR, l_ubrlcr);
516 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_M_UBRLCR, m_ubrlcr);
517 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_H_UBRLCR, h_ubrlcr);
518 1.2.6.2 nathanw
519 1.2.6.2 nathanw s = splserial();
520 1.2.6.2 nathanw
521 1.2.6.2 nathanw sc->sc_l_ubrlcr = l_ubrlcr;
522 1.2.6.2 nathanw sc->sc_m_ubrlcr = m_ubrlcr;
523 1.2.6.2 nathanw sc->sc_h_ubrlcr = h_ubrlcr;
524 1.2.6.2 nathanw
525 1.2.6.2 nathanw /*
526 1.2.6.2 nathanw * For the console, always force CLOCAL and !HUPCL, so that the port
527 1.2.6.2 nathanw * is always active.
528 1.2.6.2 nathanw */
529 1.2.6.2 nathanw if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
530 1.2.6.2 nathanw ISSET(sc->sc_hwflags, HW_FLAG_CONSOLE)) {
531 1.2.6.2 nathanw SET(t->c_cflag, CLOCAL);
532 1.2.6.2 nathanw CLR(t->c_cflag, HUPCL);
533 1.2.6.2 nathanw }
534 1.2.6.2 nathanw
535 1.2.6.2 nathanw /* and copy to tty */
536 1.2.6.2 nathanw tp->t_ispeed = 0;
537 1.2.6.2 nathanw tp->t_ospeed = t->c_ospeed;
538 1.2.6.2 nathanw tp->t_cflag = t->c_cflag;
539 1.2.6.2 nathanw
540 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_L_UBRLCR, l_ubrlcr);
541 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_M_UBRLCR, m_ubrlcr);
542 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_H_UBRLCR, h_ubrlcr);
543 1.2.6.2 nathanw
544 1.2.6.2 nathanw (void)splx(s);
545 1.2.6.2 nathanw
546 1.2.6.2 nathanw return (0);
547 1.2.6.2 nathanw }
548 1.2.6.2 nathanw
549 1.2.6.2 nathanw static int softint_scheduled = 0;
550 1.2.6.2 nathanw
551 1.2.6.2 nathanw static void
552 1.2.6.2 nathanw fcom_softintr(arg)
553 1.2.6.2 nathanw void *arg;
554 1.2.6.2 nathanw {
555 1.2.6.2 nathanw struct fcom_softc *sc = arg;
556 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
557 1.2.6.2 nathanw int s;
558 1.2.6.2 nathanw int loop;
559 1.2.6.2 nathanw int len;
560 1.2.6.2 nathanw char *ptr;
561 1.2.6.2 nathanw
562 1.2.6.2 nathanw s = spltty();
563 1.2.6.2 nathanw ptr = sc->sc_rxbuf;
564 1.2.6.2 nathanw len = sc->sc_rxpos;
565 1.2.6.2 nathanw sc->sc_rxcur ^= 1;
566 1.2.6.2 nathanw sc->sc_rxbuf = sc->sc_rxbuffer[sc->sc_rxcur];
567 1.2.6.2 nathanw sc->sc_rxpos = 0;
568 1.2.6.2 nathanw (void)splx(s);
569 1.2.6.2 nathanw
570 1.2.6.2 nathanw for (loop = 0; loop < len; ++loop)
571 1.2.6.2 nathanw (*tp->t_linesw->l_rint)(ptr[loop], tp);
572 1.2.6.2 nathanw softint_scheduled = 0;
573 1.2.6.2 nathanw }
574 1.2.6.2 nathanw
575 1.2.6.2 nathanw #if 0
576 1.2.6.2 nathanw static int
577 1.2.6.2 nathanw fcom_txintr(arg)
578 1.2.6.2 nathanw void *arg;
579 1.2.6.2 nathanw {
580 1.2.6.2 nathanw /* struct fcom_softc *sc = arg;*/
581 1.2.6.2 nathanw
582 1.2.6.2 nathanw printf("fcom_txintr()\n");
583 1.2.6.2 nathanw return(0);
584 1.2.6.2 nathanw }
585 1.2.6.2 nathanw #endif
586 1.2.6.2 nathanw
587 1.2.6.2 nathanw static int
588 1.2.6.2 nathanw fcom_rxintr(arg)
589 1.2.6.2 nathanw void *arg;
590 1.2.6.2 nathanw {
591 1.2.6.2 nathanw struct fcom_softc *sc = arg;
592 1.2.6.2 nathanw bus_space_tag_t iot = sc->sc_iot;
593 1.2.6.2 nathanw bus_space_handle_t ioh = sc->sc_ioh;
594 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
595 1.2.6.2 nathanw int status;
596 1.2.6.2 nathanw int byte;
597 1.2.6.2 nathanw
598 1.2.6.2 nathanw do {
599 1.2.6.2 nathanw status = bus_space_read_4(iot, ioh, UART_FLAGS);
600 1.2.6.2 nathanw if ((status & UART_RX_FULL))
601 1.2.6.2 nathanw break;
602 1.2.6.2 nathanw byte = bus_space_read_4(iot, ioh, UART_DATA);
603 1.2.6.2 nathanw status = bus_space_read_4(iot, ioh, UART_RX_STAT);
604 1.2.6.2 nathanw #if DDB_KEYCODE > 0
605 1.2.6.2 nathanw /*
606 1.2.6.2 nathanw * Temporary hack so that I can force the kernel into
607 1.2.6.2 nathanw * the debugger via the serial port
608 1.2.6.2 nathanw */
609 1.2.6.2 nathanw if (byte == DDB_KEYCODE) Debugger();
610 1.2.6.2 nathanw #endif
611 1.2.6.2 nathanw if (tp && (tp->t_state & TS_ISOPEN))
612 1.2.6.2 nathanw if (sc->sc_rxpos < RX_BUFFER_SIZE) {
613 1.2.6.2 nathanw sc->sc_rxbuf[sc->sc_rxpos++] = byte;
614 1.2.6.2 nathanw if (!softint_scheduled) {
615 1.2.6.2 nathanw softint_scheduled = 1;
616 1.2.6.2 nathanw callout_reset(&sc->sc_softintr_ch,
617 1.2.6.2 nathanw 1, fcom_softintr, sc);
618 1.2.6.2 nathanw }
619 1.2.6.2 nathanw }
620 1.2.6.2 nathanw } while (1);
621 1.2.6.2 nathanw return(0);
622 1.2.6.2 nathanw }
623 1.2.6.2 nathanw
624 1.2.6.2 nathanw #if 0
625 1.2.6.2 nathanw void
626 1.2.6.2 nathanw fcom_iflush(sc)
627 1.2.6.2 nathanw struct fcom_softc *sc;
628 1.2.6.2 nathanw {
629 1.2.6.2 nathanw bus_space_tag_t iot = sc->sc_iot;
630 1.2.6.2 nathanw bus_space_handle_t ioh = sc->sc_ioh;
631 1.2.6.2 nathanw
632 1.2.6.2 nathanw /* flush any pending I/O */
633 1.2.6.2 nathanw while (!ISSET(bus_space_read_4(iot, ioh, UART_FLAGS), UART_RX_FULL))
634 1.2.6.2 nathanw (void) bus_space_read_4(iot, ioh, UART_DATA);
635 1.2.6.2 nathanw }
636 1.2.6.2 nathanw #endif
637 1.2.6.2 nathanw
638 1.2.6.2 nathanw /*
639 1.2.6.2 nathanw * Following are all routines needed for COM to act as console
640 1.2.6.2 nathanw */
641 1.2.6.2 nathanw
642 1.2.6.2 nathanw #if 0
643 1.2.6.2 nathanw void
644 1.2.6.2 nathanw fcomcnprobe(cp)
645 1.2.6.2 nathanw struct consdev *cp;
646 1.2.6.2 nathanw {
647 1.2.6.2 nathanw int major;
648 1.2.6.2 nathanw
649 1.2.6.2 nathanw /* Serial console is always present so no probe */
650 1.2.6.2 nathanw
651 1.2.6.2 nathanw /* locate the major number */
652 1.2.6.5 nathanw major = cdevsw_lookup_major(&fcom_cdevsw);
653 1.2.6.2 nathanw
654 1.2.6.2 nathanw /* initialize required fields */
655 1.2.6.2 nathanw cp->cn_dev = makedev(major, CONUNIT);
656 1.2.6.2 nathanw cp->cn_pri = CN_REMOTE; /* Force a serial port console */
657 1.2.6.2 nathanw }
658 1.2.6.2 nathanw
659 1.2.6.2 nathanw void
660 1.2.6.2 nathanw fcomcninit(cp)
661 1.2.6.2 nathanw struct consdev *cp;
662 1.2.6.2 nathanw {
663 1.2.6.2 nathanw fcomconstag = &fcomcons_bs_tag;
664 1.2.6.2 nathanw
665 1.2.6.2 nathanw if (bus_space_map(fcomconstag, DC21285_ARMCSR_BASE, DC21285_ARMCSR_SIZE, 0, &fcomconsioh))
666 1.2.6.2 nathanw panic("fcomcninit: mapping failed");
667 1.2.6.2 nathanw
668 1.2.6.2 nathanw fcominitcons(fcomconstag, fcomconsioh);
669 1.2.6.2 nathanw }
670 1.2.6.2 nathanw #endif
671 1.2.6.2 nathanw
672 1.2.6.2 nathanw int
673 1.2.6.2 nathanw fcomcnattach(iobase, rate, cflag)
674 1.2.6.2 nathanw u_int iobase;
675 1.2.6.2 nathanw int rate;
676 1.2.6.2 nathanw tcflag_t cflag;
677 1.2.6.2 nathanw {
678 1.2.6.2 nathanw static struct consdev fcomcons = {
679 1.2.6.2 nathanw NULL, NULL, fcomcngetc, fcomcnputc, fcomcnpollc, NULL,
680 1.2.6.2 nathanw NODEV, CN_NORMAL
681 1.2.6.2 nathanw };
682 1.2.6.2 nathanw
683 1.2.6.2 nathanw fcomconstag = &fcomcons_bs_tag;
684 1.2.6.2 nathanw
685 1.2.6.2 nathanw if (bus_space_map(fcomconstag, iobase, DC21285_ARMCSR_SIZE,
686 1.2.6.2 nathanw 0, &fcomconsioh))
687 1.2.6.2 nathanw panic("fcomcninit: mapping failed");
688 1.2.6.2 nathanw
689 1.2.6.2 nathanw fcominit(fcomconstag, fcomconsioh, rate, cflag);
690 1.2.6.2 nathanw
691 1.2.6.2 nathanw cn_tab = &fcomcons;
692 1.2.6.2 nathanw
693 1.2.6.2 nathanw /* comcnspeed = rate;
694 1.2.6.2 nathanw comcnmode = cflag;*/
695 1.2.6.2 nathanw return (0);
696 1.2.6.2 nathanw }
697 1.2.6.2 nathanw
698 1.2.6.2 nathanw int
699 1.2.6.2 nathanw fcomcndetach(void)
700 1.2.6.2 nathanw {
701 1.2.6.2 nathanw bus_space_unmap(fcomconstag, fcomconsioh, DC21285_ARMCSR_SIZE);
702 1.2.6.2 nathanw
703 1.2.6.2 nathanw cn_tab = NULL;
704 1.2.6.2 nathanw return (0);
705 1.2.6.2 nathanw }
706 1.2.6.2 nathanw
707 1.2.6.2 nathanw /*
708 1.2.6.2 nathanw * Initialize UART to known state.
709 1.2.6.2 nathanw */
710 1.2.6.2 nathanw void
711 1.2.6.2 nathanw fcominit(iot, ioh, rate, mode)
712 1.2.6.2 nathanw bus_space_tag_t iot;
713 1.2.6.2 nathanw bus_space_handle_t ioh;
714 1.2.6.2 nathanw int rate;
715 1.2.6.2 nathanw int mode;
716 1.2.6.2 nathanw {
717 1.2.6.2 nathanw int baudrate;
718 1.2.6.2 nathanw int h_ubrlcr;
719 1.2.6.2 nathanw int m_ubrlcr;
720 1.2.6.2 nathanw int l_ubrlcr;
721 1.2.6.2 nathanw
722 1.2.6.2 nathanw switch (rate) {
723 1.2.6.2 nathanw case B1200:
724 1.2.6.2 nathanw case B2400:
725 1.2.6.2 nathanw case B4800:
726 1.2.6.2 nathanw case B9600:
727 1.2.6.2 nathanw case B19200:
728 1.2.6.2 nathanw case B38400:
729 1.2.6.2 nathanw baudrate = UART_BRD(dc21285_fclk, rate);
730 1.2.6.2 nathanw break;
731 1.2.6.2 nathanw default:
732 1.2.6.2 nathanw baudrate = UART_BRD(dc21285_fclk, 9600);
733 1.2.6.2 nathanw break;
734 1.2.6.2 nathanw }
735 1.2.6.2 nathanw
736 1.2.6.2 nathanw h_ubrlcr = 0;
737 1.2.6.2 nathanw switch (mode & CSIZE) {
738 1.2.6.2 nathanw case CS5:
739 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_5;
740 1.2.6.2 nathanw break;
741 1.2.6.2 nathanw case CS6:
742 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_6;
743 1.2.6.2 nathanw break;
744 1.2.6.2 nathanw case CS7:
745 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_7;
746 1.2.6.2 nathanw break;
747 1.2.6.2 nathanw case CS8:
748 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_8;
749 1.2.6.2 nathanw break;
750 1.2.6.2 nathanw }
751 1.2.6.2 nathanw
752 1.2.6.2 nathanw if (mode & PARENB)
753 1.2.6.2 nathanw h_ubrlcr |= UART_PARITY_ENABLE;
754 1.2.6.2 nathanw if (mode & PARODD)
755 1.2.6.2 nathanw h_ubrlcr |= UART_ODD_PARITY;
756 1.2.6.2 nathanw else
757 1.2.6.2 nathanw h_ubrlcr |= UART_EVEN_PARITY;
758 1.2.6.2 nathanw
759 1.2.6.2 nathanw if (mode & CSTOPB)
760 1.2.6.2 nathanw h_ubrlcr |= UART_STOP_BITS_2;
761 1.2.6.2 nathanw
762 1.2.6.2 nathanw m_ubrlcr = (baudrate >> 8) & 0xf;
763 1.2.6.2 nathanw l_ubrlcr = baudrate & 0xff;
764 1.2.6.2 nathanw
765 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_L_UBRLCR, l_ubrlcr);
766 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_M_UBRLCR, m_ubrlcr);
767 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_H_UBRLCR, h_ubrlcr);
768 1.2.6.2 nathanw }
769 1.2.6.2 nathanw #if 0
770 1.2.6.2 nathanw /*
771 1.2.6.2 nathanw * Set UART for console use. Do normal init, then enable interrupts.
772 1.2.6.2 nathanw */
773 1.2.6.2 nathanw void
774 1.2.6.2 nathanw fcominitcons(iot, ioh)
775 1.2.6.2 nathanw bus_space_tag_t iot;
776 1.2.6.2 nathanw bus_space_handle_t ioh;
777 1.2.6.2 nathanw {
778 1.2.6.2 nathanw int s = splserial();
779 1.2.6.2 nathanw
780 1.2.6.2 nathanw fcominit(iot, ioh, comcnspeed, comcnmode);
781 1.2.6.2 nathanw
782 1.2.6.2 nathanw delay(10000);
783 1.2.6.2 nathanw
784 1.2.6.2 nathanw (void)splx(s);
785 1.2.6.2 nathanw }
786 1.2.6.2 nathanw #endif
787 1.2.6.2 nathanw
788 1.2.6.2 nathanw int
789 1.2.6.2 nathanw fcomcngetc(dev)
790 1.2.6.2 nathanw dev_t dev;
791 1.2.6.2 nathanw {
792 1.2.6.2 nathanw int s = splserial();
793 1.2.6.2 nathanw bus_space_tag_t iot = fcomconstag;
794 1.2.6.2 nathanw bus_space_handle_t ioh = fcomconsioh;
795 1.2.6.2 nathanw u_char stat, c;
796 1.2.6.2 nathanw
797 1.2.6.2 nathanw while ((bus_space_read_4(iot, ioh, UART_FLAGS) & UART_RX_FULL) != 0)
798 1.2.6.2 nathanw ;
799 1.2.6.2 nathanw c = bus_space_read_4(iot, ioh, UART_DATA);
800 1.2.6.2 nathanw stat = bus_space_read_4(iot, ioh, UART_RX_STAT);
801 1.2.6.2 nathanw (void)splx(s);
802 1.2.6.2 nathanw #if DDB_KEYCODE > 0
803 1.2.6.2 nathanw /*
804 1.2.6.2 nathanw * Temporary hack so that I can force the kernel into
805 1.2.6.2 nathanw * the debugger via the serial port
806 1.2.6.2 nathanw */
807 1.2.6.2 nathanw if (c == DDB_KEYCODE) Debugger();
808 1.2.6.2 nathanw #endif
809 1.2.6.2 nathanw
810 1.2.6.2 nathanw return (c);
811 1.2.6.2 nathanw }
812 1.2.6.2 nathanw
813 1.2.6.2 nathanw /*
814 1.2.6.2 nathanw * Console kernel output character routine.
815 1.2.6.2 nathanw */
816 1.2.6.2 nathanw void
817 1.2.6.2 nathanw fcomcnputc(dev, c)
818 1.2.6.2 nathanw dev_t dev;
819 1.2.6.2 nathanw int c;
820 1.2.6.2 nathanw {
821 1.2.6.2 nathanw int s = splserial();
822 1.2.6.2 nathanw bus_space_tag_t iot = fcomconstag;
823 1.2.6.2 nathanw bus_space_handle_t ioh = fcomconsioh;
824 1.2.6.2 nathanw int timo;
825 1.2.6.2 nathanw
826 1.2.6.2 nathanw /* wait for any pending transmission to finish */
827 1.2.6.2 nathanw timo = 50000;
828 1.2.6.2 nathanw while ((bus_space_read_4(iot, ioh, UART_FLAGS) & UART_TX_BUSY) && --timo)
829 1.2.6.2 nathanw ;
830 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_DATA, c);
831 1.2.6.2 nathanw
832 1.2.6.2 nathanw /* wait for this transmission to complete */
833 1.2.6.2 nathanw timo = 1500000;
834 1.2.6.2 nathanw while ((bus_space_read_4(iot, ioh, UART_FLAGS) & UART_TX_BUSY) && --timo)
835 1.2.6.2 nathanw ;
836 1.2.6.2 nathanw /* Clear interrupt status here */
837 1.2.6.2 nathanw (void)splx(s);
838 1.2.6.2 nathanw }
839 1.2.6.2 nathanw
840 1.2.6.2 nathanw void
841 1.2.6.2 nathanw fcomcnpollc(dev, on)
842 1.2.6.2 nathanw dev_t dev;
843 1.2.6.2 nathanw int on;
844 1.2.6.2 nathanw {
845 1.2.6.2 nathanw }
846