linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Mack <daniel@zonque.org>
To: devicetree@vger.kernel.org, linux-serial@vger.kernel.org
Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, jslaby@suse.com,
	jringle@gridpoint.com, m.brock@vanmierlo.com,
	pascal.huerst@gmail.com, Daniel Mack <daniel@zonque.org>
Subject: [PATCH v3 6/6] sc16is7xx: Read the LSR register for basic device presence check
Date: Thu, 21 May 2020 11:11:52 +0200	[thread overview]
Message-ID: <20200521091152.404404-7-daniel@zonque.org> (raw)
In-Reply-To: <20200521091152.404404-1-daniel@zonque.org>

Currently, the driver probes just fine and binds all its resources even
if the physical device is not present.

As the device lacks an identification register, let's at least read the
LSR register to check whether a device at the configured address responds
to the request at all.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 drivers/tty/serial/sc16is7xx.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index 7e2360f8e393..5e84ed5938af 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -1181,6 +1181,7 @@ static int sc16is7xx_probe(struct device *dev,
 {
 	struct sched_param sched_param = { .sched_priority = MAX_RT_PRIO / 2 };
 	unsigned long freq = 0, *pfreq = dev_get_platdata(dev);
+	unsigned int val;
 	u32 uartclk = 0;
 	int i, ret;
 	struct sc16is7xx_port *s;
@@ -1188,6 +1189,16 @@ static int sc16is7xx_probe(struct device *dev,
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 
+	/*
+	 * This device does not have an identification register that would
+	 * tell us if we are really connected to the correct device.
+	 * The best we can do is to check if communication is at all possible.
+	 */
+	ret = regmap_read(regmap,
+			  SC16IS7XX_LSR_REG << SC16IS7XX_REG_SHIFT, &val);
+	if (ret < 0)
+		return ret;
+
 	/* Alloc port structure */
 	s = devm_kzalloc(dev, struct_size(s, p, devtype->nr_uart), GFP_KERNEL);
 	if (!s) {
-- 
2.26.2


  parent reply	other threads:[~2020-05-21  9:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21  9:11 [PATCH v3 0/6] sc16is7xx: IrDA mode and threaded IRQs Daniel Mack
2020-05-21  9:11 ` [PATCH v3 1/6] dt-bindings: sc16is7xx: Add flag to activate IrDA mode Daniel Mack
2020-05-28 22:42   ` Rob Herring
2020-05-21  9:11 ` [PATCH v3 2/6] " Daniel Mack
2020-05-21  9:11 ` [PATCH v3 3/6] sc16is7xx: Always use falling edge IRQ Daniel Mack
2020-05-21  9:11 ` [PATCH v3 4/6] sc16is7xx: Use threaded IRQ Daniel Mack
2020-05-21  9:11 ` [PATCH v3 5/6] sc16is7xx: Allow sharing the IRQ line Daniel Mack
2020-05-21  9:11 ` Daniel Mack [this message]
2020-05-22  9:07 ` [PATCH v3 0/6] sc16is7xx: IrDA mode and threaded IRQs Greg KH
2020-05-23 12:27   ` Daniel Mack

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=20200521091152.404404-7-daniel@zonque.org \
    --to=daniel@zonque.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jringle@gridpoint.com \
    --cc=jslaby@suse.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=m.brock@vanmierlo.com \
    --cc=pascal.huerst@gmail.com \
    --cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).