From 9444edfa8b5b18f8727b82853dd50345a400a316 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Thu, 22 Oct 2020 17:11:12 +0100
Subject: [PATCH] overlays: Add MAX31856 support to maxtherm overlay

Extend the maxtherm overlay with support for the MAX31856.
The driver reads the thermocouple type from a property, which is much
more civilised.

See: https://github.com/raspberrypi/linux/issues/3915

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 arch/arm/boot/dts/overlays/README             | 18 ++++++++++++-----
 .../boot/dts/overlays/maxtherm-overlay.dts    | 20 +++++++++++++++++++
 2 files changed, 33 insertions(+), 5 deletions(-)

--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -1666,20 +1666,19 @@ Params: no-sdmode               Driver d
 
 
 Name:   maxtherm
-Info:   Configure a MAX6675 or MAX31855 thermocouple as an IIO device.
+Info:   Configure a MAX6675, MAX31855 or MAX31856 thermocouple as an IIO device.
 
         For devices on spi1 or spi2, the interfaces should be enabled
         with one of the spi1-1/2/3cs and/or spi2-1/2/3cs overlays.
         The overlay expects to disable the relevant spidev node, so also using
         e.g. cs0_spidev=off is unnecessary.
 
-        Note:   with the 5.7 kernel (and later) there will also be
-                overlays for MAX31855E, MAX31855J, MAX31855K,
-                MAX31885N, MAX31855R, MAX31855S and MAX31855T.
-
         Example:
         MAX31855 on /dev/spidev0.0
             dtoverlay=maxtherm,spi0-0,max31855
+        MAX31856 using a type J thermocouple on /dev/spidev2.1
+            dtoverlay=spi2-2cs
+            dtoverlay=maxtherm,spi2-1,max31856,type_j
 
 Load:   dtoverlay=maxtherm,<param>=<val>
 Params: spi<n>-<m>              Configure device at spi<n>, cs<m>
@@ -1693,6 +1692,15 @@ Params: spi<n>-<m>              Configur
         max31855r               Enable support for the MAX31855R
         max31855s               Enable support for the MAX31855S
         max31855t               Enable support for the MAX31855T
+        max31856                Enable support for the MAX31856 (with type K)
+        type_b                  Select a type B sensor for max31856
+        type_e                  Select a type E sensor for max31856
+        type_j                  Select a type J sensor for max31856
+        type_k                  Select a type K sensor for max31856
+        type_n                  Select a type N sensor for max31856
+        type_r                  Select a type R sensor for max31856
+        type_s                  Select a type S sensor for max31856
+        type_t                  Select a type T sensor for max31856
 
 
 Name:   mbed-dac
--- a/arch/arm/boot/dts/overlays/maxtherm-overlay.dts
+++ b/arch/arm/boot/dts/overlays/maxtherm-overlay.dts
@@ -5,6 +5,8 @@
 /dts-v1/;
 /plugin/;
 
+#include <dt-bindings/iio/temperature/thermocouple.h>
+
 / {
 	compatible = "brcm,bcm2835";
 
@@ -128,6 +130,15 @@
 		};
 	};
 
+	fragment@16 {
+		target = <&max>;
+		__dormant__ {
+			compatible = "maxim,max31856";
+			spi-cpha;
+			thermocouple-type = <THERMOCOUPLE_TYPE_K>;
+		};
+	};
+
 	__overrides__ {
 		spi0-0 = <0>, "+0",
 			 <&maxfrag>,"target:0=",<&spi0>,
@@ -162,5 +173,14 @@
 		max31855r = <0>,"+13";
 		max31855s = <0>,"+14";
 		max31855t = <0>,"+15";
+		max31856  = <0>,"+16";
+		type_b    = <&max>,"thermocouple-type:0=",<THERMOCOUPLE_TYPE_B>;
+		type_e    = <&max>,"thermocouple-type:0=",<THERMOCOUPLE_TYPE_E>;
+		type_j    = <&max>,"thermocouple-type:0=",<THERMOCOUPLE_TYPE_J>;
+		type_k    = <&max>,"thermocouple-type:0=",<THERMOCOUPLE_TYPE_K>;
+		type_n    = <&max>,"thermocouple-type:0=",<THERMOCOUPLE_TYPE_N>;
+		type_r    = <&max>,"thermocouple-type:0=",<THERMOCOUPLE_TYPE_R>;
+		type_s    = <&max>,"thermocouple-type:0=",<THERMOCOUPLE_TYPE_S>;
+		type_t    = <&max>,"thermocouple-type:0=",<THERMOCOUPLE_TYPE_T>;
 	};
 };
