Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: 8250: Split base port operations from universal driver

Refactor base port operations into new file; 8250_port.c.

Legacy irq handling, RSA port support, port storage for universal
driver, driver definition, module parameters and linkage remain in
8250_core.c

The source file split and resulting modules is diagrammed below:

8250_core.c ====> 8250_core.c __
\ \
\ +-- 8250.ko (alias 8250_core)
\ 8250_pnp.c __/ (universal driver)
\
=> 8250_port.c __
\
+-- 8250_base.ko
8250_dma.c __/ (port operations)

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Peter Hurley and committed by
Greg Kroah-Hartman
b6830f6d e95044ba

+2925 -2872
+11
drivers/tty/serial/8250/8250.h
··· 211 211 } 212 212 return 1; 213 213 } 214 + 215 + static inline int serial_index(struct uart_port *port) 216 + { 217 + return port->minor - 64; 218 + } 219 + 220 + #if 0 221 + #define DEBUG_INTR(fmt...) printk(fmt) 222 + #else 223 + #define DEBUG_INTR(fmt...) do { } while (0) 224 + #endif
+8 -2870
drivers/tty/serial/8250/8250_core.c
··· 1 1 /* 2 - * Driver for 8250/16550-type serial ports 2 + * Universal/legacy driver for 8250/16550-type serial ports 3 3 * 4 4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. 5 5 * 6 6 * Copyright (C) 2001 Russell King. 7 7 * 8 + * Supports: ISA-compatible 8250/16550 ports 9 + * PNP 8250/16550 ports 10 + * early_serial_setup() ports 11 + * userspace-configurable "phantom" ports 12 + * "serial8250" platform devices 13 + * serial8250_register_8250_port() ports 14 + * 8 15 * This program is free software; you can redistribute it and/or modify 9 16 * it under the terms of the GNU General Public License as published by 10 17 * the Free Software Foundation; either version 2 of the License, or 11 18 * (at your option) any later version. 12 - * 13 - * A note about mapbase / membase 14 - * 15 - * mapbase is the physical address of the IO port. 16 - * membase is an 'ioremapped' cookie. 17 19 */ 18 - 19 - #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 20 - #define SUPPORT_SYSRQ 21 - #endif 22 20 23 21 #include <linux/module.h> 24 22 #include <linux/moduleparam.h> ··· 56 58 57 59 static struct uart_driver serial8250_reg; 58 60 59 - static int serial_index(struct uart_port *port) 60 - { 61 - return port->minor - 64; 62 - } 63 - 64 61 static unsigned int skip_txen_test; /* force skip of txen test at init time */ 65 62 66 - /* 67 - * Debugging. 68 - */ 69 - #if 0 70 - #define DEBUG_AUTOCONF(fmt...) printk(fmt) 71 - #else 72 - #define DEBUG_AUTOCONF(fmt...) do { } while (0) 73 - #endif 74 - 75 - #if 0 76 - #define DEBUG_INTR(fmt...) printk(fmt) 77 - #else 78 - #define DEBUG_INTR(fmt...) do { } while (0) 79 - #endif 80 - 81 63 #define PASS_LIMIT 512 82 - 83 - #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 84 - 85 64 86 65 #include <asm/serial.h> 87 66 /* ··· 93 118 #define NR_IRQ_HASH 32 /* Can be adjusted later */ 94 119 static struct hlist_head irq_lists[NR_IRQ_HASH]; 95 120 static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */ 96 - 97 - /* 98 - * Here we define the default xmit fifo size used for each type of UART. 99 - */ 100 - static const struct serial8250_config uart_config[] = { 101 - [PORT_UNKNOWN] = { 102 - .name = "unknown", 103 - .fifo_size = 1, 104 - .tx_loadsz = 1, 105 - }, 106 - [PORT_8250] = { 107 - .name = "8250", 108 - .fifo_size = 1, 109 - .tx_loadsz = 1, 110 - }, 111 - [PORT_16450] = { 112 - .name = "16450", 113 - .fifo_size = 1, 114 - .tx_loadsz = 1, 115 - }, 116 - [PORT_16550] = { 117 - .name = "16550", 118 - .fifo_size = 1, 119 - .tx_loadsz = 1, 120 - }, 121 - [PORT_16550A] = { 122 - .name = "16550A", 123 - .fifo_size = 16, 124 - .tx_loadsz = 16, 125 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 126 - .rxtrig_bytes = {1, 4, 8, 14}, 127 - .flags = UART_CAP_FIFO, 128 - }, 129 - [PORT_CIRRUS] = { 130 - .name = "Cirrus", 131 - .fifo_size = 1, 132 - .tx_loadsz = 1, 133 - }, 134 - [PORT_16650] = { 135 - .name = "ST16650", 136 - .fifo_size = 1, 137 - .tx_loadsz = 1, 138 - .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, 139 - }, 140 - [PORT_16650V2] = { 141 - .name = "ST16650V2", 142 - .fifo_size = 32, 143 - .tx_loadsz = 16, 144 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | 145 - UART_FCR_T_TRIG_00, 146 - .rxtrig_bytes = {8, 16, 24, 28}, 147 - .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, 148 - }, 149 - [PORT_16750] = { 150 - .name = "TI16750", 151 - .fifo_size = 64, 152 - .tx_loadsz = 64, 153 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | 154 - UART_FCR7_64BYTE, 155 - .rxtrig_bytes = {1, 16, 32, 56}, 156 - .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE, 157 - }, 158 - [PORT_STARTECH] = { 159 - .name = "Startech", 160 - .fifo_size = 1, 161 - .tx_loadsz = 1, 162 - }, 163 - [PORT_16C950] = { 164 - .name = "16C950/954", 165 - .fifo_size = 128, 166 - .tx_loadsz = 128, 167 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 168 - /* UART_CAP_EFR breaks billionon CF bluetooth card. */ 169 - .flags = UART_CAP_FIFO | UART_CAP_SLEEP, 170 - }, 171 - [PORT_16654] = { 172 - .name = "ST16654", 173 - .fifo_size = 64, 174 - .tx_loadsz = 32, 175 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | 176 - UART_FCR_T_TRIG_10, 177 - .rxtrig_bytes = {8, 16, 56, 60}, 178 - .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, 179 - }, 180 - [PORT_16850] = { 181 - .name = "XR16850", 182 - .fifo_size = 128, 183 - .tx_loadsz = 128, 184 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 185 - .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, 186 - }, 187 - [PORT_RSA] = { 188 - .name = "RSA", 189 - .fifo_size = 2048, 190 - .tx_loadsz = 2048, 191 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11, 192 - .flags = UART_CAP_FIFO, 193 - }, 194 - [PORT_NS16550A] = { 195 - .name = "NS16550A", 196 - .fifo_size = 16, 197 - .tx_loadsz = 16, 198 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 199 - .flags = UART_CAP_FIFO | UART_NATSEMI, 200 - }, 201 - [PORT_XSCALE] = { 202 - .name = "XScale", 203 - .fifo_size = 32, 204 - .tx_loadsz = 32, 205 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 206 - .flags = UART_CAP_FIFO | UART_CAP_UUE | UART_CAP_RTOIE, 207 - }, 208 - [PORT_OCTEON] = { 209 - .name = "OCTEON", 210 - .fifo_size = 64, 211 - .tx_loadsz = 64, 212 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 213 - .flags = UART_CAP_FIFO, 214 - }, 215 - [PORT_AR7] = { 216 - .name = "AR7", 217 - .fifo_size = 16, 218 - .tx_loadsz = 16, 219 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00, 220 - .flags = UART_CAP_FIFO | UART_CAP_AFE, 221 - }, 222 - [PORT_U6_16550A] = { 223 - .name = "U6_16550A", 224 - .fifo_size = 64, 225 - .tx_loadsz = 64, 226 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 227 - .flags = UART_CAP_FIFO | UART_CAP_AFE, 228 - }, 229 - [PORT_TEGRA] = { 230 - .name = "Tegra", 231 - .fifo_size = 32, 232 - .tx_loadsz = 8, 233 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | 234 - UART_FCR_T_TRIG_01, 235 - .rxtrig_bytes = {1, 4, 8, 14}, 236 - .flags = UART_CAP_FIFO | UART_CAP_RTOIE, 237 - }, 238 - [PORT_XR17D15X] = { 239 - .name = "XR17D15X", 240 - .fifo_size = 64, 241 - .tx_loadsz = 64, 242 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 243 - .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR | 244 - UART_CAP_SLEEP, 245 - }, 246 - [PORT_XR17V35X] = { 247 - .name = "XR17V35X", 248 - .fifo_size = 256, 249 - .tx_loadsz = 256, 250 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11 | 251 - UART_FCR_T_TRIG_11, 252 - .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR | 253 - UART_CAP_SLEEP, 254 - }, 255 - [PORT_LPC3220] = { 256 - .name = "LPC3220", 257 - .fifo_size = 64, 258 - .tx_loadsz = 32, 259 - .fcr = UART_FCR_DMA_SELECT | UART_FCR_ENABLE_FIFO | 260 - UART_FCR_R_TRIG_00 | UART_FCR_T_TRIG_00, 261 - .flags = UART_CAP_FIFO, 262 - }, 263 - [PORT_BRCM_TRUMANAGE] = { 264 - .name = "TruManage", 265 - .fifo_size = 1, 266 - .tx_loadsz = 1024, 267 - .flags = UART_CAP_HFIFO, 268 - }, 269 - [PORT_8250_CIR] = { 270 - .name = "CIR port" 271 - }, 272 - [PORT_ALTR_16550_F32] = { 273 - .name = "Altera 16550 FIFO32", 274 - .fifo_size = 32, 275 - .tx_loadsz = 32, 276 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 277 - .flags = UART_CAP_FIFO | UART_CAP_AFE, 278 - }, 279 - [PORT_ALTR_16550_F64] = { 280 - .name = "Altera 16550 FIFO64", 281 - .fifo_size = 64, 282 - .tx_loadsz = 64, 283 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 284 - .flags = UART_CAP_FIFO | UART_CAP_AFE, 285 - }, 286 - [PORT_ALTR_16550_F128] = { 287 - .name = "Altera 16550 FIFO128", 288 - .fifo_size = 128, 289 - .tx_loadsz = 128, 290 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 291 - .flags = UART_CAP_FIFO | UART_CAP_AFE, 292 - }, 293 - /* tx_loadsz is set to 63-bytes instead of 64-bytes to implement 294 - workaround of errata A-008006 which states that tx_loadsz should be 295 - configured less than Maximum supported fifo bytes */ 296 - [PORT_16550A_FSL64] = { 297 - .name = "16550A_FSL64", 298 - .fifo_size = 64, 299 - .tx_loadsz = 63, 300 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | 301 - UART_FCR7_64BYTE, 302 - .flags = UART_CAP_FIFO, 303 - }, 304 - }; 305 - 306 - /* Uart divisor latch read */ 307 - static int default_serial_dl_read(struct uart_8250_port *up) 308 - { 309 - return serial_in(up, UART_DLL) | serial_in(up, UART_DLM) << 8; 310 - } 311 - 312 - /* Uart divisor latch write */ 313 - static void default_serial_dl_write(struct uart_8250_port *up, int value) 314 - { 315 - serial_out(up, UART_DLL, value & 0xff); 316 - serial_out(up, UART_DLM, value >> 8 & 0xff); 317 - } 318 - 319 - #if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X) 320 - 321 - /* Au1x00/RT288x UART hardware has a weird register layout */ 322 - static const s8 au_io_in_map[8] = { 323 - 0, /* UART_RX */ 324 - 2, /* UART_IER */ 325 - 3, /* UART_IIR */ 326 - 5, /* UART_LCR */ 327 - 6, /* UART_MCR */ 328 - 7, /* UART_LSR */ 329 - 8, /* UART_MSR */ 330 - -1, /* UART_SCR (unmapped) */ 331 - }; 332 - 333 - static const s8 au_io_out_map[8] = { 334 - 1, /* UART_TX */ 335 - 2, /* UART_IER */ 336 - 4, /* UART_FCR */ 337 - 5, /* UART_LCR */ 338 - 6, /* UART_MCR */ 339 - -1, /* UART_LSR (unmapped) */ 340 - -1, /* UART_MSR (unmapped) */ 341 - -1, /* UART_SCR (unmapped) */ 342 - }; 343 - 344 - static unsigned int au_serial_in(struct uart_port *p, int offset) 345 - { 346 - if (offset >= ARRAY_SIZE(au_io_in_map)) 347 - return UINT_MAX; 348 - offset = au_io_in_map[offset]; 349 - if (offset < 0) 350 - return UINT_MAX; 351 - return __raw_readl(p->membase + (offset << p->regshift)); 352 - } 353 - 354 - static void au_serial_out(struct uart_port *p, int offset, int value) 355 - { 356 - if (offset >= ARRAY_SIZE(au_io_out_map)) 357 - return; 358 - offset = au_io_out_map[offset]; 359 - if (offset < 0) 360 - return; 361 - __raw_writel(value, p->membase + (offset << p->regshift)); 362 - } 363 - 364 - /* Au1x00 haven't got a standard divisor latch */ 365 - static int au_serial_dl_read(struct uart_8250_port *up) 366 - { 367 - return __raw_readl(up->port.membase + 0x28); 368 - } 369 - 370 - static void au_serial_dl_write(struct uart_8250_port *up, int value) 371 - { 372 - __raw_writel(value, up->port.membase + 0x28); 373 - } 374 - 375 - #endif 376 - 377 - static unsigned int hub6_serial_in(struct uart_port *p, int offset) 378 - { 379 - offset = offset << p->regshift; 380 - outb(p->hub6 - 1 + offset, p->iobase); 381 - return inb(p->iobase + 1); 382 - } 383 - 384 - static void hub6_serial_out(struct uart_port *p, int offset, int value) 385 - { 386 - offset = offset << p->regshift; 387 - outb(p->hub6 - 1 + offset, p->iobase); 388 - outb(value, p->iobase + 1); 389 - } 390 - 391 - static unsigned int mem_serial_in(struct uart_port *p, int offset) 392 - { 393 - offset = offset << p->regshift; 394 - return readb(p->membase + offset); 395 - } 396 - 397 - static void mem_serial_out(struct uart_port *p, int offset, int value) 398 - { 399 - offset = offset << p->regshift; 400 - writeb(value, p->membase + offset); 401 - } 402 - 403 - static void mem32_serial_out(struct uart_port *p, int offset, int value) 404 - { 405 - offset = offset << p->regshift; 406 - writel(value, p->membase + offset); 407 - } 408 - 409 - static unsigned int mem32_serial_in(struct uart_port *p, int offset) 410 - { 411 - offset = offset << p->regshift; 412 - return readl(p->membase + offset); 413 - } 414 - 415 - static void mem32be_serial_out(struct uart_port *p, int offset, int value) 416 - { 417 - offset = offset << p->regshift; 418 - iowrite32be(value, p->membase + offset); 419 - } 420 - 421 - static unsigned int mem32be_serial_in(struct uart_port *p, int offset) 422 - { 423 - offset = offset << p->regshift; 424 - return ioread32be(p->membase + offset); 425 - } 426 - 427 - static unsigned int io_serial_in(struct uart_port *p, int offset) 428 - { 429 - offset = offset << p->regshift; 430 - return inb(p->iobase + offset); 431 - } 432 - 433 - static void io_serial_out(struct uart_port *p, int offset, int value) 434 - { 435 - offset = offset << p->regshift; 436 - outb(value, p->iobase + offset); 437 - } 438 - 439 - static int serial8250_default_handle_irq(struct uart_port *port); 440 - static int exar_handle_irq(struct uart_port *port); 441 - 442 - static void set_io_from_upio(struct uart_port *p) 443 - { 444 - struct uart_8250_port *up = up_to_u8250p(p); 445 - 446 - up->dl_read = default_serial_dl_read; 447 - up->dl_write = default_serial_dl_write; 448 - 449 - switch (p->iotype) { 450 - case UPIO_HUB6: 451 - p->serial_in = hub6_serial_in; 452 - p->serial_out = hub6_serial_out; 453 - break; 454 - 455 - case UPIO_MEM: 456 - p->serial_in = mem_serial_in; 457 - p->serial_out = mem_serial_out; 458 - break; 459 - 460 - case UPIO_MEM32: 461 - p->serial_in = mem32_serial_in; 462 - p->serial_out = mem32_serial_out; 463 - break; 464 - 465 - case UPIO_MEM32BE: 466 - p->serial_in = mem32be_serial_in; 467 - p->serial_out = mem32be_serial_out; 468 - break; 469 - 470 - #if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X) 471 - case UPIO_AU: 472 - p->serial_in = au_serial_in; 473 - p->serial_out = au_serial_out; 474 - up->dl_read = au_serial_dl_read; 475 - up->dl_write = au_serial_dl_write; 476 - break; 477 - #endif 478 - 479 - default: 480 - p->serial_in = io_serial_in; 481 - p->serial_out = io_serial_out; 482 - break; 483 - } 484 - /* Remember loaded iotype */ 485 - up->cur_iotype = p->iotype; 486 - p->handle_irq = serial8250_default_handle_irq; 487 - } 488 - 489 - static void 490 - serial_port_out_sync(struct uart_port *p, int offset, int value) 491 - { 492 - switch (p->iotype) { 493 - case UPIO_MEM: 494 - case UPIO_MEM32: 495 - case UPIO_MEM32BE: 496 - case UPIO_AU: 497 - p->serial_out(p, offset, value); 498 - p->serial_in(p, UART_LCR); /* safe, no side-effects */ 499 - break; 500 - default: 501 - p->serial_out(p, offset, value); 502 - } 503 - } 504 - 505 - /* 506 - * For the 16C950 507 - */ 508 - static void serial_icr_write(struct uart_8250_port *up, int offset, int value) 509 - { 510 - serial_out(up, UART_SCR, offset); 511 - serial_out(up, UART_ICR, value); 512 - } 513 - 514 - static unsigned int serial_icr_read(struct uart_8250_port *up, int offset) 515 - { 516 - unsigned int value; 517 - 518 - serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); 519 - serial_out(up, UART_SCR, offset); 520 - value = serial_in(up, UART_ICR); 521 - serial_icr_write(up, UART_ACR, up->acr); 522 - 523 - return value; 524 - } 525 - 526 - /* 527 - * FIFO support. 528 - */ 529 - static void serial8250_clear_fifos(struct uart_8250_port *p) 530 - { 531 - if (p->capabilities & UART_CAP_FIFO) { 532 - serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO); 533 - serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO | 534 - UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 535 - serial_out(p, UART_FCR, 0); 536 - } 537 - } 538 - 539 - void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p) 540 - { 541 - serial8250_clear_fifos(p); 542 - serial_out(p, UART_FCR, p->fcr); 543 - } 544 - EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos); 545 - 546 - void serial8250_rpm_get(struct uart_8250_port *p) 547 - { 548 - if (!(p->capabilities & UART_CAP_RPM)) 549 - return; 550 - pm_runtime_get_sync(p->port.dev); 551 - } 552 - EXPORT_SYMBOL_GPL(serial8250_rpm_get); 553 - 554 - void serial8250_rpm_put(struct uart_8250_port *p) 555 - { 556 - if (!(p->capabilities & UART_CAP_RPM)) 557 - return; 558 - pm_runtime_mark_last_busy(p->port.dev); 559 - pm_runtime_put_autosuspend(p->port.dev); 560 - } 561 - EXPORT_SYMBOL_GPL(serial8250_rpm_put); 562 - 563 - /* 564 - * These two wrappers ensure that enable_runtime_pm_tx() can be called more than 565 - * once and disable_runtime_pm_tx() will still disable RPM because the fifo is 566 - * empty and the HW can idle again. 567 - */ 568 - static void serial8250_rpm_get_tx(struct uart_8250_port *p) 569 - { 570 - unsigned char rpm_active; 571 - 572 - if (!(p->capabilities & UART_CAP_RPM)) 573 - return; 574 - 575 - rpm_active = xchg(&p->rpm_tx_active, 1); 576 - if (rpm_active) 577 - return; 578 - pm_runtime_get_sync(p->port.dev); 579 - } 580 - 581 - static void serial8250_rpm_put_tx(struct uart_8250_port *p) 582 - { 583 - unsigned char rpm_active; 584 - 585 - if (!(p->capabilities & UART_CAP_RPM)) 586 - return; 587 - 588 - rpm_active = xchg(&p->rpm_tx_active, 0); 589 - if (!rpm_active) 590 - return; 591 - pm_runtime_mark_last_busy(p->port.dev); 592 - pm_runtime_put_autosuspend(p->port.dev); 593 - } 594 - 595 - /* 596 - * IER sleep support. UARTs which have EFRs need the "extended 597 - * capability" bit enabled. Note that on XR16C850s, we need to 598 - * reset LCR to write to IER. 599 - */ 600 - static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) 601 - { 602 - unsigned char lcr = 0, efr = 0; 603 - /* 604 - * Exar UARTs have a SLEEP register that enables or disables 605 - * each UART to enter sleep mode separately. On the XR17V35x the 606 - * register is accessible to each UART at the UART_EXAR_SLEEP 607 - * offset but the UART channel may only write to the corresponding 608 - * bit. 609 - */ 610 - serial8250_rpm_get(p); 611 - if ((p->port.type == PORT_XR17V35X) || 612 - (p->port.type == PORT_XR17D15X)) { 613 - serial_out(p, UART_EXAR_SLEEP, sleep ? 0xff : 0); 614 - goto out; 615 - } 616 - 617 - if (p->capabilities & UART_CAP_SLEEP) { 618 - if (p->capabilities & UART_CAP_EFR) { 619 - lcr = serial_in(p, UART_LCR); 620 - efr = serial_in(p, UART_EFR); 621 - serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 622 - serial_out(p, UART_EFR, UART_EFR_ECB); 623 - serial_out(p, UART_LCR, 0); 624 - } 625 - serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); 626 - if (p->capabilities & UART_CAP_EFR) { 627 - serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 628 - serial_out(p, UART_EFR, efr); 629 - serial_out(p, UART_LCR, lcr); 630 - } 631 - } 632 - out: 633 - serial8250_rpm_put(p); 634 - } 635 - 636 - #ifdef CONFIG_SERIAL_8250_RSA 637 - /* 638 - * Attempts to turn on the RSA FIFO. Returns zero on failure. 639 - * We set the port uart clock rate if we succeed. 640 - */ 641 - static int __enable_rsa(struct uart_8250_port *up) 642 - { 643 - unsigned char mode; 644 - int result; 645 - 646 - mode = serial_in(up, UART_RSA_MSR); 647 - result = mode & UART_RSA_MSR_FIFO; 648 - 649 - if (!result) { 650 - serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); 651 - mode = serial_in(up, UART_RSA_MSR); 652 - result = mode & UART_RSA_MSR_FIFO; 653 - } 654 - 655 - if (result) 656 - up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16; 657 - 658 - return result; 659 - } 660 - 661 - static void enable_rsa(struct uart_8250_port *up) 662 - { 663 - if (up->port.type == PORT_RSA) { 664 - if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) { 665 - spin_lock_irq(&up->port.lock); 666 - __enable_rsa(up); 667 - spin_unlock_irq(&up->port.lock); 668 - } 669 - if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) 670 - serial_out(up, UART_RSA_FRR, 0); 671 - } 672 - } 673 - 674 - /* 675 - * Attempts to turn off the RSA FIFO. Returns zero on failure. 676 - * It is unknown why interrupts were disabled in here. However, 677 - * the caller is expected to preserve this behaviour by grabbing 678 - * the spinlock before calling this function. 679 - */ 680 - static void disable_rsa(struct uart_8250_port *up) 681 - { 682 - unsigned char mode; 683 - int result; 684 - 685 - if (up->port.type == PORT_RSA && 686 - up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { 687 - spin_lock_irq(&up->port.lock); 688 - 689 - mode = serial_in(up, UART_RSA_MSR); 690 - result = !(mode & UART_RSA_MSR_FIFO); 691 - 692 - if (!result) { 693 - serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); 694 - mode = serial_in(up, UART_RSA_MSR); 695 - result = !(mode & UART_RSA_MSR_FIFO); 696 - } 697 - 698 - if (result) 699 - up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16; 700 - spin_unlock_irq(&up->port.lock); 701 - } 702 - } 703 - #endif /* CONFIG_SERIAL_8250_RSA */ 704 - 705 - /* 706 - * This is a quickie test to see how big the FIFO is. 707 - * It doesn't work at all the time, more's the pity. 708 - */ 709 - static int size_fifo(struct uart_8250_port *up) 710 - { 711 - unsigned char old_fcr, old_mcr, old_lcr; 712 - unsigned short old_dl; 713 - int count; 714 - 715 - old_lcr = serial_in(up, UART_LCR); 716 - serial_out(up, UART_LCR, 0); 717 - old_fcr = serial_in(up, UART_FCR); 718 - old_mcr = serial_in(up, UART_MCR); 719 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 720 - UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 721 - serial_out(up, UART_MCR, UART_MCR_LOOP); 722 - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 723 - old_dl = serial_dl_read(up); 724 - serial_dl_write(up, 0x0001); 725 - serial_out(up, UART_LCR, 0x03); 726 - for (count = 0; count < 256; count++) 727 - serial_out(up, UART_TX, count); 728 - mdelay(20);/* FIXME - schedule_timeout */ 729 - for (count = 0; (serial_in(up, UART_LSR) & UART_LSR_DR) && 730 - (count < 256); count++) 731 - serial_in(up, UART_RX); 732 - serial_out(up, UART_FCR, old_fcr); 733 - serial_out(up, UART_MCR, old_mcr); 734 - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 735 - serial_dl_write(up, old_dl); 736 - serial_out(up, UART_LCR, old_lcr); 737 - 738 - return count; 739 - } 740 - 741 - /* 742 - * Read UART ID using the divisor method - set DLL and DLM to zero 743 - * and the revision will be in DLL and device type in DLM. We 744 - * preserve the device state across this. 745 - */ 746 - static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p) 747 - { 748 - unsigned char old_dll, old_dlm, old_lcr; 749 - unsigned int id; 750 - 751 - old_lcr = serial_in(p, UART_LCR); 752 - serial_out(p, UART_LCR, UART_LCR_CONF_MODE_A); 753 - 754 - old_dll = serial_in(p, UART_DLL); 755 - old_dlm = serial_in(p, UART_DLM); 756 - 757 - serial_out(p, UART_DLL, 0); 758 - serial_out(p, UART_DLM, 0); 759 - 760 - id = serial_in(p, UART_DLL) | serial_in(p, UART_DLM) << 8; 761 - 762 - serial_out(p, UART_DLL, old_dll); 763 - serial_out(p, UART_DLM, old_dlm); 764 - serial_out(p, UART_LCR, old_lcr); 765 - 766 - return id; 767 - } 768 - 769 - /* 770 - * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's. 771 - * When this function is called we know it is at least a StarTech 772 - * 16650 V2, but it might be one of several StarTech UARTs, or one of 773 - * its clones. (We treat the broken original StarTech 16650 V1 as a 774 - * 16550, and why not? Startech doesn't seem to even acknowledge its 775 - * existence.) 776 - * 777 - * What evil have men's minds wrought... 778 - */ 779 - static void autoconfig_has_efr(struct uart_8250_port *up) 780 - { 781 - unsigned int id1, id2, id3, rev; 782 - 783 - /* 784 - * Everything with an EFR has SLEEP 785 - */ 786 - up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; 787 - 788 - /* 789 - * First we check to see if it's an Oxford Semiconductor UART. 790 - * 791 - * If we have to do this here because some non-National 792 - * Semiconductor clone chips lock up if you try writing to the 793 - * LSR register (which serial_icr_read does) 794 - */ 795 - 796 - /* 797 - * Check for Oxford Semiconductor 16C950. 798 - * 799 - * EFR [4] must be set else this test fails. 800 - * 801 - * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca) 802 - * claims that it's needed for 952 dual UART's (which are not 803 - * recommended for new designs). 804 - */ 805 - up->acr = 0; 806 - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 807 - serial_out(up, UART_EFR, UART_EFR_ECB); 808 - serial_out(up, UART_LCR, 0x00); 809 - id1 = serial_icr_read(up, UART_ID1); 810 - id2 = serial_icr_read(up, UART_ID2); 811 - id3 = serial_icr_read(up, UART_ID3); 812 - rev = serial_icr_read(up, UART_REV); 813 - 814 - DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev); 815 - 816 - if (id1 == 0x16 && id2 == 0xC9 && 817 - (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) { 818 - up->port.type = PORT_16C950; 819 - 820 - /* 821 - * Enable work around for the Oxford Semiconductor 952 rev B 822 - * chip which causes it to seriously miscalculate baud rates 823 - * when DLL is 0. 824 - */ 825 - if (id3 == 0x52 && rev == 0x01) 826 - up->bugs |= UART_BUG_QUOT; 827 - return; 828 - } 829 - 830 - /* 831 - * We check for a XR16C850 by setting DLL and DLM to 0, and then 832 - * reading back DLL and DLM. The chip type depends on the DLM 833 - * value read back: 834 - * 0x10 - XR16C850 and the DLL contains the chip revision. 835 - * 0x12 - XR16C2850. 836 - * 0x14 - XR16C854. 837 - */ 838 - id1 = autoconfig_read_divisor_id(up); 839 - DEBUG_AUTOCONF("850id=%04x ", id1); 840 - 841 - id2 = id1 >> 8; 842 - if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) { 843 - up->port.type = PORT_16850; 844 - return; 845 - } 846 - 847 - /* 848 - * It wasn't an XR16C850. 849 - * 850 - * We distinguish between the '654 and the '650 by counting 851 - * how many bytes are in the FIFO. I'm using this for now, 852 - * since that's the technique that was sent to me in the 853 - * serial driver update, but I'm not convinced this works. 854 - * I've had problems doing this in the past. -TYT 855 - */ 856 - if (size_fifo(up) == 64) 857 - up->port.type = PORT_16654; 858 - else 859 - up->port.type = PORT_16650V2; 860 - } 861 - 862 - /* 863 - * We detected a chip without a FIFO. Only two fall into 864 - * this category - the original 8250 and the 16450. The 865 - * 16450 has a scratch register (accessible with LCR=0) 866 - */ 867 - static void autoconfig_8250(struct uart_8250_port *up) 868 - { 869 - unsigned char scratch, status1, status2; 870 - 871 - up->port.type = PORT_8250; 872 - 873 - scratch = serial_in(up, UART_SCR); 874 - serial_out(up, UART_SCR, 0xa5); 875 - status1 = serial_in(up, UART_SCR); 876 - serial_out(up, UART_SCR, 0x5a); 877 - status2 = serial_in(up, UART_SCR); 878 - serial_out(up, UART_SCR, scratch); 879 - 880 - if (status1 == 0xa5 && status2 == 0x5a) 881 - up->port.type = PORT_16450; 882 - } 883 - 884 - static int broken_efr(struct uart_8250_port *up) 885 - { 886 - /* 887 - * Exar ST16C2550 "A2" devices incorrectly detect as 888 - * having an EFR, and report an ID of 0x0201. See 889 - * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html 890 - */ 891 - if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16) 892 - return 1; 893 - 894 - return 0; 895 - } 896 - 897 - /* 898 - * We know that the chip has FIFOs. Does it have an EFR? The 899 - * EFR is located in the same register position as the IIR and 900 - * we know the top two bits of the IIR are currently set. The 901 - * EFR should contain zero. Try to read the EFR. 902 - */ 903 - static void autoconfig_16550a(struct uart_8250_port *up) 904 - { 905 - unsigned char status1, status2; 906 - unsigned int iersave; 907 - 908 - up->port.type = PORT_16550A; 909 - up->capabilities |= UART_CAP_FIFO; 910 - 911 - /* 912 - * XR17V35x UARTs have an extra divisor register, DLD 913 - * that gets enabled with when DLAB is set which will 914 - * cause the device to incorrectly match and assign 915 - * port type to PORT_16650. The EFR for this UART is 916 - * found at offset 0x09. Instead check the Deice ID (DVID) 917 - * register for a 2, 4 or 8 port UART. 918 - */ 919 - if (up->port.flags & UPF_EXAR_EFR) { 920 - status1 = serial_in(up, UART_EXAR_DVID); 921 - if (status1 == 0x82 || status1 == 0x84 || status1 == 0x88) { 922 - DEBUG_AUTOCONF("Exar XR17V35x "); 923 - up->port.type = PORT_XR17V35X; 924 - up->capabilities |= UART_CAP_AFE | UART_CAP_EFR | 925 - UART_CAP_SLEEP; 926 - 927 - return; 928 - } 929 - 930 - } 931 - 932 - /* 933 - * Check for presence of the EFR when DLAB is set. 934 - * Only ST16C650V1 UARTs pass this test. 935 - */ 936 - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 937 - if (serial_in(up, UART_EFR) == 0) { 938 - serial_out(up, UART_EFR, 0xA8); 939 - if (serial_in(up, UART_EFR) != 0) { 940 - DEBUG_AUTOCONF("EFRv1 "); 941 - up->port.type = PORT_16650; 942 - up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; 943 - } else { 944 - serial_out(up, UART_LCR, 0); 945 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 946 - UART_FCR7_64BYTE); 947 - status1 = serial_in(up, UART_IIR) >> 5; 948 - serial_out(up, UART_FCR, 0); 949 - serial_out(up, UART_LCR, 0); 950 - 951 - if (status1 == 7) 952 - up->port.type = PORT_16550A_FSL64; 953 - else 954 - DEBUG_AUTOCONF("Motorola 8xxx DUART "); 955 - } 956 - serial_out(up, UART_EFR, 0); 957 - return; 958 - } 959 - 960 - /* 961 - * Maybe it requires 0xbf to be written to the LCR. 962 - * (other ST16C650V2 UARTs, TI16C752A, etc) 963 - */ 964 - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 965 - if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) { 966 - DEBUG_AUTOCONF("EFRv2 "); 967 - autoconfig_has_efr(up); 968 - return; 969 - } 970 - 971 - /* 972 - * Check for a National Semiconductor SuperIO chip. 973 - * Attempt to switch to bank 2, read the value of the LOOP bit 974 - * from EXCR1. Switch back to bank 0, change it in MCR. Then 975 - * switch back to bank 2, read it from EXCR1 again and check 976 - * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2 977 - */ 978 - serial_out(up, UART_LCR, 0); 979 - status1 = serial_in(up, UART_MCR); 980 - serial_out(up, UART_LCR, 0xE0); 981 - status2 = serial_in(up, 0x02); /* EXCR1 */ 982 - 983 - if (!((status2 ^ status1) & UART_MCR_LOOP)) { 984 - serial_out(up, UART_LCR, 0); 985 - serial_out(up, UART_MCR, status1 ^ UART_MCR_LOOP); 986 - serial_out(up, UART_LCR, 0xE0); 987 - status2 = serial_in(up, 0x02); /* EXCR1 */ 988 - serial_out(up, UART_LCR, 0); 989 - serial_out(up, UART_MCR, status1); 990 - 991 - if ((status2 ^ status1) & UART_MCR_LOOP) { 992 - unsigned short quot; 993 - 994 - serial_out(up, UART_LCR, 0xE0); 995 - 996 - quot = serial_dl_read(up); 997 - quot <<= 3; 998 - 999 - if (ns16550a_goto_highspeed(up)) 1000 - serial_dl_write(up, quot); 1001 - 1002 - serial_out(up, UART_LCR, 0); 1003 - 1004 - up->port.uartclk = 921600*16; 1005 - up->port.type = PORT_NS16550A; 1006 - up->capabilities |= UART_NATSEMI; 1007 - return; 1008 - } 1009 - } 1010 - 1011 - /* 1012 - * No EFR. Try to detect a TI16750, which only sets bit 5 of 1013 - * the IIR when 64 byte FIFO mode is enabled when DLAB is set. 1014 - * Try setting it with and without DLAB set. Cheap clones 1015 - * set bit 5 without DLAB set. 1016 - */ 1017 - serial_out(up, UART_LCR, 0); 1018 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 1019 - status1 = serial_in(up, UART_IIR) >> 5; 1020 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1021 - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 1022 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 1023 - status2 = serial_in(up, UART_IIR) >> 5; 1024 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1025 - serial_out(up, UART_LCR, 0); 1026 - 1027 - DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2); 1028 - 1029 - if (status1 == 6 && status2 == 7) { 1030 - up->port.type = PORT_16750; 1031 - up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP; 1032 - return; 1033 - } 1034 - 1035 - /* 1036 - * Try writing and reading the UART_IER_UUE bit (b6). 1037 - * If it works, this is probably one of the Xscale platform's 1038 - * internal UARTs. 1039 - * We're going to explicitly set the UUE bit to 0 before 1040 - * trying to write and read a 1 just to make sure it's not 1041 - * already a 1 and maybe locked there before we even start start. 1042 - */ 1043 - iersave = serial_in(up, UART_IER); 1044 - serial_out(up, UART_IER, iersave & ~UART_IER_UUE); 1045 - if (!(serial_in(up, UART_IER) & UART_IER_UUE)) { 1046 - /* 1047 - * OK it's in a known zero state, try writing and reading 1048 - * without disturbing the current state of the other bits. 1049 - */ 1050 - serial_out(up, UART_IER, iersave | UART_IER_UUE); 1051 - if (serial_in(up, UART_IER) & UART_IER_UUE) { 1052 - /* 1053 - * It's an Xscale. 1054 - * We'll leave the UART_IER_UUE bit set to 1 (enabled). 1055 - */ 1056 - DEBUG_AUTOCONF("Xscale "); 1057 - up->port.type = PORT_XSCALE; 1058 - up->capabilities |= UART_CAP_UUE | UART_CAP_RTOIE; 1059 - return; 1060 - } 1061 - } else { 1062 - /* 1063 - * If we got here we couldn't force the IER_UUE bit to 0. 1064 - * Log it and continue. 1065 - */ 1066 - DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); 1067 - } 1068 - serial_out(up, UART_IER, iersave); 1069 - 1070 - /* 1071 - * Exar uarts have EFR in a weird location 1072 - */ 1073 - if (up->port.flags & UPF_EXAR_EFR) { 1074 - DEBUG_AUTOCONF("Exar XR17D15x "); 1075 - up->port.type = PORT_XR17D15X; 1076 - up->capabilities |= UART_CAP_AFE | UART_CAP_EFR | 1077 - UART_CAP_SLEEP; 1078 - 1079 - return; 1080 - } 1081 - 1082 - /* 1083 - * We distinguish between 16550A and U6 16550A by counting 1084 - * how many bytes are in the FIFO. 1085 - */ 1086 - if (up->port.type == PORT_16550A && size_fifo(up) == 64) { 1087 - up->port.type = PORT_U6_16550A; 1088 - up->capabilities |= UART_CAP_AFE; 1089 - } 1090 - } 1091 - 1092 - /* 1093 - * This routine is called by rs_init() to initialize a specific serial 1094 - * port. It determines what type of UART chip this serial port is 1095 - * using: 8250, 16450, 16550, 16550A. The important question is 1096 - * whether or not this UART is a 16550A or not, since this will 1097 - * determine whether or not we can use its FIFO features or not. 1098 - */ 1099 - static void autoconfig(struct uart_8250_port *up) 1100 - { 1101 - unsigned char status1, scratch, scratch2, scratch3; 1102 - unsigned char save_lcr, save_mcr; 1103 - struct uart_port *port = &up->port; 1104 - unsigned long flags; 1105 - unsigned int old_capabilities; 1106 - 1107 - if (!port->iobase && !port->mapbase && !port->membase) 1108 - return; 1109 - 1110 - DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ", 1111 - serial_index(port), port->iobase, port->membase); 1112 - 1113 - /* 1114 - * We really do need global IRQs disabled here - we're going to 1115 - * be frobbing the chips IRQ enable register to see if it exists. 1116 - */ 1117 - spin_lock_irqsave(&port->lock, flags); 1118 - 1119 - up->capabilities = 0; 1120 - up->bugs = 0; 1121 - 1122 - if (!(port->flags & UPF_BUGGY_UART)) { 1123 - /* 1124 - * Do a simple existence test first; if we fail this, 1125 - * there's no point trying anything else. 1126 - * 1127 - * 0x80 is used as a nonsense port to prevent against 1128 - * false positives due to ISA bus float. The 1129 - * assumption is that 0x80 is a non-existent port; 1130 - * which should be safe since include/asm/io.h also 1131 - * makes this assumption. 1132 - * 1133 - * Note: this is safe as long as MCR bit 4 is clear 1134 - * and the device is in "PC" mode. 1135 - */ 1136 - scratch = serial_in(up, UART_IER); 1137 - serial_out(up, UART_IER, 0); 1138 - #ifdef __i386__ 1139 - outb(0xff, 0x080); 1140 - #endif 1141 - /* 1142 - * Mask out IER[7:4] bits for test as some UARTs (e.g. TL 1143 - * 16C754B) allow only to modify them if an EFR bit is set. 1144 - */ 1145 - scratch2 = serial_in(up, UART_IER) & 0x0f; 1146 - serial_out(up, UART_IER, 0x0F); 1147 - #ifdef __i386__ 1148 - outb(0, 0x080); 1149 - #endif 1150 - scratch3 = serial_in(up, UART_IER) & 0x0f; 1151 - serial_out(up, UART_IER, scratch); 1152 - if (scratch2 != 0 || scratch3 != 0x0F) { 1153 - /* 1154 - * We failed; there's nothing here 1155 - */ 1156 - spin_unlock_irqrestore(&port->lock, flags); 1157 - DEBUG_AUTOCONF("IER test failed (%02x, %02x) ", 1158 - scratch2, scratch3); 1159 - goto out; 1160 - } 1161 - } 1162 - 1163 - save_mcr = serial_in(up, UART_MCR); 1164 - save_lcr = serial_in(up, UART_LCR); 1165 - 1166 - /* 1167 - * Check to see if a UART is really there. Certain broken 1168 - * internal modems based on the Rockwell chipset fail this 1169 - * test, because they apparently don't implement the loopback 1170 - * test mode. So this test is skipped on the COM 1 through 1171 - * COM 4 ports. This *should* be safe, since no board 1172 - * manufacturer would be stupid enough to design a board 1173 - * that conflicts with COM 1-4 --- we hope! 1174 - */ 1175 - if (!(port->flags & UPF_SKIP_TEST)) { 1176 - serial_out(up, UART_MCR, UART_MCR_LOOP | 0x0A); 1177 - status1 = serial_in(up, UART_MSR) & 0xF0; 1178 - serial_out(up, UART_MCR, save_mcr); 1179 - if (status1 != 0x90) { 1180 - spin_unlock_irqrestore(&port->lock, flags); 1181 - DEBUG_AUTOCONF("LOOP test failed (%02x) ", 1182 - status1); 1183 - goto out; 1184 - } 1185 - } 1186 - 1187 - /* 1188 - * We're pretty sure there's a port here. Lets find out what 1189 - * type of port it is. The IIR top two bits allows us to find 1190 - * out if it's 8250 or 16450, 16550, 16550A or later. This 1191 - * determines what we test for next. 1192 - * 1193 - * We also initialise the EFR (if any) to zero for later. The 1194 - * EFR occupies the same register location as the FCR and IIR. 1195 - */ 1196 - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 1197 - serial_out(up, UART_EFR, 0); 1198 - serial_out(up, UART_LCR, 0); 1199 - 1200 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1201 - scratch = serial_in(up, UART_IIR) >> 6; 1202 - 1203 - switch (scratch) { 1204 - case 0: 1205 - autoconfig_8250(up); 1206 - break; 1207 - case 1: 1208 - port->type = PORT_UNKNOWN; 1209 - break; 1210 - case 2: 1211 - port->type = PORT_16550; 1212 - break; 1213 - case 3: 1214 - autoconfig_16550a(up); 1215 - break; 1216 - } 1217 - 1218 - #ifdef CONFIG_SERIAL_8250_RSA 1219 - /* 1220 - * Only probe for RSA ports if we got the region. 1221 - */ 1222 - if (port->type == PORT_16550A && up->probe & UART_PROBE_RSA && 1223 - __enable_rsa(up)) 1224 - port->type = PORT_RSA; 1225 - #endif 1226 - 1227 - serial_out(up, UART_LCR, save_lcr); 1228 - 1229 - port->fifosize = uart_config[up->port.type].fifo_size; 1230 - old_capabilities = up->capabilities; 1231 - up->capabilities = uart_config[port->type].flags; 1232 - up->tx_loadsz = uart_config[port->type].tx_loadsz; 1233 - 1234 - if (port->type == PORT_UNKNOWN) 1235 - goto out_lock; 1236 - 1237 - /* 1238 - * Reset the UART. 1239 - */ 1240 - #ifdef CONFIG_SERIAL_8250_RSA 1241 - if (port->type == PORT_RSA) 1242 - serial_out(up, UART_RSA_FRR, 0); 1243 - #endif 1244 - serial_out(up, UART_MCR, save_mcr); 1245 - serial8250_clear_fifos(up); 1246 - serial_in(up, UART_RX); 1247 - if (up->capabilities & UART_CAP_UUE) 1248 - serial_out(up, UART_IER, UART_IER_UUE); 1249 - else 1250 - serial_out(up, UART_IER, 0); 1251 - 1252 - out_lock: 1253 - spin_unlock_irqrestore(&port->lock, flags); 1254 - if (up->capabilities != old_capabilities) { 1255 - printk(KERN_WARNING 1256 - "ttyS%d: detected caps %08x should be %08x\n", 1257 - serial_index(port), old_capabilities, 1258 - up->capabilities); 1259 - } 1260 - out: 1261 - DEBUG_AUTOCONF("iir=%d ", scratch); 1262 - DEBUG_AUTOCONF("type=%s\n", uart_config[port->type].name); 1263 - } 1264 - 1265 - static void autoconfig_irq(struct uart_8250_port *up) 1266 - { 1267 - struct uart_port *port = &up->port; 1268 - unsigned char save_mcr, save_ier; 1269 - unsigned char save_ICP = 0; 1270 - unsigned int ICP = 0; 1271 - unsigned long irqs; 1272 - int irq; 1273 - 1274 - if (port->flags & UPF_FOURPORT) { 1275 - ICP = (port->iobase & 0xfe0) | 0x1f; 1276 - save_ICP = inb_p(ICP); 1277 - outb_p(0x80, ICP); 1278 - inb_p(ICP); 1279 - } 1280 - 1281 - /* forget possible initially masked and pending IRQ */ 1282 - probe_irq_off(probe_irq_on()); 1283 - save_mcr = serial_in(up, UART_MCR); 1284 - save_ier = serial_in(up, UART_IER); 1285 - serial_out(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2); 1286 - 1287 - irqs = probe_irq_on(); 1288 - serial_out(up, UART_MCR, 0); 1289 - udelay(10); 1290 - if (port->flags & UPF_FOURPORT) { 1291 - serial_out(up, UART_MCR, 1292 - UART_MCR_DTR | UART_MCR_RTS); 1293 - } else { 1294 - serial_out(up, UART_MCR, 1295 - UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); 1296 - } 1297 - serial_out(up, UART_IER, 0x0f); /* enable all intrs */ 1298 - serial_in(up, UART_LSR); 1299 - serial_in(up, UART_RX); 1300 - serial_in(up, UART_IIR); 1301 - serial_in(up, UART_MSR); 1302 - serial_out(up, UART_TX, 0xFF); 1303 - udelay(20); 1304 - irq = probe_irq_off(irqs); 1305 - 1306 - serial_out(up, UART_MCR, save_mcr); 1307 - serial_out(up, UART_IER, save_ier); 1308 - 1309 - if (port->flags & UPF_FOURPORT) 1310 - outb_p(save_ICP, ICP); 1311 - 1312 - port->irq = (irq > 0) ? irq : 0; 1313 - } 1314 - 1315 - static inline void __stop_tx(struct uart_8250_port *p) 1316 - { 1317 - if (p->ier & UART_IER_THRI) { 1318 - p->ier &= ~UART_IER_THRI; 1319 - serial_out(p, UART_IER, p->ier); 1320 - serial8250_rpm_put_tx(p); 1321 - } 1322 - } 1323 - 1324 - static void serial8250_stop_tx(struct uart_port *port) 1325 - { 1326 - struct uart_8250_port *up = up_to_u8250p(port); 1327 - 1328 - serial8250_rpm_get(up); 1329 - __stop_tx(up); 1330 - 1331 - /* 1332 - * We really want to stop the transmitter from sending. 1333 - */ 1334 - if (port->type == PORT_16C950) { 1335 - up->acr |= UART_ACR_TXDIS; 1336 - serial_icr_write(up, UART_ACR, up->acr); 1337 - } 1338 - serial8250_rpm_put(up); 1339 - } 1340 - 1341 - static void serial8250_start_tx(struct uart_port *port) 1342 - { 1343 - struct uart_8250_port *up = up_to_u8250p(port); 1344 - 1345 - serial8250_rpm_get_tx(up); 1346 - 1347 - if (up->dma && !up->dma->tx_dma(up)) 1348 - return; 1349 - 1350 - if (!(up->ier & UART_IER_THRI)) { 1351 - up->ier |= UART_IER_THRI; 1352 - serial_port_out(port, UART_IER, up->ier); 1353 - 1354 - if (up->bugs & UART_BUG_TXEN) { 1355 - unsigned char lsr; 1356 - lsr = serial_in(up, UART_LSR); 1357 - up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; 1358 - if (lsr & UART_LSR_THRE) 1359 - serial8250_tx_chars(up); 1360 - } 1361 - } 1362 - 1363 - /* 1364 - * Re-enable the transmitter if we disabled it. 1365 - */ 1366 - if (port->type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { 1367 - up->acr &= ~UART_ACR_TXDIS; 1368 - serial_icr_write(up, UART_ACR, up->acr); 1369 - } 1370 - } 1371 - 1372 - static void serial8250_throttle(struct uart_port *port) 1373 - { 1374 - port->throttle(port); 1375 - } 1376 - 1377 - static void serial8250_unthrottle(struct uart_port *port) 1378 - { 1379 - port->unthrottle(port); 1380 - } 1381 - 1382 - static void serial8250_stop_rx(struct uart_port *port) 1383 - { 1384 - struct uart_8250_port *up = up_to_u8250p(port); 1385 - 1386 - serial8250_rpm_get(up); 1387 - 1388 - up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); 1389 - up->port.read_status_mask &= ~UART_LSR_DR; 1390 - serial_port_out(port, UART_IER, up->ier); 1391 - 1392 - serial8250_rpm_put(up); 1393 - } 1394 - 1395 - static void serial8250_disable_ms(struct uart_port *port) 1396 - { 1397 - struct uart_8250_port *up = 1398 - container_of(port, struct uart_8250_port, port); 1399 - 1400 - /* no MSR capabilities */ 1401 - if (up->bugs & UART_BUG_NOMSR) 1402 - return; 1403 - 1404 - up->ier &= ~UART_IER_MSI; 1405 - serial_port_out(port, UART_IER, up->ier); 1406 - } 1407 - 1408 - static void serial8250_enable_ms(struct uart_port *port) 1409 - { 1410 - struct uart_8250_port *up = up_to_u8250p(port); 1411 - 1412 - /* no MSR capabilities */ 1413 - if (up->bugs & UART_BUG_NOMSR) 1414 - return; 1415 - 1416 - up->ier |= UART_IER_MSI; 1417 - 1418 - serial8250_rpm_get(up); 1419 - serial_port_out(port, UART_IER, up->ier); 1420 - serial8250_rpm_put(up); 1421 - } 1422 - 1423 - /* 1424 - * serial8250_rx_chars: processes according to the passed in LSR 1425 - * value, and returns the remaining LSR bits not handled 1426 - * by this Rx routine. 1427 - */ 1428 - unsigned char 1429 - serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr) 1430 - { 1431 - struct uart_port *port = &up->port; 1432 - unsigned char ch; 1433 - int max_count = 256; 1434 - char flag; 1435 - 1436 - do { 1437 - if (likely(lsr & UART_LSR_DR)) 1438 - ch = serial_in(up, UART_RX); 1439 - else 1440 - /* 1441 - * Intel 82571 has a Serial Over Lan device that will 1442 - * set UART_LSR_BI without setting UART_LSR_DR when 1443 - * it receives a break. To avoid reading from the 1444 - * receive buffer without UART_LSR_DR bit set, we 1445 - * just force the read character to be 0 1446 - */ 1447 - ch = 0; 1448 - 1449 - flag = TTY_NORMAL; 1450 - port->icount.rx++; 1451 - 1452 - lsr |= up->lsr_saved_flags; 1453 - up->lsr_saved_flags = 0; 1454 - 1455 - if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { 1456 - if (lsr & UART_LSR_BI) { 1457 - lsr &= ~(UART_LSR_FE | UART_LSR_PE); 1458 - port->icount.brk++; 1459 - /* 1460 - * We do the SysRQ and SAK checking 1461 - * here because otherwise the break 1462 - * may get masked by ignore_status_mask 1463 - * or read_status_mask. 1464 - */ 1465 - if (uart_handle_break(port)) 1466 - goto ignore_char; 1467 - } else if (lsr & UART_LSR_PE) 1468 - port->icount.parity++; 1469 - else if (lsr & UART_LSR_FE) 1470 - port->icount.frame++; 1471 - if (lsr & UART_LSR_OE) 1472 - port->icount.overrun++; 1473 - 1474 - /* 1475 - * Mask off conditions which should be ignored. 1476 - */ 1477 - lsr &= port->read_status_mask; 1478 - 1479 - if (lsr & UART_LSR_BI) { 1480 - DEBUG_INTR("handling break...."); 1481 - flag = TTY_BREAK; 1482 - } else if (lsr & UART_LSR_PE) 1483 - flag = TTY_PARITY; 1484 - else if (lsr & UART_LSR_FE) 1485 - flag = TTY_FRAME; 1486 - } 1487 - if (uart_handle_sysrq_char(port, ch)) 1488 - goto ignore_char; 1489 - 1490 - uart_insert_char(port, lsr, UART_LSR_OE, ch, flag); 1491 - 1492 - ignore_char: 1493 - lsr = serial_in(up, UART_LSR); 1494 - } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (--max_count > 0)); 1495 - spin_unlock(&port->lock); 1496 - tty_flip_buffer_push(&port->state->port); 1497 - spin_lock(&port->lock); 1498 - return lsr; 1499 - } 1500 - EXPORT_SYMBOL_GPL(serial8250_rx_chars); 1501 - 1502 - void serial8250_tx_chars(struct uart_8250_port *up) 1503 - { 1504 - struct uart_port *port = &up->port; 1505 - struct circ_buf *xmit = &port->state->xmit; 1506 - int count; 1507 - 1508 - if (port->x_char) { 1509 - serial_out(up, UART_TX, port->x_char); 1510 - port->icount.tx++; 1511 - port->x_char = 0; 1512 - return; 1513 - } 1514 - if (uart_tx_stopped(port)) { 1515 - serial8250_stop_tx(port); 1516 - return; 1517 - } 1518 - if (uart_circ_empty(xmit)) { 1519 - __stop_tx(up); 1520 - return; 1521 - } 1522 - 1523 - count = up->tx_loadsz; 1524 - do { 1525 - serial_out(up, UART_TX, xmit->buf[xmit->tail]); 1526 - xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 1527 - port->icount.tx++; 1528 - if (uart_circ_empty(xmit)) 1529 - break; 1530 - if (up->capabilities & UART_CAP_HFIFO) { 1531 - if ((serial_port_in(port, UART_LSR) & BOTH_EMPTY) != 1532 - BOTH_EMPTY) 1533 - break; 1534 - } 1535 - } while (--count > 0); 1536 - 1537 - if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 1538 - uart_write_wakeup(port); 1539 - 1540 - DEBUG_INTR("THRE..."); 1541 - 1542 - /* 1543 - * With RPM enabled, we have to wait until the FIFO is empty before the 1544 - * HW can go idle. So we get here once again with empty FIFO and disable 1545 - * the interrupt and RPM in __stop_tx() 1546 - */ 1547 - if (uart_circ_empty(xmit) && !(up->capabilities & UART_CAP_RPM)) 1548 - __stop_tx(up); 1549 - } 1550 - EXPORT_SYMBOL_GPL(serial8250_tx_chars); 1551 - 1552 - /* Caller holds uart port lock */ 1553 - unsigned int serial8250_modem_status(struct uart_8250_port *up) 1554 - { 1555 - struct uart_port *port = &up->port; 1556 - unsigned int status = serial_in(up, UART_MSR); 1557 - 1558 - status |= up->msr_saved_flags; 1559 - up->msr_saved_flags = 0; 1560 - if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && 1561 - port->state != NULL) { 1562 - if (status & UART_MSR_TERI) 1563 - port->icount.rng++; 1564 - if (status & UART_MSR_DDSR) 1565 - port->icount.dsr++; 1566 - if (status & UART_MSR_DDCD) 1567 - uart_handle_dcd_change(port, status & UART_MSR_DCD); 1568 - if (status & UART_MSR_DCTS) 1569 - uart_handle_cts_change(port, status & UART_MSR_CTS); 1570 - 1571 - wake_up_interruptible(&port->state->port.delta_msr_wait); 1572 - } 1573 - 1574 - return status; 1575 - } 1576 - EXPORT_SYMBOL_GPL(serial8250_modem_status); 1577 - 1578 - /* 1579 - * This handles the interrupt from one port. 1580 - */ 1581 - int serial8250_handle_irq(struct uart_port *port, unsigned int iir) 1582 - { 1583 - unsigned char status; 1584 - unsigned long flags; 1585 - struct uart_8250_port *up = up_to_u8250p(port); 1586 - int dma_err = 0; 1587 - 1588 - if (iir & UART_IIR_NO_INT) 1589 - return 0; 1590 - 1591 - spin_lock_irqsave(&port->lock, flags); 1592 - 1593 - status = serial_port_in(port, UART_LSR); 1594 - 1595 - DEBUG_INTR("status = %x...", status); 1596 - 1597 - if (status & (UART_LSR_DR | UART_LSR_BI)) { 1598 - if (up->dma) 1599 - dma_err = up->dma->rx_dma(up, iir); 1600 - 1601 - if (!up->dma || dma_err) 1602 - status = serial8250_rx_chars(up, status); 1603 - } 1604 - serial8250_modem_status(up); 1605 - if ((!up->dma || (up->dma && up->dma->tx_err)) && 1606 - (status & UART_LSR_THRE)) 1607 - serial8250_tx_chars(up); 1608 - 1609 - spin_unlock_irqrestore(&port->lock, flags); 1610 - return 1; 1611 - } 1612 - EXPORT_SYMBOL_GPL(serial8250_handle_irq); 1613 - 1614 - static int serial8250_default_handle_irq(struct uart_port *port) 1615 - { 1616 - struct uart_8250_port *up = up_to_u8250p(port); 1617 - unsigned int iir; 1618 - int ret; 1619 - 1620 - serial8250_rpm_get(up); 1621 - 1622 - iir = serial_port_in(port, UART_IIR); 1623 - ret = serial8250_handle_irq(port, iir); 1624 - 1625 - serial8250_rpm_put(up); 1626 - return ret; 1627 - } 1628 - 1629 - /* 1630 - * These Exar UARTs have an extra interrupt indicator that could 1631 - * fire for a few unimplemented interrupts. One of which is a 1632 - * wakeup event when coming out of sleep. Put this here just 1633 - * to be on the safe side that these interrupts don't go unhandled. 1634 - */ 1635 - static int exar_handle_irq(struct uart_port *port) 1636 - { 1637 - unsigned char int0, int1, int2, int3; 1638 - unsigned int iir = serial_port_in(port, UART_IIR); 1639 - int ret; 1640 - 1641 - ret = serial8250_handle_irq(port, iir); 1642 - 1643 - if ((port->type == PORT_XR17V35X) || 1644 - (port->type == PORT_XR17D15X)) { 1645 - int0 = serial_port_in(port, 0x80); 1646 - int1 = serial_port_in(port, 0x81); 1647 - int2 = serial_port_in(port, 0x82); 1648 - int3 = serial_port_in(port, 0x83); 1649 - } 1650 - 1651 - return ret; 1652 - } 1653 121 1654 122 /* 1655 123 * This is the serial driver's interrupt routine. ··· 359 1941 serial_unlink_irq_chain(up); 360 1942 } 361 1943 362 - static unsigned int serial8250_tx_empty(struct uart_port *port) 363 - { 364 - struct uart_8250_port *up = up_to_u8250p(port); 365 - unsigned long flags; 366 - unsigned int lsr; 367 - 368 - serial8250_rpm_get(up); 369 - 370 - spin_lock_irqsave(&port->lock, flags); 371 - lsr = serial_port_in(port, UART_LSR); 372 - up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; 373 - spin_unlock_irqrestore(&port->lock, flags); 374 - 375 - serial8250_rpm_put(up); 376 - 377 - return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0; 378 - } 379 - 380 - static unsigned int serial8250_get_mctrl(struct uart_port *port) 381 - { 382 - struct uart_8250_port *up = up_to_u8250p(port); 383 - unsigned int status; 384 - unsigned int ret; 385 - 386 - serial8250_rpm_get(up); 387 - status = serial8250_modem_status(up); 388 - serial8250_rpm_put(up); 389 - 390 - ret = 0; 391 - if (status & UART_MSR_DCD) 392 - ret |= TIOCM_CAR; 393 - if (status & UART_MSR_RI) 394 - ret |= TIOCM_RNG; 395 - if (status & UART_MSR_DSR) 396 - ret |= TIOCM_DSR; 397 - if (status & UART_MSR_CTS) 398 - ret |= TIOCM_CTS; 399 - return ret; 400 - } 401 - 402 - void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl) 403 - { 404 - struct uart_8250_port *up = up_to_u8250p(port); 405 - unsigned char mcr = 0; 406 - 407 - if (mctrl & TIOCM_RTS) 408 - mcr |= UART_MCR_RTS; 409 - if (mctrl & TIOCM_DTR) 410 - mcr |= UART_MCR_DTR; 411 - if (mctrl & TIOCM_OUT1) 412 - mcr |= UART_MCR_OUT1; 413 - if (mctrl & TIOCM_OUT2) 414 - mcr |= UART_MCR_OUT2; 415 - if (mctrl & TIOCM_LOOP) 416 - mcr |= UART_MCR_LOOP; 417 - 418 - mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; 419 - 420 - serial_port_out(port, UART_MCR, mcr); 421 - } 422 - EXPORT_SYMBOL_GPL(serial8250_do_set_mctrl); 423 - 424 - static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) 425 - { 426 - if (port->set_mctrl) 427 - port->set_mctrl(port, mctrl); 428 - else 429 - serial8250_do_set_mctrl(port, mctrl); 430 - } 431 - 432 - static void serial8250_break_ctl(struct uart_port *port, int break_state) 433 - { 434 - struct uart_8250_port *up = up_to_u8250p(port); 435 - unsigned long flags; 436 - 437 - serial8250_rpm_get(up); 438 - spin_lock_irqsave(&port->lock, flags); 439 - if (break_state == -1) 440 - up->lcr |= UART_LCR_SBC; 441 - else 442 - up->lcr &= ~UART_LCR_SBC; 443 - serial_port_out(port, UART_LCR, up->lcr); 444 - spin_unlock_irqrestore(&port->lock, flags); 445 - serial8250_rpm_put(up); 446 - } 447 - 448 - /* 449 - * Wait for transmitter & holding register to empty 450 - */ 451 - static void wait_for_xmitr(struct uart_8250_port *up, int bits) 452 - { 453 - unsigned int status, tmout = 10000; 454 - 455 - /* Wait up to 10ms for the character(s) to be sent. */ 456 - for (;;) { 457 - status = serial_in(up, UART_LSR); 458 - 459 - up->lsr_saved_flags |= status & LSR_SAVE_FLAGS; 460 - 461 - if ((status & bits) == bits) 462 - break; 463 - if (--tmout == 0) 464 - break; 465 - udelay(1); 466 - } 467 - 468 - /* Wait up to 1s for flow control if necessary */ 469 - if (up->port.flags & UPF_CONS_FLOW) { 470 - unsigned int tmout; 471 - for (tmout = 1000000; tmout; tmout--) { 472 - unsigned int msr = serial_in(up, UART_MSR); 473 - up->msr_saved_flags |= msr & MSR_SAVE_FLAGS; 474 - if (msr & UART_MSR_CTS) 475 - break; 476 - udelay(1); 477 - touch_nmi_watchdog(); 478 - } 479 - } 480 - } 481 - 482 - #ifdef CONFIG_CONSOLE_POLL 483 - /* 484 - * Console polling routines for writing and reading from the uart while 485 - * in an interrupt or debug context. 486 - */ 487 - 488 - static int serial8250_get_poll_char(struct uart_port *port) 489 - { 490 - struct uart_8250_port *up = up_to_u8250p(port); 491 - unsigned char lsr; 492 - int status; 493 - 494 - serial8250_rpm_get(up); 495 - 496 - lsr = serial_port_in(port, UART_LSR); 497 - 498 - if (!(lsr & UART_LSR_DR)) { 499 - status = NO_POLL_CHAR; 500 - goto out; 501 - } 502 - 503 - status = serial_port_in(port, UART_RX); 504 - out: 505 - serial8250_rpm_put(up); 506 - return status; 507 - } 508 - 509 - 510 - static void serial8250_put_poll_char(struct uart_port *port, 511 - unsigned char c) 512 - { 513 - unsigned int ier; 514 - struct uart_8250_port *up = up_to_u8250p(port); 515 - 516 - serial8250_rpm_get(up); 517 - /* 518 - * First save the IER then disable the interrupts 519 - */ 520 - ier = serial_port_in(port, UART_IER); 521 - if (up->capabilities & UART_CAP_UUE) 522 - serial_port_out(port, UART_IER, UART_IER_UUE); 523 - else 524 - serial_port_out(port, UART_IER, 0); 525 - 526 - wait_for_xmitr(up, BOTH_EMPTY); 527 - /* 528 - * Send the character out. 529 - */ 530 - serial_port_out(port, UART_TX, c); 531 - 532 - /* 533 - * Finally, wait for transmitter to become empty 534 - * and restore the IER 535 - */ 536 - wait_for_xmitr(up, BOTH_EMPTY); 537 - serial_port_out(port, UART_IER, ier); 538 - serial8250_rpm_put(up); 539 - } 540 - 541 - #endif /* CONFIG_CONSOLE_POLL */ 542 - 543 - int serial8250_do_startup(struct uart_port *port) 544 - { 545 - struct uart_8250_port *up = up_to_u8250p(port); 546 - unsigned long flags; 547 - unsigned char lsr, iir; 548 - int retval; 549 - 550 - if (port->type == PORT_8250_CIR) 551 - return -ENODEV; 552 - 553 - if (!port->fifosize) 554 - port->fifosize = uart_config[port->type].fifo_size; 555 - if (!up->tx_loadsz) 556 - up->tx_loadsz = uart_config[port->type].tx_loadsz; 557 - if (!up->capabilities) 558 - up->capabilities = uart_config[port->type].flags; 559 - up->mcr = 0; 560 - 561 - if (port->iotype != up->cur_iotype) 562 - set_io_from_upio(port); 563 - 564 - serial8250_rpm_get(up); 565 - if (port->type == PORT_16C950) { 566 - /* Wake up and initialize UART */ 567 - up->acr = 0; 568 - serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 569 - serial_port_out(port, UART_EFR, UART_EFR_ECB); 570 - serial_port_out(port, UART_IER, 0); 571 - serial_port_out(port, UART_LCR, 0); 572 - serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ 573 - serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 574 - serial_port_out(port, UART_EFR, UART_EFR_ECB); 575 - serial_port_out(port, UART_LCR, 0); 576 - } 577 - 578 - #ifdef CONFIG_SERIAL_8250_RSA 579 - /* 580 - * If this is an RSA port, see if we can kick it up to the 581 - * higher speed clock. 582 - */ 583 - enable_rsa(up); 584 - #endif 585 - /* 586 - * Clear the FIFO buffers and disable them. 587 - * (they will be reenabled in set_termios()) 588 - */ 589 - serial8250_clear_fifos(up); 590 - 591 - /* 592 - * Clear the interrupt registers. 593 - */ 594 - serial_port_in(port, UART_LSR); 595 - serial_port_in(port, UART_RX); 596 - serial_port_in(port, UART_IIR); 597 - serial_port_in(port, UART_MSR); 598 - 599 - /* 600 - * At this point, there's no way the LSR could still be 0xff; 601 - * if it is, then bail out, because there's likely no UART 602 - * here. 603 - */ 604 - if (!(port->flags & UPF_BUGGY_UART) && 605 - (serial_port_in(port, UART_LSR) == 0xff)) { 606 - printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n", 607 - serial_index(port)); 608 - retval = -ENODEV; 609 - goto out; 610 - } 611 - 612 - /* 613 - * For a XR16C850, we need to set the trigger levels 614 - */ 615 - if (port->type == PORT_16850) { 616 - unsigned char fctr; 617 - 618 - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 619 - 620 - fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); 621 - serial_port_out(port, UART_FCTR, 622 - fctr | UART_FCTR_TRGD | UART_FCTR_RX); 623 - serial_port_out(port, UART_TRG, UART_TRG_96); 624 - serial_port_out(port, UART_FCTR, 625 - fctr | UART_FCTR_TRGD | UART_FCTR_TX); 626 - serial_port_out(port, UART_TRG, UART_TRG_96); 627 - 628 - serial_port_out(port, UART_LCR, 0); 629 - } 630 - 631 - if (port->irq) { 632 - unsigned char iir1; 633 - /* 634 - * Test for UARTs that do not reassert THRE when the 635 - * transmitter is idle and the interrupt has already 636 - * been cleared. Real 16550s should always reassert 637 - * this interrupt whenever the transmitter is idle and 638 - * the interrupt is enabled. Delays are necessary to 639 - * allow register changes to become visible. 640 - */ 641 - spin_lock_irqsave(&port->lock, flags); 642 - if (up->port.irqflags & IRQF_SHARED) 643 - disable_irq_nosync(port->irq); 644 - 645 - wait_for_xmitr(up, UART_LSR_THRE); 646 - serial_port_out_sync(port, UART_IER, UART_IER_THRI); 647 - udelay(1); /* allow THRE to set */ 648 - iir1 = serial_port_in(port, UART_IIR); 649 - serial_port_out(port, UART_IER, 0); 650 - serial_port_out_sync(port, UART_IER, UART_IER_THRI); 651 - udelay(1); /* allow a working UART time to re-assert THRE */ 652 - iir = serial_port_in(port, UART_IIR); 653 - serial_port_out(port, UART_IER, 0); 654 - 655 - if (port->irqflags & IRQF_SHARED) 656 - enable_irq(port->irq); 657 - spin_unlock_irqrestore(&port->lock, flags); 658 - 659 - /* 660 - * If the interrupt is not reasserted, or we otherwise 661 - * don't trust the iir, setup a timer to kick the UART 662 - * on a regular basis. 663 - */ 664 - if ((!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) || 665 - up->port.flags & UPF_BUG_THRE) { 666 - up->bugs |= UART_BUG_THRE; 667 - } 668 - } 669 - 670 - retval = up->ops->setup_irq(up); 671 - if (retval) 672 - goto out; 673 - 674 - /* 675 - * Now, initialize the UART 676 - */ 677 - serial_port_out(port, UART_LCR, UART_LCR_WLEN8); 678 - 679 - spin_lock_irqsave(&port->lock, flags); 680 - if (up->port.flags & UPF_FOURPORT) { 681 - if (!up->port.irq) 682 - up->port.mctrl |= TIOCM_OUT1; 683 - } else 684 - /* 685 - * Most PC uarts need OUT2 raised to enable interrupts. 686 - */ 687 - if (port->irq) 688 - up->port.mctrl |= TIOCM_OUT2; 689 - 690 - serial8250_set_mctrl(port, port->mctrl); 691 - 692 - /* Serial over Lan (SoL) hack: 693 - Intel 8257x Gigabit ethernet chips have a 694 - 16550 emulation, to be used for Serial Over Lan. 695 - Those chips take a longer time than a normal 696 - serial device to signalize that a transmission 697 - data was queued. Due to that, the above test generally 698 - fails. One solution would be to delay the reading of 699 - iir. However, this is not reliable, since the timeout 700 - is variable. So, let's just don't test if we receive 701 - TX irq. This way, we'll never enable UART_BUG_TXEN. 702 - */ 703 - if (up->port.flags & UPF_NO_TXEN_TEST) 704 - goto dont_test_tx_en; 705 - 706 - /* 707 - * Do a quick test to see if we receive an 708 - * interrupt when we enable the TX irq. 709 - */ 710 - serial_port_out(port, UART_IER, UART_IER_THRI); 711 - lsr = serial_port_in(port, UART_LSR); 712 - iir = serial_port_in(port, UART_IIR); 713 - serial_port_out(port, UART_IER, 0); 714 - 715 - if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { 716 - if (!(up->bugs & UART_BUG_TXEN)) { 717 - up->bugs |= UART_BUG_TXEN; 718 - pr_debug("ttyS%d - enabling bad tx status workarounds\n", 719 - serial_index(port)); 720 - } 721 - } else { 722 - up->bugs &= ~UART_BUG_TXEN; 723 - } 724 - 725 - dont_test_tx_en: 726 - spin_unlock_irqrestore(&port->lock, flags); 727 - 728 - /* 729 - * Clear the interrupt registers again for luck, and clear the 730 - * saved flags to avoid getting false values from polling 731 - * routines or the previous session. 732 - */ 733 - serial_port_in(port, UART_LSR); 734 - serial_port_in(port, UART_RX); 735 - serial_port_in(port, UART_IIR); 736 - serial_port_in(port, UART_MSR); 737 - up->lsr_saved_flags = 0; 738 - up->msr_saved_flags = 0; 739 - 740 - /* 741 - * Request DMA channels for both RX and TX. 742 - */ 743 - if (up->dma) { 744 - retval = serial8250_request_dma(up); 745 - if (retval) { 746 - pr_warn_ratelimited("ttyS%d - failed to request DMA\n", 747 - serial_index(port)); 748 - up->dma = NULL; 749 - } 750 - } 751 - 752 - /* 753 - * Finally, enable interrupts. Note: Modem status interrupts 754 - * are set via set_termios(), which will be occurring imminently 755 - * anyway, so we don't enable them here. 756 - */ 757 - up->ier = UART_IER_RLSI | UART_IER_RDI; 758 - serial_port_out(port, UART_IER, up->ier); 759 - 760 - if (port->flags & UPF_FOURPORT) { 761 - unsigned int icp; 762 - /* 763 - * Enable interrupts on the AST Fourport board 764 - */ 765 - icp = (port->iobase & 0xfe0) | 0x01f; 766 - outb_p(0x80, icp); 767 - inb_p(icp); 768 - } 769 - retval = 0; 770 - out: 771 - serial8250_rpm_put(up); 772 - return retval; 773 - } 774 - EXPORT_SYMBOL_GPL(serial8250_do_startup); 775 - 776 - static int serial8250_startup(struct uart_port *port) 777 - { 778 - if (port->startup) 779 - return port->startup(port); 780 - return serial8250_do_startup(port); 781 - } 782 - 783 - void serial8250_do_shutdown(struct uart_port *port) 784 - { 785 - struct uart_8250_port *up = up_to_u8250p(port); 786 - unsigned long flags; 787 - 788 - serial8250_rpm_get(up); 789 - /* 790 - * Disable interrupts from this port 791 - */ 792 - up->ier = 0; 793 - serial_port_out(port, UART_IER, 0); 794 - 795 - if (up->dma) 796 - serial8250_release_dma(up); 797 - 798 - spin_lock_irqsave(&port->lock, flags); 799 - if (port->flags & UPF_FOURPORT) { 800 - /* reset interrupts on the AST Fourport board */ 801 - inb((port->iobase & 0xfe0) | 0x1f); 802 - port->mctrl |= TIOCM_OUT1; 803 - } else 804 - port->mctrl &= ~TIOCM_OUT2; 805 - 806 - serial8250_set_mctrl(port, port->mctrl); 807 - spin_unlock_irqrestore(&port->lock, flags); 808 - 809 - /* 810 - * Disable break condition and FIFOs 811 - */ 812 - serial_port_out(port, UART_LCR, 813 - serial_port_in(port, UART_LCR) & ~UART_LCR_SBC); 814 - serial8250_clear_fifos(up); 815 - 816 - #ifdef CONFIG_SERIAL_8250_RSA 817 - /* 818 - * Reset the RSA board back to 115kbps compat mode. 819 - */ 820 - disable_rsa(up); 821 - #endif 822 - 823 - /* 824 - * Read data port to reset things, and then unlink from 825 - * the IRQ chain. 826 - */ 827 - serial_port_in(port, UART_RX); 828 - serial8250_rpm_put(up); 829 - 830 - up->ops->release_irq(up); 831 - } 832 - EXPORT_SYMBOL_GPL(serial8250_do_shutdown); 833 - 834 - static void serial8250_shutdown(struct uart_port *port) 835 - { 836 - if (port->shutdown) 837 - port->shutdown(port); 838 - else 839 - serial8250_do_shutdown(port); 840 - } 841 - 842 - /* 843 - * XR17V35x UARTs have an extra fractional divisor register (DLD) 844 - * Calculate divisor with extra 4-bit fractional portion 845 - */ 846 - static unsigned int xr17v35x_get_divisor(struct uart_8250_port *up, 847 - unsigned int baud, 848 - unsigned int *frac) 849 - { 850 - struct uart_port *port = &up->port; 851 - unsigned int quot_16; 852 - 853 - quot_16 = DIV_ROUND_CLOSEST(port->uartclk, baud); 854 - *frac = quot_16 & 0x0f; 855 - 856 - return quot_16 >> 4; 857 - } 858 - 859 - static unsigned int serial8250_get_divisor(struct uart_8250_port *up, 860 - unsigned int baud, 861 - unsigned int *frac) 862 - { 863 - struct uart_port *port = &up->port; 864 - unsigned int quot; 865 - 866 - /* 867 - * Handle magic divisors for baud rates above baud_base on 868 - * SMSC SuperIO chips. 869 - * 870 - */ 871 - if ((port->flags & UPF_MAGIC_MULTIPLIER) && 872 - baud == (port->uartclk/4)) 873 - quot = 0x8001; 874 - else if ((port->flags & UPF_MAGIC_MULTIPLIER) && 875 - baud == (port->uartclk/8)) 876 - quot = 0x8002; 877 - else if (up->port.type == PORT_XR17V35X) 878 - quot = xr17v35x_get_divisor(up, baud, frac); 879 - else 880 - quot = uart_get_divisor(port, baud); 881 - 882 - /* 883 - * Oxford Semi 952 rev B workaround 884 - */ 885 - if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) 886 - quot++; 887 - 888 - return quot; 889 - } 890 - 891 - static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, 892 - tcflag_t c_cflag) 893 - { 894 - unsigned char cval; 895 - 896 - switch (c_cflag & CSIZE) { 897 - case CS5: 898 - cval = UART_LCR_WLEN5; 899 - break; 900 - case CS6: 901 - cval = UART_LCR_WLEN6; 902 - break; 903 - case CS7: 904 - cval = UART_LCR_WLEN7; 905 - break; 906 - default: 907 - case CS8: 908 - cval = UART_LCR_WLEN8; 909 - break; 910 - } 911 - 912 - if (c_cflag & CSTOPB) 913 - cval |= UART_LCR_STOP; 914 - if (c_cflag & PARENB) { 915 - cval |= UART_LCR_PARITY; 916 - if (up->bugs & UART_BUG_PARITY) 917 - up->fifo_bug = true; 918 - } 919 - if (!(c_cflag & PARODD)) 920 - cval |= UART_LCR_EPAR; 921 - #ifdef CMSPAR 922 - if (c_cflag & CMSPAR) 923 - cval |= UART_LCR_SPAR; 924 - #endif 925 - 926 - return cval; 927 - } 928 - 929 - static void serial8250_set_divisor(struct uart_port *port, unsigned int baud, 930 - unsigned int quot, unsigned int quot_frac) 931 - { 932 - struct uart_8250_port *up = up_to_u8250p(port); 933 - 934 - /* Workaround to enable 115200 baud on OMAP1510 internal ports */ 935 - if (is_omap1510_8250(up)) { 936 - if (baud == 115200) { 937 - quot = 1; 938 - serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1); 939 - } else 940 - serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0); 941 - } 942 - 943 - /* 944 - * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2, 945 - * otherwise just set DLAB 946 - */ 947 - if (up->capabilities & UART_NATSEMI) 948 - serial_port_out(port, UART_LCR, 0xe0); 949 - else 950 - serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB); 951 - 952 - serial_dl_write(up, quot); 953 - 954 - /* XR17V35x UARTs have an extra fractional divisor register (DLD) */ 955 - if (up->port.type == PORT_XR17V35X) 956 - serial_port_out(port, 0x2, quot_frac); 957 - } 958 - 959 - void 960 - serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, 961 - struct ktermios *old) 962 - { 963 - struct uart_8250_port *up = up_to_u8250p(port); 964 - unsigned char cval; 965 - unsigned long flags; 966 - unsigned int baud, quot, frac = 0; 967 - 968 - cval = serial8250_compute_lcr(up, termios->c_cflag); 969 - 970 - /* 971 - * Ask the core to calculate the divisor for us. 972 - */ 973 - baud = uart_get_baud_rate(port, termios, old, 974 - port->uartclk / 16 / 0xffff, 975 - port->uartclk / 16); 976 - quot = serial8250_get_divisor(up, baud, &frac); 977 - 978 - /* 979 - * Ok, we're now changing the port state. Do it with 980 - * interrupts disabled. 981 - */ 982 - serial8250_rpm_get(up); 983 - spin_lock_irqsave(&port->lock, flags); 984 - 985 - up->lcr = cval; /* Save computed LCR */ 986 - 987 - if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { 988 - /* NOTE: If fifo_bug is not set, a user can set RX_trigger. */ 989 - if ((baud < 2400 && !up->dma) || up->fifo_bug) { 990 - up->fcr &= ~UART_FCR_TRIGGER_MASK; 991 - up->fcr |= UART_FCR_TRIGGER_1; 992 - } 993 - } 994 - 995 - /* 996 - * MCR-based auto flow control. When AFE is enabled, RTS will be 997 - * deasserted when the receive FIFO contains more characters than 998 - * the trigger, or the MCR RTS bit is cleared. In the case where 999 - * the remote UART is not using CTS auto flow control, we must 1000 - * have sufficient FIFO entries for the latency of the remote 1001 - * UART to respond. IOW, at least 32 bytes of FIFO. 1002 - */ 1003 - if (up->capabilities & UART_CAP_AFE && port->fifosize >= 32) { 1004 - up->mcr &= ~UART_MCR_AFE; 1005 - if (termios->c_cflag & CRTSCTS) 1006 - up->mcr |= UART_MCR_AFE; 1007 - } 1008 - 1009 - /* 1010 - * Update the per-port timeout. 1011 - */ 1012 - uart_update_timeout(port, termios->c_cflag, baud); 1013 - 1014 - port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 1015 - if (termios->c_iflag & INPCK) 1016 - port->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 1017 - if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) 1018 - port->read_status_mask |= UART_LSR_BI; 1019 - 1020 - /* 1021 - * Characteres to ignore 1022 - */ 1023 - port->ignore_status_mask = 0; 1024 - if (termios->c_iflag & IGNPAR) 1025 - port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 1026 - if (termios->c_iflag & IGNBRK) { 1027 - port->ignore_status_mask |= UART_LSR_BI; 1028 - /* 1029 - * If we're ignoring parity and break indicators, 1030 - * ignore overruns too (for real raw support). 1031 - */ 1032 - if (termios->c_iflag & IGNPAR) 1033 - port->ignore_status_mask |= UART_LSR_OE; 1034 - } 1035 - 1036 - /* 1037 - * ignore all characters if CREAD is not set 1038 - */ 1039 - if ((termios->c_cflag & CREAD) == 0) 1040 - port->ignore_status_mask |= UART_LSR_DR; 1041 - 1042 - /* 1043 - * CTS flow control flag and modem status interrupts 1044 - */ 1045 - up->ier &= ~UART_IER_MSI; 1046 - if (!(up->bugs & UART_BUG_NOMSR) && 1047 - UART_ENABLE_MS(&up->port, termios->c_cflag)) 1048 - up->ier |= UART_IER_MSI; 1049 - if (up->capabilities & UART_CAP_UUE) 1050 - up->ier |= UART_IER_UUE; 1051 - if (up->capabilities & UART_CAP_RTOIE) 1052 - up->ier |= UART_IER_RTOIE; 1053 - 1054 - serial_port_out(port, UART_IER, up->ier); 1055 - 1056 - if (up->capabilities & UART_CAP_EFR) { 1057 - unsigned char efr = 0; 1058 - /* 1059 - * TI16C752/Startech hardware flow control. FIXME: 1060 - * - TI16C752 requires control thresholds to be set. 1061 - * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled. 1062 - */ 1063 - if (termios->c_cflag & CRTSCTS) 1064 - efr |= UART_EFR_CTS; 1065 - 1066 - serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 1067 - if (port->flags & UPF_EXAR_EFR) 1068 - serial_port_out(port, UART_XR_EFR, efr); 1069 - else 1070 - serial_port_out(port, UART_EFR, efr); 1071 - } 1072 - 1073 - serial8250_set_divisor(port, baud, quot, frac); 1074 - 1075 - /* 1076 - * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR 1077 - * is written without DLAB set, this mode will be disabled. 1078 - */ 1079 - if (port->type == PORT_16750) 1080 - serial_port_out(port, UART_FCR, up->fcr); 1081 - 1082 - serial_port_out(port, UART_LCR, up->lcr); /* reset DLAB */ 1083 - if (port->type != PORT_16750) { 1084 - /* emulated UARTs (Lucent Venus 167x) need two steps */ 1085 - if (up->fcr & UART_FCR_ENABLE_FIFO) 1086 - serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO); 1087 - serial_port_out(port, UART_FCR, up->fcr); /* set fcr */ 1088 - } 1089 - serial8250_set_mctrl(port, port->mctrl); 1090 - spin_unlock_irqrestore(&port->lock, flags); 1091 - serial8250_rpm_put(up); 1092 - 1093 - /* Don't rewrite B0 */ 1094 - if (tty_termios_baud_rate(termios)) 1095 - tty_termios_encode_baud_rate(termios, baud, baud); 1096 - } 1097 - EXPORT_SYMBOL(serial8250_do_set_termios); 1098 - 1099 - static void 1100 - serial8250_set_termios(struct uart_port *port, struct ktermios *termios, 1101 - struct ktermios *old) 1102 - { 1103 - if (port->set_termios) 1104 - port->set_termios(port, termios, old); 1105 - else 1106 - serial8250_do_set_termios(port, termios, old); 1107 - } 1108 - 1109 - static void 1110 - serial8250_set_ldisc(struct uart_port *port, struct ktermios *termios) 1111 - { 1112 - if (termios->c_line == N_PPS) { 1113 - port->flags |= UPF_HARDPPS_CD; 1114 - spin_lock_irq(&port->lock); 1115 - serial8250_enable_ms(port); 1116 - spin_unlock_irq(&port->lock); 1117 - } else { 1118 - port->flags &= ~UPF_HARDPPS_CD; 1119 - if (!UART_ENABLE_MS(port, termios->c_cflag)) { 1120 - spin_lock_irq(&port->lock); 1121 - serial8250_disable_ms(port); 1122 - spin_unlock_irq(&port->lock); 1123 - } 1124 - } 1125 - } 1126 - 1127 - 1128 - void serial8250_do_pm(struct uart_port *port, unsigned int state, 1129 - unsigned int oldstate) 1130 - { 1131 - struct uart_8250_port *p = up_to_u8250p(port); 1132 - 1133 - serial8250_set_sleep(p, state != 0); 1134 - } 1135 - EXPORT_SYMBOL(serial8250_do_pm); 1136 - 1137 - static void 1138 - serial8250_pm(struct uart_port *port, unsigned int state, 1139 - unsigned int oldstate) 1140 - { 1141 - if (port->pm) 1142 - port->pm(port, state, oldstate); 1143 - else 1144 - serial8250_do_pm(port, state, oldstate); 1145 - } 1146 - 1147 - static unsigned int serial8250_port_size(struct uart_8250_port *pt) 1148 - { 1149 - if (pt->port.mapsize) 1150 - return pt->port.mapsize; 1151 - if (pt->port.iotype == UPIO_AU) { 1152 - if (pt->port.type == PORT_RT2880) 1153 - return 0x100; 1154 - return 0x1000; 1155 - } 1156 - if (is_omap1_8250(pt)) 1157 - return 0x16 << pt->port.regshift; 1158 - 1159 - return 8 << pt->port.regshift; 1160 - } 1161 - 1162 - /* 1163 - * Resource handling. 1164 - */ 1165 - static int serial8250_request_std_resource(struct uart_8250_port *up) 1166 - { 1167 - unsigned int size = serial8250_port_size(up); 1168 - struct uart_port *port = &up->port; 1169 - int ret = 0; 1170 - 1171 - switch (port->iotype) { 1172 - case UPIO_AU: 1173 - case UPIO_TSI: 1174 - case UPIO_MEM32: 1175 - case UPIO_MEM32BE: 1176 - case UPIO_MEM: 1177 - if (!port->mapbase) 1178 - break; 1179 - 1180 - if (!request_mem_region(port->mapbase, size, "serial")) { 1181 - ret = -EBUSY; 1182 - break; 1183 - } 1184 - 1185 - if (port->flags & UPF_IOREMAP) { 1186 - port->membase = ioremap_nocache(port->mapbase, size); 1187 - if (!port->membase) { 1188 - release_mem_region(port->mapbase, size); 1189 - ret = -ENOMEM; 1190 - } 1191 - } 1192 - break; 1193 - 1194 - case UPIO_HUB6: 1195 - case UPIO_PORT: 1196 - if (!request_region(port->iobase, size, "serial")) 1197 - ret = -EBUSY; 1198 - break; 1199 - } 1200 - return ret; 1201 - } 1202 - 1203 - static void serial8250_release_std_resource(struct uart_8250_port *up) 1204 - { 1205 - unsigned int size = serial8250_port_size(up); 1206 - struct uart_port *port = &up->port; 1207 - 1208 - switch (port->iotype) { 1209 - case UPIO_AU: 1210 - case UPIO_TSI: 1211 - case UPIO_MEM32: 1212 - case UPIO_MEM32BE: 1213 - case UPIO_MEM: 1214 - if (!port->mapbase) 1215 - break; 1216 - 1217 - if (port->flags & UPF_IOREMAP) { 1218 - iounmap(port->membase); 1219 - port->membase = NULL; 1220 - } 1221 - 1222 - release_mem_region(port->mapbase, size); 1223 - break; 1224 - 1225 - case UPIO_HUB6: 1226 - case UPIO_PORT: 1227 - release_region(port->iobase, size); 1228 - break; 1229 - } 1230 - } 1231 - 1232 1944 #ifdef CONFIG_SERIAL_8250_RSA 1233 1945 static int serial8250_request_rsa_resource(struct uart_8250_port *up) 1234 1946 { ··· 395 2847 } 396 2848 } 397 2849 #endif 398 - 399 - static void serial8250_release_port(struct uart_port *port) 400 - { 401 - struct uart_8250_port *up = up_to_u8250p(port); 402 - 403 - serial8250_release_std_resource(up); 404 - } 405 - 406 - static int serial8250_request_port(struct uart_port *port) 407 - { 408 - struct uart_8250_port *up = up_to_u8250p(port); 409 - int ret; 410 - 411 - if (port->type == PORT_8250_CIR) 412 - return -ENODEV; 413 - 414 - ret = serial8250_request_std_resource(up); 415 - 416 - return ret; 417 - } 418 - 419 - static int fcr_get_rxtrig_bytes(struct uart_8250_port *up) 420 - { 421 - const struct serial8250_config *conf_type = &uart_config[up->port.type]; 422 - unsigned char bytes; 423 - 424 - bytes = conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(up->fcr)]; 425 - 426 - return bytes ? bytes : -EOPNOTSUPP; 427 - } 428 - 429 - static int bytes_to_fcr_rxtrig(struct uart_8250_port *up, unsigned char bytes) 430 - { 431 - const struct serial8250_config *conf_type = &uart_config[up->port.type]; 432 - int i; 433 - 434 - if (!conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(UART_FCR_R_TRIG_00)]) 435 - return -EOPNOTSUPP; 436 - 437 - for (i = 1; i < UART_FCR_R_TRIG_MAX_STATE; i++) { 438 - if (bytes < conf_type->rxtrig_bytes[i]) 439 - /* Use the nearest lower value */ 440 - return (--i) << UART_FCR_R_TRIG_SHIFT; 441 - } 442 - 443 - return UART_FCR_R_TRIG_11; 444 - } 445 - 446 - static int do_get_rxtrig(struct tty_port *port) 447 - { 448 - struct uart_state *state = container_of(port, struct uart_state, port); 449 - struct uart_port *uport = state->uart_port; 450 - struct uart_8250_port *up = 451 - container_of(uport, struct uart_8250_port, port); 452 - 453 - if (!(up->capabilities & UART_CAP_FIFO) || uport->fifosize <= 1) 454 - return -EINVAL; 455 - 456 - return fcr_get_rxtrig_bytes(up); 457 - } 458 - 459 - static int do_serial8250_get_rxtrig(struct tty_port *port) 460 - { 461 - int rxtrig_bytes; 462 - 463 - mutex_lock(&port->mutex); 464 - rxtrig_bytes = do_get_rxtrig(port); 465 - mutex_unlock(&port->mutex); 466 - 467 - return rxtrig_bytes; 468 - } 469 - 470 - static ssize_t serial8250_get_attr_rx_trig_bytes(struct device *dev, 471 - struct device_attribute *attr, char *buf) 472 - { 473 - struct tty_port *port = dev_get_drvdata(dev); 474 - int rxtrig_bytes; 475 - 476 - rxtrig_bytes = do_serial8250_get_rxtrig(port); 477 - if (rxtrig_bytes < 0) 478 - return rxtrig_bytes; 479 - 480 - return snprintf(buf, PAGE_SIZE, "%d\n", rxtrig_bytes); 481 - } 482 - 483 - static int do_set_rxtrig(struct tty_port *port, unsigned char bytes) 484 - { 485 - struct uart_state *state = container_of(port, struct uart_state, port); 486 - struct uart_port *uport = state->uart_port; 487 - struct uart_8250_port *up = 488 - container_of(uport, struct uart_8250_port, port); 489 - int rxtrig; 490 - 491 - if (!(up->capabilities & UART_CAP_FIFO) || uport->fifosize <= 1 || 492 - up->fifo_bug) 493 - return -EINVAL; 494 - 495 - rxtrig = bytes_to_fcr_rxtrig(up, bytes); 496 - if (rxtrig < 0) 497 - return rxtrig; 498 - 499 - serial8250_clear_fifos(up); 500 - up->fcr &= ~UART_FCR_TRIGGER_MASK; 501 - up->fcr |= (unsigned char)rxtrig; 502 - serial_out(up, UART_FCR, up->fcr); 503 - return 0; 504 - } 505 - 506 - static int do_serial8250_set_rxtrig(struct tty_port *port, unsigned char bytes) 507 - { 508 - int ret; 509 - 510 - mutex_lock(&port->mutex); 511 - ret = do_set_rxtrig(port, bytes); 512 - mutex_unlock(&port->mutex); 513 - 514 - return ret; 515 - } 516 - 517 - static ssize_t serial8250_set_attr_rx_trig_bytes(struct device *dev, 518 - struct device_attribute *attr, const char *buf, size_t count) 519 - { 520 - struct tty_port *port = dev_get_drvdata(dev); 521 - unsigned char bytes; 522 - int ret; 523 - 524 - if (!count) 525 - return -EINVAL; 526 - 527 - ret = kstrtou8(buf, 10, &bytes); 528 - if (ret < 0) 529 - return ret; 530 - 531 - ret = do_serial8250_set_rxtrig(port, bytes); 532 - if (ret < 0) 533 - return ret; 534 - 535 - return count; 536 - } 537 - 538 - static DEVICE_ATTR(rx_trig_bytes, S_IRUSR | S_IWUSR | S_IRGRP, 539 - serial8250_get_attr_rx_trig_bytes, 540 - serial8250_set_attr_rx_trig_bytes); 541 - 542 - static struct attribute *serial8250_dev_attrs[] = { 543 - &dev_attr_rx_trig_bytes.attr, 544 - NULL, 545 - }; 546 - 547 - static struct attribute_group serial8250_dev_attr_group = { 548 - .attrs = serial8250_dev_attrs, 549 - }; 550 - 551 - static void register_dev_spec_attr_grp(struct uart_8250_port *up) 552 - { 553 - const struct serial8250_config *conf_type = &uart_config[up->port.type]; 554 - 555 - if (conf_type->rxtrig_bytes[0]) 556 - up->port.attr_group = &serial8250_dev_attr_group; 557 - } 558 - 559 - static void serial8250_config_port(struct uart_port *port, int flags) 560 - { 561 - struct uart_8250_port *up = up_to_u8250p(port); 562 - int ret; 563 - 564 - if (port->type == PORT_8250_CIR) 565 - return; 566 - 567 - /* 568 - * Find the region that we can probe for. This in turn 569 - * tells us whether we can probe for the type of port. 570 - */ 571 - ret = serial8250_request_std_resource(up); 572 - if (ret < 0) 573 - return; 574 - 575 - if (port->iotype != up->cur_iotype) 576 - set_io_from_upio(port); 577 - 578 - if (flags & UART_CONFIG_TYPE) 579 - autoconfig(up); 580 - 581 - /* if access method is AU, it is a 16550 with a quirk */ 582 - if (port->type == PORT_16550A && port->iotype == UPIO_AU) 583 - up->bugs |= UART_BUG_NOMSR; 584 - 585 - /* HW bugs may trigger IRQ while IIR == NO_INT */ 586 - if (port->type == PORT_TEGRA) 587 - up->bugs |= UART_BUG_NOMSR; 588 - 589 - if (port->type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) 590 - autoconfig_irq(up); 591 - 592 - if (port->type == PORT_UNKNOWN) 593 - serial8250_release_std_resource(up); 594 - 595 - /* Fixme: probably not the best place for this */ 596 - if ((port->type == PORT_XR17V35X) || 597 - (port->type == PORT_XR17D15X)) 598 - port->handle_irq = exar_handle_irq; 599 - 600 - register_dev_spec_attr_grp(up); 601 - up->fcr = uart_config[up->port.type].fcr; 602 - } 603 - 604 - static int 605 - serial8250_verify_port(struct uart_port *port, struct serial_struct *ser) 606 - { 607 - if (ser->irq >= nr_irqs || ser->irq < 0 || 608 - ser->baud_base < 9600 || ser->type < PORT_UNKNOWN || 609 - ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS || 610 - ser->type == PORT_STARTECH) 611 - return -EINVAL; 612 - return 0; 613 - } 614 - 615 - static const char * 616 - serial8250_type(struct uart_port *port) 617 - { 618 - int type = port->type; 619 - 620 - if (type >= ARRAY_SIZE(uart_config)) 621 - type = 0; 622 - return uart_config[type].name; 623 - } 624 - 625 - static const struct uart_ops serial8250_pops = { 626 - .tx_empty = serial8250_tx_empty, 627 - .set_mctrl = serial8250_set_mctrl, 628 - .get_mctrl = serial8250_get_mctrl, 629 - .stop_tx = serial8250_stop_tx, 630 - .start_tx = serial8250_start_tx, 631 - .throttle = serial8250_throttle, 632 - .unthrottle = serial8250_unthrottle, 633 - .stop_rx = serial8250_stop_rx, 634 - .enable_ms = serial8250_enable_ms, 635 - .break_ctl = serial8250_break_ctl, 636 - .startup = serial8250_startup, 637 - .shutdown = serial8250_shutdown, 638 - .set_termios = serial8250_set_termios, 639 - .set_ldisc = serial8250_set_ldisc, 640 - .pm = serial8250_pm, 641 - .type = serial8250_type, 642 - .release_port = serial8250_release_port, 643 - .request_port = serial8250_request_port, 644 - .config_port = serial8250_config_port, 645 - .verify_port = serial8250_verify_port, 646 - #ifdef CONFIG_CONSOLE_POLL 647 - .poll_get_char = serial8250_get_poll_char, 648 - .poll_put_char = serial8250_put_poll_char, 649 - #endif 650 - }; 651 2850 652 2851 static const struct uart_ops *base_ops; 653 2852 static struct uart_ops univ8250_port_ops; ··· 433 3138 serial8250_isa_config = v; 434 3139 } 435 3140 EXPORT_SYMBOL(serial8250_set_isa_configurator); 436 - 437 - static void serial8250_init_port(struct uart_8250_port *up) 438 - { 439 - struct uart_port *port = &up->port; 440 - 441 - spin_lock_init(&port->lock); 442 - port->ops = &serial8250_pops; 443 - 444 - up->cur_iotype = 0xFF; 445 - } 446 - 447 - static void serial8250_set_defaults(struct uart_8250_port *up) 448 - { 449 - struct uart_port *port = &up->port; 450 - 451 - if (up->port.flags & UPF_FIXED_TYPE) { 452 - unsigned int type = up->port.type; 453 - 454 - if (!up->port.fifosize) 455 - up->port.fifosize = uart_config[type].fifo_size; 456 - if (!up->tx_loadsz) 457 - up->tx_loadsz = uart_config[type].tx_loadsz; 458 - if (!up->capabilities) 459 - up->capabilities = uart_config[type].flags; 460 - } 461 - 462 - set_io_from_upio(port); 463 - 464 - /* default dma handlers */ 465 - if (up->dma) { 466 - if (!up->dma->tx_dma) 467 - up->dma->tx_dma = serial8250_tx_dma; 468 - if (!up->dma->rx_dma) 469 - up->dma->rx_dma = serial8250_rx_dma; 470 - } 471 - } 472 3141 473 3142 #ifdef CONFIG_SERIAL_8250_RSA 474 3143 ··· 583 3324 584 3325 #ifdef CONFIG_SERIAL_8250_CONSOLE 585 3326 586 - static void serial8250_console_putchar(struct uart_port *port, int ch) 587 - { 588 - struct uart_8250_port *up = up_to_u8250p(port); 589 - 590 - wait_for_xmitr(up, UART_LSR_THRE); 591 - serial_port_out(port, UART_TX, ch); 592 - } 593 - 594 - /* 595 - * Print a string to the serial port trying not to disturb 596 - * any possible real use of the port... 597 - * 598 - * The console_lock must be held when we get here. 599 - */ 600 - static void serial8250_console_write(struct uart_8250_port *up, const char *s, 601 - unsigned int count) 602 - { 603 - struct uart_port *port = &up->port; 604 - unsigned long flags; 605 - unsigned int ier; 606 - int locked = 1; 607 - 608 - touch_nmi_watchdog(); 609 - 610 - serial8250_rpm_get(up); 611 - 612 - if (port->sysrq) 613 - locked = 0; 614 - else if (oops_in_progress) 615 - locked = spin_trylock_irqsave(&port->lock, flags); 616 - else 617 - spin_lock_irqsave(&port->lock, flags); 618 - 619 - /* 620 - * First save the IER then disable the interrupts 621 - */ 622 - ier = serial_port_in(port, UART_IER); 623 - 624 - if (up->capabilities & UART_CAP_UUE) 625 - serial_port_out(port, UART_IER, UART_IER_UUE); 626 - else 627 - serial_port_out(port, UART_IER, 0); 628 - 629 - /* check scratch reg to see if port powered off during system sleep */ 630 - if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) { 631 - struct ktermios termios; 632 - unsigned int baud, quot, frac = 0; 633 - 634 - termios.c_cflag = port->cons->cflag; 635 - if (port->state->port.tty && termios.c_cflag == 0) 636 - termios.c_cflag = port->state->port.tty->termios.c_cflag; 637 - 638 - baud = uart_get_baud_rate(port, &termios, NULL, 639 - port->uartclk / 16 / 0xffff, 640 - port->uartclk / 16); 641 - quot = serial8250_get_divisor(up, baud, &frac); 642 - 643 - serial8250_set_divisor(port, baud, quot, frac); 644 - serial_port_out(port, UART_LCR, up->lcr); 645 - serial_port_out(port, UART_MCR, UART_MCR_DTR | UART_MCR_RTS); 646 - 647 - up->canary = 0; 648 - } 649 - 650 - uart_console_write(port, s, count, serial8250_console_putchar); 651 - 652 - /* 653 - * Finally, wait for transmitter to become empty 654 - * and restore the IER 655 - */ 656 - wait_for_xmitr(up, BOTH_EMPTY); 657 - serial_port_out(port, UART_IER, ier); 658 - 659 - /* 660 - * The receive handling will happen properly because the 661 - * receive ready bit will still be set; it is not cleared 662 - * on read. However, modem control will not, we must 663 - * call it if we have saved something in the saved flags 664 - * while processing with interrupts off. 665 - */ 666 - if (up->msr_saved_flags) 667 - serial8250_modem_status(up); 668 - 669 - if (locked) 670 - spin_unlock_irqrestore(&port->lock, flags); 671 - serial8250_rpm_put(up); 672 - } 673 - 674 3327 static void univ8250_console_write(struct console *co, const char *s, 675 3328 unsigned int count) 676 3329 { 677 3330 struct uart_8250_port *up = &serial8250_ports[co->index]; 678 3331 679 3332 serial8250_console_write(up, s, count); 680 - } 681 - 682 - static unsigned int probe_baud(struct uart_port *port) 683 - { 684 - unsigned char lcr, dll, dlm; 685 - unsigned int quot; 686 - 687 - lcr = serial_port_in(port, UART_LCR); 688 - serial_port_out(port, UART_LCR, lcr | UART_LCR_DLAB); 689 - dll = serial_port_in(port, UART_DLL); 690 - dlm = serial_port_in(port, UART_DLM); 691 - serial_port_out(port, UART_LCR, lcr); 692 - 693 - quot = (dlm << 8) | dll; 694 - return (port->uartclk / 16) / quot; 695 - } 696 - 697 - static int serial8250_console_setup(struct uart_port *port, char *options, bool probe) 698 - { 699 - int baud = 9600; 700 - int bits = 8; 701 - int parity = 'n'; 702 - int flow = 'n'; 703 - 704 - if (!port->iobase && !port->membase) 705 - return -ENODEV; 706 - 707 - if (options) 708 - uart_parse_options(options, &baud, &parity, &bits, &flow); 709 - else if (probe) 710 - baud = probe_baud(port); 711 - 712 - return uart_set_options(port, port->cons, baud, parity, bits, flow); 713 3333 } 714 3334 715 3335 static int univ8250_console_setup(struct console *co, char *options)
+2898
drivers/tty/serial/8250/8250_port.c
··· 1 + /* 2 + * Base port operations for 8250/16550-type serial ports 3 + * 4 + * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. 5 + * Split from 8250_core.c, Copyright (C) 2001 Russell King. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * A note about mapbase / membase 13 + * 14 + * mapbase is the physical address of the IO port. 15 + * membase is an 'ioremapped' cookie. 16 + */ 17 + 18 + #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 19 + #define SUPPORT_SYSRQ 20 + #endif 21 + 22 + #include <linux/module.h> 23 + #include <linux/moduleparam.h> 24 + #include <linux/ioport.h> 25 + #include <linux/init.h> 26 + #include <linux/console.h> 27 + #include <linux/sysrq.h> 28 + #include <linux/delay.h> 29 + #include <linux/platform_device.h> 30 + #include <linux/tty.h> 31 + #include <linux/ratelimit.h> 32 + #include <linux/tty_flip.h> 33 + #include <linux/serial.h> 34 + #include <linux/serial_8250.h> 35 + #include <linux/nmi.h> 36 + #include <linux/mutex.h> 37 + #include <linux/slab.h> 38 + #include <linux/uaccess.h> 39 + #include <linux/pm_runtime.h> 40 + 41 + #include <asm/io.h> 42 + #include <asm/irq.h> 43 + 44 + #include "8250.h" 45 + 46 + /* 47 + * Debugging. 48 + */ 49 + #if 0 50 + #define DEBUG_AUTOCONF(fmt...) printk(fmt) 51 + #else 52 + #define DEBUG_AUTOCONF(fmt...) do { } while (0) 53 + #endif 54 + 55 + #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 56 + 57 + /* 58 + * Here we define the default xmit fifo size used for each type of UART. 59 + */ 60 + static const struct serial8250_config uart_config[] = { 61 + [PORT_UNKNOWN] = { 62 + .name = "unknown", 63 + .fifo_size = 1, 64 + .tx_loadsz = 1, 65 + }, 66 + [PORT_8250] = { 67 + .name = "8250", 68 + .fifo_size = 1, 69 + .tx_loadsz = 1, 70 + }, 71 + [PORT_16450] = { 72 + .name = "16450", 73 + .fifo_size = 1, 74 + .tx_loadsz = 1, 75 + }, 76 + [PORT_16550] = { 77 + .name = "16550", 78 + .fifo_size = 1, 79 + .tx_loadsz = 1, 80 + }, 81 + [PORT_16550A] = { 82 + .name = "16550A", 83 + .fifo_size = 16, 84 + .tx_loadsz = 16, 85 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 86 + .rxtrig_bytes = {1, 4, 8, 14}, 87 + .flags = UART_CAP_FIFO, 88 + }, 89 + [PORT_CIRRUS] = { 90 + .name = "Cirrus", 91 + .fifo_size = 1, 92 + .tx_loadsz = 1, 93 + }, 94 + [PORT_16650] = { 95 + .name = "ST16650", 96 + .fifo_size = 1, 97 + .tx_loadsz = 1, 98 + .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, 99 + }, 100 + [PORT_16650V2] = { 101 + .name = "ST16650V2", 102 + .fifo_size = 32, 103 + .tx_loadsz = 16, 104 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | 105 + UART_FCR_T_TRIG_00, 106 + .rxtrig_bytes = {8, 16, 24, 28}, 107 + .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, 108 + }, 109 + [PORT_16750] = { 110 + .name = "TI16750", 111 + .fifo_size = 64, 112 + .tx_loadsz = 64, 113 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | 114 + UART_FCR7_64BYTE, 115 + .rxtrig_bytes = {1, 16, 32, 56}, 116 + .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE, 117 + }, 118 + [PORT_STARTECH] = { 119 + .name = "Startech", 120 + .fifo_size = 1, 121 + .tx_loadsz = 1, 122 + }, 123 + [PORT_16C950] = { 124 + .name = "16C950/954", 125 + .fifo_size = 128, 126 + .tx_loadsz = 128, 127 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 128 + /* UART_CAP_EFR breaks billionon CF bluetooth card. */ 129 + .flags = UART_CAP_FIFO | UART_CAP_SLEEP, 130 + }, 131 + [PORT_16654] = { 132 + .name = "ST16654", 133 + .fifo_size = 64, 134 + .tx_loadsz = 32, 135 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | 136 + UART_FCR_T_TRIG_10, 137 + .rxtrig_bytes = {8, 16, 56, 60}, 138 + .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, 139 + }, 140 + [PORT_16850] = { 141 + .name = "XR16850", 142 + .fifo_size = 128, 143 + .tx_loadsz = 128, 144 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 145 + .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, 146 + }, 147 + [PORT_RSA] = { 148 + .name = "RSA", 149 + .fifo_size = 2048, 150 + .tx_loadsz = 2048, 151 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11, 152 + .flags = UART_CAP_FIFO, 153 + }, 154 + [PORT_NS16550A] = { 155 + .name = "NS16550A", 156 + .fifo_size = 16, 157 + .tx_loadsz = 16, 158 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 159 + .flags = UART_CAP_FIFO | UART_NATSEMI, 160 + }, 161 + [PORT_XSCALE] = { 162 + .name = "XScale", 163 + .fifo_size = 32, 164 + .tx_loadsz = 32, 165 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 166 + .flags = UART_CAP_FIFO | UART_CAP_UUE | UART_CAP_RTOIE, 167 + }, 168 + [PORT_OCTEON] = { 169 + .name = "OCTEON", 170 + .fifo_size = 64, 171 + .tx_loadsz = 64, 172 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 173 + .flags = UART_CAP_FIFO, 174 + }, 175 + [PORT_AR7] = { 176 + .name = "AR7", 177 + .fifo_size = 16, 178 + .tx_loadsz = 16, 179 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00, 180 + .flags = UART_CAP_FIFO | UART_CAP_AFE, 181 + }, 182 + [PORT_U6_16550A] = { 183 + .name = "U6_16550A", 184 + .fifo_size = 64, 185 + .tx_loadsz = 64, 186 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 187 + .flags = UART_CAP_FIFO | UART_CAP_AFE, 188 + }, 189 + [PORT_TEGRA] = { 190 + .name = "Tegra", 191 + .fifo_size = 32, 192 + .tx_loadsz = 8, 193 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | 194 + UART_FCR_T_TRIG_01, 195 + .rxtrig_bytes = {1, 4, 8, 14}, 196 + .flags = UART_CAP_FIFO | UART_CAP_RTOIE, 197 + }, 198 + [PORT_XR17D15X] = { 199 + .name = "XR17D15X", 200 + .fifo_size = 64, 201 + .tx_loadsz = 64, 202 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 203 + .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR | 204 + UART_CAP_SLEEP, 205 + }, 206 + [PORT_XR17V35X] = { 207 + .name = "XR17V35X", 208 + .fifo_size = 256, 209 + .tx_loadsz = 256, 210 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11 | 211 + UART_FCR_T_TRIG_11, 212 + .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR | 213 + UART_CAP_SLEEP, 214 + }, 215 + [PORT_LPC3220] = { 216 + .name = "LPC3220", 217 + .fifo_size = 64, 218 + .tx_loadsz = 32, 219 + .fcr = UART_FCR_DMA_SELECT | UART_FCR_ENABLE_FIFO | 220 + UART_FCR_R_TRIG_00 | UART_FCR_T_TRIG_00, 221 + .flags = UART_CAP_FIFO, 222 + }, 223 + [PORT_BRCM_TRUMANAGE] = { 224 + .name = "TruManage", 225 + .fifo_size = 1, 226 + .tx_loadsz = 1024, 227 + .flags = UART_CAP_HFIFO, 228 + }, 229 + [PORT_8250_CIR] = { 230 + .name = "CIR port" 231 + }, 232 + [PORT_ALTR_16550_F32] = { 233 + .name = "Altera 16550 FIFO32", 234 + .fifo_size = 32, 235 + .tx_loadsz = 32, 236 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 237 + .flags = UART_CAP_FIFO | UART_CAP_AFE, 238 + }, 239 + [PORT_ALTR_16550_F64] = { 240 + .name = "Altera 16550 FIFO64", 241 + .fifo_size = 64, 242 + .tx_loadsz = 64, 243 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 244 + .flags = UART_CAP_FIFO | UART_CAP_AFE, 245 + }, 246 + [PORT_ALTR_16550_F128] = { 247 + .name = "Altera 16550 FIFO128", 248 + .fifo_size = 128, 249 + .tx_loadsz = 128, 250 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 251 + .flags = UART_CAP_FIFO | UART_CAP_AFE, 252 + }, 253 + /* tx_loadsz is set to 63-bytes instead of 64-bytes to implement 254 + workaround of errata A-008006 which states that tx_loadsz should be 255 + configured less than Maximum supported fifo bytes */ 256 + [PORT_16550A_FSL64] = { 257 + .name = "16550A_FSL64", 258 + .fifo_size = 64, 259 + .tx_loadsz = 63, 260 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | 261 + UART_FCR7_64BYTE, 262 + .flags = UART_CAP_FIFO, 263 + }, 264 + }; 265 + 266 + /* Uart divisor latch read */ 267 + static int default_serial_dl_read(struct uart_8250_port *up) 268 + { 269 + return serial_in(up, UART_DLL) | serial_in(up, UART_DLM) << 8; 270 + } 271 + 272 + /* Uart divisor latch write */ 273 + static void default_serial_dl_write(struct uart_8250_port *up, int value) 274 + { 275 + serial_out(up, UART_DLL, value & 0xff); 276 + serial_out(up, UART_DLM, value >> 8 & 0xff); 277 + } 278 + 279 + #if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X) 280 + 281 + /* Au1x00/RT288x UART hardware has a weird register layout */ 282 + static const s8 au_io_in_map[8] = { 283 + 0, /* UART_RX */ 284 + 2, /* UART_IER */ 285 + 3, /* UART_IIR */ 286 + 5, /* UART_LCR */ 287 + 6, /* UART_MCR */ 288 + 7, /* UART_LSR */ 289 + 8, /* UART_MSR */ 290 + -1, /* UART_SCR (unmapped) */ 291 + }; 292 + 293 + static const s8 au_io_out_map[8] = { 294 + 1, /* UART_TX */ 295 + 2, /* UART_IER */ 296 + 4, /* UART_FCR */ 297 + 5, /* UART_LCR */ 298 + 6, /* UART_MCR */ 299 + -1, /* UART_LSR (unmapped) */ 300 + -1, /* UART_MSR (unmapped) */ 301 + -1, /* UART_SCR (unmapped) */ 302 + }; 303 + 304 + static unsigned int au_serial_in(struct uart_port *p, int offset) 305 + { 306 + if (offset >= ARRAY_SIZE(au_io_in_map)) 307 + return UINT_MAX; 308 + offset = au_io_in_map[offset]; 309 + if (offset < 0) 310 + return UINT_MAX; 311 + return __raw_readl(p->membase + (offset << p->regshift)); 312 + } 313 + 314 + static void au_serial_out(struct uart_port *p, int offset, int value) 315 + { 316 + if (offset >= ARRAY_SIZE(au_io_out_map)) 317 + return; 318 + offset = au_io_out_map[offset]; 319 + if (offset < 0) 320 + return; 321 + __raw_writel(value, p->membase + (offset << p->regshift)); 322 + } 323 + 324 + /* Au1x00 haven't got a standard divisor latch */ 325 + static int au_serial_dl_read(struct uart_8250_port *up) 326 + { 327 + return __raw_readl(up->port.membase + 0x28); 328 + } 329 + 330 + static void au_serial_dl_write(struct uart_8250_port *up, int value) 331 + { 332 + __raw_writel(value, up->port.membase + 0x28); 333 + } 334 + 335 + #endif 336 + 337 + static unsigned int hub6_serial_in(struct uart_port *p, int offset) 338 + { 339 + offset = offset << p->regshift; 340 + outb(p->hub6 - 1 + offset, p->iobase); 341 + return inb(p->iobase + 1); 342 + } 343 + 344 + static void hub6_serial_out(struct uart_port *p, int offset, int value) 345 + { 346 + offset = offset << p->regshift; 347 + outb(p->hub6 - 1 + offset, p->iobase); 348 + outb(value, p->iobase + 1); 349 + } 350 + 351 + static unsigned int mem_serial_in(struct uart_port *p, int offset) 352 + { 353 + offset = offset << p->regshift; 354 + return readb(p->membase + offset); 355 + } 356 + 357 + static void mem_serial_out(struct uart_port *p, int offset, int value) 358 + { 359 + offset = offset << p->regshift; 360 + writeb(value, p->membase + offset); 361 + } 362 + 363 + static void mem32_serial_out(struct uart_port *p, int offset, int value) 364 + { 365 + offset = offset << p->regshift; 366 + writel(value, p->membase + offset); 367 + } 368 + 369 + static unsigned int mem32_serial_in(struct uart_port *p, int offset) 370 + { 371 + offset = offset << p->regshift; 372 + return readl(p->membase + offset); 373 + } 374 + 375 + static void mem32be_serial_out(struct uart_port *p, int offset, int value) 376 + { 377 + offset = offset << p->regshift; 378 + iowrite32be(value, p->membase + offset); 379 + } 380 + 381 + static unsigned int mem32be_serial_in(struct uart_port *p, int offset) 382 + { 383 + offset = offset << p->regshift; 384 + return ioread32be(p->membase + offset); 385 + } 386 + 387 + static unsigned int io_serial_in(struct uart_port *p, int offset) 388 + { 389 + offset = offset << p->regshift; 390 + return inb(p->iobase + offset); 391 + } 392 + 393 + static void io_serial_out(struct uart_port *p, int offset, int value) 394 + { 395 + offset = offset << p->regshift; 396 + outb(value, p->iobase + offset); 397 + } 398 + 399 + static int serial8250_default_handle_irq(struct uart_port *port); 400 + static int exar_handle_irq(struct uart_port *port); 401 + 402 + static void set_io_from_upio(struct uart_port *p) 403 + { 404 + struct uart_8250_port *up = up_to_u8250p(p); 405 + 406 + up->dl_read = default_serial_dl_read; 407 + up->dl_write = default_serial_dl_write; 408 + 409 + switch (p->iotype) { 410 + case UPIO_HUB6: 411 + p->serial_in = hub6_serial_in; 412 + p->serial_out = hub6_serial_out; 413 + break; 414 + 415 + case UPIO_MEM: 416 + p->serial_in = mem_serial_in; 417 + p->serial_out = mem_serial_out; 418 + break; 419 + 420 + case UPIO_MEM32: 421 + p->serial_in = mem32_serial_in; 422 + p->serial_out = mem32_serial_out; 423 + break; 424 + 425 + case UPIO_MEM32BE: 426 + p->serial_in = mem32be_serial_in; 427 + p->serial_out = mem32be_serial_out; 428 + break; 429 + 430 + #if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X) 431 + case UPIO_AU: 432 + p->serial_in = au_serial_in; 433 + p->serial_out = au_serial_out; 434 + up->dl_read = au_serial_dl_read; 435 + up->dl_write = au_serial_dl_write; 436 + break; 437 + #endif 438 + 439 + default: 440 + p->serial_in = io_serial_in; 441 + p->serial_out = io_serial_out; 442 + break; 443 + } 444 + /* Remember loaded iotype */ 445 + up->cur_iotype = p->iotype; 446 + p->handle_irq = serial8250_default_handle_irq; 447 + } 448 + 449 + static void 450 + serial_port_out_sync(struct uart_port *p, int offset, int value) 451 + { 452 + switch (p->iotype) { 453 + case UPIO_MEM: 454 + case UPIO_MEM32: 455 + case UPIO_MEM32BE: 456 + case UPIO_AU: 457 + p->serial_out(p, offset, value); 458 + p->serial_in(p, UART_LCR); /* safe, no side-effects */ 459 + break; 460 + default: 461 + p->serial_out(p, offset, value); 462 + } 463 + } 464 + 465 + /* 466 + * For the 16C950 467 + */ 468 + static void serial_icr_write(struct uart_8250_port *up, int offset, int value) 469 + { 470 + serial_out(up, UART_SCR, offset); 471 + serial_out(up, UART_ICR, value); 472 + } 473 + 474 + static unsigned int serial_icr_read(struct uart_8250_port *up, int offset) 475 + { 476 + unsigned int value; 477 + 478 + serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); 479 + serial_out(up, UART_SCR, offset); 480 + value = serial_in(up, UART_ICR); 481 + serial_icr_write(up, UART_ACR, up->acr); 482 + 483 + return value; 484 + } 485 + 486 + /* 487 + * FIFO support. 488 + */ 489 + static void serial8250_clear_fifos(struct uart_8250_port *p) 490 + { 491 + if (p->capabilities & UART_CAP_FIFO) { 492 + serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO); 493 + serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO | 494 + UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 495 + serial_out(p, UART_FCR, 0); 496 + } 497 + } 498 + 499 + void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p) 500 + { 501 + serial8250_clear_fifos(p); 502 + serial_out(p, UART_FCR, p->fcr); 503 + } 504 + EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos); 505 + 506 + void serial8250_rpm_get(struct uart_8250_port *p) 507 + { 508 + if (!(p->capabilities & UART_CAP_RPM)) 509 + return; 510 + pm_runtime_get_sync(p->port.dev); 511 + } 512 + EXPORT_SYMBOL_GPL(serial8250_rpm_get); 513 + 514 + void serial8250_rpm_put(struct uart_8250_port *p) 515 + { 516 + if (!(p->capabilities & UART_CAP_RPM)) 517 + return; 518 + pm_runtime_mark_last_busy(p->port.dev); 519 + pm_runtime_put_autosuspend(p->port.dev); 520 + } 521 + EXPORT_SYMBOL_GPL(serial8250_rpm_put); 522 + 523 + /* 524 + * These two wrappers ensure that enable_runtime_pm_tx() can be called more than 525 + * once and disable_runtime_pm_tx() will still disable RPM because the fifo is 526 + * empty and the HW can idle again. 527 + */ 528 + static void serial8250_rpm_get_tx(struct uart_8250_port *p) 529 + { 530 + unsigned char rpm_active; 531 + 532 + if (!(p->capabilities & UART_CAP_RPM)) 533 + return; 534 + 535 + rpm_active = xchg(&p->rpm_tx_active, 1); 536 + if (rpm_active) 537 + return; 538 + pm_runtime_get_sync(p->port.dev); 539 + } 540 + 541 + static void serial8250_rpm_put_tx(struct uart_8250_port *p) 542 + { 543 + unsigned char rpm_active; 544 + 545 + if (!(p->capabilities & UART_CAP_RPM)) 546 + return; 547 + 548 + rpm_active = xchg(&p->rpm_tx_active, 0); 549 + if (!rpm_active) 550 + return; 551 + pm_runtime_mark_last_busy(p->port.dev); 552 + pm_runtime_put_autosuspend(p->port.dev); 553 + } 554 + 555 + /* 556 + * IER sleep support. UARTs which have EFRs need the "extended 557 + * capability" bit enabled. Note that on XR16C850s, we need to 558 + * reset LCR to write to IER. 559 + */ 560 + static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) 561 + { 562 + unsigned char lcr = 0, efr = 0; 563 + /* 564 + * Exar UARTs have a SLEEP register that enables or disables 565 + * each UART to enter sleep mode separately. On the XR17V35x the 566 + * register is accessible to each UART at the UART_EXAR_SLEEP 567 + * offset but the UART channel may only write to the corresponding 568 + * bit. 569 + */ 570 + serial8250_rpm_get(p); 571 + if ((p->port.type == PORT_XR17V35X) || 572 + (p->port.type == PORT_XR17D15X)) { 573 + serial_out(p, UART_EXAR_SLEEP, sleep ? 0xff : 0); 574 + goto out; 575 + } 576 + 577 + if (p->capabilities & UART_CAP_SLEEP) { 578 + if (p->capabilities & UART_CAP_EFR) { 579 + lcr = serial_in(p, UART_LCR); 580 + efr = serial_in(p, UART_EFR); 581 + serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 582 + serial_out(p, UART_EFR, UART_EFR_ECB); 583 + serial_out(p, UART_LCR, 0); 584 + } 585 + serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); 586 + if (p->capabilities & UART_CAP_EFR) { 587 + serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 588 + serial_out(p, UART_EFR, efr); 589 + serial_out(p, UART_LCR, lcr); 590 + } 591 + } 592 + out: 593 + serial8250_rpm_put(p); 594 + } 595 + 596 + #ifdef CONFIG_SERIAL_8250_RSA 597 + /* 598 + * Attempts to turn on the RSA FIFO. Returns zero on failure. 599 + * We set the port uart clock rate if we succeed. 600 + */ 601 + static int __enable_rsa(struct uart_8250_port *up) 602 + { 603 + unsigned char mode; 604 + int result; 605 + 606 + mode = serial_in(up, UART_RSA_MSR); 607 + result = mode & UART_RSA_MSR_FIFO; 608 + 609 + if (!result) { 610 + serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); 611 + mode = serial_in(up, UART_RSA_MSR); 612 + result = mode & UART_RSA_MSR_FIFO; 613 + } 614 + 615 + if (result) 616 + up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16; 617 + 618 + return result; 619 + } 620 + 621 + static void enable_rsa(struct uart_8250_port *up) 622 + { 623 + if (up->port.type == PORT_RSA) { 624 + if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) { 625 + spin_lock_irq(&up->port.lock); 626 + __enable_rsa(up); 627 + spin_unlock_irq(&up->port.lock); 628 + } 629 + if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) 630 + serial_out(up, UART_RSA_FRR, 0); 631 + } 632 + } 633 + 634 + /* 635 + * Attempts to turn off the RSA FIFO. Returns zero on failure. 636 + * It is unknown why interrupts were disabled in here. However, 637 + * the caller is expected to preserve this behaviour by grabbing 638 + * the spinlock before calling this function. 639 + */ 640 + static void disable_rsa(struct uart_8250_port *up) 641 + { 642 + unsigned char mode; 643 + int result; 644 + 645 + if (up->port.type == PORT_RSA && 646 + up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { 647 + spin_lock_irq(&up->port.lock); 648 + 649 + mode = serial_in(up, UART_RSA_MSR); 650 + result = !(mode & UART_RSA_MSR_FIFO); 651 + 652 + if (!result) { 653 + serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); 654 + mode = serial_in(up, UART_RSA_MSR); 655 + result = !(mode & UART_RSA_MSR_FIFO); 656 + } 657 + 658 + if (result) 659 + up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16; 660 + spin_unlock_irq(&up->port.lock); 661 + } 662 + } 663 + #endif /* CONFIG_SERIAL_8250_RSA */ 664 + 665 + /* 666 + * This is a quickie test to see how big the FIFO is. 667 + * It doesn't work at all the time, more's the pity. 668 + */ 669 + static int size_fifo(struct uart_8250_port *up) 670 + { 671 + unsigned char old_fcr, old_mcr, old_lcr; 672 + unsigned short old_dl; 673 + int count; 674 + 675 + old_lcr = serial_in(up, UART_LCR); 676 + serial_out(up, UART_LCR, 0); 677 + old_fcr = serial_in(up, UART_FCR); 678 + old_mcr = serial_in(up, UART_MCR); 679 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 680 + UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 681 + serial_out(up, UART_MCR, UART_MCR_LOOP); 682 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 683 + old_dl = serial_dl_read(up); 684 + serial_dl_write(up, 0x0001); 685 + serial_out(up, UART_LCR, 0x03); 686 + for (count = 0; count < 256; count++) 687 + serial_out(up, UART_TX, count); 688 + mdelay(20);/* FIXME - schedule_timeout */ 689 + for (count = 0; (serial_in(up, UART_LSR) & UART_LSR_DR) && 690 + (count < 256); count++) 691 + serial_in(up, UART_RX); 692 + serial_out(up, UART_FCR, old_fcr); 693 + serial_out(up, UART_MCR, old_mcr); 694 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 695 + serial_dl_write(up, old_dl); 696 + serial_out(up, UART_LCR, old_lcr); 697 + 698 + return count; 699 + } 700 + 701 + /* 702 + * Read UART ID using the divisor method - set DLL and DLM to zero 703 + * and the revision will be in DLL and device type in DLM. We 704 + * preserve the device state across this. 705 + */ 706 + static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p) 707 + { 708 + unsigned char old_dll, old_dlm, old_lcr; 709 + unsigned int id; 710 + 711 + old_lcr = serial_in(p, UART_LCR); 712 + serial_out(p, UART_LCR, UART_LCR_CONF_MODE_A); 713 + 714 + old_dll = serial_in(p, UART_DLL); 715 + old_dlm = serial_in(p, UART_DLM); 716 + 717 + serial_out(p, UART_DLL, 0); 718 + serial_out(p, UART_DLM, 0); 719 + 720 + id = serial_in(p, UART_DLL) | serial_in(p, UART_DLM) << 8; 721 + 722 + serial_out(p, UART_DLL, old_dll); 723 + serial_out(p, UART_DLM, old_dlm); 724 + serial_out(p, UART_LCR, old_lcr); 725 + 726 + return id; 727 + } 728 + 729 + /* 730 + * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's. 731 + * When this function is called we know it is at least a StarTech 732 + * 16650 V2, but it might be one of several StarTech UARTs, or one of 733 + * its clones. (We treat the broken original StarTech 16650 V1 as a 734 + * 16550, and why not? Startech doesn't seem to even acknowledge its 735 + * existence.) 736 + * 737 + * What evil have men's minds wrought... 738 + */ 739 + static void autoconfig_has_efr(struct uart_8250_port *up) 740 + { 741 + unsigned int id1, id2, id3, rev; 742 + 743 + /* 744 + * Everything with an EFR has SLEEP 745 + */ 746 + up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; 747 + 748 + /* 749 + * First we check to see if it's an Oxford Semiconductor UART. 750 + * 751 + * If we have to do this here because some non-National 752 + * Semiconductor clone chips lock up if you try writing to the 753 + * LSR register (which serial_icr_read does) 754 + */ 755 + 756 + /* 757 + * Check for Oxford Semiconductor 16C950. 758 + * 759 + * EFR [4] must be set else this test fails. 760 + * 761 + * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca) 762 + * claims that it's needed for 952 dual UART's (which are not 763 + * recommended for new designs). 764 + */ 765 + up->acr = 0; 766 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 767 + serial_out(up, UART_EFR, UART_EFR_ECB); 768 + serial_out(up, UART_LCR, 0x00); 769 + id1 = serial_icr_read(up, UART_ID1); 770 + id2 = serial_icr_read(up, UART_ID2); 771 + id3 = serial_icr_read(up, UART_ID3); 772 + rev = serial_icr_read(up, UART_REV); 773 + 774 + DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev); 775 + 776 + if (id1 == 0x16 && id2 == 0xC9 && 777 + (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) { 778 + up->port.type = PORT_16C950; 779 + 780 + /* 781 + * Enable work around for the Oxford Semiconductor 952 rev B 782 + * chip which causes it to seriously miscalculate baud rates 783 + * when DLL is 0. 784 + */ 785 + if (id3 == 0x52 && rev == 0x01) 786 + up->bugs |= UART_BUG_QUOT; 787 + return; 788 + } 789 + 790 + /* 791 + * We check for a XR16C850 by setting DLL and DLM to 0, and then 792 + * reading back DLL and DLM. The chip type depends on the DLM 793 + * value read back: 794 + * 0x10 - XR16C850 and the DLL contains the chip revision. 795 + * 0x12 - XR16C2850. 796 + * 0x14 - XR16C854. 797 + */ 798 + id1 = autoconfig_read_divisor_id(up); 799 + DEBUG_AUTOCONF("850id=%04x ", id1); 800 + 801 + id2 = id1 >> 8; 802 + if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) { 803 + up->port.type = PORT_16850; 804 + return; 805 + } 806 + 807 + /* 808 + * It wasn't an XR16C850. 809 + * 810 + * We distinguish between the '654 and the '650 by counting 811 + * how many bytes are in the FIFO. I'm using this for now, 812 + * since that's the technique that was sent to me in the 813 + * serial driver update, but I'm not convinced this works. 814 + * I've had problems doing this in the past. -TYT 815 + */ 816 + if (size_fifo(up) == 64) 817 + up->port.type = PORT_16654; 818 + else 819 + up->port.type = PORT_16650V2; 820 + } 821 + 822 + /* 823 + * We detected a chip without a FIFO. Only two fall into 824 + * this category - the original 8250 and the 16450. The 825 + * 16450 has a scratch register (accessible with LCR=0) 826 + */ 827 + static void autoconfig_8250(struct uart_8250_port *up) 828 + { 829 + unsigned char scratch, status1, status2; 830 + 831 + up->port.type = PORT_8250; 832 + 833 + scratch = serial_in(up, UART_SCR); 834 + serial_out(up, UART_SCR, 0xa5); 835 + status1 = serial_in(up, UART_SCR); 836 + serial_out(up, UART_SCR, 0x5a); 837 + status2 = serial_in(up, UART_SCR); 838 + serial_out(up, UART_SCR, scratch); 839 + 840 + if (status1 == 0xa5 && status2 == 0x5a) 841 + up->port.type = PORT_16450; 842 + } 843 + 844 + static int broken_efr(struct uart_8250_port *up) 845 + { 846 + /* 847 + * Exar ST16C2550 "A2" devices incorrectly detect as 848 + * having an EFR, and report an ID of 0x0201. See 849 + * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html 850 + */ 851 + if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16) 852 + return 1; 853 + 854 + return 0; 855 + } 856 + 857 + /* 858 + * We know that the chip has FIFOs. Does it have an EFR? The 859 + * EFR is located in the same register position as the IIR and 860 + * we know the top two bits of the IIR are currently set. The 861 + * EFR should contain zero. Try to read the EFR. 862 + */ 863 + static void autoconfig_16550a(struct uart_8250_port *up) 864 + { 865 + unsigned char status1, status2; 866 + unsigned int iersave; 867 + 868 + up->port.type = PORT_16550A; 869 + up->capabilities |= UART_CAP_FIFO; 870 + 871 + /* 872 + * XR17V35x UARTs have an extra divisor register, DLD 873 + * that gets enabled with when DLAB is set which will 874 + * cause the device to incorrectly match and assign 875 + * port type to PORT_16650. The EFR for this UART is 876 + * found at offset 0x09. Instead check the Deice ID (DVID) 877 + * register for a 2, 4 or 8 port UART. 878 + */ 879 + if (up->port.flags & UPF_EXAR_EFR) { 880 + status1 = serial_in(up, UART_EXAR_DVID); 881 + if (status1 == 0x82 || status1 == 0x84 || status1 == 0x88) { 882 + DEBUG_AUTOCONF("Exar XR17V35x "); 883 + up->port.type = PORT_XR17V35X; 884 + up->capabilities |= UART_CAP_AFE | UART_CAP_EFR | 885 + UART_CAP_SLEEP; 886 + 887 + return; 888 + } 889 + 890 + } 891 + 892 + /* 893 + * Check for presence of the EFR when DLAB is set. 894 + * Only ST16C650V1 UARTs pass this test. 895 + */ 896 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 897 + if (serial_in(up, UART_EFR) == 0) { 898 + serial_out(up, UART_EFR, 0xA8); 899 + if (serial_in(up, UART_EFR) != 0) { 900 + DEBUG_AUTOCONF("EFRv1 "); 901 + up->port.type = PORT_16650; 902 + up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; 903 + } else { 904 + serial_out(up, UART_LCR, 0); 905 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 906 + UART_FCR7_64BYTE); 907 + status1 = serial_in(up, UART_IIR) >> 5; 908 + serial_out(up, UART_FCR, 0); 909 + serial_out(up, UART_LCR, 0); 910 + 911 + if (status1 == 7) 912 + up->port.type = PORT_16550A_FSL64; 913 + else 914 + DEBUG_AUTOCONF("Motorola 8xxx DUART "); 915 + } 916 + serial_out(up, UART_EFR, 0); 917 + return; 918 + } 919 + 920 + /* 921 + * Maybe it requires 0xbf to be written to the LCR. 922 + * (other ST16C650V2 UARTs, TI16C752A, etc) 923 + */ 924 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 925 + if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) { 926 + DEBUG_AUTOCONF("EFRv2 "); 927 + autoconfig_has_efr(up); 928 + return; 929 + } 930 + 931 + /* 932 + * Check for a National Semiconductor SuperIO chip. 933 + * Attempt to switch to bank 2, read the value of the LOOP bit 934 + * from EXCR1. Switch back to bank 0, change it in MCR. Then 935 + * switch back to bank 2, read it from EXCR1 again and check 936 + * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2 937 + */ 938 + serial_out(up, UART_LCR, 0); 939 + status1 = serial_in(up, UART_MCR); 940 + serial_out(up, UART_LCR, 0xE0); 941 + status2 = serial_in(up, 0x02); /* EXCR1 */ 942 + 943 + if (!((status2 ^ status1) & UART_MCR_LOOP)) { 944 + serial_out(up, UART_LCR, 0); 945 + serial_out(up, UART_MCR, status1 ^ UART_MCR_LOOP); 946 + serial_out(up, UART_LCR, 0xE0); 947 + status2 = serial_in(up, 0x02); /* EXCR1 */ 948 + serial_out(up, UART_LCR, 0); 949 + serial_out(up, UART_MCR, status1); 950 + 951 + if ((status2 ^ status1) & UART_MCR_LOOP) { 952 + unsigned short quot; 953 + 954 + serial_out(up, UART_LCR, 0xE0); 955 + 956 + quot = serial_dl_read(up); 957 + quot <<= 3; 958 + 959 + if (ns16550a_goto_highspeed(up)) 960 + serial_dl_write(up, quot); 961 + 962 + serial_out(up, UART_LCR, 0); 963 + 964 + up->port.uartclk = 921600*16; 965 + up->port.type = PORT_NS16550A; 966 + up->capabilities |= UART_NATSEMI; 967 + return; 968 + } 969 + } 970 + 971 + /* 972 + * No EFR. Try to detect a TI16750, which only sets bit 5 of 973 + * the IIR when 64 byte FIFO mode is enabled when DLAB is set. 974 + * Try setting it with and without DLAB set. Cheap clones 975 + * set bit 5 without DLAB set. 976 + */ 977 + serial_out(up, UART_LCR, 0); 978 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 979 + status1 = serial_in(up, UART_IIR) >> 5; 980 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 981 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 982 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 983 + status2 = serial_in(up, UART_IIR) >> 5; 984 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 985 + serial_out(up, UART_LCR, 0); 986 + 987 + DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2); 988 + 989 + if (status1 == 6 && status2 == 7) { 990 + up->port.type = PORT_16750; 991 + up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP; 992 + return; 993 + } 994 + 995 + /* 996 + * Try writing and reading the UART_IER_UUE bit (b6). 997 + * If it works, this is probably one of the Xscale platform's 998 + * internal UARTs. 999 + * We're going to explicitly set the UUE bit to 0 before 1000 + * trying to write and read a 1 just to make sure it's not 1001 + * already a 1 and maybe locked there before we even start start. 1002 + */ 1003 + iersave = serial_in(up, UART_IER); 1004 + serial_out(up, UART_IER, iersave & ~UART_IER_UUE); 1005 + if (!(serial_in(up, UART_IER) & UART_IER_UUE)) { 1006 + /* 1007 + * OK it's in a known zero state, try writing and reading 1008 + * without disturbing the current state of the other bits. 1009 + */ 1010 + serial_out(up, UART_IER, iersave | UART_IER_UUE); 1011 + if (serial_in(up, UART_IER) & UART_IER_UUE) { 1012 + /* 1013 + * It's an Xscale. 1014 + * We'll leave the UART_IER_UUE bit set to 1 (enabled). 1015 + */ 1016 + DEBUG_AUTOCONF("Xscale "); 1017 + up->port.type = PORT_XSCALE; 1018 + up->capabilities |= UART_CAP_UUE | UART_CAP_RTOIE; 1019 + return; 1020 + } 1021 + } else { 1022 + /* 1023 + * If we got here we couldn't force the IER_UUE bit to 0. 1024 + * Log it and continue. 1025 + */ 1026 + DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); 1027 + } 1028 + serial_out(up, UART_IER, iersave); 1029 + 1030 + /* 1031 + * Exar uarts have EFR in a weird location 1032 + */ 1033 + if (up->port.flags & UPF_EXAR_EFR) { 1034 + DEBUG_AUTOCONF("Exar XR17D15x "); 1035 + up->port.type = PORT_XR17D15X; 1036 + up->capabilities |= UART_CAP_AFE | UART_CAP_EFR | 1037 + UART_CAP_SLEEP; 1038 + 1039 + return; 1040 + } 1041 + 1042 + /* 1043 + * We distinguish between 16550A and U6 16550A by counting 1044 + * how many bytes are in the FIFO. 1045 + */ 1046 + if (up->port.type == PORT_16550A && size_fifo(up) == 64) { 1047 + up->port.type = PORT_U6_16550A; 1048 + up->capabilities |= UART_CAP_AFE; 1049 + } 1050 + } 1051 + 1052 + /* 1053 + * This routine is called by rs_init() to initialize a specific serial 1054 + * port. It determines what type of UART chip this serial port is 1055 + * using: 8250, 16450, 16550, 16550A. The important question is 1056 + * whether or not this UART is a 16550A or not, since this will 1057 + * determine whether or not we can use its FIFO features or not. 1058 + */ 1059 + static void autoconfig(struct uart_8250_port *up) 1060 + { 1061 + unsigned char status1, scratch, scratch2, scratch3; 1062 + unsigned char save_lcr, save_mcr; 1063 + struct uart_port *port = &up->port; 1064 + unsigned long flags; 1065 + unsigned int old_capabilities; 1066 + 1067 + if (!port->iobase && !port->mapbase && !port->membase) 1068 + return; 1069 + 1070 + DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ", 1071 + serial_index(port), port->iobase, port->membase); 1072 + 1073 + /* 1074 + * We really do need global IRQs disabled here - we're going to 1075 + * be frobbing the chips IRQ enable register to see if it exists. 1076 + */ 1077 + spin_lock_irqsave(&port->lock, flags); 1078 + 1079 + up->capabilities = 0; 1080 + up->bugs = 0; 1081 + 1082 + if (!(port->flags & UPF_BUGGY_UART)) { 1083 + /* 1084 + * Do a simple existence test first; if we fail this, 1085 + * there's no point trying anything else. 1086 + * 1087 + * 0x80 is used as a nonsense port to prevent against 1088 + * false positives due to ISA bus float. The 1089 + * assumption is that 0x80 is a non-existent port; 1090 + * which should be safe since include/asm/io.h also 1091 + * makes this assumption. 1092 + * 1093 + * Note: this is safe as long as MCR bit 4 is clear 1094 + * and the device is in "PC" mode. 1095 + */ 1096 + scratch = serial_in(up, UART_IER); 1097 + serial_out(up, UART_IER, 0); 1098 + #ifdef __i386__ 1099 + outb(0xff, 0x080); 1100 + #endif 1101 + /* 1102 + * Mask out IER[7:4] bits for test as some UARTs (e.g. TL 1103 + * 16C754B) allow only to modify them if an EFR bit is set. 1104 + */ 1105 + scratch2 = serial_in(up, UART_IER) & 0x0f; 1106 + serial_out(up, UART_IER, 0x0F); 1107 + #ifdef __i386__ 1108 + outb(0, 0x080); 1109 + #endif 1110 + scratch3 = serial_in(up, UART_IER) & 0x0f; 1111 + serial_out(up, UART_IER, scratch); 1112 + if (scratch2 != 0 || scratch3 != 0x0F) { 1113 + /* 1114 + * We failed; there's nothing here 1115 + */ 1116 + spin_unlock_irqrestore(&port->lock, flags); 1117 + DEBUG_AUTOCONF("IER test failed (%02x, %02x) ", 1118 + scratch2, scratch3); 1119 + goto out; 1120 + } 1121 + } 1122 + 1123 + save_mcr = serial_in(up, UART_MCR); 1124 + save_lcr = serial_in(up, UART_LCR); 1125 + 1126 + /* 1127 + * Check to see if a UART is really there. Certain broken 1128 + * internal modems based on the Rockwell chipset fail this 1129 + * test, because they apparently don't implement the loopback 1130 + * test mode. So this test is skipped on the COM 1 through 1131 + * COM 4 ports. This *should* be safe, since no board 1132 + * manufacturer would be stupid enough to design a board 1133 + * that conflicts with COM 1-4 --- we hope! 1134 + */ 1135 + if (!(port->flags & UPF_SKIP_TEST)) { 1136 + serial_out(up, UART_MCR, UART_MCR_LOOP | 0x0A); 1137 + status1 = serial_in(up, UART_MSR) & 0xF0; 1138 + serial_out(up, UART_MCR, save_mcr); 1139 + if (status1 != 0x90) { 1140 + spin_unlock_irqrestore(&port->lock, flags); 1141 + DEBUG_AUTOCONF("LOOP test failed (%02x) ", 1142 + status1); 1143 + goto out; 1144 + } 1145 + } 1146 + 1147 + /* 1148 + * We're pretty sure there's a port here. Lets find out what 1149 + * type of port it is. The IIR top two bits allows us to find 1150 + * out if it's 8250 or 16450, 16550, 16550A or later. This 1151 + * determines what we test for next. 1152 + * 1153 + * We also initialise the EFR (if any) to zero for later. The 1154 + * EFR occupies the same register location as the FCR and IIR. 1155 + */ 1156 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 1157 + serial_out(up, UART_EFR, 0); 1158 + serial_out(up, UART_LCR, 0); 1159 + 1160 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1161 + scratch = serial_in(up, UART_IIR) >> 6; 1162 + 1163 + switch (scratch) { 1164 + case 0: 1165 + autoconfig_8250(up); 1166 + break; 1167 + case 1: 1168 + port->type = PORT_UNKNOWN; 1169 + break; 1170 + case 2: 1171 + port->type = PORT_16550; 1172 + break; 1173 + case 3: 1174 + autoconfig_16550a(up); 1175 + break; 1176 + } 1177 + 1178 + #ifdef CONFIG_SERIAL_8250_RSA 1179 + /* 1180 + * Only probe for RSA ports if we got the region. 1181 + */ 1182 + if (port->type == PORT_16550A && up->probe & UART_PROBE_RSA && 1183 + __enable_rsa(up)) 1184 + port->type = PORT_RSA; 1185 + #endif 1186 + 1187 + serial_out(up, UART_LCR, save_lcr); 1188 + 1189 + port->fifosize = uart_config[up->port.type].fifo_size; 1190 + old_capabilities = up->capabilities; 1191 + up->capabilities = uart_config[port->type].flags; 1192 + up->tx_loadsz = uart_config[port->type].tx_loadsz; 1193 + 1194 + if (port->type == PORT_UNKNOWN) 1195 + goto out_lock; 1196 + 1197 + /* 1198 + * Reset the UART. 1199 + */ 1200 + #ifdef CONFIG_SERIAL_8250_RSA 1201 + if (port->type == PORT_RSA) 1202 + serial_out(up, UART_RSA_FRR, 0); 1203 + #endif 1204 + serial_out(up, UART_MCR, save_mcr); 1205 + serial8250_clear_fifos(up); 1206 + serial_in(up, UART_RX); 1207 + if (up->capabilities & UART_CAP_UUE) 1208 + serial_out(up, UART_IER, UART_IER_UUE); 1209 + else 1210 + serial_out(up, UART_IER, 0); 1211 + 1212 + out_lock: 1213 + spin_unlock_irqrestore(&port->lock, flags); 1214 + if (up->capabilities != old_capabilities) { 1215 + printk(KERN_WARNING 1216 + "ttyS%d: detected caps %08x should be %08x\n", 1217 + serial_index(port), old_capabilities, 1218 + up->capabilities); 1219 + } 1220 + out: 1221 + DEBUG_AUTOCONF("iir=%d ", scratch); 1222 + DEBUG_AUTOCONF("type=%s\n", uart_config[port->type].name); 1223 + } 1224 + 1225 + static void autoconfig_irq(struct uart_8250_port *up) 1226 + { 1227 + struct uart_port *port = &up->port; 1228 + unsigned char save_mcr, save_ier; 1229 + unsigned char save_ICP = 0; 1230 + unsigned int ICP = 0; 1231 + unsigned long irqs; 1232 + int irq; 1233 + 1234 + if (port->flags & UPF_FOURPORT) { 1235 + ICP = (port->iobase & 0xfe0) | 0x1f; 1236 + save_ICP = inb_p(ICP); 1237 + outb_p(0x80, ICP); 1238 + inb_p(ICP); 1239 + } 1240 + 1241 + /* forget possible initially masked and pending IRQ */ 1242 + probe_irq_off(probe_irq_on()); 1243 + save_mcr = serial_in(up, UART_MCR); 1244 + save_ier = serial_in(up, UART_IER); 1245 + serial_out(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2); 1246 + 1247 + irqs = probe_irq_on(); 1248 + serial_out(up, UART_MCR, 0); 1249 + udelay(10); 1250 + if (port->flags & UPF_FOURPORT) { 1251 + serial_out(up, UART_MCR, 1252 + UART_MCR_DTR | UART_MCR_RTS); 1253 + } else { 1254 + serial_out(up, UART_MCR, 1255 + UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); 1256 + } 1257 + serial_out(up, UART_IER, 0x0f); /* enable all intrs */ 1258 + serial_in(up, UART_LSR); 1259 + serial_in(up, UART_RX); 1260 + serial_in(up, UART_IIR); 1261 + serial_in(up, UART_MSR); 1262 + serial_out(up, UART_TX, 0xFF); 1263 + udelay(20); 1264 + irq = probe_irq_off(irqs); 1265 + 1266 + serial_out(up, UART_MCR, save_mcr); 1267 + serial_out(up, UART_IER, save_ier); 1268 + 1269 + if (port->flags & UPF_FOURPORT) 1270 + outb_p(save_ICP, ICP); 1271 + 1272 + port->irq = (irq > 0) ? irq : 0; 1273 + } 1274 + 1275 + static inline void __stop_tx(struct uart_8250_port *p) 1276 + { 1277 + if (p->ier & UART_IER_THRI) { 1278 + p->ier &= ~UART_IER_THRI; 1279 + serial_out(p, UART_IER, p->ier); 1280 + serial8250_rpm_put_tx(p); 1281 + } 1282 + } 1283 + 1284 + static void serial8250_stop_tx(struct uart_port *port) 1285 + { 1286 + struct uart_8250_port *up = up_to_u8250p(port); 1287 + 1288 + serial8250_rpm_get(up); 1289 + __stop_tx(up); 1290 + 1291 + /* 1292 + * We really want to stop the transmitter from sending. 1293 + */ 1294 + if (port->type == PORT_16C950) { 1295 + up->acr |= UART_ACR_TXDIS; 1296 + serial_icr_write(up, UART_ACR, up->acr); 1297 + } 1298 + serial8250_rpm_put(up); 1299 + } 1300 + 1301 + static void serial8250_start_tx(struct uart_port *port) 1302 + { 1303 + struct uart_8250_port *up = up_to_u8250p(port); 1304 + 1305 + serial8250_rpm_get_tx(up); 1306 + 1307 + if (up->dma && !up->dma->tx_dma(up)) 1308 + return; 1309 + 1310 + if (!(up->ier & UART_IER_THRI)) { 1311 + up->ier |= UART_IER_THRI; 1312 + serial_port_out(port, UART_IER, up->ier); 1313 + 1314 + if (up->bugs & UART_BUG_TXEN) { 1315 + unsigned char lsr; 1316 + lsr = serial_in(up, UART_LSR); 1317 + up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; 1318 + if (lsr & UART_LSR_THRE) 1319 + serial8250_tx_chars(up); 1320 + } 1321 + } 1322 + 1323 + /* 1324 + * Re-enable the transmitter if we disabled it. 1325 + */ 1326 + if (port->type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { 1327 + up->acr &= ~UART_ACR_TXDIS; 1328 + serial_icr_write(up, UART_ACR, up->acr); 1329 + } 1330 + } 1331 + 1332 + static void serial8250_throttle(struct uart_port *port) 1333 + { 1334 + port->throttle(port); 1335 + } 1336 + 1337 + static void serial8250_unthrottle(struct uart_port *port) 1338 + { 1339 + port->unthrottle(port); 1340 + } 1341 + 1342 + static void serial8250_stop_rx(struct uart_port *port) 1343 + { 1344 + struct uart_8250_port *up = up_to_u8250p(port); 1345 + 1346 + serial8250_rpm_get(up); 1347 + 1348 + up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); 1349 + up->port.read_status_mask &= ~UART_LSR_DR; 1350 + serial_port_out(port, UART_IER, up->ier); 1351 + 1352 + serial8250_rpm_put(up); 1353 + } 1354 + 1355 + static void serial8250_disable_ms(struct uart_port *port) 1356 + { 1357 + struct uart_8250_port *up = 1358 + container_of(port, struct uart_8250_port, port); 1359 + 1360 + /* no MSR capabilities */ 1361 + if (up->bugs & UART_BUG_NOMSR) 1362 + return; 1363 + 1364 + up->ier &= ~UART_IER_MSI; 1365 + serial_port_out(port, UART_IER, up->ier); 1366 + } 1367 + 1368 + static void serial8250_enable_ms(struct uart_port *port) 1369 + { 1370 + struct uart_8250_port *up = up_to_u8250p(port); 1371 + 1372 + /* no MSR capabilities */ 1373 + if (up->bugs & UART_BUG_NOMSR) 1374 + return; 1375 + 1376 + up->ier |= UART_IER_MSI; 1377 + 1378 + serial8250_rpm_get(up); 1379 + serial_port_out(port, UART_IER, up->ier); 1380 + serial8250_rpm_put(up); 1381 + } 1382 + 1383 + /* 1384 + * serial8250_rx_chars: processes according to the passed in LSR 1385 + * value, and returns the remaining LSR bits not handled 1386 + * by this Rx routine. 1387 + */ 1388 + unsigned char 1389 + serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr) 1390 + { 1391 + struct uart_port *port = &up->port; 1392 + unsigned char ch; 1393 + int max_count = 256; 1394 + char flag; 1395 + 1396 + do { 1397 + if (likely(lsr & UART_LSR_DR)) 1398 + ch = serial_in(up, UART_RX); 1399 + else 1400 + /* 1401 + * Intel 82571 has a Serial Over Lan device that will 1402 + * set UART_LSR_BI without setting UART_LSR_DR when 1403 + * it receives a break. To avoid reading from the 1404 + * receive buffer without UART_LSR_DR bit set, we 1405 + * just force the read character to be 0 1406 + */ 1407 + ch = 0; 1408 + 1409 + flag = TTY_NORMAL; 1410 + port->icount.rx++; 1411 + 1412 + lsr |= up->lsr_saved_flags; 1413 + up->lsr_saved_flags = 0; 1414 + 1415 + if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { 1416 + if (lsr & UART_LSR_BI) { 1417 + lsr &= ~(UART_LSR_FE | UART_LSR_PE); 1418 + port->icount.brk++; 1419 + /* 1420 + * We do the SysRQ and SAK checking 1421 + * here because otherwise the break 1422 + * may get masked by ignore_status_mask 1423 + * or read_status_mask. 1424 + */ 1425 + if (uart_handle_break(port)) 1426 + goto ignore_char; 1427 + } else if (lsr & UART_LSR_PE) 1428 + port->icount.parity++; 1429 + else if (lsr & UART_LSR_FE) 1430 + port->icount.frame++; 1431 + if (lsr & UART_LSR_OE) 1432 + port->icount.overrun++; 1433 + 1434 + /* 1435 + * Mask off conditions which should be ignored. 1436 + */ 1437 + lsr &= port->read_status_mask; 1438 + 1439 + if (lsr & UART_LSR_BI) { 1440 + DEBUG_INTR("handling break...."); 1441 + flag = TTY_BREAK; 1442 + } else if (lsr & UART_LSR_PE) 1443 + flag = TTY_PARITY; 1444 + else if (lsr & UART_LSR_FE) 1445 + flag = TTY_FRAME; 1446 + } 1447 + if (uart_handle_sysrq_char(port, ch)) 1448 + goto ignore_char; 1449 + 1450 + uart_insert_char(port, lsr, UART_LSR_OE, ch, flag); 1451 + 1452 + ignore_char: 1453 + lsr = serial_in(up, UART_LSR); 1454 + } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (--max_count > 0)); 1455 + spin_unlock(&port->lock); 1456 + tty_flip_buffer_push(&port->state->port); 1457 + spin_lock(&port->lock); 1458 + return lsr; 1459 + } 1460 + EXPORT_SYMBOL_GPL(serial8250_rx_chars); 1461 + 1462 + void serial8250_tx_chars(struct uart_8250_port *up) 1463 + { 1464 + struct uart_port *port = &up->port; 1465 + struct circ_buf *xmit = &port->state->xmit; 1466 + int count; 1467 + 1468 + if (port->x_char) { 1469 + serial_out(up, UART_TX, port->x_char); 1470 + port->icount.tx++; 1471 + port->x_char = 0; 1472 + return; 1473 + } 1474 + if (uart_tx_stopped(port)) { 1475 + serial8250_stop_tx(port); 1476 + return; 1477 + } 1478 + if (uart_circ_empty(xmit)) { 1479 + __stop_tx(up); 1480 + return; 1481 + } 1482 + 1483 + count = up->tx_loadsz; 1484 + do { 1485 + serial_out(up, UART_TX, xmit->buf[xmit->tail]); 1486 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 1487 + port->icount.tx++; 1488 + if (uart_circ_empty(xmit)) 1489 + break; 1490 + if (up->capabilities & UART_CAP_HFIFO) { 1491 + if ((serial_port_in(port, UART_LSR) & BOTH_EMPTY) != 1492 + BOTH_EMPTY) 1493 + break; 1494 + } 1495 + } while (--count > 0); 1496 + 1497 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 1498 + uart_write_wakeup(port); 1499 + 1500 + DEBUG_INTR("THRE..."); 1501 + 1502 + /* 1503 + * With RPM enabled, we have to wait until the FIFO is empty before the 1504 + * HW can go idle. So we get here once again with empty FIFO and disable 1505 + * the interrupt and RPM in __stop_tx() 1506 + */ 1507 + if (uart_circ_empty(xmit) && !(up->capabilities & UART_CAP_RPM)) 1508 + __stop_tx(up); 1509 + } 1510 + EXPORT_SYMBOL_GPL(serial8250_tx_chars); 1511 + 1512 + /* Caller holds uart port lock */ 1513 + unsigned int serial8250_modem_status(struct uart_8250_port *up) 1514 + { 1515 + struct uart_port *port = &up->port; 1516 + unsigned int status = serial_in(up, UART_MSR); 1517 + 1518 + status |= up->msr_saved_flags; 1519 + up->msr_saved_flags = 0; 1520 + if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && 1521 + port->state != NULL) { 1522 + if (status & UART_MSR_TERI) 1523 + port->icount.rng++; 1524 + if (status & UART_MSR_DDSR) 1525 + port->icount.dsr++; 1526 + if (status & UART_MSR_DDCD) 1527 + uart_handle_dcd_change(port, status & UART_MSR_DCD); 1528 + if (status & UART_MSR_DCTS) 1529 + uart_handle_cts_change(port, status & UART_MSR_CTS); 1530 + 1531 + wake_up_interruptible(&port->state->port.delta_msr_wait); 1532 + } 1533 + 1534 + return status; 1535 + } 1536 + EXPORT_SYMBOL_GPL(serial8250_modem_status); 1537 + 1538 + /* 1539 + * This handles the interrupt from one port. 1540 + */ 1541 + int serial8250_handle_irq(struct uart_port *port, unsigned int iir) 1542 + { 1543 + unsigned char status; 1544 + unsigned long flags; 1545 + struct uart_8250_port *up = up_to_u8250p(port); 1546 + int dma_err = 0; 1547 + 1548 + if (iir & UART_IIR_NO_INT) 1549 + return 0; 1550 + 1551 + spin_lock_irqsave(&port->lock, flags); 1552 + 1553 + status = serial_port_in(port, UART_LSR); 1554 + 1555 + DEBUG_INTR("status = %x...", status); 1556 + 1557 + if (status & (UART_LSR_DR | UART_LSR_BI)) { 1558 + if (up->dma) 1559 + dma_err = up->dma->rx_dma(up, iir); 1560 + 1561 + if (!up->dma || dma_err) 1562 + status = serial8250_rx_chars(up, status); 1563 + } 1564 + serial8250_modem_status(up); 1565 + if ((!up->dma || (up->dma && up->dma->tx_err)) && 1566 + (status & UART_LSR_THRE)) 1567 + serial8250_tx_chars(up); 1568 + 1569 + spin_unlock_irqrestore(&port->lock, flags); 1570 + return 1; 1571 + } 1572 + EXPORT_SYMBOL_GPL(serial8250_handle_irq); 1573 + 1574 + static int serial8250_default_handle_irq(struct uart_port *port) 1575 + { 1576 + struct uart_8250_port *up = up_to_u8250p(port); 1577 + unsigned int iir; 1578 + int ret; 1579 + 1580 + serial8250_rpm_get(up); 1581 + 1582 + iir = serial_port_in(port, UART_IIR); 1583 + ret = serial8250_handle_irq(port, iir); 1584 + 1585 + serial8250_rpm_put(up); 1586 + return ret; 1587 + } 1588 + 1589 + /* 1590 + * These Exar UARTs have an extra interrupt indicator that could 1591 + * fire for a few unimplemented interrupts. One of which is a 1592 + * wakeup event when coming out of sleep. Put this here just 1593 + * to be on the safe side that these interrupts don't go unhandled. 1594 + */ 1595 + static int exar_handle_irq(struct uart_port *port) 1596 + { 1597 + unsigned char int0, int1, int2, int3; 1598 + unsigned int iir = serial_port_in(port, UART_IIR); 1599 + int ret; 1600 + 1601 + ret = serial8250_handle_irq(port, iir); 1602 + 1603 + if ((port->type == PORT_XR17V35X) || 1604 + (port->type == PORT_XR17D15X)) { 1605 + int0 = serial_port_in(port, 0x80); 1606 + int1 = serial_port_in(port, 0x81); 1607 + int2 = serial_port_in(port, 0x82); 1608 + int3 = serial_port_in(port, 0x83); 1609 + } 1610 + 1611 + return ret; 1612 + } 1613 + 1614 + static unsigned int serial8250_tx_empty(struct uart_port *port) 1615 + { 1616 + struct uart_8250_port *up = up_to_u8250p(port); 1617 + unsigned long flags; 1618 + unsigned int lsr; 1619 + 1620 + serial8250_rpm_get(up); 1621 + 1622 + spin_lock_irqsave(&port->lock, flags); 1623 + lsr = serial_port_in(port, UART_LSR); 1624 + up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; 1625 + spin_unlock_irqrestore(&port->lock, flags); 1626 + 1627 + serial8250_rpm_put(up); 1628 + 1629 + return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0; 1630 + } 1631 + 1632 + static unsigned int serial8250_get_mctrl(struct uart_port *port) 1633 + { 1634 + struct uart_8250_port *up = up_to_u8250p(port); 1635 + unsigned int status; 1636 + unsigned int ret; 1637 + 1638 + serial8250_rpm_get(up); 1639 + status = serial8250_modem_status(up); 1640 + serial8250_rpm_put(up); 1641 + 1642 + ret = 0; 1643 + if (status & UART_MSR_DCD) 1644 + ret |= TIOCM_CAR; 1645 + if (status & UART_MSR_RI) 1646 + ret |= TIOCM_RNG; 1647 + if (status & UART_MSR_DSR) 1648 + ret |= TIOCM_DSR; 1649 + if (status & UART_MSR_CTS) 1650 + ret |= TIOCM_CTS; 1651 + return ret; 1652 + } 1653 + 1654 + void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl) 1655 + { 1656 + struct uart_8250_port *up = up_to_u8250p(port); 1657 + unsigned char mcr = 0; 1658 + 1659 + if (mctrl & TIOCM_RTS) 1660 + mcr |= UART_MCR_RTS; 1661 + if (mctrl & TIOCM_DTR) 1662 + mcr |= UART_MCR_DTR; 1663 + if (mctrl & TIOCM_OUT1) 1664 + mcr |= UART_MCR_OUT1; 1665 + if (mctrl & TIOCM_OUT2) 1666 + mcr |= UART_MCR_OUT2; 1667 + if (mctrl & TIOCM_LOOP) 1668 + mcr |= UART_MCR_LOOP; 1669 + 1670 + mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; 1671 + 1672 + serial_port_out(port, UART_MCR, mcr); 1673 + } 1674 + EXPORT_SYMBOL_GPL(serial8250_do_set_mctrl); 1675 + 1676 + static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) 1677 + { 1678 + if (port->set_mctrl) 1679 + port->set_mctrl(port, mctrl); 1680 + else 1681 + serial8250_do_set_mctrl(port, mctrl); 1682 + } 1683 + 1684 + static void serial8250_break_ctl(struct uart_port *port, int break_state) 1685 + { 1686 + struct uart_8250_port *up = up_to_u8250p(port); 1687 + unsigned long flags; 1688 + 1689 + serial8250_rpm_get(up); 1690 + spin_lock_irqsave(&port->lock, flags); 1691 + if (break_state == -1) 1692 + up->lcr |= UART_LCR_SBC; 1693 + else 1694 + up->lcr &= ~UART_LCR_SBC; 1695 + serial_port_out(port, UART_LCR, up->lcr); 1696 + spin_unlock_irqrestore(&port->lock, flags); 1697 + serial8250_rpm_put(up); 1698 + } 1699 + 1700 + /* 1701 + * Wait for transmitter & holding register to empty 1702 + */ 1703 + static void wait_for_xmitr(struct uart_8250_port *up, int bits) 1704 + { 1705 + unsigned int status, tmout = 10000; 1706 + 1707 + /* Wait up to 10ms for the character(s) to be sent. */ 1708 + for (;;) { 1709 + status = serial_in(up, UART_LSR); 1710 + 1711 + up->lsr_saved_flags |= status & LSR_SAVE_FLAGS; 1712 + 1713 + if ((status & bits) == bits) 1714 + break; 1715 + if (--tmout == 0) 1716 + break; 1717 + udelay(1); 1718 + } 1719 + 1720 + /* Wait up to 1s for flow control if necessary */ 1721 + if (up->port.flags & UPF_CONS_FLOW) { 1722 + unsigned int tmout; 1723 + for (tmout = 1000000; tmout; tmout--) { 1724 + unsigned int msr = serial_in(up, UART_MSR); 1725 + up->msr_saved_flags |= msr & MSR_SAVE_FLAGS; 1726 + if (msr & UART_MSR_CTS) 1727 + break; 1728 + udelay(1); 1729 + touch_nmi_watchdog(); 1730 + } 1731 + } 1732 + } 1733 + 1734 + #ifdef CONFIG_CONSOLE_POLL 1735 + /* 1736 + * Console polling routines for writing and reading from the uart while 1737 + * in an interrupt or debug context. 1738 + */ 1739 + 1740 + static int serial8250_get_poll_char(struct uart_port *port) 1741 + { 1742 + struct uart_8250_port *up = up_to_u8250p(port); 1743 + unsigned char lsr; 1744 + int status; 1745 + 1746 + serial8250_rpm_get(up); 1747 + 1748 + lsr = serial_port_in(port, UART_LSR); 1749 + 1750 + if (!(lsr & UART_LSR_DR)) { 1751 + status = NO_POLL_CHAR; 1752 + goto out; 1753 + } 1754 + 1755 + status = serial_port_in(port, UART_RX); 1756 + out: 1757 + serial8250_rpm_put(up); 1758 + return status; 1759 + } 1760 + 1761 + 1762 + static void serial8250_put_poll_char(struct uart_port *port, 1763 + unsigned char c) 1764 + { 1765 + unsigned int ier; 1766 + struct uart_8250_port *up = up_to_u8250p(port); 1767 + 1768 + serial8250_rpm_get(up); 1769 + /* 1770 + * First save the IER then disable the interrupts 1771 + */ 1772 + ier = serial_port_in(port, UART_IER); 1773 + if (up->capabilities & UART_CAP_UUE) 1774 + serial_port_out(port, UART_IER, UART_IER_UUE); 1775 + else 1776 + serial_port_out(port, UART_IER, 0); 1777 + 1778 + wait_for_xmitr(up, BOTH_EMPTY); 1779 + /* 1780 + * Send the character out. 1781 + */ 1782 + serial_port_out(port, UART_TX, c); 1783 + 1784 + /* 1785 + * Finally, wait for transmitter to become empty 1786 + * and restore the IER 1787 + */ 1788 + wait_for_xmitr(up, BOTH_EMPTY); 1789 + serial_port_out(port, UART_IER, ier); 1790 + serial8250_rpm_put(up); 1791 + } 1792 + 1793 + #endif /* CONFIG_CONSOLE_POLL */ 1794 + 1795 + int serial8250_do_startup(struct uart_port *port) 1796 + { 1797 + struct uart_8250_port *up = up_to_u8250p(port); 1798 + unsigned long flags; 1799 + unsigned char lsr, iir; 1800 + int retval; 1801 + 1802 + if (port->type == PORT_8250_CIR) 1803 + return -ENODEV; 1804 + 1805 + if (!port->fifosize) 1806 + port->fifosize = uart_config[port->type].fifo_size; 1807 + if (!up->tx_loadsz) 1808 + up->tx_loadsz = uart_config[port->type].tx_loadsz; 1809 + if (!up->capabilities) 1810 + up->capabilities = uart_config[port->type].flags; 1811 + up->mcr = 0; 1812 + 1813 + if (port->iotype != up->cur_iotype) 1814 + set_io_from_upio(port); 1815 + 1816 + serial8250_rpm_get(up); 1817 + if (port->type == PORT_16C950) { 1818 + /* Wake up and initialize UART */ 1819 + up->acr = 0; 1820 + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 1821 + serial_port_out(port, UART_EFR, UART_EFR_ECB); 1822 + serial_port_out(port, UART_IER, 0); 1823 + serial_port_out(port, UART_LCR, 0); 1824 + serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ 1825 + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 1826 + serial_port_out(port, UART_EFR, UART_EFR_ECB); 1827 + serial_port_out(port, UART_LCR, 0); 1828 + } 1829 + 1830 + #ifdef CONFIG_SERIAL_8250_RSA 1831 + /* 1832 + * If this is an RSA port, see if we can kick it up to the 1833 + * higher speed clock. 1834 + */ 1835 + enable_rsa(up); 1836 + #endif 1837 + /* 1838 + * Clear the FIFO buffers and disable them. 1839 + * (they will be reenabled in set_termios()) 1840 + */ 1841 + serial8250_clear_fifos(up); 1842 + 1843 + /* 1844 + * Clear the interrupt registers. 1845 + */ 1846 + serial_port_in(port, UART_LSR); 1847 + serial_port_in(port, UART_RX); 1848 + serial_port_in(port, UART_IIR); 1849 + serial_port_in(port, UART_MSR); 1850 + 1851 + /* 1852 + * At this point, there's no way the LSR could still be 0xff; 1853 + * if it is, then bail out, because there's likely no UART 1854 + * here. 1855 + */ 1856 + if (!(port->flags & UPF_BUGGY_UART) && 1857 + (serial_port_in(port, UART_LSR) == 0xff)) { 1858 + printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n", 1859 + serial_index(port)); 1860 + retval = -ENODEV; 1861 + goto out; 1862 + } 1863 + 1864 + /* 1865 + * For a XR16C850, we need to set the trigger levels 1866 + */ 1867 + if (port->type == PORT_16850) { 1868 + unsigned char fctr; 1869 + 1870 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 1871 + 1872 + fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); 1873 + serial_port_out(port, UART_FCTR, 1874 + fctr | UART_FCTR_TRGD | UART_FCTR_RX); 1875 + serial_port_out(port, UART_TRG, UART_TRG_96); 1876 + serial_port_out(port, UART_FCTR, 1877 + fctr | UART_FCTR_TRGD | UART_FCTR_TX); 1878 + serial_port_out(port, UART_TRG, UART_TRG_96); 1879 + 1880 + serial_port_out(port, UART_LCR, 0); 1881 + } 1882 + 1883 + if (port->irq) { 1884 + unsigned char iir1; 1885 + /* 1886 + * Test for UARTs that do not reassert THRE when the 1887 + * transmitter is idle and the interrupt has already 1888 + * been cleared. Real 16550s should always reassert 1889 + * this interrupt whenever the transmitter is idle and 1890 + * the interrupt is enabled. Delays are necessary to 1891 + * allow register changes to become visible. 1892 + */ 1893 + spin_lock_irqsave(&port->lock, flags); 1894 + if (up->port.irqflags & IRQF_SHARED) 1895 + disable_irq_nosync(port->irq); 1896 + 1897 + wait_for_xmitr(up, UART_LSR_THRE); 1898 + serial_port_out_sync(port, UART_IER, UART_IER_THRI); 1899 + udelay(1); /* allow THRE to set */ 1900 + iir1 = serial_port_in(port, UART_IIR); 1901 + serial_port_out(port, UART_IER, 0); 1902 + serial_port_out_sync(port, UART_IER, UART_IER_THRI); 1903 + udelay(1); /* allow a working UART time to re-assert THRE */ 1904 + iir = serial_port_in(port, UART_IIR); 1905 + serial_port_out(port, UART_IER, 0); 1906 + 1907 + if (port->irqflags & IRQF_SHARED) 1908 + enable_irq(port->irq); 1909 + spin_unlock_irqrestore(&port->lock, flags); 1910 + 1911 + /* 1912 + * If the interrupt is not reasserted, or we otherwise 1913 + * don't trust the iir, setup a timer to kick the UART 1914 + * on a regular basis. 1915 + */ 1916 + if ((!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) || 1917 + up->port.flags & UPF_BUG_THRE) { 1918 + up->bugs |= UART_BUG_THRE; 1919 + } 1920 + } 1921 + 1922 + retval = up->ops->setup_irq(up); 1923 + if (retval) 1924 + goto out; 1925 + 1926 + /* 1927 + * Now, initialize the UART 1928 + */ 1929 + serial_port_out(port, UART_LCR, UART_LCR_WLEN8); 1930 + 1931 + spin_lock_irqsave(&port->lock, flags); 1932 + if (up->port.flags & UPF_FOURPORT) { 1933 + if (!up->port.irq) 1934 + up->port.mctrl |= TIOCM_OUT1; 1935 + } else 1936 + /* 1937 + * Most PC uarts need OUT2 raised to enable interrupts. 1938 + */ 1939 + if (port->irq) 1940 + up->port.mctrl |= TIOCM_OUT2; 1941 + 1942 + serial8250_set_mctrl(port, port->mctrl); 1943 + 1944 + /* Serial over Lan (SoL) hack: 1945 + Intel 8257x Gigabit ethernet chips have a 1946 + 16550 emulation, to be used for Serial Over Lan. 1947 + Those chips take a longer time than a normal 1948 + serial device to signalize that a transmission 1949 + data was queued. Due to that, the above test generally 1950 + fails. One solution would be to delay the reading of 1951 + iir. However, this is not reliable, since the timeout 1952 + is variable. So, let's just don't test if we receive 1953 + TX irq. This way, we'll never enable UART_BUG_TXEN. 1954 + */ 1955 + if (up->port.flags & UPF_NO_TXEN_TEST) 1956 + goto dont_test_tx_en; 1957 + 1958 + /* 1959 + * Do a quick test to see if we receive an 1960 + * interrupt when we enable the TX irq. 1961 + */ 1962 + serial_port_out(port, UART_IER, UART_IER_THRI); 1963 + lsr = serial_port_in(port, UART_LSR); 1964 + iir = serial_port_in(port, UART_IIR); 1965 + serial_port_out(port, UART_IER, 0); 1966 + 1967 + if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { 1968 + if (!(up->bugs & UART_BUG_TXEN)) { 1969 + up->bugs |= UART_BUG_TXEN; 1970 + pr_debug("ttyS%d - enabling bad tx status workarounds\n", 1971 + serial_index(port)); 1972 + } 1973 + } else { 1974 + up->bugs &= ~UART_BUG_TXEN; 1975 + } 1976 + 1977 + dont_test_tx_en: 1978 + spin_unlock_irqrestore(&port->lock, flags); 1979 + 1980 + /* 1981 + * Clear the interrupt registers again for luck, and clear the 1982 + * saved flags to avoid getting false values from polling 1983 + * routines or the previous session. 1984 + */ 1985 + serial_port_in(port, UART_LSR); 1986 + serial_port_in(port, UART_RX); 1987 + serial_port_in(port, UART_IIR); 1988 + serial_port_in(port, UART_MSR); 1989 + up->lsr_saved_flags = 0; 1990 + up->msr_saved_flags = 0; 1991 + 1992 + /* 1993 + * Request DMA channels for both RX and TX. 1994 + */ 1995 + if (up->dma) { 1996 + retval = serial8250_request_dma(up); 1997 + if (retval) { 1998 + pr_warn_ratelimited("ttyS%d - failed to request DMA\n", 1999 + serial_index(port)); 2000 + up->dma = NULL; 2001 + } 2002 + } 2003 + 2004 + /* 2005 + * Finally, enable interrupts. Note: Modem status interrupts 2006 + * are set via set_termios(), which will be occurring imminently 2007 + * anyway, so we don't enable them here. 2008 + */ 2009 + up->ier = UART_IER_RLSI | UART_IER_RDI; 2010 + serial_port_out(port, UART_IER, up->ier); 2011 + 2012 + if (port->flags & UPF_FOURPORT) { 2013 + unsigned int icp; 2014 + /* 2015 + * Enable interrupts on the AST Fourport board 2016 + */ 2017 + icp = (port->iobase & 0xfe0) | 0x01f; 2018 + outb_p(0x80, icp); 2019 + inb_p(icp); 2020 + } 2021 + retval = 0; 2022 + out: 2023 + serial8250_rpm_put(up); 2024 + return retval; 2025 + } 2026 + EXPORT_SYMBOL_GPL(serial8250_do_startup); 2027 + 2028 + static int serial8250_startup(struct uart_port *port) 2029 + { 2030 + if (port->startup) 2031 + return port->startup(port); 2032 + return serial8250_do_startup(port); 2033 + } 2034 + 2035 + void serial8250_do_shutdown(struct uart_port *port) 2036 + { 2037 + struct uart_8250_port *up = up_to_u8250p(port); 2038 + unsigned long flags; 2039 + 2040 + serial8250_rpm_get(up); 2041 + /* 2042 + * Disable interrupts from this port 2043 + */ 2044 + up->ier = 0; 2045 + serial_port_out(port, UART_IER, 0); 2046 + 2047 + if (up->dma) 2048 + serial8250_release_dma(up); 2049 + 2050 + spin_lock_irqsave(&port->lock, flags); 2051 + if (port->flags & UPF_FOURPORT) { 2052 + /* reset interrupts on the AST Fourport board */ 2053 + inb((port->iobase & 0xfe0) | 0x1f); 2054 + port->mctrl |= TIOCM_OUT1; 2055 + } else 2056 + port->mctrl &= ~TIOCM_OUT2; 2057 + 2058 + serial8250_set_mctrl(port, port->mctrl); 2059 + spin_unlock_irqrestore(&port->lock, flags); 2060 + 2061 + /* 2062 + * Disable break condition and FIFOs 2063 + */ 2064 + serial_port_out(port, UART_LCR, 2065 + serial_port_in(port, UART_LCR) & ~UART_LCR_SBC); 2066 + serial8250_clear_fifos(up); 2067 + 2068 + #ifdef CONFIG_SERIAL_8250_RSA 2069 + /* 2070 + * Reset the RSA board back to 115kbps compat mode. 2071 + */ 2072 + disable_rsa(up); 2073 + #endif 2074 + 2075 + /* 2076 + * Read data port to reset things, and then unlink from 2077 + * the IRQ chain. 2078 + */ 2079 + serial_port_in(port, UART_RX); 2080 + serial8250_rpm_put(up); 2081 + 2082 + up->ops->release_irq(up); 2083 + } 2084 + EXPORT_SYMBOL_GPL(serial8250_do_shutdown); 2085 + 2086 + static void serial8250_shutdown(struct uart_port *port) 2087 + { 2088 + if (port->shutdown) 2089 + port->shutdown(port); 2090 + else 2091 + serial8250_do_shutdown(port); 2092 + } 2093 + 2094 + /* 2095 + * XR17V35x UARTs have an extra fractional divisor register (DLD) 2096 + * Calculate divisor with extra 4-bit fractional portion 2097 + */ 2098 + static unsigned int xr17v35x_get_divisor(struct uart_8250_port *up, 2099 + unsigned int baud, 2100 + unsigned int *frac) 2101 + { 2102 + struct uart_port *port = &up->port; 2103 + unsigned int quot_16; 2104 + 2105 + quot_16 = DIV_ROUND_CLOSEST(port->uartclk, baud); 2106 + *frac = quot_16 & 0x0f; 2107 + 2108 + return quot_16 >> 4; 2109 + } 2110 + 2111 + static unsigned int serial8250_get_divisor(struct uart_8250_port *up, 2112 + unsigned int baud, 2113 + unsigned int *frac) 2114 + { 2115 + struct uart_port *port = &up->port; 2116 + unsigned int quot; 2117 + 2118 + /* 2119 + * Handle magic divisors for baud rates above baud_base on 2120 + * SMSC SuperIO chips. 2121 + * 2122 + */ 2123 + if ((port->flags & UPF_MAGIC_MULTIPLIER) && 2124 + baud == (port->uartclk/4)) 2125 + quot = 0x8001; 2126 + else if ((port->flags & UPF_MAGIC_MULTIPLIER) && 2127 + baud == (port->uartclk/8)) 2128 + quot = 0x8002; 2129 + else if (up->port.type == PORT_XR17V35X) 2130 + quot = xr17v35x_get_divisor(up, baud, frac); 2131 + else 2132 + quot = uart_get_divisor(port, baud); 2133 + 2134 + /* 2135 + * Oxford Semi 952 rev B workaround 2136 + */ 2137 + if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) 2138 + quot++; 2139 + 2140 + return quot; 2141 + } 2142 + 2143 + static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, 2144 + tcflag_t c_cflag) 2145 + { 2146 + unsigned char cval; 2147 + 2148 + switch (c_cflag & CSIZE) { 2149 + case CS5: 2150 + cval = UART_LCR_WLEN5; 2151 + break; 2152 + case CS6: 2153 + cval = UART_LCR_WLEN6; 2154 + break; 2155 + case CS7: 2156 + cval = UART_LCR_WLEN7; 2157 + break; 2158 + default: 2159 + case CS8: 2160 + cval = UART_LCR_WLEN8; 2161 + break; 2162 + } 2163 + 2164 + if (c_cflag & CSTOPB) 2165 + cval |= UART_LCR_STOP; 2166 + if (c_cflag & PARENB) { 2167 + cval |= UART_LCR_PARITY; 2168 + if (up->bugs & UART_BUG_PARITY) 2169 + up->fifo_bug = true; 2170 + } 2171 + if (!(c_cflag & PARODD)) 2172 + cval |= UART_LCR_EPAR; 2173 + #ifdef CMSPAR 2174 + if (c_cflag & CMSPAR) 2175 + cval |= UART_LCR_SPAR; 2176 + #endif 2177 + 2178 + return cval; 2179 + } 2180 + 2181 + static void serial8250_set_divisor(struct uart_port *port, unsigned int baud, 2182 + unsigned int quot, unsigned int quot_frac) 2183 + { 2184 + struct uart_8250_port *up = up_to_u8250p(port); 2185 + 2186 + /* Workaround to enable 115200 baud on OMAP1510 internal ports */ 2187 + if (is_omap1510_8250(up)) { 2188 + if (baud == 115200) { 2189 + quot = 1; 2190 + serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1); 2191 + } else 2192 + serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0); 2193 + } 2194 + 2195 + /* 2196 + * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2, 2197 + * otherwise just set DLAB 2198 + */ 2199 + if (up->capabilities & UART_NATSEMI) 2200 + serial_port_out(port, UART_LCR, 0xe0); 2201 + else 2202 + serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB); 2203 + 2204 + serial_dl_write(up, quot); 2205 + 2206 + /* XR17V35x UARTs have an extra fractional divisor register (DLD) */ 2207 + if (up->port.type == PORT_XR17V35X) 2208 + serial_port_out(port, 0x2, quot_frac); 2209 + } 2210 + 2211 + void 2212 + serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, 2213 + struct ktermios *old) 2214 + { 2215 + struct uart_8250_port *up = up_to_u8250p(port); 2216 + unsigned char cval; 2217 + unsigned long flags; 2218 + unsigned int baud, quot, frac = 0; 2219 + 2220 + cval = serial8250_compute_lcr(up, termios->c_cflag); 2221 + 2222 + /* 2223 + * Ask the core to calculate the divisor for us. 2224 + */ 2225 + baud = uart_get_baud_rate(port, termios, old, 2226 + port->uartclk / 16 / 0xffff, 2227 + port->uartclk / 16); 2228 + quot = serial8250_get_divisor(up, baud, &frac); 2229 + 2230 + /* 2231 + * Ok, we're now changing the port state. Do it with 2232 + * interrupts disabled. 2233 + */ 2234 + serial8250_rpm_get(up); 2235 + spin_lock_irqsave(&port->lock, flags); 2236 + 2237 + up->lcr = cval; /* Save computed LCR */ 2238 + 2239 + if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { 2240 + /* NOTE: If fifo_bug is not set, a user can set RX_trigger. */ 2241 + if ((baud < 2400 && !up->dma) || up->fifo_bug) { 2242 + up->fcr &= ~UART_FCR_TRIGGER_MASK; 2243 + up->fcr |= UART_FCR_TRIGGER_1; 2244 + } 2245 + } 2246 + 2247 + /* 2248 + * MCR-based auto flow control. When AFE is enabled, RTS will be 2249 + * deasserted when the receive FIFO contains more characters than 2250 + * the trigger, or the MCR RTS bit is cleared. In the case where 2251 + * the remote UART is not using CTS auto flow control, we must 2252 + * have sufficient FIFO entries for the latency of the remote 2253 + * UART to respond. IOW, at least 32 bytes of FIFO. 2254 + */ 2255 + if (up->capabilities & UART_CAP_AFE && port->fifosize >= 32) { 2256 + up->mcr &= ~UART_MCR_AFE; 2257 + if (termios->c_cflag & CRTSCTS) 2258 + up->mcr |= UART_MCR_AFE; 2259 + } 2260 + 2261 + /* 2262 + * Update the per-port timeout. 2263 + */ 2264 + uart_update_timeout(port, termios->c_cflag, baud); 2265 + 2266 + port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 2267 + if (termios->c_iflag & INPCK) 2268 + port->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 2269 + if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) 2270 + port->read_status_mask |= UART_LSR_BI; 2271 + 2272 + /* 2273 + * Characteres to ignore 2274 + */ 2275 + port->ignore_status_mask = 0; 2276 + if (termios->c_iflag & IGNPAR) 2277 + port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 2278 + if (termios->c_iflag & IGNBRK) { 2279 + port->ignore_status_mask |= UART_LSR_BI; 2280 + /* 2281 + * If we're ignoring parity and break indicators, 2282 + * ignore overruns too (for real raw support). 2283 + */ 2284 + if (termios->c_iflag & IGNPAR) 2285 + port->ignore_status_mask |= UART_LSR_OE; 2286 + } 2287 + 2288 + /* 2289 + * ignore all characters if CREAD is not set 2290 + */ 2291 + if ((termios->c_cflag & CREAD) == 0) 2292 + port->ignore_status_mask |= UART_LSR_DR; 2293 + 2294 + /* 2295 + * CTS flow control flag and modem status interrupts 2296 + */ 2297 + up->ier &= ~UART_IER_MSI; 2298 + if (!(up->bugs & UART_BUG_NOMSR) && 2299 + UART_ENABLE_MS(&up->port, termios->c_cflag)) 2300 + up->ier |= UART_IER_MSI; 2301 + if (up->capabilities & UART_CAP_UUE) 2302 + up->ier |= UART_IER_UUE; 2303 + if (up->capabilities & UART_CAP_RTOIE) 2304 + up->ier |= UART_IER_RTOIE; 2305 + 2306 + serial_port_out(port, UART_IER, up->ier); 2307 + 2308 + if (up->capabilities & UART_CAP_EFR) { 2309 + unsigned char efr = 0; 2310 + /* 2311 + * TI16C752/Startech hardware flow control. FIXME: 2312 + * - TI16C752 requires control thresholds to be set. 2313 + * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled. 2314 + */ 2315 + if (termios->c_cflag & CRTSCTS) 2316 + efr |= UART_EFR_CTS; 2317 + 2318 + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 2319 + if (port->flags & UPF_EXAR_EFR) 2320 + serial_port_out(port, UART_XR_EFR, efr); 2321 + else 2322 + serial_port_out(port, UART_EFR, efr); 2323 + } 2324 + 2325 + serial8250_set_divisor(port, baud, quot, frac); 2326 + 2327 + /* 2328 + * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR 2329 + * is written without DLAB set, this mode will be disabled. 2330 + */ 2331 + if (port->type == PORT_16750) 2332 + serial_port_out(port, UART_FCR, up->fcr); 2333 + 2334 + serial_port_out(port, UART_LCR, up->lcr); /* reset DLAB */ 2335 + if (port->type != PORT_16750) { 2336 + /* emulated UARTs (Lucent Venus 167x) need two steps */ 2337 + if (up->fcr & UART_FCR_ENABLE_FIFO) 2338 + serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO); 2339 + serial_port_out(port, UART_FCR, up->fcr); /* set fcr */ 2340 + } 2341 + serial8250_set_mctrl(port, port->mctrl); 2342 + spin_unlock_irqrestore(&port->lock, flags); 2343 + serial8250_rpm_put(up); 2344 + 2345 + /* Don't rewrite B0 */ 2346 + if (tty_termios_baud_rate(termios)) 2347 + tty_termios_encode_baud_rate(termios, baud, baud); 2348 + } 2349 + EXPORT_SYMBOL(serial8250_do_set_termios); 2350 + 2351 + static void 2352 + serial8250_set_termios(struct uart_port *port, struct ktermios *termios, 2353 + struct ktermios *old) 2354 + { 2355 + if (port->set_termios) 2356 + port->set_termios(port, termios, old); 2357 + else 2358 + serial8250_do_set_termios(port, termios, old); 2359 + } 2360 + 2361 + static void 2362 + serial8250_set_ldisc(struct uart_port *port, struct ktermios *termios) 2363 + { 2364 + if (termios->c_line == N_PPS) { 2365 + port->flags |= UPF_HARDPPS_CD; 2366 + spin_lock_irq(&port->lock); 2367 + serial8250_enable_ms(port); 2368 + spin_unlock_irq(&port->lock); 2369 + } else { 2370 + port->flags &= ~UPF_HARDPPS_CD; 2371 + if (!UART_ENABLE_MS(port, termios->c_cflag)) { 2372 + spin_lock_irq(&port->lock); 2373 + serial8250_disable_ms(port); 2374 + spin_unlock_irq(&port->lock); 2375 + } 2376 + } 2377 + } 2378 + 2379 + 2380 + void serial8250_do_pm(struct uart_port *port, unsigned int state, 2381 + unsigned int oldstate) 2382 + { 2383 + struct uart_8250_port *p = up_to_u8250p(port); 2384 + 2385 + serial8250_set_sleep(p, state != 0); 2386 + } 2387 + EXPORT_SYMBOL(serial8250_do_pm); 2388 + 2389 + static void 2390 + serial8250_pm(struct uart_port *port, unsigned int state, 2391 + unsigned int oldstate) 2392 + { 2393 + if (port->pm) 2394 + port->pm(port, state, oldstate); 2395 + else 2396 + serial8250_do_pm(port, state, oldstate); 2397 + } 2398 + 2399 + static unsigned int serial8250_port_size(struct uart_8250_port *pt) 2400 + { 2401 + if (pt->port.mapsize) 2402 + return pt->port.mapsize; 2403 + if (pt->port.iotype == UPIO_AU) { 2404 + if (pt->port.type == PORT_RT2880) 2405 + return 0x100; 2406 + return 0x1000; 2407 + } 2408 + if (is_omap1_8250(pt)) 2409 + return 0x16 << pt->port.regshift; 2410 + 2411 + return 8 << pt->port.regshift; 2412 + } 2413 + 2414 + /* 2415 + * Resource handling. 2416 + */ 2417 + static int serial8250_request_std_resource(struct uart_8250_port *up) 2418 + { 2419 + unsigned int size = serial8250_port_size(up); 2420 + struct uart_port *port = &up->port; 2421 + int ret = 0; 2422 + 2423 + switch (port->iotype) { 2424 + case UPIO_AU: 2425 + case UPIO_TSI: 2426 + case UPIO_MEM32: 2427 + case UPIO_MEM32BE: 2428 + case UPIO_MEM: 2429 + if (!port->mapbase) 2430 + break; 2431 + 2432 + if (!request_mem_region(port->mapbase, size, "serial")) { 2433 + ret = -EBUSY; 2434 + break; 2435 + } 2436 + 2437 + if (port->flags & UPF_IOREMAP) { 2438 + port->membase = ioremap_nocache(port->mapbase, size); 2439 + if (!port->membase) { 2440 + release_mem_region(port->mapbase, size); 2441 + ret = -ENOMEM; 2442 + } 2443 + } 2444 + break; 2445 + 2446 + case UPIO_HUB6: 2447 + case UPIO_PORT: 2448 + if (!request_region(port->iobase, size, "serial")) 2449 + ret = -EBUSY; 2450 + break; 2451 + } 2452 + return ret; 2453 + } 2454 + 2455 + static void serial8250_release_std_resource(struct uart_8250_port *up) 2456 + { 2457 + unsigned int size = serial8250_port_size(up); 2458 + struct uart_port *port = &up->port; 2459 + 2460 + switch (port->iotype) { 2461 + case UPIO_AU: 2462 + case UPIO_TSI: 2463 + case UPIO_MEM32: 2464 + case UPIO_MEM32BE: 2465 + case UPIO_MEM: 2466 + if (!port->mapbase) 2467 + break; 2468 + 2469 + if (port->flags & UPF_IOREMAP) { 2470 + iounmap(port->membase); 2471 + port->membase = NULL; 2472 + } 2473 + 2474 + release_mem_region(port->mapbase, size); 2475 + break; 2476 + 2477 + case UPIO_HUB6: 2478 + case UPIO_PORT: 2479 + release_region(port->iobase, size); 2480 + break; 2481 + } 2482 + } 2483 + 2484 + static void serial8250_release_port(struct uart_port *port) 2485 + { 2486 + struct uart_8250_port *up = up_to_u8250p(port); 2487 + 2488 + serial8250_release_std_resource(up); 2489 + } 2490 + 2491 + static int serial8250_request_port(struct uart_port *port) 2492 + { 2493 + struct uart_8250_port *up = up_to_u8250p(port); 2494 + int ret; 2495 + 2496 + if (port->type == PORT_8250_CIR) 2497 + return -ENODEV; 2498 + 2499 + ret = serial8250_request_std_resource(up); 2500 + 2501 + return ret; 2502 + } 2503 + 2504 + static int fcr_get_rxtrig_bytes(struct uart_8250_port *up) 2505 + { 2506 + const struct serial8250_config *conf_type = &uart_config[up->port.type]; 2507 + unsigned char bytes; 2508 + 2509 + bytes = conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(up->fcr)]; 2510 + 2511 + return bytes ? bytes : -EOPNOTSUPP; 2512 + } 2513 + 2514 + static int bytes_to_fcr_rxtrig(struct uart_8250_port *up, unsigned char bytes) 2515 + { 2516 + const struct serial8250_config *conf_type = &uart_config[up->port.type]; 2517 + int i; 2518 + 2519 + if (!conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(UART_FCR_R_TRIG_00)]) 2520 + return -EOPNOTSUPP; 2521 + 2522 + for (i = 1; i < UART_FCR_R_TRIG_MAX_STATE; i++) { 2523 + if (bytes < conf_type->rxtrig_bytes[i]) 2524 + /* Use the nearest lower value */ 2525 + return (--i) << UART_FCR_R_TRIG_SHIFT; 2526 + } 2527 + 2528 + return UART_FCR_R_TRIG_11; 2529 + } 2530 + 2531 + static int do_get_rxtrig(struct tty_port *port) 2532 + { 2533 + struct uart_state *state = container_of(port, struct uart_state, port); 2534 + struct uart_port *uport = state->uart_port; 2535 + struct uart_8250_port *up = 2536 + container_of(uport, struct uart_8250_port, port); 2537 + 2538 + if (!(up->capabilities & UART_CAP_FIFO) || uport->fifosize <= 1) 2539 + return -EINVAL; 2540 + 2541 + return fcr_get_rxtrig_bytes(up); 2542 + } 2543 + 2544 + static int do_serial8250_get_rxtrig(struct tty_port *port) 2545 + { 2546 + int rxtrig_bytes; 2547 + 2548 + mutex_lock(&port->mutex); 2549 + rxtrig_bytes = do_get_rxtrig(port); 2550 + mutex_unlock(&port->mutex); 2551 + 2552 + return rxtrig_bytes; 2553 + } 2554 + 2555 + static ssize_t serial8250_get_attr_rx_trig_bytes(struct device *dev, 2556 + struct device_attribute *attr, char *buf) 2557 + { 2558 + struct tty_port *port = dev_get_drvdata(dev); 2559 + int rxtrig_bytes; 2560 + 2561 + rxtrig_bytes = do_serial8250_get_rxtrig(port); 2562 + if (rxtrig_bytes < 0) 2563 + return rxtrig_bytes; 2564 + 2565 + return snprintf(buf, PAGE_SIZE, "%d\n", rxtrig_bytes); 2566 + } 2567 + 2568 + static int do_set_rxtrig(struct tty_port *port, unsigned char bytes) 2569 + { 2570 + struct uart_state *state = container_of(port, struct uart_state, port); 2571 + struct uart_port *uport = state->uart_port; 2572 + struct uart_8250_port *up = 2573 + container_of(uport, struct uart_8250_port, port); 2574 + int rxtrig; 2575 + 2576 + if (!(up->capabilities & UART_CAP_FIFO) || uport->fifosize <= 1 || 2577 + up->fifo_bug) 2578 + return -EINVAL; 2579 + 2580 + rxtrig = bytes_to_fcr_rxtrig(up, bytes); 2581 + if (rxtrig < 0) 2582 + return rxtrig; 2583 + 2584 + serial8250_clear_fifos(up); 2585 + up->fcr &= ~UART_FCR_TRIGGER_MASK; 2586 + up->fcr |= (unsigned char)rxtrig; 2587 + serial_out(up, UART_FCR, up->fcr); 2588 + return 0; 2589 + } 2590 + 2591 + static int do_serial8250_set_rxtrig(struct tty_port *port, unsigned char bytes) 2592 + { 2593 + int ret; 2594 + 2595 + mutex_lock(&port->mutex); 2596 + ret = do_set_rxtrig(port, bytes); 2597 + mutex_unlock(&port->mutex); 2598 + 2599 + return ret; 2600 + } 2601 + 2602 + static ssize_t serial8250_set_attr_rx_trig_bytes(struct device *dev, 2603 + struct device_attribute *attr, const char *buf, size_t count) 2604 + { 2605 + struct tty_port *port = dev_get_drvdata(dev); 2606 + unsigned char bytes; 2607 + int ret; 2608 + 2609 + if (!count) 2610 + return -EINVAL; 2611 + 2612 + ret = kstrtou8(buf, 10, &bytes); 2613 + if (ret < 0) 2614 + return ret; 2615 + 2616 + ret = do_serial8250_set_rxtrig(port, bytes); 2617 + if (ret < 0) 2618 + return ret; 2619 + 2620 + return count; 2621 + } 2622 + 2623 + static DEVICE_ATTR(rx_trig_bytes, S_IRUSR | S_IWUSR | S_IRGRP, 2624 + serial8250_get_attr_rx_trig_bytes, 2625 + serial8250_set_attr_rx_trig_bytes); 2626 + 2627 + static struct attribute *serial8250_dev_attrs[] = { 2628 + &dev_attr_rx_trig_bytes.attr, 2629 + NULL, 2630 + }; 2631 + 2632 + static struct attribute_group serial8250_dev_attr_group = { 2633 + .attrs = serial8250_dev_attrs, 2634 + }; 2635 + 2636 + static void register_dev_spec_attr_grp(struct uart_8250_port *up) 2637 + { 2638 + const struct serial8250_config *conf_type = &uart_config[up->port.type]; 2639 + 2640 + if (conf_type->rxtrig_bytes[0]) 2641 + up->port.attr_group = &serial8250_dev_attr_group; 2642 + } 2643 + 2644 + static void serial8250_config_port(struct uart_port *port, int flags) 2645 + { 2646 + struct uart_8250_port *up = up_to_u8250p(port); 2647 + int ret; 2648 + 2649 + if (port->type == PORT_8250_CIR) 2650 + return; 2651 + 2652 + /* 2653 + * Find the region that we can probe for. This in turn 2654 + * tells us whether we can probe for the type of port. 2655 + */ 2656 + ret = serial8250_request_std_resource(up); 2657 + if (ret < 0) 2658 + return; 2659 + 2660 + if (port->iotype != up->cur_iotype) 2661 + set_io_from_upio(port); 2662 + 2663 + if (flags & UART_CONFIG_TYPE) 2664 + autoconfig(up); 2665 + 2666 + /* if access method is AU, it is a 16550 with a quirk */ 2667 + if (port->type == PORT_16550A && port->iotype == UPIO_AU) 2668 + up->bugs |= UART_BUG_NOMSR; 2669 + 2670 + /* HW bugs may trigger IRQ while IIR == NO_INT */ 2671 + if (port->type == PORT_TEGRA) 2672 + up->bugs |= UART_BUG_NOMSR; 2673 + 2674 + if (port->type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) 2675 + autoconfig_irq(up); 2676 + 2677 + if (port->type == PORT_UNKNOWN) 2678 + serial8250_release_std_resource(up); 2679 + 2680 + /* Fixme: probably not the best place for this */ 2681 + if ((port->type == PORT_XR17V35X) || 2682 + (port->type == PORT_XR17D15X)) 2683 + port->handle_irq = exar_handle_irq; 2684 + 2685 + register_dev_spec_attr_grp(up); 2686 + up->fcr = uart_config[up->port.type].fcr; 2687 + } 2688 + 2689 + static int 2690 + serial8250_verify_port(struct uart_port *port, struct serial_struct *ser) 2691 + { 2692 + if (ser->irq >= nr_irqs || ser->irq < 0 || 2693 + ser->baud_base < 9600 || ser->type < PORT_UNKNOWN || 2694 + ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS || 2695 + ser->type == PORT_STARTECH) 2696 + return -EINVAL; 2697 + return 0; 2698 + } 2699 + 2700 + static const char * 2701 + serial8250_type(struct uart_port *port) 2702 + { 2703 + int type = port->type; 2704 + 2705 + if (type >= ARRAY_SIZE(uart_config)) 2706 + type = 0; 2707 + return uart_config[type].name; 2708 + } 2709 + 2710 + static const struct uart_ops serial8250_pops = { 2711 + .tx_empty = serial8250_tx_empty, 2712 + .set_mctrl = serial8250_set_mctrl, 2713 + .get_mctrl = serial8250_get_mctrl, 2714 + .stop_tx = serial8250_stop_tx, 2715 + .start_tx = serial8250_start_tx, 2716 + .throttle = serial8250_throttle, 2717 + .unthrottle = serial8250_unthrottle, 2718 + .stop_rx = serial8250_stop_rx, 2719 + .enable_ms = serial8250_enable_ms, 2720 + .break_ctl = serial8250_break_ctl, 2721 + .startup = serial8250_startup, 2722 + .shutdown = serial8250_shutdown, 2723 + .set_termios = serial8250_set_termios, 2724 + .set_ldisc = serial8250_set_ldisc, 2725 + .pm = serial8250_pm, 2726 + .type = serial8250_type, 2727 + .release_port = serial8250_release_port, 2728 + .request_port = serial8250_request_port, 2729 + .config_port = serial8250_config_port, 2730 + .verify_port = serial8250_verify_port, 2731 + #ifdef CONFIG_CONSOLE_POLL 2732 + .poll_get_char = serial8250_get_poll_char, 2733 + .poll_put_char = serial8250_put_poll_char, 2734 + #endif 2735 + }; 2736 + 2737 + void serial8250_init_port(struct uart_8250_port *up) 2738 + { 2739 + struct uart_port *port = &up->port; 2740 + 2741 + spin_lock_init(&port->lock); 2742 + port->ops = &serial8250_pops; 2743 + 2744 + up->cur_iotype = 0xFF; 2745 + } 2746 + EXPORT_SYMBOL_GPL(serial8250_init_port); 2747 + 2748 + void serial8250_set_defaults(struct uart_8250_port *up) 2749 + { 2750 + struct uart_port *port = &up->port; 2751 + 2752 + if (up->port.flags & UPF_FIXED_TYPE) { 2753 + unsigned int type = up->port.type; 2754 + 2755 + if (!up->port.fifosize) 2756 + up->port.fifosize = uart_config[type].fifo_size; 2757 + if (!up->tx_loadsz) 2758 + up->tx_loadsz = uart_config[type].tx_loadsz; 2759 + if (!up->capabilities) 2760 + up->capabilities = uart_config[type].flags; 2761 + } 2762 + 2763 + set_io_from_upio(port); 2764 + 2765 + /* default dma handlers */ 2766 + if (up->dma) { 2767 + if (!up->dma->tx_dma) 2768 + up->dma->tx_dma = serial8250_tx_dma; 2769 + if (!up->dma->rx_dma) 2770 + up->dma->rx_dma = serial8250_rx_dma; 2771 + } 2772 + } 2773 + EXPORT_SYMBOL_GPL(serial8250_set_defaults); 2774 + 2775 + #ifdef CONFIG_SERIAL_8250_CONSOLE 2776 + 2777 + static void serial8250_console_putchar(struct uart_port *port, int ch) 2778 + { 2779 + struct uart_8250_port *up = up_to_u8250p(port); 2780 + 2781 + wait_for_xmitr(up, UART_LSR_THRE); 2782 + serial_port_out(port, UART_TX, ch); 2783 + } 2784 + 2785 + /* 2786 + * Print a string to the serial port trying not to disturb 2787 + * any possible real use of the port... 2788 + * 2789 + * The console_lock must be held when we get here. 2790 + */ 2791 + void serial8250_console_write(struct uart_8250_port *up, const char *s, 2792 + unsigned int count) 2793 + { 2794 + struct uart_port *port = &up->port; 2795 + unsigned long flags; 2796 + unsigned int ier; 2797 + int locked = 1; 2798 + 2799 + touch_nmi_watchdog(); 2800 + 2801 + serial8250_rpm_get(up); 2802 + 2803 + if (port->sysrq) 2804 + locked = 0; 2805 + else if (oops_in_progress) 2806 + locked = spin_trylock_irqsave(&port->lock, flags); 2807 + else 2808 + spin_lock_irqsave(&port->lock, flags); 2809 + 2810 + /* 2811 + * First save the IER then disable the interrupts 2812 + */ 2813 + ier = serial_port_in(port, UART_IER); 2814 + 2815 + if (up->capabilities & UART_CAP_UUE) 2816 + serial_port_out(port, UART_IER, UART_IER_UUE); 2817 + else 2818 + serial_port_out(port, UART_IER, 0); 2819 + 2820 + /* check scratch reg to see if port powered off during system sleep */ 2821 + if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) { 2822 + struct ktermios termios; 2823 + unsigned int baud, quot, frac = 0; 2824 + 2825 + termios.c_cflag = port->cons->cflag; 2826 + if (port->state->port.tty && termios.c_cflag == 0) 2827 + termios.c_cflag = port->state->port.tty->termios.c_cflag; 2828 + 2829 + baud = uart_get_baud_rate(port, &termios, NULL, 2830 + port->uartclk / 16 / 0xffff, 2831 + port->uartclk / 16); 2832 + quot = serial8250_get_divisor(up, baud, &frac); 2833 + 2834 + serial8250_set_divisor(port, baud, quot, frac); 2835 + serial_port_out(port, UART_LCR, up->lcr); 2836 + serial_port_out(port, UART_MCR, UART_MCR_DTR | UART_MCR_RTS); 2837 + 2838 + up->canary = 0; 2839 + } 2840 + 2841 + uart_console_write(port, s, count, serial8250_console_putchar); 2842 + 2843 + /* 2844 + * Finally, wait for transmitter to become empty 2845 + * and restore the IER 2846 + */ 2847 + wait_for_xmitr(up, BOTH_EMPTY); 2848 + serial_port_out(port, UART_IER, ier); 2849 + 2850 + /* 2851 + * The receive handling will happen properly because the 2852 + * receive ready bit will still be set; it is not cleared 2853 + * on read. However, modem control will not, we must 2854 + * call it if we have saved something in the saved flags 2855 + * while processing with interrupts off. 2856 + */ 2857 + if (up->msr_saved_flags) 2858 + serial8250_modem_status(up); 2859 + 2860 + if (locked) 2861 + spin_unlock_irqrestore(&port->lock, flags); 2862 + serial8250_rpm_put(up); 2863 + } 2864 + 2865 + static unsigned int probe_baud(struct uart_port *port) 2866 + { 2867 + unsigned char lcr, dll, dlm; 2868 + unsigned int quot; 2869 + 2870 + lcr = serial_port_in(port, UART_LCR); 2871 + serial_port_out(port, UART_LCR, lcr | UART_LCR_DLAB); 2872 + dll = serial_port_in(port, UART_DLL); 2873 + dlm = serial_port_in(port, UART_DLM); 2874 + serial_port_out(port, UART_LCR, lcr); 2875 + 2876 + quot = (dlm << 8) | dll; 2877 + return (port->uartclk / 16) / quot; 2878 + } 2879 + 2880 + int serial8250_console_setup(struct uart_port *port, char *options, bool probe) 2881 + { 2882 + int baud = 9600; 2883 + int bits = 8; 2884 + int parity = 'n'; 2885 + int flow = 'n'; 2886 + 2887 + if (!port->iobase && !port->membase) 2888 + return -ENODEV; 2889 + 2890 + if (options) 2891 + uart_parse_options(options, &baud, &parity, &bits, &flow); 2892 + else if (probe) 2893 + baud = probe_baud(port); 2894 + 2895 + return uart_set_options(port, port->cons, baud, parity, bits, flow); 2896 + } 2897 + 2898 + #endif /* CONFIG_SERIAL_8250_CONSOLE */
+3 -2
drivers/tty/serial/8250/Makefile
··· 2 2 # Makefile for the 8250 serial device drivers. 3 3 # 4 4 5 - obj-$(CONFIG_SERIAL_8250) += 8250.o 5 + obj-$(CONFIG_SERIAL_8250) += 8250.o 8250_base.o 6 6 8250-y := 8250_core.o 7 7 8250-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o 8 - 8250-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o 8 + 8250_base-y := 8250_port.o 9 + 8250_base-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o 9 10 obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o 10 11 obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o 11 12 obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o
+5
include/linux/serial_8250.h
··· 152 152 unsigned char serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr); 153 153 void serial8250_tx_chars(struct uart_8250_port *up); 154 154 unsigned int serial8250_modem_status(struct uart_8250_port *up); 155 + void serial8250_init_port(struct uart_8250_port *up); 156 + void serial8250_set_defaults(struct uart_8250_port *up); 157 + void serial8250_console_write(struct uart_8250_port *up, const char *s, 158 + unsigned int count); 159 + int serial8250_console_setup(struct uart_port *port, char *options, bool probe); 155 160 156 161 extern void serial8250_set_isa_configurator(void (*v) 157 162 (int port, struct uart_port *up,