# Switchable Graphics on Asus UL30vt (asus-vga-switcheroo)

## Nicias

See later post for new method

 Ebuild now in sunrise

My asus UL30vt has both an nvidia card and a lower-powered (in both senses) intel card. I recently got switching between the two down, thanks in large part to the people in the ubuntu forums In my current situation.

I can chose which card to use at boot time in the bios.

 I don't have to do anything with config files

 The other card is powered down

 the brightness keys work for both cards (also I have an init.d service that manages brightness)

The forum posts outline how to semi-permanently pick one card via a bios setting  (SATA->compatible turns off the intel card for no clear reason.) or a module (the asus_nvidia module  in the first post, not one of the later ones) deactivates the nvidia card. This works fine, if you don't actually want to switch. The problems with this plan are:

 It requires editing xorg.conf

 Loading the asus_nvidia module when you are using the nvidia card, naturally causes a black screen.

 the brightness control system is different with the two cards.

The first problem was solved for me by the xorg people. Gentoo seems to be superior to ubuntu in this respect. My xorg runs fine in both configurations with no xorg.conf so no problems there. I stumbled on a solution to the other problems while taking the advice of powertop. Powertop suggested I lower the power going to my sata chipset or something. The command it suggested was:

```
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
```

I put this in /etc/conf.d/local.start, and then while messing around, I noticed that it wasn't working when I was using my nvidia card. The random sata setting that turns off the nvidia card in the bios also caused this /sys/ file to not be created. So I could use its existence as a test for the bios setting. 

Thus I put the module load line in local.start, so I could test for this, and not in modules.autoload.d. The same test allowed me to control the backlight in either case.

The only final problem was the module needs to be reloaded every time you hibernate. I was tempted to put it in my /etc/hibernate/common.conf as ReloadModules or somesuch, but that would cause it to be reloaded no matter which card I was using. Thus I put it under UnloadModules, and put local under ServicesRestart. Without further ado here are the relevant files:

/etc/conf.d/local.start

```

# /etc/conf.d/local.start

# This is a good place to load any misc programs

# on startup (use &>/dev/null to hide output)

echo 1500 > /proc/sys/vm/dirty_writeback_centisecs 

if [ -f "/sys/class/scsi_host/host0/link_power_management_policy" ] ; then 

   echo min_power > /sys/class/scsi_host/host0/link_power_management_policy 

   modprobe asus_nvidia

fi
```

/etc/conf.d/lcd-dim

```

# brightness level in ac mode. (intel is in hex)

NVIDIA_NORMAL=100

INTEL_NORMAL=ff

# brightness level in battery mode. (intel is in hex.)

NVIDIA_DIM=11

INTEL_DIM=10
```

/etc/init.d/lcd-dim

```
#!/sbin/runscript

start() {

        ebegin "Setting LCD brightness low"

        if [ -e /sys/class/scsi_host/host0/link_power_management_policy ]

        then

                setpci -s 00:02.0 F4.B=${INTEL_DIM}

        else      

                echo "${NVIDIA_DIM}" > /proc/acpi/video/VGA1/LCDD/brightness

        fi

        eend $?

}

stop () {

        ebegin "Setting LCD brightness high"

        if [ -e /sys/class/scsi_host/host0/link_power_management_policy ]

        then

                setpci -s 00:02.0 F4.B=${INTEL_NORMAL}

        else

                echo "${NVIDIA_NORMAL}" > /proc/acpi/video/VGA1/LCDD/brightness

        fi

        eend $?

}
```

That is the basic part, now for the hotkey acpi event files:

/etc/acpi/events/bl-key-up

```
event=hotkey ATKD 0000001

action=/etc/acpi/actions/bl_key_up.sh
```

/etc/acpi/events/bl-key-down

```
event=hotkey ATKD 0000002

action=/etc/acpi/actions/bl_key_down.sh
```

and the corresponding actions:

/etc/acpi/actions/bl_key_up.sh:

```

#!/bin/bash

if [ -e /sys/class/scsi_host/host0/link_power_management_policy ]

then

   brightness=$((0x`setpci -s 00:02.0 F4.B`+16));

   if [ $brightness -gt $((0xff)) ] ; then

      brightness=$((0xff));

   fi

   setpci -s 00:02.0 F4.B=`printf '%x' $brightness`;

else

   brightness=$((`tail -1 /proc/acpi/video/VGA1/LCDD/brightness | cut -f2 -d" "`+6))

   if [ $brightness -gt 60 ]

   then 

      brightness=$((brightness+1))

   fi

   if [ $brightness -gt 100 ]

   then 

      brightness=100

   fi

   echo ${brightness}

        echo ${brightness} > /proc/acpi/video/VGA1/LCDD/brightness

fi
```

