linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Sampaio <sampaio.ime@gmail.com>
To: zbr@ioremap.net
Cc: corbet@lwn.net, rikard.falkeborn@gmail.com,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org, Luiz Sampaio <sampaio.ime@gmail.com>
Subject: [PATCH v6 5/6] w1: ds2438: adding support for reading page1
Date: Fri,  9 Apr 2021 00:15:32 -0300	[thread overview]
Message-ID: <20210409031533.442123-6-sampaio.ime@gmail.com> (raw)
In-Reply-To: <20210409031533.442123-1-sampaio.ime@gmail.com>

Added a sysfs entry to support reading the page1 registers. This registers
contain Elapsed Time Meter (ETM) data, which shows for how long the chip is
on, as well as an Offset Register data, which can be used to calibrate the
current measurement of the chip.

Signed-off-by: Luiz Sampaio <sampaio.ime@gmail.com>
---
 .../ABI/stable/sysfs-driver-w1_ds2438         |  6 +++
 Documentation/w1/slaves/w1_ds2438.rst         |  8 ++++
 drivers/w1/slaves/w1_ds2438.c                 | 41 +++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-driver-w1_ds2438

diff --git a/Documentation/ABI/stable/sysfs-driver-w1_ds2438 b/Documentation/ABI/stable/sysfs-driver-w1_ds2438
new file mode 100644
index 000000000000..fa47437c11d9
--- /dev/null
+++ b/Documentation/ABI/stable/sysfs-driver-w1_ds2438
@@ -0,0 +1,6 @@
+What:		/sys/bus/w1/devices/.../page1
+Date:		April 2021
+Contact:	Luiz Sampaio <sampaio.ime@gmail.com>
+Description:	read the contents of the page1 of the DS2438
+		see Documentation/w1/slaves/w1_ds2438.rst for detailed information
+Users:		any user space application which wants to communicate with DS2438
diff --git a/Documentation/w1/slaves/w1_ds2438.rst b/Documentation/w1/slaves/w1_ds2438.rst
index a29309a3f8e5..ac8d0d4b0d0e 100644
--- a/Documentation/w1/slaves/w1_ds2438.rst
+++ b/Documentation/w1/slaves/w1_ds2438.rst
@@ -44,6 +44,14 @@ Internally when this file is read, the additional CRC byte is also obtained
 from the slave device. If it is correct, the 8 bytes page data are passed
 to userspace, otherwise an I/O error is returned.
 
+"page1"
+-------
+This file provides full 8 bytes of the chip Page 1 (01h).
+This page contains the ICA, elapsed time meter and current offset data of the DS2438.
+Internally when this file is read, the additional CRC byte is also obtained
+from the slave device. If it is correct, the 8 bytes page data are passed
+to userspace, otherwise an I/O error is returned.
+
 "temperature"
 -------------
 Opening and reading this file initiates the CONVERT_T (temperature conversion)
diff --git a/drivers/w1/slaves/w1_ds2438.c b/drivers/w1/slaves/w1_ds2438.c
index ef6217ecb1cb..2cfdfedb584f 100644
--- a/drivers/w1/slaves/w1_ds2438.c
+++ b/drivers/w1/slaves/w1_ds2438.c
@@ -49,6 +49,15 @@
 #define DS2438_CURRENT_MSB		0x06
 #define DS2438_THRESHOLD		0x07
 
