vt1211 module for 2.6 kernel

by Lars Ekman (emil71se at bredband . net)

Introduction

The vt1211 is a sensor chip used for instance on the EPIA-CL Mini-ITX board which I have. The board has a fan-less VIA-eden processor, and I have not connected the fan in the box. I am worried about the temperature, so I want to monitor it.

The driver for vt1211 has not been ported to kernel version 2.6 by the lm_sensors project yet. The port has been listed as in progress for several months so I decided to port it myself and hopefully give something back to the open source community.

Just to cearify; the vt1211 sensor driver was written by Mark D. Studebaker, I have just made adaptations for the 2.6 kernels.

News

Sun Nov 20 18:01:15 CET 2005
New 2.6.14.2 patch A segv on unloading was fixed.
Sun Sep 25 09:52:44 CEST 2005
New 2.6.14-rc1 patch.
Sun Sep 4 08:31:03 CEST 2005
Updated the 2.6.13 patch. Now it works, at least for me.
Sat Sep 3 21:40:40 CEST 2005
Added a WARNING for the 2.6.13 patch. Users, myself included gets a kernel Oops on 2.6.13. The driver itself is the same in the patch, so some correction is needed.
Fri Sep 2 07:59:12 CEST 2005
Added a patch for 2.6.13. My thanks to William Ewing who made this patch.
Sun Jul 3 21:58:05 CEST 2005
Added information about problems with the latest patch an older kernels (e.g Debian).
Sat Mar 19 13:16:49 CET 2005
I received a response from the lm_sensors team and some modifications had to be done for an official release. Hopefully the vt1211 driver will now be included in some future kernel release. The changes are quite large so please read the information below.
Sun Mar 6 17:34:21 CET 2005
Added a new patch for the 2.6.11 kernel. The vt1211.c file is not altered at all, just a new kernel patch.
Fri Dec 31 12:08:49 CET 2004
Added a new patch for the 2.6.10 kernel. The vt1211.c file is not altered at all, just a new kernel patch.
Fri Oct 22 17:12:42 CEST 2004
Added another sensors.conf for EPIA-M 10000N.
Tue Oct 5 17:19:28 CEST 2004
Corrected a bug in show_temp_hyst that Simon found, he also sent a new sensors.conf . Made a note about i2c-isa.ko .
Sun Sep 26 19:54:48 CEST 2004
Changed to IN_MULTIPLIER=10 (was 1) to get correct voltage readings. Large changes in this doc. (it has been a busy day)
Sun Sep 26 17:05:36 CEST 2004
Got an updated kernel patch from Stefan, and got a sensors.conf for EPIA-M 10000N from Simon. My thanks for their help and contributions.
Sun Sep 26 07:45:29 CEST 2004
The driver was updated. The in-driver register converions was made optional. The Conversion Confusion paragraph was added. This is important so please read it.
Tue Sep 21 08:01:19 CEST 2004
Added the Patches and packages chapter with useful related items provided by Stefan Plattner.

The module

Here is the source and a kernel patch;

NOTE
The 2.6.13 kernel requires an updated vt1211 driver from the patch below. Older versions of the driver gives an Oops when a sysfs file is accessed on 2.6.13.
NOTE
The 2.6.14 kernel requires yet another updated driver. The /sys files are created in a new place, I don't know if that is as it should be. For example; /sys/devices/platform/i2c-9191/9191-6000/temp3_input

The driver has been updated for release to the linux kernel. Here is a summary of the changes compared to the earlier version;

The driver can be built manually with;

        echo "obj-m := vt1211.o" > Makefile
        make -C /path/to/your/kernel2.6/source/dir SUBDIRS=$PWD modules

Read the Documentation/kbuild/modules.txt in your kernel directory for more info about how to build modules.

Older kernels than 2.11.x (e.g Debian)

NOTE
This patch will not work with older kernels. In particular is will fail on Debian which uses 2.6.8 (I think?). See the work-around below. Hopefully I will get time to make another patch shortly.

The normal_i2c_range and normal_isa_range was removed when preparing the module for integation in the kernel-tree for 2.6.11. Older kernels requires those parameters.

Please try a patch available under the Older versions section on my web page.

