Setting PWM Backlight brightness on boot

2

I am working with Linux version 3.10.17, using device tree to boot the kernel.

In the device tree, I define a "pwm-backlight" compatible driver. The driver defines a variable, default-brightness-level

On start, the driver applies this value to the "brightness" value of the driver.

I would like to know if there is a way to save a value and use it instead of the "default-brightness-level". The purpose is to be able to save a brightness value and use it on the next start of Linux.

AntoineC

Posted 2016-06-21T08:56:16.393

Reputation: 21

Couple things: 1) linux version 3.10.17 is the kernel version NOT the distro this will be used on --which makes a big difference for your question 2) you would have to either a) set the default-brightness-level to what you desired this 'on-boot' value to be OR b) create / define another level as a variable and use that as your compiled variable for the driver. – linuxdev2013 – 2016-07-06T22:17:44.607

Answers

0

Using a custom (portable) dtb file

Note: I know you mention instead of the "default-brightness-level", but if a dtb file is made, then this can be used to save the configuration that is saved outside of the kernel (i.e. could be swapped out with a different file without rebuilding the kernel).

If you have access to the dtsi file that the Kernel was built with then you can modify the value under the appropriate section in there. This file should be in the arch/arm/boot/dts directory for the kernel source.

At the same level as the compatible = "pwm-backlight", there is also a default-brightness-level parameter. Change this value to a value of your liking (it corresponds to the index of the brightness-levels array. For example:

backlight_lvds {
        compatible = "pwm-backlight";
        pwms = <&pwm4 0 500000>;
        brightness-levels = <100 75 60 50 40 30 20 10 5 0>;
        /* Default brightness level (index into the array defined by the "brightness-levels" property) */
        default-brightness-level = <5>;
        status = "okay";
    };

You can then compile the dtsi into a dtb file that is included on your boot partition. Compile using the make dtbs command. Something like:

cd ~/MyOS/kernel_imx 
export CROSS_COMPILE=`pwd`/../prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi- 
make myboard_defconfig 
make dtbs

The output dtb file is then referenced in your bootloader script. As an example, for UBoot, it's:

setenv dtbname myCustom.dtb

myCustom.dtb is the output of the make dtbs command.

CJBS

Posted 2016-06-21T08:56:16.393

Reputation: 141

0

Using sysfs

It should be possible to use sysfs to set a value to the brightness file. Have a look under /sys/class/backlight; there's most likely a sub-directory with your backlight device. In that directory, there should be a file brightness.

Pipe a value corresponding to the index of the value (in brightness-levels) that you want to use to that file. For example:

me@mydevice:/ $ echo 3 > /sys/class/backlight/backlight_lvds.0/brightness

This should set the value to the 4th entry in brightness-levels.

This file can also be queried:

me@mydevice:/ $ cat  /sys/class/backlight/backlight_lvds.0/brightness
3

CJBS

Posted 2016-06-21T08:56:16.393

Reputation: 141

0

The kernel will not do this for you (save a backlight value and apply it on next restart), but if your kernel has sysfs support, you can keep the current value in a config file (could be e.g. /etc/backlight.conf), and apply it on boot.

Whenever you change the backlight:

echo <newvalue> > /sys/class/backlight/<subdir>/brightness
echo <newvalue> > /etc/backlight.conf

On boot:

if [ -f /etc/backlight.conf ]; then
    cat /etc/backlight.conf > /sys/class/backlight/<subdir>/brightness
fi

Grodriguez

Posted 2016-06-21T08:56:16.393

Reputation: 297