LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Mariusz Bialonczyk <manio@skyboo.net>
To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman <greg@kroah.com>
Cc: Mariusz Bialonczyk <manio@skyboo.net>
Subject: [PATCH 3/4 v2] w1: ds2413: when the slave is not responding during read, select it again
Date: Wed, 22 May 2019 12:40:53 +0200	[thread overview]
Message-ID: <20190522104053.14577-1-manio@skyboo.net> (raw)
In-Reply-To: <20190520070558.20142-3-manio@skyboo.net>

The protocol is not allowing to obtain a byte of 0xff for PIO_ACCESS_READ
call. It is very likely that the slave was not addressed properly and
it is just not respoding (leaving the bus in logic high state) during
the read of sampled PIO value.
We cannot just call w1_reset_resume_command() because the problem will
persist, instead try selecting (addressing) the slave again.

Signed-off-by: Mariusz Bialonczyk <manio@skyboo.net>
---
Changes in v2:
    Optimize the if statement so the most common is checked first.

 drivers/w1/slaves/w1_ds2413.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/w1/slaves/w1_ds2413.c b/drivers/w1/slaves/w1_ds2413.c
index d63778c70568..21f08ac8a4e0 100644
--- a/drivers/w1/slaves/w1_ds2413.c
+++ b/drivers/w1/slaves/w1_ds2413.c
@@ -24,6 +24,7 @@
 #define W1_F3A_FUNC_PIO_ACCESS_READ        0xF5
 #define W1_F3A_FUNC_PIO_ACCESS_WRITE       0x5A
 #define W1_F3A_SUCCESS_CONFIRM_BYTE        0xAA
+#define W1_F3A_INVALID_PIO_STATE           0xFF
 
 static ssize_t state_read(struct file *filp, struct kobject *kobj,
 			  struct bin_attribute *bin_attr, char *buf, loff_t off,
@@ -45,6 +46,7 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj,
 	mutex_lock(&sl->master->bus_mutex);
 	dev_dbg(&sl->dev, "mutex locked");
 
+next:
 	if (w1_reset_select_slave(sl))
 		goto out;
 
@@ -52,10 +54,15 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj,
 		w1_write_8(sl->master, W1_F3A_FUNC_PIO_ACCESS_READ);
 
 		*buf = w1_read_8(sl->master);
-		/* check for correct complement */
 		if ((*buf & 0x0F) == ((~*buf >> 4) & 0x0F)) {
+			/* complement is correct */
 			bytes_read = 1;
 			goto out;
+		} else if (*buf == W1_F3A_INVALID_PIO_STATE) {
+			/* slave didn't respond, try to select it again */
+			dev_warn(&sl->dev, "slave device did not respond to PIO_ACCESS_READ, " \
+					    "reselecting, retries left: %d\n", retries);
+			goto next;
 		}
 
 		if (w1_reset_resume_command(sl->master))
-- 
2.19.0.rc1


  reply	other threads:[~2019-05-22 10:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20  7:05 [PATCH 1/4] w1: ds2413: output_write() cosmetic fixes / simplify Mariusz Bialonczyk
2019-05-20  7:05 ` [PATCH 2/4] w1: ds2413: add retry support to state_read() Mariusz Bialonczyk
2019-05-20  7:05 ` [PATCH 3/4] w1: ds2413: when the slave is not responding during read, select it again Mariusz Bialonczyk
2019-05-22 10:40   ` Mariusz Bialonczyk [this message]
2019-05-20  7:05 ` [PATCH 4/4] w1: ds2805: rename w1_family struct, fixing c-p typo Mariusz Bialonczyk
2019-05-24 18:21   ` Greg KH
2019-05-25  8:45     ` [PATCH 4/4 v2] " Mariusz Bialonczyk
2019-05-25  8:51     ` [PATCH 4/4] " Mariusz Bialonczyk

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=20190522104053.14577-1-manio@skyboo.net \
    --to=manio@skyboo.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH 3/4 v2] w1: ds2413: when the slave is not responding during read, select it again' \
    /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

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).