Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | #include "tpd.h" |
2 | ||
3 | extern struct tpd_device *tpd; | |
4 | ||
5 | //#ifdef TPD_HAVE_BUTTON | |
6 | //static int tpd_keys[TPD_KEY_COUNT] = TPD_KEYS; | |
7 | //static int tpd_keys_dim[TPD_KEY_COUNT][4] = TPD_KEYS_DIM; | |
8 | static unsigned int tpd_keycnt = 0; | |
9 | static int tpd_keys[TPD_VIRTUAL_KEY_MAX]={0}; | |
10 | static int tpd_keys_dim[TPD_VIRTUAL_KEY_MAX][4];// = {0}; | |
11 | static ssize_t mtk_virtual_keys_show(struct kobject *kobj, | |
12 | struct kobj_attribute *attr, char *buf) { | |
13 | int i, j; | |
14 | for(i=0, j=0;i<tpd_keycnt;i++) | |
15 | j+=sprintf(buf, "%s%s:%d:%d:%d:%d:%d%s",buf, | |
16 | __stringify(EV_KEY),tpd_keys[i], | |
17 | tpd_keys_dim[i][0],tpd_keys_dim[i][1], | |
18 | tpd_keys_dim[i][2],tpd_keys_dim[i][3], | |
19 | (i==tpd_keycnt-1?"\n":":")); | |
20 | return j; | |
21 | } | |
22 | ||
23 | static struct kobj_attribute mtk_virtual_keys_attr = { | |
24 | .attr = { | |
25 | .name = "virtualkeys.mtk-tpd", | |
26 | .mode = S_IRUGO, | |
27 | }, | |
28 | .show = &mtk_virtual_keys_show, | |
29 | }; | |
30 | ||
31 | static struct attribute *mtk_properties_attrs[] = { | |
32 | &mtk_virtual_keys_attr.attr, | |
33 | NULL | |
34 | }; | |
35 | ||
36 | static struct attribute_group mtk_properties_attr_group = { | |
37 | .attrs = mtk_properties_attrs, | |
38 | }; | |
39 | ||
40 | struct kobject *properties_kobj; | |
41 | ||
42 | void tpd_button_init(void) { | |
43 | int ret = 0, i = 0; | |
44 | #if 0 | |
45 | for(i=0; i<TPD_VIRTUAL_KEY_MAX; i++) | |
46 | { | |
47 | for(j=0; j<4; j++) | |
48 | { | |
49 | tpd_keys_dim[i][j]=0; | |
50 | } | |
51 | } | |
52 | #endif | |
53 | // if((tpd->kpd=input_allocate_device())==NULL) return -ENOMEM; | |
54 | tpd->kpd=input_allocate_device(); | |
55 | /* struct input_dev kpd initialization and registration */ | |
56 | tpd->kpd->name = TPD_DEVICE "-kpd"; | |
57 | set_bit(EV_KEY, tpd->kpd->evbit); | |
58 | //set_bit(EV_REL, tpd->kpd->evbit); | |
59 | //set_bit(EV_ABS, tpd->kpd->evbit); | |
60 | for(i=0;i<tpd_keycnt;i++) | |
61 | __set_bit(tpd_keys[i], tpd->kpd->keybit); | |
62 | tpd->kpd->id.bustype = BUS_HOST; | |
63 | tpd->kpd->id.vendor = 0x0001; | |
64 | tpd->kpd->id.product = 0x0001; | |
65 | tpd->kpd->id.version = 0x0100; | |
66 | if(input_register_device(tpd->kpd)) | |
67 | TPD_DMESG("input_register_device failed.(kpd)\n"); | |
68 | set_bit(EV_KEY, tpd->dev->evbit); | |
69 | for(i=0;i<tpd_keycnt;i++) | |
70 | __set_bit(tpd_keys[i], tpd->dev->keybit); | |
71 | properties_kobj = kobject_create_and_add("board_properties", NULL); | |
72 | if(properties_kobj) | |
73 | ret = sysfs_create_group(properties_kobj,&mtk_properties_attr_group); | |
74 | if(!properties_kobj || ret) | |
75 | printk("failed to create board_properties\n"); | |
76 | } | |
77 | ||
78 | void tpd_button(unsigned int x, unsigned int y, unsigned int down) { | |
79 | int i; | |
80 | if(down) { | |
81 | for(i=0;i<tpd_keycnt;i++) | |
82 | { | |
83 | if(x>=tpd_keys_dim[i][0]-(tpd_keys_dim[i][2]/2) && | |
84 | x<=tpd_keys_dim[i][0]+(tpd_keys_dim[i][2]/2) && | |
85 | y>=tpd_keys_dim[i][1]-(tpd_keys_dim[i][3]/2) && | |
86 | y<=tpd_keys_dim[i][1]+(tpd_keys_dim[i][3]/2) && | |
87 | !(tpd->btn_state&(1<<i))) | |
88 | { | |
89 | input_report_key(tpd->kpd, tpd_keys[i], 1); | |
90 | input_sync(tpd->kpd); | |
91 | tpd->btn_state|=(1<<i); | |
92 | TPD_DEBUG("[mtk-tpd] press key %d (%d)\n",i, tpd_keys[i]); | |
93 | printk("[mtk-tpd] press key %d (%d)\n",i, tpd_keys[i]); | |
94 | } | |
95 | } | |
96 | } else { | |
97 | for(i=0;i<tpd_keycnt;i++) { | |
98 | if(tpd->btn_state&(1<<i)) { | |
99 | input_report_key(tpd->kpd, tpd_keys[i], 0); | |
100 | input_sync(tpd->kpd); | |
101 | TPD_DEBUG("[mtk-tpd] release key %d (%d)\n",i, tpd_keys[i]); | |
102 | printk("[mtk-tpd] release key %d (%d)\n",i, tpd_keys[i]); | |
103 | } | |
104 | } | |
105 | tpd->btn_state=0; | |
106 | } | |
107 | } | |
108 | void tpd_button_setting(int keycnt, void *keys, void *keys_dim) | |
109 | { | |
110 | tpd_keycnt = keycnt; | |
111 | memcpy(tpd_keys, keys, keycnt*4); | |
112 | memcpy(tpd_keys_dim, keys_dim, keycnt*4*4); | |
113 | } | |
114 | //#endif |