mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mariusz Gorski <marius.gorski@gmail.com>
To: Evgeniy Polyakov <zbr@ioremap.net>, David Fries <David@Fries.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] w1: slaves: w1_therm: Add temp attribute
Date: Tue,  6 Jan 2015 15:29:56 +0100	[thread overview]
Message-ID: <1420554596-10250-3-git-send-email-marius.gorski@gmail.com> (raw)
In-Reply-To: <1420554596-10250-1-git-send-email-marius.gorski@gmail.com>

Add new attribute to simplify reading of current temperature.

Signed-off-by: Mariusz Gorski <marius.gorski@gmail.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


  parent reply	other threads:[~2015-01-06 14:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-06 14:29 [PATCH 0/2] w1: slaves: w1_therm: Add sysfs entry for current temperature Mariusz Gorski
2015-01-06 14:29 ` [PATCH 1/2] w1: slaves: w1_therm: Extract read_rom function Mariusz Gorski
2015-01-06 14:29 ` Mariusz Gorski [this message]
2015-01-06 17:42   ` [PATCH 2/2] w1: slaves: w1_therm: Add temp attribute Greg Kroah-Hartman
2015-01-06 20:19     ` Mariusz Gorski
2015-01-06 20:26       ` Greg Kroah-Hartman
2015-01-07  2:00   ` David Fries
2015-01-06 15:01 ` [PATCH 0/2] w1: slaves: w1_therm: Add sysfs entry for current temperature Richard Weinberger
2015-01-06 16:12   ` Mariusz Gorski
2015-01-06 16:50     ` Richard Weinberger
2015-01-07  2:27       ` David Fries
2015-01-07  1:59 ` David Fries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420554596-10250-3-git-send-email-marius.gorski@gmail.com \
    --to=marius.gorski@gmail.com \
    --cc=David@Fries.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zbr@ioremap.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®