-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdata.c
201 lines (161 loc) · 4.28 KB
/
cdata.c
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* =====================================================================================
*
* Filename: cdata.c
*
* Description: linux device driver for study.
*
* Version: 1.0
* Created: 05/29/2012 05:41:43 PM
* Revision: none
* Compiler: gcc
*
* Author: navi,navi
* Organization:
*
* =====================================================================================
*/
#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/vmalloc.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/miscdevice.h>
#include <linux/input.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include "cdata_ioctl.h"
#define BUF_SIZE 128
#define DEV_NAME "cdata"
#define DEV_MAJOR 121
struct cdata_t{
unsigned long *fb;
char *buf;
int index;
};
static int cdata_open(struct inode *inode, struct file *filp)
{
int minor;
struct cdata_t *cdata;
printk(KERN_INFO "(Ivan Lee)CDATA: is opened !!\n");
minor = MINOR(inode->i_rdev);
printk(KERN_INFO "(Ivan Lee)minor number = %d.\n",minor);
cdata = kmalloc(sizeof(struct cdata_t), GFP_KERNEL);
cdata->buf = kmalloc(BUF_SIZE, GFP_KERNEL);
cdata->fb = ioremap(0x33f00000, 320*240*4);
cdata->index = 0;
filp->private_data = (void*)cdata;
return 0;
}
static ssize_t cdata_read(struct file *filp, char *buf, size_t size, loff_t *off)
{
return 0;
}
void flush_lcd(void *priv)
{
struct cdata_t *cdata = (struct cdata_t*)priv;
unsigned char *fb;
unsigned char *pixel;
int index;
int i;
fb =(unsigned char *)cdata->fb;
index = cdata->index;
//printk(KERN_INFO "(Ivan Lee)%s: index = %d\n", __func__, index);
for(i = 0; i < index; i++){
//printk(KERN_INFO "(Ivan Lee)%s: index = %d\n", __func__, index);
writeb(pixel[i], fb++);
//printk(KERN_INFO "flush one byte data.\n");
}
cdata->index = 0;
}
static ssize_t cdata_write(struct file *filp, const char *buf, size_t size, loff_t *off)
{
unsigned int i;
unsigned int index;
unsigned char *pixel;
struct cdata_t *cdata = filp->private_data;
pixel = cdata->buf;
index = cdata->index;
for(i = 0; i < size; i++){
if(index >= BUF_SIZE){
cdata->index = index;
flush_lcd((void *)cdata);
index = cdata->index;
}
copy_from_user(&pixel[index], &buf[i], 1);
index++;
printk(KERN_INFO "(Ivan Lee)%s: index = %d\n", __func__, index);
}
printk(KERN_INFO "(Ivan Lee)CDATA: Write!!\n");
return size;
}
static int cdata_close(struct inode *inode, struct file *filp)
{
printk(KERN_INFO "(Ivan Lee)CDATA: is closed ~~\n");
return 0;
}
static int cdata_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
int n;
unsigned long *fb;
int i;
struct cdata_t *cdata = (struct cdata_t *)filp->private_data;
switch(cmd){
case CDATA_CLEAR: {
n = *((int *)arg);//FIXME:dirty
printk(KERN_INFO "CDATA_CLEAR: %d pixels\n", n);
//FIXME: Lock
fb = cdata->fb;
//FIXME: Unlock
for(i = 0; i < n; i++){
writel(0x000000ff, fb + i);
}
break;
}
}
return 0;
}
static int cdata_flush(struct file *filp)
{
printk(KERN_INFO "(Ivan Lee)flush one time ^_^.\n");
return 0;
}
static struct file_operations cdata_fops = {
owner: THIS_MODULE,
open: cdata_open,
release: cdata_close,
write: cdata_write,
read: cdata_read,
ioctl: cdata_ioctl,
flush: cdata_flush,
};
static int cdata_init_module(void)
{
unsigned long *fb;
int i;
if(register_chrdev(DEV_MAJOR, DEV_NAME, &cdata_fops) < 0){
printk(KERN_INFO "(Ivan Lee)CDATA: can't register driver\n");
return -1;
}
fb = ioremap(0x33f00000, 320*240*4);/*remaping I/O memory adrress, physical address trans virtual address.*/
for(i = 0; i < 320*240; i++){
writel(0x00ff0000, fb++);/*clear framebuffer to color of red.*/
}
printk(KERN_INFO "(Ivan Lee)CDATA.ko initialed.\n");
return 0;
}
static void cdata_cleanup_module(void)
{
unregister_chrdev(DEV_MAJOR, DEV_NAME);
printk(KERN_INFO "(Ivan Lee)CDATA.ko cleanup.\n");
}
module_init(cdata_init_module);
module_exit(cdata_cleanup_module);
MODULE_LICENSE("GPL");