[smartmontools-support] [PATCH] RFC: libata: Add hwmon support for SMART temperature sensors
Guenter Roeck
linux at roeck-us.net
Mon Aug 13 00:31:43 CEST 2018
On 08/09/2018 09:15 PM, Guenter Roeck wrote:
> On 08/09/2018 03:24 PM, Linus Walleij wrote:
>> S.M.A.R.T. temperature sensors have been supported for
>> years by userspace tools such as smarttools.
>>
>> The temperature readout is however also a good fit for
>> Linux' hwmon subsystem. By adding a hwmon interface to dig
>> out SMART parameter 194, we can expose the drive temperature
>> as a standard hwmon sensor.
>>
[ ... ]
>> +
>> +static int ata_hwmon_read_temp(struct ata_hwmon *ata, int *temp,
>> + int *min, int *max)
>> +{
[ ... ]
>> + if (id == SMART_TEMP_PROP_194)
>> + break;
231 also seems to report the temperature if available, as does 190.
Not sure if 190 is worth it, though - Samsung SSD 840 PRO Series supports
it but reports a static value of 28. And it seems to be either as
degrees C or as 100 - degrees C, depending on the drive manufacturer,
which makes it quite unreliable.
[ ... ]
>> +
>> +static int ata_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
>> + u32 attr, int channel, long *val)
>> +{
>> + struct ata_hwmon *ata = dev_get_drvdata(dev);
>> + int temp, min, max;
>> + int ret;
>> +
>> + if (type != hwmon_temp)
>> + return -EINVAL;
>> +
>> + ret = ata_hwmon_read_temp(ata, &temp, &min, &max);
>> + if (ret)
>> + return ret;
>> +
>> + switch (attr) {
>> + case hwmon_temp_input:
>> + *val = temp;
>> + break;
>> + case hwmon_temp_min:
>> + *val = min;
>> + break;
>> + case hwmon_temp_max:
>> + *val = max;
>> + break;
Those numbers need to be multiplied by 1,000 (hwmon ABI expects milli-degrees C).
Guenter
More information about the Smartmontools-support
mailing list