New and lighweight fan control daemon for NSA 310

Marvell Kirkwood based
lzap
Posts: 39
Joined: Wed Dec 19, 2012 11:46 am

New and lighweight fan control daemon for NSA 310

Post by lzap » Mon Jan 21, 2013 6:04 pm

https://github.com/lzap/fan3xxnsa

This is very simple and lightweight daemon that reads case temperature of Zyxel NSA-310 and sets fan speed according to the temperature.

How does it work
The NSA 310 provides three temperatures. The first two are most likely case temperatures, because according to all my measurements, they were always the same (+- one degree) as the disc temperature reported by SMART. The third temperature is from the CPU.

Please note the daemon only reads the case temperature (temp1), it ignores CPU or HDD temperatures. Because it does not make any sense to measure it (and also SMART spins up disc). Fan speed depends only on temp1, nothing else.

I use WD GreenPower in my NAS and the disc is 42 degrees Celsius when idle or light work, so the threasold is 43 degrees. Also I have noticed this cheap and small fan creates noise when rotating bellow 140 value, so the lowest is 160. Make sure screws in the back side are loose, do not tighen them much as it can put a pressure on the fan and create even more noise.

This is how it sets pwm according to temperature:

Code: Select all

Temp: 41 Pwm: 0
Temp: 42 Pwm: 0
Temp: 43 Pwm: 160
Temp: 44 Pwm: 165
Temp: 45 Pwm: 170
Temp: 46 Pwm: 175
Temp: 47 Pwm: 180
Temp: 48 Pwm: 185
Temp: 49 Pwm: 190
Temp: 50 Pwm: 195
Temp: 51 Pwm: 200
Temp: 52 Pwm: 205
Temp: 53 Pwm: 210
Temp: 54 Pwm: 215
Temp: 55 Pwm: 220
Temp: 56 Pwm: 225
Temp: 57 Pwm: 230
Temp: 58 Pwm: 235
Temp: 59 Pwm: 240
Temp: 60 Pwm: 245
Temp: 61 Pwm: 250
Temp: 62 Pwm: 255
Temp: 63 Pwm: 255
How to install
Very simple. First, you need Go language (golang). Please note Go 1.0 WILL NOT compile on ARM5, you either need some development snapshot or you can checkout master (called "default") branch. Then install and set GOROOT and PATH variables.

To install fan3xxnsa, just do:

Code: Select all

git clone
go build
And copy the binary file to a destination directory. If you are fine with ~/bin there is a script install.sh that does this for you (and also strips debug information from the binary).

Before you start the daemon, you need to enable fan control with:

Code: Select all

echo 1 > /sys/class/i2c-dev/i2c-0/device/0-002e/pwm1_enable
Then you can start it on background using nohup for example:

Code: Select all

nohup /root/bin/fan3xxnsa 1>/dev/null 2>&1 &
Must be executed as root, or you can change permissions on the pwm1 file.

Hacking
The code is very easy to understand, feel free to send patches. If you want to play with fans and temperatures, go to /sys/class/i2c-dev/i2c-0/device/0-002e directory (it can be different according to your NSA model or kernel version - try to find "pwm1_enable" file in the /sys/class directory).

Patches for other NSA models or kernel versions appreciated.

Please use github for updates, I will try to post important info here.

barmalej2
Posts: 2395
Joined: Sun Apr 29, 2012 5:24 pm

Re: New and lighweight fan control daemon for NSA 310

Post by barmalej2 » Tue Jan 22, 2013 6:56 am

It would be interesting to check, just a pity that I do not have a fan :)

User avatar
picard
Posts: 44
Joined: Tue Feb 05, 2013 6:46 am
Location: Germany
Contact:

Re: New and lighweight fan control daemon for NSA 310

Post by picard » Tue Feb 05, 2013 7:08 am

hello lzap,
hello all,

it will only work for nsa31x series.
nsa32x the row does not work because there the temp and rpm control is regulated differently.

someone has an idea to solve this for nsa32x :idea:

thank you pic

lzap
Posts: 39
Joined: Wed Dec 19, 2012 11:46 am

Re: New and lighweight fan control daemon for NSA 310

Post by lzap » Tue Feb 05, 2013 9:04 am

