xref: /csrg-svn/sys/luna68k/dev/bmc.c (revision 57292)
156876Sakito /*
256876Sakito  * Copyright (c) 1992 OMRON Corporation.
356876Sakito  * Copyright (c) 1992 The Regents of the University of California.
456876Sakito  * All rights reserved.
556876Sakito  *
656876Sakito  * This code is derived from software contributed to Berkeley by
756876Sakito  * OMRON Corporation.
856876Sakito  *
956876Sakito  * %sccs.include.redist.c%
1056876Sakito  *
11*57292Sakito  *	@(#)bmc.c	7.5 (Berkeley) 12/25/92
1256876Sakito  */
1356876Sakito 
1456876Sakito #define	BMC_NOCONSOLE
1556876Sakito 
1656876Sakito #define	BMC_CNPORT	1
1756876Sakito 
1856876Sakito #include "bmc.h"
1956876Sakito #if NBMC > 0
2056876Sakito 
2157059Sakito #include <sys/param.h>
2257059Sakito #include <sys/systm.h>
2357059Sakito #include <sys/ioctl.h>
2457059Sakito #include <sys/proc.h>
2557059Sakito #include <sys/tty.h>
2657059Sakito #include <sys/conf.h>
2757059Sakito #include <sys/file.h>
2857059Sakito #include <sys/uio.h>
2957059Sakito #include <sys/kernel.h>
3057059Sakito #include <sys/syslog.h>
3157059Sakito #include <luna68k/dev/device.h>
3257059Sakito #include <luna68k/dev/sioreg.h>
3357059Sakito #include <luna68k/dev/siovar.h>
3456876Sakito 
3556876Sakito extern	struct sio_portc *sio_port_assign();
3656876Sakito 
3756876Sakito int     bmcprobe();
3856876Sakito int     bmcopen();
3956876Sakito void    bmcstart();
4056876Sakito int     bmcparam();
4156876Sakito int     bmcintr();
4256876Sakito 
4356876Sakito struct	driver bmcdriver = {
4456876Sakito 	bmcprobe, "bmc",
4556876Sakito };
4656876Sakito 
4756876Sakito struct	bmc_softc {
4856876Sakito 	struct sio_portc *sc_pc;
4956876Sakito 	int	sc_mask;
5056876Sakito };
5156876Sakito 
5256876Sakito struct	bmc_softc bmc_softc[NBMC];
5356876Sakito 
5456876Sakito struct	tty bmc_tty[NBMC];
5556876Sakito 
5656876Sakito int	bmc_config_done = 0;
5757125Sakito int	bmcconsole = -1;
5856876Sakito int	bmcdefaultrate = B9600;				/* speed of console line is fixed */
59*57292Sakito int	bmcmajor = 13;
6056876Sakito 
6156876Sakito #define	bmcunit(x)		minor(x)
6256876Sakito 
6357125Sakito extern	struct tty *constty;
6456876Sakito 
6556876Sakito /*
66*57292Sakito  *  key-code decoding
67*57292Sakito  */
68*57292Sakito 
69*57292Sakito struct bmc_keymap {
70*57292Sakito 	int	km_type;
71*57292Sakito 	int	km_code[2];
72*57292Sakito };
73*57292Sakito 
74*57292Sakito #define KC_CHAR		0x000000FF
75*57292Sakito #define KC_TYPE		0x0000FF00
76*57292Sakito #define	KC_CODE		0x00000000
77*57292Sakito #define	KC_SHIFT	0x00000100
78*57292Sakito #define	KC_IGNORE	0x0000FF00
79*57292Sakito 
80*57292Sakito #define KS_SHIFT	0
81*57292Sakito #define KS_CTRL		1
82*57292Sakito #define KS_META		2
83*57292Sakito 
84*57292Sakito struct bmc_keymap bmc_keymap[] = {
85*57292Sakito 	KC_IGNORE,	0,		0,		/*   0 [0x00]	      */
86*57292Sakito 	KC_IGNORE,	0,		0,		/*   1 [0x01]	      */
87*57292Sakito 	KC_IGNORE,	0,		0,		/*   2 [0x02]	      */
88*57292Sakito 	KC_IGNORE,	0,		0,		/*   3 [0x03]	      */
89*57292Sakito 	KC_IGNORE,	0,		0,		/*   4 [0x04]	      */
90*57292Sakito 	KC_IGNORE,	0,		0,		/*   5 [0x05]	      */
91*57292Sakito 	KC_IGNORE,	0,		0,		/*   6 [0x06]	      */
92*57292Sakito 	KC_IGNORE,	0,		0,		/*   7 [0x07]	      */
93*57292Sakito 	KC_IGNORE,	0,		0,		/*   8 [0x08]	      */
94*57292Sakito 	KC_CODE,	0x09,		0x09,		/*   9 [0x09]	TAB   */
95*57292Sakito 	KC_SHIFT,	KS_CTRL,	KS_CTRL,	/*  10 [0x0A]	CTRL  */
96*57292Sakito 	KC_IGNORE,	0,		0,		/*  11 [0x0B]	      */
97*57292Sakito 	KC_SHIFT,	KS_SHIFT,	KS_SHIFT,	/*  12 [0x0C]	SHIFT */
98*57292Sakito 	KC_SHIFT,	KS_SHIFT,	KS_SHIFT,	/*  13 [0x0D]	SHIFT */
99*57292Sakito 	KC_IGNORE,	0,		0,		/*  14 [0x0E]	      */
100*57292Sakito 	KC_SHIFT,	KS_META,	KS_META,	/*  15 [0x0F]	META  */
101*57292Sakito 	KC_CODE,	0x1B,		0x1B,		/*  16 [0x10]	ESC   */
102*57292Sakito 	KC_CODE,	0x08,		0x08,		/*  17 [0x11]	BS    */
103*57292Sakito 	KC_CODE,	0x0D,		0x0D,		/*  18 [0x12]	CR    */
104*57292Sakito 	KC_IGNORE,	0,		0,		/*  19 [0x13]	      */
105*57292Sakito 	KC_CODE,	0x20,		0x20,		/*  20 [0x14]	SP    */
106*57292Sakito 	KC_CODE,	0x7F,		0x7F,		/*  21 [0x15]	DEL   */
107*57292Sakito 	KC_IGNORE,	0,		0,		/*  22 [0x16]	      */
108*57292Sakito 	KC_IGNORE,	0,		0,		/*  23 [0x17]	      */
109*57292Sakito 	KC_IGNORE,	0,		0,		/*  24 [0x18]	      */
110*57292Sakito 	KC_IGNORE,	0,		0,		/*  25 [0x19]	      */
111*57292Sakito 	KC_IGNORE,	0,		0,		/*  26 [0x1A]	      */
112*57292Sakito 	KC_IGNORE,	0,		0,		/*  27 [0x1B]	      */
113*57292Sakito 	KC_IGNORE,	0,		0,		/*  28 [0x1C]	      */
114*57292Sakito 	KC_IGNORE,	0,		0,		/*  29 [0x1D]	      */
115*57292Sakito 	KC_IGNORE,	0,		0,		/*  30 [0x1E]	      */
116*57292Sakito 	KC_IGNORE,	0,		0,		/*  31 [0x1F]	      */
117*57292Sakito 	KC_IGNORE,	0,		0,		/*  32 [0x20]	      */
118*57292Sakito 	KC_IGNORE,	0,		0,		/*  33 [0x21]	      */
119*57292Sakito 	KC_CODE,	0x31,		0x21,		/*  34 [0x22]	 1    */
120*57292Sakito 	KC_CODE,	0x32,		0x22,		/*  35 [0x23]	 2    */
121*57292Sakito 	KC_CODE,	0x33,		0x23,		/*  36 [0x24]	 3    */
122*57292Sakito 	KC_CODE,	0x34,		0x24,		/*  37 [0x25]	 4    */
123*57292Sakito 	KC_CODE,	0x35,		0x25,		/*  38 [0x26]	 5    */
124*57292Sakito 	KC_CODE,	0x36,		0x26,		/*  39 [0x27]	 6    */
125*57292Sakito 	KC_CODE,	0x37,		0x27,		/*  40 [0x28]	 7    */
126*57292Sakito 	KC_CODE,	0x38,		0x28,		/*  41 [0x29]	 8    */
127*57292Sakito 	KC_CODE,	0x39,		0x29,		/*  42 [0x2A]	 9    */
128*57292Sakito 	KC_CODE,	0x30,		0x30,		/*  43 [0x2B]	 0    */
129*57292Sakito 	KC_CODE,	0x2D,		0x3D,		/*  44 [0x2C]	 -    */
130*57292Sakito 	KC_CODE,	0x5E,		0x7E,		/*  45 [0x2D]	 ^    */
131*57292Sakito 	KC_CODE,	0x5C,		0x7C,		/*  46 [0x2E]	 \    */
132*57292Sakito 	KC_IGNORE,	0,		0,		/*  47 [0x2F]	      */
133*57292Sakito 	KC_IGNORE,	0,		0,		/*  48 [0x30]	      */
134*57292Sakito 	KC_IGNORE,	0,		0,		/*  49 [0x31]	      */
135*57292Sakito 	KC_CODE,	0x71,		0x51,		/*  50 [0x32]	 q    */
136*57292Sakito 	KC_CODE,	0x77,		0x57,		/*  51 [0x33]	 w    */
137*57292Sakito 	KC_CODE,	0x65,		0x45,		/*  52 [0x34]	 e    */
138*57292Sakito 	KC_CODE,	0x72,		0x52,		/*  53 [0x35]	 r    */
139*57292Sakito 	KC_CODE,	0x74,		0x54,		/*  54 [0x36]	 t    */
140*57292Sakito 	KC_CODE,	0x79,		0x59,		/*  55 [0x37]	 y    */
141*57292Sakito 	KC_CODE,	0x75,		0x55,		/*  56 [0x38]	 u    */
142*57292Sakito 	KC_CODE,	0x69,		0x49,		/*  57 [0x39]	 i    */
143*57292Sakito 	KC_CODE,	0x6F,		0x4F,		/*  58 [0x3A]	 o    */
144*57292Sakito 	KC_CODE,	0x70,		0x50,		/*  59 [0x3B]	 p    */
145*57292Sakito 	KC_CODE,	0x40,		0x60,		/*  60 [0x3C]	 @    */
146*57292Sakito 	KC_CODE,	0x5B,		0x7B,		/*  61 [0x3D]	 [    */
147*57292Sakito 	KC_IGNORE,	0,		0,		/*  62 [0x3E]	      */
148*57292Sakito 	KC_IGNORE,	0,		0,		/*  63 [0x3F]	      */
149*57292Sakito 	KC_IGNORE,	0,		0,		/*  64 [0x40]	      */
150*57292Sakito 	KC_IGNORE,	0,		0,		/*  65 [0x41]	      */
151*57292Sakito 	KC_CODE,	0x61,		0x41,		/*  66 [0x42]	 a    */
152*57292Sakito 	KC_CODE,	0x73,		0x53,		/*  67 [0x43]	 s    */
153*57292Sakito 	KC_CODE,	0x64,		0x44,		/*  68 [0x44]	 d    */
154*57292Sakito 	KC_CODE,	0x66,		0x46,		/*  69 [0x45]	 f    */
155*57292Sakito 	KC_CODE,	0x67,		0x47,		/*  70 [0x46]	 g    */
156*57292Sakito 	KC_CODE,	0x68,		0x48,		/*  71 [0x47]	 h    */
157*57292Sakito 	KC_CODE,	0x6A,		0x4A,		/*  72 [0x48]	 j    */
158*57292Sakito 	KC_CODE,	0x6B,		0x4B,		/*  73 [0x49]	 k    */
159*57292Sakito 	KC_CODE,	0x6C,		0x4C,		/*  74 [0x4A]	 l    */
160*57292Sakito 	KC_CODE,	0x3B,		0x2B,		/*  75 [0x4B]	 ;    */
161*57292Sakito 	KC_CODE,	0x3A,		0x2A,		/*  76 [0x4C]	 :    */
162*57292Sakito 	KC_CODE,	0x5D,		0x7D,		/*  77 [0x4D]	 ]    */
163*57292Sakito 	KC_IGNORE,	0,		0,		/*  78 [0x4E]	      */
164*57292Sakito 	KC_IGNORE,	0,		0,		/*  79 [0x4F]	      */
165*57292Sakito 	KC_IGNORE,	0,		0,		/*  80 [0x50]	      */
166*57292Sakito 	KC_IGNORE,	0,		0,		/*  81 [0x51]	      */
167*57292Sakito 	KC_CODE,	0x7A,		0x5A,		/*  82 [0x52]	 z    */
168*57292Sakito 	KC_CODE,	0x78,		0x58,		/*  83 [0x53]	 x    */
169*57292Sakito 	KC_CODE,	0x63,		0x43,		/*  84 [0x54]	 c    */
170*57292Sakito 	KC_CODE,	0x76,		0x56,		/*  85 [0x55]	 v    */
171*57292Sakito 	KC_CODE,	0x62,		0x42,		/*  86 [0x56]	 b    */
172*57292Sakito 	KC_CODE,	0x6E,		0x4E,		/*  87 [0x57]	 n    */
173*57292Sakito 	KC_CODE,	0x6D,		0x4D,		/*  88 [0x58]	 m    */
174*57292Sakito 	KC_CODE,	0x2C,		0x3C,		/*  89 [0x59]	 ,    */
175*57292Sakito 	KC_CODE,	0x2E,		0x3E,		/*  90 [0x5A]	 .    */
176*57292Sakito 	KC_CODE,	0x2F,		0x3F,		/*  91 [0x5B]	 /    */
177*57292Sakito 	KC_CODE,	0x5F,		0x5F,		/*  92 [0x5C]	 _    */
178*57292Sakito 	KC_IGNORE,	0,		0,		/*  93 [0x5D]	      */
179*57292Sakito 	KC_IGNORE,	0,		0,		/*  94 [0x5E]	      */
180*57292Sakito 	KC_IGNORE,	0,		0,		/*  95 [0x5F]	      */
181*57292Sakito 	KC_IGNORE,	0,		0,		/*  96 [0x60]	      */
182*57292Sakito 	KC_IGNORE,	0,		0,		/*  97 [0x61]	      */
183*57292Sakito 	KC_IGNORE,	0,		0,		/*  98 [0x62]	      */
184*57292Sakito 	KC_IGNORE,	0,		0,		/*  99 [0x63]	      */
185*57292Sakito 	KC_IGNORE,	0,		0,		/* 100 [0x64]	      */
186*57292Sakito 	KC_IGNORE,	0,		0,		/* 101 [0x65]	      */
187*57292Sakito 	KC_IGNORE,	0,		0,		/* 102 [0x66]	      */
188*57292Sakito 	KC_IGNORE,	0,		0,		/* 103 [0x67]	      */
189*57292Sakito 	KC_IGNORE,	0,		0,		/* 104 [0x68]	      */
190*57292Sakito 	KC_IGNORE,	0,		0,		/* 105 [0x69]	      */
191*57292Sakito 	KC_IGNORE,	0,		0,		/* 106 [0x6A]	      */
192*57292Sakito 	KC_IGNORE,	0,		0,		/* 107 [0x6B]	      */
193*57292Sakito 	KC_IGNORE,	0,		0,		/* 108 [0x6C]	      */
194*57292Sakito 	KC_IGNORE,	0,		0,		/* 109 [0x6D]	      */
195*57292Sakito 	KC_IGNORE,	0,		0,		/* 110 [0x6E]	      */
196*57292Sakito 	KC_IGNORE,	0,		0,		/* 111 [0x6F]	      */
197*57292Sakito 	KC_IGNORE,	0,		0,		/* 112 [0x70]	      */
198*57292Sakito 	KC_IGNORE,	0,		0,		/* 113 [0x71]	      */
199*57292Sakito 	KC_IGNORE,	0,		0,		/* 114 [0x72]	      */
200*57292Sakito 	KC_IGNORE,	0,		0,		/* 115 [0x73]	      */
201*57292Sakito 	KC_IGNORE,	0,		0,		/* 116 [0x74]	      */
202*57292Sakito 	KC_IGNORE,	0,		0,		/* 117 [0x75]	      */
203*57292Sakito 	KC_IGNORE,	0,		0,		/* 118 [0x76]	      */
204*57292Sakito 	KC_IGNORE,	0,		0,		/* 119 [0x77]	      */
205*57292Sakito 	KC_IGNORE,	0,		0,		/* 120 [0x78]	      */
206*57292Sakito 	KC_IGNORE,	0,		0,		/* 121 [0x79]	      */
207*57292Sakito 	KC_IGNORE,	0,		0,		/* 122 [0x7A]	      */
208*57292Sakito 	KC_IGNORE,	0,		0,		/* 123 [0x7B]	      */
209*57292Sakito 	KC_IGNORE,	0,		0,		/* 124 [0x7C]	      */
210*57292Sakito 	KC_IGNORE,	0,		0,		/* 125 [0x7D]	      */
211*57292Sakito 	KC_IGNORE,	0,		0,		/* 126 [0x7E]	      */
212*57292Sakito 	KC_IGNORE,	0,		0,		/* 127 [0x7F]	      */
213*57292Sakito };
214*57292Sakito 
215*57292Sakito int	shift_flag = 0;
216*57292Sakito int	ctrl_flag  = 0;
217*57292Sakito int	meta_flag  = 0;
218*57292Sakito 
219*57292Sakito bmc_decode(code)
220*57292Sakito 	register u_char code;
221*57292Sakito {
222*57292Sakito 	register unsigned int c, updown;
223*57292Sakito 
224*57292Sakito 	if (code & 0x80)
225*57292Sakito 		updown = 1;
226*57292Sakito 	else
227*57292Sakito 		updown = 0;
228*57292Sakito 
229*57292Sakito 	code &= 0x7F;
230*57292Sakito 
231*57292Sakito 	c = bmc_keymap[code].km_type;
232*57292Sakito 
233*57292Sakito 	switch(c) {
234*57292Sakito 
235*57292Sakito 	case KC_CODE:
236*57292Sakito 		if (updown)
237*57292Sakito 			c = KC_IGNORE;
238*57292Sakito 		break;
239*57292Sakito 
240*57292Sakito 	case KC_SHIFT:
241*57292Sakito 		switch(bmc_keymap[code].km_code[0]) {
242*57292Sakito 		case KS_SHIFT:
243*57292Sakito 			shift_flag = 1 - updown;
244*57292Sakito 			break;
245*57292Sakito 
246*57292Sakito 		case KS_CTRL:
247*57292Sakito 			ctrl_flag  = 1 - updown;
248*57292Sakito 			break;
249*57292Sakito 
250*57292Sakito 		case KS_META:
251*57292Sakito 			meta_flag  = 1 - updown;
252*57292Sakito 			break;
253*57292Sakito 		}
254*57292Sakito 		break;
255*57292Sakito 
256*57292Sakito 	default:
257*57292Sakito 		break;
258*57292Sakito 	}
259*57292Sakito 
260*57292Sakito 	c |= bmc_keymap[code].km_code[shift_flag];
261*57292Sakito 
262*57292Sakito 	if (bmc_keymap[code].km_type == KC_CODE) {
263*57292Sakito 		if (meta_flag)
264*57292Sakito 			c |= 0x0080;
265*57292Sakito 		if (ctrl_flag)
266*57292Sakito 			c &= 0xFF1F;
267*57292Sakito 	}
268*57292Sakito 
269*57292Sakito 	return(c);
270*57292Sakito }
271*57292Sakito 
272*57292Sakito 
273*57292Sakito /*
27456876Sakito  *  probe routine
27556876Sakito  */
27656876Sakito 
27756876Sakito bmcprobe(hd)
27856876Sakito 	register struct hp_device *hd;
27956876Sakito {
28056876Sakito }
28156876Sakito 
28256876Sakito bmcinit(port)
28356876Sakito 	register int port;
28456876Sakito {
28556876Sakito 	register struct bmc_softc *sc = &bmc_softc[0];
28656876Sakito 
28756876Sakito 	/*
28856876Sakito 	 * if BMC is already configured, should be skipped.
28956876Sakito          */
29056876Sakito 	if (bmc_config_done)
29156876Sakito 		return(0);
29256876Sakito 
29356876Sakito 	/*
29456876Sakito 	 * Check out bitmap Interface board
29556876Sakito 	 */
29656876Sakito 
29756876Sakito 	/* port checking (for keyboard) */
29856876Sakito 	if (port != 1)
29956876Sakito 		return(0);
30056876Sakito 
30156876Sakito 	/* locate the major number */
30256876Sakito 	for (bmcmajor = 0; bmcmajor < nchrdev; bmcmajor++)
30356876Sakito 		if (cdevsw[bmcmajor].d_open == bmcopen)
30456876Sakito 			break;
30556876Sakito 
30656876Sakito 	sc->sc_pc = sio_port_assign(port, bmcmajor, 0, bmcintr);
30756876Sakito 
30856876Sakito 	printf("bmc%d: port %d, address 0x%x\n", sc->sc_pc->pc_unit, port, sc->sc_pc->pc_addr);
30956876Sakito 
31056876Sakito 	bmdinit();
31156876Sakito 
31256876Sakito 	bmc_config_done = 1;
31356876Sakito 	return(1);
31456876Sakito }
31556876Sakito 
31656876Sakito 
31756876Sakito /*
31856876Sakito  *  entry routines
31956876Sakito  */
32056876Sakito 
32156876Sakito /* ARGSUSED */
32256876Sakito #ifdef __STDC__
32356876Sakito bmcopen(dev_t dev, int flag, int mode, struct proc *p)
32456876Sakito #else
32556876Sakito bmcopen(dev, flag, mode, p)
32656876Sakito 	dev_t dev;
32756876Sakito 	int flag, mode;
32856876Sakito 	struct proc *p;
32956876Sakito #endif
33056876Sakito {
33156876Sakito 	register struct tty *tp;
33256876Sakito 	register int unit;
33356876Sakito 	int error = 0;
33456876Sakito 
33556876Sakito 	unit = bmcunit(dev);
33656876Sakito 	if (unit >= NBMC)
33756876Sakito 		return (ENXIO);
33856876Sakito 	tp = &bmc_tty[unit];
33956876Sakito 	tp->t_oproc = bmcstart;
34056876Sakito 	tp->t_param = bmcparam;
34156876Sakito 	tp->t_dev = dev;
34256876Sakito 	if ((tp->t_state & TS_ISOPEN) == 0) {
34356876Sakito 		tp->t_state |= TS_WOPEN;
34456876Sakito 		ttychars(tp);
34556876Sakito 		if (tp->t_ispeed == 0) {
34656876Sakito 			tp->t_iflag = TTYDEF_IFLAG;
34756876Sakito 			tp->t_oflag = TTYDEF_OFLAG;
34856876Sakito 			tp->t_cflag = TTYDEF_CFLAG;
34956876Sakito /*			tp->t_cflag = (CREAD | CS8 | HUPCL);	*/
35056876Sakito 			tp->t_lflag = TTYDEF_LFLAG;
35156876Sakito 			tp->t_ispeed = tp->t_ospeed = bmcdefaultrate;
35256876Sakito 		}
35356876Sakito 		bmcparam(tp, &tp->t_termios);
35456876Sakito 		ttsetwater(tp);
35556876Sakito 	} else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
35656876Sakito 		return (EBUSY);
35756876Sakito 	tp->t_state |= TS_CARR_ON;
35856876Sakito 	(void) spltty();
35956876Sakito 	while ((flag&O_NONBLOCK) == 0 && (tp->t_cflag&CLOCAL) == 0 &&
36056876Sakito 	       (tp->t_state & TS_CARR_ON) == 0) {
36156876Sakito 		tp->t_state |= TS_WOPEN;
36256876Sakito 		if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH,
36356876Sakito 		    ttopen, 0))
36456876Sakito 			break;
36556876Sakito 	}
36656876Sakito 	(void) spl0();
36756876Sakito 	if (error == 0)
36856876Sakito 		error = (*linesw[tp->t_line].l_open)(dev, tp);
36956876Sakito 
37056876Sakito 	return (error);
37156876Sakito }
37256876Sakito 
37356876Sakito /*ARGSUSED*/
37456876Sakito bmcclose(dev, flag, mode, p)
37556876Sakito 	dev_t dev;
37656876Sakito 	int flag, mode;
37756876Sakito 	struct proc *p;
37856876Sakito {
37956876Sakito 	register struct tty *tp;
38056876Sakito 	register int unit;
38156876Sakito 
38256876Sakito 	unit = bmcunit(dev);
38356876Sakito 	tp = &bmc_tty[unit];
38456876Sakito 	(*linesw[tp->t_line].l_close)(tp, flag);
38556876Sakito 	ttyclose(tp);
38656876Sakito 	return (0);
38756876Sakito }
38856876Sakito 
38956876Sakito bmcread(dev, uio, flag)
39056876Sakito 	dev_t dev;
39156876Sakito 	struct uio *uio;
39256876Sakito {
39356876Sakito 	register struct tty *tp = &bmc_tty[bmcunit(dev)];
39456876Sakito 
39556876Sakito 	return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
39656876Sakito }
39756876Sakito 
39856876Sakito bmcwrite(dev, uio, flag)
39956876Sakito 	dev_t dev;
40056876Sakito 	struct uio *uio;
40156876Sakito {
40257125Sakito 	register int unit = bmcunit(dev);
40357125Sakito 	register struct tty *tp = &bmc_tty[unit];
40456876Sakito 
40557125Sakito 	if ((unit == bmcconsole) && constty &&
40657125Sakito 	    (constty->t_state&(TS_CARR_ON|TS_ISOPEN))==(TS_CARR_ON|TS_ISOPEN))
40757125Sakito 		tp = constty;
40857125Sakito 
40956876Sakito 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
41056876Sakito }
41156876Sakito 
41256876Sakito /*
41356876Sakito  * Stop output on a line.
41456876Sakito  */
41556876Sakito /*ARGSUSED*/
41656876Sakito bmcstop(tp, flag)
41756876Sakito 	register struct tty *tp;
41856876Sakito {
41956876Sakito 	register int s;
42056876Sakito 
42156876Sakito 	s = spltty();
42256876Sakito 	if (tp->t_state & TS_BUSY) {
42356876Sakito 		if ((tp->t_state&TS_TTSTOP)==0)
42456876Sakito 			tp->t_state |= TS_FLUSH;
42556876Sakito 	}
42656876Sakito 	splx(s);
42756876Sakito }
42856876Sakito 
42956876Sakito bmcioctl(dev, cmd, data, flag, p)
43056876Sakito 	dev_t dev;
43156876Sakito 	int cmd;
43256876Sakito 	caddr_t data;
43356876Sakito 	int flag;
43456876Sakito 	struct proc *p;
43556876Sakito {
43656876Sakito 	register struct tty *tp;
43756876Sakito 	register int unit = bmcunit(dev);
43856876Sakito 	register int error;
43956876Sakito 
44056876Sakito 	tp = &bmc_tty[unit];
44156876Sakito 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
44256876Sakito 	if (error >= 0)
44356876Sakito 		return (error);
44456876Sakito 	error = ttioctl(tp, cmd, data, flag);
44556876Sakito 	if (error >= 0)
44656876Sakito 		return (error);
44756876Sakito 
44856876Sakito 	switch (cmd) {
44956876Sakito 	default:
45056876Sakito 		return (ENOTTY);
45156876Sakito 	}
45256876Sakito 	return (0);
45356876Sakito }
45456876Sakito 
45556876Sakito /*
45656876Sakito  *
45756876Sakito  */
45856876Sakito void
45956876Sakito bmcstart(tp)
46056876Sakito 	register struct tty *tp;
46156876Sakito {
46256876Sakito 	int unit = bmcunit(tp->t_dev);
46356876Sakito 	register struct bmc_softc *sc = &bmc_softc[unit];
46456876Sakito 	register int cc, s;
46556876Sakito 	int hiwat = 0;
46656876Sakito 
46756876Sakito 	s = spltty();
46856876Sakito 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
46956876Sakito 		splx(s);
47056876Sakito 		return;
47156876Sakito 	}
47256876Sakito 	tp->t_state |= TS_BUSY;
47356876Sakito 	cc = tp->t_outq.c_cc;
47456876Sakito 	if (cc <= tp->t_lowat) {
47556876Sakito 		if (tp->t_state & TS_ASLEEP) {
47656876Sakito 			tp->t_state &= ~TS_ASLEEP;
47756876Sakito 			wakeup((caddr_t)&tp->t_outq);
47856876Sakito 		}
47956876Sakito 		selwakeup(&tp->t_wsel);
48056876Sakito 	}
48156876Sakito 	/*
48256876Sakito 	 * Limit the amount of output we do in one burst
48356876Sakito 	 * to prevent hogging the CPU.
48456876Sakito 	 */
48556876Sakito 	while (--cc >= 0) {
48656876Sakito 		register int c;
48756876Sakito 
48856876Sakito 		c = getc(&tp->t_outq);
48956876Sakito 		/*
49056876Sakito 		 * iteputchar() may take a long time and we don't want to
49156876Sakito 		 * block all interrupts for long periods of time.  Since
49256876Sakito 		 * there is no need to stay at high priority while outputing
49356876Sakito 		 * the character (since we don't have to worry about
49456876Sakito 		 * interrupts), we don't.  We just need to make sure that
49556876Sakito 		 * we don't reenter iteputchar, which is guarenteed by the
49656876Sakito 		 * earlier setting of TS_BUSY.
49756876Sakito 		 */
49856876Sakito 		splx(s);
49956876Sakito 		bmdputc(c & sc->sc_mask);
50056876Sakito 		spltty();
50156876Sakito 	}
50256876Sakito 	tp->t_state &= ~TS_BUSY;
50356876Sakito 	splx(s);
50456876Sakito }
50556876Sakito 
50656876Sakito bmcparam(tp, t)
50756876Sakito 	register struct tty *tp;
50856876Sakito 	register struct termios *t;
50956876Sakito {
51056876Sakito 	int unit = bmcunit(tp->t_dev);
51156876Sakito 	register struct bmc_softc *sc = &bmc_softc[unit];
51256876Sakito 	register int cflag = t->c_cflag;
51356876Sakito 
51456876Sakito         /* and copy to tty */
51556876Sakito         tp->t_ispeed = t->c_ispeed;
51656876Sakito         tp->t_ospeed = t->c_ospeed;
51756876Sakito         tp->t_cflag = cflag;
51856876Sakito 
51956876Sakito 	/*
52056876Sakito 	 * change line speed
52156876Sakito 	 */
52256876Sakito 
52356876Sakito 	switch (cflag&CSIZE) {
52456876Sakito 	case CS5:
52556876Sakito 		sc->sc_mask = 0x1F ; break;
52656876Sakito 	case CS6:
52756876Sakito 		sc->sc_mask = 0x3F ; break;
52856876Sakito 	case CS7:
52956876Sakito 		sc->sc_mask = 0x7F ; break;
53056876Sakito 	case CS8:
53156876Sakito 		sc->sc_mask = 0xFF ; break;
53256876Sakito 	}
53356876Sakito 
53456876Sakito 	/*
53556876Sakito 	 * parity
53656876Sakito 	 */
53756876Sakito 
53856876Sakito 	/*
53956876Sakito 	 * stop bit
54056876Sakito 	 */
54156876Sakito 
54256876Sakito 	return (0);
54356876Sakito }
54456876Sakito 
54556876Sakito 
54656876Sakito /*
54756876Sakito  *  interrupt handling
54856876Sakito  */
54956876Sakito 
55056876Sakito bmcintr(unit)
55156876Sakito 	register int unit;
55256876Sakito {
55356876Sakito 	register struct siodevice *sio = bmc_softc[unit].sc_pc->pc_addr;
55456876Sakito 	register struct tty *tp;
55556876Sakito 	register u_char code;
55656876Sakito 	register int c;
55756876Sakito 	int s, rr;
55856876Sakito 
55956876Sakito 	tp = &bmc_tty[unit];
56056876Sakito 	rr = siogetreg(sio);
56156876Sakito 
56256876Sakito 	if (rr & RR_RXRDY) {
56356876Sakito 		code = sio->sio_data;
564*57292Sakito 		c = bmc_decode(code);
56556876Sakito 		if (c & KC_TYPE)			/* skip special codes */
56656876Sakito 			return;
56756876Sakito 		code = (c & KC_CHAR);
56856876Sakito 		if ((tp->t_state & TS_ISOPEN) != 0)
56956876Sakito 			(*linesw[tp->t_line].l_rint)(code, tp);
57056876Sakito 	}
57156876Sakito }
57256876Sakito 
57356876Sakito /*
57456876Sakito  * Following are all routines needed for SIO to act as console
57556876Sakito  */
57656876Sakito #include "../luna68k/cons.h"
57756876Sakito 
57856876Sakito bmccnprobe(cp)
57956876Sakito 	register struct consdev *cp;
58056876Sakito {
58156876Sakito #ifdef BMC_NOCONSOLE
58256876Sakito 	cp->cn_pri = CN_DEAD;
58356876Sakito 	return;
58456876Sakito #else
58556876Sakito 	/* check DIP-SW setup */
58656876Sakito 	/* check bitmap interface board */
58756876Sakito 
58856876Sakito 	/* locate the major number */
58956876Sakito 	for (bmcmajor = 0; bmcmajor < nchrdev; bmcmajor++)
59056876Sakito 		if (cdevsw[bmcmajor].d_open == bmcopen)
59156876Sakito 			break;
59256876Sakito 
59356876Sakito 	/* initialize required fields */
59456876Sakito 	cp->cn_dev = makedev(bmcmajor, 0);
59556876Sakito 	cp->cn_tp  = &bmc_tty[0];
59656876Sakito 	cp->cn_pri = CN_INTERNAL;
59756876Sakito 
59856876Sakito 	bmc_config_done = 1;
59956876Sakito #endif
60056876Sakito }
60156876Sakito 
60256876Sakito bmccninit(cp)
60356876Sakito 	struct consdev *cp;
60456876Sakito {
60556876Sakito 	int unit = bmcunit(cp->cn_dev);
60656876Sakito 	register struct bmc_softc *sc = &bmc_softc[0];
60756876Sakito 
60856876Sakito 	sioinit((struct siodevice *) SIO_HARDADDR, bmcdefaultrate);
60956876Sakito 	bmdinit();
61056876Sakito 
61156876Sakito 	/* port assign */
61256876Sakito 	sc->sc_pc = sio_port_assign(BMC_CNPORT, bmcmajor, 0, bmcintr);
61356876Sakito 
61456876Sakito 	bmcconsole = unit;
61556876Sakito }
61656876Sakito 
61756876Sakito bmccngetc(dev)
61856876Sakito 	dev_t dev;
61956876Sakito {
62056876Sakito 	struct bmc_softc *sc = &bmc_softc[bmcunit(dev)];
62156876Sakito 	struct sio_portc *pc = sc->sc_pc;
62256876Sakito 	register int c;
62356876Sakito 	register u_char code;
62456876Sakito 
62556876Sakito 	do {
62656876Sakito 		code = sio_imgetc(pc->pc_addr);
627*57292Sakito 	} while ((c = bmc_decode(code)) & KC_TYPE);
62856876Sakito 
62956876Sakito 	return(c);
63056876Sakito }
63156876Sakito 
63256876Sakito bmccnputc(dev, c)
63356876Sakito 	dev_t dev;
63456876Sakito 	int c;
63556876Sakito {
63656876Sakito 	struct bmc_softc *sc = &bmc_softc[bmcunit(dev)];
63756876Sakito 	struct sio_portc *pc = sc->sc_pc;
63856876Sakito 
63956876Sakito 	bmdputc(c);
64056876Sakito }
64156876Sakito #endif
642