1 /*
2 * linux/drivers/char/serial.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997,
6 * 1998, 1999 Theodore Ts'o
7 *
8 * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now
9 * much more extensible to support other serial cards based on the
10 * 16450/16550A UART's. Added support for the AST FourPort and the
11 * Accent Async board.
12 *
13 * set_serial_info fixed to set the flags, custom divisor, and uart
14 * type fields. Fix suggested by Michael K. Johnson 12/12/92.
15 *
16 * 11/95: TIOCMIWAIT, TIOCGICOUNT by Angelo Haritsis <ah@doc.ic.ac.uk>
17 *
18 * 03/96: Modularised by Angelo Haritsis <ah@doc.ic.ac.uk>
19 *
20 * rs_set_termios fixed to look also for changes of the input
21 * flags INPCK, BRKINT, PARMRK, IGNPAR and IGNBRK.
22 * Bernd Anh�upl 05/17/96.
23 *
24 * 1/97: Extended dumb serial ports are a config option now.
25 * Saves 4k. Michael A. Griffith <grif@acm.org>
26 *
27 * 8/97: Fix bug in rs_set_termios with RTS
28 * Stanislav V. Voronyi <stas@uanet.kharkov.ua>
29 *
30 * 3/98: Change the IRQ detection, use of probe_irq_o*(),
31 * suppress TIOCSERGWILD and TIOCSERSWILD
32 * Etienne Lorrain <etienne.lorrain@ibm.net>
33 *
34 * 4/98: Added changes to support the ARM architecture proposed by
35 * Russell King
36 *
37 * 5/99: Updated to include support for the XR16C850 and ST16C654
38 * uarts. Stuart MacDonald <stuartm@connecttech.com>
39 *
40 * 8/99: Generalized PCI support added. Theodore Ts'o
41 *
42 * 3/00: Rid circular buffer of redundant xmit_cnt. Fix a
43 * few races on freeing buffers too.
44 * Alan Modra <alan@linuxcare.com>
45 *
46 * 5/00: Support for the RSA-DV II/S card added.
47 * Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
48 *
49 * 6/00: Remove old-style timer, use timer_list
50 * Andrew Morton <andrewm@uow.edu.au>
51 *
52 * 7/00: Support Timedia/Sunix/Exsys PCI cards
53 *
54 * 7/00: fix some returns on failure not using MOD_DEC_USE_COUNT.
55 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
56 *
57 * 10/00: add in optional software flow control for serial console.
58 * Kanoj Sarcar <kanoj@sgi.com> (Modified by Theodore Ts'o)
59 *
60 * 02/02: Fix for AMD Elan bug in transmit irq routine, by
61 * Christer Weinigel <wingel@hog.ctrl-c.liu.se>,
62 * Robert Schwebel <robert@schwebel.de>,
63 * Juergen Beisert <jbeisert@eurodsn.de>,
64 * Theodore Ts'o <tytso@mit.edu>
65 */
66
67 static char *serial_version = "5.05c";
68 static char *serial_revdate = "2001-07-08";
69
70 /*
71 * Serial driver configuration section. Here are the various options:
72 *
73 * CONFIG_HUB6
74 * Enables support for the venerable Bell Technologies
75 * HUB6 card.
76 *
77 * CONFIG_SERIAL_MANY_PORTS
78 * Enables support for ports beyond the standard, stupid
79 * COM 1/2/3/4.
80 *
81 * CONFIG_SERIAL_MULTIPORT
82 * Enables support for special multiport board support.
83 *
84 * CONFIG_SERIAL_SHARE_IRQ
85 * Enables support for multiple serial ports on one IRQ
86 *
87 * CONFIG_SERIAL_DETECT_IRQ
88 * Enable the autodetection of IRQ on standart ports
89 *
90 * SERIAL_PARANOIA_CHECK
91 * Check the magic number for the async_structure where
92 * ever possible.
93 *
94 * CONFIG_SERIAL_ACPI
95 * Enable support for serial console port and serial
96 * debug port as defined by the SPCR and DBGP tables in
97 * ACPI 2.0.
98 */
99
100 #include <linux/config.h>
101 #include <linux/version.h>
102
103 #undef SERIAL_PARANOIA_CHECK
104 #define CONFIG_SERIAL_NOPAUSE_IO
105 #define SERIAL_DO_RESTART
106
107 #if 0
108 /* These defines are normally controlled by the autoconf.h */
109 #define CONFIG_SERIAL_MANY_PORTS
110 #define CONFIG_SERIAL_SHARE_IRQ
111 #define CONFIG_SERIAL_DETECT_IRQ
112 #define CONFIG_SERIAL_MULTIPORT
113 #define CONFIG_HUB6
114 #endif
115
116 #ifdef CONFIG_PCI
117 #define ENABLE_SERIAL_PCI
118 #ifndef CONFIG_SERIAL_SHARE_IRQ
119 #define CONFIG_SERIAL_SHARE_IRQ
120 #endif
121 #ifndef CONFIG_SERIAL_MANY_PORTS
122 #define CONFIG_SERIAL_MANY_PORTS
123 #endif
124 #endif
125
126 #ifdef CONFIG_SERIAL_ACPI
127 #define ENABLE_SERIAL_ACPI
128 #endif
129
130 #if defined(CONFIG_ISAPNP)|| (defined(CONFIG_ISAPNP_MODULE) && defined(MODULE))
131 #ifndef ENABLE_SERIAL_PNP
132 #define ENABLE_SERIAL_PNP
133 #endif
134 #endif
135
136 /* Set of debugging defines */
137
138 #undef SERIAL_DEBUG_INTR
139 #undef SERIAL_DEBUG_OPEN
140 #undef SERIAL_DEBUG_FLOW
141 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
142 #undef SERIAL_DEBUG_PCI
143 #undef SERIAL_DEBUG_AUTOCONF
144
145 /* Sanity checks */
146
147 #ifdef CONFIG_SERIAL_MULTIPORT
148 #ifndef CONFIG_SERIAL_SHARE_IRQ
149 #define CONFIG_SERIAL_SHARE_IRQ
150 #endif
151 #endif
152
153 #ifdef CONFIG_HUB6
154 #ifndef CONFIG_SERIAL_MANY_PORTS
155 #define CONFIG_SERIAL_MANY_PORTS
156 #endif
157 #ifndef CONFIG_SERIAL_SHARE_IRQ
158 #define CONFIG_SERIAL_SHARE_IRQ
159 #endif
160 #endif
161
162 #ifdef MODULE
163 #undef CONFIG_SERIAL_CONSOLE
164 #endif
165
166 #define CONFIG_SERIAL_RSA
167
168 #define RS_STROBE_TIME (10*HZ)
169 #define RS_ISR_PASS_LIMIT 256
170
171 #if defined(__i386__) && (defined(CONFIG_M386) || defined(CONFIG_M486))
172 #define SERIAL_INLINE
173 #endif
174
175 /*
176 * End of serial driver configuration section.
177 */
178
179 #include <linux/module.h>
180
181 #include <linux/types.h>
182 #ifdef LOCAL_HEADERS
183 #include "serial_local.h"
184 #else
185 #include <linux/serial.h>
186 #include <linux/serialP.h>
187 #include <linux/serial_reg.h>
188 #include <asm/serial.h>
189 #define LOCAL_VERSTRING ""
190 #endif
191
192 #include <linux/errno.h>
193 #include <linux/signal.h>
194 #include <linux/sched.h>
195 #include <linux/timer.h>
196 #include <linux/interrupt.h>
197 #include <linux/tty.h>
198 #include <linux/tty_flip.h>
199 #include <linux/major.h>
200 #include <linux/string.h>
201 #include <linux/fcntl.h>
202 #include <linux/ptrace.h>
203 #include <linux/ioport.h>
204 #include <linux/mm.h>
205 #include <linux/slab.h>
206 #if (LINUX_VERSION_CODE >= 131343)
207 #include <linux/init.h>
208 #endif
209 #if (LINUX_VERSION_CODE >= 131336)
210 #include <asm/uaccess.h>
211 #endif
212 #include <linux/delay.h>
213 #ifdef CONFIG_SERIAL_CONSOLE
214 #include <linux/console.h>
215 #endif
216 #ifdef ENABLE_SERIAL_PCI
217 #include <linux/pci.h>
218 #endif
219 #ifdef ENABLE_SERIAL_PNP
220 #include <linux/isapnp.h>
221 #endif
222 #ifdef CONFIG_MAGIC_SYSRQ
223 #include <linux/sysrq.h>
224 #endif
225
226 /*
227 * All of the compatibilty code so we can compile serial.c against
228 * older kernels is hidden in serial_compat.h
229 */
230 #if defined(LOCAL_HEADERS) || (LINUX_VERSION_CODE < 0x020317) /* 2.3.23 */
231 #include "serial_compat.h"
232 #endif
233
234 #include <asm/system.h>
235 #include <asm/io.h>
236 #include <asm/irq.h>
237 #include <asm/bitops.h>
238
239 #if defined(CONFIG_MAC_SERIAL)
240 #define SERIAL_DEV_OFFSET ((_machine == _MACH_prep || _machine == _MACH_chrp) ? 0 : 2)
241 #else
242 #define SERIAL_DEV_OFFSET 0
243 #endif
244
245 #ifdef SERIAL_INLINE
246 #define _INLINE_ inline
247 #else
248 #define _INLINE_
249 #endif
250
251 static char *serial_name = "Serial driver";
252
253 static DECLARE_TASK_QUEUE(tq_serial);
254
255 static struct tty_driver serial_driver, callout_driver;
256 static int serial_refcount;
257
258 static struct timer_list serial_timer;
259
260 /* serial subtype definitions */
261 #ifndef SERIAL_TYPE_NORMAL
262 #define SERIAL_TYPE_NORMAL 1
263 #define SERIAL_TYPE_CALLOUT 2
264 #endif
265
266 /* number of characters left in xmit buffer before we ask for more */
267 #define WAKEUP_CHARS 256
268
269 /*
270 * IRQ_timeout - How long the timeout should be for each IRQ
271 * should be after the IRQ has been active.
272 */
273
274 static struct async_struct *IRQ_ports[NR_IRQS];
275 #ifdef CONFIG_SERIAL_MULTIPORT
276 static struct rs_multiport_struct rs_multiport[NR_IRQS];
277 #endif
278 static int IRQ_timeout[NR_IRQS];
279 #ifdef CONFIG_SERIAL_CONSOLE
280 static struct console sercons;
281 static int lsr_break_flag;
282 #endif
283 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
284 static unsigned long break_pressed; /* break, really ... */
285 #endif
286
287 static unsigned detect_uart_irq (struct serial_state * state);
288 static void autoconfig(struct serial_state * state);
289 static void change_speed(struct async_struct *info, struct termios *old);
290 static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
291
292 /*
293 * Here we define the default xmit fifo size used for each type of
294 * UART
295 */
296 static struct serial_uart_config uart_config[] = {
297 { "unknown", 1, 0 },
298 { "8250", 1, 0 },
299 { "16450", 1, 0 },
300 { "16550", 1, 0 },
301 { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO },
302 { "cirrus", 1, 0 }, /* usurped by cyclades.c */
303 { "ST16650", 1, UART_CLEAR_FIFO | UART_STARTECH },
304 { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO |
305 UART_STARTECH },
306 { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO},
307 { "Startech", 1, 0}, /* usurped by cyclades.c */
308 { "16C950/954", 128, UART_CLEAR_FIFO | UART_USE_FIFO},
309 { "ST16654", 64, UART_CLEAR_FIFO | UART_USE_FIFO |
310 UART_STARTECH },
311 { "XR16850", 128, UART_CLEAR_FIFO | UART_USE_FIFO |
312 UART_STARTECH },
313 { "RSA", 2048, UART_CLEAR_FIFO | UART_USE_FIFO },
314 { 0, 0}
315 };
316
317 #if defined(CONFIG_SERIAL_RSA) && defined(MODULE)
318
319 #define PORT_RSA_MAX 4
320 static int probe_rsa[PORT_RSA_MAX];
321 static int force_rsa[PORT_RSA_MAX];
322
323 MODULE_PARM(probe_rsa, "1-" __MODULE_STRING(PORT_RSA_MAX) "i");
324 MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
325 MODULE_PARM(force_rsa, "1-" __MODULE_STRING(PORT_RSA_MAX) "i");
326 MODULE_PARM_DESC(force_rsa, "Force I/O ports for RSA");
327 #endif /* CONFIG_SERIAL_RSA */
328
329 struct serial_state rs_table[RS_TABLE_SIZE] = {
330 SERIAL_PORT_DFNS /* Defined in serial.h */
331 };
332
333 #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
334 int serial_nr_ports = NR_PORTS;
335
336 #if (defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP))
337 #define NR_PCI_BOARDS 8
338
339 static struct pci_board_inst serial_pci_board[NR_PCI_BOARDS];
340
341 #ifndef IS_PCI_REGION_IOPORT
342 #define IS_PCI_REGION_IOPORT(dev, r) (pci_resource_flags((dev), (r)) & \
343 IORESOURCE_IO)
344 #endif
345 #ifndef IS_PCI_REGION_IOMEM
346 #define IS_PCI_REGION_IOMEM(dev, r) (pci_resource_flags((dev), (r)) & \
347 IORESOURCE_MEM)
348 #endif
349 #ifndef PCI_IRQ_RESOURCE
350 #define PCI_IRQ_RESOURCE(dev, r) ((dev)->irq_resource[r].start)
351 #endif
352 #ifndef pci_get_subvendor
353 #define pci_get_subvendor(dev) ((dev)->subsystem_vendor)
354 #define pci_get_subdevice(dev) ((dev)->subsystem_device)
355 #endif
356 #endif /* ENABLE_SERIAL_PCI || ENABLE_SERIAL_PNP */
357
358 #ifndef PREPARE_FUNC
359 #define PREPARE_FUNC(dev) (dev->prepare)
360 #define ACTIVATE_FUNC(dev) (dev->activate)
361 #define DEACTIVATE_FUNC(dev) (dev->deactivate)
362 #endif
363
364 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
365
366 static struct tty_struct *serial_table[NR_PORTS];
367 static struct termios *serial_termios[NR_PORTS];
368 static struct termios *serial_termios_locked[NR_PORTS];
369
370
371 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
372 #define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
373 kdevname(tty->device), (info->flags), serial_refcount,info->count,tty->count,s)
374 #else
375 #define DBG_CNT(s)
376 #endif
377
378 /*
379 * tmp_buf is used as a temporary buffer by serial_write. We need to
380 * lock it in case the copy_from_user blocks while swapping in a page,
381 * and some other program tries to do a serial write at the same time.
382 * Since the lock will only come under contention when the system is
383 * swapping and available memory is low, it makes sense to share one
384 * buffer across all the serial ports, since it significantly saves
385 * memory if large numbers of serial ports are open.
386 */
387 static unsigned char *tmp_buf;
388 #ifdef DECLARE_MUTEX
389 static DECLARE_MUTEX(tmp_buf_sem);
390 #else
391 static struct semaphore tmp_buf_sem = MUTEX;
392 #endif
393
394
serial_paranoia_check(struct async_struct * info,kdev_t device,const char * routine)395 static inline int serial_paranoia_check(struct async_struct *info,
396 kdev_t device, const char *routine)
397 {
398 #ifdef SERIAL_PARANOIA_CHECK
399 static const char *badmagic =
400 "Warning: bad magic number for serial struct (%s) in %s\n";
401 static const char *badinfo =
402 "Warning: null async_struct for (%s) in %s\n";
403
404 if (!info) {
405 printk(badinfo, kdevname(device), routine);
406 return 1;
407 }
408 if (info->magic != SERIAL_MAGIC) {
409 printk(badmagic, kdevname(device), routine);
410 return 1;
411 }
412 #endif
413 return 0;
414 }
415
serial_in(struct async_struct * info,int offset)416 static _INLINE_ unsigned int serial_in(struct async_struct *info, int offset)
417 {
418 switch (info->io_type) {
419 #ifdef CONFIG_HUB6
420 case SERIAL_IO_HUB6:
421 outb(info->hub6 - 1 + offset, info->port);
422 return inb(info->port+1);
423 #endif
424 case SERIAL_IO_MEM:
425 return readb((unsigned long) info->iomem_base +
426 (offset<<info->iomem_reg_shift));
427 default:
428 return inb(info->port + offset);
429 }
430 }
431
serial_out(struct async_struct * info,int offset,int value)432 static _INLINE_ void serial_out(struct async_struct *info, int offset,
433 int value)
434 {
435 switch (info->io_type) {
436 #ifdef CONFIG_HUB6
437 case SERIAL_IO_HUB6:
438 outb(info->hub6 - 1 + offset, info->port);
439 outb(value, info->port+1);
440 break;
441 #endif
442 case SERIAL_IO_MEM:
443 writeb(value, (unsigned long) info->iomem_base +
444 (offset<<info->iomem_reg_shift));
445 break;
446 default:
447 outb(value, info->port+offset);
448 }
449 }
450
451 /*
452 * We used to support using pause I/O for certain machines. We
453 * haven't supported this for a while, but just in case it's badly
454 * needed for certain old 386 machines, I've left these #define's
455 * in....
456 */
457 #define serial_inp(info, offset) serial_in(info, offset)
458 #define serial_outp(info, offset, value) serial_out(info, offset, value)
459
460
461 /*
462 * For the 16C950
463 */
serial_icr_write(struct async_struct * info,int offset,int value)464 void serial_icr_write(struct async_struct *info, int offset, int value)
465 {
466 serial_out(info, UART_SCR, offset);
467 serial_out(info, UART_ICR, value);
468 }
469
serial_icr_read(struct async_struct * info,int offset)470 unsigned int serial_icr_read(struct async_struct *info, int offset)
471 {
472 int value;
473
474 serial_icr_write(info, UART_ACR, info->ACR | UART_ACR_ICRRD);
475 serial_out(info, UART_SCR, offset);
476 value = serial_in(info, UART_ICR);
477 serial_icr_write(info, UART_ACR, info->ACR);
478 return value;
479 }
480
481 /*
482 * ------------------------------------------------------------
483 * rs_stop() and rs_start()
484 *
485 * This routines are called before setting or resetting tty->stopped.
486 * They enable or disable transmitter interrupts, as necessary.
487 * ------------------------------------------------------------
488 */
rs_stop(struct tty_struct * tty)489 static void rs_stop(struct tty_struct *tty)
490 {
491 struct async_struct *info = (struct async_struct *)tty->driver_data;
492 unsigned long flags;
493
494 if (serial_paranoia_check(info, tty->device, "rs_stop"))
495 return;
496
497 save_flags(flags); cli();
498 if (info->IER & UART_IER_THRI) {
499 info->IER &= ~UART_IER_THRI;
500 serial_out(info, UART_IER, info->IER);
501 }
502 if (info->state->type == PORT_16C950) {
503 info->ACR |= UART_ACR_TXDIS;
504 serial_icr_write(info, UART_ACR, info->ACR);
505 }
506 restore_flags(flags);
507 }
508
rs_start(struct tty_struct * tty)509 static void rs_start(struct tty_struct *tty)
510 {
511 struct async_struct *info = (struct async_struct *)tty->driver_data;
512 unsigned long flags;
513
514 if (serial_paranoia_check(info, tty->device, "rs_start"))
515 return;
516
517 save_flags(flags); cli();
518 if (info->xmit.head != info->xmit.tail
519 && info->xmit.buf
520 && !(info->IER & UART_IER_THRI)) {
521 info->IER |= UART_IER_THRI;
522 serial_out(info, UART_IER, info->IER);
523 }
524 if (info->state->type == PORT_16C950) {
525 info->ACR &= ~UART_ACR_TXDIS;
526 serial_icr_write(info, UART_ACR, info->ACR);
527 }
528 restore_flags(flags);
529 }
530
531 /*
532 * ----------------------------------------------------------------------
533 *
534 * Here starts the interrupt handling routines. All of the following
535 * subroutines are declared as inline and are folded into
536 * rs_interrupt(). They were separated out for readability's sake.
537 *
538 * Note: rs_interrupt() is a "fast" interrupt, which means that it
539 * runs with interrupts turned off. People who may want to modify
540 * rs_interrupt() should try to keep the interrupt handler as fast as
541 * possible. After you are done making modifications, it is not a bad
542 * idea to do:
543 *
544 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
545 *
546 * and look at the resulting assemble code in serial.s.
547 *
548 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
549 * -----------------------------------------------------------------------
550 */
551
552 /*
553 * This routine is used by the interrupt handler to schedule
554 * processing in the software interrupt portion of the driver.
555 */
rs_sched_event(struct async_struct * info,int event)556 static _INLINE_ void rs_sched_event(struct async_struct *info,
557 int event)
558 {
559 info->event |= 1 << event;
560 queue_task(&info->tqueue, &tq_serial);
561 mark_bh(SERIAL_BH);
562 }
563
receive_chars(struct async_struct * info,int * status,struct pt_regs * regs)564 static _INLINE_ void receive_chars(struct async_struct *info,
565 int *status, struct pt_regs * regs)
566 {
567 struct tty_struct *tty = info->tty;
568 unsigned char ch;
569 struct async_icount *icount;
570 int max_count = 256;
571
572 icount = &info->state->icount;
573 do {
574 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
575 tty->flip.tqueue.routine((void *) tty);
576 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
577 /* no room in flip buffer, discard rx FIFO contents to clear IRQ
578 * *FIXME* Hardware with auto flow control
579 * would benefit from leaving the data in the FIFO and
580 * disabling the rx IRQ until space becomes available.
581 */
582 do {
583 serial_inp(info, UART_RX);
584 icount->overrun++;
585 *status = serial_inp(info, UART_LSR);
586 } while ((*status & UART_LSR_DR) && (max_count-- > 0));
587 return; // if TTY_DONT_FLIP is set
588 }
589 }
590 ch = serial_inp(info, UART_RX);
591 *tty->flip.char_buf_ptr = ch;
592 icount->rx++;
593
594 #ifdef SERIAL_DEBUG_INTR
595 printk("DR%02x:%02x...", ch, *status);
596 #endif
597 *tty->flip.flag_buf_ptr = 0;
598 if (*status & (UART_LSR_BI | UART_LSR_PE |
599 UART_LSR_FE | UART_LSR_OE)) {
600 /*
601 * For statistics only
602 */
603 if (*status & UART_LSR_BI) {
604 *status &= ~(UART_LSR_FE | UART_LSR_PE);
605 icount->brk++;
606 /*
607 * We do the SysRQ and SAK checking
608 * here because otherwise the break
609 * may get masked by ignore_status_mask
610 * or read_status_mask.
611 */
612 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
613 if (info->line == sercons.index) {
614 if (!break_pressed) {
615 break_pressed = jiffies;
616 goto ignore_char;
617 }
618 break_pressed = 0;
619 }
620 #endif
621 if (info->flags & ASYNC_SAK)
622 do_SAK(tty);
623 } else if (*status & UART_LSR_PE)
624 icount->parity++;
625 else if (*status & UART_LSR_FE)
626 icount->frame++;
627 if (*status & UART_LSR_OE)
628 icount->overrun++;
629
630 /*
631 * Mask off conditions which should be ignored.
632 */
633 *status &= info->read_status_mask;
634
635 #ifdef CONFIG_SERIAL_CONSOLE
636 if (info->line == sercons.index) {
637 /* Recover the break flag from console xmit */
638 *status |= lsr_break_flag;
639 lsr_break_flag = 0;
640 }
641 #endif
642 if (*status & (UART_LSR_BI)) {
643 #ifdef SERIAL_DEBUG_INTR
644 printk("handling break....");
645 #endif
646 *tty->flip.flag_buf_ptr = TTY_BREAK;
647 } else if (*status & UART_LSR_PE)
648 *tty->flip.flag_buf_ptr = TTY_PARITY;
649 else if (*status & UART_LSR_FE)
650 *tty->flip.flag_buf_ptr = TTY_FRAME;
651 }
652 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
653 if (break_pressed && info->line == sercons.index) {
654 if (ch != 0 &&
655 time_before(jiffies, break_pressed + HZ*5)) {
656 handle_sysrq(ch, regs, NULL, NULL);
657 break_pressed = 0;
658 goto ignore_char;
659 }
660 break_pressed = 0;
661 }
662 #endif
663 if ((*status & info->ignore_status_mask) == 0) {
664 tty->flip.flag_buf_ptr++;
665 tty->flip.char_buf_ptr++;
666 tty->flip.count++;
667 }
668 if ((*status & UART_LSR_OE) &&
669 (tty->flip.count < TTY_FLIPBUF_SIZE)) {
670 /*
671 * Overrun is special, since it's reported
672 * immediately, and doesn't affect the current
673 * character
674 */
675 *tty->flip.flag_buf_ptr = TTY_OVERRUN;
676 tty->flip.count++;
677 tty->flip.flag_buf_ptr++;
678 tty->flip.char_buf_ptr++;
679 }
680 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
681 ignore_char:
682 #endif
683 *status = serial_inp(info, UART_LSR);
684 } while ((*status & UART_LSR_DR) && (max_count-- > 0));
685 #if (LINUX_VERSION_CODE > 131394) /* 2.1.66 */
686 tty_flip_buffer_push(tty);
687 #else
688 queue_task_irq_off(&tty->flip.tqueue, &tq_timer);
689 #endif
690 }
691
transmit_chars(struct async_struct * info,int * intr_done)692 static _INLINE_ void transmit_chars(struct async_struct *info, int *intr_done)
693 {
694 int count;
695
696 if (info->x_char) {
697 serial_outp(info, UART_TX, info->x_char);
698 info->state->icount.tx++;
699 info->x_char = 0;
700 if (intr_done)
701 *intr_done = 0;
702 return;
703 }
704 if (info->xmit.head == info->xmit.tail
705 || info->tty->stopped
706 || info->tty->hw_stopped) {
707 info->IER &= ~UART_IER_THRI;
708 serial_out(info, UART_IER, info->IER);
709 return;
710 }
711
712 count = info->xmit_fifo_size;
713 do {
714 serial_out(info, UART_TX, info->xmit.buf[info->xmit.tail]);
715 info->xmit.tail = (info->xmit.tail + 1) & (SERIAL_XMIT_SIZE-1);
716 info->state->icount.tx++;
717 if (info->xmit.head == info->xmit.tail)
718 break;
719 } while (--count > 0);
720
721 if (CIRC_CNT(info->xmit.head,
722 info->xmit.tail,
723 SERIAL_XMIT_SIZE) < WAKEUP_CHARS)
724 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
725
726 #ifdef SERIAL_DEBUG_INTR
727 printk("THRE...");
728 #endif
729 if (intr_done)
730 *intr_done = 0;
731
732 if (info->xmit.head == info->xmit.tail) {
733 info->IER &= ~UART_IER_THRI;
734 serial_out(info, UART_IER, info->IER);
735 }
736 }
737
check_modem_status(struct async_struct * info)738 static _INLINE_ void check_modem_status(struct async_struct *info)
739 {
740 int status;
741 struct async_icount *icount;
742
743 status = serial_in(info, UART_MSR);
744
745 if (status & UART_MSR_ANY_DELTA) {
746 icount = &info->state->icount;
747 /* update input line counters */
748 if (status & UART_MSR_TERI)
749 icount->rng++;
750 if (status & UART_MSR_DDSR)
751 icount->dsr++;
752 if (status & UART_MSR_DDCD) {
753 icount->dcd++;
754 #ifdef CONFIG_HARD_PPS
755 if ((info->flags & ASYNC_HARDPPS_CD) &&
756 (status & UART_MSR_DCD))
757 hardpps();
758 #endif
759 }
760 if (status & UART_MSR_DCTS)
761 icount->cts++;
762 wake_up_interruptible(&info->delta_msr_wait);
763 }
764
765 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
766 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
767 printk("ttys%d CD now %s...", info->line,
768 (status & UART_MSR_DCD) ? "on" : "off");
769 #endif
770 if (status & UART_MSR_DCD)
771 wake_up_interruptible(&info->open_wait);
772 else if (!((info->flags & ASYNC_CALLOUT_ACTIVE) &&
773 (info->flags & ASYNC_CALLOUT_NOHUP))) {
774 #ifdef SERIAL_DEBUG_OPEN
775 printk("doing serial hangup...");
776 #endif
777 if (info->tty)
778 tty_hangup(info->tty);
779 }
780 }
781 if (info->flags & ASYNC_CTS_FLOW) {
782 if (info->tty->hw_stopped) {
783 if (status & UART_MSR_CTS) {
784 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
785 printk("CTS tx start...");
786 #endif
787 info->tty->hw_stopped = 0;
788 info->IER |= UART_IER_THRI;
789 serial_out(info, UART_IER, info->IER);
790 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
791 return;
792 }
793 } else {
794 if (!(status & UART_MSR_CTS)) {
795 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
796 printk("CTS tx stop...");
797 #endif
798 info->tty->hw_stopped = 1;
799 info->IER &= ~UART_IER_THRI;
800 serial_out(info, UART_IER, info->IER);
801 }
802 }
803 }
804 }
805
806 #ifdef CONFIG_SERIAL_SHARE_IRQ
807 /*
808 * This is the serial driver's generic interrupt routine
809 */
rs_interrupt(int irq,void * dev_id,struct pt_regs * regs)810 static void rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
811 {
812 int status, iir;
813 struct async_struct * info;
814 int pass_counter = 0;
815 struct async_struct *end_mark = 0;
816 #ifdef CONFIG_SERIAL_MULTIPORT
817 int first_multi = 0;
818 struct rs_multiport_struct *multi;
819 #endif
820
821 #ifdef SERIAL_DEBUG_INTR
822 printk("rs_interrupt(%d)...", irq);
823 #endif
824
825 info = IRQ_ports[irq];
826 if (!info)
827 return;
828
829 #ifdef CONFIG_SERIAL_MULTIPORT
830 multi = &rs_multiport[irq];
831 if (multi->port_monitor)
832 first_multi = inb(multi->port_monitor);
833 #endif
834
835 do {
836 if (!info->tty ||
837 ((iir=serial_in(info, UART_IIR)) & UART_IIR_NO_INT)) {
838 if (!end_mark)
839 end_mark = info;
840 goto next;
841 }
842 #ifdef SERIAL_DEBUG_INTR
843 printk("IIR = %x...", serial_in(info, UART_IIR));
844 #endif
845 end_mark = 0;
846
847 info->last_active = jiffies;
848
849 status = serial_inp(info, UART_LSR);
850 #ifdef SERIAL_DEBUG_INTR
851 printk("status = %x...", status);
852 #endif
853 if (status & UART_LSR_DR)
854 receive_chars(info, &status, regs);
855 check_modem_status(info);
856 #ifdef CONFIG_MELAN
857 if ((status & UART_LSR_THRE) ||
858 /* for buggy ELAN processors */
859 ((iir & UART_IIR_ID) == UART_IIR_THRI))
860 transmit_chars(info, 0);
861 #else
862 if (status & UART_LSR_THRE)
863 transmit_chars(info, 0);
864 #endif
865
866 next:
867 info = info->next_port;
868 if (!info) {
869 info = IRQ_ports[irq];
870 if (pass_counter++ > RS_ISR_PASS_LIMIT) {
871 #if 0
872 printk("rs loop break\n");
873 #endif
874 break; /* Prevent infinite loops */
875 }
876 continue;
877 }
878 } while (end_mark != info);
879 #ifdef CONFIG_SERIAL_MULTIPORT
880 if (multi->port_monitor)
881 printk("rs port monitor (normal) irq %d: 0x%x, 0x%x\n",
882 info->state->irq, first_multi,
883 inb(multi->port_monitor));
884 #endif
885 #ifdef SERIAL_DEBUG_INTR
886 printk("end.\n");
887 #endif
888 }
889 #endif /* #ifdef CONFIG_SERIAL_SHARE_IRQ */
890
891
892 /*
893 * This is the serial driver's interrupt routine for a single port
894 */
rs_interrupt_single(int irq,void * dev_id,struct pt_regs * regs)895 static void rs_interrupt_single(int irq, void *dev_id, struct pt_regs * regs)
896 {
897 int status, iir;
898 int pass_counter = 0;
899 struct async_struct * info;
900 #ifdef CONFIG_SERIAL_MULTIPORT
901 int first_multi = 0;
902 struct rs_multiport_struct *multi;
903 #endif
904
905 #ifdef SERIAL_DEBUG_INTR
906 printk("rs_interrupt_single(%d)...", irq);
907 #endif
908
909 info = IRQ_ports[irq];
910 if (!info || !info->tty)
911 return;
912
913 #ifdef CONFIG_SERIAL_MULTIPORT
914 multi = &rs_multiport[irq];
915 if (multi->port_monitor)
916 first_multi = inb(multi->port_monitor);
917 #endif
918
919 iir = serial_in(info, UART_IIR);
920 do {
921 status = serial_inp(info, UART_LSR);
922 #ifdef SERIAL_DEBUG_INTR
923 printk("status = %x...", status);
924 #endif
925 if (status & UART_LSR_DR)
926 receive_chars(info, &status, regs);
927 check_modem_status(info);
928 #ifdef CONFIG_MELAN
929 if ((status & UART_LSR_THRE) ||
930 /* For buggy ELAN processors */
931 ((iir & UART_IIR_ID) == UART_IIR_THRI))
932 transmit_chars(info, 0);
933 #else
934 if (status & UART_LSR_THRE)
935 transmit_chars(info, 0);
936 #endif
937 if (pass_counter++ > RS_ISR_PASS_LIMIT) {
938 #ifdef SERIAL_DEBUG_INTR
939 printk("rs_single loop break.\n");
940 #endif
941 break;
942 }
943 iir = serial_in(info, UART_IIR);
944 #ifdef SERIAL_DEBUG_INTR
945 printk("IIR = %x...", iir);
946 #endif
947 } while ((iir & UART_IIR_NO_INT) == 0);
948 info->last_active = jiffies;
949 #ifdef CONFIG_SERIAL_MULTIPORT
950 if (multi->port_monitor)
951 printk("rs port monitor (single) irq %d: 0x%x, 0x%x\n",
952 info->state->irq, first_multi,
953 inb(multi->port_monitor));
954 #endif
955 #ifdef SERIAL_DEBUG_INTR
956 printk("end.\n");
957 #endif
958 }
959
960 #ifdef CONFIG_SERIAL_MULTIPORT
961 /*
962 * This is the serial driver's for multiport boards
963 */
rs_interrupt_multi(int irq,void * dev_id,struct pt_regs * regs)964 static void rs_interrupt_multi(int irq, void *dev_id, struct pt_regs * regs)
965 {
966 int status;
967 struct async_struct * info;
968 int pass_counter = 0;
969 int first_multi= 0;
970 struct rs_multiport_struct *multi;
971
972 #ifdef SERIAL_DEBUG_INTR
973 printk("rs_interrupt_multi(%d)...", irq);
974 #endif
975
976 info = IRQ_ports[irq];
977 if (!info)
978 return;
979 multi = &rs_multiport[irq];
980 if (!multi->port1) {
981 /* Should never happen */
982 printk("rs_interrupt_multi: NULL port1!\n");
983 return;
984 }
985 if (multi->port_monitor)
986 first_multi = inb(multi->port_monitor);
987
988 while (1) {
989 if (!info->tty ||
990 (serial_in(info, UART_IIR) & UART_IIR_NO_INT))
991 goto next;
992
993 info->last_active = jiffies;
994
995 status = serial_inp(info, UART_LSR);
996 #ifdef SERIAL_DEBUG_INTR
997 printk("status = %x...", status);
998 #endif
999 if (status & UART_LSR_DR)
1000 receive_chars(info, &status, regs);
1001 check_modem_status(info);
1002 if (status & UART_LSR_THRE)
1003 transmit_chars(info, 0);
1004
1005 next:
1006 info = info->next_port;
1007 if (info)
1008 continue;
1009
1010 info = IRQ_ports[irq];
1011 /*
1012 * The user was a bonehead, and misconfigured their
1013 * multiport info. Rather than lock up the kernel
1014 * in an infinite loop, if we loop too many times,
1015 * print a message and break out of the loop.
1016 */
1017 if (pass_counter++ > RS_ISR_PASS_LIMIT) {
1018 printk("Misconfigured multiport serial info "
1019 "for irq %d. Breaking out irq loop\n", irq);
1020 break;
1021 }
1022 if (multi->port_monitor)
1023 printk("rs port monitor irq %d: 0x%x, 0x%x\n",
1024 info->state->irq, first_multi,
1025 inb(multi->port_monitor));
1026 if ((inb(multi->port1) & multi->mask1) != multi->match1)
1027 continue;
1028 if (!multi->port2)
1029 break;
1030 if ((inb(multi->port2) & multi->mask2) != multi->match2)
1031 continue;
1032 if (!multi->port3)
1033 break;
1034 if ((inb(multi->port3) & multi->mask3) != multi->match3)
1035 continue;
1036 if (!multi->port4)
1037 break;
1038 if ((inb(multi->port4) & multi->mask4) != multi->match4)
1039 continue;
1040 break;
1041 }
1042 #ifdef SERIAL_DEBUG_INTR
1043 printk("end.\n");
1044 #endif
1045 }
1046 #endif
1047
1048 /*
1049 * -------------------------------------------------------------------
1050 * Here ends the serial interrupt routines.
1051 * -------------------------------------------------------------------
1052 */
1053
1054 /*
1055 * This routine is used to handle the "bottom half" processing for the
1056 * serial driver, known also the "software interrupt" processing.
1057 * This processing is done at the kernel interrupt level, after the
1058 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
1059 * is where time-consuming activities which can not be done in the
1060 * interrupt driver proper are done; the interrupt driver schedules
1061 * them using rs_sched_event(), and they get done here.
1062 */
do_serial_bh(void)1063 static void do_serial_bh(void)
1064 {
1065 run_task_queue(&tq_serial);
1066 }
1067
do_softint(void * private_)1068 static void do_softint(void *private_)
1069 {
1070 struct async_struct *info = (struct async_struct *) private_;
1071 struct tty_struct *tty;
1072
1073 tty = info->tty;
1074 if (!tty)
1075 return;
1076
1077 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
1078 tty_wakeup(tty);
1079
1080 #ifdef SERIAL_HAVE_POLL_WAIT
1081 wake_up_interruptible(&tty->poll_wait);
1082 #endif
1083 }
1084 }
1085
1086 /*
1087 * This subroutine is called when the RS_TIMER goes off. It is used
1088 * by the serial driver to handle ports that do not have an interrupt
1089 * (irq=0). This doesn't work very well for 16450's, but gives barely
1090 * passable results for a 16550A. (Although at the expense of much
1091 * CPU overhead).
1092 */
rs_timer(unsigned long dummy)1093 static void rs_timer(unsigned long dummy)
1094 {
1095 static unsigned long last_strobe;
1096 struct async_struct *info;
1097 unsigned int i;
1098 unsigned long flags;
1099
1100 if ((jiffies - last_strobe) >= RS_STROBE_TIME) {
1101 for (i=0; i < NR_IRQS; i++) {
1102 info = IRQ_ports[i];
1103 if (!info)
1104 continue;
1105 save_flags(flags); cli();
1106 #ifdef CONFIG_SERIAL_SHARE_IRQ
1107 if (info->next_port) {
1108 do {
1109 serial_out(info, UART_IER, 0);
1110 info->IER |= UART_IER_THRI;
1111 serial_out(info, UART_IER, info->IER);
1112 info = info->next_port;
1113 } while (info);
1114 #ifdef CONFIG_SERIAL_MULTIPORT
1115 if (rs_multiport[i].port1)
1116 rs_interrupt_multi(i, NULL, NULL);
1117 else
1118 #endif
1119 rs_interrupt(i, NULL, NULL);
1120 } else
1121 #endif /* CONFIG_SERIAL_SHARE_IRQ */
1122 rs_interrupt_single(i, NULL, NULL);
1123 restore_flags(flags);
1124 }
1125 }
1126 last_strobe = jiffies;
1127 mod_timer(&serial_timer, jiffies + RS_STROBE_TIME);
1128
1129 if (IRQ_ports[0]) {
1130 save_flags(flags); cli();
1131 #ifdef CONFIG_SERIAL_SHARE_IRQ
1132 rs_interrupt(0, NULL, NULL);
1133 #else
1134 rs_interrupt_single(0, NULL, NULL);
1135 #endif
1136 restore_flags(flags);
1137
1138 mod_timer(&serial_timer, jiffies + IRQ_timeout[0]);
1139 }
1140 }
1141
1142 /*
1143 * ---------------------------------------------------------------
1144 * Low level utility subroutines for the serial driver: routines to
1145 * figure out the appropriate timeout for an interrupt chain, routines
1146 * to initialize and startup a serial port, and routines to shutdown a
1147 * serial port. Useful stuff like that.
1148 * ---------------------------------------------------------------
1149 */
1150
1151 /*
1152 * This routine figures out the correct timeout for a particular IRQ.
1153 * It uses the smallest timeout of all of the serial ports in a
1154 * particular interrupt chain. Now only used for IRQ 0....
1155 */
figure_IRQ_timeout(int irq)1156 static void figure_IRQ_timeout(int irq)
1157 {
1158 struct async_struct *info;
1159 int timeout = 60*HZ; /* 60 seconds === a long time :-) */
1160
1161 info = IRQ_ports[irq];
1162 if (!info) {
1163 IRQ_timeout[irq] = 60*HZ;
1164 return;
1165 }
1166 while (info) {
1167 if (info->timeout < timeout)
1168 timeout = info->timeout;
1169 info = info->next_port;
1170 }
1171 if (!irq)
1172 timeout = timeout / 2;
1173 IRQ_timeout[irq] = (timeout > 3) ? timeout-2 : 1;
1174 }
1175
1176 #ifdef CONFIG_SERIAL_RSA
1177 /* Attempts to turn on the RSA FIFO. Returns zero on failure */
enable_rsa(struct async_struct * info)1178 static int enable_rsa(struct async_struct *info)
1179 {
1180 unsigned char mode;
1181 int result;
1182 unsigned long flags;
1183
1184 save_flags(flags); cli();
1185 mode = serial_inp(info, UART_RSA_MSR);
1186 result = mode & UART_RSA_MSR_FIFO;
1187
1188 if (!result) {
1189 serial_outp(info, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
1190 mode = serial_inp(info, UART_RSA_MSR);
1191 result = mode & UART_RSA_MSR_FIFO;
1192 }
1193
1194 restore_flags(flags);
1195 return result;
1196 }
1197
1198 /* Attempts to turn off the RSA FIFO. Returns zero on failure */
disable_rsa(struct async_struct * info)1199 static int disable_rsa(struct async_struct *info)
1200 {
1201 unsigned char mode;
1202 int result;
1203 unsigned long flags;
1204
1205 save_flags(flags); cli();
1206 mode = serial_inp(info, UART_RSA_MSR);
1207 result = !(mode & UART_RSA_MSR_FIFO);
1208
1209 if (!result) {
1210 serial_outp(info, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
1211 mode = serial_inp(info, UART_RSA_MSR);
1212 result = !(mode & UART_RSA_MSR_FIFO);
1213 }
1214
1215 restore_flags(flags);
1216 return result;
1217 }
1218 #endif /* CONFIG_SERIAL_RSA */
1219
startup(struct async_struct * info)1220 static int startup(struct async_struct * info)
1221 {
1222 unsigned long flags;
1223 int retval=0;
1224 void (*handler)(int, void *, struct pt_regs *);
1225 struct serial_state *state= info->state;
1226 unsigned long page;
1227 #ifdef CONFIG_SERIAL_MANY_PORTS
1228 unsigned short ICP;
1229 #endif
1230
1231 page = get_zeroed_page(GFP_KERNEL);
1232 if (!page)
1233 return -ENOMEM;
1234
1235 save_flags(flags); cli();
1236
1237 if (info->flags & ASYNC_INITIALIZED) {
1238 free_page(page);
1239 goto errout;
1240 }
1241
1242 if (!CONFIGURED_SERIAL_PORT(state) || !state->type) {
1243 if (info->tty)
1244 set_bit(TTY_IO_ERROR, &info->tty->flags);
1245 free_page(page);
1246 goto errout;
1247 }
1248 if (info->xmit.buf)
1249 free_page(page);
1250 else
1251 info->xmit.buf = (unsigned char *) page;
1252
1253 #ifdef SERIAL_DEBUG_OPEN
1254 printk("starting up ttys%d (irq %d)...", info->line, state->irq);
1255 #endif
1256
1257 if (uart_config[state->type].flags & UART_STARTECH) {
1258 /* Wake up UART */
1259 serial_outp(info, UART_LCR, 0xBF);
1260 serial_outp(info, UART_EFR, UART_EFR_ECB);
1261 /*
1262 * Turn off LCR == 0xBF so we actually set the IER
1263 * register on the XR16C850
1264 */
1265 serial_outp(info, UART_LCR, 0);
1266 serial_outp(info, UART_IER, 0);
1267 /*
1268 * Now reset LCR so we can turn off the ECB bit
1269 */
1270 serial_outp(info, UART_LCR, 0xBF);
1271 serial_outp(info, UART_EFR, 0);
1272 /*
1273 * For a XR16C850, we need to set the trigger levels
1274 */
1275 if (state->type == PORT_16850) {
1276 serial_outp(info, UART_FCTR, UART_FCTR_TRGD |
1277 UART_FCTR_RX);
1278 serial_outp(info, UART_TRG, UART_TRG_96);
1279 serial_outp(info, UART_FCTR, UART_FCTR_TRGD |
1280 UART_FCTR_TX);
1281 serial_outp(info, UART_TRG, UART_TRG_96);
1282 }
1283 serial_outp(info, UART_LCR, 0);
1284 }
1285
1286 if (state->type == PORT_16750) {
1287 /* Wake up UART */
1288 serial_outp(info, UART_IER, 0);
1289 }
1290
1291 if (state->type == PORT_16C950) {
1292 /* Wake up and initialize UART */
1293 info->ACR = 0;
1294 serial_outp(info, UART_LCR, 0xBF);
1295 serial_outp(info, UART_EFR, UART_EFR_ECB);
1296 serial_outp(info, UART_IER, 0);
1297 serial_outp(info, UART_LCR, 0);
1298 serial_icr_write(info, UART_CSR, 0); /* Reset the UART */
1299 serial_outp(info, UART_LCR, 0xBF);
1300 serial_outp(info, UART_EFR, UART_EFR_ECB);
1301 serial_outp(info, UART_LCR, 0);
1302 }
1303
1304 #ifdef CONFIG_SERIAL_RSA
1305 /*
1306 * If this is an RSA port, see if we can kick it up to the
1307 * higher speed clock.
1308 */
1309 if (state->type == PORT_RSA) {
1310 if (state->baud_base != SERIAL_RSA_BAUD_BASE &&
1311 enable_rsa(info))
1312 state->baud_base = SERIAL_RSA_BAUD_BASE;
1313 if (state->baud_base == SERIAL_RSA_BAUD_BASE)
1314 serial_outp(info, UART_RSA_FRR, 0);
1315 }
1316 #endif
1317
1318 /*
1319 * Clear the FIFO buffers and disable them
1320 * (they will be reenabled in change_speed())
1321 */
1322 if (uart_config[state->type].flags & UART_CLEAR_FIFO) {
1323 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
1324 serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
1325 UART_FCR_CLEAR_RCVR |
1326 UART_FCR_CLEAR_XMIT));
1327 serial_outp(info, UART_FCR, 0);
1328 }
1329
1330 /*
1331 * Clear the interrupt registers.
1332 */
1333 (void) serial_inp(info, UART_LSR);
1334 (void) serial_inp(info, UART_RX);
1335 (void) serial_inp(info, UART_IIR);
1336 (void) serial_inp(info, UART_MSR);
1337
1338 /*
1339 * At this point there's no way the LSR could still be 0xFF;
1340 * if it is, then bail out, because there's likely no UART
1341 * here.
1342 */
1343 if (!(info->flags & ASYNC_BUGGY_UART) &&
1344 (serial_inp(info, UART_LSR) == 0xff)) {
1345 printk("ttyS%d: LSR safety check engaged!\n", state->line);
1346 if (capable(CAP_SYS_ADMIN)) {
1347 if (info->tty)
1348 set_bit(TTY_IO_ERROR, &info->tty->flags);
1349 } else
1350 retval = -ENODEV;
1351 goto errout;
1352 }
1353
1354 /*
1355 * Allocate the IRQ if necessary
1356 */
1357 if (state->irq && (!IRQ_ports[state->irq] ||
1358 !IRQ_ports[state->irq]->next_port)) {
1359 if (IRQ_ports[state->irq]) {
1360 #ifdef CONFIG_SERIAL_SHARE_IRQ
1361 free_irq(state->irq, &IRQ_ports[state->irq]);
1362 #ifdef CONFIG_SERIAL_MULTIPORT
1363 if (rs_multiport[state->irq].port1)
1364 handler = rs_interrupt_multi;
1365 else
1366 #endif
1367 handler = rs_interrupt;
1368 #else
1369 retval = -EBUSY;
1370 goto errout;
1371 #endif /* CONFIG_SERIAL_SHARE_IRQ */
1372 } else
1373 handler = rs_interrupt_single;
1374
1375 retval = request_irq(state->irq, handler, SA_SHIRQ,
1376 "serial", &IRQ_ports[state->irq]);
1377 if (retval) {
1378 if (capable(CAP_SYS_ADMIN)) {
1379 if (info->tty)
1380 set_bit(TTY_IO_ERROR,
1381 &info->tty->flags);
1382 retval = 0;
1383 }
1384 goto errout;
1385 }
1386 }
1387
1388 /*
1389 * Insert serial port into IRQ chain.
1390 */
1391 info->prev_port = 0;
1392 info->next_port = IRQ_ports[state->irq];
1393 if (info->next_port)
1394 info->next_port->prev_port = info;
1395 IRQ_ports[state->irq] = info;
1396 figure_IRQ_timeout(state->irq);
1397
1398 /*
1399 * Now, initialize the UART
1400 */
1401 serial_outp(info, UART_LCR, UART_LCR_WLEN8); /* reset DLAB */
1402
1403 info->MCR = 0;
1404 if (info->tty->termios->c_cflag & CBAUD)
1405 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
1406 #ifdef CONFIG_SERIAL_MANY_PORTS
1407 if (info->flags & ASYNC_FOURPORT) {
1408 if (state->irq == 0)
1409 info->MCR |= UART_MCR_OUT1;
1410 } else
1411 #endif
1412 {
1413 if (state->irq != 0)
1414 info->MCR |= UART_MCR_OUT2;
1415 }
1416 info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
1417 serial_outp(info, UART_MCR, info->MCR);
1418
1419 /*
1420 * Finally, enable interrupts
1421 */
1422 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
1423 serial_outp(info, UART_IER, info->IER); /* enable interrupts */
1424
1425 #ifdef CONFIG_SERIAL_MANY_PORTS
1426 if (info->flags & ASYNC_FOURPORT) {
1427 /* Enable interrupts on the AST Fourport board */
1428 ICP = (info->port & 0xFE0) | 0x01F;
1429 outb_p(0x80, ICP);
1430 (void) inb_p(ICP);
1431 }
1432 #endif
1433
1434 /*
1435 * And clear the interrupt registers again for luck.
1436 */
1437 (void)serial_inp(info, UART_LSR);
1438 (void)serial_inp(info, UART_RX);
1439 (void)serial_inp(info, UART_IIR);
1440 (void)serial_inp(info, UART_MSR);
1441
1442 if (info->tty)
1443 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1444 info->xmit.head = info->xmit.tail = 0;
1445
1446 /*
1447 * Set up serial timers...
1448 */
1449 mod_timer(&serial_timer, jiffies + 2*HZ/100);
1450
1451 /*
1452 * Set up the tty->alt_speed kludge
1453 */
1454 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
1455 if (info->tty) {
1456 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1457 info->tty->alt_speed = 57600;
1458 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1459 info->tty->alt_speed = 115200;
1460 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
1461 info->tty->alt_speed = 230400;
1462 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
1463 info->tty->alt_speed = 460800;
1464 }
1465 #endif
1466
1467 /*
1468 * and set the speed of the serial port
1469 */
1470 change_speed(info, 0);
1471
1472 info->flags |= ASYNC_INITIALIZED;
1473 restore_flags(flags);
1474 return 0;
1475
1476 errout:
1477 restore_flags(flags);
1478 return retval;
1479 }
1480
1481 /*
1482 * This routine will shutdown a serial port; interrupts are disabled, and
1483 * DTR is dropped if the hangup on close termio flag is on.
1484 */
shutdown(struct async_struct * info)1485 static void shutdown(struct async_struct * info)
1486 {
1487 unsigned long flags;
1488 struct serial_state *state;
1489 int retval;
1490
1491 if (!(info->flags & ASYNC_INITIALIZED))
1492 return;
1493
1494 state = info->state;
1495
1496 #ifdef SERIAL_DEBUG_OPEN
1497 printk("Shutting down serial port %d (irq %d)....", info->line,
1498 state->irq);
1499 #endif
1500
1501 save_flags(flags); cli(); /* Disable interrupts */
1502
1503 /*
1504 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
1505 * here so the queue might never be waken up
1506 */
1507 wake_up_interruptible(&info->delta_msr_wait);
1508
1509 /*
1510 * First unlink the serial port from the IRQ chain...
1511 */
1512 if (info->next_port)
1513 info->next_port->prev_port = info->prev_port;
1514 if (info->prev_port)
1515 info->prev_port->next_port = info->next_port;
1516 else
1517 IRQ_ports[state->irq] = info->next_port;
1518 figure_IRQ_timeout(state->irq);
1519
1520 /*
1521 * Free the IRQ, if necessary
1522 */
1523 if (state->irq && (!IRQ_ports[state->irq] ||
1524 !IRQ_ports[state->irq]->next_port)) {
1525 if (IRQ_ports[state->irq]) {
1526 free_irq(state->irq, &IRQ_ports[state->irq]);
1527 retval = request_irq(state->irq, rs_interrupt_single,
1528 SA_SHIRQ, "serial",
1529 &IRQ_ports[state->irq]);
1530
1531 if (retval)
1532 printk("serial shutdown: request_irq: error %d"
1533 " Couldn't reacquire IRQ.\n", retval);
1534 } else
1535 free_irq(state->irq, &IRQ_ports[state->irq]);
1536 }
1537
1538 if (info->xmit.buf) {
1539 unsigned long pg = (unsigned long) info->xmit.buf;
1540 info->xmit.buf = 0;
1541 free_page(pg);
1542 }
1543
1544 info->IER = 0;
1545 serial_outp(info, UART_IER, 0x00); /* disable all intrs */
1546 #ifdef CONFIG_SERIAL_MANY_PORTS
1547 if (info->flags & ASYNC_FOURPORT) {
1548 /* reset interrupts on the AST Fourport board */
1549 (void) inb((info->port & 0xFE0) | 0x01F);
1550 info->MCR |= UART_MCR_OUT1;
1551 } else
1552 #endif
1553 info->MCR &= ~UART_MCR_OUT2;
1554 info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
1555
1556 /* disable break condition */
1557 serial_out(info, UART_LCR, serial_inp(info, UART_LCR) & ~UART_LCR_SBC);
1558
1559 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
1560 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1561 serial_outp(info, UART_MCR, info->MCR);
1562
1563 /* disable FIFO's */
1564 serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
1565 UART_FCR_CLEAR_RCVR |
1566 UART_FCR_CLEAR_XMIT));
1567 serial_outp(info, UART_FCR, 0);
1568
1569 #ifdef CONFIG_SERIAL_RSA
1570 /*
1571 * Reset the RSA board back to 115kbps compat mode.
1572 */
1573 if ((state->type == PORT_RSA) &&
1574 (state->baud_base == SERIAL_RSA_BAUD_BASE &&
1575 disable_rsa(info)))
1576 state->baud_base = SERIAL_RSA_BAUD_BASE_LO;
1577 #endif
1578
1579
1580 (void)serial_in(info, UART_RX); /* read data port to reset things */
1581
1582 if (info->tty)
1583 set_bit(TTY_IO_ERROR, &info->tty->flags);
1584
1585 if (uart_config[info->state->type].flags & UART_STARTECH) {
1586 /* Arrange to enter sleep mode */
1587 serial_outp(info, UART_LCR, 0xBF);
1588 serial_outp(info, UART_EFR, UART_EFR_ECB);
1589 serial_outp(info, UART_LCR, 0);
1590 serial_outp(info, UART_IER, UART_IERX_SLEEP);
1591 serial_outp(info, UART_LCR, 0xBF);
1592 serial_outp(info, UART_EFR, 0);
1593 serial_outp(info, UART_LCR, 0);
1594 }
1595 if (info->state->type == PORT_16750) {
1596 /* Arrange to enter sleep mode */
1597 serial_outp(info, UART_IER, UART_IERX_SLEEP);
1598 }
1599 info->flags &= ~ASYNC_INITIALIZED;
1600 restore_flags(flags);
1601 }
1602
1603 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
1604 static int baud_table[] = {
1605 0, 50, 75, 110, 134, 150, 200, 300,
1606 600, 1200, 1800, 2400, 4800, 9600, 19200,
1607 38400, 57600, 115200, 230400, 460800, 0 };
1608
tty_get_baud_rate(struct tty_struct * tty)1609 static int tty_get_baud_rate(struct tty_struct *tty)
1610 {
1611 struct async_struct * info = (struct async_struct *)tty->driver_data;
1612 unsigned int cflag, i;
1613
1614 cflag = tty->termios->c_cflag;
1615
1616 i = cflag & CBAUD;
1617 if (i & CBAUDEX) {
1618 i &= ~CBAUDEX;
1619 if (i < 1 || i > 2)
1620 tty->termios->c_cflag &= ~CBAUDEX;
1621 else
1622 i += 15;
1623 }
1624 if (i == 15) {
1625 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1626 i += 1;
1627 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1628 i += 2;
1629 }
1630 return baud_table[i];
1631 }
1632 #endif
1633
1634 /*
1635 * This routine is called to set the UART divisor registers to match
1636 * the specified baud rate for a serial port.
1637 */
change_speed(struct async_struct * info,struct termios * old_termios)1638 static void change_speed(struct async_struct *info,
1639 struct termios *old_termios)
1640 {
1641 int quot = 0, baud_base, baud;
1642 unsigned cflag, cval, fcr = 0;
1643 int bits;
1644 unsigned long flags;
1645
1646 if (!info->tty || !info->tty->termios)
1647 return;
1648 cflag = info->tty->termios->c_cflag;
1649 if (!CONFIGURED_SERIAL_PORT(info))
1650 return;
1651
1652 /* byte size and parity */
1653 switch (cflag & CSIZE) {
1654 case CS5: cval = 0x00; bits = 7; break;
1655 case CS6: cval = 0x01; bits = 8; break;
1656 case CS7: cval = 0x02; bits = 9; break;
1657 case CS8: cval = 0x03; bits = 10; break;
1658 /* Never happens, but GCC is too dumb to figure it out */
1659 default: cval = 0x00; bits = 7; break;
1660 }
1661 if (cflag & CSTOPB) {
1662 cval |= 0x04;
1663 bits++;
1664 }
1665 if (cflag & PARENB) {
1666 cval |= UART_LCR_PARITY;
1667 bits++;
1668 }
1669 if (!(cflag & PARODD))
1670 cval |= UART_LCR_EPAR;
1671 #ifdef CMSPAR
1672 if (cflag & CMSPAR)
1673 cval |= UART_LCR_SPAR;
1674 #endif
1675
1676 /* Determine divisor based on baud rate */
1677 baud = tty_get_baud_rate(info->tty);
1678 if (!baud)
1679 baud = 9600; /* B0 transition handled in rs_set_termios */
1680 #ifdef CONFIG_SERIAL_RSA
1681 if ((info->state->type == PORT_RSA) &&
1682 (info->state->baud_base != SERIAL_RSA_BAUD_BASE) &&
1683 enable_rsa(info))
1684 info->state->baud_base = SERIAL_RSA_BAUD_BASE;
1685 #endif
1686 baud_base = info->state->baud_base;
1687 if (info->state->type == PORT_16C950) {
1688 if (baud <= baud_base)
1689 serial_icr_write(info, UART_TCR, 0);
1690 else if (baud <= 2*baud_base) {
1691 serial_icr_write(info, UART_TCR, 0x8);
1692 baud_base = baud_base * 2;
1693 } else if (baud <= 4*baud_base) {
1694 serial_icr_write(info, UART_TCR, 0x4);
1695 baud_base = baud_base * 4;
1696 } else
1697 serial_icr_write(info, UART_TCR, 0);
1698 }
1699 if (baud == 38400 &&
1700 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
1701 quot = info->state->custom_divisor;
1702 else {
1703 if (baud == 134)
1704 /* Special case since 134 is really 134.5 */
1705 quot = (2*baud_base / 269);
1706 else if (baud)
1707 quot = baud_base / baud;
1708 }
1709 /* If the quotient is zero refuse the change */
1710 if (!quot && old_termios) {
1711 info->tty->termios->c_cflag &= ~CBAUD;
1712 info->tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD);
1713 baud = tty_get_baud_rate(info->tty);
1714 if (!baud)
1715 baud = 9600;
1716 if (baud == 38400 &&
1717 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
1718 quot = info->state->custom_divisor;
1719 else {
1720 if (baud == 134)
1721 /* Special case since 134 is really 134.5 */
1722 quot = (2*baud_base / 269);
1723 else if (baud)
1724 quot = baud_base / baud;
1725 }
1726 }
1727 /* As a last resort, if the quotient is zero, default to 9600 bps */
1728 if (!quot)
1729 quot = baud_base / 9600;
1730 /*
1731 * Work around a bug in the Oxford Semiconductor 952 rev B
1732 * chip which causes it to seriously miscalculate baud rates
1733 * when DLL is 0.
1734 */
1735 if (((quot & 0xFF) == 0) && (info->state->type == PORT_16C950) &&
1736 (info->state->revision == 0x5201))
1737 quot++;
1738
1739 info->quot = quot;
1740 info->timeout = ((info->xmit_fifo_size*HZ*bits*quot) / baud_base);
1741 info->timeout += HZ/50; /* Add .02 seconds of slop */
1742
1743 /* Set up FIFO's */
1744 if (uart_config[info->state->type].flags & UART_USE_FIFO) {
1745 if ((info->state->baud_base / quot) < 2400)
1746 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
1747 #ifdef CONFIG_SERIAL_RSA
1748 else if (info->state->type == PORT_RSA)
1749 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_14;
1750 #endif
1751 else
1752 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
1753 }
1754 if (info->state->type == PORT_16750)
1755 fcr |= UART_FCR7_64BYTE;
1756
1757 /* CTS flow control flag and modem status interrupts */
1758 info->IER &= ~UART_IER_MSI;
1759 if (info->flags & ASYNC_HARDPPS_CD)
1760 info->IER |= UART_IER_MSI;
1761 if (cflag & CRTSCTS) {
1762 info->flags |= ASYNC_CTS_FLOW;
1763 info->IER |= UART_IER_MSI;
1764 } else
1765 info->flags &= ~ASYNC_CTS_FLOW;
1766 if (cflag & CLOCAL)
1767 info->flags &= ~ASYNC_CHECK_CD;
1768 else {
1769 info->flags |= ASYNC_CHECK_CD;
1770 info->IER |= UART_IER_MSI;
1771 }
1772 serial_out(info, UART_IER, info->IER);
1773
1774 /*
1775 * Set up parity check flag
1776 */
1777 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1778
1779 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
1780 if (I_INPCK(info->tty))
1781 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1782 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
1783 info->read_status_mask |= UART_LSR_BI;
1784
1785 /*
1786 * Characters to ignore
1787 */
1788 info->ignore_status_mask = 0;
1789 if (I_IGNPAR(info->tty))
1790 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
1791 if (I_IGNBRK(info->tty)) {
1792 info->ignore_status_mask |= UART_LSR_BI;
1793 /*
1794 * If we're ignore parity and break indicators, ignore
1795 * overruns too. (For real raw support).
1796 */
1797 if (I_IGNPAR(info->tty))
1798 info->ignore_status_mask |= UART_LSR_OE;
1799 }
1800 /*
1801 * !!! ignore all characters if CREAD is not set
1802 */
1803 if ((cflag & CREAD) == 0)
1804 info->ignore_status_mask |= UART_LSR_DR;
1805 save_flags(flags); cli();
1806 if (uart_config[info->state->type].flags & UART_STARTECH) {
1807 serial_outp(info, UART_LCR, 0xBF);
1808 serial_outp(info, UART_EFR,
1809 (cflag & CRTSCTS) ? UART_EFR_CTS : 0);
1810 }
1811 serial_outp(info, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */
1812 serial_outp(info, UART_DLL, quot & 0xff); /* LS of divisor */
1813 serial_outp(info, UART_DLM, quot >> 8); /* MS of divisor */
1814 if (info->state->type == PORT_16750)
1815 serial_outp(info, UART_FCR, fcr); /* set fcr */
1816 serial_outp(info, UART_LCR, cval); /* reset DLAB */
1817 info->LCR = cval; /* Save LCR */
1818 if (info->state->type != PORT_16750) {
1819 if (fcr & UART_FCR_ENABLE_FIFO) {
1820 /* emulated UARTs (Lucent Venus 167x) need two steps */
1821 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
1822 }
1823 serial_outp(info, UART_FCR, fcr); /* set fcr */
1824 }
1825 restore_flags(flags);
1826 }
1827
rs_put_char(struct tty_struct * tty,unsigned char ch)1828 static void rs_put_char(struct tty_struct *tty, unsigned char ch)
1829 {
1830 struct async_struct *info;
1831 unsigned long flags;
1832
1833 if (!tty)
1834 return;
1835
1836 info = (struct async_struct *)tty->driver_data;
1837
1838 if (serial_paranoia_check(info, tty->device, "rs_put_char"))
1839 return;
1840
1841 if (!info->xmit.buf)
1842 return;
1843
1844 save_flags(flags); cli();
1845 if (CIRC_SPACE(info->xmit.head,
1846 info->xmit.tail,
1847 SERIAL_XMIT_SIZE) == 0) {
1848 restore_flags(flags);
1849 return;
1850 }
1851
1852 info->xmit.buf[info->xmit.head] = ch;
1853 info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
1854 restore_flags(flags);
1855 }
1856
rs_flush_chars(struct tty_struct * tty)1857 static void rs_flush_chars(struct tty_struct *tty)
1858 {
1859 struct async_struct *info = (struct async_struct *)tty->driver_data;
1860 unsigned long flags;
1861
1862 if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
1863 return;
1864
1865 if (info->xmit.head == info->xmit.tail
1866 || tty->stopped
1867 || tty->hw_stopped
1868 || !info->xmit.buf)
1869 return;
1870
1871 save_flags(flags); cli();
1872 info->IER |= UART_IER_THRI;
1873 serial_out(info, UART_IER, info->IER);
1874 restore_flags(flags);
1875 }
1876
rs_write(struct tty_struct * tty,int from_user,const unsigned char * buf,int count)1877 static int rs_write(struct tty_struct * tty, int from_user,
1878 const unsigned char *buf, int count)
1879 {
1880 int c, ret = 0;
1881 struct async_struct *info;
1882 unsigned long flags;
1883
1884 if (!tty)
1885 return 0;
1886
1887 info = (struct async_struct *)tty->driver_data;
1888
1889 if (serial_paranoia_check(info, tty->device, "rs_write"))
1890 return 0;
1891
1892 if (!info->xmit.buf || !tmp_buf)
1893 return 0;
1894
1895 save_flags(flags);
1896 if (from_user) {
1897 down(&tmp_buf_sem);
1898 while (1) {
1899 int c1;
1900 c = CIRC_SPACE_TO_END(info->xmit.head,
1901 info->xmit.tail,
1902 SERIAL_XMIT_SIZE);
1903 if (count < c)
1904 c = count;
1905 if (c <= 0)
1906 break;
1907
1908 c -= copy_from_user(tmp_buf, buf, c);
1909 if (!c) {
1910 if (!ret)
1911 ret = -EFAULT;
1912 break;
1913 }
1914 cli();
1915 c1 = CIRC_SPACE_TO_END(info->xmit.head,
1916 info->xmit.tail,
1917 SERIAL_XMIT_SIZE);
1918 if (c1 < c)
1919 c = c1;
1920 memcpy(info->xmit.buf + info->xmit.head, tmp_buf, c);
1921 info->xmit.head = ((info->xmit.head + c) &
1922 (SERIAL_XMIT_SIZE-1));
1923 restore_flags(flags);
1924 buf += c;
1925 count -= c;
1926 ret += c;
1927 }
1928 up(&tmp_buf_sem);
1929 } else {
1930 cli();
1931 while (1) {
1932 c = CIRC_SPACE_TO_END(info->xmit.head,
1933 info->xmit.tail,
1934 SERIAL_XMIT_SIZE);
1935 if (count < c)
1936 c = count;
1937 if (c <= 0) {
1938 break;
1939 }
1940 memcpy(info->xmit.buf + info->xmit.head, buf, c);
1941 info->xmit.head = ((info->xmit.head + c) &
1942 (SERIAL_XMIT_SIZE-1));
1943 buf += c;
1944 count -= c;
1945 ret += c;
1946 }
1947 restore_flags(flags);
1948 }
1949 if (info->xmit.head != info->xmit.tail
1950 && !tty->stopped
1951 && !tty->hw_stopped
1952 && !(info->IER & UART_IER_THRI)) {
1953 info->IER |= UART_IER_THRI;
1954 serial_out(info, UART_IER, info->IER);
1955 }
1956 return ret;
1957 }
1958
rs_write_room(struct tty_struct * tty)1959 static int rs_write_room(struct tty_struct *tty)
1960 {
1961 struct async_struct *info = (struct async_struct *)tty->driver_data;
1962
1963 if (serial_paranoia_check(info, tty->device, "rs_write_room"))
1964 return 0;
1965 return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
1966 }
1967
rs_chars_in_buffer(struct tty_struct * tty)1968 static int rs_chars_in_buffer(struct tty_struct *tty)
1969 {
1970 struct async_struct *info = (struct async_struct *)tty->driver_data;
1971
1972 if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
1973 return 0;
1974 return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
1975 }
1976
rs_flush_buffer(struct tty_struct * tty)1977 static void rs_flush_buffer(struct tty_struct *tty)
1978 {
1979 struct async_struct *info = (struct async_struct *)tty->driver_data;
1980 unsigned long flags;
1981
1982 if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
1983 return;
1984 save_flags(flags); cli();
1985 info->xmit.head = info->xmit.tail = 0;
1986 restore_flags(flags);
1987 #ifdef SERIAL_HAVE_POLL_WAIT
1988 wake_up_interruptible(&tty->poll_wait);
1989 #endif
1990 tty_wakeup(tty);
1991 }
1992
1993 /*
1994 * This function is used to send a high-priority XON/XOFF character to
1995 * the device
1996 */
rs_send_xchar(struct tty_struct * tty,char ch)1997 static void rs_send_xchar(struct tty_struct *tty, char ch)
1998 {
1999 struct async_struct *info = (struct async_struct *)tty->driver_data;
2000
2001 if (serial_paranoia_check(info, tty->device, "rs_send_char"))
2002 return;
2003
2004 info->x_char = ch;
2005 if (ch) {
2006 /* Make sure transmit interrupts are on */
2007 info->IER |= UART_IER_THRI;
2008 serial_out(info, UART_IER, info->IER);
2009 }
2010 }
2011
2012 /*
2013 * ------------------------------------------------------------
2014 * rs_throttle()
2015 *
2016 * This routine is called by the upper-layer tty layer to signal that
2017 * incoming characters should be throttled.
2018 * ------------------------------------------------------------
2019 */
rs_throttle(struct tty_struct * tty)2020 static void rs_throttle(struct tty_struct * tty)
2021 {
2022 struct async_struct *info = (struct async_struct *)tty->driver_data;
2023 unsigned long flags;
2024 #ifdef SERIAL_DEBUG_THROTTLE
2025 char buf[64];
2026
2027 printk("throttle %s: %d....\n", tty_name(tty, buf),
2028 tty->ldisc.chars_in_buffer(tty));
2029 #endif
2030
2031 if (serial_paranoia_check(info, tty->device, "rs_throttle"))
2032 return;
2033
2034 if (I_IXOFF(tty))
2035 rs_send_xchar(tty, STOP_CHAR(tty));
2036
2037 if (tty->termios->c_cflag & CRTSCTS)
2038 info->MCR &= ~UART_MCR_RTS;
2039
2040 save_flags(flags); cli();
2041 serial_out(info, UART_MCR, info->MCR);
2042 restore_flags(flags);
2043 }
2044
rs_unthrottle(struct tty_struct * tty)2045 static void rs_unthrottle(struct tty_struct * tty)
2046 {
2047 struct async_struct *info = (struct async_struct *)tty->driver_data;
2048 unsigned long flags;
2049 #ifdef SERIAL_DEBUG_THROTTLE
2050 char buf[64];
2051
2052 printk("unthrottle %s: %d....\n", tty_name(tty, buf),
2053 tty->ldisc.chars_in_buffer(tty));
2054 #endif
2055
2056 if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
2057 return;
2058
2059 if (I_IXOFF(tty)) {
2060 if (info->x_char)
2061 info->x_char = 0;
2062 else
2063 rs_send_xchar(tty, START_CHAR(tty));
2064 }
2065 if (tty->termios->c_cflag & CRTSCTS)
2066 info->MCR |= UART_MCR_RTS;
2067 save_flags(flags); cli();
2068 serial_out(info, UART_MCR, info->MCR);
2069 restore_flags(flags);
2070 }
2071
2072 /*
2073 * ------------------------------------------------------------
2074 * rs_ioctl() and friends
2075 * ------------------------------------------------------------
2076 */
2077
get_serial_info(struct async_struct * info,struct serial_struct * retinfo)2078 static int get_serial_info(struct async_struct * info,
2079 struct serial_struct * retinfo)
2080 {
2081 struct serial_struct tmp;
2082 struct serial_state *state = info->state;
2083
2084 if (!retinfo)
2085 return -EFAULT;
2086 memset(&tmp, 0, sizeof(tmp));
2087 tmp.type = state->type;
2088 tmp.line = state->line;
2089 tmp.port = state->port;
2090 if (HIGH_BITS_OFFSET)
2091 tmp.port_high = state->port >> HIGH_BITS_OFFSET;
2092 else
2093 tmp.port_high = 0;
2094 tmp.irq = state->irq;
2095 tmp.flags = state->flags;
2096 tmp.xmit_fifo_size = state->xmit_fifo_size;
2097 tmp.baud_base = state->baud_base;
2098 tmp.close_delay = state->close_delay;
2099 tmp.closing_wait = state->closing_wait;
2100 tmp.custom_divisor = state->custom_divisor;
2101 tmp.hub6 = state->hub6;
2102 tmp.io_type = state->io_type;
2103 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
2104 return -EFAULT;
2105 return 0;
2106 }
2107
set_serial_info(struct async_struct * info,struct serial_struct * new_info)2108 static int set_serial_info(struct async_struct * info,
2109 struct serial_struct * new_info)
2110 {
2111 struct serial_struct new_serial;
2112 struct serial_state old_state, *state;
2113 unsigned int i,change_irq,change_port;
2114 int retval = 0;
2115 unsigned long new_port;
2116
2117 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
2118 return -EFAULT;
2119 state = info->state;
2120 old_state = *state;
2121
2122 new_port = new_serial.port;
2123 if (HIGH_BITS_OFFSET)
2124 new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET;
2125
2126 change_irq = new_serial.irq != state->irq;
2127 change_port = (new_port != ((int) state->port)) ||
2128 (new_serial.hub6 != state->hub6);
2129
2130 if (!capable(CAP_SYS_ADMIN)) {
2131 if (change_irq || change_port ||
2132 (new_serial.baud_base != state->baud_base) ||
2133 (new_serial.type != state->type) ||
2134 (new_serial.close_delay != state->close_delay) ||
2135 (new_serial.xmit_fifo_size != state->xmit_fifo_size) ||
2136 ((new_serial.flags & ~ASYNC_USR_MASK) !=
2137 (state->flags & ~ASYNC_USR_MASK)))
2138 return -EPERM;
2139 state->flags = ((state->flags & ~ASYNC_USR_MASK) |
2140 (new_serial.flags & ASYNC_USR_MASK));
2141 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
2142 (new_serial.flags & ASYNC_USR_MASK));
2143 state->custom_divisor = new_serial.custom_divisor;
2144 goto check_and_exit;
2145 }
2146
2147 new_serial.irq = irq_cannonicalize(new_serial.irq);
2148
2149 if ((new_serial.irq >= NR_IRQS) || (new_serial.irq < 0) ||
2150 (new_serial.baud_base < 9600)|| (new_serial.type < PORT_UNKNOWN) ||
2151 (new_serial.type > PORT_MAX) || (new_serial.type == PORT_CIRRUS) ||
2152 (new_serial.type == PORT_STARTECH)) {
2153 return -EINVAL;
2154 }
2155
2156 if ((new_serial.type != state->type) ||
2157 (new_serial.xmit_fifo_size <= 0))
2158 new_serial.xmit_fifo_size =
2159 uart_config[new_serial.type].dfl_xmit_fifo_size;
2160
2161 /* Make sure address is not already in use */
2162 if (new_serial.type) {
2163 for (i = 0 ; i < NR_PORTS; i++)
2164 if ((state != &rs_table[i]) &&
2165 (rs_table[i].io_type == SERIAL_IO_PORT) &&
2166 (rs_table[i].port == new_port) &&
2167 rs_table[i].type)
2168 return -EADDRINUSE;
2169 }
2170
2171 if ((change_port || change_irq) && (state->count > 1))
2172 return -EBUSY;
2173
2174 /*
2175 * OK, past this point, all the error checking has been done.
2176 * At this point, we start making changes.....
2177 */
2178
2179 state->baud_base = new_serial.baud_base;
2180 state->flags = ((state->flags & ~ASYNC_FLAGS) |
2181 (new_serial.flags & ASYNC_FLAGS));
2182 info->flags = ((state->flags & ~ASYNC_INTERNAL_FLAGS) |
2183 (info->flags & ASYNC_INTERNAL_FLAGS));
2184 state->custom_divisor = new_serial.custom_divisor;
2185 state->close_delay = new_serial.close_delay * HZ/100;
2186 state->closing_wait = new_serial.closing_wait * HZ/100;
2187 #if (LINUX_VERSION_CODE > 0x20100)
2188 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2189 #endif
2190 info->xmit_fifo_size = state->xmit_fifo_size =
2191 new_serial.xmit_fifo_size;
2192
2193 if ((state->type != PORT_UNKNOWN) && state->port) {
2194 #ifdef CONFIG_SERIAL_RSA
2195 if (old_state.type == PORT_RSA)
2196 release_region(state->port + UART_RSA_BASE, 16);
2197 else
2198 #endif
2199 release_region(state->port,8);
2200 }
2201 state->type = new_serial.type;
2202 if (change_port || change_irq) {
2203 /*
2204 * We need to shutdown the serial port at the old
2205 * port/irq combination.
2206 */
2207 shutdown(info);
2208 state->irq = new_serial.irq;
2209 info->port = state->port = new_port;
2210 info->hub6 = state->hub6 = new_serial.hub6;
2211 if (info->hub6)
2212 info->io_type = state->io_type = SERIAL_IO_HUB6;
2213 else if (info->io_type == SERIAL_IO_HUB6)
2214 info->io_type = state->io_type = SERIAL_IO_PORT;
2215 }
2216 if ((state->type != PORT_UNKNOWN) && state->port) {
2217 #ifdef CONFIG_SERIAL_RSA
2218 if (state->type == PORT_RSA)
2219 request_region(state->port + UART_RSA_BASE,
2220 16, "serial_rsa(set)");
2221 else
2222 #endif
2223 request_region(state->port,8,"serial(set)");
2224 }
2225
2226
2227 check_and_exit:
2228 if ((!state->port && !state->iomem_base) || !state->type)
2229 return 0;
2230 if (info->flags & ASYNC_INITIALIZED) {
2231 if (((old_state.flags & ASYNC_SPD_MASK) !=
2232 (state->flags & ASYNC_SPD_MASK)) ||
2233 (old_state.custom_divisor != state->custom_divisor)) {
2234 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
2235 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2236 info->tty->alt_speed = 57600;
2237 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2238 info->tty->alt_speed = 115200;
2239 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2240 info->tty->alt_speed = 230400;
2241 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2242 info->tty->alt_speed = 460800;
2243 #endif
2244 change_speed(info, 0);
2245 }
2246 } else
2247 retval = startup(info);
2248 return retval;
2249 }
2250
2251
2252 /*
2253 * get_lsr_info - get line status register info
2254 *
2255 * Purpose: Let user call ioctl() to get info when the UART physically
2256 * is emptied. On bus types like RS485, the transmitter must
2257 * release the bus after transmitting. This must be done when
2258 * the transmit shift register is empty, not be done when the
2259 * transmit holding register is empty. This functionality
2260 * allows an RS485 driver to be written in user space.
2261 */
get_lsr_info(struct async_struct * info,unsigned int * value)2262 static int get_lsr_info(struct async_struct * info, unsigned int *value)
2263 {
2264 unsigned char status;
2265 unsigned int result;
2266 unsigned long flags;
2267
2268 save_flags(flags); cli();
2269 status = serial_in(info, UART_LSR);
2270 restore_flags(flags);
2271 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2272
2273 /*
2274 * If we're about to load something into the transmit
2275 * register, we'll pretend the transmitter isn't empty to
2276 * avoid a race condition (depending on when the transmit
2277 * interrupt happens).
2278 */
2279 if (info->x_char ||
2280 ((CIRC_CNT(info->xmit.head, info->xmit.tail,
2281 SERIAL_XMIT_SIZE) > 0) &&
2282 !info->tty->stopped && !info->tty->hw_stopped))
2283 result &= ~TIOCSER_TEMT;
2284
2285 if (copy_to_user(value, &result, sizeof(int)))
2286 return -EFAULT;
2287 return 0;
2288 }
2289
2290
get_modem_info(struct async_struct * info,unsigned int * value)2291 static int get_modem_info(struct async_struct * info, unsigned int *value)
2292 {
2293 unsigned char control, status;
2294 unsigned int result;
2295 unsigned long flags;
2296
2297 control = info->MCR;
2298 save_flags(flags); cli();
2299 status = serial_in(info, UART_MSR);
2300 restore_flags(flags);
2301 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
2302 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
2303 #ifdef TIOCM_OUT1
2304 | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
2305 | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
2306 #endif
2307 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
2308 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
2309 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
2310 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
2311
2312 if (copy_to_user(value, &result, sizeof(int)))
2313 return -EFAULT;
2314 return 0;
2315 }
2316
set_modem_info(struct async_struct * info,unsigned int cmd,unsigned int * value)2317 static int set_modem_info(struct async_struct * info, unsigned int cmd,
2318 unsigned int *value)
2319 {
2320 unsigned int arg;
2321 unsigned long flags;
2322
2323 if (copy_from_user(&arg, value, sizeof(int)))
2324 return -EFAULT;
2325
2326 switch (cmd) {
2327 case TIOCMBIS:
2328 if (arg & TIOCM_RTS)
2329 info->MCR |= UART_MCR_RTS;
2330 if (arg & TIOCM_DTR)
2331 info->MCR |= UART_MCR_DTR;
2332 #ifdef TIOCM_OUT1
2333 if (arg & TIOCM_OUT1)
2334 info->MCR |= UART_MCR_OUT1;
2335 if (arg & TIOCM_OUT2)
2336 info->MCR |= UART_MCR_OUT2;
2337 #endif
2338 if (arg & TIOCM_LOOP)
2339 info->MCR |= UART_MCR_LOOP;
2340 break;
2341 case TIOCMBIC:
2342 if (arg & TIOCM_RTS)
2343 info->MCR &= ~UART_MCR_RTS;
2344 if (arg & TIOCM_DTR)
2345 info->MCR &= ~UART_MCR_DTR;
2346 #ifdef TIOCM_OUT1
2347 if (arg & TIOCM_OUT1)
2348 info->MCR &= ~UART_MCR_OUT1;
2349 if (arg & TIOCM_OUT2)
2350 info->MCR &= ~UART_MCR_OUT2;
2351 #endif
2352 if (arg & TIOCM_LOOP)
2353 info->MCR &= ~UART_MCR_LOOP;
2354 break;
2355 case TIOCMSET:
2356 info->MCR = ((info->MCR & ~(UART_MCR_RTS |
2357 #ifdef TIOCM_OUT1
2358 UART_MCR_OUT1 |
2359 UART_MCR_OUT2 |
2360 #endif
2361 UART_MCR_LOOP |
2362 UART_MCR_DTR))
2363 | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
2364 #ifdef TIOCM_OUT1
2365 | ((arg & TIOCM_OUT1) ? UART_MCR_OUT1 : 0)
2366 | ((arg & TIOCM_OUT2) ? UART_MCR_OUT2 : 0)
2367 #endif
2368 | ((arg & TIOCM_LOOP) ? UART_MCR_LOOP : 0)
2369 | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
2370 break;
2371 default:
2372 return -EINVAL;
2373 }
2374 save_flags(flags); cli();
2375 info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
2376 serial_out(info, UART_MCR, info->MCR);
2377 restore_flags(flags);
2378 return 0;
2379 }
2380
do_autoconfig(struct async_struct * info)2381 static int do_autoconfig(struct async_struct * info)
2382 {
2383 int irq, retval;
2384
2385 if (!capable(CAP_SYS_ADMIN))
2386 return -EPERM;
2387
2388 if (info->state->count > 1)
2389 return -EBUSY;
2390
2391 shutdown(info);
2392
2393 autoconfig(info->state);
2394 if ((info->state->flags & ASYNC_AUTO_IRQ) &&
2395 (info->state->port != 0 || info->state->iomem_base != 0) &&
2396 (info->state->type != PORT_UNKNOWN)) {
2397 irq = detect_uart_irq(info->state);
2398 if (irq > 0)
2399 info->state->irq = irq;
2400 }
2401
2402 retval = startup(info);
2403 if (retval)
2404 return retval;
2405 return 0;
2406 }
2407
2408 /*
2409 * rs_break() --- routine which turns the break handling on or off
2410 */
2411 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
send_break(struct async_struct * info,int duration)2412 static void send_break( struct async_struct * info, int duration)
2413 {
2414 if (!CONFIGURED_SERIAL_PORT(info))
2415 return;
2416 current->state = TASK_INTERRUPTIBLE;
2417 current->timeout = jiffies + duration;
2418 cli();
2419 info->LCR |= UART_LCR_SBC;
2420 serial_out(info, UART_LCR, info->LCR);
2421 schedule();
2422 info->LCR &= ~UART_LCR_SBC;
2423 serial_out(info, UART_LCR, info->LCR);
2424 sti();
2425 }
2426 #else
rs_break(struct tty_struct * tty,int break_state)2427 static void rs_break(struct tty_struct *tty, int break_state)
2428 {
2429 struct async_struct * info = (struct async_struct *)tty->driver_data;
2430 unsigned long flags;
2431
2432 if (serial_paranoia_check(info, tty->device, "rs_break"))
2433 return;
2434
2435 if (!CONFIGURED_SERIAL_PORT(info))
2436 return;
2437 save_flags(flags); cli();
2438 if (break_state == -1)
2439 info->LCR |= UART_LCR_SBC;
2440 else
2441 info->LCR &= ~UART_LCR_SBC;
2442 serial_out(info, UART_LCR, info->LCR);
2443 restore_flags(flags);
2444 }
2445 #endif
2446
2447 #ifdef CONFIG_SERIAL_MULTIPORT
get_multiport_struct(struct async_struct * info,struct serial_multiport_struct * retinfo)2448 static int get_multiport_struct(struct async_struct * info,
2449 struct serial_multiport_struct *retinfo)
2450 {
2451 struct serial_multiport_struct ret;
2452 struct rs_multiport_struct *multi;
2453
2454 multi = &rs_multiport[info->state->irq];
2455
2456 ret.port_monitor = multi->port_monitor;
2457
2458 ret.port1 = multi->port1;
2459 ret.mask1 = multi->mask1;
2460 ret.match1 = multi->match1;
2461
2462 ret.port2 = multi->port2;
2463 ret.mask2 = multi->mask2;
2464 ret.match2 = multi->match2;
2465
2466 ret.port3 = multi->port3;
2467 ret.mask3 = multi->mask3;
2468 ret.match3 = multi->match3;
2469
2470 ret.port4 = multi->port4;
2471 ret.mask4 = multi->mask4;
2472 ret.match4 = multi->match4;
2473
2474 ret.irq = info->state->irq;
2475
2476 if (copy_to_user(retinfo,&ret,sizeof(*retinfo)))
2477 return -EFAULT;
2478 return 0;
2479 }
2480
set_multiport_struct(struct async_struct * info,struct serial_multiport_struct * in_multi)2481 static int set_multiport_struct(struct async_struct * info,
2482 struct serial_multiport_struct *in_multi)
2483 {
2484 struct serial_multiport_struct new_multi;
2485 struct rs_multiport_struct *multi;
2486 struct serial_state *state;
2487 int was_multi, now_multi;
2488 int retval;
2489 void (*handler)(int, void *, struct pt_regs *);
2490
2491 if (!capable(CAP_SYS_ADMIN))
2492 return -EPERM;
2493 state = info->state;
2494
2495 if (copy_from_user(&new_multi, in_multi,
2496 sizeof(struct serial_multiport_struct)))
2497 return -EFAULT;
2498
2499 if (new_multi.irq != state->irq || state->irq == 0 ||
2500 !IRQ_ports[state->irq])
2501 return -EINVAL;
2502
2503 multi = &rs_multiport[state->irq];
2504 was_multi = (multi->port1 != 0);
2505
2506 multi->port_monitor = new_multi.port_monitor;
2507
2508 if (multi->port1)
2509 release_region(multi->port1,1);
2510 multi->port1 = new_multi.port1;
2511 multi->mask1 = new_multi.mask1;
2512 multi->match1 = new_multi.match1;
2513 if (multi->port1)
2514 request_region(multi->port1,1,"serial(multiport1)");
2515
2516 if (multi->port2)
2517 release_region(multi->port2,1);
2518 multi->port2 = new_multi.port2;
2519 multi->mask2 = new_multi.mask2;
2520 multi->match2 = new_multi.match2;
2521 if (multi->port2)
2522 request_region(multi->port2,1,"serial(multiport2)");
2523
2524 if (multi->port3)
2525 release_region(multi->port3,1);
2526 multi->port3 = new_multi.port3;
2527 multi->mask3 = new_multi.mask3;
2528 multi->match3 = new_multi.match3;
2529 if (multi->port3)
2530 request_region(multi->port3,1,"serial(multiport3)");
2531
2532 if (multi->port4)
2533 release_region(multi->port4,1);
2534 multi->port4 = new_multi.port4;
2535 multi->mask4 = new_multi.mask4;
2536 multi->match4 = new_multi.match4;
2537 if (multi->port4)
2538 request_region(multi->port4,1,"serial(multiport4)");
2539
2540 now_multi = (multi->port1 != 0);
2541
2542 if (IRQ_ports[state->irq]->next_port &&
2543 (was_multi != now_multi)) {
2544 free_irq(state->irq, &IRQ_ports[state->irq]);
2545 if (now_multi)
2546 handler = rs_interrupt_multi;
2547 else
2548 handler = rs_interrupt;
2549
2550 retval = request_irq(state->irq, handler, SA_SHIRQ,
2551 "serial", &IRQ_ports[state->irq]);
2552 if (retval) {
2553 printk("Couldn't reallocate serial interrupt "
2554 "driver!!\n");
2555 }
2556 }
2557 return 0;
2558 }
2559 #endif
2560
rs_ioctl(struct tty_struct * tty,struct file * file,unsigned int cmd,unsigned long arg)2561 static int rs_ioctl(struct tty_struct *tty, struct file * file,
2562 unsigned int cmd, unsigned long arg)
2563 {
2564 struct async_struct * info = (struct async_struct *)tty->driver_data;
2565 struct async_icount cprev, cnow; /* kernel counter temps */
2566 struct serial_icounter_struct icount;
2567 unsigned long flags;
2568 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2569 int retval, tmp;
2570 #endif
2571
2572 if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
2573 return -ENODEV;
2574
2575 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2576 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
2577 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
2578 if (tty->flags & (1 << TTY_IO_ERROR))
2579 return -EIO;
2580 }
2581
2582 switch (cmd) {
2583 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2584 case TCSBRK: /* SVID version: non-zero arg --> no break */
2585 retval = tty_check_change(tty);
2586 if (retval)
2587 return retval;
2588 tty_wait_until_sent(tty, 0);
2589 if (signal_pending(current))
2590 return -EINTR;
2591 if (!arg) {
2592 send_break(info, HZ/4); /* 1/4 second */
2593 if (signal_pending(current))
2594 return -EINTR;
2595 }
2596 return 0;
2597 case TCSBRKP: /* support for POSIX tcsendbreak() */
2598 retval = tty_check_change(tty);
2599 if (retval)
2600 return retval;
2601 tty_wait_until_sent(tty, 0);
2602 if (signal_pending(current))
2603 return -EINTR;
2604 send_break(info, arg ? arg*(HZ/10) : HZ/4);
2605 if (signal_pending(current))
2606 return -EINTR;
2607 return 0;
2608 case TIOCGSOFTCAR:
2609 tmp = C_CLOCAL(tty) ? 1 : 0;
2610 if (copy_to_user((void *)arg, &tmp, sizeof(int)))
2611 return -EFAULT;
2612 return 0;
2613 case TIOCSSOFTCAR:
2614 if (copy_from_user(&tmp, (void *)arg, sizeof(int)))
2615 return -EFAULT;
2616
2617 tty->termios->c_cflag =
2618 ((tty->termios->c_cflag & ~CLOCAL) |
2619 (tmp ? CLOCAL : 0));
2620 return 0;
2621 #endif
2622 case TIOCMGET:
2623 return get_modem_info(info, (unsigned int *) arg);
2624 case TIOCMBIS:
2625 case TIOCMBIC:
2626 case TIOCMSET:
2627 return set_modem_info(info, cmd, (unsigned int *) arg);
2628 case TIOCGSERIAL:
2629 return get_serial_info(info,
2630 (struct serial_struct *) arg);
2631 case TIOCSSERIAL:
2632 return set_serial_info(info,
2633 (struct serial_struct *) arg);
2634 case TIOCSERCONFIG:
2635 return do_autoconfig(info);
2636
2637 case TIOCSERGETLSR: /* Get line status register */
2638 return get_lsr_info(info, (unsigned int *) arg);
2639
2640 case TIOCSERGSTRUCT:
2641 if (copy_to_user((struct async_struct *) arg,
2642 info, sizeof(struct async_struct)))
2643 return -EFAULT;
2644 return 0;
2645
2646 #ifdef CONFIG_SERIAL_MULTIPORT
2647 case TIOCSERGETMULTI:
2648 return get_multiport_struct(info,
2649 (struct serial_multiport_struct *) arg);
2650 case TIOCSERSETMULTI:
2651 return set_multiport_struct(info,
2652 (struct serial_multiport_struct *) arg);
2653 #endif
2654
2655 /*
2656 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
2657 * - mask passed in arg for lines of interest
2658 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2659 * Caller should use TIOCGICOUNT to see which one it was
2660 */
2661 case TIOCMIWAIT:
2662 save_flags(flags); cli();
2663 /* note the counters on entry */
2664 cprev = info->state->icount;
2665 restore_flags(flags);
2666 /* Force modem status interrupts on */
2667 info->IER |= UART_IER_MSI;
2668 serial_out(info, UART_IER, info->IER);
2669 while (1) {
2670 interruptible_sleep_on(&info->delta_msr_wait);
2671 /* see if a signal did it */
2672 if (signal_pending(current))
2673 return -ERESTARTSYS;
2674 save_flags(flags); cli();
2675 cnow = info->state->icount; /* atomic copy */
2676 restore_flags(flags);
2677 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2678 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2679 return -EIO; /* no change => error */
2680 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2681 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2682 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2683 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2684 return 0;
2685 }
2686 cprev = cnow;
2687 }
2688 /* NOTREACHED */
2689
2690 /*
2691 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2692 * Return: write counters to the user passed counter struct
2693 * NB: both 1->0 and 0->1 transitions are counted except for
2694 * RI where only 0->1 is counted.
2695 */
2696 case TIOCGICOUNT:
2697 save_flags(flags); cli();
2698 cnow = info->state->icount;
2699 restore_flags(flags);
2700 icount.cts = cnow.cts;
2701 icount.dsr = cnow.dsr;
2702 icount.rng = cnow.rng;
2703 icount.dcd = cnow.dcd;
2704 icount.rx = cnow.rx;
2705 icount.tx = cnow.tx;
2706 icount.frame = cnow.frame;
2707 icount.overrun = cnow.overrun;
2708 icount.parity = cnow.parity;
2709 icount.brk = cnow.brk;
2710 icount.buf_overrun = cnow.buf_overrun;
2711
2712 if (copy_to_user((void *)arg, &icount, sizeof(icount)))
2713 return -EFAULT;
2714 return 0;
2715 case TIOCSERGWILD:
2716 case TIOCSERSWILD:
2717 /* "setserial -W" is called in Debian boot */
2718 printk ("TIOCSER?WILD ioctl obsolete, ignored.\n");
2719 return 0;
2720
2721 default:
2722 return -ENOIOCTLCMD;
2723 }
2724 return 0;
2725 }
2726
rs_set_termios(struct tty_struct * tty,struct termios * old_termios)2727 static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
2728 {
2729 struct async_struct *info = (struct async_struct *)tty->driver_data;
2730 unsigned long flags;
2731 unsigned int cflag = tty->termios->c_cflag;
2732
2733 if ( (cflag == old_termios->c_cflag)
2734 && ( RELEVANT_IFLAG(tty->termios->c_iflag)
2735 == RELEVANT_IFLAG(old_termios->c_iflag)))
2736 return;
2737
2738 change_speed(info, old_termios);
2739
2740 /* Handle transition to B0 status */
2741 if ((old_termios->c_cflag & CBAUD) &&
2742 !(cflag & CBAUD)) {
2743 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
2744 save_flags(flags); cli();
2745 serial_out(info, UART_MCR, info->MCR);
2746 restore_flags(flags);
2747 }
2748
2749 /* Handle transition away from B0 status */
2750 if (!(old_termios->c_cflag & CBAUD) &&
2751 (cflag & CBAUD)) {
2752 info->MCR |= UART_MCR_DTR;
2753 if (!(tty->termios->c_cflag & CRTSCTS) ||
2754 !test_bit(TTY_THROTTLED, &tty->flags)) {
2755 info->MCR |= UART_MCR_RTS;
2756 }
2757 save_flags(flags); cli();
2758 serial_out(info, UART_MCR, info->MCR);
2759 restore_flags(flags);
2760 }
2761
2762 /* Handle turning off CRTSCTS */
2763 if ((old_termios->c_cflag & CRTSCTS) &&
2764 !(tty->termios->c_cflag & CRTSCTS)) {
2765 tty->hw_stopped = 0;
2766 rs_start(tty);
2767 }
2768
2769 #if 0
2770 /*
2771 * No need to wake up processes in open wait, since they
2772 * sample the CLOCAL flag once, and don't recheck it.
2773 * XXX It's not clear whether the current behavior is correct
2774 * or not. Hence, this may change.....
2775 */
2776 if (!(old_termios->c_cflag & CLOCAL) &&
2777 (tty->termios->c_cflag & CLOCAL))
2778 wake_up_interruptible(&info->open_wait);
2779 #endif
2780 }
2781
2782 /*
2783 * ------------------------------------------------------------
2784 * rs_close()
2785 *
2786 * This routine is called when the serial port gets closed. First, we
2787 * wait for the last remaining data to be sent. Then, we unlink its
2788 * async structure from the interrupt chain if necessary, and we free
2789 * that IRQ if nothing is left in the chain.
2790 * ------------------------------------------------------------
2791 */
rs_close(struct tty_struct * tty,struct file * filp)2792 static void rs_close(struct tty_struct *tty, struct file * filp)
2793 {
2794 struct async_struct * info = (struct async_struct *)tty->driver_data;
2795 struct serial_state *state;
2796 unsigned long flags;
2797
2798 if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
2799 return;
2800
2801 state = info->state;
2802
2803 save_flags(flags); cli();
2804
2805 if (tty_hung_up_p(filp)) {
2806 DBG_CNT("before DEC-hung");
2807 MOD_DEC_USE_COUNT;
2808 restore_flags(flags);
2809 return;
2810 }
2811
2812 #ifdef SERIAL_DEBUG_OPEN
2813 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
2814 #endif
2815 if ((tty->count == 1) && (state->count != 1)) {
2816 /*
2817 * Uh, oh. tty->count is 1, which means that the tty
2818 * structure will be freed. state->count should always
2819 * be one in these conditions. If it's greater than
2820 * one, we've got real problems, since it means the
2821 * serial port won't be shutdown.
2822 */
2823 printk("rs_close: bad serial port count; tty->count is 1, "
2824 "state->count is %d\n", state->count);
2825 state->count = 1;
2826 }
2827 if (--state->count < 0) {
2828 printk("rs_close: bad serial port count for ttys%d: %d\n",
2829 info->line, state->count);
2830 state->count = 0;
2831 }
2832 if (state->count) {
2833 DBG_CNT("before DEC-2");
2834 MOD_DEC_USE_COUNT;
2835 restore_flags(flags);
2836 return;
2837 }
2838 info->flags |= ASYNC_CLOSING;
2839 restore_flags(flags);
2840 /*
2841 * Save the termios structure, since this port may have
2842 * separate termios for callout and dialin.
2843 */
2844 if (info->flags & ASYNC_NORMAL_ACTIVE)
2845 info->state->normal_termios = *tty->termios;
2846 if (info->flags & ASYNC_CALLOUT_ACTIVE)
2847 info->state->callout_termios = *tty->termios;
2848 /*
2849 * Now we wait for the transmit buffer to clear; and we notify
2850 * the line discipline to only process XON/XOFF characters.
2851 */
2852 tty->closing = 1;
2853 if (state->closing_wait != ASYNC_CLOSING_WAIT_NONE)
2854 tty_wait_until_sent(tty, state->closing_wait);
2855 /*
2856 * At this point we stop accepting input. To do this, we
2857 * disable the receive line status interrupts, and tell the
2858 * interrupt driver to stop checking the data ready bit in the
2859 * line status register.
2860 */
2861 info->IER &= ~UART_IER_RLSI;
2862 info->read_status_mask &= ~UART_LSR_DR;
2863 if (info->flags & ASYNC_INITIALIZED) {
2864 serial_out(info, UART_IER, info->IER);
2865 /*
2866 * Before we drop DTR, make sure the UART transmitter
2867 * has completely drained; this is especially
2868 * important if there is a transmit FIFO!
2869 */
2870 rs_wait_until_sent(tty, info->timeout);
2871 }
2872 shutdown(info);
2873 if (tty->driver.flush_buffer)
2874 tty->driver.flush_buffer(tty);
2875 tty_ldisc_flush(tty);
2876 tty->closing = 0;
2877 info->event = 0;
2878 info->tty = 0;
2879 if (info->blocked_open) {
2880 if (state->close_delay) {
2881 set_current_state(TASK_INTERRUPTIBLE);
2882 schedule_timeout(state->close_delay);
2883 }
2884 wake_up_interruptible(&info->open_wait);
2885 }
2886 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
2887 ASYNC_CLOSING);
2888 wake_up_interruptible(&info->close_wait);
2889 MOD_DEC_USE_COUNT;
2890 }
2891
2892 /*
2893 * rs_wait_until_sent() --- wait until the transmitter is empty
2894 */
rs_wait_until_sent(struct tty_struct * tty,int timeout)2895 static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2896 {
2897 struct async_struct * info = (struct async_struct *)tty->driver_data;
2898 unsigned long orig_jiffies, char_time;
2899 int lsr;
2900
2901 if (serial_paranoia_check(info, tty->device, "rs_wait_until_sent"))
2902 return;
2903
2904 if (info->state->type == PORT_UNKNOWN)
2905 return;
2906
2907 if (info->xmit_fifo_size == 0)
2908 return; /* Just in case.... */
2909
2910 orig_jiffies = jiffies;
2911 /*
2912 * Set the check interval to be 1/5 of the estimated time to
2913 * send a single character, and make it at least 1. The check
2914 * interval should also be less than the timeout.
2915 *
2916 * Note: we have to use pretty tight timings here to satisfy
2917 * the NIST-PCTS.
2918 */
2919 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
2920 char_time = char_time / 5;
2921 if (char_time == 0)
2922 char_time = 1;
2923 if (timeout && timeout < char_time)
2924 char_time = timeout;
2925 /*
2926 * If the transmitter hasn't cleared in twice the approximate
2927 * amount of time to send the entire FIFO, it probably won't
2928 * ever clear. This assumes the UART isn't doing flow
2929 * control, which is currently the case. Hence, if it ever
2930 * takes longer than info->timeout, this is probably due to a
2931 * UART bug of some kind. So, we clamp the timeout parameter at
2932 * 2*info->timeout.
2933 */
2934 if (!timeout || timeout > 2*info->timeout)
2935 timeout = 2*info->timeout;
2936 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2937 printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
2938 printk("jiff=%lu...", jiffies);
2939 #endif
2940 while (!((lsr = serial_inp(info, UART_LSR)) & UART_LSR_TEMT)) {
2941 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2942 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
2943 #endif
2944 set_current_state(TASK_INTERRUPTIBLE);
2945 schedule_timeout(char_time);
2946 if (signal_pending(current))
2947 break;
2948 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2949 break;
2950 }
2951 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2952 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
2953 #endif
2954 }
2955
2956 /*
2957 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
2958 */
rs_hangup(struct tty_struct * tty)2959 static void rs_hangup(struct tty_struct *tty)
2960 {
2961 struct async_struct * info = (struct async_struct *)tty->driver_data;
2962 struct serial_state *state = info->state;
2963
2964 if (serial_paranoia_check(info, tty->device, "rs_hangup"))
2965 return;
2966
2967 state = info->state;
2968
2969 rs_flush_buffer(tty);
2970 if (info->flags & ASYNC_CLOSING)
2971 return;
2972 shutdown(info);
2973 info->event = 0;
2974 state->count = 0;
2975 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
2976 info->tty = 0;
2977 wake_up_interruptible(&info->open_wait);
2978 }
2979
2980 /*
2981 * ------------------------------------------------------------
2982 * rs_open() and friends
2983 * ------------------------------------------------------------
2984 */
block_til_ready(struct tty_struct * tty,struct file * filp,struct async_struct * info)2985 static int block_til_ready(struct tty_struct *tty, struct file * filp,
2986 struct async_struct *info)
2987 {
2988 DECLARE_WAITQUEUE(wait, current);
2989 struct serial_state *state = info->state;
2990 int retval;
2991 int do_clocal = 0, extra_count = 0;
2992 unsigned long flags;
2993
2994 /*
2995 * If the device is in the middle of being closed, then block
2996 * until it's done, and then try again.
2997 */
2998 if (tty_hung_up_p(filp) ||
2999 (info->flags & ASYNC_CLOSING)) {
3000 if (info->flags & ASYNC_CLOSING)
3001 interruptible_sleep_on(&info->close_wait);
3002 #ifdef SERIAL_DO_RESTART
3003 return ((info->flags & ASYNC_HUP_NOTIFY) ?
3004 -EAGAIN : -ERESTARTSYS);
3005 #else
3006 return -EAGAIN;
3007 #endif
3008 }
3009
3010 /*
3011 * If this is a callout device, then just make sure the normal
3012 * device isn't being used.
3013 */
3014 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
3015 if (info->flags & ASYNC_NORMAL_ACTIVE)
3016 return -EBUSY;
3017 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
3018 (info->flags & ASYNC_SESSION_LOCKOUT) &&
3019 (info->session != current->session))
3020 return -EBUSY;
3021 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
3022 (info->flags & ASYNC_PGRP_LOCKOUT) &&
3023 (info->pgrp != current->pgrp))
3024 return -EBUSY;
3025 info->flags |= ASYNC_CALLOUT_ACTIVE;
3026 return 0;
3027 }
3028
3029 /*
3030 * If non-blocking mode is set, or the port is not enabled,
3031 * then make the check up front and then exit.
3032 */
3033 if ((filp->f_flags & O_NONBLOCK) ||
3034 (tty->flags & (1 << TTY_IO_ERROR))) {
3035 if (info->flags & ASYNC_CALLOUT_ACTIVE)
3036 return -EBUSY;
3037 info->flags |= ASYNC_NORMAL_ACTIVE;
3038 return 0;
3039 }
3040
3041 if (info->flags & ASYNC_CALLOUT_ACTIVE) {
3042 if (state->normal_termios.c_cflag & CLOCAL)
3043 do_clocal = 1;
3044 } else {
3045 if (tty->termios->c_cflag & CLOCAL)
3046 do_clocal = 1;
3047 }
3048
3049 /*
3050 * Block waiting for the carrier detect and the line to become
3051 * free (i.e., not in use by the callout). While we are in
3052 * this loop, state->count is dropped by one, so that
3053 * rs_close() knows when to free things. We restore it upon
3054 * exit, either normal or abnormal.
3055 */
3056 retval = 0;
3057 add_wait_queue(&info->open_wait, &wait);
3058 #ifdef SERIAL_DEBUG_OPEN
3059 printk("block_til_ready before block: ttys%d, count = %d\n",
3060 state->line, state->count);
3061 #endif
3062 save_flags(flags); cli();
3063 if (!tty_hung_up_p(filp)) {
3064 extra_count = 1;
3065 state->count--;
3066 }
3067 restore_flags(flags);
3068 info->blocked_open++;
3069 while (1) {
3070 save_flags(flags); cli();
3071 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
3072 (tty->termios->c_cflag & CBAUD))
3073 serial_out(info, UART_MCR,
3074 serial_inp(info, UART_MCR) |
3075 (UART_MCR_DTR | UART_MCR_RTS));
3076 restore_flags(flags);
3077 set_current_state(TASK_INTERRUPTIBLE);
3078 if (tty_hung_up_p(filp) ||
3079 !(info->flags & ASYNC_INITIALIZED)) {
3080 #ifdef SERIAL_DO_RESTART
3081 if (info->flags & ASYNC_HUP_NOTIFY)
3082 retval = -EAGAIN;
3083 else
3084 retval = -ERESTARTSYS;
3085 #else
3086 retval = -EAGAIN;
3087 #endif
3088 break;
3089 }
3090 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
3091 !(info->flags & ASYNC_CLOSING) &&
3092 (do_clocal || (serial_in(info, UART_MSR) &
3093 UART_MSR_DCD)))
3094 break;
3095 if (signal_pending(current)) {
3096 retval = -ERESTARTSYS;
3097 break;
3098 }
3099 #ifdef SERIAL_DEBUG_OPEN
3100 printk("block_til_ready blocking: ttys%d, count = %d\n",
3101 info->line, state->count);
3102 #endif
3103 schedule();
3104 }
3105 set_current_state(TASK_RUNNING);
3106 remove_wait_queue(&info->open_wait, &wait);
3107 if (extra_count)
3108 state->count++;
3109 info->blocked_open--;
3110 #ifdef SERIAL_DEBUG_OPEN
3111 printk("block_til_ready after blocking: ttys%d, count = %d\n",
3112 info->line, state->count);
3113 #endif
3114 if (retval)
3115 return retval;
3116 info->flags |= ASYNC_NORMAL_ACTIVE;
3117 return 0;
3118 }
3119
get_async_struct(int line,struct async_struct ** ret_info)3120 static int get_async_struct(int line, struct async_struct **ret_info)
3121 {
3122 struct async_struct *info;
3123 struct serial_state *sstate;
3124
3125 sstate = rs_table + line;
3126 sstate->count++;
3127 if (sstate->info) {
3128 *ret_info = sstate->info;
3129 return 0;
3130 }
3131 info = kmalloc(sizeof(struct async_struct), GFP_KERNEL);
3132 if (!info) {
3133 sstate->count--;
3134 return -ENOMEM;
3135 }
3136 memset(info, 0, sizeof(struct async_struct));
3137 init_waitqueue_head(&info->open_wait);
3138 init_waitqueue_head(&info->close_wait);
3139 init_waitqueue_head(&info->delta_msr_wait);
3140 info->magic = SERIAL_MAGIC;
3141 info->port = sstate->port;
3142 info->flags = sstate->flags;
3143 info->io_type = sstate->io_type;
3144 info->iomem_base = sstate->iomem_base;
3145 info->iomem_reg_shift = sstate->iomem_reg_shift;
3146 info->xmit_fifo_size = sstate->xmit_fifo_size;
3147 info->line = line;
3148 info->tqueue.routine = do_softint;
3149 info->tqueue.data = info;
3150 info->state = sstate;
3151 if (sstate->info) {
3152 kfree(info);
3153 *ret_info = sstate->info;
3154 return 0;
3155 }
3156 *ret_info = sstate->info = info;
3157 return 0;
3158 }
3159
3160 /*
3161 * This routine is called whenever a serial port is opened. It
3162 * enables interrupts for a serial port, linking in its async structure into
3163 * the IRQ chain. It also performs the serial-specific
3164 * initialization for the tty structure.
3165 *
3166 * Note that on failure, we don't decrement the module use count - the tty
3167 * later will call rs_close, which will decrement it for us as long as
3168 * tty->driver_data is set non-NULL. --rmk
3169 */
rs_open(struct tty_struct * tty,struct file * filp)3170 static int rs_open(struct tty_struct *tty, struct file * filp)
3171 {
3172 struct async_struct *info;
3173 int retval, line;
3174 unsigned long page;
3175
3176 MOD_INC_USE_COUNT;
3177 line = MINOR(tty->device) - tty->driver.minor_start;
3178 if ((line < 0) || (line >= NR_PORTS)) {
3179 MOD_DEC_USE_COUNT;
3180 return -ENODEV;
3181 }
3182 retval = get_async_struct(line, &info);
3183 if (retval) {
3184 MOD_DEC_USE_COUNT;
3185 return retval;
3186 }
3187 tty->driver_data = info;
3188 info->tty = tty;
3189 if (serial_paranoia_check(info, tty->device, "rs_open"))
3190 return -ENODEV;
3191
3192 #ifdef SERIAL_DEBUG_OPEN
3193 printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
3194 info->state->count);
3195 #endif
3196 #if (LINUX_VERSION_CODE > 0x20100)
3197 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
3198 #endif
3199
3200 /*
3201 * This relies on lock_kernel() stuff so wants tidying for 2.5
3202 */
3203 if (!tmp_buf) {
3204 page = get_zeroed_page(GFP_KERNEL);
3205 if (!page)
3206 return -ENOMEM;
3207 if (tmp_buf)
3208 free_page(page);
3209 else
3210 tmp_buf = (unsigned char *) page;
3211 }
3212
3213 /*
3214 * If the port is the middle of closing, bail out now
3215 */
3216 if (tty_hung_up_p(filp) ||
3217 (info->flags & ASYNC_CLOSING)) {
3218 if (info->flags & ASYNC_CLOSING)
3219 interruptible_sleep_on(&info->close_wait);
3220 #ifdef SERIAL_DO_RESTART
3221 return ((info->flags & ASYNC_HUP_NOTIFY) ?
3222 -EAGAIN : -ERESTARTSYS);
3223 #else
3224 return -EAGAIN;
3225 #endif
3226 }
3227
3228 /*
3229 * Start up serial port
3230 */
3231 retval = startup(info);
3232 if (retval)
3233 return retval;
3234
3235 retval = block_til_ready(tty, filp, info);
3236 if (retval) {
3237 #ifdef SERIAL_DEBUG_OPEN
3238 printk("rs_open returning after block_til_ready with %d\n",
3239 retval);
3240 #endif
3241 return retval;
3242 }
3243
3244 if ((info->state->count == 1) &&
3245 (info->flags & ASYNC_SPLIT_TERMIOS)) {
3246 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
3247 *tty->termios = info->state->normal_termios;
3248 else
3249 *tty->termios = info->state->callout_termios;
3250 change_speed(info, 0);
3251 }
3252 #ifdef CONFIG_SERIAL_CONSOLE
3253 if (sercons.cflag && sercons.index == line) {
3254 tty->termios->c_cflag = sercons.cflag;
3255 sercons.cflag = 0;
3256 change_speed(info, 0);
3257 }
3258 #endif
3259 info->session = current->session;
3260 info->pgrp = current->pgrp;
3261
3262 #ifdef SERIAL_DEBUG_OPEN
3263 printk("rs_open ttys%d successful...", info->line);
3264 #endif
3265 return 0;
3266 }
3267
3268 /*
3269 * /proc fs routines....
3270 */
3271
line_info(char * buf,struct serial_state * state)3272 static inline int line_info(char *buf, struct serial_state *state)
3273 {
3274 struct async_struct *info = state->info, scr_info;
3275 char stat_buf[30], control, status;
3276 int ret;
3277 unsigned long flags;
3278
3279 /*
3280 * Return zero characters for ports not claimed by driver.
3281 */
3282 if (state->type == PORT_UNKNOWN) {
3283 return 0; /* ignore unused ports */
3284 }
3285
3286 ret = sprintf(buf, "%d: uart:%s port:%lX irq:%d",
3287 state->line, uart_config[state->type].name,
3288 (state->port ? state->port : (long)state->iomem_base),
3289 state->irq);
3290
3291 /*
3292 * Figure out the current RS-232 lines
3293 */
3294 if (!info) {
3295 info = &scr_info; /* This is just for serial_{in,out} */
3296
3297 info->magic = SERIAL_MAGIC;
3298 info->port = state->port;
3299 info->flags = state->flags;
3300 info->hub6 = state->hub6;
3301 info->io_type = state->io_type;
3302 info->iomem_base = state->iomem_base;
3303 info->iomem_reg_shift = state->iomem_reg_shift;
3304 info->quot = 0;
3305 info->tty = 0;
3306 }
3307 save_flags(flags); cli();
3308 status = serial_in(info, UART_MSR);
3309 control = info != &scr_info ? info->MCR : serial_in(info, UART_MCR);
3310 restore_flags(flags);
3311
3312 stat_buf[0] = 0;
3313 stat_buf[1] = 0;
3314 if (control & UART_MCR_RTS)
3315 strcat(stat_buf, "|RTS");
3316 if (status & UART_MSR_CTS)
3317 strcat(stat_buf, "|CTS");
3318 if (control & UART_MCR_DTR)
3319 strcat(stat_buf, "|DTR");
3320 if (status & UART_MSR_DSR)
3321 strcat(stat_buf, "|DSR");
3322 if (status & UART_MSR_DCD)
3323 strcat(stat_buf, "|CD");
3324 if (status & UART_MSR_RI)
3325 strcat(stat_buf, "|RI");
3326
3327 if (info->quot) {
3328 ret += sprintf(buf+ret, " baud:%d",
3329 state->baud_base / info->quot);
3330 }
3331
3332 ret += sprintf(buf+ret, " tx:%d rx:%d",
3333 state->icount.tx, state->icount.rx);
3334
3335 if (state->icount.frame)
3336 ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
3337
3338 if (state->icount.parity)
3339 ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
3340
3341 if (state->icount.brk)
3342 ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
3343
3344 if (state->icount.overrun)
3345 ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
3346
3347 /*
3348 * Last thing is the RS-232 status lines
3349 */
3350 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
3351 return ret;
3352 }
3353
rs_read_proc(char * page,char ** start,off_t off,int count,int * eof,void * data)3354 static int rs_read_proc(char *page, char **start, off_t off, int count,
3355 int *eof, void *data)
3356 {
3357 int i, len = 0, l;
3358 off_t begin = 0;
3359
3360 len += sprintf(page, "serinfo:1.0 driver:%s%s revision:%s\n",
3361 serial_version, LOCAL_VERSTRING, serial_revdate);
3362 for (i = 0; i < NR_PORTS && len < 4000; i++) {
3363 l = line_info(page + len, &rs_table[i]);
3364 len += l;
3365 if (len+begin > off+count)
3366 goto done;
3367 if (len+begin < off) {
3368 begin += len;
3369 len = 0;
3370 }
3371 }
3372 *eof = 1;
3373 done:
3374 if (off >= len+begin)
3375 return 0;
3376 *start = page + (off-begin);
3377 return ((count < begin+len-off) ? count : begin+len-off);
3378 }
3379
3380 /*
3381 * ---------------------------------------------------------------------
3382 * rs_init() and friends
3383 *
3384 * rs_init() is called at boot-time to initialize the serial driver.
3385 * ---------------------------------------------------------------------
3386 */
3387
3388 /*
3389 * This routine prints out the appropriate serial driver version
3390 * number, and identifies which options were configured into this
3391 * driver.
3392 */
3393 static char serial_options[] __initdata =
3394 #ifdef CONFIG_HUB6
3395 " HUB-6"
3396 #define SERIAL_OPT
3397 #endif
3398 #ifdef CONFIG_SERIAL_MANY_PORTS
3399 " MANY_PORTS"
3400 #define SERIAL_OPT
3401 #endif
3402 #ifdef CONFIG_SERIAL_MULTIPORT
3403 " MULTIPORT"
3404 #define SERIAL_OPT
3405 #endif
3406 #ifdef CONFIG_SERIAL_SHARE_IRQ
3407 " SHARE_IRQ"
3408 #define SERIAL_OPT
3409 #endif
3410 #ifdef CONFIG_SERIAL_DETECT_IRQ
3411 " DETECT_IRQ"
3412 #define SERIAL_OPT
3413 #endif
3414 #ifdef ENABLE_SERIAL_PCI
3415 " SERIAL_PCI"
3416 #define SERIAL_OPT
3417 #endif
3418 #ifdef ENABLE_SERIAL_PNP
3419 " ISAPNP"
3420 #define SERIAL_OPT
3421 #endif
3422 #ifdef ENABLE_SERIAL_ACPI
3423 " SERIAL_ACPI"
3424 #define SERIAL_OPT
3425 #endif
3426 #ifdef SERIAL_OPT
3427 " enabled\n";
3428 #else
3429 " no serial options enabled\n";
3430 #endif
3431 #undef SERIAL_OPT
3432
show_serial_version(void)3433 static _INLINE_ void show_serial_version(void)
3434 {
3435 printk(KERN_INFO "%s version %s%s (%s) with%s", serial_name,
3436 serial_version, LOCAL_VERSTRING, serial_revdate,
3437 serial_options);
3438 }
3439
3440 /*
3441 * This routine detect the IRQ of a serial port by clearing OUT2 when
3442 * no UART interrupt are requested (IER = 0) (*GPL*). This seems to work at
3443 * each time, as long as no other device permanently request the IRQ.
3444 * If no IRQ is detected, or multiple IRQ appear, this function returns 0.
3445 * The variable "state" and the field "state->port" should not be null.
3446 */
detect_uart_irq(struct serial_state * state)3447 static unsigned detect_uart_irq (struct serial_state * state)
3448 {
3449 int irq;
3450 unsigned long irqs;
3451 unsigned char save_mcr, save_ier;
3452 struct async_struct scr_info; /* serial_{in,out} because HUB6 */
3453
3454 #ifdef CONFIG_SERIAL_MANY_PORTS
3455 unsigned char save_ICP=0; /* no warning */
3456 unsigned short ICP=0;
3457
3458 if (state->flags & ASYNC_FOURPORT) {
3459 ICP = (state->port & 0xFE0) | 0x01F;
3460 save_ICP = inb_p(ICP);
3461 outb_p(0x80, ICP);
3462 (void) inb_p(ICP);
3463 }
3464 #endif
3465 scr_info.magic = SERIAL_MAGIC;
3466 scr_info.state = state;
3467 scr_info.port = state->port;
3468 scr_info.flags = state->flags;
3469 #ifdef CONFIG_HUB6
3470 scr_info.hub6 = state->hub6;
3471 #endif
3472 scr_info.io_type = state->io_type;
3473 scr_info.iomem_base = state->iomem_base;
3474 scr_info.iomem_reg_shift = state->iomem_reg_shift;
3475
3476 /* forget possible initially masked and pending IRQ */
3477 probe_irq_off(probe_irq_on());
3478 save_mcr = serial_inp(&scr_info, UART_MCR);
3479 save_ier = serial_inp(&scr_info, UART_IER);
3480 serial_outp(&scr_info, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);
3481
3482 irqs = probe_irq_on();
3483 serial_outp(&scr_info, UART_MCR, 0);
3484 udelay (10);
3485 if (state->flags & ASYNC_FOURPORT) {
3486 serial_outp(&scr_info, UART_MCR,
3487 UART_MCR_DTR | UART_MCR_RTS);
3488 } else {
3489 serial_outp(&scr_info, UART_MCR,
3490 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
3491 }
3492 serial_outp(&scr_info, UART_IER, 0x0f); /* enable all intrs */
3493 (void)serial_inp(&scr_info, UART_LSR);
3494 (void)serial_inp(&scr_info, UART_RX);
3495 (void)serial_inp(&scr_info, UART_IIR);
3496 (void)serial_inp(&scr_info, UART_MSR);
3497 serial_outp(&scr_info, UART_TX, 0xFF);
3498 udelay (20);
3499 irq = probe_irq_off(irqs);
3500
3501 serial_outp(&scr_info, UART_MCR, save_mcr);
3502 serial_outp(&scr_info, UART_IER, save_ier);
3503 #ifdef CONFIG_SERIAL_MANY_PORTS
3504 if (state->flags & ASYNC_FOURPORT)
3505 outb_p(save_ICP, ICP);
3506 #endif
3507 return (irq > 0)? irq : 0;
3508 }
3509
3510 /*
3511 * This is a quickie test to see how big the FIFO is.
3512 * It doesn't work at all the time, more's the pity.
3513 */
size_fifo(struct async_struct * info)3514 static int size_fifo(struct async_struct *info)
3515 {
3516 unsigned char old_fcr, old_mcr, old_dll, old_dlm;
3517 int count;
3518
3519 old_fcr = serial_inp(info, UART_FCR);
3520 old_mcr = serial_inp(info, UART_MCR);
3521 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO |
3522 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
3523 serial_outp(info, UART_MCR, UART_MCR_LOOP);
3524 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3525 old_dll = serial_inp(info, UART_DLL);
3526 old_dlm = serial_inp(info, UART_DLM);
3527 serial_outp(info, UART_DLL, 0x01);
3528 serial_outp(info, UART_DLM, 0x00);
3529 serial_outp(info, UART_LCR, 0x03);
3530 for (count = 0; count < 256; count++)
3531 serial_outp(info, UART_TX, count);
3532 mdelay(20);
3533 for (count = 0; (serial_inp(info, UART_LSR) & UART_LSR_DR) &&
3534 (count < 256); count++)
3535 serial_inp(info, UART_RX);
3536 serial_outp(info, UART_FCR, old_fcr);
3537 serial_outp(info, UART_MCR, old_mcr);
3538 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3539 serial_outp(info, UART_DLL, old_dll);
3540 serial_outp(info, UART_DLM, old_dlm);
3541
3542 return count;
3543 }
3544
3545 /*
3546 * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
3547 * When this function is called we know it is at least a StarTech
3548 * 16650 V2, but it might be one of several StarTech UARTs, or one of
3549 * its clones. (We treat the broken original StarTech 16650 V1 as a
3550 * 16550, and why not? Startech doesn't seem to even acknowledge its
3551 * existence.)
3552 *
3553 * What evil have men's minds wrought...
3554 */
autoconfig_startech_uarts(struct async_struct * info,struct serial_state * state,unsigned long flags)3555 static void autoconfig_startech_uarts(struct async_struct *info,
3556 struct serial_state *state,
3557 unsigned long flags)
3558 {
3559 unsigned char scratch, scratch2, scratch3, scratch4;
3560
3561 /*
3562 * First we check to see if it's an Oxford Semiconductor UART.
3563 *
3564 * If we have to do this here because some non-National
3565 * Semiconductor clone chips lock up if you try writing to the
3566 * LSR register (which serial_icr_read does)
3567 */
3568 if (state->type == PORT_16550A) {
3569 /*
3570 * EFR [4] must be set else this test fails
3571 *
3572 * This shouldn't be necessary, but Mike Hudson
3573 * (Exoray@isys.ca) claims that it's needed for 952
3574 * dual UART's (which are not recommended for new designs).
3575 */
3576 info->ACR = 0;
3577 serial_out(info, UART_LCR, 0xBF);
3578 serial_out(info, UART_EFR, 0x10);
3579 serial_out(info, UART_LCR, 0x00);
3580 /* Check for Oxford Semiconductor 16C950 */
3581 scratch = serial_icr_read(info, UART_ID1);
3582 scratch2 = serial_icr_read(info, UART_ID2);
3583 scratch3 = serial_icr_read(info, UART_ID3);
3584
3585 if (scratch == 0x16 && scratch2 == 0xC9 &&
3586 (scratch3 == 0x50 || scratch3 == 0x52 ||
3587 scratch3 == 0x54)) {
3588 state->type = PORT_16C950;
3589 state->revision = serial_icr_read(info, UART_REV) |
3590 (scratch3 << 8);
3591 return;
3592 }
3593 }
3594
3595 /*
3596 * We check for a XR16C850 by setting DLL and DLM to 0, and
3597 * then reading back DLL and DLM. If DLM reads back 0x10,
3598 * then the UART is a XR16C850 and the DLL contains the chip
3599 * revision. If DLM reads back 0x14, then the UART is a
3600 * XR16C854.
3601 *
3602 */
3603
3604 /* Save the DLL and DLM */
3605
3606 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3607 scratch3 = serial_inp(info, UART_DLL);
3608 scratch4 = serial_inp(info, UART_DLM);
3609
3610 serial_outp(info, UART_DLL, 0);
3611 serial_outp(info, UART_DLM, 0);
3612 scratch2 = serial_inp(info, UART_DLL);
3613 scratch = serial_inp(info, UART_DLM);
3614 serial_outp(info, UART_LCR, 0);
3615
3616 if (scratch == 0x10 || scratch == 0x14) {
3617 if (scratch == 0x10)
3618 state->revision = scratch2;
3619 state->type = PORT_16850;
3620 return;
3621 }
3622
3623 /* Restore the DLL and DLM */
3624
3625 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3626 serial_outp(info, UART_DLL, scratch3);
3627 serial_outp(info, UART_DLM, scratch4);
3628 serial_outp(info, UART_LCR, 0);
3629 /*
3630 * We distinguish between the '654 and the '650 by counting
3631 * how many bytes are in the FIFO. I'm using this for now,
3632 * since that's the technique that was sent to me in the
3633 * serial driver update, but I'm not convinced this works.
3634 * I've had problems doing this in the past. -TYT
3635 */
3636 if (size_fifo(info) == 64)
3637 state->type = PORT_16654;
3638 else
3639 state->type = PORT_16650V2;
3640 }
3641
3642 /*
3643 * This routine is called by rs_init() to initialize a specific serial
3644 * port. It determines what type of UART chip this serial port is
3645 * using: 8250, 16450, 16550, 16550A. The important question is
3646 * whether or not this UART is a 16550A or not, since this will
3647 * determine whether or not we can use its FIFO features or not.
3648 */
autoconfig(struct serial_state * state)3649 static void autoconfig(struct serial_state * state)
3650 {
3651 unsigned char status1, status2, scratch, scratch2, scratch3;
3652 unsigned char save_lcr, save_mcr;
3653 struct async_struct *info, scr_info;
3654 unsigned long flags;
3655
3656 state->type = PORT_UNKNOWN;
3657
3658 #ifdef SERIAL_DEBUG_AUTOCONF
3659 printk("Testing ttyS%d (0x%04lx, 0x%04x)...\n", state->line,
3660 state->port, (unsigned) state->iomem_base);
3661 #endif
3662
3663 if (!CONFIGURED_SERIAL_PORT(state))
3664 return;
3665
3666 info = &scr_info; /* This is just for serial_{in,out} */
3667
3668 info->magic = SERIAL_MAGIC;
3669 info->state = state;
3670 info->port = state->port;
3671 info->flags = state->flags;
3672 #ifdef CONFIG_HUB6
3673 info->hub6 = state->hub6;
3674 #endif
3675 info->io_type = state->io_type;
3676 info->iomem_base = state->iomem_base;
3677 info->iomem_reg_shift = state->iomem_reg_shift;
3678
3679 save_flags(flags); cli();
3680
3681 if (!(state->flags & ASYNC_BUGGY_UART) &&
3682 !state->iomem_base) {
3683 /*
3684 * Do a simple existence test first; if we fail this,
3685 * there's no point trying anything else.
3686 *
3687 * 0x80 is used as a nonsense port to prevent against
3688 * false positives due to ISA bus float. The
3689 * assumption is that 0x80 is a non-existent port;
3690 * which should be safe since include/asm/io.h also
3691 * makes this assumption.
3692 */
3693 scratch = serial_inp(info, UART_IER);
3694 serial_outp(info, UART_IER, 0);
3695 #ifdef __i386__
3696 outb(0xff, 0x080);
3697 #endif
3698 scratch2 = serial_inp(info, UART_IER);
3699 serial_outp(info, UART_IER, 0x0F);
3700 #ifdef __i386__
3701 outb(0, 0x080);
3702 #endif
3703 scratch3 = serial_inp(info, UART_IER);
3704 serial_outp(info, UART_IER, scratch);
3705 if (scratch2 || scratch3 != 0x0F) {
3706 #ifdef SERIAL_DEBUG_AUTOCONF
3707 printk("serial: ttyS%d: simple autoconfig failed "
3708 "(%02x, %02x)\n", state->line,
3709 scratch2, scratch3);
3710 #endif
3711 restore_flags(flags);
3712 return; /* We failed; there's nothing here */
3713 }
3714 }
3715
3716 save_mcr = serial_in(info, UART_MCR);
3717 save_lcr = serial_in(info, UART_LCR);
3718
3719 /*
3720 * Check to see if a UART is really there. Certain broken
3721 * internal modems based on the Rockwell chipset fail this
3722 * test, because they apparently don't implement the loopback
3723 * test mode. So this test is skipped on the COM 1 through
3724 * COM 4 ports. This *should* be safe, since no board
3725 * manufacturer would be stupid enough to design a board
3726 * that conflicts with COM 1-4 --- we hope!
3727 */
3728 if (!(state->flags & ASYNC_SKIP_TEST)) {
3729 serial_outp(info, UART_MCR, UART_MCR_LOOP | 0x0A);
3730 status1 = serial_inp(info, UART_MSR) & 0xF0;
3731 serial_outp(info, UART_MCR, save_mcr);
3732 if (status1 != 0x90) {
3733 #ifdef SERIAL_DEBUG_AUTOCONF
3734 printk("serial: ttyS%d: no UART loopback failed\n",
3735 state->line);
3736 #endif
3737 restore_flags(flags);
3738 return;
3739 }
3740 }
3741 serial_outp(info, UART_LCR, 0xBF); /* set up for StarTech test */
3742 serial_outp(info, UART_EFR, 0); /* EFR is the same as FCR */
3743 serial_outp(info, UART_LCR, 0);
3744 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
3745 scratch = serial_in(info, UART_IIR) >> 6;
3746 switch (scratch) {
3747 case 0:
3748 state->type = PORT_16450;
3749 break;
3750 case 1:
3751 state->type = PORT_UNKNOWN;
3752 break;
3753 case 2:
3754 state->type = PORT_16550;
3755 break;
3756 case 3:
3757 state->type = PORT_16550A;
3758 break;
3759 }
3760 if (state->type == PORT_16550A) {
3761 /* Check for Startech UART's */
3762 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3763 if (serial_in(info, UART_EFR) == 0) {
3764 serial_outp(info, UART_EFR, 0xA8);
3765 if (serial_in(info, UART_EFR) == 0) {
3766 /* We are a NS16552D/Motorola
3767 * 8xxx DUART, stop. */
3768 goto out;
3769 }
3770 state->type = PORT_16650;
3771 serial_outp(info, UART_EFR, 0);
3772 } else {
3773 serial_outp(info, UART_LCR, 0xBF);
3774 if (serial_in(info, UART_EFR) == 0)
3775 autoconfig_startech_uarts(info, state, flags);
3776 }
3777 }
3778 if (state->type == PORT_16550A) {
3779 /* Check for TI 16750 */
3780 serial_outp(info, UART_LCR, save_lcr | UART_LCR_DLAB);
3781 serial_outp(info, UART_FCR,
3782 UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
3783 scratch = serial_in(info, UART_IIR) >> 5;
3784 if (scratch == 7) {
3785 /*
3786 * If this is a 16750, and not a cheap UART
3787 * clone, then it should only go into 64 byte
3788 * mode if the UART_FCR7_64BYTE bit was set
3789 * while UART_LCR_DLAB was latched.
3790 */
3791 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
3792 serial_outp(info, UART_LCR, 0);
3793 serial_outp(info, UART_FCR,
3794 UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
3795 scratch = serial_in(info, UART_IIR) >> 5;
3796 if (scratch == 6)
3797 state->type = PORT_16750;
3798 }
3799 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
3800 }
3801 #if defined(CONFIG_SERIAL_RSA) && defined(MODULE)
3802 if (state->type == PORT_16550A) {
3803 int i;
3804
3805 for (i = 0 ; i < PORT_RSA_MAX ; ++i) {
3806 if (!probe_rsa[i] && !force_rsa[i])
3807 break;
3808 if (((probe_rsa[i] != state->port) ||
3809 check_region(state->port + UART_RSA_BASE, 16)) &&
3810 (force_rsa[i] != state->port))
3811 continue;
3812 if (!enable_rsa(info))
3813 continue;
3814 state->type = PORT_RSA;
3815 state->baud_base = SERIAL_RSA_BAUD_BASE;
3816 break;
3817 }
3818 }
3819 #endif
3820 out:
3821 serial_outp(info, UART_LCR, save_lcr);
3822 if (state->type == PORT_16450) {
3823 scratch = serial_in(info, UART_SCR);
3824 serial_outp(info, UART_SCR, 0xa5);
3825 status1 = serial_in(info, UART_SCR);
3826 serial_outp(info, UART_SCR, 0x5a);
3827 status2 = serial_in(info, UART_SCR);
3828 serial_outp(info, UART_SCR, scratch);
3829
3830 if ((status1 != 0xa5) || (status2 != 0x5a))
3831 state->type = PORT_8250;
3832 }
3833 state->xmit_fifo_size = uart_config[state->type].dfl_xmit_fifo_size;
3834
3835 if (state->type == PORT_UNKNOWN) {
3836 restore_flags(flags);
3837 return;
3838 }
3839
3840 if (info->port) {
3841 #ifdef CONFIG_SERIAL_RSA
3842 if (state->type == PORT_RSA)
3843 request_region(info->port + UART_RSA_BASE, 16,
3844 "serial_rsa(auto)");
3845 else
3846 #endif
3847 request_region(info->port,8,"serial(auto)");
3848 }
3849
3850 /*
3851 * Reset the UART.
3852 */
3853 #ifdef CONFIG_SERIAL_RSA
3854 if (state->type == PORT_RSA)
3855 serial_outp(info, UART_RSA_FRR, 0);
3856 #endif
3857 serial_outp(info, UART_MCR, save_mcr);
3858 serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
3859 UART_FCR_CLEAR_RCVR |
3860 UART_FCR_CLEAR_XMIT));
3861 serial_outp(info, UART_FCR, 0);
3862 (void)serial_in(info, UART_RX);
3863 serial_outp(info, UART_IER, 0);
3864
3865 restore_flags(flags);
3866 }
3867
3868 int register_serial(struct serial_struct *req);
3869 void unregister_serial(int line);
3870
3871 #if (LINUX_VERSION_CODE > 0x20100)
3872 EXPORT_SYMBOL(register_serial);
3873 EXPORT_SYMBOL(unregister_serial);
3874 #else
3875 static struct symbol_table serial_syms = {
3876 #include <linux/symtab_begin.h>
3877 X(register_serial),
3878 X(unregister_serial),
3879 #include <linux/symtab_end.h>
3880 };
3881 #endif
3882
3883
3884 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
3885
printk_pnp_dev_id(unsigned short vendor,unsigned short device)3886 static void __devinit printk_pnp_dev_id(unsigned short vendor,
3887 unsigned short device)
3888 {
3889 printk("%c%c%c%x%x%x%x",
3890 'A' + ((vendor >> 2) & 0x3f) - 1,
3891 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
3892 'A' + ((vendor >> 8) & 0x1f) - 1,
3893 (device >> 4) & 0x0f,
3894 device & 0x0f,
3895 (device >> 12) & 0x0f,
3896 (device >> 8) & 0x0f);
3897 }
3898
get_pci_port(struct pci_dev * dev,struct pci_board * board,struct serial_struct * req,int idx)3899 static _INLINE_ int get_pci_port(struct pci_dev *dev,
3900 struct pci_board *board,
3901 struct serial_struct *req,
3902 int idx)
3903 {
3904 unsigned long port;
3905 int base_idx;
3906 int max_port;
3907 int offset;
3908
3909 base_idx = SPCI_FL_GET_BASE(board->flags);
3910 if (board->flags & SPCI_FL_BASE_TABLE)
3911 base_idx += idx;
3912
3913 if (board->flags & SPCI_FL_REGION_SZ_CAP) {
3914 max_port = pci_resource_len(dev, base_idx) / 8;
3915 if (idx >= max_port)
3916 return 1;
3917 }
3918
3919 offset = board->first_uart_offset;
3920
3921 /* Timedia/SUNIX uses a mixture of BARs and offsets */
3922 /* Ugh, this is ugly as all hell --- TYT */
3923 if(dev->vendor == PCI_VENDOR_ID_TIMEDIA ) /* 0x1409 */
3924 switch(idx) {
3925 case 0: base_idx=0;
3926 break;
3927 case 1: base_idx=0; offset=8;
3928 break;
3929 case 2: base_idx=1;
3930 break;
3931 case 3: base_idx=1; offset=8;
3932 break;
3933 case 4: /* BAR 2*/
3934 case 5: /* BAR 3 */
3935 case 6: /* BAR 4*/
3936 case 7: base_idx=idx-2; /* BAR 5*/
3937 }
3938
3939 /* Some Titan cards are also a little weird */
3940 if (dev->vendor == PCI_VENDOR_ID_TITAN &&
3941 (dev->device == PCI_DEVICE_ID_TITAN_400L ||
3942 dev->device == PCI_DEVICE_ID_TITAN_800L)) {
3943 switch (idx) {
3944 case 0: base_idx = 1;
3945 break;
3946 case 1: base_idx = 2;
3947 break;
3948 default:
3949 base_idx = 4;
3950 offset = 8 * (idx - 2);
3951 }
3952
3953 }
3954
3955 /* HP's Diva chip puts the 4th/5th serial port further out, and
3956 * some serial ports are supposed to be hidden on certain models.
3957 */
3958 if (dev->vendor == PCI_VENDOR_ID_HP &&
3959 dev->device == PCI_DEVICE_ID_HP_SAS) {
3960 switch (dev->subsystem_device) {
3961 case 0x104B: /* Maestro */
3962 if (idx == 3) idx++;
3963 break;
3964 case 0x1282: /* Everest / Longs Peak */
3965 if (idx > 0) idx++;
3966 if (idx > 2) idx++;
3967 break;
3968 }
3969 if (idx > 2) {
3970 offset = 0x18;
3971 }
3972 }
3973
3974 port = pci_resource_start(dev, base_idx) + offset;
3975
3976 if ((board->flags & SPCI_FL_BASE_TABLE) == 0)
3977 port += idx * (board->uart_offset ? board->uart_offset : 8);
3978
3979 if (IS_PCI_REGION_IOPORT(dev, base_idx)) {
3980 req->port = port;
3981 if (HIGH_BITS_OFFSET)
3982 req->port_high = port >> HIGH_BITS_OFFSET;
3983 else
3984 req->port_high = 0;
3985 return 0;
3986 }
3987 req->io_type = SERIAL_IO_MEM;
3988 req->iomem_base = ioremap(port, board->uart_offset);
3989 req->iomem_reg_shift = board->reg_shift;
3990 req->port = 0;
3991 return 0;
3992 }
3993
get_pci_irq(struct pci_dev * dev,struct pci_board * board,int idx)3994 static _INLINE_ int get_pci_irq(struct pci_dev *dev,
3995 struct pci_board *board,
3996 int idx)
3997 {
3998 int base_idx;
3999
4000 if ((board->flags & SPCI_FL_IRQRESOURCE) == 0)
4001 return dev->irq;
4002
4003 base_idx = SPCI_FL_GET_IRQBASE(board->flags);
4004 if (board->flags & SPCI_FL_IRQ_TABLE)
4005 base_idx += idx;
4006
4007 return PCI_IRQ_RESOURCE(dev, base_idx);
4008 }
4009
4010 /*
4011 * Common enabler code shared by both PCI and ISAPNP probes
4012 */
start_pci_pnp_board(struct pci_dev * dev,struct pci_board * board)4013 static void __devinit start_pci_pnp_board(struct pci_dev *dev,
4014 struct pci_board *board)
4015 {
4016 int k, line;
4017 struct serial_struct serial_req;
4018 int base_baud;
4019
4020 if (PREPARE_FUNC(dev) && (PREPARE_FUNC(dev))(dev) < 0) {
4021 printk("serial: PNP device '");
4022 printk_pnp_dev_id(dev->vendor, dev->device);
4023 printk("' prepare failed\n");
4024 return;
4025 }
4026
4027 if (ACTIVATE_FUNC(dev) && (ACTIVATE_FUNC(dev))(dev) < 0) {
4028 printk("serial: PNP device '");
4029 printk_pnp_dev_id(dev->vendor, dev->device);
4030 printk("' activate failed\n");
4031 return;
4032 }
4033
4034 /*
4035 * Run the initialization function, if any
4036 */
4037 if (board->init_fn && ((board->init_fn)(dev, board, 1) != 0))
4038 return;
4039
4040 /*
4041 * Register the serial board in the array if we need to
4042 * shutdown the board on a module unload or card removal
4043 */
4044 if (DEACTIVATE_FUNC(dev) || board->init_fn) {
4045 for (k=0; k < NR_PCI_BOARDS; k++)
4046 if (serial_pci_board[k].dev == 0)
4047 break;
4048 if (k >= NR_PCI_BOARDS)
4049 return;
4050 serial_pci_board[k].board = *board;
4051 serial_pci_board[k].dev = dev;
4052 }
4053
4054 base_baud = board->base_baud;
4055 if (!base_baud)
4056 base_baud = BASE_BAUD;
4057 memset(&serial_req, 0, sizeof(serial_req));
4058
4059 for (k=0; k < board->num_ports; k++) {
4060 serial_req.irq = get_pci_irq(dev, board, k);
4061 if (get_pci_port(dev, board, &serial_req, k))
4062 break;
4063 serial_req.flags = ASYNC_SKIP_TEST | ASYNC_AUTOPROBE;
4064 #ifdef SERIAL_DEBUG_PCI
4065 printk("Setup PCI/PNP port: port %x, irq %d, type %d\n",
4066 serial_req.port, serial_req.irq, serial_req.io_type);
4067 #endif
4068 line = register_serial(&serial_req);
4069 if (line < 0)
4070 break;
4071 rs_table[line].baud_base = base_baud;
4072 rs_table[line].dev = dev;
4073 }
4074 }
4075 #endif /* ENABLE_SERIAL_PCI || ENABLE_SERIAL_PNP */
4076
4077 #ifdef ENABLE_SERIAL_PCI
4078 /*
4079 * Some PCI serial cards using the PLX 9050 PCI interface chip require
4080 * that the card interrupt be explicitly enabled or disabled. This
4081 * seems to be mainly needed on card using the PLX which also use I/O
4082 * mapped memory.
4083 */
4084 static int __devinit
pci_plx9050_fn(struct pci_dev * dev,struct pci_board * board,int enable)4085 pci_plx9050_fn(struct pci_dev *dev, struct pci_board *board, int enable)
4086 {
4087 u8 data, *p, irq_config;
4088 int pci_config;
4089
4090 irq_config = 0x41;
4091 pci_config = PCI_COMMAND_MEMORY;
4092 if (dev->vendor == PCI_VENDOR_ID_PANACOM)
4093 irq_config = 0x43;
4094 if ((dev->vendor == PCI_VENDOR_ID_PLX) &&
4095 (dev->device == PCI_DEVICE_ID_PLX_ROMULUS)) {
4096 /*
4097 * As the megawolf cards have the int pins active
4098 * high, and have 2 UART chips, both ints must be
4099 * enabled on the 9050. Also, the UARTS are set in
4100 * 16450 mode by default, so we have to enable the
4101 * 16C950 'enhanced' mode so that we can use the deep
4102 * FIFOs
4103 */
4104 irq_config = 0x5b;
4105 pci_config = PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
4106 }
4107
4108 pci_read_config_byte(dev, PCI_COMMAND, &data);
4109
4110 if (enable)
4111 pci_write_config_byte(dev, PCI_COMMAND,
4112 data | pci_config);
4113
4114 /* enable/disable interrupts */
4115 p = ioremap(pci_resource_start(dev, 0), 0x80);
4116 writel(enable ? irq_config : 0x00, (unsigned long)p + 0x4c);
4117 iounmap(p);
4118
4119 if (!enable)
4120 pci_write_config_byte(dev, PCI_COMMAND,
4121 data & ~pci_config);
4122 return 0;
4123 }
4124
4125
4126 /*
4127 * SIIG serial cards have an PCI interface chip which also controls
4128 * the UART clocking frequency. Each UART can be clocked independently
4129 * (except cards equiped with 4 UARTs) and initial clocking settings
4130 * are stored in the EEPROM chip. It can cause problems because this
4131 * version of serial driver doesn't support differently clocked UART's
4132 * on single PCI card. To prevent this, initialization functions set
4133 * high frequency clocking for all UART's on given card. It is safe (I
4134 * hope) because it doesn't touch EEPROM settings to prevent conflicts
4135 * with other OSes (like M$ DOS).
4136 *
4137 * SIIG support added by Andrey Panin <pazke@mail.tp.ru>, 10/1999
4138 *
4139 * There is two family of SIIG serial cards with different PCI
4140 * interface chip and different configuration methods:
4141 * - 10x cards have control registers in IO and/or memory space;
4142 * - 20x cards have control registers in standard PCI configuration space.
4143 *
4144 * SIIG initialization functions exported for use by parport_serial.c module.
4145 */
4146
4147 #define PCI_DEVICE_ID_SIIG_1S_10x (PCI_DEVICE_ID_SIIG_1S_10x_550 & 0xfffc)
4148 #define PCI_DEVICE_ID_SIIG_2S_10x (PCI_DEVICE_ID_SIIG_2S_10x_550 & 0xfff8)
4149
4150 int __devinit
pci_siig10x_fn(struct pci_dev * dev,struct pci_board * board,int enable)4151 pci_siig10x_fn(struct pci_dev *dev, struct pci_board *board, int enable)
4152 {
4153 u16 data, *p;
4154
4155 if (!enable) return 0;
4156
4157 p = ioremap(pci_resource_start(dev, 0), 0x80);
4158
4159 switch (dev->device & 0xfff8) {
4160 case PCI_DEVICE_ID_SIIG_1S_10x: /* 1S */
4161 data = 0xffdf;
4162 break;
4163 case PCI_DEVICE_ID_SIIG_2S_10x: /* 2S, 2S1P */
4164 data = 0xf7ff;
4165 break;
4166 default: /* 1S1P, 4S */
4167 data = 0xfffb;
4168 break;
4169 }
4170
4171 writew(readw((unsigned long) p + 0x28) & data, (unsigned long) p + 0x28);
4172 iounmap(p);
4173 return 0;
4174 }
4175 EXPORT_SYMBOL(pci_siig10x_fn);
4176
4177 #define PCI_DEVICE_ID_SIIG_2S_20x (PCI_DEVICE_ID_SIIG_2S_20x_550 & 0xfffc)
4178 #define PCI_DEVICE_ID_SIIG_2S1P_20x (PCI_DEVICE_ID_SIIG_2S1P_20x_550 & 0xfffc)
4179
4180 int __devinit
pci_siig20x_fn(struct pci_dev * dev,struct pci_board * board,int enable)4181 pci_siig20x_fn(struct pci_dev *dev, struct pci_board *board, int enable)
4182 {
4183 u8 data;
4184
4185 if (!enable) return 0;
4186
4187 /* Change clock frequency for the first UART. */
4188 pci_read_config_byte(dev, 0x6f, &data);
4189 pci_write_config_byte(dev, 0x6f, data & 0xef);
4190
4191 /* If this card has 2 UART, we have to do the same with second UART. */
4192 if (((dev->device & 0xfffc) == PCI_DEVICE_ID_SIIG_2S_20x) ||
4193 ((dev->device & 0xfffc) == PCI_DEVICE_ID_SIIG_2S1P_20x)) {
4194 pci_read_config_byte(dev, 0x73, &data);
4195 pci_write_config_byte(dev, 0x73, data & 0xef);
4196 }
4197 return 0;
4198 }
4199 EXPORT_SYMBOL(pci_siig20x_fn);
4200
4201 /* Added for EKF Intel i960 serial boards */
4202 static int __devinit
pci_inteli960ni_fn(struct pci_dev * dev,struct pci_board * board,int enable)4203 pci_inteli960ni_fn(struct pci_dev *dev,
4204 struct pci_board *board,
4205 int enable)
4206 {
4207 unsigned long oldval;
4208
4209 if (!(pci_get_subdevice(dev) & 0x1000))
4210 return(-1);
4211
4212 if (!enable) /* is there something to deinit? */
4213 return(0);
4214
4215 #ifdef SERIAL_DEBUG_PCI
4216 printk(KERN_DEBUG " Subsystem ID %lx (intel 960)\n",
4217 (unsigned long) dev->subsystem_device);
4218 #endif
4219 /* is firmware started? */
4220 pci_read_config_dword(dev, 0x44, (void*) &oldval);
4221 if (oldval == 0x00001000L) { /* RESET value */
4222 printk(KERN_DEBUG "Local i960 firmware missing");
4223 return(-1);
4224 }
4225 return(0);
4226 }
4227
4228 /*
4229 * Timedia has an explosion of boards, and to avoid the PCI table from
4230 * growing *huge*, we use this function to collapse some 70 entries
4231 * in the PCI table into one, for sanity's and compactness's sake.
4232 */
4233 static unsigned short timedia_single_port[] = {
4234 0x4025, 0x4027, 0x4028, 0x5025, 0x5027, 0 };
4235 static unsigned short timedia_dual_port[] = {
4236 0x0002, 0x4036, 0x4037, 0x4038, 0x4078, 0x4079, 0x4085,
4237 0x4088, 0x4089, 0x5037, 0x5078, 0x5079, 0x5085, 0x6079,
4238 0x7079, 0x8079, 0x8137, 0x8138, 0x8237, 0x8238, 0x9079,
4239 0x9137, 0x9138, 0x9237, 0x9238, 0xA079, 0xB079, 0xC079,
4240 0xD079, 0 };
4241 static unsigned short timedia_quad_port[] = {
4242 0x4055, 0x4056, 0x4095, 0x4096, 0x5056, 0x8156, 0x8157,
4243 0x8256, 0x8257, 0x9056, 0x9156, 0x9157, 0x9158, 0x9159,
4244 0x9256, 0x9257, 0xA056, 0xA157, 0xA158, 0xA159, 0xB056,
4245 0xB157, 0 };
4246 static unsigned short timedia_eight_port[] = {
4247 0x4065, 0x4066, 0x5065, 0x5066, 0x8166, 0x9066, 0x9166,
4248 0x9167, 0x9168, 0xA066, 0xA167, 0xA168, 0 };
4249 static struct timedia_struct {
4250 int num;
4251 unsigned short *ids;
4252 } timedia_data[] = {
4253 { 1, timedia_single_port },
4254 { 2, timedia_dual_port },
4255 { 4, timedia_quad_port },
4256 { 8, timedia_eight_port },
4257 { 0, 0 }
4258 };
4259
4260 static int __devinit
pci_timedia_fn(struct pci_dev * dev,struct pci_board * board,int enable)4261 pci_timedia_fn(struct pci_dev *dev, struct pci_board *board, int enable)
4262 {
4263 int i, j;
4264 unsigned short *ids;
4265
4266 if (!enable)
4267 return 0;
4268
4269 for (i=0; timedia_data[i].num; i++) {
4270 ids = timedia_data[i].ids;
4271 for (j=0; ids[j]; j++) {
4272 if (pci_get_subdevice(dev) == ids[j]) {
4273 board->num_ports = timedia_data[i].num;
4274 return 0;
4275 }
4276 }
4277 }
4278 return 0;
4279 }
4280
4281 /*
4282 * HP's Remote Management Console. The Diva chip came in several
4283 * different versions. N-class, L2000 and A500 have two Diva chips, each
4284 * with 3 UARTs (the third UART on the second chip is unused). Superdome
4285 * and Keystone have one Diva chip with 3 UARTs. Some later machines have
4286 * one Diva chip, but it has been expanded to 5 UARTs.
4287 */
4288 static int __devinit
pci_hp_diva(struct pci_dev * dev,struct pci_board * board,int enable)4289 pci_hp_diva(struct pci_dev *dev, struct pci_board *board, int enable)
4290 {
4291 if (!enable)
4292 return 0;
4293
4294 switch (dev->subsystem_device) {
4295 case 0x1049: /* Prelude Diva 1 */
4296 case 0x1223: /* Superdome */
4297 case 0x1226: /* Keystone */
4298 case 0x1282: /* Everest / Longs Peak */
4299 board->num_ports = 3;
4300 break;
4301 case 0x104A: /* Prelude Diva 2 */
4302 board->num_ports = 2;
4303 break;
4304 case 0x104B: /* Maestro */
4305 board->num_ports = 4;
4306 break;
4307 case 0x1227: /* Powerbar */
4308 board->num_ports = 1;
4309 break;
4310 }
4311
4312 return 0;
4313 }
4314
4315 static int __devinit
pci_xircom_fn(struct pci_dev * dev,struct pci_board * board,int enable)4316 pci_xircom_fn(struct pci_dev *dev, struct pci_board *board, int enable)
4317 {
4318 __set_current_state(TASK_UNINTERRUPTIBLE);
4319 schedule_timeout(HZ/10);
4320 return 0;
4321 }
4322
4323 /*
4324 * This is the configuration table for all of the PCI serial boards
4325 * which we support. It is directly indexed by the pci_board_num_t enum
4326 * value, which is encoded in the pci_device_id PCI probe table's
4327 * driver_data member.
4328 */
4329 enum pci_board_num_t {
4330 pbn_b0_1_115200,
4331 pbn_default = 0,
4332
4333 pbn_b0_2_115200,
4334 pbn_b0_4_115200,
4335
4336 pbn_b0_1_921600,
4337 pbn_b0_2_921600,
4338 pbn_b0_4_921600,
4339
4340 pbn_b0_bt_1_115200,
4341 pbn_b0_bt_2_115200,
4342 pbn_b0_bt_1_460800,
4343 pbn_b0_bt_2_460800,
4344 pbn_b0_bt_2_921600,
4345
4346 pbn_b1_1_115200,
4347 pbn_b1_2_115200,
4348 pbn_b1_4_115200,
4349 pbn_b1_8_115200,
4350
4351 pbn_b1_2_921600,
4352 pbn_b1_4_921600,
4353 pbn_b1_8_921600,
4354
4355 pbn_b1_2_1382400,
4356 pbn_b1_4_1382400,
4357 pbn_b1_8_1382400,
4358
4359 pbn_b2_1_115200,
4360 pbn_b2_8_115200,
4361 pbn_b2_4_460800,
4362 pbn_b2_8_460800,
4363 pbn_b2_16_460800,
4364 pbn_b2_4_921600,
4365 pbn_b2_8_921600,
4366
4367 pbn_b2_bt_1_115200,
4368 pbn_b2_bt_2_115200,
4369 pbn_b2_bt_4_115200,
4370 pbn_b2_bt_2_921600,
4371
4372 pbn_panacom,
4373 pbn_panacom2,
4374 pbn_panacom4,
4375 pbn_plx_romulus,
4376 pbn_oxsemi,
4377 pbn_timedia,
4378 pbn_intel_i960,
4379 pbn_sgi_ioc3,
4380 pbn_hp_diva,
4381 #ifdef CONFIG_DDB5074
4382 pbn_nec_nile4,
4383 #endif
4384
4385 pbn_dci_pccom4,
4386 pbn_dci_pccom8,
4387
4388 pbn_xircom_combo,
4389
4390 pbn_siig10x_0,
4391 pbn_siig10x_1,
4392 pbn_siig10x_2,
4393 pbn_siig10x_4,
4394 pbn_siig20x_0,
4395 pbn_siig20x_2,
4396 pbn_siig20x_4,
4397
4398 pbn_computone_4,
4399 pbn_computone_6,
4400 pbn_computone_8,
4401 };
4402
4403 static struct pci_board pci_boards[] __devinitdata = {
4404 /*
4405 * PCI Flags, Number of Ports, Base (Maximum) Baud Rate,
4406 * Offset to get to next UART's registers,
4407 * Register shift to use for memory-mapped I/O,
4408 * Initialization function, first UART offset
4409 */
4410
4411 /* Generic serial board, pbn_b0_1_115200, pbn_default */
4412 { SPCI_FL_BASE0, 1, 115200 }, /* pbn_b0_1_115200,
4413 pbn_default */
4414
4415 { SPCI_FL_BASE0, 2, 115200 }, /* pbn_b0_2_115200 */
4416 { SPCI_FL_BASE0, 4, 115200 }, /* pbn_b0_4_115200 */
4417
4418 { SPCI_FL_BASE0, 1, 921600 }, /* pbn_b0_1_921600 */
4419 { SPCI_FL_BASE0, 2, 921600 }, /* pbn_b0_2_921600 */
4420 { SPCI_FL_BASE0, 4, 921600 }, /* pbn_b0_4_921600 */
4421
4422 { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, /* pbn_b0_bt_1_115200 */
4423 { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 }, /* pbn_b0_bt_2_115200 */
4424 { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 460800 }, /* pbn_b0_bt_1_460800 */
4425 { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 460800 }, /* pbn_b0_bt_2_460800 */
4426 { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 921600 }, /* pbn_b0_bt_2_921600 */
4427
4428 { SPCI_FL_BASE1, 1, 115200 }, /* pbn_b1_1_115200 */
4429 { SPCI_FL_BASE1, 2, 115200 }, /* pbn_b1_2_115200 */
4430 { SPCI_FL_BASE1, 4, 115200 }, /* pbn_b1_4_115200 */
4431 { SPCI_FL_BASE1, 8, 115200 }, /* pbn_b1_8_115200 */
4432
4433 { SPCI_FL_BASE1, 2, 921600 }, /* pbn_b1_2_921600 */
4434 { SPCI_FL_BASE1, 4, 921600 }, /* pbn_b1_4_921600 */
4435 { SPCI_FL_BASE1, 8, 921600 }, /* pbn_b1_8_921600 */
4436
4437 { SPCI_FL_BASE1, 2, 1382400 }, /* pbn_b1_2_1382400 */
4438 { SPCI_FL_BASE1, 4, 1382400 }, /* pbn_b1_4_1382400 */
4439 { SPCI_FL_BASE1, 8, 1382400 }, /* pbn_b1_8_1382400 */
4440
4441 { SPCI_FL_BASE2, 1, 115200 }, /* pbn_b2_1_115200 */
4442 { SPCI_FL_BASE2, 8, 115200 }, /* pbn_b2_8_115200 */
4443 { SPCI_FL_BASE2, 4, 460800 }, /* pbn_b2_4_460800 */
4444 { SPCI_FL_BASE2, 8, 460800 }, /* pbn_b2_8_460800 */
4445 { SPCI_FL_BASE2, 16, 460800 }, /* pbn_b2_16_460800 */
4446 { SPCI_FL_BASE2, 4, 921600 }, /* pbn_b2_4_921600 */
4447 { SPCI_FL_BASE2, 8, 921600 }, /* pbn_b2_8_921600 */
4448
4449 { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 1, 115200 }, /* pbn_b2_bt_1_115200 */
4450 { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 115200 }, /* pbn_b2_bt_2_115200 */
4451 { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 115200 }, /* pbn_b2_bt_4_115200 */
4452 { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600 }, /* pbn_b2_bt_2_921600 */
4453
4454 { SPCI_FL_BASE2, 2, 921600, /* IOMEM */ /* pbn_panacom */
4455 0x400, 7, pci_plx9050_fn },
4456 { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600, /* pbn_panacom2 */
4457 0x400, 7, pci_plx9050_fn },
4458 { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 921600, /* pbn_panacom4 */
4459 0x400, 7, pci_plx9050_fn },
4460 { SPCI_FL_BASE2, 4, 921600, /* pbn_plx_romulus */
4461 0x20, 2, pci_plx9050_fn, 0x03 },
4462 /* This board uses the size of PCI Base region 0 to
4463 * signal now many ports are available */
4464 { SPCI_FL_BASE0 | SPCI_FL_REGION_SZ_CAP, 32, 115200 }, /* pbn_oxsemi */
4465 { SPCI_FL_BASE_TABLE, 1, 921600, /* pbn_timedia */
4466 0, 0, pci_timedia_fn },
4467 /* EKF addition for i960 Boards form EKF with serial port */
4468 { SPCI_FL_BASE0, 32, 921600, /* max 256 ports */ /* pbn_intel_i960 */
4469 8<<2, 2, pci_inteli960ni_fn, 0x10000},
4470 { SPCI_FL_BASE0 | SPCI_FL_IRQRESOURCE, /* pbn_sgi_ioc3 */
4471 1, 458333, 0, 0, 0, 0x20178 },
4472 { SPCI_FL_BASE0, 5, 115200, 8, 0, pci_hp_diva, 0}, /* pbn_hp_diva */
4473 #ifdef CONFIG_DDB5074
4474 /*
4475 * NEC Vrc-5074 (Nile 4) builtin UART.
4476 * Conditionally compiled in since this is a motherboard device.
4477 */
4478 { SPCI_FL_BASE0, 1, 520833, /* pbn_nec_nile4 */
4479 64, 3, NULL, 0x300 },
4480 #endif
4481
4482 {SPCI_FL_BASE3, 4, 115200, 8}, /* pbn_dci_pccom4 */
4483 {SPCI_FL_BASE3, 8, 115200, 8}, /* pbn_dci_pccom8 */
4484
4485 { SPCI_FL_BASE0, 1, 115200, /* pbn_xircom_combo */
4486 0, 0, pci_xircom_fn },
4487
4488 { SPCI_FL_BASE2, 1, 460800, /* pbn_siig10x_0 */
4489 0, 0, pci_siig10x_fn },
4490 { SPCI_FL_BASE2, 1, 921600, /* pbn_siig10x_1 */
4491 0, 0, pci_siig10x_fn },
4492 { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600, /* pbn_siig10x_2 */
4493 0, 0, pci_siig10x_fn },
4494 { SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 921600, /* pbn_siig10x_4 */
4495 0, 0, pci_siig10x_fn },
4496 { SPCI_FL_BASE0, 1, 921600, /* pbn_siix20x_0 */
4497 0, 0, pci_siig20x_fn },
4498 { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 921600, /* pbn_siix20x_2 */
4499 0, 0, pci_siig20x_fn },
4500 { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 4, 921600, /* pbn_siix20x_4 */
4501 0, 0, pci_siig20x_fn },
4502
4503 { SPCI_FL_BASE0, 4, 921600, /* IOMEM */ /* pbn_computone_4 */
4504 0x40, 2, NULL, 0x200 },
4505 { SPCI_FL_BASE0, 6, 921600, /* IOMEM */ /* pbn_computone_6 */
4506 0x40, 2, NULL, 0x200 },
4507 { SPCI_FL_BASE0, 8, 921600, /* IOMEM */ /* pbn_computone_8 */
4508 0x40, 2, NULL, 0x200 },
4509 };
4510
4511 /*
4512 * Given a complete unknown PCI device, try to use some heuristics to
4513 * guess what the configuration might be, based on the pitiful PCI
4514 * serial specs. Returns 0 on success, 1 on failure.
4515 */
serial_pci_guess_board(struct pci_dev * dev,struct pci_board * board)4516 static int __devinit serial_pci_guess_board(struct pci_dev *dev,
4517 struct pci_board *board)
4518 {
4519 int num_iomem = 0, num_port = 0, first_port = -1;
4520 int i;
4521
4522 /*
4523 * If it is not a communications device or the programming
4524 * interface is greater than 6, give up.
4525 *
4526 * (Should we try to make guesses for multiport serial devices
4527 * later?)
4528 */
4529 if ((((dev->class >> 8) != PCI_CLASS_COMMUNICATION_SERIAL) &&
4530 ((dev->class >> 8) != PCI_CLASS_COMMUNICATION_MODEM)) ||
4531 (dev->class & 0xff) > 6)
4532 return 1;
4533
4534 for (i=0; i < 6; i++) {
4535 if (IS_PCI_REGION_IOPORT(dev, i)) {
4536 num_port++;
4537 if (first_port == -1)
4538 first_port = i;
4539 }
4540 if (IS_PCI_REGION_IOMEM(dev, i))
4541 num_iomem++;
4542 }
4543
4544 /*
4545 * If there is 1 or 0 iomem regions, and exactly one port, use
4546 * it.
4547 */
4548 if (num_iomem <= 1 && num_port == 1) {
4549 board->flags = first_port;
4550 return 0;
4551 }
4552 return 1;
4553 }
4554
serial_init_one(struct pci_dev * dev,const struct pci_device_id * ent)4555 static int __devinit serial_init_one(struct pci_dev *dev,
4556 const struct pci_device_id *ent)
4557 {
4558 struct pci_board *board, tmp;
4559 int rc;
4560
4561 board = &pci_boards[ent->driver_data];
4562
4563 rc = pci_enable_device(dev);
4564 if (rc) return rc;
4565
4566 if (ent->driver_data == pbn_default &&
4567 serial_pci_guess_board(dev, board))
4568 return -ENODEV;
4569 else if (serial_pci_guess_board(dev, &tmp) == 0) {
4570 printk(KERN_INFO "Redundant entry in serial pci_table. "
4571 "Please send the output of\n"
4572 "lspci -vv, this message (%04x,%04x,%04x,%04x)\n"
4573 "and the manufacturer and name of "
4574 "serial board or modem board\n"
4575 "to serial-pci-info@lists.sourceforge.net.\n",
4576 dev->vendor, dev->device,
4577 pci_get_subvendor(dev), pci_get_subdevice(dev));
4578 }
4579
4580 start_pci_pnp_board(dev, board);
4581
4582 return 0;
4583 }
4584
serial_remove_one(struct pci_dev * dev)4585 static void __devexit serial_remove_one(struct pci_dev *dev)
4586 {
4587 int i;
4588
4589 /*
4590 * Iterate through all of the ports finding those that belong
4591 * to this PCI device.
4592 */
4593 for(i = 0; i < NR_PORTS; i++) {
4594 if (rs_table[i].dev != dev)
4595 continue;
4596 unregister_serial(i);
4597 rs_table[i].dev = 0;
4598 }
4599 /*
4600 * Now execute any board-specific shutdown procedure
4601 */
4602 for (i=0; i < NR_PCI_BOARDS; i++) {
4603 struct pci_board_inst *brd = &serial_pci_board[i];
4604
4605 if (serial_pci_board[i].dev != dev)
4606 continue;
4607 if (brd->board.init_fn)
4608 (brd->board.init_fn)(brd->dev, &brd->board, 0);
4609 if (DEACTIVATE_FUNC(brd->dev))
4610 (DEACTIVATE_FUNC(brd->dev))(brd->dev);
4611 serial_pci_board[i].dev = 0;
4612 }
4613 }
4614
4615
4616 static struct pci_device_id serial_pci_tbl[] __devinitdata = {
4617 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4618 PCI_SUBVENDOR_ID_CONNECT_TECH,
4619 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232, 0, 0,
4620 pbn_b1_8_1382400 },
4621 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4622 PCI_SUBVENDOR_ID_CONNECT_TECH,
4623 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232, 0, 0,
4624 pbn_b1_4_1382400 },
4625 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4626 PCI_SUBVENDOR_ID_CONNECT_TECH,
4627 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232, 0, 0,
4628 pbn_b1_2_1382400 },
4629 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4630 PCI_SUBVENDOR_ID_CONNECT_TECH,
4631 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232, 0, 0,
4632 pbn_b1_8_1382400 },
4633 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4634 PCI_SUBVENDOR_ID_CONNECT_TECH,
4635 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232, 0, 0,
4636 pbn_b1_4_1382400 },
4637 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4638 PCI_SUBVENDOR_ID_CONNECT_TECH,
4639 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232, 0, 0,
4640 pbn_b1_2_1382400 },
4641 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4642 PCI_SUBVENDOR_ID_CONNECT_TECH,
4643 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485, 0, 0,
4644 pbn_b1_8_921600 },
4645 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4646 PCI_SUBVENDOR_ID_CONNECT_TECH,
4647 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_4_4, 0, 0,
4648 pbn_b1_8_921600 },
4649 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4650 PCI_SUBVENDOR_ID_CONNECT_TECH,
4651 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485, 0, 0,
4652 pbn_b1_4_921600 },
4653 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4654 PCI_SUBVENDOR_ID_CONNECT_TECH,
4655 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485_2_2, 0, 0,
4656 pbn_b1_4_921600 },
4657 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4658 PCI_SUBVENDOR_ID_CONNECT_TECH,
4659 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_485, 0, 0,
4660 pbn_b1_2_921600 },
4661 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4662 PCI_SUBVENDOR_ID_CONNECT_TECH,
4663 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_2_6, 0, 0,
4664 pbn_b1_8_921600 },
4665 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4666 PCI_SUBVENDOR_ID_CONNECT_TECH,
4667 PCI_SUBDEVICE_ID_CONNECT_TECH_BH081101V1, 0, 0,
4668 pbn_b1_8_921600 },
4669 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
4670 PCI_SUBVENDOR_ID_CONNECT_TECH,
4671 PCI_SUBDEVICE_ID_CONNECT_TECH_BH041101V1, 0, 0,
4672 pbn_b1_4_921600 },
4673
4674 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_U530,
4675 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4676 pbn_b2_bt_1_115200 },
4677 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM2,
4678 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4679 pbn_b2_bt_2_115200 },
4680 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM422,
4681 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4682 pbn_b2_bt_4_115200 },
4683 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM232,
4684 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4685 pbn_b2_bt_2_115200 },
4686 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM4,
4687 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4688 pbn_b2_bt_4_115200 },
4689 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM8,
4690 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4691 pbn_b2_8_115200 },
4692
4693 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_GTEK_SERIAL2,
4694 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4695 pbn_b2_bt_2_115200 },
4696 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_SPCOM200,
4697 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4698 pbn_b2_bt_2_921600 },
4699 /* VScom SPCOM800, from sl@s.pl */
4700 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_SPCOM800,
4701 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4702 pbn_b2_8_921600 },
4703 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_1077,
4704 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4705 pbn_b2_4_921600 },
4706 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4707 PCI_SUBVENDOR_ID_KEYSPAN,
4708 PCI_SUBDEVICE_ID_KEYSPAN_SX2, 0, 0,
4709 pbn_panacom },
4710 { PCI_VENDOR_ID_PANACOM, PCI_DEVICE_ID_PANACOM_QUADMODEM,
4711 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4712 pbn_panacom4 },
4713 { PCI_VENDOR_ID_PANACOM, PCI_DEVICE_ID_PANACOM_DUALMODEM,
4714 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4715 pbn_panacom2 },
4716 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4717 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
4718 PCI_SUBDEVICE_ID_CHASE_PCIFAST4, 0, 0,
4719 pbn_b2_4_460800 },
4720 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4721 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
4722 PCI_SUBDEVICE_ID_CHASE_PCIFAST8, 0, 0,
4723 pbn_b2_8_460800 },
4724 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4725 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
4726 PCI_SUBDEVICE_ID_CHASE_PCIFAST16, 0, 0,
4727 pbn_b2_16_460800 },
4728 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4729 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
4730 PCI_SUBDEVICE_ID_CHASE_PCIFAST16FMC, 0, 0,
4731 pbn_b2_16_460800 },
4732 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4733 PCI_SUBVENDOR_ID_CHASE_PCIRAS,
4734 PCI_SUBDEVICE_ID_CHASE_PCIRAS4, 0, 0,
4735 pbn_b2_4_460800 },
4736 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4737 PCI_SUBVENDOR_ID_CHASE_PCIRAS,
4738 PCI_SUBDEVICE_ID_CHASE_PCIRAS8, 0, 0,
4739 pbn_b2_8_460800 },
4740 /* Megawolf Romulus PCI Serial Card, from Mike Hudson */
4741 /* (Exoray@isys.ca) */
4742 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_ROMULUS,
4743 0x10b5, 0x106a, 0, 0,
4744 pbn_plx_romulus },
4745 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_QSC100,
4746 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4747 pbn_b1_4_115200 },
4748 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_DSC100,
4749 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4750 pbn_b1_2_115200 },
4751 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_ESC100D,
4752 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4753 pbn_b1_8_115200 },
4754 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_ESC100M,
4755 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4756 pbn_b1_8_115200 },
4757 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_OXSEMI_16PCI954,
4758 PCI_VENDOR_ID_SPECIALIX, PCI_SUBDEVICE_ID_SPECIALIX_SPEED4, 0, 0,
4759 pbn_b0_4_921600 },
4760 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
4761 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4762 pbn_b0_4_115200 },
4763 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952,
4764 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4765 pbn_b0_bt_2_921600 },
4766
4767 /* Digitan DS560-558, from jimd@esoft.com */
4768 { PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_ATT_VENUS_MODEM,
4769 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4770 pbn_b1_1_115200 },
4771
4772 /* 3Com US Robotics 56k Voice Internal PCI model 5610 */
4773 { PCI_VENDOR_ID_USR, 0x1008,
4774 PCI_ANY_ID, PCI_ANY_ID, },
4775
4776 /* Titan Electronic cards */
4777 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_100,
4778 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4779 pbn_b0_1_921600 },
4780 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200,
4781 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4782 pbn_b0_2_921600 },
4783 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400,
4784 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4785 pbn_b0_4_921600 },
4786 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800B,
4787 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4788 pbn_b0_4_921600 },
4789 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_100L,
4790 PCI_ANY_ID, PCI_ANY_ID,
4791 SPCI_FL_BASE1, 1, 921600 },
4792 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200L,
4793 PCI_ANY_ID, PCI_ANY_ID,
4794 SPCI_FL_BASE1 | SPCI_FL_BASE_TABLE, 2, 921600 },
4795 /* The 400L and 800L have a custom hack in get_pci_port */
4796 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400L,
4797 PCI_ANY_ID, PCI_ANY_ID,
4798 SPCI_FL_BASE_TABLE, 4, 921600 },
4799 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800L,
4800 PCI_ANY_ID, PCI_ANY_ID,
4801 SPCI_FL_BASE_TABLE, 8, 921600 },
4802
4803 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_550,
4804 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4805 pbn_siig10x_0 },
4806 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_650,
4807 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4808 pbn_siig10x_0 },
4809 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_850,
4810 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4811 pbn_siig10x_0 },
4812 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_550,
4813 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4814 pbn_siig10x_2 },
4815 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_650,
4816 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4817 pbn_siig10x_2 },
4818 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_850,
4819 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4820 pbn_siig10x_2 },
4821 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_550,
4822 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4823 pbn_siig10x_4 },
4824 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_650,
4825 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4826 pbn_siig10x_4 },
4827 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_850,
4828 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4829 pbn_siig10x_4 },
4830 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_550,
4831 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4832 pbn_siig20x_0 },
4833 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_650,
4834 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4835 pbn_siig20x_0 },
4836 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_850,
4837 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4838 pbn_siig20x_0 },
4839 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_550,
4840 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4841 pbn_siig20x_2 },
4842 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_650,
4843 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4844 pbn_siig20x_2 },
4845 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_850,
4846 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4847 pbn_siig20x_2 },
4848 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_550,
4849 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4850 pbn_siig20x_4 },
4851 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_650,
4852 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4853 pbn_siig20x_4 },
4854 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_850,
4855 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4856 pbn_siig20x_4 },
4857
4858 /* Computone devices submitted by Doug McNash dmcnash@computone.com */
4859 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
4860 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG4,
4861 0, 0, pbn_computone_4 },
4862 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
4863 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG8,
4864 0, 0, pbn_computone_8 },
4865 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
4866 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG6,
4867 0, 0, pbn_computone_6 },
4868
4869 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI95N,
4870 PCI_ANY_ID, PCI_ANY_ID, 0, 0, pbn_oxsemi },
4871 { PCI_VENDOR_ID_TIMEDIA, PCI_DEVICE_ID_TIMEDIA_1889,
4872 PCI_VENDOR_ID_TIMEDIA, PCI_ANY_ID, 0, 0, pbn_timedia },
4873
4874 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DSERIAL,
4875 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4876 pbn_b0_bt_2_115200 },
4877 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUATRO_A,
4878 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4879 pbn_b0_bt_2_115200 },
4880 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUATRO_B,
4881 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4882 pbn_b0_bt_2_115200 },
4883 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PORT_PLUS,
4884 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4885 pbn_b0_bt_2_460800 },
4886 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUAD_A,
4887 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4888 pbn_b0_bt_2_460800 },
4889 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUAD_B,
4890 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4891 pbn_b0_bt_2_460800 },
4892 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_SSERIAL,
4893 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4894 pbn_b0_bt_1_115200 },
4895 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PORT_650,
4896 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4897 pbn_b0_bt_1_460800 },
4898
4899 /* RAStel 2 port modem, gerg@moreton.com.au */
4900 { PCI_VENDOR_ID_MORETON, PCI_DEVICE_ID_RASTEL_2PORT,
4901 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4902 pbn_b2_bt_2_115200 },
4903
4904 /* EKF addition for i960 Boards form EKF with serial port */
4905 { PCI_VENDOR_ID_INTEL, 0x1960,
4906 0xE4BF, PCI_ANY_ID, 0, 0,
4907 pbn_intel_i960 },
4908
4909 /* Xircom Cardbus/Ethernet combos */
4910 { PCI_VENDOR_ID_XIRCOM, PCI_DEVICE_ID_XIRCOM_X3201_MDM,
4911 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4912 pbn_xircom_combo },
4913
4914 /*
4915 * Untested PCI modems, sent in from various folks...
4916 */
4917
4918 /* Elsa Model 56K PCI Modem, from Andreas Rath <arh@01019freenet.de> */
4919 { PCI_VENDOR_ID_ROCKWELL, 0x1004,
4920 0x1048, 0x1500, 0, 0,
4921 pbn_b1_1_115200 },
4922
4923 { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3,
4924 0xFF00, 0, 0, 0,
4925 pbn_sgi_ioc3 },
4926
4927 /* HP Diva card */
4928 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_SAS,
4929 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4930 pbn_hp_diva },
4931 { PCI_VENDOR_ID_HP, 0x1290,
4932 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4933 pbn_b2_1_115200 },
4934
4935 #ifdef CONFIG_DDB5074
4936 /*
4937 * NEC Vrc-5074 (Nile 4) builtin UART.
4938 * Conditionally compiled in since this is a motherboard device.
4939 */
4940 { PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_NILE4,
4941 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4942 pbn_nec_nile4 },
4943 #endif
4944
4945 { PCI_VENDOR_ID_DCI, PCI_DEVICE_ID_DCI_PCCOM4,
4946 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4947 pbn_dci_pccom4 },
4948 { PCI_VENDOR_ID_DCI, PCI_DEVICE_ID_DCI_PCCOM8,
4949 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4950 pbn_dci_pccom8 },
4951
4952 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
4953 PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xffff00, },
4954 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
4955 PCI_CLASS_COMMUNICATION_MODEM << 8, 0xffff00, },
4956 { 0, }
4957 };
4958
4959 MODULE_DEVICE_TABLE(pci, serial_pci_tbl);
4960
4961 static struct pci_driver serial_pci_driver = {
4962 name: "serial",
4963 probe: serial_init_one,
4964 remove: __devexit_p(serial_remove_one),
4965 id_table: serial_pci_tbl,
4966 };
4967
4968
4969 /*
4970 * Query PCI space for known serial boards
4971 * If found, add them to the PCI device space in rs_table[]
4972 *
4973 * Accept a maximum of eight boards
4974 *
4975 */
probe_serial_pci(void)4976 static void __devinit probe_serial_pci(void)
4977 {
4978 #ifdef SERIAL_DEBUG_PCI
4979 printk(KERN_DEBUG "Entered probe_serial_pci()\n");
4980 #endif
4981
4982 /* Register call PCI serial devices. Null out
4983 * the driver name upon failure, as a signal
4984 * not to attempt to unregister the driver later
4985 */
4986 if (pci_module_init (&serial_pci_driver) != 0)
4987 serial_pci_driver.name = "";
4988
4989 #ifdef SERIAL_DEBUG_PCI
4990 printk(KERN_DEBUG "Leaving probe_serial_pci() (probe finished)\n");
4991 #endif
4992 return;
4993 }
4994
4995 #endif /* ENABLE_SERIAL_PCI */
4996
4997 #ifdef ENABLE_SERIAL_PNP
4998
4999 struct pnp_board {
5000 unsigned short vendor;
5001 unsigned short device;
5002 };
5003
5004 static struct pnp_board pnp_devices[] __devinitdata = {
5005 /* Archtek America Corp. */
5006 /* Archtek SmartLink Modem 3334BT Plug & Play */
5007 { ISAPNP_VENDOR('A', 'A', 'C'), ISAPNP_DEVICE(0x000F) },
5008 /* Anchor Datacomm BV */
5009 /* SXPro 144 External Data Fax Modem Plug & Play */
5010 { ISAPNP_VENDOR('A', 'D', 'C'), ISAPNP_DEVICE(0x0001) },
5011 /* SXPro 288 External Data Fax Modem Plug & Play */
5012 { ISAPNP_VENDOR('A', 'D', 'C'), ISAPNP_DEVICE(0x0002) },
5013 /* Rockwell 56K ACF II Fax+Data+Voice Modem */
5014 { ISAPNP_VENDOR('A', 'K', 'Y'), ISAPNP_DEVICE(0x1021) },
5015 /* AZT3005 PnP SOUND DEVICE */
5016 { ISAPNP_VENDOR('A', 'Z', 'T'), ISAPNP_DEVICE(0x4001) },
5017 /* Best Data Products Inc. Smart One 336F PnP Modem */
5018 { ISAPNP_VENDOR('B', 'D', 'P'), ISAPNP_DEVICE(0x3336) },
5019 /* Boca Research */
5020 /* Boca Complete Ofc Communicator 14.4 Data-FAX */
5021 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x0A49) },
5022 /* Boca Research 33,600 ACF Modem */
5023 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x1400) },
5024 /* Boca 33.6 Kbps Internal FD34FSVD */
5025 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x3400) },
5026 /* Boca 33.6 Kbps Internal FD34FSVD */
5027 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x0A49) },
5028 /* Best Data Products Inc. Smart One 336F PnP Modem */
5029 { ISAPNP_VENDOR('B', 'D', 'P'), ISAPNP_DEVICE(0x3336) },
5030 /* Computer Peripherals Inc */
5031 /* EuroViVa CommCenter-33.6 SP PnP */
5032 { ISAPNP_VENDOR('C', 'P', 'I'), ISAPNP_DEVICE(0x4050) },
5033 /* Creative Labs */
5034 /* Creative Labs Phone Blaster 28.8 DSVD PnP Voice */
5035 { ISAPNP_VENDOR('C', 'T', 'L'), ISAPNP_DEVICE(0x3001) },
5036 /* Creative Labs Modem Blaster 28.8 DSVD PnP Voice */
5037 { ISAPNP_VENDOR('C', 'T', 'L'), ISAPNP_DEVICE(0x3011) },
5038 /* Creative */
5039 /* Creative Modem Blaster Flash56 DI5601-1 */
5040 { ISAPNP_VENDOR('D', 'M', 'B'), ISAPNP_DEVICE(0x1032) },
5041 /* Creative Modem Blaster V.90 DI5660 */
5042 { ISAPNP_VENDOR('D', 'M', 'B'), ISAPNP_DEVICE(0x2001) },
5043 /* FUJITSU */
5044 /* Fujitsu 33600 PnP-I2 R Plug & Play */
5045 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0202) },
5046 /* Fujitsu FMV-FX431 Plug & Play */
5047 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0205) },
5048 /* Fujitsu 33600 PnP-I4 R Plug & Play */
5049 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0206) },
5050 /* Fujitsu Fax Voice 33600 PNP-I5 R Plug & Play */
5051 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0209) },
5052 /* Archtek America Corp. */
5053 /* Archtek SmartLink Modem 3334BT Plug & Play */
5054 { ISAPNP_VENDOR('G', 'V', 'C'), ISAPNP_DEVICE(0x000F) },
5055 /* Hayes */
5056 /* Hayes Optima 288 V.34-V.FC + FAX + Voice Plug & Play */
5057 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x0001) },
5058 /* Hayes Optima 336 V.34 + FAX + Voice PnP */
5059 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x000C) },
5060 /* Hayes Optima 336B V.34 + FAX + Voice PnP */
5061 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x000D) },
5062 /* Hayes Accura 56K Ext Fax Modem PnP */
5063 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5670) },
5064 /* Hayes Accura 56K Ext Fax Modem PnP */
5065 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5674) },
5066 /* Hayes Accura 56K Fax Modem PnP */
5067 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5675) },
5068 /* Hayes 288, V.34 + FAX */
5069 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0xF000) },
5070 /* Hayes Optima 288 V.34 + FAX + Voice, Plug & Play */
5071 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0xF001) },
5072 /* IBM */
5073 /* IBM Thinkpad 701 Internal Modem Voice */
5074 { ISAPNP_VENDOR('I', 'B', 'M'), ISAPNP_DEVICE(0x0033) },
5075 /* Intertex */
5076 /* Intertex 28k8 33k6 Voice EXT PnP */
5077 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xC801) },
5078 /* Intertex 33k6 56k Voice EXT PnP */
5079 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xC901) },
5080 /* Intertex 28k8 33k6 Voice SP EXT PnP */
5081 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xD801) },
5082 /* Intertex 33k6 56k Voice SP EXT PnP */
5083 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xD901) },
5084 /* Intertex 28k8 33k6 Voice SP INT PnP */
5085 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF401) },
5086 /* Intertex 28k8 33k6 Voice SP EXT PnP */
5087 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF801) },
5088 /* Intertex 33k6 56k Voice SP EXT PnP */
5089 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF901) },
5090 /* Kortex International */
5091 /* KORTEX 28800 Externe PnP */
5092 { ISAPNP_VENDOR('K', 'O', 'R'), ISAPNP_DEVICE(0x4522) },
5093 /* KXPro 33.6 Vocal ASVD PnP */
5094 { ISAPNP_VENDOR('K', 'O', 'R'), ISAPNP_DEVICE(0xF661) },
5095 /* Lasat */
5096 /* LASAT Internet 33600 PnP */
5097 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x4040) },
5098 /* Lasat Safire 560 PnP */
5099 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x4540) },
5100 /* Lasat Safire 336 PnP */
5101 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x5440) },
5102 /* Microcom, Inc. */
5103 /* Microcom TravelPorte FAST V.34 Plug & Play */
5104 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x281) },
5105 /* Microcom DeskPorte V.34 FAST or FAST+ Plug & Play */
5106 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0336) },
5107 /* Microcom DeskPorte FAST EP 28.8 Plug & Play */
5108 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0339) },
5109 /* Microcom DeskPorte 28.8P Plug & Play */
5110 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0342) },
5111 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
5112 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0500) },
5113 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
5114 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0501) },
5115 /* Microcom DeskPorte 28.8S Internal Plug & Play */
5116 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0502) },
5117 /* Motorola */
5118 /* Motorola BitSURFR Plug & Play */
5119 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1105) },
5120 /* Motorola TA210 Plug & Play */
5121 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1111) },
5122 /* Motorola HMTA 200 (ISDN) Plug & Play */
5123 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1114) },
5124 /* Motorola BitSURFR Plug & Play */
5125 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1115) },
5126 /* Motorola Lifestyle 28.8 Internal */
5127 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1190) },
5128 /* Motorola V.3400 Plug & Play */
5129 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1501) },
5130 /* Motorola Lifestyle 28.8 V.34 Plug & Play */
5131 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1502) },
5132 /* Motorola Power 28.8 V.34 Plug & Play */
5133 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1505) },
5134 /* Motorola ModemSURFR External 28.8 Plug & Play */
5135 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1509) },
5136 /* Motorola Premier 33.6 Desktop Plug & Play */
5137 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x150A) },
5138 /* Motorola VoiceSURFR 56K External PnP */
5139 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x150F) },
5140 /* Motorola ModemSURFR 56K External PnP */
5141 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1510) },
5142 /* Motorola ModemSURFR 56K Internal PnP */
5143 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1550) },
5144 /* Motorola ModemSURFR Internal 28.8 Plug & Play */
5145 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1560) },
5146 /* Motorola Premier 33.6 Internal Plug & Play */
5147 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1580) },
5148 /* Motorola OnlineSURFR 28.8 Internal Plug & Play */
5149 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x15B0) },
5150 /* Motorola VoiceSURFR 56K Internal PnP */
5151 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x15F0) },
5152 /* Com 1 */
5153 /* Deskline K56 Phone System PnP */
5154 { ISAPNP_VENDOR('M', 'V', 'X'), ISAPNP_DEVICE(0x00A1) },
5155 /* PC Rider K56 Phone System PnP */
5156 { ISAPNP_VENDOR('M', 'V', 'X'), ISAPNP_DEVICE(0x00F2) },
5157 /* Pace 56 Voice Internal Plug & Play Modem */
5158 { ISAPNP_VENDOR('P', 'M', 'C'), ISAPNP_DEVICE(0x2430) },
5159 /* Generic */
5160 /* Generic standard PC COM port */
5161 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x0500) },
5162 /* Generic 16550A-compatible COM port */
5163 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x0501) },
5164 /* Compaq 14400 Modem */
5165 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC000) },
5166 /* Compaq 2400/9600 Modem */
5167 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC001) },
5168 /* Dial-Up Networking Serial Cable between 2 PCs */
5169 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC031) },
5170 /* Dial-Up Networking Parallel Cable between 2 PCs */
5171 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC032) },
5172 /* Standard 9600 bps Modem */
5173 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC100) },
5174 /* Standard 14400 bps Modem */
5175 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC101) },
5176 /* Standard 28800 bps Modem*/
5177 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC102) },
5178 /* Standard Modem*/
5179 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC103) },
5180 /* Standard 9600 bps Modem*/
5181 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC104) },
5182 /* Standard 14400 bps Modem*/
5183 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC105) },
5184 /* Standard 28800 bps Modem*/
5185 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC106) },
5186 /* Standard Modem */
5187 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC107) },
5188 /* Standard 9600 bps Modem */
5189 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC108) },
5190 /* Standard 14400 bps Modem */
5191 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC109) },
5192 /* Standard 28800 bps Modem */
5193 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10A) },
5194 /* Standard Modem */
5195 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10B) },
5196 /* Standard 9600 bps Modem */
5197 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10C) },
5198 /* Standard 14400 bps Modem */
5199 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10D) },
5200 /* Standard 28800 bps Modem */
5201 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10E) },
5202 /* Standard Modem */
5203 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10F) },
5204 /* Standard PCMCIA Card Modem */
5205 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x2000) },
5206 /* Rockwell */
5207 /* Modular Technology */
5208 /* Rockwell 33.6 DPF Internal PnP */
5209 /* Modular Technology 33.6 Internal PnP */
5210 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x0030) },
5211 /* Kortex International */
5212 /* KORTEX 14400 Externe PnP */
5213 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x0100) },
5214 /* Viking Components, Inc */
5215 /* Viking 28.8 INTERNAL Fax+Data+Voice PnP */
5216 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x4920) },
5217 /* Rockwell */
5218 /* British Telecom */
5219 /* Modular Technology */
5220 /* Rockwell 33.6 DPF External PnP */
5221 /* BT Prologue 33.6 External PnP */
5222 /* Modular Technology 33.6 External PnP */
5223 { ISAPNP_VENDOR('R', 'S', 'S'), ISAPNP_DEVICE(0x00A0) },
5224 /* Viking 56K FAX INT */
5225 { ISAPNP_VENDOR('R', 'S', 'S'), ISAPNP_DEVICE(0x0262) },
5226 /* SupraExpress 28.8 Data/Fax PnP modem */
5227 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1310) },
5228 /* SupraExpress 33.6 Data/Fax PnP modem */
5229 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1421) },
5230 /* SupraExpress 33.6 Data/Fax PnP modem */
5231 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1590) },
5232 /* SupraExpress 33.6 Data/Fax PnP modem */
5233 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1760) },
5234 /* Phoebe Micro */
5235 /* Phoebe Micro 33.6 Data Fax 1433VQH Plug & Play */
5236 { ISAPNP_VENDOR('T', 'E', 'X'), ISAPNP_DEVICE(0x0011) },
5237 /* Archtek America Corp. */
5238 /* Archtek SmartLink Modem 3334BT Plug & Play */
5239 { ISAPNP_VENDOR('U', 'A', 'C'), ISAPNP_DEVICE(0x000F) },
5240 /* 3Com Corp. */
5241 /* Gateway Telepath IIvi 33.6 */
5242 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0000) },
5243 /* Sportster Vi 14.4 PnP FAX Voicemail */
5244 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0004) },
5245 /* U.S. Robotics 33.6K Voice INT PnP */
5246 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0006) },
5247 /* U.S. Robotics 33.6K Voice EXT PnP */
5248 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0007) },
5249 /* U.S. Robotics 33.6K Voice INT PnP */
5250 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2002) },
5251 /* U.S. Robotics 56K Voice INT PnP */
5252 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2070) },
5253 /* U.S. Robotics 56K Voice EXT PnP */
5254 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2080) },
5255 /* U.S. Robotics 56K FAX INT */
5256 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3031) },
5257 /* U.S. Robotics 56K Voice INT PnP */
5258 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3070) },
5259 /* U.S. Robotics 56K Voice EXT PnP */
5260 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3080) },
5261 /* U.S. Robotics 56K Voice INT PnP */
5262 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3090) },
5263 /* U.S. Robotics 56K Message */
5264 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9100) },
5265 /* U.S. Robotics 56K FAX EXT PnP*/
5266 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9160) },
5267 /* U.S. Robotics 56K FAX INT PnP*/
5268 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9170) },
5269 /* U.S. Robotics 56K Voice EXT PnP*/
5270 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9180) },
5271 /* U.S. Robotics 56K Voice INT PnP*/
5272 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9190) },
5273 { 0, }
5274 };
5275
avoid_irq_share(struct pci_dev * dev)5276 static inline void avoid_irq_share(struct pci_dev *dev)
5277 {
5278 int i, map = 0x1FF8;
5279 struct serial_state *state = rs_table;
5280 struct isapnp_irq *irq;
5281 struct isapnp_resources *res = dev->sysdata;
5282
5283 for (i = 0; i < NR_PORTS; i++) {
5284 if (state->type != PORT_UNKNOWN)
5285 clear_bit(state->irq, &map);
5286 state++;
5287 }
5288
5289 for ( ; res; res = res->alt)
5290 for(irq = res->irq; irq; irq = irq->next)
5291 irq->map = map;
5292 }
5293
5294 static char *modem_names[] __devinitdata = {
5295 "MODEM", "Modem", "modem", "FAX", "Fax", "fax",
5296 "56K", "56k", "K56", "33.6", "28.8", "14.4",
5297 "33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
5298 "33600", "28800", "14400", "V.90", "V.34", "V.32", 0
5299 };
5300
check_name(char * name)5301 static int __devinit check_name(char *name)
5302 {
5303 char **tmp = modem_names;
5304
5305 while (*tmp) {
5306 if (strstr(name, *tmp))
5307 return 1;
5308 tmp++;
5309 }
5310 return 0;
5311 }
5312
check_compatible_id(struct pci_dev * dev)5313 static inline int check_compatible_id(struct pci_dev *dev)
5314 {
5315 int i;
5316 for (i = 0; i < DEVICE_COUNT_COMPATIBLE; i++)
5317 if ((dev->vendor_compatible[i] ==
5318 ISAPNP_VENDOR('P', 'N', 'P')) &&
5319 (swab16(dev->device_compatible[i]) >= 0xc000) &&
5320 (swab16(dev->device_compatible[i]) <= 0xdfff))
5321 return 0;
5322 return 1;
5323 }
5324
5325 /*
5326 * Given a complete unknown ISA PnP device, try to use some heuristics to
5327 * detect modems. Currently use such heuristic set:
5328 * - dev->name or dev->bus->name must contain "modem" substring;
5329 * - device must have only one IO region (8 byte long) with base adress
5330 * 0x2e8, 0x3e8, 0x2f8 or 0x3f8.
5331 *
5332 * Such detection looks very ugly, but can detect at least some of numerous
5333 * ISA PnP modems, alternatively we must hardcode all modems in pnp_devices[]
5334 * table.
5335 */
serial_pnp_guess_board(struct pci_dev * dev,struct pci_board * board)5336 static int _INLINE_ serial_pnp_guess_board(struct pci_dev *dev,
5337 struct pci_board *board)
5338 {
5339 struct isapnp_resources *res = (struct isapnp_resources *)dev->sysdata;
5340 struct isapnp_resources *resa;
5341
5342 if (!(check_name(dev->name) || check_name(dev->bus->name)) &&
5343 !(check_compatible_id(dev)))
5344 return 1;
5345
5346 if (!res || res->next)
5347 return 1;
5348
5349 for (resa = res->alt; resa; resa = resa->alt) {
5350 struct isapnp_port *port;
5351 for (port = res->port; port; port = port->next)
5352 if ((port->size == 8) &&
5353 ((port->min == 0x2f8) ||
5354 (port->min == 0x3f8) ||
5355 (port->min == 0x2e8) ||
5356 (port->min == 0x3e8)))
5357 return 0;
5358 }
5359
5360 return 1;
5361 }
5362
probe_serial_pnp(void)5363 static void __devinit probe_serial_pnp(void)
5364 {
5365 struct pci_dev *dev = NULL;
5366 struct pnp_board *pnp_board;
5367 struct pci_board board;
5368
5369 #ifdef SERIAL_DEBUG_PNP
5370 printk("Entered probe_serial_pnp()\n");
5371 #endif
5372 if (!isapnp_present()) {
5373 #ifdef SERIAL_DEBUG_PNP
5374 printk("Leaving probe_serial_pnp() (no isapnp)\n");
5375 #endif
5376 return;
5377 }
5378
5379 isapnp_for_each_dev(dev) {
5380 if (dev->active)
5381 continue;
5382
5383 memset(&board, 0, sizeof(board));
5384 board.flags = SPCI_FL_BASE0 | SPCI_FL_PNPDEFAULT;
5385 board.num_ports = 1;
5386 board.base_baud = 115200;
5387
5388 for (pnp_board = pnp_devices; pnp_board->vendor; pnp_board++)
5389 if ((dev->vendor == pnp_board->vendor) &&
5390 (dev->device == pnp_board->device))
5391 break;
5392
5393 if (pnp_board->vendor) {
5394 /* Special case that's more efficient to hardcode */
5395 if ((pnp_board->vendor == ISAPNP_VENDOR('A', 'K', 'Y') &&
5396 pnp_board->device == ISAPNP_DEVICE(0x1021)))
5397 board.flags |= SPCI_FL_NO_SHIRQ;
5398 } else {
5399 if (serial_pnp_guess_board(dev, &board))
5400 continue;
5401 }
5402
5403 if (board.flags & SPCI_FL_NO_SHIRQ)
5404 avoid_irq_share(dev);
5405 start_pci_pnp_board(dev, &board);
5406 }
5407
5408 #ifdef SERIAL_DEBUG_PNP
5409 printk("Leaving probe_serial_pnp() (probe finished)\n");
5410 #endif
5411 return;
5412 }
5413
5414 #endif /* ENABLE_SERIAL_PNP */
5415
5416 /*
5417 * The serial driver boot-time initialization code!
5418 */
rs_init(void)5419 static int __init rs_init(void)
5420 {
5421 int i;
5422 struct serial_state * state;
5423
5424 init_bh(SERIAL_BH, do_serial_bh);
5425 init_timer(&serial_timer);
5426 serial_timer.function = rs_timer;
5427 mod_timer(&serial_timer, jiffies + RS_STROBE_TIME);
5428
5429 for (i = 0; i < NR_IRQS; i++) {
5430 IRQ_ports[i] = 0;
5431 IRQ_timeout[i] = 0;
5432 #ifdef CONFIG_SERIAL_MULTIPORT
5433 memset(&rs_multiport[i], 0,
5434 sizeof(struct rs_multiport_struct));
5435 #endif
5436 }
5437 #ifdef CONFIG_SERIAL_CONSOLE
5438 /*
5439 * The interrupt of the serial console port
5440 * can't be shared.
5441 */
5442 if (sercons.flags & CON_CONSDEV) {
5443 for(i = 0; i < NR_PORTS; i++)
5444 if (i != sercons.index &&
5445 rs_table[i].irq == rs_table[sercons.index].irq)
5446 rs_table[i].irq = 0;
5447 }
5448 #endif
5449 show_serial_version();
5450
5451 /* Initialize the tty_driver structure */
5452
5453 memset(&serial_driver, 0, sizeof(struct tty_driver));
5454 serial_driver.magic = TTY_DRIVER_MAGIC;
5455 #if (LINUX_VERSION_CODE > 0x20100)
5456 serial_driver.driver_name = "serial";
5457 #endif
5458 #if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
5459 serial_driver.name = "tts/%d";
5460 #else
5461 serial_driver.name = "ttyS";
5462 #endif
5463 serial_driver.major = TTY_MAJOR;
5464 serial_driver.minor_start = 64 + SERIAL_DEV_OFFSET;
5465 serial_driver.name_base = SERIAL_DEV_OFFSET;
5466 serial_driver.num = NR_PORTS;
5467 serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
5468 serial_driver.subtype = SERIAL_TYPE_NORMAL;
5469 serial_driver.init_termios = tty_std_termios;
5470 serial_driver.init_termios.c_cflag =
5471 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
5472 serial_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
5473 serial_driver.refcount = &serial_refcount;
5474 serial_driver.table = serial_table;
5475 serial_driver.termios = serial_termios;
5476 serial_driver.termios_locked = serial_termios_locked;
5477
5478 serial_driver.open = rs_open;
5479 serial_driver.close = rs_close;
5480 serial_driver.write = rs_write;
5481 serial_driver.put_char = rs_put_char;
5482 serial_driver.flush_chars = rs_flush_chars;
5483 serial_driver.write_room = rs_write_room;
5484 serial_driver.chars_in_buffer = rs_chars_in_buffer;
5485 serial_driver.flush_buffer = rs_flush_buffer;
5486 serial_driver.ioctl = rs_ioctl;
5487 serial_driver.throttle = rs_throttle;
5488 serial_driver.unthrottle = rs_unthrottle;
5489 serial_driver.set_termios = rs_set_termios;
5490 serial_driver.stop = rs_stop;
5491 serial_driver.start = rs_start;
5492 serial_driver.hangup = rs_hangup;
5493 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
5494 serial_driver.break_ctl = rs_break;
5495 #endif
5496 #if (LINUX_VERSION_CODE >= 131343)
5497 serial_driver.send_xchar = rs_send_xchar;
5498 serial_driver.wait_until_sent = rs_wait_until_sent;
5499 serial_driver.read_proc = rs_read_proc;
5500 #endif
5501
5502 /*
5503 * The callout device is just like normal device except for
5504 * major number and the subtype code.
5505 */
5506 callout_driver = serial_driver;
5507 #if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
5508 callout_driver.name = "cua/%d";
5509 #else
5510 callout_driver.name = "cua";
5511 #endif
5512 callout_driver.major = TTYAUX_MAJOR;
5513 callout_driver.subtype = SERIAL_TYPE_CALLOUT;
5514 #if (LINUX_VERSION_CODE >= 131343)
5515 callout_driver.read_proc = 0;
5516 callout_driver.proc_entry = 0;
5517 #endif
5518
5519 if (tty_register_driver(&serial_driver))
5520 panic("Couldn't register serial driver\n");
5521 if (tty_register_driver(&callout_driver))
5522 panic("Couldn't register callout driver\n");
5523
5524 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
5525 state->magic = SSTATE_MAGIC;
5526 state->line = i;
5527 state->type = PORT_UNKNOWN;
5528 state->custom_divisor = 0;
5529 state->close_delay = 5*HZ/10;
5530 state->closing_wait = 30*HZ;
5531 state->callout_termios = callout_driver.init_termios;
5532 state->normal_termios = serial_driver.init_termios;
5533 state->icount.cts = state->icount.dsr =
5534 state->icount.rng = state->icount.dcd = 0;
5535 state->icount.rx = state->icount.tx = 0;
5536 state->icount.frame = state->icount.parity = 0;
5537 state->icount.overrun = state->icount.brk = 0;
5538 state->irq = irq_cannonicalize(state->irq);
5539 if (state->hub6)
5540 state->io_type = SERIAL_IO_HUB6;
5541 if (state->port && check_region(state->port,8))
5542 continue;
5543 #ifdef CONFIG_MCA
5544 if ((state->flags & ASYNC_BOOT_ONLYMCA) && !MCA_bus)
5545 continue;
5546 #endif
5547 if (state->flags & ASYNC_BOOT_AUTOCONF)
5548 autoconfig(state);
5549 }
5550 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
5551 if (state->type == PORT_UNKNOWN)
5552 continue;
5553 if ( (state->flags & ASYNC_BOOT_AUTOCONF)
5554 && (state->flags & ASYNC_AUTO_IRQ)
5555 && (state->port != 0 || state->iomem_base != 0))
5556 state->irq = detect_uart_irq(state);
5557 if (state->io_type == SERIAL_IO_MEM) {
5558 printk(KERN_INFO"ttyS%02d%s at 0x%p (irq = %d) is a %s\n",
5559 state->line + SERIAL_DEV_OFFSET,
5560 (state->flags & ASYNC_FOURPORT) ? " FourPort" : "",
5561 state->iomem_base, state->irq,
5562 uart_config[state->type].name);
5563 }
5564 else {
5565 printk(KERN_INFO "ttyS%02d%s at 0x%04lx (irq = %d) is a %s\n",
5566 state->line + SERIAL_DEV_OFFSET,
5567 (state->flags & ASYNC_FOURPORT) ? " FourPort" : "",
5568 state->port, state->irq,
5569 uart_config[state->type].name);
5570 }
5571 tty_register_devfs(&serial_driver, 0,
5572 serial_driver.minor_start + state->line);
5573 tty_register_devfs(&callout_driver, 0,
5574 callout_driver.minor_start + state->line);
5575 }
5576 #ifdef ENABLE_SERIAL_PCI
5577 probe_serial_pci();
5578 #endif
5579 #ifdef ENABLE_SERIAL_PNP
5580 probe_serial_pnp();
5581 #endif
5582 return 0;
5583 }
5584
5585 /*
5586 * This is for use by architectures that know their serial console
5587 * attributes only at run time. Not to be invoked after rs_init().
5588 */
early_serial_setup(struct serial_struct * req)5589 int __init early_serial_setup(struct serial_struct *req)
5590 {
5591 int i = req->line;
5592
5593 if (i >= NR_IRQS)
5594 return(-ENOENT);
5595 rs_table[i].magic = 0;
5596 rs_table[i].baud_base = req->baud_base;
5597 rs_table[i].port = req->port;
5598 if (HIGH_BITS_OFFSET)
5599 rs_table[i].port += (unsigned long) req->port_high <<
5600 HIGH_BITS_OFFSET;
5601 rs_table[i].irq = req->irq;
5602 rs_table[i].flags = req->flags;
5603 rs_table[i].close_delay = req->close_delay;
5604 rs_table[i].io_type = req->io_type;
5605 rs_table[i].hub6 = req->hub6;
5606 rs_table[i].iomem_base = req->iomem_base;
5607 rs_table[i].iomem_reg_shift = req->iomem_reg_shift;
5608 rs_table[i].type = req->type;
5609 rs_table[i].xmit_fifo_size = req->xmit_fifo_size;
5610 rs_table[i].custom_divisor = req->custom_divisor;
5611 rs_table[i].closing_wait = req->closing_wait;
5612 return(0);
5613 }
5614
5615 /*
5616 * register_serial and unregister_serial allows for 16x50 serial ports to be
5617 * configured at run-time, to support PCMCIA modems.
5618 */
5619
5620 /**
5621 * register_serial - configure a 16x50 serial port at runtime
5622 * @req: request structure
5623 *
5624 * Configure the serial port specified by the request. If the
5625 * port exists and is in use an error is returned. If the port
5626 * is not currently in the table it is added.
5627 *
5628 * The port is then probed and if neccessary the IRQ is autodetected
5629 * If this fails an error is returned.
5630 *
5631 * On success the port is ready to use and the line number is returned.
5632 */
5633
register_serial(struct serial_struct * req)5634 int register_serial(struct serial_struct *req)
5635 {
5636 int i;
5637 unsigned long flags;
5638 struct serial_state *state;
5639 struct async_struct *info;
5640 unsigned long port;
5641
5642 port = req->port;
5643 if (HIGH_BITS_OFFSET)
5644 port += (unsigned long) req->port_high << HIGH_BITS_OFFSET;
5645
5646 save_flags(flags); cli();
5647 for (i = 0; i < NR_PORTS; i++) {
5648 if ((rs_table[i].port == port) &&
5649 (rs_table[i].iomem_base == req->iomem_base))
5650 break;
5651 }
5652 #ifdef __i386__
5653 if (i == NR_PORTS) {
5654 for (i = 4; i < NR_PORTS; i++)
5655 if ((rs_table[i].type == PORT_UNKNOWN) &&
5656 (rs_table[i].count == 0))
5657 break;
5658 }
5659 #endif
5660 if (i == NR_PORTS) {
5661 for (i = 0; i < NR_PORTS; i++)
5662 if ((rs_table[i].type == PORT_UNKNOWN) &&
5663 (rs_table[i].count == 0))
5664 break;
5665 }
5666 if (i == NR_PORTS) {
5667 restore_flags(flags);
5668 return -1;
5669 }
5670 state = &rs_table[i];
5671 if (rs_table[i].count) {
5672 restore_flags(flags);
5673 printk("Couldn't configure serial #%d (port=%ld,irq=%d): "
5674 "device already open\n", i, port, req->irq);
5675 return -1;
5676 }
5677 state->irq = req->irq;
5678 state->port = port;
5679 state->flags = req->flags;
5680 state->io_type = req->io_type;
5681 state->iomem_base = req->iomem_base;
5682 state->iomem_reg_shift = req->iomem_reg_shift;
5683 if (req->baud_base)
5684 state->baud_base = req->baud_base;
5685 if ((info = state->info) != NULL) {
5686 info->port = port;
5687 info->flags = req->flags;
5688 info->io_type = req->io_type;
5689 info->iomem_base = req->iomem_base;
5690 info->iomem_reg_shift = req->iomem_reg_shift;
5691 }
5692 autoconfig(state);
5693 if (state->type == PORT_UNKNOWN) {
5694 restore_flags(flags);
5695 printk("register_serial(): autoconfig failed\n");
5696 return -1;
5697 }
5698 restore_flags(flags);
5699
5700 if ((state->flags & ASYNC_AUTO_IRQ) && CONFIGURED_SERIAL_PORT(state))
5701 state->irq = detect_uart_irq(state);
5702
5703 printk(KERN_INFO "ttyS%02d at %s 0x%04lx (irq = %d) is a %s\n",
5704 state->line + SERIAL_DEV_OFFSET,
5705 state->iomem_base ? "iomem" : "port",
5706 state->iomem_base ? (unsigned long)state->iomem_base :
5707 state->port, state->irq, uart_config[state->type].name);
5708 tty_register_devfs(&serial_driver, 0,
5709 serial_driver.minor_start + state->line);
5710 tty_register_devfs(&callout_driver, 0,
5711 callout_driver.minor_start + state->line);
5712 return state->line + SERIAL_DEV_OFFSET;
5713 }
5714
5715 /**
5716 * unregister_serial - deconfigure a 16x50 serial port
5717 * @line: line to deconfigure
5718 *
5719 * The port specified is deconfigured and its resources are freed. Any
5720 * user of the port is disconnected as if carrier was dropped. Line is
5721 * the port number returned by register_serial().
5722 */
5723
unregister_serial(int line)5724 void unregister_serial(int line)
5725 {
5726 unsigned long flags;
5727 struct serial_state *state = &rs_table[line];
5728
5729 save_flags(flags); cli();
5730 if (state->info && state->info->tty)
5731 tty_hangup(state->info->tty);
5732 state->type = PORT_UNKNOWN;
5733 printk(KERN_INFO "ttyS%02d unloaded\n", state->line);
5734 /* These will be hidden, because they are devices that will no longer
5735 * be available to the system. (ie, PCMCIA modems, once ejected)
5736 */
5737 tty_unregister_devfs(&serial_driver,
5738 serial_driver.minor_start + state->line);
5739 tty_unregister_devfs(&callout_driver,
5740 callout_driver.minor_start + state->line);
5741 restore_flags(flags);
5742 }
5743
rs_fini(void)5744 static void __exit rs_fini(void)
5745 {
5746 unsigned long flags;
5747 int e1, e2;
5748 int i;
5749 struct async_struct *info;
5750
5751 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
5752 del_timer_sync(&serial_timer);
5753 save_flags(flags); cli();
5754 remove_bh(SERIAL_BH);
5755 if ((e1 = tty_unregister_driver(&serial_driver)))
5756 printk("serial: failed to unregister serial driver (%d)\n",
5757 e1);
5758 if ((e2 = tty_unregister_driver(&callout_driver)))
5759 printk("serial: failed to unregister callout driver (%d)\n",
5760 e2);
5761 restore_flags(flags);
5762
5763 for (i = 0; i < NR_PORTS; i++) {
5764 if ((info = rs_table[i].info)) {
5765 rs_table[i].info = NULL;
5766 kfree(info);
5767 }
5768 if ((rs_table[i].type != PORT_UNKNOWN) && rs_table[i].port) {
5769 #ifdef CONFIG_SERIAL_RSA
5770 if (rs_table[i].type == PORT_RSA)
5771 release_region(rs_table[i].port +
5772 UART_RSA_BASE, 16);
5773 else
5774 #endif
5775 release_region(rs_table[i].port, 8);
5776 }
5777 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
5778 if (rs_table[i].iomem_base)
5779 iounmap(rs_table[i].iomem_base);
5780 #endif
5781 }
5782 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
5783 for (i=0; i < NR_PCI_BOARDS; i++) {
5784 struct pci_board_inst *brd = &serial_pci_board[i];
5785
5786 if (serial_pci_board[i].dev == 0)
5787 continue;
5788 if (brd->board.init_fn)
5789 (brd->board.init_fn)(brd->dev, &brd->board, 0);
5790 if (DEACTIVATE_FUNC(brd->dev))
5791 (DEACTIVATE_FUNC(brd->dev))(brd->dev);
5792 }
5793 #endif
5794 if (tmp_buf) {
5795 unsigned long pg = (unsigned long) tmp_buf;
5796 tmp_buf = NULL;
5797 free_page(pg);
5798 }
5799
5800 #ifdef ENABLE_SERIAL_PCI
5801 if (serial_pci_driver.name[0])
5802 pci_unregister_driver (&serial_pci_driver);
5803 #endif
5804 }
5805
5806 module_init(rs_init);
5807 module_exit(rs_fini);
5808 MODULE_DESCRIPTION("Standard/generic (dumb) serial driver");
5809 MODULE_AUTHOR("Theodore Ts'o <tytso@mit.edu>");
5810 MODULE_LICENSE("GPL");
5811
5812
5813 /*
5814 * ------------------------------------------------------------
5815 * Serial console driver
5816 * ------------------------------------------------------------
5817 */
5818 #ifdef CONFIG_SERIAL_CONSOLE
5819
5820 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
5821
5822 static struct async_struct async_sercons;
5823
5824 /*
5825 * Wait for transmitter & holding register to empty
5826 */
wait_for_xmitr(struct async_struct * info)5827 static inline void wait_for_xmitr(struct async_struct *info)
5828 {
5829 unsigned int status, tmout = 1000000;
5830
5831 do {
5832 status = serial_in(info, UART_LSR);
5833
5834 if (status & UART_LSR_BI)
5835 lsr_break_flag = UART_LSR_BI;
5836
5837 if (--tmout == 0)
5838 break;
5839 } while((status & BOTH_EMPTY) != BOTH_EMPTY);
5840
5841 /* Wait for flow control if necessary */
5842 if (info->flags & ASYNC_CONS_FLOW) {
5843 tmout = 1000000;
5844 while (--tmout &&
5845 ((serial_in(info, UART_MSR) & UART_MSR_CTS) == 0));
5846 }
5847 }
5848
5849
5850 /*
5851 * Print a string to the serial port trying not to disturb
5852 * any possible real use of the port...
5853 *
5854 * The console must be locked when we get here.
5855 */
serial_console_write(struct console * co,const char * s,unsigned count)5856 static void serial_console_write(struct console *co, const char *s,
5857 unsigned count)
5858 {
5859 static struct async_struct *info = &async_sercons;
5860 int ier;
5861 unsigned i;
5862
5863 /*
5864 * First save the IER then disable the interrupts
5865 */
5866 ier = serial_in(info, UART_IER);
5867 serial_out(info, UART_IER, 0x00);
5868
5869 /*
5870 * Now, do each character
5871 */
5872 for (i = 0; i < count; i++, s++) {
5873 wait_for_xmitr(info);
5874
5875 /*
5876 * Send the character out.
5877 * If a LF, also do CR...
5878 */
5879 serial_out(info, UART_TX, *s);
5880 if (*s == 10) {
5881 wait_for_xmitr(info);
5882 serial_out(info, UART_TX, 13);
5883 }
5884 }
5885
5886 /*
5887 * Finally, Wait for transmitter & holding register to empty
5888 * and restore the IER
5889 */
5890 wait_for_xmitr(info);
5891 serial_out(info, UART_IER, ier);
5892 }
5893
serial_console_device(struct console * c)5894 static kdev_t serial_console_device(struct console *c)
5895 {
5896 return MKDEV(TTY_MAJOR, 64 + c->index);
5897 }
5898
5899 /*
5900 * Setup initial baud/bits/parity/flow control. We do two things here:
5901 * - construct a cflag setting for the first rs_open()
5902 * - initialize the serial port
5903 * Return non-zero if we didn't find a serial port.
5904 */
serial_console_setup(struct console * co,char * options)5905 static int __init serial_console_setup(struct console *co, char *options)
5906 {
5907 static struct async_struct *info;
5908 struct serial_state *state;
5909 unsigned cval;
5910 int baud = 9600;
5911 int bits = 8;
5912 int parity = 'n';
5913 int doflow = 0;
5914 int cflag = CREAD | HUPCL | CLOCAL;
5915 int quot = 0;
5916 char *s;
5917
5918 if (options) {
5919 baud = simple_strtoul(options, NULL, 10);
5920 s = options;
5921 while(*s >= '0' && *s <= '9')
5922 s++;
5923 if (*s) parity = *s++;
5924 if (*s) bits = *s++ - '0';
5925 if (*s) doflow = (*s++ == 'r');
5926 }
5927
5928 /*
5929 * Now construct a cflag setting.
5930 */
5931 switch(baud) {
5932 case 1200:
5933 cflag |= B1200;
5934 break;
5935 case 2400:
5936 cflag |= B2400;
5937 break;
5938 case 4800:
5939 cflag |= B4800;
5940 break;
5941 case 19200:
5942 cflag |= B19200;
5943 break;
5944 case 38400:
5945 cflag |= B38400;
5946 break;
5947 case 57600:
5948 cflag |= B57600;
5949 break;
5950 case 115200:
5951 cflag |= B115200;
5952 break;
5953 case 9600:
5954 default:
5955 cflag |= B9600;
5956 /*
5957 * Set this to a sane value to prevent a divide error
5958 */
5959 baud = 9600;
5960 break;
5961 }
5962 switch(bits) {
5963 case 7:
5964 cflag |= CS7;
5965 break;
5966 default:
5967 case 8:
5968 cflag |= CS8;
5969 break;
5970 }
5971 switch(parity) {
5972 case 'o': case 'O':
5973 cflag |= PARODD;
5974 break;
5975 case 'e': case 'E':
5976 cflag |= PARENB;
5977 break;
5978 }
5979 co->cflag = cflag;
5980
5981 /*
5982 * Divisor, bytesize and parity
5983 */
5984 state = rs_table + co->index;
5985 if (doflow)
5986 state->flags |= ASYNC_CONS_FLOW;
5987 info = &async_sercons;
5988 info->magic = SERIAL_MAGIC;
5989 info->state = state;
5990 info->port = state->port;
5991 info->flags = state->flags;
5992 #ifdef CONFIG_HUB6
5993 info->hub6 = state->hub6;
5994 #endif
5995 info->io_type = state->io_type;
5996 info->iomem_base = state->iomem_base;
5997 info->iomem_reg_shift = state->iomem_reg_shift;
5998 quot = state->baud_base / baud;
5999 cval = cflag & (CSIZE | CSTOPB);
6000 #if defined(__powerpc__) || defined(__alpha__)
6001 cval >>= 8;
6002 #else /* !__powerpc__ && !__alpha__ */
6003 cval >>= 4;
6004 #endif /* !__powerpc__ && !__alpha__ */
6005 if (cflag & PARENB)
6006 cval |= UART_LCR_PARITY;
6007 if (!(cflag & PARODD))
6008 cval |= UART_LCR_EPAR;
6009
6010 /*
6011 * Disable UART interrupts, set DTR and RTS high
6012 * and set speed.
6013 */
6014 serial_out(info, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */
6015 serial_out(info, UART_DLL, quot & 0xff); /* LS of divisor */
6016 serial_out(info, UART_DLM, quot >> 8); /* MS of divisor */
6017 serial_out(info, UART_LCR, cval); /* reset DLAB */
6018 serial_out(info, UART_IER, 0);
6019 serial_out(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
6020
6021 /*
6022 * If we read 0xff from the LSR, there is no UART here.
6023 */
6024 if (serial_in(info, UART_LSR) == 0xff)
6025 return -1;
6026
6027 return 0;
6028 }
6029
6030 static struct console sercons = {
6031 name: "ttyS",
6032 write: serial_console_write,
6033 device: serial_console_device,
6034 setup: serial_console_setup,
6035 flags: CON_PRINTBUFFER,
6036 index: -1,
6037 };
6038
6039 /*
6040 * Register console.
6041 */
serial_console_init(void)6042 void __init serial_console_init(void)
6043 {
6044 register_console(&sercons);
6045 }
6046 #endif
6047
6048 /*
6049 Local variables:
6050 compile-command: "gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe -fno-strength-reduce -march=i586 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -DEXPORT_SYMTAB -c serial.c"
6051 End:
6052 */
6053