root/lm-sensors/branches/lm-sensors-3.0.0/prog/pwm/vt1211_pwm @ 5338

Revision 5338, 4.4 KB (checked in by khali, 5 years ago)

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.

  • Property svn:executable set to *
Line 
1#!/bin/sh
2#
3# vt1211_pwm - Manually control the PWM outputs of the VIA vt1211 Super-I/O
4#
5# Copyright (C) 2008 Juerg Haefliger (juergh at gmail.com>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20#
21
22function usage
23{
24    echo "Usage: vt1211_pwm -i <pwm> | -r <pwm> | -s <pwm>,<val>"
25    echo
26    echo "DESCRIPTION"
27    echo "   This tool provides manual control of the PWM outputs of the VIA "
28    echo "   vt1211 Super-I/O."
29    echo
30    echo "OPTIONS"
31    echo "   -d               Display the current PWM settings of the vt1211."
32    echo "   -i <pwm>         Initialize the PWM output for manual control."
33    echo "   -r <pwm>         Restore the PWM output to the original settings."
34    echo "   -s <pwm>,<val>   Set the PWM output duty-cycle. "
35    echo
36    echo "WITH"
37    echo "   <pwm>   PWM output (1-2)."
38    echo "   <val>   PWM duty-cycle (0-255)."
39    echo
40    exit 2
41}
42
43function set_attr
44{
45    local tmp
46    read tmp < $1
47    echo "echo $tmp > $1"
48    echo $2 > $1
49}
50
51# check if we have the right permissions to run
52if [ `whoami` != "root" ] ; then
53    echo "You must be root to run this script."
54    exit 1
55fi
56
57# parse the command line options
58action=
59nr=1
60val=0
61while getopts di:r:s: opt ; do
62    [ -z "$action" ] || usage
63    case $opt in
64        d)  action="display"
65            ;;
66        i)  action="init"
67            nr=$OPTARG
68            ;;
69        r)  action="restore"
70            nr=$OPTARG
71            ;;
72        s)  action="set"
73            nr=${OPTARG%,*}
74            val=${OPTARG#*,}
75            ;;
76        ?)  usage
77            ;;
78    esac
79done
80
81[ -z "$action" ] && usage
82[ $nr -lt 1 -o $nr -gt 2 ] && usage
83[ $val -lt 0 -o $val -gt 255 ] && usage
84
85# check hwmon device
86dev=`ls -d /sys/devices/platform/vt1211.*`
87if [ -z "$dev" ] ; then
88    echo "Platform device vt1211 not found. Did you load the vt1211 module?"
89    exit 1
90fi
91
92# init file
93initfile="/root/.vt1211_pwm${nr}"
94
95# ACTION: display
96if [ $action = "display" ] ; then
97    for nr in 1 2 ; do
98        read mode < ${dev}/pwm${nr}_enable
99        if [ $mode -eq 0 ] ; then
100            mode_txt="(disabled)"
101        elif [ $mode -eq 2 ] ; then
102            mode_txt="(auto)    "
103        else
104            mode_txt="(unknown) "
105        fi
106        read val < ${dev}/pwm${nr}
107        dc=$((val * 100 / 255))
108        echo "pwm${nr}: mode = ${mode} ${mode_txt}, val = ${val} (${dc}%)"
109    done
110fi
111
112# ACTION: init
113if [ $action = "init" ] ; then
114    # check for an init file
115    if [ -e  $initfile ] ; then
116        echo " $initfile exists. Did you already initialize this PWM?"
117        exit 1
118    fi
119
120    (
121        # set the pwm-to-temp mapping
122        # use the internal temp as a reference
123        set_attr ${dev}/pwm${nr}_auto_channels_temp 2
124
125        # enable the pwm auto controller
126        set_attr ${dev}/pwm${nr}_enable 2
127
128        # set the PWM duty-cycle
129        set_attr ${dev}/pwm${nr}_auto_point2_pwm 0
130        set_attr ${dev}/pwm${nr}_auto_point3_pwm 255
131
132        # set the temp boundaries to extrem values
133        set_attr ${dev}/pwm1_auto_point1_temp 0
134        set_attr ${dev}/pwm1_auto_point2_temp 0
135        set_attr ${dev}/pwm1_auto_point3_temp 1000000
136        set_attr ${dev}/pwm1_auto_point4_temp 1000000
137
138    ) > $initfile
139
140    exit 0
141fi
142
143# ACTION: restore
144if [ $action = "restore" ] ; then
145    # check for an init file
146    if [ ! -e  $initfile ] ; then
147        echo " $initfile not found. Nothing to restore."
148        exit 1
149    fi
150
151    sh $initfile
152    rm $initfile
153
154    exit 0
155fi
156
157# ACTION: set
158if [ $action = "set" ] ; then
159    # check for an init file
160    if [ ! -e $initfile ] ; then
161        echo "$initfile not found. Did you initialize this PWM?"
162        exit 1
163    fi
164
165    # set the PWM duty-cycle
166    echo $val > ${dev}/pwm${nr}_auto_point3_pwm
167
168    # fool the vt1211 into believing there is a temp change
169    # otherwise the new PWM duty-cycle doesn't take effect
170    echo 0 > ${dev}/pwm1_auto_point3_temp
171    echo 1000000 > ${dev}/pwm1_auto_point3_temp
172
173    # read the new PWM duty-cycle back and print it
174    read val < ${dev}/pwm${nr}
175    dc=$((val * 100 / 255))
176    echo "pwm${nr} is now at ${val} (${dc}%)."
177
178    exit 0
179fi
Note: See TracBrowser for help on using the browser.