Skip to contentSkip to conversation

hwmon: ads7828 optional parameters from the device tree

PATCH In review Sam Povilus 6 participants 8 messages Mar 21, 2017 – Mar 24, 2017 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 hwmon: ads7828 optional parameters from the device tree

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.

---
 .../devicetree/bindings/hwmon/ads7828.txt          | 26 ++++++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt    |  2 --
 drivers/hwmon/ads7828.c                            | 21 +++++++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +26 -0
new file mode 100644
index 000000000000..5a0c4a7c6144
@@ -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 = <&vref>;
+	   ti,differential-input;
+  };
+
Documentation/devicetree/bindings/i2c/trivial-devices.txt +0 -2
index cdd7b48826c3..87648909f6ce 100644
@@ -163,8 +163,6 @@ st,m41t00		Serial real-time clock (RTC)
 st,m41t62		Serial real-time clock (RTC) with alarm
 st,m41t80		M41T80 - SERIAL ACCESS RTC WITH ALARMS
 taos,tsl2550		Ambient Light Sensor with SMBUS/Two Wire Serial Interface
-ti,ads7828		8-Channels, 12-bit ADC
-ti,ads7830		8-Channels, 8-bit ADC
 ti,tsc2003		I2C Touch-Screen Controller
 ti,tmp102		Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface
 ti,tmp103		Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface
drivers/hwmon/ads7828.c +21 -0
index ee396ff167d9..0be4804a9e59 100644
@@ -34,6 +34,9 @@
 #include <linux/platform_data/ads7828.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
+#include <linux/regulator/consumer.h>
+
+#define MV_TO_UV 1000
 
 /* The ADS7828 registers */
 #define ADS7828_CMD_SD_SE	0x80	/* Single ended inputs */
@@ -118,9 +121,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;
+	struct regulator *reg;
+
 
 	data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
 	if (!data)
@@ -131,6 +137,21 @@ 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) {
+		if (of_get_property(dev->of_node, "ti,differential-input",
+				    NULL))
+			diff_input = true;
+		reg = devm_regulator_get_optional(dev, "vref");
+		if (!IS_ERR(reg)) {
+			vref_uv = regulator_get_voltage(reg);
+			if ((vref_uv >= ADS7828_EXT_VREF_MV_MIN * MV_TO_UV) &&
+			    (vref_uv <= ADS7828_EXT_VREF_MV_MAX * MV_TO_UV)) {
+				vref_mv = DIV_ROUND_CLOSEST(vref_uv, MV_TO_UV);
+				ext_vref = true;
+			} else {
+				return  -EINVAL;
+			}
+		}
 	}
 
 	/* Bound Vref with min/max values */
Signature · 6 lines
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20170321032434.9268-1-kernel.development-iezDrKAjiWs@public.gmane.org

#2 lore raw
Quoted 37 lines · 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.

---
 .../devicetree/bindings/hwmon/ads7828.txt          | 26 ++++++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt    |  2 --
 drivers/hwmon/ads7828.c                            | 21 +++++++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +11 -0
new file mode 100644
index 000000000000..5a0c4a7c6144
@@ -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

Documentation/devicetree/bindings/hwmon/ads7828.txt line 21

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +10 -0
+  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";

s/comatible/compatible/

Documentation/devicetree/bindings/hwmon/ads7828.txt line 23

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +2 -0
+	   reg = <0x48>;
+	   vref = <&vref>;

Looking into the source of of_get_regulator(), either this has to be vref-supply or I am missing something.

Didn't I mention all this before ?

Quoted 21 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +3 -0
+	   ti,differential-input;
+  };
+
Documentation/devicetree/bindings/i2c/trivial-devices.txt +0 -2
index cdd7b48826c3..87648909f6ce 100644
@@ -163,8 +163,6 @@ st,m41t00		Serial real-time clock (RTC)
 st,m41t62		Serial real-time clock (RTC) with alarm
 st,m41t80		M41T80 - SERIAL ACCESS RTC WITH ALARMS
 taos,tsl2550		Ambient Light Sensor with SMBUS/Two Wire Serial Interface
-ti,ads7828		8-Channels, 12-bit ADC
-ti,ads7830		8-Channels, 8-bit ADC
 ti,tsc2003		I2C Touch-Screen Controller
 ti,tmp102		Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface
 ti,tmp103		Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface
drivers/hwmon/ads7828.c +0 -0
index ee396ff167d9..0be4804a9e59 100644

drivers/hwmon/ads7828.c line 37

Quoted 4 lines
drivers/hwmon/ads7828.c +1 -0
@@ -34,6 +34,9 @@
 #include <linux/platform_data/ads7828.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
+#include <linux/regulator/consumer.h>

alphabetic order please

Quoted 6 lines
drivers/hwmon/ads7828.c +2 -0
+
+#define MV_TO_UV 1000
 
 /* The ADS7828 registers */
 #define ADS7828_CMD_SD_SE	0x80	/* Single ended inputs */

