754dfa73ffb7b7137e93e42e7f3a271b442311ac
[openwrt/staging/thess.git] /
1 From f12f813cfa6aa36fef4ab9d9b42db8938ea10a3a 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 671/782] w1: ds2413: when the slave is not responding during
5 read, select it again
6
7 commit 3856032a0628e6b94badb9131a706dda185e071d upstream.
8
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.
15
16 Signed-off-by: Mariusz Bialonczyk <manio@skyboo.net>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18 ---
19 drivers/w1/slaves/w1_ds2413.c | 9 ++++++++-
20 1 file changed, 8 insertions(+), 1 deletion(-)
21
22 --- a/drivers/w1/slaves/w1_ds2413.c
23 +++ b/drivers/w1/slaves/w1_ds2413.c
24 @@ -24,6 +24,7 @@
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
29
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");
35
36 +next:
37 if (w1_reset_select_slave(sl))
38 goto out;
39
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);
42
43 *buf = w1_read_8(sl->master);
44 - /* check for correct complement */
45 if ((*buf & 0x0F) == ((~*buf >> 4) & 0x0F)) {
46 + /* complement is correct */
47 bytes_read = 1;
48 goto out;
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);
53 + goto next;
54 }
55
56 if (w1_reset_resume_command(sl->master))