iio: temperature: add support for Maxim thermocouple chips
Subsystems (2)
PATCH v5 1/1 iio: temperature: add support for Maxim thermocouple chips
Add initial driver support for MAX6675, and MAX31855 thermocouple chips.
---
Changes from v1:
* switch to iio_device_*_direct_mode wrappers
* add const to structs
* removed useless cast
Changes from v2:
* mark buffer data invalid on disconnected thermocouple
* add .address = 0 to be consistent
* add missing scan_mask for the max31855 part
Changes from v3:
* fixed several typos of max31855 part number
Changes from v4:
* drop maxim_thermocouple_validate_buffer() due to peer review saying this is an incorrect way to signal an invalid reading
.../iio/temperature/maxim_thermocouple.txt | 21 ++
drivers/iio/temperature/Kconfig | 14 ++ drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/maxim_thermocouple.c | 279 +++++++++++++++++++++ 4 files changed, 315 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt create mode 100644 drivers/iio/temperature/maxim_thermocouple.c
Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt new file +21 -0
@@ -0,0 +1,21 @@ +Maxim thermocouple support + +* https://datasheets.maximintegrated.com/en/ds/MAX6675.pdf +* https://datasheets.maximintegrated.com/en/ds/MAX31855.pdf + +Required properties: + + - compatible: must be "maxim,max31855" or "maxim,max6675" + - reg: SPI chip select number for the device + - spi-max-frequency: must be 4300000 + - spi-cpha: must be defined for max6675 to enable SPI mode 1 + + Refer to spi/spi-bus.txt for generic SPI slave bindings. + +Example: + + max31855@0 { + compatible = "maxim,max31855"; + reg = <0>; + spi-max-frequency = <4300000>; + };
drivers/iio/temperature/Kconfig +14 -0
@@ -3,6 +3,20 @@ # menu "Temperature sensors" +config MAXIM_THERMOCOUPLE + tristate "Maxim thermocouple sensors" + depends on SPI + help + If you say yes here you get support for the Maxim series of + thermocouple sensors connected via SPI. + + Supported sensors: + * MAX6675 + * MAX31855 + + This driver can also be built as a module. If so, the module will + be called maxim_thermocouple. + config MLX90614 tristate "MLX90614 contact-less infrared sensor" depends on I2C
drivers/iio/temperature/Makefile +1 -0
@@ -2,6 +2,7 @@ # Makefile for industrial I/O temperature drivers # +obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o obj-$(CONFIG_MLX90614) += mlx90614.o obj-$(CONFIG_TMP006) += tmp006.o obj-$(CONFIG_TSYS01) += tsys01.o
drivers/iio/temperature/maxim_thermocouple.c new file +279 -0
279 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 23 lines · Matt Ranostay
Add initial driver support for MAX6675, and MAX31855 thermocouple chips.
Cc Marek Vasut <[email protected]>Cc Matt Porter <[email protected]>Signed-off-by Matt Ranostay <[email protected]>---
Changes from v1:
* switch to iio_device_*_direct_mode wrappers
* add const to structs
* removed useless castChanges from v2:
* mark buffer data invalid on disconnected thermocouple
* add .address = 0 to be consistent
* add missingscan_maskfor the max31855 partChanges from v3:
* fixed several typos of max31855 part numberChanges from v4:
* dropmaxim_thermocouple_validate_buffer()due to peer review saying this is an incorrect way to signal an invalid reading
[...]
Quoted 30 lines
drivers/iio/temperature/maxim_thermocouple.c new file +30
-0+const struct iio_chan_spec max31855_channels[] = { + {/* thermocouple temperature */ + .type =IIO_TEMP , + .address =2 , + .info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_SCALE ), + .scan_index =0 , + .scan_type = { + .sign ='s' , + .realbits =14 , + .storagebits =16 , + .shift =2 , + .endianness =IIO_BE , + }, + }, + {/* cold junction temperature */ + .type =IIO_TEMP , + .address =0 , + .channel2 =IIO_MOD_TEMP_AMBIENT , + .modified =1 , + .info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_SCALE ), + .scan_index =1 , + .scan_type = { + .sign ='s' , + .realbits =12 , + .storagebits =16 , + .shift =4 , + .endianness =IIO_BE , + },
drivers/iio/temperature/maxim_thermocouple.c line 91
Quoted 10 lines
drivers/iio/temperature/maxim_thermocouple.c new file +10
-0+ }, + IIO_CHAN_SOFT_TIMESTAMP(2), +}; + +static const unsigned long max31855_scan_masks[] = {0x3 ,0 }; + +struct maxim_thermocouple_chip { +const struct iio_chan_spec *channels; +const unsigned long *scan_masks; +int num_channels;
const u8 or u32 ?
drivers/iio/temperature/maxim_thermocouple.c line 92
Quoted 1 line
drivers/iio/temperature/maxim_thermocouple.c new file +1
-0+int read_size;
const u8
drivers/iio/temperature/maxim_thermocouple.c line 95
Quoted 2 lines
drivers/iio/temperature/maxim_thermocouple.c new file +2
-0+/* bit-check for valid input */ +int status_bit;
const bool ?
You can save some slop in here, see also:
http://www.catb.org/esr/structure-packing/
Quoted 17 lines
drivers/iio/temperature/maxim_thermocouple.c new file +17
-0+}; + +const struct maxim_thermocouple_chip maxim_thermocouple_chips[] = { + [MAX6675 ] = { + .channels = max6675_channels, + .num_channels =ARRAY_SIZE (max6675_channels), + .read_size =2 , + .status_bit =BIT (2 ), + }, + [MAX31855 ] = { + .channels = max31855_channels, + .num_channels =ARRAY_SIZE (max31855_channels), + .read_size =4 , + .scan_masks = max31855_scan_masks, + .status_bit =BIT (16 ), + }, +};
[...]
Signature · 2 lines
Best regards, Marek Vasut
Quoted 70 lines · Marek Vasut
Quoted 23 lines · Matt Ranostay
Add initial driver support for MAX6675, and MAX31855 thermocouple chips.
Cc Marek Vasut <[email protected]>Cc Matt Porter <[email protected]>Signed-off-by Matt Ranostay <[email protected]>---
Changes from v1:
* switch to iio_device_*_direct_mode wrappers
* add const to structs
* removed useless castChanges from v2:
* mark buffer data invalid on disconnected thermocouple
* add .address = 0 to be consistent
* add missingscan_maskfor the max31855 partChanges from v3:
* fixed several typos of max31855 part numberChanges from v4:
* dropmaxim_thermocouple_validate_buffer()due to peer review saying this is an incorrect way to signal an invalid reading[...]
Quoted 30 lines
drivers/iio/temperature/maxim_thermocouple.c new file +30
-0+const struct iio_chan_spec max31855_channels[] = { + {/* thermocouple temperature */ + .type =IIO_TEMP , + .address =2 , + .info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_SCALE ), + .scan_index =0 , + .scan_type = { + .sign ='s' , + .realbits =14 , + .storagebits =16 , + .shift =2 , + .endianness =IIO_BE , + }, + }, + {/* cold junction temperature */ + .type =IIO_TEMP , + .address =0 , + .channel2 =IIO_MOD_TEMP_AMBIENT , + .modified =1 , + .info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_SCALE ), + .scan_index =1 , + .scan_type = { + .sign ='s' , + .realbits =12 , + .storagebits =16 , + .shift =4 , + .endianness =IIO_BE , + },drivers/iio/temperature/maxim_thermocouple.c line 91
Quoted 10 lines
drivers/iio/temperature/maxim_thermocouple.c new file +10
-0+ }, + IIO_CHAN_SOFT_TIMESTAMP(2), +}; + +static const unsigned long max31855_scan_masks[] = {0x3 ,0 }; + +struct maxim_thermocouple_chip { +const struct iio_chan_spec *channels; +const unsigned long *scan_masks; +int num_channels;const u8 or u32 ?
Quoted 3 lines
Quoted 1 line
+ int
read_size;const u8
Ok not sure saving 2 or 4 bytes of memory really matters that much :).
Quoted 5 lines
drivers/iio/temperature/maxim_thermocouple.c line 95
Quoted 3 lines
drivers/iio/temperature/maxim_thermocouple.c new file +2
-0+/* bit-check for valid input */ +int status_bit;const bool ?
It is a bitmask of a single bit for the validation. I guess it could be const u32
Quoted 26 lines
You can save some slop in here, see also:
http://www.catb.org/esr/structure-packing/Quoted 7 lines
drivers/iio/temperature/maxim_thermocouple.c new file +7
-0+}; + +const struct maxim_thermocouple_chip maxim_thermocouple_chips[] = { + [MAX6675 ] = { + .channels = max6675_channels, + .num_channels =ARRAY_SIZE (max6675_channels), + .read_size =2 ,drivers/iio/temperature/maxim_thermocouple.c line 112
Quoted 10 lines
drivers/iio/temperature/maxim_thermocouple.c new file +10
-0+ .status_bit = BIT(2), + }, + [MAX31855] = { + .channels = max31855_channels, + .num_channels = ARRAY_SIZE(max31855_channels), + .read_size = 4, + .scan_masks = max31855_scan_masks, + .status_bit = BIT(16), + }, +};[...]
--
Best regards,
Marek Vasut
Quoted 71 lines · Matt Ranostay
Quoted 70 lines · Marek Vasut
Quoted 23 lines · Matt Ranostay
Add initial driver support for MAX6675, and MAX31855 thermocouple chips.
Cc Marek Vasut <[email protected]>Cc Matt Porter <[email protected]>Signed-off-by Matt Ranostay <[email protected]>---
Changes from v1:
* switch to iio_device_*_direct_mode wrappers
* add const to structs
* removed useless castChanges from v2:
* mark buffer data invalid on disconnected thermocouple
* add .address = 0 to be consistent
* add missingscan_maskfor the max31855 partChanges from v3:
* fixed several typos of max31855 part numberChanges from v4:
* dropmaxim_thermocouple_validate_buffer()due to peer review saying this is an incorrect way to signal an invalid reading[...]
Quoted 30 lines
drivers/iio/temperature/maxim_thermocouple.c new file +30
-0+const struct iio_chan_spec max31855_channels[] = { + {/* thermocouple temperature */ + .type =IIO_TEMP , + .address =2 , + .info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_SCALE ), + .scan_index =0 , + .scan_type = { + .sign ='s' , + .realbits =14 , + .storagebits =16 , + .shift =2 , + .endianness =IIO_BE , + }, + }, + {/* cold junction temperature */ + .type =IIO_TEMP , + .address =0 , + .channel2 =IIO_MOD_TEMP_AMBIENT , + .modified =1 , + .info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_SCALE ), + .scan_index =1 , + .scan_type = { + .sign ='s' , + .realbits =12 , + .storagebits =16 , + .shift =4 , + .endianness =IIO_BE , + },drivers/iio/temperature/maxim_thermocouple.c line 91
Quoted 10 lines
drivers/iio/temperature/maxim_thermocouple.c new file +10
-0+ }, + IIO_CHAN_SOFT_TIMESTAMP(2), +}; + +static const unsigned long max31855_scan_masks[] = {0x3 ,0 }; + +struct maxim_thermocouple_chip { +const struct iio_chan_spec *channels; +const unsigned long *scan_masks; +int num_channels;const u8 or u32 ?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+ int
read_size;const u8
Ok not sure saving 2 or 4 bytes of memory really matters that much :).
Although I make it part of v6.. since I noticed the buffer isn't cachealigned as well
Quoted 35 lines
Quoted 6 lines
drivers/iio/temperature/maxim_thermocouple.c line 95
Quoted 4 lines
drivers/iio/temperature/maxim_thermocouple.c new file +2
-0+/* bit-check for valid input */ +int status_bit;const bool ?
It is a bitmask of a single bit for the validation. I guess it could be const u32
Quoted 26 lines
You can save some slop in here, see also:
http://www.catb.org/esr/structure-packing/Quoted 7 lines
drivers/iio/temperature/maxim_thermocouple.c new file +7
-0+}; + +const struct maxim_thermocouple_chip maxim_thermocouple_chips[] = { + [MAX6675 ] = { + .channels = max6675_channels, + .num_channels =ARRAY_SIZE (max6675_channels), + .read_size =2 ,drivers/iio/temperature/maxim_thermocouple.c line 112
Quoted 10 lines
drivers/iio/temperature/maxim_thermocouple.c new file +10
-0+ .status_bit = BIT(2), + }, + [MAX31855] = { + .channels = max31855_channels, + .num_channels = ARRAY_SIZE(max31855_channels), + .read_size = 4, + .scan_masks = max31855_scan_masks, + .status_bit = BIT(16), + }, +};[...]
--
Best regards,
Marek Vasut