fan Monitoring & Control Module http://www.lsc-group.phys.uwm.edu/~ballen/driver/ December 2002 Version 1.4 Copyright Bruce Allen 2001, 2002 University of Wisconsin - Milwaukee Physics Department This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. You should have received a copy of the GNU General Public License (for example COPYING); if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. --------------------------------------------------------------------- QUICKSTART (0) Download fan-1.4.tar.gz, and unpack using "tar zxvf fan-1.4.tar.gz". (1) Go into the directory fan-1.4 and build fan.o by typing "make" (2) Load fan module by typing "insmod fan.o". (You must be root) (3) You can read fan information in /proc/fans. Writing to some of the files there will control fan speed, etc. (4) "make install" will install module in /lib/modules, add startup script to /etc/rc.d/init.d and copy this file into /usr/share/doc/fan-monitor --------------------------------------------------------------------- TABLE OF CONTENTS: (1) Description (2) Supported Kernel (3) What is required? (4) How do I install the fan monitor? (5) How do I tell if it is working? (6) What are the different entries in /proc/fans? (7) How do I control the fan speeds and other parameters? (8) What value should I use for /proc/fans/divisors? (9) Where can I get detailed info about the controller chips? (10) What clock source should I choose? (11) What are the options in loading the module? (12) How does the tachometer work? (13) How does the fan speed control work? (14) What else is needed/planned (15) Why did you do this? (16) Acknowlegements --------------------------------------------------------------------- (1) DESCRIPTION This is a simple fan-monitor and control module for the SMSC LPC47M1xx family of Super I/O Controllers. These allow two system fans to have their speeds monitored and controlled. The supported chips are LPC47M10x, LPC47M120, LPC47M13x, LPC47M14x, LPC47M15x, and LPC47M192. These chips are used on a number of Intel Pentium Motherboards, including the D815EEA, D815EEA2, D815EFV, and others. --------------------------------------------------------------------- (2) SUPPORTED KERNEL Linux kernel 2.4.x . May work under kernel 2.2.x --------------------------------------------------------------------- (3) WHAT IS REQUIRED? The /proc file system must be installed in the kernel. This is part of all standard distributions. You can tell if you have a /proc file system installed by typing "ls /proc". As long as something is listed (rather than "file not found") you have a /proc file system. You can control the speed of any fan. However to monitor fan speeds you must have "3-pin" tachometer fans plugged into the motherboard. --------------------------------------------------------------------- (4) HOW DO I INSTALL THE FAN MONITOR? The following two files are needed: Makefile fan.c Type "make". This will produce a file called "fan.o". To start the fan monitor, type "insmod fan.o" (you must be root to do this). Look in /var/log/messages to see startup messages, or error messages. WARNING: if your system does not contain one of the above LM47M1xx chips, the insmod command could potentially lock up your system, because it probes for the chip. --------------------------------------------------------------------- (5) HOW DO I TELL IF IT IS WORKING? After the installation above, look in the directory /proc/fans. It should contain the following: ls /proc/fans/ clocks divisors dutycycles info preloads rpms These are all human-readable files containing information about your system fans. For example: cat /proc/fans/info CNTL 0xff FANS 0xe5 0xe5 TACH 0x25 0xff PREL 0x0 0x0 Fan 1 clock mode 7 120 Hz Fan 1 duty cycle 64 / 64 (effectively clock is DC ON) Fan 1 preload register is 0 Fan 1 divisor is 8 Fan 1 tachometer register is 37 Fan 1 pulses-per-revolution is 2 Fan 1 RPM is 3321 ... This shows that Fan 1 is turning at 3321 revolutions-per-minute (rpm) and that its being driven as hard (fast) as possible (duty cycle 64/64=100%). Stick your finger or a pencil into the fan and see how the rpm value changes. Note that on some systems, a particular fan tachometer may be connected to a different fan than the fan speed control. For example on my Intel system, fan 1 is a chassis fan. The fan 1 tachometer monitors its speed, and the fan 1 speed control sets its speed. The fan 2 tachometer monitors the CPU cooling fan, but the CPU fan is not adjustable speed: it is set to run as fast as possible. The fan 2 speed control actually controls an optional second chassis fan. --------------------------------------------------------------------- (6) WHAT ARE THE DIFFERENT ENTRIES IN /proc/fans? The six files in /proc/fans contain the following: info: readable only. All information about the fans The raw LPC47M1xx fan registers are listed on the first line. The other registers are described below. rpms: readable only. The rotations-per-minute rates of the fans preloads: read/write. Tachometer register preload values Range 0-255. dutycycles: read/write. The dutycycle of the clocks driving the fans. Range 0-64. By writing these, you can control the fan speed. divisors: read/write. The divisor values used to compute fan speeds. Allowed values are 1, 2, 4 and 8. clocks: read/write. The possible choice of clocks to use for the pulse-width-modulated fan outpus. Allowed values are 0 to 7. These correspond to frequencies of 0 15625 Hz 1 23438 Hz 2 40 Hz 3 60 Hz 4 31250 Hz 5 46876 Hz 6 80 Hz 7 120 Hz If you are not sure which clock frequency to use, I suggest mode 5 (46876 Hz) --------------------------------------------------------------------- (7) HOW TO I CONTROL THE FAN SPEEDS AND OTHER PARAMETERS? To modify the values, you can use commands like: echo 4 7 > /proc/fans/clocks You must be root do to this. This sets the clock source for fan 1 to 31250 Hz and the clock source for fan 2 to 120 Hz. To control the fan speeds, use commands like: echo 32 64 > /proc/fans/dutycycles This sets the power to fan 1 to 32/64 (50%) of its maximum value -- roughly half speed, and the power to fan 2 to 64/64 (100%) of its maximum value. --------------------------------------------------------------------- (8) WHAT VALUE SHOULD I USE FOR /proc/fans/divisors? Start with 8 echo 8 8 > /proc/fans/divisors Decrease the value until the value of the tachometer registers shown in /proc/fans/info is in the range 100-200. This will give you the most accurate RPM readings. --------------------------------------------------------------------- (9) WHERE CAN I GET DETAILED INFORMATION ABOUT THE CONTROLLER CHIPS? http://www.smsc.com/main/datasheets/47m13x.pdf pages 144-8, 177-80, 182-4 Other information: http://www.smsc.com/main/datasheets/47m10x.pdf http://www.smsc.com/main/datasheets/47m120.pdf http://www.smsc.com/main/datasheets/47m14x.pdf --------------------------------------------------------------------- (10) WHAT CLOCK SOURCE SHOULD I CHOOSE? I suggest clock source 5: echo 5 5 > /proc/fans/clocks The clock is driven by a pulse width modulator. The clock source frequency is the modulation frequency. I've found that if you use the low-frequency (40-120 Hz) modulation frequencies, it tends to introduce noise on the tachometer pulse line, and leads to inaccurate tachometer register and rpm readings. --------------------------------------------------------------------- (11) WHAT ARE THE OPTIONS IN LOADING THE MODULE? The two options are siocfgport and pulses_per_revolution. The first is the address of the chip. According to SMSC documentation it should be either 0x2e or 0x4e. The default value is 0x2e. To use other values, use for example: insmod fan.o siocfgport=0x4e The values must be positive. The second is the number of pulses-per-revolution of your fan tachometers. Most tachometer fans produce two pulses per revolution, and this is the default value. If you have something different, say your fan 1 produces 3 pulses per revolution, and your fan 2 produces 2, then use: insmod fan.o pulses-per-revolution=3,2 You can also use the options together, for example: insmod fan.o pulses_per_revolution=3,2 siocfgport=0x4e --------------------------------------------------------------------- (12) HOW DOES THE TACHOMETER WORK? The chip has an internal 32768 Hz clock. This clock is divided down by the factor in "divisors" (1,2,4, or 8) to get a lower-frequency clock signal. This lower frequency clock is then gated into the counter (tachometer register). The gate is controlled by the tachometer pulse pin on the fan. Thus, if the fan turns slower, there is a longer time interval during which the divided-down clock gets counted, and the tachometer register will accumulate larger values. If the fan stops turning, the tachometer register will contain the largest possible 8-bit value: 255. A "preload" value is put into the tachometer register before counting is started. This is useful for generating interrupts. You will probably want preload values of 0. Thus: 32768 x 60 tac = pre + --------------- ppr x div x rpm where: tac = tachometer register value (range 0 to 255) pre = preload register value (range 0 to 255) ppr = pulses per revolution, adjustable parameter > 0, default value 2 div = divisor, adjustable parameter = 1, 2, 4, 8. Default value is set by bios (on Intel motherboards, it is 8). rpm = rotations per minute rate of fan --------------------------------------------------------------------- (13) HOW DOES THE FAN SPEED CONTROL WORK? The fan speed control is accomplished by providing a pulse-width modulated DC signal to the fan. The modulation clock is one of the 8 possible "clock" choices between 40 Hz and 46876 Hz listed above. The duty cycle for the modulation ranges from 0 (DC, fan off) to 64 (DC, fan on). --------------------------------------------------------------------- (14) WHAT ELSE IS NEEDED/PLANNED? I will at some point write a simple daemon that watches the fan speeds, and raises an alarm when a fan slows or stops. I may also write a daemon or version of the driver that adjusts the fan speeds to keep the system temperature constant. A nice way to raise the alarms, without having to write a daemon, is for me to implement an interupt handler in the fan module. But this may take a bit of time as I have to learn how. If you want to do either of these things, please get in touch! --------------------------------------------------------------------- (15) WHY DID YOU DO THIS? My research group is building a cluster of 300 machines based on an Intel motherboard that has these fan monitors. We'd like to know when fans are failing or dead! --------------------------------------------------------------------- (16) ACKNOWLEGEMENTS Thanks to Jonathan Teh for sending me some code fragments that showed how to configure the LPC47M1xx. Thanks to Frodo Looijaard and the lm_sensors group for their assistance. Thanks to Alessandro Rubini for writing "Linux Device Drivers".