* [PATCH] hwmon: (max1111) change sysfs interface to in[0-3]_input in millivolts
@ 2011-11-09 13:01 Eric Miao
0 siblings, 0 replies; 2+ messages in thread
From: Eric Miao @ 2011-11-09 13:01 UTC (permalink / raw)
To: linux-kernel, lm-sensors; +Cc: Eric Miao
This patch fixed the inconsistent max1111 sysfs interface as pointed
out by Jean Delvare:
It was pointed to me that the max1111 driver doesn't implement the
standard sysfs interface for hwmon drivers (as described in
Documentation/hwmon/sysfs-interface). It exports files adc[0-3]_in,
which
aren't part of the standard interface. Presumably these should be
renamed to in[0-3]_input. Renaming them is probably not sufficient
though, as I see no scaling done in the driver. As the MAX1111 chip has
a documented full scale of 2.048V, I take it that the LSB of the ADC
has a weight of 8 mV. Exporting raw register values to user-space is
not OK.
Reported-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Eric Miao <eric.y.miao@gmail.com>
---
drivers/hwmon/max1111.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
index c97b78e..5586cca 100644
--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -106,11 +106,14 @@ static ssize_t show_adc(struct device *dev,
if (ret < 0)
return ret;
- return sprintf(buf, "%d\n", ret);
+ /* assume the reference voltage to be 2.048V, with an 8-bit sample,
+ * the LSB weight is 8mV
+ */
+ return sprintf(buf, "%d\n", ret * 8);
}
#define MAX1111_ADC_ATTR(_id) \
- SENSOR_DEVICE_ATTR(adc##_id##_in, S_IRUGO, show_adc, NULL, _id)
+ SENSOR_DEVICE_ATTR(in##_id##_input, S_IRUGO, show_adc, NULL, _id)
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
static MAX1111_ADC_ATTR(0);
@@ -120,10 +123,10 @@ static MAX1111_ADC_ATTR(3);
static struct attribute *max1111_attributes[] = {
&dev_attr_name.attr,
- &sensor_dev_attr_adc0_in.dev_attr.attr,
- &sensor_dev_attr_adc1_in.dev_attr.attr,
- &sensor_dev_attr_adc2_in.dev_attr.attr,
- &sensor_dev_attr_adc3_in.dev_attr.attr,
+ &sensor_dev_attr_in0_input.dev_attr.attr,
+ &sensor_dev_attr_in1_input.dev_attr.attr,
+ &sensor_dev_attr_in2_input.dev_attr.attr,
+ &sensor_dev_attr_in3_input.dev_attr.attr,
NULL,
};
--
1.7.5.4
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH] hwmon: (max1111) change sysfs interface to in[0-3]_input in millivolts
@ 2011-11-09 11:15 Eric Miao
0 siblings, 0 replies; 2+ messages in thread
From: Eric Miao @ 2011-11-09 11:15 UTC (permalink / raw)
To: linux-kernel, lm-sensors; +Cc: Eric Miao
This patch fixed the inconsistent max1111 sysfs interface as pointed
out by Jean Delvare:
It was pointed to me that the max1111 driver doesn't implement the
standard sysfs interface for hwmon drivers (as described in
Documentation/hwmon/sysfs-interface). It exports files adc[0-3]_in,
which
aren't part of the standard interface. Presumably these should be
renamed to in[0-3]_input. Renaming them is probably not sufficient
though, as I see no scaling done in the driver. As the MAX1111 chip has
a documented full scale of 2.048V, I take it that the LSB of the ADC
has a weight of 8 mV. Exporting raw register values to user-space is
not OK.
Reported-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Eric Miao <eric.y.miao@gmail.com>
---
drivers/hwmon/max1111.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
index c97b78e..0e9fcfd 100644
--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -106,11 +106,12 @@ static ssize_t show_adc(struct device *dev,
if (ret < 0)
return ret;
- return sprintf(buf, "%d\n", ret);
+ /* assume the reference voltage to be 2.048V */
+ return sprintf(buf, "%d\n", 2048 * 256 / ret);
}
#define MAX1111_ADC_ATTR(_id) \
- SENSOR_DEVICE_ATTR(adc##_id##_in, S_IRUGO, show_adc, NULL, _id)
+ SENSOR_DEVICE_ATTR(in##_id##_input, S_IRUGO, show_adc, NULL, _id)
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
static MAX1111_ADC_ATTR(0);
@@ -120,10 +121,10 @@ static MAX1111_ADC_ATTR(3);
static struct attribute *max1111_attributes[] = {
&dev_attr_name.attr,
- &sensor_dev_attr_adc0_in.dev_attr.attr,
- &sensor_dev_attr_adc1_in.dev_attr.attr,
- &sensor_dev_attr_adc2_in.dev_attr.attr,
- &sensor_dev_attr_adc3_in.dev_attr.attr,
+ &sensor_dev_attr_in0_input.dev_attr.attr,
+ &sensor_dev_attr_in1_input.dev_attr.attr,
+ &sensor_dev_attr_in2_input.dev_attr.attr,
+ &sensor_dev_attr_in3_input.dev_attr.attr,
NULL,
};
--
1.7.5.4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-11-09 13:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-09 13:01 [PATCH] hwmon: (max1111) change sysfs interface to in[0-3]_input in millivolts Eric Miao
-- strict thread matches above, loose matches on Subject: below --
2011-11-09 11:15 Eric Miao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®