forked from jollen/ldd-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdata-ts.c
163 lines (128 loc) · 3.42 KB
/
cdata-ts.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
#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>
void cdata_bh(unsigned long);
DECLARE_TASKLET(my_tasklet, cdata_bh, NULL);
struct cdata_ts {
struct input_dev ts_input;
int x;
int y;
};
void cdata_ts_handler(int irq, void *priv, struct pt_regs *reg);
static int ts_input_open(struct input_dev *dev)
{
struct cdata_ts *cdata = (struct cdata_ts *)dev->private;
}
static int ts_input_close(struct input_dev *dev)
{
}
void cdata_ts_handler(int irq, void *priv, struct pt_regs *reg)
{
struct cdata_ts *cdata = (struct cdata_ts *)priv;
printk(KERN_INFO "data_ts: TH...\n");
/* FIXME: read (x,y) from ADC */
cdata->x = 100;
cdata->y = 100;
my_tasklet.data = (unsigned long)cdata;
tasklet_schedule(&my_tasklet);
}
void cdata_bh(unsigned long priv)
{
struct cdata_ts *cdata = (struct cdata_ts *)priv;
struct input_dev *dev = &cdata->ts_input;
printk(KERN_INFO "data_ts: down...\n");
input_report_abs(dev, ABS_X, cdata->x);
input_report_abs(dev, ABS_Y, cdata->y);
}
static int cdata_ts_open(struct inode *inode, struct file *filp)
{
struct cdata_ts *cdata;
cdata = kmalloc(sizeof(struct cdata_ts), GFP_KERNEL);
set_gpio_ctrl(GPIO_YPON);
set_gpio_ctrl(GPIO_YMON);
set_gpio_ctrl(GPIO_XPON);
set_gpio_ctrl(GPIO_XMON);
ADCTSC = DOWN_INT | XP_PULL_UP_EN | \
XP_AIN | XM_HIZ | YP_AIN | YM_GND | \
XP_PST(WAIT_INT_MODE);
/* Request touch panel IRQ */
if (request_irq(IRQ_TC, cdata_ts_handler, 0,
"cdata-ts", (void *)cdata)) {
printk(KERN_ALERT "cdata: request irq failed.\n");
return -1;
}
/** handling input device ***/
cdata->ts_input.name = "cdata-ts";
cdata->ts_input.open = ts_input_open;
cdata->ts_input.close = ts_input_close;
cdata->ts_input.private = (void *)cdata;
// Set events
cdata->ts_input.evbit[0] = BIT(EV_ABS);
// Set types
cdata->ts_input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
input_register_device(&cdata->ts_input);
cdata->x = 0;
cdata->y = 0;
filp->private_data = (void *)cdata;
return 0;
}
static ssize_t cdata_ts_read(struct file *filp, char *buf, size_t size, loff_t *off)
{
return 0;
}
static ssize_t cdata_ts_write(struct file *filp, const char *buf, size_t size,
loff_t *off)
{
return 0;
}
static int cdata_ts_close(struct inode *inode, struct file *filp)
{
return 0;
}
static int cdata_ts_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
return -ENOTTY;
}
static struct file_operations cdata_ts_fops = {
owner: THIS_MODULE,
open: cdata_ts_open,
release: cdata_ts_close,
read: cdata_ts_read,
write: cdata_ts_write,
ioctl: cdata_ts_ioctl,
};
static struct miscdevice cdata_ts_misc = {
minor: CDATA_TS_MINOR,
name: "cdata-ts",
fops: &cdata_ts_fops,
};
int cdata_ts_init_module(void)
{
if (misc_register(&cdata_ts_misc) < 0) {
printk(KERN_INFO "CDATA-TS: can't register driver\n");
return -1;
}
printk(KERN_INFO "CDATA-TS: cdata_ts_init_module\n");
return 0;
}
void cdata_ts_cleanup_module(void)
{
misc_register(&cdata_ts_misc);
}
module_init(cdata_ts_init_module);
module_exit(cdata_ts_cleanup_module);
MODULE_LICENSE("GPL");