Based on Linux 3.18.y
Overview
The linux backlight subsystem is used to provide an interface for user space to control the backlight brightness of LCD or other display devices in the /sys directory.
The brightness here is not two states of on and off, and there can be many levels of brightness, which is convenient for the user space to adjust the brightness of the backlight according to the needs of energy saving and visual range.
Related code
The code of the backlight subsystem is in the /driver/video/backlight directory.
The important file is: generic_bl.c backlight.c lcd.c
Kernel configuration
In order to support the backlight subsystem, the following configuration needs to be used in the kernel:
Device Drives --->
Graphics Support --->
[*]Backlight & LCD device support --->
<*>Platform LCD controls
<*>Lowlevel Backlight controls
Important data structure
include/linux/backlight.h
driver/video/backlight/genrtic_bl.c
/* 通用的背光控制代码,driver已经注册好了,只需要注册device就能使用 */
struct generic_bl_info {
const char *name; //名字字符指针,这个名字会出现在/sys/class/backlight/中
int max_intensity; //最大亮度
int default_intensity; //默认亮度
int limit_mask; //亮度值的掩码,如0xff
void (*set_bl_intensity)(int intensity); //设置亮度的函数
void (*kick_battery)(void); //设置亮度之后调用的函数,与电池相关,可以不定义
};
How to use the backlight subsystem
static void eukrea_mbimx27_bl_set_intensity(int intensity)
{
/*在这个函数中根据参数intensity的值设置背光,具体通过PWM还是其它手段,要根据硬件了*/
}
static struct generic_bl_info eukrea_mbimx27_bl_info = {
.name = "eukrea_mbimx27-bl",
.max_intensity = 0xff,
.default_intensity = 0xff,
.set_bl_intensity = eukrea_mbimx27_bl_set_intensity,
};
static struct platform_device eukrea_mbimx27_bl_dev = {
.name = "generic-bl", //这个名字必须是"generic-bl"
.id = 1,
.dev = {
.platform_data = &eukrea_mbimx27_bl_info,
},
};
platform_device_register(&eukrea_mbimx27_bl_dev);
After registering eukrea_mbimx27_bl_dev, you can see the backlight properties file under /sys/class/backlight/eukrea_mbimx27-bl/.
sys file attribute description
The files of the backlight subsystem are in /sys/class/backlight/XXX/, where XXX is the name of the backlight device, which is specified during registration.
/sys/class/backlight/XXX/下的属性文件有:
actual_brightness brightness max_brightness subsystem@
bl_power device@ power/ uevent
重要的文件有两个:
max_brightness :最大亮度值
brightness:当前实际的亮度值(内核中记录的值)
可以使用 "cat /sys/class/backlight/XXX/brightness"查看当前背光亮度,使用 "echo _数字_ >> /sys/class/backlight/XXX/brightness"设置背光亮度。