Skip to contentSkip to conversation

iio: temperature: Add MAX31865 RTD Support

PATCH Superseded Navin Sankar Velliangiri 2 participants 4 messages Aug 4, 2021 – Aug 8, 2021

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 iio: temperature: Add MAX31865 RTD Support

This patch adds support for Maxim MAX31865 RTD temperature sensor support.

More information can be found in:
https://datasheets.maximintegrated.com/en/ds/MAX31865.pdf

---

Note:
Changes in v2:

	-> removed unnecessary header #include <linux/util_macros.h>
	-> implemented mutex to protect the device state
	-> Added __cacheline_aligned buffer to hold the raw temperature data
	-> implemented separate function to enable_bias() & disable_bias()
	-> call max31865_init() func when updating the filter
	-> Added ABI documentation for reference & testing
	-> dropped spi_set_drvdata()

Changes in v3:

	-> Moved buf[2] __cacheline_aligned to last element of struct
	max31865_data
	-> get_unaligned_be16 is used to express the raw temp data
	-> Added in_temp_filter_notch_frequency_avail to check available
	frequency
	-> removed mutex lock & unlock in max31865_probe() func
---
 .../sysfs-bus-iio-temperature-max31865        |  20 +
 drivers/iio/temperature/Kconfig               |  10 +
 drivers/iio/temperature/Makefile              |   1 +
 drivers/iio/temperature/max31865.c            | 355 ++++++++++++++++++
 4 files changed, 386 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-temperature-max31865
 create mode 100644 drivers/iio/temperature/max31865.c
Documentation/ABI/testing/sysfs-bus-iio-temperature-max31865 new file +20 -0
new file mode 100644
index 000000000000..368655539627
@@ -0,0 +1,20 @@
+What:		/sys/bus/iio/devices/iio:deviceX/fault_ovuv
+KernelVersion:	5.11
+Contact:	[email protected]
+Description:
+		Overvoltage or Undervoltage Input fault. The internal circuitry
+		is protected from excessive voltages applied to the thermocouple
+		cables at FORCE+, FORCE2, RTDIN+ & RTDIN-. This circuitry turn
+		off when the input voltage is negative or greater than VDD.
+
+		Reading returns '1' if input voltage is negative or greater
+		than VDD, otherwise '0'.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_temp_filter_notch_frequency
+KernelVersion:	5.11
+Contact:	[email protected]
+Description:
+		Notch frequency in Hz for a noise rejection filter. Used i.e for
+		line noise rejection.
+
+		Valid notch filter values are 50 Hz and 60 Hz.
drivers/iio/temperature/Kconfig +10 -0
index 4df60082c1fa..c9412abca069 100644
@@ -128,4 +128,14 @@ config MAX31856
 	  This driver can also be built as a module.  If so, the module
 	  will be called max31856.
 
+config MAX31865
+	tristate "MAX31865 RTD to Digital converter"
+	depends on SPI
+	help
+	  If you say yes here you get support for MAX31865
+	  thermocouple sensor chip connected via SPI.
+
+	  This driver can also be build as a module. If so, the module
+	  will be called max31865.
+
 endmenu
drivers/iio/temperature/Makefile +1 -0
index 90c113115422..a8f3187258dc 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_LTC2983) += ltc2983.o
 obj-$(CONFIG_HID_SENSOR_TEMP) += hid-sensor-temperature.o
 obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o
 obj-$(CONFIG_MAX31856) += max31856.o
+obj-$(CONFIG_MAX31865) += max31865.o
 obj-$(CONFIG_MLX90614) += mlx90614.o
 obj-$(CONFIG_MLX90632) += mlx90632.o
 obj-$(CONFIG_TMP006) += tmp006.o
drivers/iio/temperature/max31865.c new file +355 -0

355 lines not on this page · raw message

Signature · 1 line
2.32.0
#1 lore raw

PATCH v3 2/2 dt-bindings: iio: temperature: add MAXIM max31865 support

Add DT bindings for MAXIM max31865 RTD sensor.

---

Note:
Changes in v2:

	-> Changed the name RTD to Resistance Temperature Detector
	-> renamed maxim,no-of-wires to 3-wire
	-> fixed code alignment for the example

Changes in v3:

	-> Added more information about 3 wire RTD connection
---
 .../iio/temperature/maxim,max31865.yaml       | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/maxim,max31865.yaml
Documentation/devicetree/bindings/iio/temperature/maxim,max31865.yaml new file +52 -0
new file mode 100644
index 000000000000..aafb33b16549
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/temperature/maxim,max31865.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Maxim MAX31865 Resistance Temperature Detector.
+
+maintainers:
+  - Navin Sankar Velliangiri <[email protected]>
+
+description: |
+  https://datasheets.maximintegrated.com/en/ds/MAX31865.pdf
+
+properties:
+  compatible:
+    const: maxim,max31865
+
+  reg:
+    maxItems: 1
+
+  maxim,3-wire:
+    description:
+      Identifies the number of wires used by the RTD. Setting this property
+      enables 3-wire RTD connection. Else 2-wire or 4-wire RTD connection.
+    type: boolean
+
+  spi-max-frequency: true
+  spi-cpha: true
+
+required:
+  - compatible
+  - reg
+  - spi-cpha
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+       #address-cells = <1>;
+       #size-cells = <0>;
+
+       temp_sensor@0 {
+         compatible = "maxim,max31865";
+         reg = <0>;
+         spi-max-frequency = <400000>;
+         spi-cpha;
+         maxim,3-wire;
+       };
+    };
+...
Signature · 1 line
2.32.0
maintainer
#2 lore raw

Re: [PATCH v3 2/2] dt-bindings: iio: temperature: add MAXIM max31865 support

Quoted 3 lines · On Wed, 4 Aug 2021 21:12:54 +0530 Navin Sankar Velliangiri…

Add DT bindings for MAXIM max31865 RTD sensor.

dt-bindings need to be cc'd to the devicetree list and maintainers so they can review them.

There has also been some recent discussion on having spi modes in bindings when the device only supports one option. The preference is to instead have the driver enforce those by an spi_mode() call. (e.g. spi-cpha)

There are corner cases (usually involving some cheap level conversion) where this doesn't work, but in those cases the 'required' below wouldn't work either, so we leave them to be dealt with if they ever happen for a particular piece of hardware.

Jonathan

Quoted 74 lines

---

Note:
Changes in v2:

	-> Changed the name RTD to Resistance Temperature Detector
	-> renamed maxim,no-of-wires to 3-wire
	-> fixed code alignment for the example  

Changes in v3:

	-> Added more information about 3 wire RTD connection  
---
 .../iio/temperature/maxim,max31865.yaml       | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/maxim,max31865.yaml
Documentation/devicetree/bindings/iio/temperature/maxim,max31865.yaml new file +52 -0
new file mode 100644
index 000000000000..aafb33b16549
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/temperature/maxim,max31865.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Maxim MAX31865 Resistance Temperature Detector.
+
+maintainers:
+  - Navin Sankar Velliangiri <[email protected]>
+
+description: |
+  https://datasheets.maximintegrated.com/en/ds/MAX31865.pdf
+
+properties:
+  compatible:
+    const: maxim,max31865
+
+  reg:
+    maxItems: 1
+
+  maxim,3-wire:
+    description:
+      Identifies the number of wires used by the RTD. Setting this property
+      enables 3-wire RTD connection. Else 2-wire or 4-wire RTD connection.
+    type: boolean
+
+  spi-max-frequency: true
+  spi-cpha: true
+
+required:
+  - compatible
+  - reg
+  - spi-cpha
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+       #address-cells = <1>;
+       #size-cells = <0>;
+
+       temp_sensor@0 {
+         compatible = "maxim,max31865";
+         reg = <0>;
+         spi-max-frequency = <400000>;
+         spi-cpha;
+         maxim,3-wire;
+       };
+    };
+...
maintainer
#3 lore raw
In reply to Navin Sankar Velliangiri
Quoted 8 lines · On Wed, 4 Aug 2021 21:12:53 +0530 Navin Sankar Velliangiri…

This patch adds support for Maxim MAX31865 RTD temperature sensor support.

More information can be found in:
https://datasheets.maximintegrated.com/en/ds/MAX31865.pdf

Hi Navin,

A few follow up comments around the ABI.

Thanks,

Jonathan

Quoted 37 lines

---

Note:
Changes in v2:

	-> removed unnecessary header #include <linux/util_macros.h>
	-> implemented mutex to protect the device state
	-> Added __cacheline_aligned buffer to hold the raw temperature data
	-> implemented separate function to enable_bias() & disable_bias()
	-> call max31865_init() func when updating the filter
	-> Added ABI documentation for reference & testing
	-> dropped spi_set_drvdata()  

Changes in v3:

	-> Moved buf[2] __cacheline_aligned to last element of struct  
	max31865_data
	-> get_unaligned_be16 is used to express the raw temp data
	-> Added in_temp_filter_notch_frequency_avail to check available  
	frequency
	-> removed mutex lock & unlock in max31865_probe() func  
---
 .../sysfs-bus-iio-temperature-max31865        |  20 +
 drivers/iio/temperature/Kconfig               |  10 +
 drivers/iio/temperature/Makefile              |   1 +
 drivers/iio/temperature/max31865.c            | 355 ++++++++++++++++++
 4 files changed, 386 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-temperature-max31865
 create mode 100644 drivers/iio/temperature/max31865.c
