linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andrea Merello <andrea.merello@gmail.com>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Colin Ian King <colin.king@canonical.com>,
	Patrick Havelange <patrick.havelange@essensium.com>,
	Paresh Chaudhary <paresh.chaudhary@rockwellcollins.com>,
	Matt Weber <matthew.weber@rockwellcollins.com>,
	Matt Ranostay <matt.ranostay@konsulko.com>,
	Chuhong Yuan <hslester96@gmail.com>,
	Daniel Gomez <dagmcr@gmail.com>,
	linux-iio@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org
Subject: Re: [v2 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute
Date: Sat, 16 Nov 2019 14:51:30 +0000	[thread overview]
Message-ID: <20191116145130.265f84fc@archlinux> (raw)
In-Reply-To: <20191111153517.13862-9-andrea.merello@gmail.com>

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);


  reply	other threads:[~2019-11-16 14:51 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-23 12:17 [PATCH 0/3] iio: max31856: provide more configuration options Andrea Merello
2019-09-23 12:17 ` [PATCH 1/3] iio: max31856: add option for setting mains filter rejection frequency Andrea Merello
2019-10-06  7:54   ` Jonathan Cameron
2019-10-16 13:14     ` Andrea Merello
2019-10-17 12:32       ` Jonathan Cameron
2019-10-18 13:46         ` Andrea Merello
2019-10-22  9:34           ` Jonathan Cameron
2019-10-23  8:29             ` Andrea Merello
2019-10-27  9:22               ` Jonathan Cameron
2019-10-28  7:32                 ` Andrea Merello
2019-11-02 14:17                   ` Jonathan Cameron
2019-11-04 13:51                     ` Andrea Merello
2019-09-23 12:17 ` [PATCH 2/3] iio: max31856: add support for configuring the HW averaging Andrea Merello
2019-10-06  7:55   ` Jonathan Cameron
2019-10-16 13:33     ` Andrea Merello
2019-10-17 12:34       ` Jonathan Cameron
2019-10-18 13:47         ` Andrea Merello
2019-09-23 12:17 ` [PATCH 3/3] iio: max31856: add support for runtime-configuring the thermocouple type Andrea Merello
2019-10-06  7:58   ` Jonathan Cameron
2019-10-16 13:43     ` Andrea Merello
2019-10-17 12:35       ` Jonathan Cameron
2019-10-18 13:48         ` Andrea Merello
2019-11-11 15:35 ` [v2 0/9] iio: max31856: provide more configuration options Andrea Merello
2019-11-11 15:35   ` [v2 1/9] iio: max31856: add option for setting mains filter rejection frequency Andrea Merello
2019-11-11 22:59     ` Matt Ranostay
2019-11-16 14:29       ` Jonathan Cameron
2019-11-11 15:35   ` [v2 2/9] Documentation: ABI: document IIO in_temp_filter_notch_center_frequency file Andrea Merello
2019-11-11 15:35   ` [v2 3/9] iio: max31856: add support for configuring the HW averaging Andrea Merello
2019-11-11 23:01     ` Matt Ranostay
2019-11-11 15:35   ` [v2 4/9] RFC: iio: core: add char type for sysfs attributes Andrea Merello
2019-11-16 14:45     ` Jonathan Cameron
2019-11-11 15:35   ` [v2 5/9] iio: core: add thermocouple_type standard attribute Andrea Merello
2019-11-11 15:35   ` [v2 6/9] Documentation: ABI: document IIO thermocouple_type file Andrea Merello
2019-11-16 14:47     ` Jonathan Cameron
2019-11-11 15:35   ` [v2 7/9] iio: max31856: add support for runtime-configuring the thermocouple type Andrea Merello
2019-11-16 14:49     ` Jonathan Cameron
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 [this message]
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
2019-11-20 14:47   ` [v3 0/9] iio: max31856: provide more configuration options Andrea Merello
2019-11-20 14:47     ` [v3 1/9] iio: max31856: add option for setting mains filter rejection frequency Andrea Merello
2019-11-23 12:30       ` Jonathan Cameron
2019-11-20 14:47     ` [v3 2/9] Documentation: ABI: document IIO in_temp_filter_notch_center_frequency file Andrea Merello
2019-11-23 12:31       ` Jonathan Cameron
2019-11-20 14:47     ` [v3 3/9] iio: max31856: add support for configuring the HW averaging Andrea Merello
2019-11-23 12:32       ` Jonathan Cameron
2019-11-20 14:47     ` [v3 4/9] RFC: iio: core: add char type for sysfs attributes Andrea Merello
2019-11-23 12:33       ` Jonathan Cameron
2019-11-20 14:47     ` [v3 5/9] iio: core: add thermocouple_type standard attribute Andrea Merello
2019-11-23 12:36       ` Jonathan Cameron
2019-11-20 14:47     ` [v3 6/9] Documentation: ABI: document IIO thermocouple_type file Andrea Merello
2019-11-23 12:37       ` Jonathan Cameron
2019-11-20 14:47     ` [v3 7/9] iio: max31856: add support for runtime-configuring the thermocouple type Andrea Merello
2019-11-23 12:40       ` Jonathan Cameron
2019-11-23 12:41         ` Jonathan Cameron
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191116145130.265f84fc@archlinux \
    --to=jic23@kernel.org \
    --cc=andrea.merello@gmail.com \
    --cc=colin.king@canonical.com \
    --cc=dagmcr@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hslester96@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=matt.ranostay@konsulko.com \
    --cc=matthew.weber@rockwellcollins.com \
    --cc=paresh.chaudhary@rockwellcollins.com \
    --cc=patrick.havelange@essensium.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).