Re: [PATCH v7 3/3] iio:temperature: Add MAX31856 thermocouple support

2019-03-30 Thread Jonathan Cameron
On Tue, 26 Mar 2019 12:18:42 +0100
Patrick Havelange  wrote:

> From: Paresh Chaudhary 
> 
> This patch adds support for Maxim MAX31856 thermocouple
> temperature sensor support.
> 
> More information can be found in:
> https://www.maximintegrated.com/en/ds/MAX31856.pdf
> 
> NOTE: Driver support only Comparator Mode.
> 
> Signed-off-by: Paresh Chaudhary 
> Signed-off-by: Matt Weber 
> Signed-off-by: Patrick Havelange 
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
> Changes
> v1 -> v2
> [Peter
>   1. Fixed all space & 'return' related comments
>   2. Removed 'sysfs_create_group' api  because
>  iio_device_register function is handling sysfs entry
>   3. Return -EIO if there is any fault
>   4. Added check for 'read_size' before spi read call
>   5. Removed license text from the source file
>   6. Added .o file in alphabetic order
>   7. Used #defines instead of magic bits
> 
> v2 -> v3
> [Jonathan
>   1. Used bool for fault_oc and fault_ovuv
>   2. Changed 'max31856_read' function and use byte array to
>  store registers value.
>   3. Used 'GENMASK' where required
> 4. Changed logic 'max31856_thermocouple_read' function. Used
>  array to read registers value.
>   5. Used 'devm_iio_device_register' and removed 'max31856_remove'.
>   6. Fixed other cosmetic changes.
>   7. Added 'sysfs-bus-iio-temperature-max31856' file and updated
>  'MAINTAINERS' file.
> 
> v3 -> v4
> [Jonathan
>   1. Removed unwanted logic
>   2. Updated code to handle return value of max31856_read call
>   3. Added devicetree id table
>   4. Removed one-shot support from driver as this support was not
>  implemented with correct design.
> 
> v4 -> v5
> [Patrick
>   1. Rename thermocouple type to maxim,thermocouple-type for DT entry
>   2. Don't cache values from the Fault Status Register
>   3. Simplify a bit max31856_init()
>   4. Use IIO_NO_MOD in switch case + default error case
>   5. Use dev_*() instead of pr_*()
>   6. Fix missing space in comments
>   7. Removed iio_info.driver_module assignment as no longer present
>   8. Don't keep read/write buffer into the internal driver struct
>   9. Updated kernel version, add missing space in documentation
>10. Updated (c) year
>11. Removed linux/init.h #include
>12. More use of BIT() macro
>13. Removed iio_chan_spec.address assignment as not used
>14. In max31856_thermocouple_read(), same switch case order as
>  channels definition
>15. Refactor show_fault_*() functions
>16. Use u8 as register type in max31856_{read,write}()
> 
> v5 -> v6
> [Patrick
>   1. Use generic thermocouple-type property
>   2. Fix doc for fault_ovuv entry
>   3. Add check for supported thermocouple-types in probe()
> 
> v6 -> v7
> [Patrick
>   1. None
> ---
>  .../sysfs-bus-iio-temperature-max31856|  24 ++
>  drivers/iio/temperature/Kconfig   |  10 +
>  drivers/iio/temperature/Makefile  |   1 +
>  drivers/iio/temperature/max31856.c| 353 ++
>  4 files changed, 388 insertions(+)
>  create mode 100644 
> Documentation/ABI/testing/sysfs-bus-iio-temperature-max31856
>  create mode 100644 drivers/iio/temperature/max31856.c
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-temperature-max31856 
> b/Documentation/ABI/testing/sysfs-bus-iio-temperature-max31856
> new file mode 100644
> index ..3b3509a3ef2f
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-temperature-max31856
> @@ -0,0 +1,24 @@
> +What:/sys/bus/iio/devices/iio:deviceX/fault_oc
> +KernelVersion:   5.1
> +Contact: linux-...@vger.kernel.org
> +Description:
> + Open-circuit fault. The detection of open-circuit faults,
> + such as those caused by broken thermocouple wires.
> + Reading returns either '1' or '0'.
> + '1' = An open circuit such as broken thermocouple wires
> +   has been detected.
> + '0' = No open circuit or broken thermocouple wires are detected
> +
> +What:/sys/bus/iio/devices/iio:deviceX/fault_ovuv
> +KernelVersion:   5.1
> +Contact: linux-...@vger.kernel.org
> +Description:
> + Overvoltage or Undervoltage Input Fault. The internal circuitry
> + is protected from excessive voltages applied to the thermocouple
> + cables by integrated MOSFETs at the T+ and T- inputs, and the
> + BIAS output. These MOSFETs turn off when the input voltage is
> + negative or greater than VDD.
> + Reading returns either '1' or '0'.
> + '1' = The input voltage is negative or greater than VDD.
> + '0' = The input voltage is positive and less than VDD 

[PATCH v7 3/3] iio:temperature: Add MAX31856 thermocouple support

2019-03-26 Thread Patrick Havelange
From: Paresh Chaudhary 

This patch adds support for Maxim MAX31856 thermocouple
temperature sensor support.

More information can be found in:
https://www.maximintegrated.com/en/ds/MAX31856.pdf

NOTE: Driver support only Comparator Mode.

Signed-off-by: Paresh Chaudhary 
Signed-off-by: Matt Weber 
Signed-off-by: Patrick Havelange 
---
Changes
v1 -> v2
[Peter
1. Fixed all space & 'return' related comments
2. Removed 'sysfs_create_group' api  because
   iio_device_register function is handling sysfs entry
3. Return -EIO if there is any fault
4. Added check for 'read_size' before spi read call
5. Removed license text from the source file
6. Added .o file in alphabetic order
7. Used #defines instead of magic bits

v2 -> v3
[Jonathan
1. Used bool for fault_oc and fault_ovuv
2. Changed 'max31856_read' function and use byte array to
   store registers value.
3. Used 'GENMASK' where required
4. Changed logic 'max31856_thermocouple_read' function. Used
   array to read registers value.
5. Used 'devm_iio_device_register' and removed 'max31856_remove'.
6. Fixed other cosmetic changes.
7. Added 'sysfs-bus-iio-temperature-max31856' file and updated
   'MAINTAINERS' file.

v3 -> v4
[Jonathan
1. Removed unwanted logic
2. Updated code to handle return value of max31856_read call
3. Added devicetree id table
4. Removed one-shot support from driver as this support was not
   implemented with correct design.

v4 -> v5
[Patrick
1. Rename thermocouple type to maxim,thermocouple-type for DT entry
2. Don't cache values from the Fault Status Register
3. Simplify a bit max31856_init()
4. Use IIO_NO_MOD in switch case + default error case
5. Use dev_*() instead of pr_*()
6. Fix missing space in comments
7. Removed iio_info.driver_module assignment as no longer present
8. Don't keep read/write buffer into the internal driver struct
9. Updated kernel version, add missing space in documentation
   10. Updated (c) year
   11. Removed linux/init.h #include
   12. More use of BIT() macro
   13. Removed iio_chan_spec.address assignment as not used
   14. In max31856_thermocouple_read(), same switch case order as
   channels definition
   15. Refactor show_fault_*() functions
   16. Use u8 as register type in max31856_{read,write}()

v5 -> v6
[Patrick
1. Use generic thermocouple-type property
2. Fix doc for fault_ovuv entry
3. Add check for supported thermocouple-types in probe()

v6 -> v7
[Patrick
1. None
---
 .../sysfs-bus-iio-temperature-max31856|  24 ++
 drivers/iio/temperature/Kconfig   |  10 +
 drivers/iio/temperature/Makefile  |   1 +
 drivers/iio/temperature/max31856.c| 353 ++
 4 files changed, 388 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-temperature-max31856
 create mode 100644 drivers/iio/temperature/max31856.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-temperature-max31856 
b/Documentation/ABI/testing/sysfs-bus-iio-temperature-max31856
new file mode 100644
index ..3b3509a3ef2f
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-temperature-max31856
@@ -0,0 +1,24 @@
+What:  /sys/bus/iio/devices/iio:deviceX/fault_oc
+KernelVersion: 5.1
+Contact:   linux-...@vger.kernel.org
+Description:
+   Open-circuit fault. The detection of open-circuit faults,
+   such as those caused by broken thermocouple wires.
+   Reading returns either '1' or '0'.
+   '1' = An open circuit such as broken thermocouple wires
+ has been detected.
+   '0' = No open circuit or broken thermocouple wires are detected
+
+What:  /sys/bus/iio/devices/iio:deviceX/fault_ovuv
+KernelVersion: 5.1
+Contact:   linux-...@vger.kernel.org
+Description:
+   Overvoltage or Undervoltage Input Fault. The internal circuitry
+   is protected from excessive voltages applied to the thermocouple
+   cables by integrated MOSFETs at the T+ and T- inputs, and the
+   BIAS output. These MOSFETs turn off when the input voltage is
+   negative or greater than VDD.
+   Reading returns either '1' or '0'.
+   '1' = The input voltage is negative or greater than VDD.
+   '0' = The input voltage is positive and less than VDD (normal
+   state).
diff --git a/drivers/iio/temperature/Kconfig b/drivers/iio/temperature/Kconfig
index 82e4a62745e2..c66eeb23615b 100644
--- a/drivers/iio/temperature/Kconfig
+++ b/drivers/iio/temperature/Kconfig
@@ -97,4 +97,14 @@ config TSYS02D
  This driver can also be built as a module. If so, the module will