public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: Jaghathiswari Rankappagounder Natarajan <jaghu@google.com>
To: zbr@ioremap.net, linux-kernel@vger.kernel.org,
	linux@roeck-us.net, jdelvare@suse.com,
	linux-hwmon@vger.kernel.org
Cc: Jaghathiswari Rankappagounder Natarajan <jaghu@google.com>
Subject: [PATCH linux v1 3/3] drivers: w1: add hwmon temp support for w1_therm
Date: Wed, 14 Jun 2017 14:59:44 -0700	[thread overview]
Message-ID: <20170614215944.24984-4-jaghu@google.com> (raw)
In-Reply-To: <20170614215944.24984-1-jaghu@google.com>

This change adds hwmon temp support for w1_therm.

Signed-off-by: Jaghathiswari Rankappagounder Natarajan <jaghu@google.com>
Change-Id: I66c0837d63b5a5839227319608eb8061b917f5fa
---
 drivers/w1/slaves/w1_therm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 88f4cc8c3908..dba2d21fa731 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -105,8 +105,12 @@ static ssize_t w1_slave_store(struct device *device,
 static ssize_t w1_seq_show(struct device *device,
 	struct device_attribute *attr, char *buf);

+static ssize_t temp1_input_show(struct device *device,
+	struct device_attribute *attr, char *buf);
+
 static DEVICE_ATTR_RW(w1_slave);
 static DEVICE_ATTR_RO(w1_seq);
+static DEVICE_ATTR_RO(temp1_input);

 static struct attribute *w1_therm_attrs[] = {
 	&dev_attr_w1_slave.attr,
@@ -118,19 +122,27 @@ static struct attribute *w1_ds28ea00_attrs[] = {
 	&dev_attr_w1_seq.attr,
 	NULL,
 };
+static struct attribute *w1_therm_hwmon_attrs[] = {
+	&dev_attr_temp1_input.attr,
+	NULL,
+};
+
 ATTRIBUTE_GROUPS(w1_therm);
 ATTRIBUTE_GROUPS(w1_ds28ea00);
+ATTRIBUTE_GROUPS(w1_therm_hwmon);

 static struct w1_family_ops w1_therm_fops = {
 	.add_slave	= w1_therm_add_slave,
 	.remove_slave	= w1_therm_remove_slave,
 	.groups		= w1_therm_groups,
+	.hwmon_groups   = w1_therm_hwmon_groups,
 };

 static struct w1_family_ops w1_ds28ea00_fops = {
 	.add_slave	= w1_therm_add_slave,
 	.remove_slave	= w1_therm_remove_slave,
 	.groups		= w1_ds28ea00_groups,
+	.hwmon_groups   = w1_therm_hwmon_groups,
 };

 static struct w1_family w1_therm_family_DS18S20 = {
@@ -559,6 +571,38 @@ static ssize_t w1_slave_show(struct device *device,
 	return ret;
 }

+static ssize_t temp1_input_show(struct device *device,
+				struct device_attribute *attr, char *buf)
+{
+	struct w1_slave *sl = dev_get_drvdata(device);
+	u8 *family_data = sl->family_data;
+	struct therm_info info;
+	int ret;
+
+	if (!sl->family_data)
+		return -ENODEV;
+
+	/* prevent the slave from going away in sleep */
+	atomic_inc(THERM_REFCNT(family_data));
+
+	ret = read_therm(device, sl, &info);
+	if (ret)
+		goto dec_refcnt;
+
+	if (!info.verdict) {
+		dev_warn(device, "Read failed CRC check\n");
+		ret = -EIO;
+		goto dec_refcnt;
+	}
+
+	ret = sprintf(buf, "%d\n",
+			w1_convert_temp(info.rom, sl->family->fid));
+
+dec_refcnt:
+	atomic_dec(THERM_REFCNT(family_data));
+	return ret;
+}
+
 #define W1_42_CHAIN	0x99
 #define W1_42_CHAIN_OFF	0x3C
 #define W1_42_CHAIN_OFF_INV	0xC3
--
2.13.1.508.gb3defc5cc-goog


  parent reply	other threads:[~2017-06-14 21:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-14 21:59 [PATCH linux v1 0/3] Export 1-wire thermal sensors as hwmon device Jaghathiswari Rankappagounder Natarajan
2017-06-14 21:59 ` [PATCH linux v1 1/3] drivers: w1: add hwmon support structures Jaghathiswari Rankappagounder Natarajan
2017-06-14 22:38   ` Guenter Roeck
2017-06-14 21:59 ` [PATCH linux v1 2/3] drivers: w1: refactor w1_slave_show to make the temp reading functionality separate Jaghathiswari Rankappagounder Natarajan
2017-06-14 21:59 ` Jaghathiswari Rankappagounder Natarajan [this message]
2017-06-17 14:37 ` [PATCH linux v1 0/3] Export 1-wire thermal sensors as hwmon device Evgeniy Polyakov

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=20170614215944.24984-4-jaghu@google.com \
    --to=jaghu@google.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --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