aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Povilus <kernel.development@povil.us>2017-03-29 23:46:37 -0400
committerGuenter Roeck <linux@roeck-us.net>2017-04-02 10:01:53 -0400
commita8ddfea09566c37aabe70fbb6d07ff232982c9f4 (patch)
tree84498c3c597cd25339c01e011375c82435a6ccc8
parenta4811b6cb4069eb2f17ffebcd29f2e5b0f76ee31 (diff)
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>
-rw-r--r--Documentation/devicetree/bindings/hwmon/ads7828.txt25
-rw-r--r--drivers/hwmon/ads7828.c15
2 files changed, 40 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/hwmon/ads7828.txt b/Documentation/devicetree/bindings/hwmon/ads7828.txt
new file mode 100644
index 000000000000..fe0cc4ad7ea9
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ads7828.txt
@@ -0,0 +1,25 @@
1ads7828 properties
2
3Required properties:
4- compatible: Should be one of
5 ti,ads7828
6 ti,ads7830
7- reg: I2C address
8
9Optional properties:
10
11- ti,differential-input
12 Set to use the device in differential mode.
13- vref-supply
14 The external reference on the device is set to this regulators output. If it
15 does not exists the internal reference will be used and output by the ads78xx
16 on the "external vref" pin.
17
18 Example ADS7828 node:
19
20 ads7828: ads@48 {
21 comatible = "ti,ads7828";
22 reg = <0x48>;
23 vref-supply = <&vref>;
24 ti,differential-input;
25 };
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 @@
35#include <linux/platform_data/ads7828.h> 35#include <linux/platform_data/ads7828.h>
36#include <linux/regmap.h> 36#include <linux/regmap.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/regulator/consumer.h>
38 39
39/* The ADS7828 registers */ 40/* The ADS7828 registers */
40#define ADS7828_CMD_SD_SE 0x80 /* Single ended inputs */ 41#define ADS7828_CMD_SD_SE 0x80 /* Single ended inputs */
@@ -119,10 +120,12 @@ static int ads7828_probe(struct i2c_client *client,
119 struct ads7828_data *data; 120 struct ads7828_data *data;
120 struct device *hwmon_dev; 121 struct device *hwmon_dev;
121 unsigned int vref_mv = ADS7828_INT_VREF_MV; 122 unsigned int vref_mv = ADS7828_INT_VREF_MV;
123 unsigned int vref_uv;
122 bool diff_input = false; 124 bool diff_input = false;
123 bool ext_vref = false; 125 bool ext_vref = false;
124 unsigned int regval; 126 unsigned int regval;
125 enum ads7828_chips chip; 127 enum ads7828_chips chip;
128 struct regulator *reg;
126 129
127 data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL); 130 data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
128 if (!data) 131 if (!data)
@@ -133,6 +136,18 @@ static int ads7828_probe(struct i2c_client *client,
133 ext_vref = pdata->ext_vref; 136 ext_vref = pdata->ext_vref;
134 if (ext_vref && pdata->vref_mv) 137 if (ext_vref && pdata->vref_mv)
135 vref_mv = pdata->vref_mv; 138 vref_mv = pdata->vref_mv;
139 } else if (dev->of_node) {
140 diff_input = of_property_read_bool(dev->of_node,
141 "ti,differential-input");
142 reg = devm_regulator_get_optional(dev, "vref");
143 if (!IS_ERR(reg)) {
144 vref_uv = regulator_get_voltage(reg);
145 vref_mv = DIV_ROUND_CLOSEST(vref_uv, 1000);
146 if (vref_mv < ADS7828_EXT_VREF_MV_MIN ||
147 vref_mv > ADS7828_EXT_VREF_MV_MAX)
148 return -EINVAL;
149 ext_vref = true;
150 }
136 } 151 }
137 152
138 if (client->dev.of_node) 153 if (client->dev.of_node)