aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/slaves
diff options
context:
space:
mode:
authorDavid Fries <David@Fries.net>2014-01-15 23:29:24 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-02-07 18:40:18 -0500
commiteb2c0da4ac2f4614b0bd3a1b6a0e9b82d0802e08 (patch)
tree014d00301649ca8720db7168ebca51e810ad6793 /drivers/w1/slaves
parentd53f0a2c0574e6414dceeec59ae5a9e749bd058b (diff)
w1: use family_data instead of rom in w1_slave
The first line printed from w1_slave gives the context of the w1 device. So does the second line, but if the CRC check failed, the second line contains the last successful result. It is confusing when it prints the temperature next to the line that might be a previous conversion and has nothing to do with that printed temperature value. Modify the code to store the last good conversion in family_data, which is designed for custom data structures. Signed-off-by: David Fries <David@Fries.net> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/w1/slaves')
-rw-r--r--drivers/w1/slaves/w1_therm.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 8b5ff33f72cf..1f11a20a8ab9 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -27,6 +27,7 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/device.h> 28#include <linux/device.h>
29#include <linux/types.h> 29#include <linux/types.h>
30#include <linux/slab.h>
30#include <linux/delay.h> 31#include <linux/delay.h>
31 32
32#include "../w1.h" 33#include "../w1.h"
@@ -58,6 +59,19 @@ MODULE_ALIAS("w1-family-" __stringify(W1_THERM_DS28EA00));
58static int w1_strong_pullup = 1; 59static int w1_strong_pullup = 1;
59module_param_named(strong_pullup, w1_strong_pullup, int, 0); 60module_param_named(strong_pullup, w1_strong_pullup, int, 0);
60 61
62static int w1_therm_add_slave(struct w1_slave *sl)
63{
64 sl->family_data = kzalloc(9, GFP_KERNEL);
65 if (!sl->family_data)
66 return -ENOMEM;
67 return 0;
68}
69
70static void w1_therm_remove_slave(struct w1_slave *sl)
71{
72 kfree(sl->family_data);
73 sl->family_data = NULL;
74}
61 75
62static ssize_t w1_slave_show(struct device *device, 76static ssize_t w1_slave_show(struct device *device,
63 struct device_attribute *attr, char *buf); 77 struct device_attribute *attr, char *buf);
@@ -71,6 +85,8 @@ static struct attribute *w1_therm_attrs[] = {
71ATTRIBUTE_GROUPS(w1_therm); 85ATTRIBUTE_GROUPS(w1_therm);
72 86
73static struct w1_family_ops w1_therm_fops = { 87static struct w1_family_ops w1_therm_fops = {
88 .add_slave = w1_therm_add_slave,
89 .remove_slave = w1_therm_remove_slave,
74 .groups = w1_therm_groups, 90 .groups = w1_therm_groups,
75}; 91};
76 92
@@ -253,12 +269,13 @@ static ssize_t w1_slave_show(struct device *device,
253 c -= snprintf(buf + PAGE_SIZE - c, c, ": crc=%02x %s\n", 269 c -= snprintf(buf + PAGE_SIZE - c, c, ": crc=%02x %s\n",
254 crc, (verdict) ? "YES" : "NO"); 270 crc, (verdict) ? "YES" : "NO");
255 if (verdict) 271 if (verdict)
256 memcpy(sl->rom, rom, sizeof(sl->rom)); 272 memcpy(sl->family_data, rom, sizeof(rom));
257 else 273 else
258 dev_warn(device, "Read failed CRC check\n"); 274 dev_warn(device, "Read failed CRC check\n");
259 275
260 for (i = 0; i < 9; ++i) 276 for (i = 0; i < 9; ++i)
261 c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", sl->rom[i]); 277 c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ",
278 ((u8 *)sl->family_data)[i]);
262 279
263 c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n", 280 c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n",
264 w1_convert_temp(rom, sl->family->fid)); 281 w1_convert_temp(rom, sl->family->fid));