国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品
電子工程網
標題:
【飛凌】platform_device + miscdevice 模式的LED驅動程序
[打印本頁]
作者:
yanhong
時間:
2010-7-30 12:46
標題:
【飛凌】platform_device + miscdevice 模式的LED驅動程序
本文轉引自 飛凌嵌入式 Linux技術交流區
www.witech.com.cn
感謝作者朋友的分享精神!
這是我最近學習Linux驅動模型的成果,發出來大家共同學習一下,該程序還有很多缺陷,希望高手能不吝賜教
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
MODULE_AUTHOR("YUZIQIANG");
MODULE_DESCRIPTION("LEDS DRIVE");
MODULE_VERSION("0.1");
MODULE_LICENSE("GPL");
#define DEV_NAME "FL2440LED"
#define LED_MAGIC 'L'
#define LED_ON _IOW(LED_MAGIC,0,int)
#define LED_OFF _IOW(LED_MAGIC,1,int)
#define LED_MINOR 125
#define LED_MAJOR 10
#define LED_CON 0
#define LED_DAT 4
#define LED_UP 8
int major;
dev_t devNu;
struct cdev ledCdev ;
void *ledbase;
ssize_t led_read(struct file *filp,char __user *buffer,size_t size,loff_t *offset);
ssize_t led_write(struct file *filp,const char __user *buffer,size_t size,loff_t *offset);
int led_open(struct inode *inode,struct file *filp);
int led_release(struct inode *inode,struct file *filp);
int led_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg);
static int led_probe(struct platform_device *pdev);
static int led_remove(struct platform_device *pdev);
struct resource s3c_led_resource[] ={
[0]={
.start = 0x56000010,
.end = 0x5600001b,
.flags = IORESOURCE_MEM,
}
};
struct file_operations led_opt ={
.owner = THIS_MODULE,
.ioctl = led_ioctl,
.open = led_open,
.read = led_read,
.write = led_write,
.release = led_release,
};
static struct miscdevice misc_led ={
.minor = LED_MINOR,
.name = "led",
.fops = &led_opt,
};
struct platform_device ledDevice= {
.name = "led",
.id = -1,//why
.num_resources = ARRAY_SIZE(s3c_led_resource),
.resource = s3c_led_resource,
.dev = {
.release = led_release,
}
};
struct platform_driver ledDriver ={
.probe = led_probe,
.remove = led_remove,
.driver = {
.owner = THIS_MODULE,
.name = "led",
}
};
int led_open(struct inode *inode,struct file *filp)
{
//GPBCON = 0x55555555;
writel(0x55555555,ledbase+LED_CON);
//GPBUP = 0xffffffff;
writel(0,ledbase+LED_UP);
writel(0,ledbase+LED_DAT);
//GPBDAT = 0x00000000;
printk("\nopen success \n");
return 0;
}
ssize_t led_read(struct file *filp,char __user *buffer,size_t size,loff_t *offset)
{
return 0;
}
ssize_t led_write(struct file *filp,const char __user *buffer,size_t size,loff_t *offset)
{
return 0;
}
int led_release(struct inode *inode,struct file *filp)
{
return 0;
}
int led_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
{
unsigned long tmp;
int pin=0;
///check the command is in the right form
if(arg>4||arg<1)
return -1;
if(_IOC_NR(cmd)>1||_IOC_NR(cmd)<0)
return -1;
if(arg==1)
pin=5;
else if(arg==2)
pin = 6;
else if(arg==3)
pin=8;
else if(arg==4)
pin=10;
else pin= 0;
do {
if(cmd==LED_ON)
{
tmp = readl(ledbase+LED_DAT);
tmp &=(~(1<
writel(tmp,ledbase +LED_DAT);
}
else if(cmd==LED_OFF)
{
tmp = readl(ledbase+LED_DAT);
tmp |=(1<
writel(tmp,ledbase +LED_DAT);
}
else
printk("command error");
break;
}
while(0);
///command switch
/*
switch (arg) {
case 1:
if(cmd==LED_ON)
{
tmp = readl(ledbase+LED_DAT);
tmp &=(~(1<<5));
writel(tmp,ledbase +LED_DAT);
}
else if(cmd==LED_OFF)
{
tmp = readl(ledbase+LED_DAT);
tmp |=(1<<5);
writel(tmp,ledbase +LED_DAT);
}
else
printk("command error");
break;
case 2:
if(cmd==LED_ON)
{
tmp = readl(ledbase+LED_DAT);
tmp &=(~(1<<6));
writel(tmp,ledbase +LED_DAT);
}
else if(cmd==LED_OFF)
{
tmp = readl(ledbase+LED_DAT);
tmp |=(1<<6);
writel(tmp,ledbase +LED_DAT);
}
else
printk("command error");
break;
case 3:
if(cmd==LED_ON)
{
tmp = readl(ledbase+LED_DAT);
tmp &=(~(1<<8));
writel(tmp,ledbase +LED_DAT);
}
else if(cmd==LED_OFF)
{
tmp = readl(ledbase+LED_DAT);
tmp |=(1<<8);
writel(tmp,ledbase +LED_DAT);
}
else
printk("command error");
break;
case 4:
if(cmd==LED_ON)
{
tmp = readl(ledbase+LED_DAT);
tmp &=(~(1<<10));
writel(tmp,ledbase +LED_DAT);
}
else if(cmd==LED_OFF)
{
tmp = readl(ledbase+LED_DAT);
tmp |=(1<<10);
writel(tmp,ledbase +LED_DAT);
}
else
printk("command error");
break;
default :
printk("error");
break;
}
*/
return 0;
}
static int led_probe(struct platform_device *pdev)
{
struct resource *res;
struct device *dev;
int size;
int ret;
dev=&pdev->dev;
printk("\nMatch success");
res= platform_get_resource(pdev,IORESOURCE_MEM,0);
if(res==NULL)
{
dev_err(dev,"no memory resource specified\n");
return -ENOENT;
}
size = res->end-res->start +1;
ledbase = ioremap(res->start,size);
if(ledbase==NULL)
{
dev_err(dev,"fail to ioremap() region\n");
ret=-EINVAL;
goto err_req;
}
ret=misc_register(&misc_led);
if(ret)
{
dev_err(dev,"cannot register led miscdev ");
goto err_misc;
}
err_misc:
iounmap(ledbase);
err_req:
return ret;
}
static int led_remove(struct platform_device *pdev)
{
//iounmap(ledbase);這一句有問題,加上就會出現oops
misc_deregister(&misc_led);
return 0;
}
int __init ledInit(void)
{
//int ret;
//struct class *ledClass = class_create(THIS_MODULE,"ledClass");
//alloc_chrdev_region(&devNu,0,1,DEV_NAME);
major = LED_MAJOR;
printk("\nMAJOR is %d\n",major);
devNu = MKDEV(LED_MAJOR,LED_MINOR);
//regist miscdevice
//misc_register(&misc_led);
//cdev_init(&ledCdev,&led_opt);
//ledCdev.owner = THIS_MODULE;
//ledCdev.ops = &led_opt;
//cdev_add(&ledCdev,devNu,1);
//AUTOMATIC CREATE DEVICE FILE IN /dev
platform_device_register(&ledDevice);
platform_driver_register(&ledDriver);
//device_create(ledClass,NULL,devNu,NULL,"led");
//在platform_device的總線中注冊設備時,會自動在/dev/下面生成設備文件,
//所以在這里若果在調用device_create就會出錯
//在platform_device_register中會創建/dev/下面的設備文件
//并且在調用platform_device_unregister的時候也會自動刪除/dev/下面創建的設備文件。
return 0;
}
void __exit ledExit(void)
{
//cdev_del(&ledCdev);
//unregister_chrdev_region(devNu,1);
//misc_deregister(&misc_led);
platform_driver_unregister(&ledDriver);
platform_device_unregister(&ledDevice);
}
module_init(ledInit);
module_exit(ledExit);
PS:
雖然有點大材小用,但是用來熟悉platform——device還是不錯的。
歡迎光臨 電子工程網 (http://m.qingdxww.cn/)
Powered by Discuz! X3.4
主站蜘蛛池模板:
日韩国产成人精品视频
|
7756短视频
|
国产专区_爽死777
|
亚洲视频免费在线观看
|
亚洲页码
|
偷自视频区视频真实在线
|
亚洲男人的天堂在线观看
|
国产成人无码AV麻豆
|
羞羞漫画视频
|
欧美一级视频免费
|
亚洲成a人片毛片在线
|
亚洲综合小视频
|
娇妻归来在线观看免费完整版电影
|
夜色伊甸园
|
欧美一级片在线观看
|
亚洲最新在线
|
中国xxxxxl17仙踪林
|
蜜桃传媒视频
|
四虎tv
|
三级黄免费
|
香蕉在线视频观看
|
国产69精品麻豆久久久久
|
小柔的性放荡羞辱日记动漫
|
欧美成人一级视频
|
午夜国产视频
|
一级毛片免费完整视频
|
久久超碰色中文字幕
|
欧美极品jizzhd欧美
|
日本一区二区在线
|
唯美清纯 自拍偷
|
国产精品第一综合首页
|
亚洲精品无码国产爽快A片
|
一级大片视频
|
在线观看 亚洲
|
99久久国产露脸精品竹菊传煤
|
人妻激情综合久久久久蜜桃
|
午夜欧美福利
|
小视频在线观看免费
|
曰本女同互慰高清在线观看
|
蜜桃传媒在线观看入口
|
一级毛片a女人刺激视频免费
|