2012-08-10 14:18:24

by Bitan Biswas

[permalink] [raw]
Subject: hwmon : raw reading -> temperature conversion

Hi,

I have a question related to hwmon driver and need suggestions.

I am working on a temperature sensor driver that is hwmon driver.
- The temperature is calculated from raw sensor reading and
certain initialization parameters.
- Raw reading obtained from 2 different sensor instances under
same conditions can differ. Further, initialization parameters
are specific to each hardware instance.
- Expressions with floating point operands are used to compute
the temperature value.

In our platform there are multiple kernel level clients to the
temperature sensor driver.
Hence I am planning to present temperature to these clients
from kernel driver itself.

But looking at the hwmon linux documentation, seems the sensor
kernel drivers should report only raw readings.
The raw readings can be converted into required output,
e.g. temperature in this case, by respective user space implementation.

However because of my driver clients being in kernel space, I am
thinking of doing fixed point calculations in the sensor driver
and get the temperature corresponding to raw sensor readings.

Please let me know if this a correct approach?

If there is a better way, please suggest.

-regards,
Bitan


2012-08-10 18:43:26

by Guenter Roeck

[permalink] [raw]
Subject: Re: [lm-sensors] hwmon : raw reading -> temperature conversion

On Fri, Aug 10, 2012 at 07:48:14PM +0530, Bitan Biswas wrote:
> Hi,
>
> I have a question related to hwmon driver and need suggestions.
>
> I am working on a temperature sensor driver that is hwmon driver.
> - The temperature is calculated from raw sensor reading and
> certain initialization parameters.
> - Raw reading obtained from 2 different sensor instances under
> same conditions can differ. Further, initialization parameters
> are specific to each hardware instance.
> - Expressions with floating point operands are used to compute
> the temperature value.
>
> In our platform there are multiple kernel level clients to the
> temperature sensor driver.
> Hence I am planning to present temperature to these clients
> from kernel driver itself.
>
> But looking at the hwmon linux documentation, seems the sensor
> kernel drivers should report only raw readings.
> The raw readings can be converted into required output,
> e.g. temperature in this case, by respective user space implementation.
>
"raw" means the value as reported to the sensor. For example, for an ADC, the
raw value means the voltage in mV as seen on the sensor's input pins. This
voltage is the voltage to be reported. Converting it to a "real" voltage as,
typically, determined by a set of voltage divider resistors should be done in
user space.

For temperature sensors this is a bit more tricky. Presumably you get readings
from a thermistor or similar. The hwmon subsystem includes a driver for NTC
thermistors; maybe you can get some ideas from it. Maybe you can even use
it and/or extend it to support your hardware.

> However because of my driver clients being in kernel space, I am
> thinking of doing fixed point calculations in the sensor driver
> and get the temperature corresponding to raw sensor readings.
>
> Please let me know if this a correct approach?
>
Question is really what chip you are using, and how exactly your hardware looks
like. Do you use a generic ADC ? If so, is it already supported in the kernel ?
How are the thermistor readings converted and reported to SW ?

Thanks,
Guenter

2012-08-13 07:27:34

by Bitan Biswas

[permalink] [raw]
Subject: Re: [lm-sensors] hwmon : raw reading -> temperature conversion

Hi Guenter,

Thank you for the guidance.

>>
>> But looking at the hwmon linux documentation, seems the sensor
>> kernel drivers should report only raw readings.
>> The raw readings can be converted into required output,
>> e.g. temperature in this case, by respective user space implementation.
>>
> "raw" means the value as reported to the sensor. For example, for an ADC, the
> raw value means the voltage in mV as seen on the sensor's input pins. This
> voltage is the voltage to be reported. Converting it to a "real" voltage as,
> typically, determined by a set of voltage divider resistors should be done in
> user space.
>
> For temperature sensors this is a bit more tricky. Presumably you get readings
> from a thermistor or similar. The hwmon subsystem includes a driver for NTC
> thermistors; maybe you can get some ideas from it. Maybe you can even use
> it and/or extend it to support your hardware.

