Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ### BEGIN INIT INFO
- # Provides: x220-pm
- # Required-Start: $local_fs
- # Required-Stop: $local_fs
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Sets various power management features for X220 laptops
- # Description: Sets available power management options in /sys for X220 laptops.
- # Disables PCI "Runtime PM" on shutdown in order to shutdown the
- # laptop properly.
- ### END INIT INFO
- set -e
- BAT_START_CHARGE_THRESH=30
- BAT_STOP_CHARGE_THRESH=85
- PCI_RUNTIME_PM_ACTIVE='auto'
- PCI_RUNTIME_PM_DISABLED='on'
- SATA_LINK_PM_POLICY='min_power'
- CPU_GOVERNOR='ondemand'
- various_pm() {
- # disables WOL for ethernet device
- # enables WLAN device power management
- # enables sound card power management
- ethtool -s eth0 wol d
- ifconfig eth0 down
- iwconfig wlan0 power on
- echo 1 > /sys/module/snd_hda_intel/parameters/power_save
- }
- bat_charge_thresh() {
- # sets battery charge thresholds
- # note: start_charge_thresh doesn't work with smapi 0.41 and is therefore disabled
- local start_thresh=$1
- local stop_thresh=$2
- for bat in /sys/devices/platform/smapi/BAT*
- do
- #echo $start_thresh > $bat/start_charge_thresh
- echo $stop_thresh > $bat/stop_charge_thresh
- done
- }
- sata_link_pm() {
- # sets SATA link power management policy
- local policy=$1
- for linkpm in /sys/class/scsi_host/host*/link_power_management_policy
- do
- echo $policy > $linkpm
- done
- }
- cpu_governor() {
- # sets the CPU scaling governor
- local gov=$1
- for cpugov in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
- do
- echo $gov > $cpugov
- done
- }
- pci_runtime_pm() {
- # sets the PCI runtime PM for all available devices
- local mode=$1 # 'on' or 'auto' where 'auto' is causing shutdown problems
- for pcicontrol in /sys/bus/pci/devices/*/power/control
- do
- echo $mode > $pcicontrol
- done
- }
- case "$1" in
- start)
- various_pm
- bat_charge_thresh $BAT_START_CHARGE_THRESH $BAT_STOP_CHARGE_THRESH
- cpu_governor $CPU_GOVERNOR
- sata_link_pm $SATA_LINK_PM_POLICY
- pci_runtime_pm $PCI_RUNTIME_PM_ACTIVE
- ;;
- stop)
- pci_runtime_pm $PCI_RUNTIME_PM_DISABLED
- ;;
- *)
- N=/etc/init.d/x220-pm
- echo "Usage: $N {start|stop}" >&2
- exit 1
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement