diff mbox series

[4/4] iio: humidity: hdc3020: add reset management

Message ID 20240220-hdc3020-pm-v1-4-d8e60dbe79e9@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series iio: humidity: hdc3020: add power and reset management | expand

Commit Message

Javier Carrasco Feb. 20, 2024, 9:14 p.m. UTC
The HDC3020 provides an active low reset signal that must be handled if
connected. Asserting this signal turns the device into Trigger-on Demand
measurement mode, reducing its power consumption when no measurements
are required like in low-power modes.

According to the datasheet, the longest "Reset Ready" is 3 ms, which is
only taken into account if the reset signal is defined.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/iio/humidity/hdc3020.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Jonathan Cameron Feb. 24, 2024, 6:25 p.m. UTC | #1
On Tue, 20 Feb 2024 22:14:58 +0100
Javier Carrasco <javier.carrasco.cruz@gmail.com> wrote:

> The HDC3020 provides an active low reset signal that must be handled if
> connected. Asserting this signal turns the device into Trigger-on Demand
> measurement mode, reducing its power consumption when no measurements
> are required like in low-power modes.
> 
> According to the datasheet, the longest "Reset Ready" is 3 ms, which is
> only taken into account if the reset signal is defined.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Rest of this series looks good to me.

Hopefully you'll soon have a sensible base and can drop patch 1.
Ideal is Greg takes my pull request shortly and I rebase the tree
asap so that I can get a clean base for a second pull request late
this week.  The aim is 1 week in linux-next (usually in via char-misc
not my tree) before the merge window opens.  So busy week ;)

Thanks,

Jonathan
diff mbox series

Patch

diff --git a/drivers/iio/humidity/hdc3020.c b/drivers/iio/humidity/hdc3020.c
index 0da5c5c41cd2..bd2f57a7eedc 100644
--- a/drivers/iio/humidity/hdc3020.c
+++ b/drivers/iio/humidity/hdc3020.c
@@ -15,6 +15,7 @@ 
 #include <linux/cleanup.h>
 #include <linux/crc8.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
@@ -70,6 +71,7 @@ 
 
 struct hdc3020_data {
 	struct i2c_client *client;
+	struct gpio_desc *reset_gpio;
 	struct regulator *vdd_supply;
 	/*
 	 * Ensure that the sensor configuration (currently only heater is
@@ -564,6 +566,11 @@  static int hdc3020_power_on(struct hdc3020_data *data)
 
 	fsleep(5000);
 
+	if (data->reset_gpio) {
+		gpiod_set_value_cansleep(data->reset_gpio, 0);
+		fsleep(3000);
+	}
+
 	if (data->client->irq) {
 		/*
 		 * The alert output is activated by default upon power up,
@@ -581,6 +588,9 @@  static int hdc3020_power_off(struct hdc3020_data *data)
 {
 	hdc3020_exec_cmd(data, HDC3020_EXIT_AUTO);
 
+	if (data->reset_gpio)
+		gpiod_set_value_cansleep(data->reset_gpio, 1);
+
 	return regulator_disable(data->vdd_supply);
 }
 
@@ -621,6 +631,12 @@  static int hdc3020_probe(struct i2c_client *client)
 		return dev_err_probe(&client->dev, PTR_ERR(data->vdd_supply),
 				     "Unable to get VDD regulator\n");
 
+	data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
+						   GPIOD_OUT_HIGH);
+	if (IS_ERR(data->reset_gpio))
+		return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio),
+				     "Cannot get reset GPIO\n");
+
 	hdc3020_power_on(data);
 
 	if (client->irq) {