Skip to content

Commit

Permalink
FROMGIT iio: magnetometer: ak8975: Fix reading for ak099xx sensors
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
barni2000 committed Sep 17, 2024
1 parent fdc7979 commit 09c1ba7
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions drivers/iio/magnetometer/ak8975.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,22 +696,8 @@ 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 with zero if the data is ready. */
return !data->def->ctrl_regs[ST1_DRDY];
}

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

/* Read out ST2 for release lock on measurment data. */
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;
}

mutex_unlock(&data->lock);

pm_runtime_mark_last_busy(&data->client->dev);
Expand Down

0 comments on commit 09c1ba7

Please sign in to comment.