'how to bind thermal temperature sensor with emc2103 fan

how to bind an external temperature sensor with fan emc2103 in Linux. As emc2103 has its own temperature sensor which its use to control fan speed. but I want to control fan speed based on CPU temperature. how to build this CPU temperature sensor with this emc2103 fan



Solution 1:[1]

It all depends on how is the emc2103 chip configured by BIOS.

Looking at the emc2103 kernel module source code, it should be possible to modify the fan speed by writing to file fan1_target in /sys/class/hwmon/hwmonX where X is a number assigned to the module. It is the one which is a symlink somewhere to i2c (hwmon2 in my example).

ll /sys/class/hwmon/
total 0
lrwxrwxrwx 1 root root 0 Apr  5 16:20 hwmon0 -> ../../devices/virtual/thermal/thermal_zone0/hwmon0
lrwxrwxrwx 1 root root 0 Apr  5 16:20 hwmon1 -> ../../devices/pci0000:00/0000:00:13.0/0000:01:00.0/hwmon/hwmon1
lrwxrwxrwx 1 root root 0 Apr  5 16:20 hwmon2 -> ../../devices/pci0000:00/0000:00:1f.1/i2c-1/1-002e/hwmon/hwmon2
lrwxrwxrwx 1 root root 0 Apr  5 16:20 hwmon3 -> ../../devices/pci0000

However at least on my Odroid H2 machine, the emc2103 chip is controlled by BIOS and writing to the fan1_target file has no effect. If I disable fan control in BIOS, it probably cuts the power to the fan, because I was not able to make it running.

But as the emc2103 chip is an i2c device, it can be manually configured via the i2cget and i2cset commands (i2c-tools package in Debian). First you need to load the i2c_dev kernel module and then determine on which i2c bus is the chip located (you can use i2cdetect command for that). The emc2103 chip is at address 0x2E. In case of Odroid H2, it is on the same bus as the DRAM SPD memory chip (dmesg|grep SPD), however on every boot it is assigned different bus number.

You can look at the emc2103 datasheet (and the kernel module source) to see which registers to read and write.

Again, for Odroid H2 it was enough to disable use of the Lookup Tables which was enabled by BIOS and then I was able to control the fan speed by writing to fan1_target. To disable it, you need to write value 0x00 to register 0x50 using command:

i2cset -y bus 0x2E 0x50 0x00

where bus is the i2c bus number where the device is located. This will fail with the emc2103 kernel module loaded. So either unload it, or add -f parameter to force it.

In my case I want the fan to be run based on HDD temperature, so I will try to utilize the LUT table as setup by BIOS, but add thresholds for Temp3, which I will set to "Pushed Temperature", which can be set using i2c. That way I can have both the board temp (as measure by the chip itself) and HDD temp values automatically evaluated.

Another possibility is to use something like hddfancontrol or fan2go to control the fan speed using the hwmon /sys files.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marki555