| .. | .. |
|---|
| 8 | 8 | * |
|---|
| 9 | 9 | */ |
|---|
| 10 | 10 | |
|---|
| 11 | +#include <linux/clk.h> |
|---|
| 11 | 12 | #include <linux/device.h> |
|---|
| 12 | 13 | #include <linux/io.h> |
|---|
| 13 | 14 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 26 | 27 | #include <linux/pm_qos.h> |
|---|
| 27 | 28 | #include <linux/pm_wakeirq.h> |
|---|
| 28 | 29 | #include <linux/dma-mapping.h> |
|---|
| 30 | +#include <linux/sys_soc.h> |
|---|
| 29 | 31 | |
|---|
| 30 | 32 | #include "8250.h" |
|---|
| 31 | 33 | |
|---|
| .. | .. |
|---|
| 39 | 41 | * The same errata is applicable to AM335x and DRA7x processors too. |
|---|
| 40 | 42 | */ |
|---|
| 41 | 43 | #define UART_ERRATA_CLOCK_DISABLE (1 << 3) |
|---|
| 44 | +#define UART_HAS_EFR2 BIT(4) |
|---|
| 45 | +#define UART_HAS_RHR_IT_DIS BIT(5) |
|---|
| 46 | +#define UART_RX_TIMEOUT_QUIRK BIT(6) |
|---|
| 42 | 47 | |
|---|
| 43 | 48 | #define OMAP_UART_FCR_RX_TRIG 6 |
|---|
| 44 | 49 | #define OMAP_UART_FCR_TX_TRIG 4 |
|---|
| .. | .. |
|---|
| 92 | 97 | #define OMAP_UART_REV_52 0x0502 |
|---|
| 93 | 98 | #define OMAP_UART_REV_63 0x0603 |
|---|
| 94 | 99 | |
|---|
| 100 | +/* Interrupt Enable Register 2 */ |
|---|
| 101 | +#define UART_OMAP_IER2 0x1B |
|---|
| 102 | +#define UART_OMAP_IER2_RHR_IT_DIS BIT(2) |
|---|
| 103 | + |
|---|
| 104 | +/* Enhanced features register 2 */ |
|---|
| 105 | +#define UART_OMAP_EFR2 0x23 |
|---|
| 106 | +#define UART_OMAP_EFR2_TIMEOUT_BEHAVE BIT(6) |
|---|
| 107 | + |
|---|
| 108 | +/* RX FIFO occupancy indicator */ |
|---|
| 109 | +#define UART_OMAP_RX_LVL 0x19 |
|---|
| 110 | + |
|---|
| 95 | 111 | struct omap8250_priv { |
|---|
| 96 | 112 | int line; |
|---|
| 97 | 113 | u8 habit; |
|---|
| .. | .. |
|---|
| 104 | 120 | u8 delayed_restore; |
|---|
| 105 | 121 | u16 quot; |
|---|
| 106 | 122 | |
|---|
| 123 | + u8 tx_trigger; |
|---|
| 124 | + u8 rx_trigger; |
|---|
| 107 | 125 | bool is_suspending; |
|---|
| 108 | 126 | int wakeirq; |
|---|
| 109 | 127 | int wakeups_enabled; |
|---|
| .. | .. |
|---|
| 117 | 135 | bool throttled; |
|---|
| 118 | 136 | }; |
|---|
| 119 | 137 | |
|---|
| 138 | +struct omap8250_dma_params { |
|---|
| 139 | + u32 rx_size; |
|---|
| 140 | + u8 rx_trigger; |
|---|
| 141 | + u8 tx_trigger; |
|---|
| 142 | +}; |
|---|
| 143 | + |
|---|
| 144 | +struct omap8250_platdata { |
|---|
| 145 | + struct omap8250_dma_params *dma_params; |
|---|
| 146 | + u8 habit; |
|---|
| 147 | +}; |
|---|
| 148 | + |
|---|
| 120 | 149 | #ifdef CONFIG_SERIAL_8250_DMA |
|---|
| 121 | 150 | static void omap_8250_rx_dma_flush(struct uart_8250_port *p); |
|---|
| 122 | 151 | #else |
|---|
| .. | .. |
|---|
| 128 | 157 | return readl(up->port.membase + (reg << up->port.regshift)); |
|---|
| 129 | 158 | } |
|---|
| 130 | 159 | |
|---|
| 131 | | -static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
|---|
| 160 | +/* |
|---|
| 161 | + * Called on runtime PM resume path from omap8250_restore_regs(), and |
|---|
| 162 | + * omap8250_set_mctrl(). |
|---|
| 163 | + */ |
|---|
| 164 | +static void __omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
|---|
| 132 | 165 | { |
|---|
| 133 | 166 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 134 | 167 | struct omap8250_priv *priv = up->port.private_data; |
|---|
| .. | .. |
|---|
| 136 | 169 | |
|---|
| 137 | 170 | serial8250_do_set_mctrl(port, mctrl); |
|---|
| 138 | 171 | |
|---|
| 139 | | - /* |
|---|
| 140 | | - * Turn off autoRTS if RTS is lowered and restore autoRTS setting |
|---|
| 141 | | - * if RTS is raised |
|---|
| 142 | | - */ |
|---|
| 143 | | - lcr = serial_in(up, UART_LCR); |
|---|
| 144 | | - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
|---|
| 145 | | - if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS)) |
|---|
| 146 | | - priv->efr |= UART_EFR_RTS; |
|---|
| 147 | | - else |
|---|
| 148 | | - priv->efr &= ~UART_EFR_RTS; |
|---|
| 149 | | - serial_out(up, UART_EFR, priv->efr); |
|---|
| 150 | | - serial_out(up, UART_LCR, lcr); |
|---|
| 172 | + if (!mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS)) { |
|---|
| 173 | + /* |
|---|
| 174 | + * Turn off autoRTS if RTS is lowered and restore autoRTS |
|---|
| 175 | + * setting if RTS is raised |
|---|
| 176 | + */ |
|---|
| 177 | + lcr = serial_in(up, UART_LCR); |
|---|
| 178 | + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
|---|
| 179 | + if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS)) |
|---|
| 180 | + priv->efr |= UART_EFR_RTS; |
|---|
| 181 | + else |
|---|
| 182 | + priv->efr &= ~UART_EFR_RTS; |
|---|
| 183 | + serial_out(up, UART_EFR, priv->efr); |
|---|
| 184 | + serial_out(up, UART_LCR, lcr); |
|---|
| 185 | + } |
|---|
| 186 | +} |
|---|
| 187 | + |
|---|
| 188 | +static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
|---|
| 189 | +{ |
|---|
| 190 | + int err; |
|---|
| 191 | + |
|---|
| 192 | + err = pm_runtime_resume_and_get(port->dev); |
|---|
| 193 | + if (err) |
|---|
| 194 | + return; |
|---|
| 195 | + |
|---|
| 196 | + __omap8250_set_mctrl(port, mctrl); |
|---|
| 197 | + |
|---|
| 198 | + pm_runtime_mark_last_busy(port->dev); |
|---|
| 199 | + pm_runtime_put_autosuspend(port->dev); |
|---|
| 151 | 200 | } |
|---|
| 152 | 201 | |
|---|
| 153 | 202 | /* |
|---|
| .. | .. |
|---|
| 162 | 211 | static void omap_8250_mdr1_errataset(struct uart_8250_port *up, |
|---|
| 163 | 212 | struct omap8250_priv *priv) |
|---|
| 164 | 213 | { |
|---|
| 165 | | - u8 timeout = 255; |
|---|
| 166 | | - |
|---|
| 167 | 214 | serial_out(up, UART_OMAP_MDR1, priv->mdr1); |
|---|
| 168 | 215 | udelay(2); |
|---|
| 169 | 216 | serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_XMIT | |
|---|
| 170 | 217 | UART_FCR_CLEAR_RCVR); |
|---|
| 171 | | - /* |
|---|
| 172 | | - * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and |
|---|
| 173 | | - * TX_FIFO_E bit is 1. |
|---|
| 174 | | - */ |
|---|
| 175 | | - while (UART_LSR_THRE != (serial_in(up, UART_LSR) & |
|---|
| 176 | | - (UART_LSR_THRE | UART_LSR_DR))) { |
|---|
| 177 | | - timeout--; |
|---|
| 178 | | - if (!timeout) { |
|---|
| 179 | | - /* Should *never* happen. we warn and carry on */ |
|---|
| 180 | | - dev_crit(up->port.dev, "Errata i202: timedout %x\n", |
|---|
| 181 | | - serial_in(up, UART_LSR)); |
|---|
| 182 | | - break; |
|---|
| 183 | | - } |
|---|
| 184 | | - udelay(1); |
|---|
| 185 | | - } |
|---|
| 186 | 218 | } |
|---|
| 187 | 219 | |
|---|
| 188 | 220 | static void omap_8250_get_divisor(struct uart_port *port, unsigned int baud, |
|---|
| .. | .. |
|---|
| 261 | 293 | { |
|---|
| 262 | 294 | struct omap8250_priv *priv = up->port.private_data; |
|---|
| 263 | 295 | struct uart_8250_dma *dma = up->dma; |
|---|
| 296 | + u8 mcr = serial8250_in_MCR(up); |
|---|
| 264 | 297 | |
|---|
| 265 | 298 | if (dma && dma->tx_running) { |
|---|
| 266 | 299 | /* |
|---|
| .. | .. |
|---|
| 277 | 310 | serial_out(up, UART_EFR, UART_EFR_ECB); |
|---|
| 278 | 311 | |
|---|
| 279 | 312 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
|---|
| 280 | | - serial8250_out_MCR(up, UART_MCR_TCRTLR); |
|---|
| 313 | + serial8250_out_MCR(up, mcr | UART_MCR_TCRTLR); |
|---|
| 281 | 314 | serial_out(up, UART_FCR, up->fcr); |
|---|
| 282 | 315 | |
|---|
| 283 | 316 | omap8250_update_scr(up, priv); |
|---|
| .. | .. |
|---|
| 287 | 320 | serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_RESTORE(16) | |
|---|
| 288 | 321 | OMAP_UART_TCR_HALT(52)); |
|---|
| 289 | 322 | serial_out(up, UART_TI752_TLR, |
|---|
| 290 | | - TRIGGER_TLR_MASK(TX_TRIGGER) << UART_TI752_TLR_TX | |
|---|
| 291 | | - TRIGGER_TLR_MASK(RX_TRIGGER) << UART_TI752_TLR_RX); |
|---|
| 323 | + TRIGGER_TLR_MASK(priv->tx_trigger) << UART_TI752_TLR_TX | |
|---|
| 324 | + TRIGGER_TLR_MASK(priv->rx_trigger) << UART_TI752_TLR_RX); |
|---|
| 292 | 325 | |
|---|
| 293 | 326 | serial_out(up, UART_LCR, 0); |
|---|
| 294 | 327 | |
|---|
| 295 | 328 | /* drop TCR + TLR access, we setup XON/XOFF later */ |
|---|
| 296 | | - serial8250_out_MCR(up, up->mcr); |
|---|
| 329 | + serial8250_out_MCR(up, mcr); |
|---|
| 330 | + |
|---|
| 297 | 331 | serial_out(up, UART_IER, up->ier); |
|---|
| 298 | 332 | |
|---|
| 299 | 333 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
|---|
| .. | .. |
|---|
| 310 | 344 | |
|---|
| 311 | 345 | omap8250_update_mdr1(up, priv); |
|---|
| 312 | 346 | |
|---|
| 313 | | - up->port.ops->set_mctrl(&up->port, up->port.mctrl); |
|---|
| 347 | + __omap8250_set_mctrl(&up->port, up->port.mctrl); |
|---|
| 348 | + |
|---|
| 349 | + if (up->port.rs485.flags & SER_RS485_ENABLED) |
|---|
| 350 | + serial8250_em485_stop_tx(up); |
|---|
| 314 | 351 | } |
|---|
| 315 | 352 | |
|---|
| 316 | 353 | /* |
|---|
| .. | .. |
|---|
| 427 | 464 | * This is because threshold and trigger values are the same. |
|---|
| 428 | 465 | */ |
|---|
| 429 | 466 | up->fcr = UART_FCR_ENABLE_FIFO; |
|---|
| 430 | | - up->fcr |= TRIGGER_FCR_MASK(TX_TRIGGER) << OMAP_UART_FCR_TX_TRIG; |
|---|
| 431 | | - up->fcr |= TRIGGER_FCR_MASK(RX_TRIGGER) << OMAP_UART_FCR_RX_TRIG; |
|---|
| 467 | + up->fcr |= TRIGGER_FCR_MASK(priv->tx_trigger) << OMAP_UART_FCR_TX_TRIG; |
|---|
| 468 | + up->fcr |= TRIGGER_FCR_MASK(priv->rx_trigger) << OMAP_UART_FCR_RX_TRIG; |
|---|
| 432 | 469 | |
|---|
| 433 | 470 | priv->scr = OMAP_UART_SCR_RX_TRIG_GRANU1_MASK | OMAP_UART_SCR_TX_EMPTY | |
|---|
| 434 | 471 | OMAP_UART_SCR_TX_TRIG_GRANU1_MASK; |
|---|
| .. | .. |
|---|
| 443 | 480 | priv->efr = 0; |
|---|
| 444 | 481 | up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF); |
|---|
| 445 | 482 | |
|---|
| 446 | | - if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) { |
|---|
| 483 | + if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW && |
|---|
| 484 | + !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS) && |
|---|
| 485 | + !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_CTS)) { |
|---|
| 447 | 486 | /* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ |
|---|
| 448 | 487 | up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; |
|---|
| 449 | 488 | priv->efr |= UART_EFR_CTS; |
|---|
| .. | .. |
|---|
| 505 | 544 | static void omap_serial_fill_features_erratas(struct uart_8250_port *up, |
|---|
| 506 | 545 | struct omap8250_priv *priv) |
|---|
| 507 | 546 | { |
|---|
| 547 | + const struct soc_device_attribute k3_soc_devices[] = { |
|---|
| 548 | + { .family = "AM65X", }, |
|---|
| 549 | + { .family = "J721E", .revision = "SR1.0" }, |
|---|
| 550 | + { /* sentinel */ } |
|---|
| 551 | + }; |
|---|
| 508 | 552 | u32 mvr, scheme; |
|---|
| 509 | 553 | u16 revision, major, minor; |
|---|
| 510 | 554 | |
|---|
| .. | .. |
|---|
| 552 | 596 | default: |
|---|
| 553 | 597 | break; |
|---|
| 554 | 598 | } |
|---|
| 599 | + |
|---|
| 600 | + /* |
|---|
| 601 | + * AM65x SR1.0, AM65x SR2.0 and J721e SR1.0 don't |
|---|
| 602 | + * don't have RHR_IT_DIS bit in IER2 register. So drop to flag |
|---|
| 603 | + * to enable errata workaround. |
|---|
| 604 | + */ |
|---|
| 605 | + if (soc_device_match(k3_soc_devices)) |
|---|
| 606 | + priv->habit &= ~UART_HAS_RHR_IT_DIS; |
|---|
| 555 | 607 | } |
|---|
| 556 | 608 | |
|---|
| 557 | 609 | static void omap8250_uart_qos_work(struct work_struct *work) |
|---|
| .. | .. |
|---|
| 559 | 611 | struct omap8250_priv *priv; |
|---|
| 560 | 612 | |
|---|
| 561 | 613 | priv = container_of(work, struct omap8250_priv, qos_work); |
|---|
| 562 | | - pm_qos_update_request(&priv->pm_qos_request, priv->latency); |
|---|
| 614 | + cpu_latency_qos_update_request(&priv->pm_qos_request, priv->latency); |
|---|
| 563 | 615 | } |
|---|
| 564 | 616 | |
|---|
| 565 | 617 | #ifdef CONFIG_SERIAL_8250_DMA |
|---|
| .. | .. |
|---|
| 569 | 621 | static irqreturn_t omap8250_irq(int irq, void *dev_id) |
|---|
| 570 | 622 | { |
|---|
| 571 | 623 | struct uart_port *port = dev_id; |
|---|
| 624 | + struct omap8250_priv *priv = port->private_data; |
|---|
| 572 | 625 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 573 | | - unsigned int iir; |
|---|
| 626 | + unsigned int iir, lsr; |
|---|
| 574 | 627 | int ret; |
|---|
| 575 | 628 | |
|---|
| 576 | 629 | #ifdef CONFIG_SERIAL_8250_DMA |
|---|
| .. | .. |
|---|
| 581 | 634 | #endif |
|---|
| 582 | 635 | |
|---|
| 583 | 636 | serial8250_rpm_get(up); |
|---|
| 637 | + lsr = serial_port_in(port, UART_LSR); |
|---|
| 584 | 638 | iir = serial_port_in(port, UART_IIR); |
|---|
| 585 | 639 | ret = serial8250_handle_irq(port, iir); |
|---|
| 640 | + |
|---|
| 641 | + /* |
|---|
| 642 | + * On K3 SoCs, it is observed that RX TIMEOUT is signalled after |
|---|
| 643 | + * FIFO has been drained, in which case a dummy read of RX FIFO |
|---|
| 644 | + * is required to clear RX TIMEOUT condition. |
|---|
| 645 | + */ |
|---|
| 646 | + if (priv->habit & UART_RX_TIMEOUT_QUIRK && |
|---|
| 647 | + (iir & UART_IIR_RX_TIMEOUT) == UART_IIR_RX_TIMEOUT && |
|---|
| 648 | + serial_port_in(port, UART_OMAP_RX_LVL) == 0) { |
|---|
| 649 | + serial_port_in(port, UART_RX); |
|---|
| 650 | + } |
|---|
| 651 | + |
|---|
| 652 | + /* Stop processing interrupts on input overrun */ |
|---|
| 653 | + if ((lsr & UART_LSR_OE) && up->overrun_backoff_time_ms > 0) { |
|---|
| 654 | + unsigned long delay; |
|---|
| 655 | + |
|---|
| 656 | + up->ier = port->serial_in(port, UART_IER); |
|---|
| 657 | + if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) { |
|---|
| 658 | + port->ops->stop_rx(port); |
|---|
| 659 | + } else { |
|---|
| 660 | + /* Keep restarting the timer until |
|---|
| 661 | + * the input overrun subsides. |
|---|
| 662 | + */ |
|---|
| 663 | + cancel_delayed_work(&up->overrun_backoff); |
|---|
| 664 | + } |
|---|
| 665 | + |
|---|
| 666 | + delay = msecs_to_jiffies(up->overrun_backoff_time_ms); |
|---|
| 667 | + schedule_delayed_work(&up->overrun_backoff, delay); |
|---|
| 668 | + } |
|---|
| 669 | + |
|---|
| 586 | 670 | serial8250_rpm_put(up); |
|---|
| 587 | 671 | |
|---|
| 588 | 672 | return IRQ_RETVAL(ret); |
|---|
| .. | .. |
|---|
| 602 | 686 | |
|---|
| 603 | 687 | pm_runtime_get_sync(port->dev); |
|---|
| 604 | 688 | |
|---|
| 605 | | - up->mcr = 0; |
|---|
| 606 | 689 | serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
|---|
| 607 | 690 | |
|---|
| 608 | 691 | serial_out(up, UART_LCR, UART_LCR_WLEN8); |
|---|
| .. | .. |
|---|
| 641 | 724 | priv->wer |= OMAP_UART_TX_WAKEUP_EN; |
|---|
| 642 | 725 | serial_out(up, UART_OMAP_WER, priv->wer); |
|---|
| 643 | 726 | |
|---|
| 644 | | - if (up->dma) |
|---|
| 727 | + if (up->dma && !(priv->habit & UART_HAS_EFR2)) |
|---|
| 645 | 728 | up->dma->rx_dma(up); |
|---|
| 646 | 729 | |
|---|
| 647 | 730 | pm_runtime_mark_last_busy(port->dev); |
|---|
| .. | .. |
|---|
| 666 | 749 | pm_runtime_get_sync(port->dev); |
|---|
| 667 | 750 | |
|---|
| 668 | 751 | serial_out(up, UART_OMAP_WER, 0); |
|---|
| 752 | + if (priv->habit & UART_HAS_EFR2) |
|---|
| 753 | + serial_out(up, UART_OMAP_EFR2, 0x0); |
|---|
| 669 | 754 | |
|---|
| 670 | 755 | up->ier = 0; |
|---|
| 671 | 756 | serial_out(up, UART_IER, 0); |
|---|
| .. | .. |
|---|
| 689 | 774 | static void omap_8250_throttle(struct uart_port *port) |
|---|
| 690 | 775 | { |
|---|
| 691 | 776 | struct omap8250_priv *priv = port->private_data; |
|---|
| 692 | | - struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 693 | 777 | unsigned long flags; |
|---|
| 694 | 778 | |
|---|
| 695 | 779 | pm_runtime_get_sync(port->dev); |
|---|
| 696 | 780 | |
|---|
| 697 | 781 | spin_lock_irqsave(&port->lock, flags); |
|---|
| 698 | | - up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); |
|---|
| 699 | | - serial_out(up, UART_IER, up->ier); |
|---|
| 782 | + port->ops->stop_rx(port); |
|---|
| 700 | 783 | priv->throttled = true; |
|---|
| 701 | 784 | spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 702 | 785 | |
|---|
| 703 | 786 | pm_runtime_mark_last_busy(port->dev); |
|---|
| 704 | 787 | pm_runtime_put_autosuspend(port->dev); |
|---|
| 705 | | -} |
|---|
| 706 | | - |
|---|
| 707 | | -static int omap_8250_rs485_config(struct uart_port *port, |
|---|
| 708 | | - struct serial_rs485 *rs485) |
|---|
| 709 | | -{ |
|---|
| 710 | | - struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 711 | | - |
|---|
| 712 | | - /* Clamp the delays to [0, 100ms] */ |
|---|
| 713 | | - rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U); |
|---|
| 714 | | - rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U); |
|---|
| 715 | | - |
|---|
| 716 | | - port->rs485 = *rs485; |
|---|
| 717 | | - |
|---|
| 718 | | - /* |
|---|
| 719 | | - * Both serial8250_em485_init and serial8250_em485_destroy |
|---|
| 720 | | - * are idempotent |
|---|
| 721 | | - */ |
|---|
| 722 | | - if (rs485->flags & SER_RS485_ENABLED) { |
|---|
| 723 | | - int ret = serial8250_em485_init(up); |
|---|
| 724 | | - |
|---|
| 725 | | - if (ret) { |
|---|
| 726 | | - rs485->flags &= ~SER_RS485_ENABLED; |
|---|
| 727 | | - port->rs485.flags &= ~SER_RS485_ENABLED; |
|---|
| 728 | | - } |
|---|
| 729 | | - return ret; |
|---|
| 730 | | - } |
|---|
| 731 | | - |
|---|
| 732 | | - serial8250_em485_destroy(up); |
|---|
| 733 | | - |
|---|
| 734 | | - return 0; |
|---|
| 735 | 788 | } |
|---|
| 736 | 789 | |
|---|
| 737 | 790 | static void omap_8250_unthrottle(struct uart_port *port) |
|---|
| .. | .. |
|---|
| 747 | 800 | if (up->dma) |
|---|
| 748 | 801 | up->dma->rx_dma(up); |
|---|
| 749 | 802 | up->ier |= UART_IER_RLSI | UART_IER_RDI; |
|---|
| 803 | + port->read_status_mask |= UART_LSR_DR; |
|---|
| 750 | 804 | serial_out(up, UART_IER, up->ier); |
|---|
| 751 | 805 | spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 752 | 806 | |
|---|
| .. | .. |
|---|
| 757 | 811 | #ifdef CONFIG_SERIAL_8250_DMA |
|---|
| 758 | 812 | static int omap_8250_rx_dma(struct uart_8250_port *p); |
|---|
| 759 | 813 | |
|---|
| 814 | +/* Must be called while priv->rx_dma_lock is held */ |
|---|
| 760 | 815 | static void __dma_rx_do_complete(struct uart_8250_port *p) |
|---|
| 761 | 816 | { |
|---|
| 762 | | - struct omap8250_priv *priv = p->port.private_data; |
|---|
| 763 | 817 | struct uart_8250_dma *dma = p->dma; |
|---|
| 764 | 818 | struct tty_port *tty_port = &p->port.state->port; |
|---|
| 819 | + struct omap8250_priv *priv = p->port.private_data; |
|---|
| 820 | + struct dma_chan *rxchan = dma->rxchan; |
|---|
| 821 | + dma_cookie_t cookie; |
|---|
| 765 | 822 | struct dma_tx_state state; |
|---|
| 766 | 823 | int count; |
|---|
| 767 | | - unsigned long flags; |
|---|
| 768 | 824 | int ret; |
|---|
| 769 | | - |
|---|
| 770 | | - spin_lock_irqsave(&priv->rx_dma_lock, flags); |
|---|
| 825 | + u32 reg; |
|---|
| 771 | 826 | |
|---|
| 772 | 827 | if (!dma->rx_running) |
|---|
| 773 | | - goto unlock; |
|---|
| 828 | + goto out; |
|---|
| 774 | 829 | |
|---|
| 830 | + cookie = dma->rx_cookie; |
|---|
| 775 | 831 | dma->rx_running = 0; |
|---|
| 776 | | - dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); |
|---|
| 777 | 832 | |
|---|
| 778 | | - count = dma->rx_size - state.residue; |
|---|
| 779 | | - if (count < dma->rx_size) |
|---|
| 780 | | - dmaengine_terminate_async(dma->rxchan); |
|---|
| 833 | + /* Re-enable RX FIFO interrupt now that transfer is complete */ |
|---|
| 834 | + if (priv->habit & UART_HAS_RHR_IT_DIS) { |
|---|
| 835 | + reg = serial_in(p, UART_OMAP_IER2); |
|---|
| 836 | + reg &= ~UART_OMAP_IER2_RHR_IT_DIS; |
|---|
| 837 | + serial_out(p, UART_OMAP_IER2, UART_OMAP_IER2_RHR_IT_DIS); |
|---|
| 838 | + } |
|---|
| 839 | + |
|---|
| 840 | + dmaengine_tx_status(rxchan, cookie, &state); |
|---|
| 841 | + |
|---|
| 842 | + count = dma->rx_size - state.residue + state.in_flight_bytes; |
|---|
| 843 | + if (count < dma->rx_size) { |
|---|
| 844 | + dmaengine_terminate_async(rxchan); |
|---|
| 845 | + |
|---|
| 846 | + /* |
|---|
| 847 | + * Poll for teardown to complete which guarantees in |
|---|
| 848 | + * flight data is drained. |
|---|
| 849 | + */ |
|---|
| 850 | + if (state.in_flight_bytes) { |
|---|
| 851 | + int poll_count = 25; |
|---|
| 852 | + |
|---|
| 853 | + while (dmaengine_tx_status(rxchan, cookie, NULL) && |
|---|
| 854 | + poll_count--) |
|---|
| 855 | + cpu_relax(); |
|---|
| 856 | + |
|---|
| 857 | + if (poll_count == -1) |
|---|
| 858 | + dev_err(p->port.dev, "teardown incomplete\n"); |
|---|
| 859 | + } |
|---|
| 860 | + } |
|---|
| 781 | 861 | if (!count) |
|---|
| 782 | | - goto unlock; |
|---|
| 862 | + goto out; |
|---|
| 783 | 863 | ret = tty_insert_flip_string(tty_port, dma->rx_buf, count); |
|---|
| 784 | 864 | |
|---|
| 785 | 865 | p->port.icount.rx += ret; |
|---|
| 786 | 866 | p->port.icount.buf_overrun += count - ret; |
|---|
| 787 | | -unlock: |
|---|
| 788 | | - spin_unlock_irqrestore(&priv->rx_dma_lock, flags); |
|---|
| 867 | +out: |
|---|
| 789 | 868 | |
|---|
| 790 | 869 | tty_flip_buffer_push(tty_port); |
|---|
| 791 | 870 | } |
|---|
| .. | .. |
|---|
| 811 | 890 | return; |
|---|
| 812 | 891 | } |
|---|
| 813 | 892 | __dma_rx_do_complete(p); |
|---|
| 814 | | - if (!priv->throttled) |
|---|
| 815 | | - omap_8250_rx_dma(p); |
|---|
| 893 | + if (!priv->throttled) { |
|---|
| 894 | + p->ier |= UART_IER_RLSI | UART_IER_RDI; |
|---|
| 895 | + serial_out(p, UART_IER, p->ier); |
|---|
| 896 | + if (!(priv->habit & UART_HAS_EFR2)) |
|---|
| 897 | + omap_8250_rx_dma(p); |
|---|
| 898 | + } |
|---|
| 816 | 899 | |
|---|
| 817 | 900 | spin_unlock_irqrestore(&p->port.lock, flags); |
|---|
| 818 | 901 | } |
|---|
| .. | .. |
|---|
| 838 | 921 | if (WARN_ON_ONCE(ret)) |
|---|
| 839 | 922 | priv->rx_dma_broken = true; |
|---|
| 840 | 923 | } |
|---|
| 841 | | - spin_unlock_irqrestore(&priv->rx_dma_lock, flags); |
|---|
| 842 | | - |
|---|
| 843 | 924 | __dma_rx_do_complete(p); |
|---|
| 925 | + spin_unlock_irqrestore(&priv->rx_dma_lock, flags); |
|---|
| 844 | 926 | } |
|---|
| 845 | 927 | |
|---|
| 846 | 928 | static int omap_8250_rx_dma(struct uart_8250_port *p) |
|---|
| .. | .. |
|---|
| 850 | 932 | int err = 0; |
|---|
| 851 | 933 | struct dma_async_tx_descriptor *desc; |
|---|
| 852 | 934 | unsigned long flags; |
|---|
| 935 | + u32 reg; |
|---|
| 853 | 936 | |
|---|
| 854 | 937 | if (priv->rx_dma_broken) |
|---|
| 855 | 938 | return -EINVAL; |
|---|
| 856 | 939 | |
|---|
| 857 | 940 | spin_lock_irqsave(&priv->rx_dma_lock, flags); |
|---|
| 858 | 941 | |
|---|
| 859 | | - if (dma->rx_running) |
|---|
| 942 | + if (dma->rx_running) { |
|---|
| 943 | + enum dma_status state; |
|---|
| 944 | + |
|---|
| 945 | + state = dmaengine_tx_status(dma->rxchan, dma->rx_cookie, NULL); |
|---|
| 946 | + if (state == DMA_COMPLETE) { |
|---|
| 947 | + /* |
|---|
| 948 | + * Disable RX interrupts to allow RX DMA completion |
|---|
| 949 | + * callback to run. |
|---|
| 950 | + */ |
|---|
| 951 | + p->ier &= ~(UART_IER_RLSI | UART_IER_RDI); |
|---|
| 952 | + serial_out(p, UART_IER, p->ier); |
|---|
| 953 | + } |
|---|
| 860 | 954 | goto out; |
|---|
| 955 | + } |
|---|
| 861 | 956 | |
|---|
| 862 | 957 | desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr, |
|---|
| 863 | 958 | dma->rx_size, DMA_DEV_TO_MEM, |
|---|
| .. | .. |
|---|
| 872 | 967 | desc->callback_param = p; |
|---|
| 873 | 968 | |
|---|
| 874 | 969 | dma->rx_cookie = dmaengine_submit(desc); |
|---|
| 970 | + |
|---|
| 971 | + /* |
|---|
| 972 | + * Disable RX FIFO interrupt while RX DMA is enabled, else |
|---|
| 973 | + * spurious interrupt may be raised when data is in the RX FIFO |
|---|
| 974 | + * but is yet to be drained by DMA. |
|---|
| 975 | + */ |
|---|
| 976 | + if (priv->habit & UART_HAS_RHR_IT_DIS) { |
|---|
| 977 | + reg = serial_in(p, UART_OMAP_IER2); |
|---|
| 978 | + reg |= UART_OMAP_IER2_RHR_IT_DIS; |
|---|
| 979 | + serial_out(p, UART_OMAP_IER2, UART_OMAP_IER2_RHR_IT_DIS); |
|---|
| 980 | + } |
|---|
| 875 | 981 | |
|---|
| 876 | 982 | dma_async_issue_pending(dma->rxchan); |
|---|
| 877 | 983 | out: |
|---|
| .. | .. |
|---|
| 915 | 1021 | ret = omap_8250_tx_dma(p); |
|---|
| 916 | 1022 | if (ret) |
|---|
| 917 | 1023 | en_thri = true; |
|---|
| 918 | | - |
|---|
| 919 | 1024 | } else if (p->capabilities & UART_CAP_RPM) { |
|---|
| 920 | 1025 | en_thri = true; |
|---|
| 921 | 1026 | } |
|---|
| 922 | 1027 | |
|---|
| 923 | 1028 | if (en_thri) { |
|---|
| 924 | 1029 | dma->tx_err = 1; |
|---|
| 925 | | - p->ier |= UART_IER_THRI; |
|---|
| 926 | | - serial_port_out(&p->port, UART_IER, p->ier); |
|---|
| 1030 | + serial8250_set_THRI(p); |
|---|
| 927 | 1031 | } |
|---|
| 928 | 1032 | |
|---|
| 929 | 1033 | spin_unlock_irqrestore(&p->port.lock, flags); |
|---|
| .. | .. |
|---|
| 951 | 1055 | ret = -EBUSY; |
|---|
| 952 | 1056 | goto err; |
|---|
| 953 | 1057 | } |
|---|
| 954 | | - if (p->ier & UART_IER_THRI) { |
|---|
| 955 | | - p->ier &= ~UART_IER_THRI; |
|---|
| 956 | | - serial_out(p, UART_IER, p->ier); |
|---|
| 957 | | - } |
|---|
| 1058 | + serial8250_clear_THRI(p); |
|---|
| 958 | 1059 | return 0; |
|---|
| 959 | 1060 | } |
|---|
| 960 | 1061 | |
|---|
| .. | .. |
|---|
| 1012 | 1113 | if (dma->tx_err) |
|---|
| 1013 | 1114 | dma->tx_err = 0; |
|---|
| 1014 | 1115 | |
|---|
| 1015 | | - if (p->ier & UART_IER_THRI) { |
|---|
| 1016 | | - p->ier &= ~UART_IER_THRI; |
|---|
| 1017 | | - serial_out(p, UART_IER, p->ier); |
|---|
| 1018 | | - } |
|---|
| 1116 | + serial8250_clear_THRI(p); |
|---|
| 1019 | 1117 | if (skip_byte) |
|---|
| 1020 | 1118 | serial_out(p, UART_TX, xmit->buf[xmit->tail]); |
|---|
| 1021 | 1119 | return 0; |
|---|
| .. | .. |
|---|
| 1036 | 1134 | return omap_8250_rx_dma(up); |
|---|
| 1037 | 1135 | } |
|---|
| 1038 | 1136 | |
|---|
| 1137 | +static unsigned char omap_8250_handle_rx_dma(struct uart_8250_port *up, |
|---|
| 1138 | + u8 iir, unsigned char status) |
|---|
| 1139 | +{ |
|---|
| 1140 | + if ((status & (UART_LSR_DR | UART_LSR_BI)) && |
|---|
| 1141 | + (iir & UART_IIR_RDI)) { |
|---|
| 1142 | + if (handle_rx_dma(up, iir)) { |
|---|
| 1143 | + status = serial8250_rx_chars(up, status); |
|---|
| 1144 | + omap_8250_rx_dma(up); |
|---|
| 1145 | + } |
|---|
| 1146 | + } |
|---|
| 1147 | + |
|---|
| 1148 | + return status; |
|---|
| 1149 | +} |
|---|
| 1150 | + |
|---|
| 1151 | +static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir, |
|---|
| 1152 | + unsigned char status) |
|---|
| 1153 | +{ |
|---|
| 1154 | + /* |
|---|
| 1155 | + * Queue a new transfer if FIFO has data. |
|---|
| 1156 | + */ |
|---|
| 1157 | + if ((status & (UART_LSR_DR | UART_LSR_BI)) && |
|---|
| 1158 | + (up->ier & UART_IER_RDI)) { |
|---|
| 1159 | + omap_8250_rx_dma(up); |
|---|
| 1160 | + serial_out(up, UART_OMAP_EFR2, UART_OMAP_EFR2_TIMEOUT_BEHAVE); |
|---|
| 1161 | + } else if ((iir & 0x3f) == UART_IIR_RX_TIMEOUT) { |
|---|
| 1162 | + /* |
|---|
| 1163 | + * Disable RX timeout, read IIR to clear |
|---|
| 1164 | + * current timeout condition, clear EFR2 to |
|---|
| 1165 | + * periodic timeouts, re-enable interrupts. |
|---|
| 1166 | + */ |
|---|
| 1167 | + up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); |
|---|
| 1168 | + serial_out(up, UART_IER, up->ier); |
|---|
| 1169 | + omap_8250_rx_dma_flush(up); |
|---|
| 1170 | + serial_in(up, UART_IIR); |
|---|
| 1171 | + serial_out(up, UART_OMAP_EFR2, 0x0); |
|---|
| 1172 | + up->ier |= UART_IER_RLSI | UART_IER_RDI; |
|---|
| 1173 | + serial_out(up, UART_IER, up->ier); |
|---|
| 1174 | + } |
|---|
| 1175 | +} |
|---|
| 1176 | + |
|---|
| 1039 | 1177 | /* |
|---|
| 1040 | 1178 | * This is mostly serial8250_handle_irq(). We have a slightly different DMA |
|---|
| 1041 | 1179 | * hoook for RX/TX and need different logic for them in the ISR. Therefore we |
|---|
| .. | .. |
|---|
| 1044 | 1182 | static int omap_8250_dma_handle_irq(struct uart_port *port) |
|---|
| 1045 | 1183 | { |
|---|
| 1046 | 1184 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 1185 | + struct omap8250_priv *priv = up->port.private_data; |
|---|
| 1047 | 1186 | unsigned char status; |
|---|
| 1048 | 1187 | unsigned long flags; |
|---|
| 1049 | 1188 | u8 iir; |
|---|
| .. | .. |
|---|
| 1053 | 1192 | iir = serial_port_in(port, UART_IIR); |
|---|
| 1054 | 1193 | if (iir & UART_IIR_NO_INT) { |
|---|
| 1055 | 1194 | serial8250_rpm_put(up); |
|---|
| 1056 | | - return 0; |
|---|
| 1195 | + return IRQ_HANDLED; |
|---|
| 1057 | 1196 | } |
|---|
| 1058 | 1197 | |
|---|
| 1059 | 1198 | spin_lock_irqsave(&port->lock, flags); |
|---|
| 1060 | 1199 | |
|---|
| 1061 | 1200 | status = serial_port_in(port, UART_LSR); |
|---|
| 1062 | 1201 | |
|---|
| 1063 | | - if (status & (UART_LSR_DR | UART_LSR_BI)) { |
|---|
| 1064 | | - if (handle_rx_dma(up, iir)) { |
|---|
| 1065 | | - status = serial8250_rx_chars(up, status); |
|---|
| 1066 | | - omap_8250_rx_dma(up); |
|---|
| 1067 | | - } |
|---|
| 1068 | | - } |
|---|
| 1202 | + if (priv->habit & UART_HAS_EFR2) |
|---|
| 1203 | + am654_8250_handle_rx_dma(up, iir, status); |
|---|
| 1204 | + else |
|---|
| 1205 | + status = omap_8250_handle_rx_dma(up, iir, status); |
|---|
| 1206 | + |
|---|
| 1069 | 1207 | serial8250_modem_status(up); |
|---|
| 1070 | 1208 | if (status & UART_LSR_THRE && up->dma->tx_err) { |
|---|
| 1071 | 1209 | if (uart_tx_stopped(&up->port) || |
|---|
| .. | .. |
|---|
| 1082 | 1220 | } |
|---|
| 1083 | 1221 | } |
|---|
| 1084 | 1222 | |
|---|
| 1085 | | - spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 1223 | + uart_unlock_and_check_sysrq(port, flags); |
|---|
| 1086 | 1224 | serial8250_rpm_put(up); |
|---|
| 1087 | 1225 | return 1; |
|---|
| 1088 | 1226 | } |
|---|
| .. | .. |
|---|
| 1107 | 1245 | return 0; |
|---|
| 1108 | 1246 | } |
|---|
| 1109 | 1247 | |
|---|
| 1110 | | -static const u8 omap4_habit = UART_ERRATA_CLOCK_DISABLE; |
|---|
| 1111 | | -static const u8 am3352_habit = OMAP_DMA_TX_KICK | UART_ERRATA_CLOCK_DISABLE; |
|---|
| 1112 | | -static const u8 dra742_habit = UART_ERRATA_CLOCK_DISABLE; |
|---|
| 1248 | +static struct omap8250_dma_params am654_dma = { |
|---|
| 1249 | + .rx_size = SZ_2K, |
|---|
| 1250 | + .rx_trigger = 1, |
|---|
| 1251 | + .tx_trigger = TX_TRIGGER, |
|---|
| 1252 | +}; |
|---|
| 1253 | + |
|---|
| 1254 | +static struct omap8250_dma_params am33xx_dma = { |
|---|
| 1255 | + .rx_size = RX_TRIGGER, |
|---|
| 1256 | + .rx_trigger = RX_TRIGGER, |
|---|
| 1257 | + .tx_trigger = TX_TRIGGER, |
|---|
| 1258 | +}; |
|---|
| 1259 | + |
|---|
| 1260 | +static struct omap8250_platdata am654_platdata = { |
|---|
| 1261 | + .dma_params = &am654_dma, |
|---|
| 1262 | + .habit = UART_HAS_EFR2 | UART_HAS_RHR_IT_DIS | |
|---|
| 1263 | + UART_RX_TIMEOUT_QUIRK, |
|---|
| 1264 | +}; |
|---|
| 1265 | + |
|---|
| 1266 | +static struct omap8250_platdata am33xx_platdata = { |
|---|
| 1267 | + .dma_params = &am33xx_dma, |
|---|
| 1268 | + .habit = OMAP_DMA_TX_KICK | UART_ERRATA_CLOCK_DISABLE, |
|---|
| 1269 | +}; |
|---|
| 1270 | + |
|---|
| 1271 | +static struct omap8250_platdata omap4_platdata = { |
|---|
| 1272 | + .dma_params = &am33xx_dma, |
|---|
| 1273 | + .habit = UART_ERRATA_CLOCK_DISABLE, |
|---|
| 1274 | +}; |
|---|
| 1113 | 1275 | |
|---|
| 1114 | 1276 | static const struct of_device_id omap8250_dt_ids[] = { |
|---|
| 1115 | | - { .compatible = "ti,am654-uart" }, |
|---|
| 1277 | + { .compatible = "ti,am654-uart", .data = &am654_platdata, }, |
|---|
| 1116 | 1278 | { .compatible = "ti,omap2-uart" }, |
|---|
| 1117 | 1279 | { .compatible = "ti,omap3-uart" }, |
|---|
| 1118 | | - { .compatible = "ti,omap4-uart", .data = &omap4_habit, }, |
|---|
| 1119 | | - { .compatible = "ti,am3352-uart", .data = &am3352_habit, }, |
|---|
| 1120 | | - { .compatible = "ti,am4372-uart", .data = &am3352_habit, }, |
|---|
| 1121 | | - { .compatible = "ti,dra742-uart", .data = &dra742_habit, }, |
|---|
| 1280 | + { .compatible = "ti,omap4-uart", .data = &omap4_platdata, }, |
|---|
| 1281 | + { .compatible = "ti,am3352-uart", .data = &am33xx_platdata, }, |
|---|
| 1282 | + { .compatible = "ti,am4372-uart", .data = &am33xx_platdata, }, |
|---|
| 1283 | + { .compatible = "ti,dra742-uart", .data = &omap4_platdata, }, |
|---|
| 1122 | 1284 | {}, |
|---|
| 1123 | 1285 | }; |
|---|
| 1124 | 1286 | MODULE_DEVICE_TABLE(of, omap8250_dt_ids); |
|---|
| 1125 | 1287 | |
|---|
| 1126 | 1288 | static int omap8250_probe(struct platform_device *pdev) |
|---|
| 1127 | 1289 | { |
|---|
| 1128 | | - struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 1129 | | - struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
|---|
| 1290 | + struct device_node *np = pdev->dev.of_node; |
|---|
| 1130 | 1291 | struct omap8250_priv *priv; |
|---|
| 1292 | + const struct omap8250_platdata *pdata; |
|---|
| 1131 | 1293 | struct uart_8250_port up; |
|---|
| 1132 | | - int ret; |
|---|
| 1294 | + struct resource *regs; |
|---|
| 1133 | 1295 | void __iomem *membase; |
|---|
| 1296 | + int irq, ret; |
|---|
| 1134 | 1297 | |
|---|
| 1135 | | - if (!regs || !irq) { |
|---|
| 1136 | | - dev_err(&pdev->dev, "missing registers or irq\n"); |
|---|
| 1298 | + irq = platform_get_irq(pdev, 0); |
|---|
| 1299 | + if (irq < 0) |
|---|
| 1300 | + return irq; |
|---|
| 1301 | + |
|---|
| 1302 | + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 1303 | + if (!regs) { |
|---|
| 1304 | + dev_err(&pdev->dev, "missing registers\n"); |
|---|
| 1137 | 1305 | return -EINVAL; |
|---|
| 1138 | 1306 | } |
|---|
| 1139 | 1307 | |
|---|
| .. | .. |
|---|
| 1141 | 1309 | if (!priv) |
|---|
| 1142 | 1310 | return -ENOMEM; |
|---|
| 1143 | 1311 | |
|---|
| 1144 | | - membase = devm_ioremap_nocache(&pdev->dev, regs->start, |
|---|
| 1312 | + membase = devm_ioremap(&pdev->dev, regs->start, |
|---|
| 1145 | 1313 | resource_size(regs)); |
|---|
| 1146 | 1314 | if (!membase) |
|---|
| 1147 | 1315 | return -ENODEV; |
|---|
| .. | .. |
|---|
| 1150 | 1318 | up.port.dev = &pdev->dev; |
|---|
| 1151 | 1319 | up.port.mapbase = regs->start; |
|---|
| 1152 | 1320 | up.port.membase = membase; |
|---|
| 1153 | | - up.port.irq = irq->start; |
|---|
| 1321 | + up.port.irq = irq; |
|---|
| 1154 | 1322 | /* |
|---|
| 1155 | 1323 | * It claims to be 16C750 compatible however it is a little different. |
|---|
| 1156 | 1324 | * It has EFR and has no FCR7_64byte bit. The AFE (which it claims to |
|---|
| .. | .. |
|---|
| 1185 | 1353 | up.port.shutdown = omap_8250_shutdown; |
|---|
| 1186 | 1354 | up.port.throttle = omap_8250_throttle; |
|---|
| 1187 | 1355 | up.port.unthrottle = omap_8250_unthrottle; |
|---|
| 1188 | | - up.port.rs485_config = omap_8250_rs485_config; |
|---|
| 1356 | + up.port.rs485_config = serial8250_em485_config; |
|---|
| 1357 | + up.rs485_start_tx = serial8250_em485_start_tx; |
|---|
| 1358 | + up.rs485_stop_tx = serial8250_em485_stop_tx; |
|---|
| 1359 | + up.port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); |
|---|
| 1189 | 1360 | |
|---|
| 1190 | | - if (pdev->dev.of_node) { |
|---|
| 1191 | | - const struct of_device_id *id; |
|---|
| 1192 | | - |
|---|
| 1193 | | - ret = of_alias_get_id(pdev->dev.of_node, "serial"); |
|---|
| 1194 | | - |
|---|
| 1195 | | - of_property_read_u32(pdev->dev.of_node, "clock-frequency", |
|---|
| 1196 | | - &up.port.uartclk); |
|---|
| 1197 | | - priv->wakeirq = irq_of_parse_and_map(pdev->dev.of_node, 1); |
|---|
| 1198 | | - |
|---|
| 1199 | | - id = of_match_device(of_match_ptr(omap8250_dt_ids), &pdev->dev); |
|---|
| 1200 | | - if (id && id->data) |
|---|
| 1201 | | - priv->habit |= *(u8 *)id->data; |
|---|
| 1202 | | - } else { |
|---|
| 1203 | | - ret = pdev->id; |
|---|
| 1204 | | - } |
|---|
| 1361 | + ret = of_alias_get_id(np, "serial"); |
|---|
| 1205 | 1362 | if (ret < 0) { |
|---|
| 1206 | | - dev_err(&pdev->dev, "failed to get alias/pdev id\n"); |
|---|
| 1363 | + dev_err(&pdev->dev, "failed to get alias\n"); |
|---|
| 1207 | 1364 | return ret; |
|---|
| 1208 | 1365 | } |
|---|
| 1209 | 1366 | up.port.line = ret; |
|---|
| 1367 | + |
|---|
| 1368 | + if (of_property_read_u32(np, "clock-frequency", &up.port.uartclk)) { |
|---|
| 1369 | + struct clk *clk; |
|---|
| 1370 | + |
|---|
| 1371 | + clk = devm_clk_get(&pdev->dev, NULL); |
|---|
| 1372 | + if (IS_ERR(clk)) { |
|---|
| 1373 | + if (PTR_ERR(clk) == -EPROBE_DEFER) |
|---|
| 1374 | + return -EPROBE_DEFER; |
|---|
| 1375 | + } else { |
|---|
| 1376 | + up.port.uartclk = clk_get_rate(clk); |
|---|
| 1377 | + } |
|---|
| 1378 | + } |
|---|
| 1379 | + |
|---|
| 1380 | + if (of_property_read_u32(np, "overrun-throttle-ms", |
|---|
| 1381 | + &up.overrun_backoff_time_ms) != 0) |
|---|
| 1382 | + up.overrun_backoff_time_ms = 0; |
|---|
| 1383 | + |
|---|
| 1384 | + priv->wakeirq = irq_of_parse_and_map(np, 1); |
|---|
| 1385 | + |
|---|
| 1386 | + pdata = of_device_get_match_data(&pdev->dev); |
|---|
| 1387 | + if (pdata) |
|---|
| 1388 | + priv->habit |= pdata->habit; |
|---|
| 1210 | 1389 | |
|---|
| 1211 | 1390 | if (!up.port.uartclk) { |
|---|
| 1212 | 1391 | up.port.uartclk = DEFAULT_CLK_SPEED; |
|---|
| .. | .. |
|---|
| 1215 | 1394 | DEFAULT_CLK_SPEED); |
|---|
| 1216 | 1395 | } |
|---|
| 1217 | 1396 | |
|---|
| 1218 | | - priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
|---|
| 1219 | | - priv->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
|---|
| 1220 | | - pm_qos_add_request(&priv->pm_qos_request, PM_QOS_CPU_DMA_LATENCY, |
|---|
| 1221 | | - priv->latency); |
|---|
| 1397 | + priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; |
|---|
| 1398 | + priv->calc_latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; |
|---|
| 1399 | + cpu_latency_qos_add_request(&priv->pm_qos_request, priv->latency); |
|---|
| 1222 | 1400 | INIT_WORK(&priv->qos_work, omap8250_uart_qos_work); |
|---|
| 1223 | 1401 | |
|---|
| 1224 | 1402 | spin_lock_init(&priv->rx_dma_lock); |
|---|
| .. | .. |
|---|
| 1226 | 1404 | device_init_wakeup(&pdev->dev, true); |
|---|
| 1227 | 1405 | pm_runtime_enable(&pdev->dev); |
|---|
| 1228 | 1406 | pm_runtime_use_autosuspend(&pdev->dev); |
|---|
| 1229 | | - pm_runtime_set_autosuspend_delay(&pdev->dev, -1); |
|---|
| 1407 | + |
|---|
| 1408 | + /* |
|---|
| 1409 | + * Disable runtime PM until autosuspend delay unless specifically |
|---|
| 1410 | + * enabled by the user via sysfs. This is the historic way to |
|---|
| 1411 | + * prevent an unsafe default policy with lossy characters on wake-up. |
|---|
| 1412 | + * For serdev devices this is not needed, the policy can be managed by |
|---|
| 1413 | + * the serdev driver. |
|---|
| 1414 | + */ |
|---|
| 1415 | + if (!of_get_available_child_count(pdev->dev.of_node)) |
|---|
| 1416 | + pm_runtime_set_autosuspend_delay(&pdev->dev, -1); |
|---|
| 1230 | 1417 | |
|---|
| 1231 | 1418 | pm_runtime_irq_safe(&pdev->dev); |
|---|
| 1232 | 1419 | |
|---|
| .. | .. |
|---|
| 1234 | 1421 | |
|---|
| 1235 | 1422 | omap_serial_fill_features_erratas(&up, priv); |
|---|
| 1236 | 1423 | up.port.handle_irq = omap8250_no_handle_irq; |
|---|
| 1424 | + priv->rx_trigger = RX_TRIGGER; |
|---|
| 1425 | + priv->tx_trigger = TX_TRIGGER; |
|---|
| 1237 | 1426 | #ifdef CONFIG_SERIAL_8250_DMA |
|---|
| 1238 | | - if (pdev->dev.of_node) { |
|---|
| 1239 | | - /* |
|---|
| 1240 | | - * Oh DMA support. If there are no DMA properties in the DT then |
|---|
| 1241 | | - * we will fall back to a generic DMA channel which does not |
|---|
| 1242 | | - * really work here. To ensure that we do not get a generic DMA |
|---|
| 1243 | | - * channel assigned, we have the the_no_dma_filter_fn() here. |
|---|
| 1244 | | - * To avoid "failed to request DMA" messages we check for DMA |
|---|
| 1245 | | - * properties in DT. |
|---|
| 1246 | | - */ |
|---|
| 1247 | | - ret = of_property_count_strings(pdev->dev.of_node, "dma-names"); |
|---|
| 1248 | | - if (ret == 2) { |
|---|
| 1249 | | - up.dma = &priv->omap8250_dma; |
|---|
| 1250 | | - priv->omap8250_dma.fn = the_no_dma_filter_fn; |
|---|
| 1251 | | - priv->omap8250_dma.tx_dma = omap_8250_tx_dma; |
|---|
| 1252 | | - priv->omap8250_dma.rx_dma = omap_8250_rx_dma; |
|---|
| 1253 | | - priv->omap8250_dma.rx_size = RX_TRIGGER; |
|---|
| 1254 | | - priv->omap8250_dma.rxconf.src_maxburst = RX_TRIGGER; |
|---|
| 1255 | | - priv->omap8250_dma.txconf.dst_maxburst = TX_TRIGGER; |
|---|
| 1427 | + /* |
|---|
| 1428 | + * Oh DMA support. If there are no DMA properties in the DT then |
|---|
| 1429 | + * we will fall back to a generic DMA channel which does not |
|---|
| 1430 | + * really work here. To ensure that we do not get a generic DMA |
|---|
| 1431 | + * channel assigned, we have the the_no_dma_filter_fn() here. |
|---|
| 1432 | + * To avoid "failed to request DMA" messages we check for DMA |
|---|
| 1433 | + * properties in DT. |
|---|
| 1434 | + */ |
|---|
| 1435 | + ret = of_property_count_strings(np, "dma-names"); |
|---|
| 1436 | + if (ret == 2) { |
|---|
| 1437 | + struct omap8250_dma_params *dma_params = NULL; |
|---|
| 1438 | + |
|---|
| 1439 | + up.dma = &priv->omap8250_dma; |
|---|
| 1440 | + up.dma->fn = the_no_dma_filter_fn; |
|---|
| 1441 | + up.dma->tx_dma = omap_8250_tx_dma; |
|---|
| 1442 | + up.dma->rx_dma = omap_8250_rx_dma; |
|---|
| 1443 | + if (pdata) |
|---|
| 1444 | + dma_params = pdata->dma_params; |
|---|
| 1445 | + |
|---|
| 1446 | + if (dma_params) { |
|---|
| 1447 | + up.dma->rx_size = dma_params->rx_size; |
|---|
| 1448 | + up.dma->rxconf.src_maxburst = dma_params->rx_trigger; |
|---|
| 1449 | + up.dma->txconf.dst_maxburst = dma_params->tx_trigger; |
|---|
| 1450 | + priv->rx_trigger = dma_params->rx_trigger; |
|---|
| 1451 | + priv->tx_trigger = dma_params->tx_trigger; |
|---|
| 1452 | + } else { |
|---|
| 1453 | + up.dma->rx_size = RX_TRIGGER; |
|---|
| 1454 | + up.dma->rxconf.src_maxburst = RX_TRIGGER; |
|---|
| 1455 | + up.dma->txconf.dst_maxburst = TX_TRIGGER; |
|---|
| 1256 | 1456 | } |
|---|
| 1257 | 1457 | } |
|---|
| 1258 | 1458 | #endif |
|---|
| .. | .. |
|---|
| 1276 | 1476 | static int omap8250_remove(struct platform_device *pdev) |
|---|
| 1277 | 1477 | { |
|---|
| 1278 | 1478 | struct omap8250_priv *priv = platform_get_drvdata(pdev); |
|---|
| 1479 | + int err; |
|---|
| 1480 | + |
|---|
| 1481 | + err = pm_runtime_resume_and_get(&pdev->dev); |
|---|
| 1482 | + if (err) |
|---|
| 1483 | + return err; |
|---|
| 1279 | 1484 | |
|---|
| 1280 | 1485 | pm_runtime_dont_use_autosuspend(&pdev->dev); |
|---|
| 1281 | 1486 | pm_runtime_put_sync(&pdev->dev); |
|---|
| 1487 | + flush_work(&priv->qos_work); |
|---|
| 1282 | 1488 | pm_runtime_disable(&pdev->dev); |
|---|
| 1283 | 1489 | serial8250_unregister_port(priv->line); |
|---|
| 1284 | | - pm_qos_remove_request(&priv->pm_qos_request); |
|---|
| 1490 | + cpu_latency_qos_remove_request(&priv->pm_qos_request); |
|---|
| 1285 | 1491 | device_init_wakeup(&pdev->dev, false); |
|---|
| 1286 | 1492 | return 0; |
|---|
| 1287 | 1493 | } |
|---|
| .. | .. |
|---|
| 1431 | 1637 | if (up->dma && up->dma->rxchan) |
|---|
| 1432 | 1638 | omap_8250_rx_dma_flush(up); |
|---|
| 1433 | 1639 | |
|---|
| 1434 | | - priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
|---|
| 1640 | + priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; |
|---|
| 1435 | 1641 | schedule_work(&priv->qos_work); |
|---|
| 1436 | 1642 | |
|---|
| 1437 | 1643 | return 0; |
|---|
| .. | .. |
|---|
| 1451 | 1657 | if (omap8250_lost_context(up)) |
|---|
| 1452 | 1658 | omap8250_restore_regs(up); |
|---|
| 1453 | 1659 | |
|---|
| 1454 | | - if (up->dma && up->dma->rxchan) |
|---|
| 1660 | + if (up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2)) |
|---|
| 1455 | 1661 | omap_8250_rx_dma(up); |
|---|
| 1456 | 1662 | |
|---|
| 1457 | 1663 | priv->latency = priv->calc_latency; |
|---|