public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Cc: Jiri Slaby <jirislaby@kernel.org>, Hugo Villeneuve <hugo@hugovil.com>
Subject: [PATCH v2 07/16] serial: max3100: Enable TIOCM_LOOP
Date: Tue,  2 Apr 2024 22:50:34 +0300	[thread overview]
Message-ID: <20240402195306.269276-8-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20240402195306.269276-1-andriy.shevchenko@linux.intel.com>

Enable or disable loopback at run-time.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/max3100.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 6dc20e4ec078..cd6a80e97868 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -32,14 +32,12 @@
 
 /**
  * struct plat_max3100 - MAX3100 SPI UART platform data
- * @loopback:            force MAX3100 in loopback
  * @crystal:             1 for 3.6864 Mhz, 0 for 1.8432
  *
  * You should use this structure in your machine description to specify
  * how the MAX3100 is connected.
  */
 struct plat_max3100 {
-	int loopback;
 	int crystal;
 };
 
@@ -109,6 +107,7 @@ struct max3100_port {
 
 	int minor;		/* minor number */
 	int crystal;		/* 1 if 3.6864Mhz crystal 0 for 1.8432 */
+	int loopback_commit;	/* need to change loopback */
 	int loopback;		/* 1 if we are in loopback mode */
 
 	/* for handling irqs: need workqueue since we do spi_sync */
@@ -257,7 +256,7 @@ static void max3100_work(struct work_struct *w)
 	struct max3100_port *s = container_of(w, struct max3100_port, work);
 	int rxchars;
 	u16 tx, rx;
-	int conf, cconf, crts;
+	int conf, cconf, cloopback, crts;
 	struct circ_buf *xmit = &s->port.state->xmit;
 
 	dev_dbg(&s->spi->dev, "%s\n", __func__);
@@ -268,11 +267,15 @@ static void max3100_work(struct work_struct *w)
 		conf = s->conf;
 		cconf = s->conf_commit;
 		s->conf_commit = 0;
+		cloopback = s->loopback_commit;
+		s->loopback_commit = 0;
 		crts = s->rts_commit;
 		s->rts_commit = 0;
 		spin_unlock(&s->conf_lock);
 		if (cconf)
 			max3100_sr(s, MAX3100_WC | conf, &rx);
+		if (cloopback)
+			max3100_sr(s, 0x4001, &rx);
 		if (crts) {
 			max3100_sr(s, MAX3100_WD | MAX3100_TE |
 				   (s->rts ? MAX3100_RTS : 0), &rx);
@@ -397,18 +400,24 @@ static void max3100_set_mctrl(struct uart_port *port, unsigned int mctrl)
 	struct max3100_port *s = container_of(port,
 					      struct max3100_port,
 					      port);
-	int rts;
+	int loopback, rts;
 
 	dev_dbg(&s->spi->dev, "%s\n", __func__);
 
+	loopback = (mctrl & TIOCM_LOOP) > 0;
 	rts = (mctrl & TIOCM_RTS) > 0;
 
 	spin_lock(&s->conf_lock);
+	if (s->loopback != loopback) {
+		s->loopback = loopback;
+		s->loopback_commit = 1;
+	}
 	if (s->rts != rts) {
 		s->rts = rts;
 		s->rts_commit = 1;
-		max3100_dowork(s);
 	}
+	if (s->loopback_commit || s->rts_commit)
+		max3100_dowork(s);
 	spin_unlock(&s->conf_lock);
 }
 
@@ -595,12 +604,6 @@ static int max3100_startup(struct uart_port *port)
 		return -EBUSY;
 	}
 
-	if (s->loopback) {
-		u16 tx, rx;
-		tx = 0x4001;
-		max3100_sr(s, tx, &rx);
-	}
-
 	s->conf_commit = 1;
 	max3100_dowork(s);
 	/* wait for clock to settle */
@@ -756,7 +759,6 @@ static int max3100_probe(struct spi_device *spi)
 	spi_set_drvdata(spi, max3100s[i]);
 	pdata = dev_get_platdata(&spi->dev);
 	max3100s[i]->crystal = pdata->crystal;
-	max3100s[i]->loopback = pdata->loopback;
 	max3100s[i]->minor = i;
 	timer_setup(&max3100s[i]->timer, max3100_timeout, 0);
 
-- 
2.43.0.rc1.1.gbec44491f096


  parent reply	other threads:[~2024-04-02 19:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 19:50 [PATCH v2 00/16] serial: max3100: Put into shape Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 01/16] serial: max3100: Lock port->lock when calling uart_handle_cts_change() Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 02/16] serial: max3100: Update uart_driver_registered on driver removal Andy Shevchenko
2024-04-02 20:11   ` Hugo Villeneuve
2024-04-02 19:50 ` [PATCH v2 03/16] serial: max3100: Fix bitwise types Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 04/16] serial: max3100: Make struct plat_max3100 local Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 05/16] serial: max3100: Remove custom HW shutdown support Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 06/16] serial: max3100: Replace custom polling timeout with standard one Andy Shevchenko
2024-04-02 19:50 ` Andy Shevchenko [this message]
2024-04-02 19:50 ` [PATCH v2 08/16] serial: max3100: Get crystal frequency via device property Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 09/16] serial: max3100: Remove duplicating irq field Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 10/16] serial: max3100: Switch to use dev_err_probe() Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 11/16] serial: max3100: Replace MODULE_ALIAS() with respective ID tables Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 12/16] serial: max3100: Switch to DEFINE_SIMPLE_DEV_PM_OPS() Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 13/16] serial: max3100: Extract to_max3100_port() helper macro Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 14/16] serial: max3100: Remove unneeded forward declaration Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 15/16] serial: max3100: Sort headers Andy Shevchenko
2024-04-02 19:50 ` [PATCH v2 16/16] serial: max3100: Update Kconfig entry Andy Shevchenko
2024-04-09 13:52 ` [PATCH v2 00/16] serial: max3100: Put into shape Greg Kroah-Hartman
2024-04-09 13:55   ` Andy Shevchenko
2024-04-09 14:48     ` Andy Shevchenko

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=20240402195306.269276-8-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hugo@hugovil.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.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