From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-iio@vger.kernel.org
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
Eva Rachel Retuya <eraretuya@gmail.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 2/4] iio: accel: adxl345: use scan_index for accessing accel registers
Date: Sun, 17 Jun 2018 00:04:41 +0900 [thread overview]
Message-ID: <1529161484-28781-3-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1529161484-28781-1-git-send-email-akinobu.mita@gmail.com>
Currently the address field in iio_chan_spec is filled with an accel
data register address for the corresponding axis.
In preparation for adding calibration offset support, this makes use of
scan_index field to access accel data registers instead of using address
field. This change makes it easier to access both accel registers and
calibration offset registers with fewer lines of code as these are
located in X-axis, Y-axis, Z-axis order.
Cc: Eva Rachel Retuya <eraretuya@gmail.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
drivers/iio/accel/adxl345_core.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 8e0d56b..6b62f82 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -49,19 +49,19 @@ struct adxl345_data {
u8 data_range;
};
-#define ADXL345_CHANNEL(reg, axis) { \
+#define ADXL345_CHANNEL(si, axis) { \
.type = IIO_ACCEL, \
.modified = 1, \
.channel2 = IIO_MOD_##axis, \
- .address = reg, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
+ .scan_index = si, \
}
static const struct iio_chan_spec adxl345_channels[] = {
- ADXL345_CHANNEL(ADXL345_REG_DATAX0, X),
- ADXL345_CHANNEL(ADXL345_REG_DATAY0, Y),
- ADXL345_CHANNEL(ADXL345_REG_DATAZ0, Z),
+ ADXL345_CHANNEL(0, X),
+ ADXL345_CHANNEL(1, Y),
+ ADXL345_CHANNEL(2, Z),
};
static int adxl345_read_raw(struct iio_dev *indio_dev,
@@ -79,8 +79,9 @@ static int adxl345_read_raw(struct iio_dev *indio_dev,
* ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte
* and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte
*/
- ret = regmap_bulk_read(data->regmap, chan->address, ®val,
- sizeof(regval));
+ ret = regmap_bulk_read(data->regmap, ADXL345_REG_DATAX0 +
+ sizeof(regval) * chan->scan_index,
+ ®val, sizeof(regval));
if (ret < 0)
return ret;
--
2.7.4
next prev parent reply other threads:[~2018-06-16 15:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-16 15:04 [PATCH 0/4] iio: accel: adxl345: add calibration offset and sampling frequency support Akinobu Mita
2018-06-16 15:04 ` [PATCH 1/4] iio: accel: adxl345: add link to datasheet Akinobu Mita
2018-06-16 15:04 ` Akinobu Mita [this message]
2018-06-16 15:04 ` [PATCH 3/4] iio: accel: adxl345: add calibration offset support Akinobu Mita
2018-06-16 18:48 ` Jonathan Cameron
2018-06-18 14:50 ` Akinobu Mita
2018-06-16 15:04 ` [PATCH 4/4] iio: accel: adxl345: add sampling frequency support Akinobu Mita
2018-06-16 18:50 ` Jonathan Cameron
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=1529161484-28781-3-git-send-email-akinobu.mita@gmail.com \
--to=akinobu.mita@gmail.com \
--cc=andy.shevchenko@gmail.com \
--cc=eraretuya@gmail.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.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;
as well as URLs for NNTP newsgroup(s).