xref: /OK3568_Linux_fs/kernel/drivers/input/touchscreen/vtl_ts/vtl_ts.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * VTL CTP driver
3  *
4  * Copyright (C) 2013 VTL Corporation.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  */
21 
22 #include <linux/kernel.h>
23 #include <linux/timer.h>
24 #include <linux/types.h>
25 #include <linux/module.h>
26 #include <linux/version.h>
27 #include <linux/fs.h>
28 #include <linux/proc_fs.h>
29 #include <linux/uaccess.h>
30 #include <linux/i2c.h>
31 #include <linux/delay.h>
32 #include <linux/interrupt.h>
33 #include <linux/input.h>
34 #include <linux/input/mt.h>
35 #include <linux/gpio.h>
36 #include <linux/sched.h>
37 #include <linux/kthread.h>
38 #include <linux/of_gpio.h>
39 #include <linux/vmalloc.h>
40 
41 
42 #include "vtl_ts.h"
43 #include "chip.h"
44 #include "apk.h"
45 #include "tp_fw.h"
46 
47 
48 #define		TS_THREAD_PRIO		90
49 static DECLARE_WAIT_QUEUE_HEAD(waiter);
50 //static struct task_struct *ts_thread = NULL;
51 static unsigned char thread_syn_flag =0;
52 
53 
54 // ****************************************************************************
55 // Globel or static variables
56 // ****************************************************************************
57 static struct ts_driver	g_driver;
58 static int vtl_first_init_flag = 1;
59 struct ts_info	g_ts = {
60 	.driver = &g_driver,
61 	.debug  = DEBUG_ENABLE,
62 };
63 struct ts_info	*pg_ts = &g_ts;
64 
65 static struct i2c_device_id vtl_ts_id[] = {
66 	{ DRIVER_NAME, 0 },
67 	{ }
68 };
69 MODULE_DEVICE_TABLE(i2c,vtl_ts_id);
70 
71 
72 /*
73 static struct i2c_board_info i2c_info[] = {
74 	{
75 		I2C_BOARD_INFO(DRIVER_NAME, 0x01),
76 		.platform_data = NULL,
77 	},
78 };
79 */
80 
81 
82 // ****************************************************************************
83 // Function declaration
84 // ****************************************************************************
85 unsigned char *gtpfw;
vtl_ts_config(struct ts_info * ts)86 static int vtl_ts_config(struct ts_info *ts)
87 {
88 	struct device *dev = &ts->driver->client->dev;
89 	//struct ts_config_info *ts_config_info;
90 	int err;
91 	struct device_node *np = dev->of_node;
92 	enum of_gpio_flags rst_flags;
93 	unsigned long irq_flags;
94 	int val;
95 	gtpfw = tp_fw;
96 
97 
98 	DEBUG();
99 	/* ts config */
100 	ts->config_info.touch_point_number = TOUCH_POINT_NUM;
101 	if(dev->platform_data !=NULL)
102 	{
103 		return -1;
104 	}
105 	else
106 	{
107 
108 		if (of_property_read_u32(np, "screen_max_x", &val)) {
109 			dev_err(&ts->driver->client->dev, "no screen_max_x defined\n");
110 			return -EINVAL;
111 		}
112 		ts->config_info.screen_max_x = val;
113 
114 		if (of_property_read_u32(np, "screen_max_y", &val)) {
115 			dev_err(&ts->driver->client->dev, "no screen_max_y defined\n");
116 			return -EINVAL;
117 		}
118 		ts->config_info.screen_max_y = val;
119 
120         if (of_property_read_u32(np, "xy_swap", &val)) {
121 			val = 0;
122         }
123         ts->config_info.xy_swap = val;
124 
125         if (of_property_read_u32(np, "x_reverse", &val)) {
126 			val = 0;
127         }
128         ts->config_info.x_reverse = val;
129 
130         if (of_property_read_u32(np, "y_reverse", &val)) {
131 			val = 0;
132         }
133         ts->config_info.y_reverse = val;
134 
135         if (of_property_read_u32(np, "x_mul", &val)) {
136 			val = 1;
137         }
138         ts->config_info.x_mul = val;
139 
140         if (of_property_read_u32(np, "y_mul", &val)) {
141 			val = 1;
142         }
143         ts->config_info.y_mul = val;
144 
145 
146 		if (of_property_read_u32(np, "bin_ver", &val)) {
147             val = 0;
148         }
149 		ts->config_info.bin_ver = val;
150 		printk("--->>> vtl_ts : xy_swap %d, x_reverse %d, y_reverse %d, x_mul %d, y_mul %d, bin_ver %d\n",
151 				ts->config_info.xy_swap,
152 				ts->config_info.x_reverse, ts->config_info.y_reverse,
153 				ts->config_info.x_mul, ts->config_info.y_mul,
154 				ts->config_info.bin_ver);
155 		printk("the screen_x is %d , screen_y is %d \n",ts->config_info.screen_max_x,ts->config_info.screen_max_y);
156 
157 		ts->config_info.irq_gpio_number = of_get_named_gpio_flags(np, "irq_gpio_number", 0, (enum of_gpio_flags *)&irq_flags);
158 		ts->config_info.rst_gpio_number = of_get_named_gpio_flags(np, "rst_gpio_number", 0, &rst_flags);
159 
160 	}
161 
162 	ts->config_info.irq_number = gpio_to_irq(ts->config_info.irq_gpio_number);/* IRQ config*/
163 
164 	err = gpio_request(ts->config_info.rst_gpio_number, "vtl_ts_rst");
165 	if ( err ) {
166 		return -EIO;
167 	}
168 	gpio_direction_output(ts->config_info.rst_gpio_number, 1);
169 	//gpio_set_value(ts->config_info.rst_gpio_number, 1);
170 
171 	return 0;
172 }
173 
174 
vtl_ts_get_object(void)175 struct ts_info	* vtl_ts_get_object(void)
176 {
177 	DEBUG();
178 
179 	return pg_ts;
180 }
181 #if 0
182 static void vtl_ts_free_gpio(void)
183 {
184 	struct ts_info *ts;
185 	ts =pg_ts;
186 	DEBUG();
187 
188 	gpio_free(ts->config_info.rst_gpio_number);
189 }
190 #endif
191 
vtl_ts_hw_reset(void)192 void vtl_ts_hw_reset(void)
193 {
194 	struct ts_info *ts;
195 	ts =pg_ts;
196 	DEBUG();
197 
198 	//gpio_set_value(ts->config_info.rst_gpio_number, 1);
199 	//msleep(10);
200 	gpio_set_value(ts->config_info.rst_gpio_number, 0);
201 	msleep(50);
202 	gpio_set_value(ts->config_info.rst_gpio_number, 1);
203 	//msleep(250);
204 	msleep(5);
205 	chip_solfware_reset(ts->driver->client);//20140306
206 }
207 
vtl_ts_wakeup(void)208 static void vtl_ts_wakeup(void)
209 {
210 	struct ts_info *ts;
211 	ts =pg_ts;
212 	DEBUG();
213 
214 	gpio_set_value(ts->config_info.rst_gpio_number, 0);
215 	//msleep(50);
216 	msleep(20);
217 	gpio_set_value(ts->config_info.rst_gpio_number, 1);
218 	msleep(5);
219 	chip_solfware_reset(ts->driver->client);//20140306
220 }
221 
vtl_ts_irq(int irq,void * dev)222 static irqreturn_t vtl_ts_irq(int irq, void *dev)
223 {
224 	struct ts_info *ts;
225 	ts =pg_ts;
226 
227 	DEBUG();
228 
229 	disable_irq_nosync(ts->config_info.irq_number);// Disable ts interrupt
230 	thread_syn_flag=1;
231 	wake_up_interruptible(&waiter);
232 
233 	return IRQ_HANDLED;
234 }
235 
236 
vtl_ts_read_xy_data(struct ts_info * ts)237 static int vtl_ts_read_xy_data(struct ts_info *ts)
238 {
239 	struct i2c_msg msgs;
240 	int ret;
241 
242 	DEBUG();
243 
244 	msgs.addr = ts->driver->client->addr;
245 	msgs.flags = 0x01;  // 0x00: write 0x01:read
246 	msgs.len = sizeof(ts->xy_data.buf);
247 	msgs.buf = ts->xy_data.buf;
248 //	msgs.scl_rate = TS_I2C_SPEED; ///only for rockchip platform
249 	ret = i2c_transfer( ts->driver->client->adapter, &msgs, 1);
250 	if(ret != 1){
251 		printk("___%s:i2c read xy_data err___\n",__func__);
252 		return -1;
253 	}
254 	return 0;
255 #if 0
256 	ret = vtl_ts_i2c_read(client,client->addr,ts->xy_data.buf,sizeof(ts->xy_data.buf));
257 	if(ret){
258 		printk("___%s:i2c read err___\n",__func__);
259 		return -1;
260 	}
261 	return 0;
262 #endif
263 }
264 
vtl_ts_report_xy_coord(struct ts_info * ts)265 static void vtl_ts_report_xy_coord(struct ts_info *ts)
266 {
267 	int id;
268 	int sync;
269 	int x, y;
270 	unsigned int press;
271 	unsigned char touch_point_number;
272 	static unsigned int release = 0;
273 	struct input_dev *input_dev;
274 	union ts_xy_data *xy_data;
275 
276 	DEBUG();
277 
278 	xy_data = &ts->xy_data;
279 	input_dev = ts->driver->input_dev;
280 	touch_point_number = ts->config_info.touch_point_number;
281 
282 
283 
284 	/* report points */
285 	sync = 0;  press = 0;
286 	for ( id = 0; id <touch_point_number; id++ ) //down
287 	{
288 		if ((xy_data->point[id].xhi != 0xFF) && (xy_data->point[id].yhi != 0xFF) &&
289 		     ( (xy_data->point[id].status == 1) || (xy_data->point[id].status == 2)))
290 		{
291 
292 /*
293 			printk("--->>> vtl_ts report: xy_swap %d, x_reverse %d, y_reverse %d, x_mul %d, y_mul %d, bin_ver %d\n",
294 					ts->config_info.xy_swap,
295 					ts->config_info.x_reverse, ts->config_info.y_reverse,
296 					ts->config_info.x_mul, ts->config_info.y_mul,
297 					ts->config_info.bin_ver);
298 */
299 
300 			if (ts->config_info.xy_swap == 1) {
301 				x = (xy_data->point[id].yhi<<4)|(xy_data->point[id].ylo&0xF);
302 				y = (xy_data->point[id].xhi<<4)|(xy_data->point[id].xlo&0xF);
303 			} else {
304 				x = (xy_data->point[id].xhi<<4)|(xy_data->point[id].xlo&0xF);
305 		 		y = (xy_data->point[id].yhi<<4)|(xy_data->point[id].ylo&0xF);
306 			}
307 			if (ts->config_info.x_reverse)
308 				x = ts->config_info.screen_max_x - x;
309 			if (ts->config_info.y_reverse)
310 				y = ts->config_info.screen_max_y - y;
311 
312 			x = ts->config_info.x_mul*x;
313 			y = ts->config_info.x_mul*y;
314 
315 		//#if(DEBUG_ENABLE)
316 		//if((ts->debug)||(DEBUG_ENABLE)){
317 		if(ts->debug){
318 			printk("id = %d,status = %d,X = %d,Y = %d\n",xy_data->point[id].id,xy_data->point[id].status,x,y);
319 			//XY_DEBUG(xy_data->point[id].id,xy_data->point[id].status,x,y);
320 		}
321 		//#endif
322 			input_mt_slot(input_dev, xy_data->point[id].id - 1);
323 			input_report_abs(input_dev, ABS_MT_TRACKING_ID, xy_data->point[id].id-1);
324 			//input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, true);
325 			input_report_abs(input_dev, ABS_MT_POSITION_X, x);
326 			input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
327 			input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, 1);
328 			input_report_abs(input_dev, ABS_MT_WIDTH_MAJOR, 1);
329 
330 			press |= 0x01 << (xy_data->point[id].id - 1);
331 			sync = 1;
332 
333 		}
334 
335 	}
336 	release &= (release ^ press);//release point flag
337 
338 	for ( id = 0; id < touch_point_number; id++ ) //up
339 	{
340 		if ( release & (0x01<<id) )
341 		{
342 			input_mt_slot(input_dev, id);
343 			input_report_abs(input_dev, ABS_MT_TRACKING_ID, -1);
344 			sync = 1;
345 		}
346 	}
347 
348 	release = press;
349 	if(sync)
350 	{
351 		input_sync(input_dev);
352 	}
353 }
354 
355 
356 
vtl_ts_suspend(struct i2c_client * client,pm_message_t mesg)357 int vtl_ts_suspend(struct i2c_client *client, pm_message_t mesg)
358 {
359 	struct ts_info *ts;
360 	unsigned char i;
361 	ts =pg_ts;
362 	DEBUG();
363 	if(ts->config_info.ctp_used)
364 	{
365 		vtl_first_init_flag = 0;
366 		disable_irq(ts->config_info.irq_number);
367 		chip_enter_sleep_mode();
368 
369 		for(i=0;i<ts->config_info.touch_point_number;i++)
370 		{
371 			input_mt_slot(ts->driver->input_dev,i);
372 			input_report_abs(ts->driver->input_dev, ABS_MT_TRACKING_ID, -1);
373 			//input_mt_report_slot_state(ts->driver->input_dev, MT_TOOL_FINGER, false);
374 		}
375 		input_sync(ts->driver->input_dev);
376 	}
377 	return 0;
378 }
379 
vtl_ts_resume(struct i2c_client * client)380 int vtl_ts_resume(struct i2c_client *client)
381 {
382 	struct ts_info *ts;
383 	unsigned char i;
384 	ts =pg_ts;
385 
386 	DEBUG();
387 	if(ts->config_info.ctp_used)
388 	{
389 		/* Hardware reset */
390 		//vtl_ts_hw_reset();
391 		vtl_ts_wakeup();
392 		for(i=0;i<ts->config_info.touch_point_number;i++)
393 		{
394 			input_mt_slot(ts->driver->input_dev,i);
395 			input_report_abs(ts->driver->input_dev, ABS_MT_TRACKING_ID, -1);
396 			//input_mt_report_slot_state(ts->driver->input_dev, MT_TOOL_FINGER, false);
397 		}
398 		input_sync(ts->driver->input_dev);
399 		if(vtl_first_init_flag==0)
400 			enable_irq(ts->config_info.irq_number);
401 	}
402 	return 0;
403 }
404 
vtl_ts_early_suspend(struct tp_device * tp)405 static int vtl_ts_early_suspend(struct tp_device *tp)
406 {
407 	struct ts_info *ts;
408 	ts =pg_ts;
409 
410 	DEBUG();
411 
412 	vtl_ts_suspend(ts->driver->client, PMSG_SUSPEND);
413 
414 	return 0;
415 }
416 
vtl_ts_early_resume(struct tp_device * tp)417 static int vtl_ts_early_resume(struct tp_device *tp)
418 {
419 	struct ts_info *ts;
420 	ts =pg_ts;
421 	DEBUG();
422 
423 	vtl_ts_resume(ts->driver->client);
424 
425 	return 0;
426 }
427 
vtl_ts_remove(struct i2c_client * client)428 int  vtl_ts_remove(struct i2c_client *client)
429 {
430 	struct ts_info *ts;
431 	ts =pg_ts;
432 
433 	DEBUG();
434 
435 	free_irq(ts->config_info.irq_number, ts);
436 	gpio_free(ts->config_info.rst_gpio_number);
437 	//vtl_ts_free_gpio();
438 
439 	//#ifdef CONFIG_HAS_EARLYSUSPEND
440 	//unregister_early_suspend(&ts->driver->early_suspend);
441 	tp_unregister_fb(&ts->tp);
442 	//#endif
443 	if(ts->driver->input_dev != NULL)
444 	{
445 		input_unregister_device(ts->driver->input_dev);
446 	}
447 
448 	if ( ts->driver->proc_entry != NULL ){
449 		remove_proc_entry(DRIVER_NAME, NULL);
450 	}
451 
452 	if(ts->driver->ts_thread != NULL)
453 	{
454 		printk("___kthread stop start___\n");
455 		thread_syn_flag=1;
456 		wake_up_interruptible(&waiter);
457 		kthread_stop(ts->driver->ts_thread);
458 		ts->driver->ts_thread = NULL;
459 		printk("___kthread stop end___\n");
460 	}
461 	return 0;
462 }
463 
vtl_ts_init_input_dev(struct ts_info * ts)464 static int vtl_ts_init_input_dev(struct ts_info *ts)
465 {
466 	struct input_dev *input_dev;
467 	struct device *dev;
468 	int err;
469 
470 	DEBUG();
471 
472 
473 	dev = &ts->driver->client->dev;
474 
475 	/* allocate input device */
476 	ts->driver->input_dev = input_allocate_device();
477 	if ( ts->driver->input_dev == NULL ) {
478 		dev_err(dev, "Unable to allocate input device for device %s.\n", DRIVER_NAME);
479 		return -1;
480 	}
481 
482 	input_dev = ts->driver->input_dev;
483 
484 	input_dev->name = DRIVER_NAME;
485     	input_dev->id.bustype = BUS_I2C;
486     	input_dev->id.vendor  = 0xaaaa;
487     	input_dev->id.product = 0x5555;
488     	input_dev->id.version = 0x0001;
489 
490 	/* config input device */
491 	__set_bit(EV_SYN, input_dev->evbit);
492 	__set_bit(EV_KEY, input_dev->evbit);
493 	__set_bit(EV_ABS, input_dev->evbit);
494 
495 
496 	//set_bit(BTN_TOUCH, input_dev->keybit);//20130923
497 	//set_bit(ABS_MT_POSITION_X, input_dev->absbit);//20130923
498     	//set_bit(ABS_MT_POSITION_Y, input_dev->absbit);//20130923
499 
500 	__set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
501 
502 	input_mt_init_slots(input_dev, TOUCH_POINT_NUM,0);
503 	input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, ts->config_info.screen_max_x, 0, 0);
504 	input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, ts->config_info.screen_max_y, 0, 0);
505 	input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0,ts->config_info.touch_point_number, 0, 0);
506 	input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
507 	input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
508 
509 
510 	/* register input device */
511 	err = input_register_device(input_dev);
512 	if ( err ) {
513 		input_free_device(ts->driver->input_dev);
514 		ts->driver->input_dev = NULL;
515 		dev_err(dev, "Unable to register input device for device %s.\n", DRIVER_NAME);
516 		return -1;
517 	}
518 
519 	return 0;
520 }
521 
522 
vtl_ts_handler(void * data)523 static int vtl_ts_handler(void *data)
524 {
525 	int ret;
526 	struct device *dev;
527 	struct ts_info *ts;
528 	//struct sched_param param = { .sched_priority = TS_THREAD_PRIO};
529 	DEBUG();
530 	//sched_setscheduler(current, SCHED_RR, &param);
531 
532 	ts = (struct ts_info *)data;
533 	dev = &ts->driver->client->dev;
534 
535 
536 	/* Request platform resources (gpio/interrupt pins) */
537 	ret = vtl_ts_config(ts);
538 	if(ret){
539 
540 		dev_err(dev, "VTL touch screen config Failed.\n");
541 		goto ERR_TS_CONFIG;
542 	}
543 
544 	vtl_ts_hw_reset();
545 
546 
547 	ret = chip_init();
548 	if(ret){
549 
550 		dev_err(dev, "vtl ts chip init failed.\n");
551 		goto ERR_CHIP_INIT;
552 	}
553 
554 	/*init input dev*/
555 	ret = vtl_ts_init_input_dev(ts);
556 	if(ret){
557 
558 		dev_err(dev, "init input dev failed.\n");
559 		goto ERR_INIT_INPUT;
560 	}
561 
562 	/* Create Proc Entry File */
563 	#if 0
564 	ts->driver->proc_entry = create_proc_entry(DRIVER_NAME, 0666/*S_IFREG | S_IRUGO | S_IWUSR*/, NULL);
565 	if ( ts->driver->proc_entry == NULL ) {
566 		dev_err(dev, "Failed creating proc dir entry file.\n");
567 		goto ERR_PROC_ENTRY;
568 	}  else{
569 		ts->driver->proc_entry->proc_fops = &apk_fops;
570 	}
571 	#endif
572 	/* register early suspend */
573 //#ifdef CONFIG_HAS_EARLYSUSPEND
574 	//ts->driver->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
575 	//ts->driver->early_suspend.suspend = vtl_ts_early_suspend;
576 	//ts->driver->early_suspend.resume = vtl_ts_early_resume;
577 	//register_early_suspend(&ts->driver->early_suspend);
578 
579 
580 //#endif
581 
582 	/* Init irq */
583 	ret = request_irq(ts->config_info.irq_number, vtl_ts_irq, IRQF_TRIGGER_FALLING, DRIVER_NAME, ts);
584 	if ( ret ) {
585 		dev_err(dev, "Unable to request irq for device %s.\n", DRIVER_NAME);
586 		goto ERR_IRQ_REQ;
587 	}
588 	//disable_irq(pg_ts->config_info.irq_number);
589 	ts->config_info.ctp_used =1;
590 
591 	ts->tp.tp_resume = vtl_ts_early_resume;
592     ts->tp.tp_suspend = vtl_ts_early_suspend;
593     tp_register_fb(&ts->tp);
594 
595 	while (!kthread_should_stop())//while(1)
596 	{
597 		//set_current_state(TASK_INTERRUPTIBLE);
598 		wait_event_interruptible(waiter, thread_syn_flag);
599 		thread_syn_flag = 0;
600 		//set_current_state(TASK_RUNNING);
601 		//printk("__state = %x_%x_\n",current->state,ts->driver->ts_thread->state);
602 		ret = vtl_ts_read_xy_data(ts);
603 
604 		if(!ret){
605 			vtl_ts_report_xy_coord(ts);
606 		}
607 		else
608 		{
609 			printk("____read xy_data error___\n");
610 		}
611 		// Enable ts interrupt
612 		enable_irq(pg_ts->config_info.irq_number);
613 	}
614 
615 	printk("vtl_ts_Kthread exit,%s(%d)\n",__func__,__LINE__);
616 	return 0;
617 
618 
619 
620 
621 ERR_IRQ_REQ:
622 	//#ifdef CONFIG_HAS_EARLYSUSPEND
623 	//unregister_early_suspend(&ts->driver->early_suspend);
624 	//#endif
625 	tp_unregister_fb(&ts->tp);
626 	if ( ts->driver->proc_entry ){
627 		remove_proc_entry(DRIVER_NAME, NULL);
628 		ts->driver->proc_entry = NULL;
629 	}
630 
631 /* ERR_PROC_ENTRY: */
632 	if(ts->driver->input_dev){
633 		input_unregister_device(ts->driver->input_dev);
634 		ts->driver->input_dev = NULL;
635 	}
636 ERR_INIT_INPUT:
637 ERR_CHIP_INIT:
638 	gpio_free(ts->config_info.rst_gpio_number);
639 ERR_TS_CONFIG:
640 	ts->config_info.ctp_used =0;
641 	printk("vtl_ts_Kthread exit,%s(%d)\n",__func__,__LINE__);
642 	//do_exit(0);
643 	return 0;
644 }
645 
646 
647 
vtl_ts_probe(struct i2c_client * client,const struct i2c_device_id * id)648 int vtl_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
649 {
650 	int err = -1;
651 	struct ts_info *ts;
652 	struct device *dev;
653 
654 	DEBUG();
655 
656 	ts = pg_ts;
657 	ts->driver->client = client;
658 	dev = &ts->driver->client->dev;
659 
660 	/* Check I2C Functionality */
661 	err = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
662 	if ( !err ) {
663 		dev_err(dev, "Check I2C Functionality Failed.\n");
664 		return ENODEV;
665 	}
666 
667 
668 	//ts->driver->ts_thread = kthread_run(vtl_ts_handler, NULL, DRIVER_NAME);
669 	ts->driver->ts_thread = kthread_run(vtl_ts_handler, ts, DRIVER_NAME);
670 	if (IS_ERR(ts->driver->ts_thread)) {
671 		err = PTR_ERR(ts->driver->ts_thread);
672 		ts->driver->ts_thread = NULL;
673 		dev_err(dev, "failed to create kernel thread: %d\n", err);
674 		return -1;
675 		//goto ERR_CREATE_TS_THREAD;
676 	}
677 
678 	printk("___%s() end____ \n", __func__);
679 
680 	return 0;
681 
682 
683 
684 }
685 
686 static struct of_device_id vtl_ts_dt_ids[] = {
687 	{ .compatible = "ct,vtl_ts" },
688 	{ }
689 };
690 
691 struct i2c_driver vtl_ts_driver  = {
692 
693 	.driver = {
694 		.owner	= THIS_MODULE,
695 		.name	= DRIVER_NAME,
696 		.of_match_table = of_match_ptr(vtl_ts_dt_ids),
697 	},
698 	.id_table	= vtl_ts_id,
699 	.probe      	= vtl_ts_probe,
700 //#ifndef CONFIG_HAS_EARLYSUSPEND
701 	//.suspend	= vtl_ts_suspend,
702 	//.resume	    	= vtl_ts_resume,
703 //#endif
704 	.remove 	= vtl_ts_remove,
705 };
706 
707 
708 
vtl_ts_init(void)709 int __init vtl_ts_init(void)
710 {
711 	DEBUG();
712 	return i2c_add_driver(&vtl_ts_driver);
713 }
714 
vtl_ts_exit(void)715 void __exit vtl_ts_exit(void)
716 {
717 	DEBUG();
718 	i2c_del_driver(&vtl_ts_driver);
719 }
720 
721 module_init(vtl_ts_init);
722 module_exit(vtl_ts_exit);
723 
724 MODULE_AUTHOR("yangdechu@vtl.com.cn");
725 MODULE_DESCRIPTION("VTL touchscreen driver for rockchip,V1.0");
726 MODULE_LICENSE("GPL");
727 
728 
729