Linux-Hwmon Archive on lore.kernel.org
 help / Atom feed
* [PATCH 0/2] hwmon (ina3221) Add single-shot mode support
  2019-01-05  0:50 [PATCH 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
@ 2019-01-05  0:49 ` Nicolin Chen
  2019-01-05  0:50 ` [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Nicolin Chen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Nicolin Chen @ 2019-01-05  0:49 UTC (permalink / raw)
  To: jdelvare, linux, robh+dt, mark.rutland
  Cc: 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.

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                       | 28 +++++++++++++++++++
 2 files changed, 38 insertions(+)

-- 
2.17.1


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

* [PATCH 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property
  2019-01-05  0:50 ` [PATCH 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
@ 2019-01-05  0:49   ` Nicolin Chen
  2019-01-11 21:31   ` Rob Herring
  1 sibling, 0 replies; 11+ messages in thread
From: Nicolin Chen @ 2019-01-05  0:49 UTC (permalink / raw)
  To: jdelvare, linux, robh+dt, mark.rutland
  Cc: 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>
---
 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	[flat|nested] 11+ messages in thread

* [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property
  2019-01-05  0:50 ` [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Nicolin Chen
@ 2019-01-05  0:49   ` Nicolin Chen
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolin Chen @ 2019-01-05  0:49 UTC (permalink / raw)
  To: jdelvare, linux, robh+dt, mark.rutland
  Cc: 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>
---
 drivers/hwmon/ina3221.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index e90ccac8bebb..152735659e19 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -91,6 +91,12 @@ enum ina3221_channels {
 	INA3221_NUM_CHANNELS
 };
 
+enum ina3221_modes {
+	INA3221_MODE_SINGLE_SHOT,
+	INA3221_MODE_CONTINUOUS,
+	INA3221_NUM_MODES,
+};
+
 /**
  * struct ina3221_input - channel input source specific information
  * @label: label of channel input source
@@ -111,6 +117,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
+ * @mode: Operating mode -- continuous or single-shot
  */
 struct ina3221_data {
 	struct device *pm_dev;
@@ -119,6 +126,7 @@ struct ina3221_data {
 	struct ina3221_input inputs[INA3221_NUM_CHANNELS];
 	struct mutex lock;
 	u32 reg_config;
+	enum ina3221_modes mode;
 };
 
 static inline bool ina3221_is_enabled(struct ina3221_data *ina, int channel)
@@ -188,6 +196,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->mode == INA3221_MODE_SINGLE_SHOT)
+			regmap_write(ina->regmap, INA3221_CONFIG,
+				     ina->reg_config);
+
 		ret = ina3221_wait_for_data(ina);
 		if (ret)
 			return ret;
@@ -232,6 +245,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->mode == INA3221_MODE_SINGLE_SHOT)
+			regmap_write(ina->regmap, INA3221_CONFIG,
+				     ina->reg_config);
+
 		ret = ina3221_wait_for_data(ina);
 		if (ret)
 			return ret;
@@ -617,6 +635,9 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
 	if (!np)
 		return 0;
 
+	if (of_property_read_bool(np, "ti,single-shot"))
+		ina->mode = INA3221_MODE_SINGLE_SHOT;
+
 	for_each_child_of_node(np, child) {
 		ret = ina3221_probe_child_from_dt(dev, child, ina);
 		if (ret)
@@ -654,6 +675,9 @@ static int ina3221_probe(struct i2c_client *client,
 		}
 	}
 
+	/* Hardware default uses the continuous mode */
+	ina->mode = INA3221_MODE_CONTINUOUS;
+
 	for (i = 0; i < INA3221_NUM_CHANNELS; i++)
 		ina->inputs[i].shunt_resistor = INA3221_RSHUNT_DEFAULT;
 
@@ -666,6 +690,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->mode == INA3221_MODE_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	[flat|nested] 11+ messages in thread

* [PATCH 0/2] hwmon (ina3221) Add single-shot mode support
@ 2019-01-05  0:50 Nicolin Chen
  2019-01-05  0:49 ` Nicolin Chen
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Nicolin Chen @ 2019-01-05  0:50 UTC (permalink / raw)
  To: linux-hwmon

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.

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                       | 28 +++++++++++++++++++
 2 files changed, 38 insertions(+)

-- 
2.17.1

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

* [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property
  2019-01-05  0:50 [PATCH 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
  2019-01-05  0:49 ` Nicolin Chen
@ 2019-01-05  0:50 ` Nicolin Chen
  2019-01-05  0:49   ` Nicolin Chen
  2019-01-05  0:50 ` [PATCH 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Nicolin Chen @ 2019-01-05  0:50 UTC (permalink / raw)
  To: linux-hwmon

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 <nicoleots...@gmail.com>
---
 drivers/hwmon/ina3221.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index e90ccac8bebb..152735659e19 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -91,6 +91,12 @@ enum ina3221_channels {
        INA3221_NUM_CHANNELS
 };
 
+enum ina3221_modes {
+       INA3221_MODE_SINGLE_SHOT,
+       INA3221_MODE_CONTINUOUS,
+       INA3221_NUM_MODES,
+};
+
 /**
  * struct ina3221_input - channel input source specific information
  * @label: label of channel input source
@@ -111,6 +117,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
+ * @mode: Operating mode -- continuous or single-shot
  */
 struct ina3221_data {
        struct device *pm_dev;
@@ -119,6 +126,7 @@ struct ina3221_data {
        struct ina3221_input inputs[INA3221_NUM_CHANNELS];
        struct mutex lock;
        u32 reg_config;
+       enum ina3221_modes mode;
 };
 
 static inline bool ina3221_is_enabled(struct ina3221_data *ina, int channel)
@@ -188,6 +196,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->mode == INA3221_MODE_SINGLE_SHOT)
+                       regmap_write(ina->regmap, INA3221_CONFIG,
+                                    ina->reg_config);
+
                ret = ina3221_wait_for_data(ina);
                if (ret)
                        return ret;
@@ -232,6 +245,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->mode == INA3221_MODE_SINGLE_SHOT)
+                       regmap_write(ina->regmap, INA3221_CONFIG,
+                                    ina->reg_config);
+
                ret = ina3221_wait_for_data(ina);
                if (ret)
                        return ret;
@@ -617,6 +635,9 @@ static int ina3221_probe_from_dt(struct device *dev, struct 
ina3221_data *ina)
        if (!np)
                return 0;
 
+       if (of_property_read_bool(np, "ti,single-shot"))
+               ina->mode = INA3221_MODE_SINGLE_SHOT;
+
        for_each_child_of_node(np, child) {
                ret = ina3221_probe_child_from_dt(dev, child, ina);
                if (ret)
@@ -654,6 +675,9 @@ static int ina3221_probe(struct i2c_client *client,
                }
        }
 
+       /* Hardware default uses the continuous mode */
+       ina->mode = INA3221_MODE_CONTINUOUS;
+
        for (i = 0; i < INA3221_NUM_CHANNELS; i++)
                ina->inputs[i].shunt_resistor = INA3221_RSHUNT_DEFAULT;
 
@@ -666,6 +690,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->mode == INA3221_MODE_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	[flat|nested] 11+ messages in thread

* [PATCH 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property
  2019-01-05  0:50 [PATCH 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
  2019-01-05  0:49 ` Nicolin Chen
  2019-01-05  0:50 ` [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Nicolin Chen
@ 2019-01-05  0:50 ` Nicolin Chen
  2019-01-05  0:49   ` Nicolin Chen
  2019-01-11 21:31   ` Rob Herring
  2019-01-05  2:38 ` [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Guenter Roeck
  2019-01-05  2:48 ` Nicolin Chen
  4 siblings, 2 replies; 11+ messages in thread
From: Nicolin Chen @ 2019-01-05  0:50 UTC (permalink / raw)
  To: linux-hwmon

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 <nicoleots...@gmail.com>
---
 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	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property
  2019-01-05  2:38 ` [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Guenter Roeck
@ 2019-01-05  2:37   ` Guenter Roeck
  0 siblings, 0 replies; 11+ messages in thread
From: Guenter Roeck @ 2019-01-05  2:37 UTC (permalink / raw)
  To: Nicolin Chen, jdelvare, robh+dt, mark.rutland
  Cc: linux-hwmon, devicetree, linux-kernel

On 1/4/19 4:49 PM, 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.
> 
> 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>
> ---
>   drivers/hwmon/ina3221.c | 28 ++++++++++++++++++++++++++++
>   1 file changed, 28 insertions(+)
> 
> diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
> index e90ccac8bebb..152735659e19 100644
> --- a/drivers/hwmon/ina3221.c
> +++ b/drivers/hwmon/ina3221.c
> @@ -91,6 +91,12 @@ enum ina3221_channels {
>   	INA3221_NUM_CHANNELS
>   };
>   
> +enum ina3221_modes {
> +	INA3221_MODE_SINGLE_SHOT,
> +	INA3221_MODE_CONTINUOUS,
> +	INA3221_NUM_MODES,

Is NUM_MODES used anywhere ? Please drop unless there is a reason to keep it.

Guenter

> +};
> +
>   /**
>    * struct ina3221_input - channel input source specific information
>    * @label: label of channel input source
> @@ -111,6 +117,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
> + * @mode: Operating mode -- continuous or single-shot
>    */
>   struct ina3221_data {
>   	struct device *pm_dev;
> @@ -119,6 +126,7 @@ struct ina3221_data {
>   	struct ina3221_input inputs[INA3221_NUM_CHANNELS];
>   	struct mutex lock;
>   	u32 reg_config;
> +	enum ina3221_modes mode;
>   };
>   
>   static inline bool ina3221_is_enabled(struct ina3221_data *ina, int channel)
> @@ -188,6 +196,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->mode == INA3221_MODE_SINGLE_SHOT)
> +			regmap_write(ina->regmap, INA3221_CONFIG,
> +				     ina->reg_config);
> +
>   		ret = ina3221_wait_for_data(ina);
>   		if (ret)
>   			return ret;
> @@ -232,6 +245,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->mode == INA3221_MODE_SINGLE_SHOT)
> +			regmap_write(ina->regmap, INA3221_CONFIG,
> +				     ina->reg_config);
> +
>   		ret = ina3221_wait_for_data(ina);
>   		if (ret)
>   			return ret;
> @@ -617,6 +635,9 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
>   	if (!np)
>   		return 0;
>   
> +	if (of_property_read_bool(np, "ti,single-shot"))
> +		ina->mode = INA3221_MODE_SINGLE_SHOT;
> +
>   	for_each_child_of_node(np, child) {
>   		ret = ina3221_probe_child_from_dt(dev, child, ina);
>   		if (ret)
> @@ -654,6 +675,9 @@ static int ina3221_probe(struct i2c_client *client,
>   		}
>   	}
>   
> +	/* Hardware default uses the continuous mode */
> +	ina->mode = INA3221_MODE_CONTINUOUS;
> +
>   	for (i = 0; i < INA3221_NUM_CHANNELS; i++)
>   		ina->inputs[i].shunt_resistor = INA3221_RSHUNT_DEFAULT;
>   
> @@ -666,6 +690,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->mode == INA3221_MODE_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)
> 


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

* Re: [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property
  2019-01-05  0:50 [PATCH 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
                   ` (2 preceding siblings ...)
  2019-01-05  0:50 ` [PATCH 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
@ 2019-01-05  2:38 ` Guenter Roeck
  2019-01-05  2:37   ` Guenter Roeck
  2019-01-05  2:48 ` Nicolin Chen
  4 siblings, 1 reply; 11+ messages in thread
From: Guenter Roeck @ 2019-01-05  2:38 UTC (permalink / raw)
  To: linux-hwmon


On 1/4/19 4:49 PM, 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.

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 <nicoleots...@gmail.com>
---
  drivers/hwmon/ina3221.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)

diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index e90ccac8bebb..152735659e19 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -91,6 +91,12 @@ enum ina3221_channels {
        INA3221_NUM_CHANNELS
  };
  
+enum ina3221_modes {

+       INA3221_MODE_SINGLE_SHOT,
+       INA3221_MODE_CONTINUOUS,
+       INA3221_NUM_MODES,


Is NUM_MODES used anywhere ? Please drop unless there is a reason to keep it.

Guenter


+};
+
  /**
   * struct ina3221_input - channel input source specific information
   * @label: label of channel input source
@@ -111,6 +117,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
+ * @mode: Operating mode -- continuous or single-shot
   */
  struct ina3221_data {
        struct device *pm_dev;
@@ -119,6 +126,7 @@ struct ina3221_data {
        struct ina3221_input inputs[INA3221_NUM_CHANNELS];
        struct mutex lock;
        u32 reg_config;
+       enum ina3221_modes mode;
  };
  
  static inline bool ina3221_is_enabled(struct ina3221_data *ina, int channel)

@@ -188,6 +196,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->mode == INA3221_MODE_SINGLE_SHOT)
+                       regmap_write(ina->regmap, INA3221_CONFIG,
+                                    ina->reg_config);
+
                ret = ina3221_wait_for_data(ina);
                if (ret)
                        return ret;
@@ -232,6 +245,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->mode == INA3221_MODE_SINGLE_SHOT)
+                       regmap_write(ina->regmap, INA3221_CONFIG,
+                                    ina->reg_config);
+
                ret = ina3221_wait_for_data(ina);
                if (ret)
                        return ret;
@@ -617,6 +635,9 @@ static int ina3221_probe_from_dt(struct device *dev, struct 
ina3221_data *ina)
        if (!np)
                return 0;
  
+	if (of_property_read_bool(np, "ti,single-shot"))

+               ina->mode = INA3221_MODE_SINGLE_SHOT;
+
        for_each_child_of_node(np, child) {
                ret = ina3221_probe_child_from_dt(dev, child, ina);
                if (ret)
@@ -654,6 +675,9 @@ static int ina3221_probe(struct i2c_client *client,
                }
        }
  
+	/* Hardware default uses the continuous mode */

+       ina->mode = INA3221_MODE_CONTINUOUS;
+
        for (i = 0; i < INA3221_NUM_CHANNELS; i++)
                ina->inputs[i].shunt_resistor = INA3221_RSHUNT_DEFAULT;
  
@@ -666,6 +690,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->mode == INA3221_MODE_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)

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

* Re: [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property
  2019-01-05  2:48 ` Nicolin Chen
@ 2019-01-05  2:48   ` Nicolin Chen
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolin Chen @ 2019-01-05  2:48 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: jdelvare, robh+dt, mark.rutland, linux-hwmon, devicetree, linux-kernel

On Fri, Jan 04, 2019 at 06:37:55PM -0800, Guenter Roeck wrote:
> > +enum ina3221_modes {
> > +	INA3221_MODE_SINGLE_SHOT,
> > +	INA3221_MODE_CONTINUOUS,
> > +	INA3221_NUM_MODES,
> 
> Is NUM_MODES used anywhere ? Please drop unless there is a reason to keep it.

Will clean it up in v2.

Thanks
Nicolin

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

* Re: [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property
  2019-01-05  0:50 [PATCH 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
                   ` (3 preceding siblings ...)
  2019-01-05  2:38 ` [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Guenter Roeck
@ 2019-01-05  2:48 ` Nicolin Chen
  2019-01-05  2:48   ` Nicolin Chen
  4 siblings, 1 reply; 11+ messages in thread
From: Nicolin Chen @ 2019-01-05  2:48 UTC (permalink / raw)
  To: linux-hwmon

On Fri, Jan 04, 2019 at 06:37:55PM -0800, Guenter Roeck wrote:
> > +enum ina3221_modes {
> > +   INA3221_MODE_SINGLE_SHOT,
> > +   INA3221_MODE_CONTINUOUS,
> > +   INA3221_NUM_MODES,
> 
> Is NUM_MODES used anywhere ? Please drop unless there is a reason to keep it.

Will clean it up in v2.

Thanks
Nicolin

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

* Re: [PATCH 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property
  2019-01-05  0:50 ` [PATCH 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
  2019-01-05  0:49   ` Nicolin Chen
@ 2019-01-11 21:31   ` Rob Herring
  1 sibling, 0 replies; 11+ messages in thread
From: Rob Herring @ 2019-01-11 21:31 UTC (permalink / raw)
  To: Nicolin Chen
  Cc: jdelvare, linux, robh+dt, mark.rutland, linux-hwmon, devicetree,
	linux-kernel

On Fri,  4 Jan 2019 16:49:03 -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 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>
> ---
>  Documentation/devicetree/bindings/hwmon/ina3221.txt | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

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

end of thread, back to index

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-05  0:50 [PATCH 0/2] hwmon (ina3221) Add single-shot mode support Nicolin Chen
2019-01-05  0:49 ` Nicolin Chen
2019-01-05  0:50 ` [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Nicolin Chen
2019-01-05  0:49   ` Nicolin Chen
2019-01-05  0:50 ` [PATCH 1/2] dt-bindings: hwmon: ina3221: Add ti,single-shot property Nicolin Chen
2019-01-05  0:49   ` Nicolin Chen
2019-01-11 21:31   ` Rob Herring
2019-01-05  2:38 ` [PATCH 2/2] hwmon: (ina3221) Implement ti,single-shot DT property Guenter Roeck
2019-01-05  2:37   ` Guenter Roeck
2019-01-05  2:48 ` Nicolin Chen
2019-01-05  2:48   ` Nicolin Chen

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org linux-hwmon@archiver.kernel.org
	public-inbox-index linux-hwmon


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/ public-inbox