From patchwork Mon Oct 29 09:10:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Song, Elen" X-Patchwork-Id: 1662481 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 5C6183FDDA for ; Mon, 29 Oct 2012 09:14:58 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TSlOz-0003M5-CK; Mon, 29 Oct 2012 09:12:57 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TSlOp-0003JO-16 for linux-arm-kernel@merlin.infradead.org; Mon, 29 Oct 2012 09:12:47 +0000 Received: from newsmtp5.atmel.com ([204.2.163.5] helo=sjogate2.atmel.com) by casper.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TSlOk-0000af-7u for linux-arm-kernel@lists.infradead.org; Mon, 29 Oct 2012 09:12:45 +0000 Received: from penbh01.corp.atmel.com ([10.168.5.31]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id q9T97Tvf001641; Mon, 29 Oct 2012 02:07:30 -0700 (PDT) Received: from penmb01.corp.atmel.com ([10.168.5.33]) by penbh01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 29 Oct 2012 17:12:30 +0800 Received: from shaarm01.corp.atmel.com ([10.217.6.34]) by penmb01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 29 Oct 2012 17:12:30 +0800 From: Elen Song To: nicolas.ferre@atmel.com, patrice.vilchez@atmel.com, plagnioj@jcrosoft.com Subject: [PATCH 3/6] Serial: AT91: Request tx dma channel Date: Mon, 29 Oct 2012 17:10:14 +0800 Message-Id: <1351501814-8600-1-git-send-email-elen.song@atmel.com> X-Mailer: git-send-email 1.7.9.5 X-OriginalArrivalTime: 29 Oct 2012 09:12:30.0260 (UTC) FILETIME=[85D43F40:01CDB5B5] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121029_091242_771151_2FEB0E2B X-CRM114-Status: GOOD ( 12.96 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: jm.lin@atmel.com, linux@arm.linux.org.uk, elen.song@atmel.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Request a slave dma channel for tx dma use Signed-off-by: Elen Song --- drivers/tty/serial/atmel_serial.c | 110 +++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 8a4b8f8..c02a919 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -151,6 +151,14 @@ struct atmel_uart_port { short use_pdc_tx; /* enable PDC transmitter */ struct atmel_dma_buffer pdc_tx; /* PDC transmitter */ + spinlock_t lock_tx; /* port lock */ + struct dma_chan *chan_tx; + struct dma_async_tx_descriptor *desc_tx; + dma_cookie_t cookie_tx; + + struct scatterlist sg_tx; + unsigned int sg_len_tx; + struct tasklet_struct tasklet; unsigned int irq_status; unsigned int irq_status_prev; @@ -582,6 +590,102 @@ static void atmel_tx_chars(struct uart_port *port) UART_PUT_IER(port, atmel_port->tx_done_mask); } +static void atmel_tx_dma_release(struct atmel_uart_port *atmel_port) +{ + struct dma_chan *chan = atmel_port->chan_tx; + + atmel_port->chan_tx = NULL; + atmel_port->cookie_tx = -EINVAL; + if (chan) { + dmaengine_terminate_all(chan); + dma_release_channel(chan); + } +} + +static bool filter(struct dma_chan *chan, void *slave) +{ + struct at_dma_slave *sl = slave; + + if (sl->dma_dev == chan->device->dev) { + chan->private = sl; + return true; + } else { + return false; + } +} + +static void atmel_tx_request_dma(struct atmel_uart_port *atmel_port) +{ + struct uart_port *port; + struct atmel_uart_data *pdata; + dma_cap_mask_t mask; + struct dma_chan *chan = NULL; + struct dma_slave_config config; + int ret; + + if (atmel_port == NULL) + return; + + port = &(atmel_port->uart); + pdata = (struct atmel_uart_data *)port->private_data; + + if (!pdata) { + dev_notice(port->dev, "DMA not available, using PIO\n"); + return; + } + + dma_cap_zero(mask); + dma_cap_set(DMA_SLAVE, mask); + + if (atmel_use_dma_tx(port) && pdata->dma_tx_slave) { + pdata->dma_tx_slave->tx_reg = port->mapbase + ATMEL_US_THR; + chan = dma_request_channel(mask, filter, pdata->dma_tx_slave); + dev_dbg(port->dev, "%s: TX: got channel %p\n", __func__, chan); + } + + if (chan) { + int nent; + + spin_lock_init(&atmel_port->lock_tx); + atmel_port->chan_tx = chan; + + sg_init_table(&atmel_port->sg_tx, 1); + /* UART circular tx buffer is an aligned page. */ + BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK); + sg_set_page(&atmel_port->sg_tx, + virt_to_page(port->state->xmit.buf), + UART_XMIT_SIZE, + (int)port->state->xmit.buf & ~PAGE_MASK); + nent = dma_map_sg(port->dev, + &atmel_port->sg_tx, + 1, + DMA_MEM_TO_DEV); + + if (!nent) + dev_dbg(port->dev, "need to release resource of dma\n"); + else + dev_dbg(port->dev, "%s: mapped %d@%p to %x\n", __func__, + sg_dma_len(&atmel_port->sg_tx), + port->state->xmit.buf, + sg_dma_address(&atmel_port->sg_tx)); + + atmel_port->sg_len_tx = nent; + } + + /* Configure the slave DMA */ + memset(&config, 0, sizeof(config)); + config.direction = DMA_MEM_TO_DEV; + config.dst_addr_width = pdata->dma_tx_slave->reg_width; + config.dst_addr = pdata->dma_tx_slave->tx_reg; + + ret = dmaengine_device_control(chan, DMA_SLAVE_CONFIG, + (unsigned long)&config); + if (ret) { + dev_err(port->dev, "DMA tx slave configuration failed\n"); + return; + } +} + /* * receive interrupt handler. */ @@ -994,6 +1098,9 @@ static int atmel_startup(struct uart_port *port) pdc->ofs = 0; } + if (atmel_use_dma_tx(port)) + atmel_tx_request_dma(atmel_port); + /* * If there is a specific "open" function (to register * control line interrupts) @@ -1070,6 +1177,9 @@ static void atmel_shutdown(struct uart_port *port) DMA_TO_DEVICE); } + if (atmel_use_dma_tx(port)) + atmel_tx_dma_release(atmel_port); + /* * Disable all interrupts, port and break condition. */