The sensor is Tegra3 integrated thermal sensor. It is not a thermistor,
but gives a counter reading. The expressions to convert the counter to
temperature use characterization data and certain initialization
parameters. I looked at the NTC thermistor driver. The expressions I
need to use to convert counter value to temperature would need floating
point arguments.

>
>> However because of my driver clients being in kernel space, I am
>> thinking of doing fixed point calculations in the sensor driver
>> and get the temperature corresponding to raw sensor readings.
>>
>> Please let me know if this a correct approach?
>>
> Question is really what chip you are using, and how exactly your hardware looks
> like. Do you use a generic ADC ? If so, is it already supported in the kernel ?
> How are the thermistor readings converted and reported to SW ?

I think this is somewhat like an ADC but I need to implement the
expressions to convert the counter readings to temperature. Using fixed
point approximations instead of the floating point operands, the
expressions can be implemented in kernel. The expressions to be used for
calculation are specific to chip and I could not find a existing driver
that could support this sensor.

There are expressions that can convert the counter readings to
temperature and vice-versa.
1) SW could call the driver callbacks and get the temperature.
2) SW could also request temperature thresholds to be configured for
thermal monitoring.

The software that may need to use the temperature are some other kernel
drivers.

Is it not allowed to implement the counter raw readings to temperature
in the hwmon sensor driver?


>
> Thanks,
> Guenter
>

2012-08-13 13:44:15

by Guenter Roeck

[permalink] [raw]
Subject: Re: [lm-sensors] hwmon : raw reading -> temperature conversion

On Mon, Aug 13, 2012 at 12:57:03PM +0530, Bitan Biswas wrote:
> Hi Guenter,
>
> Thank you for the guidance.
>
> >>
> >>But looking at the hwmon linux documentation, seems the sensor
> >>kernel drivers should report only raw readings.
> >>The raw readings can be converted into required output,
> >>e.g. temperature in this case, by respective user space implementation.
> >>
> >"raw" means the value as reported to the sensor. For example, for an ADC, the
> >raw value means the voltage in mV as seen on the sensor's input pins. This
> >voltage is the voltage to be reported. Converting it to a "real" voltage as,
> >typically, determined by a set of voltage divider resistors should be done in
> >user space.
> >
> >For temperature sensors this is a bit more tricky. Presumably you get readings
> >from a thermistor or similar. The hwmon subsystem includes a driver for NTC
> >thermistors; maybe you can get some ideas from it. Maybe you can even use
> >it and/or extend it to support your hardware.
>
> The sensor is Tegra3 integrated thermal sensor. It is not a
> thermistor, but gives a counter reading. The expressions to convert
> the counter to temperature use characterization data and certain
> initialization parameters. I looked at the NTC thermistor driver.
> The expressions I need to use to convert counter value to
> temperature would need floating point arguments.
>
> >
> >>However because of my driver clients being in kernel space, I am
> >>thinking of doing fixed point calculations in the sensor driver
> >>and get the temperature corresponding to raw sensor readings.
> >>
> >>Please let me know if this a correct approach?
> >>
> >Question is really what chip you are using, and how exactly your hardware looks
> >like. Do you use a generic ADC ? If so, is it already supported in the kernel ?
> >How are the thermistor readings converted and reported to SW ?
>
> I think this is somewhat like an ADC but I need to implement the
> expressions to convert the counter readings to temperature. Using
> fixed point approximations instead of the floating point operands,
> the expressions can be implemented in kernel. The expressions to be
> used for calculation are specific to chip and I could not find a
> existing driver that could support this sensor.
>
> There are expressions that can convert the counter readings to
> temperature and vice-versa.
> 1) SW could call the driver callbacks and get the temperature.
> 2) SW could also request temperature thresholds to be configured for
> thermal monitoring.
>
> The software that may need to use the temperature are some other
> kernel drivers.
>
> Is it not allowed to implement the counter raw readings to
> temperature in the hwmon sensor driver?
>
If you look at the NTC driver, that is pretty much exactly what it does. It
accepts Ohm or Volt as input, and calculates a temperature from it. One can
think of a counter reading as to be similar to a resistance reading; if you
do that, you have a good starting point for your driver. You can use either
fixed point approximations, or a table approach as in the NTC driver.

Thanks,
Guenter