Turning Display Backlight On and Off

1. Overview

This application note explains how to enable the display backlight on and off, in those hardware design where the backlight is controlled by a GPIO and, therefore, can have one of the two states: off and on.

Note the display backlight can be controlled independently of any display software. That is, the backlight may be turned on and off regardless of whether or not your BSP configuration has a display device driver (and an upper-layer GUI stack) enabled.

2. Understanding Implementation

Control of the LCD backlight is managed by the standard Linux driver gpio_backlight.c residing in the linux/drivers/video/backlight directory in the kernel tree. The driver is enabled at the build time by the CONFIG_BACKLIGHT_GPIO kernel config option.

For the run-time configuration of the kernel, the LCD backlight is configured in the kernel dts file. For instance, in the i.MX RT1050 BSP refer to rootfs.dts.IMXRT105X_NXPEVK in the projects/rootfs directory:

backlight { compatible = "gpio-backlight"; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_backlight>; gpios = <&gpio2 31 GPIO_ACTIVE_HIGH>; };

Note that in this configuration the backlight is turned off at system startup.

If the LCD is not physically connected, we recommend keeping the GPIO controlling the backlight off to avoid possible damage to the board components. Since this demo software for NXP i.MXRT10xx-EVK boards can be used in both variants: with and without the LCD connected, the backlight is off by default.

One can add the default-on property to the backlight node to start the system with the LCD backlight enabled, like as follows:

backlight { compatible = "gpio-backlight"; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_backlight>; gpios = <&gpio2 31 GPIO_ACTIVE_HIGH>; default-on; };

3. Controlling Backlight

To turn the LCD backlight on, run the following command:

/ # echo 0 > /sys/class/backlight/backlight/bl_power

To turn the LCD backlight off, run the following command: