From e97786e97972b095f182d1ebbaf1fdf87f17808f Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Sat, 7 Apr 2012 11:57:45 -0400 Subject: [PATCH] More logical pwr_{on,off}. --- sbin/snail.nv_pwr_off | 38 +++++++++++++++++++++++++++----------- sbin/snail.nv_pwr_on | 38 +++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/sbin/snail.nv_pwr_off b/sbin/snail.nv_pwr_off index c2a5561..8d4a0f8 100755 --- a/sbin/snail.nv_pwr_off +++ b/sbin/snail.nv_pwr_off @@ -1,14 +1,30 @@ #!/bin/bash -model=`dmidecode $@ -s system-product-name` +TRIES=8 -let retry=8 -while [ 0 -lt $retry ]; do - if [ -f /sys/kernel/debug/vgaswitcheroo/switch ]; then +lsmod | grep '^nouveau ' >/dev/null && modprobe -rf nouveau &>/dev/null + +# Trying vgaswitcheroo method +if [ -f /sys/kernel/debug/vgaswitcheroo/switch ]; then + let tries=$TRIES + while [ 0 -lt $tries ]; do modprobe -r nvidia \ && echo 'OFF DIS' > /sys/kernel/debug/vgaswitcheroo/switch \ && exit 0 - else + + sleep 0.01 + let tries-- + echo "tries left: $tries" + done + echo "Cann't power off nVidia chip ;-(" + exit -1 +fi + +# Trying acpi_call method +if [ -f /proc/acpi/call ]; then + model=`dmidecode $@ -s system-product-name` + tries=$TRIES + while [ 0 -lt $tries ]; do case "$model" in M11XR2) modprobe -r nvidia \ @@ -89,12 +105,12 @@ while [ 0 -lt $retry ]; do *) echo "Snail: unknown Notebook model: $model"; exit -1 ;; esac - fi - sleep 0.2 - let retry-- - echo "retry countdown: $retry" -done + sleep 0.01 + let tries-- + echo "tries left: $tries" + done +fi +echo "Cann't power off nVidia chip" exit -1 - diff --git a/sbin/snail.nv_pwr_on b/sbin/snail.nv_pwr_on index b300378..c25a02a 100755 --- a/sbin/snail.nv_pwr_on +++ b/sbin/snail.nv_pwr_on @@ -1,14 +1,30 @@ #!/bin/bash -model=`dmidecode $@ -s system-product-name` +TRIES=8 -let retry=8 -while [ 0 -lt $retry ]; do - if [ -f /sys/kernel/debug/vgaswitcheroo/switch ]; then +lsmod | grep '^nouveau ' >/dev/null && modprobe -rf nouveau &>/dev/null + +# Trying vgaswitcheroo method +if [ -f /sys/kernel/debug/vgaswitcheroo/switch ]; then + let tries=$TRIES + while [ 0 -lt $tries ]; do echo 'ON DIS' > /sys/kernel/debug/vgaswitcheroo/switch \ && modprobe nvidia \ && exit 0 - else + + sleep 0.01 + let tries-- + echo "tries left: $tries" + done + echo "Cann't power on nVidia chip ;-(" + exit -1 +fi + +# Trying acpi_call method +if [ -f /proc/acpi/call ]; then + model=`dmidecode $@ -s system-product-name` + tries=$TRIES + while [ 0 -lt $tries ]; do case "$model" in M11XR2) echo '\_SB.PCI0.P0P2.PEGP._PS0' > /proc/acpi/call \ @@ -89,12 +105,12 @@ while [ 0 -lt $retry ]; do *) echo "Snail: unknown Notebook model: $model"; exit -1 ;; esac - fi - sleep 0.01 - let retry-- - echo "retry countdown $retry" -done + sleep 0.01 + let tries-- + echo "tries left: $tries" + done +fi +echo "Cann't power on nVidia chip" exit -1 -