Skip to content

Commit 269efcf

Browse files
sknseanJonathan Cameron
authored andcommitted
iio: accel: fxls8962af: add wake on event
This adds ways for the SoC to wake from accelerometer wake events. In the suspend function we skip disabling the sensor if wakeup-source and events are activated. If buffered reads are enabled they will be deactivated before suspend. As the onboard buffer is only holding up to 32 12-bit X/Y/Z data triplets. Signed-off-by: Sean Nyekjaer <sean@geanix.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20210920114221.1595543-2-sean@geanix.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 131fb9f commit 269efcf

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

‎drivers/iio/accel/fxls8962af-core.c‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct fxls8962af_data {
166166
} scan;
167167
int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
168168
struct iio_mount_matrix orientation;
169+
int irq;
169170
u8 watermark;
170171
u8 enable_event;
171172
u16 lower_thres;
@@ -1156,6 +1157,7 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
11561157
data = iio_priv(indio_dev);
11571158
dev_set_drvdata(dev, indio_dev);
11581159
data->regmap = regmap;
1160+
data->irq = irq;
11591161

11601162
ret = iio_read_mount_matrix(dev, &data->orientation);
11611163
if (ret)
@@ -1225,6 +1227,9 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
12251227
if (ret)
12261228
return ret;
12271229

1230+
if (device_property_read_bool(dev, "wakeup-source"))
1231+
device_init_wakeup(dev, true);
1232+
12281233
return devm_iio_device_register(dev, indio_dev);
12291234
}
12301235
EXPORT_SYMBOL_GPL(fxls8962af_core_probe);
@@ -1250,9 +1255,46 @@ static int __maybe_unused fxls8962af_runtime_resume(struct device *dev)
12501255
return fxls8962af_active(data);
12511256
}
12521257

1258+
static int __maybe_unused fxls8962af_suspend(struct device *dev)
1259+
{
1260+
struct iio_dev *indio_dev = dev_get_drvdata(dev);
1261+
struct fxls8962af_data *data = iio_priv(indio_dev);
1262+
1263+
if (device_may_wakeup(dev) && data->enable_event) {
1264+
enable_irq_wake(data->irq);
1265+
1266+
/*
1267+
* Disable buffer, as the buffer is so small the device will wake
1268+
* almost immediately.
1269+
*/
1270+
if (iio_buffer_enabled(indio_dev))
1271+
fxls8962af_buffer_predisable(indio_dev);
1272+
} else {
1273+
fxls8962af_runtime_suspend(dev);
1274+
}
1275+
1276+
return 0;
1277+
}
1278+
1279+
static int __maybe_unused fxls8962af_resume(struct device *dev)
1280+
{
1281+
struct iio_dev *indio_dev = dev_get_drvdata(dev);
1282+
struct fxls8962af_data *data = iio_priv(indio_dev);
1283+
1284+
if (device_may_wakeup(dev) && data->enable_event) {
1285+
disable_irq_wake(data->irq);
1286+
1287+
if (iio_buffer_enabled(indio_dev))
1288+
fxls8962af_buffer_postenable(indio_dev);
1289+
} else {
1290+
fxls8962af_runtime_resume(dev);
1291+
}
1292+
1293+
return 0;
1294+
}
1295+
12531296
const struct dev_pm_ops fxls8962af_pm_ops = {
1254-
SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1255-
pm_runtime_force_resume)
1297+
SET_SYSTEM_SLEEP_PM_OPS(fxls8962af_suspend, fxls8962af_resume)
12561298
SET_RUNTIME_PM_OPS(fxls8962af_runtime_suspend,
12571299
fxls8962af_runtime_resume, NULL)
12581300
};

0 commit comments

Comments
 (0)