/etc/acpi/actions/bl_key_down.sh:

```
#!/bin/bash

if [ -e /sys/class/scsi_host/host0/link_power_management_policy ]

then

   brightness=$((0x`setpci -s 00:02.0 F4.B`-4));

   if [ $brightness -lt 0 ] ; then

      brightness=1;

   fi

   setpci -s 00:02.0 F4.B=`printf '%x' $brightness`;

else

   brightness=$((`tail -1 /proc/acpi/video/VGA1/LCDD/brightness | cut -f2 -d" "`-7))

   if [ $brightness -lt 60 ]

   then 

      brightness=$((brightness+1))

   fi

   if [ $brightness -lt 5 ]

   then 

      brightness=5

   fi

   echo ${brightness}

        echo ${brightness} > /proc/acpi/video/VGA1/LCDD/brightness

fi
```

Well, I hope that helps anyone else with the same or a similar laptop. If you came here from the ubuntu forums, sorry this post is rather technical and gentoo-specific. I hope you can adjust it for ubuntu.Last edited by Nicias on Sun May 29, 2011 8:45 pm; edited 4 times in total

----------

## Nicias

I also have an ebuild for the module, if someone wants it.

----------

## josedb

will be apreciated.  Hope this works on ul80 series, seems to be no  problem.

----------

## josedb

Asus UL80vt here

Geforce m210

Intel 4500

```
jose-mov ~ # /etc/init.d/lcd-dim start

/etc/init.d/lcd-dim: línea 4:  : no se encontró la orden

/etc/init.d/lcd-dim: línea 5:  : no se encontró la orden

/etc/init.d/lcd-dim: línea 6:  : no se encontró la orden

/etc/init.d/lcd-dim: línea 7:  : no se encontró la orden

/etc/init.d/lcd-dim: línea 8:  : no se encontró la orden

/etc/init.d/lcd-dim: línea 9:  : no se encontró la orden

/etc/init.d/lcd-dim: línea 10:  : no se encontró la orden

/etc/init.d/lcd-dim: línea 11:  : no se encontró la orden

 * ERROR: lcd-dim failed to start

```

```
jose-mov ~ # sh /etc/acpi/actions/bl_key_down.sh 

/etc/acpi/actions/bl_key_down.sh: línea 6: error sintáctico cerca del elemento inesperado `then'

/etc/acpi/actions/bl_key_down.sh: línea 6: `   if [ $brightness -lt 0 ] ; then '
```

```
jose-mov ~ # dmesg |grep asus

[    3.313799] asus_laptop: Asus Laptop Support version 0.42

[    3.385137] asus_laptop:   UL80VT model detected

[    3.385594] asus_laptop: Backlight controlled by ACPI video driver

[    3.385652] input: Asus Laptop extra buttons as /devices/platform/asus_laptop/input/input7
```

setpci -s 00:02.0 F4.B=`printf '%x' $brightness`;  works for hexadecimal values

----------

## Nicias

Sorry for the delay, life here has been somewhat hectic. Here is my ebuild:

```
# Copyright 1999-2008 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

inherit linux-mod eutils

DESCRIPTION="modules to turn of nvidia card for asus laptops"

HOMEPAGE="http://usbirboy.sourceforge.net/"

SRC_URI="${PN}.tgz"

SLOT="0"

KEYWORDS="alpha amd64 ia64 ppc ppc64 x86"

LICENSE="GPL-2"

IUSE=""

S=${WORKDIR}/${PN}

DEPEND=""

RDEPEND=""

MODULE_NAMES="asus_nvidia(acpi:${S})"

BUILD_TARGEST="default"

pkg_setup() {

        linux-mod_pkg_setup || die

}

src_compile(){

        linux-mod_src_compile || die

}

src_install(){

        linux-mod_src_install || die

}
```

Two things.

 I have no idea where I got the tarball from. I'd put it up if I knew someplace to dump it (like pastebin for files.) its less than 4k

 The ebuild only works about half the time. Go figure.  

On to your specific question.  It looks like the files got corrupted somewhere along the way. I don't see why the init script should be giving what I guess is "command not found" every line.

----------

## Nicias

Ok, someone has worked out how to use the switcheroo code in the kernel for this laptop.  Their git repo is at:

