3
# vt1211_pwm - Manually control the PWM outputs of the VIA vt1211 Super-I/O
5
# Copyright (C) 2008 Juerg Haefliger (juergh at gmail.com>
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.
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.
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.
24
echo "Usage: vt1211_pwm -i <pwm> | -r <pwm> | -s <pwm>,<val>"
27
echo " This tool provides manual control of the PWM outputs of the VIA "
28
echo " vt1211 Super-I/O."
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. "
37
echo " <pwm> PWM output (1-2)."
38
echo " <val> PWM duty-cycle (0-255)."
51
# check if we have the right permissions to run
52
if [ `whoami` != "root" ] ; then
53
echo "You must be root to run this script."
57
# parse the command line options
61
while getopts di:r:s: opt ; do
62
[ -z "$action" ] || usage
81
[ -z "$action" ] && usage
82
[ $nr -lt 1 -o $nr -gt 2 ] && usage
83
[ $val -lt 0 -o $val -gt 255 ] && usage
86
dev=`ls -d /sys/devices/platform/vt1211.*`
87
if [ -z "$dev" ] ; then
88
echo "Platform device vt1211 not found. Did you load the vt1211 module?"
93
initfile="/root/.vt1211_pwm${nr}"
96
if [ $action = "display" ] ; then
98
read mode < ${dev}/pwm${nr}_enable
99
if [ $mode -eq 0 ] ; then
100
mode_txt="(disabled)"
101
elif [ $mode -eq 2 ] ; then
104
mode_txt="(unknown) "
106
read val < ${dev}/pwm${nr}
107
dc=$((val * 100 / 255))
108
echo "pwm${nr}: mode = ${mode} ${mode_txt}, val = ${val} (${dc}%)"
113
if [ $action = "init" ] ; then
114
# check for an init file
115
if [ -e $initfile ] ; then
116
echo " $initfile exists. Did you already initialize this PWM?"
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
125
# enable the pwm auto controller
126
set_attr ${dev}/pwm${nr}_enable 2
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
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
144
if [ $action = "restore" ] ; then
145
# check for an init file
146
if [ ! -e $initfile ] ; then
147
echo " $initfile not found. Nothing to restore."
158
if [ $action = "set" ] ; then
159
# check for an init file
160
if [ ! -e $initfile ] ; then
161
echo "$initfile not found. Did you initialize this PWM?"
165
# set the PWM duty-cycle
166
echo $val > ${dev}/pwm${nr}_auto_point3_pwm
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
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}%)."