LCD的背光主要涉及到两个地方
1.休眠和唤醒的开关
2.背光的亮度调整
安卓设置中可以控制背光的亮度,JNI层的实现
frameworks/base/services/jni/com_android_server_LightsService.cpp
LIGHT_INDEX_BACKLIGHT = 0
hw_module_t* module;
Devices* devices;
err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
devices->lights[LIGHT_INDEX_BACKLIGHT] = get_device(module, LIGHT_ID_BACKLIGHT);
.....
static void setLight_native(JNIEnv *env, jobject clazz, int ptr,
int light, int colorARGB, int flashMode, int onMS, int offMS, int brightnessMode)
{
......
devices->lights[light]->set_light(devices->lights[light], &state);
}
//主要是调用hw中的open
static light_device_t* get_device(hw_module_t* module, char const* name)
{
int err;
hw_device_t* device;
err = module->methods->open(module, name, &device);
if (err == 0) {
return (light_device_t*)device;
} else {
return NULL;
}
}
这里主要去调用HAL层。
imx6的背光HAL层实现在:
hardware/imx/lights/fsl_lights.c
简略的列一下:
static int lights_device_open(const struct hw_module_t* module, const char* name, struct hw_device_t** device) { .... dev->common.close = light_close_backlight; dev->set_light = set_light_backlight; property_get("hw.backlight.dev", value, "pwm-backlight"); strcpy(path, "/sys/class/backlight/"); strcat(path, value); strcpy(max_path, path); strcat(max_path, "/max_brightness"); strcat(path, "/brightness"); ALOGI("max backlight file is %s\n", max_path); ALOGI("backlight brightness file is %s\n", path); } /sys/class/backlight/pwm-backlight.0/pwm-backlight/brightness /sys/class/backlight/pwm-backlight.0/max_brightness static int set_light_backlight(struct light_device_t* dev, struct light_state_t const* state) { /sys/class/backlight/pwm-backlight/pwm-backlight.0 /brightness /sys/class/backlight/pwm-backlight.0/max_brightness 这两个文件里读写值 }
这里为了检测问题,测试了一下:
/sys/class/backlight/pwm-backlight/
pwm-backlight.0 /brightness
这个文件无论怎么写,都不会让背光灭掉,只起到调节背光大小的作用,做过屏幕改不了背光那么就需要
1.手动修改这个文件是否能改
2.检查驱动是否有问题
arch/arm/mach-mx6/board-mx6q_sabresd.c 这是我么的板文件
根据原理图上背光的总开关由一个GPIO管教控制,我们只需要看看这个管教是不是在休眠的时候关闭掉即可。
这是背光相关的控制实现
static struct platform_pwm_backlight_data mx6_sabresd_pwm_backlight_data = {
.pwm_id = 1,
.max_brightness = 248,
.dft_brightness = 128,
.lth_brightness = 60,
.pwm_period_ns = 50000,
.init = mx6q_backlight_init, //这里做初始化,顺便把屏幕点亮
.exit = mx6q_backlight_exit,//这里释放资源
.notify =mx6q_backlight_notify //这个实现是自己加的
};
static int mx6q_backlight_notify(struct device *dev, int brightness){
if(brightness >0){
gpio_direction_output(SABRESD_BACKLIGHT_EN, 1);
}else{ //等于0的时候关闭背光
gpio_direction_output(SABRESD_BACKLIGHT_EN, 0);
}
return 0;
}
然后驱动在:
drivers/video/backlight/pwm_bl.c
这里主要看一下休眠和唤醒的实现里的操作,其实根本不需要修改代码,我们需要参考调用流程,来在板文件做好相应的处理即可。