[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251030072752.349633-5-flavra@baylibre.com>
Date: Thu, 30 Oct 2025 08:27:47 +0100
From: Francesco Lavra <flavra@...libre.com>
To: Lorenzo Bianconi <lorenzo@...nel.org>,
Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>,
linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 4/9] iio: imu: st_lsm6dsx: dynamically allocate iio_event_spec structs
In preparation for adding support for more event types, drop the
static declaration of a single struct iio_event_spec variable, in
favor of allocating and initializing the iio_event_spec array
dynamically, so that it can contain more than one entry if a given
sensor supports more than one event source.
Signed-off-by: Francesco Lavra <flavra@...libre.com>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 7 -----
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 30 ++++++++++++++++++--
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 5c73156b714a..ec4efb29c4cc 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -439,13 +439,6 @@ struct st_lsm6dsx_hw {
} scan[ST_LSM6DSX_ID_MAX];
};
-static __maybe_unused const struct iio_event_spec st_lsm6dsx_event = {
- .type = IIO_EV_TYPE_THRESH,
- .dir = IIO_EV_DIR_EITHER,
- .mask_separate = BIT(IIO_EV_INFO_VALUE) |
- BIT(IIO_EV_INFO_ENABLE)
-};
-
static __maybe_unused const unsigned long st_lsm6dsx_available_scan_masks[] = {
0x7, 0x0,
};
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 4bae5da8910e..76025971c05d 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -2314,9 +2314,33 @@ static int st_lsm6dsx_chan_init(struct iio_chan_spec *channels, struct st_lsm6ds
chan->scan_type.endianness = IIO_LE;
chan->ext_info = st_lsm6dsx_ext_info;
if (id == ST_LSM6DSX_ID_ACC) {
- if (hw->settings->event_settings.sources[ST_LSM6DSX_EVENT_WAKEUP].value.addr) {
- chan->event_spec = &st_lsm6dsx_event;
- chan->num_event_specs = 1;
+ const struct st_lsm6dsx_event_src *event_src;
+ unsigned int event_sources;
+ int event;
+
+ event_src = hw->settings->event_settings.sources;
+ event_sources = 0;
+ for (event = 0; event < ST_LSM6DSX_EVENT_MAX; event++) {
+ if (event_src[event].status_reg) {
+ event_sources |= BIT(event);
+ chan->num_event_specs++;
+ }
+ }
+ if (event_sources) {
+ struct iio_event_spec *event_spec;
+
+ event_spec = devm_kzalloc(hw->dev,
+ chan->num_event_specs * sizeof(*event_spec),
+ GFP_KERNEL);
+ if (!event_spec)
+ return -ENOMEM;
+ chan->event_spec = event_spec;
+ if (event_sources & BIT(ST_LSM6DSX_EVENT_WAKEUP)) {
+ event_spec->type = IIO_EV_TYPE_THRESH;
+ event_spec->dir = IIO_EV_DIR_EITHER;
+ event_spec->mask_separate = BIT(IIO_EV_INFO_VALUE) |
+ BIT(IIO_EV_INFO_ENABLE);
+ }
}
}
return 0;
--
2.39.5
Powered by blists - more mailing lists