* [v2 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute [not found] ` <20191111153517.13862-1-andrea.merello@gmail.com> @ 2019-11-11 15:35 ` Andrea Merello 2019-11-16 14:51 ` Jonathan Cameron 2019-11-11 15:35 ` [v2 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings Andrea Merello [not found] ` <20191120144756.28424-1-andrea.merello@gmail.com> 2 siblings, 1 reply; 8+ messages in thread From: Andrea Merello @ 2019-11-11 15:35 UTC (permalink / raw) To: jic23 Cc: Andrea Merello, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler, Colin Ian King, Patrick Havelange, Paresh Chaudhary, Matt Weber, Matt Ranostay, Chuhong Yuan, Daniel Gomez, linux-iio, Rob Herring, Mark Rutland, devicetree 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: Paresh Chaudhary <paresh.chaudhary@rockwellcollins.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> --- drivers/iio/temperature/maxim_thermocouple.c | 45 ++++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c index d1360605209c..6fa5ae9fb4ec 100644 --- a/drivers/iio/temperature/maxim_thermocouple.c +++ b/drivers/iio/temperature/maxim_thermocouple.c @@ -14,6 +14,7 @@ #include <linux/of_device.h> #include <linux/spi/spi.h> #include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> #include <linux/iio/trigger.h> #include <linux/iio/buffer.h> #include <linux/iio/triggered_buffer.h> @@ -24,13 +25,25 @@ enum { MAX6675, MAX31855, + MAX31855K, + MAX31855J, + MAX31855N, + MAX31855S, + MAX31855T, + MAX31855E, + MAX31855R, +}; + +const char maxim_tc_types[] = { + 'K', '?', 'K', 'J', 'N', 'S', 'T', 'E', 'R' }; static const struct iio_chan_spec max6675_channels[] = { { /* thermocouple temperature */ .type = IIO_TEMP, .info_mask_separate = - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), .scan_index = 0, .scan_type = { .sign = 's', @@ -48,7 +61,8 @@ static const struct iio_chan_spec max31855_channels[] = { .type = IIO_TEMP, .address = 2, .info_mask_separate = - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), .scan_index = 0, .scan_type = { .sign = 's', @@ -110,6 +124,7 @@ struct maxim_thermocouple_data { const struct maxim_thermocouple_chip *chip; u8 buffer[16] ____cacheline_aligned; + char tc_type; }; static int maxim_thermocouple_read(struct maxim_thermocouple_data *data, @@ -196,8 +211,11 @@ static int maxim_thermocouple_read_raw(struct iio_dev *indio_dev, ret = IIO_VAL_INT; } break; + case IIO_CHAN_INFO_THERMOCOUPLE_TYPE: + *val = data->tc_type; + ret = IIO_VAL_CHAR; + break; } - return ret; } @@ -210,8 +228,9 @@ static int maxim_thermocouple_probe(struct spi_device *spi) const struct spi_device_id *id = spi_get_device_id(spi); struct iio_dev *indio_dev; struct maxim_thermocouple_data *data; + const int chip_type = (id->driver_data == MAX6675) ? MAX6675 : MAX31855; const struct maxim_thermocouple_chip *chip = - &maxim_thermocouple_chips[id->driver_data]; + &maxim_thermocouple_chips[chip_type]; int ret; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); @@ -229,6 +248,7 @@ static int maxim_thermocouple_probe(struct spi_device *spi) data = iio_priv(indio_dev); data->spi = spi; data->chip = chip; + data->tc_type = maxim_tc_types[id->driver_data]; ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, @@ -236,12 +256,22 @@ static int maxim_thermocouple_probe(struct spi_device *spi) if (ret) return ret; + if (id->driver_data == MAX31855) + dev_warn(&spi->dev, "generic max31855 ID is deprecated\nplease use more specific part type"); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id maxim_thermocouple_id[] = { {"max6675", MAX6675}, {"max31855", MAX31855}, + {"max31855k", MAX31855K}, + {"max31855j", MAX31855J}, + {"max31855n", MAX31855N}, + {"max31855s", MAX31855S}, + {"max31855t", MAX31855T}, + {"max31855e", MAX31855E}, + {"max31855r", MAX31855R}, {}, }; MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); @@ -249,6 +279,13 @@ MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); static const struct of_device_id maxim_thermocouple_of_match[] = { { .compatible = "maxim,max6675" }, { .compatible = "maxim,max31855" }, + { .compatible = "maxim,max31855k" }, + { .compatible = "maxim,max31855j" }, + { .compatible = "maxim,max31855n" }, + { .compatible = "maxim,max31855s" }, + { .compatible = "maxim,max31855t" }, + { .compatible = "maxim,max31855e" }, + { .compatible = "maxim,max31855r" }, { }, }; MODULE_DEVICE_TABLE(of, maxim_thermocouple_of_match); -- 2.17.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [v2 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute 2019-11-11 15:35 ` [v2 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute Andrea Merello @ 2019-11-16 14:51 ` Jonathan Cameron 0 siblings, 0 replies; 8+ messages in thread From: Jonathan Cameron @ 2019-11-16 14:51 UTC (permalink / raw) To: Andrea Merello Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler, Colin Ian King, Patrick Havelange, Paresh Chaudhary, Matt Weber, Matt Ranostay, Chuhong Yuan, Daniel Gomez, linux-iio, Rob Herring, Mark Rutland, devicetree On Mon, 11 Nov 2019 16:35:16 +0100 Andrea Merello <andrea.merello@gmail.com> wrote: > 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. Trivial comment inline. Thanks, J > > 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: Paresh Chaudhary <paresh.chaudhary@rockwellcollins.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> > --- > drivers/iio/temperature/maxim_thermocouple.c | 45 ++++++++++++++++++-- > 1 file changed, 41 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c > index d1360605209c..6fa5ae9fb4ec 100644 > --- a/drivers/iio/temperature/maxim_thermocouple.c > +++ b/drivers/iio/temperature/maxim_thermocouple.c > @@ -14,6 +14,7 @@ > #include <linux/of_device.h> > #include <linux/spi/spi.h> > #include <linux/iio/iio.h> > +#include <linux/iio/sysfs.h> > #include <linux/iio/trigger.h> > #include <linux/iio/buffer.h> > #include <linux/iio/triggered_buffer.h> > @@ -24,13 +25,25 @@ > enum { > MAX6675, > MAX31855, > + MAX31855K, > + MAX31855J, > + MAX31855N, > + MAX31855S, > + MAX31855T, > + MAX31855E, > + MAX31855R, > +}; > + > +const char maxim_tc_types[] = { > + 'K', '?', 'K', 'J', 'N', 'S', 'T', 'E', 'R' > }; > > static const struct iio_chan_spec max6675_channels[] = { > { /* thermocouple temperature */ > .type = IIO_TEMP, > .info_mask_separate = > - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), > + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | > + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), > .scan_index = 0, > .scan_type = { > .sign = 's', > @@ -48,7 +61,8 @@ static const struct iio_chan_spec max31855_channels[] = { > .type = IIO_TEMP, > .address = 2, > .info_mask_separate = > - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), > + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | > + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), > .scan_index = 0, > .scan_type = { > .sign = 's', > @@ -110,6 +124,7 @@ struct maxim_thermocouple_data { > const struct maxim_thermocouple_chip *chip; > > u8 buffer[16] ____cacheline_aligned; > + char tc_type; > }; > > static int maxim_thermocouple_read(struct maxim_thermocouple_data *data, > @@ -196,8 +211,11 @@ static int maxim_thermocouple_read_raw(struct iio_dev *indio_dev, > ret = IIO_VAL_INT; > } > break; > + case IIO_CHAN_INFO_THERMOCOUPLE_TYPE: > + *val = data->tc_type; > + ret = IIO_VAL_CHAR; > + break; > } > - Another stray whitespace change. > return ret; > } > > @@ -210,8 +228,9 @@ static int maxim_thermocouple_probe(struct spi_device *spi) > const struct spi_device_id *id = spi_get_device_id(spi); > struct iio_dev *indio_dev; > struct maxim_thermocouple_data *data; > + const int chip_type = (id->driver_data == MAX6675) ? MAX6675 : MAX31855; > const struct maxim_thermocouple_chip *chip = > - &maxim_thermocouple_chips[id->driver_data]; > + &maxim_thermocouple_chips[chip_type]; > int ret; > > indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); > @@ -229,6 +248,7 @@ static int maxim_thermocouple_probe(struct spi_device *spi) > data = iio_priv(indio_dev); > data->spi = spi; > data->chip = chip; > + data->tc_type = maxim_tc_types[id->driver_data]; > > ret = devm_iio_triggered_buffer_setup(&spi->dev, > indio_dev, NULL, > @@ -236,12 +256,22 @@ static int maxim_thermocouple_probe(struct spi_device *spi) > if (ret) > return ret; > > + if (id->driver_data == MAX31855) > + dev_warn(&spi->dev, "generic max31855 ID is deprecated\nplease use more specific part type"); > + > return devm_iio_device_register(&spi->dev, indio_dev); > } > > static const struct spi_device_id maxim_thermocouple_id[] = { > {"max6675", MAX6675}, > {"max31855", MAX31855}, > + {"max31855k", MAX31855K}, > + {"max31855j", MAX31855J}, > + {"max31855n", MAX31855N}, > + {"max31855s", MAX31855S}, > + {"max31855t", MAX31855T}, > + {"max31855e", MAX31855E}, > + {"max31855r", MAX31855R}, > {}, > }; > MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); > @@ -249,6 +279,13 @@ MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); > static const struct of_device_id maxim_thermocouple_of_match[] = { > { .compatible = "maxim,max6675" }, > { .compatible = "maxim,max31855" }, > + { .compatible = "maxim,max31855k" }, > + { .compatible = "maxim,max31855j" }, > + { .compatible = "maxim,max31855n" }, > + { .compatible = "maxim,max31855s" }, > + { .compatible = "maxim,max31855t" }, > + { .compatible = "maxim,max31855e" }, > + { .compatible = "maxim,max31855r" }, > { }, > }; > MODULE_DEVICE_TABLE(of, maxim_thermocouple_of_match); ^ permalink raw reply [flat|nested] 8+ messages in thread
* [v2 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings [not found] ` <20191111153517.13862-1-andrea.merello@gmail.com> 2019-11-11 15:35 ` [v2 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute Andrea Merello @ 2019-11-11 15:35 ` Andrea Merello 2019-11-14 22:12 ` Rob Herring [not found] ` <20191120144756.28424-1-andrea.merello@gmail.com> 2 siblings, 1 reply; 8+ messages in thread From: Andrea Merello @ 2019-11-11 15:35 UTC (permalink / raw) To: jic23 Cc: Andrea Merello, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler, Colin Ian King, Patrick Havelange, Paresh Chaudhary, Matt Weber, Matt Ranostay, Chuhong Yuan, Daniel Gomez, linux-iio, Rob Herring, Mark Rutland, devicetree Now the maxim_thermocouple has new, more specific, 'compatible' strings for better distinguish the various supported chips. This patch updates the DT bindings documentation accordingly 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: Paresh Chaudhary <paresh.chaudhary@rockwellcollins.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> --- .../bindings/iio/temperature/maxim_thermocouple.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt b/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt index 28bc5c4d965b..bb85cd0e039c 100644 --- a/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt +++ b/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt @@ -5,7 +5,10 @@ Maxim thermocouple support Required properties: - - compatible: must be "maxim,max31855" or "maxim,max6675" + - compatible: must be "maxim,max6675" or one of the following: + "maxim,max31855k", "maxim,max31855j", "maxim,max31855n", + "maxim,max31855s", "maxim,max31855t", "maxim,max31855e", + "maxim,max31855r"; the generic "max,max31855" is deprecated. - 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 @@ -15,7 +18,7 @@ Required properties: Example: max31855@0 { - compatible = "maxim,max31855"; + compatible = "maxim,max31855k"; reg = <0>; spi-max-frequency = <4300000>; }; -- 2.17.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [v2 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings 2019-11-11 15:35 ` [v2 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings Andrea Merello @ 2019-11-14 22:12 ` Rob Herring 0 siblings, 0 replies; 8+ messages in thread From: Rob Herring @ 2019-11-14 22:12 UTC (permalink / raw) To: Andrea Merello Cc: jic23, Andrea Merello, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler, Colin Ian King, Patrick Havelange, Paresh Chaudhary, Matt Weber, Matt Ranostay, Chuhong Yuan, Daniel Gomez, linux-iio, Mark Rutland, devicetree On Mon, 11 Nov 2019 16:35:17 +0100, Andrea Merello wrote: > Now the maxim_thermocouple has new, more specific, 'compatible' strings for > better distinguish the various supported chips. > > This patch updates the DT bindings documentation accordingly > > 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: Paresh Chaudhary <paresh.chaudhary@rockwellcollins.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> > --- > .../bindings/iio/temperature/maxim_thermocouple.txt | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > Acked-by: Rob Herring <robh@kernel.org> ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <20191120144756.28424-1-andrea.merello@gmail.com>]
* [v3 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute [not found] ` <20191120144756.28424-1-andrea.merello@gmail.com> @ 2019-11-20 14:47 ` Andrea Merello 2019-11-23 12:46 ` Jonathan Cameron 2019-11-20 14:47 ` [v3 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings Andrea Merello 1 sibling, 1 reply; 8+ messages in thread From: Andrea Merello @ 2019-11-20 14:47 UTC (permalink / raw) To: jic23 Cc: Andrea Merello, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler, Colin Ian King, Patrick Havelange, Matt Weber, Matt Ranostay, Chuhong Yuan, Daniel Gomez, linux-iio, Rob Herring, Mark Rutland, devicetree 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> --- drivers/iio/temperature/maxim_thermocouple.c | 44 ++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c index d1360605209c..9906b31fe863 100644 --- a/drivers/iio/temperature/maxim_thermocouple.c +++ b/drivers/iio/temperature/maxim_thermocouple.c @@ -14,6 +14,7 @@ #include <linux/of_device.h> #include <linux/spi/spi.h> #include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> #include <linux/iio/trigger.h> #include <linux/iio/buffer.h> #include <linux/iio/triggered_buffer.h> @@ -24,13 +25,25 @@ enum { MAX6675, MAX31855, + MAX31855K, + MAX31855J, + MAX31855N, + MAX31855S, + MAX31855T, + MAX31855E, + MAX31855R, +}; + +const char maxim_tc_types[] = { + 'K', '?', 'K', 'J', 'N', 'S', 'T', 'E', 'R' }; static const struct iio_chan_spec max6675_channels[] = { { /* thermocouple temperature */ .type = IIO_TEMP, .info_mask_separate = - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), .scan_index = 0, .scan_type = { .sign = 's', @@ -48,7 +61,8 @@ static const struct iio_chan_spec max31855_channels[] = { .type = IIO_TEMP, .address = 2, .info_mask_separate = - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), .scan_index = 0, .scan_type = { .sign = 's', @@ -110,6 +124,7 @@ struct maxim_thermocouple_data { const struct maxim_thermocouple_chip *chip; u8 buffer[16] ____cacheline_aligned; + char tc_type; }; 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, ret = IIO_VAL_INT; } break; + case IIO_CHAN_INFO_THERMOCOUPLE_TYPE: + *val = data->tc_type; + ret = IIO_VAL_CHAR; + break; } return ret; @@ -210,8 +229,9 @@ static int maxim_thermocouple_probe(struct spi_device *spi) const struct spi_device_id *id = spi_get_device_id(spi); struct iio_dev *indio_dev; struct maxim_thermocouple_data *data; + const int chip_type = (id->driver_data == MAX6675) ? MAX6675 : MAX31855; const struct maxim_thermocouple_chip *chip = - &maxim_thermocouple_chips[id->driver_data]; + &maxim_thermocouple_chips[chip_type]; int ret; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); @@ -229,6 +249,7 @@ static int maxim_thermocouple_probe(struct spi_device *spi) data = iio_priv(indio_dev); data->spi = spi; data->chip = chip; + data->tc_type = maxim_tc_types[id->driver_data]; ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, @@ -236,12 +257,22 @@ static int maxim_thermocouple_probe(struct spi_device *spi) if (ret) return ret; + if (id->driver_data == MAX31855) + dev_warn(&spi->dev, "generic max31855 ID is deprecated\nplease use more specific part type"); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id maxim_thermocouple_id[] = { {"max6675", MAX6675}, {"max31855", MAX31855}, + {"max31855k", MAX31855K}, + {"max31855j", MAX31855J}, + {"max31855n", MAX31855N}, + {"max31855s", MAX31855S}, + {"max31855t", MAX31855T}, + {"max31855e", MAX31855E}, + {"max31855r", MAX31855R}, {}, }; MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); @@ -249,6 +280,13 @@ MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); static const struct of_device_id maxim_thermocouple_of_match[] = { { .compatible = "maxim,max6675" }, { .compatible = "maxim,max31855" }, + { .compatible = "maxim,max31855k" }, + { .compatible = "maxim,max31855j" }, + { .compatible = "maxim,max31855n" }, + { .compatible = "maxim,max31855s" }, + { .compatible = "maxim,max31855t" }, + { .compatible = "maxim,max31855e" }, + { .compatible = "maxim,max31855r" }, { }, }; MODULE_DEVICE_TABLE(of, maxim_thermocouple_of_match); -- 2.17.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [v3 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute 2019-11-20 14:47 ` [v3 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute Andrea Merello @ 2019-11-23 12:46 ` Jonathan Cameron 0 siblings, 0 replies; 8+ messages in thread From: Jonathan Cameron @ 2019-11-23 12:46 UTC (permalink / raw) To: Andrea Merello Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler, Colin Ian King, Patrick Havelange, Matt Weber, Matt Ranostay, Chuhong Yuan, Daniel Gomez, linux-iio, Rob Herring, Mark Rutland, devicetree On Wed, 20 Nov 2019 15:47:55 +0100 Andrea Merello <andrea.merello@gmail.com> wrote: > 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. I'm going to gamble on this as seems fairly obviously correct plus your DT spoofing tests should have tested the new code. Obviously actual tests appreciated if anyone with hardware has time. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > > 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> > --- > drivers/iio/temperature/maxim_thermocouple.c | 44 ++++++++++++++++++-- > 1 file changed, 41 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c > index d1360605209c..9906b31fe863 100644 > --- a/drivers/iio/temperature/maxim_thermocouple.c > +++ b/drivers/iio/temperature/maxim_thermocouple.c > @@ -14,6 +14,7 @@ > #include <linux/of_device.h> > #include <linux/spi/spi.h> > #include <linux/iio/iio.h> > +#include <linux/iio/sysfs.h> > #include <linux/iio/trigger.h> > #include <linux/iio/buffer.h> > #include <linux/iio/triggered_buffer.h> > @@ -24,13 +25,25 @@ > enum { > MAX6675, > MAX31855, > + MAX31855K, > + MAX31855J, > + MAX31855N, > + MAX31855S, > + MAX31855T, > + MAX31855E, > + MAX31855R, > +}; > + > +const char maxim_tc_types[] = { > + 'K', '?', 'K', 'J', 'N', 'S', 'T', 'E', 'R' > }; > > static const struct iio_chan_spec max6675_channels[] = { > { /* thermocouple temperature */ > .type = IIO_TEMP, > .info_mask_separate = > - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), > + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | > + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), > .scan_index = 0, > .scan_type = { > .sign = 's', > @@ -48,7 +61,8 @@ static const struct iio_chan_spec max31855_channels[] = { > .type = IIO_TEMP, > .address = 2, > .info_mask_separate = > - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), > + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | > + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), > .scan_index = 0, > .scan_type = { > .sign = 's', > @@ -110,6 +124,7 @@ struct maxim_thermocouple_data { > const struct maxim_thermocouple_chip *chip; > > u8 buffer[16] ____cacheline_aligned; > + char tc_type; > }; > > 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, > ret = IIO_VAL_INT; > } > break; > + case IIO_CHAN_INFO_THERMOCOUPLE_TYPE: > + *val = data->tc_type; > + ret = IIO_VAL_CHAR; > + break; > } > > return ret; > @@ -210,8 +229,9 @@ static int maxim_thermocouple_probe(struct spi_device *spi) > const struct spi_device_id *id = spi_get_device_id(spi); > struct iio_dev *indio_dev; > struct maxim_thermocouple_data *data; > + const int chip_type = (id->driver_data == MAX6675) ? MAX6675 : MAX31855; > const struct maxim_thermocouple_chip *chip = > - &maxim_thermocouple_chips[id->driver_data]; > + &maxim_thermocouple_chips[chip_type]; > int ret; > > indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); > @@ -229,6 +249,7 @@ static int maxim_thermocouple_probe(struct spi_device *spi) > data = iio_priv(indio_dev); > data->spi = spi; > data->chip = chip; > + data->tc_type = maxim_tc_types[id->driver_data]; > > ret = devm_iio_triggered_buffer_setup(&spi->dev, > indio_dev, NULL, > @@ -236,12 +257,22 @@ static int maxim_thermocouple_probe(struct spi_device *spi) > if (ret) > return ret; > > + if (id->driver_data == MAX31855) > + dev_warn(&spi->dev, "generic max31855 ID is deprecated\nplease use more specific part type"); > + > return devm_iio_device_register(&spi->dev, indio_dev); > } > > static const struct spi_device_id maxim_thermocouple_id[] = { > {"max6675", MAX6675}, > {"max31855", MAX31855}, > + {"max31855k", MAX31855K}, > + {"max31855j", MAX31855J}, > + {"max31855n", MAX31855N}, > + {"max31855s", MAX31855S}, > + {"max31855t", MAX31855T}, > + {"max31855e", MAX31855E}, > + {"max31855r", MAX31855R}, > {}, > }; > MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); > @@ -249,6 +280,13 @@ MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); > static const struct of_device_id maxim_thermocouple_of_match[] = { > { .compatible = "maxim,max6675" }, > { .compatible = "maxim,max31855" }, > + { .compatible = "maxim,max31855k" }, > + { .compatible = "maxim,max31855j" }, > + { .compatible = "maxim,max31855n" }, > + { .compatible = "maxim,max31855s" }, > + { .compatible = "maxim,max31855t" }, > + { .compatible = "maxim,max31855e" }, > + { .compatible = "maxim,max31855r" }, > { }, > }; > MODULE_DEVICE_TABLE(of, maxim_thermocouple_of_match); ^ permalink raw reply [flat|nested] 8+ messages in thread
* [v3 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings [not found] ` <20191120144756.28424-1-andrea.merello@gmail.com> 2019-11-20 14:47 ` [v3 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute Andrea Merello @ 2019-11-20 14:47 ` Andrea Merello 2019-11-23 12:46 ` Jonathan Cameron 1 sibling, 1 reply; 8+ messages in thread From: Andrea Merello @ 2019-11-20 14:47 UTC (permalink / raw) To: jic23 Cc: Andrea Merello, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler, Colin Ian King, Patrick Havelange, Matt Weber, Matt Ranostay, Chuhong Yuan, Daniel Gomez, linux-iio, Rob Herring, Mark Rutland, devicetree Now the maxim_thermocouple has new, more specific, 'compatible' strings for better distinguish the various supported chips. This patch updates the DT bindings documentation accordingly 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> Acked-by: Rob Herring <robh@kernel.org> --- .../bindings/iio/temperature/maxim_thermocouple.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt b/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt index 28bc5c4d965b..bb85cd0e039c 100644 --- a/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt +++ b/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt @@ -5,7 +5,10 @@ Maxim thermocouple support Required properties: - - compatible: must be "maxim,max31855" or "maxim,max6675" + - compatible: must be "maxim,max6675" or one of the following: + "maxim,max31855k", "maxim,max31855j", "maxim,max31855n", + "maxim,max31855s", "maxim,max31855t", "maxim,max31855e", + "maxim,max31855r"; the generic "max,max31855" is deprecated. - 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 @@ -15,7 +18,7 @@ Required properties: Example: max31855@0 { - compatible = "maxim,max31855"; + compatible = "maxim,max31855k"; reg = <0>; spi-max-frequency = <4300000>; }; -- 2.17.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [v3 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings 2019-11-20 14:47 ` [v3 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings Andrea Merello @ 2019-11-23 12:46 ` Jonathan Cameron 0 siblings, 0 replies; 8+ messages in thread From: Jonathan Cameron @ 2019-11-23 12:46 UTC (permalink / raw) To: Andrea Merello Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler, Colin Ian King, Patrick Havelange, Matt Weber, Matt Ranostay, Chuhong Yuan, Daniel Gomez, linux-iio, Rob Herring, Mark Rutland, devicetree On Wed, 20 Nov 2019 15:47:56 +0100 Andrea Merello <andrea.merello@gmail.com> wrote: > Now the maxim_thermocouple has new, more specific, 'compatible' strings for > better distinguish the various supported chips. > > This patch updates the DT bindings documentation accordingly > > 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> > Acked-by: Rob Herring <robh@kernel.org> Applied, Thanks, Jonathan > --- > .../bindings/iio/temperature/maxim_thermocouple.txt | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt b/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt > index 28bc5c4d965b..bb85cd0e039c 100644 > --- a/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt > +++ b/Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt > @@ -5,7 +5,10 @@ Maxim thermocouple support > > Required properties: > > - - compatible: must be "maxim,max31855" or "maxim,max6675" > + - compatible: must be "maxim,max6675" or one of the following: > + "maxim,max31855k", "maxim,max31855j", "maxim,max31855n", > + "maxim,max31855s", "maxim,max31855t", "maxim,max31855e", > + "maxim,max31855r"; the generic "max,max31855" is deprecated. > - 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 > @@ -15,7 +18,7 @@ Required properties: > Example: > > max31855@0 { > - compatible = "maxim,max31855"; > + compatible = "maxim,max31855k"; > reg = <0>; > spi-max-frequency = <4300000>; > }; ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-11-23 12:47 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <20190923121714.13672-1-andrea.merello@gmail.com> [not found] ` <20191111153517.13862-1-andrea.merello@gmail.com> 2019-11-11 15:35 ` [v2 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute Andrea Merello 2019-11-16 14:51 ` Jonathan Cameron 2019-11-11 15:35 ` [v2 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings Andrea Merello 2019-11-14 22:12 ` Rob Herring [not found] ` <20191120144756.28424-1-andrea.merello@gmail.com> 2019-11-20 14:47 ` [v3 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute Andrea Merello 2019-11-23 12:46 ` Jonathan Cameron 2019-11-20 14:47 ` [v3 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings Andrea Merello 2019-11-23 12:46 ` Jonathan Cameron
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).