Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: maxim_thermocouple: add thermocouple_type sysfs attribute

We added a sysfs ABI for getting/setting the type of a thermocouple. This
driver supports chips that support specific fixed thermocouple types; we
cannot set it, but still we can add this sysfs attribute in RO mode to
read-back the thermocouple type.

This driver supports actually several chips:
- max6675
- max31855[k/j/n/s/t/e/r]asa family

Max6675 supports only K-type thermocouples, so we can just report that.

Each chip in max31855 family supports just one specific thermocouple type
(in the obvious way: i.e. max31855jasa supports J-type). This driver did
accept a generic SPI ID and OF compatible "max31855" which does not give
any clue about which chip is really involved (and unfortunately it seems
we have no way to detect it).

This patch introduces a new set of, more specific, SPI IDs and OF
compatible strings to better match the chip type.

The old, generic, "max31855" binding is kept for compatibility reasons, but
this patch aims to deprecate it, so, should we hit it, a warning is spit.
In such case the reported thermocouple type in sysfs is '?', because we
have no way to know.

Regarding the implementation: the thermocouple type information is stored
in the driver private data and I've kept only two maxim_thermocouple_chip
types in order to avoid a lot of duplications (seven chip types with just
a different thermocouple type).

RFT because I have no real HW to test this.

Cc: Hartmut Knaack <knaack.h@gmx.de>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: Colin Ian King <colin.king@canonical.com>
Cc: Patrick Havelange <patrick.havelange@essensium.com>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Matt Ranostay <matt.ranostay@konsulko.com>
Cc: Chuhong Yuan <hslester96@gmail.com>
Cc: Daniel Gomez <dagmcr@gmail.com>
Cc: linux-iio@vger.kernel.org
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: devicetree@vger.kernel.org
Signed-off-by: Andrea Merello <andrea.merello@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andrea Merello and committed by
Jonathan Cameron
d7f6a749 ea410307

+41 -3
+41 -3
drivers/iio/temperature/maxim_thermocouple.c
··· 14 14 #include <linux/of_device.h> 15 15 #include <linux/spi/spi.h> 16 16 #include <linux/iio/iio.h> 17 + #include <linux/iio/sysfs.h> 17 18 #include <linux/iio/trigger.h> 18 19 #include <linux/iio/buffer.h> 19 20 #include <linux/iio/triggered_buffer.h> ··· 25 24 enum { 26 25 MAX6675, 27 26 MAX31855, 27 + MAX31855K, 28 + MAX31855J, 29 + MAX31855N, 30 + MAX31855S, 31 + MAX31855T, 32 + MAX31855E, 33 + MAX31855R, 34 + }; 35 + 36 + static const char maxim_tc_types[] = { 37 + 'K', '?', 'K', 'J', 'N', 'S', 'T', 'E', 'R' 28 38 }; 29 39 30 40 static const struct iio_chan_spec max6675_channels[] = { 31 41 { /* thermocouple temperature */ 32 42 .type = IIO_TEMP, 33 43 .info_mask_separate = 34 - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 44 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | 45 + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), 35 46 .scan_index = 0, 36 47 .scan_type = { 37 48 .sign = 's', ··· 61 48 .type = IIO_TEMP, 62 49 .address = 2, 63 50 .info_mask_separate = 64 - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 51 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | 52 + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), 65 53 .scan_index = 0, 66 54 .scan_type = { 67 55 .sign = 's', ··· 124 110 const struct maxim_thermocouple_chip *chip; 125 111 126 112 u8 buffer[16] ____cacheline_aligned; 113 + char tc_type; 127 114 }; 128 115 129 116 static int maxim_thermocouple_read(struct maxim_thermocouple_data *data, ··· 211 196 ret = IIO_VAL_INT; 212 197 } 213 198 break; 199 + case IIO_CHAN_INFO_THERMOCOUPLE_TYPE: 200 + *val = data->tc_type; 201 + ret = IIO_VAL_CHAR; 202 + break; 214 203 } 215 204 216 205 return ret; ··· 229 210 const struct spi_device_id *id = spi_get_device_id(spi); 230 211 struct iio_dev *indio_dev; 231 212 struct maxim_thermocouple_data *data; 213 + const int chip_type = (id->driver_data == MAX6675) ? MAX6675 : MAX31855; 232 214 const struct maxim_thermocouple_chip *chip = 233 - &maxim_thermocouple_chips[id->driver_data]; 215 + &maxim_thermocouple_chips[chip_type]; 234 216 int ret; 235 217 236 218 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); ··· 249 229 data = iio_priv(indio_dev); 250 230 data->spi = spi; 251 231 data->chip = chip; 232 + data->tc_type = maxim_tc_types[id->driver_data]; 252 233 253 234 ret = devm_iio_triggered_buffer_setup(&spi->dev, 254 235 indio_dev, NULL, ··· 257 236 if (ret) 258 237 return ret; 259 238 239 + if (id->driver_data == MAX31855) 240 + dev_warn(&spi->dev, "generic max31855 ID is deprecated\nplease use more specific part type"); 241 + 260 242 return devm_iio_device_register(&spi->dev, indio_dev); 261 243 } 262 244 263 245 static const struct spi_device_id maxim_thermocouple_id[] = { 264 246 {"max6675", MAX6675}, 265 247 {"max31855", MAX31855}, 248 + {"max31855k", MAX31855K}, 249 + {"max31855j", MAX31855J}, 250 + {"max31855n", MAX31855N}, 251 + {"max31855s", MAX31855S}, 252 + {"max31855t", MAX31855T}, 253 + {"max31855e", MAX31855E}, 254 + {"max31855r", MAX31855R}, 266 255 {}, 267 256 }; 268 257 MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); ··· 280 249 static const struct of_device_id maxim_thermocouple_of_match[] = { 281 250 { .compatible = "maxim,max6675" }, 282 251 { .compatible = "maxim,max31855" }, 252 + { .compatible = "maxim,max31855k" }, 253 + { .compatible = "maxim,max31855j" }, 254 + { .compatible = "maxim,max31855n" }, 255 + { .compatible = "maxim,max31855s" }, 256 + { .compatible = "maxim,max31855t" }, 257 + { .compatible = "maxim,max31855e" }, 258 + { .compatible = "maxim,max31855r" }, 283 259 { }, 284 260 }; 285 261 MODULE_DEVICE_TABLE(of, maxim_thermocouple_of_match);