Auto detect drivers for switchable graphics

From ThinkWiki
Revision as of 06:52, 23 February 2011 by Cyberey66 (Talk | contribs) (←Created page with '== Auto detection and configuration for switchable graphics == Select ThinkPads feature switchable graphics, where a low power consumption integrated GPU and high perform...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Auto detection and configuration for switchable graphics

Select ThinkPads feature switchable graphics, where a low power consumption integrated GPU and high performance dedicated GPU is combined and you have the ability to switch between them, sacrificing either performance or battery life. Switching under Linux requires a reboot and if one wishes to use binary drivers, switching is generally not possible without first uninstalling the binary drivers and reinstalling the open source drivers and viceversa.

Recently purchasing a W500, I wanted to be able to easily switch between the discrete ATI Fire GL graphics using the fglrx drivers and integrated Intel HD graphics with the open source Xorg drivers. I decided to write a simple init script to detect which card is selected (using the BIOS) and configure xorg and provide the correct libraries.


Requirements

The script only works to switch between and ATI video card with fglrx drivers and Intel Integrated graphics with xorg drivers. To select between the drivers, you simply select either 'Discrete' or 'Integrated' in the bios and then boot as normal. The fglrx and xorg drivers use different libraries and this is the reason they are not compatible with each other. The two specific libraries are: libGL.so.1.2 and libglx.so. The script requires copies of the libraries to be stores in /usr/lib/ and /usr/lib/xorg/modules/extensions/ respectively.

Specifically, the fglrx libraries are stored as:

/usr/lib/libGL.so.1.2.fglrx /usr/lib/xorg/modules/extensions/libglx.so.fglrx

and the original xorg libraries are stored as:

/usr/lib/libGL.so.1.2.xorg /usr/lib/xorg/modules/extensions/libglx.so.xorg

In addition, xorg.conf files for each driver, intel and fglrx, must be stored as:

/etc/X11/xorg.conf.intel for integrated graphics /etc/X11/xorg.conf.fglrx for discrete graphics


Initial Setup

The first step is select the integrated graphics chip in the bios and boot into Linux without fglrx installed. One then makes copies of the two libraries mentioned above.

cp /usr/lib/libGL.so.1.2 /usr/lib/libGL.so.1.2.xorg cp /usr/lib/xorg/modules/extensions/libglx.so.xorg

The next step is to create a simple xorg.conf and save it in the same directory as xorg.conf as xorg.conf.intel. Simply is must contain:

Section "Device" Identifier "Anyname here will work" Driver "intel" EndSection

The next step is the same but with the ATI card selected in the BIOS and the fglrx drivers installed.

cp /usr/lib/libGL.so.1.2 /usr/lib/libGL.so.1.2.fglrx cp /usr/lib/xorg/modules/extensions/libglx.so.fglrx

Next we need a copy of an xorg.conf for fglrx. You can simply generate one and make a copy using:

aticonfig --initial cp /etc/X11/xorg.conf /etc/X11/xorg.conf.fglrx

Now we are ready to setup the script.

Script

The script is below and can be saved as video_switch.

  1. !/bin/bash
  2. check for intel integrated drivers

intel=`lspci | grep Integrated\ Graphics` ATI=`lspci | grep ATI`

if [ "$intel" ] ; then #setup drivers for intel Xorg driver cp /etc/X11/xorg.conf.intel /etc/X11/xorg.conf

# switch libraries to fglrx libraries # need to switch /usr/lib/libGL.so.1.2 and # /usr/lib/xorg/modules/extensions/libglx.so

# I stored a copy of libGL.so.1.2 to libGL.so.1.2.xorg # when xorg drivers were installed # switch libraries to Xorg libraries cp /usr/lib/libGL.so.1.2.xorg /usr/lib/libGL.so.1.2

   	ln -s /usr/lib/libGL.so.1.2 libGL.so.1
   	ln -s /usr/lib/libGL.so.1 libGL.so

cp /usr/lib/xorg/modules/extensions/libglx.so.xorg /usr/lib/xorg/modules/extensions/libglx.so


echo "Switched to Xorg Intel drivers"

fi if [ "$ATI" ] ; then #setup drivers for ATI fglrx driver

cp /etc/X11/xorg.conf.fglrx /etc/X11/xorg.conf # switch libraries to fglrx libraries # need to switch /usr/lib/libGL.so.1.2 and # /usr/lib/xorg/modules/extensions/libglx.so

# I stored a copy of libGL.so.1.2 to libGL.so.1.2.fglrx # when fglrx drivers were installed cp /usr/lib/libGL.so.1.2.fglrx /usr/lib/libGL.so.1.2 # link the other two libraries

   	ln -s /usr/lib/libGL.so.1.2 libGL.so.1
   	ln -s /usr/lib/libGL.so.1 libGL.so

#same as before, stored a backup when fglrx was installed cp /usr/lib/xorg/modules/extensions/libglx.so.fglrx /usr/lib/xorg/modules/extensions/libglx.so

echo "Switched to Discrete fglrx drivers"

echo "Switched to ATI fglrx drivers" fi

We now set this as an init script to run during boot:

First copy the script

       sudo cp scripts/video_switch /etc/init.d/

Set it as executable:

       sudo chmod +x /etc/init.d/video_switch

And set the script to run during boot

       sudo update-rc.d video_switch defaults

Now you can select your graphics card in your bios and you are all ready to go!

Sorry for the bad formatting, I just wanted to copy this somewhere and share it while it was still fresh in my head. I will come back to clean it up. --Cyberey66 05:52, 23 February 2011 (CET)