summaryrefslogtreecommitdiff
path: root/drivers/misc/m4sensorhub_passive.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/m4sensorhub_passive.c')
-rw-r--r--drivers/misc/m4sensorhub_passive.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/drivers/misc/m4sensorhub_passive.c b/drivers/misc/m4sensorhub_passive.c
index 692a70ae69f..70c77692573 100644
--- a/drivers/misc/m4sensorhub_passive.c
+++ b/drivers/misc/m4sensorhub_passive.c
@@ -46,6 +46,7 @@ struct m4pas_driver_data {
struct m4sensorhub_passive_iio_data iiodat[M4PAS_NUM_PASSIVE_BUFFERS];
int16_t samplerate;
+ int16_t latest_samplerate;
uint16_t status;
};
@@ -183,7 +184,9 @@ static int m4pas_set_samplerate(struct iio_dev *iio, int16_t rate)
* Currently, there is no concept of setting a sample rate for this
* sensor, so this function only enables/disables interrupt reporting.
*/
- dd->samplerate = rate;
+ dd->latest_samplerate = rate;
+ if (dd->samplerate == rate)
+ goto m4pas_set_samplerate_fail;
if (rate >= 0) {
/* Enable passive mode feature */
@@ -205,6 +208,7 @@ static int m4pas_set_samplerate(struct iio_dev *iio, int16_t rate)
goto m4pas_set_samplerate_fail;
}
dd->status = dd->status | (1 << M4PAS_IRQ_ENABLED_BIT);
+ dd->samplerate = rate;
}
} else {
/* Disable passive mode feature */
@@ -226,6 +230,7 @@ static int m4pas_set_samplerate(struct iio_dev *iio, int16_t rate)
goto m4pas_set_samplerate_fail;
}
dd->status = dd->status & ~(1 << M4PAS_IRQ_ENABLED_BIT);
+ dd->samplerate = rate;
}
}
@@ -479,6 +484,7 @@ static int m4pas_probe(struct platform_device *pdev)
mutex_init(&(dd->mutex));
platform_set_drvdata(pdev, iio);
dd->samplerate = -1; /* We always start disabled */
+ dd->latest_samplerate = dd->samplerate;
err = m4pas_create_iiodev(iio); /* iio and dd are freed on fail */
if (err < 0) {
@@ -528,6 +534,17 @@ m4pas_remove_exit:
return 0;
}
+static int m4pas_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ struct iio_dev *iio = platform_get_drvdata(pdev);
+ struct m4pas_driver_data *dd = iio_priv(iio);
+ mutex_lock(&(dd->mutex));
+ if (m4pas_set_samplerate(iio, dd->latest_samplerate) < 0)
+ m4pas_err("%s: setrate retry failed\n", __func__);
+ mutex_unlock(&(dd->mutex));
+ return 0;
+}
+
static struct of_device_id m4passive_match_tbl[] = {
{ .compatible = "mot,m4passive" },
{},
@@ -537,7 +554,7 @@ static struct platform_driver m4pas_driver = {
.probe = m4pas_probe,
.remove = __exit_p(m4pas_remove),
.shutdown = NULL,
- .suspend = NULL,
+ .suspend = m4pas_suspend,
.resume = NULL,
.driver = {
.name = M4PAS_DRIVER_NAME,