]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/serial/8250.c
Merge with ../linux-2.6
[linux-2.6-omap-h63xx.git] / drivers / serial / 8250.c
1 /*
2  *  linux/drivers/char/8250.c
3  *
4  *  Driver for 8250/16550-type serial ports
5  *
6  *  Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
7  *
8  *  Copyright (C) 2001 Russell King.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  *  $Id: 8250.c,v 1.90 2002/07/28 10:03:27 rmk Exp $
16  *
17  * A note about mapbase / membase
18  *
19  *  mapbase is the physical address of the IO port.
20  *  membase is an 'ioremapped' cookie.
21  */
22 #include <linux/config.h>
23
24 #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
25 #define SUPPORT_SYSRQ
26 #endif
27
28 #include <linux/module.h>
29 #include <linux/moduleparam.h>
30 #include <linux/ioport.h>
31 #include <linux/init.h>
32 #include <linux/console.h>
33 #include <linux/sysrq.h>
34 #include <linux/mca.h>
35 #include <linux/delay.h>
36 #include <linux/platform_device.h>
37 #include <linux/tty.h>
38 #include <linux/tty_flip.h>
39 #include <linux/serial_reg.h>
40 #include <linux/serial_core.h>
41 #include <linux/serial.h>
42 #include <linux/serial_8250.h>
43 #include <linux/nmi.h>
44
45 #include <asm/io.h>
46 #include <asm/irq.h>
47
48 #include "8250.h"
49
50 /*
51  * Configuration:
52  *   share_irqs - whether we pass SA_SHIRQ to request_irq().  This option
53  *                is unsafe when used on edge-triggered interrupts.
54  */
55 static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
56
57 /*
58  * Debugging.
59  */
60 #if 0
61 #define DEBUG_AUTOCONF(fmt...)  printk(fmt)
62 #else
63 #define DEBUG_AUTOCONF(fmt...)  do { } while (0)
64 #endif
65
66 #if 0
67 #define DEBUG_INTR(fmt...)      printk(fmt)
68 #else
69 #define DEBUG_INTR(fmt...)      do { } while (0)
70 #endif
71
72 #define PASS_LIMIT      256
73
74 /*
75  * We default to IRQ0 for the "no irq" hack.   Some
76  * machine types want others as well - they're free
77  * to redefine this in their header file.
78  */
79 #define is_real_interrupt(irq)  ((irq) != 0)
80
81 #ifdef CONFIG_SERIAL_8250_DETECT_IRQ
82 #define CONFIG_SERIAL_DETECT_IRQ 1
83 #endif
84 #ifdef CONFIG_SERIAL_8250_MANY_PORTS
85 #define CONFIG_SERIAL_MANY_PORTS 1
86 #endif
87
88 /*
89  * HUB6 is always on.  This will be removed once the header
90  * files have been cleaned.
91  */
92 #define CONFIG_HUB6 1
93
94 #include <asm/serial.h>
95
96 /*
97  * SERIAL_PORT_DFNS tells us about built-in ports that have no
98  * standard enumeration mechanism.   Platforms that can find all
99  * serial ports via mechanisms like ACPI or PCI need not supply it.
100  */
101 #ifndef SERIAL_PORT_DFNS
102 #define SERIAL_PORT_DFNS
103 #endif
104
105 static struct old_serial_port old_serial_port[] = {
106         SERIAL_PORT_DFNS /* defined in asm/serial.h */
107 };
108
109 #define UART_NR CONFIG_SERIAL_8250_NR_UARTS
110
111 #ifdef CONFIG_SERIAL_8250_RSA
112
113 #define PORT_RSA_MAX 4
114 static unsigned long probe_rsa[PORT_RSA_MAX];
115 static unsigned int probe_rsa_count;
116 #endif /* CONFIG_SERIAL_8250_RSA  */
117
118 struct uart_8250_port {
119         struct uart_port        port;
120         struct timer_list       timer;          /* "no irq" timer */
121         struct list_head        list;           /* ports on this IRQ */
122         unsigned short          capabilities;   /* port capabilities */
123         unsigned short          bugs;           /* port bugs */
124         unsigned int            tx_loadsz;      /* transmit fifo load size */
125         unsigned char           acr;
126         unsigned char           ier;
127         unsigned char           lcr;
128         unsigned char           mcr;
129         unsigned char           mcr_mask;       /* mask of user bits */
130         unsigned char           mcr_force;      /* mask of forced bits */
131         unsigned char           lsr_break_flag;
132
133         /*
134          * We provide a per-port pm hook.
135          */
136         void                    (*pm)(struct uart_port *port,
137                                       unsigned int state, unsigned int old);
138 };
139
140 struct irq_info {
141         spinlock_t              lock;
142         struct list_head        *head;
143 };
144
145 static struct irq_info irq_lists[NR_IRQS];
146
147 /*
148  * Here we define the default xmit fifo size used for each type of UART.
149  */
150 static const struct serial8250_config uart_config[] = {
151         [PORT_UNKNOWN] = {
152                 .name           = "unknown",
153                 .fifo_size      = 1,
154                 .tx_loadsz      = 1,
155         },
156         [PORT_8250] = {
157                 .name           = "8250",
158                 .fifo_size      = 1,
159                 .tx_loadsz      = 1,
160         },
161         [PORT_16450] = {
162                 .name           = "16450",
163                 .fifo_size      = 1,
164                 .tx_loadsz      = 1,
165         },
166         [PORT_16550] = {
167                 .name           = "16550",
168                 .fifo_size      = 1,
169                 .tx_loadsz      = 1,
170         },
171         [PORT_16550A] = {
172                 .name           = "16550A",
173                 .fifo_size      = 16,
174                 .tx_loadsz      = 16,
175                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
176                 .flags          = UART_CAP_FIFO,
177         },
178         [PORT_CIRRUS] = {
179                 .name           = "Cirrus",
180                 .fifo_size      = 1,
181                 .tx_loadsz      = 1,
182         },
183         [PORT_16650] = {
184                 .name           = "ST16650",
185                 .fifo_size      = 1,
186                 .tx_loadsz      = 1,
187                 .flags          = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
188         },
189         [PORT_16650V2] = {
190                 .name           = "ST16650V2",
191                 .fifo_size      = 32,
192                 .tx_loadsz      = 16,
193                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
194                                   UART_FCR_T_TRIG_00,
195                 .flags          = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
196         },
197         [PORT_16750] = {
198                 .name           = "TI16750",
199                 .fifo_size      = 64,
200                 .tx_loadsz      = 64,
201                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
202                                   UART_FCR7_64BYTE,
203                 .flags          = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE,
204         },
205         [PORT_STARTECH] = {
206                 .name           = "Startech",
207                 .fifo_size      = 1,
208                 .tx_loadsz      = 1,
209         },
210         [PORT_16C950] = {
211                 .name           = "16C950/954",
212                 .fifo_size      = 128,
213                 .tx_loadsz      = 128,
214                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
215                 .flags          = UART_CAP_FIFO,
216         },
217         [PORT_16654] = {
218                 .name           = "ST16654",
219                 .fifo_size      = 64,
220                 .tx_loadsz      = 32,
221                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
222                                   UART_FCR_T_TRIG_10,
223                 .flags          = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
224         },
225         [PORT_16850] = {
226                 .name           = "XR16850",
227                 .fifo_size      = 128,
228                 .tx_loadsz      = 128,
229                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
230                 .flags          = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
231         },
232         [PORT_RSA] = {
233                 .name           = "RSA",
234                 .fifo_size      = 2048,
235                 .tx_loadsz      = 2048,
236                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11,
237                 .flags          = UART_CAP_FIFO,
238         },
239         [PORT_NS16550A] = {
240                 .name           = "NS16550A",
241                 .fifo_size      = 16,
242                 .tx_loadsz      = 16,
243                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
244                 .flags          = UART_CAP_FIFO | UART_NATSEMI,
245         },
246         [PORT_XSCALE] = {
247                 .name           = "XScale",
248                 .fifo_size      = 32,
249                 .tx_loadsz      = 32,
250                 .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
251                 .flags          = UART_CAP_FIFO | UART_CAP_UUE,
252         },
253 };
254
255 #ifdef CONFIG_SERIAL_8250_AU1X00
256
257 /* Au1x00 UART hardware has a weird register layout */
258 static const u8 au_io_in_map[] = {
259         [UART_RX]  = 0,
260         [UART_IER] = 2,
261         [UART_IIR] = 3,
262         [UART_LCR] = 5,
263         [UART_MCR] = 6,
264         [UART_LSR] = 7,
265         [UART_MSR] = 8,
266 };
267
268 static const u8 au_io_out_map[] = {
269         [UART_TX]  = 1,
270         [UART_IER] = 2,
271         [UART_FCR] = 4,
272         [UART_LCR] = 5,
273         [UART_MCR] = 6,
274 };
275
276 /* sane hardware needs no mapping */
277 static inline int map_8250_in_reg(struct uart_8250_port *up, int offset)
278 {
279         if (up->port.iotype != UPIO_AU)
280                 return offset;
281         return au_io_in_map[offset];
282 }
283
284 static inline int map_8250_out_reg(struct uart_8250_port *up, int offset)
285 {
286         if (up->port.iotype != UPIO_AU)
287                 return offset;
288         return au_io_out_map[offset];
289 }
290
291 #else
292
293 /* sane hardware needs no mapping */
294 #define map_8250_in_reg(up, offset) (offset)
295 #define map_8250_out_reg(up, offset) (offset)
296
297 #endif
298
299 static _INLINE_ unsigned int serial_in(struct uart_8250_port *up, int offset)
300 {
301         offset = map_8250_in_reg(up, offset) << up->port.regshift;
302
303         switch (up->port.iotype) {
304         case UPIO_HUB6:
305                 outb(up->port.hub6 - 1 + offset, up->port.iobase);
306                 return inb(up->port.iobase + 1);
307
308         case UPIO_MEM:
309                 return readb(up->port.membase + offset);
310
311         case UPIO_MEM32:
312                 return readl(up->port.membase + offset);
313
314 #ifdef CONFIG_SERIAL_8250_AU1X00
315         case UPIO_AU:
316                 return __raw_readl(up->port.membase + offset);
317 #endif
318
319         default:
320                 return inb(up->port.iobase + offset);
321         }
322 }
323
324 static _INLINE_ void
325 serial_out(struct uart_8250_port *up, int offset, int value)
326 {
327         offset = map_8250_out_reg(up, offset) << up->port.regshift;
328
329         switch (up->port.iotype) {
330         case UPIO_HUB6:
331                 outb(up->port.hub6 - 1 + offset, up->port.iobase);
332                 outb(value, up->port.iobase + 1);
333                 break;
334
335         case UPIO_MEM:
336                 writeb(value, up->port.membase + offset);
337                 break;
338
339         case UPIO_MEM32:
340                 writel(value, up->port.membase + offset);
341                 break;
342
343 #ifdef CONFIG_SERIAL_8250_AU1X00
344         case UPIO_AU:
345                 __raw_writel(value, up->port.membase + offset);
346                 break;
347 #endif
348
349         default:
350                 outb(value, up->port.iobase + offset);
351         }
352 }
353
354 /*
355  * We used to support using pause I/O for certain machines.  We
356  * haven't supported this for a while, but just in case it's badly
357  * needed for certain old 386 machines, I've left these #define's
358  * in....
359  */
360 #define serial_inp(up, offset)          serial_in(up, offset)
361 #define serial_outp(up, offset, value)  serial_out(up, offset, value)
362
363
364 /*
365  * For the 16C950
366  */
367 static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
368 {
369         serial_out(up, UART_SCR, offset);
370         serial_out(up, UART_ICR, value);
371 }
372
373 static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
374 {
375         unsigned int value;
376
377         serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
378         serial_out(up, UART_SCR, offset);
379         value = serial_in(up, UART_ICR);
380         serial_icr_write(up, UART_ACR, up->acr);
381
382         return value;
383 }
384
385 /*
386  * FIFO support.
387  */
388 static inline void serial8250_clear_fifos(struct uart_8250_port *p)
389 {
390         if (p->capabilities & UART_CAP_FIFO) {
391                 serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO);
392                 serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO |
393                                UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
394                 serial_outp(p, UART_FCR, 0);
395         }
396 }
397
398 /*
399  * IER sleep support.  UARTs which have EFRs need the "extended
400  * capability" bit enabled.  Note that on XR16C850s, we need to
401  * reset LCR to write to IER.
402  */
403 static inline void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
404 {
405         if (p->capabilities & UART_CAP_SLEEP) {
406                 if (p->capabilities & UART_CAP_EFR) {
407                         serial_outp(p, UART_LCR, 0xBF);
408                         serial_outp(p, UART_EFR, UART_EFR_ECB);
409                         serial_outp(p, UART_LCR, 0);
410                 }
411                 serial_outp(p, UART_IER, sleep ? UART_IERX_SLEEP : 0);
412                 if (p->capabilities & UART_CAP_EFR) {
413                         serial_outp(p, UART_LCR, 0xBF);
414                         serial_outp(p, UART_EFR, 0);
415                         serial_outp(p, UART_LCR, 0);
416                 }
417         }
418 }
419
420 #ifdef CONFIG_SERIAL_8250_RSA
421 /*
422  * Attempts to turn on the RSA FIFO.  Returns zero on failure.
423  * We set the port uart clock rate if we succeed.
424  */
425 static int __enable_rsa(struct uart_8250_port *up)
426 {
427         unsigned char mode;
428         int result;
429
430         mode = serial_inp(up, UART_RSA_MSR);
431         result = mode & UART_RSA_MSR_FIFO;
432
433         if (!result) {
434                 serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
435                 mode = serial_inp(up, UART_RSA_MSR);
436                 result = mode & UART_RSA_MSR_FIFO;
437         }
438
439         if (result)
440                 up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
441
442         return result;
443 }
444
445 static void enable_rsa(struct uart_8250_port *up)
446 {
447         if (up->port.type == PORT_RSA) {
448                 if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
449                         spin_lock_irq(&up->port.lock);
450                         __enable_rsa(up);
451                         spin_unlock_irq(&up->port.lock);
452                 }
453                 if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
454                         serial_outp(up, UART_RSA_FRR, 0);
455         }
456 }
457
458 /*
459  * Attempts to turn off the RSA FIFO.  Returns zero on failure.
460  * It is unknown why interrupts were disabled in here.  However,
461  * the caller is expected to preserve this behaviour by grabbing
462  * the spinlock before calling this function.
463  */
464 static void disable_rsa(struct uart_8250_port *up)
465 {
466         unsigned char mode;
467         int result;
468
469         if (up->port.type == PORT_RSA &&
470             up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
471                 spin_lock_irq(&up->port.lock);
472
473                 mode = serial_inp(up, UART_RSA_MSR);
474                 result = !(mode & UART_RSA_MSR_FIFO);
475
476                 if (!result) {
477                         serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
478                         mode = serial_inp(up, UART_RSA_MSR);
479                         result = !(mode & UART_RSA_MSR_FIFO);
480                 }
481
482                 if (result)
483                         up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
484                 spin_unlock_irq(&up->port.lock);
485         }
486 }
487 #endif /* CONFIG_SERIAL_8250_RSA */
488
489 /*
490  * This is a quickie test to see how big the FIFO is.
491  * It doesn't work at all the time, more's the pity.
492  */
493 static int size_fifo(struct uart_8250_port *up)
494 {
495         unsigned char old_fcr, old_mcr, old_dll, old_dlm, old_lcr;
496         int count;
497
498         old_lcr = serial_inp(up, UART_LCR);
499         serial_outp(up, UART_LCR, 0);
500         old_fcr = serial_inp(up, UART_FCR);
501         old_mcr = serial_inp(up, UART_MCR);
502         serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
503                     UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
504         serial_outp(up, UART_MCR, UART_MCR_LOOP);
505         serial_outp(up, UART_LCR, UART_LCR_DLAB);
506         old_dll = serial_inp(up, UART_DLL);
507         old_dlm = serial_inp(up, UART_DLM);
508         serial_outp(up, UART_DLL, 0x01);
509         serial_outp(up, UART_DLM, 0x00);
510         serial_outp(up, UART_LCR, 0x03);
511         for (count = 0; count < 256; count++)
512                 serial_outp(up, UART_TX, count);
513         mdelay(20);/* FIXME - schedule_timeout */
514         for (count = 0; (serial_inp(up, UART_LSR) & UART_LSR_DR) &&
515              (count < 256); count++)
516                 serial_inp(up, UART_RX);
517         serial_outp(up, UART_FCR, old_fcr);
518         serial_outp(up, UART_MCR, old_mcr);
519         serial_outp(up, UART_LCR, UART_LCR_DLAB);
520         serial_outp(up, UART_DLL, old_dll);
521         serial_outp(up, UART_DLM, old_dlm);
522         serial_outp(up, UART_LCR, old_lcr);
523
524         return count;
525 }
526
527 /*
528  * Read UART ID using the divisor method - set DLL and DLM to zero
529  * and the revision will be in DLL and device type in DLM.  We
530  * preserve the device state across this.
531  */
532 static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p)
533 {
534         unsigned char old_dll, old_dlm, old_lcr;
535         unsigned int id;
536
537         old_lcr = serial_inp(p, UART_LCR);
538         serial_outp(p, UART_LCR, UART_LCR_DLAB);
539
540         old_dll = serial_inp(p, UART_DLL);
541         old_dlm = serial_inp(p, UART_DLM);
542
543         serial_outp(p, UART_DLL, 0);
544         serial_outp(p, UART_DLM, 0);
545
546         id = serial_inp(p, UART_DLL) | serial_inp(p, UART_DLM) << 8;
547
548         serial_outp(p, UART_DLL, old_dll);
549         serial_outp(p, UART_DLM, old_dlm);
550         serial_outp(p, UART_LCR, old_lcr);
551
552         return id;
553 }
554
555 /*
556  * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
557  * When this function is called we know it is at least a StarTech
558  * 16650 V2, but it might be one of several StarTech UARTs, or one of
559  * its clones.  (We treat the broken original StarTech 16650 V1 as a
560  * 16550, and why not?  Startech doesn't seem to even acknowledge its
561  * existence.)
562  * 
563  * What evil have men's minds wrought...
564  */
565 static void autoconfig_has_efr(struct uart_8250_port *up)
566 {
567         unsigned int id1, id2, id3, rev;
568
569         /*
570          * Everything with an EFR has SLEEP
571          */
572         up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
573
574         /*
575          * First we check to see if it's an Oxford Semiconductor UART.
576          *
577          * If we have to do this here because some non-National
578          * Semiconductor clone chips lock up if you try writing to the
579          * LSR register (which serial_icr_read does)
580          */
581
582         /*
583          * Check for Oxford Semiconductor 16C950.
584          *
585          * EFR [4] must be set else this test fails.
586          *
587          * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca)
588          * claims that it's needed for 952 dual UART's (which are not
589          * recommended for new designs).
590          */
591         up->acr = 0;
592         serial_out(up, UART_LCR, 0xBF);
593         serial_out(up, UART_EFR, UART_EFR_ECB);
594         serial_out(up, UART_LCR, 0x00);
595         id1 = serial_icr_read(up, UART_ID1);
596         id2 = serial_icr_read(up, UART_ID2);
597         id3 = serial_icr_read(up, UART_ID3);
598         rev = serial_icr_read(up, UART_REV);
599
600         DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev);
601
602         if (id1 == 0x16 && id2 == 0xC9 &&
603             (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) {
604                 up->port.type = PORT_16C950;
605
606                 /*
607                  * Enable work around for the Oxford Semiconductor 952 rev B
608                  * chip which causes it to seriously miscalculate baud rates
609                  * when DLL is 0.
610                  */
611                 if (id3 == 0x52 && rev == 0x01)
612                         up->bugs |= UART_BUG_QUOT;
613                 return;
614         }
615         
616         /*
617          * We check for a XR16C850 by setting DLL and DLM to 0, and then
618          * reading back DLL and DLM.  The chip type depends on the DLM
619          * value read back:
620          *  0x10 - XR16C850 and the DLL contains the chip revision.
621          *  0x12 - XR16C2850.
622          *  0x14 - XR16C854.
623          */
624         id1 = autoconfig_read_divisor_id(up);
625         DEBUG_AUTOCONF("850id=%04x ", id1);
626
627         id2 = id1 >> 8;
628         if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) {
629                 up->port.type = PORT_16850;
630                 return;
631         }
632
633         /*
634          * It wasn't an XR16C850.
635          *
636          * We distinguish between the '654 and the '650 by counting
637          * how many bytes are in the FIFO.  I'm using this for now,
638          * since that's the technique that was sent to me in the
639          * serial driver update, but I'm not convinced this works.
640          * I've had problems doing this in the past.  -TYT
641          */
642         if (size_fifo(up) == 64)
643                 up->port.type = PORT_16654;
644         else
645                 up->port.type = PORT_16650V2;
646 }
647
648 /*
649  * We detected a chip without a FIFO.  Only two fall into
650  * this category - the original 8250 and the 16450.  The
651  * 16450 has a scratch register (accessible with LCR=0)
652  */
653 static void autoconfig_8250(struct uart_8250_port *up)
654 {
655         unsigned char scratch, status1, status2;
656
657         up->port.type = PORT_8250;
658
659         scratch = serial_in(up, UART_SCR);
660         serial_outp(up, UART_SCR, 0xa5);
661         status1 = serial_in(up, UART_SCR);
662         serial_outp(up, UART_SCR, 0x5a);
663         status2 = serial_in(up, UART_SCR);
664         serial_outp(up, UART_SCR, scratch);
665
666         if (status1 == 0xa5 && status2 == 0x5a)
667                 up->port.type = PORT_16450;
668 }
669
670 static int broken_efr(struct uart_8250_port *up)
671 {
672         /*
673          * Exar ST16C2550 "A2" devices incorrectly detect as
674          * having an EFR, and report an ID of 0x0201.  See
675          * http://www.exar.com/info.php?pdf=dan180_oct2004.pdf
676          */
677         if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16)
678                 return 1;
679
680         return 0;
681 }
682
683 /*
684  * We know that the chip has FIFOs.  Does it have an EFR?  The
685  * EFR is located in the same register position as the IIR and
686  * we know the top two bits of the IIR are currently set.  The
687  * EFR should contain zero.  Try to read the EFR.
688  */
689 static void autoconfig_16550a(struct uart_8250_port *up)
690 {
691         unsigned char status1, status2;
692         unsigned int iersave;
693
694         up->port.type = PORT_16550A;
695         up->capabilities |= UART_CAP_FIFO;
696
697         /*
698          * Check for presence of the EFR when DLAB is set.
699          * Only ST16C650V1 UARTs pass this test.
700          */
701         serial_outp(up, UART_LCR, UART_LCR_DLAB);
702         if (serial_in(up, UART_EFR) == 0) {
703                 serial_outp(up, UART_EFR, 0xA8);
704                 if (serial_in(up, UART_EFR) != 0) {
705                         DEBUG_AUTOCONF("EFRv1 ");
706                         up->port.type = PORT_16650;
707                         up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
708                 } else {
709                         DEBUG_AUTOCONF("Motorola 8xxx DUART ");
710                 }
711                 serial_outp(up, UART_EFR, 0);
712                 return;
713         }
714
715         /*
716          * Maybe it requires 0xbf to be written to the LCR.
717          * (other ST16C650V2 UARTs, TI16C752A, etc)
718          */
719         serial_outp(up, UART_LCR, 0xBF);
720         if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) {
721                 DEBUG_AUTOCONF("EFRv2 ");
722                 autoconfig_has_efr(up);
723                 return;
724         }
725
726         /*
727          * Check for a National Semiconductor SuperIO chip.
728          * Attempt to switch to bank 2, read the value of the LOOP bit
729          * from EXCR1. Switch back to bank 0, change it in MCR. Then
730          * switch back to bank 2, read it from EXCR1 again and check
731          * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2
732          */
733         serial_outp(up, UART_LCR, 0);
734         status1 = serial_in(up, UART_MCR);
735         serial_outp(up, UART_LCR, 0xE0);
736         status2 = serial_in(up, 0x02); /* EXCR1 */
737
738         if (!((status2 ^ status1) & UART_MCR_LOOP)) {
739                 serial_outp(up, UART_LCR, 0);
740                 serial_outp(up, UART_MCR, status1 ^ UART_MCR_LOOP);
741                 serial_outp(up, UART_LCR, 0xE0);
742                 status2 = serial_in(up, 0x02); /* EXCR1 */
743                 serial_outp(up, UART_LCR, 0);
744                 serial_outp(up, UART_MCR, status1);
745
746                 if ((status2 ^ status1) & UART_MCR_LOOP) {
747                         unsigned short quot;
748
749                         serial_outp(up, UART_LCR, 0xE0);
750
751                         quot = serial_inp(up, UART_DLM) << 8;
752                         quot += serial_inp(up, UART_DLL);
753                         quot <<= 3;
754
755                         status1 = serial_in(up, 0x04); /* EXCR1 */
756                         status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
757                         status1 |= 0x10;  /* 1.625 divisor for baud_base --> 921600 */
758                         serial_outp(up, 0x04, status1);
759                         
760                         serial_outp(up, UART_DLL, quot & 0xff);
761                         serial_outp(up, UART_DLM, quot >> 8);
762
763                         serial_outp(up, UART_LCR, 0);
764
765                         up->port.uartclk = 921600*16;
766                         up->port.type = PORT_NS16550A;
767                         up->capabilities |= UART_NATSEMI;
768                         return;
769                 }
770         }
771
772         /*
773          * No EFR.  Try to detect a TI16750, which only sets bit 5 of
774          * the IIR when 64 byte FIFO mode is enabled when DLAB is set.
775          * Try setting it with and without DLAB set.  Cheap clones
776          * set bit 5 without DLAB set.
777          */
778         serial_outp(up, UART_LCR, 0);
779         serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
780         status1 = serial_in(up, UART_IIR) >> 5;
781         serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
782         serial_outp(up, UART_LCR, UART_LCR_DLAB);
783         serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
784         status2 = serial_in(up, UART_IIR) >> 5;
785         serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
786         serial_outp(up, UART_LCR, 0);
787
788         DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);
789
790         if (status1 == 6 && status2 == 7) {
791                 up->port.type = PORT_16750;
792                 up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP;
793                 return;
794         }
795
796         /*
797          * Try writing and reading the UART_IER_UUE bit (b6).
798          * If it works, this is probably one of the Xscale platform's
799          * internal UARTs.
800          * We're going to explicitly set the UUE bit to 0 before
801          * trying to write and read a 1 just to make sure it's not
802          * already a 1 and maybe locked there before we even start start.
803          */
804         iersave = serial_in(up, UART_IER);
805         serial_outp(up, UART_IER, iersave & ~UART_IER_UUE);
806         if (!(serial_in(up, UART_IER) & UART_IER_UUE)) {
807                 /*
808                  * OK it's in a known zero state, try writing and reading
809                  * without disturbing the current state of the other bits.
810                  */
811                 serial_outp(up, UART_IER, iersave | UART_IER_UUE);
812                 if (serial_in(up, UART_IER) & UART_IER_UUE) {
813                         /*
814                          * It's an Xscale.
815                          * We'll leave the UART_IER_UUE bit set to 1 (enabled).
816                          */
817                         DEBUG_AUTOCONF("Xscale ");
818                         up->port.type = PORT_XSCALE;
819                         up->capabilities |= UART_CAP_UUE;
820                         return;
821                 }
822         } else {
823                 /*
824                  * If we got here we couldn't force the IER_UUE bit to 0.
825                  * Log it and continue.
826                  */
827                 DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
828         }
829         serial_outp(up, UART_IER, iersave);
830 }
831
832 /*
833  * This routine is called by rs_init() to initialize a specific serial
834  * port.  It determines what type of UART chip this serial port is
835  * using: 8250, 16450, 16550, 16550A.  The important question is
836  * whether or not this UART is a 16550A or not, since this will
837  * determine whether or not we can use its FIFO features or not.
838  */
839 static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
840 {
841         unsigned char status1, scratch, scratch2, scratch3;
842         unsigned char save_lcr, save_mcr;
843         unsigned long flags;
844
845         if (!up->port.iobase && !up->port.mapbase && !up->port.membase)
846                 return;
847
848         DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ",
849                         up->port.line, up->port.iobase, up->port.membase);
850
851         /*
852          * We really do need global IRQs disabled here - we're going to
853          * be frobbing the chips IRQ enable register to see if it exists.
854          */
855         spin_lock_irqsave(&up->port.lock, flags);
856 //      save_flags(flags); cli();
857
858         up->capabilities = 0;
859         up->bugs = 0;
860
861         if (!(up->port.flags & UPF_BUGGY_UART)) {
862                 /*
863                  * Do a simple existence test first; if we fail this,
864                  * there's no point trying anything else.
865                  * 
866                  * 0x80 is used as a nonsense port to prevent against
867                  * false positives due to ISA bus float.  The
868                  * assumption is that 0x80 is a non-existent port;
869                  * which should be safe since include/asm/io.h also
870                  * makes this assumption.
871                  *
872                  * Note: this is safe as long as MCR bit 4 is clear
873                  * and the device is in "PC" mode.
874                  */
875                 scratch = serial_inp(up, UART_IER);
876                 serial_outp(up, UART_IER, 0);
877 #ifdef __i386__
878                 outb(0xff, 0x080);
879 #endif
880                 scratch2 = serial_inp(up, UART_IER);
881                 serial_outp(up, UART_IER, 0x0F);
882 #ifdef __i386__
883                 outb(0, 0x080);
884 #endif
885                 scratch3 = serial_inp(up, UART_IER);
886                 serial_outp(up, UART_IER, scratch);
887                 if (scratch2 != 0 || scratch3 != 0x0F) {
888                         /*
889                          * We failed; there's nothing here
890                          */
891                         DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
892                                        scratch2, scratch3);
893                         goto out;
894                 }
895         }
896
897         save_mcr = serial_in(up, UART_MCR);
898         save_lcr = serial_in(up, UART_LCR);
899
900         /* 
901          * Check to see if a UART is really there.  Certain broken
902          * internal modems based on the Rockwell chipset fail this
903          * test, because they apparently don't implement the loopback
904          * test mode.  So this test is skipped on the COM 1 through
905          * COM 4 ports.  This *should* be safe, since no board
906          * manufacturer would be stupid enough to design a board
907          * that conflicts with COM 1-4 --- we hope!
908          */
909         if (!(up->port.flags & UPF_SKIP_TEST)) {
910                 serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);
911                 status1 = serial_inp(up, UART_MSR) & 0xF0;
912                 serial_outp(up, UART_MCR, save_mcr);
913                 if (status1 != 0x90) {
914                         DEBUG_AUTOCONF("LOOP test failed (%02x) ",
915                                        status1);
916                         goto out;
917                 }
918         }
919
920         /*
921          * We're pretty sure there's a port here.  Lets find out what
922          * type of port it is.  The IIR top two bits allows us to find
923          * out if it's 8250 or 16450, 16550, 16550A or later.  This
924          * determines what we test for next.
925          *
926          * We also initialise the EFR (if any) to zero for later.  The
927          * EFR occupies the same register location as the FCR and IIR.
928          */
929         serial_outp(up, UART_LCR, 0xBF);
930         serial_outp(up, UART_EFR, 0);
931         serial_outp(up, UART_LCR, 0);
932
933         serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
934         scratch = serial_in(up, UART_IIR) >> 6;
935
936         DEBUG_AUTOCONF("iir=%d ", scratch);
937
938         switch (scratch) {
939         case 0:
940                 autoconfig_8250(up);
941                 break;
942         case 1:
943                 up->port.type = PORT_UNKNOWN;
944                 break;
945         case 2:
946                 up->port.type = PORT_16550;
947                 break;
948         case 3:
949                 autoconfig_16550a(up);
950                 break;
951         }
952
953 #ifdef CONFIG_SERIAL_8250_RSA
954         /*
955          * Only probe for RSA ports if we got the region.
956          */
957         if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) {
958                 int i;
959
960                 for (i = 0 ; i < probe_rsa_count; ++i) {
961                         if (probe_rsa[i] == up->port.iobase &&
962                             __enable_rsa(up)) {
963                                 up->port.type = PORT_RSA;
964                                 break;
965                         }
966                 }
967         }
968 #endif
969
970 #ifdef CONFIG_SERIAL_8250_AU1X00
971         /* if access method is AU, it is a 16550 with a quirk */
972         if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU)
973                 up->bugs |= UART_BUG_NOMSR;
974 #endif
975
976         serial_outp(up, UART_LCR, save_lcr);
977
978         if (up->capabilities != uart_config[up->port.type].flags) {
979                 printk(KERN_WARNING
980                        "ttyS%d: detected caps %08x should be %08x\n",
981                         up->port.line, up->capabilities,
982                         uart_config[up->port.type].flags);
983         }
984
985         up->port.fifosize = uart_config[up->port.type].fifo_size;
986         up->capabilities = uart_config[up->port.type].flags;
987         up->tx_loadsz = uart_config[up->port.type].tx_loadsz;
988
989         if (up->port.type == PORT_UNKNOWN)
990                 goto out;
991
992         /*
993          * Reset the UART.
994          */
995 #ifdef CONFIG_SERIAL_8250_RSA
996         if (up->port.type == PORT_RSA)
997                 serial_outp(up, UART_RSA_FRR, 0);
998 #endif
999         serial_outp(up, UART_MCR, save_mcr);
1000         serial8250_clear_fifos(up);
1001         (void)serial_in(up, UART_RX);
1002         serial_outp(up, UART_IER, 0);
1003
1004  out:   
1005         spin_unlock_irqrestore(&up->port.lock, flags);
1006 //      restore_flags(flags);
1007         DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name);
1008 }
1009
1010 static void autoconfig_irq(struct uart_8250_port *up)
1011 {
1012         unsigned char save_mcr, save_ier;
1013         unsigned char save_ICP = 0;
1014         unsigned int ICP = 0;
1015         unsigned long irqs;
1016         int irq;
1017
1018         if (up->port.flags & UPF_FOURPORT) {
1019                 ICP = (up->port.iobase & 0xfe0) | 0x1f;
1020                 save_ICP = inb_p(ICP);
1021                 outb_p(0x80, ICP);
1022                 (void) inb_p(ICP);
1023         }
1024
1025         /* forget possible initially masked and pending IRQ */
1026         probe_irq_off(probe_irq_on());
1027         save_mcr = serial_inp(up, UART_MCR);
1028         save_ier = serial_inp(up, UART_IER);
1029         serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);
1030         
1031         irqs = probe_irq_on();
1032         serial_outp(up, UART_MCR, 0);
1033         udelay (10);
1034         if (up->port.flags & UPF_FOURPORT)  {
1035                 serial_outp(up, UART_MCR,
1036                             UART_MCR_DTR | UART_MCR_RTS);
1037         } else {
1038                 serial_outp(up, UART_MCR,
1039                             UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
1040         }
1041         serial_outp(up, UART_IER, 0x0f);        /* enable all intrs */
1042         (void)serial_inp(up, UART_LSR);
1043         (void)serial_inp(up, UART_RX);
1044         (void)serial_inp(up, UART_IIR);
1045         (void)serial_inp(up, UART_MSR);
1046         serial_outp(up, UART_TX, 0xFF);
1047         udelay (20);
1048         irq = probe_irq_off(irqs);
1049
1050         serial_outp(up, UART_MCR, save_mcr);
1051         serial_outp(up, UART_IER, save_ier);
1052
1053         if (up->port.flags & UPF_FOURPORT)
1054                 outb_p(save_ICP, ICP);
1055
1056         up->port.irq = (irq > 0) ? irq : 0;
1057 }
1058
1059 static inline void __stop_tx(struct uart_8250_port *p)
1060 {
1061         if (p->ier & UART_IER_THRI) {
1062                 p->ier &= ~UART_IER_THRI;
1063                 serial_out(p, UART_IER, p->ier);
1064         }
1065 }
1066
1067 static void serial8250_stop_tx(struct uart_port *port)
1068 {
1069         struct uart_8250_port *up = (struct uart_8250_port *)port;
1070
1071         __stop_tx(up);
1072
1073         /*
1074          * We really want to stop the transmitter from sending.
1075          */
1076         if (up->port.type == PORT_16C950) {
1077                 up->acr |= UART_ACR_TXDIS;
1078                 serial_icr_write(up, UART_ACR, up->acr);
1079         }
1080 }
1081
1082 static void transmit_chars(struct uart_8250_port *up);
1083
1084 static void serial8250_start_tx(struct uart_port *port)
1085 {
1086         struct uart_8250_port *up = (struct uart_8250_port *)port;
1087
1088         if (!(up->ier & UART_IER_THRI)) {
1089                 up->ier |= UART_IER_THRI;
1090                 serial_out(up, UART_IER, up->ier);
1091
1092                 if (up->bugs & UART_BUG_TXEN) {
1093                         unsigned char lsr, iir;
1094                         lsr = serial_in(up, UART_LSR);
1095                         iir = serial_in(up, UART_IIR);
1096                         if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT)
1097                                 transmit_chars(up);
1098                 }
1099         }
1100
1101         /*
1102          * Re-enable the transmitter if we disabled it.
1103          */
1104         if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
1105                 up->acr &= ~UART_ACR_TXDIS;
1106                 serial_icr_write(up, UART_ACR, up->acr);
1107         }
1108 }
1109
1110 static void serial8250_stop_rx(struct uart_port *port)
1111 {
1112         struct uart_8250_port *up = (struct uart_8250_port *)port;
1113
1114         up->ier &= ~UART_IER_RLSI;
1115         up->port.read_status_mask &= ~UART_LSR_DR;
1116         serial_out(up, UART_IER, up->ier);
1117 }
1118
1119 static void serial8250_enable_ms(struct uart_port *port)
1120 {
1121         struct uart_8250_port *up = (struct uart_8250_port *)port;
1122
1123         /* no MSR capabilities */
1124         if (up->bugs & UART_BUG_NOMSR)
1125                 return;
1126
1127         up->ier |= UART_IER_MSI;
1128         serial_out(up, UART_IER, up->ier);
1129 }
1130
1131 static _INLINE_ void
1132 receive_chars(struct uart_8250_port *up, int *status, struct pt_regs *regs)
1133 {
1134         struct tty_struct *tty = up->port.info->tty;
1135         unsigned char ch, lsr = *status;
1136         int max_count = 256;
1137         char flag;
1138
1139         do {
1140                 /* The following is not allowed by the tty layer and
1141                    unsafe. It should be fixed ASAP */
1142                 if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
1143                         if (tty->low_latency) {
1144                                 spin_unlock(&up->port.lock);
1145                                 tty_flip_buffer_push(tty);
1146                                 spin_lock(&up->port.lock);
1147                         }
1148                         /*
1149                          * If this failed then we will throw away the
1150                          * bytes but must do so to clear interrupts
1151                          */
1152                 }
1153                 ch = serial_inp(up, UART_RX);
1154                 flag = TTY_NORMAL;
1155                 up->port.icount.rx++;
1156
1157 #ifdef CONFIG_SERIAL_8250_CONSOLE
1158                 /*
1159                  * Recover the break flag from console xmit
1160                  */
1161                 if (up->port.line == up->port.cons->index) {
1162                         lsr |= up->lsr_break_flag;
1163                         up->lsr_break_flag = 0;
1164                 }
1165 #endif
1166
1167                 if (unlikely(lsr & (UART_LSR_BI | UART_LSR_PE |
1168                                     UART_LSR_FE | UART_LSR_OE))) {
1169                         /*
1170                          * For statistics only
1171                          */
1172                         if (lsr & UART_LSR_BI) {
1173                                 lsr &= ~(UART_LSR_FE | UART_LSR_PE);
1174                                 up->port.icount.brk++;
1175                                 /*
1176                                  * We do the SysRQ and SAK checking
1177                                  * here because otherwise the break
1178                                  * may get masked by ignore_status_mask
1179                                  * or read_status_mask.
1180                                  */
1181                                 if (uart_handle_break(&up->port))
1182                                         goto ignore_char;
1183                         } else if (lsr & UART_LSR_PE)
1184                                 up->port.icount.parity++;
1185                         else if (lsr & UART_LSR_FE)
1186                                 up->port.icount.frame++;
1187                         if (lsr & UART_LSR_OE)
1188                                 up->port.icount.overrun++;
1189
1190                         /*
1191                          * Mask off conditions which should be ignored.
1192                          */
1193                         lsr &= up->port.read_status_mask;
1194
1195                         if (lsr & UART_LSR_BI) {
1196                                 DEBUG_INTR("handling break....");
1197                                 flag = TTY_BREAK;
1198                         } else if (lsr & UART_LSR_PE)
1199                                 flag = TTY_PARITY;
1200                         else if (lsr & UART_LSR_FE)
1201                                 flag = TTY_FRAME;
1202                 }
1203                 if (uart_handle_sysrq_char(&up->port, ch, regs))
1204                         goto ignore_char;
1205
1206                 uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
1207
1208         ignore_char:
1209                 lsr = serial_inp(up, UART_LSR);
1210         } while ((lsr & UART_LSR_DR) && (max_count-- > 0));
1211         spin_unlock(&up->port.lock);
1212         tty_flip_buffer_push(tty);
1213         spin_lock(&up->port.lock);
1214         *status = lsr;
1215 }
1216
1217 static _INLINE_ void transmit_chars(struct uart_8250_port *up)
1218 {
1219         struct circ_buf *xmit = &up->port.info->xmit;
1220         int count;
1221
1222         if (up->port.x_char) {
1223                 serial_outp(up, UART_TX, up->port.x_char);
1224                 up->port.icount.tx++;
1225                 up->port.x_char = 0;
1226                 return;
1227         }
1228         if (uart_tx_stopped(&up->port)) {
1229                 serial8250_stop_tx(&up->port);
1230                 return;
1231         }
1232         if (uart_circ_empty(xmit)) {
1233                 __stop_tx(up);
1234                 return;
1235         }
1236
1237         count = up->tx_loadsz;
1238         do {
1239                 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
1240                 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
1241                 up->port.icount.tx++;
1242                 if (uart_circ_empty(xmit))
1243                         break;
1244         } while (--count > 0);
1245
1246         if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
1247                 uart_write_wakeup(&up->port);
1248
1249         DEBUG_INTR("THRE...");
1250
1251         if (uart_circ_empty(xmit))
1252                 __stop_tx(up);
1253 }
1254
1255 static _INLINE_ void check_modem_status(struct uart_8250_port *up)
1256 {
1257         int status;
1258
1259         status = serial_in(up, UART_MSR);
1260
1261         if ((status & UART_MSR_ANY_DELTA) == 0)
1262                 return;
1263
1264         if (status & UART_MSR_TERI)
1265                 up->port.icount.rng++;
1266         if (status & UART_MSR_DDSR)
1267                 up->port.icount.dsr++;
1268         if (status & UART_MSR_DDCD)
1269                 uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
1270         if (status & UART_MSR_DCTS)
1271                 uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
1272
1273         wake_up_interruptible(&up->port.info->delta_msr_wait);
1274 }
1275
1276 /*
1277  * This handles the interrupt from one port.
1278  */
1279 static inline void
1280 serial8250_handle_port(struct uart_8250_port *up, struct pt_regs *regs)
1281 {
1282         unsigned int status = serial_inp(up, UART_LSR);
1283
1284         DEBUG_INTR("status = %x...", status);
1285
1286         if (status & UART_LSR_DR)
1287                 receive_chars(up, &status, regs);
1288         check_modem_status(up);
1289         if (status & UART_LSR_THRE)
1290                 transmit_chars(up);
1291 }
1292
1293 /*
1294  * This is the serial driver's interrupt routine.
1295  *
1296  * Arjan thinks the old way was overly complex, so it got simplified.
1297  * Alan disagrees, saying that need the complexity to handle the weird
1298  * nature of ISA shared interrupts.  (This is a special exception.)
1299  *
1300  * In order to handle ISA shared interrupts properly, we need to check
1301  * that all ports have been serviced, and therefore the ISA interrupt
1302  * line has been de-asserted.
1303  *
1304  * This means we need to loop through all ports. checking that they
1305  * don't have an interrupt pending.
1306  */
1307 static irqreturn_t serial8250_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1308 {
1309         struct irq_info *i = dev_id;
1310         struct list_head *l, *end = NULL;
1311         int pass_counter = 0, handled = 0;
1312
1313         DEBUG_INTR("serial8250_interrupt(%d)...", irq);
1314
1315         spin_lock(&i->lock);
1316
1317         l = i->head;
1318         do {
1319                 struct uart_8250_port *up;
1320                 unsigned int iir;
1321
1322                 up = list_entry(l, struct uart_8250_port, list);
1323
1324                 iir = serial_in(up, UART_IIR);
1325                 if (!(iir & UART_IIR_NO_INT)) {
1326                         spin_lock(&up->port.lock);
1327                         serial8250_handle_port(up, regs);
1328                         spin_unlock(&up->port.lock);
1329
1330                         handled = 1;
1331
1332                         end = NULL;
1333                 } else if (end == NULL)
1334                         end = l;
1335
1336                 l = l->next;
1337
1338                 if (l == i->head && pass_counter++ > PASS_LIMIT) {
1339                         /* If we hit this, we're dead. */
1340                         printk(KERN_ERR "serial8250: too much work for "
1341                                 "irq%d\n", irq);
1342                         break;
1343                 }
1344         } while (l != end);
1345
1346         spin_unlock(&i->lock);
1347
1348         DEBUG_INTR("end.\n");
1349
1350         //return IRQ_RETVAL(handled);
1351         return IRQ_HANDLED;     /* FIXME: iir status not ready on 1510 */
1352 }
1353
1354 /*
1355  * To support ISA shared interrupts, we need to have one interrupt
1356  * handler that ensures that the IRQ line has been deasserted
1357  * before returning.  Failing to do this will result in the IRQ
1358  * line being stuck active, and, since ISA irqs are edge triggered,
1359  * no more IRQs will be seen.
1360  */
1361 static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
1362 {
1363         spin_lock_irq(&i->lock);
1364
1365         if (!list_empty(i->head)) {
1366                 if (i->head == &up->list)
1367                         i->head = i->head->next;
1368                 list_del(&up->list);
1369         } else {
1370                 BUG_ON(i->head != &up->list);
1371                 i->head = NULL;
1372         }
1373
1374         spin_unlock_irq(&i->lock);
1375 }
1376
1377 static int serial_link_irq_chain(struct uart_8250_port *up)
1378 {
1379         struct irq_info *i = irq_lists + up->port.irq;
1380         int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? SA_SHIRQ : 0;
1381
1382         spin_lock_irq(&i->lock);
1383
1384         if (i->head) {
1385                 list_add(&up->list, i->head);
1386                 spin_unlock_irq(&i->lock);
1387
1388                 ret = 0;
1389         } else {
1390                 INIT_LIST_HEAD(&up->list);
1391                 i->head = &up->list;
1392                 spin_unlock_irq(&i->lock);
1393
1394                 ret = request_irq(up->port.irq, serial8250_interrupt,
1395                                   irq_flags, "serial", i);
1396                 if (ret < 0)
1397                         serial_do_unlink(i, up);
1398         }
1399
1400         return ret;
1401 }
1402
1403 static void serial_unlink_irq_chain(struct uart_8250_port *up)
1404 {
1405         struct irq_info *i = irq_lists + up->port.irq;
1406
1407         BUG_ON(i->head == NULL);
1408
1409         if (list_empty(i->head))
1410                 free_irq(up->port.irq, i);
1411
1412         serial_do_unlink(i, up);
1413 }
1414
1415 /*
1416  * This function is used to handle ports that do not have an
1417  * interrupt.  This doesn't work very well for 16450's, but gives
1418  * barely passable results for a 16550A.  (Although at the expense
1419  * of much CPU overhead).
1420  */
1421 static void serial8250_timeout(unsigned long data)
1422 {
1423         struct uart_8250_port *up = (struct uart_8250_port *)data;
1424         unsigned int timeout;
1425         unsigned int iir;
1426
1427         iir = serial_in(up, UART_IIR);
1428         if (!(iir & UART_IIR_NO_INT)) {
1429                 spin_lock(&up->port.lock);
1430                 serial8250_handle_port(up, NULL);
1431                 spin_unlock(&up->port.lock);
1432         }
1433
1434         timeout = up->port.timeout;
1435         timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
1436         mod_timer(&up->timer, jiffies + timeout);
1437 }
1438
1439 static unsigned int serial8250_tx_empty(struct uart_port *port)
1440 {
1441         struct uart_8250_port *up = (struct uart_8250_port *)port;
1442         unsigned long flags;
1443         unsigned int ret;
1444
1445         spin_lock_irqsave(&up->port.lock, flags);
1446         ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
1447         spin_unlock_irqrestore(&up->port.lock, flags);
1448
1449         return ret;
1450 }
1451
1452 static unsigned int serial8250_get_mctrl(struct uart_port *port)
1453 {
1454         struct uart_8250_port *up = (struct uart_8250_port *)port;
1455         unsigned char status;
1456         unsigned int ret;
1457
1458         status = serial_in(up, UART_MSR);
1459
1460         ret = 0;
1461         if (status & UART_MSR_DCD)
1462                 ret |= TIOCM_CAR;
1463         if (status & UART_MSR_RI)
1464                 ret |= TIOCM_RNG;
1465         if (status & UART_MSR_DSR)
1466                 ret |= TIOCM_DSR;
1467         if (status & UART_MSR_CTS)
1468                 ret |= TIOCM_CTS;
1469         return ret;
1470 }
1471
1472 static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
1473 {
1474         struct uart_8250_port *up = (struct uart_8250_port *)port;
1475         unsigned char mcr = 0;
1476
1477         if (mctrl & TIOCM_RTS)
1478                 mcr |= UART_MCR_RTS;
1479         if (mctrl & TIOCM_DTR)
1480                 mcr |= UART_MCR_DTR;
1481         if (mctrl & TIOCM_OUT1)
1482                 mcr |= UART_MCR_OUT1;
1483         if (mctrl & TIOCM_OUT2)
1484                 mcr |= UART_MCR_OUT2;
1485         if (mctrl & TIOCM_LOOP)
1486                 mcr |= UART_MCR_LOOP;
1487
1488         mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr;
1489
1490         serial_out(up, UART_MCR, mcr);
1491 }
1492
1493 static void serial8250_break_ctl(struct uart_port *port, int break_state)
1494 {
1495         struct uart_8250_port *up = (struct uart_8250_port *)port;
1496         unsigned long flags;
1497
1498         spin_lock_irqsave(&up->port.lock, flags);
1499         if (break_state == -1)
1500                 up->lcr |= UART_LCR_SBC;
1501         else
1502                 up->lcr &= ~UART_LCR_SBC;
1503         serial_out(up, UART_LCR, up->lcr);
1504         spin_unlock_irqrestore(&up->port.lock, flags);
1505 }
1506
1507 static int serial8250_startup(struct uart_port *port)
1508 {
1509         struct uart_8250_port *up = (struct uart_8250_port *)port;
1510         unsigned long flags;
1511         unsigned char lsr, iir;
1512         int retval;
1513
1514         up->capabilities = uart_config[up->port.type].flags;
1515         up->mcr = 0;
1516
1517         if (up->port.type == PORT_16C950) {
1518                 /* Wake up and initialize UART */
1519                 up->acr = 0;
1520                 serial_outp(up, UART_LCR, 0xBF);
1521                 serial_outp(up, UART_EFR, UART_EFR_ECB);
1522                 serial_outp(up, UART_IER, 0);
1523                 serial_outp(up, UART_LCR, 0);
1524                 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
1525                 serial_outp(up, UART_LCR, 0xBF);
1526                 serial_outp(up, UART_EFR, UART_EFR_ECB);
1527                 serial_outp(up, UART_LCR, 0);
1528         }
1529
1530 #ifdef CONFIG_SERIAL_8250_RSA
1531         /*
1532          * If this is an RSA port, see if we can kick it up to the
1533          * higher speed clock.
1534          */
1535         enable_rsa(up);
1536 #endif
1537
1538         /*
1539          * Clear the FIFO buffers and disable them.
1540          * (they will be reeanbled in set_termios())
1541          */
1542         serial8250_clear_fifos(up);
1543
1544         /*
1545          * Clear the interrupt registers.
1546          */
1547         (void) serial_inp(up, UART_LSR);
1548         (void) serial_inp(up, UART_RX);
1549         (void) serial_inp(up, UART_IIR);
1550         (void) serial_inp(up, UART_MSR);
1551
1552         /*
1553          * At this point, there's no way the LSR could still be 0xff;
1554          * if it is, then bail out, because there's likely no UART
1555          * here.
1556          */
1557         if (!(up->port.flags & UPF_BUGGY_UART) &&
1558             (serial_inp(up, UART_LSR) == 0xff)) {
1559                 printk("ttyS%d: LSR safety check engaged!\n", up->port.line);
1560                 return -ENODEV;
1561         }
1562
1563         /*
1564          * For a XR16C850, we need to set the trigger levels
1565          */
1566         if (up->port.type == PORT_16850) {
1567                 unsigned char fctr;
1568
1569                 serial_outp(up, UART_LCR, 0xbf);
1570
1571                 fctr = serial_inp(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
1572                 serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX);
1573                 serial_outp(up, UART_TRG, UART_TRG_96);
1574                 serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX);
1575                 serial_outp(up, UART_TRG, UART_TRG_96);
1576
1577                 serial_outp(up, UART_LCR, 0);
1578         }
1579
1580         /*
1581          * If the "interrupt" for this port doesn't correspond with any
1582          * hardware interrupt, we use a timer-based system.  The original
1583          * driver used to do this with IRQ0.
1584          */
1585         if (!is_real_interrupt(up->port.irq)) {
1586                 unsigned int timeout = up->port.timeout;
1587
1588                 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
1589
1590                 up->timer.data = (unsigned long)up;
1591                 mod_timer(&up->timer, jiffies + timeout);
1592         } else {
1593                 retval = serial_link_irq_chain(up);
1594                 if (retval)
1595                         return retval;
1596         }
1597
1598         /*
1599          * Now, initialize the UART
1600          */
1601         serial_outp(up, UART_LCR, UART_LCR_WLEN8);
1602
1603         spin_lock_irqsave(&up->port.lock, flags);
1604         if (up->port.flags & UPF_FOURPORT) {
1605                 if (!is_real_interrupt(up->port.irq))
1606                         up->port.mctrl |= TIOCM_OUT1;
1607         } else
1608                 /*
1609                  * Most PC uarts need OUT2 raised to enable interrupts.
1610                  */
1611                 if (is_real_interrupt(up->port.irq))
1612                         up->port.mctrl |= TIOCM_OUT2;
1613
1614         serial8250_set_mctrl(&up->port, up->port.mctrl);
1615
1616         /*
1617          * Do a quick test to see if we receive an
1618          * interrupt when we enable the TX irq.
1619          */
1620         serial_outp(up, UART_IER, UART_IER_THRI);
1621         lsr = serial_in(up, UART_LSR);
1622         iir = serial_in(up, UART_IIR);
1623         serial_outp(up, UART_IER, 0);
1624
1625         if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
1626                 if (!(up->bugs & UART_BUG_TXEN)) {
1627                         up->bugs |= UART_BUG_TXEN;
1628                         pr_debug("ttyS%d - enabling bad tx status workarounds\n",
1629                                  port->line);
1630                 }
1631         } else {
1632                 up->bugs &= ~UART_BUG_TXEN;
1633         }
1634
1635         spin_unlock_irqrestore(&up->port.lock, flags);
1636
1637         /*
1638          * Finally, enable interrupts.  Note: Modem status interrupts
1639          * are set via set_termios(), which will be occurring imminently
1640          * anyway, so we don't enable them here.
1641          */
1642         up->ier = UART_IER_RLSI | UART_IER_RDI;
1643         serial_outp(up, UART_IER, up->ier);
1644
1645         if (up->port.flags & UPF_FOURPORT) {
1646                 unsigned int icp;
1647                 /*
1648                  * Enable interrupts on the AST Fourport board
1649                  */
1650                 icp = (up->port.iobase & 0xfe0) | 0x01f;
1651                 outb_p(0x80, icp);
1652                 (void) inb_p(icp);
1653         }
1654
1655         /*
1656          * And clear the interrupt registers again for luck.
1657          */
1658         (void) serial_inp(up, UART_LSR);
1659         (void) serial_inp(up, UART_RX);
1660         (void) serial_inp(up, UART_IIR);
1661         (void) serial_inp(up, UART_MSR);
1662
1663         return 0;
1664 }
1665
1666 static void serial8250_shutdown(struct uart_port *port)
1667 {
1668         struct uart_8250_port *up = (struct uart_8250_port *)port;
1669         unsigned long flags;
1670
1671         /*
1672          * Disable interrupts from this port
1673          */
1674         up->ier = 0;
1675         serial_outp(up, UART_IER, 0);
1676
1677         spin_lock_irqsave(&up->port.lock, flags);
1678         if (up->port.flags & UPF_FOURPORT) {
1679                 /* reset interrupts on the AST Fourport board */
1680                 inb((up->port.iobase & 0xfe0) | 0x1f);
1681                 up->port.mctrl |= TIOCM_OUT1;
1682         } else
1683                 up->port.mctrl &= ~TIOCM_OUT2;
1684
1685         serial8250_set_mctrl(&up->port, up->port.mctrl);
1686         spin_unlock_irqrestore(&up->port.lock, flags);
1687
1688         /*
1689          * Disable break condition and FIFOs
1690          */
1691         serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
1692         serial8250_clear_fifos(up);
1693
1694 #ifdef CONFIG_SERIAL_8250_RSA
1695         /*
1696          * Reset the RSA board back to 115kbps compat mode.
1697          */
1698         disable_rsa(up);
1699 #endif
1700
1701         /*
1702          * Read data port to reset things, and then unlink from
1703          * the IRQ chain.
1704          */
1705         (void) serial_in(up, UART_RX);
1706
1707         if (!is_real_interrupt(up->port.irq))
1708                 del_timer_sync(&up->timer);
1709         else
1710                 serial_unlink_irq_chain(up);
1711 }
1712
1713 static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud)
1714 {
1715         unsigned int quot;
1716
1717         /*
1718          * Handle magic divisors for baud rates above baud_base on
1719          * SMSC SuperIO chips.
1720          */
1721         if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
1722             baud == (port->uartclk/4))
1723                 quot = 0x8001;
1724         else if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
1725                  baud == (port->uartclk/8))
1726                 quot = 0x8002;
1727         else
1728                 quot = uart_get_divisor(port, baud);
1729
1730         return quot;
1731 }
1732
1733 static void
1734 serial8250_set_termios(struct uart_port *port, struct termios *termios,
1735                        struct termios *old)
1736 {
1737         struct uart_8250_port *up = (struct uart_8250_port *)port;
1738         unsigned char cval, fcr = 0;
1739         unsigned long flags;
1740         unsigned int baud, quot;
1741
1742         switch (termios->c_cflag & CSIZE) {
1743         case CS5:
1744                 cval = UART_LCR_WLEN5;
1745                 break;
1746         case CS6:
1747                 cval = UART_LCR_WLEN6;
1748                 break;
1749         case CS7:
1750                 cval = UART_LCR_WLEN7;
1751                 break;
1752         default:
1753         case CS8:
1754                 cval = UART_LCR_WLEN8;
1755                 break;
1756         }
1757
1758         if (termios->c_cflag & CSTOPB)
1759                 cval |= UART_LCR_STOP;
1760         if (termios->c_cflag & PARENB)
1761                 cval |= UART_LCR_PARITY;
1762         if (!(termios->c_cflag & PARODD))
1763                 cval |= UART_LCR_EPAR;
1764 #ifdef CMSPAR
1765         if (termios->c_cflag & CMSPAR)
1766                 cval |= UART_LCR_SPAR;
1767 #endif
1768
1769         /*
1770          * Ask the core to calculate the divisor for us.
1771          */
1772         baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); 
1773         quot = serial8250_get_divisor(port, baud);
1774
1775         /*
1776          * Oxford Semi 952 rev B workaround
1777          */
1778         if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0)
1779                 quot ++;
1780
1781         if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) {
1782                 if (baud < 2400)
1783                         fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
1784                 else
1785                         fcr = uart_config[up->port.type].fcr;
1786         }
1787
1788         /*
1789          * MCR-based auto flow control.  When AFE is enabled, RTS will be
1790          * deasserted when the receive FIFO contains more characters than
1791          * the trigger, or the MCR RTS bit is cleared.  In the case where
1792          * the remote UART is not using CTS auto flow control, we must
1793          * have sufficient FIFO entries for the latency of the remote
1794          * UART to respond.  IOW, at least 32 bytes of FIFO.
1795          */
1796         if (up->capabilities & UART_CAP_AFE && up->port.fifosize >= 32) {
1797                 up->mcr &= ~UART_MCR_AFE;
1798                 if (termios->c_cflag & CRTSCTS)
1799                         up->mcr |= UART_MCR_AFE;
1800         }
1801
1802         /*
1803          * Ok, we're now changing the port state.  Do it with
1804          * interrupts disabled.
1805          */
1806         spin_lock_irqsave(&up->port.lock, flags);
1807
1808         /*
1809          * Update the per-port timeout.
1810          */
1811         uart_update_timeout(port, termios->c_cflag, baud);
1812
1813         up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
1814         if (termios->c_iflag & INPCK)
1815                 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1816         if (termios->c_iflag & (BRKINT | PARMRK))
1817                 up->port.read_status_mask |= UART_LSR_BI;
1818
1819         /*
1820          * Characteres to ignore
1821          */
1822         up->port.ignore_status_mask = 0;
1823         if (termios->c_iflag & IGNPAR)
1824                 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
1825         if (termios->c_iflag & IGNBRK) {
1826                 up->port.ignore_status_mask |= UART_LSR_BI;
1827                 /*
1828                  * If we're ignoring parity and break indicators,
1829                  * ignore overruns too (for real raw support).
1830                  */
1831                 if (termios->c_iflag & IGNPAR)
1832                         up->port.ignore_status_mask |= UART_LSR_OE;
1833         }
1834
1835         /*
1836          * ignore all characters if CREAD is not set
1837          */
1838         if ((termios->c_cflag & CREAD) == 0)
1839                 up->port.ignore_status_mask |= UART_LSR_DR;
1840
1841         /*
1842          * CTS flow control flag and modem status interrupts
1843          */
1844         up->ier &= ~UART_IER_MSI;
1845         if (!(up->bugs & UART_BUG_NOMSR) &&
1846                         UART_ENABLE_MS(&up->port, termios->c_cflag))
1847                 up->ier |= UART_IER_MSI;
1848         if (up->capabilities & UART_CAP_UUE)
1849                 up->ier |= UART_IER_UUE | UART_IER_RTOIE;
1850
1851         serial_out(up, UART_IER, up->ier);
1852
1853         if (up->capabilities & UART_CAP_EFR) {
1854                 unsigned char efr = 0;
1855                 /*
1856                  * TI16C752/Startech hardware flow control.  FIXME:
1857                  * - TI16C752 requires control thresholds to be set.
1858                  * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
1859                  */
1860                 if (termios->c_cflag & CRTSCTS)
1861                         efr |= UART_EFR_CTS;
1862
1863                 serial_outp(up, UART_LCR, 0xBF);
1864                 serial_outp(up, UART_EFR, efr);
1865         }
1866
1867 #ifdef CONFIG_ARCH_OMAP15XX
1868         /* Workaround to enable 115200 baud on OMAP1510 internal ports */
1869         if (cpu_is_omap1510() && is_omap_port((unsigned int)up->port.membase)) {
1870                 if (baud == 115200) {
1871                         quot = 1;
1872                         serial_out(up, UART_OMAP_OSC_12M_SEL, 1);
1873                 } else
1874                         serial_out(up, UART_OMAP_OSC_12M_SEL, 0);
1875         }
1876 #endif
1877
1878         if (up->capabilities & UART_NATSEMI) {
1879                 /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */
1880                 serial_outp(up, UART_LCR, 0xe0);
1881         } else {
1882                 serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
1883         }
1884
1885         serial_outp(up, UART_DLL, quot & 0xff);         /* LS of divisor */
1886         serial_outp(up, UART_DLM, quot >> 8);           /* MS of divisor */
1887
1888         /*
1889          * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
1890          * is written without DLAB set, this mode will be disabled.
1891          */
1892         if (up->port.type == PORT_16750)
1893                 serial_outp(up, UART_FCR, fcr);
1894
1895         serial_outp(up, UART_LCR, cval);                /* reset DLAB */
1896         up->lcr = cval;                                 /* Save LCR */
1897         if (up->port.type != PORT_16750) {
1898                 if (fcr & UART_FCR_ENABLE_FIFO) {
1899                         /* emulated UARTs (Lucent Venus 167x) need two steps */
1900                         serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
1901                 }
1902                 serial_outp(up, UART_FCR, fcr);         /* set fcr */
1903         }
1904         serial8250_set_mctrl(&up->port, up->port.mctrl);
1905         spin_unlock_irqrestore(&up->port.lock, flags);
1906 }
1907
1908 static void
1909 serial8250_pm(struct uart_port *port, unsigned int state,
1910               unsigned int oldstate)
1911 {
1912         struct uart_8250_port *p = (struct uart_8250_port *)port;
1913
1914         serial8250_set_sleep(p, state != 0);
1915
1916         if (p->pm)
1917                 p->pm(port, state, oldstate);
1918 }
1919
1920 /*
1921  * Resource handling.
1922  */
1923 static int serial8250_request_std_resource(struct uart_8250_port *up)
1924 {
1925         unsigned int size = 8 << up->port.regshift;
1926         int ret = 0;
1927
1928 #ifdef CONFIG_ARCH_OMAP
1929         if (is_omap_port((unsigned int)up->port.membase))
1930                 size = 0x16 << up->port.regshift;
1931 #endif
1932
1933         switch (up->port.iotype) {
1934         case UPIO_MEM:
1935                 if (!up->port.mapbase)
1936                         break;
1937
1938                 if (!request_mem_region(up->port.mapbase, size, "serial")) {
1939                         ret = -EBUSY;
1940                         break;
1941                 }
1942
1943                 if (up->port.flags & UPF_IOREMAP) {
1944                         up->port.membase = ioremap(up->port.mapbase, size);
1945                         if (!up->port.membase) {
1946                                 release_mem_region(up->port.mapbase, size);
1947                                 ret = -ENOMEM;
1948                         }
1949                 }
1950                 break;
1951
1952         case UPIO_HUB6:
1953         case UPIO_PORT:
1954                 if (!request_region(up->port.iobase, size, "serial"))
1955                         ret = -EBUSY;
1956                 break;
1957         }
1958         return ret;
1959 }
1960
1961 static void serial8250_release_std_resource(struct uart_8250_port *up)
1962 {
1963         unsigned int size = 8 << up->port.regshift;
1964
1965         switch (up->port.iotype) {
1966         case UPIO_MEM:
1967                 if (!up->port.mapbase)
1968                         break;
1969
1970                 if (up->port.flags & UPF_IOREMAP) {
1971                         iounmap(up->port.membase);
1972                         up->port.membase = NULL;
1973                 }
1974
1975                 release_mem_region(up->port.mapbase, size);
1976                 break;
1977
1978         case UPIO_HUB6:
1979         case UPIO_PORT:
1980                 release_region(up->port.iobase, size);
1981                 break;
1982         }
1983 }
1984
1985 static int serial8250_request_rsa_resource(struct uart_8250_port *up)
1986 {
1987         unsigned long start = UART_RSA_BASE << up->port.regshift;
1988         unsigned int size = 8 << up->port.regshift;
1989         int ret = 0;
1990
1991         switch (up->port.iotype) {
1992         case UPIO_MEM:
1993                 ret = -EINVAL;
1994                 break;
1995
1996         case UPIO_HUB6:
1997         case UPIO_PORT:
1998                 start += up->port.iobase;
1999                 if (!request_region(start, size, "serial-rsa"))
2000                         ret = -EBUSY;
2001                 break;
2002         }
2003
2004         return ret;
2005 }
2006
2007 static void serial8250_release_rsa_resource(struct uart_8250_port *up)
2008 {
2009         unsigned long offset = UART_RSA_BASE << up->port.regshift;
2010         unsigned int size = 8 << up->port.regshift;
2011
2012         switch (up->port.iotype) {
2013         case UPIO_MEM:
2014                 break;
2015
2016         case UPIO_HUB6:
2017         case UPIO_PORT:
2018                 release_region(up->port.iobase + offset, size);
2019                 break;
2020         }
2021 }
2022
2023 static void serial8250_release_port(struct uart_port *port)
2024 {
2025         struct uart_8250_port *up = (struct uart_8250_port *)port;
2026
2027         serial8250_release_std_resource(up);
2028         if (up->port.type == PORT_RSA)
2029                 serial8250_release_rsa_resource(up);
2030 }
2031
2032 static int serial8250_request_port(struct uart_port *port)
2033 {
2034         struct uart_8250_port *up = (struct uart_8250_port *)port;
2035         int ret = 0;
2036
2037         ret = serial8250_request_std_resource(up);
2038         if (ret == 0 && up->port.type == PORT_RSA) {
2039                 ret = serial8250_request_rsa_resource(up);
2040                 if (ret < 0)
2041                         serial8250_release_std_resource(up);
2042         }
2043
2044         return ret;
2045 }
2046
2047 static void serial8250_config_port(struct uart_port *port, int flags)
2048 {
2049         struct uart_8250_port *up = (struct uart_8250_port *)port;
2050         int probeflags = PROBE_ANY;
2051         int ret;
2052
2053         /*
2054          * Don't probe for MCA ports on non-MCA machines.
2055          */
2056         if (up->port.flags & UPF_BOOT_ONLYMCA && !MCA_bus)
2057                 return;
2058
2059         /*
2060          * Find the region that we can probe for.  This in turn
2061          * tells us whether we can probe for the type of port.
2062          */
2063         ret = serial8250_request_std_resource(up);
2064         if (ret < 0)
2065                 return;
2066
2067         ret = serial8250_request_rsa_resource(up);
2068         if (ret < 0)
2069                 probeflags &= ~PROBE_RSA;
2070
2071         if (flags & UART_CONFIG_TYPE)
2072                 autoconfig(up, probeflags);
2073         if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
2074                 autoconfig_irq(up);
2075
2076         if (up->port.type != PORT_RSA && probeflags & PROBE_RSA)
2077                 serial8250_release_rsa_resource(up);
2078         if (up->port.type == PORT_UNKNOWN)
2079                 serial8250_release_std_resource(up);
2080 }
2081
2082 static int
2083 serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
2084 {
2085         if (ser->irq >= NR_IRQS || ser->irq < 0 ||
2086             ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
2087             ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS ||
2088             ser->type == PORT_STARTECH)
2089                 return -EINVAL;
2090         return 0;
2091 }
2092
2093 static const char *
2094 serial8250_type(struct uart_port *port)
2095 {
2096         int type = port->type;
2097
2098         if (type >= ARRAY_SIZE(uart_config))
2099                 type = 0;
2100         return uart_config[type].name;
2101 }
2102
2103 static struct uart_ops serial8250_pops = {
2104         .tx_empty       = serial8250_tx_empty,
2105         .set_mctrl      = serial8250_set_mctrl,
2106         .get_mctrl      = serial8250_get_mctrl,
2107         .stop_tx        = serial8250_stop_tx,
2108         .start_tx       = serial8250_start_tx,
2109         .stop_rx        = serial8250_stop_rx,
2110         .enable_ms      = serial8250_enable_ms,
2111         .break_ctl      = serial8250_break_ctl,
2112         .startup        = serial8250_startup,
2113         .shutdown       = serial8250_shutdown,
2114         .set_termios    = serial8250_set_termios,
2115         .pm             = serial8250_pm,
2116         .type           = serial8250_type,
2117         .release_port   = serial8250_release_port,
2118         .request_port   = serial8250_request_port,
2119         .config_port    = serial8250_config_port,
2120         .verify_port    = serial8250_verify_port,
2121 };
2122
2123 static struct uart_8250_port serial8250_ports[UART_NR];
2124
2125 static void __init serial8250_isa_init_ports(void)
2126 {
2127         struct uart_8250_port *up;
2128         static int first = 1;
2129         int i;
2130
2131         if (!first)
2132                 return;
2133         first = 0;
2134
2135         for (i = 0; i < UART_NR; i++) {
2136                 struct uart_8250_port *up = &serial8250_ports[i];
2137
2138                 up->port.line = i;
2139                 spin_lock_init(&up->port.lock);
2140
2141                 init_timer(&up->timer);
2142                 up->timer.function = serial8250_timeout;
2143
2144                 /*
2145                  * ALPHA_KLUDGE_MCR needs to be killed.
2146                  */
2147                 up->mcr_mask = ~ALPHA_KLUDGE_MCR;
2148                 up->mcr_force = ALPHA_KLUDGE_MCR;
2149
2150                 up->port.ops = &serial8250_pops;
2151         }
2152
2153         for (i = 0, up = serial8250_ports;
2154              i < ARRAY_SIZE(old_serial_port) && i < UART_NR;
2155              i++, up++) {
2156                 up->port.iobase   = old_serial_port[i].port;
2157                 up->port.irq      = irq_canonicalize(old_serial_port[i].irq);
2158                 up->port.uartclk  = old_serial_port[i].baud_base * 16;
2159                 up->port.flags    = old_serial_port[i].flags;
2160                 up->port.hub6     = old_serial_port[i].hub6;
2161                 up->port.membase  = old_serial_port[i].iomem_base;
2162                 up->port.iotype   = old_serial_port[i].io_type;
2163                 up->port.regshift = old_serial_port[i].iomem_reg_shift;
2164                 if (share_irqs)
2165                         up->port.flags |= UPF_SHARE_IRQ;
2166         }
2167 }
2168
2169 static void __init
2170 serial8250_register_ports(struct uart_driver *drv, struct device *dev)
2171 {
2172         int i;
2173
2174         serial8250_isa_init_ports();
2175
2176         for (i = 0; i < UART_NR; i++) {
2177                 struct uart_8250_port *up = &serial8250_ports[i];
2178
2179                 up->port.dev = dev;
2180                 uart_add_one_port(drv, &up->port);
2181         }
2182 }
2183
2184 #ifdef CONFIG_SERIAL_8250_CONSOLE
2185
2186 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
2187
2188 /*
2189  *      Wait for transmitter & holding register to empty
2190  */
2191 static inline void wait_for_xmitr(struct uart_8250_port *up)
2192 {
2193         unsigned int status, tmout = 10000;
2194
2195         /* Wait up to 10ms for the character(s) to be sent. */
2196         do {
2197                 status = serial_in(up, UART_LSR);
2198
2199                 if (status & UART_LSR_BI)
2200                         up->lsr_break_flag = UART_LSR_BI;
2201
2202                 if (--tmout == 0)
2203                         break;
2204                 udelay(1);
2205         } while ((status & BOTH_EMPTY) != BOTH_EMPTY);
2206
2207         /* Wait up to 1s for flow control if necessary */
2208         if (up->port.flags & UPF_CONS_FLOW) {
2209                 tmout = 1000000;
2210                 while (--tmout &&
2211                        ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
2212                         udelay(1);
2213         }
2214 }
2215
2216 /*
2217  *      Print a string to the serial port trying not to disturb
2218  *      any possible real use of the port...
2219  *
2220  *      The console_lock must be held when we get here.
2221  */
2222 static void
2223 serial8250_console_write(struct console *co, const char *s, unsigned int count)
2224 {
2225         struct uart_8250_port *up = &serial8250_ports[co->index];
2226         unsigned int ier;
2227         int i;
2228
2229         touch_nmi_watchdog();
2230
2231         /*
2232          *      First save the UER then disable the interrupts
2233          */
2234         ier = serial_in(up, UART_IER);
2235
2236         if (up->capabilities & UART_CAP_UUE)
2237                 serial_out(up, UART_IER, UART_IER_UUE);
2238         else
2239                 serial_out(up, UART_IER, 0);
2240
2241         /*
2242          *      Now, do each character
2243          */
2244         for (i = 0; i < count; i++, s++) {
2245                 wait_for_xmitr(up);
2246
2247                 /*
2248                  *      Send the character out.
2249                  *      If a LF, also do CR...
2250                  */
2251                 serial_out(up, UART_TX, *s);
2252                 if (*s == 10) {
2253                         wait_for_xmitr(up);
2254                         serial_out(up, UART_TX, 13);
2255                 }
2256         }
2257
2258         /*
2259          *      Finally, wait for transmitter to become empty
2260          *      and restore the IER
2261          */
2262         wait_for_xmitr(up);
2263         serial_out(up, UART_IER, ier);
2264 }
2265
2266 static int serial8250_console_setup(struct console *co, char *options)
2267 {
2268         struct uart_port *port;
2269         int baud = 9600;
2270         int bits = 8;
2271         int parity = 'n';
2272         int flow = 'n';
2273
2274         /*
2275          * Check whether an invalid uart number has been specified, and
2276          * if so, search for the first available port that does have
2277          * console support.
2278          */
2279         if (co->index >= UART_NR)
2280                 co->index = 0;
2281         port = &serial8250_ports[co->index].port;
2282         if (!port->iobase && !port->membase)
2283                 return -ENODEV;
2284
2285         if (options)
2286                 uart_parse_options(options, &baud, &parity, &bits, &flow);
2287
2288         return uart_set_options(port, co, baud, parity, bits, flow);
2289 }
2290
2291 static struct uart_driver serial8250_reg;
2292 static struct console serial8250_console = {
2293         .name           = "ttyS",
2294         .write          = serial8250_console_write,
2295         .device         = uart_console_device,
2296         .setup          = serial8250_console_setup,
2297         .flags          = CON_PRINTBUFFER,
2298         .index          = -1,
2299         .data           = &serial8250_reg,
2300 };
2301
2302 static int __init serial8250_console_init(void)
2303 {
2304         serial8250_isa_init_ports();
2305         register_console(&serial8250_console);
2306         return 0;
2307 }
2308 console_initcall(serial8250_console_init);
2309
2310 static int __init find_port(struct uart_port *p)
2311 {
2312         int line;
2313         struct uart_port *port;
2314
2315         for (line = 0; line < UART_NR; line++) {
2316                 port = &serial8250_ports[line].port;
2317                 if (p->iotype == port->iotype &&
2318                     p->iobase == port->iobase &&
2319                     p->membase == port->membase)
2320                         return line;
2321         }
2322         return -ENODEV;
2323 }
2324
2325 int __init serial8250_start_console(struct uart_port *port, char *options)
2326 {
2327         int line;
2328
2329         line = find_port(port);
2330         if (line < 0)
2331                 return -ENODEV;
2332
2333         add_preferred_console("ttyS", line, options);
2334         printk("Adding console on ttyS%d at %s 0x%lx (options '%s')\n",
2335                 line, port->iotype == UPIO_MEM ? "MMIO" : "I/O port",
2336                 port->iotype == UPIO_MEM ? (unsigned long) port->mapbase :
2337                     (unsigned long) port->iobase, options);
2338         if (!(serial8250_console.flags & CON_ENABLED)) {
2339                 serial8250_console.flags &= ~CON_PRINTBUFFER;
2340                 register_console(&serial8250_console);
2341         }
2342         return line;
2343 }
2344
2345 #define SERIAL8250_CONSOLE      &serial8250_console
2346 #else
2347 #define SERIAL8250_CONSOLE      NULL
2348 #endif
2349
2350 static struct uart_driver serial8250_reg = {
2351         .owner                  = THIS_MODULE,
2352         .driver_name            = "serial",
2353         .devfs_name             = "tts/",
2354         .dev_name               = "ttyS",
2355         .major                  = TTY_MAJOR,
2356         .minor                  = 64,
2357         .nr                     = UART_NR,
2358         .cons                   = SERIAL8250_CONSOLE,
2359 };
2360
2361 int __init early_serial_setup(struct uart_port *port)
2362 {
2363         if (port->line >= ARRAY_SIZE(serial8250_ports))
2364                 return -ENODEV;
2365
2366         serial8250_isa_init_ports();
2367         serial8250_ports[port->line].port       = *port;
2368         serial8250_ports[port->line].port.ops   = &serial8250_pops;
2369         return 0;
2370 }
2371
2372 /**
2373  *      serial8250_suspend_port - suspend one serial port
2374  *      @line:  serial line number
2375  *      @level: the level of port suspension, as per uart_suspend_port
2376  *
2377  *      Suspend one serial port.
2378  */
2379 void serial8250_suspend_port(int line)
2380 {
2381         uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port);
2382 }
2383
2384 /**
2385  *      serial8250_resume_port - resume one serial port
2386  *      @line:  serial line number
2387  *      @level: the level of port resumption, as per uart_resume_port
2388  *
2389  *      Resume one serial port.
2390  */
2391 void serial8250_resume_port(int line)
2392 {
2393         uart_resume_port(&serial8250_reg, &serial8250_ports[line].port);
2394 }
2395
2396 /*
2397  * Register a set of serial devices attached to a platform device.  The
2398  * list is terminated with a zero flags entry, which means we expect
2399  * all entries to have at least UPF_BOOT_AUTOCONF set.
2400  */
2401 static int __devinit serial8250_probe(struct device *dev)
2402 {
2403         struct plat_serial8250_port *p = dev->platform_data;
2404         struct uart_port port;
2405         int ret, i;
2406
2407         memset(&port, 0, sizeof(struct uart_port));
2408
2409         for (i = 0; p && p->flags != 0; p++, i++) {
2410                 port.iobase     = p->iobase;
2411                 port.membase    = p->membase;
2412                 port.irq        = p->irq;
2413                 port.uartclk    = p->uartclk;
2414                 port.regshift   = p->regshift;
2415                 port.iotype     = p->iotype;
2416                 port.flags      = p->flags;
2417                 port.mapbase    = p->mapbase;
2418                 port.hub6       = p->hub6;
2419                 port.dev        = dev;
2420                 if (share_irqs)
2421                         port.flags |= UPF_SHARE_IRQ;
2422                 ret = serial8250_register_port(&port);
2423                 if (ret < 0) {
2424                         dev_err(dev, "unable to register port at index %d "
2425                                 "(IO%lx MEM%lx IRQ%d): %d\n", i,
2426                                 p->iobase, p->mapbase, p->irq, ret);
2427                 }
2428         }
2429         return 0;
2430 }
2431
2432 /*
2433  * Remove serial ports registered against a platform device.
2434  */
2435 static int __devexit serial8250_remove(struct device *dev)
2436 {
2437         int i;
2438
2439         for (i = 0; i < UART_NR; i++) {
2440                 struct uart_8250_port *up = &serial8250_ports[i];
2441
2442                 if (up->port.dev == dev)
2443                         serial8250_unregister_port(i);
2444         }
2445         return 0;
2446 }
2447
2448 static int serial8250_suspend(struct device *dev, pm_message_t state)
2449 {
2450         int i;
2451
2452         for (i = 0; i < UART_NR; i++) {
2453                 struct uart_8250_port *up = &serial8250_ports[i];
2454
2455                 if (up->port.type != PORT_UNKNOWN && up->port.dev == dev)
2456                         uart_suspend_port(&serial8250_reg, &up->port);
2457         }
2458
2459         return 0;
2460 }
2461
2462 static int serial8250_resume(struct device *dev)
2463 {
2464         int i;
2465
2466         for (i = 0; i < UART_NR; i++) {
2467                 struct uart_8250_port *up = &serial8250_ports[i];
2468
2469                 if (up->port.type != PORT_UNKNOWN && up->port.dev == dev)
2470                         uart_resume_port(&serial8250_reg, &up->port);
2471         }
2472
2473         return 0;
2474 }
2475
2476 static struct device_driver serial8250_isa_driver = {
2477         .name           = "serial8250",
2478         .bus            = &platform_bus_type,
2479         .probe          = serial8250_probe,
2480         .remove         = __devexit_p(serial8250_remove),
2481         .suspend        = serial8250_suspend,
2482         .resume         = serial8250_resume,
2483 };
2484
2485 /*
2486  * This "device" covers _all_ ISA 8250-compatible serial devices listed
2487  * in the table in include/asm/serial.h
2488  */
2489 static struct platform_device *serial8250_isa_devs;
2490
2491 /*
2492  * serial8250_register_port and serial8250_unregister_port allows for
2493  * 16x50 serial ports to be configured at run-time, to support PCMCIA
2494  * modems and PCI multiport cards.
2495  */
2496 static DECLARE_MUTEX(serial_sem);
2497
2498 static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
2499 {
2500         int i;
2501
2502         /*
2503          * First, find a port entry which matches.
2504          */
2505         for (i = 0; i < UART_NR; i++)
2506                 if (uart_match_port(&serial8250_ports[i].port, port))
2507                         return &serial8250_ports[i];
2508
2509         /*
2510          * We didn't find a matching entry, so look for the first
2511          * free entry.  We look for one which hasn't been previously
2512          * used (indicated by zero iobase).
2513          */
2514         for (i = 0; i < UART_NR; i++)
2515                 if (serial8250_ports[i].port.type == PORT_UNKNOWN &&
2516                     serial8250_ports[i].port.iobase == 0)
2517                         return &serial8250_ports[i];
2518
2519         /*
2520          * That also failed.  Last resort is to find any entry which
2521          * doesn't have a real port associated with it.
2522          */
2523         for (i = 0; i < UART_NR; i++)
2524                 if (serial8250_ports[i].port.type == PORT_UNKNOWN)
2525                         return &serial8250_ports[i];
2526
2527         return NULL;
2528 }
2529
2530 /**
2531  *      serial8250_register_port - register a serial port
2532  *      @port: serial port template
2533  *
2534  *      Configure the serial port specified by the request. If the
2535  *      port exists and is in use, it is hung up and unregistered
2536  *      first.
2537  *
2538  *      The port is then probed and if necessary the IRQ is autodetected
2539  *      If this fails an error is returned.
2540  *
2541  *      On success the port is ready to use and the line number is returned.
2542  */
2543 int serial8250_register_port(struct uart_port *port)
2544 {
2545         struct uart_8250_port *uart;
2546         int ret = -ENOSPC;
2547
2548         if (port->uartclk == 0)
2549                 return -EINVAL;
2550
2551         down(&serial_sem);
2552
2553         uart = serial8250_find_match_or_unused(port);
2554         if (uart) {
2555                 uart_remove_one_port(&serial8250_reg, &uart->port);
2556
2557                 uart->port.iobase   = port->iobase;
2558                 uart->port.membase  = port->membase;
2559                 uart->port.irq      = port->irq;
2560                 uart->port.uartclk  = port->uartclk;
2561                 uart->port.fifosize = port->fifosize;
2562                 uart->port.regshift = port->regshift;
2563                 uart->port.iotype   = port->iotype;
2564                 uart->port.flags    = port->flags | UPF_BOOT_AUTOCONF;
2565                 uart->port.mapbase  = port->mapbase;
2566                 if (port->dev)
2567                         uart->port.dev = port->dev;
2568
2569                 ret = uart_add_one_port(&serial8250_reg, &uart->port);
2570                 if (ret == 0)
2571                         ret = uart->port.line;
2572         }
2573         up(&serial_sem);
2574
2575         return ret;
2576 }
2577 EXPORT_SYMBOL(serial8250_register_port);
2578
2579 /**
2580  *      serial8250_unregister_port - remove a 16x50 serial port at runtime
2581  *      @line: serial line number
2582  *
2583  *      Remove one serial port.  This may not be called from interrupt
2584  *      context.  We hand the port back to the our control.
2585  */
2586 void serial8250_unregister_port(int line)
2587 {
2588         struct uart_8250_port *uart = &serial8250_ports[line];
2589
2590         down(&serial_sem);
2591         uart_remove_one_port(&serial8250_reg, &uart->port);
2592         if (serial8250_isa_devs) {
2593                 uart->port.flags &= ~UPF_BOOT_AUTOCONF;
2594                 uart->port.type = PORT_UNKNOWN;
2595                 uart->port.dev = &serial8250_isa_devs->dev;
2596                 uart_add_one_port(&serial8250_reg, &uart->port);
2597         } else {
2598                 uart->port.dev = NULL;
2599         }
2600         up(&serial_sem);
2601 }
2602 EXPORT_SYMBOL(serial8250_unregister_port);
2603
2604 static int __init serial8250_init(void)
2605 {
2606         int ret, i;
2607
2608         printk(KERN_INFO "Serial: 8250/16550 driver $Revision: 1.90 $ "
2609                 "%d ports, IRQ sharing %sabled\n", (int) UART_NR,
2610                 share_irqs ? "en" : "dis");
2611
2612         for (i = 0; i < NR_IRQS; i++)
2613                 spin_lock_init(&irq_lists[i].lock);
2614
2615         ret = uart_register_driver(&serial8250_reg);
2616         if (ret)
2617                 goto out;
2618
2619         serial8250_isa_devs = platform_device_register_simple("serial8250",
2620                                          PLAT8250_DEV_LEGACY, NULL, 0);
2621         if (IS_ERR(serial8250_isa_devs)) {
2622                 ret = PTR_ERR(serial8250_isa_devs);
2623                 goto unreg;
2624         }
2625
2626         serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev);
2627
2628         ret = driver_register(&serial8250_isa_driver);
2629         if (ret == 0)
2630                 goto out;
2631
2632         platform_device_unregister(serial8250_isa_devs);
2633  unreg:
2634         uart_unregister_driver(&serial8250_reg);
2635  out:
2636         return ret;
2637 }
2638
2639 static void __exit serial8250_exit(void)
2640 {
2641         struct platform_device *isa_dev = serial8250_isa_devs;
2642
2643         /*
2644          * This tells serial8250_unregister_port() not to re-register
2645          * the ports (thereby making serial8250_isa_driver permanently
2646          * in use.)
2647          */
2648         serial8250_isa_devs = NULL;
2649
2650         driver_unregister(&serial8250_isa_driver);
2651         platform_device_unregister(isa_dev);
2652
2653         uart_unregister_driver(&serial8250_reg);
2654 }
2655
2656 module_init(serial8250_init);
2657 module_exit(serial8250_exit);
2658
2659 EXPORT_SYMBOL(serial8250_suspend_port);
2660 EXPORT_SYMBOL(serial8250_resume_port);
2661
2662 MODULE_LICENSE("GPL");
2663 MODULE_DESCRIPTION("Generic 8250/16x50 serial driver $Revision: 1.90 $");
2664
2665 module_param(share_irqs, uint, 0644);
2666 MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices"
2667         " (unsafe)");
2668
2669 #ifdef CONFIG_SERIAL_8250_RSA
2670 module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444);
2671 MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
2672 #endif
2673 MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);