drivers/hwmon/ads7828.c static int ads7828_probe(struct i2c_client *client, · line 130

Quoted 10 lines
drivers/hwmon/ads7828.c +3 -0
@@ -118,9 +121,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;
+	struct regulator *reg;
+
 

Please no double empty lines.

Quoted 10 lines
drivers/hwmon/ads7828.c +4 -0
 	data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
 	if (!data)
@@ -131,6 +137,21 @@ 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) {
+		if (of_get_property(dev->of_node, "ti,differential-input",
+				    NULL))
+			diff_input = true;

drivers/hwmon/ads7828.c static int ads7828_probe(struct i2c_client *client, · line 153

Quoted 10 lines
drivers/hwmon/ads7828.c +10 -0
+		reg = devm_regulator_get_optional(dev, "vref");
+		if (!IS_ERR(reg)) {
+			vref_uv = regulator_get_voltage(reg);
+			if ((vref_uv >= ADS7828_EXT_VREF_MV_MIN * MV_TO_UV) &&
+			    (vref_uv <= ADS7828_EXT_VREF_MV_MAX * MV_TO_UV)) {
+				vref_mv = DIV_ROUND_CLOSEST(vref_uv, MV_TO_UV);
+				ext_vref = true;
+			} else {
+				return  -EINVAL;
+			}

Easier would be

			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;

I don't think we need the MV_TO_UV define.

drivers/hwmon/ads7828.c static int ads7828_probe(struct i2c_client *client, · line 157

Quoted 5 lines
drivers/hwmon/ads7828.c +1 -0
+		}
 	}
 
 	/* Bound Vref with min/max values */

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 9 lines · Wolfram Sang
Quoted 2 lines
 .../devicetree/bindings/i2c/trivial-devices.txt    |  2 --

This file is about to get moved one directory up:

https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git/commit/?h=dt/next&id=b7e252fcddfa573bb1ee275b53bba6cef85671d4

Just so you know already...

Thanks! I'm a bit new to this, what's the best way for me to handle this? Submit against Linus' tree (presumably making a merge nightmare for someone) or rebase my branch off robh's (and presumably risking some other branch's patch conflicting)?

A message that is not in the archive (sent off-list or not yet received): 20170322130555.wgwrkeju43dvj232-vsA/[email protected]

#6 lore raw
Quoted 6 lines · Sam Povilus
Quoted 5 lines · Wolfram Sang
Quoted 2 lines
 .../devicetree/bindings/i2c/trivial-devices.txt    |  2 --

This file is about to get moved one directory up:

Quoted 7 lines
Quoted 4 lines

https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git/commit/?h=dt/next&id=b7e252fcddfa573bb1ee275b53bba6cef85671d4

Just so you know already...

Thanks! I'm a bit new to this, what's the best way for me to handle this?

I mentioned this also for the HWMON maintainers. They will let you know their preference and if you need to do something.

Regards,

Wolfram

maintainer
#7 lore raw
In reply to Sam Povilus
Quoted 8 lines · Sam Povilus
Quoted 7 lines · Wolfram Sang
Quoted 2 lines
 .../devicetree/bindings/i2c/trivial-devices.txt    |  2 --

This file is about to get moved one directory up:

https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git/commit/?h=dt/next&id=b7e252fcddfa573bb1ee275b53bba6cef85671d4

Quoted 7 lines
Quoted 2 lines

Just so you know already...

Thanks! I'm a bit new to this, what's the best way for me to handle this? Submit against Linus' tree (presumably making a merge nightmare for someone) or rebase my branch off robh's (and presumably risking some other branch's patch conflicting)?

Send me a separate patch for just this file and I'll pick it up.

Rob

maintainer
#8 lore raw
Quoted 12 lines · Rob Herring
Quoted 11 lines · Sam Povilus
Quoted 9 lines · Wolfram Sang
Quoted 2 lines
 .../devicetree/bindings/i2c/trivial-devices.txt    |  2 --

This file is about to get moved one directory up:

https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git/commit/?h=dt/next&id=b7e252fcddfa573bb1ee275b53bba6cef85671d4

Just so you know already...

Quoted 7 lines
Quoted 4 lines

Thanks! I'm a bit new to this, what's the best way for me to handle this? Submit against Linus' tree (presumably making a merge nightmare for someone) or rebase my branch off robh's (and presumably risking some other branch's patch conflicting)?

Send me a separate patch for just this file and I'll pick it up.

Agreed, that seems to be the best approach.

Thanks,
Guenter

maintainer
#9 lore raw
In reply to Sam Povilus
Quoted 29 lines · 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.

---
 .../devicetree/bindings/hwmon/ads7828.txt          | 26 ++++++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt    |  2 --
 drivers/hwmon/ads7828.c                            | 21 +++++++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +3 -0
new file mode 100644
index 000000000000..5a0c4a7c6144
@@ -0,0 +1,26 @@
+ads7828 properties
+
+Required properties:

Documentation/devicetree/bindings/hwmon/ads7828.txt line 13

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +10 -0
+- 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

What does this point to?

Should be vref-supply?

Documentation/devicetree/bindings/hwmon/ads7828.txt line 20

Quoted 7 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +7 -0
+  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 {

adc@...

Documentation/devicetree/bindings/hwmon/ads7828.txt line 23

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +3 -0
+  	   comatible = "ti,ads7828";
+	   reg = <0x48>;
+	   vref = <&vref>;

Add a vref node to the example.

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +3 -0
+	   ti,differential-input;
+  };
+