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>
This commit is contained in:
committed by
Jonathan Cameron
parent
131fb9f2b9
commit
269efcf0bb
@@ -166,6 +166,7 @@ struct fxls8962af_data {
|
|||||||
} scan;
|
} scan;
|
||||||
int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
|
int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
|
||||||
struct iio_mount_matrix orientation;
|
struct iio_mount_matrix orientation;
|
||||||
|
int irq;
|
||||||
u8 watermark;
|
u8 watermark;
|
||||||
u8 enable_event;
|
u8 enable_event;
|
||||||
u16 lower_thres;
|
u16 lower_thres;
|
||||||
@@ -1156,6 +1157,7 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
|
|||||||
data = iio_priv(indio_dev);
|
data = iio_priv(indio_dev);
|
||||||
dev_set_drvdata(dev, indio_dev);
|
dev_set_drvdata(dev, indio_dev);
|
||||||
data->regmap = regmap;
|
data->regmap = regmap;
|
||||||
|
data->irq = irq;
|
||||||
|
|
||||||
ret = iio_read_mount_matrix(dev, &data->orientation);
|
ret = iio_read_mount_matrix(dev, &data->orientation);
|
||||||
if (ret)
|
if (ret)
|
||||||
@@ -1225,6 +1227,9 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
if (device_property_read_bool(dev, "wakeup-source"))
|
||||||
|
device_init_wakeup(dev, true);
|
||||||
|
|
||||||
return devm_iio_device_register(dev, indio_dev);
|
return devm_iio_device_register(dev, indio_dev);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(fxls8962af_core_probe);
|
EXPORT_SYMBOL_GPL(fxls8962af_core_probe);
|
||||||
@@ -1250,9 +1255,46 @@ static int __maybe_unused fxls8962af_runtime_resume(struct device *dev)
|
|||||||
return fxls8962af_active(data);
|
return fxls8962af_active(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int __maybe_unused fxls8962af_suspend(struct device *dev)
|
||||||
|
{
|
||||||
|
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
||||||
|
struct fxls8962af_data *data = iio_priv(indio_dev);
|
||||||
|
|
||||||
|
if (device_may_wakeup(dev) && data->enable_event) {
|
||||||
|
enable_irq_wake(data->irq);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disable buffer, as the buffer is so small the device will wake
|
||||||
|
* almost immediately.
|
||||||
|
*/
|
||||||
|
if (iio_buffer_enabled(indio_dev))
|
||||||
|
fxls8962af_buffer_predisable(indio_dev);
|
||||||
|
} else {
|
||||||
|
fxls8962af_runtime_suspend(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __maybe_unused fxls8962af_resume(struct device *dev)
|
||||||
|
{
|
||||||
|
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
||||||
|
struct fxls8962af_data *data = iio_priv(indio_dev);
|
||||||
|
|
||||||
|
if (device_may_wakeup(dev) && data->enable_event) {
|
||||||
|
disable_irq_wake(data->irq);
|
||||||
|
|
||||||
|
if (iio_buffer_enabled(indio_dev))
|
||||||
|
fxls8962af_buffer_postenable(indio_dev);
|
||||||
|
} else {
|
||||||
|
fxls8962af_runtime_resume(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const struct dev_pm_ops fxls8962af_pm_ops = {
|
const struct dev_pm_ops fxls8962af_pm_ops = {
|
||||||
SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
|
SET_SYSTEM_SLEEP_PM_OPS(fxls8962af_suspend, fxls8962af_resume)
|
||||||
pm_runtime_force_resume)
|
|
||||||
SET_RUNTIME_PM_OPS(fxls8962af_runtime_suspend,
|
SET_RUNTIME_PM_OPS(fxls8962af_runtime_suspend,
|
||||||
fxls8962af_runtime_resume, NULL)
|
fxls8962af_runtime_resume, NULL)
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user