From: Gustavo Silva <gustavograzs@gmail.com>
To: jic23@kernel.org
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
lars@metafoo.de, christophe.jaillet@wanadoo.fr,
devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/6] iio: chemical: ens160: add power management support
Date: Tue, 28 May 2024 21:14:22 -0300 [thread overview]
Message-ID: <20240529001504.33648-5-gustavograzs@gmail.com> (raw)
In-Reply-To: <20240529001504.33648-1-gustavograzs@gmail.com>
ENS160 supports a deep sleep mode for minimal power consumption.
Use it to add PM sleep capability to the driver.
Signed-off-by: Gustavo Silva <gustavograzs@gmail.com>
---
no changes in v2
drivers/iio/chemical/ens160.h | 3 +++
drivers/iio/chemical/ens160_core.c | 23 +++++++++++++++++++++++
drivers/iio/chemical/ens160_i2c.c | 1 +
drivers/iio/chemical/ens160_spi.c | 1 +
4 files changed, 28 insertions(+)
diff --git a/drivers/iio/chemical/ens160.h b/drivers/iio/chemical/ens160.h
index e6cc0987a..f9f0575ce 100644
--- a/drivers/iio/chemical/ens160.h
+++ b/drivers/iio/chemical/ens160.h
@@ -4,4 +4,7 @@
int devm_ens160_core_probe(struct device *dev, struct regmap *regmap, int irq,
const char *name);
+
+extern const struct dev_pm_ops ens160_pm_ops;
+
#endif
diff --git a/drivers/iio/chemical/ens160_core.c b/drivers/iio/chemical/ens160_core.c
index 74ef7f150..dd501e655 100644
--- a/drivers/iio/chemical/ens160_core.c
+++ b/drivers/iio/chemical/ens160_core.c
@@ -215,6 +215,29 @@ static const struct iio_info ens160_info = {
.read_raw = ens160_read_raw,
};
+static int ens160_suspend(struct device *dev)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct ens160_data *data = iio_priv(indio_dev);
+
+ return ens160_set_mode(data, ENS160_REG_MODE_DEEP_SLEEP);
+}
+
+static int ens160_resume(struct device *dev)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct ens160_data *data = iio_priv(indio_dev);
+ int ret;
+
+ ret = ens160_set_mode(data, ENS160_REG_MODE_IDLE);
+ if (ret)
+ return ret;
+
+ return ens160_set_mode(data, ENS160_REG_MODE_STANDARD);
+}
+EXPORT_NS_SIMPLE_DEV_PM_OPS(ens160_pm_ops, ens160_suspend, ens160_resume,
+ IIO_ENS160);
+
static irqreturn_t ens160_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
diff --git a/drivers/iio/chemical/ens160_i2c.c b/drivers/iio/chemical/ens160_i2c.c
index 4bf3c455c..06d2967a9 100644
--- a/drivers/iio/chemical/ens160_i2c.c
+++ b/drivers/iio/chemical/ens160_i2c.c
@@ -49,6 +49,7 @@ static struct i2c_driver ens160_i2c_driver = {
.driver = {
.name = "ens160_i2c",
.of_match_table = ens160_of_i2c_match,
+ .pm = pm_sleep_ptr(&ens160_pm_ops),
},
.probe = ens160_i2c_probe,
.id_table = ens160_i2c_id,
diff --git a/drivers/iio/chemical/ens160_spi.c b/drivers/iio/chemical/ens160_spi.c
index 91528c5e3..f9603f51d 100644
--- a/drivers/iio/chemical/ens160_spi.c
+++ b/drivers/iio/chemical/ens160_spi.c
@@ -49,6 +49,7 @@ static struct spi_driver ens160_spi_driver = {
.driver = {
.name = "ens160_spi",
.of_match_table = ens160_spi_of_match,
+ .pm = pm_sleep_ptr(&ens160_pm_ops),
},
.probe = ens160_spi_probe,
.id_table = ens160_spi_id,
--
2.45.1
next prev parent reply other threads:[~2024-05-29 0:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 0:14 [PATCH v2 1/6] dt-bindings: vendor-prefixes: add ScioSense Gustavo Silva
2024-05-29 0:14 ` [PATCH v2 2/6] dt-bindings: iio: chemical: add ENS160 sensor Gustavo Silva
2024-05-29 1:42 ` Rob Herring (Arm)
2024-05-29 16:36 ` Conor Dooley
2024-05-29 16:37 ` Conor Dooley
2024-05-31 22:33 ` Gustavo Silva
2024-05-29 0:14 ` [PATCH v2 3/6] iio: chemical: add driver for " Gustavo Silva
2024-06-02 11:24 ` Jonathan Cameron
2024-05-29 0:14 ` [PATCH v2 4/6] iio: chemical: ens160: add triggered buffer support Gustavo Silva
2024-06-02 11:27 ` Jonathan Cameron
2024-05-29 0:14 ` Gustavo Silva [this message]
2024-05-29 0:14 ` [PATCH v2 6/6] MAINTAINERS: Add ScioSense ENS160 Gustavo Silva
2024-05-29 7:29 ` [PATCH v2 1/6] dt-bindings: vendor-prefixes: add ScioSense Krzysztof Kozlowski
2024-05-29 16:34 ` Conor Dooley
2024-05-31 22:22 ` Gustavo Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240529001504.33648-5-gustavograzs@gmail.com \
--to=gustavograzs@gmail.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).