footbridge_com.c revision 1.2.6.2 1 1.2.6.2 nathanw /* $NetBSD: footbridge_com.c,v 1.2.6.2 2002/01/11 23:38:03 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/conf.h>
54 1.2.6.2 nathanw #include <arm/footbridge/dc21285mem.h>
55 1.2.6.2 nathanw #include <arm/footbridge/dc21285reg.h>
56 1.2.6.2 nathanw #include <arm/footbridge/footbridgevar.h>
57 1.2.6.2 nathanw #include <arm/footbridge/footbridge.h>
58 1.2.6.2 nathanw
59 1.2.6.2 nathanw #include <dev/cons.h>
60 1.2.6.2 nathanw
61 1.2.6.2 nathanw #include "fcom.h"
62 1.2.6.2 nathanw
63 1.2.6.2 nathanw extern u_int dc21285_fclk;
64 1.2.6.2 nathanw
65 1.2.6.2 nathanw
66 1.2.6.2 nathanw #ifdef DDB
67 1.2.6.2 nathanw /*
68 1.2.6.2 nathanw * Define the keycode recognised as a request to call the debugger
69 1.2.6.2 nathanw * A value of 0 disables the feature when DDB is built in
70 1.2.6.2 nathanw */
71 1.2.6.2 nathanw #ifndef DDB_KEYCODE
72 1.2.6.2 nathanw #define DDB_KEYCODE 0
73 1.2.6.2 nathanw #endif /* DDB_KEYCODE */
74 1.2.6.2 nathanw #endif /* DDB */
75 1.2.6.2 nathanw
76 1.2.6.2 nathanw struct fcom_softc {
77 1.2.6.2 nathanw struct device sc_dev;
78 1.2.6.2 nathanw bus_space_tag_t sc_iot;
79 1.2.6.2 nathanw bus_space_handle_t sc_ioh;
80 1.2.6.2 nathanw void *sc_ih;
81 1.2.6.2 nathanw struct callout sc_softintr_ch;
82 1.2.6.2 nathanw int sc_rx_irq;
83 1.2.6.2 nathanw int sc_tx_irq;
84 1.2.6.2 nathanw int sc_hwflags;
85 1.2.6.2 nathanw #define HW_FLAG_CONSOLE 0x01
86 1.2.6.2 nathanw int sc_swflags;
87 1.2.6.2 nathanw int sc_l_ubrlcr;
88 1.2.6.2 nathanw int sc_m_ubrlcr;
89 1.2.6.2 nathanw int sc_h_ubrlcr;
90 1.2.6.2 nathanw char *sc_rxbuffer[2];
91 1.2.6.2 nathanw char *sc_rxbuf;
92 1.2.6.2 nathanw int sc_rxpos;
93 1.2.6.2 nathanw int sc_rxcur;
94 1.2.6.2 nathanw struct tty *sc_tty;
95 1.2.6.2 nathanw };
96 1.2.6.2 nathanw
97 1.2.6.2 nathanw #define RX_BUFFER_SIZE 0x100
98 1.2.6.2 nathanw
99 1.2.6.2 nathanw /* Macros to clear/set/test flags. */
100 1.2.6.2 nathanw #define SET(t, f) (t) |= (f)
101 1.2.6.2 nathanw #define CLR(t, f) (t) &= ~(f)
102 1.2.6.2 nathanw #define ISSET(t, f) ((t) & (f))
103 1.2.6.2 nathanw
104 1.2.6.2 nathanw static int fcom_probe __P((struct device *, struct cfdata *, void *));
105 1.2.6.2 nathanw static void fcom_attach __P((struct device *, struct device *, void *));
106 1.2.6.2 nathanw static void fcom_softintr __P((void *));
107 1.2.6.2 nathanw
108 1.2.6.2 nathanw int fcomopen __P((dev_t dev, int flag, int mode, struct proc *p));
109 1.2.6.2 nathanw static int fcom_rxintr __P((void *));
110 1.2.6.2 nathanw /*static int fcom_txintr __P((void *));*/
111 1.2.6.2 nathanw
112 1.2.6.2 nathanw /*struct consdev;*/
113 1.2.6.2 nathanw /*void fcomcnprobe __P((struct consdev *));
114 1.2.6.2 nathanw void fcomcninit __P((struct consdev *));*/
115 1.2.6.2 nathanw int fcomcngetc __P((dev_t));
116 1.2.6.2 nathanw void fcomcnputc __P((dev_t, int));
117 1.2.6.2 nathanw void fcomcnpollc __P((dev_t, int));
118 1.2.6.2 nathanw
119 1.2.6.2 nathanw struct cfattach fcom_ca = {
120 1.2.6.2 nathanw sizeof(struct fcom_softc), fcom_probe, fcom_attach
121 1.2.6.2 nathanw };
122 1.2.6.2 nathanw
123 1.2.6.2 nathanw extern struct cfdriver fcom_cd;
124 1.2.6.2 nathanw
125 1.2.6.2 nathanw void fcominit __P((bus_space_tag_t, bus_space_handle_t, int, int));
126 1.2.6.2 nathanw void fcominitcons __P((bus_space_tag_t, bus_space_handle_t));
127 1.2.6.2 nathanw
128 1.2.6.2 nathanw bus_space_tag_t fcomconstag;
129 1.2.6.2 nathanw bus_space_handle_t fcomconsioh;
130 1.2.6.2 nathanw extern int comcnmode;
131 1.2.6.2 nathanw extern int comcnspeed;
132 1.2.6.2 nathanw
133 1.2.6.2 nathanw #define COMUNIT(x) (minor(x))
134 1.2.6.2 nathanw #ifndef CONUNIT
135 1.2.6.2 nathanw #define CONUNIT 0
136 1.2.6.2 nathanw #endif
137 1.2.6.2 nathanw
138 1.2.6.2 nathanw /*
139 1.2.6.2 nathanw * The console is set up at init time, well in advance of the reset of the
140 1.2.6.2 nathanw * system and thus we have a private bus space tag for the console.
141 1.2.6.2 nathanw *
142 1.2.6.2 nathanw * The tag is provided by fcom_io.c and fcom_io_asm.S
143 1.2.6.2 nathanw */
144 1.2.6.2 nathanw extern struct bus_space fcomcons_bs_tag;
145 1.2.6.2 nathanw
146 1.2.6.2 nathanw /*
147 1.2.6.2 nathanw * int fcom_probe(struct device *parent, struct cfdata *cf, void *aux)
148 1.2.6.2 nathanw *
149 1.2.6.2 nathanw * Make sure we are trying to attach a com device and then
150 1.2.6.2 nathanw * probe for one.
151 1.2.6.2 nathanw */
152 1.2.6.2 nathanw
153 1.2.6.2 nathanw static int
154 1.2.6.2 nathanw fcom_probe(parent, cf, aux)
155 1.2.6.2 nathanw struct device *parent;
156 1.2.6.2 nathanw struct cfdata *cf;
157 1.2.6.2 nathanw void *aux;
158 1.2.6.2 nathanw {
159 1.2.6.2 nathanw union footbridge_attach_args *fba = aux;
160 1.2.6.2 nathanw
161 1.2.6.2 nathanw if (strcmp(fba->fba_name, "fcom") == 0)
162 1.2.6.2 nathanw return(1);
163 1.2.6.2 nathanw return(0);
164 1.2.6.2 nathanw }
165 1.2.6.2 nathanw
166 1.2.6.2 nathanw /*
167 1.2.6.2 nathanw * void fcom_attach(struct device *parent, struct device *self, void *aux)
168 1.2.6.2 nathanw *
169 1.2.6.2 nathanw * attach the com device
170 1.2.6.2 nathanw */
171 1.2.6.2 nathanw
172 1.2.6.2 nathanw static void
173 1.2.6.2 nathanw fcom_attach(parent, self, aux)
174 1.2.6.2 nathanw struct device *parent, *self;
175 1.2.6.2 nathanw void *aux;
176 1.2.6.2 nathanw {
177 1.2.6.2 nathanw union footbridge_attach_args *fba = aux;
178 1.2.6.2 nathanw struct fcom_softc *sc = (struct fcom_softc *)self;
179 1.2.6.2 nathanw
180 1.2.6.2 nathanw /* Set up the softc */
181 1.2.6.2 nathanw sc->sc_iot = fba->fba_fca.fca_iot;
182 1.2.6.2 nathanw sc->sc_ioh = fba->fba_fca.fca_ioh;
183 1.2.6.2 nathanw callout_init(&sc->sc_softintr_ch);
184 1.2.6.2 nathanw sc->sc_rx_irq = fba->fba_fca.fca_rx_irq;
185 1.2.6.2 nathanw sc->sc_tx_irq = fba->fba_fca.fca_tx_irq;
186 1.2.6.2 nathanw sc->sc_hwflags = 0;
187 1.2.6.2 nathanw sc->sc_swflags = 0;
188 1.2.6.2 nathanw
189 1.2.6.2 nathanw /* If we have a console tag then make a note of it */
190 1.2.6.2 nathanw if (fcomconstag)
191 1.2.6.2 nathanw sc->sc_hwflags |= HW_FLAG_CONSOLE;
192 1.2.6.2 nathanw
193 1.2.6.2 nathanw if (sc->sc_hwflags & HW_FLAG_CONSOLE) {
194 1.2.6.2 nathanw int major;
195 1.2.6.2 nathanw
196 1.2.6.2 nathanw /* locate the major number */
197 1.2.6.2 nathanw for (major = 0; major < nchrdev; ++major)
198 1.2.6.2 nathanw if (cdevsw[major].d_open == fcomopen)
199 1.2.6.2 nathanw break;
200 1.2.6.2 nathanw
201 1.2.6.2 nathanw cn_tab->cn_dev = makedev(major, sc->sc_dev.dv_unit);
202 1.2.6.2 nathanw printf(": console");
203 1.2.6.2 nathanw }
204 1.2.6.2 nathanw printf("\n");
205 1.2.6.2 nathanw
206 1.2.6.2 nathanw sc->sc_ih = intr_claim(sc->sc_rx_irq, IPL_SERIAL, "serial rx",
207 1.2.6.2 nathanw fcom_rxintr, sc);
208 1.2.6.2 nathanw if (sc->sc_ih == NULL)
209 1.2.6.2 nathanw panic("%s: Cannot install rx interrupt handler\n",
210 1.2.6.2 nathanw sc->sc_dev.dv_xname);
211 1.2.6.2 nathanw }
212 1.2.6.2 nathanw
213 1.2.6.2 nathanw static void fcomstart __P((struct tty *));
214 1.2.6.2 nathanw static int fcomparam __P((struct tty *, struct termios *));
215 1.2.6.2 nathanw
216 1.2.6.2 nathanw int
217 1.2.6.2 nathanw fcomopen(dev, flag, mode, p)
218 1.2.6.2 nathanw dev_t dev;
219 1.2.6.2 nathanw int flag, mode;
220 1.2.6.2 nathanw struct proc *p;
221 1.2.6.2 nathanw {
222 1.2.6.2 nathanw struct fcom_softc *sc;
223 1.2.6.2 nathanw int unit = minor(dev);
224 1.2.6.2 nathanw struct tty *tp;
225 1.2.6.2 nathanw
226 1.2.6.2 nathanw if (unit >= fcom_cd.cd_ndevs)
227 1.2.6.2 nathanw return ENXIO;
228 1.2.6.2 nathanw sc = fcom_cd.cd_devs[unit];
229 1.2.6.2 nathanw if (!sc)
230 1.2.6.2 nathanw return ENXIO;
231 1.2.6.2 nathanw if (!(tp = sc->sc_tty))
232 1.2.6.2 nathanw sc->sc_tty = tp = ttymalloc();
233 1.2.6.2 nathanw if (!sc->sc_rxbuffer[0]) {
234 1.2.6.2 nathanw sc->sc_rxbuffer[0] = malloc(RX_BUFFER_SIZE, M_DEVBUF, M_WAITOK);
235 1.2.6.2 nathanw sc->sc_rxbuffer[1] = malloc(RX_BUFFER_SIZE, M_DEVBUF, M_WAITOK);
236 1.2.6.2 nathanw sc->sc_rxpos = 0;
237 1.2.6.2 nathanw sc->sc_rxcur = 0;
238 1.2.6.2 nathanw sc->sc_rxbuf = sc->sc_rxbuffer[sc->sc_rxcur];
239 1.2.6.2 nathanw if (!sc->sc_rxbuf)
240 1.2.6.2 nathanw panic("%s: Cannot allocate rx buffer memory",
241 1.2.6.2 nathanw sc->sc_dev.dv_xname);
242 1.2.6.2 nathanw }
243 1.2.6.2 nathanw tp->t_oproc = fcomstart;
244 1.2.6.2 nathanw tp->t_param = fcomparam;
245 1.2.6.2 nathanw tp->t_dev = dev;
246 1.2.6.2 nathanw if (!(tp->t_state & TS_ISOPEN && tp->t_wopen == 0)) {
247 1.2.6.2 nathanw ttychars(tp);
248 1.2.6.2 nathanw tp->t_cflag = TTYDEF_CFLAG;
249 1.2.6.2 nathanw tp->t_iflag = TTYDEF_IFLAG;
250 1.2.6.2 nathanw tp->t_oflag = TTYDEF_OFLAG;
251 1.2.6.2 nathanw tp->t_lflag = TTYDEF_LFLAG;
252 1.2.6.2 nathanw
253 1.2.6.2 nathanw /*
254 1.2.6.2 nathanw * Initialize the termios status to the defaults. Add in the
255 1.2.6.2 nathanw * sticky bits from TIOCSFLAGS.
256 1.2.6.2 nathanw */
257 1.2.6.2 nathanw tp->t_ispeed = 0;
258 1.2.6.2 nathanw if (ISSET(sc->sc_hwflags, HW_FLAG_CONSOLE))
259 1.2.6.2 nathanw tp->t_ospeed = comcnspeed;
260 1.2.6.2 nathanw else
261 1.2.6.2 nathanw tp->t_ospeed = TTYDEF_SPEED;
262 1.2.6.2 nathanw
263 1.2.6.2 nathanw fcomparam(tp, &tp->t_termios);
264 1.2.6.2 nathanw ttsetwater(tp);
265 1.2.6.2 nathanw } else if ((tp->t_state&TS_XCLUDE) && suser(p->p_ucred, &p->p_acflag))
266 1.2.6.2 nathanw return EBUSY;
267 1.2.6.2 nathanw tp->t_state |= TS_CARR_ON;
268 1.2.6.2 nathanw
269 1.2.6.2 nathanw return (*tp->t_linesw->l_open)(dev, tp);
270 1.2.6.2 nathanw }
271 1.2.6.2 nathanw
272 1.2.6.2 nathanw int
273 1.2.6.2 nathanw fcomclose(dev, flag, mode, p)
274 1.2.6.2 nathanw dev_t dev;
275 1.2.6.2 nathanw int flag, mode;
276 1.2.6.2 nathanw struct proc *p;
277 1.2.6.2 nathanw {
278 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
279 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
280 1.2.6.2 nathanw /* XXX This is for cons.c. */
281 1.2.6.2 nathanw if (!ISSET(tp->t_state, TS_ISOPEN))
282 1.2.6.2 nathanw return (0);
283 1.2.6.2 nathanw
284 1.2.6.2 nathanw (*tp->t_linesw->l_close)(tp, flag);
285 1.2.6.2 nathanw ttyclose(tp);
286 1.2.6.2 nathanw #ifdef DIAGNOSTIC
287 1.2.6.2 nathanw if (sc->sc_rxbuffer[0] == NULL)
288 1.2.6.2 nathanw panic("fcomclose: rx buffers not allocated\n");
289 1.2.6.2 nathanw #endif /* DIAGNOSTIC */
290 1.2.6.2 nathanw free(sc->sc_rxbuffer[0], M_DEVBUF);
291 1.2.6.2 nathanw free(sc->sc_rxbuffer[1], M_DEVBUF);
292 1.2.6.2 nathanw sc->sc_rxbuffer[0] = NULL;
293 1.2.6.2 nathanw sc->sc_rxbuffer[1] = NULL;
294 1.2.6.2 nathanw
295 1.2.6.2 nathanw return 0;
296 1.2.6.2 nathanw }
297 1.2.6.2 nathanw
298 1.2.6.2 nathanw int
299 1.2.6.2 nathanw fcomread(dev, uio, flag)
300 1.2.6.2 nathanw dev_t dev;
301 1.2.6.2 nathanw struct uio *uio;
302 1.2.6.2 nathanw int flag;
303 1.2.6.2 nathanw {
304 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
305 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
306 1.2.6.2 nathanw
307 1.2.6.2 nathanw return (*tp->t_linesw->l_read)(tp, uio, flag);
308 1.2.6.2 nathanw }
309 1.2.6.2 nathanw
310 1.2.6.2 nathanw int
311 1.2.6.2 nathanw fcomwrite(dev, uio, flag)
312 1.2.6.2 nathanw dev_t dev;
313 1.2.6.2 nathanw struct uio *uio;
314 1.2.6.2 nathanw int flag;
315 1.2.6.2 nathanw {
316 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
317 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
318 1.2.6.2 nathanw
319 1.2.6.2 nathanw return (*tp->t_linesw->l_write)(tp, uio, flag);
320 1.2.6.2 nathanw }
321 1.2.6.2 nathanw
322 1.2.6.2 nathanw int
323 1.2.6.2 nathanw fcompoll(dev, events, p)
324 1.2.6.2 nathanw dev_t dev;
325 1.2.6.2 nathanw int events;
326 1.2.6.2 nathanw struct proc *p;
327 1.2.6.2 nathanw {
328 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
329 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
330 1.2.6.2 nathanw
331 1.2.6.2 nathanw return ((*tp->t_linesw->l_poll)(tp, events, p));
332 1.2.6.2 nathanw }
333 1.2.6.2 nathanw
334 1.2.6.2 nathanw int
335 1.2.6.2 nathanw fcomioctl(dev, cmd, data, flag, p)
336 1.2.6.2 nathanw dev_t dev;
337 1.2.6.2 nathanw u_long cmd;
338 1.2.6.2 nathanw caddr_t data;
339 1.2.6.2 nathanw int flag;
340 1.2.6.2 nathanw struct proc *p;
341 1.2.6.2 nathanw {
342 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
343 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
344 1.2.6.2 nathanw int error;
345 1.2.6.2 nathanw
346 1.2.6.2 nathanw if ((error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p)) >= 0)
347 1.2.6.2 nathanw return error;
348 1.2.6.2 nathanw if ((error = ttioctl(tp, cmd, data, flag, p)) >= 0)
349 1.2.6.2 nathanw return error;
350 1.2.6.2 nathanw
351 1.2.6.2 nathanw switch (cmd) {
352 1.2.6.2 nathanw case TIOCGFLAGS:
353 1.2.6.2 nathanw *(int *)data = sc->sc_swflags;
354 1.2.6.2 nathanw break;
355 1.2.6.2 nathanw
356 1.2.6.2 nathanw case TIOCSFLAGS:
357 1.2.6.2 nathanw error = suser(p->p_ucred, &p->p_acflag);
358 1.2.6.2 nathanw if (error)
359 1.2.6.2 nathanw return (error);
360 1.2.6.2 nathanw sc->sc_swflags = *(int *)data;
361 1.2.6.2 nathanw break;
362 1.2.6.2 nathanw }
363 1.2.6.2 nathanw
364 1.2.6.2 nathanw return ENOTTY;
365 1.2.6.2 nathanw }
366 1.2.6.2 nathanw
367 1.2.6.2 nathanw struct tty *
368 1.2.6.2 nathanw fcomtty(dev)
369 1.2.6.2 nathanw dev_t dev;
370 1.2.6.2 nathanw {
371 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(dev)];
372 1.2.6.2 nathanw
373 1.2.6.2 nathanw return sc->sc_tty;
374 1.2.6.2 nathanw }
375 1.2.6.2 nathanw
376 1.2.6.2 nathanw void
377 1.2.6.2 nathanw fcomstop(tp, flag)
378 1.2.6.2 nathanw struct tty *tp;
379 1.2.6.2 nathanw int flag;
380 1.2.6.2 nathanw {
381 1.2.6.2 nathanw }
382 1.2.6.2 nathanw
383 1.2.6.2 nathanw static void
384 1.2.6.2 nathanw fcomstart(tp)
385 1.2.6.2 nathanw struct tty *tp;
386 1.2.6.2 nathanw {
387 1.2.6.2 nathanw struct clist *cl;
388 1.2.6.2 nathanw int s, len;
389 1.2.6.2 nathanw u_char buf[64];
390 1.2.6.2 nathanw int loop;
391 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(tp->t_dev)];
392 1.2.6.2 nathanw bus_space_tag_t iot = sc->sc_iot;
393 1.2.6.2 nathanw bus_space_handle_t ioh = sc->sc_ioh;
394 1.2.6.2 nathanw int timo;
395 1.2.6.2 nathanw
396 1.2.6.2 nathanw s = spltty();
397 1.2.6.2 nathanw if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
398 1.2.6.2 nathanw (void)splx(s);
399 1.2.6.2 nathanw return;
400 1.2.6.2 nathanw }
401 1.2.6.2 nathanw tp->t_state |= TS_BUSY;
402 1.2.6.2 nathanw (void)splx(s);
403 1.2.6.2 nathanw
404 1.2.6.2 nathanw /* s = splserial();*/
405 1.2.6.2 nathanw /* wait for any pending transmission to finish */
406 1.2.6.2 nathanw timo = 100000;
407 1.2.6.2 nathanw while ((bus_space_read_4(iot, ioh, UART_FLAGS) & UART_TX_BUSY) && --timo)
408 1.2.6.2 nathanw ;
409 1.2.6.2 nathanw
410 1.2.6.2 nathanw s = splserial();
411 1.2.6.2 nathanw if (bus_space_read_4(iot, ioh, UART_FLAGS) & UART_TX_BUSY) {
412 1.2.6.2 nathanw tp->t_state |= TS_TIMEOUT;
413 1.2.6.2 nathanw callout_reset(&tp->t_rstrt_ch, 1, ttrstrt, tp);
414 1.2.6.2 nathanw (void)splx(s);
415 1.2.6.2 nathanw return;
416 1.2.6.2 nathanw }
417 1.2.6.2 nathanw
418 1.2.6.2 nathanw (void)splx(s);
419 1.2.6.2 nathanw
420 1.2.6.2 nathanw cl = &tp->t_outq;
421 1.2.6.2 nathanw len = q_to_b(cl, buf, 64);
422 1.2.6.2 nathanw for (loop = 0; loop < len; ++loop) {
423 1.2.6.2 nathanw /* s = splserial();*/
424 1.2.6.2 nathanw
425 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_DATA, buf[loop]);
426 1.2.6.2 nathanw
427 1.2.6.2 nathanw /* wait for this transmission to complete */
428 1.2.6.2 nathanw timo = 100000;
429 1.2.6.2 nathanw while ((bus_space_read_4(iot, ioh, UART_FLAGS) & UART_TX_BUSY) && --timo)
430 1.2.6.2 nathanw ;
431 1.2.6.2 nathanw /* (void)splx(s);*/
432 1.2.6.2 nathanw }
433 1.2.6.2 nathanw s = spltty();
434 1.2.6.2 nathanw tp->t_state &= ~TS_BUSY;
435 1.2.6.2 nathanw if (cl->c_cc) {
436 1.2.6.2 nathanw tp->t_state |= TS_TIMEOUT;
437 1.2.6.2 nathanw callout_reset(&tp->t_rstrt_ch, 1, ttrstrt, tp);
438 1.2.6.2 nathanw }
439 1.2.6.2 nathanw if (cl->c_cc <= tp->t_lowat) {
440 1.2.6.2 nathanw if (tp->t_state & TS_ASLEEP) {
441 1.2.6.2 nathanw tp->t_state &= ~TS_ASLEEP;
442 1.2.6.2 nathanw wakeup(cl);
443 1.2.6.2 nathanw }
444 1.2.6.2 nathanw selwakeup(&tp->t_wsel);
445 1.2.6.2 nathanw }
446 1.2.6.2 nathanw (void)splx(s);
447 1.2.6.2 nathanw }
448 1.2.6.2 nathanw
449 1.2.6.2 nathanw static int
450 1.2.6.2 nathanw fcomparam(tp, t)
451 1.2.6.2 nathanw struct tty *tp;
452 1.2.6.2 nathanw struct termios *t;
453 1.2.6.2 nathanw {
454 1.2.6.2 nathanw struct fcom_softc *sc = fcom_cd.cd_devs[minor(tp->t_dev)];
455 1.2.6.2 nathanw bus_space_tag_t iot = sc->sc_iot;
456 1.2.6.2 nathanw bus_space_handle_t ioh = sc->sc_ioh;
457 1.2.6.2 nathanw int baudrate;
458 1.2.6.2 nathanw int h_ubrlcr;
459 1.2.6.2 nathanw int m_ubrlcr;
460 1.2.6.2 nathanw int l_ubrlcr;
461 1.2.6.2 nathanw int s;
462 1.2.6.2 nathanw
463 1.2.6.2 nathanw /* check requested parameters */
464 1.2.6.2 nathanw if (t->c_ospeed < 0)
465 1.2.6.2 nathanw return (EINVAL);
466 1.2.6.2 nathanw if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
467 1.2.6.2 nathanw return (EINVAL);
468 1.2.6.2 nathanw
469 1.2.6.2 nathanw switch (t->c_ospeed) {
470 1.2.6.2 nathanw case B1200:
471 1.2.6.2 nathanw case B2400:
472 1.2.6.2 nathanw case B4800:
473 1.2.6.2 nathanw case B9600:
474 1.2.6.2 nathanw case B19200:
475 1.2.6.2 nathanw case B38400:
476 1.2.6.2 nathanw baudrate = UART_BRD(dc21285_fclk, t->c_ospeed);
477 1.2.6.2 nathanw break;
478 1.2.6.2 nathanw default:
479 1.2.6.2 nathanw baudrate = UART_BRD(dc21285_fclk, 9600);
480 1.2.6.2 nathanw break;
481 1.2.6.2 nathanw }
482 1.2.6.2 nathanw
483 1.2.6.2 nathanw l_ubrlcr = baudrate & 0xff;
484 1.2.6.2 nathanw m_ubrlcr = (baudrate >> 8) & 0xf;
485 1.2.6.2 nathanw h_ubrlcr = 0;
486 1.2.6.2 nathanw
487 1.2.6.2 nathanw switch (ISSET(t->c_cflag, CSIZE)) {
488 1.2.6.2 nathanw case CS5:
489 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_5;
490 1.2.6.2 nathanw break;
491 1.2.6.2 nathanw case CS6:
492 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_6;
493 1.2.6.2 nathanw break;
494 1.2.6.2 nathanw case CS7:
495 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_7;
496 1.2.6.2 nathanw break;
497 1.2.6.2 nathanw case CS8:
498 1.2.6.2 nathanw h_ubrlcr |= UART_DATA_BITS_8;
499 1.2.6.2 nathanw break;
500 1.2.6.2 nathanw }
501 1.2.6.2 nathanw
502 1.2.6.2 nathanw if (ISSET(t->c_cflag, PARENB)) {
503 1.2.6.2 nathanw h_ubrlcr |= UART_PARITY_ENABLE;
504 1.2.6.2 nathanw if (ISSET(t->c_cflag, PARODD))
505 1.2.6.2 nathanw h_ubrlcr |= UART_ODD_PARITY;
506 1.2.6.2 nathanw else
507 1.2.6.2 nathanw h_ubrlcr |= UART_EVEN_PARITY;
508 1.2.6.2 nathanw }
509 1.2.6.2 nathanw
510 1.2.6.2 nathanw if (ISSET(t->c_cflag, CSTOPB))
511 1.2.6.2 nathanw h_ubrlcr |= UART_STOP_BITS_2;
512 1.2.6.2 nathanw
513 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_L_UBRLCR, l_ubrlcr);
514 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_M_UBRLCR, m_ubrlcr);
515 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_H_UBRLCR, h_ubrlcr);
516 1.2.6.2 nathanw
517 1.2.6.2 nathanw s = splserial();
518 1.2.6.2 nathanw
519 1.2.6.2 nathanw sc->sc_l_ubrlcr = l_ubrlcr;
520 1.2.6.2 nathanw sc->sc_m_ubrlcr = m_ubrlcr;
521 1.2.6.2 nathanw sc->sc_h_ubrlcr = h_ubrlcr;
522 1.2.6.2 nathanw
523 1.2.6.2 nathanw /*
524 1.2.6.2 nathanw * For the console, always force CLOCAL and !HUPCL, so that the port
525 1.2.6.2 nathanw * is always active.
526 1.2.6.2 nathanw */
527 1.2.6.2 nathanw if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
528 1.2.6.2 nathanw ISSET(sc->sc_hwflags, HW_FLAG_CONSOLE)) {
529 1.2.6.2 nathanw SET(t->c_cflag, CLOCAL);
530 1.2.6.2 nathanw CLR(t->c_cflag, HUPCL);
531 1.2.6.2 nathanw }
532 1.2.6.2 nathanw
533 1.2.6.2 nathanw /* and copy to tty */
534 1.2.6.2 nathanw tp->t_ispeed = 0;
535 1.2.6.2 nathanw tp->t_ospeed = t->c_ospeed;
536 1.2.6.2 nathanw tp->t_cflag = t->c_cflag;
537 1.2.6.2 nathanw
538 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_L_UBRLCR, l_ubrlcr);
539 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_M_UBRLCR, m_ubrlcr);
540 1.2.6.2 nathanw bus_space_write_4(iot, ioh, UART_H_UBRLCR, h_ubrlcr);
541 1.2.6.2 nathanw
542 1.2.6.2 nathanw (void)splx(s);
543 1.2.6.2 nathanw
544 1.2.6.2 nathanw return (0);
545 1.2.6.2 nathanw }
546 1.2.6.2 nathanw
547 1.2.6.2 nathanw static int softint_scheduled = 0;
548 1.2.6.2 nathanw
549 1.2.6.2 nathanw static void
550 1.2.6.2 nathanw fcom_softintr(arg)
551 1.2.6.2 nathanw void *arg;
552 1.2.6.2 nathanw {
553 1.2.6.2 nathanw struct fcom_softc *sc = arg;
554 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
555 1.2.6.2 nathanw int s;
556 1.2.6.2 nathanw int loop;
557 1.2.6.2 nathanw int len;
558 1.2.6.2 nathanw char *ptr;
559 1.2.6.2 nathanw
560 1.2.6.2 nathanw s = spltty();
561 1.2.6.2 nathanw ptr = sc->sc_rxbuf;
562 1.2.6.2 nathanw len = sc->sc_rxpos;
563 1.2.6.2 nathanw sc->sc_rxcur ^= 1;
564 1.2.6.2 nathanw sc->sc_rxbuf = sc->sc_rxbuffer[sc->sc_rxcur];
565 1.2.6.2 nathanw sc->sc_rxpos = 0;
566 1.2.6.2 nathanw (void)splx(s);
567 1.2.6.2 nathanw
568 1.2.6.2 nathanw for (loop = 0; loop < len; ++loop)
569 1.2.6.2 nathanw (*tp->t_linesw->l_rint)(ptr[loop], tp);
570 1.2.6.2 nathanw softint_scheduled = 0;
571 1.2.6.2 nathanw }
572 1.2.6.2 nathanw
573 1.2.6.2 nathanw #if 0
574 1.2.6.2 nathanw static int
575 1.2.6.2 nathanw fcom_txintr(arg)
576 1.2.6.2 nathanw void *arg;
577 1.2.6.2 nathanw {
578 1.2.6.2 nathanw /* struct fcom_softc *sc = arg;*/
579 1.2.6.2 nathanw
580 1.2.6.2 nathanw printf("fcom_txintr()\n");
581 1.2.6.2 nathanw return(0);
582 1.2.6.2 nathanw }
583 1.2.6.2 nathanw #endif
584 1.2.6.2 nathanw
585 1.2.6.2 nathanw static int
586 1.2.6.2 nathanw fcom_rxintr(arg)
587 1.2.6.2 nathanw void *arg;
588 1.2.6.2 nathanw {
589 1.2.6.2 nathanw struct fcom_softc *sc = arg;
590 1.2.6.2 nathanw bus_space_tag_t iot = sc->sc_iot;
591 1.2.6.2 nathanw bus_space_handle_t ioh = sc->sc_ioh;
592 1.2.6.2 nathanw struct tty *tp = sc->sc_tty;
593 1.2.6.2 nathanw int status;
594 1.2.6.2 nathanw int byte;
595 1.2.6.2 nathanw
596 1.2.6.2 nathanw do {
597 1.2.6.2 nathanw status = bus_space_read_4(iot, ioh, UART_FLAGS);
598 1.2.6.2 nathanw if ((status & UART_RX_FULL))
599 1.2.6.2 nathanw break;
600 1.2.6.2 nathanw byte = bus_space_read_4(iot, ioh, UART_DATA);
601 1.2.6.2 nathanw status = bus_space_read_4(iot, ioh, UART_RX_STAT);
602 1.2.6.2 nathanw #if DDB_KEYCODE > 0
603 1.2.6.2 nathanw /*
604 1.2.6.2 nathanw * Temporary hack so that I can force the kernel into
605 1.2.6.2 nathanw * the debugger via the serial port
606 1.2.6.2 nathanw */
607 1.2.6.2 nathanw if (byte == DDB_KEYCODE) Debugger();
608 1.2.6.2 nathanw #endif
609 1.2.6.2 nathanw if (tp && (tp->t_state & TS_ISOPEN))
610 1.2.6.2 nathanw if (sc->sc_rxpos < RX_BUFFER_SIZE) {
611 1.2.6.2 nathanw sc->sc_rxbuf[sc->sc_rxpos++] = byte;
612 1.2.6.2 nathanw if (!softint_scheduled) {
613 1.2.6.2 nathanw softint_scheduled = 1;
614 1.2.6.2 nathanw callout_reset(&sc->sc_softintr_ch,
615 1.2.6.2 nathanw 1, fcom_softintr, sc);
616 1.2.6.2 nathanw }
617 1.2.6.2 nathanw }
618 1.2.6.2 nathanw } while (1);
619 1.2.6.2 nathanw return(0);
620 1.2.6.2 nathanw }
621 1.2.6.2 nathanw
622 1.2.6.2 nathanw #if 0
623 1.2.6.2 nathanw void
624 1.2.6.2 nathanw fcom_iflush(sc)
625 1.2.6.2 nathanw struct fcom_softc *sc;
626 1.2.6.2 nathanw {
627 1.2.6.2 nathanw bus_space_tag_t iot = sc->sc_iot;
628 1.2.6.2 nathanw bus_space_handle_t ioh = sc->sc_ioh;
629 1.2.6.2 nathanw
630 1.2.6.2 nathanw /* flush any pending I/O */
631 1.2.6.2 nathanw while (!ISSET(bus_space_read_4(iot, ioh, UART_FLAGS), UART_RX_FULL))
632 1.2.6.2 nathanw (void) bus_space_read_4(iot, ioh, UART_DATA);
633 1.2.6.2 nathanw }
634 1.2.6.2 nathanw #endif
635 1.2.6.2 nathanw
636 1.2.6.2 nathanw /*
637 1.2.6.2 nathanw * Following are all routines needed for COM to act as console
638 1.2.6.2 nathanw */
639 1.2.6.2 nathanw
640 1.2.6.2 nathanw #if 0
641 1.2.6.2 nathanw void
642 1.2.6.2 nathanw fcomcnprobe(cp)
643 1.2.6.2 nathanw struct consdev *cp;
644 1.2.6.2 nathanw {
645 1.2.6.2 nathanw int major;
646 1.2.6.2 nathanw
647 1.2.6.2 nathanw /* Serial console is always present so no probe */
648 1.2.6.2 nathanw
649 1.2.6.2 nathanw /* locate the major number */
650 1.2.6.2 nathanw for (major = 0; major < nchrdev; major++)
651 1.2.6.2 nathanw if (cdevsw[major].d_open == fcomopen)
652 1.2.6.2 nathanw break;
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