devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Andrew Hepp <andrew.hepp@ahepp.dev>,
	devicetree@vger.kernel.org, linux-iio@vger.kernel.org
Cc: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Jonathan Cameron <jic23@kernel.org>
Subject: Re: [PATCH 2/2] iio: temperature: Add MCP9600 thermocouple EMF converter
Date: Sun, 19 Mar 2023 11:59:38 -0700	[thread overview]
Message-ID: <89271a29-5b02-34fe-409b-373e3b8044ef@metafoo.de> (raw)
In-Reply-To: <20230319184728.49232-3-andrew.hepp@ahepp.dev>

This looks really good. I have some small comments, and I apologize for 
only having them so late in the review cycle.

On 3/19/23 11:47, Andrew Hepp wrote:
> Add support for the MCP9600 thermocouple EMF converter.

Would be nice to have a very short description of the capabilities of 
the sensor in the commit message.

>
> Datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/MCP960X-Data-Sheet-20005426.pdf
> Signed-off-by: Andrew Hepp <andrew.hepp@ahepp.dev>
> ---
> [...]
> diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c
> new file mode 100644
> index 000000000000..b6d8ffb90c36
> --- /dev/null
> +++ b/drivers/iio/temperature/mcp9600.c
> @@ -0,0 +1,145 @@
> +// SPDX-License-Identifier: GPL-2.0+
> [...]
> +static const struct iio_chan_spec mcp9600_channels[] = {
> +	{
> +		.type = IIO_TEMP,
> +		.address = MCP9600_HOT_JUNCTION,
> +		.info_mask_separate =
> +			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> +	},
> +	{
> +		.type = IIO_TEMP,
> +		.address = MCP9600_COLD_JUNCTION,
> +		.channel2 = IIO_MOD_TEMP_AMBIENT,
> +		.modified = 1,
> +		.info_mask_separate =
> +			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> +	},
> +	IIO_CHAN_SOFT_TIMESTAMP(2),
If you do not have supported for buffered capture there is no need to 
include a timestamp in the channel spec. There is no way to read it 
without buffered support.
> +};
> +
> +struct mcp9600_data {
> +	struct i2c_client *client;
> +	struct mutex read_lock; /* lock to prevent concurrent reads */
> +};
> +
> +static int mcp9600_read(struct mcp9600_data *data,
> +			struct iio_chan_spec const *chan, int *val)
> +{
> +	__be16 buf;
buf does not seem to be used.
> +	int ret;
> +
> +	mutex_lock(&data->read_lock);
Do you actually need the custom lock? i2c_smbus_read_word_swapped itself 
should provide locking and there is only a single operation under your 
custom lock, which will already be atomic.
> +	ret = i2c_smbus_read_word_swapped(data->client, chan->address);
> +	mutex_unlock(&data->read_lock);
> +
> +	if (ret < 0)
> +		return ret;
> +	*val = ret;
> +
> +	return 0;
> +}
> +
> [...]
> +static int mcp9600_probe(struct i2c_client *client)
> +{
> +	struct iio_dev *indio_dev;
> +	struct mcp9600_data *data;
> +	int ret;
> +
> +	ret = i2c_smbus_read_byte_data(client, MCP9600_DEVICE_ID);
> +	if (ret < 0)
> +		return ret;

Might as well throw an error message in here for better diagnostics.

     return dev_err_probe(&client->dev, ret, "Failed to read device ID\n");



  reply	other threads:[~2023-03-19 18:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-19 18:47 [PATCH 0/2] Add support for the MCP9600 thermocouple EMF converter Andrew Hepp
2023-03-19 18:47 ` [PATCH 1/2] dt-bindings: iio: Add " Andrew Hepp
2023-03-20  6:45   ` Krzysztof Kozlowski
2023-03-19 18:47 ` [PATCH 2/2] iio: temperature: " Andrew Hepp
2023-03-19 18:59   ` Lars-Peter Clausen [this message]
2023-03-23 18:20     ` Andrew Hepp
2023-03-26 16:26       ` Jonathan Cameron
2023-03-19 21:24   ` kernel test robot
2023-03-19 18:52 ` [PATCH 0/2] Add support for the " Andrew Hepp

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=89271a29-5b02-34fe-409b-373e3b8044ef@metafoo.de \
    --to=lars@metafoo.de \
    --cc=andrew.hepp@ahepp.dev \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --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).