Skip to content

Commit 73328d2

Browse files
barni2000gregkh
authored andcommitted
iio: magnetometer: ak8975: Fix reading for ak099xx sensors
commit 129464e upstream. 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 <[email protected]> Link: https://patch.msgid.link/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3374f06 commit 73328d2

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

drivers/iio/magnetometer/ak8975.c

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

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

713699
/* Retrieve raw flux value for one of the x, y, or z axis. */
@@ -734,6 +720,20 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
734720
if (ret < 0)
735721
goto exit;
736722

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

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

0 commit comments

Comments
 (0)