Commit c50d09a8 authored by Mariusz Bialonczyk's avatar Mariusz Bialonczyk Committed by Greg Kroah-Hartman

w1: ds2413: add retry support to state_read()

The state_read() was calling PIO_ACCESS_READ once and bail out if it
failed for this first time.
This commit is improving this to trying more times before it give up,
similarly as the write call is currently doing.
Signed-off-by: default avatarMariusz Bialonczyk <manio@skyboo.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ae2ee27a
...@@ -30,6 +30,9 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj, ...@@ -30,6 +30,9 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj,
size_t count) size_t count)
{ {
struct w1_slave *sl = kobj_to_w1_slave(kobj); struct w1_slave *sl = kobj_to_w1_slave(kobj);
unsigned int retries = W1_F3A_RETRIES;
ssize_t bytes_read = -EIO;
dev_dbg(&sl->dev, dev_dbg(&sl->dev,
"Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p",
bin_attr->attr.name, kobj, (unsigned int)off, count, buf); bin_attr->attr.name, kobj, (unsigned int)off, count, buf);
...@@ -42,22 +45,30 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj, ...@@ -42,22 +45,30 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj,
mutex_lock(&sl->master->bus_mutex); mutex_lock(&sl->master->bus_mutex);
dev_dbg(&sl->dev, "mutex locked"); dev_dbg(&sl->dev, "mutex locked");
if (w1_reset_select_slave(sl)) { if (w1_reset_select_slave(sl))
mutex_unlock(&sl->master->bus_mutex); goto out;
return -EIO;
}
w1_write_8(sl->master, W1_F3A_FUNC_PIO_ACCESS_READ); while (retries--) {
*buf = w1_read_8(sl->master); w1_write_8(sl->master, W1_F3A_FUNC_PIO_ACCESS_READ);
mutex_unlock(&sl->master->bus_mutex); *buf = w1_read_8(sl->master);
dev_dbg(&sl->dev, "mutex unlocked"); /* check for correct complement */
if ((*buf & 0x0F) == ((~*buf >> 4) & 0x0F)) {
bytes_read = 1;
goto out;
}
/* check for correct complement */ if (w1_reset_resume_command(sl->master))
if ((*buf & 0x0F) != ((~*buf >> 4) & 0x0F)) goto out; /* unrecoverable error */
return -EIO;
else dev_warn(&sl->dev, "PIO_ACCESS_READ error, retries left: %d\n", retries);
return 1; }
out:
mutex_unlock(&sl->master->bus_mutex);
dev_dbg(&sl->dev, "%s, mutex unlocked, retries: %d\n",
(bytes_read > 0) ? "succeeded" : "error", retries);
return bytes_read;
} }
static BIN_ATTR_RO(state, 1); static BIN_ATTR_RO(state, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment