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

serial: tegra: Add helper function for handling RX buffer

In the tegra UART driver there are three places where the RX DMA buffer
is handled and pushed up to the tty layer. In all three instances the
same functions are called and so instead of duplicating the code in three
places, move this code to a new helper function and use this new function.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jon Hunter and committed by
Greg Kroah-Hartman
32ede4a5 b0e066cc

+24 -42
+24 -42
drivers/tty/serial/serial-tegra.c
··· 569 569 TEGRA_UART_RX_DMA_BUFFER_SIZE, DMA_TO_DEVICE); 570 570 } 571 571 572 + static void tegra_uart_rx_buffer_push(struct tegra_uart_port *tup, 573 + unsigned int residue) 574 + { 575 + struct tty_port *port = &tup->uport.state->port; 576 + struct tty_struct *tty = tty_port_tty_get(port); 577 + unsigned int count; 578 + 579 + async_tx_ack(tup->rx_dma_desc); 580 + count = tup->rx_bytes_requested - residue; 581 + 582 + /* If we are here, DMA is stopped */ 583 + tegra_uart_copy_rx_to_tty(tup, port, count); 584 + 585 + tegra_uart_handle_rx_pio(tup, port); 586 + if (tty) { 587 + tty_flip_buffer_push(port); 588 + tty_kref_put(tty); 589 + } 590 + } 591 + 572 592 static void tegra_uart_rx_dma_complete(void *args) 573 593 { 574 594 struct tegra_uart_port *tup = args; 575 595 struct uart_port *u = &tup->uport; 576 - unsigned int count = tup->rx_bytes_requested; 577 - struct tty_struct *tty = tty_port_tty_get(&tup->uport.state->port); 578 - struct tty_port *port = &u->state->port; 579 596 unsigned long flags; 580 597 struct dma_tx_state state; 581 598 enum dma_status status; ··· 606 589 goto done; 607 590 } 608 591 609 - async_tx_ack(tup->rx_dma_desc); 610 - 611 592 /* Deactivate flow control to stop sender */ 612 593 if (tup->rts_active) 613 594 set_rts(tup, false); 614 595 615 - /* If we are here, DMA is stopped */ 616 - tegra_uart_copy_rx_to_tty(tup, port, count); 617 - 618 - tegra_uart_handle_rx_pio(tup, port); 619 - if (tty) { 620 - tty_flip_buffer_push(port); 621 - tty_kref_put(tty); 622 - } 596 + tegra_uart_rx_buffer_push(tup, 0); 623 597 tegra_uart_start_rx_dma(tup); 624 598 625 599 /* Activate flow control to start transfer */ ··· 624 616 static void tegra_uart_handle_rx_dma(struct tegra_uart_port *tup) 625 617 { 626 618 struct dma_tx_state state; 627 - struct tty_struct *tty = tty_port_tty_get(&tup->uport.state->port); 628 - struct tty_port *port = &tup->uport.state->port; 629 - unsigned int count; 630 619 631 620 /* Deactivate flow control to stop sender */ 632 621 if (tup->rts_active) 633 622 set_rts(tup, false); 634 623 635 624 dmaengine_terminate_all(tup->rx_dma_chan); 636 - dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state); 637 - async_tx_ack(tup->rx_dma_desc); 638 - count = tup->rx_bytes_requested - state.residue; 639 - 640 - /* If we are here, DMA is stopped */ 641 - tegra_uart_copy_rx_to_tty(tup, port, count); 642 - 643 - tegra_uart_handle_rx_pio(tup, port); 644 - if (tty) { 645 - tty_flip_buffer_push(port); 646 - tty_kref_put(tty); 647 - } 625 + dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state); 626 + tegra_uart_rx_buffer_push(tup, state.residue); 648 627 tegra_uart_start_rx_dma(tup); 649 628 650 629 if (tup->rts_active) ··· 750 755 static void tegra_uart_stop_rx(struct uart_port *u) 751 756 { 752 757 struct tegra_uart_port *tup = to_tegra_uport(u); 753 - struct tty_struct *tty; 754 - struct tty_port *port = &u->state->port; 755 758 struct dma_tx_state state; 756 759 unsigned long ier; 757 - int count; 758 760 759 761 if (tup->rts_active) 760 762 set_rts(tup, false); 761 763 762 764 if (!tup->rx_in_progress) 763 765 return; 764 - 765 - tty = tty_port_tty_get(&tup->uport.state->port); 766 766 767 767 tegra_uart_wait_sym_time(tup, 1); /* wait a character interval */ 768 768 ··· 769 779 tup->rx_in_progress = 0; 770 780 dmaengine_terminate_all(tup->rx_dma_chan); 771 781 dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state); 772 - async_tx_ack(tup->rx_dma_desc); 773 - count = tup->rx_bytes_requested - state.residue; 774 - tegra_uart_copy_rx_to_tty(tup, port, count); 775 - tegra_uart_handle_rx_pio(tup, port); 776 - 777 - if (tty) { 778 - tty_flip_buffer_push(port); 779 - tty_kref_put(tty); 780 - } 782 + tegra_uart_rx_buffer_push(tup, state.residue); 781 783 } 782 784 783 785 static void tegra_uart_hw_deinit(struct tegra_uart_port *tup)