Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/drivers/char/riscom.c -- RISCom/8 multiport serial driver. | |
3 | * | |
4 | * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com) | |
5 | * | |
6 | * This code is loosely based on the Linux serial driver, written by | |
9492e135 AC |
7 | * Linus Torvalds, Theodore T'so and others. The RISCom/8 card |
8 | * programming info was obtained from various drivers for other OSes | |
9 | * (FreeBSD, ISC, etc), but no source code from those drivers were | |
1da177e4 LT |
10 | * directly included in this driver. |
11 | * | |
12 | * | |
13 | * This program is free software; you can redistribute it and/or modify | |
14 | * it under the terms of the GNU General Public License as published by | |
15 | * the Free Software Foundation; either version 2 of the License, or | |
16 | * (at your option) any later version. | |
17 | * | |
18 | * This program is distributed in the hope that it will be useful, | |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | * GNU General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU General Public License | |
24 | * along with this program; if not, write to the Free Software | |
25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
26 | * | |
27 | * Revision 1.1 | |
28 | * | |
29 | * ChangeLog: | |
30 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 27-Jun-2001 | |
31 | * - get rid of check_region and several cleanups | |
32 | */ | |
33 | ||
34 | #include <linux/module.h> | |
35 | ||
9492e135 | 36 | #include <linux/io.h> |
1da177e4 LT |
37 | #include <linux/kernel.h> |
38 | #include <linux/sched.h> | |
39 | #include <linux/ioport.h> | |
40 | #include <linux/interrupt.h> | |
41 | #include <linux/errno.h> | |
42 | #include <linux/tty.h> | |
43 | #include <linux/mm.h> | |
44 | #include <linux/serial.h> | |
45 | #include <linux/fcntl.h> | |
46 | #include <linux/major.h> | |
47 | #include <linux/init.h> | |
48 | #include <linux/delay.h> | |
33f0f88f | 49 | #include <linux/tty_flip.h> |
d9afa435 | 50 | #include <linux/spinlock.h> |
1da177e4 | 51 | |
9492e135 | 52 | #include <linux/uaccess.h> |
1da177e4 LT |
53 | |
54 | #include "riscom8.h" | |
55 | #include "riscom8_reg.h" | |
56 | ||
57 | /* Am I paranoid or not ? ;-) */ | |
58 | #define RISCOM_PARANOIA_CHECK | |
59 | ||
9492e135 AC |
60 | /* |
61 | * Crazy InteliCom/8 boards sometimes have swapped CTS & DSR signals. | |
1da177e4 | 62 | * You can slightly speed up things by #undefing the following option, |
9492e135 | 63 | * if you are REALLY sure that your board is correct one. |
1da177e4 LT |
64 | */ |
65 | ||
66 | #define RISCOM_BRAIN_DAMAGED_CTS | |
67 | ||
9492e135 | 68 | /* |
1da177e4 LT |
69 | * The following defines are mostly for testing purposes. But if you need |
70 | * some nice reporting in your syslog, you can define them also. | |
71 | */ | |
72 | #undef RC_REPORT_FIFO | |
73 | #undef RC_REPORT_OVERRUN | |
74 | ||
75 | ||
76 | #define RISCOM_LEGAL_FLAGS \ | |
77 | (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \ | |
78 | ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \ | |
79 | ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP) | |
80 | ||
1da177e4 | 81 | static struct tty_driver *riscom_driver; |
1da177e4 | 82 | |
d9afa435 JG |
83 | static DEFINE_SPINLOCK(riscom_lock); |
84 | ||
1da177e4 LT |
85 | static struct riscom_board rc_board[RC_NBOARD] = { |
86 | { | |
87 | .base = RC_IOBASE1, | |
88 | }, | |
89 | { | |
90 | .base = RC_IOBASE2, | |
91 | }, | |
92 | { | |
93 | .base = RC_IOBASE3, | |
94 | }, | |
95 | { | |
96 | .base = RC_IOBASE4, | |
97 | }, | |
98 | }; | |
99 | ||
100 | static struct riscom_port rc_port[RC_NBOARD * RC_NPORT]; | |
101 | ||
102 | /* RISCom/8 I/O ports addresses (without address translation) */ | |
103 | static unsigned short rc_ioport[] = { | |
fe971071 | 104 | #if 1 |
1da177e4 | 105 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, |
fe971071 | 106 | #else |
1da177e4 LT |
107 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10, |
108 | 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62, | |
109 | 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101 | |
fe971071 | 110 | #endif |
1da177e4 | 111 | }; |
fe971071 | 112 | #define RC_NIOPORT ARRAY_SIZE(rc_ioport) |
1da177e4 LT |
113 | |
114 | ||
9492e135 | 115 | static int rc_paranoia_check(struct riscom_port const *port, |
1da177e4 LT |
116 | char *name, const char *routine) |
117 | { | |
118 | #ifdef RISCOM_PARANOIA_CHECK | |
119 | static const char badmagic[] = KERN_INFO | |
120 | "rc: Warning: bad riscom port magic number for device %s in %s\n"; | |
121 | static const char badinfo[] = KERN_INFO | |
122 | "rc: Warning: null riscom port for device %s in %s\n"; | |
123 | ||
124 | if (!port) { | |
125 | printk(badinfo, name, routine); | |
126 | return 1; | |
127 | } | |
128 | if (port->magic != RISCOM8_MAGIC) { | |
129 | printk(badmagic, name, routine); | |
130 | return 1; | |
131 | } | |
132 | #endif | |
133 | return 0; | |
134 | } | |
135 | ||
136 | /* | |
9492e135 | 137 | * |
1da177e4 | 138 | * Service functions for RISCom/8 driver. |
9492e135 | 139 | * |
1da177e4 LT |
140 | */ |
141 | ||
142 | /* Get board number from pointer */ | |
9492e135 | 143 | static inline int board_No(struct riscom_board const *bp) |
1da177e4 LT |
144 | { |
145 | return bp - rc_board; | |
146 | } | |
147 | ||
148 | /* Get port number from pointer */ | |
9492e135 | 149 | static inline int port_No(struct riscom_port const *port) |
1da177e4 | 150 | { |
9492e135 | 151 | return RC_PORT(port - rc_port); |
1da177e4 LT |
152 | } |
153 | ||
154 | /* Get pointer to board from pointer to port */ | |
9492e135 | 155 | static inline struct riscom_board *port_Board(struct riscom_port const *port) |
1da177e4 LT |
156 | { |
157 | return &rc_board[RC_BOARD(port - rc_port)]; | |
158 | } | |
159 | ||
160 | /* Input Byte from CL CD180 register */ | |
9492e135 AC |
161 | static inline unsigned char rc_in(struct riscom_board const *bp, |
162 | unsigned short reg) | |
1da177e4 LT |
163 | { |
164 | return inb(bp->base + RC_TO_ISA(reg)); | |
165 | } | |
166 | ||
167 | /* Output Byte to CL CD180 register */ | |
9492e135 | 168 | static inline void rc_out(struct riscom_board const *bp, unsigned short reg, |
1da177e4 LT |
169 | unsigned char val) |
170 | { | |
171 | outb(val, bp->base + RC_TO_ISA(reg)); | |
172 | } | |
173 | ||
174 | /* Wait for Channel Command Register ready */ | |
9492e135 | 175 | static void rc_wait_CCR(struct riscom_board const *bp) |
1da177e4 LT |
176 | { |
177 | unsigned long delay; | |
178 | ||
179 | /* FIXME: need something more descriptive then 100000 :) */ | |
9492e135 | 180 | for (delay = 100000; delay; delay--) |
1da177e4 LT |
181 | if (!rc_in(bp, CD180_CCR)) |
182 | return; | |
9492e135 | 183 | |
1da177e4 LT |
184 | printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp)); |
185 | } | |
186 | ||
187 | /* | |
188 | * RISCom/8 probe functions. | |
189 | */ | |
190 | ||
9492e135 | 191 | static int rc_request_io_range(struct riscom_board * const bp) |
1da177e4 LT |
192 | { |
193 | int i; | |
9492e135 AC |
194 | |
195 | for (i = 0; i < RC_NIOPORT; i++) | |
1da177e4 LT |
196 | if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1, |
197 | "RISCom/8")) { | |
198 | goto out_release; | |
199 | } | |
200 | return 0; | |
201 | out_release: | |
202 | printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n", | |
203 | board_No(bp), bp->base); | |
9492e135 | 204 | while (--i >= 0) |
1da177e4 LT |
205 | release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1); |
206 | return 1; | |
207 | } | |
208 | ||
9492e135 | 209 | static void rc_release_io_range(struct riscom_board * const bp) |
1da177e4 LT |
210 | { |
211 | int i; | |
9492e135 AC |
212 | |
213 | for (i = 0; i < RC_NIOPORT; i++) | |
1da177e4 LT |
214 | release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1); |
215 | } | |
9492e135 | 216 | |
1da177e4 | 217 | /* Reset and setup CD180 chip */ |
9492e135 | 218 | static void __init rc_init_CD180(struct riscom_board const *bp) |
1da177e4 LT |
219 | { |
220 | unsigned long flags; | |
9492e135 | 221 | |
d9afa435 JG |
222 | spin_lock_irqsave(&riscom_lock, flags); |
223 | ||
9492e135 AC |
224 | rc_out(bp, RC_CTOUT, 0); /* Clear timeout */ |
225 | rc_wait_CCR(bp); /* Wait for CCR ready */ | |
226 | rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */ | |
d9afa435 | 227 | spin_unlock_irqrestore(&riscom_lock, flags); |
9492e135 | 228 | msleep(50); /* Delay 0.05 sec */ |
d9afa435 | 229 | spin_lock_irqsave(&riscom_lock, flags); |
9492e135 AC |
230 | rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */ |
231 | rc_out(bp, CD180_GICR, 0); /* Clear all bits */ | |
232 | rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */ | |
233 | rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for tx intr */ | |
234 | rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for rx intr */ | |
235 | ||
1da177e4 LT |
236 | /* Setting up prescaler. We need 4 ticks per 1 ms */ |
237 | rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8); | |
238 | rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff); | |
9492e135 | 239 | |
d9afa435 | 240 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 LT |
241 | } |
242 | ||
243 | /* Main probing routine, also sets irq. */ | |
244 | static int __init rc_probe(struct riscom_board *bp) | |
245 | { | |
246 | unsigned char val1, val2; | |
247 | int irqs = 0; | |
248 | int retries; | |
9492e135 | 249 | |
1da177e4 LT |
250 | bp->irq = 0; |
251 | ||
252 | if (rc_request_io_range(bp)) | |
253 | return 1; | |
9492e135 | 254 | |
1da177e4 LT |
255 | /* Are the I/O ports here ? */ |
256 | rc_out(bp, CD180_PPRL, 0x5a); | |
257 | outb(0xff, 0x80); | |
258 | val1 = rc_in(bp, CD180_PPRL); | |
259 | rc_out(bp, CD180_PPRL, 0xa5); | |
260 | outb(0x00, 0x80); | |
261 | val2 = rc_in(bp, CD180_PPRL); | |
9492e135 | 262 | |
1da177e4 LT |
263 | if ((val1 != 0x5a) || (val2 != 0xa5)) { |
264 | printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n", | |
265 | board_No(bp), bp->base); | |
266 | goto out_release; | |
267 | } | |
9492e135 | 268 | |
1da177e4 | 269 | /* It's time to find IRQ for this board */ |
9492e135 | 270 | for (retries = 0; retries < 5 && irqs <= 0; retries++) { |
1da177e4 | 271 | irqs = probe_irq_on(); |
9492e135 AC |
272 | rc_init_CD180(bp); /* Reset CD180 chip */ |
273 | rc_out(bp, CD180_CAR, 2); /* Select port 2 */ | |
1da177e4 | 274 | rc_wait_CCR(bp); |
9492e135 AC |
275 | rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */ |
276 | rc_out(bp, CD180_IER, IER_TXRDY);/* Enable tx empty intr */ | |
c4ebd927 | 277 | msleep(50); |
1da177e4 | 278 | irqs = probe_irq_off(irqs); |
9492e135 AC |
279 | val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */ |
280 | val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */ | |
281 | rc_init_CD180(bp); /* Reset CD180 again */ | |
282 | ||
1da177e4 LT |
283 | if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) { |
284 | printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not " | |
285 | "found.\n", board_No(bp), bp->base); | |
286 | goto out_release; | |
287 | } | |
288 | } | |
9492e135 | 289 | |
1da177e4 LT |
290 | if (irqs <= 0) { |
291 | printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board " | |
292 | "at 0x%03x.\n", board_No(bp), bp->base); | |
293 | goto out_release; | |
294 | } | |
295 | bp->irq = irqs; | |
296 | bp->flags |= RC_BOARD_PRESENT; | |
9492e135 | 297 | |
1da177e4 LT |
298 | printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at " |
299 | "0x%03x, IRQ %d.\n", | |
300 | board_No(bp), | |
301 | (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */ | |
302 | bp->base, bp->irq); | |
9492e135 | 303 | |
1da177e4 LT |
304 | return 0; |
305 | out_release: | |
306 | rc_release_io_range(bp); | |
307 | return 1; | |
308 | } | |
309 | ||
9492e135 AC |
310 | /* |
311 | * | |
1da177e4 | 312 | * Interrupt processing routines. |
9492e135 | 313 | * |
1da177e4 LT |
314 | */ |
315 | ||
9492e135 AC |
316 | static struct riscom_port *rc_get_port(struct riscom_board const *bp, |
317 | unsigned char const *what) | |
1da177e4 LT |
318 | { |
319 | unsigned char channel; | |
9492e135 AC |
320 | struct riscom_port *port; |
321 | ||
1da177e4 LT |
322 | channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF; |
323 | if (channel < CD180_NCH) { | |
324 | port = &rc_port[board_No(bp) * RC_NPORT + channel]; | |
85f8f810 | 325 | if (port->port.flags & ASYNC_INITIALIZED) |
1da177e4 | 326 | return port; |
1da177e4 | 327 | } |
9492e135 | 328 | printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n", |
1da177e4 LT |
329 | board_No(bp), what, channel); |
330 | return NULL; | |
331 | } | |
332 | ||
9492e135 | 333 | static void rc_receive_exc(struct riscom_board const *bp) |
1da177e4 LT |
334 | { |
335 | struct riscom_port *port; | |
336 | struct tty_struct *tty; | |
337 | unsigned char status; | |
33f0f88f | 338 | unsigned char ch, flag; |
9492e135 AC |
339 | |
340 | port = rc_get_port(bp, "Receive"); | |
341 | if (port == NULL) | |
1da177e4 LT |
342 | return; |
343 | ||
85f8f810 | 344 | tty = port->port.tty; |
9492e135 AC |
345 | |
346 | #ifdef RC_REPORT_OVERRUN | |
1da177e4 | 347 | status = rc_in(bp, CD180_RCSR); |
33f0f88f | 348 | if (status & RCSR_OE) |
1da177e4 | 349 | port->overrun++; |
1da177e4 | 350 | status &= port->mark_mask; |
9492e135 | 351 | #else |
1da177e4 | 352 | status = rc_in(bp, CD180_RCSR) & port->mark_mask; |
9492e135 | 353 | #endif |
1da177e4 | 354 | ch = rc_in(bp, CD180_RDR); |
9492e135 | 355 | if (!status) |
1da177e4 | 356 | return; |
1da177e4 LT |
357 | if (status & RCSR_TOUT) { |
358 | printk(KERN_WARNING "rc%d: port %d: Receiver timeout. " | |
9492e135 | 359 | "Hardware problems ?\n", |
1da177e4 LT |
360 | board_No(bp), port_No(port)); |
361 | return; | |
9492e135 | 362 | |
1da177e4 LT |
363 | } else if (status & RCSR_BREAK) { |
364 | printk(KERN_INFO "rc%d: port %d: Handling break...\n", | |
365 | board_No(bp), port_No(port)); | |
33f0f88f | 366 | flag = TTY_BREAK; |
85f8f810 | 367 | if (port->port.flags & ASYNC_SAK) |
1da177e4 | 368 | do_SAK(tty); |
9492e135 AC |
369 | |
370 | } else if (status & RCSR_PE) | |
33f0f88f | 371 | flag = TTY_PARITY; |
9492e135 AC |
372 | |
373 | else if (status & RCSR_FE) | |
33f0f88f | 374 | flag = TTY_FRAME; |
9492e135 AC |
375 | |
376 | else if (status & RCSR_OE) | |
33f0f88f | 377 | flag = TTY_OVERRUN; |
1da177e4 | 378 | else |
33f0f88f | 379 | flag = TTY_NORMAL; |
9492e135 | 380 | |
33f0f88f AC |
381 | tty_insert_flip_char(tty, ch, flag); |
382 | tty_flip_buffer_push(tty); | |
1da177e4 LT |
383 | } |
384 | ||
9492e135 | 385 | static void rc_receive(struct riscom_board const *bp) |
1da177e4 LT |
386 | { |
387 | struct riscom_port *port; | |
388 | struct tty_struct *tty; | |
389 | unsigned char count; | |
9492e135 AC |
390 | |
391 | port = rc_get_port(bp, "Receive"); | |
392 | if (port == NULL) | |
1da177e4 | 393 | return; |
9492e135 | 394 | |
85f8f810 | 395 | tty = port->port.tty; |
9492e135 | 396 | |
1da177e4 | 397 | count = rc_in(bp, CD180_RDCR); |
9492e135 | 398 | |
1da177e4 LT |
399 | #ifdef RC_REPORT_FIFO |
400 | port->hits[count > 8 ? 9 : count]++; | |
9492e135 AC |
401 | #endif |
402 | ||
1da177e4 | 403 | while (count--) { |
33f0f88f | 404 | if (tty_buffer_request_room(tty, 1) == 0) { |
1da177e4 LT |
405 | printk(KERN_WARNING "rc%d: port %d: Working around " |
406 | "flip buffer overflow.\n", | |
407 | board_No(bp), port_No(port)); | |
408 | break; | |
409 | } | |
33f0f88f | 410 | tty_insert_flip_char(tty, rc_in(bp, CD180_RDR), TTY_NORMAL); |
1da177e4 | 411 | } |
33f0f88f | 412 | tty_flip_buffer_push(tty); |
1da177e4 LT |
413 | } |
414 | ||
9492e135 | 415 | static void rc_transmit(struct riscom_board const *bp) |
1da177e4 LT |
416 | { |
417 | struct riscom_port *port; | |
418 | struct tty_struct *tty; | |
419 | unsigned char count; | |
9492e135 AC |
420 | |
421 | port = rc_get_port(bp, "Transmit"); | |
422 | if (port == NULL) | |
1da177e4 | 423 | return; |
9492e135 | 424 | |
85f8f810 | 425 | tty = port->port.tty; |
9492e135 AC |
426 | |
427 | if (port->IER & IER_TXEMPTY) { | |
1da177e4 LT |
428 | /* FIFO drained */ |
429 | rc_out(bp, CD180_CAR, port_No(port)); | |
430 | port->IER &= ~IER_TXEMPTY; | |
431 | rc_out(bp, CD180_IER, port->IER); | |
432 | return; | |
433 | } | |
9492e135 | 434 | |
1da177e4 LT |
435 | if ((port->xmit_cnt <= 0 && !port->break_length) |
436 | || tty->stopped || tty->hw_stopped) { | |
437 | rc_out(bp, CD180_CAR, port_No(port)); | |
438 | port->IER &= ~IER_TXRDY; | |
439 | rc_out(bp, CD180_IER, port->IER); | |
440 | return; | |
441 | } | |
9492e135 | 442 | |
1da177e4 LT |
443 | if (port->break_length) { |
444 | if (port->break_length > 0) { | |
445 | if (port->COR2 & COR2_ETC) { | |
446 | rc_out(bp, CD180_TDR, CD180_C_ESC); | |
447 | rc_out(bp, CD180_TDR, CD180_C_SBRK); | |
448 | port->COR2 &= ~COR2_ETC; | |
449 | } | |
450 | count = min_t(int, port->break_length, 0xff); | |
451 | rc_out(bp, CD180_TDR, CD180_C_ESC); | |
452 | rc_out(bp, CD180_TDR, CD180_C_DELAY); | |
453 | rc_out(bp, CD180_TDR, count); | |
9492e135 AC |
454 | port->break_length -= count; |
455 | if (port->break_length == 0) | |
1da177e4 LT |
456 | port->break_length--; |
457 | } else { | |
458 | rc_out(bp, CD180_TDR, CD180_C_ESC); | |
459 | rc_out(bp, CD180_TDR, CD180_C_EBRK); | |
460 | rc_out(bp, CD180_COR2, port->COR2); | |
461 | rc_wait_CCR(bp); | |
462 | rc_out(bp, CD180_CCR, CCR_CORCHG2); | |
463 | port->break_length = 0; | |
464 | } | |
465 | return; | |
466 | } | |
9492e135 | 467 | |
1da177e4 LT |
468 | count = CD180_NFIFO; |
469 | do { | |
85f8f810 | 470 | rc_out(bp, CD180_TDR, port->port.xmit_buf[port->xmit_tail++]); |
1da177e4 LT |
471 | port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1); |
472 | if (--port->xmit_cnt <= 0) | |
473 | break; | |
474 | } while (--count > 0); | |
9492e135 | 475 | |
1da177e4 LT |
476 | if (port->xmit_cnt <= 0) { |
477 | rc_out(bp, CD180_CAR, port_No(port)); | |
478 | port->IER &= ~IER_TXRDY; | |
479 | rc_out(bp, CD180_IER, port->IER); | |
480 | } | |
481 | if (port->xmit_cnt <= port->wakeup_chars) | |
b98e70de | 482 | tty_wakeup(tty); |
1da177e4 LT |
483 | } |
484 | ||
9492e135 | 485 | static void rc_check_modem(struct riscom_board const *bp) |
1da177e4 LT |
486 | { |
487 | struct riscom_port *port; | |
488 | struct tty_struct *tty; | |
489 | unsigned char mcr; | |
9492e135 AC |
490 | |
491 | port = rc_get_port(bp, "Modem"); | |
492 | if (port == NULL) | |
1da177e4 | 493 | return; |
9492e135 | 494 | |
85f8f810 | 495 | tty = port->port.tty; |
9492e135 | 496 | |
1da177e4 | 497 | mcr = rc_in(bp, CD180_MCR); |
9492e135 AC |
498 | if (mcr & MCR_CDCHG) { |
499 | if (rc_in(bp, CD180_MSVR) & MSVR_CD) | |
85f8f810 | 500 | wake_up_interruptible(&port->port.open_wait); |
1da177e4 | 501 | else |
b98e70de | 502 | tty_hangup(tty); |
1da177e4 | 503 | } |
9492e135 | 504 | |
1da177e4 LT |
505 | #ifdef RISCOM_BRAIN_DAMAGED_CTS |
506 | if (mcr & MCR_CTSCHG) { | |
507 | if (rc_in(bp, CD180_MSVR) & MSVR_CTS) { | |
508 | tty->hw_stopped = 0; | |
509 | port->IER |= IER_TXRDY; | |
510 | if (port->xmit_cnt <= port->wakeup_chars) | |
b98e70de | 511 | tty_wakeup(tty); |
1da177e4 LT |
512 | } else { |
513 | tty->hw_stopped = 1; | |
514 | port->IER &= ~IER_TXRDY; | |
515 | } | |
516 | rc_out(bp, CD180_IER, port->IER); | |
517 | } | |
518 | if (mcr & MCR_DSRCHG) { | |
519 | if (rc_in(bp, CD180_MSVR) & MSVR_DSR) { | |
520 | tty->hw_stopped = 0; | |
521 | port->IER |= IER_TXRDY; | |
522 | if (port->xmit_cnt <= port->wakeup_chars) | |
b98e70de | 523 | tty_wakeup(tty); |
1da177e4 LT |
524 | } else { |
525 | tty->hw_stopped = 1; | |
526 | port->IER &= ~IER_TXRDY; | |
527 | } | |
528 | rc_out(bp, CD180_IER, port->IER); | |
529 | } | |
530 | #endif /* RISCOM_BRAIN_DAMAGED_CTS */ | |
9492e135 | 531 | |
1da177e4 LT |
532 | /* Clear change bits */ |
533 | rc_out(bp, CD180_MCR, 0); | |
534 | } | |
535 | ||
536 | /* The main interrupt processing routine */ | |
9492e135 | 537 | static irqreturn_t rc_interrupt(int dummy, void *dev_id) |
1da177e4 LT |
538 | { |
539 | unsigned char status; | |
540 | unsigned char ack; | |
f07ef395 | 541 | struct riscom_board *bp = dev_id; |
1da177e4 LT |
542 | unsigned long loop = 0; |
543 | int handled = 0; | |
544 | ||
c7bec5ab | 545 | if (!(bp->flags & RC_BOARD_ACTIVE)) |
1da177e4 | 546 | return IRQ_NONE; |
c7bec5ab | 547 | |
1da177e4 LT |
548 | while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) & |
549 | (RC_BSR_TOUT | RC_BSR_TINT | | |
550 | RC_BSR_MINT | RC_BSR_RINT))) { | |
551 | handled = 1; | |
9492e135 | 552 | if (status & RC_BSR_TOUT) |
1da177e4 LT |
553 | printk(KERN_WARNING "rc%d: Got timeout. Hardware " |
554 | "error?\n", board_No(bp)); | |
1da177e4 LT |
555 | else if (status & RC_BSR_RINT) { |
556 | ack = rc_in(bp, RC_ACK_RINT); | |
1da177e4 LT |
557 | if (ack == (RC_ID | GIVR_IT_RCV)) |
558 | rc_receive(bp); | |
559 | else if (ack == (RC_ID | GIVR_IT_REXC)) | |
560 | rc_receive_exc(bp); | |
561 | else | |
562 | printk(KERN_WARNING "rc%d: Bad receive ack " | |
563 | "0x%02x.\n", | |
564 | board_No(bp), ack); | |
1da177e4 LT |
565 | } else if (status & RC_BSR_TINT) { |
566 | ack = rc_in(bp, RC_ACK_TINT); | |
1da177e4 LT |
567 | if (ack == (RC_ID | GIVR_IT_TX)) |
568 | rc_transmit(bp); | |
569 | else | |
570 | printk(KERN_WARNING "rc%d: Bad transmit ack " | |
571 | "0x%02x.\n", | |
572 | board_No(bp), ack); | |
1da177e4 LT |
573 | } else /* if (status & RC_BSR_MINT) */ { |
574 | ack = rc_in(bp, RC_ACK_MINT); | |
9492e135 | 575 | if (ack == (RC_ID | GIVR_IT_MODEM)) |
1da177e4 LT |
576 | rc_check_modem(bp); |
577 | else | |
578 | printk(KERN_WARNING "rc%d: Bad modem ack " | |
579 | "0x%02x.\n", | |
580 | board_No(bp), ack); | |
9492e135 | 581 | } |
1da177e4 LT |
582 | rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */ |
583 | rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */ | |
584 | } | |
585 | return IRQ_RETVAL(handled); | |
586 | } | |
587 | ||
588 | /* | |
589 | * Routines for open & close processing. | |
590 | */ | |
591 | ||
592 | /* Called with disabled interrupts */ | |
9492e135 | 593 | static int rc_setup_board(struct riscom_board *bp) |
1da177e4 LT |
594 | { |
595 | int error; | |
596 | ||
9492e135 | 597 | if (bp->flags & RC_BOARD_ACTIVE) |
1da177e4 | 598 | return 0; |
9492e135 | 599 | |
0f2ed4c6 | 600 | error = request_irq(bp->irq, rc_interrupt, IRQF_DISABLED, |
f07ef395 | 601 | "RISCom/8", bp); |
9492e135 | 602 | if (error) |
1da177e4 | 603 | return error; |
9492e135 | 604 | |
1da177e4 LT |
605 | rc_out(bp, RC_CTOUT, 0); /* Just in case */ |
606 | bp->DTR = ~0; | |
607 | rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */ | |
9492e135 | 608 | |
1da177e4 | 609 | bp->flags |= RC_BOARD_ACTIVE; |
9492e135 | 610 | |
1da177e4 LT |
611 | return 0; |
612 | } | |
613 | ||
614 | /* Called with disabled interrupts */ | |
f07ef395 | 615 | static void rc_shutdown_board(struct riscom_board *bp) |
1da177e4 LT |
616 | { |
617 | if (!(bp->flags & RC_BOARD_ACTIVE)) | |
618 | return; | |
9492e135 | 619 | |
1da177e4 | 620 | bp->flags &= ~RC_BOARD_ACTIVE; |
9492e135 | 621 | |
1da177e4 | 622 | free_irq(bp->irq, NULL); |
9492e135 | 623 | |
1da177e4 LT |
624 | bp->DTR = ~0; |
625 | rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */ | |
9492e135 | 626 | |
1da177e4 LT |
627 | } |
628 | ||
629 | /* | |
9492e135 | 630 | * Setting up port characteristics. |
1da177e4 LT |
631 | * Must be called with disabled interrupts |
632 | */ | |
633 | static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port) | |
634 | { | |
85f8f810 | 635 | struct tty_struct *tty = port->port.tty; |
1da177e4 LT |
636 | unsigned long baud; |
637 | long tmp; | |
638 | unsigned char cor1 = 0, cor3 = 0; | |
639 | unsigned char mcor1 = 0, mcor2 = 0; | |
9492e135 | 640 | |
1da177e4 LT |
641 | port->IER = 0; |
642 | port->COR2 = 0; | |
643 | port->MSVR = MSVR_RTS; | |
9492e135 | 644 | |
c7bce309 | 645 | baud = tty_get_baud_rate(tty); |
9492e135 | 646 | |
1da177e4 LT |
647 | /* Select port on the board */ |
648 | rc_out(bp, CD180_CAR, port_No(port)); | |
9492e135 | 649 | |
c7bce309 | 650 | if (!baud) { |
1da177e4 LT |
651 | /* Drop DTR & exit */ |
652 | bp->DTR |= (1u << port_No(port)); | |
653 | rc_out(bp, RC_DTR, bp->DTR); | |
654 | return; | |
655 | } else { | |
656 | /* Set DTR on */ | |
657 | bp->DTR &= ~(1u << port_No(port)); | |
658 | rc_out(bp, RC_DTR, bp->DTR); | |
659 | } | |
9492e135 | 660 | |
1da177e4 | 661 | /* |
9492e135 | 662 | * Now we must calculate some speed depended things |
1da177e4 | 663 | */ |
9492e135 | 664 | |
1da177e4 | 665 | /* Set baud rate for port */ |
c7bce309 | 666 | tmp = (((RC_OSCFREQ + baud/2) / baud + |
1da177e4 LT |
667 | CD180_TPC/2) / CD180_TPC); |
668 | ||
9492e135 AC |
669 | rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff); |
670 | rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff); | |
671 | rc_out(bp, CD180_RBPRL, tmp & 0xff); | |
1da177e4 | 672 | rc_out(bp, CD180_TBPRL, tmp & 0xff); |
9492e135 | 673 | |
c7bce309 | 674 | baud = (baud + 5) / 10; /* Estimated CPS */ |
9492e135 | 675 | |
1da177e4 | 676 | /* Two timer ticks seems enough to wakeup something like SLIP driver */ |
9492e135 | 677 | tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO; |
1da177e4 LT |
678 | port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ? |
679 | SERIAL_XMIT_SIZE - 1 : tmp); | |
9492e135 | 680 | |
1da177e4 LT |
681 | /* Receiver timeout will be transmission time for 1.5 chars */ |
682 | tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud; | |
683 | tmp = (tmp > 0xff) ? 0xff : tmp; | |
684 | rc_out(bp, CD180_RTPR, tmp); | |
9492e135 AC |
685 | |
686 | switch (C_CSIZE(tty)) { | |
687 | case CS5: | |
1da177e4 LT |
688 | cor1 |= COR1_5BITS; |
689 | break; | |
9492e135 | 690 | case CS6: |
1da177e4 LT |
691 | cor1 |= COR1_6BITS; |
692 | break; | |
9492e135 | 693 | case CS7: |
1da177e4 LT |
694 | cor1 |= COR1_7BITS; |
695 | break; | |
9492e135 | 696 | case CS8: |
1da177e4 LT |
697 | cor1 |= COR1_8BITS; |
698 | break; | |
699 | } | |
9492e135 | 700 | if (C_CSTOPB(tty)) |
1da177e4 | 701 | cor1 |= COR1_2SB; |
9492e135 | 702 | |
1da177e4 | 703 | cor1 |= COR1_IGNORE; |
9492e135 | 704 | if (C_PARENB(tty)) { |
1da177e4 | 705 | cor1 |= COR1_NORMPAR; |
9492e135 | 706 | if (C_PARODD(tty)) |
1da177e4 | 707 | cor1 |= COR1_ODDP; |
9492e135 | 708 | if (I_INPCK(tty)) |
1da177e4 LT |
709 | cor1 &= ~COR1_IGNORE; |
710 | } | |
711 | /* Set marking of some errors */ | |
712 | port->mark_mask = RCSR_OE | RCSR_TOUT; | |
9492e135 | 713 | if (I_INPCK(tty)) |
1da177e4 | 714 | port->mark_mask |= RCSR_FE | RCSR_PE; |
9492e135 | 715 | if (I_BRKINT(tty) || I_PARMRK(tty)) |
1da177e4 | 716 | port->mark_mask |= RCSR_BREAK; |
9492e135 | 717 | if (I_IGNPAR(tty)) |
1da177e4 | 718 | port->mark_mask &= ~(RCSR_FE | RCSR_PE); |
9492e135 | 719 | if (I_IGNBRK(tty)) { |
1da177e4 | 720 | port->mark_mask &= ~RCSR_BREAK; |
9492e135 | 721 | if (I_IGNPAR(tty)) |
1da177e4 LT |
722 | /* Real raw mode. Ignore all */ |
723 | port->mark_mask &= ~RCSR_OE; | |
724 | } | |
725 | /* Enable Hardware Flow Control */ | |
726 | if (C_CRTSCTS(tty)) { | |
727 | #ifdef RISCOM_BRAIN_DAMAGED_CTS | |
728 | port->IER |= IER_DSR | IER_CTS; | |
729 | mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD; | |
730 | mcor2 |= MCOR2_DSROD | MCOR2_CTSOD; | |
9492e135 AC |
731 | tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & |
732 | (MSVR_CTS|MSVR_DSR)); | |
1da177e4 LT |
733 | #else |
734 | port->COR2 |= COR2_CTSAE; | |
735 | #endif | |
736 | } | |
737 | /* Enable Software Flow Control. FIXME: I'm not sure about this */ | |
738 | /* Some people reported that it works, but I still doubt */ | |
739 | if (I_IXON(tty)) { | |
740 | port->COR2 |= COR2_TXIBE; | |
741 | cor3 |= (COR3_FCT | COR3_SCDE); | |
742 | if (I_IXANY(tty)) | |
743 | port->COR2 |= COR2_IXM; | |
744 | rc_out(bp, CD180_SCHR1, START_CHAR(tty)); | |
745 | rc_out(bp, CD180_SCHR2, STOP_CHAR(tty)); | |
746 | rc_out(bp, CD180_SCHR3, START_CHAR(tty)); | |
747 | rc_out(bp, CD180_SCHR4, STOP_CHAR(tty)); | |
748 | } | |
749 | if (!C_CLOCAL(tty)) { | |
750 | /* Enable CD check */ | |
751 | port->IER |= IER_CD; | |
752 | mcor1 |= MCOR1_CDZD; | |
753 | mcor2 |= MCOR2_CDOD; | |
754 | } | |
9492e135 AC |
755 | |
756 | if (C_CREAD(tty)) | |
1da177e4 LT |
757 | /* Enable receiver */ |
758 | port->IER |= IER_RXD; | |
9492e135 | 759 | |
1da177e4 | 760 | /* Set input FIFO size (1-8 bytes) */ |
9492e135 | 761 | cor3 |= RISCOM_RXFIFO; |
1da177e4 LT |
762 | /* Setting up CD180 channel registers */ |
763 | rc_out(bp, CD180_COR1, cor1); | |
764 | rc_out(bp, CD180_COR2, port->COR2); | |
765 | rc_out(bp, CD180_COR3, cor3); | |
766 | /* Make CD180 know about registers change */ | |
767 | rc_wait_CCR(bp); | |
768 | rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); | |
769 | /* Setting up modem option registers */ | |
770 | rc_out(bp, CD180_MCOR1, mcor1); | |
771 | rc_out(bp, CD180_MCOR2, mcor2); | |
772 | /* Enable CD180 transmitter & receiver */ | |
773 | rc_wait_CCR(bp); | |
774 | rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN); | |
775 | /* Enable interrupts */ | |
776 | rc_out(bp, CD180_IER, port->IER); | |
777 | /* And finally set RTS on */ | |
778 | rc_out(bp, CD180_MSVR, port->MSVR); | |
779 | } | |
780 | ||
781 | /* Must be called with interrupts enabled */ | |
782 | static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port) | |
783 | { | |
784 | unsigned long flags; | |
9492e135 | 785 | |
85f8f810 | 786 | if (port->port.flags & ASYNC_INITIALIZED) |
1da177e4 | 787 | return 0; |
9492e135 | 788 | |
85f8f810 AC |
789 | if (tty_port_alloc_xmit_buf(&port->port) < 0) |
790 | return -ENOMEM; | |
791 | ||
d9afa435 JG |
792 | spin_lock_irqsave(&riscom_lock, flags); |
793 | ||
d99101fd | 794 | clear_bit(TTY_IO_ERROR, &port->port.tty->flags); |
85f8f810 | 795 | if (port->port.count == 1) |
1da177e4 | 796 | bp->count++; |
1da177e4 LT |
797 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
798 | rc_change_speed(bp, port); | |
85f8f810 | 799 | port->port.flags |= ASYNC_INITIALIZED; |
9492e135 | 800 | |
d9afa435 | 801 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 LT |
802 | return 0; |
803 | } | |
804 | ||
805 | /* Must be called with interrupts disabled */ | |
d99101fd AC |
806 | static void rc_shutdown_port(struct tty_struct *tty, |
807 | struct riscom_board *bp, struct riscom_port *port) | |
1da177e4 | 808 | { |
85f8f810 | 809 | if (!(port->port.flags & ASYNC_INITIALIZED)) |
1da177e4 | 810 | return; |
9492e135 | 811 | |
1da177e4 LT |
812 | #ifdef RC_REPORT_OVERRUN |
813 | printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n", | |
814 | board_No(bp), port_No(port), port->overrun); | |
9492e135 | 815 | #endif |
1da177e4 LT |
816 | #ifdef RC_REPORT_FIFO |
817 | { | |
818 | int i; | |
9492e135 | 819 | |
1da177e4 LT |
820 | printk(KERN_INFO "rc%d: port %d: FIFO hits [ ", |
821 | board_No(bp), port_No(port)); | |
9492e135 | 822 | for (i = 0; i < 10; i++) |
1da177e4 | 823 | printk("%ld ", port->hits[i]); |
1da177e4 LT |
824 | printk("].\n"); |
825 | } | |
9492e135 | 826 | #endif |
85f8f810 | 827 | tty_port_free_xmit_buf(&port->port); |
d99101fd | 828 | if (C_HUPCL(tty)) { |
1da177e4 LT |
829 | /* Drop DTR */ |
830 | bp->DTR |= (1u << port_No(port)); | |
831 | rc_out(bp, RC_DTR, bp->DTR); | |
832 | } | |
9492e135 AC |
833 | |
834 | /* Select port */ | |
1da177e4 LT |
835 | rc_out(bp, CD180_CAR, port_No(port)); |
836 | /* Reset port */ | |
837 | rc_wait_CCR(bp); | |
838 | rc_out(bp, CD180_CCR, CCR_SOFTRESET); | |
839 | /* Disable all interrupts from this port */ | |
840 | port->IER = 0; | |
841 | rc_out(bp, CD180_IER, port->IER); | |
9492e135 | 842 | |
d99101fd | 843 | set_bit(TTY_IO_ERROR, &tty->flags); |
85f8f810 | 844 | port->port.flags &= ~ASYNC_INITIALIZED; |
9492e135 | 845 | |
1da177e4 LT |
846 | if (--bp->count < 0) { |
847 | printk(KERN_INFO "rc%d: rc_shutdown_port: " | |
848 | "bad board count: %d\n", | |
849 | board_No(bp), bp->count); | |
850 | bp->count = 0; | |
851 | } | |
1da177e4 LT |
852 | /* |
853 | * If this is the last opened port on the board | |
854 | * shutdown whole board | |
855 | */ | |
9492e135 | 856 | if (!bp->count) |
1da177e4 LT |
857 | rc_shutdown_board(bp); |
858 | } | |
859 | ||
31f35939 AC |
860 | static int carrier_raised(struct tty_port *port) |
861 | { | |
862 | struct riscom_port *p = container_of(port, struct riscom_port, port); | |
863 | struct riscom_board *bp = port_Board(p); | |
864 | unsigned long flags; | |
865 | int CD; | |
866 | ||
867 | spin_lock_irqsave(&riscom_lock, flags); | |
868 | rc_out(bp, CD180_CAR, port_No(p)); | |
869 | CD = rc_in(bp, CD180_MSVR) & MSVR_CD; | |
870 | rc_out(bp, CD180_MSVR, MSVR_RTS); | |
871 | bp->DTR &= ~(1u << port_No(p)); | |
872 | rc_out(bp, RC_DTR, bp->DTR); | |
873 | spin_unlock_irqrestore(&riscom_lock, flags); | |
874 | return CD; | |
875 | } | |
876 | ||
9492e135 | 877 | static int rc_open(struct tty_struct *tty, struct file *filp) |
1da177e4 LT |
878 | { |
879 | int board; | |
880 | int error; | |
9492e135 AC |
881 | struct riscom_port *port; |
882 | struct riscom_board *bp; | |
883 | ||
1da177e4 LT |
884 | board = RC_BOARD(tty->index); |
885 | if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT)) | |
886 | return -ENODEV; | |
9492e135 | 887 | |
1da177e4 LT |
888 | bp = &rc_board[board]; |
889 | port = rc_port + board * RC_NPORT + RC_PORT(tty->index); | |
890 | if (rc_paranoia_check(port, tty->name, "rc_open")) | |
891 | return -ENODEV; | |
9492e135 AC |
892 | |
893 | error = rc_setup_board(bp); | |
894 | if (error) | |
1da177e4 | 895 | return error; |
9492e135 | 896 | |
85f8f810 | 897 | port->port.count++; |
1da177e4 | 898 | tty->driver_data = port; |
85f8f810 | 899 | port->port.tty = tty; |
9492e135 AC |
900 | |
901 | error = rc_setup_port(bp, port); | |
902 | if (error == 0) | |
36c621d8 | 903 | error = tty_port_block_til_ready(&port->port, tty, filp); |
9492e135 | 904 | return error; |
1da177e4 LT |
905 | } |
906 | ||
978e595f AC |
907 | static void rc_flush_buffer(struct tty_struct *tty) |
908 | { | |
c9f19e96 | 909 | struct riscom_port *port = tty->driver_data; |
978e595f AC |
910 | unsigned long flags; |
911 | ||
912 | if (rc_paranoia_check(port, tty->name, "rc_flush_buffer")) | |
913 | return; | |
914 | ||
915 | spin_lock_irqsave(&riscom_lock, flags); | |
978e595f | 916 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
978e595f AC |
917 | spin_unlock_irqrestore(&riscom_lock, flags); |
918 | ||
919 | tty_wakeup(tty); | |
920 | } | |
921 | ||
9492e135 | 922 | static void rc_close(struct tty_struct *tty, struct file *filp) |
1da177e4 | 923 | { |
c9f19e96 | 924 | struct riscom_port *port = tty->driver_data; |
1da177e4 LT |
925 | struct riscom_board *bp; |
926 | unsigned long flags; | |
927 | unsigned long timeout; | |
9492e135 | 928 | |
1da177e4 LT |
929 | if (!port || rc_paranoia_check(port, tty->name, "close")) |
930 | return; | |
d9afa435 | 931 | |
1da177e4 | 932 | bp = port_Board(port); |
a6614999 AC |
933 | |
934 | if (tty_port_close_start(&port->port, tty, filp) == 0) | |
935 | return; | |
936 | ||
1da177e4 LT |
937 | /* |
938 | * At this point we stop accepting input. To do this, we | |
939 | * disable the receive line status interrupts, and tell the | |
940 | * interrupt driver to stop checking the data ready bit in the | |
941 | * line status register. | |
942 | */ | |
c2ba38cd AC |
943 | |
944 | spin_lock_irqsave(&riscom_lock, flags); | |
1da177e4 | 945 | port->IER &= ~IER_RXD; |
85f8f810 | 946 | if (port->port.flags & ASYNC_INITIALIZED) { |
1da177e4 LT |
947 | port->IER &= ~IER_TXRDY; |
948 | port->IER |= IER_TXEMPTY; | |
949 | rc_out(bp, CD180_CAR, port_No(port)); | |
950 | rc_out(bp, CD180_IER, port->IER); | |
951 | /* | |
952 | * Before we drop DTR, make sure the UART transmitter | |
953 | * has completely drained; this is especially | |
954 | * important if there is a transmit FIFO! | |
955 | */ | |
9492e135 AC |
956 | timeout = jiffies + HZ; |
957 | while (port->IER & IER_TXEMPTY) { | |
c2ba38cd | 958 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 | 959 | msleep_interruptible(jiffies_to_msecs(port->timeout)); |
c2ba38cd | 960 | spin_lock_irqsave(&riscom_lock, flags); |
1da177e4 LT |
961 | if (time_after(jiffies, timeout)) |
962 | break; | |
963 | } | |
964 | } | |
d99101fd | 965 | rc_shutdown_port(tty, bp, port); |
978e595f | 966 | rc_flush_buffer(tty); |
c2ba38cd | 967 | spin_unlock_irqrestore(&riscom_lock, flags); |
d9afa435 | 968 | |
a6614999 | 969 | tty_port_close_end(&port->port, tty); |
1da177e4 LT |
970 | } |
971 | ||
9492e135 | 972 | static int rc_write(struct tty_struct *tty, |
1da177e4 LT |
973 | const unsigned char *buf, int count) |
974 | { | |
c9f19e96 | 975 | struct riscom_port *port = tty->driver_data; |
1da177e4 LT |
976 | struct riscom_board *bp; |
977 | int c, total = 0; | |
978 | unsigned long flags; | |
9492e135 | 979 | |
1da177e4 LT |
980 | if (rc_paranoia_check(port, tty->name, "rc_write")) |
981 | return 0; | |
9492e135 | 982 | |
1da177e4 LT |
983 | bp = port_Board(port); |
984 | ||
1da177e4 | 985 | while (1) { |
d9afa435 JG |
986 | spin_lock_irqsave(&riscom_lock, flags); |
987 | ||
1da177e4 LT |
988 | c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1, |
989 | SERIAL_XMIT_SIZE - port->xmit_head)); | |
d9afa435 JG |
990 | if (c <= 0) |
991 | break; /* lock continues to be held */ | |
1da177e4 | 992 | |
85f8f810 | 993 | memcpy(port->port.xmit_buf + port->xmit_head, buf, c); |
1da177e4 LT |
994 | port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1); |
995 | port->xmit_cnt += c; | |
d9afa435 JG |
996 | |
997 | spin_unlock_irqrestore(&riscom_lock, flags); | |
1da177e4 LT |
998 | |
999 | buf += c; | |
1000 | count -= c; | |
1001 | total += c; | |
1002 | } | |
1003 | ||
1da177e4 LT |
1004 | if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped && |
1005 | !(port->IER & IER_TXRDY)) { | |
1006 | port->IER |= IER_TXRDY; | |
1007 | rc_out(bp, CD180_CAR, port_No(port)); | |
1008 | rc_out(bp, CD180_IER, port->IER); | |
1009 | } | |
d9afa435 JG |
1010 | |
1011 | spin_unlock_irqrestore(&riscom_lock, flags); | |
1da177e4 LT |
1012 | |
1013 | return total; | |
1014 | } | |
1015 | ||
9492e135 | 1016 | static int rc_put_char(struct tty_struct *tty, unsigned char ch) |
1da177e4 | 1017 | { |
c9f19e96 | 1018 | struct riscom_port *port = tty->driver_data; |
1da177e4 | 1019 | unsigned long flags; |
bbbbb96f | 1020 | int ret = 0; |
1da177e4 LT |
1021 | |
1022 | if (rc_paranoia_check(port, tty->name, "rc_put_char")) | |
bbbbb96f | 1023 | return 0; |
1da177e4 | 1024 | |
d9afa435 | 1025 | spin_lock_irqsave(&riscom_lock, flags); |
9492e135 | 1026 | |
1da177e4 LT |
1027 | if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) |
1028 | goto out; | |
1029 | ||
85f8f810 | 1030 | port->port.xmit_buf[port->xmit_head++] = ch; |
1da177e4 LT |
1031 | port->xmit_head &= SERIAL_XMIT_SIZE - 1; |
1032 | port->xmit_cnt++; | |
bbbbb96f | 1033 | ret = 1; |
d9afa435 JG |
1034 | |
1035 | out: | |
1036 | spin_unlock_irqrestore(&riscom_lock, flags); | |
bbbbb96f | 1037 | return ret; |
1da177e4 LT |
1038 | } |
1039 | ||
9492e135 | 1040 | static void rc_flush_chars(struct tty_struct *tty) |
1da177e4 | 1041 | { |
c9f19e96 | 1042 | struct riscom_port *port = tty->driver_data; |
1da177e4 | 1043 | unsigned long flags; |
9492e135 | 1044 | |
1da177e4 LT |
1045 | if (rc_paranoia_check(port, tty->name, "rc_flush_chars")) |
1046 | return; | |
9492e135 | 1047 | |
d99101fd | 1048 | if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped) |
1da177e4 LT |
1049 | return; |
1050 | ||
d9afa435 JG |
1051 | spin_lock_irqsave(&riscom_lock, flags); |
1052 | ||
1da177e4 LT |
1053 | port->IER |= IER_TXRDY; |
1054 | rc_out(port_Board(port), CD180_CAR, port_No(port)); | |
1055 | rc_out(port_Board(port), CD180_IER, port->IER); | |
d9afa435 JG |
1056 | |
1057 | spin_unlock_irqrestore(&riscom_lock, flags); | |
1da177e4 LT |
1058 | } |
1059 | ||
9492e135 | 1060 | static int rc_write_room(struct tty_struct *tty) |
1da177e4 | 1061 | { |
c9f19e96 | 1062 | struct riscom_port *port = tty->driver_data; |
1da177e4 | 1063 | int ret; |
9492e135 | 1064 | |
1da177e4 LT |
1065 | if (rc_paranoia_check(port, tty->name, "rc_write_room")) |
1066 | return 0; | |
1067 | ||
1068 | ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1; | |
1069 | if (ret < 0) | |
1070 | ret = 0; | |
1071 | return ret; | |
1072 | } | |
1073 | ||
1074 | static int rc_chars_in_buffer(struct tty_struct *tty) | |
1075 | { | |
c9f19e96 | 1076 | struct riscom_port *port = tty->driver_data; |
9492e135 | 1077 | |
1da177e4 LT |
1078 | if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer")) |
1079 | return 0; | |
9492e135 | 1080 | |
1da177e4 LT |
1081 | return port->xmit_cnt; |
1082 | } | |
1083 | ||
1da177e4 LT |
1084 | static int rc_tiocmget(struct tty_struct *tty, struct file *file) |
1085 | { | |
c9f19e96 | 1086 | struct riscom_port *port = tty->driver_data; |
9492e135 | 1087 | struct riscom_board *bp; |
1da177e4 LT |
1088 | unsigned char status; |
1089 | unsigned int result; | |
1090 | unsigned long flags; | |
1091 | ||
bf9d8929 | 1092 | if (rc_paranoia_check(port, tty->name, __func__)) |
1da177e4 LT |
1093 | return -ENODEV; |
1094 | ||
1095 | bp = port_Board(port); | |
d9afa435 JG |
1096 | |
1097 | spin_lock_irqsave(&riscom_lock, flags); | |
1098 | ||
1da177e4 LT |
1099 | rc_out(bp, CD180_CAR, port_No(port)); |
1100 | status = rc_in(bp, CD180_MSVR); | |
1101 | result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG; | |
d9afa435 JG |
1102 | |
1103 | spin_unlock_irqrestore(&riscom_lock, flags); | |
1104 | ||
1da177e4 LT |
1105 | result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0) |
1106 | | ((status & MSVR_DTR) ? TIOCM_DTR : 0) | |
1107 | | ((status & MSVR_CD) ? TIOCM_CAR : 0) | |
1108 | | ((status & MSVR_DSR) ? TIOCM_DSR : 0) | |
1109 | | ((status & MSVR_CTS) ? TIOCM_CTS : 0); | |
1110 | return result; | |
1111 | } | |
1112 | ||
1113 | static int rc_tiocmset(struct tty_struct *tty, struct file *file, | |
1114 | unsigned int set, unsigned int clear) | |
1115 | { | |
c9f19e96 | 1116 | struct riscom_port *port = tty->driver_data; |
1da177e4 LT |
1117 | unsigned long flags; |
1118 | struct riscom_board *bp; | |
1119 | ||
bf9d8929 | 1120 | if (rc_paranoia_check(port, tty->name, __func__)) |
1da177e4 LT |
1121 | return -ENODEV; |
1122 | ||
1123 | bp = port_Board(port); | |
1124 | ||
d9afa435 JG |
1125 | spin_lock_irqsave(&riscom_lock, flags); |
1126 | ||
1da177e4 LT |
1127 | if (set & TIOCM_RTS) |
1128 | port->MSVR |= MSVR_RTS; | |
1129 | if (set & TIOCM_DTR) | |
1130 | bp->DTR &= ~(1u << port_No(port)); | |
1131 | ||
1132 | if (clear & TIOCM_RTS) | |
1133 | port->MSVR &= ~MSVR_RTS; | |
1134 | if (clear & TIOCM_DTR) | |
1135 | bp->DTR |= (1u << port_No(port)); | |
1136 | ||
1137 | rc_out(bp, CD180_CAR, port_No(port)); | |
1138 | rc_out(bp, CD180_MSVR, port->MSVR); | |
1139 | rc_out(bp, RC_DTR, bp->DTR); | |
d9afa435 JG |
1140 | |
1141 | spin_unlock_irqrestore(&riscom_lock, flags); | |
1142 | ||
1da177e4 LT |
1143 | return 0; |
1144 | } | |
1145 | ||
781cff5c | 1146 | static int rc_send_break(struct tty_struct *tty, int length) |
1da177e4 | 1147 | { |
c9f19e96 | 1148 | struct riscom_port *port = tty->driver_data; |
1da177e4 LT |
1149 | struct riscom_board *bp = port_Board(port); |
1150 | unsigned long flags; | |
9492e135 | 1151 | |
781cff5c AC |
1152 | if (length == 0 || length == -1) |
1153 | return -EOPNOTSUPP; | |
1154 | ||
d9afa435 JG |
1155 | spin_lock_irqsave(&riscom_lock, flags); |
1156 | ||
1da177e4 LT |
1157 | port->break_length = RISCOM_TPS / HZ * length; |
1158 | port->COR2 |= COR2_ETC; | |
1159 | port->IER |= IER_TXRDY; | |
1160 | rc_out(bp, CD180_CAR, port_No(port)); | |
1161 | rc_out(bp, CD180_COR2, port->COR2); | |
1162 | rc_out(bp, CD180_IER, port->IER); | |
1163 | rc_wait_CCR(bp); | |
1164 | rc_out(bp, CD180_CCR, CCR_CORCHG2); | |
1165 | rc_wait_CCR(bp); | |
d9afa435 JG |
1166 | |
1167 | spin_unlock_irqrestore(&riscom_lock, flags); | |
781cff5c | 1168 | return 0; |
1da177e4 LT |
1169 | } |
1170 | ||
9492e135 AC |
1171 | static int rc_set_serial_info(struct riscom_port *port, |
1172 | struct serial_struct __user *newinfo) | |
1da177e4 LT |
1173 | { |
1174 | struct serial_struct tmp; | |
1175 | struct riscom_board *bp = port_Board(port); | |
1176 | int change_speed; | |
9492e135 | 1177 | |
1da177e4 LT |
1178 | if (copy_from_user(&tmp, newinfo, sizeof(tmp))) |
1179 | return -EFAULT; | |
9492e135 AC |
1180 | |
1181 | #if 0 | |
1da177e4 LT |
1182 | if ((tmp.irq != bp->irq) || |
1183 | (tmp.port != bp->base) || | |
1184 | (tmp.type != PORT_CIRRUS) || | |
1185 | (tmp.baud_base != (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC) || | |
1186 | (tmp.custom_divisor != 0) || | |
1187 | (tmp.xmit_fifo_size != CD180_NFIFO) || | |
1188 | (tmp.flags & ~RISCOM_LEGAL_FLAGS)) | |
1189 | return -EINVAL; | |
9492e135 AC |
1190 | #endif |
1191 | ||
85f8f810 | 1192 | change_speed = ((port->port.flags & ASYNC_SPD_MASK) != |
1da177e4 | 1193 | (tmp.flags & ASYNC_SPD_MASK)); |
9492e135 | 1194 | |
1da177e4 | 1195 | if (!capable(CAP_SYS_ADMIN)) { |
44b7d1b3 AC |
1196 | if ((tmp.close_delay != port->port.close_delay) || |
1197 | (tmp.closing_wait != port->port.closing_wait) || | |
1da177e4 | 1198 | ((tmp.flags & ~ASYNC_USR_MASK) != |
85f8f810 | 1199 | (port->port.flags & ~ASYNC_USR_MASK))) |
1da177e4 | 1200 | return -EPERM; |
85f8f810 | 1201 | port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | |
1da177e4 LT |
1202 | (tmp.flags & ASYNC_USR_MASK)); |
1203 | } else { | |
85f8f810 | 1204 | port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) | |
1da177e4 | 1205 | (tmp.flags & ASYNC_FLAGS)); |
44b7d1b3 AC |
1206 | port->port.close_delay = tmp.close_delay; |
1207 | port->port.closing_wait = tmp.closing_wait; | |
1da177e4 LT |
1208 | } |
1209 | if (change_speed) { | |
d9afa435 JG |
1210 | unsigned long flags; |
1211 | ||
1212 | spin_lock_irqsave(&riscom_lock, flags); | |
1da177e4 | 1213 | rc_change_speed(bp, port); |
d9afa435 | 1214 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 LT |
1215 | } |
1216 | return 0; | |
1217 | } | |
1218 | ||
9492e135 | 1219 | static int rc_get_serial_info(struct riscom_port *port, |
1da177e4 LT |
1220 | struct serial_struct __user *retinfo) |
1221 | { | |
1222 | struct serial_struct tmp; | |
1223 | struct riscom_board *bp = port_Board(port); | |
9492e135 | 1224 | |
1da177e4 LT |
1225 | memset(&tmp, 0, sizeof(tmp)); |
1226 | tmp.type = PORT_CIRRUS; | |
1227 | tmp.line = port - rc_port; | |
1228 | tmp.port = bp->base; | |
1229 | tmp.irq = bp->irq; | |
85f8f810 | 1230 | tmp.flags = port->port.flags; |
1da177e4 | 1231 | tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC; |
44b7d1b3 AC |
1232 | tmp.close_delay = port->port.close_delay * HZ/100; |
1233 | tmp.closing_wait = port->port.closing_wait * HZ/100; | |
1da177e4 LT |
1234 | tmp.xmit_fifo_size = CD180_NFIFO; |
1235 | return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0; | |
1236 | } | |
1237 | ||
9492e135 | 1238 | static int rc_ioctl(struct tty_struct *tty, struct file *filp, |
1da177e4 | 1239 | unsigned int cmd, unsigned long arg) |
1da177e4 | 1240 | { |
c9f19e96 | 1241 | struct riscom_port *port = tty->driver_data; |
1da177e4 | 1242 | void __user *argp = (void __user *)arg; |
781cff5c | 1243 | int retval; |
9492e135 | 1244 | |
1da177e4 LT |
1245 | if (rc_paranoia_check(port, tty->name, "rc_ioctl")) |
1246 | return -ENODEV; | |
9492e135 | 1247 | |
1da177e4 | 1248 | switch (cmd) { |
9492e135 AC |
1249 | case TIOCGSERIAL: |
1250 | lock_kernel(); | |
eb174552 AC |
1251 | retval = rc_get_serial_info(port, argp); |
1252 | unlock_kernel(); | |
1da177e4 | 1253 | break; |
9492e135 AC |
1254 | case TIOCSSERIAL: |
1255 | lock_kernel(); | |
eb174552 AC |
1256 | retval = rc_set_serial_info(port, argp); |
1257 | unlock_kernel(); | |
1258 | break; | |
9492e135 | 1259 | default: |
eb174552 | 1260 | retval = -ENOIOCTLCMD; |
1da177e4 | 1261 | } |
eb174552 | 1262 | return retval; |
1da177e4 LT |
1263 | } |
1264 | ||
9492e135 | 1265 | static void rc_throttle(struct tty_struct *tty) |
1da177e4 | 1266 | { |
c9f19e96 | 1267 | struct riscom_port *port = tty->driver_data; |
1da177e4 LT |
1268 | struct riscom_board *bp; |
1269 | unsigned long flags; | |
9492e135 | 1270 | |
1da177e4 LT |
1271 | if (rc_paranoia_check(port, tty->name, "rc_throttle")) |
1272 | return; | |
1da177e4 | 1273 | bp = port_Board(port); |
d9afa435 JG |
1274 | |
1275 | spin_lock_irqsave(&riscom_lock, flags); | |
1da177e4 LT |
1276 | port->MSVR &= ~MSVR_RTS; |
1277 | rc_out(bp, CD180_CAR, port_No(port)); | |
d9afa435 | 1278 | if (I_IXOFF(tty)) { |
1da177e4 LT |
1279 | rc_wait_CCR(bp); |
1280 | rc_out(bp, CD180_CCR, CCR_SSCH2); | |
1281 | rc_wait_CCR(bp); | |
1282 | } | |
1283 | rc_out(bp, CD180_MSVR, port->MSVR); | |
d9afa435 | 1284 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 LT |
1285 | } |
1286 | ||
9492e135 | 1287 | static void rc_unthrottle(struct tty_struct *tty) |
1da177e4 | 1288 | { |
c9f19e96 | 1289 | struct riscom_port *port = tty->driver_data; |
1da177e4 LT |
1290 | struct riscom_board *bp; |
1291 | unsigned long flags; | |
9492e135 | 1292 | |
1da177e4 LT |
1293 | if (rc_paranoia_check(port, tty->name, "rc_unthrottle")) |
1294 | return; | |
1da177e4 | 1295 | bp = port_Board(port); |
d9afa435 | 1296 | |
9492e135 | 1297 | spin_lock_irqsave(&riscom_lock, flags); |
1da177e4 LT |
1298 | port->MSVR |= MSVR_RTS; |
1299 | rc_out(bp, CD180_CAR, port_No(port)); | |
1300 | if (I_IXOFF(tty)) { | |
1301 | rc_wait_CCR(bp); | |
1302 | rc_out(bp, CD180_CCR, CCR_SSCH1); | |
1303 | rc_wait_CCR(bp); | |
1304 | } | |
1305 | rc_out(bp, CD180_MSVR, port->MSVR); | |
d9afa435 | 1306 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 LT |
1307 | } |
1308 | ||
9492e135 | 1309 | static void rc_stop(struct tty_struct *tty) |
1da177e4 | 1310 | { |
c9f19e96 | 1311 | struct riscom_port *port = tty->driver_data; |
1da177e4 LT |
1312 | struct riscom_board *bp; |
1313 | unsigned long flags; | |
9492e135 | 1314 | |
1da177e4 LT |
1315 | if (rc_paranoia_check(port, tty->name, "rc_stop")) |
1316 | return; | |
9492e135 | 1317 | |
1da177e4 | 1318 | bp = port_Board(port); |
d9afa435 | 1319 | |
9492e135 | 1320 | spin_lock_irqsave(&riscom_lock, flags); |
1da177e4 LT |
1321 | port->IER &= ~IER_TXRDY; |
1322 | rc_out(bp, CD180_CAR, port_No(port)); | |
1323 | rc_out(bp, CD180_IER, port->IER); | |
d9afa435 | 1324 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 LT |
1325 | } |
1326 | ||
9492e135 | 1327 | static void rc_start(struct tty_struct *tty) |
1da177e4 | 1328 | { |
c9f19e96 | 1329 | struct riscom_port *port = tty->driver_data; |
1da177e4 LT |
1330 | struct riscom_board *bp; |
1331 | unsigned long flags; | |
9492e135 | 1332 | |
1da177e4 LT |
1333 | if (rc_paranoia_check(port, tty->name, "rc_start")) |
1334 | return; | |
9492e135 | 1335 | |
1da177e4 | 1336 | bp = port_Board(port); |
9492e135 | 1337 | |
d9afa435 JG |
1338 | spin_lock_irqsave(&riscom_lock, flags); |
1339 | ||
85f8f810 | 1340 | if (port->xmit_cnt && port->port.xmit_buf && !(port->IER & IER_TXRDY)) { |
1da177e4 LT |
1341 | port->IER |= IER_TXRDY; |
1342 | rc_out(bp, CD180_CAR, port_No(port)); | |
1343 | rc_out(bp, CD180_IER, port->IER); | |
1344 | } | |
d9afa435 | 1345 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 LT |
1346 | } |
1347 | ||
9492e135 | 1348 | static void rc_hangup(struct tty_struct *tty) |
1da177e4 | 1349 | { |
c9f19e96 | 1350 | struct riscom_port *port = tty->driver_data; |
1da177e4 | 1351 | struct riscom_board *bp; |
c2ba38cd | 1352 | unsigned long flags; |
9492e135 | 1353 | |
1da177e4 LT |
1354 | if (rc_paranoia_check(port, tty->name, "rc_hangup")) |
1355 | return; | |
9492e135 | 1356 | |
1da177e4 | 1357 | bp = port_Board(port); |
9492e135 | 1358 | |
d99101fd | 1359 | rc_shutdown_port(tty, bp, port); |
c2ba38cd | 1360 | spin_lock_irqsave(&port->port.lock, flags); |
85f8f810 AC |
1361 | port->port.count = 0; |
1362 | port->port.flags &= ~ASYNC_NORMAL_ACTIVE; | |
1363 | port->port.tty = NULL; | |
1364 | wake_up_interruptible(&port->port.open_wait); | |
c2ba38cd | 1365 | spin_unlock_irqrestore(&port->port.lock, flags); |
1da177e4 LT |
1366 | } |
1367 | ||
9492e135 AC |
1368 | static void rc_set_termios(struct tty_struct *tty, |
1369 | struct ktermios *old_termios) | |
1da177e4 | 1370 | { |
c9f19e96 | 1371 | struct riscom_port *port = tty->driver_data; |
1da177e4 | 1372 | unsigned long flags; |
9492e135 | 1373 | |
1da177e4 LT |
1374 | if (rc_paranoia_check(port, tty->name, "rc_set_termios")) |
1375 | return; | |
1da177e4 | 1376 | |
d9afa435 | 1377 | spin_lock_irqsave(&riscom_lock, flags); |
1da177e4 | 1378 | rc_change_speed(port_Board(port), port); |
d9afa435 | 1379 | spin_unlock_irqrestore(&riscom_lock, flags); |
1da177e4 LT |
1380 | |
1381 | if ((old_termios->c_cflag & CRTSCTS) && | |
1382 | !(tty->termios->c_cflag & CRTSCTS)) { | |
1383 | tty->hw_stopped = 0; | |
1384 | rc_start(tty); | |
1385 | } | |
1386 | } | |
1387 | ||
b68e31d0 | 1388 | static const struct tty_operations riscom_ops = { |
1da177e4 LT |
1389 | .open = rc_open, |
1390 | .close = rc_close, | |
1391 | .write = rc_write, | |
1392 | .put_char = rc_put_char, | |
1393 | .flush_chars = rc_flush_chars, | |
1394 | .write_room = rc_write_room, | |
1395 | .chars_in_buffer = rc_chars_in_buffer, | |
1396 | .flush_buffer = rc_flush_buffer, | |
1397 | .ioctl = rc_ioctl, | |
1398 | .throttle = rc_throttle, | |
1399 | .unthrottle = rc_unthrottle, | |
1400 | .set_termios = rc_set_termios, | |
1401 | .stop = rc_stop, | |
1402 | .start = rc_start, | |
1403 | .hangup = rc_hangup, | |
1404 | .tiocmget = rc_tiocmget, | |
1405 | .tiocmset = rc_tiocmset, | |
781cff5c | 1406 | .break_ctl = rc_send_break, |
1da177e4 LT |
1407 | }; |
1408 | ||
31f35939 AC |
1409 | static const struct tty_port_operations riscom_port_ops = { |
1410 | .carrier_raised = carrier_raised, | |
1411 | }; | |
1412 | ||
1413 | ||
1386a820 | 1414 | static int __init rc_init_drivers(void) |
1da177e4 LT |
1415 | { |
1416 | int error; | |
1417 | int i; | |
1418 | ||
1419 | riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT); | |
9492e135 | 1420 | if (!riscom_driver) |
1da177e4 | 1421 | return -ENOMEM; |
9492e135 | 1422 | |
1da177e4 LT |
1423 | riscom_driver->owner = THIS_MODULE; |
1424 | riscom_driver->name = "ttyL"; | |
1da177e4 LT |
1425 | riscom_driver->major = RISCOM8_NORMAL_MAJOR; |
1426 | riscom_driver->type = TTY_DRIVER_TYPE_SERIAL; | |
1427 | riscom_driver->subtype = SERIAL_TYPE_NORMAL; | |
1428 | riscom_driver->init_termios = tty_std_termios; | |
1429 | riscom_driver->init_termios.c_cflag = | |
1430 | B9600 | CS8 | CREAD | HUPCL | CLOCAL; | |
606d099c AC |
1431 | riscom_driver->init_termios.c_ispeed = 9600; |
1432 | riscom_driver->init_termios.c_ospeed = 9600; | |
781cff5c | 1433 | riscom_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK; |
1da177e4 | 1434 | tty_set_operations(riscom_driver, &riscom_ops); |
9492e135 AC |
1435 | error = tty_register_driver(riscom_driver); |
1436 | if (error != 0) { | |
1da177e4 LT |
1437 | put_tty_driver(riscom_driver); |
1438 | printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, " | |
9492e135 | 1439 | "error = %d\n", error); |
1da177e4 LT |
1440 | return 1; |
1441 | } | |
1da177e4 LT |
1442 | memset(rc_port, 0, sizeof(rc_port)); |
1443 | for (i = 0; i < RC_NPORT * RC_NBOARD; i++) { | |
85f8f810 | 1444 | tty_port_init(&rc_port[i].port); |
31f35939 | 1445 | rc_port[i].port.ops = &riscom_port_ops; |
44b7d1b3 | 1446 | rc_port[i].magic = RISCOM8_MAGIC; |
1da177e4 | 1447 | } |
1da177e4 LT |
1448 | return 0; |
1449 | } | |
1450 | ||
1451 | static void rc_release_drivers(void) | |
1452 | { | |
1da177e4 LT |
1453 | tty_unregister_driver(riscom_driver); |
1454 | put_tty_driver(riscom_driver); | |
1da177e4 LT |
1455 | } |
1456 | ||
1457 | #ifndef MODULE | |
1458 | /* | |
1459 | * Called at boot time. | |
9492e135 | 1460 | * |
1da177e4 LT |
1461 | * You can specify IO base for up to RC_NBOARD cards, |
1462 | * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt. | |
1463 | * Note that there will be no probing at default | |
1464 | * addresses in this case. | |
1465 | * | |
9492e135 | 1466 | */ |
1da177e4 LT |
1467 | static int __init riscom8_setup(char *str) |
1468 | { | |
1469 | int ints[RC_NBOARD]; | |
1470 | int i; | |
1471 | ||
1472 | str = get_options(str, ARRAY_SIZE(ints), ints); | |
1473 | ||
1474 | for (i = 0; i < RC_NBOARD; i++) { | |
1475 | if (i < ints[0]) | |
1476 | rc_board[i].base = ints[i+1]; | |
9492e135 | 1477 | else |
1da177e4 LT |
1478 | rc_board[i].base = 0; |
1479 | } | |
1480 | return 1; | |
1481 | } | |
1482 | ||
1483 | __setup("riscom8=", riscom8_setup); | |
1484 | #endif | |
1485 | ||
1486 | static char banner[] __initdata = | |
1487 | KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin " | |
1488 | "1994-1996.\n"; | |
1489 | static char no_boards_msg[] __initdata = | |
1490 | KERN_INFO "rc: No RISCom/8 boards detected.\n"; | |
1491 | ||
9492e135 AC |
1492 | /* |
1493 | * This routine must be called by kernel at boot time | |
1da177e4 LT |
1494 | */ |
1495 | static int __init riscom8_init(void) | |
1496 | { | |
1497 | int i; | |
1498 | int found = 0; | |
1499 | ||
1500 | printk(banner); | |
1501 | ||
9492e135 | 1502 | if (rc_init_drivers()) |
1da177e4 LT |
1503 | return -EIO; |
1504 | ||
9492e135 AC |
1505 | for (i = 0; i < RC_NBOARD; i++) |
1506 | if (rc_board[i].base && !rc_probe(&rc_board[i])) | |
1da177e4 | 1507 | found++; |
1da177e4 LT |
1508 | if (!found) { |
1509 | rc_release_drivers(); | |
1510 | printk(no_boards_msg); | |
1511 | return -EIO; | |
1512 | } | |
1513 | return 0; | |
1514 | } | |
1515 | ||
1516 | #ifdef MODULE | |
1517 | static int iobase; | |
1518 | static int iobase1; | |
1519 | static int iobase2; | |
1520 | static int iobase3; | |
8d3b33f6 RR |
1521 | module_param(iobase, int, 0); |
1522 | module_param(iobase1, int, 0); | |
1523 | module_param(iobase2, int, 0); | |
1524 | module_param(iobase3, int, 0); | |
1da177e4 LT |
1525 | |
1526 | MODULE_LICENSE("GPL"); | |
1527 | #endif /* MODULE */ | |
1528 | ||
1529 | /* | |
1530 | * You can setup up to 4 boards (current value of RC_NBOARD) | |
1531 | * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter. | |
1532 | * | |
1533 | */ | |
9492e135 | 1534 | static int __init riscom8_init_module(void) |
1da177e4 LT |
1535 | { |
1536 | #ifdef MODULE | |
1537 | int i; | |
1538 | ||
1539 | if (iobase || iobase1 || iobase2 || iobase3) { | |
9492e135 | 1540 | for (i = 0; i < RC_NBOARD; i++) |
9efda797 | 1541 | rc_board[i].base = 0; |
1da177e4 LT |
1542 | } |
1543 | ||
1544 | if (iobase) | |
1545 | rc_board[0].base = iobase; | |
1546 | if (iobase1) | |
1547 | rc_board[1].base = iobase1; | |
1548 | if (iobase2) | |
1549 | rc_board[2].base = iobase2; | |
1550 | if (iobase3) | |
1551 | rc_board[3].base = iobase3; | |
1552 | #endif /* MODULE */ | |
1553 | ||
1554 | return riscom8_init(); | |
1555 | } | |
9492e135 AC |
1556 | |
1557 | static void __exit riscom8_exit_module(void) | |
1da177e4 LT |
1558 | { |
1559 | int i; | |
9492e135 | 1560 | |
1da177e4 | 1561 | rc_release_drivers(); |
9492e135 AC |
1562 | for (i = 0; i < RC_NBOARD; i++) |
1563 | if (rc_board[i].flags & RC_BOARD_PRESENT) | |
1da177e4 | 1564 | rc_release_io_range(&rc_board[i]); |
9492e135 | 1565 | |
1da177e4 LT |
1566 | } |
1567 | ||
1568 | module_init(riscom8_init_module); | |
1569 | module_exit(riscom8_exit_module); |