Can you do find /sys/class/i2c-dev and paste the output? I think it must be on a different path. Also which kernel are you using? It depends on the kernel version rather than hardware - I think the hardware is the same.

barmalej2
Posts: 2395
Joined: Sun Apr 29, 2012 5:24 pm

Re: New and lighweight fan control daemon for NSA 310

Post by barmalej2 » Tue Feb 05, 2013 9:23 am

Almost the same, but not identical.

User avatar
picard
Posts: 44
Joined: Tue Feb 05, 2013 6:46 am
Location: Germany
Contact:

Re: New and lighweight fan control daemon for NSA 310

Post by picard » Tue Feb 05, 2013 9:34 am

lzap wrote:Can you do find /sys/class/i2c-dev and paste the output? I think it must be on a different path. Also which kernel are you using? It depends on the kernel version rather than hardware - I think the hardware is the same.

Code: Select all

root@NSA325:~# find /sys/class/i2c-dev
/sys/class/i2c-dev
/sys/class/i2c-dev/i2c-0

Code: Select all

root@NSA325:~# uname -a
Linux NSA325 2.6.31.8 #3 Mon Nov 12 15:27:15 CST 2012 armv5tel GNU/Linux
thanks for help :P

lzap
Posts: 39
Joined: Wed Dec 19, 2012 11:46 am

Re: New and lighweight fan control daemon for NSA 310

Post by lzap » Tue Feb 05, 2013 10:35 am

Ok please do this:

Code: Select all

find /sys/class/i2c-adapter
You probably have it on a wrong path.

User avatar
picard
Posts: 44
Joined: Tue Feb 05, 2013 6:46 am
Location: Germany
Contact:

Re: New and lighweight fan control daemon for NSA 310

Post by picard » Tue Feb 05, 2013 1:29 pm

Code: Select all

root@NSA325:~# find /sys/class/i2c-adapter
/sys/class/i2c-adapter
/sys/class/i2c-adapter/i2c-0
and

Code: Select all

