Initial import from FreeBSD RELENG_4:
[games.git] / sys / dev / serial / dgb / dgmreg.h
1 /*-
2  * $FreeBSD: src/sys/dev/dgb/dgmreg.h,v 1.4.2.1 2001/09/23 19:54:54 brian Exp $
3  *
4  *  Digiboard driver.
5  *
6  *  Stage 1. "Better than nothing".
7  *  Stage 2. "Gee, it works!".
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions, and the following disclaimer,
14  *    without modification, immediately at the beginning of the file.
15  * 2. Redistributions of binary code must retain the above copyright
16  *    notice, this list of conditions, and the following disclaimer,
17  *    without modification, in the accompanying documentation.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
25  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *  Written by Sergey Babkin,
34  *      Joint Stock Commercial Bank "Chelindbank"
35  *      (Chelyabinsk, Russia)
36  *      babkin@freebsd.org
37  */
38
39 #define MAX_DGM_PORTS 64
40
41 /* digi.h */
42 /*          Definitions for DigiBoard ditty(1) command.                 */
43
44 #if !defined(TIOCMODG)
45 #define TIOCMODG        ('d'<<8) | 250          /* get modem ctrl state */
46 #define TIOCMODS        ('d'<<8) | 251          /* set modem ctrl state */
47 #endif
48
49 #if !defined(TIOCMSET)
50 #define TIOCMSET        ('d'<<8) | 252          /* set modem ctrl state */
51 #define TIOCMGET        ('d'<<8) | 253          /* set modem ctrl state */
52 #endif
53
54 #if !defined(TIOCMBIC)
55 #define TIOCMBIC        ('d'<<8) | 254          /* set modem ctrl state */
56 #define TIOCMBIS        ('d'<<8) | 255          /* set modem ctrl state */
57 #endif
58
59 #if !defined(TIOCSDTR)
60 #define TIOCSDTR        ('e'<<8) | 0            /* set DTR              */
61 #define TIOCCDTR        ('e'<<8) | 1            /* clear DTR            */
62 #endif
63
64 /************************************************************************
65  * Ioctl command arguments for DIGI parameters.
66  ************************************************************************/
67 #define DIGI_GETA       ('e'<<8) | 94           /* Read params          */
68
69 #define DIGI_SETA       ('e'<<8) | 95           /* Set params           */
70 #define DIGI_SETAW      ('e'<<8) | 96           /* Drain & set params   */
71 #define DIGI_SETAF      ('e'<<8) | 97           /* Drain, flush & set params */
72
73 #define DIGI_GETFLOW    ('e'<<8) | 99           /* Get startc/stopc flow */
74                                                 /* control characters    */
75 #define DIGI_SETFLOW    ('e'<<8) | 100          /* Set startc/stopc flow */
76                                                 /* control characters    */
77 #define DIGI_GETAFLOW   ('e'<<8) | 101          /* Get Aux. startc/stopc */
78                                                 /* flow control chars    */
79 #define DIGI_SETAFLOW   ('e'<<8) | 102          /* Set Aux. startc/stopc */
80                                                 /* flow control chars    */
81
82 struct  digiflow_struct {
83         unsigned char   startc;                         /* flow cntl start char */
84         unsigned char   stopc;                          /* flow cntl stop char  */
85 };
86
87 typedef struct digiflow_struct digiflow_t;
88
89
90 /************************************************************************
91  * Values for digi_flags 
92  ************************************************************************/
93 #define DIGI_IXON       0x0001          /* Handle IXON in the FEP       */
94 #define DIGI_FAST       0x0002          /* Fast baud rates              */
95 #define RTSPACE         0x0004          /* RTS input flow control       */
96 #define CTSPACE         0x0008          /* CTS output flow control      */
97 #define DSRPACE         0x0010          /* DSR output flow control      */
98 #define DCDPACE         0x0020          /* DCD output flow control      */
99 #define DTRPACE         0x0040          /* DTR input flow control       */
100 #define DIGI_FORCEDCD   0x0100          /* Force carrier                */
101 #define DIGI_ALTPIN     0x0200          /* Alternate RJ-45 pin config   */
102 #define DIGI_AIXON      0x0400          /* Aux flow control in fep      */
103
104
105 /************************************************************************
106  * Structure used with ioctl commands for DIGI parameters.
107  ************************************************************************/
108 struct digi_struct {
109         unsigned short  digi_flags;             /* Flags (see above)    */
110 };
111
112 typedef struct digi_struct digi_t;
113
114 /* fep.h */
115
116 #define FEP_CSTART       0x400L
117 #define FEP_CMAX         0x800L
118 #define FEP_ISTART       0x800L
119 #define FEP_IMAX         0xC00L
120 #define FEP_CIN          0xD10L
121 #define FEP_GLOBAL       0xD10L
122 #define FEP_EIN          0xD18L
123 #define FEPSTAT      0xD20L
124 #define CHANSTRUCT   0x1000L
125 #define RXTXBUF      0x4000L
126
127
128 struct global_data {
129         volatile ushort cin;
130         volatile ushort cout;
131         volatile ushort cstart;
132         volatile ushort cmax;
133         volatile ushort ein;
134         volatile ushort eout;
135         volatile ushort istart;
136         volatile ushort imax;
137 };
138
139
140 struct board_chan {
141         int filler1; 
142         int filler2;
143         volatile ushort tseg;
144         volatile ushort tin;
145         volatile ushort tout;
146         volatile ushort tmax;
147         
148         volatile ushort rseg;
149         volatile ushort rin;
150         volatile ushort rout;
151         volatile ushort rmax;
152         
153         volatile ushort tlow;
154         volatile ushort rlow;
155         volatile ushort rhigh;
156         volatile ushort incr;
157         
158         volatile ushort etime;
159         volatile ushort edelay;
160         volatile u_char *dev;
161         
162         volatile ushort iflag;
163         volatile ushort oflag;
164         volatile ushort cflag;
165         volatile ushort gmask;
166         
167         volatile ushort col;
168         volatile ushort delay;
169         volatile ushort imask;
170         volatile ushort tflush;
171
172         int filler3;
173         int filler4;
174         int filler5;
175         int filler6;
176         
177         volatile u_char num;
178         volatile u_char ract;
179         volatile u_char bstat;
180         volatile u_char tbusy;
181         volatile u_char iempty;
182         volatile u_char ilow;
183         volatile u_char idata;
184         volatile u_char eflag;
185         
186         volatile u_char tflag;
187         volatile u_char rflag;
188         volatile u_char xmask;
189         volatile u_char xval;
190         volatile u_char mstat;
191         volatile u_char mchange;
192         volatile u_char mint;
193         volatile u_char lstat;
194
195         volatile u_char mtran;
196         volatile u_char orun;
197         volatile u_char startca;
198         volatile u_char stopca;
199         volatile u_char startc;
200         volatile u_char stopc;
201         volatile u_char vnext;
202         volatile u_char hflow;
203
204         volatile u_char fillc;
205         volatile u_char ochar;
206         volatile u_char omask;
207
208         u_char filler7;
209         u_char filler8[28];
210 }; 
211
212
213 #define SRXLWATER      0xE0
214 #define SRXHWATER      0xE1
215 #define STOUT          0xE2
216 #define PAUSETX        0xE3
217 #define RESUMETX       0xE4
218 #define SAUXONOFFC     0xE6
219 #define SENDBREAK      0xE8
220 #define SETMODEM       0xE9
221 #define SETIFLAGS      0xEA
222 #define SONOFFC        0xEB
223 #define STXLWATER      0xEC
224 #define PAUSERX        0xEE
225 #define RESUMERX       0xEF
226 #define SETBUFFER      0xF2
227 #define SETCOOKED      0xF3
228 #define SETHFLOW       0xF4
229 #define SETCTRLFLAGS   0xF5
230 #define SETVNEXT       0xF6
231
232
233
234 #define BREAK_IND        0x01
235 #define LOWTX_IND        0x02
236 #define EMPTYTX_IND      0x04
237 #define DATA_IND         0x08
238 #define MODEMCHG_IND     0x20
239
240 #define ALL_IND (BREAK_IND|LOWTX_IND|EMPTYTX_IND|DATA_IND|MODEMCHG_IND)
241
242 #define CD    0x80      
243 #define DSR   0x20
244 #define CTS   0x10
245 #define DTR   0x01
246 #define RTS   0x02
247 #define RI    0x40
248
249 #define FEPCODESEG  0x0200L
250 #define FEPCODE     0x2000L
251 #define BIOSCODE    0xf800L
252 #define BIOSOFFSET  0x1000L
253
254 #define MISCGLOBAL  0x0C00L
255 #define NPORT       0x0C02L
256 #define MBOX        0x0C40L
257 #define BOTWIN      0x100L
258 #define TOPWIN      0xFF00L
259
260 #define FEPCLR      0x00
261 #define FEPMEM      0x02
262 #define FEPRST      0x04
263 #define FEPINT      0x08
264 #define FEPMASK     0x0e
265 #define FEPWIN      0x80
266
267 #define PCXI    0
268 #define PCXE    1
269 #define PCXEVE  2
270 #define PCXEM   3
271
272 static char * const board_desc[] = {
273         "PC/Xi (64K)",
274         "PC/Xe (64K)",
275         "PC/Xe (8K) ",
276         "PC/Xem ",
277 };
278
279 #define STARTC      021
280 #define STOPC       023
281 #define IAIXON      0x2000
282
283
284 struct board_info       {
285         u_char status;
286         u_char type;
287         u_char altpin;
288         ushort numports;
289         ushort port;
290         u_long  membase;
291 };
292
293
294 #define TXSTOPPED   0x1
295 #define LOWWAIT         0x2
296 #define EMPTYWAIT       0x4
297
298 #define DISABLED   0
299 #define ENABLED    1
300 #define OFF        0
301 #define ON         1
302
303 #define FEPTIMEOUT 200000  
304 #define SERIAL_TYPE_NORMAL      1
305 #define SERIAL_TYPE_CALLOUT     2
306 #define PCXE_EVENT_HANGUP   1
307
308 struct channel {
309         u_char unit;           /* board unit number */
310         u_char omodem;         /* FEP output modem status     */
311         u_char imodem;         /* FEP input modem status      */
312         u_char modemfake;      /* Modem values to be forced   */
313         u_char modem;          /* Force values                */
314         u_char hflow;
315         u_char dsr;
316         u_char dcd;
317         u_char stopc;
318         u_char startc;
319         u_char stopca;
320         u_char startca;
321         u_char fepstopc;
322         u_char fepstartc;
323         u_char fepstopca;
324         u_char fepstartca;
325         u_char txwin;
326         u_char rxwin;
327         ushort fepiflag;
328         ushort fepcflag;
329         ushort fepoflag;
330         ushort txbufhead;
331         ushort txbufsize;
332         ushort rxbufhead;
333         ushort rxbufsize;
334         int close_delay;
335         int count;
336         int blocked_open;
337         int event;
338         int asyncflags;
339         uint dev;
340         long session;
341         long pgrp;
342         u_long statusflags;
343         u_long c_iflag;
344         u_long c_cflag;
345         u_long c_lflag;
346         u_long c_oflag;
347         u_char *txptr;
348         u_char *rxptr;
349         struct board_info *board;
350         struct board_chan *brdchan;
351         struct digi_struct digiext;
352         struct tty *tty;
353         struct termios normal_termios;
354         struct termios callout_termios;
355         volatile struct global_data *mailbox;
356 };
357
358 /* flags for configuring */
359
360 #define DGBFLAG_ALTPIN  0x0001  /* chande DCD and DCD */
361 #define DGBFLAG_NOWIN   0x0002  /* use windowed PC/Xe as non-windowed */
362
363 #define DB_RD     0x0001
364 #define DB_WR     0x0002
365 #define DB_WIN    0x0004
366 #define DB_INFO   0x0008
367 #define DB_EXCEPT 0x0010
368 #define DB_OPEN   0x0100
369 #define DB_CLOSE  0x0200
370 #define DB_DATA   0x0400
371 #define DB_RXDATA 0x0401
372 #define DB_TXDATA 0x0402
373 #define DB_EVENT  0x0800
374 #define DB_MODEM  0x1000
375 #define DB_BREAK  0x2000
376 #define DB_PARAM  0x4000
377 #define DB_FEP    0x8000
378
379 /* debugging printout */
380
381 #ifdef DEBUG
382 #define DPRINT1(l,a1)                   (dgmdebug&l ? printf(a1) : 0)
383 #define DPRINT2(l,a1,a2)                (dgmdebug&l ? printf(a1,a2) : 0)
384 #define DPRINT3(l,a1,a2,a3)             (dgmdebug&l ? printf(a1,a2,a3) : 0)
385 #define DPRINT4(l,a1,a2,a3,a4)          (dgmdebug&l ? printf(a1,a2,a3,a4) : 0)
386 #define DPRINT5(l,a1,a2,a3,a4,a5)       (dgmdebug&l ? printf(a1,a2,a3,a4,a5) : 0)
387 #define DPRINT6(l,a1,a2,a3,a4,a5,a6)    (dgmdebug&l ? printf(a1,a2,a3,a4,a5,a6) : 0)
388 #define DPRINT7(l,a1,a2,a3,a4,a5,a6,a7) (dgmdebug&l ? printf(a1,a2,a3,a4,a5,a6,a7) : 0)
389 #else
390 #define DPRINT1(l,a1)
391 #define DPRINT2(l,a1,a2)
392 #define DPRINT3(l,a1,a2,a3)
393 #define DPRINT4(l,a1,a2,a3,a4)
394 #define DPRINT5(l,a1,a2,a3,a4,a5)
395 #define DPRINT6(l,a1,a2,a3,a4,a5,a6)
396 #define DPRINT7(l,a1,a2,a3,a4,a5,a6,a7)
397 #endif
398
399
400         /* These are termios bits as the FEP understands them */
401
402 /* c_cflag bits */
403 #define FEP_CBAUD       0x00000f
404 #define  FEP_B0         0x000000                /* hang up */
405 #define  FEP_B50        0x000001
406 #define  FEP_B75        0x000002
407 #define  FEP_B110       0x000003
408 #define  FEP_B134       0x000004
409 #define  FEP_B150       0x000005
410 #define  FEP_B200       0x000006
411 #define  FEP_B300       0x000007
412 #define  FEP_B600       0x000008
413 #define  FEP_B1200      0x000009
414 #define  FEP_B1800      0x00000a
415 #define  FEP_B2400      0x00000b
416 #define  FEP_B4800      0x00000c
417 #define  FEP_B9600      0x00000d
418 #define  FEP_B19200     0x00000e
419 #define  FEP_B38400     0x00000f
420 #define FEP_EXTA FEP_B19200
421 #define FEP_EXTB FEP_B38400
422 #define FEP_CSIZE       0x000030
423 #define   FEP_CS5       0x000000
424 #define   FEP_CS6       0x000010
425 #define   FEP_CS7       0x000020
426 #define   FEP_CS8       0x000030
427 #define FEP_CSTOPB      0x000040
428 #define FEP_CREAD       0x000080
429 #define FEP_PARENB      0x000100
430 #define FEP_PARODD      0x000200
431 #define FEP_CLOCAL      0x000800
432 #define FEP_FASTBAUD    0x000400
433 /* c_iflag bits */
434 #define FEP_IGNBRK      0000001
435 #define FEP_BRKINT      0000002
436 #define FEP_IGNPAR      0000004
437 #define FEP_PARMRK      0000010
438 #define FEP_INPCK       0000020
439 #define FEP_ISTRIP      0000040
440 #define FEP_IXON        0002000
441 #define FEP_IXANY       0004000
442 #define FEP_IXOFF       0010000