- Kai Germaschewski: ymfpci cleanups and resource leak fixes
[davej-history.git] / drivers / char / dz.h
blobbf106e1ea786c8d3a55b6cb51f50ede3a954d7ed
1 /*
2 * dz.h: Serial port driver for DECStations equiped
3 * with the DZ chipset.
5 * Copyright (C) 1998 Olivier A. D. Lebaillif
6 *
7 * Email: olivier.lebaillif@ifrsys.com
9 */
10 #ifndef DZ_SERIAL_H
11 #define DZ_SERIAL_H
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) */
80 #define DZ_B50 0x0000
81 #define DZ_B75 0x0100
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 */
109 #define DZ_NB_PORT 4
111 #define DZ_XMIT_SIZE 4096 /* buffer size */
112 #define WAKEUP_CHARS DZ_XMIT_SIZE/4
114 #define DZ_EVENT_WRITE_WAKEUP 0
116 #ifndef MIN
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 */
134 struct dz_serial {
135 unsigned port; /* base address for the port */
136 int type;
137 int flags;
138 int baud_base;
139 int blocked_open;
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 */
153 int magic;
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 struct termios normal_termios;
160 struct termios callout_termios;
161 wait_queue_head_t open_wait;
162 wait_queue_head_t close_wait;
164 long session; /* Session of opening process */
165 long pgrp; /* pgrp of opening process */
167 unsigned char is_console; /* flag indicating a serial console */
168 unsigned char is_initialized;
171 static struct dz_serial multi[DZ_NB_PORT]; /* Four serial lines in the DZ chip */
172 static struct dz_serial *dz_console;
173 static struct tty_driver serial_driver, callout_driver;
175 static struct tty_struct *serial_table[DZ_NB_PORT];
176 static struct termios *serial_termios[DZ_NB_PORT];
177 static struct termios *serial_termios_locked[DZ_NB_PORT];
179 static int serial_refcount;
182 * tmp_buf is used as a temporary buffer by serial_write. We need to
183 * lock it in case the copy_from_user blocks while swapping in a page,
184 * and some other program tries to do a serial write at the same time.
185 * Since the lock will only come under contention when the system is
186 * swapping and available memory is low, it makes sense to share one
187 * buffer across all the serial ports, since it significantly saves
188 * memory if large numbers of serial ports are open.
190 static unsigned char *tmp_buf;
191 static DECLARE_MUTEX(tmp_buf_sem);
193 static char *dz_name = "DECstation DZ serial driver version ";
194 static char *dz_version = "1.02";
196 static inline unsigned short dz_in (struct dz_serial *, unsigned);
197 static inline void dz_out (struct dz_serial *, unsigned, unsigned short);
199 static inline void dz_sched_event (struct dz_serial *, int);
200 static inline void receive_chars (struct dz_serial *);
201 static inline void transmit_chars (struct dz_serial *);
202 static inline void check_modem_status (struct dz_serial *);
204 static void dz_stop (struct tty_struct *);
205 static void dz_start (struct tty_struct *);
206 static void dz_interrupt (int, void *, struct pt_regs *);
207 static void do_serial_bh (void);
208 static void do_softint (void *);
209 static void do_serial_hangup (void *);
210 static void change_speed (struct dz_serial *);
211 static void dz_flush_chars (struct tty_struct *);
212 static void dz_console_print (struct console *, const char *, unsigned int);
213 static void dz_flush_buffer (struct tty_struct *);
214 static void dz_throttle (struct tty_struct *);
215 static void dz_unthrottle (struct tty_struct *);
216 static void dz_send_xchar (struct tty_struct *, char);
217 static void shutdown (struct dz_serial *);
218 static void send_break (struct dz_serial *, int);
219 static void dz_set_termios (struct tty_struct *, struct termios *);
220 static void dz_close (struct tty_struct *, struct file *);
221 static void dz_hangup (struct tty_struct *);
222 static void show_serial_version (void);
224 static int dz_write (struct tty_struct *, int, const unsigned char *, int);
225 static int dz_write_room (struct tty_struct *);
226 static int dz_chars_in_buffer (struct tty_struct *);
227 static int startup (struct dz_serial *);
228 static int get_serial_info (struct dz_serial *, struct serial_struct *);
229 static int set_serial_info (struct dz_serial *, struct serial_struct *);
230 static int get_lsr_info (struct dz_serial *, unsigned int *);
231 static int dz_ioctl (struct tty_struct *, struct file *, unsigned int, unsigned long);
232 static int block_til_ready (struct tty_struct *, struct file *, struct dz_serial *);
233 static int dz_open (struct tty_struct *, struct file *);
235 #ifdef MODULE
236 int init_module (void)
237 void cleanup_module (void)
238 #endif
240 #endif
242 #endif /* DZ_SERIAL_H */