root@NSA325:~# find /sys/class/i2c-adapter/i2c-0/
/sys/class/i2c-adapter/i2c-0/
/sys/class/i2c-adapter/i2c-0/uevent
/sys/class/i2c-adapter/i2c-0/subsystem
/sys/class/i2c-adapter/i2c-0/device
/sys/class/i2c-adapter/i2c-0/name
/sys/class/i2c-adapter/i2c-0/new_device
/sys/class/i2c-adapter/i2c-0/delete_device
/sys/class/i2c-adapter/i2c-0/0-0051
/sys/class/i2c-adapter/i2c-0/0-0051/uevent
/sys/class/i2c-adapter/i2c-0/0-0051/name
/sys/class/i2c-adapter/i2c-0/0-0051/modalias
/sys/class/i2c-adapter/i2c-0/0-0051/subsystem
/sys/class/i2c-adapter/i2c-0/0-0051/driver
/sys/class/i2c-adapter/i2c-0/0-0051/rtc
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/uevent
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/dev
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/subsystem
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/device
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/name
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/date
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/time
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/since_epoch
/sys/class/i2c-adapter/i2c-0/0-0051/rtc/rtc0/max_user_freq
/sys/class/i2c-adapter/i2c-0/i2c-0
/sys/class/i2c-adapter/i2c-0/i2c-0/uevent
/sys/class/i2c-adapter/i2c-0/i2c-0/dev
/sys/class/i2c-adapter/i2c-0/i2c-0/subsystem
/sys/class/i2c-adapter/i2c-0/i2c-0/device
/sys/class/i2c-adapter/i2c-0/i2c-0/name
i have found /sys/class/i2c-adapter/i2c-0/0-0051, but I do not know ... nothing there shows me temp or rpm :(

takeoo111111
Posts: 2
Joined: Sat Jan 26, 2013 7:25 pm

Re: New and lighweight fan control daemon for NSA 310

Post by takeoo111111 » Tue Feb 05, 2013 5:03 pm

Hi,

I can confirm that 'issue' for NSA320.

Code: Select all

/sys# find /sys/class/i2c*
/sys/class/i2c-dev
/sys/class/i2c-dev/i2c-0
As you can see, the directory is named i2c-dev. But it seems to be the same. I also have a module 0-0051, its the RTC of the board.

Code: Select all

/sys/class/i2c-dev/i2c-0/device/0-0051# cat name
pcf8563
/sys/class/i2c-dev/i2c-0/device/0-0051/rtc/rtc1# cat name
rtc-pcf8563
I can't find anything that looks like a PWM controller :(
I'm running a self compiled Kernel 3.2.0. I used the config of Peeter123 KLICK, with slight changes. (Debian 6.0)
Module "LM85" is enabled in kernel config.

It would be awesome to find a workaround.

barmalej2
Posts: 2395
Joined: Sun Apr 29, 2012 5:24 pm

Re: New and lighweight fan control daemon for NSA 310

Post by barmalej2 » Wed Feb 06, 2013 5:45 am

Philips microchip PCF8563 is real time clock/calendar (btw NSA 310 doesn't has this chip) http://www.datasheetcatalog.org/datashe ... 563-02.pdf and has no relationship with fan control.

User avatar
picard
Posts: 44
Joined: Tue Feb 05, 2013 6:46 am
Location: Germany
Contact:

Re: New and lighweight fan control daemon for NSA 310

Post by picard » Wed Feb 06, 2013 7:23 am

hello barmalej2,

interesting, thanks for your help.

So we can not read RPM and TEMP and control :?:

pic

lzap
Posts: 39
Joined: Wed Dec 19, 2012 11:46 am

Re: New and lighweight fan control daemon for NSA 310

Post by lzap » Wed Feb 06, 2013 10:02 am

Maybe you miss a driver in kernel. Maybe copypaste your lsmod output and kernel config so I can compare to mine.

barmalej2
Posts: 2395
Joined: Sun Apr 29, 2012 5:24 pm

Re: New and lighweight fan control daemon for NSA 310

Post by barmalej2 » Wed Feb 06, 2013 11:47 am

lzap wrote:The first two are most likely case temperatures, because according to all my measurements, they were always the same (+- one degree) . The third temperature is from the CPU.
Is it logical to relate fan control with case temperature and not with CPU? I'm not criticizing, but I asking for your opinion, why you have chosen so :?:

takeoo111111
Posts: 2
Joined: Sat Jan 26, 2013 7:25 pm

Re: New and lighweight fan control daemon for NSA 310

Post by takeoo111111 » Wed Feb 06, 2013 3:51 pm

picard wrote:hello barmalej2,

interesting, thanks for your help.

So we can not read RPM and TEMP and control :?:

pic
For me its possible to read RPM and TEMP from /proc/mcu.
You can use this: (By AA666, here at the end of his post)
Here is a script to show current temperature and FAN speed:
/usr/local/sbin/hw

Code: Select all

#!/bin/bash
for line in `cat /proc/mcu` ; do
    case $line in
        'MagicNumber:'*)
            if [ ${line#MagicNumber:} != 85 ] ; then
                exit
            fi
        ;;
        'Rpss:'*)
            declare -i fan1=${line#Rpss:}
            declare -i fan=1000/$fan1*60
            echo fan1=$fan rpm
        ;;
        'Temperature:'*)
            temp1=${line#Temperature:}
            temp=${temp1:0:2}.${temp1:2:1}
            echo temp1=$temp *C
        ;;
    esac
done

Mijzelf
Posts: 6224
Joined: Mon Jun 16, 2008 10:45 am

Re: New and lighweight fan control daemon for NSA 310

Post by Mijzelf » Wed Feb 06, 2013 9:06 pm

/proc/mcu is not available on the NSA325. The CPU temp and fan rpm in the webinterface are read by zyshd. By intercepting the system calls of this daemon using strace, I found that the read is actually done by i2cget.

Code: Select all

i2cget -y 0x0 0x0a 0x07
reads the temperature (possibly in degrees Celsius) and

Code: Select all

i2cgey -y 0x0 0x0a 0x08
reads the fan rpm. The unit is not clear to me. The read value is 0x17 (23), and the rotation is 2608 rpm in the webinterface. I cannot remember I ever saw another value.

BTW, I've added a package i2c-tools to my slacker repository, as spin-off of these investigations.

Post Reply