[PATCH 2/2] w1: slaves: w1_therm: Add temp attribute
From: Mariusz Gorski
Date: Tue Jan 06 2015 - 09:34:07 EST
Add new attribute to simplify reading of current temperature.
Signed-off-by: Mariusz Gorski <marius.gorski@xxxxxxxxx>
---
drivers/w1/slaves/w1_therm.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 3bad3d6..65af193 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -76,10 +76,15 @@ static void w1_therm_remove_slave(struct w1_slave *sl)
static ssize_t w1_slave_show(struct device *device,
struct device_attribute *attr, char *buf);
+static ssize_t temp_show(struct device *device,
+ struct device_attribute *attr, char *buf);
+
static DEVICE_ATTR_RO(w1_slave);
+static DEVICE_ATTR_RO(temp);
static struct attribute *w1_therm_attrs[] = {
&dev_attr_w1_slave.attr,
+ &dev_attr_temp.attr,
NULL,
};
ATTRIBUTE_GROUPS(w1_therm);
@@ -299,6 +304,33 @@ static ssize_t w1_slave_show(struct device *device,
return PAGE_SIZE - c;
}
+static ssize_t temp_show(struct device *device,
+ struct device_attribute *attr, char *buf)
+{
+ struct w1_slave *sl = dev_to_w1_slave(device);
+ struct w1_master *dev = sl->master;
+ u8 rom[9], verdict;
+ int temp;
+
+ if (mutex_lock_interruptible(&dev->bus_mutex))
+ return -EINTR;
+
+ memset(rom, 0, sizeof(rom));
+
+ verdict = read_rom(device, rom);
+
+ if (verdict < 0)
+ return verdict;
+
+ mutex_unlock(&dev->bus_mutex);
+
+ if (!verdict)
+ return -EIO;
+
+ temp = w1_convert_temp(rom, sl->family->fid);
+ return snprintf(buf, PAGE_SIZE, "%d\n", temp);
+}
+
static int __init w1_therm_init(void)
{
int err, i;
--
2.2.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/