https://github.com/awilliam/asus-switcheroo

I packaged that and put in a bug for a new ebuild

It works for me with the closed-source nvidia driver. When I start up, the nvidia card is powered off, and use the intel card. If I want to, I can run a command and switch to the nvidia card, at the cost of losing my VT's. To switch back I have to restart, but no mucking around in the BIOS.

I also have modified my LCD dimming scripts, and I can put them up if there is interest.

----------

## anarchist

I would be very interested in getting the brightness scripts. 

The switcheroo itself works great for me. Thanks for that  :Smile: 

----------

## Nicias

No problem. Here are my scripts, as written they depend on using the closed source nvidia drivers:

/etc/init.d/lcd-dim

```
#!/sbin/runscript

start() {

    if [ -f /proc/acpi/video/VGA1/LCDD/brightness ]

    then

        ebegin "Setting LCD brightness"

        if ( lsmod | grep nvidia ) 

        then

                echo "${NVIDIA_DIM}" > /proc/acpi/video/VGA1/LCDD/brightness

        else            

                setpci -s 00:02.0 F4.B=${INTEL_DIM}

        fi

        eend $?

    else

        ewarn "Setting LCD brightness is not supported."

    fi

}

stop () {

    if [ -f /proc/acpi/video/VGA1/LCDD/brightness ]

    then

        ebegin "Setting LCD brightness"

        if [ -e /sys/class/scsi_host/host0/link_power_management_policy ]

        then

                setpci -s 00:02.0 F4.B=${INTEL_NORMAL}

        else

                echo "${NVIDIA_NORMAL}" > /proc/acpi/video/VGA1/LCDD/brightness

        fi

        eend $?

    else

        ewarn "Setting LCD brightness is not supported."

    fi

}
```

/etc/conf.d/lcd-dim

```
# See /proc/acpi/video/VGA1/LCDD/brightness for available values

# Please read /usr/src/linux/Documentation/thinkpad-acpi.txt

# brightness level in ac mode. Default is 7. (intel is in hex)

NVIDIA_NORMAL=100

INTEL_NORMAL=ff

# brightness level in battery mode. Default is 4. (intel is in hex.)

NVIDIA_DIM=11

INTEL_DIM=10
```

/etc/acpi/events/bl-key-down

```
# replace "ac_adapter" below with the event generated on your laptop

# For example, ac_adapter.* will match ac_adapter AC 00000080 00000000

event=hotkey ATKD 0000002

action=/etc/acpi/actions/bl_key_down.sh
```

/etc/acpi/events/bl-key-up

```
# replace "ac_adapter" below with the event generated on your laptop

# For example, ac_adapter.* will match ac_adapter AC 00000080 00000000

event=hotkey ATKD 0000001

action=/etc/acpi/actions/bl_key_up.sh
```

/etc/acpi/actions/bl_key_down.sh

```
#!/bin/bash

if ( lsmod | grep nvidia )

then

   brightness=$((`tail -1 /proc/acpi/video/VGA1/LCDD/brightness | cut -f2 -d" "`-7))

   if [ $brightness -lt 60 ]

   then 

      brightness=$((brightness+1))

   fi

   if [ $brightness -lt 5 ]

   then 

      brightness=5

   fi

   echo ${brightness}

        echo ${brightness} > /proc/acpi/video/VGA1/LCDD/brightness

else

   brightness=$((0x`setpci -s 00:02.0 F4.B`-16));

   if [ $brightness -lt 1 ] ; then

      brightness=1;

   fi

   setpci -s 00:02.0 F4.B=`printf '%x' $brightness`;

fi
```

/etc/acpi/actions/bl_key_up.sh

```
#!/bin/bash

if ( lsmod | grep nvidia )

then

   brightness=$((`tail -1 /proc/acpi/video/VGA1/LCDD/brightness | cut -f2 -d" "`+6))

   if [ $brightness -gt 60 ]

   then 

      brightness=$((brightness+1))

   fi

   if [ $brightness -gt 100 ]

   then 

      brightness=100

   fi

   echo ${brightness}

        echo ${brightness} > /proc/acpi/video/VGA1/LCDD/brightness

else

   brightness=$((0x`setpci -s 00:02.0 F4.B`+16));

   if [ $brightness -gt $((0xff)) ] ; then

      brightness=$((0xff));

   fi

   setpci -s 00:02.0 F4.B=`printf '%x' $brightness`;

fi
```

I hope that helps.

----------

