2 * drivers/input/touchscreen/gt801_ts.c
4 * Copyright (C) 2010 ROCKCHIP, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/earlysuspend.h>
19 #include <linux/hrtimer.h>
20 #include <linux/i2c.h>
21 #include <linux/input.h>
22 #include <linux/interrupt.h>
24 #include <linux/gpio.h>
25 #include <mach/iomux.h>
26 #include <mach/board.h>
27 #include <linux/platform_device.h>
28 #include <linux/async.h>
29 #include <linux/workqueue.h>
30 #include <linux/slab.h>
31 #include <linux/input/mt.h>
32 #include <asm/mach/time.h>
33 #include "ct360_calib.h"
37 #define MYCT360_DEBUG 0
40 #define ct360printk(msg...) printk(msg);
42 #define ct360printk(msg...)
46 #define yj_printk(msg...) printk(msg);
48 #define yj_printk(msg...)
52 #define boot_printk(msg...) printk(msg);
54 #define boot_printk(msg...)
59 #define myct360printk(msg...) printk(msg);
61 #define myct360printk(msg...)
64 static int touch_flag_up=0;
65 static int touch_flag_down = 0;
67 static int last_num_point=1;
69 static int last_x[2]={0,0};
70 static int last_y[2]={0,0};
72 #define ct360_TS_NAME "ct360_ts"
73 #define TOUCH_NUMBER 5
74 #define TOUCH_REG_NUM 4
75 #define IOMUX_NAME_SIZE 48
78 ptxh = 0, ptxl = 1, ptyh = 2, ptyl = 3, ptpressure = 4,
81 TOUCH_UP = 0, TOUCH_DOWN = 1,
86 const unsigned char GT801_RegData[]={
87 0x0F,0x02,0x04,0x28,0x02,0x14,0x14,0x10,0x28,0xFA,0x03,0x20,0x05,0x00,0x01,
88 0x23,0x45,0x67,0x89,0xAB,0xCD,0xE1,0x00,0x00,0x35,0x2E,0x4D,0xC1,0x20,0x05,
89 0x00,0x80,0x50,0x3C,0x1E,0xB4,0x00,0x33,0x2C,0x01,0xEC,0x00,0x32,0x00,0x00,
90 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
93 /*tochscreen private data*/
94 static int touch_state[TOUCH_NUMBER] = {TOUCH_UP,TOUCH_UP};
95 struct ct360_ts_data *ct360;
96 #ifdef CONFIG_HAS_EARLYSUSPEND
97 static void ct360_ts_early_suspend(struct early_suspend *h);
98 static void ct360_ts_late_resume(struct early_suspend *h);
102 static int ct360_read_regs(struct i2c_client *client, u8 buf[], unsigned len)
105 ret = i2c_master_normal_recv(client, buf, len, 400*1000);
107 printk("ct360_ts_work_func:i2c_transfer fail =%d\n",ret);
110 /* set the ct360 registe,used i2c bus*/
111 static int ct360_write_regs(struct i2c_client *client, u8 const buf[], unsigned short len)
114 ret = i2c_master_normal_send(client, buf, len, 100*1000);
116 printk("ct360_ts_work_func:i2c_transfer fail =%d\n",ret);
121 extern char Binary_Data[16384];
124 #define CT36X_TS_I2C_SPEED 300*1000
126 static void ct36x_ts_reg_read(struct i2c_client *client, unsigned short addr, char *buf, int len, int rate)
131 msgs.flags = 0x01; // 0x00: write 0x01:read
134 msgs.scl_rate = rate;
135 i2c_transfer(client->adapter, &msgs, 1);
138 static void ct36x_ts_reg_write(struct i2c_client *client, unsigned short addr, char *buf, int len, int rate)
143 msgs.flags = 0x00; // 0x00: write 0x01:read
146 msgs.scl_rate = rate;
147 i2c_transfer(client->adapter, &msgs, 1);
151 int CT360_CTP_BootLoader(struct ct360_ts_data *ts)
154 unsigned int ver_chk_cnt = 0;
155 unsigned int flash_addr = 0;
156 unsigned char CheckSum[16];
158 //------------------------------
159 // Step1 --> initial BootLoader
160 // Note. 0x7F -> 0x00 -> 0xA5 ;
162 //------------------------------
163 printk("%s() Set mcu to idle \n", __FUNCTION__);
164 ts->data.buf[0] = 0x00;
165 ts->data.buf[1] = 0xA5;
166 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 2, CT36X_TS_I2C_SPEED);
169 //------------------------------
170 // Reset I2C Offset address
171 // Note. 0x7F -> 0x00
172 //------------------------------
173 printk(&"%s() Reset i2c offset address \n", __FUNCTION__);
174 ts->data.buf[0] = 0x00;
175 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 1, CT36X_TS_I2C_SPEED);
178 //------------------------------
179 // Read I2C Bus status
180 //------------------------------
181 printk("%s() Read i2c bus status \n", __FUNCTION__);
182 ct36x_ts_reg_read(ts->client, 0x7F, ts->data.buf, 1, CT36X_TS_I2C_SPEED);
183 mdelay(10); // Delay 1 ms
185 // if return "AAH" then going next step
186 if (ts->data.buf[0] != 0xAA)
188 printk("%s() i2c bus status: 0x%x \n", __FUNCTION__, ts->data.buf[0]);
192 //------------------------------
193 // Check incomplete flash erase
194 //------------------------------
195 printk("%s() Flash erase verify \n", __FUNCTION__);
196 ts->data.buf[0] = 0x00;
197 ts->data.buf[1] = 0x99; // Generate check sum command -->read flash, set addr
198 ts->data.buf[2] = 0x00; // define a flash address for CT36x to generate check sum
199 ts->data.buf[3] = 0x00; //
200 ts->data.buf[4] = 0x08; // Define a data length for CT36x to generate check sum
202 // Write Genertate check sum command to CT36x
203 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 5, CT36X_TS_I2C_SPEED);
204 mdelay(10); // Delay 10 ms
206 ct36x_ts_reg_read(ts->client, 0x7F, ts->data.buf, 13, CT36X_TS_I2C_SPEED);
207 mdelay(10); // Delay 10 ms
209 CheckSum[0] = ts->data.buf[5];
210 CheckSum[1] = ts->data.buf[6];
212 ts->data.buf[0] = 0x00;
213 ts->data.buf[1] = 0x99; // Generate check sum command -->read flash, set addr
214 ts->data.buf[2] = 0x3F; // define a flash address for CT36x to generate check sum
215 ts->data.buf[3] = 0xE0; //
216 ts->data.buf[4] = 0x08; // Define a data length for CT36x to generate check sum
217 // Write Genertate check sum command to CT36x
218 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 5, CT36X_TS_I2C_SPEED);
219 mdelay(10); // Delay 10 ms
221 ct36x_ts_reg_read(ts->client, 0x7F, ts->data.buf, 13, CT36X_TS_I2C_SPEED);
224 CheckSum[2] = ts->data.buf[5];
225 CheckSum[3] = ts->data.buf[6];
227 if ( (CheckSum[0] ^ CheckSum[2]) == 0xFF && (CheckSum[1] ^ CheckSum[3]) == 0xFF )
230 //------------------------------
231 // check valid Vendor ID
232 //------------------------------
233 printk("%s() Vendor ID Check \n", __FUNCTION__);
234 ts->data.buf[0] = 0x00;
235 ts->data.buf[1] = 0x99; // Generate check sum command -->read flash, set addr
236 ts->data.buf[2] = 0x00; // define a flash address for CT365 to generate check sum
237 ts->data.buf[3] = 0x44; //
238 ts->data.buf[4] = 0x08; // Define a data length for CT365 to generate check sum
240 // Write Genertate check sum command to CT36x
241 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 5, CT36X_TS_I2C_SPEED);
242 mdelay(10); // Delay 10 ms
244 ct36x_ts_reg_read(ts->client, 0x7F, ts->data.buf, 13, CT36X_TS_I2C_SPEED);
245 mdelay(10); // Delay 10 ms
247 // Read check sum and flash data from CT36x
248 if ( (ts->data.buf[5] != 'V') || (ts->data.buf[9] != 'T') )
251 ts->data.buf[0] = 0x00;
252 ts->data.buf[1] = 0x99; // Generate check sum command -->read flash,set addr
253 ts->data.buf[2] = 0x00; // define a flash address for CT365 to generate check sum
254 ts->data.buf[3] = 0xA4; //
255 ts->data.buf[4] = 0x08; // Define a data length for CT365 to generate check sum
257 // Write Genertate check sum command to CT365
258 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 5, CT36X_TS_I2C_SPEED);
259 mdelay(10); // Delay 10 ms
261 ct36x_ts_reg_read(ts->client, 0x7F, ts->data.buf, 13, CT36X_TS_I2C_SPEED);
262 mdelay(10); // Delay 10 ms
264 if ((ts->data.buf[5] != 'V') || (ts->data.buf[9] != 'T'))
267 if ( ver_chk_cnt >= 2 ) {
268 printk("%s() Invalid FW Version \n", __FUNCTION__);
273 //-----------------------------------------------------
274 // Step 2 : Erase 32K flash memory via Mass Erase (33H)
275 // 0x7F --> 0x00 --> 0x33 --> 0x00;
276 //-----------------------------------------------------
277 printk("%s() Erase flash \n", __FUNCTION__);
278 for(i = 0; i < 8; i++ ) {
279 ts->data.buf[0] = 0x00; // Offset address
280 ts->data.buf[1] = 0x33; // Mass Erase command
281 ts->data.buf[2] = 0x00 + (i * 8);
282 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 3, CT36X_TS_I2C_SPEED);
283 mdelay(120); // Delay 10 mS
285 //------------------------------
286 // Reset I2C Offset address
287 // Note. 0x7F -> 0x00
288 //------------------------------
289 ts->data.buf[0] = 0x00;
290 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 1, CT36X_TS_I2C_SPEED);
291 mdelay(120); // Delay 10 mS
293 //------------------------------
294 // Read I2C Bus status
295 //------------------------------
296 ct36x_ts_reg_read(ts->client, 0x7F, ts->data.buf, 1, CT36X_TS_I2C_SPEED);
297 mdelay(10); // Delay 1 ms
299 // if return "AAH" then going next step
300 if( ts->data.buf[0] != 0xAA )
304 //----------------------------------------
305 // Step3. Host write 128 bytes to CT36x
306 // Step4. Host read checksum to verify ;
307 // Write/Read for 256 times ( 32k Bytes )
308 //----------------------------------------
309 printk("%s() flash FW \n", __FUNCTION__);
310 for ( flash_addr = 0; flash_addr < 0x3FFF; flash_addr+=8 ) {
311 // Step 3 : write binary data to CT36x
312 ts->data.buf[0] = 0x00; // Offset address
313 ts->data.buf[1] = 0x55; // Flash write command
314 ts->data.buf[2] = (char)(flash_addr >> 8); // Flash address [15:8]
315 ts->data.buf[3] = (char)(flash_addr & 0xFF); // Flash address [7:0]
316 ts->data.buf[4] = 0x08; // Data Length
318 if( flash_addr == 160 || flash_addr == 168 ) {
319 ts->data.buf[6] = ~Binary_Data[flash_addr + 0]; // Binary data 1
320 ts->data.buf[7] = ~Binary_Data[flash_addr + 1]; // Binary data 2
321 ts->data.buf[8] = ~Binary_Data[flash_addr + 2]; // Binary data 3
322 ts->data.buf[9] = ~Binary_Data[flash_addr + 3]; // Binary data 4
323 ts->data.buf[10] = ~Binary_Data[flash_addr + 4]; // Binary data 5
324 ts->data.buf[11] = ~Binary_Data[flash_addr + 5]; // Binary data 6
325 ts->data.buf[12] = ~Binary_Data[flash_addr + 6]; // Binary data 7
326 ts->data.buf[13] = ~Binary_Data[flash_addr + 7]; // Binary data 8
328 ts->data.buf[6] = Binary_Data[flash_addr + 0]; // Binary data 1
329 ts->data.buf[7] = Binary_Data[flash_addr + 1]; // Binary data 2
330 ts->data.buf[8] = Binary_Data[flash_addr + 2]; // Binary data 3
331 ts->data.buf[9] = Binary_Data[flash_addr + 3]; // Binary data 4
332 ts->data.buf[10] = Binary_Data[flash_addr + 4]; // Binary data 5
333 ts->data.buf[11] = Binary_Data[flash_addr + 5]; // Binary data 6
334 ts->data.buf[12] = Binary_Data[flash_addr + 6]; // Binary data 7
335 ts->data.buf[13] = Binary_Data[flash_addr + 7]; // Binary data 8
337 // Calculate a check sum by Host controller.
338 // Checksum = / (FLASH_ADRH+FLASH_ADRL+LENGTH+
339 // Binary_Data1+Binary_Data2+Binary_Data3+Binary_Data4+
340 // Binary_Data5+Binary_Data6+Binary_Data7+Binary_Data8) + 1
341 CheckSum[0] = ~(ts->data.buf[2] + ts->data.buf[3] + ts->data.buf[4] + ts->data.buf[6] + ts->data.buf[7] +
342 ts->data.buf[8] + ts->data.buf[9] + ts->data.buf[10] + ts->data.buf[11] + ts->data.buf[12] +
343 ts->data.buf[13]) + 1;
345 ts->data.buf[5] = CheckSum[0]; // Load check sum to I2C Buffer
347 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 14, CT36X_TS_I2C_SPEED); // Host write I2C_Buf[0?K12] to CT365.
348 mdelay(1); // 8 Bytes program --> Need 1 ms delay time
350 // Step4. Verify process
351 printk("%s(flash_addr:0x%04x) Verify FW \n", __FUNCTION__, flash_addr);
352 //Step 4 : Force CT365 generate check sum for host to compare data.
353 //Prepare get check sum from CT36x
354 ts->data.buf[0] = 0x00;
355 ts->data.buf[1] = 0x99; // Generate check sum command
356 ts->data.buf[2] = (char)(flash_addr >> 8); // define a flash address for NT1100x to generate check sum
357 ts->data.buf[3] = (char)(flash_addr & 0xFF); //
358 ts->data.buf[4] = 0x08; // Define a data length for CT36x to generate check sum
360 ct36x_ts_reg_write(ts->client, 0x7F, ts->data.buf, 5, CT36X_TS_I2C_SPEED); // Write Genertate check sum command to CT365
361 mdelay(1); // Delay 1 ms
363 ct36x_ts_reg_read(ts->client, 0x7F, ts->data.buf, 13, CT36X_TS_I2C_SPEED); // Read check sum and flash data from CT365
365 // Compare host check sum with CT365 check sum(I2C_Buf[4])
366 if ( ts->data.buf[4] != CheckSum[0] ) {
375 /*read the ct360 register ,used i2c bus*/
377 static int ct360_init_panel(struct ct360_ts_data *ts)
382 static void report_value(int x,int y,struct ct360_ts_data *ts)
384 myct360printk("%s(%d,%d)\n", __FUNCTION__,x, y);
385 //if((x>ts->x_max)||(y>ts->y_max))
387 myct360printk("x=%d,y=%d,swap=%d\n",x,y,ts->swap_xy);
393 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1); //Finger Size
394 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
395 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
396 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 1); //Touch Size
397 input_mt_sync(ts->input_dev);
401 static void ct360_ts_work_func(struct work_struct *work)
403 //struct timespec now;
404 //now = current_kernel_time();//(&now);
405 //printk("now %lu:%lu\n",now.tv_sec,now.tv_nsec);
407 unsigned short x = 0;
408 unsigned short y = 0;
409 int i,ret,syn_flag = 0;
412 unsigned char buf[TOUCH_REG_NUM*TOUCH_NUMBER+1] = {0};
415 int touch_state_index=0;
417 struct ct360_ts_data *ts = container_of(work, struct ct360_ts_data, work);
418 //printk("before read the gpio_get_value(ts->client->irq) is %d\n",gpio_get_value(ts->client->irq));
420 ret= ct360_read_regs(ts->client, buf, TOUCH_REG_NUM*TOUCH_NUMBER);//only one data represent the current touch num
422 printk("%s:i2c_transfer fail =%d\n", __FUNCTION__, toatl_num);
423 //enable_irq(ts->irq);
427 for (i = 0; i < 20; i += TOUCH_REG_NUM)
429 point_status = buf[i] & 0x0F;
430 point_id = buf[i] >> 4;
431 //printk("point_status:0x%02x, point_id:0x%02x i = %d\n", point_status, point_id, i);
432 //printk("buf: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", buf[i], buf[i+1], buf[i+2], buf[i+3]);
433 //if (point_status != 0)
436 if((point_status == 1) || (point_status == 2)) {
437 x = (((s16)buf[i+1] << 4)|((s16)buf[i+3] >> 4));
438 y = (((s16)buf[i+2] << 4)|((s16)buf[i+3] & 0x0f));
439 //printk("x=%d,y=%d\n",x,y);
441 input_mt_slot(ts->input_dev, point_id);
442 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
443 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, point_id);
444 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 100); //Finger Size
445 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
446 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
447 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 100); //Touch Size
450 // touch_state[touch_state_index] = TOUCH_DOWN;
451 //printk("TOUCH_DOWN\n");
452 // last_x[touch_state_index]=x;
453 // last_y[touch_state_index]=y;
456 } else if(point_status == 3 || point_status == 0) {
457 //if(touch_state[touch_state_index] == TOUCH_DOWN){
458 //ct360printk("%s:%d touch up\n",__FUNCTION__,i);
459 input_mt_slot(ts->input_dev, point_id);
460 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);
461 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
463 touch_state[touch_state_index] = TOUCH_UP;
464 //printk("TOUCH_UP:%d\n", point_id);
470 input_sync(ts->input_dev);
473 //printk("the gpio_get_value(ts->client->irq) is %d\n",gpio_get_value(ts->client->irq));
476 // queue_delayed_work(ts->ct360_wq, &ts->work, msecs_to_jiffies(15));
480 // enable_irq(ts->irq);
485 static irqreturn_t ct360_ts_irq_handler(int irq, void *dev_id)
487 struct ct360_ts_data *ts = dev_id;
488 //printk("the ts->irq is %d ts->client->addr=%d\n",gpio_get_value(ts->irq),ts->client->addr);
489 // disable_irq_nosync(ts->irq);
491 queue_work(ts->ct360_wq, &ts->work);
496 static int ct360_chip_Init(struct i2c_client *client)
500 unsigned char status;
501 printk("enter ct360_chip_Init!!!!\n");
505 ret = i2c_master_reg8_send(client, start_reg, buf0, 1, 200*1000);
509 ret = i2c_master_reg8_send(client, start_reg, buf1, 1, 200*1000);
512 printk("\n--%s--Set Register values error !!!\n",__FUNCTION__);
514 i2c_master_reg8_recv(client,start_reg,&status,1,200*1000);
515 printk("the status is %x",status);
518 printk("the status11 is %x",status);
524 static int ct360_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
526 struct ct360_ts_data *ts;
527 struct ct360_platform_data *pdata = client->dev.platform_data;
529 char loader_buf[3] = {0xfF,0x0f,0x2A};
531 char boot_loader[2] = {0};
533 ct360printk("%s \n",__FUNCTION__);
536 dev_err(&client->dev, "empty platform_data\n");
537 goto err_check_functionality_failed;
539 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
540 printk(KERN_ERR "ct360_ts_probe: need I2C_FUNC_I2C\n");
542 goto err_check_functionality_failed;
545 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
548 goto err_alloc_data_failed;
551 ts->ct360_wq = create_singlethread_workqueue("ct360_wq");
553 printk(KERN_ERR"%s: create workqueue failed\n", __func__);
555 goto err_input_dev_alloc_failed;
558 INIT_WORK(&ts->work, ct360_ts_work_func);
560 i2c_set_clientdata(client, ts);
577 ret=ct360_write_regs(client,loader_buf, 3);
579 printk("\n--%s--Set Register values error !!!\n",__FUNCTION__);
583 printk("%s...........%d\n",__FUNCTION__,boot_buf);
584 ret = i2c_master_normal_send(client,boot_loader,1,100*1000);
586 printk("ct360_ts_probe:sdf i2c_transfer fail =%d\n",ret);
588 printk("%s.............ok\n",__FUNCTION__);
591 ret = ct360_read_regs(client,&boot_buf,1);
592 printk("%s....3......%x\n",__FUNCTION__,boot_buf);
595 printk("ct360_ts_probe:i2c_transfer fail =%d\n",ret);
597 printk("%s.............boot_buf=%d\n",__FUNCTION__,boot_buf);
599 if ((Binary_Data[16372] - boot_buf) >= 1)
601 printk("start Bootloader ...........boot_Buf=%x.....%d......%x..........TP \n\n",boot_buf,(Binary_Data[16372]-boot_buf),Binary_Data[16372]);
602 ret = CT360_CTP_BootLoader(ts);
604 printk("TP Bootloader success\n");
606 printk("TP Bootloader failed ret=%d\n",ret);
607 printk("stop Bootloader.................................TP \n\n");
611 printk("Don't need bootloader.skip it %x \n",Binary_Data[16372]);
614 ts->client->addr = 0x01;
624 ts->client->addr = 0x01;
625 //ret=ct360_chip_Init(ts->client);
628 // printk("%s:chips init failed\n",__FUNCTION__);
629 // goto err_input_dev_alloc_failed;
634 /* allocate input device */
635 ts->input_dev = input_allocate_device();
636 if (ts->input_dev == NULL) {
638 printk(KERN_ERR "%s: Failed to allocate input device\n",__FUNCTION__);
639 goto err_input_dev_alloc_failed;
642 ts->x_max = pdata->x_max;
643 ts->y_max = pdata->y_max;
645 ts->input_dev->name = ct360_TS_NAME;
646 ts->input_dev->dev.parent = &client->dev;
648 __set_bit(EV_ABS, ts->input_dev->evbit);
649 __set_bit(EV_KEY, ts->input_dev->evbit);
650 __set_bit(EV_REP, ts->input_dev->evbit);
651 __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
652 set_bit(ABS_MT_POSITION_X, ts->input_dev->absbit);
653 set_bit(ABS_MT_POSITION_Y, ts->input_dev->absbit);
654 set_bit(ABS_MT_TOUCH_MAJOR, ts->input_dev->absbit);
655 set_bit(ABS_MT_WIDTH_MAJOR, ts->input_dev->absbit);
657 input_mt_init_slots(ts->input_dev, 5);
658 input_set_abs_params(ts->input_dev,ABS_MT_POSITION_X, 0, ts->x_max, 0, 0);
659 input_set_abs_params(ts->input_dev,ABS_MT_POSITION_Y, 0, ts->y_max, 0, 0);
660 input_set_abs_params(ts->input_dev,ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
661 input_set_abs_params(ts->input_dev,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
663 ret = input_register_device(ts->input_dev);
665 printk(KERN_ERR "%s: Unable to register %s input device\n", __FUNCTION__,ts->input_dev->name);
666 goto err_input_register_device_failed;
669 ts->irq = gpio_to_irq(client->irq);
670 ret = request_irq(ts->irq, ct360_ts_irq_handler, IRQF_TRIGGER_FALLING, client->name, ts);
672 printk("!!! ct360 request_irq failed\n");
673 goto err_input_register_device_failed;
676 #ifdef CONFIG_HAS_EARLYSUSPEND
677 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
678 ts->early_suspend.suspend = ct360_ts_early_suspend;
679 ts->early_suspend.resume = ct360_ts_late_resume;
680 register_early_suspend(&ts->early_suspend);
682 printk(KERN_INFO "%s: probe ok ts->client->addr=%d!!\n", __FUNCTION__,ts->client->addr);
686 err_input_register_device_failed:
687 input_free_device(ts->input_dev);
688 err_input_dev_alloc_failed:
690 err_alloc_data_failed:
691 err_check_functionality_failed:
696 static int ct360_ts_remove(struct i2c_client *client)
698 struct ct360_ts_data *ts = i2c_get_clientdata(client);
699 unregister_early_suspend(&ts->early_suspend);
700 free_irq(ts->irq, ts);
701 input_unregister_device(ts->input_dev);
703 destroy_workqueue(ts->ct360_wq);
709 static int ct360_ts_suspend(struct i2c_client *client, pm_message_t mesg)
711 struct ct360_ts_data *ts = i2c_get_clientdata(client);
712 struct ct360_platform_data *pdata = client->dev.platform_data;
714 printk("ct360 TS Suspend\n");
715 //if(pdata->shutdown)
716 // pdata->shutdown(1);
718 disable_irq(ts->irq);
719 cancel_work_sync(&ts->work);
721 char buf[3] = {0xff,0x0f,0x2b};
722 char buf1[2]={0x00,0x00};
725 ret = i2c_master_normal_send(client,buf,3,100*1000);
728 printk("ct360_ts supend fail!\n");
732 ret = i2c_master_normal_send(client,buf1,2,100*1000);
735 printk("ct360_ts supend fail!!!\n");
738 //printk("the buf1 is %x\n",buf[0]);
739 //gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
744 static int ct360_ts_resume(struct i2c_client *client)
746 struct ct360_ts_data *ts = i2c_get_clientdata(client);
747 struct ct360_platform_data *pdata = client->dev.platform_data;
748 // if(pdata->shutdown)
749 // pdata->shutdown(0);
751 //ct360_init_panel(ts);
753 printk("ct360 TS Resume\n");
762 // gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
765 //printk("enabling IRQ %d\n", ts->irq);
771 #ifdef CONFIG_HAS_EARLYSUSPEND
772 static void ct360_ts_early_suspend(struct early_suspend *h)
775 struct ct360_ts_data *ts;
776 //printk("======%s======\n",__FUNCTION__);
777 ts = container_of(h, struct ct360_ts_data, early_suspend);
778 ct360_ts_suspend(ts->client, PMSG_SUSPEND);
782 static void ct360_ts_late_resume(struct early_suspend *h)
785 struct ct360_ts_data *ts;
786 ts = container_of(h, struct ct360_ts_data, early_suspend);
787 ct360_ts_resume(ts->client);
792 static const struct i2c_device_id ct360_ts_id[] = {
793 { ct360_TS_NAME, 0 },
797 static struct i2c_driver ct360_ts_driver = {
798 .probe = ct360_ts_probe,
799 .remove = ct360_ts_remove,
800 #ifndef CONFIG_HAS_EARLYSUSPEND
801 .suspend = ct360_ts_suspend,
802 .resume = ct360_ts_resume,
804 .id_table = ct360_ts_id,
806 .name = ct360_TS_NAME,
810 static int __devinit ct360_ts_init(void)
812 printk("%s\n",__FUNCTION__);
814 return i2c_add_driver(&ct360_ts_driver);
817 static void __exit ct360_ts_exit(void)
819 printk("%s\n",__FUNCTION__);
820 i2c_del_driver(&ct360_ts_driver);
823 late_initcall_sync(ct360_ts_init);
824 module_exit(ct360_ts_exit);
826 MODULE_DESCRIPTION("ct360 Touchscreen Driver");
827 MODULE_LICENSE("GPL");