input: touchscreen: add touch screen of gslx680 for rk3399-firefly-edp
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / byd693x_ts.c
1 \r
2 \r
3 #include <linux/i2c.h>\r
4 #include <linux/input.h>\r
5 \r
6 #include <linux/interrupt.h>\r
7 #include <linux/delay.h>\r
8 #include <linux/interrupt.h>\r
9 #include <linux/errno.h>\r
10 #include <linux/kernel.h>\r
11 #include <linux/module.h>\r
12 #include <linux/slab.h>\r
13 #include <linux/input/mt.h>             //use slot B protocol, Android 4.0 system\r
14 #include <linux/platform_device.h>\r
15 #include <linux/async.h>\r
16 #include <linux/hrtimer.h>\r
17 #include <linux/init.h>\r
18 #include <linux/ioport.h>\r
19 #include <asm/irq.h>\r
20 #include <asm/io.h>\r
21 #include <asm/uaccess.h>\r
22 #include <linux/gpio.h>\r
23 #ifdef CONFIG_RK_CONFIG\r
24 #include <mach/config.h>\r
25 #endif\r
26 #include <mach/irqs.h>\r
27 //#include <mach/system.h>\r
28 //#include <mach/hardware.h>\r
29 //#include <mach/sys_config.h>\r
30 #include <mach/board.h>\r
31 \r
32 #ifdef CONFIG_HAS_EARLYSUSPEND\r
33     #include <linux/pm.h>\r
34     #include <linux/earlysuspend.h>\r
35 #endif\r
36 \r
37 //#define       CONFIG_TS_FUNCTION_CALLED_DEBUG                 //Display the debug information whitch function is called\r
38 //#define CONFIG_TS_PROBE_DEBUG         //Display the debug information in byd693x_ts_probe function\r
39 //#define CONFIG_TS_I2C_TRANSFER_DEBUG          //Display the debug information of IIC transfer\r
40 //#define CONFIG_TPKEY_STATUS_DEBUG                     //Display the debug information of Touch Key status\r
41 //#define CONFIG_TS_WORKQUEUE_DEBUG             //Display the debug ihnformation of creating work queue\r
42 //#define CONFIG_TS_COORDIATE_DEBUG             //\r
43 //#define CONFIG_TS_CUTEDGE_DEBUG                       //\r
44 \r
45 //----------------------------------------//\r
46 #define TOUCH_INT_NO    SW_INT_IRQNO_PIO    //GPIO :set the interrupt \r
47 #define byd693x_I2C_NAME        "byd693x-ts"\r
48 \r
49 //----------------------------------------//\r
50 struct ChipSetting {\r
51         char No;\r
52         char Reg;\r
53         char Data1;\r
54         char Data2;\r
55 };\r
56 \r
57 #include "byd693x_ts.h"\r
58 \r
59 #define VERSION         "byd693x_20120731_16:52_V1.2_Charles@Raysens@Zed"\r
60 #define CTP_NAME        "byd693x-ts"\r
61 \r
62 #define TP_MODULE_NAME  CTP_NAME\r
63 #ifdef CONFIG_RK_CONFIG\r
64 \r
65 enum {\r
66 #if defined(RK2928_PHONEPAD_DEFAULT_CONFIG)\r
67         DEF_EN = 1,\r
68 #else\r
69         DEF_EN = 0,\r
70 #endif\r
71         DEF_IRQ = 0x002003c7,\r
72         DEF_RST = 0X000003d5,\r
73         DEF_I2C = 2, \r
74         DEF_ADDR = 0x52,\r
75         DEF_X_MAX = 800,\r
76         DEF_Y_MAX = 480,\r
77 };\r
78 static int en = DEF_EN;\r
79 module_param(en, int, 0644);\r
80 \r
81 static int irq = DEF_IRQ;\r
82 module_param(irq, int, 0644);\r
83 static int rst =DEF_RST;\r
84 module_param(rst, int, 0644);\r
85 \r
86 static int i2c = DEF_I2C;            // i2c channel\r
87 module_param(i2c, int, 0644);\r
88 static int addr = DEF_ADDR;           // i2c addr\r
89 module_param(addr, int, 0644);\r
90 static int x_max = DEF_X_MAX;\r
91 module_param(x_max, int, 0644);\r
92 static int y_max = DEF_Y_MAX;\r
93 module_param(y_max, int, 0644);\r
94 \r
95 #include "rk_tp.c"\r
96 #endif\r
97 \r
98 \r
99 \r
100 struct byd_platform_data *byd6932_pdata; \r
101 \r
102 \r
103 #define FINGER_NO_MAX           10              //Define the max finger number, but the really finger number: fetch from .fex file\r
104 #define BYD_COORD_READ_ADDR 0x5c\r
105 \r
106 static int SCREEN_MAX_X = 1024;\r
107 static int SCREEN_MAX_Y = 600;\r
108 static int Get_Finger_Num = 5;\r
109 \r
110 #define RESO_X_NO               0\r
111 #define RESO_Y_NO               1\r
112 \r
113 struct ChipSetting byd693xcfg_Resolution[]={                                                    \r
114 //{ 2,0x08,     200/256,        200%256},       //      1       FTHD_H;FTHD_L   //¨º???¡ã¡ä?¨¹?D?¦Ì\r
115 //{ 2,0x0A,     120/256,        120%256},       //      2       NTHD_H;NTHD_L   //??¨¦¨´?D?¦Ì\r
116 { 2,0x0C,       800/256,        800%256},       //      3 RESX_H;RESX_L //X¡¤?¡À??¨º\r
117 { 2,0x0E,       480/256,        480%256},       //      4       RESY_H;RESY_L   //Y¡¤?¡À??¨º\r
118 };\r
119 \r
120 static void deviceResume(struct i2c_client *client);\r
121 static void deviceSuspend(struct i2c_client *client);\r
122 void byd693xdeviceInit(struct i2c_client *client); \r
123 \r
124 //static int byd693x_ts_open(struct input_dev *dev);\r
125 //static void byd693x_ts_close(struct input_dev *dev);\r
126 static int byd693x_ts_suspend(struct i2c_client *client, pm_message_t mesg);\r
127 static int byd693x_ts_resume(struct i2c_client *client);\r
128 #ifdef CONFIG_HAS_EARLYSUSPEND\r
129 static void byd693x_ts_early_suspend(struct early_suspend *h);\r
130 static void byd693x_ts_late_resume(struct early_suspend *h);\r
131 #endif /* CONFIG_HAS_EARLYSUSPEND */\r
132 \r
133 static irqreturn_t byd693x_ts_isr(int irq, void *dev_id);\r
134 static struct workqueue_struct *byd693x_wq;\r
135 \r
136 \r
137 struct byd_ts_priv {\r
138         struct i2c_client *client;\r
139         struct input_dev *input;\r
140         struct hrtimer timer;\r
141         struct work_struct  byd_work;\r
142 #ifdef  CONFIG_HAS_EARLYSUSPEND\r
143         struct early_suspend early_suspend;\r
144 #endif \r
145 \r
146         int irq;\r
147         int FingerNo;\r
148         int FingerDetect;\r
149         u8 btn_pre_TPKey;\r
150         int suspend_opend;\r
151 };\r
152 \r
153 /***********************************************************\r
154 Read Data from TP through IIC\r
155 ***********************************************************/\r
156 static int ReadRegister(struct i2c_client *client,uint8_t reg,unsigned char *buf, int ByteLen)\r
157 {\r
158 //      unsigned char buf[4];\r
159         struct i2c_msg msg[2];\r
160         int ret;\r
161 \r
162 //      memset(buf, 0xFF, sizeof(buf));\r
163         msg[0].addr = client->addr;\r
164         msg[0].flags = 0;\r
165         msg[0].len = 1;\r
166         msg[0].buf = &reg;\r
167         msg[0].scl_rate=byd693x_I2C_RATE;\r
168 \r
169         msg[1].addr = client->addr;\r
170         msg[1].flags = I2C_M_RD;\r
171         msg[1].len = ByteLen;\r
172         msg[1].buf = buf;\r
173         msg[1].scl_rate=byd693x_I2C_RATE;\r
174 \r
175         ret = i2c_transfer(client->adapter, msg, 2);\r
176 \r
177         #ifdef CONFIG_TS_I2C_TRANSFER_DEBUG\r
178         if(ret<0)       printk("                ReadRegister: i2c_transfer Error !\n");\r
179         else            printk("                ReadRegister: i2c_transfer OK !\n");\r
180         #endif\r
181         if(ret<0)               {       return 0;       }\r
182                 else            {       return 1;       }\r
183 }\r
184 \r
185 /***********************************************************\r
186 Write Data to TP through IIC\r
187 ***********************************************************/\r
188 static void WriteRegister(struct i2c_client *client,uint8_t Reg,unsigned char Data1,unsigned char Data2,int ByteNo)\r
189 {       \r
190         struct i2c_msg msg;\r
191         unsigned char buf[4];\r
192         int ret;\r
193 \r
194         buf[0]=Reg;\r
195         buf[1]=Data1;\r
196         buf[2]=Data2;\r
197         buf[3]=0;\r
198 \r
199         msg.addr = client->addr;\r
200         msg.flags = 0;\r
201         msg.len = ByteNo+1;\r
202         msg.buf = (char *)buf;\r
203         msg.scl_rate=byd693x_I2C_RATE;\r
204         ret = i2c_transfer(client->adapter, &msg, 1);\r
205 \r
206         #ifdef CONFIG_TS_I2C_TRANSFER_DEBUG\r
207         if(ret<0)       printk("                WriteRegister: i2c_master_send Error !\n");\r
208         else            printk("                WriteRegister: i2c_master_send OK !\n");\r
209         #endif\r
210 }\r
211 \r
212 void byd693xdeviceInit(struct i2c_client *client)\r
213 {       \r
214         deviceSuspend(client);\r
215         deviceResume(client);\r
216 mdelay(30);\r
217 }\r
218 \r
219 static void deviceResume(struct i2c_client *client)\r
220 {       \r
221         int i;\r
222 \r
223         for(i=0;i<sizeof(Resume)/sizeof(Resume[0]);i++)\r
224         {\r
225                 WriteRegister(  client,Resume[i].Reg,\r
226                                 Resume[i].Data1,Resume[i].Data2,\r
227                                 Resume[i].No);\r
228         }\r
229         mdelay(20);\r
230         //Config the resolution of CTP\r
231         for(i=0;i<sizeof(byd693xcfg_Resolution)/sizeof(byd693xcfg_Resolution[0]);i++)\r
232         {\r
233                 WriteRegister(  client,byd693xcfg_Resolution[i].Reg,\r
234                                 byd693xcfg_Resolution[i].Data1,byd693xcfg_Resolution[i].Data2,\r
235                                 byd693xcfg_Resolution[i].No);\r
236         }\r
237         mdelay(20);\r
238 }\r
239 \r
240 static void deviceSuspend(struct i2c_client *client)\r
241 {       \r
242         int i;\r
243         \r
244         for(i=0;i<sizeof(Suspend)/sizeof(Suspend[0]);i++)\r
245         {\r
246                 WriteRegister(  client,Suspend[i].Reg,\r
247                                 Suspend[i].Data1,Suspend[i].Data2,\r
248                                 Suspend[i].No);\r
249         }\r
250         mdelay(50);\r
251 }\r
252 \r
253 static void bf693x_ts_send_keyevent(struct byd_ts_priv *byd_priv,u8 btn_status)\r
254 {\r
255         \r
256         switch(btn_status & 0xf0)\r
257         {\r
258                 case 0x90:\r
259                         byd_priv->btn_pre_TPKey = TPKey_code[0];\r
260                         break;\r
261                 case 0xa0:\r
262                         byd_priv->btn_pre_TPKey = TPKey_code[1];\r
263                         break;\r
264                 case 0xb0:\r
265                         byd_priv->btn_pre_TPKey = TPKey_code[2];\r
266                         break;\r
267                 case 0xc0:\r
268                         byd_priv->btn_pre_TPKey = TPKey_code[3];\r
269                         break;\r
270                 case 0xf0:\r
271                         input_report_key(byd_priv->input, byd_priv->btn_pre_TPKey, REPORT_TPKEY_UP);\r
272                         input_sync(byd_priv->input);\r
273                         return;\r
274                 default:\r
275                         return;\r
276         }\r
277         input_report_key(byd_priv->input, byd_priv->btn_pre_TPKey, REPORT_TPKEY_DOWN);\r
278         input_sync(byd_priv->input);\r
279 }\r
280         \r
281 static void byd693x_ts_work(struct work_struct *work)\r
282 {\r
283         int i;\r
284         unsigned short xpos=0, ypos=0;\r
285         unsigned char Coord_Buf[4*FINGER_NO_MAX +1];            //Define the max finger data\r
286         u8 btn_status;\r
287         u8 Finger_ID,Finger_Status,Report_Status;\r
288 \r
289         struct byd_ts_priv *byd_priv = container_of(work,struct byd_ts_priv,byd_work);\r
290 \r
291         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
292         printk("+-----------------------------------------+\n");\r
293         printk("|       byd693x_ts_work!                  |\n");\r
294         printk("+-----------------------------------------+\n");\r
295         #endif\r
296         if (byd_priv->suspend_opend == 1)\r
297                 return ;\r
298                 \r
299         ReadRegister(byd_priv->client,BYD_COORD_READ_ADDR,Coord_Buf,(4 * Get_Finger_Num +1));           //read only the used finger number data\r
300                 \r
301         btn_status = Coord_Buf[0];\r
302 #ifdef CONFIG_TS_COORDIATE_DEBUG\r
303         printk("btn_status is: 0x%x\n",btn_status);\r
304 #endif\r
305         \r
306         if ( 0x00 == (btn_status & 0x80))\r
307         {\r
308                 return;\r
309         }\r
310 \r
311         bf693x_ts_send_keyevent(byd_priv,btn_status);\r
312 \r
313         byd_priv->FingerDetect = 0;\r
314         Report_Status = 0;\r
315         if ((btn_status & 0x0f))\r
316                 {\r
317                         for(i=0;i< (btn_status & 0x0f);i++)\r
318                         {\r
319                                 Finger_ID = (Coord_Buf[i*4 + 1]>>4)-1;\r
320                                 Finger_Status = Coord_Buf[i*4 + 3] & 0xf0;\r
321                                 xpos = Coord_Buf[i*4 + 1] & 0x0f;\r
322                                 xpos = (xpos <<8) | Coord_Buf[i*4 + 2];\r
323                                 \r
324                                 ypos = Coord_Buf[i*4 + 3] & 0x0f;\r
325                                 ypos = (ypos <<8) | Coord_Buf[i*4 + 4];\r
326                         \r
327                         if (byd6932_pdata ->swap_xy)\r
328                                 swap(xpos, ypos);\r
329                         if (byd6932_pdata ->xpol)\r
330                                 xpos = byd6932_pdata ->screen_max_x -xpos;\r
331                         if (byd6932_pdata ->ypol)\r
332                                 ypos = byd6932_pdata ->screen_max_y -ypos;\r
333 \r
334                                 if((0xa0 == Finger_Status) || (0x90 == Finger_Status))          //0xa0:The first Touch;  0x90: Hold Finger Touch\r
335                                 {\r
336                                         byd_priv->FingerDetect++;\r
337                                         Report_Status = 1;\r
338 //                                      printk("Finger_ID = 0x%x, DOWN\n", Finger_ID);\r
339                                         input_mt_slot(byd_priv->input, Finger_ID);              //Slot B protocol\r
340                                         input_report_abs(byd_priv->input, ABS_MT_TRACKING_ID, Finger_ID);\r
341                                         input_report_abs(byd_priv->input, ABS_MT_TOUCH_MAJOR, REPORT_TOUCH_MAJOR); //Finger Size\r
342                                         input_report_abs(byd_priv->input, ABS_MT_POSITION_X, xpos);\r
343                                         input_report_abs(byd_priv->input, ABS_MT_POSITION_Y, ypos);\r
344                                         input_report_abs(byd_priv->input, ABS_MT_WIDTH_MAJOR, REPORT_WIDTH_MAJOR); //Touch Size\r
345                 \r
346                                         #ifdef CONFIG_TS_COORDIATE_DEBUG\r
347                                                 printk("  Finger Touch X = %d , Y = %d, State = 0x%x,Finger_ID=0x%x\n\n",xpos,ypos,Finger_Status,Finger_ID);\r
348                                         #endif\r
349                                 }\r
350                                 \r
351                                 if (Finger_Status == 0xc0)\r
352                                 {\r
353                                         Report_Status = 1;\r
354                                         input_mt_slot(byd_priv->input, Finger_ID);\r
355                                         input_report_abs(byd_priv->input, ABS_MT_TRACKING_ID, -1);\r
356                                 #ifdef CONFIG_TS_COORDIATE_DEBUG\r
357                                         printk("        Touch release  X = %d , Y = %d, State = 0x%x,Finger_ID=0x%x\n\n",xpos,ypos,Finger_Status,Finger_ID);\r
358                                 #endif\r
359                                 }\r
360                         }\r
361                 }\r
362         if (Report_Status)\r
363         {\r
364                         input_sync(byd_priv->input);\r
365         }\r
366 }\r
367 \r
368 static int byd693x_init_platform_hw(void)\r
369 {\r
370     if(gpio_request(byd6932_pdata->rst_pin,NULL) != 0){\r
371       gpio_free(byd6932_pdata->rst_pin);\r
372       printk("byd693x_init_platform_hw gpio_request error\n");\r
373       return -EIO;\r
374     }\r
375 \r
376     if(gpio_request(byd6932_pdata->int_pin, NULL) != 0){\r
377       gpio_free(byd6932_pdata->int_pin);\r
378       printk("byd693x_init_platform_hw gpio_request error\n");\r
379       return -EIO;\r
380     }\r
381     gpio_pull_updown(byd6932_pdata->int_pin, 1);\r
382     gpio_direction_output(byd6932_pdata->rst_pin, 1);\r
383     return 0;\r
384 }\r
385 \r
386 \r
387 static int byd693x_ts_probe(struct i2c_client *client,const struct i2c_device_id *idp)\r
388 {\r
389         struct byd_ts_priv *byd_priv;\r
390         struct input_dev *byd_input = NULL;\r
391         struct byd_platform_data *pdata = client->dev.platform_data;\r
392         unsigned char tp_buf[1];\r
393         int error = -1;\r
394 #ifdef CONFIG_RK_CONFIG\r
395         struct port_config rst_cfg = get_port_config(rst);\r
396         struct port_config irq_cfg = get_port_config(irq);\r
397 \r
398         if(!pdata){\r
399                 pdata = kzalloc(sizeof(struct byd_platform_data), GFP_KERNEL);\r
400                 if(!pdata){\r
401                         printk("byd693x_ts_probe: kzalloc Error!\n");\r
402                         return -ENOMEM;\r
403                 };\r
404         }\r
405         pdata->rst_pin = rst_cfg.gpio;\r
406         pdata->int_pin = irq_cfg.gpio;\r
407         pdata->screen_max_x = x_max;\r
408         pdata->screen_max_y = y_max;\r
409 #endif\r
410 \r
411 \r
412         byd6932_pdata = pdata;\r
413         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
414                 printk("+-----------------------------------------+\n");\r
415                 printk("|       byd693x_ts_probe!                 |\n");\r
416                 printk("+-----------------------------------------+\n");\r
417         #endif\r
418         \r
419         if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))\r
420         {\r
421                 #ifdef CONFIG_TS_PROBE_DEBUG\r
422                         printk("                byd693x_ts_probe: need I2C_FUNC_I2C\n");\r
423                 #endif\r
424                 return -ENODEV;\r
425         }\r
426         else\r
427         {\r
428                 #ifdef CONFIG_TS_PROBE_DEBUG\r
429                         printk("                byd693x_ts_probe: i2c Check OK!\n");\r
430                         printk("                byd693x_ts_probe: i2c_client name : %s\n",client->name);\r
431                 #endif\r
432         }\r
433 \r
434         byd_priv = kzalloc(sizeof(*byd_priv), GFP_KERNEL);\r
435         if (!byd_priv)\r
436         {\r
437                 #ifdef CONFIG_TS_PROBE_DEBUG\r
438                         printk("                byd693x_ts_probe: kzalloc Error!\n");\r
439                 #endif\r
440                 error=-ENODEV;\r
441                 goto    err0;\r
442         }\r
443         else\r
444         {\r
445                 #ifdef CONFIG_TS_PROBE_DEBUG\r
446                         printk("                byd693x_ts_probe: kzalloc OK!\n");\r
447                 #endif\r
448         }\r
449 \r
450 \r
451 \r
452         dev_set_drvdata(&client->dev, byd_priv);\r
453         byd_input = input_allocate_device();\r
454         if (!byd_input)\r
455         {\r
456                 #ifdef CONFIG_TS_PROBE_DEBUG\r
457                         printk("                byd693x_ts_probe: input_allocate_device Error\n");\r
458                 #endif\r
459                 error=-ENODEV;\r
460                 goto    err1;\r
461         }\r
462         else\r
463         {\r
464                 #ifdef CONFIG_TS_PROBE_DEBUG\r
465                         printk("                byd693x_ts_probe: input_allocate_device OK\n");\r
466                 #endif\r
467         }\r
468 \r
469         //only check BYD BF6932\r
470         error = ReadRegister(client, BYD_COORD_READ_ADDR, tp_buf, sizeof(tp_buf));\r
471         if (error <= 0)\r
472         {\r
473                 printk(KERN_ALERT "BYD BF6932 Touchscreen not found \n");\r
474                 gpio_free(pdata->rst_pin);\r
475                 gpio_free(pdata->int_pin);\r
476                 goto err1;\r
477         }\r
478 \r
479 //      byd_input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | BIT_MASK(EV_SYN)|BIT_MASK(EV_REP) ;\r
480 //      byd_input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH) | BIT_MASK(BTN_2);\r
481         byd_input->name = client->name;\r
482         byd_input->id.bustype = BUS_I2C;\r
483         byd_input->id.vendor  = 0x2878; // Modify for Vendor ID\r
484         byd_input->dev.parent = &client->dev;\r
485 //      byd_input->open = byd693x_ts_open;\r
486 //      byd_input->close = byd693x_ts_close;\r
487         input_set_drvdata(byd_input, byd_priv);\r
488         byd_priv->client = client;\r
489         byd_priv->input = byd_input;\r
490         byd_priv->irq = pdata->int_pin;\r
491         byd_priv->FingerNo=FINGER_NO_MAX;\r
492 \r
493         byd_input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);\r
494         byd_input->absbit[0] = BIT(ABS_X) | BIT(ABS_Y); // for android\r
495 \r
496         __set_bit(EV_ABS, byd_input->evbit);\r
497         __set_bit(INPUT_PROP_DIRECT, byd_input->propbit);\r
498         set_bit(ABS_MT_POSITION_X, byd_input->absbit);\r
499         set_bit(ABS_MT_POSITION_Y, byd_input->absbit);\r
500         set_bit(ABS_MT_TOUCH_MAJOR, byd_input->absbit);\r
501         set_bit(ABS_MT_WIDTH_MAJOR, byd_input->absbit);\r
502 \r
503 //      deviceReset(client);\r
504 //      printk("BYD Touchscreen I2C Address: 0x%02X\n",client->addr);\r
505 //      printk("BYD Touchscreen Device ID  : BF6932\n");\r
506         \r
507         //config the resolution of CTP\r
508         byd693xcfg_Resolution[RESO_X_NO].Data1 = (char)(pdata->screen_max_x >>8);\r
509         byd693xcfg_Resolution[RESO_X_NO].Data2 = (char)(pdata->screen_max_x & 0xff);\r
510         \r
511         byd693xcfg_Resolution[RESO_Y_NO].Data1 = (char)(pdata->screen_max_y >>8);\r
512         byd693xcfg_Resolution[RESO_Y_NO].Data2 = (char)(pdata->screen_max_y & 0xff);\r
513         \r
514         byd693xdeviceInit(client);\r
515  \r
516         input_mt_init_slots(byd_input, MAX_TRACKID_ITEM);\r
517 \r
518 \r
519         input_set_abs_params(byd_input, ABS_MT_TOUCH_MAJOR, 0, MAX_TOUCH_MAJOR, 0, 0);\r
520         input_set_abs_params(byd_input, ABS_MT_WIDTH_MAJOR, 0, MAX_WIDTH_MAJOR, 0, 0);\r
521         input_set_abs_params(byd_input, ABS_MT_POSITION_X,  0,pdata->screen_max_x + 1, 0, 0);\r
522         input_set_abs_params(byd_input, ABS_MT_POSITION_Y,  0,pdata->screen_max_y + 1, 0, 0);\r
523 \r
524 #ifdef USE_TOUCH_KEY\r
525         set_bit(KEY_MENU, byd_input->keybit);\r
526         set_bit(KEY_HOME, byd_input->keybit);\r
527         set_bit(KEY_BACK, byd_input->keybit);\r
528         set_bit(KEY_SEARCH, byd_input->keybit);\r
529 #endif\r
530         \r
531         INIT_WORK(&byd_priv->byd_work, byd693x_ts_work);\r
532 \r
533         error = input_register_device(byd_input);\r
534 \r
535         if(error)\r
536         {\r
537                 #ifdef CONFIG_TS_PROBE_DEBUG\r
538                         printk("                byd693x_ts_probe: input_register_device input Error!\n");\r
539                 #endif\r
540                 error=-ENODEV;\r
541                 goto    err1;\r
542         }\r
543         else\r
544         {\r
545                 #ifdef CONFIG_TS_PROBE_DEBUG\r
546                         printk("                byd693x_ts_probe: input_register_device input OK!\n");\r
547                 #endif\r
548         }\r
549 \r
550                 error = byd693x_init_platform_hw();             //Init RK29 GPIO\r
551                 if(0 != error)\r
552                 {\r
553                         printk("%s:Init_INT set_irq_mode err. \n", __func__);\r
554                         goto exit_set_irq_mode;\r
555                 }\r
556                 // Options for different interrupt system \r
557 //              error = request_irq(byd_priv->irq, byd693x_ts_isr, IRQF_DISABLED|IRQF_TRIGGER_FALLING, client->name,byd_priv);\r
558 //              error = request_irq(byd_priv->irq, byd693x_ts_isr, IRQF_TRIGGER_FALLING, client->name,byd_priv);\r
559                 error = request_irq(byd_priv->irq, byd693x_ts_isr, IRQF_TRIGGER_FALLING, client->name,byd_priv);\r
560                 if(error)\r
561                 {\r
562                 #ifdef CONFIG_TS_PROBE_DEBUG\r
563                         printk("                byd693x_ts_probe: request_irq Error!\n");\r
564                 #endif\r
565                         error=-ENODEV;\r
566                         goto err2;\r
567                 }\r
568                 else\r
569                 {\r
570                 #ifdef CONFIG_TS_PROBE_DEBUG\r
571                         printk("                byd693x_ts_probe: request_irq OK!\n");\r
572                         #endif\r
573                 }       \r
574 \r
575         printk("Install BYD BF6932 Touchscreen driver successfully\n");\r
576         \r
577 #ifdef  CONFIG_HAS_EARLYSUSPEND\r
578         byd_priv->early_suspend.suspend = byd693x_ts_early_suspend;\r
579         byd_priv->early_suspend.resume  = byd693x_ts_late_resume;\r
580         byd_priv->early_suspend.level   = EARLY_SUSPEND_LEVEL_DISABLE_FB+1;\r
581         register_early_suspend(&byd_priv->early_suspend);\r
582 #endif \r
583         return 0;\r
584 exit_set_irq_mode:\r
585 err2:   input_unregister_device(byd_input);     \r
586 err1:   input_free_device(byd_input);\r
587         kfree(byd_priv);\r
588 //exit_gpio_wakeup_request_failed:      \r
589 err0:   dev_set_drvdata(&client->dev, NULL);\r
590         return error;\r
591 }\r
592 \r
593 /*\r
594 static int byd693x_ts_open(struct input_dev *dev)\r
595 {\r
596         struct byd_ts_priv *byd_priv = input_get_drvdata(dev);\r
597         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
598         printk("+-----------------------------------------+\n");\r
599         printk("|       byd693x_ts_open!                  |\n");\r
600         printk("+-----------------------------------------+\n");\r
601         #endif  \r
602         deviceResume(byd_priv->client);\r
603         enable_irq(byd_priv->irq);\r
604         byd_priv->suspend_opend = 0;\r
605         return 0;\r
606 }\r
607 \r
608 static void byd693x_ts_close(struct input_dev *dev)\r
609 {\r
610         struct byd_ts_priv *byd_priv = input_get_drvdata(dev);\r
611         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
612         printk("+-----------------------------------------+\n");\r
613         printk("|       byd693x_ts_close!                 |\n");\r
614         printk("+-----------------------------------------+\n");\r
615         #endif\r
616         deviceSuspend(byd_priv->client);        \r
617         byd_priv->suspend_opend = 1;\r
618         disable_irq(byd_priv->irq);\r
619 }\r
620 */\r
621 \r
622 static int byd693x_ts_resume(struct i2c_client *client)\r
623 {\r
624         struct byd_ts_priv *byd_priv = dev_get_drvdata(&client->dev);\r
625         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
626         printk("+-----------------------------------------+\n");\r
627         printk("|       byd693x_ts_resume!                |\n");\r
628         printk("+-----------------------------------------+\n");\r
629         #endif\r
630 \r
631         deviceResume(client);\r
632         byd_priv->suspend_opend = 0;            \r
633         enable_irq(byd_priv->irq);\r
634         return 0;\r
635 }\r
636 \r
637 static int byd693x_ts_suspend(struct i2c_client *client, pm_message_t mesg)\r
638 {\r
639         struct byd_ts_priv *byd_priv = dev_get_drvdata(&client->dev);\r
640         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
641         printk("+-----------------------------------------+\n");\r
642         printk("|       byd693x_ts_suspend!               |\n");\r
643         printk("+-----------------------------------------+\n");\r
644         #endif\r
645         byd_priv->suspend_opend = 1;\r
646 \r
647         disable_irq(byd_priv->irq);\r
648         deviceSuspend(client);\r
649         return 0;\r
650 }\r
651 \r
652 #ifdef  CONFIG_HAS_EARLYSUSPEND\r
653 static void byd693x_ts_late_resume(struct early_suspend *h)\r
654 {\r
655         struct byd_ts_priv *byd_priv = container_of(h, struct byd_ts_priv, early_suspend);\r
656         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
657         printk("+-----------------------------------------+\n");\r
658         printk("|       byd693x_ts_late_resume!           |\n");\r
659         printk("+-----------------------------------------+\n");\r
660         #endif\r
661         byd693x_ts_resume(byd_priv->client);\r
662 }\r
663 static void byd693x_ts_early_suspend(struct early_suspend *h)\r
664 {\r
665         struct byd_ts_priv *byd_priv = container_of(h, struct byd_ts_priv, early_suspend);\r
666         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
667         printk("+-----------------------------------------+\n");\r
668         printk("|       byd693x_ts_early_suspend!         |\n");\r
669         printk("+-----------------------------------------+\n");\r
670         #endif\r
671         byd693x_ts_suspend(byd_priv->client, PMSG_SUSPEND);\r
672 }\r
673 #endif\r
674 \r
675 static int byd693x_ts_remove(struct i2c_client *client)\r
676 {\r
677         struct byd_ts_priv *byd_priv = dev_get_drvdata(&client->dev);\r
678         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
679         printk("+-----------------------------------------+\n");\r
680         printk("|       byd693x_ts_remove !               |\n");\r
681         printk("+-----------------------------------------+\n");\r
682         #endif\r
683         free_irq(byd_priv->irq, byd_priv);\r
684         input_unregister_device(byd_priv->input);\r
685         input_free_device(byd_priv->input);\r
686         kfree(byd_priv);\r
687         dev_set_drvdata(&client->dev, NULL);\r
688         return 0;\r
689 }\r
690 \r
691 static irqreturn_t byd693x_ts_isr(int irq, void *dev_id)\r
692 {\r
693         struct byd_ts_priv *byd_priv = dev_id;\r
694         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
695         printk("+-----------------------------------------+\n");\r
696         printk("|       byd693x_ts_isr!                   |\n");\r
697         printk("+-----------------------------------------+\n");\r
698         #endif  \r
699         disable_irq_nosync(byd_priv->irq);\r
700         queue_work(byd693x_wq, &byd_priv->byd_work);\r
701         enable_irq(byd_priv->irq);\r
702         return IRQ_HANDLED;\r
703 }\r
704 \r
705 static const struct i2c_device_id byd693x_ts_id[] = {\r
706         { CTP_NAME, 0 },\r
707         { }\r
708 };\r
709 \r
710 MODULE_DEVICE_TABLE(i2c, byd693x_ts_id);\r
711 \r
712 static struct i2c_driver byd693x_ts_driver = {\r
713         .driver = {\r
714                 .name = CTP_NAME,\r
715         },\r
716         .probe = byd693x_ts_probe,\r
717         .remove = byd693x_ts_remove,\r
718 #ifndef CONFIG_HAS_EARLYSUSPEND\r
719         .suspend = byd693x_ts_suspend,\r
720         .resume = byd693x_ts_resume,\r
721 #endif\r
722         .id_table = byd693x_ts_id,\r
723 };\r
724 \r
725 static char banner[] __initdata = KERN_INFO "BYD Touchscreen driver, (c) 2012 BYD Systech Ltd.\n";\r
726 static int __init byd693x_ts_init(void)\r
727 {\r
728         int ret;\r
729 \r
730 #ifdef CONFIG_RK_CONFIG\r
731         ret = tp_board_init();\r
732 \r
733         if(ret < 0)\r
734                 return ret;\r
735 #endif\r
736         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
737         printk("+-----------------------------------------+\n");\r
738         printk("|       byd_ts_init!                      |\n");\r
739         printk("+-----------------------------------------+\n");\r
740         #endif\r
741         printk(banner);\r
742         printk("==================byd693x_ts_init===========================\n");\r
743         printk("Version =%s\n",VERSION);\r
744         byd693x_wq = create_singlethread_workqueue("byd693x_wq");\r
745         if (!byd693x_wq)\r
746         {\r
747                 #ifdef CONFIG_TS_WORKQUEUE_DEBUG\r
748                 printk("                byd693x_ts_init: create_singlethread_workqueue Error!\n");\r
749                 #endif\r
750                 return -ENOMEM;\r
751         }\r
752         else\r
753         {\r
754                 #ifdef CONFIG_TS_WORKQUEUE_DEBUG\r
755                 printk("                byd693x_ts_init: create_singlethread_workqueue OK!\n");\r
756                 #endif\r
757         }\r
758         ret=i2c_add_driver(&byd693x_ts_driver);\r
759         #ifdef CONFIG_TS_I2C_TRANSFER_DEBUG\r
760         if(ret) printk("                byd693x_ts_init: i2c_add_driver Error! \n");\r
761         else    printk("                byd693x_ts_init: i2c_add_driver OK! \n");\r
762         #endif\r
763         return ret;\r
764 }\r
765 \r
766 static void __exit byd693x_ts_exit(void)\r
767 {\r
768         #ifdef CONFIG_TS_FUNCTION_CALLED_DEBUG\r
769         printk("+-----------------------------------------+\n");\r
770         printk("|       byd693x_ts_exit!                  |\n");\r
771         printk("+-----------------------------------------+\n");\r
772         #endif\r
773         i2c_del_driver(&byd693x_ts_driver);\r
774         if (byd693x_wq) destroy_workqueue(byd693x_wq);\r
775 }\r
776 \r
777 module_init(byd693x_ts_init);\r
778 module_exit(byd693x_ts_exit);\r
779 \r
780 MODULE_AUTHOR("BYD Systech Ltd - Raysens Design Technology, Charles Chen.");\r
781 MODULE_LICENSE("GPL v2");\r
782 MODULE_DESCRIPTION("byd693x Touchscreen Driver 1.2_Charles@Raysens@20120731");\r