Documentation/ABI/testing/sysfs-bus-iio-temperature-max31865 new file +3 -0
new file mode 100644
index 000000000000..368655539627
@@ -0,0 +1,20 @@
+What:		/sys/bus/iio/devices/iio:deviceX/fault_ovuv
+KernelVersion:	5.11
+Contact:	[email protected]

Documentation/ABI/testing/sysfs-bus-iio-temperature-max31865 line 13

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-max31865 new file +10 -0
+Description:
+		Overvoltage or Undervoltage Input fault. The internal circuitry
+		is protected from excessive voltages applied to the thermocouple
+		cables at FORCE+, FORCE2, RTDIN+ & RTDIN-. This circuitry turn
+		off when the input voltage is negative or greater than VDD.
+
+		Reading returns '1' if input voltage is negative or greater
+		than VDD, otherwise '0'.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_temp_filter_notch_frequency

As mentioned below, also needs to include documentation for _available Ideally we'll make this part of the core ABI and move this to the main docs.

Quoted 7 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-max31865 new file +7 -0
+KernelVersion:	5.11
+Contact:	[email protected]
+Description:
+		Notch frequency in Hz for a noise rejection filter. Used i.e for
+		line noise rejection.
+
+		Valid notch filter values are 50 Hz and 60 Hz.

...

Quoted 6 lines
drivers/iio/temperature/max31865.c new file +0 -0
new file mode 100644
index 000000000000..dfeba8f3f6e4
@@ -0,0 +1,355 @@

...

Quoted 12 lines
drivers/iio/temperature/max31865.c new file +12 -0
+static ssize_t show_fault_ovuv(struct device *dev,
+			      struct device_attribute *attr,
+			      char *buf)
+{
+	return show_fault(dev, MAX31865_FAULT_OVUV, buf);
+}
+
+static ssize_t show_filter(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);

drivers/iio/temperature/max31865.c line 233

Quoted 10 lines
drivers/iio/temperature/max31865.c new file +10 -0
+	struct max31865_data *data = iio_priv(indio_dev);
+
+	return sprintf(buf, "%d\n", data->filter_50hz ? 50 : 60);
+}
+
+static ssize_t show_avail_notch_frequency(struct device *dev,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	return snprintf(buf, 12, "50 Hz\n60 Hz");

That's not the format of _available. Check the documentation for existing _available attributes. It should be a simple

"50 60\n"

I would prefer to see this added to the IIO core rather than done as a custom attribute. If you really don't want to do that for some reason then fair enough and I'll add it to the todo list (which is unfortunately mostly in my head or on random bits of paper, so whether anything gets done is fairly random...)

Quoted 35 lines
drivers/iio/temperature/max31865.c new file +35 -0
+}
+
+static ssize_t set_filter(struct device *dev,
+			  struct device_attribute *attr,
+			  const char *buf,
+			  size_t len)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct max31865_data *data = iio_priv(indio_dev);
+	unsigned int freq;
+	int ret;
+
+	ret = kstrtouint(buf, 10, &freq);
+	if (ret)
+		return ret;
+
+	switch (freq) {
+	case 50:
+		data->filter_50hz = true;
+		break;
+	case 60:
+		data->filter_50hz = false;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	mutex_lock(&data->lock);
+	ret = max31865_init(data);
+	mutex_unlock(&data->lock);
+	if (ret)
+		return ret;
+
+	return len;
+}

drivers/iio/temperature/max31865.c line 278

Quoted 10 lines
drivers/iio/temperature/max31865.c new file +10 -0
+
+static IIO_DEVICE_ATTR(fault_ovuv, 0444, show_fault_ovuv, NULL, 0);
+static IIO_DEVICE_ATTR(in_temp_filter_notch_frequency_avail, 0444,
+		     show_avail_notch_frequency, NULL, 0);
+static IIO_DEVICE_ATTR(in_temp_filter_notch_frequency, 0644,
+		    show_filter, set_filter, 0);
+
+static struct attribute *max31865_attributes[] = {
+	&iio_dev_attr_fault_ovuv.dev_attr.attr,
+	&iio_dev_attr_in_temp_filter_notch_frequency_avail.dev_attr.attr,

No documentation for this new ABI element. The _avail bits need to be explicitly documented as well as what they refer to. Also check the naming against existing attributes. Should be _available
(I got this wrong in previous review - sorry about that!)

Quoted 13 lines
drivers/iio/temperature/max31865.c new file +13 -0
+	&iio_dev_attr_in_temp_filter_notch_frequency.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group max31865_group = {
+	.attrs = max31865_attributes,
+};
+
+static const struct iio_info max31865_info = {
+	.read_raw = max31865_read_raw,
+	.attrs = &max31865_group,
+};
+

...