From: "Barnabás Czémán" <barnabas.czeman@mainlining.org>
To: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Albrieux <jonathan.albrieux@gmail.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux@mainlining.org,
"Barnabás Czémán" <barnabas.czeman@mainlining.org>
Subject: [PATCH 1/3] iio: magnetometer: ak8975: Fix reading for ak099xx sensors
Date: Mon, 05 Aug 2024 22:31:42 +0200 [thread overview]
Message-ID: <20240805-ak09918-v1-1-70837eebd7d8@mainlining.org> (raw)
In-Reply-To: <20240805-ak09918-v1-0-70837eebd7d8@mainlining.org>
ST2 register read should be placed after read measurment data,
because it will get correct values after it.
Signed-off-by: Barnabás Czémán <barnabas.czeman@mainlining.org>
---
drivers/iio/magnetometer/ak8975.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index dd466c5fa621..925d76062b3e 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -692,22 +692,7 @@ static int ak8975_start_read_axis(struct ak8975_data *data,
if (ret < 0)
return ret;
- /* This will be executed only for non-interrupt based waiting case */
- if (ret & data->def->ctrl_masks[ST1_DRDY]) {
- ret = i2c_smbus_read_byte_data(client,
- data->def->ctrl_regs[ST2]);
- if (ret < 0) {
- dev_err(&client->dev, "Error in reading ST2\n");
- return ret;
- }
- if (ret & (data->def->ctrl_masks[ST2_DERR] |
- data->def->ctrl_masks[ST2_HOFL])) {
- dev_err(&client->dev, "ST2 status error 0x%x\n", ret);
- return -EINVAL;
- }
- }
-
- return 0;
+ return !(ret & data->def->ctrl_masks[ST1_DRDY]);
}
/* Retrieve raw flux value for one of the x, y, or z axis. */
@@ -731,6 +716,20 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
ret = i2c_smbus_read_i2c_block_data_or_emulated(
client, def->data_regs[index],
sizeof(rval), (u8*)&rval);
+ ret = i2c_smbus_read_byte_data(client,
+ data->def->ctrl_regs[ST2]);
+ if (ret < 0) {
+ dev_err(&client->dev, "Error in reading ST2\n");
+ goto exit;
+ }
+
+ if (ret & (data->def->ctrl_masks[ST2_DERR] |
+ data->def->ctrl_masks[ST2_HOFL])) {
+ dev_err(&client->dev, "ST2 status error 0x%x\n", ret);
+ ret = -EINVAL;
+ goto exit;
+ }
+
if (ret < 0)
goto exit;
--
2.46.0
next prev parent reply other threads:[~2024-08-05 20:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 20:31 [PATCH 0/3] Add support for AK09918 Barnabás Czémán
2024-08-05 20:31 ` Barnabás Czémán [this message]
2024-08-05 20:31 ` [PATCH 2/3] dt-bindings: iio: imu: magnetometer: Add ak09118 Barnabás Czémán
2024-08-06 5:21 ` Krzysztof Kozlowski
2024-08-05 20:31 ` [PATCH 3/3] iio: magnetometer: ak8975: Add AK09118 support Barnabás Czémán
2024-08-06 5:22 ` 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=20240805-ak09918-v1-1-70837eebd7d8@mainlining.org \
--to=barnabas.czeman@mainlining.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=jonathan.albrieux@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@mainlining.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
all inboxes | Powered by JetHome®