From: "Paller, Kim Seer" <KimSeer.Paller@analog.com>
To: "andy.shevchenko@gmail.com" <andy.shevchenko@gmail.com>
Cc: "jic23@kernel.org" <jic23@kernel.org>,
"lars@metafoo.de" <lars@metafoo.de>,
"krzysztof.kozlowski@linaro.org" <krzysztof.kozlowski@linaro.org>,
"broonie@kernel.org" <broonie@kernel.org>,
"lgirdwood@gmail.com" <lgirdwood@gmail.com>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v2 2/2] iio: adc: max14001: New driver
Date: Tue, 6 Jun 2023 03:39:43 +0000 [thread overview]
Message-ID: <a38229ec97934d2fa0c5ab85c8edd325@analog.com> (raw)
In-Reply-To: <ZH6CZJCBTXrsUErm@surfacebook>
> -----Original Message-----
> From: andy.shevchenko@gmail.com <andy.shevchenko@gmail.com>
> Sent: Tuesday, June 6, 2023 8:49 AM
> To: Paller, Kim Seer <KimSeer.Paller@analog.com>
> Cc: jic23@kernel.org; lars@metafoo.de; krzysztof.kozlowski@linaro.org;
> broonie@kernel.org; lgirdwood@gmail.com; linux-iio@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: Re: [PATCH v2 2/2] iio: adc: max14001: New driver
>
> [External]
>
> Mon, Jun 05, 2023 at 09:07:55PM +0800, Kim Seer Paller kirjoitti:
> > The MAX14001 is configurable, isolated 10-bit ADCs for multi-range
> > binary inputs.
>
> First question, why don't you use regmap SPI?
I found it difficult to implement the regmap interface due to the timing diagram
requirements. The chip select needs to be changed between transfers, which, as
far as I know, does not work with regmap. Additionally, the regmap_config
parameters, specifically reg_bits and val_bits, cannot be set to specific values.
This limitation makes it challenging to accommodate specific configurations
such as using 5 bits for register address and 10 bits for data.
>
> ...
>
> > +static int max14001_read(void *context, unsigned int reg_addr,
> > + unsigned int *data)
>
> Strange indentation.
>
> > +{
> > + struct max14001_state *st = context;
> > + u16 tx = 0;
>
> Redundant assignment.
>
> > + int ret;
> > +
> > + struct spi_transfer xfers[] = {
> > + {
> > + .tx_buf = &st->spi_tx_buffer,
> > + .len = 2,
> > + .cs_change = 1,
> > + }, {
> > + .rx_buf = &st->spi_rx_buffer,
> > + .len = 2,
> > + },
> > + };
> > +
> > + tx = FIELD_PREP(MAX14001_ADDR_MASK, reg_addr);
>
> > + st->spi_tx_buffer = bitrev16(cpu_to_be16(tx));
>
> This is strange. Why this monsteur construct with bitrev16() is used?
>
> According to the datasheet, the bit stream is LE16, where 10 LSB is data,
> 5 MSB is address and bit 11 is R/W.
I discovered that following the instructions in the application note made
the implementation much easier.
https://www.analog.com/media/en/technical-documentation/user-guides/guide-to-programming-the-max14001max14002-isolated-adcs--maxim-integrated.pdf
To ensure compatibility with the device, I changed the format to big
endian and reversed the data before sending it to the device.
This is why I used the "bitrev" function. I'm happy to report that
this approach worked perfectly.
>
> > + 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;
>
> Ditto.
>
> > + return 0;
> > +}
>
> > +static int max14001_write(void *context, unsigned int reg_addr,
> > + unsigned int data)
> > +{
> > + struct max14001_state *st = context;
> > + u16 tx = 0;
>
> Redundant assignment.
>
> > + tx = FIELD_PREP(MAX14001_ADDR_MASK, reg_addr);
> > + tx |= FIELD_PREP(MAX14001_SET_WRITE_BIT, 1);
> > + tx |= FIELD_PREP(MAX14001_DATA_MASK, data);
> > +
> > + st->spi_tx_buffer = bitrev16(cpu_to_be16(tx));
> > +
> > + return spi_write(st->spi, &st->spi_tx_buffer, 2);
>
> sizeof() ?
>
> > +}
>
> ...
>
> > + return dev_err_probe(&spi->dev, PTR_ERR(vref),
> > + "Failed to get vref regulator");
>
> With
>
> struct device *dev = &spi->dev;
>
> this and other calls in this function can be made neater.
>
> --
> With Best Regards,
> Andy Shevchenko
>
prev parent reply other threads:[~2023-06-06 3:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-05 13:07 [PATCH v2 0/2] Add max14001 support Kim Seer Paller
2023-06-05 13:07 ` [PATCH v2 1/2] dt-bindings:iio:adc: add max14001 Kim Seer Paller
2023-06-05 13:30 ` Krzysztof Kozlowski
2023-06-06 3:21 ` Paller, Kim Seer
2023-06-05 13:07 ` [PATCH v2 2/2] iio: adc: max14001: New driver Kim Seer Paller
2023-06-05 19:24 ` Jonathan Cameron
2023-06-06 3:21 ` Paller, Kim Seer
2023-06-06 10:35 ` Jonathan Cameron
2023-06-07 11:17 ` Paller, Kim Seer
2023-06-07 14:49 ` Jonathan Cameron
2023-06-06 0:48 ` andy.shevchenko
2023-06-06 3:39 ` Paller, Kim Seer [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=a38229ec97934d2fa0c5ab85c8edd325@analog.com \
--to=kimseer.paller@analog.com \
--cc=andy.shevchenko@gmail.com \
--cc=broonie@kernel.org \
--cc=jic23@kernel.org \
--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 \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.