diff options
author | LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn> | 2022-07-01 02:30:30 +0000 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2022-07-19 09:38:53 +0100 |
commit | 3cfb0e1d395a4323f325baaff58b8fe4a8ff9ecd (patch) | |
tree | 7a5dd1a401d818f128078ee05d0f8fd5805639ec /drivers/iio | |
parent | 5e1f91850365de55ca74945866c002fda8f00331 (diff) | |
download | linux-rpi-3cfb0e1d395a4323f325baaff58b8fe4a8ff9ecd.tar.gz linux-rpi-3cfb0e1d395a4323f325baaff58b8fe4a8ff9ecd.tar.bz2 linux-rpi-3cfb0e1d395a4323f325baaff58b8fe4a8ff9ecd.zip |
iio: accel: sca3300: Extend the trigger buffer from 16 to 32 bytes
After added inclination angle channels, the trigger buffer size is
insufficient. Extend the buffer size from 16 to 32 bytes, and change
the trigger buffer from the struct to a u8 array to adapt the sensor
with/without inclination angles output.
New trigger buffer data:
- SCA3300: 3 accel channels, temp, and timestamp.
- SCL3300: 3 accel channels, temp, 3 incli channels, and timestamp.
Readjustment the scan index to make it consistent with the buffer data.
Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
Link: https://lore.kernel.org/r/20220701023030.2527019-2-Qing-wu.Li@leica-geosystems.com.cn
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/accel/sca3300.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c index 3c4827bfef53..eaa0c9cfda44 100644 --- a/drivers/iio/accel/sca3300.c +++ b/drivers/iio/accel/sca3300.c @@ -52,12 +52,21 @@ enum sca3300_scan_indexes { SCA3300_ACC_Y, SCA3300_ACC_Z, SCA3300_TEMP, - SCA3300_TIMESTAMP, SCA3300_INCLI_X, SCA3300_INCLI_Y, SCA3300_INCLI_Z, + SCA3300_SCAN_MAX }; +/* + * Buffer size max case: + * Three accel channels, two bytes per channel. + * Temperature channel, two bytes. + * Three incli channels, two bytes per channel. + * Timestamp channel, eight bytes. + */ +#define SCA3300_MAX_BUFFER_SIZE (ALIGN(sizeof(s16) * SCA3300_SCAN_MAX, sizeof(s64)) + sizeof(s64)) + #define SCA3300_ACCEL_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ .address = reg, \ @@ -140,10 +149,10 @@ static const struct iio_chan_spec scl3300_channels[] = { SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Y, 0x2, Y), SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Z, 0x3, Z), SCA3300_TEMP_CHANNEL(SCA3300_TEMP, 0x05), - IIO_CHAN_SOFT_TIMESTAMP(4), SCA3300_INCLI_CHANNEL(SCA3300_INCLI_X, 0x09, X), SCA3300_INCLI_CHANNEL(SCA3300_INCLI_Y, 0x0A, Y), SCA3300_INCLI_CHANNEL(SCA3300_INCLI_Z, 0x0B, Z), + IIO_CHAN_SOFT_TIMESTAMP(7), }; static const unsigned long sca3300_scan_masks[] = { @@ -184,7 +193,9 @@ struct sca3300_chip_info { * @spi: SPI device structure * @lock: Data buffer lock * @chip: Sensor chip specific information - * @scan: Triggered buffer. Four channel 16-bit data + 64-bit timestamp + * @buffer: Triggered buffer: + * -SCA3300: 4 channel 16-bit data + 64-bit timestamp + * -SCL3300: 7 channel 16-bit data + 64-bit timestamp * @txbuf: Transmit buffer * @rxbuf: Receive buffer */ @@ -192,10 +203,7 @@ struct sca3300_data { struct spi_device *spi; struct mutex lock; const struct sca3300_chip_info *chip; - struct { - s16 channels[4]; - s64 ts __aligned(sizeof(s64)); - } scan; + u8 buffer[SCA3300_MAX_BUFFER_SIZE] __aligned(sizeof(s64)); u8 txbuf[4] __aligned(IIO_DMA_MINALIGN); u8 rxbuf[4]; }; @@ -484,21 +492,21 @@ static irqreturn_t sca3300_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct sca3300_data *data = iio_priv(indio_dev); int bit, ret, val, i = 0; + s16 *channels = (s16 *)data->buffer; for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) { - ret = sca3300_read_reg(data, sca3300_channels[bit].address, - &val); + ret = sca3300_read_reg(data, indio_dev->channels[bit].address, &val); if (ret) { dev_err_ratelimited(&data->spi->dev, "failed to read register, error: %d\n", ret); /* handled, but bailing out due to errors */ goto out; } - data->scan.channels[i++] = val; + channels[i++] = val; } - iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, iio_get_time_ns(indio_dev)); out: iio_trigger_notify_done(indio_dev->trig); |