mini2440之背光驱动

背光是由LCD上LCD_PWR(GPG4)控制的。

#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>

#undef DEBUG
//#define DEBUG
#ifdef DEBUG
#define DPRINTK(x...) {printk(__FUNCTION__"(%d): ",__LINE__);printk(##x);}
#else
#define DPRINTK(x...) (void)(0)
#endif
//定义设备名为backlight
#define DEVICE_NAME	"backlight"

//定义背光变量bl_state,以记录背光的开关状态
static unsigned int bl_state;
//设置背光开关的函数主要是翻转背光变量bl_state
static inline void set_bl(int state)
{
	bl_state = !!state;//翻转背光变量bl_state
	//把结果写入背光所用的寄存器GPG(4),
	s3c2410_gpio_setpin(S3C2410_GPG(4), bl_state);
}
//获取背光开关的函数
static inline unsigned int get_bl(void)
{
	return bl_state;
}
//从应用程序读取参数并传递到内核中
static ssize_t dev_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 dev_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 dev_fops = {
	owner:	THIS_MODULE,
	read:	dev_read,	
	write:	dev_write,
};

static struct miscdevice misc = {
	.minor = MISC_DYNAMIC_MINOR,
	.name = DEVICE_NAME,
	.fops = &dev_fops,
};

static int __init dev_init(void)
{
	int ret;

	ret = misc_register(&misc);

	printk (DEVICE_NAME"\tinitialized\n");
//配置LCD背光引脚状态
	s3c2410_gpio_cfgpin(S3C2410_GPG(4), S3C2410_GPIO_OUTPUT);
	set_bl(1);
	return ret;
}


static void __exit dev_exit(void)
{
	misc_deregister(&misc);
}

module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARM Inc.");


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值