[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1420554596-10250-3-git-send-email-marius.gorski@gmail.com>
Date: Tue, 6 Jan 2015 15:29:56 +0100
From: Mariusz Gorski <marius.gorski@...il.com>
To: Evgeniy Polyakov <zbr@...emap.net>, David Fries <David@...es.net>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH 2/2] w1: slaves: w1_therm: Add temp attribute
Add new attribute to simplify reading of current temperature.
Signed-off-by: Mariusz Gorski <marius.gorski@...il.com>
---
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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists