aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorStefan Agner <stefan@agner.ch>2015-01-10 03:33:45 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-02-02 13:09:55 -0500
commit4a818c4396cb8f0d00b48921654e7918ed54f17f (patch)
tree347a40237562e477c33b9aa372e26be1486b9c82 /drivers/tty
parent5f1437f61a0b351d25b528c159360da3d5e8c77b (diff)
serial: fsl_lpuart: move DMA channel request to probe
Move the DMA channel request to probe to avoid requesting the DMA channel on each opening of the ttyLPx device. This also fixes a potential issue that TX channel is not freed when only RX channel allocation fails. The DMA channels are now handled independently, so one could use UART with DMA only in TX direction for instance. Signed-off-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/serial/fsl_lpuart.c96
1 files changed, 44 insertions, 52 deletions
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index e95c4971327b..0ea0af76cb9a 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -237,7 +237,8 @@ struct lpuart_port {
237 unsigned int rxfifo_size; 237 unsigned int rxfifo_size;
238 bool lpuart32; 238 bool lpuart32;
239 239
240 bool lpuart_dma_use; 240 bool lpuart_dma_tx_use;
241 bool lpuart_dma_rx_use;
241 struct dma_chan *dma_tx_chan; 242 struct dma_chan *dma_tx_chan;
242 struct dma_chan *dma_rx_chan; 243 struct dma_chan *dma_rx_chan;
243 struct dma_async_tx_descriptor *dma_tx_desc; 244 struct dma_async_tx_descriptor *dma_tx_desc;
@@ -568,7 +569,7 @@ static void lpuart_start_tx(struct uart_port *port)
568 temp = readb(port->membase + UARTCR2); 569 temp = readb(port->membase + UARTCR2);
569 writeb(temp | UARTCR2_TIE, port->membase + UARTCR2); 570 writeb(temp | UARTCR2_TIE, port->membase + UARTCR2);
570 571
571 if (sport->lpuart_dma_use) { 572 if (sport->lpuart_dma_tx_use) {
572 if (!uart_circ_empty(xmit) && !sport->dma_tx_in_progress) 573 if (!uart_circ_empty(xmit) && !sport->dma_tx_in_progress)
573 lpuart_prepare_tx(sport); 574 lpuart_prepare_tx(sport);
574 } else { 575 } else {
@@ -761,13 +762,13 @@ static irqreturn_t lpuart_int(int irq, void *dev_id)
761 crdma = readb(sport->port.membase + UARTCR5); 762 crdma = readb(sport->port.membase + UARTCR5);
762 763
763 if (sts & UARTSR1_RDRF && !(crdma & UARTCR5_RDMAS)) { 764 if (sts & UARTSR1_RDRF && !(crdma & UARTCR5_RDMAS)) {
764 if (sport->lpuart_dma_use) 765 if (sport->lpuart_dma_rx_use)
765 lpuart_prepare_rx(sport); 766 lpuart_prepare_rx(sport);
766 else 767 else
767 lpuart_rxint(irq, dev_id); 768 lpuart_rxint(irq, dev_id);
768 } 769 }
769 if (sts & UARTSR1_TDRE && !(crdma & UARTCR5_TDMAS)) { 770 if (sts & UARTSR1_TDRE && !(crdma & UARTCR5_TDMAS)) {
770 if (sport->lpuart_dma_use) 771 if (sport->lpuart_dma_tx_use)
771 lpuart_pio_tx(sport); 772 lpuart_pio_tx(sport);
772 else 773 else
773 lpuart_txint(irq, dev_id); 774 lpuart_txint(irq, dev_id);
@@ -950,26 +951,17 @@ static int lpuart_dma_tx_request(struct uart_port *port)
950{ 951{
951 struct lpuart_port *sport = container_of(port, 952 struct lpuart_port *sport = container_of(port,
952 struct lpuart_port, port); 953 struct lpuart_port, port);
953 struct dma_chan *tx_chan;
954 struct dma_slave_config dma_tx_sconfig; 954 struct dma_slave_config dma_tx_sconfig;
955 dma_addr_t dma_bus; 955 dma_addr_t dma_bus;
956 unsigned char *dma_buf; 956 unsigned char *dma_buf;
957 int ret; 957 int ret;
958 958
959 tx_chan = dma_request_slave_channel(sport->port.dev, "tx"); 959 dma_bus = dma_map_single(sport->dma_tx_chan->device->dev,
960
961 if (!tx_chan) {
962 dev_err(sport->port.dev, "Dma tx channel request failed!\n");
963 return -ENODEV;
964 }
965
966 dma_bus = dma_map_single(tx_chan->device->dev,
967 sport->port.state->xmit.buf, 960 sport->port.state->xmit.buf,
968 UART_XMIT_SIZE, DMA_TO_DEVICE); 961 UART_XMIT_SIZE, DMA_TO_DEVICE);
969 962
970 if (dma_mapping_error(tx_chan->device->dev, dma_bus)) { 963 if (dma_mapping_error(sport->dma_tx_chan->device->dev, dma_bus)) {
971 dev_err(sport->port.dev, "dma_map_single tx failed\n"); 964 dev_err(sport->port.dev, "dma_map_single tx failed\n");
972 dma_release_channel(tx_chan);
973 return -ENOMEM; 965 return -ENOMEM;
974 } 966 }
975 967
@@ -978,16 +970,14 @@ static int lpuart_dma_tx_request(struct uart_port *port)
978 dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 970 dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
979 dma_tx_sconfig.dst_maxburst = sport->txfifo_size; 971 dma_tx_sconfig.dst_maxburst = sport->txfifo_size;
980 dma_tx_sconfig.direction = DMA_MEM_TO_DEV; 972 dma_tx_sconfig.direction = DMA_MEM_TO_DEV;
981 ret = dmaengine_slave_config(tx_chan, &dma_tx_sconfig); 973 ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig);
982 974
983 if (ret < 0) { 975 if (ret < 0) {
984 dev_err(sport->port.dev, 976 dev_err(sport->port.dev,
985 "Dma slave config failed, err = %d\n", ret); 977 "Dma slave config failed, err = %d\n", ret);
986 dma_release_channel(tx_chan);
987 return ret; 978 return ret;
988 } 979 }
989 980
990 sport->dma_tx_chan = tx_chan;
991 sport->dma_tx_buf_virt = dma_buf; 981 sport->dma_tx_buf_virt = dma_buf;
992 sport->dma_tx_buf_bus = dma_bus; 982 sport->dma_tx_buf_bus = dma_bus;
993 sport->dma_tx_in_progress = 0; 983 sport->dma_tx_in_progress = 0;
@@ -999,34 +989,24 @@ static int lpuart_dma_rx_request(struct uart_port *port)
999{ 989{
1000 struct lpuart_port *sport = container_of(port, 990 struct lpuart_port *sport = container_of(port,
1001 struct lpuart_port, port); 991 struct lpuart_port, port);
1002 struct dma_chan *rx_chan;
1003 struct dma_slave_config dma_rx_sconfig; 992 struct dma_slave_config dma_rx_sconfig;
1004 dma_addr_t dma_bus; 993 dma_addr_t dma_bus;
1005 unsigned char *dma_buf; 994 unsigned char *dma_buf;
1006 int ret; 995 int ret;
1007 996
1008 rx_chan = dma_request_slave_channel(sport->port.dev, "rx");
1009
1010 if (!rx_chan) {
1011 dev_err(sport->port.dev, "Dma rx channel request failed!\n");
1012 return -ENODEV;
1013 }
1014
1015 dma_buf = devm_kzalloc(sport->port.dev, 997 dma_buf = devm_kzalloc(sport->port.dev,
1016 FSL_UART_RX_DMA_BUFFER_SIZE, GFP_KERNEL); 998 FSL_UART_RX_DMA_BUFFER_SIZE, GFP_KERNEL);
1017 999
1018 if (!dma_buf) { 1000 if (!dma_buf) {
1019 dev_err(sport->port.dev, "Dma rx alloc failed\n"); 1001 dev_err(sport->port.dev, "Dma rx alloc failed\n");
1020 dma_release_channel(rx_chan);
1021 return -ENOMEM; 1002 return -ENOMEM;
1022 } 1003 }
1023 1004
1024 dma_bus = dma_map_single(rx_chan->device->dev, dma_buf, 1005 dma_bus = dma_map_single(sport->dma_rx_chan->device->dev, dma_buf,
1025 FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE); 1006 FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE);
1026 1007
1027 if (dma_mapping_error(rx_chan->device->dev, dma_bus)) { 1008 if (dma_mapping_error(sport->dma_rx_chan->device->dev, dma_bus)) {
1028 dev_err(sport->port.dev, "dma_map_single rx failed\n"); 1009 dev_err(sport->port.dev, "dma_map_single rx failed\n");
1029 dma_release_channel(rx_chan);
1030 return -ENOMEM; 1010 return -ENOMEM;
1031 } 1011 }
1032 1012
@@ -1034,16 +1014,14 @@ static int lpuart_dma_rx_request(struct uart_port *port)
1034 dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 1014 dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
1035 dma_rx_sconfig.src_maxburst = 1; 1015 dma_rx_sconfig.src_maxburst = 1;
1036 dma_rx_sconfig.direction = DMA_DEV_TO_MEM; 1016 dma_rx_sconfig.direction = DMA_DEV_TO_MEM;
1037 ret = dmaengine_slave_config(rx_chan, &dma_rx_sconfig); 1017 ret = dmaengine_slave_config(sport->dma_rx_chan, &dma_rx_sconfig);
1038 1018
1039 if (ret < 0) { 1019 if (ret < 0) {
1040 dev_err(sport->port.dev, 1020 dev_err(sport->port.dev,
1041 "Dma slave config failed, err = %d\n", ret); 1021 "Dma slave config failed, err = %d\n", ret);
1042 dma_release_channel(rx_chan);
1043 return ret; 1022 return ret;
1044 } 1023 }
1045 1024
1046 sport->dma_rx_chan = rx_chan;
1047 sport->dma_rx_buf_virt = dma_buf; 1025 sport->dma_rx_buf_virt = dma_buf;
1048 sport->dma_rx_buf_bus = dma_bus; 1026 sport->dma_rx_buf_bus = dma_bus;
1049 sport->dma_rx_in_progress = 0; 1027 sport->dma_rx_in_progress = 0;
@@ -1055,31 +1033,24 @@ static void lpuart_dma_tx_free(struct uart_port *port)
1055{ 1033{
1056 struct lpuart_port *sport = container_of(port, 1034 struct lpuart_port *sport = container_of(port,
1057 struct lpuart_port, port); 1035 struct lpuart_port, port);
1058 struct dma_chan *dma_chan;
1059 1036
1060 dma_unmap_single(sport->port.dev, sport->dma_tx_buf_bus, 1037 dma_unmap_single(sport->port.dev, sport->dma_tx_buf_bus,
1061 UART_XMIT_SIZE, DMA_TO_DEVICE); 1038 UART_XMIT_SIZE, DMA_TO_DEVICE);
1062 dma_chan = sport->dma_tx_chan; 1039
1063 sport->dma_tx_chan = NULL;
1064 sport->dma_tx_buf_bus = 0; 1040 sport->dma_tx_buf_bus = 0;
1065 sport->dma_tx_buf_virt = NULL; 1041 sport->dma_tx_buf_virt = NULL;
1066 dma_release_channel(dma_chan);
1067} 1042}
1068 1043
1069static void lpuart_dma_rx_free(struct uart_port *port) 1044static void lpuart_dma_rx_free(struct uart_port *port)
1070{ 1045{
1071 struct lpuart_port *sport = container_of(port, 1046 struct lpuart_port *sport = container_of(port,
1072 struct lpuart_port, port); 1047 struct lpuart_port, port);
1073 struct dma_chan *dma_chan;
1074 1048
1075 dma_unmap_single(sport->port.dev, sport->dma_rx_buf_bus, 1049 dma_unmap_single(sport->port.dev, sport->dma_rx_buf_bus,
1076 FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE); 1050 FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE);
1077 1051
1078 dma_chan = sport->dma_rx_chan;
1079 sport->dma_rx_chan = NULL;
1080 sport->dma_rx_buf_bus = 0; 1052 sport->dma_rx_buf_bus = 0;
1081 sport->dma_rx_buf_virt = NULL; 1053 sport->dma_rx_buf_virt = NULL;
1082 dma_release_channel(dma_chan);
1083} 1054}
1084 1055
1085static int lpuart_startup(struct uart_port *port) 1056static int lpuart_startup(struct uart_port *port)
@@ -1098,17 +1069,21 @@ static int lpuart_startup(struct uart_port *port)
1098 sport->rxfifo_size = 0x1 << (((temp >> UARTPFIFO_RXSIZE_OFF) & 1069 sport->rxfifo_size = 0x1 << (((temp >> UARTPFIFO_RXSIZE_OFF) &
1099 UARTPFIFO_FIFOSIZE_MASK) + 1); 1070 UARTPFIFO_FIFOSIZE_MASK) + 1);
1100 1071
1101 /* Whether use dma support by dma request results */ 1072 if (sport->dma_rx_chan && !lpuart_dma_rx_request(port)) {
1102 if (lpuart_dma_tx_request(port) || lpuart_dma_rx_request(port)) { 1073 sport->lpuart_dma_rx_use = true;
1103 sport->lpuart_dma_use = false;
1104 } else {
1105 sport->lpuart_dma_use = true;
1106 setup_timer(&sport->lpuart_timer, lpuart_timer_func, 1074 setup_timer(&sport->lpuart_timer, lpuart_timer_func,
1107 (unsigned long)sport); 1075 (unsigned long)sport);
1076 } else
1077 sport->lpuart_dma_rx_use = false;
1078
1079
1080 if (sport->dma_tx_chan && !lpuart_dma_tx_request(port)) {
1081 sport->lpuart_dma_tx_use = true;
1108 temp = readb(port->membase + UARTCR5); 1082 temp = readb(port->membase + UARTCR5);
1109 temp &= ~UARTCR5_RDMAS; 1083 temp &= ~UARTCR5_RDMAS;
1110 writeb(temp | UARTCR5_TDMAS, port->membase + UARTCR5); 1084 writeb(temp | UARTCR5_TDMAS, port->membase + UARTCR5);
1111 } 1085 } else
1086 sport->lpuart_dma_tx_use = false;
1112 1087
1113 ret = devm_request_irq(port->dev, port->irq, lpuart_int, 0, 1088 ret = devm_request_irq(port->dev, port->irq, lpuart_int, 0,
1114 DRIVER_NAME, sport); 1089 DRIVER_NAME, sport);
@@ -1179,12 +1154,13 @@ static void lpuart_shutdown(struct uart_port *port)
1179 1154
1180 devm_free_irq(port->dev, port->irq, sport); 1155 devm_free_irq(port->dev, port->irq, sport);
1181 1156
1182 if (sport->lpuart_dma_use) { 1157 if (sport->lpuart_dma_rx_use) {
1158 lpuart_dma_rx_free(&sport->port);
1183 del_timer_sync(&sport->lpuart_timer); 1159 del_timer_sync(&sport->lpuart_timer);
1184
1185 lpuart_dma_tx_free(port);
1186 lpuart_dma_rx_free(port);
1187 } 1160 }
1161
1162 if (sport->lpuart_dma_tx_use)
1163 lpuart_dma_tx_free(&sport->port);
1188} 1164}
1189 1165
1190static void lpuart32_shutdown(struct uart_port *port) 1166static void lpuart32_shutdown(struct uart_port *port)
@@ -1306,7 +1282,7 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
1306 /* update the per-port timeout */ 1282 /* update the per-port timeout */
1307 uart_update_timeout(port, termios->c_cflag, baud); 1283 uart_update_timeout(port, termios->c_cflag, baud);
1308 1284
1309 if (sport->lpuart_dma_use) { 1285 if (sport->lpuart_dma_rx_use) {
1310 /* Calculate delay for 1.5 DMA buffers */ 1286 /* Calculate delay for 1.5 DMA buffers */
1311 sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) * 1287 sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) *
1312 FSL_UART_RX_DMA_BUFFER_SIZE * 3 / 1288 FSL_UART_RX_DMA_BUFFER_SIZE * 3 /
@@ -1835,6 +1811,16 @@ static int lpuart_probe(struct platform_device *pdev)
1835 return ret; 1811 return ret;
1836 } 1812 }
1837 1813
1814 sport->dma_tx_chan = dma_request_slave_channel(sport->port.dev, "tx");
1815 if (!sport->dma_tx_chan)
1816 dev_info(sport->port.dev, "DMA tx channel request failed, "
1817 "operating without tx DMA\n");
1818
1819 sport->dma_rx_chan = dma_request_slave_channel(sport->port.dev, "rx");
1820 if (!sport->dma_rx_chan)
1821 dev_info(sport->port.dev, "DMA rx channel request failed, "
1822 "operating without rx DMA\n");
1823
1838 return 0; 1824 return 0;
1839} 1825}
1840 1826
@@ -1846,6 +1832,12 @@ static int lpuart_remove(struct platform_device *pdev)
1846 1832
1847 clk_disable_unprepare(sport->clk); 1833 clk_disable_unprepare(sport->clk);
1848 1834
1835 if (sport->dma_tx_chan)
1836 dma_release_channel(sport->dma_tx_chan);
1837
1838 if (sport->dma_rx_chan)
1839 dma_release_channel(sport->dma_rx_chan);
1840
1849 return 0; 1841 return 0;
1850} 1842}
1851 1843