1 From 2c5817c444e95254ed4888c12345c2dabe401fda Mon Sep 17 00:00:00 2001
2 From: Mariusz Bialonczyk <manio@skyboo.net>
3 Date: Wed, 22 May 2019 12:40:53 +0200
4 Subject: [PATCH 672/773] w1: ds2413: when the slave is not responding during
7 commit 3856032a0628e6b94badb9131a706dda185e071d upstream.
9 The protocol is not allowing to obtain a byte of 0xff for PIO_ACCESS_READ
10 call. It is very likely that the slave was not addressed properly and
11 it is just not respoding (leaving the bus in logic high state) during
12 the read of sampled PIO value.
13 We cannot just call w1_reset_resume_command() because the problem will
14 persist, instead try selecting (addressing) the slave again.
16 Signed-off-by: Mariusz Bialonczyk <manio@skyboo.net>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 drivers/w1/slaves/w1_ds2413.c | 9 ++++++++-
20 1 file changed, 8 insertions(+), 1 deletion(-)
22 --- a/drivers/w1/slaves/w1_ds2413.c
23 +++ b/drivers/w1/slaves/w1_ds2413.c
25 #define W1_F3A_FUNC_PIO_ACCESS_READ 0xF5
26 #define W1_F3A_FUNC_PIO_ACCESS_WRITE 0x5A
27 #define W1_F3A_SUCCESS_CONFIRM_BYTE 0xAA
28 +#define W1_F3A_INVALID_PIO_STATE 0xFF
30 static ssize_t state_read(struct file *filp, struct kobject *kobj,
31 struct bin_attribute *bin_attr, char *buf, loff_t off,
32 @@ -45,6 +46,7 @@ static ssize_t state_read(struct file *f
33 mutex_lock(&sl->master->bus_mutex);
34 dev_dbg(&sl->dev, "mutex locked");
37 if (w1_reset_select_slave(sl))
40 @@ -52,10 +54,15 @@ static ssize_t state_read(struct file *f
41 w1_write_8(sl->master, W1_F3A_FUNC_PIO_ACCESS_READ);
43 *buf = w1_read_8(sl->master);
44 - /* check for correct complement */
45 if ((*buf & 0x0F) == ((~*buf >> 4) & 0x0F)) {
46 + /* complement is correct */
49 + } else if (*buf == W1_F3A_INVALID_PIO_STATE) {
50 + /* slave didn't respond, try to select it again */
51 + dev_warn(&sl->dev, "slave device did not respond to PIO_ACCESS_READ, " \
52 + "reselecting, retries left: %d\n", retries);
56 if (w1_reset_resume_command(sl->master))