Or ou can simply add the removed lines (tested by others). If so add before line 74 where you get the error;

...
static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };
static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END };

SENSORS_INSMOD_1(vt1211);
...

Intall the module

Install it with the usual module-init-tools;

        insmod i2c-sensor.ko
        insmod vt1211.ko

The example is my commands. You may use modprobe , or require more or less modules to be loaded before vt1211.ko.

NOTE
The i2c-isa.ko module is required, else the 0-6000 directories will be missing. It seems like modprobe can miss this. A user had this problem on Fedora Core 3 test2.

Check the result by examining the /sys files;

# cd /sys/devices/platform/i2c-0/0-6000/
# ls
alarms           fan2_pwm         in4_max          temp3_input
detach_state     fan2_pwm_enable  in4_min          temp3_max
fan1_div         in0_ref          in5_input        temp3_max_hyst
fan1_input       in2_input        in5_max          temp4_input
fan1_min         in2_max          in5_min          temp4_max
fan1_pwm         in2_min          name             temp4_max_hyst
fan1_pwm_enable  in3_input        power            vrm
fan2_div         in3_max          temp2_input
fan2_input       in3_min          temp2_max
fan2_min         in4_input        temp2_max_hyst
# cat temp3_input in[2345]_input
99250
1190
1900
2090
2020

The i2c-0/0-6000 is an address and may differ on your system.

Register convertion

The values in the files under /sys are raw un-converted register values. These will be converted to readable values by some program like sensors . Or you can check the formulas in sensors.conf and convert them yourself;

        # compute temp3  (@ - 65) / 0.9686,  (@ * 0.9686) + 65
        echo "scale=2; (99.250-65)/0.9686" | bc -q
        35.36

So the register value 99250 is converted to 35.36 degree Celsius. The example uses bc for the computation. Note that the value from the driver is divided by the multiplier .

The sensors.conf from lm_sensors works fine on my EPIA-CL except for the Core voltage konstant which should be 1.0.

However the EPIA-M boards seems to need a modified sensors.conf . Since I do not own a EPIA-M myself I can only provide files cotributed by others. Here are some;

sensors.conf.txt
A sensors.conf for the EPIA-M 10000N board from Simon
sensors2.conf.txt
Another contributed sensors.conf for the EPIA-M 10000N, found at VIAARENA in Oct 2003.

Here are a configuration for gkrellm that corresponds to the standard sensors.conf. It works fine on my EPIA-CL board, but will probably not be accurate for EPIA-M boards.

gkrellm multipliers for EPIA-CL (probably not EPIA-M)
Register Factor Offset
temp3 (CPU) 1.0324 -67.1071
in2 (Core) 1.0438 -0.031
in3 (+5V) 2.5050 -0.075
in4 (+12V) 5.9512 -0.178
in5 (+3.3V) 1.6579 -0.050
NOTE
If you have a sensors.conf or gkrellm multipliers for other boards, please send them to me and I will include them in this section.

Configuration

It is possible to configure some sensors for either temp or voltage ( in ). This is done by writing to the file;

This file contains a bitmask for the sensors. The following table is taken from the sensors.conf file;

uch_config bits
Sensor Voltage Mode Temp Mode config bit
Reading 1 temp3
UCH1/Reading2 in0 temp2 0x04 (4)
UCH2 in1 temp4 0x08 (8)
UCH3 in2 temp5 0x10 (16)
UCH4 in3 temp6 0x20 (32)
UCH5 in4 temp7 0x40 (64)
3.3V in5

Usually this is set by BIOS and should not be changed.

A fix in libsensors so that uch_config can be set by sensors -s is checked in.

Testing

I know there are tools for reading the sensors, but I have only tested this by printing the files under /sys. My Mini-ITX system is a primitive diskless system so installing tools (especially perl based) requires too much job.

I have tried to compare the CPU temperature and the voltages towards the PC Health Status menu on the BIOS screen. The voltage values are about the same. The CPU temperature from the vt1211 module seems a bit (~4 degrees) higher than the BIOS value. I do not know why or which is most correct, but I think its the same if you run the original 2.4 version of the module.

The fan_pwm is supposed to control the fan speed. I connected the fan in my system but could not control it. I read something on the viaarena forum that the fan on my board is connected to 12V always, so this is not necessarily a fault. I think the value is written ok by the driver, but the HW refuses to accept it. Example;

# echo 1 > fan2_pwm_enable
# echo 50 > fan2_pwm; cat fan2_pwm
50
# cat fan2_pwm
255

The value 50 seems to be written, but when the HW value is re-read by the driver it is back to 255 (100% fan speed).

The thermistor sensors (temp2 and temp4) are not used on my board so I can not test them. The translation formula is again taken from /etc/sensors.conf and seems a bit simplified compared to via686a.

Most other values I have just tried to read and write. No alarms tested. Some things like the vrm I do not understand, so I can't test them.

Older versions

The older version of this driver contained register convertions and did not include all sensor files by default. Here is some information about the old version of the driver. It should be considered obsolete.

Patches and packages

Stefan Plattner has provided alternative ways of installing the vt1211 driver. These are easier than the instruction above for most Linux users.

First the vt1211 driver as a patch to the kernel instead of a stand-alone module.

And a ready to use debian package of kernel 2.6.8 with all the relevant epia patches plus supermount is available here.

My thanks to Stefan for providing these packages.

On request I have made a kernel path for the 2.6.10 kernel. The module is not altered at all;

The 2.6.10 patch works for 2.6.10 but with warnings. Here is a version for 2.6.11. The module is still the same.

Conversion Confusion

When I made the port i read these documents in the Documentation/i2c/ directory in the kernel source;

The examples below is taken from kernel 2.6.8.1. In the porting-clients you can read;

        "Use the file names specified in Documentation/i2c/sysfs-interface
         for the individual files. Also convert the units these files read 
         and write to the specified ones."

The units in sysfs-interface is for instance instance;

        temp[1-4]_input Temperature input value.
                Unit: millidegree Celcius
                Read only value.

From this I concluded that the conversions should be done inside the driver. This is also done in the other VIA driver, the via686a.c . But I was wrong ...

I got a mail from Simon who owns a new EPIA-M 10000N board. On his board the register conversions are different. For instance;

        temp3 (@*@*0.0046)-(@*0.088)-0.748, (@*0.9686)+65

Here is the sensors.conf for the EPIA-M 10000N board from Simon;

Here is another contributed sensors.conf for the EPIA-M 10000N, found at VIAARENA about 12 month ago (Oct 2003);

For other (older) boards the sensors.conf in the lm_sensors package will probably do nicely.

Reading the sysfs-interface again more carefully I found;

        ... the conversions cannot be hard coded into the driver and
        have to be done in user space.

        For this reason, even if we aim at a chip-independant
        libsensors, it will still require a configuration file
        (e.g. /etc/sensors.conf) for proper values conversion,
        labeling of inputs and hiding of unused inputs.

So the register values should not be converted by the driver. But the register values should still be multiplied by a factor inside the driver.

Register multipliers
Multiplier 2.4 kernel 2.6 kernel
TEMP_MULTIPLIER 10 1000
IN_MULTIPLIER (volt) 1(?) 10(?)

The IN_MULTIPLIER I think is incorrect in my 2.4 version (from lm_sensors-2.8.5) it should be 10 to fit the sensors.conf formulas. Further I think the the value should really be 1000 in the 2.6 version. Here is an example with IN_MULTIPLIER=10;

        # compute in4 ((@ * 100) - 3) / (0.1754 * 95.8), ...
        > cat /sys/devices/platform/i2c-0/0-6000/in4_input
        2080
        > echo "((2080*100)-3)/(0.1754*95.8)" | bc -q
        12378

This is the 12V in milli-volt, so it looks OK. But the formula contains (@*100) which no other sensor-chip driver has. So I really think that IN_MULTIPLIER=1000 should be used, and the formula should be;

        compute in4 (@ - 3) / (0.1754 * 95.8),

As you might understand I am a bit confused about this, but is is clear that the conversion should not be done by the driver. So The internal register conversion is disabled by default, but can be re-enabled. The register multipliers are macros and easy to alter.

It shouldn't be very hard to alter the driver and the translation files (e.g /etc/sensors.conf) to get correct values, but if anybody knows the correct way, please let me know.

Generated: Sun Nov 20 18:07:09 2005