how-to_‎ > ‎

Laptop LCD backlight brightness adjust workaround when bios and acpi are not cooperative

posted Oct 5, 2011, 4:50 AM by Daniele Albrizio   [ updated Oct 5, 2011, 4:56 AM ]
This works on my Samsung NP-Q45 using a
00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (primary) (rev 03)

Tried acpi_backlight=vendor as kernel parameter also, with no suceess.

So, after reading a post from hesapotman I wrote 2 scripts, 2 sudoerrs lines and 2 keyboard hotkey mappings to make it just work.

So let's see the two short similar scripts:

/etc/adminscripts/brightness/brup
#!/bin/bash
# Pulls backlight brightness UP one step

typeset -i new=16#ff

Current=`sudo setpci -s 00:02.0 F4.B`
echo brightness now $Current

new=16#$Current+16

# roof it to 0xff
if (( $new > 0xff )) ; then
  new=16#ff
fi

printf "sudo setpci -s 00:02.0 F4.B=%x\n" $new |sh

/etc/adminscripts/brightness/brdn
#!/bin/bash
# Pulls backlight brightness DOWN one step

typeset -i new=16#ff

Current=`sudo setpci -s 00:02.0 F4.B`
echo brightness now $Current

new=16#$Current-16

# floor it to 0x1f
if (( $new < 0x1f )) ; then
  new=16#1f
fi

printf "sudo setpci -s 00:02.0 F4.B=%x\n" $new |sh


Hexadecimal values in bash may be represented as base#value where base is 16 or as 0xHH where HH is the value. Those scripts first reads function B from slot F4 of pci device 00:02.0, adds or subtracts 16 bits and rewrite the values in the same place.

Adjust increments and floor/ceiling limits to your needs.

You may test each script separately running them directly from the commandline (remember to chmod 700 them).

Now we need to associate each script to a key sequence. It seems perhaps that this commands needs to be run as root from within gnome. So first add these two linws to sudoers file using visudo.

# Cmnd alias specification
Cmnd_Alias BRIGHT_CMDS = /etc/adminscripts/brightness/brup, /etc/adminscripts/brightness/brdn

# User privilege specification
ALL ALL=(ALL) NOPASSWD: BRIGHT_CMDS

Then using "Keyboard Shortcuts" application inside gnome, assign the shortcuts:

Click add, as Name put something like Brightness UP/DOWN and as Command put sudo or gksudo /etc/adminscripts/brightness/brup and brdn respectively.

Click on shortcut field and associate your preferred key combination.
Comments