OK6410的LED驱动

1.通过git下载完整的代码

git clone https://github.com/xuxianyin5490/s3c6410_led.git

2.驱动的核心代码

 C Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include<linux/module.h>
#include<linux/init.h>
#include<linux/miscdevice.h>
#include<linux/fs.h>
#include<linux/wait.h>
#include< asm/gpio.h>
#include< asm/io.h>
#include<linux/ioport.h>
#include< asm/uaccess.h>
#include<linux/sched.h>

#define DEVICENAME   "s3c6410_led"

#define GPMCON      0x7F008820
#define GPMDAT      0x7F008824
#define GPMPUD      0x7F008828

static  volatile  long  int *gpmcon;
static  volatile  long  int *gpmdat;
static  volatile  long  int *gpmpud;


int s3c6410_open ( struct inode *inode,  struct file *file)
{
    iowrite32((ioread32(gpmcon) & 0xFFFF0000),gpmcon);
    iowrite32((ioread32(gpmcon) | 0x1111),gpmcon);
     return  0;
}

int s3c6410_ioctl ( struct inode *inode,  struct file *file,  unsigned  int cmd,  unsigned  long arg)
{
     if(cmd> 1)
    {
         return - 1;
    }
     if(arg> 3)
    {
         return - 1;
    }
     switch(cmd)
    {
         case  0:
            {
                iowrite16((ioread16(gpmdat)|( 1<<arg)),gpmdat);      
            }
             break;
         case  1:
            {
                iowrite16((ioread16(gpmdat)&(~( 1<<arg))),gpmdat);
            }
             break;
         default:
             break;
    }

     return  0;
}

int s3c6410_close( struct inode *inode,  struct file *file)
{
     return  0;
}

struct file_operations s3c6410_fops = 
{
    .owner = THIS_MODULE,
    .open = &s3c6410_open,
    .ioctl = &s3c6410_ioctl,
    .release = &s3c6410_close,
};

struct miscdevice misc =
{
    .minor = MISC_DYNAMIC_MINOR,
    .name = DEVICENAME,
    .fops = &s3c6410_fops,
};

static  int __init led_init( void)
{
     int ret= 0;
     if(!request_mem_region(GPMCON, 12, "s3c6410_led"))
    {
        ret = -EBUSY;
        printk( "s3c6410_led request_mem_failed\n");
         goto request_mem_failed;
    }
    gpmcon = ioremap(GPMCON, 4);
     if(gpmcon== NULL)
    {
        ret = -EBUSY;
        printk( "s3c6410_led gpmcon failed\n");
         goto gpmcon_failed;
    }
    gpmdat = ioremap(GPMDAT, 4);
     if(gpmdat== NULL)
    {
        ret = -EBUSY;
        printk( "s3c6410_led gpmdat failed\n");
         goto gpmdat_failed;
    }
    gpmpud = ioremap(GPMPUD, 4);
     if(gpmpud== NULL)
    {
        ret = -EBUSY;
        printk( "s3c6410_led gpmpub failed\n");
         goto gpmpud_failed;
    }
    ret = misc_register(&misc);
     if(ret< 0)
    {
         return -EBUSY;
         goto misc_regster_failed;
    }
    printk( "s3c6410 led initialize\n");
     return ret;
misc_regster_failed:
    misc_deregister(&misc);
gpmpud_failed:
    iounmap(gpmpud);
gpmdat_failed:
    iounmap(gpmdat);
gpmcon_failed:
    iounmap(gpmcon);
request_mem_failed:
    release_mem_region(GPMCON, 12);
     return ret;
}

static  void __exit led_exit( void)
{
    iounmap(gpmpud);
    iounmap(gpmdat);
    iounmap(gpmcon);
    release_mem_region(GPMCON, 12);
    misc_deregister(&misc);
    printk( "s3c6410 led exit\n");
}

module_init(led_init);
module_exit(led_exit);

MODULE_AUTHOR( "Xu Xianyin");
MODULE_LICENSE( "GPL");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值