Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v1] hwmon: (iio_hwmon) Enable power exporting from IIO
@ 2019-08-22 14:22 Michal Simek
  2019-08-31 15:06 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Michal Simek @ 2019-08-22 14:22 UTC (permalink / raw)
  To: linux-kernel, monstr, michal.simek
  Cc: Guenter Roeck, Jean Delvare, linux-hwmon

There is no reason why power channel shouldn't be exported as is done for
voltage, current, temperature and humidity.

Power channel is available on iio ina226 driver.

Sysfs IIO documentation for power attribute added by commit 7c6d5c7ee883
("iio: Documentation: Add missing documentation for power attribute")
is declaring that value is in mili-Watts but hwmon interface is expecting
value in micro-Watts that's why there is a need for mili-Watts to
micro-Watts conversion.

Tested on Xilinx ZCU102 board.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

Changes in v1:
- from RFC - fix power conversion mili-Watts to micro-Watts

 drivers/hwmon/iio_hwmon.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
index f1c2d5faedf0..b85a125dd86f 100644
--- a/drivers/hwmon/iio_hwmon.c
+++ b/drivers/hwmon/iio_hwmon.c
@@ -44,12 +44,20 @@ static ssize_t iio_hwmon_read_val(struct device *dev,
 	int ret;
 	struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
 	struct iio_hwmon_state *state = dev_get_drvdata(dev);
+	struct iio_channel *chan = &state->channels[sattr->index];
+	enum iio_chan_type type;
+
+	ret = iio_read_channel_processed(chan, &result);
+	if (ret < 0)
+		return ret;
 
-	ret = iio_read_channel_processed(&state->channels[sattr->index],
-					&result);
+	ret = iio_get_channel_type(chan, &type);
 	if (ret < 0)
 		return ret;
 
+	if (type == IIO_POWER)
+		result *= 1000; /* mili-Watts to micro-Watts conversion */
+
 	return sprintf(buf, "%d\n", result);
 }
 
@@ -59,7 +67,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
 	struct iio_hwmon_state *st;
 	struct sensor_device_attribute *a;
 	int ret, i;
-	int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1;
+	int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1, power_i = 1;
 	enum iio_chan_type type;
 	struct iio_channel *channels;
 	struct device *hwmon_dev;
@@ -114,6 +122,10 @@ static int iio_hwmon_probe(struct platform_device *pdev)
 			n = curr_i++;
 			prefix = "curr";
 			break;
+		case IIO_POWER:
+			n = power_i++;
+			prefix = "power";
+			break;
 		case IIO_HUMIDITYRELATIVE:
 			n = humidity_i++;
 			prefix = "humidity";
-- 
2.17.1


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

* Re: [PATCH v1] hwmon: (iio_hwmon) Enable power exporting from IIO
  2019-08-22 14:22 [PATCH v1] hwmon: (iio_hwmon) Enable power exporting from IIO Michal Simek
@ 2019-08-31 15:06 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2019-08-31 15:06 UTC (permalink / raw)
  To: Michal Simek; +Cc: linux-kernel, monstr, Jean Delvare, linux-hwmon

On Thu, Aug 22, 2019 at 04:22:24PM +0200, Michal Simek wrote:
> There is no reason why power channel shouldn't be exported as is done for
> voltage, current, temperature and humidity.
> 
> Power channel is available on iio ina226 driver.
> 
> Sysfs IIO documentation for power attribute added by commit 7c6d5c7ee883
> ("iio: Documentation: Add missing documentation for power attribute")
> is declaring that value is in mili-Watts but hwmon interface is expecting
> value in micro-Watts that's why there is a need for mili-Watts to
> micro-Watts conversion.
> 
> Tested on Xilinx ZCU102 board.
> 
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>

Applied to hwmon-next.

Thanks,
Guenter

> ---
> 
> Changes in v1:
> - from RFC - fix power conversion mili-Watts to micro-Watts
> 
>  drivers/hwmon/iio_hwmon.c | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
> index f1c2d5faedf0..b85a125dd86f 100644
> --- a/drivers/hwmon/iio_hwmon.c
> +++ b/drivers/hwmon/iio_hwmon.c
> @@ -44,12 +44,20 @@ static ssize_t iio_hwmon_read_val(struct device *dev,
>  	int ret;
>  	struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
>  	struct iio_hwmon_state *state = dev_get_drvdata(dev);
> +	struct iio_channel *chan = &state->channels[sattr->index];
> +	enum iio_chan_type type;
> +
> +	ret = iio_read_channel_processed(chan, &result);
> +	if (ret < 0)
> +		return ret;
>  
> -	ret = iio_read_channel_processed(&state->channels[sattr->index],
> -					&result);
> +	ret = iio_get_channel_type(chan, &type);
>  	if (ret < 0)
>  		return ret;
>  
> +	if (type == IIO_POWER)
> +		result *= 1000; /* mili-Watts to micro-Watts conversion */
> +
>  	return sprintf(buf, "%d\n", result);
>  }
>  
> @@ -59,7 +67,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
>  	struct iio_hwmon_state *st;
>  	struct sensor_device_attribute *a;
>  	int ret, i;
> -	int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1;
> +	int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1, power_i = 1;
>  	enum iio_chan_type type;
>  	struct iio_channel *channels;
>  	struct device *hwmon_dev;
> @@ -114,6 +122,10 @@ static int iio_hwmon_probe(struct platform_device *pdev)
>  			n = curr_i++;
>  			prefix = "curr";
>  			break;
> +		case IIO_POWER:
> +			n = power_i++;
> +			prefix = "power";
> +			break;
>  		case IIO_HUMIDITYRELATIVE:
>  			n = humidity_i++;
>  			prefix = "humidity";

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 14:22 [PATCH v1] hwmon: (iio_hwmon) Enable power exporting from IIO Michal Simek
2019-08-31 15:06 ` Guenter Roeck

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