* [PATCH v6] hwmon: ads7828 optional parameters from the device tree
@ 2017-03-30 3:46 Sam Povilus
2017-04-02 11:35 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Sam Povilus @ 2017-03-30 3:46 UTC (permalink / raw)
To: wsa, jdelvare, linux, linux-hwmon, linux-i2c, devicetree, robh+dt,
mark.rutland
Cc: Sam Povilus
Adding the ability for the ads7828 and ads7830 to use the device tree to
get their optional parameters, instead of using platform devices. This
allows people using custom boards to also use the ads7828 in a non-default
manner.
v2: conforming to coding style
v3: changing from "_" to "-" for device tree entries
v4: using regulator subsystem for voltage source, renaming differential
input property
v5: checking for invalid vref values sooner and returning error if they are
bad, not warning user.
v6: optimization per Guenter Roeck
Signed-off-by: Sam Povilus <kernel.development@povil.us>
---
.../devicetree/bindings/hwmon/ads7828.txt | 26 ++++++++++++++++++++++
drivers/hwmon/ads7828.c | 15 +++++++++++++
2 files changed, 41 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
diff --git a/Documentation/devicetree/bindings/hwmon/ads7828.txt b/Documentation/devicetree/bindings/hwmon/ads7828.txt
new file mode 100644
index 000000000000..a1251b19079d
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ads7828.txt
@@ -0,0 +1,26 @@
+ads7828 properties
+
+Required properties:
+- compatible: Should be one of
+ ti,ads7828
+ ti,ads7830
+- reg: I2C address
+
+Optional properties:
+
+- ti,differential-input
+ Set to use the device in differential mode.
+- vref
+ The external reference on the device is set to this regulators output. If it
+ does not exists the internal reference will be used and output by the ads78xx
+ on the "external vref" pin.
+
+ Example ADS7828 node:
+
+ ads7828: ads@48 {
+ comatible = "ti,ads7828";
+ reg = <0x48>;
+ vref-supply = <&vref>;
+ ti,differential-input;
+ };
+
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index ee396ff167d9..88330a233b1d 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -34,6 +34,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 */
@@ -118,9 +119,11 @@ 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;
+ struct regulator *reg;
data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
if (!data)
@@ -131,6 +134,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;
+ }
}
/* Bound Vref with min/max values */
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v6] hwmon: ads7828 optional parameters from the device tree
2017-03-30 3:46 [PATCH v6] hwmon: ads7828 optional parameters from the device tree Sam Povilus
@ 2017-04-02 11:35 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2017-04-02 11:35 UTC (permalink / raw)
To: Sam Povilus, wsa, jdelvare, linux-hwmon, linux-i2c, devicetree,
robh+dt, mark.rutland
On 03/29/2017 08:46 PM, Sam Povilus wrote:
> Adding the ability for the ads7828 and ads7830 to use the device tree to
> get their optional parameters, instead of using platform devices. This
> allows people using custom boards to also use the ads7828 in a non-default
> manner.
>
> v2: conforming to coding style
> v3: changing from "_" to "-" for device tree entries
> v4: using regulator subsystem for voltage source, renaming differential
> input property
> v5: checking for invalid vref values sooner and returning error if they are
> bad, not warning user.
> v6: optimization per Guenter Roeck
>
> Signed-off-by: Sam Povilus <kernel.development@povil.us>
Applied, after fixing up some whitespace errors in ads7828.txt.
Guenter
> ---
> .../devicetree/bindings/hwmon/ads7828.txt | 26 ++++++++++++++++++++++
> drivers/hwmon/ads7828.c | 15 +++++++++++++
> 2 files changed, 41 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
>
> diff --git a/Documentation/devicetree/bindings/hwmon/ads7828.txt b/Documentation/devicetree/bindings/hwmon/ads7828.txt
> new file mode 100644
> index 000000000000..a1251b19079d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/ads7828.txt
> @@ -0,0 +1,26 @@
> +ads7828 properties
> +
> +Required properties:
> +- compatible: Should be one of
> + ti,ads7828
> + ti,ads7830
> +- reg: I2C address
> +
> +Optional properties:
> +
> +- ti,differential-input
> + Set to use the device in differential mode.
> +- vref
changed to vref-supply
> + The external reference on the device is set to this regulators output. If it
> + does not exists the internal reference will be used and output by the ads78xx
> + on the "external vref" pin.
> +
> + Example ADS7828 node:
> +
> + ads7828: ads@48 {
> + comatible = "ti,ads7828";
> + reg = <0x48>;
> + vref-supply = <&vref>;
> + ti,differential-input;
> + };
> +
> diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
> index ee396ff167d9..88330a233b1d 100644
> --- a/drivers/hwmon/ads7828.c
> +++ b/drivers/hwmon/ads7828.c
> @@ -34,6 +34,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 */
> @@ -118,9 +119,11 @@ 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;
> + struct regulator *reg;
>
> data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
> if (!data)
> @@ -131,6 +134,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;
> + }
> }
>
> /* Bound Vref with min/max values */
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-04-02 11:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-30 3:46 [PATCH v6] hwmon: ads7828 optional parameters from the device tree Sam Povilus
2017-04-02 11:35 ` Guenter Roeck
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).