From 118a1021989c95531fc2b07fae8cd23b0ba09acd Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 21 Sep 2008 15:25:39 +0000 Subject: [PATCH] Add a script that provides manual control of the vt1211 PWM outputs. This script puts the vt1211 in automatic PWM mode and fools the chip into believing that there is a temp change to force the PWM outputs to specified values. This is necessary since the standard manual mode of the vt1211 doesn't seem to work. Patch from Juerg Haeflinger. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5338 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/pwm/Module.mk | 7 ++ prog/pwm/vt1211_pwm | 179 ++++++++++++++++++++++++++++++++++++++++++ prog/pwm/vt1211_pwm.8 | 52 ++++++++++++ 3 files changed, 238 insertions(+) create mode 100755 prog/pwm/vt1211_pwm create mode 100644 prog/pwm/vt1211_pwm.8 diff --git a/prog/pwm/Module.mk b/prog/pwm/Module.mk index 970c1610..30de1e31 100644 --- a/prog/pwm/Module.mk +++ b/prog/pwm/Module.mk @@ -25,6 +25,13 @@ PROGPWMMAN8FILES := $(MODULE_DIR)/fancontrol.8 $(MODULE_DIR)/pwmconfig.8 PROGPWMTARGETS := $(MODULE_DIR)/fancontrol \ $(MODULE_DIR)/pwmconfig +# The vt1211_pwm script is not installed by default, pass VT1211_PWM=1 +# to get it +ifeq ($(VT1211_PWM),1) +PROGPWMMAN8FILES += $(MODULE_DIR)/vt1211_pwm.8 +PROGPWMTARGETS += $(MODULE_DIR)/vt1211_pwm +endif + REMOVEPWMBIN := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(SBINDIR)/%,$(PROGPWMTARGETS)) REMOVEPWMMAN := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(PROGPWMMAN8DIR)/%,$(PROGPWMMAN8FILES)) diff --git a/prog/pwm/vt1211_pwm b/prog/pwm/vt1211_pwm new file mode 100755 index 00000000..e03a65da --- /dev/null +++ b/prog/pwm/vt1211_pwm @@ -0,0 +1,179 @@ +#!/bin/sh +# +# vt1211_pwm - Manually control the PWM outputs of the VIA vt1211 Super-I/O +# +# Copyright (C) 2008 Juerg Haefliger (juergh at gmail.com> +# +# 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 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +function usage +{ + echo "Usage: vt1211_pwm -i | -r | -s ," + echo + echo "DESCRIPTION" + echo " This tool provides manual control of the PWM outputs of the VIA " + echo " vt1211 Super-I/O." + echo + echo "OPTIONS" + echo " -d Display the current PWM settings of the vt1211." + echo " -i Initialize the PWM output for manual control." + echo " -r Restore the PWM output to the original settings." + echo " -s , Set the PWM output duty-cycle. " + echo + echo "WITH" + echo " PWM output (1-2)." + echo " PWM duty-cycle (0-255)." + echo + exit 2 +} + +function set_attr +{ + local tmp + read tmp < $1 + echo "echo $tmp > $1" + echo $2 > $1 +} + +# check if we have the right permissions to run +if [ `whoami` != "root" ] ; then + echo "You must be root to run this script." + exit 1 +fi + +# parse the command line options +action= +nr=1 +val=0 +while getopts di:r:s: opt ; do + [ -z "$action" ] || usage + case $opt in + d) action="display" + ;; + i) action="init" + nr=$OPTARG + ;; + r) action="restore" + nr=$OPTARG + ;; + s) action="set" + nr=${OPTARG%,*} + val=${OPTARG#*,} + ;; + ?) usage + ;; + esac +done + +[ -z "$action" ] && usage +[ $nr -lt 1 -o $nr -gt 2 ] && usage +[ $val -lt 0 -o $val -gt 255 ] && usage + +# check hwmon device +dev=`ls -d /sys/devices/platform/vt1211.*` +if [ -z "$dev" ] ; then + echo "Platform device vt1211 not found. Did you load the vt1211 module?" + exit 1 +fi + +# init file +initfile="/root/.vt1211_pwm${nr}" + +# ACTION: display +if [ $action = "display" ] ; then + for nr in 1 2 ; do + read mode < ${dev}/pwm${nr}_enable + if [ $mode -eq 0 ] ; then + mode_txt="(disabled)" + elif [ $mode -eq 2 ] ; then + mode_txt="(auto) " + else + mode_txt="(unknown) " + fi + read val < ${dev}/pwm${nr} + dc=$((val * 100 / 255)) + echo "pwm${nr}: mode = ${mode} ${mode_txt}, val = ${val} (${dc}%)" + done +fi + +# ACTION: init +if [ $action = "init" ] ; then + # check for an init file + if [ -e $initfile ] ; then + echo " $initfile exists. Did you already initialize this PWM?" + exit 1 + fi + + ( + # set the pwm-to-temp mapping + # use the internal temp as a reference + set_attr ${dev}/pwm${nr}_auto_channels_temp 2 + + # enable the pwm auto controller + set_attr ${dev}/pwm${nr}_enable 2 + + # set the PWM duty-cycle + set_attr ${dev}/pwm${nr}_auto_point2_pwm 0 + set_attr ${dev}/pwm${nr}_auto_point3_pwm 255 + + # set the temp boundaries to extrem values + set_attr ${dev}/pwm1_auto_point1_temp 0 + set_attr ${dev}/pwm1_auto_point2_temp 0 + set_attr ${dev}/pwm1_auto_point3_temp 1000000 + set_attr ${dev}/pwm1_auto_point4_temp 1000000 + + ) > $initfile + + exit 0 +fi + +# ACTION: restore +if [ $action = "restore" ] ; then + # check for an init file + if [ ! -e $initfile ] ; then + echo " $initfile not found. Nothing to restore." + exit 1 + fi + + sh $initfile + rm $initfile + + exit 0 +fi + +# ACTION: set +if [ $action = "set" ] ; then + # check for an init file + if [ ! -e $initfile ] ; then + echo "$initfile not found. Did you initialize this PWM?" + exit 1 + fi + + # set the PWM duty-cycle + echo $val > ${dev}/pwm${nr}_auto_point3_pwm + + # fool the vt1211 into believing there is a temp change + # otherwise the new PWM duty-cycle doesn't take effect + echo 0 > ${dev}/pwm1_auto_point3_temp + echo 1000000 > ${dev}/pwm1_auto_point3_temp + + # read the new PWM duty-cycle back and print it + read val < ${dev}/pwm${nr} + dc=$((val * 100 / 255)) + echo "pwm${nr} is now at ${val} (${dc}%)." + + exit 0 +fi diff --git a/prog/pwm/vt1211_pwm.8 b/prog/pwm/vt1211_pwm.8 new file mode 100644 index 00000000..f4a3c5e1 --- /dev/null +++ b/prog/pwm/vt1211_pwm.8 @@ -0,0 +1,52 @@ +.TH VT1211_PWM 8 "July 2008" "lm-sensors 3" +.SH NAME +vt1211_pwm \- manual control of VIA vt1211 PWM outputs + +.SH SYNOPSIS +.B vt1211_pwm +.B -d | -i | -r | -s , + +.SH DESCRIPTION +\fBvt1211_pwm\fP is a shell script that provides manual control of the two PWM +outputs of the VIA vt1211 Super-I/O device. + +.SH OPTIONS +.TP +.B -d +Display the current settings of the two PWM outputs. +.TP +.B -i +Initialize PWM \fB\fP for manual control. Valid numbers for \fB\fP +are 1 or 2. This option also writes the original vt1211 register values to +~/.vt1211_pwm\fB\fP which is used for restoring the original settings. +.TP +.B -r +Restore PWM \fB\fP to the orignal settings. Valid numbers for \fB\fP +are 1 or 2. This options reads the original settings from +~/.vt1211_pwm\fB\fP and writes them to the vt1211. +.TP +.B -s , +Set PMW \fB\fP output to \fB\fP. Valid numbers for \fB\fP are 1 +or 2 and valid numbers for \fB\fP are 0 to 255. The \fB\fP range of +0-255 maps to an output duty-cycle of 0%-100%, i.e., output duty-cycle = +\fB\fP * 100 / 255. + +.SH REQUIREMENTS +You need root privileges to execute the vt1211_pwm script and the vt1211 kernel +module needs to be loaded and you obviously need to have fans connected to the +PWM outputs of the vt1211 :-) + +.SH WARNING +This script puts the PWM controller of the vt1211 into automatic mode and +toggles the thermal thresholds between extrem values to fool the chip into +believing that there is a temperature change and thus forcing the PWM outputs +to change to the specified values. Since there is only a single PWM controller +that controls both PWM outputs, setting the duty-cycle of one PWM output could +affect the duty-cycle of the other PWM output. Use at you own risk! + +.SH SEE ALSO +sensors(1) + +.SH AUTHOR +.PP +Juerg Haefliger