From patchwork Tue Jun 28 05:32:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhuvanchandra DV X-Patchwork-Id: 9201881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5E43D6075F for ; Tue, 28 Jun 2016 05:37:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D4C7285C3 for ; Tue, 28 Jun 2016 05:37:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FE68285E9; Tue, 28 Jun 2016 05:37:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D4DB9285C3 for ; Tue, 28 Jun 2016 05:37:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bHlgE-0001kY-Mb; Tue, 28 Jun 2016 05:35:26 +0000 Received: from mail-db5eur01on0105.outbound.protection.outlook.com ([104.47.2.105] helo=EUR01-DB5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bHlej-0007cL-VB for linux-arm-kernel@lists.infradead.org; Tue, 28 Jun 2016 05:33:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toradex.onmicrosoft.com; s=selector1-toradex-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DTlzGl7FO/D+Me1mRA35o5oj32a/X4RGOAf9xrndoCY=; b=EEWrANsWrpWa7o1LYATWWdCTZ7qDMNPaalMz3tMuXf37qwuU8DuH+jnXK/dDl3welTkEjzb+0e7LEa9xFsSs9ePDni2rWo3BR83S7DsbevSXuC6PgjQ9QjNQ2auMBdcCuA8g9qjmyZ2TgXVPMxInIaMDJSzvuSqaZeby0u25pu4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bhuvanchandra.dv@toradex.com; Received: from tdx-in-nb-0014.toradex.ext (115.115.243.34) by HE1PR0501MB2089.eurprd05.prod.outlook.com (10.167.246.9) with Microsoft SMTP Server (TLS) id 15.1.523.12; Tue, 28 Jun 2016 05:33:35 +0000 From: Bhuvanchandra DV To: Subject: [PATCH v2 9/9] tty: serial: fsl_lpuart: Add support for RS-485 Date: Tue, 28 Jun 2016 11:02:35 +0530 Message-ID: <20160628053235.5114-10-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160628053235.5114-1-bhuvanchandra.dv@toradex.com> References: <20160628053235.5114-1-bhuvanchandra.dv@toradex.com> MIME-Version: 1.0 X-Originating-IP: [115.115.243.34] X-ClientProxiedBy: BM1PR01CA0056.INDPRD01.PROD.OUTLOOK.COM (10.163.199.28) To HE1PR0501MB2089.eurprd05.prod.outlook.com (10.167.246.9) X-MS-Office365-Filtering-Correlation-Id: 092179f6-60e2-4af2-1559-08d39f15c1a1 X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2089; 2:HDhTu4oiXHsg7I9LKewgAqdDJ/Y8iBrT5GBC7cBwYiwL7w0zyQTp7uKD0KnPUGLaA1XfnGS8YZKjhRv60tSuSySormfjtPsH4vrZocOnZ6hCWcoJvPGQbdPjHp32CK+OuPhlPNIx6V3vUJC3b+w60xY3eWoeRv8jyEi80wCG4Ur5sibezwbHpKheOlMRk0Eh; 3:0i0+Wjyxj1q0c49MMWtt30WRiKN1EaOUxnPJ7yAHWWplOCCvIvC7qo53kOnDKhdSP5445/liNkK1TAYsubz/V0qrVONY3vnQ07nCIKkk4lL4vHnrDFZWAbPTaxI0ghJB X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0501MB2089; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2089; 25:3RhTvN7mI3t7W6W3Qm5Qp6KWl87VoyUVqJuplawKyQfeZgBtoPs4BdXVO2+K8cw09qVDq7A6bRMak+A00EgutYxlFO0FNW1gv+i+KuczyqEV4XXZpd77HAE4opZVceyIrJoW79uOtFsfRKj7Jvb8Nn65MHJOIASAIZz5PglqczNWbCfuzoI00qN2AiEgSeDTQ9LMXoqMZYsKk8Nv98J48KqA9/mXjUvIssAwEwNob2AfeepA0H89G72a0wfB79RIbC+xfj/0HSDI0Axts1HV67DONb+l/SvJBghl5p+5Dh5dWvXW18sx4xHllV3HPRV/4TFwd36UruZDuFZUZIWWEmn04XDDrv0qTevdWOb5lWDwjvWB0q/pB4klxAnl3iKLn0LhT65/dP+bwm28R/Vljkr5SX1KdhaioKqAIBaJ/zbQ+wielw/xfRquzApZfdHxGos74ivWjAGKAnPvFAZibSKTs9eY8zFCT6dfVYQAHWUbhQGpwcfYbAnI+jQ2NvZTx+mP74KaiDuJOMxr0DrIkp+7yharLiiyRbws4O8P+nGP+6RBfAPqsxI6F22i8oK4JG2w9yDZRe6/hXN7EYDVDfWf9mL5Ajg619VzT+RtIRYcPmZSDNZGHMFH+OvxdtQ9y+n29JzHH3aQgY1V1/sZSe6Bv0tmLRi8utwAotsfGwjao+PzoP1E2oxfb7sxohIBkmYa4AQL/TANaukRr55ab8uxpvmWfHABj1oyiDiT80M= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2089; 20:Qt/5X72C3URcRAWRGxtAbAzKHivHL+VsTEewk14ZVC5avH4+7gX0VorvJfvkP6O6ClA8wtf2DPh0SbwH6FJX6zWK22JKH1P9wtMO2bkErrq9KRmc5RCWJRRY0DWjPPZopbksgcxhA5XzSLPFczDJKC21h4QUYfb7U7JhmjYS6g4le+Yn58D3wQx7ZCm1gUDjLTVMhG6oBK29p+QPwGwBZFxtetWtXLxKIYZvWxHpxDcyH73zPM9Vr2i8SKEuQ9q5OG4l+J+Htm+hlK+R8tQCte3Y5QHjFGxuIYGL3QVs7XRLfws6NYkXIR1HMyDTVsHae5T84sqh1MmI8YrvDFB1dw==; 4:x3Sph3s7SppchrJRVkeREHIwZbgW0exK0JxGrDlYbdPxgbKc0TdwOvZBoLFZgG6nmoVho9XyWOHj9jSsJ8g3HJqTWqEcPPEv7EHKCtCdWW3m4vJ8gROcTtQqEZm5QVHwluJEXu1tGNnyQ09SM8tIrQOHU4OlAYie5gyek7MIJWt0fgNR8YGCRr2L5KuNs63/Af3ewrZXDvgTmiEBRYxILmdYNvYevGYEx3hEPnRKSOPEzHptezJELjrQCwiPQGY0CO2bHdX6ckQzjNnLikQXNcI3mL/MKp1JNhhB0ga4g95MjlzsxgD0smXzjkNUbDu1lu7G30OoYOAkGhNaJU24YpkgwcfSuay+ePr4kIRY3SG2B7ohZrjbfWESXokvR+LL X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:HE1PR0501MB2089; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2089; X-Forefront-PRVS: 0987ACA2E2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(189998001)(50226002)(110136002)(107886002)(7846002)(47776003)(66066001)(36756003)(8676002)(101416001)(1076002)(48376002)(33646002)(6116002)(81166006)(92566002)(3846002)(50986999)(586003)(81156014)(50466002)(2351001)(2950100001)(77096005)(105586002)(229853001)(86362001)(76176999)(5003940100001)(68736007)(305945005)(106356001)(4326007)(7736002)(53416004)(4001430100002)(19580405001)(19580395003)(69596002)(42186005)(97736004)(2906002); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0501MB2089; H:tdx-in-nb-0014.toradex.ext; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: toradex.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0501MB2089; 23:/P2YJ3hkUVW8LmpCkBRdeue0WeRcn24BqzVogCE?= =?us-ascii?Q?zFHr5pc5sad2oWyllAniGmEIFDehC8p4YN8HoyYXg+jWFX8h+1hlhthmG+xS?= =?us-ascii?Q?3sOPM7cguaQaZCV7SV8CxuVO/Tswm5cfCTtXiZkHpWqCd26upfiVfqrE1unY?= =?us-ascii?Q?FUQtJyV5ydQPQmPZGomMJ8nFsKHRF42dhUfAYM0NbmRVfDVE1xcCPw6O23zp?= =?us-ascii?Q?cRvB4jQyu9x9ceH0jeIhVEN4Cck2YMiW9C/kkec/AjHynchYwzXgI3wkluiY?= =?us-ascii?Q?L02oNHp+BCU9RD/uiPwwulyT/jPgwKoASZT+V+u0T2HxmCiezv+ghOisOO3B?= =?us-ascii?Q?CFweerRH5dGr9X0jtXsYkVxdxQNK+L7VbcEuVCUoEK0Gw6eFfqFovB/u4XVb?= =?us-ascii?Q?QHT0JDA/uglU/3d9uFj0VK8OBqYul5VT3JCMJNSzMTm2a5Pnz9tu2caljxLc?= =?us-ascii?Q?4T7iZurq22Q3jfuC7+90NxZuEoq9V5/FcRIQopt5AxJh/0Td0dTuz7zzFtxp?= =?us-ascii?Q?FlJk53XtOE4beDoOuAvZufvtAELrZkhWkMM1bNwfEP16i8qZKzusMT6cndkk?= =?us-ascii?Q?TSezO91rxE3B5g4AuK3n48yFug3a5RLruMGrBplF8WDg5yWI3iVcOkQy8LGH?= =?us-ascii?Q?cuR2mxGeInyox68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ooJEwfgykvIXJ9zfxr84Gmaed9+NnzT5wGIkL0xvGGOsd38uuMSWGiTzxp+S19snLUH/X5zn2DJbedAMMgVVafstRXPEUxYT8t7vw==; 24:0p8N1bcmWwdp/YHoBu95bVAyztANlI+4Q8ww6aBbLLrOMyfr1DREEohMGJiEaS0XNpQD72FbxjMLWNjRXL49KlRXoXMMHq7iGQLrHZTSlcY=; 7:rXRAl/m/tWCGQOgkH5e5DpR+kA2e4YlF+O/WJym1Cn3PivUZsORWvro/sUkYmozWDRzPkVvoJvya+jEi920O04r2lHLbej8Sbv6DhVd+Xr43C7LoSmx+1BrDhVbHaCzbW1wCyjInh0xLDSDAfQBgRQ6udwPLTNJ+hpG+Xk7xVs3VLncSdHGaUCTCviBjkn74u0i1/t0XBO2D56V0ZL/rmzQA43fPPX8B8S5smjTdNMMMr/8ibjFp26opcUiK6YAS115eJ+2s+T8onXq+h4gssA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2016 05:33:35.7840 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2089 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160627_223354_436171_6E1A8AD5 X-CRM114-Status: GOOD ( 15.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-serial@vger.kernel.org, mturquette@baylibre.com, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, stefan@agner.ch, kernel@pengutronix.de, jslaby@suse.com, shawnguo@kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bhuvanchandra DV Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Enable Vybrid's build-in support for RS-485 auto RTS for controlling line direction of RS-485 transceiver driver. Enable RS485 feature by either using ioctrl 'TIOCSRS485' or enable it in the device tree by setting 'linux,rs485-enabled-at-boot-time' property. Signed-off-by: Bhuvanchandra DV --- drivers/tty/serial/fsl_lpuart.c | 78 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index 134090a..4d1fca4 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -917,6 +917,52 @@ static void lpuart_dma_rx_free(struct uart_port *port) sport->dma_rx_cookie = -EINVAL; } +static int lpuart_config_rs485(struct uart_port *port, + struct serial_rs485 *rs485) +{ + struct lpuart_port *sport = container_of(port, + struct lpuart_port, port); + + u8 modem = readb(sport->port.membase + UARTMODEM) & + ~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE); + writeb(modem, sport->port.membase + UARTMODEM); + + if (rs485->flags & SER_RS485_ENABLED) { + /* Enable auto RS-485 RTS mode */ + modem |= UARTMODEM_TXRTSE; + + /* + * RTS needs to be logic HIGH either during transer _or_ after + * transfer, other variants are not supported by the hardware. + */ + + if (!(rs485->flags & (SER_RS485_RTS_ON_SEND | + SER_RS485_RTS_AFTER_SEND))) + rs485->flags |= SER_RS485_RTS_ON_SEND; + + if (rs485->flags & SER_RS485_RTS_ON_SEND && + rs485->flags & SER_RS485_RTS_AFTER_SEND) + rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; + + /* + * The hardware defaults to RTS logic HIGH while transfer. + * Switch polarity in case RTS shall be logic HIGH + * after transfer. + * Note: UART is assumed to be active high. + */ + if (rs485->flags & SER_RS485_RTS_ON_SEND) + modem &= ~UARTMODEM_TXRTSPOL; + else if (rs485->flags & SER_RS485_RTS_AFTER_SEND) + modem |= UARTMODEM_TXRTSPOL; + } + + /* Store the new configuration */ + sport->port.rs485 = *rs485; + + writeb(modem, sport->port.membase + UARTMODEM); + return 0; +} + static unsigned int lpuart_get_mctrl(struct uart_port *port) { unsigned int temp = 0; @@ -950,17 +996,22 @@ static unsigned int lpuart32_get_mctrl(struct uart_port *port) static void lpuart_set_mctrl(struct uart_port *port, unsigned int mctrl) { unsigned char temp; + struct lpuart_port *sport = container_of(port, + struct lpuart_port, port); - temp = readb(port->membase + UARTMODEM) & + /* Make sure RXRTSE bit is not set when RS485 is enabled */ + if (!(sport->port.rs485.flags & SER_RS485_ENABLED)) { + temp = readb(sport->port.membase + UARTMODEM) & ~(UARTMODEM_RXRTSE | UARTMODEM_TXCTSE); - if (mctrl & TIOCM_RTS) - temp |= UARTMODEM_RXRTSE; + if (mctrl & TIOCM_RTS) + temp |= UARTMODEM_RXRTSE; - if (mctrl & TIOCM_CTS) - temp |= UARTMODEM_TXCTSE; + if (mctrl & TIOCM_CTS) + temp |= UARTMODEM_TXCTSE; - writeb(temp, port->membase + UARTMODEM); + writeb(temp, port->membase + UARTMODEM); + } } static void lpuart32_set_mctrl(struct uart_port *port, unsigned int mctrl) @@ -1256,6 +1307,13 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios, cr1 |= UARTCR1_M; } + /* + * When auto RS-485 RTS mode is enabled, + * hardware flow control need to be disabled. + */ + if (sport->port.rs485.flags & SER_RS485_ENABLED) + termios->c_cflag &= ~CRTSCTS; + if (termios->c_cflag & CRTSCTS) { modem |= (UARTMODEM_RXRTSE | UARTMODEM_TXCTSE); } else { @@ -1864,6 +1922,8 @@ static int lpuart_probe(struct platform_device *pdev) sport->port.ops = &lpuart_pops; sport->port.flags = UPF_BOOT_AUTOCONF; + sport->port.rs485_config = lpuart_config_rs485; + sport->clk = devm_clk_get(&pdev->dev, "ipg"); if (IS_ERR(sport->clk)) { ret = PTR_ERR(sport->clk); @@ -1904,6 +1964,12 @@ static int lpuart_probe(struct platform_device *pdev) dev_info(sport->port.dev, "DMA rx channel request failed, " "operating without rx DMA\n"); + if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time")) { + sport->port.rs485.flags |= SER_RS485_ENABLED; + sport->port.rs485.flags |= SER_RS485_RTS_ON_SEND; + writeb(UARTMODEM_TXRTSE, sport->port.membase + UARTMODEM); + } + return 0; }