Thursday, June 30, 2011

Backlight workaround for Linux Mint 11

First off, make sure this workaround applies to you. [Update: I thought this only worked with Intel graphics, but a comment below suggests it also works with ATI.] From a terminal emulator, run:
user@hostname ~ $ lspci | grep VGA
and you should see this:
00:02.0 VGA compatible controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 09)
00:02.0 in the above is the device address of the video card. Yours may be different, so use your value in the script below.

I'm running Linux Mint 11, but this should also work on Ubuntu 11.04 (and maybe other distros, too.) [Update: I've switched to Arch Linux with Gnome 3 XFCE and this method works there.]

Create a script to set the brightness to your liking. In /usr/local/bin create a file called set-brightness:
user@hostname ~ $ gksu gedit /usr/local/bin/set-brightness
and make it look like this:
#!/bin/sh -e

setpci -s 00:02.0 F4.B=60

exit 0
You can change the 60 on line 3 to any hexadecimal value between 00 (full brightness) and FF (full darkness). 60 equates to 62.5% brightness, which I find easier on my eyes in a darker environment. If you prefer full brightness, then use:
setpci -s 00:02.0 F4.B=00
Make sure to make /usr/local/bin/set-brightness executable:
user@hostname ~ $ sudo chmod +x /usr/local/bin/set-brightness
Test the script to make sure it works:
user@hostname ~ $ sudo set-brightness
You can change the value for brightness used in set-brightness, save the file and re-run the script to tweak the brightness to the level you prefer.

To set the backlight on boot edit /etc/rc.local:
user@hostname ~ $ gksu gedit /etc/rc.local
Add a line:
/usr/local/bin/set-brightness
before
exit 0
and save the file. This takes care of setting the backlight at the login screen.

However, when the laptop resumes from suspension or thaws from hibernation, the backlight fails to return to the level set in set-brightness. To address this issue, create a file 00_set-brightness in /etc/pm/sleep.d:
user@hostname ~ $ gksu gedit /etc/pm/sleep.d/00_set-brightness
and make it look like this:
#!/bin/sh -e

case "$1" in
   thaw|resume) /usr/local/bin/set-brightness ;
esac

exit 0
Make 00_set-brightness executable:
user@hostname ~ $ sudo chmod +x /etc/pm/sleep.d/00_set-brightness
Now the brightness will be set properly after suspension or hibernation.

If you prefer to use the brightness function keys on your laptop, check out Kamal Mustafa's PPA. Alternatively, you can get crude brightness control using the function keys by modifying /etc/default/grub:
user@hostname ~ $ gksu gedit /etc/default/grub
Change this line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to look like this:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=Linux"
and run update-grub:
user@hostname ~ $ sudo update-grub
[Update: If using a distro that runs GRUB rather than GRUB2, modify the kernel line of /boot/grub/menu.lst to include acpi_osi=Linux instead of doing the above.] Reboot and you should have some use of the brightness keys. I only get 5 levels of brightness using this method.

3 comments:

  1. Thanks really help me with an ATI and HP 6735B
    I have just replaced 00:02.0 by 01:05.0

    ReplyDelete
  2. Absolute magic. I'm a first time Linux user. Great post. Worked on an Acer Emachine D725

    ReplyDelete