linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
To: Bjorn Andersson <bjorn.andersson@linaro.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: <linux-remoteproc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	Deepak Kumar Singh <quic_deesin@quicinc.com>,
	Chris Lew <quic_clew@quicinc.com>, <arnaud.pouliquen@foss.st.com>
Subject: [RFC PATCH 09/10] rpmsg: tty : Add the support of the flow control
Date: Fri, 20 May 2022 10:29:39 +0200	[thread overview]
Message-ID: <20220520082940.2984914-10-arnaud.pouliquen@foss.st.com> (raw)
In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com>

Add Software flow control support based on the RPMsg flow
control channel.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
---
 drivers/tty/rpmsg_tty.c | 50 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/drivers/tty/rpmsg_tty.c b/drivers/tty/rpmsg_tty.c
index 29db413bbc03..fc1dc4a5ca9d 100644
--- a/drivers/tty/rpmsg_tty.c
+++ b/drivers/tty/rpmsg_tty.c
@@ -30,6 +30,7 @@ struct rpmsg_tty_port {
 	struct tty_port		port;	 /* TTY port data */
 	int			id;	 /* TTY rpmsg index */
 	struct rpmsg_device	*rpdev;	 /* rpmsg device */
+	bool			flow_stopped; /* remote device flow control */
 };
 
 static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src)
@@ -106,6 +107,9 @@ static unsigned int rpmsg_tty_write_room(struct tty_struct *tty)
 	struct rpmsg_tty_port *cport = tty->driver_data;
 	int size;
 
+	if (cport->flow_stopped)
+		return 0;
+
 	size = rpmsg_get_mtu(cport->rpdev->ept);
 	if (size < 0)
 		return 0;
@@ -118,6 +122,28 @@ static void rpmsg_tty_hangup(struct tty_struct *tty)
 	tty_port_hangup(tty->port);
 }
 
+static void rpmsg_tty_throttle(struct tty_struct *tty)
+{
+	struct rpmsg_tty_port *cport = tty->driver_data;
+	int ret;
+
+	/* Disable remote transmission */
+	ret = rpmsg_set_flow_control(cport->rpdev->ept, RPMSG_ADDR_ANY, 0);
+	if (ret && ret != ENXIO)
+		dev_err(tty->dev, "cannot send control (%d)\n", ret);
+};
+
+static void rpmsg_tty_unthrottle(struct tty_struct *tty)
+{
+	struct rpmsg_tty_port *cport = tty->driver_data;
+	int ret;
+
+	/* Enable remote transmission */
+	ret = rpmsg_set_flow_control(cport->rpdev->ept, RPMSG_ADDR_ANY, 1);
+	if (ret && ret != ENXIO)
+		dev_err(tty->dev, "cannot send control (%d)\n", ret);
+};
+
 static const struct tty_operations rpmsg_tty_ops = {
 	.install	= rpmsg_tty_install,
 	.open		= rpmsg_tty_open,
@@ -126,6 +152,8 @@ static const struct tty_operations rpmsg_tty_ops = {
 	.write_room	= rpmsg_tty_write_room,
 	.hangup		= rpmsg_tty_hangup,
 	.cleanup	= rpmsg_tty_cleanup,
+	.throttle	= rpmsg_tty_throttle,
+	.unthrottle	= rpmsg_tty_unthrottle,
 };
 
 static struct rpmsg_tty_port *rpmsg_tty_alloc_cport(void)
@@ -162,11 +190,32 @@ static void rpmsg_tty_destruct_port(struct tty_port *port)
 	kfree(cport);
 }
 
+static void rpmsg_tty_dtr_rts(struct tty_port *port, int raise)
+{
+	if (!port->tty)
+		return;
+
+	if (raise)
+		rpmsg_tty_unthrottle(port->tty);
+	else
+		rpmsg_tty_throttle(port->tty);
+}
+
 static const struct tty_port_operations rpmsg_tty_port_ops = {
 	.destruct = rpmsg_tty_destruct_port,
+	.dtr_rts  = rpmsg_tty_dtr_rts,
 };
 
 
+static int rpmsg_tty_dsr_cts(struct rpmsg_device *rpdev, void *priv, u32 state)
+{
+	struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev);
+
+	cport->flow_stopped = !state;
+
+	return 0;
+}
+
 static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
 {
 	struct rpmsg_tty_port *cport;
@@ -225,6 +274,7 @@ static struct rpmsg_driver rpmsg_tty_rpmsg_drv = {
 	.probe		= rpmsg_tty_probe,
 	.callback	= rpmsg_tty_cb,
 	.remove		= rpmsg_tty_remove,
+	.signals        = rpmsg_tty_dsr_cts,
 };
 
 static int __init rpmsg_tty_init(void)
-- 
2.25.1


  parent reply	other threads:[~2022-05-20  8:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20  8:29 [RFC PATCH 00/10] Introduction of rpmsg flow control service Arnaud Pouliquen
2022-05-20  8:29 ` [RFC PATCH 01/10] rpmsg: core: Add signal API support Arnaud Pouliquen
2022-05-20  8:29 ` [RFC PATCH 02/10] rpmsg: char: Add TIOCMGET/TIOCMSET ioctl support Arnaud Pouliquen
2022-05-20  8:29 ` [RFC PATCH 03/10] rpmsg: core: Add rpmsg device remote flow control announcement ops Arnaud Pouliquen
2022-05-20  8:29 ` [RFC PATCH 04/10] rpmsg: virtio: Implement the announce_remote_fc ops Arnaud Pouliquen
2022-05-20  8:29 ` [RFC PATCH 05/10] rpmsg: Introduce flow control channel driver Arnaud Pouliquen
2022-05-20  8:29 ` [RFC PATCH 06/10] rpmsg: virtio: Add support of the VIRTIO_RPMSG_F_FC feature Arnaud Pouliquen
2022-05-20  8:29 ` [RFC PATCH 07/10] rpmsg: virtio: Implement the set_flow_control ops Arnaud Pouliquen
2022-05-20  8:29 ` [RFC PATCH 08/10] rpmsg: Add the destination address in rpmsg_set_flow_control Arnaud Pouliquen
2022-05-20  8:29 ` Arnaud Pouliquen [this message]
2022-05-20  8:29 ` [RFC PATCH 10/10] rpmsg: virtio: Set default dst address on flow control Arnaud Pouliquen
2022-05-24 15:34 ` [RFC PATCH 00/10] Introduction of rpmsg flow control service Mathieu Poirier
2022-05-25  8:57   ` Arnaud POULIQUEN

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=20220520082940.2984914-10-arnaud.pouliquen@foss.st.com \
    --to=arnaud.pouliquen@foss.st.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=quic_clew@quicinc.com \
    --cc=quic_deesin@quicinc.com \
    /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).