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