diff options
author | Crestez Dan Leonard <leonard.crestez@intel.com> | 2016-04-29 15:05:32 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2016-05-01 12:54:38 -0400 |
commit | a8175ba33542d625430b66a805ef315ea3b4e755 (patch) | |
tree | c28511b9b8fa1c0f0604cdc43cc519d23b87a378 /drivers/iio | |
parent | fbced0e9465152d628ece5fd0d11de4e7a1f5ce5 (diff) |
iio: ak8975: Support adapters limited to BYTE_DATA
The device has simple 8-bit registers but the driver incorrectly uses
block or word reads without checking functionality bits.
Fix by using i2c_smbus_read_i2c_block_data_or_emulated instead of
i2c_smbus_read_i2c_block_data or i2c_smbus_read_word_data. This will
check functionality bits and use the fastest available transfer method.
Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/magnetometer/ak8975.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index dbf066129a04..c24b8a509ed8 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c | |||
@@ -430,8 +430,8 @@ static int ak8975_who_i_am(struct i2c_client *client, | |||
430 | * AK8975 | DEVICE_ID | NA | 430 | * AK8975 | DEVICE_ID | NA |
431 | * AK8963 | DEVICE_ID | NA | 431 | * AK8963 | DEVICE_ID | NA |
432 | */ | 432 | */ |
433 | ret = i2c_smbus_read_i2c_block_data(client, AK09912_REG_WIA1, | 433 | ret = i2c_smbus_read_i2c_block_data_or_emulated( |
434 | 2, wia_val); | 434 | client, AK09912_REG_WIA1, 2, wia_val); |
435 | if (ret < 0) { | 435 | if (ret < 0) { |
436 | dev_err(&client->dev, "Error reading WIA\n"); | 436 | dev_err(&client->dev, "Error reading WIA\n"); |
437 | return ret; | 437 | return ret; |
@@ -543,9 +543,9 @@ static int ak8975_setup(struct i2c_client *client) | |||
543 | } | 543 | } |
544 | 544 | ||
545 | /* Get asa data and store in the device data. */ | 545 | /* Get asa data and store in the device data. */ |
546 | ret = i2c_smbus_read_i2c_block_data(client, | 546 | ret = i2c_smbus_read_i2c_block_data_or_emulated( |
547 | data->def->ctrl_regs[ASA_BASE], | 547 | client, data->def->ctrl_regs[ASA_BASE], |
548 | 3, data->asa); | 548 | 3, data->asa); |
549 | if (ret < 0) { | 549 | if (ret < 0) { |
550 | dev_err(&client->dev, "Not able to read asa data\n"); | 550 | dev_err(&client->dev, "Not able to read asa data\n"); |
551 | return ret; | 551 | return ret; |
@@ -686,6 +686,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val) | |||
686 | struct ak8975_data *data = iio_priv(indio_dev); | 686 | struct ak8975_data *data = iio_priv(indio_dev); |
687 | const struct i2c_client *client = data->client; | 687 | const struct i2c_client *client = data->client; |
688 | const struct ak_def *def = data->def; | 688 | const struct ak_def *def = data->def; |
689 | u16 buff; | ||
689 | int ret; | 690 | int ret; |
690 | 691 | ||
691 | mutex_lock(&data->lock); | 692 | mutex_lock(&data->lock); |
@@ -694,14 +695,17 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val) | |||
694 | if (ret) | 695 | if (ret) |
695 | goto exit; | 696 | goto exit; |
696 | 697 | ||
697 | ret = i2c_smbus_read_word_data(client, def->data_regs[index]); | 698 | ret = i2c_smbus_read_i2c_block_data_or_emulated( |
699 | client, def->data_regs[index], | ||
700 | sizeof(buff), (u8*)&buff); | ||
698 | if (ret < 0) | 701 | if (ret < 0) |
699 | goto exit; | 702 | goto exit; |
700 | 703 | ||
701 | mutex_unlock(&data->lock); | 704 | mutex_unlock(&data->lock); |
702 | 705 | ||
703 | /* Clamp to valid range. */ | 706 | /* Swap bytes and convert to valid range. */ |
704 | *val = clamp_t(s16, ret, -def->range, def->range); | 707 | buff = le16_to_cpu(buff); |
708 | *val = clamp_t(s16, buff, -def->range, def->range); | ||
705 | return IIO_VAL_INT; | 709 | return IIO_VAL_INT; |
706 | 710 | ||
707 | exit: | 711 | exit: |