linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support
@ 2019-01-17 23:12 Nicolin Chen
  2019-01-17 23:12 ` [PATCH v3 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nicolin Chen @ 2019-01-17 23:12 UTC (permalink / raw)
  To: jdelvare, linux
  Cc: robh+dt, mark.rutland, linux-hwmon, devicetree, linux-kernel

By default, ina3221, as a hardware monitor, continuously measures
the inputs and generates corresponding data. However, for battery
powered devices, this mode might be power consuming.

This series of patches add a feature of changing default operating
mode to its single-shot mode via DT.

Changelog
v2->v3:
 * Added "Reviewed-by" from Rob to PATCH-1
 * Cleaned-up PATCH-2
v1->v2:
 * Cleaned-up PATCH-2

Nicolin Chen (2):
  dt-bindings: hwmon: ina3221: Add ti,single-shot property
  hwmon: (ina3221) Implement ti,single-shot DT property

 .../devicetree/bindings/hwmon/ina3221.txt     | 10 ++++++++++
 drivers/hwmon/ina3221.c                       | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property
  2019-01-17 23:12 [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
@ 2019-01-17 23:12 ` Nicolin Chen
  2019-01-17 23:12 ` [PATCH v3 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Nicolin Chen
  2019-01-17 23:36 ` [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolin Chen @ 2019-01-17 23:12 UTC (permalink / raw)
  To: jdelvare, linux
  Cc: robh+dt, mark.rutland, linux-hwmon, devicetree, linux-kernel

By default, ina3221, as a hardware monitor, continuously measures
the inputs and generates corresponding data. However, for battery
powered devices, this mode might be power consuming.

This patch adds a "ti,single-shot" property to allow changing the
default continuous mode to single-shot operating mode.

Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
Changelog
v2->v3:
 * Added "Reviewed-by" from Rob
v1->v2:
 * N/A

 Documentation/devicetree/bindings/hwmon/ina3221.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/devicetree/bindings/hwmon/ina3221.txt b/Documentation/devicetree/bindings/hwmon/ina3221.txt
index a7b25caa2b8e..fa63b6171407 100644
--- a/Documentation/devicetree/bindings/hwmon/ina3221.txt
+++ b/Documentation/devicetree/bindings/hwmon/ina3221.txt
@@ -6,6 +6,16 @@ Texas Instruments INA3221 Device Tree Bindings
   - reg: I2C address
 
   Optional properties:
+  - ti,single-shot: This chip has two power modes: single-shot (chip takes one
+                    measurement and then shuts itself down) and continuous (
+                    chip takes continuous measurements). The continuous mode is
+                    more reliable and suitable for hardware monitor type device,
+                    but the single-shot mode is more power-friendly and useful
+                    for battery-powered device which cares power consumptions
+                    while still needs some measurements occasionally.
+                    If this property is present, the single-shot mode will be
+                    used, instead of the default continuous one for monitoring.
+
   = The node contains optional child nodes for three channels =
   = Each child node describes the information of input source =
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/2] hwmon: (ina3221) Implement ti,single-shot DT property
  2019-01-17 23:12 [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
  2019-01-17 23:12 ` [PATCH v3 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
@ 2019-01-17 23:12 ` Nicolin Chen
  2019-01-17 23:36 ` [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolin Chen @ 2019-01-17 23:12 UTC (permalink / raw)
  To: jdelvare, linux
  Cc: robh+dt, mark.rutland, linux-hwmon, devicetree, linux-kernel

By default, ina3221, as a hardware monitor, continuously measures
the inputs and generates corresponding data. However, for battery
powered devices, this mode might be power consuming.

The DT binding doc is updated with a new boolean type property to
allow changing the default operating mode from consuming mode to
single-shot mode, which will measure input on demand and then shut
down to save power.

So this patch implements the DT property accordingly.

Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
---
Changelog
v2->v3:
 * Dropped useless if condition by using the return value directly.
v1->v2:
 * Replaced the useless mode defines with a boolean variable.

 drivers/hwmon/ina3221.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index e90ccac8bebb..a1e94d5d1e41 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -111,6 +111,7 @@ struct ina3221_input {
  * @inputs: Array of channel input source specific structures
  * @lock: mutex lock to serialize sysfs attribute accesses
  * @reg_config: Register value of INA3221_CONFIG
+ * @single_shot: running in single-shot operating mode
  */
 struct ina3221_data {
 	struct device *pm_dev;
@@ -119,6 +120,8 @@ struct ina3221_data {
 	struct ina3221_input inputs[INA3221_NUM_CHANNELS];
 	struct mutex lock;
 	u32 reg_config;
+
+	bool single_shot;
 };
 
 static inline bool ina3221_is_enabled(struct ina3221_data *ina, int channel)
@@ -188,6 +191,11 @@ static int ina3221_read_in(struct device *dev, u32 attr, int channel, long *val)
 		if (!ina3221_is_enabled(ina, channel))
 			return -ENODATA;
 
+		/* Write CONFIG register to trigger a single-shot measurement */
+		if (ina->single_shot)
+			regmap_write(ina->regmap, INA3221_CONFIG,
+				     ina->reg_config);
+
 		ret = ina3221_wait_for_data(ina);
 		if (ret)
 			return ret;
@@ -232,6 +240,11 @@ static int ina3221_read_curr(struct device *dev, u32 attr,
 		if (!ina3221_is_enabled(ina, channel))
 			return -ENODATA;
 
+		/* Write CONFIG register to trigger a single-shot measurement */
+		if (ina->single_shot)
+			regmap_write(ina->regmap, INA3221_CONFIG,
+				     ina->reg_config);
+
 		ret = ina3221_wait_for_data(ina);
 		if (ret)
 			return ret;
@@ -617,6 +630,8 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
 	if (!np)
 		return 0;
 
+	ina->single_shot = of_property_read_bool(np, "ti,single-shot");
+
 	for_each_child_of_node(np, child) {
 		ret = ina3221_probe_child_from_dt(dev, child, ina);
 		if (ret)
@@ -666,6 +681,10 @@ static int ina3221_probe(struct i2c_client *client,
 	/* The driver will be reset, so use reset value */
 	ina->reg_config = INA3221_CONFIG_DEFAULT;
 
+	/* Clear continuous bit to use single-shot mode */
+	if (ina->single_shot)
+		ina->reg_config &= ~INA3221_CONFIG_MODE_CONTINUOUS;
+
 	/* Disable channels if their inputs are disconnected */
 	for (i = 0; i < INA3221_NUM_CHANNELS; i++) {
 		if (ina->inputs[i].disconnected)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support
  2019-01-17 23:12 [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
  2019-01-17 23:12 ` [PATCH v3 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
  2019-01-17 23:12 ` [PATCH v3 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Nicolin Chen
@ 2019-01-17 23:36 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2019-01-17 23:36 UTC (permalink / raw)
  To: Nicolin Chen
  Cc: jdelvare, robh+dt, mark.rutland, linux-hwmon, devicetree, linux-kernel

On Thu, Jan 17, 2019 at 03:12:51PM -0800, Nicolin Chen wrote:
> By default, ina3221, as a hardware monitor, continuously measures
> the inputs and generates corresponding data. However, for battery
> powered devices, this mode might be power consuming.
> 
> This series of patches add a feature of changing default operating
> mode to its single-shot mode via DT.
> 
> Changelog
> v2->v3:
>  * Added "Reviewed-by" from Rob to PATCH-1
>  * Cleaned-up PATCH-2
> v1->v2:
>  * Cleaned-up PATCH-2
> 
> Nicolin Chen (2):
>   dt-bindings: hwmon: ina3221: Add ti,single-shot property
>   hwmon: (ina3221) Implement ti,single-shot DT property
> 
>  .../devicetree/bindings/hwmon/ina3221.txt     | 10 ++++++++++
>  drivers/hwmon/ina3221.c                       | 19 +++++++++++++++++++
>  2 files changed, 29 insertions(+)
> 
Series applied to hwmon-next.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-17 23:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17 23:12 [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
2019-01-17 23:12 ` [PATCH v3 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
2019-01-17 23:12 ` [PATCH v3 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Nicolin Chen
2019-01-17 23:36 ` [PATCH v3 0/2] hwmon (ina3221) Add single-shot mode support Guenter Roeck

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).