| .. | .. |
|---|
| 11 | 11 | * membase is an 'ioremapped' cookie. |
|---|
| 12 | 12 | */ |
|---|
| 13 | 13 | |
|---|
| 14 | | -#if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
|---|
| 15 | | -#define SUPPORT_SYSRQ |
|---|
| 16 | | -#endif |
|---|
| 17 | | - |
|---|
| 18 | 14 | #include <linux/module.h> |
|---|
| 19 | 15 | #include <linux/moduleparam.h> |
|---|
| 20 | 16 | #include <linux/ioport.h> |
|---|
| 21 | 17 | #include <linux/init.h> |
|---|
| 22 | 18 | #include <linux/console.h> |
|---|
| 19 | +#include <linux/gpio/consumer.h> |
|---|
| 23 | 20 | #include <linux/sysrq.h> |
|---|
| 24 | 21 | #include <linux/delay.h> |
|---|
| 25 | 22 | #include <linux/platform_device.h> |
|---|
| .. | .. |
|---|
| 40 | 37 | |
|---|
| 41 | 38 | #include "8250.h" |
|---|
| 42 | 39 | |
|---|
| 43 | | -/* |
|---|
| 44 | | - * These are definitions for the Exar XR17V35X and XR17(C|D)15X |
|---|
| 45 | | - */ |
|---|
| 46 | | -#define UART_EXAR_INT0 0x80 |
|---|
| 47 | | -#define UART_EXAR_SLEEP 0x8b /* Sleep mode */ |
|---|
| 48 | | -#define UART_EXAR_DVID 0x8d /* Device identification */ |
|---|
| 49 | | - |
|---|
| 50 | 40 | /* Nuvoton NPCM timeout register */ |
|---|
| 51 | 41 | #define UART_NPCM_TOR 7 |
|---|
| 52 | 42 | #define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */ |
|---|
| .. | .. |
|---|
| 66 | 56 | * Here we define the default xmit fifo size used for each type of UART. |
|---|
| 67 | 57 | */ |
|---|
| 68 | 58 | static const struct serial8250_config uart_config[] = { |
|---|
| 59 | +#ifndef CONFIG_ROCKCHIP_MINI_KERNEL |
|---|
| 69 | 60 | [PORT_UNKNOWN] = { |
|---|
| 70 | 61 | .name = "unknown", |
|---|
| 71 | 62 | .fifo_size = 1, |
|---|
| .. | .. |
|---|
| 86 | 77 | .fifo_size = 1, |
|---|
| 87 | 78 | .tx_loadsz = 1, |
|---|
| 88 | 79 | }, |
|---|
| 80 | +#endif |
|---|
| 89 | 81 | [PORT_16550A] = { |
|---|
| 90 | 82 | .name = "16550A", |
|---|
| 91 | 83 | .fifo_size = 16, |
|---|
| .. | .. |
|---|
| 94 | 86 | .rxtrig_bytes = {1, 4, 8, 14}, |
|---|
| 95 | 87 | .flags = UART_CAP_FIFO, |
|---|
| 96 | 88 | }, |
|---|
| 89 | +#ifndef CONFIG_ROCKCHIP_MINI_KERNEL |
|---|
| 97 | 90 | [PORT_CIRRUS] = { |
|---|
| 98 | 91 | .name = "Cirrus", |
|---|
| 99 | 92 | .fifo_size = 1, |
|---|
| .. | .. |
|---|
| 309 | 302 | .rxtrig_bytes = {1, 4, 8, 14}, |
|---|
| 310 | 303 | .flags = UART_CAP_FIFO, |
|---|
| 311 | 304 | }, |
|---|
| 305 | + [PORT_SUNIX] = { |
|---|
| 306 | + .name = "Sunix", |
|---|
| 307 | + .fifo_size = 128, |
|---|
| 308 | + .tx_loadsz = 128, |
|---|
| 309 | + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
|---|
| 310 | + .rxtrig_bytes = {1, 32, 64, 112}, |
|---|
| 311 | + .flags = UART_CAP_FIFO | UART_CAP_SLEEP, |
|---|
| 312 | + }, |
|---|
| 313 | +#endif |
|---|
| 312 | 314 | }; |
|---|
| 313 | 315 | |
|---|
| 314 | 316 | /* Uart divisor latch read */ |
|---|
| .. | .. |
|---|
| 386 | 388 | |
|---|
| 387 | 389 | #endif |
|---|
| 388 | 390 | |
|---|
| 391 | +#ifndef CONFIG_ROCKCHIP_MINI_KERNEL |
|---|
| 389 | 392 | static unsigned int hub6_serial_in(struct uart_port *p, int offset) |
|---|
| 390 | 393 | { |
|---|
| 391 | 394 | offset = offset << p->regshift; |
|---|
| .. | .. |
|---|
| 459 | 462 | offset = offset << p->regshift; |
|---|
| 460 | 463 | outb(value, p->iobase + offset); |
|---|
| 461 | 464 | } |
|---|
| 465 | +#endif |
|---|
| 462 | 466 | |
|---|
| 463 | 467 | static int serial8250_default_handle_irq(struct uart_port *port); |
|---|
| 464 | 468 | |
|---|
| .. | .. |
|---|
| 469 | 473 | up->dl_read = default_serial_dl_read; |
|---|
| 470 | 474 | up->dl_write = default_serial_dl_write; |
|---|
| 471 | 475 | |
|---|
| 476 | +#ifndef CONFIG_ROCKCHIP_MINI_KERNEL |
|---|
| 472 | 477 | switch (p->iotype) { |
|---|
| 473 | 478 | case UPIO_HUB6: |
|---|
| 474 | 479 | p->serial_in = hub6_serial_in; |
|---|
| .. | .. |
|---|
| 509 | 514 | p->serial_out = io_serial_out; |
|---|
| 510 | 515 | break; |
|---|
| 511 | 516 | } |
|---|
| 517 | +#endif |
|---|
| 512 | 518 | /* Remember loaded iotype */ |
|---|
| 513 | 519 | up->cur_iotype = p->iotype; |
|---|
| 514 | 520 | p->handle_irq = serial8250_default_handle_irq; |
|---|
| .. | .. |
|---|
| 532 | 538 | } |
|---|
| 533 | 539 | |
|---|
| 534 | 540 | /* |
|---|
| 535 | | - * For the 16C950 |
|---|
| 536 | | - */ |
|---|
| 537 | | -static void serial_icr_write(struct uart_8250_port *up, int offset, int value) |
|---|
| 538 | | -{ |
|---|
| 539 | | - serial_out(up, UART_SCR, offset); |
|---|
| 540 | | - serial_out(up, UART_ICR, value); |
|---|
| 541 | | -} |
|---|
| 542 | | - |
|---|
| 543 | | -static unsigned int serial_icr_read(struct uart_8250_port *up, int offset) |
|---|
| 544 | | -{ |
|---|
| 545 | | - unsigned int value; |
|---|
| 546 | | - |
|---|
| 547 | | - serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); |
|---|
| 548 | | - serial_out(up, UART_SCR, offset); |
|---|
| 549 | | - value = serial_in(up, UART_ICR); |
|---|
| 550 | | - serial_icr_write(up, UART_ACR, up->acr); |
|---|
| 551 | | - |
|---|
| 552 | | - return value; |
|---|
| 553 | | -} |
|---|
| 554 | | - |
|---|
| 555 | | -/* |
|---|
| 556 | 541 | * FIFO support. |
|---|
| 557 | 542 | */ |
|---|
| 558 | 543 | static void serial8250_clear_fifos(struct uart_8250_port *p) |
|---|
| .. | .. |
|---|
| 563 | 548 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
|---|
| 564 | 549 | serial_out(p, UART_FCR, 0); |
|---|
| 565 | 550 | } |
|---|
| 566 | | -} |
|---|
| 567 | | - |
|---|
| 568 | | -static inline void serial8250_em485_rts_after_send(struct uart_8250_port *p) |
|---|
| 569 | | -{ |
|---|
| 570 | | - unsigned char mcr = serial8250_in_MCR(p); |
|---|
| 571 | | - |
|---|
| 572 | | - if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND) |
|---|
| 573 | | - mcr |= UART_MCR_RTS; |
|---|
| 574 | | - else |
|---|
| 575 | | - mcr &= ~UART_MCR_RTS; |
|---|
| 576 | | - serial8250_out_MCR(p, mcr); |
|---|
| 577 | 551 | } |
|---|
| 578 | 552 | |
|---|
| 579 | 553 | static enum hrtimer_restart serial8250_em485_handle_start_tx(struct hrtimer *t); |
|---|
| .. | .. |
|---|
| 623 | 597 | * |
|---|
| 624 | 598 | * Return 0 - success, -errno - otherwise |
|---|
| 625 | 599 | */ |
|---|
| 626 | | -int serial8250_em485_init(struct uart_8250_port *p) |
|---|
| 600 | +static int serial8250_em485_init(struct uart_8250_port *p) |
|---|
| 627 | 601 | { |
|---|
| 628 | 602 | if (p->em485) |
|---|
| 629 | | - return 0; |
|---|
| 603 | + goto deassert_rts; |
|---|
| 630 | 604 | |
|---|
| 631 | 605 | p->em485 = kmalloc(sizeof(struct uart_8250_em485), GFP_ATOMIC); |
|---|
| 632 | 606 | if (!p->em485) |
|---|
| .. | .. |
|---|
| 640 | 614 | p->em485->start_tx_timer.function = &serial8250_em485_handle_start_tx; |
|---|
| 641 | 615 | p->em485->port = p; |
|---|
| 642 | 616 | p->em485->active_timer = NULL; |
|---|
| 643 | | - serial8250_em485_rts_after_send(p); |
|---|
| 617 | + p->em485->tx_stopped = true; |
|---|
| 618 | + |
|---|
| 619 | +deassert_rts: |
|---|
| 620 | + if (p->em485->tx_stopped) |
|---|
| 621 | + p->rs485_stop_tx(p); |
|---|
| 644 | 622 | |
|---|
| 645 | 623 | return 0; |
|---|
| 646 | 624 | } |
|---|
| 647 | | -EXPORT_SYMBOL_GPL(serial8250_em485_init); |
|---|
| 648 | 625 | |
|---|
| 649 | 626 | /** |
|---|
| 650 | 627 | * serial8250_em485_destroy() - put uart_8250_port into normal state |
|---|
| .. | .. |
|---|
| 671 | 648 | p->em485 = NULL; |
|---|
| 672 | 649 | } |
|---|
| 673 | 650 | EXPORT_SYMBOL_GPL(serial8250_em485_destroy); |
|---|
| 651 | + |
|---|
| 652 | +/** |
|---|
| 653 | + * serial8250_em485_config() - generic ->rs485_config() callback |
|---|
| 654 | + * @port: uart port |
|---|
| 655 | + * @rs485: rs485 settings |
|---|
| 656 | + * |
|---|
| 657 | + * Generic callback usable by 8250 uart drivers to activate rs485 settings |
|---|
| 658 | + * if the uart is incapable of driving RTS as a Transmit Enable signal in |
|---|
| 659 | + * hardware, relying on software emulation instead. |
|---|
| 660 | + */ |
|---|
| 661 | +int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485) |
|---|
| 662 | +{ |
|---|
| 663 | + struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 664 | + |
|---|
| 665 | + /* pick sane settings if the user hasn't */ |
|---|
| 666 | + if (!!(rs485->flags & SER_RS485_RTS_ON_SEND) == |
|---|
| 667 | + !!(rs485->flags & SER_RS485_RTS_AFTER_SEND)) { |
|---|
| 668 | + rs485->flags |= SER_RS485_RTS_ON_SEND; |
|---|
| 669 | + rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; |
|---|
| 670 | + } |
|---|
| 671 | + |
|---|
| 672 | + gpiod_set_value(port->rs485_term_gpio, |
|---|
| 673 | + rs485->flags & SER_RS485_TERMINATE_BUS); |
|---|
| 674 | + |
|---|
| 675 | + /* |
|---|
| 676 | + * Both serial8250_em485_init() and serial8250_em485_destroy() |
|---|
| 677 | + * are idempotent. |
|---|
| 678 | + */ |
|---|
| 679 | + if (rs485->flags & SER_RS485_ENABLED) |
|---|
| 680 | + return serial8250_em485_init(up); |
|---|
| 681 | + |
|---|
| 682 | + serial8250_em485_destroy(up); |
|---|
| 683 | + return 0; |
|---|
| 684 | +} |
|---|
| 685 | +EXPORT_SYMBOL_GPL(serial8250_em485_config); |
|---|
| 674 | 686 | |
|---|
| 675 | 687 | /* |
|---|
| 676 | 688 | * These two wrappers ensure that enable_runtime_pm_tx() can be called more than |
|---|
| .. | .. |
|---|
| 714 | 726 | static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) |
|---|
| 715 | 727 | { |
|---|
| 716 | 728 | unsigned char lcr = 0, efr = 0; |
|---|
| 717 | | - /* |
|---|
| 718 | | - * Exar UARTs have a SLEEP register that enables or disables |
|---|
| 719 | | - * each UART to enter sleep mode separately. On the XR17V35x the |
|---|
| 720 | | - * register is accessible to each UART at the UART_EXAR_SLEEP |
|---|
| 721 | | - * offset but the UART channel may only write to the corresponding |
|---|
| 722 | | - * bit. |
|---|
| 723 | | - */ |
|---|
| 729 | + |
|---|
| 724 | 730 | serial8250_rpm_get(p); |
|---|
| 725 | | - if ((p->port.type == PORT_XR17V35X) || |
|---|
| 726 | | - (p->port.type == PORT_XR17D15X)) { |
|---|
| 727 | | - serial_out(p, UART_EXAR_SLEEP, sleep ? 0xff : 0); |
|---|
| 728 | | - goto out; |
|---|
| 729 | | - } |
|---|
| 730 | 731 | |
|---|
| 731 | 732 | if (p->capabilities & UART_CAP_SLEEP) { |
|---|
| 732 | 733 | if (p->capabilities & UART_CAP_EFR) { |
|---|
| .. | .. |
|---|
| 736 | 737 | serial_out(p, UART_EFR, UART_EFR_ECB); |
|---|
| 737 | 738 | serial_out(p, UART_LCR, 0); |
|---|
| 738 | 739 | } |
|---|
| 739 | | - serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); |
|---|
| 740 | + serial8250_set_IER(p, sleep ? UART_IERX_SLEEP : 0); |
|---|
| 740 | 741 | if (p->capabilities & UART_CAP_EFR) { |
|---|
| 741 | 742 | serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); |
|---|
| 742 | 743 | serial_out(p, UART_EFR, efr); |
|---|
| 743 | 744 | serial_out(p, UART_LCR, lcr); |
|---|
| 744 | 745 | } |
|---|
| 745 | 746 | } |
|---|
| 746 | | -out: |
|---|
| 747 | + |
|---|
| 747 | 748 | serial8250_rpm_put(p); |
|---|
| 748 | 749 | } |
|---|
| 749 | 750 | |
|---|
| .. | .. |
|---|
| 1016 | 1017 | up->port.type = PORT_16550A; |
|---|
| 1017 | 1018 | up->capabilities |= UART_CAP_FIFO; |
|---|
| 1018 | 1019 | |
|---|
| 1019 | | - /* |
|---|
| 1020 | | - * XR17V35x UARTs have an extra divisor register, DLD |
|---|
| 1021 | | - * that gets enabled with when DLAB is set which will |
|---|
| 1022 | | - * cause the device to incorrectly match and assign |
|---|
| 1023 | | - * port type to PORT_16650. The EFR for this UART is |
|---|
| 1024 | | - * found at offset 0x09. Instead check the Deice ID (DVID) |
|---|
| 1025 | | - * register for a 2, 4 or 8 port UART. |
|---|
| 1026 | | - */ |
|---|
| 1027 | | - if (up->port.flags & UPF_EXAR_EFR) { |
|---|
| 1028 | | - status1 = serial_in(up, UART_EXAR_DVID); |
|---|
| 1029 | | - if (status1 == 0x82 || status1 == 0x84 || status1 == 0x88) { |
|---|
| 1030 | | - DEBUG_AUTOCONF("Exar XR17V35x "); |
|---|
| 1031 | | - up->port.type = PORT_XR17V35X; |
|---|
| 1032 | | - up->capabilities |= UART_CAP_AFE | UART_CAP_EFR | |
|---|
| 1033 | | - UART_CAP_SLEEP; |
|---|
| 1034 | | - |
|---|
| 1035 | | - return; |
|---|
| 1036 | | - } |
|---|
| 1037 | | - |
|---|
| 1038 | | - } |
|---|
| 1020 | + if (!IS_ENABLED(CONFIG_SERIAL_8250_16550A_VARIANTS)) |
|---|
| 1021 | + return; |
|---|
| 1039 | 1022 | |
|---|
| 1040 | 1023 | /* |
|---|
| 1041 | 1024 | * Check for presence of the EFR when DLAB is set. |
|---|
| .. | .. |
|---|
| 1174 | 1157 | DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); |
|---|
| 1175 | 1158 | } |
|---|
| 1176 | 1159 | serial_out(up, UART_IER, iersave); |
|---|
| 1177 | | - |
|---|
| 1178 | | - /* |
|---|
| 1179 | | - * Exar uarts have EFR in a weird location |
|---|
| 1180 | | - */ |
|---|
| 1181 | | - if (up->port.flags & UPF_EXAR_EFR) { |
|---|
| 1182 | | - DEBUG_AUTOCONF("Exar XR17D15x "); |
|---|
| 1183 | | - up->port.type = PORT_XR17D15X; |
|---|
| 1184 | | - up->capabilities |= UART_CAP_AFE | UART_CAP_EFR | |
|---|
| 1185 | | - UART_CAP_SLEEP; |
|---|
| 1186 | | - |
|---|
| 1187 | | - return; |
|---|
| 1188 | | - } |
|---|
| 1189 | 1160 | |
|---|
| 1190 | 1161 | /* |
|---|
| 1191 | 1162 | * We distinguish between 16550A and U6 16550A by counting |
|---|
| .. | .. |
|---|
| 1369 | 1340 | fintek_8250_probe(up); |
|---|
| 1370 | 1341 | |
|---|
| 1371 | 1342 | if (up->capabilities != old_capabilities) { |
|---|
| 1372 | | - pr_warn("%s: detected caps %08x should be %08x\n", |
|---|
| 1373 | | - port->name, old_capabilities, up->capabilities); |
|---|
| 1343 | + dev_warn(port->dev, "detected caps %08x should be %08x\n", |
|---|
| 1344 | + old_capabilities, up->capabilities); |
|---|
| 1374 | 1345 | } |
|---|
| 1375 | 1346 | out: |
|---|
| 1376 | 1347 | DEBUG_AUTOCONF("iir=%d ", scratch); |
|---|
| .. | .. |
|---|
| 1440 | 1411 | |
|---|
| 1441 | 1412 | up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); |
|---|
| 1442 | 1413 | up->port.read_status_mask &= ~UART_LSR_DR; |
|---|
| 1443 | | - serial_port_out(port, UART_IER, up->ier); |
|---|
| 1414 | + serial8250_set_IER(up, up->ier); |
|---|
| 1444 | 1415 | |
|---|
| 1445 | 1416 | serial8250_rpm_put(up); |
|---|
| 1446 | 1417 | } |
|---|
| 1447 | 1418 | |
|---|
| 1448 | | -static void __do_stop_tx_rs485(struct uart_8250_port *p) |
|---|
| 1419 | +/** |
|---|
| 1420 | + * serial8250_em485_stop_tx() - generic ->rs485_stop_tx() callback |
|---|
| 1421 | + * @p: uart 8250 port |
|---|
| 1422 | + * |
|---|
| 1423 | + * Generic callback usable by 8250 uart drivers to stop rs485 transmission. |
|---|
| 1424 | + */ |
|---|
| 1425 | +void serial8250_em485_stop_tx(struct uart_8250_port *p) |
|---|
| 1449 | 1426 | { |
|---|
| 1450 | | - serial8250_em485_rts_after_send(p); |
|---|
| 1427 | + unsigned char mcr = serial8250_in_MCR(p); |
|---|
| 1428 | + |
|---|
| 1429 | + if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND) |
|---|
| 1430 | + mcr |= UART_MCR_RTS; |
|---|
| 1431 | + else |
|---|
| 1432 | + mcr &= ~UART_MCR_RTS; |
|---|
| 1433 | + serial8250_out_MCR(p, mcr); |
|---|
| 1451 | 1434 | |
|---|
| 1452 | 1435 | /* |
|---|
| 1453 | 1436 | * Empty the RX FIFO, we are not interested in anything |
|---|
| .. | .. |
|---|
| 1458 | 1441 | serial8250_clear_and_reinit_fifos(p); |
|---|
| 1459 | 1442 | |
|---|
| 1460 | 1443 | p->ier |= UART_IER_RLSI | UART_IER_RDI; |
|---|
| 1461 | | - serial_port_out(&p->port, UART_IER, p->ier); |
|---|
| 1444 | + serial8250_set_IER(p, p->ier); |
|---|
| 1462 | 1445 | } |
|---|
| 1463 | 1446 | } |
|---|
| 1447 | +EXPORT_SYMBOL_GPL(serial8250_em485_stop_tx); |
|---|
| 1448 | + |
|---|
| 1464 | 1449 | static enum hrtimer_restart serial8250_em485_handle_stop_tx(struct hrtimer *t) |
|---|
| 1465 | 1450 | { |
|---|
| 1466 | 1451 | struct uart_8250_em485 *em485; |
|---|
| .. | .. |
|---|
| 1473 | 1458 | serial8250_rpm_get(p); |
|---|
| 1474 | 1459 | spin_lock_irqsave(&p->port.lock, flags); |
|---|
| 1475 | 1460 | if (em485->active_timer == &em485->stop_tx_timer) { |
|---|
| 1476 | | - __do_stop_tx_rs485(p); |
|---|
| 1461 | + p->rs485_stop_tx(p); |
|---|
| 1477 | 1462 | em485->active_timer = NULL; |
|---|
| 1463 | + em485->tx_stopped = true; |
|---|
| 1478 | 1464 | } |
|---|
| 1479 | 1465 | spin_unlock_irqrestore(&p->port.lock, flags); |
|---|
| 1480 | 1466 | serial8250_rpm_put(p); |
|---|
| .. | .. |
|---|
| 1495 | 1481 | struct uart_8250_em485 *em485 = p->em485; |
|---|
| 1496 | 1482 | |
|---|
| 1497 | 1483 | /* |
|---|
| 1498 | | - * __do_stop_tx_rs485 is going to set RTS according to config |
|---|
| 1484 | + * rs485_stop_tx() is going to set RTS according to config |
|---|
| 1499 | 1485 | * AND flush RX FIFO if required. |
|---|
| 1500 | 1486 | */ |
|---|
| 1501 | 1487 | if (p->port.rs485.delay_rts_after_send > 0) { |
|---|
| .. | .. |
|---|
| 1503 | 1489 | start_hrtimer_ms(&em485->stop_tx_timer, |
|---|
| 1504 | 1490 | p->port.rs485.delay_rts_after_send); |
|---|
| 1505 | 1491 | } else { |
|---|
| 1506 | | - __do_stop_tx_rs485(p); |
|---|
| 1492 | + p->rs485_stop_tx(p); |
|---|
| 1493 | + em485->active_timer = NULL; |
|---|
| 1494 | + em485->tx_stopped = true; |
|---|
| 1507 | 1495 | } |
|---|
| 1508 | 1496 | } |
|---|
| 1509 | 1497 | |
|---|
| 1510 | 1498 | static inline void __do_stop_tx(struct uart_8250_port *p) |
|---|
| 1511 | 1499 | { |
|---|
| 1512 | | - if (p->ier & UART_IER_THRI) { |
|---|
| 1513 | | - p->ier &= ~UART_IER_THRI; |
|---|
| 1514 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 1515 | | - p->ier &= ~UART_IER_PTIME; |
|---|
| 1516 | | -#endif |
|---|
| 1517 | | - serial_out(p, UART_IER, p->ier); |
|---|
| 1500 | + if (serial8250_clear_THRI(p)) |
|---|
| 1518 | 1501 | serial8250_rpm_put_tx(p); |
|---|
| 1519 | | - } |
|---|
| 1520 | 1502 | } |
|---|
| 1521 | 1503 | |
|---|
| 1522 | 1504 | static inline void __stop_tx(struct uart_8250_port *p) |
|---|
| .. | .. |
|---|
| 1525 | 1507 | |
|---|
| 1526 | 1508 | if (em485) { |
|---|
| 1527 | 1509 | unsigned char lsr = serial_in(p, UART_LSR); |
|---|
| 1510 | + p->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
|---|
| 1511 | + |
|---|
| 1528 | 1512 | /* |
|---|
| 1529 | 1513 | * To provide required timeing and allow FIFO transfer, |
|---|
| 1530 | 1514 | * __stop_tx_rs485() must be called only when both FIFO and |
|---|
| .. | .. |
|---|
| 1533 | 1517 | */ |
|---|
| 1534 | 1518 | if ((lsr & BOTH_EMPTY) != BOTH_EMPTY) |
|---|
| 1535 | 1519 | return; |
|---|
| 1536 | | - |
|---|
| 1537 | | - em485->active_timer = NULL; |
|---|
| 1538 | 1520 | |
|---|
| 1539 | 1521 | __stop_tx_rs485(p); |
|---|
| 1540 | 1522 | } |
|---|
| .. | .. |
|---|
| 1570 | 1552 | return; |
|---|
| 1571 | 1553 | #endif |
|---|
| 1572 | 1554 | |
|---|
| 1573 | | - if (!(up->ier & UART_IER_THRI)) { |
|---|
| 1574 | | - up->ier |= UART_IER_THRI; |
|---|
| 1575 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 1576 | | - up->ier |= UART_IER_PTIME; |
|---|
| 1577 | | -#endif |
|---|
| 1578 | | - serial_port_out(port, UART_IER, up->ier); |
|---|
| 1579 | | - |
|---|
| 1555 | + if (serial8250_set_THRI(up)) { |
|---|
| 1580 | 1556 | if (up->bugs & UART_BUG_TXEN) { |
|---|
| 1581 | 1557 | unsigned char lsr; |
|---|
| 1582 | 1558 | |
|---|
| .. | .. |
|---|
| 1596 | 1572 | } |
|---|
| 1597 | 1573 | } |
|---|
| 1598 | 1574 | |
|---|
| 1599 | | -static inline void start_tx_rs485(struct uart_port *port) |
|---|
| 1575 | +/** |
|---|
| 1576 | + * serial8250_em485_start_tx() - generic ->rs485_start_tx() callback |
|---|
| 1577 | + * @up: uart 8250 port |
|---|
| 1578 | + * |
|---|
| 1579 | + * Generic callback usable by 8250 uart drivers to start rs485 transmission. |
|---|
| 1580 | + * Assumes that setting the RTS bit in the MCR register means RTS is high. |
|---|
| 1581 | + * (Some chips use inverse semantics.) Further assumes that reception is |
|---|
| 1582 | + * stoppable by disabling the UART_IER_RDI interrupt. (Some chips set the |
|---|
| 1583 | + * UART_LSR_DR bit even when UART_IER_RDI is disabled, foiling this approach.) |
|---|
| 1584 | + */ |
|---|
| 1585 | +void serial8250_em485_start_tx(struct uart_8250_port *up) |
|---|
| 1600 | 1586 | { |
|---|
| 1601 | | - struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 1602 | | - struct uart_8250_em485 *em485 = up->em485; |
|---|
| 1603 | | - unsigned char mcr; |
|---|
| 1587 | + unsigned char mcr = serial8250_in_MCR(up); |
|---|
| 1604 | 1588 | |
|---|
| 1605 | 1589 | if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) |
|---|
| 1606 | 1590 | serial8250_stop_rx(&up->port); |
|---|
| 1607 | 1591 | |
|---|
| 1592 | + if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) |
|---|
| 1593 | + mcr |= UART_MCR_RTS; |
|---|
| 1594 | + else |
|---|
| 1595 | + mcr &= ~UART_MCR_RTS; |
|---|
| 1596 | + serial8250_out_MCR(up, mcr); |
|---|
| 1597 | +} |
|---|
| 1598 | +EXPORT_SYMBOL_GPL(serial8250_em485_start_tx); |
|---|
| 1599 | + |
|---|
| 1600 | +static inline void start_tx_rs485(struct uart_port *port) |
|---|
| 1601 | +{ |
|---|
| 1602 | + struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 1603 | + struct uart_8250_em485 *em485 = up->em485; |
|---|
| 1604 | + |
|---|
| 1605 | + /* |
|---|
| 1606 | + * While serial8250_em485_handle_stop_tx() is a noop if |
|---|
| 1607 | + * em485->active_timer != &em485->stop_tx_timer, it might happen that |
|---|
| 1608 | + * the timer is still armed and triggers only after the current bunch of |
|---|
| 1609 | + * chars is send and em485->active_timer == &em485->stop_tx_timer again. |
|---|
| 1610 | + * So cancel the timer. There is still a theoretical race condition if |
|---|
| 1611 | + * the timer is already running and only comes around to check for |
|---|
| 1612 | + * em485->active_timer when &em485->stop_tx_timer is armed again. |
|---|
| 1613 | + */ |
|---|
| 1614 | + if (em485->active_timer == &em485->stop_tx_timer) |
|---|
| 1615 | + hrtimer_try_to_cancel(&em485->stop_tx_timer); |
|---|
| 1616 | + |
|---|
| 1608 | 1617 | em485->active_timer = NULL; |
|---|
| 1609 | 1618 | |
|---|
| 1610 | | - mcr = serial8250_in_MCR(up); |
|---|
| 1611 | | - if (!!(up->port.rs485.flags & SER_RS485_RTS_ON_SEND) != |
|---|
| 1612 | | - !!(mcr & UART_MCR_RTS)) { |
|---|
| 1613 | | - if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) |
|---|
| 1614 | | - mcr |= UART_MCR_RTS; |
|---|
| 1615 | | - else |
|---|
| 1616 | | - mcr &= ~UART_MCR_RTS; |
|---|
| 1617 | | - serial8250_out_MCR(up, mcr); |
|---|
| 1619 | + if (em485->tx_stopped) { |
|---|
| 1620 | + em485->tx_stopped = false; |
|---|
| 1621 | + |
|---|
| 1622 | + up->rs485_start_tx(up); |
|---|
| 1618 | 1623 | |
|---|
| 1619 | 1624 | if (up->port.rs485.delay_rts_before_send > 0) { |
|---|
| 1620 | 1625 | em485->active_timer = &em485->start_tx_timer; |
|---|
| .. | .. |
|---|
| 1680 | 1685 | if (up->bugs & UART_BUG_NOMSR) |
|---|
| 1681 | 1686 | return; |
|---|
| 1682 | 1687 | |
|---|
| 1688 | + mctrl_gpio_disable_ms(up->gpios); |
|---|
| 1689 | + |
|---|
| 1683 | 1690 | up->ier &= ~UART_IER_MSI; |
|---|
| 1684 | | - serial_port_out(port, UART_IER, up->ier); |
|---|
| 1691 | + serial8250_set_IER(up, up->ier); |
|---|
| 1685 | 1692 | } |
|---|
| 1686 | 1693 | |
|---|
| 1687 | 1694 | static void serial8250_enable_ms(struct uart_port *port) |
|---|
| .. | .. |
|---|
| 1692 | 1699 | if (up->bugs & UART_BUG_NOMSR) |
|---|
| 1693 | 1700 | return; |
|---|
| 1694 | 1701 | |
|---|
| 1702 | + mctrl_gpio_enable_ms(up->gpios); |
|---|
| 1703 | + |
|---|
| 1695 | 1704 | up->ier |= UART_IER_MSI; |
|---|
| 1696 | 1705 | |
|---|
| 1697 | 1706 | serial8250_rpm_get(up); |
|---|
| 1698 | | - serial_port_out(port, UART_IER, up->ier); |
|---|
| 1707 | + serial8250_set_IER(up, up->ier); |
|---|
| 1699 | 1708 | serial8250_rpm_put(up); |
|---|
| 1700 | 1709 | } |
|---|
| 1701 | 1710 | |
|---|
| .. | .. |
|---|
| 1747 | 1756 | lsr &= port->read_status_mask; |
|---|
| 1748 | 1757 | |
|---|
| 1749 | 1758 | if (lsr & UART_LSR_BI) { |
|---|
| 1750 | | - pr_debug("%s: handling break\n", __func__); |
|---|
| 1759 | + dev_dbg(port->dev, "handling break\n"); |
|---|
| 1751 | 1760 | flag = TTY_BREAK; |
|---|
| 1752 | 1761 | } else if (lsr & UART_LSR_PE) |
|---|
| 1753 | 1762 | flag = TTY_PARITY; |
|---|
| 1754 | 1763 | else if (lsr & UART_LSR_FE) |
|---|
| 1755 | 1764 | flag = TTY_FRAME; |
|---|
| 1756 | 1765 | } |
|---|
| 1757 | | - if (uart_handle_sysrq_char(port, ch)) |
|---|
| 1766 | + if (uart_prepare_sysrq_char(port, ch)) |
|---|
| 1758 | 1767 | return; |
|---|
| 1759 | 1768 | |
|---|
| 1760 | 1769 | uart_insert_char(port, lsr, UART_LSR_OE, ch, flag); |
|---|
| .. | .. |
|---|
| 1790 | 1799 | int count; |
|---|
| 1791 | 1800 | |
|---|
| 1792 | 1801 | if (port->x_char) { |
|---|
| 1793 | | - serial_out(up, UART_TX, port->x_char); |
|---|
| 1794 | | - port->icount.tx++; |
|---|
| 1795 | | - port->x_char = 0; |
|---|
| 1802 | + uart_xchar_out(port, UART_TX); |
|---|
| 1796 | 1803 | return; |
|---|
| 1797 | 1804 | } |
|---|
| 1798 | 1805 | if (uart_tx_stopped(port)) { |
|---|
| .. | .. |
|---|
| 1807 | 1814 | count = up->tx_loadsz; |
|---|
| 1808 | 1815 | do { |
|---|
| 1809 | 1816 | serial_out(up, UART_TX, xmit->buf[xmit->tail]); |
|---|
| 1817 | + if (up->bugs & UART_BUG_TXRACE) { |
|---|
| 1818 | + /* |
|---|
| 1819 | + * The Aspeed BMC virtual UARTs have a bug where data |
|---|
| 1820 | + * may get stuck in the BMC's Tx FIFO from bursts of |
|---|
| 1821 | + * writes on the APB interface. |
|---|
| 1822 | + * |
|---|
| 1823 | + * Delay back-to-back writes by a read cycle to avoid |
|---|
| 1824 | + * stalling the VUART. Read a register that won't have |
|---|
| 1825 | + * side-effects and discard the result. |
|---|
| 1826 | + */ |
|---|
| 1827 | + serial_in(up, UART_SCR); |
|---|
| 1828 | + } |
|---|
| 1810 | 1829 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
|---|
| 1811 | 1830 | port->icount.tx++; |
|---|
| 1812 | 1831 | if (uart_circ_empty(xmit)) |
|---|
| .. | .. |
|---|
| 1868 | 1887 | return up->dma->rx_dma(up); |
|---|
| 1869 | 1888 | #else |
|---|
| 1870 | 1889 | switch (iir & 0x3f) { |
|---|
| 1890 | + case UART_IIR_RDI: |
|---|
| 1891 | + if (!up->dma->rx_running) |
|---|
| 1892 | + break; |
|---|
| 1893 | + fallthrough; |
|---|
| 1894 | + case UART_IIR_RLSI: |
|---|
| 1871 | 1895 | case UART_IIR_RX_TIMEOUT: |
|---|
| 1872 | 1896 | serial8250_rx_dma_flush(up); |
|---|
| 1873 | | - /* fall-through */ |
|---|
| 1874 | | - case UART_IIR_RLSI: |
|---|
| 1875 | 1897 | return true; |
|---|
| 1876 | 1898 | } |
|---|
| 1877 | 1899 | return up->dma->rx_dma(up); |
|---|
| .. | .. |
|---|
| 1886 | 1908 | unsigned char status; |
|---|
| 1887 | 1909 | unsigned long flags; |
|---|
| 1888 | 1910 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 1911 | +#ifndef CONFIG_ARCH_ROCKCHIP |
|---|
| 1889 | 1912 | bool skip_rx = false; |
|---|
| 1913 | +#endif |
|---|
| 1890 | 1914 | |
|---|
| 1891 | 1915 | if (iir & UART_IIR_NO_INT) |
|---|
| 1892 | 1916 | return 0; |
|---|
| .. | .. |
|---|
| 1895 | 1919 | |
|---|
| 1896 | 1920 | status = serial_port_in(port, UART_LSR); |
|---|
| 1897 | 1921 | |
|---|
| 1922 | +#ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 1923 | + if (status & (UART_LSR_DR | UART_LSR_BI)) { |
|---|
| 1924 | + int dma_err = -1; |
|---|
| 1925 | + |
|---|
| 1926 | + if (up->dma && up->dma->rxchan) |
|---|
| 1927 | + dma_err = handle_rx_dma(up, iir); |
|---|
| 1928 | + |
|---|
| 1929 | + if (!up->dma || dma_err) |
|---|
| 1930 | + status = serial8250_rx_chars(up, status); |
|---|
| 1931 | + } |
|---|
| 1932 | +#else |
|---|
| 1898 | 1933 | /* |
|---|
| 1899 | 1934 | * If port is stopped and there are no error conditions in the |
|---|
| 1900 | 1935 | * FIFO, then don't drain the FIFO, as this may lead to TTY buffer |
|---|
| .. | .. |
|---|
| 1909 | 1944 | skip_rx = true; |
|---|
| 1910 | 1945 | |
|---|
| 1911 | 1946 | if (status & (UART_LSR_DR | UART_LSR_BI) && !skip_rx) { |
|---|
| 1912 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 1913 | | - int dma_err = -1; |
|---|
| 1914 | | - |
|---|
| 1915 | | - if (up->dma && up->dma->rxchan) |
|---|
| 1916 | | - dma_err = handle_rx_dma(up, iir); |
|---|
| 1917 | | - |
|---|
| 1918 | | - if (!up->dma || dma_err) |
|---|
| 1919 | | - status = serial8250_rx_chars(up, status); |
|---|
| 1920 | | -#else |
|---|
| 1921 | 1947 | if (!up->dma || handle_rx_dma(up, iir)) |
|---|
| 1922 | 1948 | status = serial8250_rx_chars(up, status); |
|---|
| 1923 | | -#endif |
|---|
| 1924 | 1949 | } |
|---|
| 1950 | +#endif |
|---|
| 1925 | 1951 | serial8250_modem_status(up); |
|---|
| 1926 | 1952 | #ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 1927 | 1953 | if ((!up->dma || (up->dma && (!up->dma->txchan || up->dma->tx_err))) && |
|---|
| 1928 | 1954 | ((iir & 0xf) == UART_IIR_THRI)) |
|---|
| 1929 | 1955 | serial8250_tx_chars(up); |
|---|
| 1930 | 1956 | #else |
|---|
| 1931 | | - if ((!up->dma || up->dma->tx_err) && (status & UART_LSR_THRE) && |
|---|
| 1932 | | - (up->ier & UART_IER_THRI)) |
|---|
| 1957 | + if ((!up->dma || (up->dma && up->dma->tx_err)) && |
|---|
| 1958 | + (status & UART_LSR_THRE)) |
|---|
| 1933 | 1959 | serial8250_tx_chars(up); |
|---|
| 1934 | 1960 | #endif |
|---|
| 1935 | 1961 | |
|---|
| .. | .. |
|---|
| 1949 | 1975 | port->name); |
|---|
| 1950 | 1976 | } |
|---|
| 1951 | 1977 | #endif |
|---|
| 1952 | | - spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 1978 | + uart_unlock_and_check_sysrq(port, flags); |
|---|
| 1953 | 1979 | return 1; |
|---|
| 1954 | 1980 | } |
|---|
| 1955 | 1981 | EXPORT_SYMBOL_GPL(serial8250_handle_irq); |
|---|
| .. | .. |
|---|
| 2015 | 2041 | { |
|---|
| 2016 | 2042 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 2017 | 2043 | unsigned int status; |
|---|
| 2018 | | - unsigned int ret; |
|---|
| 2044 | + unsigned int val; |
|---|
| 2019 | 2045 | |
|---|
| 2020 | 2046 | serial8250_rpm_get(up); |
|---|
| 2021 | 2047 | status = serial8250_modem_status(up); |
|---|
| 2022 | 2048 | serial8250_rpm_put(up); |
|---|
| 2023 | 2049 | |
|---|
| 2024 | | - ret = 0; |
|---|
| 2025 | | - if (status & UART_MSR_DCD) |
|---|
| 2026 | | - ret |= TIOCM_CAR; |
|---|
| 2027 | | - if (status & UART_MSR_RI) |
|---|
| 2028 | | - ret |= TIOCM_RNG; |
|---|
| 2029 | | - if (status & UART_MSR_DSR) |
|---|
| 2030 | | - ret |= TIOCM_DSR; |
|---|
| 2031 | | - if (status & UART_MSR_CTS) |
|---|
| 2032 | | - ret |= TIOCM_CTS; |
|---|
| 2033 | | - return ret; |
|---|
| 2050 | + val = serial8250_MSR_to_TIOCM(status); |
|---|
| 2051 | + if (up->gpios) |
|---|
| 2052 | + return mctrl_gpio_get(up->gpios, &val); |
|---|
| 2053 | + |
|---|
| 2054 | + return val; |
|---|
| 2034 | 2055 | } |
|---|
| 2035 | 2056 | EXPORT_SYMBOL_GPL(serial8250_do_get_mctrl); |
|---|
| 2036 | 2057 | |
|---|
| .. | .. |
|---|
| 2044 | 2065 | void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl) |
|---|
| 2045 | 2066 | { |
|---|
| 2046 | 2067 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 2047 | | - unsigned char mcr = 0; |
|---|
| 2068 | + unsigned char mcr; |
|---|
| 2048 | 2069 | |
|---|
| 2049 | | - if (mctrl & TIOCM_RTS) |
|---|
| 2050 | | - mcr |= UART_MCR_RTS; |
|---|
| 2051 | | - if (mctrl & TIOCM_DTR) |
|---|
| 2052 | | - mcr |= UART_MCR_DTR; |
|---|
| 2053 | | - if (mctrl & TIOCM_OUT1) |
|---|
| 2054 | | - mcr |= UART_MCR_OUT1; |
|---|
| 2055 | | - if (mctrl & TIOCM_OUT2) |
|---|
| 2056 | | - mcr |= UART_MCR_OUT2; |
|---|
| 2057 | | - if (mctrl & TIOCM_LOOP) |
|---|
| 2058 | | - mcr |= UART_MCR_LOOP; |
|---|
| 2070 | + mcr = serial8250_TIOCM_to_MCR(mctrl); |
|---|
| 2059 | 2071 | |
|---|
| 2060 | 2072 | mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; |
|---|
| 2061 | 2073 | |
|---|
| .. | .. |
|---|
| 2065 | 2077 | |
|---|
| 2066 | 2078 | static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
|---|
| 2067 | 2079 | { |
|---|
| 2080 | + if (port->rs485.flags & SER_RS485_ENABLED) |
|---|
| 2081 | + return; |
|---|
| 2082 | + |
|---|
| 2068 | 2083 | if (port->set_mctrl) |
|---|
| 2069 | 2084 | port->set_mctrl(port, mctrl); |
|---|
| 2070 | 2085 | else |
|---|
| .. | .. |
|---|
| 2156 | 2171 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 2157 | 2172 | |
|---|
| 2158 | 2173 | serial8250_rpm_get(up); |
|---|
| 2159 | | - /* |
|---|
| 2160 | | - * First save the IER then disable the interrupts |
|---|
| 2161 | | - */ |
|---|
| 2162 | | - ier = serial_port_in(port, UART_IER); |
|---|
| 2163 | | - if (up->capabilities & UART_CAP_UUE) |
|---|
| 2164 | | - serial_port_out(port, UART_IER, UART_IER_UUE); |
|---|
| 2165 | | - else |
|---|
| 2166 | | - serial_port_out(port, UART_IER, 0); |
|---|
| 2174 | + ier = serial8250_clear_IER(up); |
|---|
| 2167 | 2175 | |
|---|
| 2168 | 2176 | wait_for_xmitr(up, BOTH_EMPTY); |
|---|
| 2169 | 2177 | /* |
|---|
| .. | .. |
|---|
| 2176 | 2184 | * and restore the IER |
|---|
| 2177 | 2185 | */ |
|---|
| 2178 | 2186 | wait_for_xmitr(up, BOTH_EMPTY); |
|---|
| 2179 | | - serial_port_out(port, UART_IER, ier); |
|---|
| 2187 | + serial8250_set_IER(up, ier); |
|---|
| 2180 | 2188 | serial8250_rpm_put(up); |
|---|
| 2181 | 2189 | } |
|---|
| 2182 | 2190 | |
|---|
| .. | .. |
|---|
| 2244 | 2252 | enable_rsa(up); |
|---|
| 2245 | 2253 | #endif |
|---|
| 2246 | 2254 | |
|---|
| 2247 | | - if (port->type == PORT_XR17V35X) { |
|---|
| 2248 | | - /* |
|---|
| 2249 | | - * First enable access to IER [7:5], ISR [5:4], FCR [5:4], |
|---|
| 2250 | | - * MCR [7:5] and MSR [7:0] |
|---|
| 2251 | | - */ |
|---|
| 2252 | | - serial_port_out(port, UART_XR_EFR, UART_EFR_ECB); |
|---|
| 2253 | | - |
|---|
| 2254 | | - /* |
|---|
| 2255 | | - * Make sure all interrups are masked until initialization is |
|---|
| 2256 | | - * complete and the FIFOs are cleared |
|---|
| 2257 | | - */ |
|---|
| 2258 | | - serial_port_out(port, UART_IER, 0); |
|---|
| 2259 | | - } |
|---|
| 2260 | | - |
|---|
| 2261 | 2255 | /* |
|---|
| 2262 | 2256 | * Clear the FIFO buffers and disable them. |
|---|
| 2263 | 2257 | * (they will be reenabled in set_termios()) |
|---|
| .. | .. |
|---|
| 2271 | 2265 | serial_port_in(port, UART_RX); |
|---|
| 2272 | 2266 | serial_port_in(port, UART_IIR); |
|---|
| 2273 | 2267 | serial_port_in(port, UART_MSR); |
|---|
| 2274 | | - if ((port->type == PORT_XR17V35X) || (port->type == PORT_XR17D15X)) |
|---|
| 2275 | | - serial_port_in(port, UART_EXAR_INT0); |
|---|
| 2276 | 2268 | |
|---|
| 2277 | 2269 | /* |
|---|
| 2278 | 2270 | * At this point, there's no way the LSR could still be 0xff; |
|---|
| .. | .. |
|---|
| 2281 | 2273 | */ |
|---|
| 2282 | 2274 | if (!(port->flags & UPF_BUGGY_UART) && |
|---|
| 2283 | 2275 | (serial_port_in(port, UART_LSR) == 0xff)) { |
|---|
| 2284 | | - pr_info_ratelimited("%s: LSR safety check engaged!\n", port->name); |
|---|
| 2276 | + dev_info_ratelimited(port->dev, "LSR safety check engaged!\n"); |
|---|
| 2285 | 2277 | retval = -ENODEV; |
|---|
| 2286 | 2278 | goto out; |
|---|
| 2287 | 2279 | } |
|---|
| .. | .. |
|---|
| 2313 | 2305 | (port->type == PORT_ALTR_16550_F128)) && (port->fifosize > 1)) { |
|---|
| 2314 | 2306 | /* Bounds checking of TX threshold (valid 0 to fifosize-2) */ |
|---|
| 2315 | 2307 | if ((up->tx_loadsz < 2) || (up->tx_loadsz > port->fifosize)) { |
|---|
| 2316 | | - pr_err("%s TX FIFO Threshold errors, skipping\n", |
|---|
| 2317 | | - port->name); |
|---|
| 2308 | + dev_err(port->dev, "TX FIFO Threshold errors, skipping\n"); |
|---|
| 2318 | 2309 | } else { |
|---|
| 2319 | 2310 | serial_port_out(port, UART_ALTR_AFR, |
|---|
| 2320 | 2311 | UART_ALTR_EN_TXFIFO_LW); |
|---|
| .. | .. |
|---|
| 2418 | 2409 | if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { |
|---|
| 2419 | 2410 | if (!(up->bugs & UART_BUG_TXEN)) { |
|---|
| 2420 | 2411 | up->bugs |= UART_BUG_TXEN; |
|---|
| 2421 | | - pr_debug("%s - enabling bad tx status workarounds\n", |
|---|
| 2422 | | - port->name); |
|---|
| 2412 | + dev_dbg(port->dev, "enabling bad tx status workarounds\n"); |
|---|
| 2423 | 2413 | } |
|---|
| 2424 | 2414 | } else { |
|---|
| 2425 | 2415 | up->bugs &= ~UART_BUG_TXEN; |
|---|
| .. | .. |
|---|
| 2437 | 2427 | serial_port_in(port, UART_RX); |
|---|
| 2438 | 2428 | serial_port_in(port, UART_IIR); |
|---|
| 2439 | 2429 | serial_port_in(port, UART_MSR); |
|---|
| 2440 | | - if ((port->type == PORT_XR17V35X) || (port->type == PORT_XR17D15X)) |
|---|
| 2441 | | - serial_port_in(port, UART_EXAR_INT0); |
|---|
| 2442 | 2430 | up->lsr_saved_flags = 0; |
|---|
| 2443 | 2431 | up->msr_saved_flags = 0; |
|---|
| 2444 | 2432 | |
|---|
| .. | .. |
|---|
| 2446 | 2434 | * Request DMA channels for both RX and TX. |
|---|
| 2447 | 2435 | */ |
|---|
| 2448 | 2436 | if (up->dma) { |
|---|
| 2449 | | - retval = serial8250_request_dma(up); |
|---|
| 2450 | | - if (retval) { |
|---|
| 2437 | + const char *msg = NULL; |
|---|
| 2438 | + |
|---|
| 2439 | + if (uart_console(port)) |
|---|
| 2440 | + msg = "forbid DMA for kernel console"; |
|---|
| 2441 | + else if (serial8250_request_dma(up)) |
|---|
| 2451 | 2442 | #ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 2452 | | - pr_warn_ratelimited("%s - failed to request DMA, use interrupt mode\n", |
|---|
| 2453 | | - port->name); |
|---|
| 2443 | + msg = "failed to request DMA, use interrupt mode"; |
|---|
| 2454 | 2444 | #else |
|---|
| 2455 | | - pr_warn_ratelimited("%s - failed to request DMA\n", |
|---|
| 2456 | | - port->name); |
|---|
| 2445 | + msg = "failed to request DMA"; |
|---|
| 2457 | 2446 | #endif |
|---|
| 2447 | + if (msg) { |
|---|
| 2448 | + dev_warn_ratelimited(port->dev, "%s\n", msg); |
|---|
| 2458 | 2449 | up->dma = NULL; |
|---|
| 2459 | 2450 | } |
|---|
| 2460 | 2451 | } |
|---|
| .. | .. |
|---|
| 2500 | 2491 | */ |
|---|
| 2501 | 2492 | spin_lock_irqsave(&port->lock, flags); |
|---|
| 2502 | 2493 | up->ier = 0; |
|---|
| 2503 | | - serial_port_out(port, UART_IER, 0); |
|---|
| 2494 | + serial8250_set_IER(up, 0); |
|---|
| 2504 | 2495 | spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 2505 | 2496 | |
|---|
| 2506 | 2497 | synchronize_irq(port->irq); |
|---|
| .. | .. |
|---|
| 2552 | 2543 | serial8250_do_shutdown(port); |
|---|
| 2553 | 2544 | } |
|---|
| 2554 | 2545 | |
|---|
| 2555 | | -/* |
|---|
| 2556 | | - * XR17V35x UARTs have an extra fractional divisor register (DLD) |
|---|
| 2557 | | - * Calculate divisor with extra 4-bit fractional portion |
|---|
| 2558 | | - */ |
|---|
| 2559 | | -static unsigned int xr17v35x_get_divisor(struct uart_8250_port *up, |
|---|
| 2560 | | - unsigned int baud, |
|---|
| 2561 | | - unsigned int *frac) |
|---|
| 2562 | | -{ |
|---|
| 2563 | | - struct uart_port *port = &up->port; |
|---|
| 2564 | | - unsigned int quot_16; |
|---|
| 2565 | | - |
|---|
| 2566 | | - quot_16 = DIV_ROUND_CLOSEST(port->uartclk, baud); |
|---|
| 2567 | | - *frac = quot_16 & 0x0f; |
|---|
| 2568 | | - |
|---|
| 2569 | | - return quot_16 >> 4; |
|---|
| 2570 | | -} |
|---|
| 2571 | | - |
|---|
| 2572 | 2546 | /* Nuvoton NPCM UARTs have a custom divisor calculation */ |
|---|
| 2573 | 2547 | static unsigned int npcm_get_divisor(struct uart_8250_port *up, |
|---|
| 2574 | 2548 | unsigned int baud) |
|---|
| .. | .. |
|---|
| 2596 | 2570 | else if ((port->flags & UPF_MAGIC_MULTIPLIER) && |
|---|
| 2597 | 2571 | baud == (port->uartclk/8)) |
|---|
| 2598 | 2572 | quot = 0x8002; |
|---|
| 2599 | | - else if (up->port.type == PORT_XR17V35X) |
|---|
| 2600 | | - quot = xr17v35x_get_divisor(up, baud, frac); |
|---|
| 2601 | 2573 | else if (up->port.type == PORT_NPCM) |
|---|
| 2602 | 2574 | quot = npcm_get_divisor(up, baud); |
|---|
| 2603 | 2575 | else |
|---|
| .. | .. |
|---|
| 2699 | 2671 | #ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 2700 | 2672 | serial_port_out(port, UART_MCR, up->mcr); |
|---|
| 2701 | 2673 | #endif |
|---|
| 2702 | | - |
|---|
| 2703 | | - /* XR17V35x UARTs have an extra fractional divisor register (DLD) */ |
|---|
| 2704 | | - if (up->port.type == PORT_XR17V35X) { |
|---|
| 2705 | | - /* Preserve bits not related to baudrate; DLD[7:4]. */ |
|---|
| 2706 | | - quot_frac |= serial_port_in(port, 0x2) & 0xf0; |
|---|
| 2707 | | - serial_port_out(port, 0x2, quot_frac); |
|---|
| 2708 | | - } |
|---|
| 2709 | 2674 | } |
|---|
| 2710 | 2675 | EXPORT_SYMBOL_GPL(serial8250_do_set_divisor); |
|---|
| 2711 | 2676 | |
|---|
| .. | .. |
|---|
| 2747 | 2712 | */ |
|---|
| 2748 | 2713 | return uart_get_baud_rate(port, termios, old, min, max); |
|---|
| 2749 | 2714 | } |
|---|
| 2715 | + |
|---|
| 2716 | +/* |
|---|
| 2717 | + * Note in order to avoid the tty port mutex deadlock don't use the next method |
|---|
| 2718 | + * within the uart port callbacks. Primarily it's supposed to be utilized to |
|---|
| 2719 | + * handle a sudden reference clock rate change. |
|---|
| 2720 | + */ |
|---|
| 2721 | +void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk) |
|---|
| 2722 | +{ |
|---|
| 2723 | + struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 2724 | + struct tty_port *tport = &port->state->port; |
|---|
| 2725 | + unsigned int baud, quot, frac = 0; |
|---|
| 2726 | + struct ktermios *termios; |
|---|
| 2727 | + struct tty_struct *tty; |
|---|
| 2728 | + unsigned long flags; |
|---|
| 2729 | + |
|---|
| 2730 | + tty = tty_port_tty_get(tport); |
|---|
| 2731 | + if (!tty) { |
|---|
| 2732 | + mutex_lock(&tport->mutex); |
|---|
| 2733 | + port->uartclk = uartclk; |
|---|
| 2734 | + mutex_unlock(&tport->mutex); |
|---|
| 2735 | + return; |
|---|
| 2736 | + } |
|---|
| 2737 | + |
|---|
| 2738 | + down_write(&tty->termios_rwsem); |
|---|
| 2739 | + mutex_lock(&tport->mutex); |
|---|
| 2740 | + |
|---|
| 2741 | + if (port->uartclk == uartclk) |
|---|
| 2742 | + goto out_lock; |
|---|
| 2743 | + |
|---|
| 2744 | + port->uartclk = uartclk; |
|---|
| 2745 | + |
|---|
| 2746 | + if (!tty_port_initialized(tport)) |
|---|
| 2747 | + goto out_lock; |
|---|
| 2748 | + |
|---|
| 2749 | + termios = &tty->termios; |
|---|
| 2750 | + |
|---|
| 2751 | + baud = serial8250_get_baud_rate(port, termios, NULL); |
|---|
| 2752 | + quot = serial8250_get_divisor(port, baud, &frac); |
|---|
| 2753 | + |
|---|
| 2754 | + serial8250_rpm_get(up); |
|---|
| 2755 | + spin_lock_irqsave(&port->lock, flags); |
|---|
| 2756 | + |
|---|
| 2757 | + uart_update_timeout(port, termios->c_cflag, baud); |
|---|
| 2758 | + |
|---|
| 2759 | + serial8250_set_divisor(port, baud, quot, frac); |
|---|
| 2760 | + serial_port_out(port, UART_LCR, up->lcr); |
|---|
| 2761 | + |
|---|
| 2762 | + spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 2763 | + serial8250_rpm_put(up); |
|---|
| 2764 | + |
|---|
| 2765 | +out_lock: |
|---|
| 2766 | + mutex_unlock(&tport->mutex); |
|---|
| 2767 | + up_write(&tty->termios_rwsem); |
|---|
| 2768 | + tty_kref_put(tty); |
|---|
| 2769 | +} |
|---|
| 2770 | +EXPORT_SYMBOL_GPL(serial8250_update_uartclk); |
|---|
| 2750 | 2771 | |
|---|
| 2751 | 2772 | void |
|---|
| 2752 | 2773 | serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, |
|---|
| .. | .. |
|---|
| 2842 | 2863 | if (up->capabilities & UART_CAP_RTOIE) |
|---|
| 2843 | 2864 | up->ier |= UART_IER_RTOIE; |
|---|
| 2844 | 2865 | |
|---|
| 2845 | | - serial_port_out(port, UART_IER, up->ier); |
|---|
| 2866 | + serial8250_set_IER(up, up->ier); |
|---|
| 2846 | 2867 | #endif |
|---|
| 2847 | 2868 | |
|---|
| 2848 | 2869 | if (up->capabilities & UART_CAP_EFR) { |
|---|
| .. | .. |
|---|
| 2863 | 2884 | } |
|---|
| 2864 | 2885 | |
|---|
| 2865 | 2886 | #ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 2866 | | - /* Reset uart to make sure it is idle, then set buad rate */ |
|---|
| 2887 | + /* Reset uart to make sure it is idle, then set baud rate */ |
|---|
| 2867 | 2888 | serial_port_out(port, 0x88 >> 2, 0x7); |
|---|
| 2868 | 2889 | #endif |
|---|
| 2869 | 2890 | |
|---|
| .. | .. |
|---|
| 2902 | 2923 | if (up->capabilities & UART_CAP_RTOIE) |
|---|
| 2903 | 2924 | up->ier |= UART_IER_RTOIE; |
|---|
| 2904 | 2925 | |
|---|
| 2905 | | - serial_port_out(port, UART_IER, up->ier); |
|---|
| 2926 | + serial8250_set_IER(up, up->ier); |
|---|
| 2906 | 2927 | #endif |
|---|
| 2907 | 2928 | |
|---|
| 2908 | 2929 | spin_unlock_irqrestore(&port->lock, flags); |
|---|
| .. | .. |
|---|
| 3001 | 3022 | case UPIO_MEM32BE: |
|---|
| 3002 | 3023 | case UPIO_MEM16: |
|---|
| 3003 | 3024 | case UPIO_MEM: |
|---|
| 3004 | | - if (!port->mapbase) |
|---|
| 3025 | + if (!port->mapbase) { |
|---|
| 3026 | + ret = -EINVAL; |
|---|
| 3005 | 3027 | break; |
|---|
| 3028 | + } |
|---|
| 3006 | 3029 | |
|---|
| 3007 | 3030 | if (!request_mem_region(port->mapbase, size, "serial")) { |
|---|
| 3008 | 3031 | ret = -EBUSY; |
|---|
| .. | .. |
|---|
| 3010 | 3033 | } |
|---|
| 3011 | 3034 | |
|---|
| 3012 | 3035 | if (port->flags & UPF_IOREMAP) { |
|---|
| 3013 | | - port->membase = ioremap_nocache(port->mapbase, size); |
|---|
| 3036 | + port->membase = ioremap(port->mapbase, size); |
|---|
| 3014 | 3037 | if (!port->membase) { |
|---|
| 3015 | 3038 | release_mem_region(port->mapbase, size); |
|---|
| 3016 | 3039 | ret = -ENOMEM; |
|---|
| .. | .. |
|---|
| 3121 | 3144 | return rxtrig_bytes; |
|---|
| 3122 | 3145 | } |
|---|
| 3123 | 3146 | |
|---|
| 3124 | | -static ssize_t serial8250_get_attr_rx_trig_bytes(struct device *dev, |
|---|
| 3147 | +static ssize_t rx_trig_bytes_show(struct device *dev, |
|---|
| 3125 | 3148 | struct device_attribute *attr, char *buf) |
|---|
| 3126 | 3149 | { |
|---|
| 3127 | 3150 | struct tty_port *port = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 3167 | 3190 | return ret; |
|---|
| 3168 | 3191 | } |
|---|
| 3169 | 3192 | |
|---|
| 3170 | | -static ssize_t serial8250_set_attr_rx_trig_bytes(struct device *dev, |
|---|
| 3193 | +static ssize_t rx_trig_bytes_store(struct device *dev, |
|---|
| 3171 | 3194 | struct device_attribute *attr, const char *buf, size_t count) |
|---|
| 3172 | 3195 | { |
|---|
| 3173 | 3196 | struct tty_port *port = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 3188 | 3211 | return count; |
|---|
| 3189 | 3212 | } |
|---|
| 3190 | 3213 | |
|---|
| 3191 | | -static DEVICE_ATTR(rx_trig_bytes, S_IRUSR | S_IWUSR | S_IRGRP, |
|---|
| 3192 | | - serial8250_get_attr_rx_trig_bytes, |
|---|
| 3193 | | - serial8250_set_attr_rx_trig_bytes); |
|---|
| 3214 | +static DEVICE_ATTR_RW(rx_trig_bytes); |
|---|
| 3194 | 3215 | |
|---|
| 3195 | 3216 | static struct attribute *serial8250_dev_attrs[] = { |
|---|
| 3196 | 3217 | &dev_attr_rx_trig_bytes.attr, |
|---|
| 3197 | | - NULL, |
|---|
| 3198 | | - }; |
|---|
| 3218 | + NULL |
|---|
| 3219 | +}; |
|---|
| 3199 | 3220 | |
|---|
| 3200 | 3221 | static struct attribute_group serial8250_dev_attr_group = { |
|---|
| 3201 | 3222 | .attrs = serial8250_dev_attrs, |
|---|
| 3202 | | - }; |
|---|
| 3223 | +}; |
|---|
| 3203 | 3224 | |
|---|
| 3204 | 3225 | static void register_dev_spec_attr_grp(struct uart_8250_port *up) |
|---|
| 3205 | 3226 | { |
|---|
| .. | .. |
|---|
| 3299 | 3320 | |
|---|
| 3300 | 3321 | spin_lock_init(&port->lock); |
|---|
| 3301 | 3322 | port->ops = &serial8250_pops; |
|---|
| 3323 | + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); |
|---|
| 3302 | 3324 | |
|---|
| 3303 | 3325 | up->cur_iotype = 0xFF; |
|---|
| 3304 | 3326 | } |
|---|
| .. | .. |
|---|
| 3333 | 3355 | |
|---|
| 3334 | 3356 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
|---|
| 3335 | 3357 | |
|---|
| 3336 | | -static void serial8250_console_putchar(struct uart_port *port, int ch) |
|---|
| 3358 | +static void serial8250_console_putchar_locked(struct uart_port *port, int ch) |
|---|
| 3337 | 3359 | { |
|---|
| 3338 | 3360 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 3339 | 3361 | |
|---|
| 3340 | 3362 | wait_for_xmitr(up, UART_LSR_THRE); |
|---|
| 3341 | 3363 | serial_port_out(port, UART_TX, ch); |
|---|
| 3364 | +} |
|---|
| 3365 | + |
|---|
| 3366 | +static void serial8250_console_putchar(struct uart_port *port, int ch) |
|---|
| 3367 | +{ |
|---|
| 3368 | + struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 3369 | + unsigned int flags; |
|---|
| 3370 | + |
|---|
| 3371 | + wait_for_xmitr(up, UART_LSR_THRE); |
|---|
| 3372 | + |
|---|
| 3373 | + console_atomic_lock(&flags); |
|---|
| 3374 | + serial8250_console_putchar_locked(port, ch); |
|---|
| 3375 | + console_atomic_unlock(flags); |
|---|
| 3342 | 3376 | } |
|---|
| 3343 | 3377 | |
|---|
| 3344 | 3378 | /* |
|---|
| .. | .. |
|---|
| 3359 | 3393 | |
|---|
| 3360 | 3394 | serial8250_set_divisor(port, baud, quot, frac); |
|---|
| 3361 | 3395 | serial_port_out(port, UART_LCR, up->lcr); |
|---|
| 3362 | | - serial8250_out_MCR(up, UART_MCR_DTR | UART_MCR_RTS); |
|---|
| 3396 | + serial8250_out_MCR(up, up->mcr | UART_MCR_DTR | UART_MCR_RTS); |
|---|
| 3397 | +} |
|---|
| 3398 | + |
|---|
| 3399 | +void serial8250_console_write_atomic(struct uart_8250_port *up, |
|---|
| 3400 | + const char *s, unsigned int count) |
|---|
| 3401 | +{ |
|---|
| 3402 | + struct uart_port *port = &up->port; |
|---|
| 3403 | + unsigned int flags; |
|---|
| 3404 | + unsigned int ier; |
|---|
| 3405 | + |
|---|
| 3406 | + console_atomic_lock(&flags); |
|---|
| 3407 | + |
|---|
| 3408 | + touch_nmi_watchdog(); |
|---|
| 3409 | + |
|---|
| 3410 | + ier = serial8250_clear_IER(up); |
|---|
| 3411 | + |
|---|
| 3412 | + if (atomic_fetch_inc(&up->console_printing)) { |
|---|
| 3413 | + uart_console_write(port, "\n", 1, |
|---|
| 3414 | + serial8250_console_putchar_locked); |
|---|
| 3415 | + } |
|---|
| 3416 | + uart_console_write(port, s, count, serial8250_console_putchar_locked); |
|---|
| 3417 | + atomic_dec(&up->console_printing); |
|---|
| 3418 | + |
|---|
| 3419 | + wait_for_xmitr(up, BOTH_EMPTY); |
|---|
| 3420 | + serial8250_set_IER(up, ier); |
|---|
| 3421 | + |
|---|
| 3422 | + console_atomic_unlock(flags); |
|---|
| 3363 | 3423 | } |
|---|
| 3364 | 3424 | |
|---|
| 3365 | 3425 | /* |
|---|
| .. | .. |
|---|
| 3367 | 3427 | * any possible real use of the port... |
|---|
| 3368 | 3428 | * |
|---|
| 3369 | 3429 | * The console_lock must be held when we get here. |
|---|
| 3430 | + * |
|---|
| 3431 | + * Doing runtime PM is really a bad idea for the kernel console. |
|---|
| 3432 | + * Thus, we assume the function is called when device is powered up. |
|---|
| 3370 | 3433 | */ |
|---|
| 3371 | 3434 | void serial8250_console_write(struct uart_8250_port *up, const char *s, |
|---|
| 3372 | 3435 | unsigned int count) |
|---|
| 3373 | 3436 | { |
|---|
| 3437 | + struct uart_8250_em485 *em485 = up->em485; |
|---|
| 3374 | 3438 | struct uart_port *port = &up->port; |
|---|
| 3375 | 3439 | unsigned long flags; |
|---|
| 3376 | 3440 | unsigned int ier; |
|---|
| 3377 | | - int locked = 1; |
|---|
| 3378 | 3441 | |
|---|
| 3379 | 3442 | touch_nmi_watchdog(); |
|---|
| 3380 | 3443 | |
|---|
| 3381 | | - serial8250_rpm_get(up); |
|---|
| 3444 | + spin_lock_irqsave(&port->lock, flags); |
|---|
| 3382 | 3445 | |
|---|
| 3383 | | - if (port->sysrq) |
|---|
| 3384 | | - locked = 0; |
|---|
| 3385 | | - else if (oops_in_progress) |
|---|
| 3386 | | - locked = spin_trylock_irqsave(&port->lock, flags); |
|---|
| 3387 | | - else |
|---|
| 3388 | | - spin_lock_irqsave(&port->lock, flags); |
|---|
| 3389 | | - |
|---|
| 3390 | | - /* |
|---|
| 3391 | | - * First save the IER then disable the interrupts |
|---|
| 3392 | | - */ |
|---|
| 3393 | | - ier = serial_port_in(port, UART_IER); |
|---|
| 3394 | | - |
|---|
| 3395 | | - if (up->capabilities & UART_CAP_UUE) |
|---|
| 3396 | | - serial_port_out(port, UART_IER, UART_IER_UUE); |
|---|
| 3397 | | - else |
|---|
| 3398 | | - serial_port_out(port, UART_IER, 0); |
|---|
| 3446 | + ier = serial8250_clear_IER(up); |
|---|
| 3399 | 3447 | |
|---|
| 3400 | 3448 | /* check scratch reg to see if port powered off during system sleep */ |
|---|
| 3401 | 3449 | if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) { |
|---|
| .. | .. |
|---|
| 3403 | 3451 | up->canary = 0; |
|---|
| 3404 | 3452 | } |
|---|
| 3405 | 3453 | |
|---|
| 3454 | + if (em485) { |
|---|
| 3455 | + if (em485->tx_stopped) |
|---|
| 3456 | + up->rs485_start_tx(up); |
|---|
| 3457 | + mdelay(port->rs485.delay_rts_before_send); |
|---|
| 3458 | + } |
|---|
| 3459 | + |
|---|
| 3460 | + atomic_inc(&up->console_printing); |
|---|
| 3406 | 3461 | uart_console_write(port, s, count, serial8250_console_putchar); |
|---|
| 3462 | + atomic_dec(&up->console_printing); |
|---|
| 3407 | 3463 | |
|---|
| 3408 | 3464 | /* |
|---|
| 3409 | 3465 | * Finally, wait for transmitter to become empty |
|---|
| 3410 | 3466 | * and restore the IER |
|---|
| 3411 | 3467 | */ |
|---|
| 3412 | 3468 | wait_for_xmitr(up, BOTH_EMPTY); |
|---|
| 3413 | | - serial_port_out(port, UART_IER, ier); |
|---|
| 3469 | + |
|---|
| 3470 | + if (em485) { |
|---|
| 3471 | + mdelay(port->rs485.delay_rts_after_send); |
|---|
| 3472 | + if (em485->tx_stopped) |
|---|
| 3473 | + up->rs485_stop_tx(up); |
|---|
| 3474 | + } |
|---|
| 3475 | + serial8250_set_IER(up, ier); |
|---|
| 3414 | 3476 | |
|---|
| 3415 | 3477 | /* |
|---|
| 3416 | 3478 | * The receive handling will happen properly because the |
|---|
| .. | .. |
|---|
| 3422 | 3484 | if (up->msr_saved_flags) |
|---|
| 3423 | 3485 | serial8250_modem_status(up); |
|---|
| 3424 | 3486 | |
|---|
| 3425 | | - if (locked) |
|---|
| 3426 | | - spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 3427 | | - serial8250_rpm_put(up); |
|---|
| 3487 | + spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 3428 | 3488 | } |
|---|
| 3429 | 3489 | |
|---|
| 3430 | 3490 | static unsigned int probe_baud(struct uart_port *port) |
|---|
| .. | .. |
|---|
| 3444 | 3504 | |
|---|
| 3445 | 3505 | int serial8250_console_setup(struct uart_port *port, char *options, bool probe) |
|---|
| 3446 | 3506 | { |
|---|
| 3507 | + struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 3447 | 3508 | int baud = 9600; |
|---|
| 3448 | 3509 | int bits = 8; |
|---|
| 3449 | 3510 | int parity = 'n'; |
|---|
| 3450 | 3511 | int flow = 'n'; |
|---|
| 3512 | + int ret; |
|---|
| 3451 | 3513 | |
|---|
| 3452 | 3514 | if (!port->iobase && !port->membase) |
|---|
| 3453 | 3515 | return -ENODEV; |
|---|
| 3516 | + |
|---|
| 3517 | + atomic_set(&up->console_printing, 0); |
|---|
| 3454 | 3518 | |
|---|
| 3455 | 3519 | if (options) |
|---|
| 3456 | 3520 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
|---|
| 3457 | 3521 | else if (probe) |
|---|
| 3458 | 3522 | baud = probe_baud(port); |
|---|
| 3459 | 3523 | |
|---|
| 3460 | | - return uart_set_options(port, port->cons, baud, parity, bits, flow); |
|---|
| 3524 | + ret = uart_set_options(port, port->cons, baud, parity, bits, flow); |
|---|
| 3525 | + if (ret) |
|---|
| 3526 | + return ret; |
|---|
| 3527 | + |
|---|
| 3528 | + if (port->dev) |
|---|
| 3529 | + pm_runtime_get_sync(port->dev); |
|---|
| 3530 | + |
|---|
| 3531 | + return 0; |
|---|
| 3532 | +} |
|---|
| 3533 | + |
|---|
| 3534 | +int serial8250_console_exit(struct uart_port *port) |
|---|
| 3535 | +{ |
|---|
| 3536 | + if (port->dev) |
|---|
| 3537 | + pm_runtime_put_sync(port->dev); |
|---|
| 3538 | + |
|---|
| 3539 | + return 0; |
|---|
| 3461 | 3540 | } |
|---|
| 3462 | 3541 | |
|---|
| 3463 | 3542 | #endif /* CONFIG_SERIAL_8250_CONSOLE */ |
|---|