Skip to content

Commit d7f6a74

Browse files
andreamerellojic23
authored andcommitted
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 <[email protected]> Cc: Lars-Peter Clausen <[email protected]> Cc: Peter Meerwald-Stadler <[email protected]> Cc: Colin Ian King <[email protected]> Cc: Patrick Havelange <[email protected]> Cc: Matt Weber <[email protected]> Cc: Matt Ranostay <[email protected]> Cc: Chuhong Yuan <[email protected]> Cc: Daniel Gomez <[email protected]> Cc: [email protected] Cc: Rob Herring <[email protected]> Cc: Mark Rutland <[email protected]> Cc: [email protected] Signed-off-by: Andrea Merello <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent ea41030 commit d7f6a74

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

drivers/iio/temperature/maxim_thermocouple.c

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/of_device.h>
1515
#include <linux/spi/spi.h>
1616
#include <linux/iio/iio.h>
17+
#include <linux/iio/sysfs.h>
1718
#include <linux/iio/trigger.h>
1819
#include <linux/iio/buffer.h>
1920
#include <linux/iio/triggered_buffer.h>
@@ -24,13 +25,25 @@
2425
enum {
2526
MAX6675,
2627
MAX31855,
28+
MAX31855K,
29+
MAX31855J,
30+
MAX31855N,
31+
MAX31855S,
32+
MAX31855T,
33+
MAX31855E,
34+
MAX31855R,
35+
};
36+
37+
static const char maxim_tc_types[] = {
38+
'K', '?', 'K', 'J', 'N', 'S', 'T', 'E', 'R'
2739
};
2840

2941
static const struct iio_chan_spec max6675_channels[] = {
3042
{ /* thermocouple temperature */
3143
.type = IIO_TEMP,
3244
.info_mask_separate =
33-
BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
45+
BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) |
46+
BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE),
3447
.scan_index = 0,
3548
.scan_type = {
3649
.sign = 's',
@@ -48,7 +61,8 @@ static const struct iio_chan_spec max31855_channels[] = {
4861
.type = IIO_TEMP,
4962
.address = 2,
5063
.info_mask_separate =
51-
BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
64+
BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) |
65+
BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE),
5266
.scan_index = 0,
5367
.scan_type = {
5468
.sign = 's',
@@ -110,6 +124,7 @@ struct maxim_thermocouple_data {
110124
const struct maxim_thermocouple_chip *chip;
111125

112126
u8 buffer[16] ____cacheline_aligned;
127+
char tc_type;
113128
};
114129

115130
static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
@@ -196,6 +211,10 @@ static int maxim_thermocouple_read_raw(struct iio_dev *indio_dev,
196211
ret = IIO_VAL_INT;
197212
}
198213
break;
214+
case IIO_CHAN_INFO_THERMOCOUPLE_TYPE:
215+
*val = data->tc_type;
216+
ret = IIO_VAL_CHAR;
217+
break;
199218
}
200219

201220
return ret;
@@ -210,8 +229,9 @@ static int maxim_thermocouple_probe(struct spi_device *spi)
210229
const struct spi_device_id *id = spi_get_device_id(spi);
211230
struct iio_dev *indio_dev;
212231
struct maxim_thermocouple_data *data;
232+
const int chip_type = (id->driver_data == MAX6675) ? MAX6675 : MAX31855;
213233
const struct maxim_thermocouple_chip *chip =
214-
&maxim_thermocouple_chips[id->driver_data];
234+
&maxim_thermocouple_chips[chip_type];
215235
int ret;
216236

217237
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
@@ -229,26 +249,44 @@ static int maxim_thermocouple_probe(struct spi_device *spi)
229249
data = iio_priv(indio_dev);
230250
data->spi = spi;
231251
data->chip = chip;
252+
data->tc_type = maxim_tc_types[id->driver_data];
232253

233254
ret = devm_iio_triggered_buffer_setup(&spi->dev,
234255
indio_dev, NULL,
235256
maxim_thermocouple_trigger_handler, NULL);
236257
if (ret)
237258
return ret;
238259

260+
if (id->driver_data == MAX31855)
261+
dev_warn(&spi->dev, "generic max31855 ID is deprecated\nplease use more specific part type");
262+
239263
return devm_iio_device_register(&spi->dev, indio_dev);
240264
}
241265

242266
static const struct spi_device_id maxim_thermocouple_id[] = {
243267
{"max6675", MAX6675},
244268
{"max31855", MAX31855},
269+
{"max31855k", MAX31855K},
270+
{"max31855j", MAX31855J},
271+
{"max31855n", MAX31855N},
272+
{"max31855s", MAX31855S},
273+
{"max31855t", MAX31855T},
274+
{"max31855e", MAX31855E},
275+
{"max31855r", MAX31855R},
245276
{},
246277
};
247278
MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id);
248279

249280
static const struct of_device_id maxim_thermocouple_of_match[] = {
250281
{ .compatible = "maxim,max6675" },
251282
{ .compatible = "maxim,max31855" },
283+
{ .compatible = "maxim,max31855k" },
284+
{ .compatible = "maxim,max31855j" },
285+
{ .compatible = "maxim,max31855n" },
286+
{ .compatible = "maxim,max31855s" },
287+
{ .compatible = "maxim,max31855t" },
288+
{ .compatible = "maxim,max31855e" },
289+
{ .compatible = "maxim,max31855r" },
252290
{ },
253291
};
254292
MODULE_DEVICE_TABLE(of, maxim_thermocouple_of_match);

0 commit comments

Comments
 (0)