5

In order to control my backlight, I need to do the following:

sudo setpci -s 00:02.1 F4.B=x

This could be read as:

For the PCI device with the ID 00:02.1, set the register F4 (byte only) to x.

To figure out a value I want for x, I'd like to read its current value (in a script I'm writing). How do I do this?

Early work:

This seems to be the domain of lspci. I tried

sudo lspci -x -s 00:02.1

but this doesn't give enough range (doesn't reach register/address F4). I can do it with the -xxx command line, however. This gives me a dump at which I can see the byte at F4, which I verified I can manipulate with the setpci command. However, the manual says:

  -xxx   Show hexadecimal dump of the whole PCI configuration space. It is  available  only  to  root  as  several  PCI
         devices  crash when you try to read some parts of the config space (this behavior probably doesn't violate the
         PCI standard, but it's at least very stupid). However, such devices are rare, so you needn't worry much.

So I'd rather not put that in a program that runs automatically as root. Any way to just read the value for register F4? A getpci program? A setpci flag? Some special lspci flag I missed?

(Environment is Ubuntu Netbook Remix 9.04 (karmic) (32-bit) on a Samsung N140 netbook)

1

2 Answers 2

10

You want the program setpci. It looks like this format would do what you want:

setpci -s 00:02.1 F4.B

See man setpci: the only difference with your version is you're trying to set the register, so you name it and assign a value ("F4.B=x"). Here, just name it; don't assign a value.

From the manpage:

Operations

To query value of a configuration register, just name it (either by typing its name or by typing register address with optional .B, .W or .L suffix specifying register width as byte, word or longword).

To set a register, write reg=values where reg is the same as you would use to query the register and values is a comma-separated list of values you want to write starting with the given address. Each value to be written can be specified either as a hexadecimal number or as a bits:mask pair which causes the bits corresponding to binary ones in the mask to be changed to values of the corresponding bits in the bits

3
  • i would've looked for a getpci first too... Dec 26, 2009 at 1:11
  • 2
    List all regnames with setpci --dumpregs. Also possible to use device ID directly with -d 1234:5678. Aug 5, 2017 at 19:22
  • If you add a one line awk, you can print the values of each dumpregs register: setpci --dumpregs | gawk '{if ($2 != 0){printf("setpci -s 2e:00.0 %s.%s\n",$3,$2);system("setpci -s 2e:00.0 " $3"."$2)}}'. Needs a little more work for CAP registers, but displaying pci registers and values for a device completes the answer. Aug 12, 2019 at 21:10
1

Take into account that this will not work if your display uses the new intel_backlight interface (until this date only the gnome power manager can manage it).

Please read this: https://askubuntu.com/questions/57236/unable-to-change-brightness-in-a-lenovo-laptop/81389#81389 and the links listed Especially my post (under the name Álvaro)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .