Skip to contentSkip to conversation

hwmon: (max1111) change sysfs interface to in[0-3]_input in millivolts

PATCH In review Eric Miao 2 participants 5 messages Nov 9, 2011 Hardware monitoring

lore
Share & tools
lore

Eric Miao

author
#0 lore raw

PATCH 1/1 hwmon: (max1111) change sysfs interface to in[0-3]_input in millivolts

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.

---
 drivers/hwmon/max1111.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/hwmon/max1111.c +7 -6
index c97b78e..0e9fcfd 100644
@@ -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,
 };
 
Signature · 1 line
1.7.5.4
#1 lore raw

Hi Eric,

Quoted 25 lines · 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.

---
 drivers/hwmon/max1111.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/hwmon/max1111.c +0 -0
index c97b78e..0e9fcfd 100644

drivers/hwmon/max1111.c static ssize_t show_adc(struct device *dev, · line 110

Quoted 6 lines
drivers/hwmon/max1111.c +2 -1
@@ -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);

I bet you did not actually test your changes? ret == 0 would obviously crash the driver. The formula looks wrong anyway, should be 2048 * ret / 256. Or in short ret * 8, i.e. LSB weight of the ADC is 8 mV.

Quoted 13 lines
drivers/hwmon/max1111.c +1 -2
 }
 
 #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,

drivers/hwmon/max1111.c static MAX1111_ADC_ATTR(3); · line 130

Quoted 10 lines
drivers/hwmon/max1111.c +4 -3
-	&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,
 };
 

The rest of the changes look good.

Signature · 1 line
Jean Delvare
author
#2 lore raw
Quoted 31 lines · Jean Delvare

Hi Eric,

Quoted 28 lines · 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.

---
 drivers/hwmon/max1111.c |   13 +++++++------

 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/hwmon/max1111.c +0 -0
index c97b78e..0e9fcfd 100644
@@ -106,11 +106,12 @@ static ssize_t show_adc(struct device *dev,
       if (ret < 0)
               return ret;
 
Quoted 8 lines

drivers/hwmon/max1111.c static ssize_t show_adc(struct device *dev, · line 110

Quoted 3 lines
drivers/hwmon/max1111.c +2 -1
-     return sprintf(buf, "%d\n", ret);
+     /* assume the reference voltage to be 2.048V */
+     return sprintf(buf, "%d\n", 2048 * 256 / ret);

I bet you did not actually test your changes? ret == 0 would obviously crash the driver. The formula looks wrong anyway, should be 2048 * ret / 256. Or in short ret * 8, i.e. LSB weight of the ADC is 8 mV.

Oops, shame to death.

How about simply '2048 * ret / 256' to make it clear and leave it to the compiler to optimize?

Quoted 29 lines
Quoted 13 lines
drivers/hwmon/max1111.c +1 -2
  }
 
  #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,

drivers/hwmon/max1111.c static MAX1111_ADC_ATTR(3); · line 130

Quoted 10 lines
drivers/hwmon/max1111.c +4 -3
-     &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,
  };
 

The rest of the changes look good.

--
Jean Delvare

#3 lore raw
Quoted 41 lines · Eric Miao
Quoted 31 lines · Jean Delvare

Hi Eric,

Quoted 28 lines · 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.

---
 drivers/hwmon/max1111.c |   13 +++++++------

 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/hwmon/max1111.c +0 -0
index c97b78e..0e9fcfd 100644
@@ -106,11 +106,12 @@ static ssize_t show_adc(struct device *dev,
       if (ret < 0)
               return ret;
 
Quoted 8 lines

drivers/hwmon/max1111.c static ssize_t show_adc(struct device *dev, · line 110

Quoted 3 lines
drivers/hwmon/max1111.c +2 -1
-     return sprintf(buf, "%d\n", ret);
+     /* assume the reference voltage to be 2.048V */
+     return sprintf(buf, "%d\n", 2048 * 256 / ret);

I bet you did not actually test your changes? ret == 0 would obviously crash the driver. The formula looks wrong anyway, should be 2048 * ret / 256. Or in short ret * 8, i.e. LSB weight of the ADC is 8 mV.

Quoted 4 lines

Oops, shame to death.

How about simply '2048 * ret / 256' to make it clear and leave it to the compiler to optimize?

I find the concept of LSB weight clear enough, but ultimately that's up to you, as long as the compiler actually optimizes it.

Signature · 1 line
Jean Delvare
author
#4 lore raw
Quoted 42 lines · Jean Delvare
Quoted 41 lines · Eric Miao
Quoted 39 lines · Jean Delvare

Hi Eric,

Quoted 25 lines · 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.

---
 drivers/hwmon/max1111.c |   13 +++++++------

 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/hwmon/max1111.c +0 -0
index c97b78e..0e9fcfd 100644

drivers/hwmon/max1111.c static ssize_t show_adc(struct device *dev, · line 110

Quoted 6 lines
drivers/hwmon/max1111.c +2 -1
@@ -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);

I bet you did not actually test your changes? ret == 0 would obviously crash the driver. The formula looks wrong anyway, should be 2048 * ret / 256. Or in short ret * 8, i.e. LSB weight of the ADC is 8 mV.

Quoted 7 lines
Quoted 4 lines

Oops, shame to death.

How about simply '2048 * ret / 256' to make it clear and leave it to the compiler to optimize?

I find the concept of LSB weight clear enough, but ultimately that's up to you, as long as the compiler actually optimizes it.

Sounds good, updated and resubmitted.