Changing fan speed of ATI under linux

Intro

Having multiple GPUs under Linux means you are especially interested in wanting to adjust fan speeds manually. The trick is to change the DISPLAY to the device you want to alter.

Solution

Example for two devices:

$ export DISPLAY=:0
$ aticonfig --pplib-cmd "set fanspeed 0 60"

$ export DISPLAY=:0.1
$ aticonfig --pplib-cmd "set fanspeed 0 60"

Shell Script

#!/bin/bash

##
# atifan.sh v1.1
# by chort
##

# NB: Changing fan speed does not persist through reboots!

# Which GPU device you're modifying. If you have only one GPU, it's 0,
#  unless you have a multi-GPU card (5970, 6990) in which case you have
#  to set each separately (once for DEVICE=0, once for DEVICE=1).
# XXX Todo: Improve usability by passing device ID as argument.
DEVICE=0
export DISPLAY=":0.${DEVICE}"

function usage {
        echo "Usage: $0 [get|set <%>]"
}

if [ -z "$1" ]
then
        usage
fi

if [ X"$1" == "Xget" ]
then
        aticonfig --pplib-cmd "get fanspeed 0"
        aticonfig --adapter=$DEVICE --odgt
fi

if [ X"$1" == "Xset" ]
then
        if [ $2 -gt 9 2>/dev/null ] && [ $2 -lt 99 ]
        then
                echo "Setting fanspeed to ${2}%"
                aticonfig --pplib-cmd "set fanspeed 0 $2"
                aticonfig --pplib-cmd "get fanspeed 0"
        else
                # Only values from 10% to 100% are valid
                usage
        fi
fi