summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2013-02-07 06:19:57 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2013-02-07 06:19:57 +0200
commitea4f2c77727801359db983f6ccf1894aa24ebb91 (patch)
tree431d725ac7ac68caab3854474cac08b8fdca96c0
parentbc43bf01f5f37513caf470bcea5be1524ed6284b (diff)
Add power related scripts
-rwxr-xr-xpower/intel-audio-powersave9
-rwxr-xr-xpower/pci_devices61
-rwxr-xr-xpower/pcie_aspm5
-rwxr-xr-xpower/sata_alpm10
-rwxr-xr-xpower/usb_autosuspend8
-rwxr-xr-xpower/wireless79
6 files changed, 172 insertions, 0 deletions
diff --git a/power/intel-audio-powersave b/power/intel-audio-powersave
new file mode 100755
index 0000000..c4cd5dd
--- /dev/null
+++ b/power/intel-audio-powersave
@@ -0,0 +1,9 @@
1#!/bin/sh
2
3for dev in /sys/module/snd_*; do
4 [ -w "$dev/parameters/power_save" ] || continue
5 printf "Setting power savings for %s to %d..." "${dev##*/}" "1"
6 echo "1" > "$dev/parameters/power_save" && echo Done. || echo Failed.
7done
8
9exit 0
diff --git a/power/pci_devices b/power/pci_devices
new file mode 100755
index 0000000..a6fe6d4
--- /dev/null
+++ b/power/pci_devices
@@ -0,0 +1,61 @@
1#!/bin/sh
2
3#
4# This script adjusts the power control of a set of PCI devices that
5# prove beneficial to enable power savings
6#
7
8PCI_DEVICES_PM_ENABLE="${PCI_DEVICES_PM_ENABLE:-true}"
9
10set_pci_device()
11{
12 for dev in /sys/bus/pci/devices/* ; do
13 if [ -e $dev/class -a -e $dev/power/control ]; then
14 id=`basename $dev`
15 case `cat $dev/class` in
16 0x020000) # ethernet
17 echo "Setting Ethernet device $id to $1"
18 echo $1 > $dev/power/control
19 ;;
20 0x028000) # wireless
21 echo "Setting Wireless device $id to $1"
22 echo $1 > $dev/power/control
23 ;;
24 0x040300) # audio
25 echo "Setting Audio device $id to $1"
26 echo $1 > $dev/power/control
27 ;;
28 0x060000) # host bridge
29 echo "Setting Host Bridge $id to $1"
30 echo $1 > $dev/power/control
31 ;;
32 0x080500) # SD card reader
33 echo "Setting SD card reader device $id to $1"
34 echo $1 > $dev/power/control
35 ;;
36 0x088000|0x088001) # card reader
37 echo "Setting card reader device $id to $1"
38 echo $1 > $dev/power/control
39 ;;
40 0x0c0000|0x0c0010) # firewire
41 echo "Setting FireWire device $id to $1"
42 echo $1 > $dev/power/control
43 ;;
44 esac
45 fi
46 done
47}
48
49case "$1" in
50 true) # powersaving on
51 [ "$PCI_DEVICES_PM_ENABLE" = true ] && set_pci_device "auto"
52 ;;
53 false) # powersaving off
54 [ "$PCI_DEVICES_PM_ENABLE" = true ] && set_pci_device "auto"
55 ;;
56 *)
57 exit 254
58 ;;
59esac
60
61exit 0
diff --git a/power/pcie_aspm b/power/pcie_aspm
new file mode 100755
index 0000000..f1ee4b0
--- /dev/null
+++ b/power/pcie_aspm
@@ -0,0 +1,5 @@
1#!/bin/sh
2
3echo powersave > /sys/module/pcie_aspm/parameters/policy
4
5exit 0
diff --git a/power/sata_alpm b/power/sata_alpm
new file mode 100755
index 0000000..53c6bc3
--- /dev/null
+++ b/power/sata_alpm
@@ -0,0 +1,10 @@
1#!/bin/sh
2
3for f in /sys/class/scsi_host/host*; do
4 [ -w "$f/link_power_management_policy" ] || continue
5 printf "Setting SATA ALPM on %s to %s..." "${f##*/}" "min_power"
6 echo "min_power" > "$f/link_power_management_policy" && echo Done. || \
7 echo Failed.
8done
9
10exit 0
diff --git a/power/usb_autosuspend b/power/usb_autosuspend
new file mode 100755
index 0000000..3e811be
--- /dev/null
+++ b/power/usb_autosuspend
@@ -0,0 +1,8 @@
1#!/bin/sh
2
3for dev in /sys/bus/usb/devices/* ; do
4 echo Setting $dev to auto
5 echo auto > $dev/power/control
6 done
7
8exit 0
diff --git a/power/wireless b/power/wireless
new file mode 100755
index 0000000..9aea282
--- /dev/null
+++ b/power/wireless
@@ -0,0 +1,79 @@
1#!/bin/sh
2
3. "${PM_FUNCTIONS}"
4
5# See if we have the usual wireless tools.
6# Do not just fail because not all cards require these.
7which iwpriv >/dev/null 2>&1 && have_iwpriv="true"
8which iwconfig >/dev/null 2>&1 && have_iwconfig="true"
9
10# If only all the drivers did The Right Thing with iwconfig power.
11# Too bad they do not.
12
13get_wireless_params() {
14 # $1 = interface
15 # $2 = on or off
16 unset iwpriv iwconfig iwlevel
17
18 # Don't do anything if we cannot find a driver for this iface.
19 [ -L "/sys/class/net/$1/device/driver" ] || return 1
20 # Skip if not a wireless card.
21 [ -d "/sys/class/net/$1/wireless" ] || return 1
22 # Also don't do anything if the device is disabled
23 [ "$(cat /sys/class/net/$1/device/enable)" = "1" ] || return 1
24 driver="$(readlink "/sys/class/net/$1/device/driver")"
25 driver=${driver##*/}
26 case $driver in
27 ipw2100) iwpriv_ac="set_power 5"
28 iwpriv_batt="set_power 5"
29 iwconfig_ac="power on"
30 iwconfig_batt="power on";;
31 ipw3945)
32 iwpriv_ac="set_power 6"
33 iwpriv_batt="set_power 7";;
34 iwl*) if [ -f "/sys/class/net/$1/device/power_level" ]; then
35 iwlevel_ac=3
36 iwlevel_batt=3
37 else
38 iwconfig_ac="power on"
39 iwconfig_batt="power on"
40 fi;;
41 *) iwconfig_ac="power on"
42 iwconfig_batt="power on";;
43 esac
44 case $2 in
45 off) [ "$iwpriv_ac" ] && iwpriv="$iwpriv_ac"
46 [ "$iwconfig_ac" ] && iwconfig="$iwconfig_ac"
47 [ "$iwlevel_ac" ] && iwlevel="$iwlevel_ac";;
48 on) [ "$iwpriv_batt" ] && iwpriv="$iwpriv_batt"
49 [ "$iwconfig_batt" ] && iwconfig="$iwconfig_batt"
50 [ "$iwlevel_batt" ] && iwlevel="$iwlevel_batt";;
51 esac
52 return 0
53}
54
55wireless_powersave() {
56 for dev in /sys/class/net/*; do
57 get_wireless_params "${dev##*/}" "$1" || continue
58 ret=0
59 printf "Turning powersave for %s %s..." "${dev##*/}" "$1"
60 if [ "$have_iwconfig" = true -a "$iwconfig" ]; then
61 iwconfig "${dev##*/}" $iwconfig || ret=1
62 fi
63 if [ "$have_iwpriv" = true -a "$iwpriv" ]; then
64 iwpriv "${dev##*/}" $iwpriv || ret=1
65 fi
66 if [ "$iwlevel" ]; then
67 echo "$iwlevel" > "$dev/device/power_level" || ret=1
68 fi
69 [ "$ret" -eq 0 ] && echo Done. || echo Failed.
70 done
71}
72
73case $1 in
74 true) wireless_powersave on ;;
75 false) wireless_powersave off ;;
76 *) exit $NA ;;
77esac
78
79exit 0