From patchwork Tue Jul 16 02:43:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Song, Elen" X-Patchwork-Id: 2827872 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E25F2C0AB2 for ; Tue, 16 Jul 2013 03:24:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ED7FF20182 for ; Tue, 16 Jul 2013 03:24:53 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C912C2017F for ; Tue, 16 Jul 2013 03:24:52 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UyvNl-00033d-4R; Tue, 16 Jul 2013 02:52:55 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UyvMk-00070Z-S2; Tue, 16 Jul 2013 02:51:50 +0000 Received: from nasmtp02.atmel.com ([204.2.163.16]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UyvMi-0006zz-1y for linux-arm-kernel@lists.infradead.org; Tue, 16 Jul 2013 02:51:48 +0000 Received: from apsmtp01.atmel.com (10.168.254.31) by sjoedg01.corp.atmel.com (10.64.253.30) with Microsoft SMTP Server (TLS) id 14.2.342.3; Mon, 15 Jul 2013 19:57:41 -0700 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server id 14.2.342.3; Tue, 16 Jul 2013 10:51:21 +0800 From: Elen Song To: , , Subject: [PATCH V2 5/8] serial: at91: support run time switch transfer mode Date: Tue, 16 Jul 2013 10:43:44 +0800 Message-ID: <1373942627-7121-6-git-send-email-elen.song@atmel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1373942627-7121-1-git-send-email-elen.song@atmel.com> References: <1373942627-7121-1-git-send-email-elen.song@atmel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130715_225148_293099_7B3C57D9 X-CRM114-Status: GOOD ( 14.80 ) X-Spam-Score: -2.3 (--) Cc: gregkh@linuxfoundation.org, elen.song@atmel.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We will switch to pio mode when request of dma or pdc fail. But soon or later, when the request is success, the transfer mode can switch to them at next open serial port action. So in startup stage, we should get original transfer mode. Signed-off-by: Elen Song --- drivers/tty/serial/atmel_serial.c | 139 +++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 59 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 298b58c..ad787fd1 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -1371,6 +1371,80 @@ static void atmel_tasklet_func(unsigned long data) spin_unlock(&port->lock); } +static int atmel_init_property(struct atmel_uart_port *atmel_port, + struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct atmel_uart_data *pdata = pdev->dev.platform_data; + + if (np) { + /* DMA/PDC usage specification */ + if (of_get_property(np, "atmel,use-dma-rx", NULL)) { + if (of_get_property(np, "dmas", NULL)) { + atmel_port->use_dma_rx = 1; + atmel_port->use_pdc_rx = 0; + } else { + atmel_port->use_dma_rx = 0; + atmel_port->use_pdc_rx = 1; + } + } else { + atmel_port->use_dma_rx = 0; + atmel_port->use_pdc_rx = 0; + } + + if (of_get_property(np, "atmel,use-dma-tx", NULL)) { + if (of_get_property(np, "dmas", NULL)) { + atmel_port->use_dma_tx = 1; + atmel_port->use_pdc_tx = 0; + } else { + atmel_port->use_dma_tx = 0; + atmel_port->use_pdc_tx = 1; + } + } else { + atmel_port->use_dma_tx = 0; + atmel_port->use_pdc_tx = 0; + } + + } else { + atmel_port->use_pdc_rx = pdata->use_dma_rx; + atmel_port->use_pdc_tx = pdata->use_dma_tx; + atmel_port->use_dma_rx = 0; + atmel_port->use_dma_tx = 0; + } + + return 0; +} + +static void atmel_init_rs485(struct atmel_uart_port *atmel_port, + struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct atmel_uart_data *pdata = pdev->dev.platform_data; + + if (np) { + u32 rs485_delay[2]; + /* rs485 properties */ + if (of_property_read_u32_array(np, "rs485-rts-delay", + rs485_delay, 2) == 0) { + struct serial_rs485 *rs485conf = &atmel_port->rs485; + + rs485conf->delay_rts_before_send = rs485_delay[0]; + rs485conf->delay_rts_after_send = rs485_delay[1]; + rs485conf->flags = 0; + + if (of_get_property(np, "rs485-rx-during-tx", NULL)) + rs485conf->flags |= SER_RS485_RX_DURING_TX; + + if (of_get_property(np, "linux,rs485-enabled-at-boot-time", + NULL)) + rs485conf->flags |= SER_RS485_ENABLED; + } + } else { + atmel_port->rs485 = pdata->rs485; + } + +} + static void atmel_set_ops(struct uart_port *port) { struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); @@ -1409,6 +1483,7 @@ static void atmel_set_ops(struct uart_port *port) */ static int atmel_startup(struct uart_port *port) { + struct platform_device *pdev = to_platform_device(port->dev); struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); struct tty_struct *tty = port->state->port.tty; int retval; @@ -1433,6 +1508,8 @@ static int atmel_startup(struct uart_port *port) /* * Initialize DMA (if necessary) */ + atmel_init_property(atmel_port, pdev); + if (atmel_port->prepare_rx) { retval = atmel_port->prepare_rx(port); if (retval < 0) @@ -1878,55 +1955,6 @@ static struct uart_ops atmel_pops = { #endif }; -static void atmel_of_init_port(struct atmel_uart_port *atmel_port, - struct device_node *np) -{ - u32 rs485_delay[2]; - - /* DMA/PDC usage specification */ - if (of_get_property(np, "atmel,use-dma-rx", NULL)) { - if (of_get_property(np, "dmas", NULL)) { - atmel_port->use_dma_rx = 1; - atmel_port->use_pdc_rx = 0; - } else { - atmel_port->use_dma_rx = 0; - atmel_port->use_pdc_rx = 1; - } - } else { - atmel_port->use_dma_rx = 0; - atmel_port->use_pdc_rx = 0; - } - - if (of_get_property(np, "atmel,use-dma-tx", NULL)) { - if (of_get_property(np, "dmas", NULL)) { - atmel_port->use_dma_tx = 1; - atmel_port->use_pdc_tx = 0; - } else { - atmel_port->use_dma_tx = 0; - atmel_port->use_pdc_tx = 1; - } - } else { - atmel_port->use_dma_tx = 0; - atmel_port->use_pdc_tx = 0; - } - - /* rs485 properties */ - if (of_property_read_u32_array(np, "rs485-rts-delay", - rs485_delay, 2) == 0) { - struct serial_rs485 *rs485conf = &atmel_port->rs485; - - rs485conf->delay_rts_before_send = rs485_delay[0]; - rs485conf->delay_rts_after_send = rs485_delay[1]; - rs485conf->flags = 0; - - if (of_get_property(np, "rs485-rx-during-tx", NULL)) - rs485conf->flags |= SER_RS485_RX_DURING_TX; - - if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL)) - rs485conf->flags |= SER_RS485_ENABLED; - } -} - /* * Configure the port from the platform device resource info. */ @@ -1936,17 +1964,10 @@ static void atmel_init_port(struct atmel_uart_port *atmel_port, struct uart_port *port = &atmel_port->uart; struct atmel_uart_data *pdata = pdev->dev.platform_data; - if (pdev->dev.of_node) { - atmel_of_init_port(atmel_port, pdev->dev.of_node); - } else { - atmel_port->use_pdc_rx = pdata->use_dma_rx; - atmel_port->use_pdc_tx = pdata->use_dma_tx; - atmel_port->use_dma_rx = 0; - atmel_port->use_dma_tx = 0; - atmel_port->rs485 = pdata->rs485; - } + if (!atmel_init_property(atmel_port, pdev)) + atmel_set_ops(port); - atmel_set_ops(port); + atmel_init_rs485(atmel_port, pdev); port->iotype = UPIO_MEM; port->flags = UPF_BOOT_AUTOCONF;