From: David Lechner <dlechner@baylibre.com>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
"Miclaus, Antoniu" <Antoniu.Miclaus@analog.com>
Cc: "jic23@kernel.org" <jic23@kernel.org>,
"robh@kernel.org" <robh@kernel.org>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>
Subject: Re: [PATCH v9 8/8] iio: adc: ad4851: add ad485x driver
Date: Tue, 14 Jan 2025 09:51:26 -0600 [thread overview]
Message-ID: <95e54ca0-041e-4e6e-8364-d22d6d2e16a5@baylibre.com> (raw)
In-Reply-To: <20250114132035.00004abd@huawei.com>
On 1/14/25 7:20 AM, Jonathan Cameron wrote:
>
> Hi Antoniu
>
> For future replies please crop to only the bits you are reply to.
> Took me a couple of goes to find the reply, so in some cases
> the important parts can be completely missed by a reader if
> the rest isn't cropped down.
>
> ...
>
>>>> +static int ad4851_set_oversampling_ratio(struct iio_dev *indio_dev,
>>>> + const struct iio_chan_spec *chan,
>>>> + unsigned int osr)
>>>> +{
>>>> + struct ad4851_state *st = iio_priv(indio_dev);
>>>> + int val, ret;
>>>> +
>>>> + guard(mutex)(&st->lock);
>>>> +
>>>> + if (osr == 1) {
>>>> + ret = regmap_clear_bits(st->regmap,
>>> AD4851_REG_OVERSAMPLE,
>>>> + AD4851_OS_EN_MSK);
>>>> + if (ret)
>>>> + return ret;
>>>> + } else {
>>>> + val = ad4851_osr_to_regval(osr);
>>>> + if (val < 0)
>>>> + return -EINVAL;
>>>> +
>>>> + ret = regmap_update_bits(st->regmap,
>>> AD4851_REG_OVERSAMPLE,
>>>> + AD4851_OS_EN_MSK |
>>>> + AD4851_OS_RATIO_MSK,
>>>> + FIELD_PREP(AD4851_OS_EN_MSK,
>>> 1) |
>>>> +
>>> FIELD_PREP(AD4851_OS_RATIO_MSK, val));
>>>> + if (ret)
>>>> + return ret;
>>>> + }
>>>> +
>>>> + ret = iio_backend_oversampling_ratio_set(st->back, osr);
>>>> + if (ret)
>>>> + return ret;
>>>> +
>>>> + switch (st->info->resolution) {
>>>> + case 20:
>>>> + switch (osr) {
>>>> + case 0:
>>>> + return -EINVAL;
>>>> + case 1:
>>>> + val = 20;
>>>> + break;
>>>> + default:
>>>> + val = 24;
>>>> + break;
>>>> + }
>>>> + break;
>>>> + case 16:
>>>> + val = 16;
>>>> + break;
>>>> + default:
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + ret = iio_backend_data_size_set(st->back, val);
>>>> + if (ret)
>>>> + return ret;
>>>> +
>>>> + if (osr == 1 || st->info->resolution == 16) {
>>>> + ret = regmap_clear_bits(st->regmap, AD4851_REG_PACKET,
>>>> + AD4851_PACKET_FORMAT_MASK);
>>>> + if (ret)
>>>> + return ret;
>>>> +
>>>> + st->resolution_boost_enabled = false;
>>>> + } else {
>>>> + ret = regmap_update_bits(st->regmap, AD4851_REG_PACKET,
>>>
>>> regmap_set_bits
>>
>> Why? Packet format is two bits wide according to the register map.
Oops, I was expecting it to be symmetric with regmap_clear_bits() above. But
of course you are correct.
>>
>>>> + AD4851_PACKET_FORMAT_MASK,
>>>> +
>>> FIELD_PREP(AD4851_PACKET_FORMAT_MASK, 1));
>>>> + if (ret)
>>>> + return ret;
>>>> +
>>>> + st->resolution_boost_enabled = true;
>>>> + }
>>>> +
>>>> + if (st->osr != osr) {
>>>> + ret = ad4851_scale_fill(indio_dev);
>>>> + if (ret)
>>>> + return ret;
>>>> +
>>>> + st->osr = osr;
>>>> + }
>>>> +
>>>> + return 0;
>>>> +}
>>>> +
> ...
>
>>>> +static int ad4851_setup(struct ad4851_state *st)
>>>> +{
>>>> + unsigned int product_id;
>>>> + int ret;
>>>> +
>>>> + if (st->pd_gpio) {
>>>> + /* To initiate a global reset, bring the PD pin high twice */
>>>> + gpiod_set_value(st->pd_gpio, 1);
>>>> + fsleep(1);
>>>> + gpiod_set_value(st->pd_gpio, 0);
>>>> + fsleep(1);
>>>> + gpiod_set_value(st->pd_gpio, 1);
>>>> + fsleep(1);
>>>> + gpiod_set_value(st->pd_gpio, 0);
>>>> + fsleep(1000);
>>>> + } else {
>>>> + ret = regmap_set_bits(st->regmap,
>>> AD4851_REG_INTERFACE_CONFIG_A,
>>>> + AD4851_SW_RESET);
>>>> + if (ret)
>>>> + return ret;
>>>> + }
>>>> +
>>>> + if (st->vrefbuf_en) {
>>>> + ret = regmap_set_bits(st->regmap,
>>> AD4851_REG_DEVICE_CTRL,
>>>> + AD4851_REFBUF_PD);
>>>> + if (ret)
>>>> + return ret;
>>>> + }
>>>> +
>>>> + if (st->vrefio_en) {
>>>> + ret = regmap_set_bits(st->regmap,
>>> AD4851_REG_DEVICE_CTRL,
>>>> + AD4851_REFSEL_PD);
>>>> + if (ret)
>>>> + return ret;
>>>> + }
>>>
>>> PD stands for power down, so should we be powering down if not enabled?
>>> (i.e.
>>> if is missing !)
>> We power down the internal reference if the external one is used. Not sure what is wrong here.
I see. The macro name is wrong, which made me think it was doing something
different. It should be AD4851_REF_SEL rather than AD4851_REFSEL_PD.
>>>> +
>>>> + ret = regmap_write(st->regmap,
>>> AD4851_REG_INTERFACE_CONFIG_B,
>>>> + AD4851_SINGLE_INSTRUCTION);
>>>> + if (ret)
>>>> + return ret;
>>>> +
>>>> + ret = regmap_write(st->regmap,
>>> AD4851_REG_INTERFACE_CONFIG_A,
>>>> + AD4851_SDO_ENABLE);
>>>> + if (ret)
>>>> + return ret;
>>>> +
>
> Thanks,
>
> Jonathan
next prev parent reply other threads:[~2025-01-14 15:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 12:01 [PATCH v9 1/8] iio: backend: add API for interface get Antoniu Miclaus
2024-12-20 12:01 ` [PATCH v9 2/8] iio: backend: add support for data size set Antoniu Miclaus
2024-12-20 12:01 ` [PATCH v9 3/8] iio: backend: add API for oversampling Antoniu Miclaus
2024-12-20 12:01 ` [PATCH v9 4/8] iio: adc: adi-axi-adc: add interface type Antoniu Miclaus
2024-12-20 12:01 ` [PATCH v9 5/8] iio: adc: adi-axi-adc: set data format Antoniu Miclaus
2024-12-20 12:01 ` [PATCH v9 6/8] iio: adc: adi-axi-adc: add oversampling Antoniu Miclaus
2024-12-20 12:01 ` [PATCH v9 7/8] dt-bindings: iio: adc: add ad4851 Antoniu Miclaus
2024-12-23 11:40 ` Jonathan Cameron
2025-01-08 16:48 ` David Lechner
2024-12-20 12:01 ` [PATCH v9 8/8] iio: adc: ad4851: add ad485x driver Antoniu Miclaus
2024-12-23 12:00 ` Jonathan Cameron
2025-01-08 17:06 ` David Lechner
2025-01-08 23:24 ` David Lechner
2025-01-14 12:01 ` Miclaus, Antoniu
2025-01-14 13:20 ` Jonathan Cameron
2025-01-14 15:51 ` David Lechner [this message]
2025-01-17 9:59 ` Uwe Kleine-König
2025-01-17 15:43 ` Jonathan Cameron
2024-12-23 11:33 ` [PATCH v9 1/8] iio: backend: add API for interface get 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=95e54ca0-041e-4e6e-8364-d22d6d2e16a5@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Antoniu.Miclaus@analog.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@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