summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Simek <michal.simek@xilinx.com>2019-08-22 10:22:24 -0400
committerGuenter Roeck <linux@roeck-us.net>2019-09-03 15:47:17 -0400
commitbc34301b10672dcc86cc3d93cfbf785eba16ddbe (patch)
treedfd936c119a4da2864eb74017916eae3608308b2
parentbe7ec9196bc487771415ba063188e6356625f703 (diff)
hwmon: (iio_hwmon) Enable power exporting from IIO
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> Link: https://lore.kernel.org/r/db71f5ae87e4521a2856a1be5544de0b6cede575.1566483741.git.michal.simek@xilinx.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/iio_hwmon.c18
1 files 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,
44 int ret; 44 int ret;
45 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 45 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
46 struct iio_hwmon_state *state = dev_get_drvdata(dev); 46 struct iio_hwmon_state *state = dev_get_drvdata(dev);
47 struct iio_channel *chan = &state->channels[sattr->index];
48 enum iio_chan_type type;
49
50 ret = iio_read_channel_processed(chan, &result);
51 if (ret < 0)
52 return ret;
47 53
48 ret = iio_read_channel_processed(&state->channels[sattr->index], 54 ret = iio_get_channel_type(chan, &type);
49 &result);
50 if (ret < 0) 55 if (ret < 0)
51 return ret; 56 return ret;
52 57
58 if (type == IIO_POWER)
59 result *= 1000; /* mili-Watts to micro-Watts conversion */
60
53 return sprintf(buf, "%d\n", result); 61 return sprintf(buf, "%d\n", result);
54} 62}
55 63
@@ -59,7 +67,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
59 struct iio_hwmon_state *st; 67 struct iio_hwmon_state *st;
60 struct sensor_device_attribute *a; 68 struct sensor_device_attribute *a;
61 int ret, i; 69 int ret, i;
62 int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1; 70 int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1, power_i = 1;
63 enum iio_chan_type type; 71 enum iio_chan_type type;
64 struct iio_channel *channels; 72 struct iio_channel *channels;
65 struct device *hwmon_dev; 73 struct device *hwmon_dev;
@@ -114,6 +122,10 @@ static int iio_hwmon_probe(struct platform_device *pdev)
114 n = curr_i++; 122 n = curr_i++;
115 prefix = "curr"; 123 prefix = "curr";
116 break; 124 break;
125 case IIO_POWER:
126 n = power_i++;
127 prefix = "power";
128 break;
117 case IIO_HUMIDITYRELATIVE: 129 case IIO_HUMIDITYRELATIVE:
118 n = humidity_i++; 130 n = humidity_i++;
119 prefix = "humidity"; 131 prefix = "humidity";