All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Adamski, Krzysztof (Nokia - PL/Wroclaw)"  <krzysztof.adamski@nokia.com>
To: Guenter Roeck <linux@roeck-us.net>, Jean Delvare <jdelvare@suse.com>
Cc: "linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
	"Sverdlin,
	Alexander (Nokia - DE/Ulm)" <alexander.sverdlin@nokia.com>
Subject: [PATCH v3 3/4] lm25066: support SAMPLES_FOR_AVG register
Date: Sun, 14 Apr 2019 21:59:19 +0000	[thread overview]
Message-ID: <81104f51d2c10aff1932de23a24d5bc133b52ab7.1555273192.git.krzysztof.adamski@nokia.com> (raw)
In-Reply-To: <cover.1555273192.git.krzysztof.adamski@nokia.com>

Manufacturer specific SAMPLES_FOR_AVG register allows setting the number
of samples used in computing the average values (PMBUS_VIRT_READ_*_AVG).
The number we write is an exponent of base 2 of the number of samples so
for example writing 3 will result in 8 samples average.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/pmbus/lm25066.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index 53db78753a0d..715d4ab57516 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -26,6 +26,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/log2.h>
 #include "pmbus.h"
 
 enum chips { lm25056, lm25066, lm5064, lm5066, lm5066i };
@@ -39,12 +40,15 @@ enum chips { lm25056, lm25066, lm5064, lm5066, lm5066i };
 #define LM25066_CLEAR_PIN_PEAK		0xd6
 #define LM25066_DEVICE_SETUP		0xd9
 #define LM25066_READ_AVG_VIN		0xdc
+#define LM25066_SAMPLES_FOR_AVG		0xdb
 #define LM25066_READ_AVG_VOUT		0xdd
 #define LM25066_READ_AVG_IIN		0xde
 #define LM25066_READ_AVG_PIN		0xdf
 
 #define LM25066_DEV_SETUP_CL		BIT(4)	/* Current limit */
 
+#define LM25066_SAMPLES_FOR_AVG_MAX	4096
+
 /* LM25056 only */
 
 #define LM25056_VAUX_OV_WARN_LIMIT	0xe3
@@ -284,6 +288,12 @@ static int lm25066_read_word_data(struct i2c_client *client, int page, int reg)
 	case PMBUS_VIRT_RESET_PIN_HISTORY:
 		ret = 0;
 		break;
+	case PMBUS_VIRT_SAMPLES:
+		ret = pmbus_read_byte_data(client, 0, LM25066_SAMPLES_FOR_AVG);
+		if (ret < 0)
+			break;
+		ret = 1 << ret;
+		break;
 	default:
 		ret = -ENODATA;
 		break;
@@ -398,6 +408,11 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
 	case PMBUS_VIRT_RESET_PIN_HISTORY:
 		ret = pmbus_write_byte(client, 0, LM25066_CLEAR_PIN_PEAK);
 		break;
+	case PMBUS_VIRT_SAMPLES:
+		word = clamp_val(word, 1, LM25066_SAMPLES_FOR_AVG_MAX);
+		ret = pmbus_write_byte_data(client, 0, LM25066_SAMPLES_FOR_AVG,
+					    ilog2(word));
+		break;
 	default:
 		ret = -ENODATA;
 		break;
@@ -438,7 +453,7 @@ static int lm25066_probe(struct i2c_client *client,
 
 	info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VMON
 	  | PMBUS_HAVE_PIN | PMBUS_HAVE_IIN | PMBUS_HAVE_STATUS_INPUT
-	  | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
+	  | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_SAMPLES;
 
 	if (data->id == lm25056) {
 		info->func[0] |= PMBUS_HAVE_STATUS_VMON;
-- 
2.20.1


  parent reply	other threads:[~2019-04-14 21:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-14 21:58 [PATCH v3 0/4] pmbus: extend configurability via sysfs Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-04-14 21:58 ` [PATCH v3 1/4] pmbus: introduce PMBUS_VIRT_*_SAMPLES registers Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-04-15 20:13   ` Guenter Roeck
2019-04-14 21:58 ` [PATCH v3 2/4] hwmon: Document the samples attributes Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-04-15 20:14   ` Guenter Roeck
2019-04-14 21:59 ` Adamski, Krzysztof (Nokia - PL/Wroclaw) [this message]
2019-04-15 20:16   ` [PATCH v3 3/4] lm25066: support SAMPLES_FOR_AVG register Guenter Roeck
2019-04-14 21:59 ` [PATCH v3 4/4] pmbus_core: export coefficients via sysfs Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-04-14 22:37   ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-04-15  2:38     ` Guenter Roeck
2019-04-15  8:34       ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-04-15 16:33         ` Guenter Roeck
2019-04-15 20:26           ` Adamski, Krzysztof (Nokia - PL/Wroclaw)

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=81104f51d2c10aff1932de23a24d5bc133b52ab7.1555273192.git.krzysztof.adamski@nokia.com \
    --to=krzysztof.adamski@nokia.com \
    --cc=alexander.sverdlin@nokia.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.