Skip to content

Commit 129464e

Browse files
barni2000jic23
authored andcommitted
iio: magnetometer: ak8975: Fix reading for ak099xx sensors
Move ST2 reading with overflow handling after measurement data reading. ST2 register read have to be read after read measurment data, because it means end of the reading and realease the lock on the data. Remove ST2 read skip on interrupt based waiting because ST2 required to be read out at and of the axis read. Fixes: 57e73a4 ("iio: ak8975: add ak09911 and ak09912 support") Signed-off-by: Barnabás Czémán <barnabas.czeman@mainlining.org> Link: https://patch.msgid.link/20240819-ak09918-v4-2-f0734d14cfb9@mainlining.org Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 3b92fc4 commit 129464e

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

drivers/iio/magnetometer/ak8975.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -696,22 +696,8 @@ static int ak8975_start_read_axis(struct ak8975_data *data,
696696
if (ret < 0)
697697
return ret;
698698

699-
/* This will be executed only for non-interrupt based waiting case */
700-
if (ret & data->def->ctrl_masks[ST1_DRDY]) {
701-
ret = i2c_smbus_read_byte_data(client,
702-
data->def->ctrl_regs[ST2]);
703-
if (ret < 0) {
704-
dev_err(&client->dev, "Error in reading ST2\n");
705-
return ret;
706-
}
707-
if (ret & (data->def->ctrl_masks[ST2_DERR] |
708-
data->def->ctrl_masks[ST2_HOFL])) {
709-
dev_err(&client->dev, "ST2 status error 0x%x\n", ret);
710-
return -EINVAL;
711-
}
712-
}
713-
714-
return 0;
699+
/* Return with zero if the data is ready. */
700+
return !data->def->ctrl_regs[ST1_DRDY];
715701
}
716702

717703
/* Retrieve raw flux value for one of the x, y, or z axis. */
@@ -738,6 +724,20 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
738724
if (ret < 0)
739725
goto exit;
740726

727+
/* Read out ST2 for release lock on measurment data. */
728+
ret = i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST2]);
729+
if (ret < 0) {
730+
dev_err(&client->dev, "Error in reading ST2\n");
731+
goto exit;
732+
}
733+
734+
if (ret & (data->def->ctrl_masks[ST2_DERR] |
735+
data->def->ctrl_masks[ST2_HOFL])) {
736+
dev_err(&client->dev, "ST2 status error 0x%x\n", ret);
737+
ret = -EINVAL;
738+
goto exit;
739+
}
740+
741741
mutex_unlock(&data->lock);
742742

743743
pm_runtime_mark_last_busy(&data->client->dev);

0 commit comments

Comments
 (0)