Skip to content

Commit

Permalink
hwmon: (lm25066) Support SAMPLES_FOR_AVG register
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Adamski, Krzysztof (Nokia - PL/Wroclaw) authored and Guenter Roeck committed Apr 16, 2019
1 parent bfe033a commit 5d9e8b3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion drivers/hwmon/pmbus/lm25066.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5d9e8b3

Please sign in to comment.