1 /****************************************************************************************
2 * driver/input/touchscreen/atmel_mxt224.c
3 *Copyright :ROCKCHIP Inc
8 ********************************************************************************************/
9 #include <linux/module.h>
10 #include <linux/delay.h>
11 #include <linux/earlysuspend.h>
12 #include <linux/hrtimer.h>
13 #include <linux/i2c.h>
14 #include <linux/input.h>
15 #include <linux/interrupt.h>
17 #include <linux/platform_device.h>
18 #include <linux/async.h>
19 #include <mach/gpio.h>
20 #include <linux/irq.h>
21 #include <mach/board.h>
23 #define FEATURE_CFG_DUMP
25 static int mxt224_i2c_write(struct i2c_client *client, u16 offset,void *buf,int size);
26 static int mxt224_i2c_read(struct i2c_client *client, u16 offset,void *buf,int size);
27 static int mXT224_probe(struct i2c_client *client, const struct i2c_device_id *id);
28 static int mXT224_remove(struct i2c_client *client);
30 #ifdef FEATURE_CFG_DUMP
31 static int total_size = 0;
36 #define local_debug //printk
38 #define ID_INFORMATION_SIZE 0x7
39 #define OBJECT_TABLE_ELEMENT_SIZE 0x6
41 #define TABLE_SIZE_ADDR ID_INFORMATION_SIZE-1
42 #define MESSAGE_T5 0x5
44 #define MXT224_REPORTID_T9_OFFSET 9
45 #define MXT224_MT_SCAN_POINTS 2
47 struct mxt224_id_info{
57 struct mxt224_table_info{
66 #define CFGERR_MASK (0x01<<3)
95 struct mxt224_id_info id_info;
97 struct mxt224_table_info *table_info;
111 //struct hrtimer timer;
112 struct i2c_client *client;
113 struct input_dev *input_dev;
114 struct delayed_work work;
115 struct workqueue_struct *mxt224_wq;
117 int (*power)(int on);
118 /* Object table relation */
119 struct mxt224_obj obj;
122 static struct mXT224_info ts_data = {
123 .int_gpio = RK29_PIN0_PA2,
124 .reset_gpio = RK29_PIN6_PC3,
130 struct report_id_table{
136 static struct report_id_table* id_table = NULL;
137 static u8 T9_cfg[31] = {0};
145 struct mxt224_key_info{
150 const struct mxt224_key_info key_info[] = {
158 const u8 T7[] = {0xff, 0xff, 0x32};
159 const u8 T8[] = {0x08, 0x05, 0x14, 0x14, 0x00, 0x00, 0x0a, 0x0f};
160 const u8 T9[] = {0x83, 0x00, 0x00, 0x0D, 0x0A, 0x00, 0x11, 0x28,
161 0x02, 0x01, 0x00, 0x01, 0x01, 0x00, 0x0A, 0x0A,
162 0x0A, 0x0A, 0x01, 0x5A, 0x00, 0xEF, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164 ///////////////////////////////////////
165 //0x83, 0x0D, 0x0A, 0x03, 0x03, 0x00, 0x11, 0x28,
166 //0x02, 0x03, 0x00, 0x01, 0x01, 0x00, 0x0A, 0x0A,
167 //0x0A, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168 //0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170 const u8 T15[] = {0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x41, 0x1E,
172 const u8 T18[] = {0x00, 0x00 };
173 const u8 T19[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
175 const u8 T20[] = {0x00, 0x64, 0x64, 0x64, 0x64, 0x00, 0x00, 0x00,
176 0x00, 0x00, 0x00, 0x00 };
177 const u8 T22[] = {0x15, 0x00, 0x00, 0x00, 0x19, 0xFF, 0xE7, 0x04,
178 0x32, 0x00, 0x01, 0x0A, 0x0F, 0x14, 0x19, 0x1E,
180 /////////////////////////////////////
181 //0x15, 0x00, 0x00, 0x00, 0x19, 0xff, 0xe7, 0x04,
182 //0x32, 0x00, 0x01, 0x0a, 0x0f, 0x14, 0x19, 0x1e,
185 const u8 T23[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186 0x00, 0x00, 0x00, 0x00, 0x00 };
187 const u8 T24[] = {0x03, 0x04, 0x03, 0xFF, 0x00, 0x64, 0x64, 0x01,
188 0x0A, 0x14, 0x28, 0x00, 0x4B, 0x00, 0x02, 0x00,
190 const u8 T25[] = {0x00, 0x00, 0x2E, 0xE0, 0x1B, 0x58, 0x36, 0xB0,
191 0x01, 0xF4, 0x00, 0x00, 0x00, 0x00 };
192 const u8 T27[] = {0x03, 0x02, 0x00, 0xE0, 0x03, 0x00, 0x23};
193 const u8 T28[] = {0x00, 0x00, 0x00, 0x04, 0x08, 0xF6 };
194 const u8 T38[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
196 const struct mxt224_cfg cfg_table[] = {
200 {15, T15, sizeof(T15)},
201 {18, T18, sizeof(T18)},
202 {19, T19, sizeof(T19)},
203 {20, T20, sizeof(T20)},
204 {22, T22, sizeof(T22)},
205 {23, T23, sizeof(T23)},
206 {24, T24, sizeof(T24)},
207 {25, T25, sizeof(T25)},
208 {27, T27, sizeof(T27)},
209 {28, T28, sizeof(T28)},
210 {38, T38, sizeof(T38)}
230 enum mXT224_touch_status{
236 u32 static crc24(u32 crc, u8 firstbyte, u8 secondbyte)
238 const u32 crcpoly = 0x80001b;
242 data_word = (u16)((u16)(secondbyte<<8u)|firstbyte);
243 result = ((crc<<1u)^(u32)data_word);
244 if(result & 0x1000000){
250 u32 static get_crc24(const u8* src, int cnt)
255 while(index < (cnt-1)){
256 crc = crc24(crc, *(src+index), *(src+index+1));
261 crc = crc24(crc, *(src+index), 0);
263 crc = (crc & 0x00ffffff);
267 static u32 mXT224_cfg_crc(void)
274 for(index=0; index<((sizeof(cfg_table)/sizeof(cfg_table[0]))-1); index++){
275 const u8* data = cfg_table[index].data;
276 while(sub_index <(cfg_table[index].size-1)){
277 crc = crc24(crc, *(data+sub_index), *(data+sub_index+1));
280 if(sub_index != cfg_table[index].size){
281 if(index == ((sizeof(cfg_table)/sizeof(cfg_table[0]))-1)){
282 crc = crc24(crc, *(data+sub_index), 0);
284 const u8* next_data = cfg_table[index+1].data;
285 crc = crc24(crc, *(data+sub_index), *(next_data));
286 crc = (crc & 0x00ffffff);
292 crc = (crc & 0x00ffffff);
295 //crc = crc24(crc, 0, 0);
296 crc = (crc & 0x00ffffff);
300 static void mxt224_mem_dbg(const void *src, int cnt)
304 const u8* disp = (u8*)src;
305 local_debug(KERN_INFO "%s: start...\n", __func__);
306 for(index=0; index < cnt; index++){
307 local_debug(KERN_INFO "0x%2x ", disp[index]);
309 local_debug(KERN_INFO "\n%s: ...end\n", __func__);
315 static irqreturn_t mXT224_ts_interrupt(int irq, void *handle)
317 struct mXT224_info *ts = handle;
318 local_debug(KERN_INFO "%s\n", __func__);
320 disable_irq_nosync(ts->int_gpio);
321 queue_delayed_work(ts->mxt224_wq, &ts->work, 0);
327 static u16 mXT224_get_obj_addr(u8 type, struct mxt224_table_info *info, u8 info_size)
332 for(index=0; index < info_size; index++){
333 if(type == info[index].obj_type){
334 addr = info[index].start_addr_msb;
336 addr |= info[index].start_addr_lsb;
344 static struct report_id_table* mXT224_build_report_id_table(
345 struct mxt224_table_info *info, u8 info_size)
350 id_table = (struct report_id_table*)kzalloc(info_size*sizeof(struct report_id_table), GFP_KERNEL);
353 local_debug(KERN_INFO "%s: Can't get memory!\n", __func__);
359 for(index = 0; index < info_size; index++){
360 #ifdef FEATURE_CFG_DUMP
361 total_size += ((info[index].size+1)*(info[index].instance+1));
363 if(info[index].obj_type == 0x5)
365 if(info[index].report_id == 0x00)
368 id_table[write_index].obj_type = info[index].obj_type;
369 id_table[write_index].report_start = (offset+1);
370 id_table[write_index].report_end = id_table[write_index].report_start+
371 info[index].report_id*(info[index].instance+1)-1;
373 offset = id_table[write_index].report_end;
377 #ifdef FEATURE_CFG_DUMP
378 for(index = 0; index < info_size; index++){
379 local_debug(KERN_INFO "%s: Object type:%d, size:[%d]\n", __func__,
380 info[index].obj_type, info[index].size+1);
388 static u8 mXT224_get_obj_type(u8 id, struct report_id_table* table, u8 table_size)
392 for(index=0; index < table_size; index++){
393 local_debug(KERN_INFO "%s: ID:%d, start:[%d], end:[%d], type:[%d]\n", __func__,
394 id, table[index].report_start, table[index].report_end,
395 table[index].obj_type);
396 if(id>=table[index].report_start && id<=table[index].report_end){
401 switch(table[index].obj_type){
407 int t9_offset = id-table[index].report_start;
408 if(t9_offset < MXT224_REPORTID_T9_OFFSET){
409 return MSG_T9_MT_1+t9_offset;
416 return MSG_T9_KEY_PRESS;
424 #define TS_POLL_PERIOD 10000*1000
428 static void mXT224_load_cfg(void)
435 local_debug(KERN_INFO "%s\n", __func__);
437 if(ts_data.cfg_delay){
440 ts_data.cfg_delay = 1;
442 // hrtimer_start(&ts_data.timer, ktime_set(0, TS_POLL_PERIOD), HRTIMER_MODE_REL);
444 for(index=0; index<(sizeof(cfg_table)/sizeof(cfg_table[0])); index++){
446 const u8* data = cfg_table[index].data;
447 u16 addr = mXT224_get_obj_addr(cfg_table[index].type, ts_data.obj.table_info,
448 ts_data.obj.table_size);
449 rc = mxt224_i2c_write(ts_data.client, addr, data, cfg_table[index].size);
451 local_debug(KERN_INFO "%s: Load mXT224 config failed, addr: 0x%x!\n", __func__, addr);
455 addr = mXT224_get_obj_addr(6, ts_data.obj.table_info, ts_data.obj.table_size);
460 rc = mxt224_i2c_write(ts_data.client, addr, buf, 6);
463 local_debug(KERN_INFO "%s: Back up NV failed!\n", __func__);
469 gpio_set_value(ts_data.reset_gpio, 0);
472 gpio_set_value(ts_data.reset_gpio, 1);
479 #define DETECT_MASK (0x01<<7)
480 #define RELEASE_MASK (0x01<<5)
481 #define MOVE_MASK (0x01<<4)
487 static int mXT224_process_msg(u8 id, u8 *msg)
493 local_debug(KERN_INFO "%s: Process mXT224 msg MSG_T6!\n", __func__);
494 u32 checksum = ((union msg_body*)msg)->t6.checksum;
496 u8 status = ((union msg_body*)msg)->t6.status;
498 if(status & CFGERR_MASK){
499 local_debug(KERN_INFO "%s: Process mXT224 cfg error!\n", __func__);
500 // mXT224_load_cfg();
503 if(checksum!=cfg_crc){
504 local_debug(KERN_INFO "%s: Process mXT224 cfg CRC error!\n", __func__);
505 local_debug(KERN_INFO "%s: Read CRC:[0x%x], Our CRC:[0x%x]\n", __func__, checksum, cfg_crc);
520 local_debug(KERN_INFO "%s: Process mXT224 msg MSG_T9_MT!\n", __func__);
523 x = ((union msg_body*)msg)->t9.x_msb;
525 x |= (((union msg_body*)msg)->t9.xy_poslisb>>4);
527 y = ((union msg_body*)msg)->t9.y_msb;
529 ((union msg_body*)msg)->t9.xy_poslisb &= 0x0f;
531 y |= ((union msg_body*)msg)->t9.xy_poslisb;
533 local_debug(KERN_INFO "%s: X[%d], Y[%d]\n", __func__, x, y);
535 if(((union msg_body*)msg)->t9.status & DETECT_MASK)
537 tcStatus = STATUS_PRESS;
538 }else if(((union msg_body*)msg)->t9.status & RELEASE_MASK)
540 tcStatus = STATUS_RELEASE;
543 input_report_abs(ts_data.input_dev, ABS_MT_TRACKING_ID, id - 1);
544 input_report_abs(ts_data.input_dev, ABS_MT_TOUCH_MAJOR, tcStatus);
545 input_report_abs(ts_data.input_dev, ABS_MT_WIDTH_MAJOR, 0);
546 input_report_abs(ts_data.input_dev, ABS_MT_POSITION_X, x);
547 input_report_abs(ts_data.input_dev, ABS_MT_POSITION_Y, y);
548 input_mt_sync(ts_data.input_dev);
549 local_debug(KERN_INFO "%s,input_report_abs x is %d,y is %d. status is [%d].\n", __func__, x, y, tcStatus);
552 case MSG_T9_KEY_PRESS:
554 int keyStatus, keyIndex;
556 keyStatus = ((union msg_body*)msg)->t9.status >> 7;
557 if(keyStatus) //press.
559 keyIndex = ((union msg_body*)msg)->t9.x_msb;
560 ts_data.last_key_index = keyIndex;
562 keyIndex = ts_data.last_key_index;
586 local_debug(KERN_INFO "%s: Default keyIndex [0x%x]\n", __func__, keyIndex);
590 local_debug(KERN_INFO "%s: Touch KEY code is [%d], keyStatus is [%d]\n", __func__, key_info[keyIndex].code, keyStatus);
592 input_report_key(ts_data.input_dev, key_info[keyIndex].code, keyStatus);
599 local_debug(KERN_INFO "%s: Default id[0x%x]\n", __func__, id);
609 static void mXT224_work_func(struct work_struct *work)
611 u8 track[MXT224_MT_SCAN_POINTS];
612 int index, ret, read_points;
613 struct message_t5 msg_t5_array[MXT224_MT_SCAN_POINTS];
615 local_debug(KERN_INFO "%s\n", __func__);
618 ret = mxt224_i2c_read(ts_data.client, ts_data.obj.msg_t5_addr,
619 (u8*)&msg_t5_array[0], sizeof(struct message_t5) * MXT224_MT_SCAN_POINTS);
620 read_points = ret / sizeof(struct message_t5);
622 local_debug(KERN_INFO "%s, this time read_points is %d\n", __func__, read_points);
623 mxt224_mem_dbg((u8*)&msg_t5_array[0], sizeof(struct message_t5) * read_points);
625 for(index = 0; index < read_points; index++)
627 if(msg_t5_array[index].report_id == 0xFF) // dirty message, don't process.
632 track[index] = mXT224_get_obj_type(msg_t5_array[index].report_id, id_table, ts_data.obj.table_size);
634 if(track[index] == 0){
635 local_debug(KERN_INFO "%s: Get object type failed!, report id[0x%x]\n", __func__, msg_t5_array[index].report_id);
639 local_debug(KERN_INFO "%s,object's msg type is %d.\n", __func__, track[index]);
642 for(index = 0; index < read_points; index++)
644 if(track[index] == 0xFF)
646 mXT224_process_msg(track[index], (u8*)&msg_t5_array[index].body);
647 if(track[index] == track[read_points - 1] || track[read_points - 1] == 0xFF)
649 input_sync(ts_data.input_dev);
650 local_debug(KERN_INFO "%s,input_sync ts_data.input_dev.\n", __func__);
655 enable_irq(ts_data.int_gpio);
659 static int mxt224_i2c_write(struct i2c_client *client, u16 offset,void *buf,int size)
661 unsigned char objectAddr[2+size];
664 objectAddr[0] = offset & 0x00FF;
665 objectAddr[1] = offset >> 8;
666 memcpy(&objectAddr[2], (char *)buf, size);
667 retlen = i2c_master_normal_send(client, objectAddr,2 + size, 200*1000);
672 static int mxt224_i2c_read(struct i2c_client *client, u16 offset,void *buf,int size)
674 unsigned char objectAddr[2];
677 if(ts_data.last_read_addr != offset)
679 ts_data.last_read_addr = offset;
680 objectAddr[0] = offset & 0x00FF;
681 objectAddr[1] = offset >> 8;
682 retlen = i2c_master_normal_send(client, objectAddr,2, 200*1000);
686 retlen = i2c_master_normal_recv(client, (char *)buf, size, 200*1000);
691 static int mXT224_probe(struct i2c_client *client, const struct i2c_device_id *id)
699 struct message_t5 msg_t5;
701 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
704 rc = gpio_request(ts_data.int_gpio, "Touch_int");
708 local_debug(KERN_INFO "%s: Request GPIO failed!\n", __func__);
712 rc = gpio_request(ts_data.reset_gpio, "Touch_reset");
716 local_debug(KERN_INFO "%s: Request mXT224 reset GPIO failed!\n", __func__);
720 /* store the value */
721 i2c_set_clientdata(client, &ts_data);
722 ts_data.client = client;
723 ts_data.int_gpio= client->irq;
724 //client->driver = &mXT224_driver;
726 ts_data.mxt224_wq = create_rt_workqueue("mxt224_wq");
727 INIT_DELAYED_WORK(&ts_data.work, mXT224_work_func);
730 gpio_pull_updown(ts_data.int_gpio, 1);
732 gpio_direction_output(ts_data.reset_gpio, 0);
733 gpio_set_value(ts_data.reset_gpio, GPIO_LOW);
735 gpio_set_value(ts_data.reset_gpio, GPIO_HIGH);
738 /* Try get mXT224 table size */
740 rc = mxt224_i2c_read(client, TABLE_SIZE_ADDR, &ts_data.obj.table_size, 1);
744 local_debug(KERN_INFO "%s: Get table size failed!\n", __func__);
750 /* Try get mXT224 device info */
751 info_size = CRC_SIZE+ID_INFORMATION_SIZE+ts_data.obj.table_size*OBJECT_TABLE_ELEMENT_SIZE;
753 ts_data.obj.table_info_byte = (u8*)kzalloc(info_size, GFP_KERNEL);
755 if(!ts_data.obj.table_info_byte)
757 local_debug(KERN_INFO "%s: Can't get memory!\n", __func__);
762 rc = mxt224_i2c_read(client, 0, ts_data.obj.table_info_byte, info_size);
766 local_debug(KERN_INFO "%s: Get mXT224 info failed!\n", __func__);
767 goto get_info_failed;
770 ts_data.obj.table_info = (struct mxt224_table_info*)(ts_data.obj.table_info_byte+ID_INFORMATION_SIZE);
771 mxt224_mem_dbg(ts_data.obj.table_info_byte, info_size);
776 /* Try get and check CRC */
777 ts_data.obj.info_crc = (ts_data.obj.table_info_byte[info_size-3])|
778 (ts_data.obj.table_info_byte[info_size-2]<<8)|
779 (ts_data.obj.table_info_byte[info_size-1]<<16);
780 crc = get_crc24(ts_data.obj.table_info_byte, info_size-CRC_SIZE);
782 if(ts_data.obj.info_crc != crc)
784 //1 TODO: Need set config table
786 local_debug(KERN_INFO "%s:CRC failed, read CRC:[0x%x], get CRC:[0x%x]\n", __func__, ts_data.obj.info_crc, crc);
793 cfg_crc = mXT224_cfg_crc();
798 /* Build report id table */
799 mXT224_build_report_id_table(ts_data.obj.table_info, ts_data.obj.table_size);
803 /* Dump mXT224 config setting */
804 #ifdef FEATURE_CFG_DUMP
806 local_debug(KERN_INFO "%s: Config size: %d\n", __func__, total_size);
808 cfg_dmup = (u8*)kzalloc(info_size+total_size, GFP_KERNEL);
812 local_debug(KERN_INFO "%s: Cannot get memory!\n", __func__);
816 mxt224_i2c_read(client, 0, cfg_dmup, info_size+total_size);
817 mxt224_mem_dbg(cfg_dmup, info_size+total_size);
821 /* Try get mXT224 ID info */
822 rc = mxt224_i2c_read(client, 0, &ts_data.obj.id_info, ID_INFORMATION_SIZE);
824 local_debug(KERN_INFO "%s: ID version is 0x%x.\n", __func__, ts_data.obj.id_info.version);
827 /* Try get message T5 info */
828 if(gpio_get_value(ts_data.int_gpio))
830 //1 TODO: Need check touch interrput pin
832 local_debug(KERN_INFO "%s: GPIO status error!\n", __func__);
838 ts_data.obj.msg_t5_addr = mXT224_get_obj_addr(0x5, ts_data.obj.table_info, ts_data.obj.table_size);
840 rc = mxt224_i2c_read(client, ts_data.obj.msg_t5_addr, (u8*)&msg_t5, sizeof(struct message_t5));
844 local_debug(KERN_INFO "%s:Can't get message T5!\n", __func__);
848 mxt224_mem_dbg((u8*)&msg_t5, sizeof(struct message_t5));
849 mXT224_process_msg(mXT224_get_obj_type(msg_t5.report_id, id_table, ts_data.obj.table_size), (u8*)&msg_t5.body);
851 object_addr = mXT224_get_obj_addr(0x9, ts_data.obj.table_info, ts_data.obj.table_size);
853 rc = mxt224_i2c_read(client, object_addr, (u8*)&T9_cfg[0], 31);
857 local_debug(KERN_INFO "%s:Can't get message T9!\n", __func__);
861 mxt224_mem_dbg((u8*)&T9_cfg[0], 31);
863 local_debug(KERN_INFO "%s:Change T9 orient to [0]!\n", __func__);
866 rc = mxt224_i2c_write(client, object_addr, (u8*)&T9_cfg[0], 31);
869 local_debug(KERN_INFO "%s:Can't write message T9!\n", __func__);
873 rc = mxt224_i2c_read(client, object_addr, (u8*)&T9_cfg[0], 31);
877 local_debug(KERN_INFO "%s:Can't get message T9!\n", __func__);
880 mxt224_mem_dbg((u8*)&T9_cfg[0], 31);
882 //local_debug(KERN_INFO "%s:Find obj report: 0x%x\n", __func__,
883 // mXT224_get_obj_type(msg_t5.report_id, id_table, obj_table_size));
886 if(gpio_get_value(ts_data.int_gpio))
888 local_debug(KERN_INFO "%s: GPIO value is high\n", __func__);
892 ts_data.input_dev = input_allocate_device();
893 if (!ts_data.input_dev)
899 input_set_drvdata(ts_data.input_dev, &ts_data);
901 snprintf(ts_data.phys, sizeof(ts_data.phys),
902 "%s/input0", dev_name(&client->dev));
904 ts_data.input_dev->name = "mXT224_touch";
905 ts_data.input_dev->id.bustype = BUS_I2C;
906 ts_data.input_dev->phys = ts_data.phys;
909 set_bit(EV_SYN, ts_data.input_dev->evbit);
910 set_bit(EV_KEY, ts_data.input_dev->evbit);
911 set_bit(BTN_TOUCH, ts_data.input_dev->keybit);
912 set_bit(BTN_2, ts_data.input_dev->keybit);
913 set_bit(EV_ABS, ts_data.input_dev->evbit);
915 input_set_abs_params(ts_data.input_dev, ABS_X, 0, 240, 0, 0);
916 input_set_abs_params(ts_data.input_dev, ABS_Y, 0, 320, 0, 0);
918 for(index=0; index<(sizeof(key_info)/sizeof(key_info[0])); index++)
920 input_set_capability(ts_data.input_dev, EV_KEY, key_info[index].code);
923 ts_data.input_dev->evbit[0] = BIT_MASK(EV_ABS)|BIT_MASK(EV_KEY)|BIT_MASK(EV_SYN);
924 ts_data.input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
925 //ts_data.input_dev->keybit[BIT_WORD(BTN_2)] = BIT_MASK(BTN_2);
927 for(index=0; index<(sizeof(key_info)/sizeof(key_info[0])); index++)
929 input_set_capability(ts_data.input_dev, EV_KEY, key_info[index].code);
931 input_set_abs_params(ts_data.input_dev, ABS_X, 0, CONFIG_MXT224_MAX_X, 0, 0);
932 input_set_abs_params(ts_data.input_dev, ABS_Y, 0, CONFIG_MXT224_MAX_Y, 0, 0);
933 input_set_abs_params(ts_data.input_dev, ABS_PRESSURE, 0, 255, 0, 0);
934 input_set_abs_params(ts_data.input_dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
935 input_set_abs_params(ts_data.input_dev, ABS_HAT0X, 0, CONFIG_MXT224_MAX_X, 0, 0);
936 input_set_abs_params(ts_data.input_dev, ABS_HAT0Y, 0, CONFIG_MXT224_MAX_Y, 0, 0);
937 input_set_abs_params(ts_data.input_dev, ABS_MT_POSITION_X,0, CONFIG_MXT224_MAX_X, 0, 0);
938 input_set_abs_params(ts_data.input_dev, ABS_MT_POSITION_Y, 0, CONFIG_MXT224_MAX_Y, 0, 0);
939 input_set_abs_params(ts_data.input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
940 input_set_abs_params(ts_data.input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
941 input_set_abs_params(ts_data.input_dev, ABS_MT_TRACKING_ID, 0, 10, 0, 0);
944 rc = input_register_device(ts_data.input_dev);
948 dev_err(&client->dev, "mXT224: input_register_device rc=%d\n", rc);
952 ts_data.int_gpio = gpio_to_irq(ts_data.int_gpio);
954 rc = request_irq(ts_data.int_gpio, mXT224_ts_interrupt,
955 IRQF_TRIGGER_FALLING, "mXT224_touch", &ts_data);
958 local_debug(KERN_INFO "mXT224 request interrput failed!\n");
960 local_debug(KERN_INFO "mXT224 request interrput successed!\n");
967 /* Free mXT224 info */
970 if(ts_data.input_dev != NULL)
971 input_free_device(ts_data.input_dev);
973 #ifdef FEATURE_CFG_DUMP
976 kfree(ts_data.obj.table_info_byte);
988 static int __devexit mXT224_remove(struct i2c_client *client)
990 struct mXT224_info *ts = i2c_get_clientdata(client);
992 free_irq(ts->int_gpio, ts);
993 if (cancel_delayed_work_sync(&ts->work)) {
995 * Work was pending, therefore we need to enable
996 * IRQ here to balance the disable_irq() done in the
999 enable_irq(ts->int_gpio);
1002 input_unregister_device(ts->input_dev);
1004 if(id_table != NULL)
1012 static const struct i2c_device_id mXT224_ts_id[] = {
1013 { "mXT224_touch", 0 },
1017 MODULE_DEVICE_TABLE(i2c, mXT224_ts_id);
1019 static struct i2c_driver mXT224_driver = {
1021 .owner = THIS_MODULE,
1022 .name = "mXT224_touch"
1024 .id_table = mXT224_ts_id,
1025 .probe = mXT224_probe,
1026 .remove = __devexit_p(mXT224_remove),
1029 static void __init mXT_init_async(void *unused, async_cookie_t cookie)
1031 local_debug("--------> %s <-------------\n",__func__);
1032 i2c_add_driver(&mXT224_driver);
1036 static int __init mXT_init(void)
1038 async_schedule(mXT_init_async, NULL);
1043 static void __exit mXT_exit(void)
1045 i2c_del_driver(&mXT224_driver);
1049 module_init(mXT_init);
1050 module_exit(mXT_exit);
1052 MODULE_LICENSE("GPL");