forked from jollen/ldd-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdata-fb-2.6.c
181 lines (145 loc) · 3.88 KB
/
cdata-fb-2.6.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
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#ifdef CONFIG_SMP
#define __SMP__
#endif
#define CDATA_MAJOR 121
#define BUFSIZE 1024
#define LCD_WIDTH (640)
#define LCD_HEIGHT (480)
#define LCD_BPP (1)
#define LCD_SIZE (LCD_WIDTH*LCD_HEIGHT*LCD_BPP)
struct cdata_t {
char data[BUFSIZE];
int index;
char *iomem;
unsigned int offset;
#if 0
struct timer_list timer;
#endif
struct work_struct work;
wait_queue_head_t wait;
};
static DECLARE_MUTEX(cdata_sem);
// Supporting APIs
void flush_lcd(struct work_struct *work)
{
struct cdata_t *cdata = container_of(work, struct cdata_t, work);
char *fb = cdata->iomem;
int offset = cdata->offset;
int index = cdata->index;
int i;
for (i = 0; i < index; i++) {
writeb(cdata->data[i], fb + offset);
offset++;
if (offset >= LCD_SIZE)
offset = 0;
}
cdata->index = 0;
cdata->offset = offset;
// Wake up process
//current->state = TASK_RUNNING;
wake_up(&cdata->wait);
}
static int cdata_open(struct inode *inode, struct file *filp)
{
struct cdata_t *cdata;
cdata = (struct cdata_t *)kmalloc(sizeof(struct cdata_t), GFP_KERNEL);
cdata->index = 0;
init_waitqueue_head(&cdata->wait);
cdata->iomem = ioremap(0xe0000000, LCD_SIZE);
#if 0
init_timer(&cdata->timer);
#endif
INIT_WORK(&cdata->work, flush_lcd);
cdata->offset = 0;
filp->private_data = (void *)cdata;
return 0;
}
static int cdata_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
printk(KERN_ALERT "cdata: in cdata_ioctl()\n");
return 0;
}
static ssize_t cdata_read(struct file *filp, char *buf,
size_t size, loff_t *off)
{
printk(KERN_ALERT "cdata: in cdata_read()\n");
return 0;
}
static ssize_t cdata_write(struct file *filp, const char *buf,
size_t count, loff_t *off)
{
struct cdata_t *cdata = (struct cdata_t *)filp->private_data;
DECLARE_WAITQUEUE(wait, current);
int i;
down(&cdata_sem);
for (i = 0; i < count; i++) {
if (cdata->index >= BUFSIZE) {
add_wait_queue(&cdata->wait, &wait);
current->state = TASK_INTERRUPTIBLE;
/*
*/
#if 0
cdata->timer.expires = jiffies + 500;
cdata->timer.function = flush_lcd;
cdata->timer.data = (unsigned long)cdata;
add_timer(&cdata->timer);
#endif
schedule_work_on(1, &cdata->work);
schedule();
current->state = TASK_RUNNING;
remove_wait_queue(&cdata->wait, &wait);
}
if (copy_from_user(&cdata->data[cdata->index++], &buf[i], 1))
return -EFAULT;
}
up(&cdata_sem);
return 0;
}
static int cdata_release(struct inode *inode, struct file *filp)
{
printk(KERN_ALERT "cdata: in cdata_release()\n");
return 0;
}
static int cdata_mmap(struct file *filp, struct vm_area_struct *vma)
{
unsigned long start = vma->vm_start;
unsigned long end = vma->vm_end;
unsigned long size;
size = end - start;
//remap_page_range(start, 0x33f00000, size, PAGE_SHARED);
}
struct file_operations cdata_fops = {
open: cdata_open,
release: cdata_release,
ioctl: cdata_ioctl,
read: cdata_read,
write: cdata_write,
mmap: cdata_mmap,
};
int my_init_module(void)
{
int i;
if (register_chrdev(CDATA_MAJOR, "cdata", &cdata_fops)) {
printk(KERN_ALERT "cdata module: can't registered.\n");
}
return 0;
}
void my_cleanup_module(void)
{
unregister_chrdev(CDATA_MAJOR, "cdata");
printk(KERN_ALERT "cdata module: unregisterd.\n");
}
module_init(my_init_module);
module_exit(my_cleanup_module);
MODULE_LICENSE("GPL");