.. | .. |
---|
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> |
---|
| 18 | +#include <linux/irq.h> |
---|
22 | 19 | #include <linux/console.h> |
---|
| 20 | +#include <linux/gpio/consumer.h> |
---|
23 | 21 | #include <linux/sysrq.h> |
---|
24 | 22 | #include <linux/delay.h> |
---|
25 | 23 | #include <linux/platform_device.h> |
---|
.. | .. |
---|
31 | 29 | #include <linux/nmi.h> |
---|
32 | 30 | #include <linux/mutex.h> |
---|
33 | 31 | #include <linux/slab.h> |
---|
34 | | -#include <linux/kdb.h> |
---|
35 | 32 | #include <linux/uaccess.h> |
---|
36 | 33 | #include <linux/pm_runtime.h> |
---|
37 | 34 | #include <linux/ktime.h> |
---|
.. | .. |
---|
40 | 37 | #include <asm/irq.h> |
---|
41 | 38 | |
---|
42 | 39 | #include "8250.h" |
---|
43 | | - |
---|
44 | | -/* |
---|
45 | | - * These are definitions for the Exar XR17V35X and XR17(C|D)15X |
---|
46 | | - */ |
---|
47 | | -#define UART_EXAR_INT0 0x80 |
---|
48 | | -#define UART_EXAR_SLEEP 0x8b /* Sleep mode */ |
---|
49 | | -#define UART_EXAR_DVID 0x8d /* Device identification */ |
---|
50 | 40 | |
---|
51 | 41 | /* Nuvoton NPCM timeout register */ |
---|
52 | 42 | #define UART_NPCM_TOR 7 |
---|
.. | .. |
---|
67 | 57 | * Here we define the default xmit fifo size used for each type of UART. |
---|
68 | 58 | */ |
---|
69 | 59 | static const struct serial8250_config uart_config[] = { |
---|
| 60 | +#ifndef CONFIG_ROCKCHIP_MINI_KERNEL |
---|
70 | 61 | [PORT_UNKNOWN] = { |
---|
71 | 62 | .name = "unknown", |
---|
72 | 63 | .fifo_size = 1, |
---|
.. | .. |
---|
87 | 78 | .fifo_size = 1, |
---|
88 | 79 | .tx_loadsz = 1, |
---|
89 | 80 | }, |
---|
| 81 | +#endif |
---|
90 | 82 | [PORT_16550A] = { |
---|
91 | 83 | .name = "16550A", |
---|
92 | 84 | .fifo_size = 16, |
---|
.. | .. |
---|
95 | 87 | .rxtrig_bytes = {1, 4, 8, 14}, |
---|
96 | 88 | .flags = UART_CAP_FIFO, |
---|
97 | 89 | }, |
---|
| 90 | +#ifndef CONFIG_ROCKCHIP_MINI_KERNEL |
---|
98 | 91 | [PORT_CIRRUS] = { |
---|
99 | 92 | .name = "Cirrus", |
---|
100 | 93 | .fifo_size = 1, |
---|
.. | .. |
---|
310 | 303 | .rxtrig_bytes = {1, 4, 8, 14}, |
---|
311 | 304 | .flags = UART_CAP_FIFO, |
---|
312 | 305 | }, |
---|
| 306 | + [PORT_SUNIX] = { |
---|
| 307 | + .name = "Sunix", |
---|
| 308 | + .fifo_size = 128, |
---|
| 309 | + .tx_loadsz = 128, |
---|
| 310 | + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
---|
| 311 | + .rxtrig_bytes = {1, 32, 64, 112}, |
---|
| 312 | + .flags = UART_CAP_FIFO | UART_CAP_SLEEP, |
---|
| 313 | + }, |
---|
| 314 | +#endif |
---|
313 | 315 | }; |
---|
314 | 316 | |
---|
315 | 317 | /* Uart divisor latch read */ |
---|
.. | .. |
---|
387 | 389 | |
---|
388 | 390 | #endif |
---|
389 | 391 | |
---|
| 392 | +#ifndef CONFIG_ROCKCHIP_MINI_KERNEL |
---|
390 | 393 | static unsigned int hub6_serial_in(struct uart_port *p, int offset) |
---|
391 | 394 | { |
---|
392 | 395 | offset = offset << p->regshift; |
---|
.. | .. |
---|
460 | 463 | offset = offset << p->regshift; |
---|
461 | 464 | outb(value, p->iobase + offset); |
---|
462 | 465 | } |
---|
| 466 | +#endif |
---|
463 | 467 | |
---|
464 | 468 | static int serial8250_default_handle_irq(struct uart_port *port); |
---|
465 | 469 | |
---|
.. | .. |
---|
470 | 474 | up->dl_read = default_serial_dl_read; |
---|
471 | 475 | up->dl_write = default_serial_dl_write; |
---|
472 | 476 | |
---|
| 477 | +#ifndef CONFIG_ROCKCHIP_MINI_KERNEL |
---|
473 | 478 | switch (p->iotype) { |
---|
474 | 479 | case UPIO_HUB6: |
---|
475 | 480 | p->serial_in = hub6_serial_in; |
---|
.. | .. |
---|
510 | 515 | p->serial_out = io_serial_out; |
---|
511 | 516 | break; |
---|
512 | 517 | } |
---|
| 518 | +#endif |
---|
513 | 519 | /* Remember loaded iotype */ |
---|
514 | 520 | up->cur_iotype = p->iotype; |
---|
515 | 521 | p->handle_irq = serial8250_default_handle_irq; |
---|
.. | .. |
---|
533 | 539 | } |
---|
534 | 540 | |
---|
535 | 541 | /* |
---|
536 | | - * For the 16C950 |
---|
537 | | - */ |
---|
538 | | -static void serial_icr_write(struct uart_8250_port *up, int offset, int value) |
---|
539 | | -{ |
---|
540 | | - serial_out(up, UART_SCR, offset); |
---|
541 | | - serial_out(up, UART_ICR, value); |
---|
542 | | -} |
---|
543 | | - |
---|
544 | | -static unsigned int serial_icr_read(struct uart_8250_port *up, int offset) |
---|
545 | | -{ |
---|
546 | | - unsigned int value; |
---|
547 | | - |
---|
548 | | - serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); |
---|
549 | | - serial_out(up, UART_SCR, offset); |
---|
550 | | - value = serial_in(up, UART_ICR); |
---|
551 | | - serial_icr_write(up, UART_ACR, up->acr); |
---|
552 | | - |
---|
553 | | - return value; |
---|
554 | | -} |
---|
555 | | - |
---|
556 | | -/* |
---|
557 | 542 | * FIFO support. |
---|
558 | 543 | */ |
---|
559 | 544 | static void serial8250_clear_fifos(struct uart_8250_port *p) |
---|
.. | .. |
---|
564 | 549 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
---|
565 | 550 | serial_out(p, UART_FCR, 0); |
---|
566 | 551 | } |
---|
567 | | -} |
---|
568 | | - |
---|
569 | | -static inline void serial8250_em485_rts_after_send(struct uart_8250_port *p) |
---|
570 | | -{ |
---|
571 | | - unsigned char mcr = serial8250_in_MCR(p); |
---|
572 | | - |
---|
573 | | - if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND) |
---|
574 | | - mcr |= UART_MCR_RTS; |
---|
575 | | - else |
---|
576 | | - mcr &= ~UART_MCR_RTS; |
---|
577 | | - serial8250_out_MCR(p, mcr); |
---|
578 | 552 | } |
---|
579 | 553 | |
---|
580 | 554 | static enum hrtimer_restart serial8250_em485_handle_start_tx(struct hrtimer *t); |
---|
.. | .. |
---|
624 | 598 | * |
---|
625 | 599 | * Return 0 - success, -errno - otherwise |
---|
626 | 600 | */ |
---|
627 | | -int serial8250_em485_init(struct uart_8250_port *p) |
---|
| 601 | +static int serial8250_em485_init(struct uart_8250_port *p) |
---|
628 | 602 | { |
---|
629 | 603 | if (p->em485) |
---|
630 | | - return 0; |
---|
| 604 | + goto deassert_rts; |
---|
631 | 605 | |
---|
632 | 606 | p->em485 = kmalloc(sizeof(struct uart_8250_em485), GFP_ATOMIC); |
---|
633 | 607 | if (!p->em485) |
---|
.. | .. |
---|
641 | 615 | p->em485->start_tx_timer.function = &serial8250_em485_handle_start_tx; |
---|
642 | 616 | p->em485->port = p; |
---|
643 | 617 | p->em485->active_timer = NULL; |
---|
644 | | - serial8250_em485_rts_after_send(p); |
---|
| 618 | + p->em485->tx_stopped = true; |
---|
| 619 | + |
---|
| 620 | +deassert_rts: |
---|
| 621 | + if (p->em485->tx_stopped) |
---|
| 622 | + p->rs485_stop_tx(p); |
---|
645 | 623 | |
---|
646 | 624 | return 0; |
---|
647 | 625 | } |
---|
648 | | -EXPORT_SYMBOL_GPL(serial8250_em485_init); |
---|
649 | 626 | |
---|
650 | 627 | /** |
---|
651 | 628 | * serial8250_em485_destroy() - put uart_8250_port into normal state |
---|
.. | .. |
---|
672 | 649 | p->em485 = NULL; |
---|
673 | 650 | } |
---|
674 | 651 | EXPORT_SYMBOL_GPL(serial8250_em485_destroy); |
---|
| 652 | + |
---|
| 653 | +/** |
---|
| 654 | + * serial8250_em485_config() - generic ->rs485_config() callback |
---|
| 655 | + * @port: uart port |
---|
| 656 | + * @rs485: rs485 settings |
---|
| 657 | + * |
---|
| 658 | + * Generic callback usable by 8250 uart drivers to activate rs485 settings |
---|
| 659 | + * if the uart is incapable of driving RTS as a Transmit Enable signal in |
---|
| 660 | + * hardware, relying on software emulation instead. |
---|
| 661 | + */ |
---|
| 662 | +int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485) |
---|
| 663 | +{ |
---|
| 664 | + struct uart_8250_port *up = up_to_u8250p(port); |
---|
| 665 | + |
---|
| 666 | + /* pick sane settings if the user hasn't */ |
---|
| 667 | + if (!!(rs485->flags & SER_RS485_RTS_ON_SEND) == |
---|
| 668 | + !!(rs485->flags & SER_RS485_RTS_AFTER_SEND)) { |
---|
| 669 | + rs485->flags |= SER_RS485_RTS_ON_SEND; |
---|
| 670 | + rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; |
---|
| 671 | + } |
---|
| 672 | + |
---|
| 673 | + gpiod_set_value(port->rs485_term_gpio, |
---|
| 674 | + rs485->flags & SER_RS485_TERMINATE_BUS); |
---|
| 675 | + |
---|
| 676 | + /* |
---|
| 677 | + * Both serial8250_em485_init() and serial8250_em485_destroy() |
---|
| 678 | + * are idempotent. |
---|
| 679 | + */ |
---|
| 680 | + if (rs485->flags & SER_RS485_ENABLED) |
---|
| 681 | + return serial8250_em485_init(up); |
---|
| 682 | + |
---|
| 683 | + serial8250_em485_destroy(up); |
---|
| 684 | + return 0; |
---|
| 685 | +} |
---|
| 686 | +EXPORT_SYMBOL_GPL(serial8250_em485_config); |
---|
675 | 687 | |
---|
676 | 688 | /* |
---|
677 | 689 | * These two wrappers ensure that enable_runtime_pm_tx() can be called more than |
---|
.. | .. |
---|
715 | 727 | static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) |
---|
716 | 728 | { |
---|
717 | 729 | unsigned char lcr = 0, efr = 0; |
---|
718 | | - /* |
---|
719 | | - * Exar UARTs have a SLEEP register that enables or disables |
---|
720 | | - * each UART to enter sleep mode separately. On the XR17V35x the |
---|
721 | | - * register is accessible to each UART at the UART_EXAR_SLEEP |
---|
722 | | - * offset but the UART channel may only write to the corresponding |
---|
723 | | - * bit. |
---|
724 | | - */ |
---|
| 730 | + |
---|
725 | 731 | serial8250_rpm_get(p); |
---|
726 | | - if ((p->port.type == PORT_XR17V35X) || |
---|
727 | | - (p->port.type == PORT_XR17D15X)) { |
---|
728 | | - serial_out(p, UART_EXAR_SLEEP, sleep ? 0xff : 0); |
---|
729 | | - goto out; |
---|
730 | | - } |
---|
731 | 732 | |
---|
732 | 733 | if (p->capabilities & UART_CAP_SLEEP) { |
---|
733 | 734 | if (p->capabilities & UART_CAP_EFR) { |
---|
.. | .. |
---|
744 | 745 | serial_out(p, UART_LCR, lcr); |
---|
745 | 746 | } |
---|
746 | 747 | } |
---|
747 | | -out: |
---|
| 748 | + |
---|
748 | 749 | serial8250_rpm_put(p); |
---|
749 | 750 | } |
---|
750 | 751 | |
---|
.. | .. |
---|
1017 | 1018 | up->port.type = PORT_16550A; |
---|
1018 | 1019 | up->capabilities |= UART_CAP_FIFO; |
---|
1019 | 1020 | |
---|
1020 | | - /* |
---|
1021 | | - * XR17V35x UARTs have an extra divisor register, DLD |
---|
1022 | | - * that gets enabled with when DLAB is set which will |
---|
1023 | | - * cause the device to incorrectly match and assign |
---|
1024 | | - * port type to PORT_16650. The EFR for this UART is |
---|
1025 | | - * found at offset 0x09. Instead check the Deice ID (DVID) |
---|
1026 | | - * register for a 2, 4 or 8 port UART. |
---|
1027 | | - */ |
---|
1028 | | - if (up->port.flags & UPF_EXAR_EFR) { |
---|
1029 | | - status1 = serial_in(up, UART_EXAR_DVID); |
---|
1030 | | - if (status1 == 0x82 || status1 == 0x84 || status1 == 0x88) { |
---|
1031 | | - DEBUG_AUTOCONF("Exar XR17V35x "); |
---|
1032 | | - up->port.type = PORT_XR17V35X; |
---|
1033 | | - up->capabilities |= UART_CAP_AFE | UART_CAP_EFR | |
---|
1034 | | - UART_CAP_SLEEP; |
---|
1035 | | - |
---|
1036 | | - return; |
---|
1037 | | - } |
---|
1038 | | - |
---|
1039 | | - } |
---|
| 1021 | + if (!IS_ENABLED(CONFIG_SERIAL_8250_16550A_VARIANTS)) |
---|
| 1022 | + return; |
---|
1040 | 1023 | |
---|
1041 | 1024 | /* |
---|
1042 | 1025 | * Check for presence of the EFR when DLAB is set. |
---|
.. | .. |
---|
1175 | 1158 | DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); |
---|
1176 | 1159 | } |
---|
1177 | 1160 | serial_out(up, UART_IER, iersave); |
---|
1178 | | - |
---|
1179 | | - /* |
---|
1180 | | - * Exar uarts have EFR in a weird location |
---|
1181 | | - */ |
---|
1182 | | - if (up->port.flags & UPF_EXAR_EFR) { |
---|
1183 | | - DEBUG_AUTOCONF("Exar XR17D15x "); |
---|
1184 | | - up->port.type = PORT_XR17D15X; |
---|
1185 | | - up->capabilities |= UART_CAP_AFE | UART_CAP_EFR | |
---|
1186 | | - UART_CAP_SLEEP; |
---|
1187 | | - |
---|
1188 | | - return; |
---|
1189 | | - } |
---|
1190 | 1161 | |
---|
1191 | 1162 | /* |
---|
1192 | 1163 | * We distinguish between 16550A and U6 16550A by counting |
---|
.. | .. |
---|
1370 | 1341 | fintek_8250_probe(up); |
---|
1371 | 1342 | |
---|
1372 | 1343 | if (up->capabilities != old_capabilities) { |
---|
1373 | | - pr_warn("%s: detected caps %08x should be %08x\n", |
---|
1374 | | - port->name, old_capabilities, up->capabilities); |
---|
| 1344 | + dev_warn(port->dev, "detected caps %08x should be %08x\n", |
---|
| 1345 | + old_capabilities, up->capabilities); |
---|
1375 | 1346 | } |
---|
1376 | 1347 | out: |
---|
1377 | 1348 | DEBUG_AUTOCONF("iir=%d ", scratch); |
---|
.. | .. |
---|
1446 | 1417 | serial8250_rpm_put(up); |
---|
1447 | 1418 | } |
---|
1448 | 1419 | |
---|
1449 | | -static void __do_stop_tx_rs485(struct uart_8250_port *p) |
---|
| 1420 | +/** |
---|
| 1421 | + * serial8250_em485_stop_tx() - generic ->rs485_stop_tx() callback |
---|
| 1422 | + * @p: uart 8250 port |
---|
| 1423 | + * |
---|
| 1424 | + * Generic callback usable by 8250 uart drivers to stop rs485 transmission. |
---|
| 1425 | + */ |
---|
| 1426 | +void serial8250_em485_stop_tx(struct uart_8250_port *p) |
---|
1450 | 1427 | { |
---|
1451 | | - serial8250_em485_rts_after_send(p); |
---|
| 1428 | + unsigned char mcr = serial8250_in_MCR(p); |
---|
| 1429 | + |
---|
| 1430 | + if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND) |
---|
| 1431 | + mcr |= UART_MCR_RTS; |
---|
| 1432 | + else |
---|
| 1433 | + mcr &= ~UART_MCR_RTS; |
---|
| 1434 | + serial8250_out_MCR(p, mcr); |
---|
1452 | 1435 | |
---|
1453 | 1436 | /* |
---|
1454 | 1437 | * Empty the RX FIFO, we are not interested in anything |
---|
.. | .. |
---|
1462 | 1445 | serial_port_out(&p->port, UART_IER, p->ier); |
---|
1463 | 1446 | } |
---|
1464 | 1447 | } |
---|
| 1448 | +EXPORT_SYMBOL_GPL(serial8250_em485_stop_tx); |
---|
| 1449 | + |
---|
1465 | 1450 | static enum hrtimer_restart serial8250_em485_handle_stop_tx(struct hrtimer *t) |
---|
1466 | 1451 | { |
---|
1467 | 1452 | struct uart_8250_em485 *em485; |
---|
.. | .. |
---|
1474 | 1459 | serial8250_rpm_get(p); |
---|
1475 | 1460 | spin_lock_irqsave(&p->port.lock, flags); |
---|
1476 | 1461 | if (em485->active_timer == &em485->stop_tx_timer) { |
---|
1477 | | - __do_stop_tx_rs485(p); |
---|
| 1462 | + p->rs485_stop_tx(p); |
---|
1478 | 1463 | em485->active_timer = NULL; |
---|
| 1464 | + em485->tx_stopped = true; |
---|
1479 | 1465 | } |
---|
1480 | 1466 | spin_unlock_irqrestore(&p->port.lock, flags); |
---|
1481 | 1467 | serial8250_rpm_put(p); |
---|
.. | .. |
---|
1496 | 1482 | struct uart_8250_em485 *em485 = p->em485; |
---|
1497 | 1483 | |
---|
1498 | 1484 | /* |
---|
1499 | | - * __do_stop_tx_rs485 is going to set RTS according to config |
---|
| 1485 | + * rs485_stop_tx() is going to set RTS according to config |
---|
1500 | 1486 | * AND flush RX FIFO if required. |
---|
1501 | 1487 | */ |
---|
1502 | 1488 | if (p->port.rs485.delay_rts_after_send > 0) { |
---|
.. | .. |
---|
1504 | 1490 | start_hrtimer_ms(&em485->stop_tx_timer, |
---|
1505 | 1491 | p->port.rs485.delay_rts_after_send); |
---|
1506 | 1492 | } else { |
---|
1507 | | - __do_stop_tx_rs485(p); |
---|
| 1493 | + p->rs485_stop_tx(p); |
---|
| 1494 | + em485->active_timer = NULL; |
---|
| 1495 | + em485->tx_stopped = true; |
---|
1508 | 1496 | } |
---|
1509 | 1497 | } |
---|
1510 | 1498 | |
---|
1511 | 1499 | static inline void __do_stop_tx(struct uart_8250_port *p) |
---|
1512 | 1500 | { |
---|
1513 | | - if (p->ier & UART_IER_THRI) { |
---|
1514 | | - p->ier &= ~UART_IER_THRI; |
---|
1515 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
---|
1516 | | - p->ier &= ~UART_IER_PTIME; |
---|
1517 | | -#endif |
---|
1518 | | - serial_out(p, UART_IER, p->ier); |
---|
| 1501 | + if (serial8250_clear_THRI(p)) |
---|
1519 | 1502 | serial8250_rpm_put_tx(p); |
---|
1520 | | - } |
---|
1521 | 1503 | } |
---|
1522 | 1504 | |
---|
1523 | 1505 | static inline void __stop_tx(struct uart_8250_port *p) |
---|
.. | .. |
---|
1526 | 1508 | |
---|
1527 | 1509 | if (em485) { |
---|
1528 | 1510 | unsigned char lsr = serial_in(p, UART_LSR); |
---|
| 1511 | + p->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
---|
| 1512 | + |
---|
1529 | 1513 | /* |
---|
1530 | 1514 | * To provide required timeing and allow FIFO transfer, |
---|
1531 | 1515 | * __stop_tx_rs485() must be called only when both FIFO and |
---|
.. | .. |
---|
1534 | 1518 | */ |
---|
1535 | 1519 | if ((lsr & BOTH_EMPTY) != BOTH_EMPTY) |
---|
1536 | 1520 | return; |
---|
1537 | | - |
---|
1538 | | - em485->active_timer = NULL; |
---|
1539 | 1521 | |
---|
1540 | 1522 | __stop_tx_rs485(p); |
---|
1541 | 1523 | } |
---|
.. | .. |
---|
1571 | 1553 | return; |
---|
1572 | 1554 | #endif |
---|
1573 | 1555 | |
---|
1574 | | - if (!(up->ier & UART_IER_THRI)) { |
---|
1575 | | - up->ier |= UART_IER_THRI; |
---|
1576 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
---|
1577 | | - up->ier |= UART_IER_PTIME; |
---|
1578 | | -#endif |
---|
1579 | | - serial_port_out(port, UART_IER, up->ier); |
---|
1580 | | - |
---|
| 1556 | + if (serial8250_set_THRI(up)) { |
---|
1581 | 1557 | if (up->bugs & UART_BUG_TXEN) { |
---|
1582 | 1558 | unsigned char lsr; |
---|
1583 | 1559 | |
---|
.. | .. |
---|
1597 | 1573 | } |
---|
1598 | 1574 | } |
---|
1599 | 1575 | |
---|
1600 | | -static inline void start_tx_rs485(struct uart_port *port) |
---|
| 1576 | +/** |
---|
| 1577 | + * serial8250_em485_start_tx() - generic ->rs485_start_tx() callback |
---|
| 1578 | + * @up: uart 8250 port |
---|
| 1579 | + * |
---|
| 1580 | + * Generic callback usable by 8250 uart drivers to start rs485 transmission. |
---|
| 1581 | + * Assumes that setting the RTS bit in the MCR register means RTS is high. |
---|
| 1582 | + * (Some chips use inverse semantics.) Further assumes that reception is |
---|
| 1583 | + * stoppable by disabling the UART_IER_RDI interrupt. (Some chips set the |
---|
| 1584 | + * UART_LSR_DR bit even when UART_IER_RDI is disabled, foiling this approach.) |
---|
| 1585 | + */ |
---|
| 1586 | +void serial8250_em485_start_tx(struct uart_8250_port *up) |
---|
1601 | 1587 | { |
---|
1602 | | - struct uart_8250_port *up = up_to_u8250p(port); |
---|
1603 | | - struct uart_8250_em485 *em485 = up->em485; |
---|
1604 | | - unsigned char mcr; |
---|
| 1588 | + unsigned char mcr = serial8250_in_MCR(up); |
---|
1605 | 1589 | |
---|
1606 | 1590 | if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) |
---|
1607 | 1591 | serial8250_stop_rx(&up->port); |
---|
1608 | 1592 | |
---|
| 1593 | + if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) |
---|
| 1594 | + mcr |= UART_MCR_RTS; |
---|
| 1595 | + else |
---|
| 1596 | + mcr &= ~UART_MCR_RTS; |
---|
| 1597 | + serial8250_out_MCR(up, mcr); |
---|
| 1598 | +} |
---|
| 1599 | +EXPORT_SYMBOL_GPL(serial8250_em485_start_tx); |
---|
| 1600 | + |
---|
| 1601 | +static inline void start_tx_rs485(struct uart_port *port) |
---|
| 1602 | +{ |
---|
| 1603 | + struct uart_8250_port *up = up_to_u8250p(port); |
---|
| 1604 | + struct uart_8250_em485 *em485 = up->em485; |
---|
| 1605 | + |
---|
| 1606 | + /* |
---|
| 1607 | + * While serial8250_em485_handle_stop_tx() is a noop if |
---|
| 1608 | + * em485->active_timer != &em485->stop_tx_timer, it might happen that |
---|
| 1609 | + * the timer is still armed and triggers only after the current bunch of |
---|
| 1610 | + * chars is send and em485->active_timer == &em485->stop_tx_timer again. |
---|
| 1611 | + * So cancel the timer. There is still a theoretical race condition if |
---|
| 1612 | + * the timer is already running and only comes around to check for |
---|
| 1613 | + * em485->active_timer when &em485->stop_tx_timer is armed again. |
---|
| 1614 | + */ |
---|
| 1615 | + if (em485->active_timer == &em485->stop_tx_timer) |
---|
| 1616 | + hrtimer_try_to_cancel(&em485->stop_tx_timer); |
---|
| 1617 | + |
---|
1609 | 1618 | em485->active_timer = NULL; |
---|
1610 | 1619 | |
---|
1611 | | - mcr = serial8250_in_MCR(up); |
---|
1612 | | - if (!!(up->port.rs485.flags & SER_RS485_RTS_ON_SEND) != |
---|
1613 | | - !!(mcr & UART_MCR_RTS)) { |
---|
1614 | | - if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) |
---|
1615 | | - mcr |= UART_MCR_RTS; |
---|
1616 | | - else |
---|
1617 | | - mcr &= ~UART_MCR_RTS; |
---|
1618 | | - serial8250_out_MCR(up, mcr); |
---|
| 1620 | + if (em485->tx_stopped) { |
---|
| 1621 | + em485->tx_stopped = false; |
---|
| 1622 | + |
---|
| 1623 | + up->rs485_start_tx(up); |
---|
1619 | 1624 | |
---|
1620 | 1625 | if (up->port.rs485.delay_rts_before_send > 0) { |
---|
1621 | 1626 | em485->active_timer = &em485->start_tx_timer; |
---|
.. | .. |
---|
1681 | 1686 | if (up->bugs & UART_BUG_NOMSR) |
---|
1682 | 1687 | return; |
---|
1683 | 1688 | |
---|
| 1689 | + mctrl_gpio_disable_ms(up->gpios); |
---|
| 1690 | + |
---|
1684 | 1691 | up->ier &= ~UART_IER_MSI; |
---|
1685 | 1692 | serial_port_out(port, UART_IER, up->ier); |
---|
1686 | 1693 | } |
---|
.. | .. |
---|
1692 | 1699 | /* no MSR capabilities */ |
---|
1693 | 1700 | if (up->bugs & UART_BUG_NOMSR) |
---|
1694 | 1701 | return; |
---|
| 1702 | + |
---|
| 1703 | + mctrl_gpio_enable_ms(up->gpios); |
---|
1695 | 1704 | |
---|
1696 | 1705 | up->ier |= UART_IER_MSI; |
---|
1697 | 1706 | |
---|
.. | .. |
---|
1748 | 1757 | lsr &= port->read_status_mask; |
---|
1749 | 1758 | |
---|
1750 | 1759 | if (lsr & UART_LSR_BI) { |
---|
1751 | | - pr_debug("%s: handling break\n", __func__); |
---|
| 1760 | + dev_dbg(port->dev, "handling break\n"); |
---|
1752 | 1761 | flag = TTY_BREAK; |
---|
1753 | 1762 | } else if (lsr & UART_LSR_PE) |
---|
1754 | 1763 | flag = TTY_PARITY; |
---|
1755 | 1764 | else if (lsr & UART_LSR_FE) |
---|
1756 | 1765 | flag = TTY_FRAME; |
---|
1757 | 1766 | } |
---|
1758 | | - if (uart_handle_sysrq_char(port, ch)) |
---|
| 1767 | + if (uart_prepare_sysrq_char(port, ch)) |
---|
1759 | 1768 | return; |
---|
1760 | 1769 | |
---|
1761 | 1770 | uart_insert_char(port, lsr, UART_LSR_OE, ch, flag); |
---|
.. | .. |
---|
1791 | 1800 | int count; |
---|
1792 | 1801 | |
---|
1793 | 1802 | if (port->x_char) { |
---|
1794 | | - serial_out(up, UART_TX, port->x_char); |
---|
1795 | | - port->icount.tx++; |
---|
1796 | | - port->x_char = 0; |
---|
| 1803 | + uart_xchar_out(port, UART_TX); |
---|
1797 | 1804 | return; |
---|
1798 | 1805 | } |
---|
1799 | 1806 | if (uart_tx_stopped(port)) { |
---|
.. | .. |
---|
1808 | 1815 | count = up->tx_loadsz; |
---|
1809 | 1816 | do { |
---|
1810 | 1817 | serial_out(up, UART_TX, xmit->buf[xmit->tail]); |
---|
| 1818 | + if (up->bugs & UART_BUG_TXRACE) { |
---|
| 1819 | + /* |
---|
| 1820 | + * The Aspeed BMC virtual UARTs have a bug where data |
---|
| 1821 | + * may get stuck in the BMC's Tx FIFO from bursts of |
---|
| 1822 | + * writes on the APB interface. |
---|
| 1823 | + * |
---|
| 1824 | + * Delay back-to-back writes by a read cycle to avoid |
---|
| 1825 | + * stalling the VUART. Read a register that won't have |
---|
| 1826 | + * side-effects and discard the result. |
---|
| 1827 | + */ |
---|
| 1828 | + serial_in(up, UART_SCR); |
---|
| 1829 | + } |
---|
1811 | 1830 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
---|
1812 | 1831 | port->icount.tx++; |
---|
1813 | 1832 | if (uart_circ_empty(xmit)) |
---|
.. | .. |
---|
1869 | 1888 | return up->dma->rx_dma(up); |
---|
1870 | 1889 | #else |
---|
1871 | 1890 | switch (iir & 0x3f) { |
---|
| 1891 | + case UART_IIR_RDI: |
---|
| 1892 | + if (!up->dma->rx_running) |
---|
| 1893 | + break; |
---|
| 1894 | + fallthrough; |
---|
| 1895 | + case UART_IIR_RLSI: |
---|
1872 | 1896 | case UART_IIR_RX_TIMEOUT: |
---|
1873 | 1897 | serial8250_rx_dma_flush(up); |
---|
1874 | | - /* fall-through */ |
---|
1875 | | - case UART_IIR_RLSI: |
---|
1876 | 1898 | return true; |
---|
1877 | 1899 | } |
---|
1878 | 1900 | return up->dma->rx_dma(up); |
---|
.. | .. |
---|
1887 | 1909 | unsigned char status; |
---|
1888 | 1910 | unsigned long flags; |
---|
1889 | 1911 | struct uart_8250_port *up = up_to_u8250p(port); |
---|
| 1912 | +#ifndef CONFIG_ARCH_ROCKCHIP |
---|
| 1913 | + struct tty_port *tport = &port->state->port; |
---|
1890 | 1914 | bool skip_rx = false; |
---|
| 1915 | +#endif |
---|
1891 | 1916 | |
---|
1892 | 1917 | if (iir & UART_IIR_NO_INT) |
---|
1893 | 1918 | return 0; |
---|
.. | .. |
---|
1896 | 1921 | |
---|
1897 | 1922 | status = serial_port_in(port, UART_LSR); |
---|
1898 | 1923 | |
---|
| 1924 | +#ifdef CONFIG_ARCH_ROCKCHIP |
---|
| 1925 | + if (status & (UART_LSR_DR | UART_LSR_BI)) { |
---|
| 1926 | + int dma_err = -1; |
---|
| 1927 | + |
---|
| 1928 | + if (up->dma && up->dma->rxchan) |
---|
| 1929 | + dma_err = handle_rx_dma(up, iir); |
---|
| 1930 | + |
---|
| 1931 | + if (!up->dma || dma_err) |
---|
| 1932 | + status = serial8250_rx_chars(up, status); |
---|
| 1933 | + } |
---|
| 1934 | +#else |
---|
1899 | 1935 | /* |
---|
1900 | 1936 | * If port is stopped and there are no error conditions in the |
---|
1901 | 1937 | * FIFO, then don't drain the FIFO, as this may lead to TTY buffer |
---|
.. | .. |
---|
1910 | 1946 | skip_rx = true; |
---|
1911 | 1947 | |
---|
1912 | 1948 | if (status & (UART_LSR_DR | UART_LSR_BI) && !skip_rx) { |
---|
1913 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
---|
1914 | | - int dma_err = -1; |
---|
| 1949 | + struct irq_data *d; |
---|
1915 | 1950 | |
---|
1916 | | - if (up->dma && up->dma->rxchan) |
---|
1917 | | - dma_err = handle_rx_dma(up, iir); |
---|
1918 | | - |
---|
1919 | | - if (!up->dma || dma_err) |
---|
1920 | | - status = serial8250_rx_chars(up, status); |
---|
1921 | | -#else |
---|
| 1951 | + d = irq_get_irq_data(port->irq); |
---|
| 1952 | + if (d && irqd_is_wakeup_set(d)) |
---|
| 1953 | + pm_wakeup_event(tport->tty->dev, 0); |
---|
1922 | 1954 | if (!up->dma || handle_rx_dma(up, iir)) |
---|
1923 | 1955 | status = serial8250_rx_chars(up, status); |
---|
1924 | | -#endif |
---|
1925 | 1956 | } |
---|
| 1957 | +#endif |
---|
1926 | 1958 | serial8250_modem_status(up); |
---|
1927 | 1959 | #ifdef CONFIG_ARCH_ROCKCHIP |
---|
1928 | 1960 | if ((!up->dma || (up->dma && (!up->dma->txchan || up->dma->tx_err))) && |
---|
1929 | 1961 | ((iir & 0xf) == UART_IIR_THRI)) |
---|
1930 | 1962 | serial8250_tx_chars(up); |
---|
1931 | 1963 | #else |
---|
1932 | | - if ((!up->dma || up->dma->tx_err) && (status & UART_LSR_THRE) && |
---|
1933 | | - (up->ier & UART_IER_THRI)) |
---|
| 1964 | + if ((!up->dma || (up->dma && up->dma->tx_err)) && |
---|
| 1965 | + (status & UART_LSR_THRE)) |
---|
1934 | 1966 | serial8250_tx_chars(up); |
---|
1935 | 1967 | #endif |
---|
1936 | 1968 | |
---|
.. | .. |
---|
1950 | 1982 | port->name); |
---|
1951 | 1983 | } |
---|
1952 | 1984 | #endif |
---|
1953 | | - spin_unlock_irqrestore(&port->lock, flags); |
---|
| 1985 | + uart_unlock_and_check_sysrq(port, flags); |
---|
1954 | 1986 | return 1; |
---|
1955 | 1987 | } |
---|
1956 | 1988 | EXPORT_SYMBOL_GPL(serial8250_handle_irq); |
---|
.. | .. |
---|
1997 | 2029 | static unsigned int serial8250_tx_empty(struct uart_port *port) |
---|
1998 | 2030 | { |
---|
1999 | 2031 | struct uart_8250_port *up = up_to_u8250p(port); |
---|
| 2032 | + unsigned int result = 0; |
---|
2000 | 2033 | unsigned long flags; |
---|
2001 | 2034 | unsigned int lsr; |
---|
2002 | 2035 | |
---|
2003 | 2036 | serial8250_rpm_get(up); |
---|
2004 | 2037 | |
---|
2005 | 2038 | spin_lock_irqsave(&port->lock, flags); |
---|
2006 | | - lsr = serial_port_in(port, UART_LSR); |
---|
2007 | | - up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
---|
| 2039 | + if (!serial8250_tx_dma_running(up)) { |
---|
| 2040 | + lsr = serial_port_in(port, UART_LSR); |
---|
| 2041 | + up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
---|
| 2042 | + |
---|
| 2043 | + if ((lsr & BOTH_EMPTY) == BOTH_EMPTY) |
---|
| 2044 | + result = TIOCSER_TEMT; |
---|
| 2045 | + } |
---|
2008 | 2046 | spin_unlock_irqrestore(&port->lock, flags); |
---|
2009 | 2047 | |
---|
2010 | 2048 | serial8250_rpm_put(up); |
---|
2011 | 2049 | |
---|
2012 | | - return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0; |
---|
| 2050 | + return result; |
---|
2013 | 2051 | } |
---|
2014 | 2052 | |
---|
2015 | 2053 | unsigned int serial8250_do_get_mctrl(struct uart_port *port) |
---|
2016 | 2054 | { |
---|
2017 | 2055 | struct uart_8250_port *up = up_to_u8250p(port); |
---|
2018 | 2056 | unsigned int status; |
---|
2019 | | - unsigned int ret; |
---|
| 2057 | + unsigned int val; |
---|
2020 | 2058 | |
---|
2021 | 2059 | serial8250_rpm_get(up); |
---|
2022 | 2060 | status = serial8250_modem_status(up); |
---|
2023 | 2061 | serial8250_rpm_put(up); |
---|
2024 | 2062 | |
---|
2025 | | - ret = 0; |
---|
2026 | | - if (status & UART_MSR_DCD) |
---|
2027 | | - ret |= TIOCM_CAR; |
---|
2028 | | - if (status & UART_MSR_RI) |
---|
2029 | | - ret |= TIOCM_RNG; |
---|
2030 | | - if (status & UART_MSR_DSR) |
---|
2031 | | - ret |= TIOCM_DSR; |
---|
2032 | | - if (status & UART_MSR_CTS) |
---|
2033 | | - ret |= TIOCM_CTS; |
---|
2034 | | - return ret; |
---|
| 2063 | + val = serial8250_MSR_to_TIOCM(status); |
---|
| 2064 | + if (up->gpios) |
---|
| 2065 | + return mctrl_gpio_get(up->gpios, &val); |
---|
| 2066 | + |
---|
| 2067 | + return val; |
---|
2035 | 2068 | } |
---|
2036 | 2069 | EXPORT_SYMBOL_GPL(serial8250_do_get_mctrl); |
---|
2037 | 2070 | |
---|
.. | .. |
---|
2045 | 2078 | void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl) |
---|
2046 | 2079 | { |
---|
2047 | 2080 | struct uart_8250_port *up = up_to_u8250p(port); |
---|
2048 | | - unsigned char mcr = 0; |
---|
| 2081 | + unsigned char mcr; |
---|
2049 | 2082 | |
---|
2050 | | - if (mctrl & TIOCM_RTS) |
---|
2051 | | - mcr |= UART_MCR_RTS; |
---|
2052 | | - if (mctrl & TIOCM_DTR) |
---|
2053 | | - mcr |= UART_MCR_DTR; |
---|
2054 | | - if (mctrl & TIOCM_OUT1) |
---|
2055 | | - mcr |= UART_MCR_OUT1; |
---|
2056 | | - if (mctrl & TIOCM_OUT2) |
---|
2057 | | - mcr |= UART_MCR_OUT2; |
---|
2058 | | - if (mctrl & TIOCM_LOOP) |
---|
2059 | | - mcr |= UART_MCR_LOOP; |
---|
| 2083 | + mcr = serial8250_TIOCM_to_MCR(mctrl); |
---|
2060 | 2084 | |
---|
2061 | 2085 | mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; |
---|
2062 | 2086 | |
---|
.. | .. |
---|
2066 | 2090 | |
---|
2067 | 2091 | static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
---|
2068 | 2092 | { |
---|
| 2093 | + if (port->rs485.flags & SER_RS485_ENABLED) |
---|
| 2094 | + return; |
---|
| 2095 | + |
---|
2069 | 2096 | if (port->set_mctrl) |
---|
2070 | 2097 | port->set_mctrl(port, mctrl); |
---|
2071 | 2098 | else |
---|
.. | .. |
---|
2245 | 2272 | enable_rsa(up); |
---|
2246 | 2273 | #endif |
---|
2247 | 2274 | |
---|
2248 | | - if (port->type == PORT_XR17V35X) { |
---|
2249 | | - /* |
---|
2250 | | - * First enable access to IER [7:5], ISR [5:4], FCR [5:4], |
---|
2251 | | - * MCR [7:5] and MSR [7:0] |
---|
2252 | | - */ |
---|
2253 | | - serial_port_out(port, UART_XR_EFR, UART_EFR_ECB); |
---|
2254 | | - |
---|
2255 | | - /* |
---|
2256 | | - * Make sure all interrups are masked until initialization is |
---|
2257 | | - * complete and the FIFOs are cleared |
---|
2258 | | - */ |
---|
2259 | | - serial_port_out(port, UART_IER, 0); |
---|
2260 | | - } |
---|
2261 | | - |
---|
2262 | 2275 | /* |
---|
2263 | 2276 | * Clear the FIFO buffers and disable them. |
---|
2264 | 2277 | * (they will be reenabled in set_termios()) |
---|
.. | .. |
---|
2272 | 2285 | serial_port_in(port, UART_RX); |
---|
2273 | 2286 | serial_port_in(port, UART_IIR); |
---|
2274 | 2287 | serial_port_in(port, UART_MSR); |
---|
2275 | | - if ((port->type == PORT_XR17V35X) || (port->type == PORT_XR17D15X)) |
---|
2276 | | - serial_port_in(port, UART_EXAR_INT0); |
---|
2277 | 2288 | |
---|
2278 | 2289 | /* |
---|
2279 | 2290 | * At this point, there's no way the LSR could still be 0xff; |
---|
.. | .. |
---|
2282 | 2293 | */ |
---|
2283 | 2294 | if (!(port->flags & UPF_BUGGY_UART) && |
---|
2284 | 2295 | (serial_port_in(port, UART_LSR) == 0xff)) { |
---|
2285 | | - pr_info_ratelimited("%s: LSR safety check engaged!\n", port->name); |
---|
| 2296 | + dev_info_ratelimited(port->dev, "LSR safety check engaged!\n"); |
---|
2286 | 2297 | retval = -ENODEV; |
---|
2287 | 2298 | goto out; |
---|
2288 | 2299 | } |
---|
.. | .. |
---|
2314 | 2325 | (port->type == PORT_ALTR_16550_F128)) && (port->fifosize > 1)) { |
---|
2315 | 2326 | /* Bounds checking of TX threshold (valid 0 to fifosize-2) */ |
---|
2316 | 2327 | if ((up->tx_loadsz < 2) || (up->tx_loadsz > port->fifosize)) { |
---|
2317 | | - pr_err("%s TX FIFO Threshold errors, skipping\n", |
---|
2318 | | - port->name); |
---|
| 2328 | + dev_err(port->dev, "TX FIFO Threshold errors, skipping\n"); |
---|
2319 | 2329 | } else { |
---|
2320 | 2330 | serial_port_out(port, UART_ALTR_AFR, |
---|
2321 | 2331 | UART_ALTR_EN_TXFIFO_LW); |
---|
.. | .. |
---|
2419 | 2429 | if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { |
---|
2420 | 2430 | if (!(up->bugs & UART_BUG_TXEN)) { |
---|
2421 | 2431 | up->bugs |= UART_BUG_TXEN; |
---|
2422 | | - pr_debug("%s - enabling bad tx status workarounds\n", |
---|
2423 | | - port->name); |
---|
| 2432 | + dev_dbg(port->dev, "enabling bad tx status workarounds\n"); |
---|
2424 | 2433 | } |
---|
2425 | 2434 | } else { |
---|
2426 | 2435 | up->bugs &= ~UART_BUG_TXEN; |
---|
.. | .. |
---|
2438 | 2447 | serial_port_in(port, UART_RX); |
---|
2439 | 2448 | serial_port_in(port, UART_IIR); |
---|
2440 | 2449 | serial_port_in(port, UART_MSR); |
---|
2441 | | - if ((port->type == PORT_XR17V35X) || (port->type == PORT_XR17D15X)) |
---|
2442 | | - serial_port_in(port, UART_EXAR_INT0); |
---|
2443 | 2450 | up->lsr_saved_flags = 0; |
---|
2444 | 2451 | up->msr_saved_flags = 0; |
---|
2445 | 2452 | |
---|
.. | .. |
---|
2447 | 2454 | * Request DMA channels for both RX and TX. |
---|
2448 | 2455 | */ |
---|
2449 | 2456 | if (up->dma) { |
---|
2450 | | - retval = serial8250_request_dma(up); |
---|
2451 | | - if (retval) { |
---|
| 2457 | + const char *msg = NULL; |
---|
| 2458 | + |
---|
| 2459 | + if (uart_console(port)) |
---|
| 2460 | + msg = "forbid DMA for kernel console"; |
---|
| 2461 | + else if (serial8250_request_dma(up)) |
---|
2452 | 2462 | #ifdef CONFIG_ARCH_ROCKCHIP |
---|
2453 | | - pr_warn_ratelimited("%s - failed to request DMA, use interrupt mode\n", |
---|
2454 | | - port->name); |
---|
| 2463 | + msg = "failed to request DMA, use interrupt mode"; |
---|
2455 | 2464 | #else |
---|
2456 | | - pr_warn_ratelimited("%s - failed to request DMA\n", |
---|
2457 | | - port->name); |
---|
| 2465 | + msg = "failed to request DMA"; |
---|
2458 | 2466 | #endif |
---|
| 2467 | + if (msg) { |
---|
| 2468 | + dev_warn_ratelimited(port->dev, "%s\n", msg); |
---|
2459 | 2469 | up->dma = NULL; |
---|
2460 | 2470 | } |
---|
2461 | 2471 | } |
---|
.. | .. |
---|
2553 | 2563 | serial8250_do_shutdown(port); |
---|
2554 | 2564 | } |
---|
2555 | 2565 | |
---|
2556 | | -/* |
---|
2557 | | - * XR17V35x UARTs have an extra fractional divisor register (DLD) |
---|
2558 | | - * Calculate divisor with extra 4-bit fractional portion |
---|
2559 | | - */ |
---|
2560 | | -static unsigned int xr17v35x_get_divisor(struct uart_8250_port *up, |
---|
2561 | | - unsigned int baud, |
---|
2562 | | - unsigned int *frac) |
---|
2563 | | -{ |
---|
2564 | | - struct uart_port *port = &up->port; |
---|
2565 | | - unsigned int quot_16; |
---|
2566 | | - |
---|
2567 | | - quot_16 = DIV_ROUND_CLOSEST(port->uartclk, baud); |
---|
2568 | | - *frac = quot_16 & 0x0f; |
---|
2569 | | - |
---|
2570 | | - return quot_16 >> 4; |
---|
2571 | | -} |
---|
2572 | | - |
---|
2573 | 2566 | /* Nuvoton NPCM UARTs have a custom divisor calculation */ |
---|
2574 | 2567 | static unsigned int npcm_get_divisor(struct uart_8250_port *up, |
---|
2575 | 2568 | unsigned int baud) |
---|
.. | .. |
---|
2597 | 2590 | else if ((port->flags & UPF_MAGIC_MULTIPLIER) && |
---|
2598 | 2591 | baud == (port->uartclk/8)) |
---|
2599 | 2592 | quot = 0x8002; |
---|
2600 | | - else if (up->port.type == PORT_XR17V35X) |
---|
2601 | | - quot = xr17v35x_get_divisor(up, baud, frac); |
---|
2602 | 2593 | else if (up->port.type == PORT_NPCM) |
---|
2603 | 2594 | quot = npcm_get_divisor(up, baud); |
---|
2604 | 2595 | else |
---|
.. | .. |
---|
2700 | 2691 | #ifdef CONFIG_ARCH_ROCKCHIP |
---|
2701 | 2692 | serial_port_out(port, UART_MCR, up->mcr); |
---|
2702 | 2693 | #endif |
---|
2703 | | - |
---|
2704 | | - /* XR17V35x UARTs have an extra fractional divisor register (DLD) */ |
---|
2705 | | - if (up->port.type == PORT_XR17V35X) { |
---|
2706 | | - /* Preserve bits not related to baudrate; DLD[7:4]. */ |
---|
2707 | | - quot_frac |= serial_port_in(port, 0x2) & 0xf0; |
---|
2708 | | - serial_port_out(port, 0x2, quot_frac); |
---|
2709 | | - } |
---|
2710 | 2694 | } |
---|
2711 | 2695 | EXPORT_SYMBOL_GPL(serial8250_do_set_divisor); |
---|
2712 | 2696 | |
---|
.. | .. |
---|
2748 | 2732 | */ |
---|
2749 | 2733 | return uart_get_baud_rate(port, termios, old, min, max); |
---|
2750 | 2734 | } |
---|
| 2735 | + |
---|
| 2736 | +/* |
---|
| 2737 | + * Note in order to avoid the tty port mutex deadlock don't use the next method |
---|
| 2738 | + * within the uart port callbacks. Primarily it's supposed to be utilized to |
---|
| 2739 | + * handle a sudden reference clock rate change. |
---|
| 2740 | + */ |
---|
| 2741 | +void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk) |
---|
| 2742 | +{ |
---|
| 2743 | + struct uart_8250_port *up = up_to_u8250p(port); |
---|
| 2744 | + struct tty_port *tport = &port->state->port; |
---|
| 2745 | + unsigned int baud, quot, frac = 0; |
---|
| 2746 | + struct ktermios *termios; |
---|
| 2747 | + struct tty_struct *tty; |
---|
| 2748 | + unsigned long flags; |
---|
| 2749 | + |
---|
| 2750 | + tty = tty_port_tty_get(tport); |
---|
| 2751 | + if (!tty) { |
---|
| 2752 | + mutex_lock(&tport->mutex); |
---|
| 2753 | + port->uartclk = uartclk; |
---|
| 2754 | + mutex_unlock(&tport->mutex); |
---|
| 2755 | + return; |
---|
| 2756 | + } |
---|
| 2757 | + |
---|
| 2758 | + down_write(&tty->termios_rwsem); |
---|
| 2759 | + mutex_lock(&tport->mutex); |
---|
| 2760 | + |
---|
| 2761 | + if (port->uartclk == uartclk) |
---|
| 2762 | + goto out_lock; |
---|
| 2763 | + |
---|
| 2764 | + port->uartclk = uartclk; |
---|
| 2765 | + |
---|
| 2766 | + if (!tty_port_initialized(tport)) |
---|
| 2767 | + goto out_lock; |
---|
| 2768 | + |
---|
| 2769 | + termios = &tty->termios; |
---|
| 2770 | + |
---|
| 2771 | + baud = serial8250_get_baud_rate(port, termios, NULL); |
---|
| 2772 | + quot = serial8250_get_divisor(port, baud, &frac); |
---|
| 2773 | + |
---|
| 2774 | + serial8250_rpm_get(up); |
---|
| 2775 | + spin_lock_irqsave(&port->lock, flags); |
---|
| 2776 | + |
---|
| 2777 | + uart_update_timeout(port, termios->c_cflag, baud); |
---|
| 2778 | + |
---|
| 2779 | + serial8250_set_divisor(port, baud, quot, frac); |
---|
| 2780 | + serial_port_out(port, UART_LCR, up->lcr); |
---|
| 2781 | + |
---|
| 2782 | + spin_unlock_irqrestore(&port->lock, flags); |
---|
| 2783 | + serial8250_rpm_put(up); |
---|
| 2784 | + |
---|
| 2785 | +out_lock: |
---|
| 2786 | + mutex_unlock(&tport->mutex); |
---|
| 2787 | + up_write(&tty->termios_rwsem); |
---|
| 2788 | + tty_kref_put(tty); |
---|
| 2789 | +} |
---|
| 2790 | +EXPORT_SYMBOL_GPL(serial8250_update_uartclk); |
---|
2751 | 2791 | |
---|
2752 | 2792 | void |
---|
2753 | 2793 | serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, |
---|
.. | .. |
---|
2864 | 2904 | } |
---|
2865 | 2905 | |
---|
2866 | 2906 | #ifdef CONFIG_ARCH_ROCKCHIP |
---|
2867 | | - /* Reset uart to make sure it is idle, then set buad rate */ |
---|
| 2907 | + /* Reset uart to make sure it is idle, then set baud rate */ |
---|
2868 | 2908 | serial_port_out(port, 0x88 >> 2, 0x7); |
---|
2869 | 2909 | #endif |
---|
2870 | 2910 | |
---|
.. | .. |
---|
3002 | 3042 | case UPIO_MEM32BE: |
---|
3003 | 3043 | case UPIO_MEM16: |
---|
3004 | 3044 | case UPIO_MEM: |
---|
3005 | | - if (!port->mapbase) |
---|
| 3045 | + if (!port->mapbase) { |
---|
| 3046 | + ret = -EINVAL; |
---|
3006 | 3047 | break; |
---|
| 3048 | + } |
---|
3007 | 3049 | |
---|
3008 | 3050 | if (!request_mem_region(port->mapbase, size, "serial")) { |
---|
3009 | 3051 | ret = -EBUSY; |
---|
.. | .. |
---|
3011 | 3053 | } |
---|
3012 | 3054 | |
---|
3013 | 3055 | if (port->flags & UPF_IOREMAP) { |
---|
3014 | | - port->membase = ioremap_nocache(port->mapbase, size); |
---|
| 3056 | + port->membase = ioremap(port->mapbase, size); |
---|
3015 | 3057 | if (!port->membase) { |
---|
3016 | 3058 | release_mem_region(port->mapbase, size); |
---|
3017 | 3059 | ret = -ENOMEM; |
---|
.. | .. |
---|
3122 | 3164 | return rxtrig_bytes; |
---|
3123 | 3165 | } |
---|
3124 | 3166 | |
---|
3125 | | -static ssize_t serial8250_get_attr_rx_trig_bytes(struct device *dev, |
---|
| 3167 | +static ssize_t rx_trig_bytes_show(struct device *dev, |
---|
3126 | 3168 | struct device_attribute *attr, char *buf) |
---|
3127 | 3169 | { |
---|
3128 | 3170 | struct tty_port *port = dev_get_drvdata(dev); |
---|
.. | .. |
---|
3168 | 3210 | return ret; |
---|
3169 | 3211 | } |
---|
3170 | 3212 | |
---|
3171 | | -static ssize_t serial8250_set_attr_rx_trig_bytes(struct device *dev, |
---|
| 3213 | +static ssize_t rx_trig_bytes_store(struct device *dev, |
---|
3172 | 3214 | struct device_attribute *attr, const char *buf, size_t count) |
---|
3173 | 3215 | { |
---|
3174 | 3216 | struct tty_port *port = dev_get_drvdata(dev); |
---|
.. | .. |
---|
3189 | 3231 | return count; |
---|
3190 | 3232 | } |
---|
3191 | 3233 | |
---|
3192 | | -static DEVICE_ATTR(rx_trig_bytes, S_IRUSR | S_IWUSR | S_IRGRP, |
---|
3193 | | - serial8250_get_attr_rx_trig_bytes, |
---|
3194 | | - serial8250_set_attr_rx_trig_bytes); |
---|
| 3234 | +static DEVICE_ATTR_RW(rx_trig_bytes); |
---|
3195 | 3235 | |
---|
3196 | 3236 | static struct attribute *serial8250_dev_attrs[] = { |
---|
3197 | 3237 | &dev_attr_rx_trig_bytes.attr, |
---|
3198 | | - NULL, |
---|
3199 | | - }; |
---|
| 3238 | + NULL |
---|
| 3239 | +}; |
---|
3200 | 3240 | |
---|
3201 | 3241 | static struct attribute_group serial8250_dev_attr_group = { |
---|
3202 | 3242 | .attrs = serial8250_dev_attrs, |
---|
3203 | | - }; |
---|
| 3243 | +}; |
---|
3204 | 3244 | |
---|
3205 | 3245 | static void register_dev_spec_attr_grp(struct uart_8250_port *up) |
---|
3206 | 3246 | { |
---|
.. | .. |
---|
3299 | 3339 | struct uart_port *port = &up->port; |
---|
3300 | 3340 | |
---|
3301 | 3341 | spin_lock_init(&port->lock); |
---|
| 3342 | + port->pm = NULL; |
---|
3302 | 3343 | port->ops = &serial8250_pops; |
---|
| 3344 | + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); |
---|
3303 | 3345 | |
---|
3304 | 3346 | up->cur_iotype = 0xFF; |
---|
3305 | 3347 | } |
---|
.. | .. |
---|
3360 | 3402 | |
---|
3361 | 3403 | serial8250_set_divisor(port, baud, quot, frac); |
---|
3362 | 3404 | serial_port_out(port, UART_LCR, up->lcr); |
---|
3363 | | - serial8250_out_MCR(up, UART_MCR_DTR | UART_MCR_RTS); |
---|
| 3405 | + serial8250_out_MCR(up, up->mcr | UART_MCR_DTR | UART_MCR_RTS); |
---|
3364 | 3406 | } |
---|
3365 | 3407 | |
---|
3366 | 3408 | /* |
---|
.. | .. |
---|
3368 | 3410 | * any possible real use of the port... |
---|
3369 | 3411 | * |
---|
3370 | 3412 | * The console_lock must be held when we get here. |
---|
| 3413 | + * |
---|
| 3414 | + * Doing runtime PM is really a bad idea for the kernel console. |
---|
| 3415 | + * Thus, we assume the function is called when device is powered up. |
---|
3371 | 3416 | */ |
---|
3372 | 3417 | void serial8250_console_write(struct uart_8250_port *up, const char *s, |
---|
3373 | 3418 | unsigned int count) |
---|
3374 | 3419 | { |
---|
| 3420 | + struct uart_8250_em485 *em485 = up->em485; |
---|
3375 | 3421 | struct uart_port *port = &up->port; |
---|
3376 | 3422 | unsigned long flags; |
---|
3377 | 3423 | unsigned int ier; |
---|
.. | .. |
---|
3379 | 3425 | |
---|
3380 | 3426 | touch_nmi_watchdog(); |
---|
3381 | 3427 | |
---|
3382 | | - serial8250_rpm_get(up); |
---|
3383 | | - |
---|
3384 | | - if (port->sysrq || oops_in_progress) |
---|
3385 | | - locked = 0; |
---|
3386 | | - else if (in_kdb_printk()) |
---|
| 3428 | + if (oops_in_progress) |
---|
3387 | 3429 | locked = spin_trylock_irqsave(&port->lock, flags); |
---|
3388 | 3430 | else |
---|
3389 | 3431 | spin_lock_irqsave(&port->lock, flags); |
---|
.. | .. |
---|
3404 | 3446 | up->canary = 0; |
---|
3405 | 3447 | } |
---|
3406 | 3448 | |
---|
| 3449 | + if (em485) { |
---|
| 3450 | + if (em485->tx_stopped) |
---|
| 3451 | + up->rs485_start_tx(up); |
---|
| 3452 | + mdelay(port->rs485.delay_rts_before_send); |
---|
| 3453 | + } |
---|
| 3454 | + |
---|
3407 | 3455 | uart_console_write(port, s, count, serial8250_console_putchar); |
---|
3408 | 3456 | |
---|
3409 | 3457 | /* |
---|
.. | .. |
---|
3411 | 3459 | * and restore the IER |
---|
3412 | 3460 | */ |
---|
3413 | 3461 | wait_for_xmitr(up, BOTH_EMPTY); |
---|
| 3462 | + |
---|
| 3463 | + if (em485) { |
---|
| 3464 | + mdelay(port->rs485.delay_rts_after_send); |
---|
| 3465 | + if (em485->tx_stopped) |
---|
| 3466 | + up->rs485_stop_tx(up); |
---|
| 3467 | + } |
---|
| 3468 | + |
---|
3414 | 3469 | serial_port_out(port, UART_IER, ier); |
---|
3415 | 3470 | |
---|
3416 | 3471 | /* |
---|
.. | .. |
---|
3425 | 3480 | |
---|
3426 | 3481 | if (locked) |
---|
3427 | 3482 | spin_unlock_irqrestore(&port->lock, flags); |
---|
3428 | | - serial8250_rpm_put(up); |
---|
3429 | 3483 | } |
---|
3430 | 3484 | |
---|
3431 | 3485 | static unsigned int probe_baud(struct uart_port *port) |
---|
.. | .. |
---|
3449 | 3503 | int bits = 8; |
---|
3450 | 3504 | int parity = 'n'; |
---|
3451 | 3505 | int flow = 'n'; |
---|
| 3506 | + int ret; |
---|
3452 | 3507 | |
---|
3453 | 3508 | if (!port->iobase && !port->membase) |
---|
3454 | 3509 | return -ENODEV; |
---|
.. | .. |
---|
3458 | 3513 | else if (probe) |
---|
3459 | 3514 | baud = probe_baud(port); |
---|
3460 | 3515 | |
---|
3461 | | - return uart_set_options(port, port->cons, baud, parity, bits, flow); |
---|
| 3516 | + ret = uart_set_options(port, port->cons, baud, parity, bits, flow); |
---|
| 3517 | + if (ret) |
---|
| 3518 | + return ret; |
---|
| 3519 | + |
---|
| 3520 | + if (port->dev) |
---|
| 3521 | + pm_runtime_get_sync(port->dev); |
---|
| 3522 | + |
---|
| 3523 | + return 0; |
---|
| 3524 | +} |
---|
| 3525 | + |
---|
| 3526 | +int serial8250_console_exit(struct uart_port *port) |
---|
| 3527 | +{ |
---|
| 3528 | + if (port->dev) |
---|
| 3529 | + pm_runtime_put_sync(port->dev); |
---|
| 3530 | + |
---|
| 3531 | + return 0; |
---|
3462 | 3532 | } |
---|
3463 | 3533 | |
---|
3464 | 3534 | #endif /* CONFIG_SERIAL_8250_CONSOLE */ |
---|