+/* Page #1 definitions */
+#define DS2438_ETM_0			0x00
+#define DS2438_ETM_1			0x01
+#define DS2438_ETM_2			0x02
+#define DS2438_ETM_3			0x03
+#define DS2438_ICA			0x04
+#define DS2438_OFFSET_LSB		0x05
+#define DS2438_OFFSET_MSB		0x06
+
 static int w1_ds2438_get_page(struct w1_slave *sl, int pageno, u8 *buf)
 {
 	unsigned int retries = W1_DS2438_RETRIES;
@@ -325,6 +334,36 @@ static ssize_t page0_read(struct file *filp, struct kobject *kobj,
 	return ret;
 }
 
+static ssize_t page1_read(struct file *filp, struct kobject *kobj,
+			  struct bin_attribute *bin_attr, char *buf,
+			  loff_t off, size_t count)
+{
+	struct w1_slave *sl = kobj_to_w1_slave(kobj);
+	int ret;
+	u8 w1_buf[DS2438_PAGE_SIZE + 1 /*for CRC*/];
+
+	if (off != 0)
+		return 0;
+	if (!buf)
+		return -EINVAL;
+
+	mutex_lock(&sl->master->bus_mutex);
+
+	/* Read no more than page1 size */
+	if (count > DS2438_PAGE_SIZE)
+		count = DS2438_PAGE_SIZE;
+
+	if (w1_ds2438_get_page(sl, 1, w1_buf) == 0) {
+		memcpy(buf, &w1_buf, count);
+		ret = count;
+	} else
+		ret = -EIO;
+
+	mutex_unlock(&sl->master->bus_mutex);
+
+	return ret;
+}
+
 static ssize_t temperature_read(struct file *filp, struct kobject *kobj,
 				struct bin_attribute *bin_attr, char *buf,
 				loff_t off, size_t count)
@@ -390,6 +429,7 @@ static ssize_t vdd_read(struct file *filp, struct kobject *kobj,
 
 static BIN_ATTR_RW(iad, 0664, iad_write, 0);
 static BIN_ATTR_RO(page0, DS2438_PAGE_SIZE);
+static BIN_ATTR_RO(page1, DS2438_PAGE_SIZE);
 static BIN_ATTR_RO(temperature, 0/* real length varies */);
 static BIN_ATTR_RO(vad, 0/* real length varies */);
 static BIN_ATTR_RO(vdd, 0/* real length varies */);
@@ -397,6 +437,7 @@ static BIN_ATTR_RO(vdd, 0/* real length varies */);
 static struct bin_attribute *w1_ds2438_bin_attrs[] = {
 	&bin_attr_iad,
 	&bin_attr_page0,
+	&bin_attr_page1,
 	&bin_attr_temperature,
 	&bin_attr_vad,
 	&bin_attr_vdd,
-- 
2.30.1


  parent reply	other threads:[~2021-04-09  3:15 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210405105009.420924-1-sampaio.ime@gmail.com>
2021-04-09  3:09 ` [PATCH v5 0/9] w1: ds2438: adding support for calibration of current measurements Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 1/6] w1: ds2438: fixed a coding style issue Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 2/6] w1: ds2438: fixed if brackets " Luiz Sampaio
2021-04-09  4:39     ` Joe Perches
2021-04-09 14:40     ` Joe Perches
2021-04-16 22:26       ` Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 3/6] w1: ds2438: fixed a " Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 4/6] w1: ds2438: fixing bug that would always get page0 Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 5/6] w1: ds2438: adding support for reading page1 Luiz Sampaio
2021-04-09  3:09   ` [PATCH v5 6/6] w1: ds2438: support for writing to offset register Luiz Sampaio
2021-04-09  3:15   ` [PATCH v6 0/9] w1: ds2438: adding support for calibration of current measurements Luiz Sampaio
2021-04-09  3:15     ` [PATCH v6 1/6] w1: ds2438: fixed a coding style issue Luiz Sampaio
2021-04-09  3:15     ` [PATCH v6 2/6] w1: ds2438: fixed if brackets " Luiz Sampaio
2021-04-09  3:15     ` [PATCH v6 3/6] w1: ds2438: fixed a " Luiz Sampaio
2021-04-09  9:44       ` kernel test robot
2021-04-09 10:43       ` kernel test robot
2021-04-10  8:38       ` Greg KH
2021-04-09  3:15     ` [PATCH v6 4/6] w1: ds2438: fixing bug that would always get page0 Luiz Sampaio
2021-04-09  3:15     ` Luiz Sampaio [this message]
2021-04-09  3:15     ` [PATCH v6 6/6] w1: ds2438: support for writing to offset register Luiz Sampaio
2021-04-16 22:17     ` [PATCH v7 0/6] w1: ds2438: adding support for calibration of current measurements Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 1/6] w1: ds2438: fixed a coding style issue Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 2/6] w1: ds2438: fixed if brackets " Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 3/6] w1: ds2438: changed sysfs macro for rw file Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 4/6] w1: ds2438: fixing bug that would always get page0 Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 5/6] w1: ds2438: adding support for reading page1 Luiz Sampaio
2021-04-16 22:17       ` [PATCH v7 6/6] w1: ds2438: support for writing to offset register Luiz Sampaio
2021-04-17  5:25         ` kernel test robot
2021-05-14 11:47       ` [PATCH v7 0/6] w1: ds2438: adding support for calibration of current measurements Greg KH
2021-05-19 22:30     ` [PATCH v8 " Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 1/6] w1: ds2438: fixed a coding style issue Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 2/6] w1: ds2438: fixed if brackets " Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 3/6] w1: ds2438: changed sysfs macro for rw file Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 4/6] w1: ds2438: fixing bug that would always get page0 Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 5/6] w1: ds2438: adding support for reading page1 Luiz Sampaio
2021-05-19 22:30       ` [PATCH v8 6/6] w1: ds2438: support for writing to offset register Luiz Sampaio

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=20210409031533.442123-6-sampaio.ime@gmail.com \
    --to=sampaio.ime@gmail.com \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rikard.falkeborn@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).