This patch looks great, but isn't quite sufficient. This will set the autosuspend timeout for all existing USB devices to 0 when activated, but will not modify the timeout for new USB devices. This can be set by writing to /sys/module/usbcore/parameters/autosuspend. Both this and the existing behavior of the script are required to make sure that all USB devices connected to the system when on battery have autosuspend=0.

I'm not sure how to set the default power level for new devices - it would probably require some HAL hooks.

Attached is a modified version of the script with this change.

- Michael
#! /bin/sh
# 
# Laptop mode tools module: USB Auto Suspend  power saving mode.
#

if [ x$CONTROL_USB_AUTOSUSPEND = x1 ] ; then
    if [ $ON_AC -eq 1 ]; then
        if [ -f /sys/module/usbcore/parameters/autosuspend ]; then
            echo 2 > /sys/module/usbcore/parameters/autosuspend
            $LM_VERBOSE && echo "Disabling auto suspend mode for new USB 
devices."
        fi
        if [ -d /sys/bus/usb/devices ]; then
            for usb_device in /sys/bus/usb/devices/*;
            do
                usb_device=`basename $usb_device`;
                if [ -f /sys/bus/usb/devices/$usb_device/power/autosuspend ]; 
then
                    echo 2 > /sys/bus/usb/devices/$usb_device/power/autosuspend;
                    $LM_VERBOSE && echo "Disabling auto suspend mode for usb 
device $usb_device." >> $OUTPUT
                fi

                if [ -f /sys/bus/usb/devices/$usb_device/power/level ]; then
                    echo "auto" > /sys/bus/usb/devices/$usb_device/power/level;
                    $LM_VERBOSE && echo "Setting auto power level for usb 
device $usb_device." >> $OUTPUT
                fi
            done
        else
            #This will rarely happen.
            $LM_VERBOSE && echo "There are no USB devices." >> $OUTPUT
        fi
    else
        if [ -f /sys/module/usbcore/parameters/autosuspend ]; then
            echo 0 > /sys/module/usbcore/parameters/autosuspend
            $LM_VERBOSE && echo "Enabling auto suspend mode for new USB 
devices."
        fi
        if [ -d /sys/bus/usb/devices ]; then
            for usb_device in /sys/bus/usb/devices/*;
            do
                usb_device=`basename $usb_device`;
                if [ -f /sys/bus/usb/devices/$usb_device/power/autosuspend ]; 
then
                    echo 0 > /sys/bus/usb/devices/$usb_device/power/autosuspend;
                    $LM_VERBOSE && echo "Enabling auto suspend mode for usb 
device $usb_device." >> $OUTPUT
                fi

                if [ -f /sys/bus/usb/devices/$usb_device/power/level ]; then
                    echo "auto" > /sys/bus/usb/devices/$usb_device/power/level;
                    $LM_VERBOSE && echo "Enabling auto power level for usb 
device $usb_device." >> $OUTPUT
                fi
            done
        else
            #This will rarely happen.
            $LM_VERBOSE && echo "There are no USB devices." >> $OUTPUT
        fi
    fi
else
    $LM_VERBOSE && echo "USB auto suspend is disabled." >> $OUTPUT
fi

Reply via email to