From patchwork Thu Feb 21 17:17:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kepplinger X-Patchwork-Id: 10824409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D716113B5 for ; Thu, 21 Feb 2019 17:19:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACEC729F84 for ; Thu, 21 Feb 2019 17:19:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C746311DB; Thu, 21 Feb 2019 17:19:01 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 00D7F2BA10 for ; Thu, 21 Feb 2019 17:19:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=T7Eo/gNrE4u1bniNFdxN7jNkudx96I20403Wk4JZT+o=; b=DNakpWqtl0MNcomrAyOALjgCF Lr64kegDXfbibD+8k9CPNdJR6joZl/CxAFytwX3CZDGVsnPNZnUr+/ZZ2K06777mU/k6yOADj5D6l G7fbH2lpwcRF7MyAIH4eO+2TxCwui/7CAUzfE0Yd/ZIfjo8jFeXzurTtbODZ4K2z9gHcdliz42mqL BS4D63NwKtmblWmJBWbBM+ToH/5IvXzu1ryX0Vf4dOn9EL2e6bB1knM9V7K4D6mGLMAYg+8wSCxr2 0uRhmyPCXIRpyyCUMDma/MSK4xueeML1AV7BwafXyPCi7h6OYPyR32i0QslvQdv7bigMH1Px3sAze YppJf46dA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwrzt-0006X0-UM; Thu, 21 Feb 2019 17:18:57 +0000 Received: from mx-ginzinger.sigmacloud.services ([185.154.235.147]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwrzZ-00065G-PU for linux-arm-kernel@lists.infradead.org; Thu, 21 Feb 2019 17:18:42 +0000 Received: from [31.193.165.228] (port=45893 helo=mx-ginzinger.sigmacloud.services) by mx-ginzinger.sigmacloud.services with esmtps (TLSv1.2:AES256-GCM-SHA384:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1gwrzJ-00028u-15; Thu, 21 Feb 2019 18:18:21 +0100 Received: from martin-laptop.buero.ginzinger.com (10.10.1.120) by exc1.buero.ginzinger.com (10.1.1.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1466.3; Thu, 21 Feb 2019 18:18:20 +0100 X-CTCH-RefID: str=0001.0A0B020F.5C6EDD5D.0031, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 From: Martin Kepplinger To: , , , , , , , , , , , , , , Subject: [PATCH v2 4/9] serial: 8250: add support for rs485 RTS delays in microseconds Date: Thu, 21 Feb 2019 18:17:53 +0100 Message-ID: <20190221171758.10322-4-martin.kepplinger@ginzinger.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221171758.10322-1-martin.kepplinger@ginzinger.com> References: <20190221171758.10322-1-martin.kepplinger@ginzinger.com> X-Originating-IP: [10.10.1.120] X-ClientProxiedBy: exc1.buero.ginzinger.com (10.1.1.204) To exc1.buero.ginzinger.com (10.1.1.204) X-EXCLAIMER-MD-ORIGINAL-SUBJECT: [NOSIG][NODISC][PATCH v2 4/9] serial: 8250: add support for rs485 RTS delays in microseconds X-EXCLAIMER-MD-CONFIG: 9dd172f7-de2e-4231-b886-ec11f46e03b3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190221_091838_379105_3B1B20D4 X-CRM114-Status: GOOD ( 15.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Kepplinger , linux-kernel@vger.kernel.org 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 Read struct serial_rs485's flag SER_RS485_DELAY_IN_USEC and apply the delay accordingly. Signed-off-by: Martin Kepplinger --- drivers/tty/serial/8250/8250_omap.c | 13 +++++++++++-- drivers/tty/serial/8250/8250_port.c | 25 +++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c index 0a8316632d75..cbce43ac60b1 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -720,8 +720,17 @@ static int omap_8250_rs485_config(struct uart_port *port, struct uart_8250_port *up = up_to_u8250p(port); /* Clamp the delays to [0, 100ms] */ - rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U); - rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U); + if (rs485->flags & SER_RS485_DELAY_IN_USEC) { + rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, + 100000U); + rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, + 100000U); + } else { + rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, + 100U); + rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, + 100U); + } port->rs485 = *rs485; diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index d2f3310abe54..0cee4aa8323d 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1483,6 +1483,15 @@ static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec) hrtimer_start(hrt, t, HRTIMER_MODE_REL); } +static void start_hrtimer_us(struct hrtimer *hrt, unsigned long usec) +{ + long sec = usec / 1000000; + long nsec = (usec % 1000000) * 1000000000; + ktime_t t = ktime_set(sec, nsec); + + hrtimer_start(hrt, t, HRTIMER_MODE_REL); +} + static void __stop_tx_rs485(struct uart_8250_port *p) { struct uart_8250_em485 *em485 = p->em485; @@ -1493,8 +1502,12 @@ static void __stop_tx_rs485(struct uart_8250_port *p) */ if (p->port.rs485.delay_rts_after_send > 0) { em485->active_timer = &em485->stop_tx_timer; - start_hrtimer_ms(&em485->stop_tx_timer, - p->port.rs485.delay_rts_after_send); + if (p->port.rs485.flags & SER_RS485_DELAY_IN_USEC) + start_hrtimer_us(&em485->stop_tx_timer, + p->port.rs485.delay_rts_after_send); + else + start_hrtimer_ms(&em485->stop_tx_timer, + p->port.rs485.delay_rts_after_send); } else { __do_stop_tx_rs485(p); } @@ -1600,8 +1613,12 @@ static inline void start_tx_rs485(struct uart_port *port) if (up->port.rs485.delay_rts_before_send > 0) { em485->active_timer = &em485->start_tx_timer; - start_hrtimer_ms(&em485->start_tx_timer, - up->port.rs485.delay_rts_before_send); + if (up->port.rs485.flags & SER_RS485_DELAY_IN_USEC) + start_hrtimer_us(&em485->start_tx_timer, + up->port.rs485.delay_rts_before_send); + else + start_hrtimer_ms(&em485->start_tx_timer, + up->port.rs485.delay_rts_before_send); return; } }