2 * dz.h: Serial port driver for DECStations equiped
5 * Copyright (C) 1998 Olivier A. D. Lebaillif
7 * Email: olivier.lebaillif@ifrsys.com
14 * Definitions for the Control and Status Received.
16 #define DZ_TRDY 0x8000 /* Transmitter empty */
17 #define DZ_TIE 0x4000 /* Transmitter Interrupt Enable */
18 #define DZ_RDONE 0x0080 /* Receiver data ready */
19 #define DZ_RIE 0x0040 /* Receive Interrupt Enable */
20 #define DZ_MSE 0x0020 /* Master Scan Enable */
21 #define DZ_CLR 0x0010 /* Master reset */
22 #define DZ_MAINT 0x0008 /* Loop Back Mode */
25 * Definitions for the Received buffer.
27 #define DZ_RBUF_MASK 0x00FF /* Data Mask in the Receive Buffer */
28 #define DZ_LINE_MASK 0x0300 /* Line Mask in the Receive Buffer */
29 #define DZ_DVAL 0x8000 /* Valid Data indicator */
30 #define DZ_OERR 0x4000 /* Overrun error indicator */
31 #define DZ_FERR 0x2000 /* Frame error indicator */
32 #define DZ_PERR 0x1000 /* Parity error indicator */
34 #define LINE(x) (x & DZ_LINE_MASK) >> 8 /* Get the line number from the input buffer */
35 #define UCHAR(x) (unsigned char)(x & DZ_RBUF_MASK)
38 * Definitions for the Transmit Register.
40 #define DZ_LINE_KEYBOARD 0x0001
41 #define DZ_LINE_MOUSE 0x0002
42 #define DZ_LINE_MODEM 0x0004
43 #define DZ_LINE_PRINTER 0x0008
45 #define DZ_MODEM_DTR 0x0400 /* DTR for the modem line (2) */
48 * Definitions for the Modem Status Register.
50 #define DZ_MODEM_DSR 0x0200 /* DSR for the modem line (2) */
53 * Definitions for the Transmit Data Register.
55 #define DZ_BRK0 0x0100 /* Break assertion for line 0 */
56 #define DZ_BRK1 0x0200 /* Break assertion for line 1 */
57 #define DZ_BRK2 0x0400 /* Break assertion for line 2 */
58 #define DZ_BRK3 0x0800 /* Break assertion for line 3 */
61 * Definitions for the Line Parameter Register.
63 #define DZ_KEYBOARD 0x0000 /* line 0 = keyboard */
64 #define DZ_MOUSE 0x0001 /* line 1 = mouse */
65 #define DZ_MODEM 0x0002 /* line 2 = modem */
66 #define DZ_PRINTER 0x0003 /* line 3 = printer */
68 #define DZ_CSIZE 0x0018 /* Number of bits per byte (mask) */
69 #define DZ_CS5 0x0000 /* 5 bits per byte */
70 #define DZ_CS6 0x0008 /* 6 bits per byte */
71 #define DZ_CS7 0x0010 /* 7 bits per byte */
72 #define DZ_CS8 0x0018 /* 8 bits per byte */
74 #define DZ_CSTOPB 0x0020 /* 2 stop bits instead of one */
76 #define DZ_PARENB 0x0040 /* Parity enable */
77 #define DZ_PARODD 0x0080 /* Odd parity instead of even */
79 #define DZ_CBAUD 0x0E00 /* Baud Rate (mask) */
82 #define DZ_B110 0x0200
83 #define DZ_B134 0x0300
84 #define DZ_B150 0x0400
85 #define DZ_B300 0x0500
86 #define DZ_B600 0x0600
87 #define DZ_B1200 0x0700
88 #define DZ_B1800 0x0800
89 #define DZ_B2000 0x0900
90 #define DZ_B2400 0x0A00
91 #define DZ_B3600 0x0B00
92 #define DZ_B4800 0x0C00
93 #define DZ_B7200 0x0D00
94 #define DZ_B9600 0x0E00
96 #define DZ_CREAD 0x1000 /* Enable receiver */
97 #define DZ_RXENAB 0x1000 /* enable receive char */
99 * Addresses for the DZ registers
101 #define DZ_CSR 0x00 /* Control and Status Register */
102 #define DZ_RBUF 0x08 /* Receive Buffer */
103 #define DZ_LPR 0x08 /* Line Parameters Register */
104 #define DZ_TCR 0x10 /* Transmitter Control Register */
105 #define DZ_MSR 0x18 /* Modem Status Register */
106 #define DZ_TDR 0x18 /* Transmit Data Register */
111 #define DZ_XMIT_SIZE 4096 /* buffer size */
112 #define WAKEUP_CHARS DZ_XMIT_SIZE/4
114 #define DZ_EVENT_WRITE_WAKEUP 0
117 #define MIN(a,b) ((a) < (b) ? (a) : (b))
119 #define DZ_INITIALIZED 0x80000000 /* Serial port was initialized */
120 #define DZ_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */
121 #define DZ_NORMAL_ACTIVE 0x20000000 /* Normal device is active */
122 #define DZ_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */
123 #define DZ_CLOSING 0x08000000 /* Serial port is closing */
124 #define DZ_CTS_FLOW 0x04000000 /* Do CTS flow control */
125 #define DZ_CHECK_CD 0x02000000 /* i.e., CLOCAL */
127 #define DZ_CLOSING_WAIT_INF 0
128 #define DZ_CLOSING_WAIT_NONE 65535
130 #define DZ_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
131 #define DZ_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
132 #define DZ_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */
135 unsigned port; /* base address for the port */
140 unsigned short close_delay;
141 unsigned short closing_wait;
142 unsigned short line; /* port/line number */
143 unsigned short cflags; /* line configuration flag */
144 unsigned short x_char; /* xon/xoff character */
145 unsigned short read_status_mask; /* mask for read condition */
146 unsigned short ignore_status_mask; /* mask for ignore condition */
147 unsigned long event; /* mask used in BH */
148 unsigned char *xmit_buf; /* Transmit buffer */
149 int xmit_head; /* Position of the head */
150 int xmit_tail; /* Position of the tail */
151 int xmit_cnt; /* Count of the chars in the buffer */
152 int count; /* indicates how many times it has been opened */
155 struct async_icount icount; /* keep track of things ... */
156 struct tty_struct *tty; /* tty associated */
157 struct tq_struct tqueue; /* Queue for BH */
158 struct tq_struct tqueue_hangup;
159 wait_queue_head_t open_wait;
160 wait_queue_head_t close_wait;
162 unsigned char is_console; /* flag indicating a serial console */
163 unsigned char is_initialized;
166 static struct dz_serial multi[DZ_NB_PORT]; /* Four serial lines in the DZ chip */
167 static struct dz_serial *dz_console;
170 * tmp_buf is used as a temporary buffer by serial_write. We need to
171 * lock it in case the copy_from_user blocks while swapping in a page,
172 * and some other program tries to do a serial write at the same time.
173 * Since the lock will only come under contention when the system is
174 * swapping and available memory is low, it makes sense to share one
175 * buffer across all the serial ports, since it significantly saves
176 * memory if large numbers of serial ports are open.
178 static unsigned char *tmp_buf;
179 static DECLARE_MUTEX(tmp_buf_sem);
181 static char *dz_name = "DECstation DZ serial driver version ";
182 static char *dz_version = "1.02";
184 static inline unsigned short dz_in (struct dz_serial *, unsigned);
185 static inline void dz_out (struct dz_serial *, unsigned, unsigned short);
187 static inline void dz_sched_event (struct dz_serial *, int);
188 static inline void receive_chars (struct dz_serial *);
189 static inline void transmit_chars (struct dz_serial *);
190 static inline void check_modem_status (struct dz_serial *);
192 static void dz_stop (struct tty_struct *);
193 static void dz_start (struct tty_struct *);
194 static void dz_interrupt (int, void *, struct pt_regs *);
195 static void do_serial_bh (void);
196 static void do_softint (void *);
197 static void do_serial_hangup (void *);
198 static void change_speed (struct dz_serial *);
199 static void dz_flush_chars (struct tty_struct *);
200 static void dz_console_print (struct console *, const char *, unsigned int);
201 static void dz_flush_buffer (struct tty_struct *);
202 static void dz_throttle (struct tty_struct *);
203 static void dz_unthrottle (struct tty_struct *);
204 static void dz_send_xchar (struct tty_struct *, char);
205 static void shutdown (struct dz_serial *);
206 static void send_break (struct dz_serial *, int);
207 static void dz_set_termios (struct tty_struct *, struct termios *);
208 static void dz_close (struct tty_struct *, struct file *);
209 static void dz_hangup (struct tty_struct *);
210 static void show_serial_version (void);
212 static int dz_write (struct tty_struct *, int, const unsigned char *, int);
213 static int dz_write_room (struct tty_struct *);
214 static int dz_chars_in_buffer (struct tty_struct *);
215 static int startup (struct dz_serial *);
216 static int get_serial_info (struct dz_serial *, struct serial_struct *);
217 static int set_serial_info (struct dz_serial *, struct serial_struct *);
218 static int get_lsr_info (struct dz_serial *, unsigned int *);
219 static int dz_ioctl (struct tty_struct *, struct file *, unsigned int, unsigned long);
220 static int block_til_ready (struct tty_struct *, struct file *, struct dz_serial *);
221 static int dz_open (struct tty_struct *, struct file *);
224 int init_module (void)
225 void cleanup_module (void)
230 #endif /* DZ_SERIAL_H */