1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
case "$1" in
  true) # Enable power saving settings on battery
        # Device Runtime-PM
        for dpcontrol in /sys/bus/{pci,spi,i2c}/devices/*/power/control; do echo auto > $dpcontrol; done
        # Disable nmi_watchdog
        echo 0 > /proc/sys/kernel/nmi_watchdog
        # kernel write mode
        echo 5 > /proc/sys/vm/laptop_mode
        echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
        # disk powersave
        hdparm -S 36 -B 128 /dev/sda &> /dev/null
        for i in /sys/class/scsi_host/host*/link_power_management_policy; do echo min_power > $i; done
        # sound card powersave
        echo 60 > /sys/module/snd_hda_intel/parameters/power_save
        echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
        # wlan0 powersave
        iw dev wlan0 set power_save on &> /dev/null
        ;;
  false) # Return to default on AC power
        # Device Runtime-PM
        for dpcontrol in /sys/bus/{pci,spi,i2c}/devices/*/power/control; do echo on > $dpcontrol; done
        # Enable nmi_watchdog
        echo 1 > /proc/sys/kernel/nmi_watchdog
        # kernel write mode
        echo 0 > /proc/sys/vm/laptop_mode
        echo 500 > /proc/sys/vm/dirty_writeback_centisecs
        # disk powersave
        hdparm -S 0 -B 254 /dev/sda &> /dev/null
        for i in /sys/class/scsi_host/host*/link_power_management_policy; do echo max_performance > $i; done
        # sound card powersave
        echo 300 > /sys/module/snd_hda_intel/parameters/power_save
        echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
        # wlan0 powersave
        iw dev wlan0 set power_save off &> /dev/null
        ;;
esac
exit 0