scmi: Add scale & offset to the accelerator in the kernel

To be able to test scaling in guests running on hosts with the dummy
IIO module.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
This commit is contained in:
Milan Zamazal 2023-08-08 12:58:06 +02:00 committed by Alex Bennée
parent 458f168639
commit b84bf46d68
2 changed files with 14 additions and 0 deletions

View File

@ -14,6 +14,7 @@ Otherwise, this alternative is provided with the following changes:
- Simplified Makefile for out of tree compilation.
- The accelerometer has three axes instead of just one.
- The Y axis of the accelerometer has offset and scale.
Of course, you can modified it further for your liking if needed.

View File

@ -16,6 +16,7 @@
*
* - Dropped conditional parts.
* - Use 3 axes in the accelerometer device.
* - Define offset and scale for some of the accelerometer axes.
*/
#include <linux/kernel.h>
#include <linux/slab.h>
@ -184,6 +185,9 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
/* Channel 2 is use for modifiers */
.channel2 = IIO_MOD_Y,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
.info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ),
@ -352,6 +356,15 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
*val2 = 1344;
ret = IIO_VAL_INT_PLUS_NANO;
}
break;
case IIO_ACCEL:
switch(chan->scan_index) {
case DUMMY_INDEX_ACCEL_Y:
*val = 0;
*val2 = 1344;
break;
}
ret = IIO_VAL_INT_PLUS_MICRO;
break;
default:
break;