linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <moorray3-5tc4TXWwyLM@public.gmane.org>
To: Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
Cc: "Jon Ringle" <jringle-gkqdKIIuv0Hby3iVrkZq2A@public.gmane.org>,
	linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Karol Dębogórski" <k.debogorski-XA5MxPtj9CQ@public.gmane.org>,
	"Jakub Kicinski" <kubakici-5tc4TXWwyLM@public.gmane.org>
Subject: [PATCH 3/4] sc16is7xx: expose RTS inversion in RS-485 mode
Date: Tue, 17 Mar 2015 00:28:48 +0100	[thread overview]
Message-ID: <1426548529-21738-4-git-send-email-moorray3@wp.pl> (raw)
In-Reply-To: <1426548529-21738-1-git-send-email-moorray3-5tc4TXWwyLM@public.gmane.org>

From: Jakub Kicinski <kubakici-5tc4TXWwyLM@public.gmane.org>

Hardware is capable of inverting RTS signal when working
in RS-485 mode.  Expose this functionality to user space.
Relay on a matching combination of standard flags
(SER_RS485_RTS_ON_SEND and SER_RS485_RTS_AFTER_SEND) to
detect when user space is requesting inverted RTS mode.

Signed-off-by: Jakub Kicinski <kubakici-5tc4TXWwyLM@public.gmane.org>
---
 drivers/tty/serial/sc16is7xx.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index e6b396e584f3..24902d589b07 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -829,16 +829,30 @@ static void sc16is7xx_set_termios(struct uart_port *port,
 }
 
 static int sc16is7xx_config_rs485(struct uart_port *port,
-				   struct serial_rs485 *rs485)
+				  struct serial_rs485 *rs485)
 {
-	if (port->rs485.flags & SER_RS485_ENABLED)
-		sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT);
-	else
-		sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT,
-				      0);
+	const u32 mask = SC16IS7XX_EFCR_AUTO_RS485_BIT |
+			 SC16IS7XX_EFCR_RTS_INVERT_BIT;
+	u32 efcr = 0;
+
+	if (rs485->flags & SER_RS485_ENABLED) {
+		bool rts_during_rx, rts_during_tx;
+
+		rts_during_rx = rs485->flags & SER_RS485_RTS_AFTER_SEND;
+		rts_during_tx = rs485->flags & SER_RS485_RTS_ON_SEND;
+
+		efcr |= SC16IS7XX_EFCR_AUTO_RS485_BIT;
+
+		if (!rts_during_rx && rts_during_tx)
+			/* default */;
+		else if (rts_during_rx && !rts_during_tx)
+			efcr |= SC16IS7XX_EFCR_RTS_INVERT_BIT;
+		else
+			return -EINVAL;
+	}
+
+	sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, mask, efcr);
+
 	port->rs485 = *rs485;
 
 	return 0;
-- 
2.1.0

  parent reply	other threads:[~2015-03-16 23:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16 23:28 [PATCH 0/4] serial: sc16is7xx: bunch of small fixes Jakub Kicinski
     [not found] ` <1426548529-21738-1-git-send-email-moorray3-5tc4TXWwyLM@public.gmane.org>
2015-03-16 23:28   ` [PATCH 1/4] sc16is7xx: remove ports on probe error path Jakub Kicinski
     [not found]     ` <1426548529-21738-2-git-send-email-moorray3-5tc4TXWwyLM@public.gmane.org>
2015-03-17 14:41       ` Jon Ringle
2015-03-16 23:28   ` [PATCH 2/4] sc16is7xx: don't wipe out port configuration on shutdown Jakub Kicinski
     [not found]     ` <1426548529-21738-3-git-send-email-moorray3-5tc4TXWwyLM@public.gmane.org>
2015-03-17 14:43       ` Jon Ringle
2015-03-16 23:28   ` Jakub Kicinski [this message]
     [not found]     ` <1426548529-21738-4-git-send-email-moorray3-5tc4TXWwyLM@public.gmane.org>
2015-03-17 14:45       ` [PATCH 3/4] sc16is7xx: expose RTS inversion in RS-485 mode Jon Ringle
     [not found]         ` <alpine.DEB.2.10.1503171043400.3566-cn3jTo8IYkmeSY0hgfj7bYJKnSiCLr9B28t4la5Gatg@public.gmane.org>
2015-03-17 14:57           ` Jakub Kiciński
2015-03-26 21:37             ` Greg Kroah-Hartman
     [not found]               ` <20150326213701.GA29278-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2015-03-26 21:48                 ` Jakub Kiciński
2015-03-16 23:28   ` [PATCH 4/4] sc16is7xx: enable the clock Jakub Kicinski
     [not found]     ` <1426548529-21738-5-git-send-email-moorray3-5tc4TXWwyLM@public.gmane.org>
2015-03-17 14:46       ` Jon Ringle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426548529-21738-4-git-send-email-moorray3@wp.pl \
    --to=moorray3-5tc4txwwylm@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=jringle-gkqdKIIuv0Hby3iVrkZq2A@public.gmane.org \
    --cc=k.debogorski-XA5MxPtj9CQ@public.gmane.org \
    --cc=kubakici-5tc4TXWwyLM@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).