From: Jonathan Cameron <jic23@kernel.org>
To: Andrej Valek <andrej.v@skyrain.eu>
Cc: linux-iio@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Puranjay Mohan <puranjay@kernel.org>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
David Lechner <dlechner@baylibre.com>,
Kessler Markus <markus.kessler@hilti.com>
Subject: Re: [PATCH v3] iio: accel: fix ADXL355 startup race condition
Date: Sat, 4 Oct 2025 16:47:32 +0100 [thread overview]
Message-ID: <20251004164732.3d70091c@jic23-huawei> (raw)
In-Reply-To: <20251001143702.587073-1-andrej.v@skyrain.eu>
On Wed, 1 Oct 2025 16:37:02 +0200
Andrej Valek <andrej.v@skyrain.eu> wrote:
> From: Valek Andrej <andrej.v@skyrain.eu>
>
> There is an race-condition where device is not full working after SW reset.
> Therefore it's necessary to wait some time after reset and verify shadow
> registers values by reading and comparing the values before/after reset.
> This mechanism is described in datasheet at least from revision D.
>
> Signed-off-by: Valek Andrej <andrej.v@skyrain.eu>
> Signed-off-by: Kessler Markus <markus.kessler@hilti.com>
Hi Valek,
One process thing is to not reply to an existing thread with a new version.
Whilst it seems nice and tidy when we only have one patch in a series, it can
get very complex to read if we have deep threads with many versions being commented
on at the same time. Also tends to end up way off the top of the screen in
threaded email clients. Hence this is about the last patch I'm replying to today
just because for once I've more or less caught up with all my IIO related emails.
So just send a fresh series that isn't in reply to anything.
Mostly good, but can you reply with a fixes tag and are you fine with me
adding the error check I call out below?
> ---
> drivers/iio/accel/adxl355_core.c | 41 ++++++++++++++++++++++++++++----
> 1 file changed, 36 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/adxl355_core.c
> index 2e00fd51b4d5..782085d74ab8 100644
> --- a/drivers/iio/accel/adxl355_core.c
> +++ b/drivers/iio/accel/adxl355_core.c
> @@ -56,6 +56,8 @@
> #define ADXL355_POWER_CTL_DRDY_MSK BIT(2)
> #define ADXL355_SELF_TEST_REG 0x2E
> #define ADXL355_RESET_REG 0x2F
> +#define ADXL355_BASE_ADDR_SHADOW_REG 0x50
> +#define ADXL355_SHADOW_REG_COUNT 5
>
> #define ADXL355_DEVID_AD_VAL 0xAD
> #define ADXL355_DEVID_MST_VAL 0x1D
> @@ -294,6 +296,8 @@ static void adxl355_fill_3db_frequency_table(struct adxl355_data *data)
> static int adxl355_setup(struct adxl355_data *data)
> {
> unsigned int regval;
> + u8 *shadow_regs __free(kfree) = kzalloc(ADXL355_SHADOW_REG_COUNT, GFP_KERNEL);
> + int retries = 5; /* the number is chosen based on empirical reasons */
> int ret;
if (!shadow_regs)
return -ENOMEM;
Whilst very unlikely to happen we still need to handle memory allocation failure.
>
> ret = regmap_read(data->regmap, ADXL355_DEVID_AD_REG, ®val);
> @@ -321,14 +325,41 @@ static int adxl355_setup(struct adxl355_data *data)
> if (regval != ADXL355_PARTID_VAL)
> dev_warn(data->dev, "Invalid DEV ID 0x%02x\n", regval);
>
> - /*
> - * Perform a software reset to make sure the device is in a consistent
> - * state after start-up.
> - */
> - ret = regmap_write(data->regmap, ADXL355_RESET_REG, ADXL355_RESET_CODE);
> + /* Read shadow registers to be compared after reset */
> + ret = regmap_bulk_read(data->regmap,
> + ADXL355_BASE_ADDR_SHADOW_REG,
> + shadow_regs, ADXL355_SHADOW_REG_COUNT);
> if (ret)
> return ret;
>
> + do {
> + if (--retries == 0) {
> + dev_err(data->dev, "Shadow registers mismatch\n");
> + return -EIO;
> + }
> +
> + /*
> + * Perform a software reset to make sure the device is in a consistent
> + * state after start-up.
> + */
> + ret = regmap_write(data->regmap, ADXL355_RESET_REG,
> + ADXL355_RESET_CODE);
> + if (ret)
> + return ret;
> +
> + /* Wait at least 5ms after software reset */
> + usleep_range(5000, 10000);
> +
> + /* Read shadow registers for comparison */
> + ret = regmap_bulk_read(data->regmap,
> + ADXL355_BASE_ADDR_SHADOW_REG,
> + data->buffer.buf,
> + ADXL355_SHADOW_REG_COUNT);
> + if (ret)
> + return ret;
> + } while (memcmp(shadow_regs, data->buffer.buf,
> + ADXL355_SHADOW_REG_COUNT));
> +
> ret = regmap_update_bits(data->regmap, ADXL355_POWER_CTL_REG,
> ADXL355_POWER_CTL_DRDY_MSK,
> FIELD_PREP(ADXL355_POWER_CTL_DRDY_MSK, 1));
next prev parent reply other threads:[~2025-10-04 15:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 8:55 [PATCH] drivers: iio: accel: fix ADX355 startup race condition Andrej Valek
2025-09-10 18:30 ` Jonathan Cameron
2025-09-11 9:33 ` Andrej Valek
2025-09-12 14:12 ` Jonathan Cameron
2025-09-15 12:03 ` Andrej Valek
2025-09-15 15:53 ` Jonathan Cameron
2025-09-16 7:07 ` Andrej Valek
2025-09-27 13:51 ` Jonathan Cameron
2025-09-29 6:10 ` Andrej Valek
2025-10-01 13:29 ` David Lechner
2025-10-01 14:42 ` Andrej Valek
2025-09-10 18:31 ` Jonathan Cameron
2025-09-15 11:58 ` [PATCH v2] iio: accel: fix ADXL355 " Andrej Valek
2025-09-27 13:55 ` Jonathan Cameron
2025-10-01 14:37 ` [PATCH v3] " Andrej Valek
2025-10-04 15:47 ` Jonathan Cameron [this message]
2025-10-06 10:03 ` Andrej Valek
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=20251004164732.3d70091c@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andrej.v@skyrain.eu \
--cc=dlechner@baylibre.com \
--cc=jonathan.cameron@huawei.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=markus.kessler@hilti.com \
--cc=puranjay@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