Changeset 2187

Show
Ignore:
Timestamp:
12/20/03 19:40:39 (9 years ago)
Author:
mds
Message:

initial 2.6 support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/pwm/pwmconfig

    r2178 r2187  
    11#!/bin/bash 
    22# 
    3 # pwmconfig v0.6 
     3# pwmconfig v0.7 
    44# Tests the pwm outputs of sensors and configures fancontrol 
    55# 
     
    4040 
    4141DELAY=5 # 3 seconds delay is too short for large fans, thus I increased it to 5 
     42MAX=255 
    4243 
    4344DIR=/proc/sys/dev/sensors 
     45SDIR=/sys/bus/i2c/devices 
    4446if [ ! -d $DIR ] 
    4547then 
    46         echo $0: 'No sensors found! (modprobe sensor modules?)' 
    47         exit 1 
     48        if [ ! -d $SDIR ] 
     49        then 
     50                echo $0: 'No sensors found! (modprobe sensor modules?)' 
     51                exit 1 
     52        else 
     53                SYSFS=1 
     54                DIR=$SDIR 
     55        fi       
    4856fi 
    4957 
     
    5664fi 
    5765 
    58 PWM=`echo */pwm*` 
    59 if [ "*/pwm*" = "$PWM" ] 
     66PWM=`echo */pwm[1-9]` 
     67if [ "*/pwm[1-9]" = "$PWM" ] 
    6068then 
    6169        echo $0: 'There are no pwm-capable sensor modules installed' 
     
    6371fi 
    6472 
    65 FAN=`echo */fan[1-9]` 
    66 if [ "*/fan[1-9]" = "$FAN" ] 
     73if [ "$SYSFS" = "1" ] 
     74then 
     75        MATCH='*/fan_input[1-9]' 
     76else 
     77        MATCH='*/fan[1-9]' 
     78fi 
     79FAN=`echo $MATCH` 
     80if [ "$MATCH" = "$FAN" ] 
    6781then 
    6882        echo $0: 'There are no fan-capable sensor modules installed' 
    6983        exit 1 
    7084fi 
     85 
     86function pwmdisable() 
     87{ 
     88        if [ "$SYSFS" = "1" ] 
     89        then 
     90                echo $MAX > $1 
     91                ENABLE=${1/pwm/pwm_enable} 
     92                if [ -f $ENABLE ] 
     93                then 
     94                        echo 0 > $ENABLE 
     95                fi 
     96        else 
     97                echo $MAX 0 > $1 
     98        fi 
     99} 
     100 
     101function pwmenable() 
     102{ 
     103        if [ "$SYSFS" = "1" ] 
     104        then 
     105                ENABLE=${1/pwm/pwm_enable} 
     106                if [ -f $ENABLE ] 
     107                then 
     108                        echo 1 > $ENABLE 
     109                fi 
     110        else 
     111                echo $MAX 1 > $1 
     112        fi 
     113} 
     114 
     115function pwmset() 
     116{ 
     117        echo $2 > $1 
     118} 
    71119 
    72120echo 'Found the following PWM controls:' 
     
    76124        if [ -w $i ] 
    77125        then 
    78                 echo 255 0 > $i 
     126                pwmdisable $i 
    79127        else 
    80128                NOTROOT=1 
     
    86134for i in $FAN 
    87135do 
     136        # this will return the first field if there's only one (sysfs) 
    88137        S=`cat $i | cut -d' ' -f2` 
    89138        if [ "$S" = "0" -o "$S" = "-1" ] 
     
    162211        fi 
    163212 
    164         let pwm=255 
     213        let pwm=$MAX 
     214        pwmenable $P 
    165215        while [ $pwm -ge 0 ] 
    166216        do 
    167                 echo $pwm 1 > $P         
    168                 S=`cat $F | cut -d' ' -f2` 
    169                 echo "    PWM $pwm FAN $S" 
    170                 if [ "$PLOT" = "y" ] 
    171                 then 
    172                         echo "$pwm $S" >> $TMP2 
    173                 fi 
    174                 if [ "$S" = "0" -o "S" = "-1" ] 
    175                 then 
    176                         echo 255 0 > $P  
    177                         echo "    Fan Stopped at PWM = $pwm" 
    178                         if [ $pwm -eq 255 ] 
    179                         then 
    180                                 echo "    This fan appears to stop when the PWM is enabled;" 
    181                                 echo "    perhaps the fan input shares a pin with the PWM output" 
    182                                 echo "    on the sensor chip." 
    183                                 rm -f $TMP1 $TMP2 
    184                                 echo 
    185                                 return 0 
    186                         fi 
    187                         break 
    188                 fi 
    189                 let pwm=$pwm-$STEP 
     217                pwmset $P $pwm   
    190218                sleep $PDELAY 
    191219                if [ $? -ne 0 ] 
    192220                then 
    193                         echo 255 0 > $P  
     221                        pwmdisable $P    
    194222                        echo '^C received, aborting...' 
    195223                        rm -f $TMP1 $TMP2 
    196224                        exit 1 
    197225                fi               
     226                # this will return the first field if there's only one (sysfs) 
     227                S=`cat $F | cut -d' ' -f2` 
     228                echo "    PWM $pwm FAN $S" 
     229                if [ "$PLOT" = "y" ] 
     230                then 
     231                        echo "$pwm $S" >> $TMP2 
     232                fi 
     233                if [ "$S" = "0" -o "S" = "-1" ] 
     234                then 
     235                        pwmdisable $P    
     236                        echo "    Fan Stopped at PWM = $pwm" 
     237                        if [ $pwm -eq $MAX ] 
     238                        then 
     239                                echo "    This fan appears to stop when the PWM is enabled;" 
     240                                echo "    perhaps the fan input shares a pin with the PWM output" 
     241                                echo "    on the sensor chip." 
     242                                echo "    You cannot control this fan with this PWM output." 
     243                                rm -f $TMP1 $TMP2 
     244                                echo 
     245                                return 0 
     246                        fi 
     247                        break 
     248                fi 
     249                let pwm=$pwm-$STEP 
    198250        done 
    199         echo 255 0 > $P  
     251        pwmdisable $P    
    200252        if [ "$PLOT" = "y" ] 
    201253        then 
     
    209261do 
    210262        echo Testing pwm control $i ... 
    211         echo 0 1 > $i 
     263        pwmenable $i 
     264        pwmset $i 0 
    212265        sleep $DELAY 
    213266        if [ $? -ne 0 ] 
    214267        then 
    215                 echo 255 0 > $i 
     268                pwmdisable $i 
    216269                echo '^C received, restoring PWM and aborting...' 
    217270                exit 1 
     
    222275        do 
    223276                OS=`echo $SPEEDS | cut -d' ' -f$count` 
     277                # this will return the first field if there's only one (sysfs) 
    224278                S=`cat $j | cut -d' ' -f2` 
    225279                echo "  $j ... speed was $OS now $S" 
    226                 echo 255 0 > $i 
     280                pwmdisable $i 
    227281                let threshold=2*$OS/3 
    228282                if [ $S -lt $threshold ] 
     
    244298                                exit 1 
    245299                        fi               
     300                        # this will return the first field if there's only one (sysfs) 
    246301                        S=`cat $j | cut -d' ' -f2` 
    247302                        if [ $S -lt $threshold ] 
     
    295350fi 
    296351 
    297 TEMPS=`echo */temp[1-9]` 
    298 if [ "*/temp[0-9]*" = "$TEMPS" ] 
     352if [ "$SYSFS" = "1" ] 
     353then 
     354        MATCH='*/temp_input[1-9]' 
     355else 
     356        MATCH='*/temp[1-9]' 
     357fi 
     358TEMPS=`echo $MATCH` 
     359if [ "$MATCH" = "$TEMPS" ] 
    299360then 
    300361        echo $0: 'There are no temperature-capable sensor modules installed' 
     
    353414        do 
    354415                let fanval=fanval+10 
    355                 if [ $fanval -gt 240 ] ; then let fanval=255 ; let fanok=1 ; fi 
     416                if [ $fanval -gt 240 ] ; then let fanval=$MAX ; let fanok=1 ; fi 
    356417                echo -n "Setting $pwms to $fanval..." 
    357418                echo $fanval > $pwms 
     
    360421        done 
    361422        let fanval=fanval+20 
    362         if [ $fanval -gt 240 ] ; then let fanval=255 ; fi 
     423        if [ $fanval -gt 240 ] ; then let fanval=$MAX ; fi 
    363424        echo "OK, using $fanval" 
    364         echo 255 > $pwms 
     425        echo $MAX > $pwms 
    365426} 
    366427 
     
    372433        echo 'We will use this value +20 as the minimum speed.' 
    373434        let fanok=0 
    374         let fanval=255 
     435        let fanval=$MAX 
    375436        until [ "$fanok" = "1" ] 
    376437        do 
     
    383444        done 
    384445        let fanval=fanval+20 
    385         if [ $fanval -gt 255 ] ; then let fanval=255 ; fi 
     446        if [ $fanval -gt $MAX ] ; then let fanval=$MAX ; fi 
    386447        echo "OK, using $fanval" 
    387         echo 255 > $pwms 
     448        echo $MAX > $pwms 
    388449} 
    389450 
     
    445506                for j in $TEMPS 
    446507                do 
     508                        # this will return the first field if there's only one (sysfs) 
    447509                        S=`cat $j | cut -d' ' -f3` 
     510                        if [ "$SYSFS" = "1" ] 
     511                        then 
     512                                let S="$S / 1000" 
     513                        fi 
    448514                        echo "$j        $S" 
    449515                done 
     
    458524                                if [ "$FCTEMPS" = "" ] 
    459525                                then 
    460                                         FCTEMPS="${pwms}=>${tempss}" 
     526                                        FCTEMPS="${pwms}=${tempss}" 
    461527                                else 
    462528                                        FCTEMPS="`echo $FCTEMPS | sed -e "s/${pwmsed}[^ ]* *//g\"` ${pwms}=${tempss}" 
     
    473539                        if [ "$MINTEMP" = "" ] 
    474540                        then 
    475                                 MINTEMP="${pwms}=>${XMT}" 
     541                                MINTEMP="${pwms}=${XMT}" 
    476542                        else 
    477543                                MINTEMP="`echo $MINTEMP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMT}" 
     
    487553                        if [ "$MAXTEMP" = "" ] 
    488554                        then 
    489                                 MAXTEMP="${pwms}=>${XMT}" 
     555                                MAXTEMP="${pwms}=${XMT}" 
    490556                        else 
    491557                                MAXTEMP="`echo $MAXTEMP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMT}" 
    492558                        fi 
    493559                        echo 
    494                         echo 'Enter the minimum PWM value (0-255)' 
     560                        echo "Enter the minimum PWM value (0-$MAX)" 
    495561                        echo -n "at which the fan STARTS spinning (press t to test) ($DEFMINSTART): " 
    496562                        read XMV 
     
    506572                        if [ "$MINSTART" = "" ] 
    507573                        then 
    508                                 MINSTART="${pwms}=>${XMV}" 
     574                                MINSTART="${pwms}=${XMV}" 
    509575                        else 
    510576                                MINSTART="`echo $MINSTART | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMV}" 
    511577                        fi 
    512578                        echo 
    513                         echo 'Enter the minimum PWM value (0-255)' 
     579                        echo "Enter the minimum PWM value (0-$MAX)" 
    514580                        echo -n "at which the fan STOPS spinning (press t to test) ($DEFMINSTOP): " 
    515581                        read XMV 
     
    525591                        if [ "$MINSTOP" = "" ] 
    526592                        then 
    527                                 MINSTOP="${pwms}=>${XMV}" 
     593                                MINSTOP="${pwms}=${XMV}" 
    528594                        else 
    529595                                MINSTOP="`echo $MINSTOP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMV}"