From: Jonathan Cameron <jic23@kernel.org>
To: Kim Seer Paller <kimseer.paller@analog.com>
Cc: <lars@metafoo.de>, <lgirdwood@gmail.com>, <broonie@kernel.org>,
<Michael.Hennerich@analog.com>, <andy.shevchenko@gmail.com>,
<robh@kernel.org>, <krzysztof.kozlowski@linaro.org>,
<conor+dt@kernel.org>, <linux-iio@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>
Subject: Re: [PATCH v6 2/2] iio: adc: max14001: New driver
Date: Sat, 17 Jun 2023 19:43:28 +0100 [thread overview]
Message-ID: <20230617194318.1a9b0e9c@jic23-huawei> (raw)
In-Reply-To: <20230614004857.134980-2-kimseer.paller@analog.com>
On Wed, 14 Jun 2023 08:48:57 +0800
Kim Seer Paller <kimseer.paller@analog.com> wrote:
> The MAX14001 is configurable, isolated 10-bit ADCs for multi-range
> binary inputs.
>
> Signed-off-by: Kim Seer Paller <kimseer.paller@analog.com>
Build tests showed up a set of warnings we need to deal with.
Jonathan
> +
> +static int max14001_read(void *context, unsigned int reg_addr, unsigned int *data)
> +{
> + struct max14001_state *st = context;
> + int ret;
> +
> + struct spi_transfer xfers[] = {
> + {
> + .tx_buf = &st->spi_tx_buffer,
> + .len = sizeof(st->spi_tx_buffer),
> + .cs_change = 1,
> + }, {
> + .rx_buf = &st->spi_rx_buffer,
> + .len = sizeof(st->spi_rx_buffer),
> + },
> + };
> +
> + st->spi_tx_buffer = bitrev16(cpu_to_be16(FIELD_PREP(MAX14001_ADDR_MASK,
> + reg_addr)));
This gives an endian warning with sparse.
drivers/iio/adc/max14001.c:81:29: warning: incorrect type in initializer (different base types)
drivers/iio/adc/max14001.c:81:29: expected unsigned short [usertype] __x
drivers/iio/adc/max14001.c:81:29: got restricted __be16 [usertype]
drivers/iio/adc/max14001.c:81:27: warning: incorrect type in assignment (different base types)
drivers/iio/adc/max14001.c:81:27: expected restricted __be16 [usertype] spi_tx_buffer
drivers/iio/adc/max14001.c:81:27: got int
drivers/iio/adc/max14001.c:97:29: warning: incorrect type in initializer (different base types)
drivers/iio/adc/max14001.c:97:29: expected unsigned short [usertype] __x
drivers/iio/adc/max14001.c:97:29: got restricted __be16 [usertype]
drivers/iio/adc/max14001.c:97:27: warning: incorrect type in assignment (different base types)
drivers/iio/adc/max14001.c:97:27: expected restricted __be16 [usertype] spi_tx_buffer
drivers/iio/adc/max14001.c:97:27: got int
Using a forced cast and adding a comment is probably fine to fix this... Bit reversing
a big endian value is not going to be common enough to warrant anything clever.
> +
> + ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
> + if (ret)
> + return ret;
> +
> + *data = bitrev16(be16_to_cpu(st->spi_rx_buffer)) & MAX14001_DATA_MASK;
But it got me looking. Seems a bit odd that this isn't a direct reverse of what
is done on the tx bfufer.
e.g.
be16_to_cpu(bitrev16(st->spi_rx_buffer))
I'm struggling to figure out enough of the datasheet to understand this.
Perhaps you could add some comments on the logic?
> +
> + return 0;
> +}
> +
> +static int max14001_write(void *context, unsigned int reg_addr, unsigned int data)
> +{
> + struct max14001_state *st = context;
> +
> + st->spi_tx_buffer = bitrev16(cpu_to_be16(
> + FIELD_PREP(MAX14001_ADDR_MASK, reg_addr) |
> + FIELD_PREP(MAX14001_SET_WRITE_BIT, 1) |
> + FIELD_PREP(MAX14001_DATA_MASK, data)));
> +
> + return spi_write(st->spi, &st->spi_tx_buffer, sizeof(st->spi_tx_buffer));
> +}
next prev parent reply other threads:[~2023-06-17 18:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-14 0:48 [PATCH v6 1/2] dt-bindings: iio: adc: add max14001 Kim Seer Paller
2023-06-14 0:48 ` [PATCH v6 2/2] iio: adc: max14001: New driver Kim Seer Paller
2023-06-14 9:11 ` Andy Shevchenko
2023-06-14 10:43 ` Paller, Kim Seer
2023-06-14 11:53 ` Andy Shevchenko
2023-06-17 18:34 ` Jonathan Cameron
2023-06-17 18:37 ` Jonathan Cameron
2023-06-17 18:30 ` Jonathan Cameron
2023-06-17 18:43 ` Jonathan Cameron [this message]
2023-06-14 6:30 ` [PATCH v6 1/2] dt-bindings: iio: adc: add max14001 Krzysztof Kozlowski
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=20230617194318.1a9b0e9c@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy.shevchenko@gmail.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kimseer.paller@analog.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@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