aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Hunter <jonathanh@nvidia.com>2015-10-09 09:50:02 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-10-18 00:07:57 -0400
commit32ede4a51754cb62b0d43d91cb7c4e3c57069a9c (patch)
tree0244e41e96e47bef06e1438f08dc98620d54e791
parentb0e066ccb5b2c474385fe10dbb385bde10738177 (diff)
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>
-rw-r--r--drivers/tty/serial/serial-tegra.c66
1 files changed, 24 insertions, 42 deletions
diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c
index 11aa5e1e3705..1d6fc60ed013 100644
--- a/drivers/tty/serial/serial-tegra.c
+++ b/drivers/tty/serial/serial-tegra.c
@@ -569,13 +569,30 @@ static void tegra_uart_copy_rx_to_tty(struct tegra_uart_port *tup,
569 TEGRA_UART_RX_DMA_BUFFER_SIZE, DMA_TO_DEVICE); 569 TEGRA_UART_RX_DMA_BUFFER_SIZE, DMA_TO_DEVICE);
570} 570}
571 571
572static 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
572static void tegra_uart_rx_dma_complete(void *args) 592static void tegra_uart_rx_dma_complete(void *args)
573{ 593{
574 struct tegra_uart_port *tup = args; 594 struct tegra_uart_port *tup = args;
575 struct uart_port *u = &tup->uport; 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 unsigned long flags; 596 unsigned long flags;
580 struct dma_tx_state state; 597 struct dma_tx_state state;
581 enum dma_status status; 598 enum dma_status status;
@@ -589,20 +606,11 @@ static void tegra_uart_rx_dma_complete(void *args)
589 goto done; 606 goto done;
590 } 607 }
591 608
592 async_tx_ack(tup->rx_dma_desc);
593
594 /* Deactivate flow control to stop sender */ 609 /* Deactivate flow control to stop sender */
595 if (tup->rts_active) 610 if (tup->rts_active)
596 set_rts(tup, false); 611 set_rts(tup, false);
597 612
598 /* If we are here, DMA is stopped */ 613 tegra_uart_rx_buffer_push(tup, 0);
599 tegra_uart_copy_rx_to_tty(tup, port, count);
600
601 tegra_uart_handle_rx_pio(tup, port);
602 if (tty) {
603 tty_flip_buffer_push(port);
604 tty_kref_put(tty);
605 }
606 tegra_uart_start_rx_dma(tup); 614 tegra_uart_start_rx_dma(tup);
607 615
608 /* Activate flow control to start transfer */ 616 /* Activate flow control to start transfer */
@@ -616,27 +624,14 @@ done:
616static void tegra_uart_handle_rx_dma(struct tegra_uart_port *tup) 624static void tegra_uart_handle_rx_dma(struct tegra_uart_port *tup)
617{ 625{
618 struct dma_tx_state state; 626 struct dma_tx_state state;
619 struct tty_struct *tty = tty_port_tty_get(&tup->uport.state->port);
620 struct tty_port *port = &tup->uport.state->port;
621 unsigned int count;
622 627
623 /* Deactivate flow control to stop sender */ 628 /* Deactivate flow control to stop sender */
624 if (tup->rts_active) 629 if (tup->rts_active)
625 set_rts(tup, false); 630 set_rts(tup, false);
626 631
627 dmaengine_terminate_all(tup->rx_dma_chan); 632 dmaengine_terminate_all(tup->rx_dma_chan);
628 dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state); 633 dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state);
629 async_tx_ack(tup->rx_dma_desc); 634 tegra_uart_rx_buffer_push(tup, state.residue);
630 count = tup->rx_bytes_requested - state.residue;
631
632 /* If we are here, DMA is stopped */
633 tegra_uart_copy_rx_to_tty(tup, port, count);
634
635 tegra_uart_handle_rx_pio(tup, port);
636 if (tty) {
637 tty_flip_buffer_push(port);
638 tty_kref_put(tty);
639 }
640 tegra_uart_start_rx_dma(tup); 635 tegra_uart_start_rx_dma(tup);
641 636
642 if (tup->rts_active) 637 if (tup->rts_active)
@@ -755,11 +750,8 @@ static irqreturn_t tegra_uart_isr(int irq, void *data)
755static void tegra_uart_stop_rx(struct uart_port *u) 750static void tegra_uart_stop_rx(struct uart_port *u)
756{ 751{
757 struct tegra_uart_port *tup = to_tegra_uport(u); 752 struct tegra_uart_port *tup = to_tegra_uport(u);
758 struct tty_struct *tty;
759 struct tty_port *port = &u->state->port;
760 struct dma_tx_state state; 753 struct dma_tx_state state;
761 unsigned long ier; 754 unsigned long ier;
762 int count;
763 755
764 if (tup->rts_active) 756 if (tup->rts_active)
765 set_rts(tup, false); 757 set_rts(tup, false);
@@ -767,8 +759,6 @@ static void tegra_uart_stop_rx(struct uart_port *u)
767 if (!tup->rx_in_progress) 759 if (!tup->rx_in_progress)
768 return; 760 return;
769 761
770 tty = tty_port_tty_get(&tup->uport.state->port);
771
772 tegra_uart_wait_sym_time(tup, 1); /* wait a character interval */ 762 tegra_uart_wait_sym_time(tup, 1); /* wait a character interval */
773 763
774 ier = tup->ier_shadow; 764 ier = tup->ier_shadow;
@@ -779,15 +769,7 @@ static void tegra_uart_stop_rx(struct uart_port *u)
779 tup->rx_in_progress = 0; 769 tup->rx_in_progress = 0;
780 dmaengine_terminate_all(tup->rx_dma_chan); 770 dmaengine_terminate_all(tup->rx_dma_chan);
781 dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state); 771 dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state);
782 async_tx_ack(tup->rx_dma_desc); 772 tegra_uart_rx_buffer_push(tup, state.residue);
783 count = tup->rx_bytes_requested - state.residue;
784 tegra_uart_copy_rx_to_tty(tup, port, count);
785 tegra_uart_handle_rx_pio(tup, port);
786
787 if (tty) {
788 tty_flip_buffer_push(port);
789 tty_kref_put(tty);
790 }
791} 773}
792 774
793static void tegra_uart_hw_deinit(struct tegra_uart_port *tup) 775static void tegra_uart_hw_deinit(struct tegra_uart_port *tup)