#!/bin/sh

# Samsung N220 laptop power saving in Debian
# By Chris Newland @chriswhocodes, www.chrisnewland.com
# Free to copy, modify, and distribute!

# Set the brightness to 5 out of 255 (00-ff)
setpci -s 00:02.0 F4.B=05

# Set all USB devices to autosuspend when not in use
for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 1 >$i; done

# Set all USB devices to auto power management
for i in /sys/bus/usb/devices/*/power/level; do echo auto >$i; done

# Set SATA links 0-3 to use minimum power
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
echo min_power > /sys/class/scsi_host/host1/link_power_management_policy
echo min_power > /sys/class/scsi_host/host2/link_power_management_policy
echo min_power > /sys/class/scsi_host/host3/link_power_management_policy

# Tell the kernel to use maximum laptop_mode power saving features
echo 5 > /proc/sys/vm/laptop_mode

# Don't write to disk immediately, allow 15 seconds of unwritten data
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

# Set the Intel high definition audio controller to use power saving
echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller

# Send the audio subsystem to sleep 1 second after the last sound has finished
echo 1 > /sys/module/snd_hda_intel/parameters/power_save