Skip to contentSkip to conversation

hwmon: ads7828 optional parameters from the device tree

PATCH Superseded Sam Povilus 4 participants 6 messages Mar 12, 2017 – Mar 16, 2017 2 messages not in the archive

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 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.

Also adding a note to the user if they misconfigure the device's external reference.

v2: conforming to coding style
v3: changing from "_" to "-" for device tree entries

---
 Documentation/devicetree/bindings/hwmon/ads7828.txt    | 18 ++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt        |  2 --
 drivers/hwmon/ads7828.c                                | 15 +++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +18 -0
new file mode 100644
index 000000000000..0d37cd3fd31b
@@ -0,0 +1,18 @@
+ads7828 properties
+
+Required properties:
+- compatible:
+	Should be one of
+	       ti,ads7828
+	       ti,ads7830
+- reg: I2C address
+
+Optional properties:
+
+- diff-input
+  Set to use the device in differential mode.
+- ext-vref
+  Set to enable the external voltage reference on the device.
+- vref-mv
+  The external reference on the device is set to this as an unsigned integer in
+  milivolts. Must use "ext_vref" for this to have any meaning.
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 +15 -0
index ee396ff167d9..d1f7ba5d7a2b 100644
@@ -118,6 +118,7 @@ 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_mv_tmp;
 	bool diff_input = false;
 	bool ext_vref = false;
 	unsigned int regval;
@@ -131,11 +132,25 @@ 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, "diff-input", NULL))
+			diff_input = true;
+		if (of_get_property(dev->of_node, "ext-vref", NULL))
+			ext_vref = true;
+		if (!of_property_read_u32(dev->of_node, "vref-mv", &vref_mv_tmp)
+		   && ext_vref)
+			vref_mv = vref_mv_tmp;
 	}
 
 	/* Bound Vref with min/max values */
+	vref_mv_tmp = vref_mv;
 	vref_mv = clamp_val(vref_mv, ADS7828_EXT_VREF_MV_MIN,
 			    ADS7828_EXT_VREF_MV_MAX);
+	if (vref_mv_tmp != vref_mv) {
+		pr_info("You used and invalid external vref,"
+			" it has been clamped to %u",
+			vref_mv);
+	}
 
 	/* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */
 	if (id->driver_data == ads7828) {
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 27 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.

Also adding a note to the user if they misconfigure the device's external reference.

v2: conforming to coding style
v3: changing from "_" to "-" for device tree entries

---
 Documentation/devicetree/bindings/hwmon/ads7828.txt    | 18 ++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt        |  2 --
 drivers/hwmon/ads7828.c                                | 15 +++++++++++++++
 3 files changed, 33 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..0d37cd3fd31b
@@ -0,0 +1,18 @@
+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:
+
+- diff-input
+  Set to use the device in differential mode.

I'll wait for Rob to comment, but "differential-input" sounds better to me, Also, it would have to have a "ti," prefix.

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

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +5 -0
+- ext-vref
+  Set to enable the external voltage reference on the device.
+- vref-mv
+  The external reference on the device is set to this as an unsigned integer in
+  milivolts. Must use "ext_vref" for this to have any meaning.

ext_vref, though as suggested below I think it would be better to use a standard property. Also, it seems to me that ext-vref is really unnecessary; the presence of "vref" can imply that the reference voltage is external.

Quoted 27 lines
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 +1 -0
index ee396ff167d9..d1f7ba5d7a2b 100644
@@ -118,6 +118,7 @@ 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_mv_tmp;
 	bool diff_input = false;
 	bool ext_vref = false;
 	unsigned int regval;
@@ -131,11 +132,25 @@ static int ads7828_probe(struct i2c_client *client,
 		ext_vref = pdata->ext_vref;

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

Quoted 10 lines
drivers/hwmon/ads7828.c +8 -0
 		if (ext_vref && pdata->vref_mv)
 			vref_mv = pdata->vref_mv;
+	} else if (dev->of_node) {
+		if (of_get_property(dev->of_node, "diff-input", NULL))
+			diff_input = true;
+		if (of_get_property(dev->of_node, "ext-vref", NULL))
+			ext_vref = true;
+		if (!of_property_read_u32(dev->of_node, "vref-mv", &vref_mv_tmp)
+		   && ext_vref)
+			vref_mv = vref_mv_tmp;

Please consider using devm_regulator_get_optional() and thus standard properties.

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

Quoted 11 lines
drivers/hwmon/ads7828.c +6 -0
 	}
 
 	/* Bound Vref with min/max values */
+	vref_mv_tmp = vref_mv;
 	vref_mv = clamp_val(vref_mv, ADS7828_EXT_VREF_MV_MIN,
 			    ADS7828_EXT_VREF_MV_MAX);
+	if (vref_mv_tmp != vref_mv) {
+		pr_info("You used and invalid external vref,"
+			" it has been clamped to %u",
+			vref_mv);
+	}

This is an unrelated change.

Quoted 4 lines
drivers/hwmon/ads7828.c +0 -0
 	/* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */
 	if (id->driver_data == ads7828) {
 
#2 lore raw
Quoted 33 lines · Guenter Roeck
Quoted 32 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.

Also adding a note to the user if they misconfigure the device's external reference.

v2: conforming to coding style
v3: changing from "_" to "-" for device tree entries

---
 Documentation/devicetree/bindings/hwmon/ads7828.txt    | 18 ++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt        |  2 --
 drivers/hwmon/ads7828.c                                | 15 +++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +8 -0
new file mode 100644
index 000000000000..0d37cd3fd31b
@@ -0,0 +1,18 @@
+ads7828 properties
+
+Required properties:
+- compatible:
+	Should be one of
+	       ti,ads7828
+	       ti,ads7830
+- reg: I2C address
Quoted 9 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +5 -0
+
+Optional properties:
+
+- diff-input
+  Set to use the device in differential mode.

I'll wait for Rob to comment, but "differential-input" sounds better to me, Also, it would have to have a "ti," prefix.

The platform device uses diff_input, are we going for consistancy or correctness? I am good with either.

Quoted 10 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +5 -0
+- ext-vref
+  Set to enable the external voltage reference on the device.
+- vref-mv
+  The external reference on the device is set to this as an unsigned integer in
+  milivolts. Must use "ext_vref" for this to have any meaning.

ext_vref, though as suggested below I think it would be better to use a standard property. Also, it seems to me that ext-vref is really unnecessary; the presence of "vref" can imply that the reference voltage is external.

I agree, but again, the platform device seperates it. Consistancy or correctness?

Quoted 31 lines
Quoted 31 lines
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 +3 -0
index ee396ff167d9..d1f7ba5d7a2b 100644
@@ -118,6 +118,7 @@ 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_mv_tmp;
 	bool diff_input = false;
 	bool ext_vref = false;
 	unsigned int regval;
@@ -131,11 +132,25 @@ 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, "diff-input", NULL))
Quoted 9 lines

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

Quoted 6 lines
drivers/hwmon/ads7828.c +6 -0
+			diff_input = true;
+		if (of_get_property(dev->of_node, "ext-vref", NULL))
+			ext_vref = true;
+		if (!of_property_read_u32(dev->of_node, "vref-mv", &vref_mv_tmp)
+		   && ext_vref)
+			vref_mv = vref_mv_tmp;

Please consider using devm_regulator_get_optional() and thus standard properties.

I'd have to disagree with this, but not strongly. In my reading of Documentation/power/regulator/overview.txt it seems like the regulator subsystem is exclusivly for regulators not for references. I would hope that most board designers would not use a regulator, and especially not a switch mode regulator for the input to a reference. Am I reading the regulator subsystem overview wrong? or are people using it for things that it's not quite intended (I will admit it looks like a number of other adcs use it)? or is there some other explination.

Quoted 19 lines

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

Quoted 11 lines
drivers/hwmon/ads7828.c +6 -0
 	}
 
 	/* Bound Vref with min/max values */
+	vref_mv_tmp = vref_mv;
 	vref_mv = clamp_val(vref_mv, ADS7828_EXT_VREF_MV_MIN,
 			    ADS7828_EXT_VREF_MV_MAX);
+	if (vref_mv_tmp != vref_mv) {
+		pr_info("You used and invalid external vref,"
+			" it has been clamped to %u",
+			vref_mv);
+	}

This is an unrelated change.

Quoted 4 lines
drivers/hwmon/ads7828.c +0 -0
 	/* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */
 	if (id->driver_data == ads7828) {
 
maintainer
#3 lore raw
Quoted 44 lines · Sam Povilus
Quoted 33 lines · Guenter Roeck
Quoted 32 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.

Also adding a note to the user if they misconfigure the device's external reference.

v2: conforming to coding style
v3: changing from "_" to "-" for device tree entries

---
 Documentation/devicetree/bindings/hwmon/ads7828.txt    | 18 ++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt        |  2 --
 drivers/hwmon/ads7828.c                                | 15 +++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +8 -0
new file mode 100644
index 000000000000..0d37cd3fd31b
@@ -0,0 +1,18 @@
+ads7828 properties
+
+Required properties:
+- compatible:
+	Should be one of
+	       ti,ads7828
+	       ti,ads7830
+- reg: I2C address
Quoted 9 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +5 -0
+
+Optional properties:
+
+- diff-input
+  Set to use the device in differential mode.

I'll wait for Rob to comment, but "differential-input" sounds better to me, Also, it would have to have a "ti," prefix.

Quoted 3 lines

The platform device uses diff_input, are we going for consistancy or correctness? I am good with either.

What does a platform device variable name, ie a Linux implementation detail, have to do with a devicetree property name ?

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +5 -0
+- ext-vref
+  Set to enable the external voltage reference on the device.
+- vref-mv
+  The external reference on the device is set to this as an unsigned integer in
+  milivolts. Must use "ext_vref" for this to have any meaning.
Quoted 8 lines
Quoted 4 lines

ext_vref, though as suggested below I think it would be better to use a standard property. Also, it seems to me that ext-vref is really unnecessary; the presence of "vref" can imply that the reference voltage is external.

I agree, but again, the platform device seperates it. Consistancy or correctness?

Same question.

Quoted 41 lines
Quoted 31 lines
Quoted 31 lines
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 +3 -0
index ee396ff167d9..d1f7ba5d7a2b 100644
@@ -118,6 +118,7 @@ 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_mv_tmp;
 	bool diff_input = false;
 	bool ext_vref = false;
 	unsigned int regval;
@@ -131,11 +132,25 @@ 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, "diff-input", NULL))
Quoted 9 lines

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

Quoted 6 lines
drivers/hwmon/ads7828.c +6 -0
+			diff_input = true;
+		if (of_get_property(dev->of_node, "ext-vref", NULL))
+			ext_vref = true;
+		if (!of_property_read_u32(dev->of_node, "vref-mv", &vref_mv_tmp)
+		   && ext_vref)
+			vref_mv = vref_mv_tmp;

Please consider using devm_regulator_get_optional() and thus standard properties.

Quoted 9 lines

I'd have to disagree with this, but not strongly. In my reading of Documentation/power/regulator/overview.txt it seems like the regulator subsystem is exclusivly for regulators not for references. I would hope that most board designers would not use a regulator, and especially not a switch mode regulator for the input to a reference. Am I reading the regulator subsystem overview wrong? or are people using it for things that it's not quite intended (I will admit it looks like a number of other adcs use it)? or is there some other explination.

A reference voltage is still a voltage which can be enabled or disabled. By using a regulator one leaves it open if that voltage is enabled if the chip is not in use. We also don't usually tell board designers how to design the hardware. Besides, it is quite convenient.

Can you point me to the location in above documentation which states that reference voltages shall not use regulators ? I seem to be unable to find it.

Thanks,
Guenter

A message that is not in the archive (sent off-list or not yet received): 0540770e-6604-f224-9e00-c34e8c5c3c91-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org

#5 lore raw
Quoted 45 lines · Guenter Roeck
Quoted 44 lines · Sam Povilus
Quoted 42 lines · Guenter Roeck
Quoted 27 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.

Also adding a note to the user if they misconfigure the device's external reference.

v2: conforming to coding style
v3: changing from "_" to "-" for device tree entries

---
 Documentation/devicetree/bindings/hwmon/ads7828.txt    | 18 ++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt        |  2 --
 drivers/hwmon/ads7828.c                                | 15 +++++++++++++++
 3 files changed, 33 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..0d37cd3fd31b
@@ -0,0 +1,18 @@
+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:
+
+- diff-input
+  Set to use the device in differential mode.

I'll wait for Rob to comment, but "differential-input" sounds better to me, Also, it would have to have a "ti," prefix.

Quoted 7 lines
Quoted 3 lines

The platform device uses diff_input, are we going for consistancy or correctness? I am good with either.

What does a platform device variable name, ie a Linux implementation detail, have to do with a devicetree property name ?

Isn't the device tree property name also an implementation detail?

Quoted 68 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +5 -0
+- ext-vref
+  Set to enable the external voltage reference on the device.
+- vref-mv
+  The external reference on the device is set to this as an unsigned integer in
+  milivolts. Must use "ext_vref" for this to have any meaning.
Quoted 8 lines
Quoted 4 lines

ext_vref, though as suggested below I think it would be better to use a standard property. Also, it seems to me that ext-vref is really unnecessary; the presence of "vref" can imply that the reference voltage is external.

I agree, but again, the platform device seperates it. Consistancy or correctness?

Same question.

Quoted 41 lines
Quoted 31 lines
Quoted 31 lines
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 +3 -0
index ee396ff167d9..d1f7ba5d7a2b 100644
@@ -118,6 +118,7 @@ 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_mv_tmp;
 	bool diff_input = false;
 	bool ext_vref = false;
 	unsigned int regval;
@@ -131,11 +132,25 @@ 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, "diff-input", NULL))
Quoted 9 lines

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

Quoted 6 lines
drivers/hwmon/ads7828.c +6 -0
+			diff_input = true;
+		if (of_get_property(dev->of_node, "ext-vref", NULL))
+			ext_vref = true;
+		if (!of_property_read_u32(dev->of_node, "vref-mv", &vref_mv_tmp)
+		   && ext_vref)
+			vref_mv = vref_mv_tmp;

Please consider using devm_regulator_get_optional() and thus standard properties.

Quoted 9 lines

I'd have to disagree with this, but not strongly. In my reading of Documentation/power/regulator/overview.txt it seems like the regulator subsystem is exclusivly for regulators not for references. I would hope that most board designers would not use a regulator, and especially not a switch mode regulator for the input to a reference. Am I reading the regulator subsystem overview wrong? or are people using it for things that it's not quite intended (I will admit it looks like a number of other adcs use it)? or is there some other explination.

Quoted 8 lines

A reference voltage is still a voltage which can be enabled or disabled. By using a regulator one leaves it open if that voltage is enabled if the chip is not in use. We also don't usually tell board designers how to design the hardware. Besides, it is quite convenient.

Can you point me to the location in above documentation which states that reference voltages shall not use regulators ? I seem to be unable to find it.

"reference voltages shall not use regulators" It's not a shall not it's a should not. Regulators are significantly more inaccurate than references, subject to far more noise pass-through, and treated very differently by the electronics design community. One could use a system wide regulated bus for a reference to an ADC, but that would significantly reduce the accuracy and precision of your measurements. In almost all cases board designers are going to use always on references for this application, something that puts them well outside the purpose of the regulator subsystem.

Quoted 3 lines

Thanks,
Guenter

--
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): 20170316132811.jsu7pprl4zqeifxz-vsA/[email protected]

#7 lore raw
Quoted 50 lines · Sam Povilus
Quoted 49 lines · Guenter Roeck
Quoted 47 lines · Sam Povilus
Quoted 33 lines · Guenter Roeck
Quoted 32 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.

Also adding a note to the user if they misconfigure the device's external reference.

v2: conforming to coding style
v3: changing from "_" to "-" for device tree entries

---
 Documentation/devicetree/bindings/hwmon/ads7828.txt    | 18 ++++++++++++++++++
 .../devicetree/bindings/i2c/trivial-devices.txt        |  2 --
 drivers/hwmon/ads7828.c                                | 15 +++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +8 -0
new file mode 100644
index 000000000000..0d37cd3fd31b
@@ -0,0 +1,18 @@
+ads7828 properties
+
+Required properties:
+- compatible:
+	Should be one of
+	       ti,ads7828
+	       ti,ads7830
+- reg: I2C address
Quoted 9 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +5 -0
+
+Optional properties:
+
+- diff-input
+  Set to use the device in differential mode.

I'll wait for Rob to comment, but "differential-input" sounds better to me, Also, it would have to have a "ti," prefix.

The platform device uses diff_input, are we going for consistancy or correctness? I am good with either.

Quoted 6 lines
Quoted 3 lines

What does a platform device variable name, ie a Linux implementation detail, have to do with a devicetree property name ?

Isn't the device tree property name also an implementation detail?

Devicetree properties are supposed to be operating system independent properties used to describe the hardware. That is hardly an implementation detail.

Quoted 77 lines
Quoted 68 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ads7828.txt new file +5 -0
+- ext-vref
+  Set to enable the external voltage reference on the device.
+- vref-mv
+  The external reference on the device is set to this as an unsigned integer in
+  milivolts. Must use "ext_vref" for this to have any meaning.
Quoted 8 lines
Quoted 4 lines

ext_vref, though as suggested below I think it would be better to use a standard property. Also, it seems to me that ext-vref is really unnecessary; the presence of "vref" can imply that the reference voltage is external.

I agree, but again, the platform device seperates it. Consistancy or correctness?

Same question.

Quoted 41 lines
Quoted 31 lines
Quoted 31 lines
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 +3 -0
index ee396ff167d9..d1f7ba5d7a2b 100644
@@ -118,6 +118,7 @@ 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_mv_tmp;
 	bool diff_input = false;
 	bool ext_vref = false;
 	unsigned int regval;
@@ -131,11 +132,25 @@ 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, "diff-input", NULL))
Quoted 9 lines

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

Quoted 6 lines
drivers/hwmon/ads7828.c +6 -0
+			diff_input = true;
+		if (of_get_property(dev->of_node, "ext-vref", NULL))
+			ext_vref = true;
+		if (!of_property_read_u32(dev->of_node, "vref-mv", &vref_mv_tmp)
+		   && ext_vref)
+			vref_mv = vref_mv_tmp;

Please consider using devm_regulator_get_optional() and thus standard properties.

Quoted 9 lines

I'd have to disagree with this, but not strongly. In my reading of Documentation/power/regulator/overview.txt it seems like the regulator subsystem is exclusivly for regulators not for references. I would hope that most board designers would not use a regulator, and especially not a switch mode regulator for the input to a reference. Am I reading the regulator subsystem overview wrong? or are people using it for things that it's not quite intended (I will admit it looks like a number of other adcs use it)? or is there some other explination.

Quoted 8 lines

A reference voltage is still a voltage which can be enabled or disabled. By using a regulator one leaves it open if that voltage is enabled if the chip is not in use. We also don't usually tell board designers how to design the hardware. Besides, it is quite convenient.

Can you point me to the location in above documentation which states that reference voltages shall not use regulators ? I seem to be unable to find it.

Quoted 10 lines

"reference voltages shall not use regulators" It's not a shall not it's a should not. Regulators are significantly more inaccurate than references, subject to far more noise pass-through, and treated very differently by the electronics design community. One could use a system wide regulated bus for a reference to an ADC, but that would significantly reduce the accuracy and precision of your measurements. In almost all cases board designers are going to use always on references for this application, something that puts them well outside the purpose of the regulator subsystem.

You are right in a narrow sense, by associating the term "regulator" as used in the Linux kernel with a hardware regulator chip which may have the properties you describe.

However, there is nothing that states that a "regulator", in the context used in the Linux kernel, shall be implemented as (potentially noisy) hardware regulator, or that the regulator subssystem shall not support, say, on/off regulators (or the ability to turn battery voltages on/off), or, for that matter, stable voltages suitable as reference voltages. Creating such an artificial restriction would severely limit the use case for the Linux regulator subsystem, would result in code duplication and fragmentation all over the place, and just doesn't make sense.

As an example, have a look at drivers/regulator/fixed.c; it is a regulator which can optionally be turned on and off using a GPIO pin (but is more likely always on) and provides a single fixed voltage. That regulator is used as follows in at least one devicetree file (there are more similar uses).

	vbat: fixedregulator@0 {
		compatible = "regulator-fixed";
		regulator-name = "vbat";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		regulator-boot-on;
	};

It is quite unlikely that this regulator has the properties you describe. Following your logic, such a use would not be appropriate just because the term "regulator" is used.

Thanks,
Guenter
--
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