Advertisement
Guest User

x220 power management init script

a guest
Dec 15th, 2011
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.23 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: x220-pm
  4. # Required-Start:    $local_fs
  5. # Required-Stop:     $local_fs
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Sets various power management features for X220 laptops
  9. # Description:       Sets available power management options in /sys for X220 laptops.
  10. #                    Disables PCI "Runtime PM" on shutdown in order to shutdown the
  11. #                    laptop properly.
  12. ### END INIT INFO
  13.  
  14. set -e
  15.  
  16. BAT_START_CHARGE_THRESH=30
  17. BAT_STOP_CHARGE_THRESH=85
  18. PCI_RUNTIME_PM_ACTIVE='auto'
  19. PCI_RUNTIME_PM_DISABLED='on'
  20. SATA_LINK_PM_POLICY='min_power'
  21. CPU_GOVERNOR='ondemand'
  22.  
  23.  
  24. various_pm() {
  25. # disables WOL for ethernet device
  26. # enables WLAN device power management
  27. # enables sound card power management
  28.     ethtool -s eth0 wol d
  29.     ifconfig eth0 down
  30.     iwconfig wlan0 power on
  31.     echo 1 > /sys/module/snd_hda_intel/parameters/power_save
  32. }
  33.  
  34. bat_charge_thresh() {
  35. # sets battery charge thresholds
  36. # note: start_charge_thresh doesn't work with smapi 0.41 and is therefore disabled
  37.     local start_thresh=$1
  38.     local stop_thresh=$2
  39.     for bat in /sys/devices/platform/smapi/BAT*
  40.     do
  41.         #echo $start_thresh > $bat/start_charge_thresh
  42.         echo $stop_thresh > $bat/stop_charge_thresh
  43.     done
  44. }
  45.  
  46. sata_link_pm() {
  47. # sets SATA link power management policy
  48.     local policy=$1
  49.     for linkpm in /sys/class/scsi_host/host*/link_power_management_policy
  50.     do
  51.         echo $policy > $linkpm
  52.     done
  53. }
  54.  
  55. cpu_governor() {
  56. # sets the CPU scaling governor
  57.     local gov=$1
  58.     for cpugov in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  59.     do
  60.         echo $gov > $cpugov
  61.     done
  62. }
  63.  
  64. pci_runtime_pm() {
  65. # sets the PCI runtime PM for all available devices
  66.     local mode=$1 # 'on' or 'auto' where 'auto' is causing shutdown problems
  67.     for pcicontrol in /sys/bus/pci/devices/*/power/control
  68.     do
  69.         echo $mode > $pcicontrol
  70.     done
  71. }
  72.  
  73.  
  74. case "$1" in
  75.     start)
  76.         various_pm
  77.         bat_charge_thresh $BAT_START_CHARGE_THRESH $BAT_STOP_CHARGE_THRESH
  78.         cpu_governor $CPU_GOVERNOR
  79.         sata_link_pm $SATA_LINK_PM_POLICY
  80.         pci_runtime_pm $PCI_RUNTIME_PM_ACTIVE
  81.     ;;
  82.     stop)
  83.         pci_runtime_pm $PCI_RUNTIME_PM_DISABLED
  84.     ;;
  85.     *)
  86.         N=/etc/init.d/x220-pm
  87.         echo "Usage: $N {start|stop}" >&2
  88.         exit 1
  89.     ;;
  90. esac
  91.  
  92. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement