LCD背光驱动基于PWM1(timer1),因为使用的是GPB1这个IO口来控制,由它输出的PWM来控制背光的亮暗程度。
内核中通用的驱动文件为:drivers/video/backlight/pwm_bl.c
调光原理:PWM输出的频率固定,改变PWM的占空比即可改变LCD背光的亮度
在mach-xc2440.c中添加LCD背光驱动的支持:
加入必要的头文件:
#include
#include
在xc2440_devices[ ]结构体中加入:
&xc2440_backlight_device,
构建LCD背光设备的platform_device结构体:
- /* LCD Backlight */
-
static int xc2440_backlight_init(struct device *dev)
-
{
-
gpio_request(S3C2410_GPB(1), "Backlight");
-
gpio_direction_output(S3C2410_GPB(1), 0);
-
s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_NONE);
-
s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1);
-
-
return 0;
-
}
-
-
static void xc2440_backlight_exit(struct device *dev)
-
{
-
gpio_direction_output(S3C2410_GPB(1), 1);
-
}
-
-
static struct platform_pwm_backlight_data xc2440_backlight_data = {
-
.pwm_id = 1,
-
.max_brightness = 100,
-
.dft_brightness = 40,
-
.pwm_period_ns = 800000,
-
.init = xc2440_backlight_init,
-
.exit = xc2440_backlight_exit,
-
};
-
-
static struct platform_device xc2440_backlight_device = {
-
.name = "pwm-backlight",
-
.dev = {
-
.parent = &s3c_device_timer[1].dev,
-
.platform_data = &xc2440_backlight_data,
-
},
-
.id = 1,
-
};
说明:
platform_device的name是pwm-backlight,这个和driver中的name一致,dev的parent是s3c_device_timer[1],也就是上一节移植的PWM1设备
platform_data中max_brightness是最大背光亮度值,dft_brightness是初始值,pwm_period_ns是PWM的输出频率,这个要在driver中转成频率值
我这个配置中:背光调节范围是(0~100),初始值是40,频率是1KHz左右
在init函数中将GPB1管脚设置为TOUT1模式,在exit函数中禁止GPB1输出
查看drivers/video/backlight目录下的Kconifg文件,定义了pwm bl的配置:
- config BACKLIGHT_PWM
- tristate "Generic PWM based Backlight Driver"
- depends on HAVE_PWM
配置内核,支持LCD背光驱动:
- Device Drivers --->
-
Graphics support --->
-
[*] Backlight & LCD device support --->
-
<*> Lowlevel Backlight control
-
<*> Generic PWM based Backlight Driver
查看设备:
/sys/class/backlight/pwm-backlight.1/brightness
操作设备:
#cat /sys/class/backlight/pwm-backlight.1/max_brightness (查看背光最大值)
#echo 15 > /sys/class/backlight/pwm-backlight.1/brightness (设置背光亮度)
阅读(152) | 评论(0) | 转发(0) |