* [PATCH v2 1/2] hwmon: (ltc4151) Make shunt-resistor configurable
[not found] <20160727144859.GA18846@rob-hp-laptop>
@ 2016-08-01 10:07 ` Daniel Golle
2016-08-01 10:08 ` [PATCH 2/2] hwmon: (ltc4151) Add devicetree binding for ltc4151 Daniel Golle
1 sibling, 0 replies; 2+ messages in thread
From: Daniel Golle @ 2016-08-01 10:07 UTC (permalink / raw)
To: Guenter Roeck, Axel Lin, Per Dalén; +Cc: devicetree, linux-hwmon
Allow to specify the resistance of the attached shunt via DT by
adding the shunt-resistor property. Fall-back to the previous
default (1 mOhm) if unset.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
v2: add -micro-ohms unit suffix
drivers/hwmon/ltc4151.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/ltc4151.c b/drivers/hwmon/ltc4151.c
index c86a184..d36e5e1 100644
--- a/drivers/hwmon/ltc4151.c
+++ b/drivers/hwmon/ltc4151.c
@@ -30,6 +30,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/of.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/slab.h>
@@ -52,6 +53,7 @@ struct ltc4151_data {
struct mutex update_lock;
bool valid;
unsigned long last_updated; /* in jiffies */
+ unsigned int shunt; /* in micro ohms */
/* Registers */
u8 regs[6];
@@ -111,9 +113,9 @@ static int ltc4151_get_value(struct ltc4151_data *data, u8 reg)
case LTC4151_SENSE_H:
/*
* 20uV resolution. Convert to current as measured with
- * an 1 mOhm sense resistor, in mA.
+ * a given sense resistor, in mA.
*/
- val = val * 20;
+ val = val * 20 * 1000 / data->shunt;
break;
case LTC4151_VIN_H:
/* 25 mV per increment */
@@ -176,6 +178,7 @@ static int ltc4151_probe(struct i2c_client *client,
struct device *dev = &client->dev;
struct ltc4151_data *data;
struct device *hwmon_dev;
+ u32 shunt;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV;
@@ -184,6 +187,14 @@ static int ltc4151_probe(struct i2c_client *client,
if (!data)
return -ENOMEM;
+ if (of_property_read_u32(client->dev.of_node, "shunt-resistor-micro-ohms", &shunt))
+ shunt = 1000; /* 1 mOhm if not set via DT */
+
+ if (shunt == 0)
+ return -EINVAL;
+
+ data->shunt = shunt;
+
data->client = client;
mutex_init(&data->update_lock);
@@ -199,10 +210,16 @@ static const struct i2c_device_id ltc4151_id[] = {
};
MODULE_DEVICE_TABLE(i2c, ltc4151_id);
+static const struct of_device_id ltc4151_match[] = {
+ { .compatible = "lltc,ltc4151" },
+ {},
+};
+
/* This is the driver that will be inserted */
static struct i2c_driver ltc4151_driver = {
.driver = {
.name = "ltc4151",
+ .of_match_table = of_match_ptr(ltc4151_match),
},
.probe = ltc4151_probe,
.id_table = ltc4151_id,
--
2.9.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] hwmon: (ltc4151) Add devicetree binding for ltc4151
[not found] <20160727144859.GA18846@rob-hp-laptop>
2016-08-01 10:07 ` [PATCH v2 1/2] hwmon: (ltc4151) Make shunt-resistor configurable Daniel Golle
@ 2016-08-01 10:08 ` Daniel Golle
1 sibling, 0 replies; 2+ messages in thread
From: Daniel Golle @ 2016-08-01 10:08 UTC (permalink / raw)
To: Guenter Roeck, Axel Lin, Per Dalén; +Cc: devicetree, linux-hwmon
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
v2: add description and -micro-ohms unit suffix to property
Documentation/devicetree/bindings/hwmon/ltc4151.txt | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/ltc4151.txt
diff --git a/Documentation/devicetree/bindings/hwmon/ltc4151.txt b/Documentation/devicetree/bindings/hwmon/ltc4151.txt
new file mode 100644
index 0000000..d008a5e
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ltc4151.txt
@@ -0,0 +1,18 @@
+LTC4151 High Voltage I2C Current and Voltage Monitor
+
+Required properties:
+- compatible: Must be "lltc,ltc4151"
+- reg: I2C address
+
+Optional properties:
+- shunt-resistor-micro-ohms
+ Shunt resistor value in micro-Ohms
+ Defaults to <1000> if unset.
+
+Example:
+
+ltc4151@6e {
+ compatible = "lltc,ltc4151";
+ reg = <0x6e>;
+ shunt-resistor-micro-ohms = <1500>;
+};
--
2.9.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-01 10:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20160727144859.GA18846@rob-hp-laptop>
2016-08-01 10:07 ` [PATCH v2 1/2] hwmon: (ltc4151) Make shunt-resistor configurable Daniel Golle
2016-08-01 10:08 ` [PATCH 2/2] hwmon: (ltc4151) Add devicetree binding for ltc4151 Daniel Golle
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).