Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andrew Hepp <andrew.hepp@ahepp.dev>
Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Subject: Re: [PATCH v5 2/2] iio: temperature: Add MCP9600 thermocouple EMF converter
Date: Sun, 12 Mar 2023 16:14:38 +0000	[thread overview]
Message-ID: <20230312161438.304f5004@jic23-huawei> (raw)
In-Reply-To: <20230305213604.4747-3-andrew.hepp@ahepp.dev>

On Sun,  5 Mar 2023 13:36:04 -0800
Andrew Hepp <andrew.hepp@ahepp.dev> wrote:

> Add support for the MCP9600 thermocouple EMF converter.
> 
> Datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/MCP960X-Data-Sheet-20005426.pdf
> Signed-off-by: Andrew Hepp <andrew.hepp@ahepp.dev>

Hi Andrew,

One minor improvement suggested inline.

If you can test with 
i2c_smbus_read_word_swapped() as suggested (I'm never sure when we need
the swapped form) that would be great.

If we had been later in the cycle I'd have taken this anyway and suggested
that change as a follow up patch, but we have lots of time, so no rush.

Thanks,

Jonathan

> +static int mcp9600_read(struct mcp9600_data *data,
> +			struct iio_chan_spec const *chan, int *val)
> +{
> +	__be16 buf;
> +	int ret;
> +
> +	mutex_lock(&data->read_lock);
> +	ret = i2c_smbus_read_i2c_block_data(data->client, chan->address, 2,
> +					    (u8 *)&buf);

Rare to see this call, so I went looking in the datasheet
https://www.kernel.org/doc/html/v5.5/i2c/smbus-protocol.html gives the structure
of this command as
S Addr Wr [A] Comm [A]
           S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

which matches the datasheet. However for two bytes it's also the same as...

S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
which is the more common

i2c_smbus_read_word_data() which has a defined endian type and which
I think is the wrong one here.

Given that's a common situation we also have
i2c_smbus_read_word_swapped() which is same thing but for data the opposite
way around and will avoid the need for an explicit endian swap.

Jonathan



> +	mutex_unlock(&data->read_lock);
> +
> +	if (ret < 0)
> +		return ret;
> +	*val = be16_to_cpu(buf);
> +
> +	return 0;
> +}
> +

      reply	other threads:[~2023-03-12 16:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-05 21:36 [PATCH v5 0/2] Add support for the MCP9600 thermocouple EMF converter Andrew Hepp
2023-03-05 21:36 ` [PATCH v5 1/2] dt-bindings: iio: Add " Andrew Hepp
2023-03-06  6:34   ` Krzysztof Kozlowski
2023-03-05 21:36 ` [PATCH v5 2/2] iio: temperature: " Andrew Hepp
2023-03-12 16:14   ` Jonathan Cameron [this message]

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=20230312161438.304f5004@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andrew.hepp@ahepp.dev \
    --cc=devicetree@vger.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