sab.c revision 1.33 1 /* $NetBSD: sab.c,v 1.33 2006/10/01 17:31:47 martin Exp $ */
2 /* $OpenBSD: sab.c,v 1.7 2002/04/08 17:49:42 jason Exp $ */
3
4 /*
5 * Copyright (c) 2001 Jason L. Wright (jason (at) thought.net)
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Jason L. Wright
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 * Effort sponsored in part by the Defense Advanced Research Projects
35 * Agency (DARPA) and Air Force Research Laboratory, Air Force
36 * Materiel Command, USAF, under agreement number F30602-01-2-0537.
37 *
38 */
39
40 /*
41 * SAB82532 Dual UART driver
42 */
43
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: sab.c,v 1.33 2006/10/01 17:31:47 martin Exp $");
46
47 #include <sys/types.h>
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/device.h>
51 #include <sys/conf.h>
52 #include <sys/file.h>
53 #include <sys/ioctl.h>
54 #include <sys/kernel.h>
55 #include <sys/proc.h>
56 #include <sys/tty.h>
57 #include <sys/syslog.h>
58 #include <sys/kauth.h>
59
60 #include <machine/autoconf.h>
61 #include <machine/openfirm.h>
62
63 #include <dev/cons.h>
64
65 #include <dev/ebus/ebusreg.h>
66 #include <dev/ebus/ebusvar.h>
67 #include <sparc64/dev/sab82532reg.h>
68
69 #include "locators.h"
70
71 #define SABUNIT(x) (minor(x) & 0x7ffff)
72 #define SABDIALOUT(x) (minor(x) & 0x80000)
73
74 #define SABTTY_RBUF_SIZE 1024 /* must be divisible by 2 */
75
76 struct sab_softc {
77 struct device sc_dv;
78 struct intrhand * sc_ih;
79 bus_space_tag_t sc_bt;
80 bus_space_handle_t sc_bh;
81 struct sabtty_softc * sc_child[SAB_NCHAN];
82 u_int sc_nchild;
83 void * sc_softintr;
84 int sc_node;
85 };
86
87 struct sabtty_attach_args {
88 u_int sbt_portno;
89 };
90
91 struct sabtty_softc {
92 struct device sc_dv;
93 struct sab_softc * sc_parent;
94 bus_space_tag_t sc_bt;
95 bus_space_handle_t sc_bh;
96 struct tty * sc_tty;
97 u_int sc_portno;
98 uint8_t sc_pvr_dtr, sc_pvr_dsr;
99 uint8_t sc_imr0, sc_imr1;
100 int sc_openflags;
101 u_char * sc_txp;
102 int sc_txc;
103 int sc_flags;
104 #define SABTTYF_STOP 0x01
105 #define SABTTYF_DONE 0x02
106 #define SABTTYF_RINGOVERFLOW 0x04
107 #define SABTTYF_CDCHG 0x08
108 #define SABTTYF_CONS_IN 0x10
109 #define SABTTYF_CONS_OUT 0x20
110 #define SABTTYF_TXDRAIN 0x40
111 #define SABTTYF_DONTDDB 0x80
112 uint8_t sc_rbuf[SABTTY_RBUF_SIZE];
113 uint8_t *sc_rend, *sc_rput, *sc_rget;
114 uint8_t sc_polling, sc_pollrfc;
115 };
116
117 struct sabtty_softc *sabtty_cons_input;
118 struct sabtty_softc *sabtty_cons_output;
119
120 #define SAB_READ(sc,r) \
121 bus_space_read_1((sc)->sc_bt, (sc)->sc_bh, (r))
122 #define SAB_WRITE(sc,r,v) \
123 bus_space_write_1((sc)->sc_bt, (sc)->sc_bh, (r), (v))
124 #define SAB_WRITE_BLOCK(sc,r,p,c) \
125 bus_space_write_region_1((sc)->sc_bt, (sc)->sc_bh, (r), (p), (c))
126
127 int sab_match(struct device *, struct cfdata *, void *);
128 void sab_attach(struct device *, struct device *, void *);
129 int sab_print(void *, const char *);
130 int sab_intr(void *);
131
132 void sab_softintr(void *);
133 void sab_cnputc(dev_t, int);
134 int sab_cngetc(dev_t);
135 void sab_cnpollc(dev_t, int);
136
137 int sabtty_match(struct device *, struct cfdata *, void *);
138 void sabtty_attach(struct device *, struct device *, void *);
139 void sabtty_start(struct tty *);
140 int sabtty_param(struct tty *, struct termios *);
141 int sabtty_intr(struct sabtty_softc *, int *);
142 void sabtty_softintr(struct sabtty_softc *);
143 int sabtty_mdmctrl(struct sabtty_softc *, int, int);
144 void sabtty_cec_wait(struct sabtty_softc *);
145 void sabtty_tec_wait(struct sabtty_softc *);
146 void sabtty_reset(struct sabtty_softc *);
147 void sabtty_flush(struct sabtty_softc *);
148 int sabtty_speed(int);
149 void sabtty_console_flags(struct sabtty_softc *);
150 void sabtty_cnpollc(struct sabtty_softc *, int);
151 void sabtty_shutdown(void *);
152 int sabttyparam(struct sabtty_softc *, struct tty *, struct termios *);
153
154 void sabtty_cnputc(struct sabtty_softc *, int);
155 int sabtty_cngetc(struct sabtty_softc *);
156
157 CFATTACH_DECL(sab, sizeof(struct sab_softc),
158 sab_match, sab_attach, NULL, NULL);
159
160 extern struct cfdriver sab_cd;
161
162 CFATTACH_DECL(sabtty, sizeof(struct sabtty_softc),
163 sabtty_match, sabtty_attach, NULL, NULL);
164
165 extern struct cfdriver sabtty_cd;
166
167 dev_type_open(sabopen);
168 dev_type_close(sabclose);
169 dev_type_read(sabread);
170 dev_type_write(sabwrite);
171 dev_type_ioctl(sabioctl);
172 dev_type_stop(sabstop);
173 dev_type_tty(sabtty);
174 dev_type_poll(sabpoll);
175
176 static struct cnm_state sabtty_cnm_state;
177
178 const struct cdevsw sabtty_cdevsw = {
179 sabopen, sabclose, sabread, sabwrite, sabioctl,
180 sabstop, sabtty, sabpoll, nommap, ttykqfilter, D_TTY
181 };
182
183 struct sabtty_rate {
184 int baud;
185 int n, m;
186 };
187
188 struct sabtty_rate sabtty_baudtable[] = {
189 { 50, 35, 10 },
190 { 75, 47, 9 },
191 { 110, 32, 9 },
192 { 134, 53, 8 },
193 { 150, 47, 8 },
194 { 200, 35, 8 },
195 { 300, 47, 7 },
196 { 600, 47, 6 },
197 { 1200, 47, 5 },
198 { 1800, 31, 5 },
199 { 2400, 47, 4 },
200 { 4800, 47, 3 },
201 { 9600, 47, 2 },
202 { 19200, 47, 1 },
203 { 38400, 23, 1 },
204 { 57600, 15, 1 },
205 { 115200, 7, 1 },
206 { 230400, 3, 1 },
207 { 460800, 1, 1 },
208 { 76800, 11, 1 },
209 { 153600, 5, 1 },
210 { 307200, 3, 1 },
211 { 614400, 3, 0 },
212 { 921600, 0, 1 },
213 };
214
215 int
216 sab_match(struct device *parent, struct cfdata *match, void *aux)
217 {
218 struct ebus_attach_args *ea = aux;
219 char *compat;
220
221 if (strcmp(ea->ea_name, "se") == 0)
222 return (1);
223
224 compat = prom_getpropstring(ea->ea_node, "compatible");
225 if (compat != NULL && !strcmp(compat, "sab82532"))
226 return (1);
227
228 return (0);
229 }
230
231 void
232 sab_attach(struct device *parent, struct device *self, void *aux)
233 {
234 struct sab_softc *sc = (struct sab_softc *)self;
235 struct ebus_attach_args *ea = aux;
236 uint8_t r;
237 u_int i;
238 int locs[SABCF_NLOCS];
239
240 sc->sc_bt = ea->ea_bustag;
241 sc->sc_node = ea->ea_node;
242
243 /* Use prom mapping, if available. */
244 if (ea->ea_nvaddr)
245 sparc_promaddr_to_handle(sc->sc_bt, ea->ea_vaddr[0], &sc->sc_bh);
246 else if (bus_space_map(sc->sc_bt, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
247 ea->ea_reg[0].size, 0, &sc->sc_bh) != 0) {
248 printf(": can't map register space\n");
249 return;
250 }
251
252 sc->sc_ih = bus_intr_establish(ea->ea_bustag, ea->ea_intr[0],
253 IPL_TTY, sab_intr, sc);
254 if (sc->sc_ih == NULL) {
255 printf(": can't map interrupt\n");
256 return;
257 }
258
259 sc->sc_softintr = softintr_establish(IPL_TTY, sab_softintr, sc);
260 if (sc->sc_softintr == NULL) {
261 printf(": can't get soft intr\n");
262 return;
263 }
264
265 aprint_normal(": rev ");
266 r = SAB_READ(sc, SAB_VSTR) & SAB_VSTR_VMASK;
267 switch (r) {
268 case SAB_VSTR_V_1:
269 aprint_normal("1");
270 break;
271 case SAB_VSTR_V_2:
272 aprint_normal("2");
273 break;
274 case SAB_VSTR_V_32:
275 aprint_normal("3.2");
276 break;
277 default:
278 aprint_normal("unknown(0x%x)", r);
279 break;
280 }
281 aprint_normal("\n");
282
283 /* Let current output drain */
284 DELAY(100000);
285
286 /* Set all pins, except DTR pins to be inputs */
287 SAB_WRITE(sc, SAB_PCR, ~(SAB_PVR_DTR_A | SAB_PVR_DTR_B));
288 /* Disable port interrupts */
289 SAB_WRITE(sc, SAB_PIM, 0xff);
290 SAB_WRITE(sc, SAB_PVR, SAB_PVR_DTR_A | SAB_PVR_DTR_B | SAB_PVR_MAGIC);
291 SAB_WRITE(sc, SAB_IPC, SAB_IPC_ICPL);
292
293 for (i = 0; i < SAB_NCHAN; i++) {
294 struct sabtty_attach_args stax;
295
296 stax.sbt_portno = i;
297
298 locs[SABCF_CHANNEL] = i;
299
300 sc->sc_child[i] =
301 (struct sabtty_softc *)config_found_sm_loc(self,
302 "sab", locs, &stax, sab_print, config_stdsubmatch);
303 if (sc->sc_child[i] != NULL)
304 sc->sc_nchild++;
305 }
306 }
307
308 int
309 sab_print(void *args, const char *name)
310 {
311 struct sabtty_attach_args *sa = args;
312
313 if (name)
314 aprint_normal("sabtty at %s", name);
315 aprint_normal(" port %u", sa->sbt_portno);
316 return (UNCONF);
317 }
318
319 int
320 sab_intr(void *vsc)
321 {
322 struct sab_softc *sc = vsc;
323 int r = 0, needsoft = 0;
324 uint8_t gis;
325
326 gis = SAB_READ(sc, SAB_GIS);
327
328 /* channel A */
329 if ((gis & (SAB_GIS_ISA1 | SAB_GIS_ISA0)) && sc->sc_child[0] &&
330 sc->sc_child[0]->sc_tty)
331 r |= sabtty_intr(sc->sc_child[0], &needsoft);
332
333 /* channel B */
334 if ((gis & (SAB_GIS_ISB1 | SAB_GIS_ISB0)) && sc->sc_child[1] &&
335 sc->sc_child[1]->sc_tty)
336 r |= sabtty_intr(sc->sc_child[1], &needsoft);
337
338 if (needsoft)
339 softintr_schedule(sc->sc_softintr);
340
341 return (r);
342 }
343
344 void
345 sab_softintr(void *vsc)
346 {
347 struct sab_softc *sc = vsc;
348
349 if (sc->sc_child[0] && sc->sc_child[0]->sc_tty)
350 sabtty_softintr(sc->sc_child[0]);
351 if (sc->sc_child[1] && sc->sc_child[1]->sc_tty)
352 sabtty_softintr(sc->sc_child[1]);
353 }
354
355 int
356 sabtty_match(struct device *parent, struct cfdata *match, void *aux)
357 {
358
359 return (1);
360 }
361
362 void
363 sabtty_attach(struct device *parent, struct device *self, void *aux)
364 {
365 struct sabtty_softc *sc = (struct sabtty_softc *)self;
366 struct sabtty_attach_args *sa = aux;
367 int r;
368 int maj;
369
370 sc->sc_tty = ttymalloc();
371 if (sc->sc_tty == NULL) {
372 aprint_normal(": failed to allocate tty\n");
373 return;
374 }
375 tty_attach(sc->sc_tty);
376 sc->sc_tty->t_oproc = sabtty_start;
377 sc->sc_tty->t_param = sabtty_param;
378
379 sc->sc_parent = (struct sab_softc *)parent;
380 sc->sc_bt = sc->sc_parent->sc_bt;
381 sc->sc_portno = sa->sbt_portno;
382 sc->sc_rend = sc->sc_rbuf + SABTTY_RBUF_SIZE;
383
384 switch (sa->sbt_portno) {
385 case 0: /* port A */
386 sc->sc_pvr_dtr = SAB_PVR_DTR_A;
387 sc->sc_pvr_dsr = SAB_PVR_DSR_A;
388 r = bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh,
389 SAB_CHAN_A, SAB_CHANLEN, &sc->sc_bh);
390 break;
391 case 1: /* port B */
392 sc->sc_pvr_dtr = SAB_PVR_DTR_B;
393 sc->sc_pvr_dsr = SAB_PVR_DSR_B;
394 r = bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh,
395 SAB_CHAN_B, SAB_CHANLEN, &sc->sc_bh);
396 break;
397 default:
398 aprint_normal(": invalid channel: %u\n", sa->sbt_portno);
399 return;
400 }
401 if (r != 0) {
402 aprint_normal(": failed to allocate register subregion\n");
403 return;
404 }
405
406 sabtty_console_flags(sc);
407
408 if (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) {
409 struct termios t;
410 const char *acc;
411
412 /* Let residual prom output drain */
413 DELAY(100000);
414
415 switch (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) {
416 case SABTTYF_CONS_IN:
417 acc = "input";
418 break;
419 case SABTTYF_CONS_OUT:
420 acc = "output";
421 break;
422 case SABTTYF_CONS_IN|SABTTYF_CONS_OUT:
423 default:
424 acc = "i/o";
425 break;
426 }
427
428 t.c_ispeed= 0;
429 t.c_ospeed = 9600;
430 t.c_cflag = CREAD | CS8 | HUPCL;
431 sc->sc_tty->t_ospeed = 0;
432 sabttyparam(sc, sc->sc_tty, &t);
433
434 if (sc->sc_flags & SABTTYF_CONS_IN) {
435 sabtty_cons_input = sc;
436 cn_tab->cn_pollc = sab_cnpollc;
437 cn_tab->cn_getc = sab_cngetc;
438 maj = cdevsw_lookup_major(&sabtty_cdevsw);
439 cn_tab->cn_dev = makedev(maj, device_unit(self));
440 shutdownhook_establish(sabtty_shutdown, sc);
441 cn_init_magic(&sabtty_cnm_state);
442 cn_set_magic("\047\001"); /* default magic is BREAK */
443 }
444
445 if (sc->sc_flags & SABTTYF_CONS_OUT) {
446 sabtty_tec_wait(sc);
447 sabtty_cons_output = sc;
448 cn_tab->cn_putc = sab_cnputc;
449 maj = cdevsw_lookup_major(&sabtty_cdevsw);
450 cn_tab->cn_dev = makedev(maj, device_unit(self));
451 }
452 aprint_normal(": console %s", acc);
453 } else {
454 /* Not a console... */
455 sabtty_reset(sc);
456 }
457
458 aprint_normal("\n");
459 }
460
461 int
462 sabtty_intr(struct sabtty_softc *sc, int *needsoftp)
463 {
464 uint8_t isr0, isr1;
465 int i, len = 0, needsoft = 0, r = 0, clearfifo = 0;
466
467 isr0 = SAB_READ(sc, SAB_ISR0);
468 isr1 = SAB_READ(sc, SAB_ISR1);
469
470 if (isr0 || isr1)
471 r = 1;
472
473 if (isr0 & SAB_ISR0_RPF) {
474 len = 32;
475 clearfifo = 1;
476 }
477 if (isr0 & SAB_ISR0_TCD) {
478 len = (32 - 1) & SAB_READ(sc, SAB_RBCL);
479 clearfifo = 1;
480 }
481 if (isr0 & SAB_ISR0_TIME) {
482 sabtty_cec_wait(sc);
483 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RFRD);
484 }
485 if (isr0 & SAB_ISR0_RFO) {
486 sc->sc_flags |= SABTTYF_RINGOVERFLOW;
487 clearfifo = 1;
488 }
489 if (len != 0) {
490 uint8_t *ptr, b;
491
492 ptr = sc->sc_rput;
493 for (i = 0; i < len; i++) {
494 b = SAB_READ(sc, SAB_RFIFO);
495 if (i % 2 == 0) /* skip status byte */
496 cn_check_magic(sc->sc_tty->t_dev,
497 b, sabtty_cnm_state);
498 *ptr++ = b;
499 if (ptr == sc->sc_rend)
500 ptr = sc->sc_rbuf;
501 if (ptr == sc->sc_rget) {
502 if (ptr == sc->sc_rbuf)
503 ptr = sc->sc_rend;
504 ptr--;
505 sc->sc_flags |= SABTTYF_RINGOVERFLOW;
506 }
507 }
508 sc->sc_rput = ptr;
509 needsoft = 1;
510 }
511
512 if (clearfifo) {
513 sabtty_cec_wait(sc);
514 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RMC);
515 }
516
517 if (isr0 & SAB_ISR0_CDSC) {
518 sc->sc_flags |= SABTTYF_CDCHG;
519 needsoft = 1;
520 }
521
522 if (isr1 & SAB_ISR1_BRKT)
523 cn_check_magic(sc->sc_tty->t_dev,
524 CNC_BREAK, sabtty_cnm_state);
525
526 if (isr1 & (SAB_ISR1_XPR | SAB_ISR1_ALLS)) {
527 if ((SAB_READ(sc, SAB_STAR) & SAB_STAR_XFW) &&
528 (sc->sc_flags & SABTTYF_STOP) == 0) {
529 if (sc->sc_txc < 32)
530 len = sc->sc_txc;
531 else
532 len = 32;
533
534 if (len > 0) {
535 SAB_WRITE_BLOCK(sc, SAB_XFIFO, sc->sc_txp, len);
536 sc->sc_txp += len;
537 sc->sc_txc -= len;
538
539 sabtty_cec_wait(sc);
540 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XF);
541
542 /*
543 * Prevent the false end of xmit from
544 * confusing things below.
545 */
546 isr1 &= ~SAB_ISR1_ALLS;
547 }
548 }
549
550 if ((sc->sc_txc == 0) || (sc->sc_flags & SABTTYF_STOP)) {
551 if ((sc->sc_imr1 & SAB_IMR1_XPR) == 0) {
552 sc->sc_imr1 |= SAB_IMR1_XPR;
553 sc->sc_imr1 &= ~SAB_IMR1_ALLS;
554 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
555 }
556 }
557 }
558
559 if ((isr1 & SAB_ISR1_ALLS) && ((sc->sc_txc == 0) ||
560 (sc->sc_flags & SABTTYF_STOP))) {
561 if (sc->sc_flags & SABTTYF_TXDRAIN)
562 wakeup(sc);
563 sc->sc_flags &= ~SABTTYF_STOP;
564 sc->sc_flags |= SABTTYF_DONE;
565 sc->sc_imr1 |= SAB_IMR1_ALLS;
566 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
567 needsoft = 1;
568 }
569
570 if (needsoft)
571 *needsoftp = needsoft;
572 return (r);
573 }
574
575 void
576 sabtty_softintr(struct sabtty_softc *sc)
577 {
578 struct tty *tp = sc->sc_tty;
579 int s, flags;
580 uint8_t r;
581
582 if (tp == NULL)
583 return;
584
585 if ((tp->t_state & TS_ISOPEN) == 0)
586 return;
587
588 while (sc->sc_rget != sc->sc_rput) {
589 int data;
590 uint8_t stat;
591
592 data = sc->sc_rget[0];
593 stat = sc->sc_rget[1];
594 sc->sc_rget += 2;
595 if (stat & SAB_RSTAT_PE)
596 data |= TTY_PE;
597 if (stat & SAB_RSTAT_FE)
598 data |= TTY_FE;
599 if (sc->sc_rget == sc->sc_rend)
600 sc->sc_rget = sc->sc_rbuf;
601
602 (*tp->t_linesw->l_rint)(data, tp);
603 }
604
605 s = splhigh();
606 flags = sc->sc_flags;
607 sc->sc_flags &= ~(SABTTYF_DONE|SABTTYF_CDCHG|SABTTYF_RINGOVERFLOW);
608 splx(s);
609
610 if (flags & SABTTYF_CDCHG) {
611 s = spltty();
612 r = SAB_READ(sc, SAB_VSTR) & SAB_VSTR_CD;
613 splx(s);
614
615 (*tp->t_linesw->l_modem)(tp, r);
616 }
617
618 if (flags & SABTTYF_RINGOVERFLOW)
619 log(LOG_WARNING, "%s: ring overflow\n",
620 device_xname(&sc->sc_dv));
621
622 if (flags & SABTTYF_DONE) {
623 ndflush(&tp->t_outq, sc->sc_txp - tp->t_outq.c_cf);
624 tp->t_state &= ~TS_BUSY;
625 (*tp->t_linesw->l_start)(tp);
626 }
627 }
628
629 int
630 sabopen(dev_t dev, int flags, int mode, struct lwp *l)
631 {
632 struct sabtty_softc *sc;
633 struct tty *tp;
634 struct proc *p;
635 int s, s1;
636
637 sc = device_lookup(&sabtty_cd, SABUNIT(dev));
638 if (sc == NULL)
639 return (ENXIO);
640
641 tp = sc->sc_tty;
642 tp->t_dev = dev;
643 p = l->l_proc;
644
645 if ((tp->t_state & TS_ISOPEN) == 0) {
646 ttychars(tp);
647 tp->t_iflag = TTYDEF_IFLAG;
648 tp->t_oflag = TTYDEF_OFLAG;
649 tp->t_cflag = TTYDEF_CFLAG;
650 if (sc->sc_openflags & TIOCFLAG_CLOCAL)
651 tp->t_cflag |= CLOCAL;
652 if (sc->sc_openflags & TIOCFLAG_CRTSCTS)
653 tp->t_cflag |= CRTSCTS;
654 if (sc->sc_openflags & TIOCFLAG_MDMBUF)
655 tp->t_cflag |= MDMBUF;
656 tp->t_lflag = TTYDEF_LFLAG;
657 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
658
659 sc->sc_rput = sc->sc_rget = sc->sc_rbuf;
660
661 s = spltty();
662
663 ttsetwater(tp);
664
665 s1 = splhigh();
666 sabtty_reset(sc);
667 sabtty_param(tp, &tp->t_termios);
668 sc->sc_imr0 = SAB_IMR0_PERR | SAB_IMR0_FERR | SAB_IMR0_PLLA;
669 SAB_WRITE(sc, SAB_IMR0, sc->sc_imr0);
670 sc->sc_imr1 = SAB_IMR1_BRK | SAB_IMR1_ALLS | SAB_IMR1_XDU |
671 SAB_IMR1_TIN | SAB_IMR1_CSC | SAB_IMR1_XMR | SAB_IMR1_XPR;
672 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
673 SAB_WRITE(sc, SAB_CCR0, SAB_READ(sc, SAB_CCR0) | SAB_CCR0_PU);
674 sabtty_cec_wait(sc);
675 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XRES);
676 sabtty_cec_wait(sc);
677 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
678 sabtty_cec_wait(sc);
679 splx(s1);
680
681 sabtty_flush(sc);
682
683 if ((sc->sc_openflags & TIOCFLAG_SOFTCAR) ||
684 (SAB_READ(sc, SAB_VSTR) & SAB_VSTR_CD))
685 tp->t_state |= TS_CARR_ON;
686 else
687 tp->t_state &= ~TS_CARR_ON;
688 } else if ((tp->t_state & TS_XCLUDE) &&
689 (!kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
690 &l->l_acflag))) {
691 return (EBUSY);
692 } else {
693 s = spltty();
694 }
695
696 if ((flags & O_NONBLOCK) == 0) {
697 while ((tp->t_cflag & CLOCAL) == 0 &&
698 (tp->t_state & TS_CARR_ON) == 0) {
699 int error;
700
701 error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
702 "sabttycd", 0);
703 if (error != 0) {
704 splx(s);
705 return (error);
706 }
707 }
708 }
709
710 splx(s);
711
712 s = (*tp->t_linesw->l_open)(dev, tp);
713 if (s != 0) {
714 if (tp->t_state & TS_ISOPEN)
715 return (s);
716
717 if (tp->t_cflag & HUPCL) {
718 sabtty_mdmctrl(sc, 0, DMSET);
719 (void)tsleep(sc, TTIPRI, ttclos, hz);
720 }
721
722 if ((sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) == 0) {
723 /* Flush and power down if we're not the console */
724 sabtty_flush(sc);
725 sabtty_reset(sc);
726 }
727 }
728 return (s);
729 }
730
731 int
732 sabclose(dev_t dev, int flags, int mode, struct lwp *l)
733 {
734 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
735 struct sab_softc *bc = sc->sc_parent;
736 struct tty *tp = sc->sc_tty;
737 int s;
738
739 (*tp->t_linesw->l_close)(tp, flags);
740
741 s = spltty();
742
743 if ((tp->t_state & TS_ISOPEN) == 0) {
744 /* Wait for output drain */
745 sc->sc_imr1 &= ~SAB_IMR1_ALLS;
746 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
747 sc->sc_flags |= SABTTYF_TXDRAIN;
748 (void)tsleep(sc, TTIPRI, ttclos, 5 * hz);
749 sc->sc_imr1 |= SAB_IMR1_ALLS;
750 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
751 sc->sc_flags &= ~SABTTYF_TXDRAIN;
752
753 if (tp->t_cflag & HUPCL) {
754 sabtty_mdmctrl(sc, 0, DMSET);
755 (void)tsleep(bc, TTIPRI, ttclos, hz);
756 }
757
758 if ((sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) == 0) {
759 /* Flush and power down if we're not the console */
760 sabtty_flush(sc);
761 sabtty_reset(sc);
762 }
763 }
764
765 ttyclose(tp);
766 splx(s);
767
768 return (0);
769 }
770
771 int
772 sabread(dev_t dev, struct uio *uio, int flags)
773 {
774 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
775 struct tty *tp = sc->sc_tty;
776
777 return ((*tp->t_linesw->l_read)(tp, uio, flags));
778 }
779
780 int
781 sabwrite(dev_t dev, struct uio *uio, int flags)
782 {
783 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
784 struct tty *tp = sc->sc_tty;
785
786 return ((*tp->t_linesw->l_write)(tp, uio, flags));
787 }
788
789 int
790 sabioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct lwp *l)
791 {
792 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
793 struct tty *tp = sc->sc_tty;
794 int error;
795
796 error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flags, l);
797 if (error >= 0)
798 return (error);
799
800 error = ttioctl(tp, cmd, data, flags, l);
801 if (error >= 0)
802 return (error);
803
804 error = 0;
805
806 switch (cmd) {
807 case TIOCSBRK:
808 SAB_WRITE(sc, SAB_DAFO,
809 SAB_READ(sc, SAB_DAFO) | SAB_DAFO_XBRK);
810 break;
811 case TIOCCBRK:
812 SAB_WRITE(sc, SAB_DAFO,
813 SAB_READ(sc, SAB_DAFO) & ~SAB_DAFO_XBRK);
814 break;
815 case TIOCSDTR:
816 sabtty_mdmctrl(sc, TIOCM_DTR, DMBIS);
817 break;
818 case TIOCCDTR:
819 sabtty_mdmctrl(sc, TIOCM_DTR, DMBIC);
820 break;
821 case TIOCMBIS:
822 sabtty_mdmctrl(sc, *((int *)data), DMBIS);
823 break;
824 case TIOCMBIC:
825 sabtty_mdmctrl(sc, *((int *)data), DMBIC);
826 break;
827 case TIOCMGET:
828 *((int *)data) = sabtty_mdmctrl(sc, 0, DMGET);
829 break;
830 case TIOCMSET:
831 sabtty_mdmctrl(sc, *((int *)data), DMSET);
832 break;
833 case TIOCGFLAGS:
834 *((int *)data) = sc->sc_openflags;
835 break;
836 case TIOCSFLAGS:
837 if (kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
838 &l->l_acflag))
839 error = EPERM;
840 else
841 sc->sc_openflags = *((int *)data) &
842 (TIOCFLAG_SOFTCAR | TIOCFLAG_CLOCAL |
843 TIOCFLAG_CRTSCTS | TIOCFLAG_MDMBUF);
844 break;
845 default:
846 error = ENOTTY;
847 }
848
849 return (error);
850 }
851
852 struct tty *
853 sabtty(dev_t dev)
854 {
855 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
856
857 return (sc->sc_tty);
858 }
859
860 void
861 sabstop(struct tty *tp, int flag)
862 {
863 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(tp->t_dev));
864 int s;
865
866 s = spltty();
867 if (tp->t_state & TS_BUSY) {
868 if ((tp->t_state & TS_TTSTOP) == 0)
869 tp->t_state |= TS_FLUSH;
870 sc->sc_flags |= SABTTYF_STOP;
871 sc->sc_imr1 &= ~SAB_IMR1_ALLS;
872 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
873 }
874 splx(s);
875 }
876
877 int
878 sabpoll(dev_t dev, int events, struct lwp *l)
879 {
880 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
881 struct tty *tp = sc->sc_tty;
882
883 return ((*tp->t_linesw->l_poll)(tp, events, l));
884 }
885
886 int
887 sabtty_mdmctrl(struct sabtty_softc *sc, int bits, int how)
888 {
889 uint8_t r;
890 int s;
891
892 s = spltty();
893 switch (how) {
894 case DMGET:
895 bits = 0;
896 if (SAB_READ(sc, SAB_STAR) & SAB_STAR_CTS)
897 bits |= TIOCM_CTS;
898 if ((SAB_READ(sc, SAB_VSTR) & SAB_VSTR_CD) == 0)
899 bits |= TIOCM_CD;
900
901 r = SAB_READ(sc, SAB_PVR);
902 if ((r & sc->sc_pvr_dtr) == 0)
903 bits |= TIOCM_DTR;
904 if ((r & sc->sc_pvr_dsr) == 0)
905 bits |= TIOCM_DSR;
906
907 r = SAB_READ(sc, SAB_MODE);
908 if ((r & (SAB_MODE_RTS|SAB_MODE_FRTS)) == SAB_MODE_RTS)
909 bits |= TIOCM_RTS;
910 break;
911 case DMSET:
912 r = SAB_READ(sc, SAB_MODE);
913 if (bits & TIOCM_RTS) {
914 r &= ~SAB_MODE_FRTS;
915 r |= SAB_MODE_RTS;
916 } else
917 r |= SAB_MODE_FRTS | SAB_MODE_RTS;
918 SAB_WRITE(sc, SAB_MODE, r);
919
920 r = SAB_READ(sc, SAB_PVR);
921 if (bits & TIOCM_DTR)
922 r &= ~sc->sc_pvr_dtr;
923 else
924 r |= sc->sc_pvr_dtr;
925 SAB_WRITE(sc, SAB_PVR, r);
926 break;
927 case DMBIS:
928 if (bits & TIOCM_RTS) {
929 r = SAB_READ(sc, SAB_MODE);
930 r &= ~SAB_MODE_FRTS;
931 r |= SAB_MODE_RTS;
932 SAB_WRITE(sc, SAB_MODE, r);
933 }
934 if (bits & TIOCM_DTR) {
935 r = SAB_READ(sc, SAB_PVR);
936 r &= ~sc->sc_pvr_dtr;
937 SAB_WRITE(sc, SAB_PVR, r);
938 }
939 break;
940 case DMBIC:
941 if (bits & TIOCM_RTS) {
942 r = SAB_READ(sc, SAB_MODE);
943 r |= SAB_MODE_FRTS | SAB_MODE_RTS;
944 SAB_WRITE(sc, SAB_MODE, r);
945 }
946 if (bits & TIOCM_DTR) {
947 r = SAB_READ(sc, SAB_PVR);
948 r |= sc->sc_pvr_dtr;
949 SAB_WRITE(sc, SAB_PVR, r);
950 }
951 break;
952 }
953 splx(s);
954 return (bits);
955 }
956
957 int
958 sabttyparam(struct sabtty_softc *sc, struct tty *tp, struct termios *t)
959 {
960 int s, ospeed;
961 tcflag_t cflag;
962 uint8_t dafo, r;
963
964 ospeed = sabtty_speed(t->c_ospeed);
965 if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
966 return (EINVAL);
967
968 s = spltty();
969
970 /* hang up line if ospeed is zero, otherwise raise dtr */
971 sabtty_mdmctrl(sc, TIOCM_DTR,
972 (t->c_ospeed == 0) ? DMBIC : DMBIS);
973
974 dafo = SAB_READ(sc, SAB_DAFO);
975
976 cflag = t->c_cflag;
977
978 if (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) {
979 cflag |= CLOCAL;
980 cflag &= ~HUPCL;
981 }
982
983 if (cflag & CSTOPB)
984 dafo |= SAB_DAFO_STOP;
985 else
986 dafo &= ~SAB_DAFO_STOP;
987
988 dafo &= ~SAB_DAFO_CHL_CSIZE;
989 switch (cflag & CSIZE) {
990 case CS5:
991 dafo |= SAB_DAFO_CHL_CS5;
992 break;
993 case CS6:
994 dafo |= SAB_DAFO_CHL_CS6;
995 break;
996 case CS7:
997 dafo |= SAB_DAFO_CHL_CS7;
998 break;
999 default:
1000 dafo |= SAB_DAFO_CHL_CS8;
1001 break;
1002 }
1003
1004 dafo &= ~SAB_DAFO_PARMASK;
1005 if (cflag & PARENB) {
1006 if (cflag & PARODD)
1007 dafo |= SAB_DAFO_PAR_ODD;
1008 else
1009 dafo |= SAB_DAFO_PAR_EVEN;
1010 } else
1011 dafo |= SAB_DAFO_PAR_NONE;
1012 SAB_WRITE(sc, SAB_DAFO, dafo);
1013
1014 if (ospeed != 0) {
1015 SAB_WRITE(sc, SAB_BGR, ospeed & 0xff);
1016 r = SAB_READ(sc, SAB_CCR2);
1017 r &= ~(SAB_CCR2_BR9 | SAB_CCR2_BR8);
1018 r |= (ospeed >> 2) & (SAB_CCR2_BR9 | SAB_CCR2_BR8);
1019 SAB_WRITE(sc, SAB_CCR2, r);
1020 }
1021
1022 r = SAB_READ(sc, SAB_MODE);
1023 r |= SAB_MODE_RAC;
1024 if (cflag & CRTSCTS) {
1025 r &= ~(SAB_MODE_RTS | SAB_MODE_FCTS);
1026 r |= SAB_MODE_FRTS;
1027 sc->sc_imr1 &= ~SAB_IMR1_CSC;
1028 } else {
1029 r |= SAB_MODE_RTS | SAB_MODE_FCTS;
1030 r &= ~SAB_MODE_FRTS;
1031 sc->sc_imr1 |= SAB_IMR1_CSC;
1032 }
1033 SAB_WRITE(sc, SAB_MODE, r);
1034 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
1035
1036 tp->t_cflag = cflag;
1037
1038 splx(s);
1039 return (0);
1040 }
1041
1042 int
1043 sabtty_param(struct tty *tp, struct termios *t)
1044 {
1045 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(tp->t_dev));
1046
1047 return (sabttyparam(sc, tp, t));
1048 }
1049
1050 void
1051 sabtty_start(struct tty *tp)
1052 {
1053 struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(tp->t_dev));
1054 int s;
1055
1056 s = spltty();
1057 if ((tp->t_state & (TS_TTSTOP | TS_TIMEOUT | TS_BUSY)) == 0) {
1058 if (tp->t_outq.c_cc <= tp->t_lowat) {
1059 if (tp->t_state & TS_ASLEEP) {
1060 tp->t_state &= ~TS_ASLEEP;
1061 wakeup(&tp->t_outq);
1062 }
1063 selwakeup(&tp->t_wsel);
1064 }
1065 if (tp->t_outq.c_cc) {
1066 sc->sc_txc = ndqb(&tp->t_outq, 0);
1067 sc->sc_txp = tp->t_outq.c_cf;
1068 tp->t_state |= TS_BUSY;
1069 sc->sc_imr1 &= ~(SAB_ISR1_XPR | SAB_ISR1_ALLS);
1070 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
1071 }
1072 }
1073 splx(s);
1074 }
1075
1076 void
1077 sabtty_cec_wait(struct sabtty_softc *sc)
1078 {
1079 int i = 50000;
1080
1081 for (;;) {
1082 if ((SAB_READ(sc, SAB_STAR) & SAB_STAR_CEC) == 0)
1083 return;
1084 if (--i == 0)
1085 break;
1086 DELAY(1);
1087 }
1088 }
1089
1090 void
1091 sabtty_tec_wait(struct sabtty_softc *sc)
1092 {
1093 int i = 200000;
1094
1095 for (;;) {
1096 if ((SAB_READ(sc, SAB_STAR) & SAB_STAR_TEC) == 0)
1097 return;
1098 if (--i == 0)
1099 break;
1100 DELAY(1);
1101 }
1102 }
1103
1104 void
1105 sabtty_reset(struct sabtty_softc *sc)
1106 {
1107 /* power down */
1108 SAB_WRITE(sc, SAB_CCR0, 0);
1109
1110 /* set basic configuration */
1111 SAB_WRITE(sc, SAB_CCR0,
1112 SAB_CCR0_MCE | SAB_CCR0_SC_NRZ | SAB_CCR0_SM_ASYNC);
1113 SAB_WRITE(sc, SAB_CCR1, SAB_CCR1_ODS | SAB_CCR1_BCR | SAB_CCR1_CM_7);
1114 SAB_WRITE(sc, SAB_CCR2, SAB_CCR2_BDF | SAB_CCR2_SSEL | SAB_CCR2_TOE);
1115 SAB_WRITE(sc, SAB_CCR3, 0);
1116 SAB_WRITE(sc, SAB_CCR4, SAB_CCR4_MCK4 | SAB_CCR4_EBRG | SAB_CCR4_ICD);
1117 SAB_WRITE(sc, SAB_MODE, SAB_MODE_RTS | SAB_MODE_FCTS | SAB_MODE_RAC);
1118 SAB_WRITE(sc, SAB_RFC,
1119 SAB_RFC_DPS | SAB_RFC_RFDF | SAB_RFC_RFTH_32CHAR);
1120
1121 /* clear interrupts */
1122 sc->sc_imr0 = sc->sc_imr1 = 0xff;
1123 SAB_WRITE(sc, SAB_IMR0, sc->sc_imr0);
1124 SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
1125 (void)SAB_READ(sc, SAB_ISR0);
1126 (void)SAB_READ(sc, SAB_ISR1);
1127 }
1128
1129 void
1130 sabtty_flush(struct sabtty_softc *sc)
1131 {
1132 /* clear rx fifo */
1133 sabtty_cec_wait(sc);
1134 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
1135
1136 /* clear tx fifo */
1137 sabtty_cec_wait(sc);
1138 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XRES);
1139 }
1140
1141 int
1142 sabtty_speed(int rate)
1143 {
1144 int i, len, r;
1145
1146 if (rate == 0)
1147 return (0);
1148 len = sizeof(sabtty_baudtable)/sizeof(sabtty_baudtable[0]);
1149 for (i = 0; i < len; i++) {
1150 if (rate == sabtty_baudtable[i].baud) {
1151 r = sabtty_baudtable[i].n |
1152 (sabtty_baudtable[i].m << 6);
1153 return (r);
1154 }
1155 }
1156 return (-1);
1157 }
1158
1159 void
1160 sabtty_cnputc(struct sabtty_softc *sc, int c)
1161 {
1162 sabtty_tec_wait(sc);
1163 SAB_WRITE(sc, SAB_TIC, c);
1164 sabtty_tec_wait(sc);
1165 }
1166
1167 int
1168 sabtty_cngetc(struct sabtty_softc *sc)
1169 {
1170 uint8_t r, len;
1171
1172 again:
1173 do {
1174 r = SAB_READ(sc, SAB_STAR);
1175 } while ((r & SAB_STAR_RFNE) == 0);
1176
1177 /*
1178 * Ok, at least one byte in RFIFO, ask for permission to access RFIFO
1179 * (I hate this chip... hate hate hate).
1180 */
1181 sabtty_cec_wait(sc);
1182 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RFRD);
1183
1184 /* Wait for RFIFO to come ready */
1185 do {
1186 r = SAB_READ(sc, SAB_ISR0);
1187 } while ((r & SAB_ISR0_TCD) == 0);
1188
1189 len = SAB_READ(sc, SAB_RBCL) & (32 - 1);
1190 if (len == 0)
1191 goto again; /* Shouldn't happen... */
1192
1193 r = SAB_READ(sc, SAB_RFIFO);
1194
1195 /*
1196 * Blow away everything left in the FIFO...
1197 */
1198 sabtty_cec_wait(sc);
1199 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RMC);
1200 return (r);
1201 }
1202
1203 void
1204 sabtty_cnpollc(struct sabtty_softc *sc, int on)
1205 {
1206 uint8_t r;
1207
1208 if (on) {
1209 if (sc->sc_polling)
1210 return;
1211 SAB_WRITE(sc, SAB_IPC, SAB_READ(sc, SAB_IPC) | SAB_IPC_VIS);
1212 r = sc->sc_pollrfc = SAB_READ(sc, SAB_RFC);
1213 r &= ~(SAB_RFC_RFDF);
1214 SAB_WRITE(sc, SAB_RFC, r);
1215 sabtty_cec_wait(sc);
1216 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
1217 sc->sc_polling = 1;
1218 } else {
1219 if (!sc->sc_polling)
1220 return;
1221 SAB_WRITE(sc, SAB_IPC, SAB_READ(sc, SAB_IPC) & ~SAB_IPC_VIS);
1222 SAB_WRITE(sc, SAB_RFC, sc->sc_pollrfc);
1223 sabtty_cec_wait(sc);
1224 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
1225 sc->sc_polling = 0;
1226 }
1227 }
1228
1229 void
1230 sab_cnputc(dev_t dev, int c)
1231 {
1232 struct sabtty_softc *sc = sabtty_cons_output;
1233
1234 if (sc == NULL)
1235 return;
1236 sabtty_cnputc(sc, c);
1237 }
1238
1239 void
1240 sab_cnpollc(dev_t dev, int on)
1241 {
1242 struct sabtty_softc *sc = sabtty_cons_input;
1243
1244 sabtty_cnpollc(sc, on);
1245 }
1246
1247 int
1248 sab_cngetc(dev_t dev)
1249 {
1250 struct sabtty_softc *sc = sabtty_cons_input;
1251
1252 if (sc == NULL)
1253 return (-1);
1254 return (sabtty_cngetc(sc));
1255 }
1256
1257 void
1258 sabtty_console_flags(struct sabtty_softc *sc)
1259 {
1260 int node, channel, cookie;
1261 char buf[255];
1262
1263 node = sc->sc_parent->sc_node;
1264 channel = sc->sc_portno;
1265
1266 /* Default to channel 0 if there are no explicit prom args */
1267 cookie = 0;
1268
1269 if (node == prom_instance_to_package(prom_stdin())) {
1270 if (prom_getoption("input-device", buf, sizeof buf) == 0 &&
1271 strcmp("ttyb", buf) == 0)
1272 cookie = 1;
1273
1274 if (channel == cookie)
1275 sc->sc_flags |= SABTTYF_CONS_IN;
1276 }
1277
1278 /* Default to same channel if there are no explicit prom args */
1279
1280 if (node == prom_instance_to_package(prom_stdout())) {
1281 if (prom_getoption("output-device", buf, sizeof buf) == 0 &&
1282 strcmp("ttyb", buf) == 0)
1283 cookie = 1;
1284
1285 if (channel == cookie)
1286 sc->sc_flags |= SABTTYF_CONS_OUT;
1287 }
1288 }
1289
1290 void
1291 sabtty_shutdown(void *vsc)
1292 {
1293 struct sabtty_softc *sc = vsc;
1294
1295 /* Have to put the chip back into single char mode */
1296 sc->sc_flags |= SABTTYF_DONTDDB;
1297 SAB_WRITE(sc, SAB_RFC, SAB_READ(sc, SAB_RFC) & ~SAB_RFC_RFDF);
1298 sabtty_cec_wait(sc);
1299 SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
1300 sabtty_cec_wait(sc);
1301 }
1302