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