TransWikia.com

Setting PWM Backlight brightness on boot

Super User Asked by AntoineC on December 20, 2021

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.

3 Answers

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

Answered by Grodriguez on December 20, 2021

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

Answered by CJBS on December 20, 2021

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.

Answered by CJBS on December 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP