Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7688571
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2010-12-18 15:36:00

TX2440_backlight.c源码

/************************************************
LCD背光的驱动,在TX2440A开发板上做测试

维护记录: 2009-10-30 V1.0 by xgc

linux内核:2.6.31.4

硬件接法:
        GPG4 -- LCD_PWREN
驱动用法:
        设备名称:TX2440-backlight
*************************************************/

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>

//#include

//#include


//#include


//#include

//#include

//#include

//#include

    
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/gpio.h>

#define DEVICE_NAME    "TX2440-backlight"
static int BACKLIGHT_Major = 0;            /* 主设备号 */

static unsigned int bl_state;

static inline void set_bl(int state)
{
    bl_state = !!state;
    s3c2410_gpio_setpin(S3C2410_GPG(4), bl_state);
}

static inline unsigned int get_bl(void)
{
    return bl_state;
}

static int TX2440_backlight_open(struct inode *inode, struct file *file)
{
    printk("TX2440-BACKLIGHT Driver Open Called!\n");
    return 0;
}

static int TX2440_backlight_release(struct inode *inode, struct file *file)
{
    printk("TX2440-BACKLIGHT Driver Release Called!\n");
    return 0;
}

static ssize_t TX2440_backlight_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
{
    unsigned char ch;
    int ret;
    
    if (count == 0)
    {
        return count;
    }
    
    ret = copy_from_user(&ch, buffer, sizeof ch) ? -EFAULT : 0;
    
    if (ret)
    {
        return ret;
    }

    ch &= 0x01;
    set_bl(ch);
        
    return count;
}

static ssize_t TX2440_backlight_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
    int ret;
    unsigned char str[] = {'0', '1' };

    if (count == 0)
    {
        return 0;
    }

    ret = copy_to_user(buffer, str + get_bl(), sizeof(unsigned char) ) ? -EFAULT : 0;

    if (ret)
    {
        return ret;
    }

    return sizeof(unsigned char);
}

static struct file_operations TX2440_backlight_fops =
{
    .owner = THIS_MODULE,
    .open = TX2440_backlight_open,
    .release = TX2440_backlight_release,
    .read = TX2440_backlight_read,    
    .write = TX2440_backlight_write,
};

static struct class *backlight_class;

static int __init TX2440_backlight_init(void)
{
    printk("TX2440 BACKLIGHT DRIVER MODULE INIT\n");

    s3c2410_gpio_cfgpin(S3C2410_GPG(4), S3C2410_GPIO_OUTPUT);
    set_bl(1);
    
    BACKLIGHT_Major = register_chrdev(0, DEVICE_NAME, &TX2440_backlight_fops);
    if (BACKLIGHT_Major < 0)
    {
        printk(DEVICE_NAME " can't register major number\n");
        return BACKLIGHT_Major;
    }
    printk("register TX2440-BACKLIGHT Driver OK! Major = %d\n", BACKLIGHT_Major);

    backlight_class = class_create(THIS_MODULE, DEVICE_NAME);
    if(IS_ERR(backlight_class))
    {
        printk("Err: failed in TX2440-BACKLIGHT class. \n");
        return -1;
    }

    device_create(backlight_class, NULL, MKDEV(BACKLIGHT_Major, 0), NULL, DEVICE_NAME);

    printk(DEVICE_NAME " initialized\n");
    
    return 0;
}


static void __exit TX2440_backlight_exit(void)
{
    printk("TX2440 BACKLIGHT DRIVER MODULE EXIT\n");
    unregister_chrdev(BACKLIGHT_Major, DEVICE_NAME);
    device_destroy(backlight_class, MKDEV(BACKLIGHT_Major, 0));
    class_destroy(backlight_class);
}

module_init(TX2440_backlight_init);
module_exit(TX2440_backlight_exit);

MODULE_AUTHOR("www.txmcu.com");        
MODULE_DESCRIPTION("TX2440 BACKLIGHT Driver");    
MODULE_LICENSE("GPL");


 

将背光驱动源码TX2440_backlight.c 放到drivers/video/目录下,修改同目录下Kconfig 文件,在1948 行加入:

config TX2440_BACKLIGHT

tristate "Backlight support for TX2440A"

depends on FB_S3C2410

help

LCD backlight driver for TX2440A

修改同目录下Makefile 文件,在最后面加入:

obj-$(CONFIG_TX2440_BACKLIGHT) += TX2440_backlight.o

 

配置内核,支持LCD 背光:

Device Drivers --->

Graphics support --->

<*> Support for frame buffer devices --->

<*> Backlight support for TX2440A

 

系统启动时,自动加载背光驱动,设备名为:TX2440-backlight

 

测试背光驱动:

执行 #echo 0 > /dev/TX2440-backlight 会使LCD 背光熄灭

执行 #echo 1 > /dev/TX2440-backlight 会使LCD 背光点亮

 

修改LCD 背光控制,使LCD 常亮

系统启动后会开启一个定时器,当到达定时时间后就会关闭LCD 显示,也就相当于进入了待机模式,它可以由一些事件来唤醒。默认的待机时间是10 分钟,你可以自己设置这个时间,也可以关闭待机功能,使LCD 背光常亮。

方法:修改drivers/char/vt.c 文件

176 static int blankinterval = 10*60; 􀃅10 分钟

改成: static int blankinterval = 0; 􀃅改为0,或自定义时间

 

阅读(1938) | 评论(0) | 转发(4) |
0

上一篇:USB 摄像头

下一篇:s3c2410_ts.c

给主人留下些什么吧!~~