1、硬件原理图分析。由原理图得知LCD的背光是由2440的GPG4口控制的
2、在 linux-2.6.39/drivers/video/backlight/目录下,创建my2440_backlight.c文件,代码内容如下:
-
#include <linux/errno.h>
-
#include <linux/kernel.h>
-
#include <linux/module.h>
-
#include <linux/slab.h>
-
#include <linux/input.h>
-
#include <linux/init.h>
-
#include <linux/serio.h>
-
#include <linux/delay.h>
-
#include <linux/clk.h>
-
#include <linux/miscdevice.h>
-
#include <linux/gpio.h>
-
-
#include <asm/io.h>
-
#include <asm/irq.h>
-
#include <asm/uaccess.h>
-
#include <mach/regs-clock.h>
-
#include <plat/regs-timer.h>
-
-
#include <mach/regs-gpio.h>
-
#include <linux/cdev.h>
-
#include "my2440_backlight.h"
-
-
#define DEVICE_NAME "backlight" //设备名称
-
#define DEVICE_MINOR 5 //次设备号,这里我们将设备注册为misc设备,这种设备的主设备号都为10
-
-
static int my2440_backlight_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
-
{
-
-
switch(cmd)
-
{
-
case BL_OFF:
-
//当接收的命令为0时,就将GPG4引脚设为低电平,关闭背光
-
s3c2410_gpio_setpin(S3C2410_GPG(4), 0);
-
printk(DEVICE_NAME " turn off!\n");
-
return 0;
-
case BL_ON:
-
//当接收的命令为1时,就将GPG4引脚设为高电平,开启背光
-
s3c2410_gpio_setpin(S3C2410_GPG(4), 1);
-
printk(DEVICE_NAME " turn on!\n");
-
return 0;
-
default:
-
printk("error cmd\n");
-
return -EINVAL;
-
}
-
}
-
-
static struct file_operations dev_fops =
-
{
-
.owner = THIS_MODULE,
-
.unlocked_ioctl = my2440_backlight_ioctl, //这里只使用控制IO口的方式来控制背光
-
};
-
-
static struct miscdevice misc =
-
{
-
.minor = DEVICE_MINOR,
-
.name = DEVICE_NAME,
-
.fops = &dev_fops,
-
};
-
-
static int __init dev_init(void)
-
{
-
int ret;
-
-
ret = misc_register(&misc); //注册成misc设备
-
-
if(ret < 0)
-
{
-
printk("Register misc device fiald!");
-
return ret;
-
}
-
//将GPG4口配置成输出口
-
s3c2410_gpio_cfgpin(S3C2410_GPG(4), S3C2410_GPIO_OUTPUT);
-
-
return ret;
-
}
-
-
static void __exit dev_exit(void)
-
{
-
misc_deregister(&misc); //注销该misc设备
-
}
-
-
module_init(dev_init);
-
module_exit(dev_exit);
-
-
MODULE_LICENSE("GPL");
-
MODULE_AUTHOR("lisi");
-
MODULE_DESCRIPTION("Backlight control for my2440");
在 linux-2.6.39/drivers/video/backlight/目录下,创建my2440_backlight.h文件,代码内容如下:
点击(此处)折叠或打开
-
#define BL_MAGIC 'B'
-
#define BL_ON _IO(BL_MAGIC,0)
-
#define BL_OFF _IO(BL_MAGIC,1)
修改backlight/目录下的Kconfig文件,添加背光选项
#gedit linux-2.6.39/drivers/video/backlight/Kconfig
|
config MY2440_LCD_BACKLIGHT
tristate "My2440 LCD Backlight Controls"
depends on BACKLIGHT_LCD_SUPPORT
default y
|
修改backlight/目录下的Makefile文件,在最后一行添加
#gedit linux-2.6.39/drivers/video/backlight/Makefile
|
obj-$(CONFIG_MY2440_LCD_BACKLIGHT) += my2440_backlight.o
|
配置内核选项,选中上面添加的配置项
Device Drivers --->
Graphics support --->
[*] Backlight & LCD device support --->
--- Backlight & LCD device support
<*> My2440 LCD Backlight Controls (NEW)
< > Lowlevel LCD controls
< > Lowlevel Backlight controls
|
3、编写测试代码backlight_test.c,,使用交叉编译工具进行静态编译,内容如下:
#arm-linux-gcc -static backlight_test.c -o backlight_test
点击(此处)折叠或打开
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <fcntl.h>
-
#include <sys/ioctl.h>
-
#include "my2440_backlight.h"
-
-
int main(int argc, char **argv)
-
{
-
int fd;
-
int cmd;
-
-
if(argc <2)
-
{
-
printf("Please enter the sencond para!\n");
-
return 0;
-
}
-
-
cmd = atoi(argv[1]);
-
-
fd = open("/dev/backlight1",O_RDWR);
-
-
if(cmd == 1)
-
{
-
ioctl(fd,BL_ON);
-
}
-
else if(cmd == 0)
-
{
-
ioctl(fd,BL_OFF);
-
}
-
return 0;
-
}
4、测试结果如下:
阅读(1277) | 评论(0) | 转发(0) |