Re: [lm-sensors] [PATCH] hwmon: (max1111) change sysfs interface toin[0-3]_input in millivolts

From: Eric Miao
Date: Wed Nov 09 2011 - 07:33:49 EST


On Wed, Nov 9, 2011 at 8:22 PM, Jean Delvare <khali@xxxxxxxxxxxx> wrote:
> Hi Eric,
>
> On Wed, Â9 Nov 2011 19:15:03 +0800, Eric Miao wrote:
>> 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@xxxxxxxxxxxx>
>> Signed-off-by: Eric Miao <eric.y.miao@xxxxxxxxx>
>> ---
>> Â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);
>
> 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?

>> Â}
>>
>> Â#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,
>> Â};
>>
>
> The rest of the changes look good.
>
> --
> Jean Delvare
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/