summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorSam Povilus <kernel.development@povil.us>2017-03-29 21:46:37 -0600
committerGuenter Roeck <linux@roeck-us.net>2017-04-02 07:01:53 -0700
commita8ddfea09566c37aabe70fbb6d07ff232982c9f4 (patch)
tree84498c3c597cd25339c01e011375c82435a6ccc8 /drivers/hwmon
parenta4811b6cb4069eb2f17ffebcd29f2e5b0f76ee31 (diff)
downloadlinux-a8ddfea09566c37aabe70fbb6d07ff232982c9f4.tar.gz
linux-a8ddfea09566c37aabe70fbb6d07ff232982c9f4.tar.bz2
linux-a8ddfea09566c37aabe70fbb6d07ff232982c9f4.zip
hwmon: (ads7828) Accept optional parameters from device tree
Adding the ability for the ads7828 and ads7830 to use device tree to get optional parameters instead of using platform devices. This allows people using custom boards to also use the ads7828 in a non-default manner. Signed-off-by: Sam Povilus <kernel.development@povil.us> [groeck: Fixed whitespace errors in ads7828.txt] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/ads7828.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index b0ef66687816..898607bf682b 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -35,6 +35,7 @@
#include <linux/platform_data/ads7828.h>
#include <linux/regmap.h>
#include <linux/slab.h>
+#include <linux/regulator/consumer.h>
/* The ADS7828 registers */
#define ADS7828_CMD_SD_SE 0x80 /* Single ended inputs */
@@ -119,10 +120,12 @@ static int ads7828_probe(struct i2c_client *client,
struct ads7828_data *data;
struct device *hwmon_dev;
unsigned int vref_mv = ADS7828_INT_VREF_MV;
+ unsigned int vref_uv;
bool diff_input = false;
bool ext_vref = false;
unsigned int regval;
enum ads7828_chips chip;
+ struct regulator *reg;
data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
if (!data)
@@ -133,6 +136,18 @@ static int ads7828_probe(struct i2c_client *client,
ext_vref = pdata->ext_vref;
if (ext_vref && pdata->vref_mv)
vref_mv = pdata->vref_mv;
+ } else if (dev->of_node) {
+ diff_input = of_property_read_bool(dev->of_node,
+ "ti,differential-input");
+ reg = devm_regulator_get_optional(dev, "vref");
+ if (!IS_ERR(reg)) {
+ vref_uv = regulator_get_voltage(reg);
+ vref_mv = DIV_ROUND_CLOSEST(vref_uv, 1000);
+ if (vref_mv < ADS7828_EXT_VREF_MV_MIN ||
+ vref_mv > ADS7828_EXT_VREF_MV_MAX)
+ return -EINVAL;
+ ext_vref = true;
+ }
}
if (client->dev.of_node)