1 /* drivers/input/touchscreen/gt1x.c
2 *
3 * 2010 - 2014 Goodix Technology.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be a reference
11 * to you, when you are integrating the GOODiX's CTP IC into your system,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * Version: 1.4
17 * Release Date: 2015/07/10
18 */
19
20 #include <linux/irq.h>
21 #include "gt1x.h"
22 #include <linux/input/mt.h>
23
24 static struct work_struct gt1x_work;
25 static struct input_dev *input_dev;
26 static struct workqueue_struct *gt1x_wq;
27 static const char *gt1x_ts_name = "goodix-ts";
28 static const char *input_dev_phys = "input/ts";
29 #ifdef CONFIG_PM
30 static const struct dev_pm_ops gt1x_ts_pm_ops;
31 #endif
32 #ifdef GTP_CONFIG_OF
33 bool gt1x_gt5688;
34 int gt1x_rst_gpio;
35 int gt1x_int_gpio;
36 static bool power_invert;
37 #endif
38
39 static int gt1x_register_powermanger(void);
40 static int gt1x_unregister_powermanger(void);
41
42 /**
43 * gt1x_i2c_write - i2c write.
44 * @addr: register address.
45 * @buffer: data buffer.
46 * @len: the bytes of data to write.
47 *Return: 0: success, otherwise: failed
48 */
gt1x_i2c_write(u16 addr,u8 * buffer,s32 len)49 s32 gt1x_i2c_write(u16 addr, u8 *buffer, s32 len)
50 {
51 struct i2c_msg msg = {
52 .flags = 0,
53 .addr = gt1x_i2c_client->addr,
54 };
55 return _do_i2c_write(&msg, addr, buffer, len);
56 }
57
58 /**
59 * gt1x_i2c_read - i2c read.
60 * @addr: register address.
61 * @buffer: data buffer.
62 * @len: the bytes of data to write.
63 *Return: 0: success, otherwise: failed
64 */
gt1x_i2c_read(u16 addr,u8 * buffer,s32 len)65 s32 gt1x_i2c_read(u16 addr, u8 *buffer, s32 len)
66 {
67 u8 addr_buf[GTP_ADDR_LENGTH] = { (addr >> 8) & 0xFF, addr & 0xFF };
68 struct i2c_msg msgs[2] = {
69 {
70 .addr = gt1x_i2c_client->addr,
71 .flags = 0,
72 .buf = addr_buf,
73 .len = GTP_ADDR_LENGTH},
74 {
75 .addr = gt1x_i2c_client->addr,
76 .flags = I2C_M_RD}
77 };
78 return _do_i2c_read(msgs, addr, buffer, len);
79 }
80
81 static spinlock_t irq_lock;
82 static s32 irq_is_disable;
83
84 /**
85 * gt1x_irq_enable - enable irq function.
86 *
87 */
gt1x_irq_enable(void)88 void gt1x_irq_enable(void)
89 {
90 unsigned long irqflags = 0;
91
92 GTP_DEBUG_FUNC();
93
94 spin_lock_irqsave(&irq_lock, irqflags);
95 if (irq_is_disable) {
96 enable_irq(gt1x_i2c_client->irq);
97 irq_is_disable = 0;
98 }
99 spin_unlock_irqrestore(&irq_lock, irqflags);
100 }
101
102 /**
103 * gt1x_irq_enable - disable irq function.
104 *
105 */
gt1x_irq_disable(void)106 void gt1x_irq_disable(void)
107 {
108 unsigned long irqflags;
109
110 GTP_DEBUG_FUNC();
111
112 spin_lock_irqsave(&irq_lock, irqflags);
113 if (!irq_is_disable) {
114 irq_is_disable = 1;
115 disable_irq_nosync(gt1x_i2c_client->irq);
116 }
117 spin_unlock_irqrestore(&irq_lock, irqflags);
118 }
119
120 #ifndef GTP_CONFIG_OF
gt1x_power_switch(s32 state)121 int gt1x_power_switch(s32 state)
122 {
123 return 0;
124 }
125 #endif
126
gt1x_debug_proc(u8 * buf,int count)127 int gt1x_debug_proc(u8 *buf, int count)
128 {
129 return -1;
130 }
131
132 #if GTP_CHARGER_SWITCH
gt1x_get_charger_status(void)133 u32 gt1x_get_charger_status(void)
134 {
135 #error Need to get charger status of your platform.
136 }
137 #endif
138
139 /**
140 * gt1x_ts_irq_handler - External interrupt service routine for interrupt mode.
141 * @irq: interrupt number.
142 * @dev_id: private data pointer.
143 * Return: Handle Result.
144 * IRQ_HANDLED: interrupt handled successfully
145 */
gt1x_ts_irq_handler(int irq,void * dev_id)146 static irqreturn_t gt1x_ts_irq_handler(int irq, void *dev_id)
147 {
148 GTP_DEBUG_FUNC();
149 gt1x_irq_disable();
150 queue_work(gt1x_wq, >1x_work);
151 return IRQ_HANDLED;
152 }
153
154 /**
155 * gt1x_touch_down - Report touch point event .
156 * @id: trackId
157 * @x: input x coordinate
158 * @y: input y coordinate
159 * @w: input pressure
160 * Return: none.
161 */
gt1x_touch_down(s32 x,s32 y,s32 size,s32 id)162 void gt1x_touch_down(s32 x, s32 y, s32 size, s32 id)
163 {
164 #if GTP_CHANGE_X2Y
165 GTP_SWAP(x, y);
166 #endif
167
168 if (gt1x_ics_slot_report) {
169 input_mt_slot(input_dev, id);
170 input_report_abs(input_dev, ABS_MT_PRESSURE, size);
171 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, size);
172 input_report_abs(input_dev, ABS_MT_TRACKING_ID, id);
173 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
174 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
175 } else {
176 input_report_key(input_dev, BTN_TOUCH, 1);
177
178 if ((!size) && (!id)) {
179 /* for virtual button */
180 input_report_abs(input_dev, ABS_MT_PRESSURE, 100);
181 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, 100);
182 } else {
183 input_report_abs(input_dev, ABS_MT_PRESSURE, size);
184 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, size);
185 input_report_abs(input_dev, ABS_MT_TRACKING_ID, id);
186 }
187 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
188 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
189 input_mt_sync(input_dev);
190
191 }
192 }
193
194 /**
195 * gt1x_touch_up - Report touch release event.
196 * @id: trackId
197 * Return: none.
198 */
gt1x_touch_up(s32 id)199 void gt1x_touch_up(s32 id)
200 {
201 if (gt1x_ics_slot_report) {
202 input_mt_slot(input_dev, id);
203 input_report_abs(input_dev, ABS_MT_TRACKING_ID, -1);
204 } else {
205 input_report_key(input_dev, BTN_TOUCH, 0);
206 input_mt_sync(input_dev);
207 }
208 }
209
210 /**
211 * gt1x_ts_work_func - Goodix touchscreen work function.
212 * @iwork: work struct of gt1x_workqueue.
213 * Return: none.
214 */
gt1x_ts_work_func(struct work_struct * work)215 static void gt1x_ts_work_func(struct work_struct *work)
216 {
217 u8 end_cmd = 0;
218 u8 finger = 0;
219 s32 ret = 0;
220 u8 point_data[11] = { 0 };
221
222 if (update_info.status) {
223 GTP_DEBUG("Ignore interrupts during fw update.");
224 return;
225 }
226
227 #if GTP_GESTURE_WAKEUP
228 ret = gesture_event_handler(input_dev);
229 if (ret >= 0) {
230 goto exit_work_func;
231 }
232 #endif
233
234 if (gt1x_halt) {
235 GTP_DEBUG("Ignore interrupts after suspend...");
236 return;
237 }
238
239 ret = gt1x_i2c_read(GTP_READ_COOR_ADDR, point_data, sizeof(point_data));
240 if (ret < 0) {
241 GTP_ERROR("I2C transfer error!");
242 #if !GTP_ESD_PROTECT
243 gt1x_power_reset();
244 #endif
245 goto exit_work_func;
246 }
247
248 finger = point_data[0];
249 if (finger == 0x00) {
250 gt1x_request_event_handler();
251 }
252
253 if ((finger & 0x80) == 0) {
254 #if HOTKNOT_BLOCK_RW
255 if (!hotknot_paired_flag)
256 #endif
257 {
258 /*GTP_ERROR("buffer not ready:0x%02x", finger);*/
259 goto exit_eint;
260 }
261 }
262 #if HOTKNOT_BLOCK_RW
263 ret = hotknot_event_handler(point_data);
264 if (!ret) {
265 goto exit_work_func;
266 }
267 #endif
268
269 #if GTP_PROXIMITY
270 ret = gt1x_prox_event_handler(point_data);
271 if (ret > 0) {
272 goto exit_work_func;
273 }
274 #endif
275
276 #if GTP_WITH_STYLUS
277 ret = gt1x_touch_event_handler(point_data, input_dev, pen_dev);
278 #else
279 ret = gt1x_touch_event_handler(point_data, input_dev, NULL);
280 #endif
281
282 exit_work_func:
283 if (!gt1x_rawdiff_mode && (ret >= 0 || ret == ERROR_VALUE)) {
284 ret = gt1x_i2c_write(GTP_READ_COOR_ADDR, &end_cmd, 1);
285 if (ret < 0) {
286 GTP_ERROR("I2C write end_cmd error!");
287 }
288 }
289 exit_eint:
290 gt1x_irq_enable();
291
292 }
293
294 /*
295 * Devices Tree support,
296 */
297 #ifdef GTP_CONFIG_OF
298
299 static struct regulator *vdd_ana;
300 /**
301 * gt1x_parse_dt - parse platform infomation form devices tree.
302 */
gt1x_parse_dt(struct device * dev)303 static int gt1x_parse_dt(struct device *dev)
304 {
305 struct device_node *np;
306 const char *tp_type;
307 #ifdef CONFIG_PM
308 struct device_node *root;
309 const char *machine_compatible;
310 #endif
311
312 if (!dev)
313 return -ENODEV;
314
315 np = dev->of_node;
316
317 if (!of_property_read_string(np, "goodix,ic_type", &tp_type)) {
318 GTP_INFO("GTP ic_type: %s", tp_type);
319
320 if (strstr(tp_type, "gt5688"))
321 gt1x_gt5688 = true;
322 }
323
324 gt1x_int_gpio = of_get_named_gpio(np, "goodix,irq-gpio", 0);
325 gt1x_rst_gpio = of_get_named_gpio(np, "goodix,rst-gpio", 0);
326
327 if (!gpio_is_valid(gt1x_int_gpio) && !gpio_is_valid(gt1x_rst_gpio)) {
328 GTP_ERROR("Invalid GPIO, irq-gpio:%d, rst-gpio:%d",
329 gt1x_int_gpio, gt1x_rst_gpio);
330 return -EINVAL;
331 }
332
333 if (!gpio_is_valid(gt1x_int_gpio)) {
334 GTP_ERROR("Invalid GPIO, irq-gpio:%d",
335 gt1x_int_gpio);
336 return -EINVAL;
337 }
338
339 vdd_ana = devm_regulator_get_optional(dev, "vdd_ana");
340 if (PTR_ERR(vdd_ana) == -ENODEV) {
341 GTP_ERROR("vdd_ana not specified, fallback to power-supply");
342 vdd_ana = devm_regulator_get_optional(dev, "power");
343 if (PTR_ERR(vdd_ana) == -ENODEV) {
344 GTP_ERROR("power not specified, ignore power ctrl");
345 vdd_ana = NULL;
346 } else {
347 power_invert = of_property_read_bool(np, "power-invert");
348 GTP_INFO("Power Invert,%s ", power_invert ? "yes" : "no");
349 }
350 }
351 if (IS_ERR(vdd_ana)) {
352 GTP_ERROR("regulator get of vdd_ana/power-supply failed");
353 return PTR_ERR(vdd_ana);
354 }
355
356 gt1x_ics_slot_report = of_property_read_bool(dev->of_node, "gtp_ics_slot_report");
357 #ifdef CONFIG_PM
358 root = of_find_node_by_path("/");
359 if (root) {
360 machine_compatible = of_get_property(root, "compatible", NULL);
361 of_node_put(root);
362 if (strstr(machine_compatible, "linux"))
363 dev->driver->pm = >1x_ts_pm_ops;
364 }
365 #endif
366
367 return 0;
368 }
369
370 /**
371 * gt1x_power_switch - power switch .
372 * @on: 1-switch on, 0-switch off.
373 * return: 0-succeed, -1-faileds
374 */
gt1x_power_switch(int on)375 int gt1x_power_switch(int on)
376 {
377 int ret = 0;
378 struct i2c_client *client = gt1x_i2c_client;
379
380 if (!client || !vdd_ana)
381 return -1;
382
383 if (on) {
384 GTP_DEBUG("GTP power on.");
385 if (power_invert) {
386 if (regulator_is_enabled(vdd_ana) > 0)
387 ret = regulator_disable(vdd_ana);
388 } else {
389 ret = regulator_enable(vdd_ana);
390 }
391 } else {
392 GTP_DEBUG("GTP power off.");
393 if (power_invert) {
394 if (!regulator_is_enabled(vdd_ana))
395 ret = regulator_enable(vdd_ana);
396 } else {
397 ret = regulator_disable(vdd_ana);
398 }
399 }
400 return ret;
401 }
402 #endif
403
gt1x_remove_gpio_and_power(void)404 static void gt1x_remove_gpio_and_power(void)
405 {
406 if (gpio_is_valid(gt1x_int_gpio))
407 gpio_free(gt1x_int_gpio);
408
409 if (gpio_is_valid(gt1x_rst_gpio))
410 gpio_free(gt1x_rst_gpio);
411
412 if (gt1x_i2c_client && gt1x_i2c_client->irq)
413 free_irq(gt1x_i2c_client->irq, gt1x_i2c_client);
414 }
415
416
417 /**
418 * gt1x_request_io_port - Request gpio(INT & RST) ports.
419 */
gt1x_request_io_port(void)420 static s32 gt1x_request_io_port(void)
421 {
422 s32 ret = 0;
423
424 GTP_DEBUG_FUNC();
425 ret = gpio_request(GTP_INT_PORT, "GTP_INT_IRQ");
426 if (ret < 0) {
427 GTP_ERROR("Failed to request GPIO:%d, ERRNO:%d", (s32) GTP_INT_PORT, ret);
428 return ret;
429 }
430
431 GTP_GPIO_AS_INT(GTP_INT_PORT);
432 gt1x_i2c_client->irq = GTP_INT_IRQ;
433
434 if (gpio_is_valid(gt1x_rst_gpio)) {
435 ret = gpio_request(GTP_RST_PORT, "GTP_RST_PORT");
436 if (ret < 0) {
437 GTP_ERROR("Failed to request GPIO:%d, ERRNO:%d", (s32) GTP_RST_PORT, ret);
438 gpio_free(GTP_INT_PORT);
439 return ret;
440 }
441
442 GTP_GPIO_AS_INPUT(GTP_RST_PORT);
443 }
444
445 return 0;
446 }
447
448 /**
449 * gt1x_request_irq - Request interrupt.
450 * Return
451 * 0: succeed, -1: failed.
452 */
gt1x_request_irq(void)453 static s32 gt1x_request_irq(void)
454 {
455 s32 ret = -1;
456 const u8 irq_table[] = GTP_IRQ_TAB;
457
458 GTP_DEBUG_FUNC();
459 GTP_DEBUG("INT trigger type:%x", gt1x_int_type);
460
461 ret = request_irq(gt1x_i2c_client->irq, gt1x_ts_irq_handler, irq_table[gt1x_int_type], gt1x_i2c_client->name, gt1x_i2c_client);
462 if (ret) {
463 GTP_ERROR("Request IRQ failed!ERRNO:%d.", ret);
464 GTP_GPIO_AS_INPUT(GTP_INT_PORT);
465 gpio_free(GTP_INT_PORT);
466
467 return -1;
468 } else {
469 gt1x_irq_disable();
470 return 0;
471 }
472 }
473
474 /**
475 * gt1x_request_input_dev - Request input device Function.
476 * Return
477 * 0: succeed, -1: failed.
478 */
gt1x_request_input_dev(void)479 static s8 gt1x_request_input_dev(void)
480 {
481 s8 ret = -1;
482 #if GTP_HAVE_TOUCH_KEY
483 u8 index = 0;
484 #endif
485
486 GTP_DEBUG_FUNC();
487
488 input_dev = input_allocate_device();
489 if (input_dev == NULL) {
490 GTP_ERROR("Failed to allocate input device.");
491 return -ENOMEM;
492 }
493
494 input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
495 if (gt1x_ics_slot_report) {
496 #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 7, 0))
497 input_mt_init_slots(input_dev, 16, INPUT_MT_DIRECT);
498 #else
499 input_mt_init_slots(input_dev, 16);
500 #endif
501 } else {
502 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
503 }
504 set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
505
506 #if GTP_HAVE_TOUCH_KEY
507 for (index = 0; index < GTP_MAX_KEY_NUM; index++) {
508 input_set_capability(input_dev, EV_KEY, gt1x_touch_key_array[index]);
509 }
510 #endif
511
512 #if GTP_GESTURE_WAKEUP
513 input_set_capability(input_dev, EV_KEY, KEY_GES_REGULAR);
514 input_set_capability(input_dev, EV_KEY, KEY_GES_CUSTOM);
515 #endif
516
517 #if GTP_CHANGE_X2Y
518 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, gt1x_abs_y_max, 0, 0);
519 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, gt1x_abs_x_max, 0, 0);
520 #else
521 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, gt1x_abs_x_max, 0, 0);
522 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, gt1x_abs_y_max, 0, 0);
523 #endif
524 input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
525 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
526 input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
527
528 input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0);
529 input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0);
530
531 input_dev->name = gt1x_ts_name;
532 input_dev->phys = input_dev_phys;
533 input_dev->id.bustype = BUS_I2C;
534 input_dev->id.vendor = 0xDEAD;
535 input_dev->id.product = 0xBEEF;
536 input_dev->id.version = 10427;
537
538 ret = input_register_device(input_dev);
539 if (ret) {
540 GTP_ERROR("Register %s input device failed", input_dev->name);
541 return -ENODEV;
542 }
543
544 return 0;
545 }
546
547 /**
548 * gt1x_ts_probe - I2c probe.
549 * @client: i2c device struct.
550 * @id: device id.
551 * Return 0: succeed, -1: failed.
552 */
gt1x_ts_probe(struct i2c_client * client,const struct i2c_device_id * id)553 static int gt1x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
554 {
555 s32 ret = -1;
556 #if GTP_AUTO_UPDATE
557 struct task_struct *thread = NULL;
558 #endif
559 /*do NOT remove these logs*/
560 GTP_INFO("GTP Driver Version: %s", GTP_DRIVER_VERSION);
561 GTP_INFO("GTP I2C Address: 0x%02x", client->addr);
562
563 gt1x_i2c_client = client;
564 spin_lock_init(&irq_lock);
565
566 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
567 GTP_ERROR("I2C check functionality failed.");
568 return -ENODEV;
569 }
570
571 #ifdef GTP_CONFIG_OF /* device tree support */
572 if (client->dev.of_node) {
573 ret = gt1x_parse_dt(&client->dev);
574 if (ret)
575 return ret;
576 }
577 #endif
578
579 ret = gt1x_request_io_port();
580 if (ret < 0) {
581 GTP_ERROR("GTP request IO port failed.");
582 return ret;
583 }
584
585 ret = gt1x_init();
586 if (ret != 0) {
587 GTP_ERROR("GTP init failed!!!");
588 return ret;
589 }
590
591 gt1x_wq = create_singlethread_workqueue("gt1x_wq");
592 if (!gt1x_wq) {
593 GTP_ERROR("Creat workqueue failed.");
594 return -ENOMEM;
595 }
596
597 INIT_WORK(>1x_work, gt1x_ts_work_func);
598
599 ret = gt1x_request_input_dev();
600 if (ret < 0) {
601 GTP_ERROR("GTP request input dev failed");
602 }
603
604 ret = gt1x_request_irq();
605 if (ret < 0) {
606 GTP_DEBUG("GTP works in polling mode.");
607 } else {
608 GTP_DEBUG("GTP works in interrupt mode.");
609 }
610
611 #if GTP_GESTURE_WAKEUP
612 enable_irq_wake(client->irq);
613 #endif
614
615 gt1x_irq_enable();
616
617 #if GTP_ESD_PROTECT
618 /*must before auto update*/
619 gt1x_init_esd_protect();
620 gt1x_esd_switch(SWITCH_ON);
621 #endif
622
623 #if GTP_AUTO_UPDATE
624 thread = kthread_run(gt1x_auto_update_proc, (void *)NULL, "gt1x_auto_update");
625 if (IS_ERR(thread)) {
626 ret = PTR_ERR(thread);
627 GTP_ERROR("Failed to create auto-update thread: %d.", ret);
628 }
629 #endif
630 gt1x_register_powermanger();
631 return 0;
632 }
633
634 /**
635 * gt1x_ts_remove - Goodix touchscreen driver release function.
636 * @client: i2c device struct.
637 * Return 0: succeed, -1: failed.
638 */
gt1x_ts_remove(struct i2c_client * client)639 static int gt1x_ts_remove(struct i2c_client *client)
640 {
641 GTP_DEBUG_FUNC();
642 GTP_DEBUG("GTP driver removing...");
643 gt1x_unregister_powermanger();
644
645 #if GTP_GESTURE_WAKEUP
646 disable_irq_wake(client->irq);
647 #endif
648 gt1x_deinit();
649 input_unregister_device(input_dev);
650 gt1x_remove_gpio_and_power();
651 if (gt1x_wq) {
652 destroy_workqueue(gt1x_wq);
653 }
654
655 return 0;
656 }
657
658 #if defined(CONFIG_FB)
659 /* frame buffer notifier block control the suspend/resume procedure */
660 static struct notifier_block gt1x_fb_notifier;
661 static int tp_status;
662
gtp_fb_notifier_callback(struct notifier_block * noti,unsigned long event,void * data)663 static int gtp_fb_notifier_callback(struct notifier_block *noti, unsigned long event, void *data)
664 {
665 struct fb_event *ev_data = data;
666 int *blank;
667
668 #if GTP_INCELL_PANEL
669 #ifndef FB_EARLY_EVENT_BLANK
670 #error Need add FB_EARLY_EVENT_BLANK to fbmem.c
671 #endif
672
673 if (ev_data && ev_data->data && event == FB_EARLY_EVENT_BLANK
674 && tp_status != FB_BLANK_UNBLANK) {
675 blank = ev_data->data;
676 if (*blank == FB_BLANK_UNBLANK) {
677 tp_status = *blank;
678 GTP_DEBUG("Resume by fb notifier.");
679 gt1x_resume();
680 }
681 }
682 #else
683 if (ev_data && ev_data->data && event == FB_EVENT_BLANK
684 && tp_status != FB_BLANK_UNBLANK) {
685 blank = ev_data->data;
686 if (*blank == FB_BLANK_UNBLANK) {
687 tp_status = *blank;
688 GTP_DEBUG("Resume by fb notifier.");
689 gt1x_resume();
690 }
691 }
692 #endif
693
694 if (ev_data && ev_data->data && event == FB_EVENT_BLANK
695 && tp_status == FB_BLANK_UNBLANK) {
696 blank = ev_data->data;
697 if (*blank == FB_BLANK_POWERDOWN) {
698 tp_status = *blank;
699 GTP_DEBUG("Suspend by fb notifier.");
700 gt1x_suspend();
701 }
702 }
703
704 return 0;
705 }
706 #elif defined(CONFIG_HAS_EARLYSUSPEND)
707 /* earlysuspend module the suspend/resume procedure */
gt1x_ts_early_suspend(struct early_suspend * h)708 static void gt1x_ts_early_suspend(struct early_suspend *h)
709 {
710 gt1x_suspend();
711 }
712
gt1x_ts_late_resume(struct early_suspend * h)713 static void gt1x_ts_late_resume(struct early_suspend *h)
714 {
715 gt1x_resume();
716 }
717
718 static struct early_suspend gt1x_early_suspend = {
719 .level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1,
720 .suspend = gt1x_ts_early_suspend,
721 .resume = gt1x_ts_late_resume,
722 };
723 #endif
724
725 #ifdef CONFIG_PM
726 /**
727 * gt1x_ts_suspend - i2c suspend callback function.
728 * @dev: i2c device.
729 * Return 0: succeed, -1: failed.
730 */
gt1x_pm_suspend(struct device * dev)731 static int gt1x_pm_suspend(struct device *dev)
732 {
733 return gt1x_suspend();
734 }
735
736 /**
737 * gt1x_ts_resume - i2c resume callback function.
738 * @dev: i2c device.
739 * Return 0: succeed, -1: failed.
740 */
gt1x_pm_resume(struct device * dev)741 static int gt1x_pm_resume(struct device *dev)
742 {
743 return gt1x_resume();
744 }
745
746 /* bus control the suspend/resume procedure */
747 static const struct dev_pm_ops gt1x_ts_pm_ops = {
748 .suspend = gt1x_pm_suspend,
749 .resume = gt1x_pm_resume,
750 };
751 #endif
752
gt1x_register_powermanger(void)753 static int gt1x_register_powermanger(void)
754 {
755 #if defined(CONFIG_FB)
756 tp_status = FB_BLANK_UNBLANK;
757 gt1x_fb_notifier.notifier_call = gtp_fb_notifier_callback;
758 fb_register_client(>1x_fb_notifier);
759
760 #elif defined(CONFIG_HAS_EARLYSUSPEND)
761 register_early_suspend(>1x_early_suspend);
762 #endif
763 return 0;
764 }
765
gt1x_unregister_powermanger(void)766 static int gt1x_unregister_powermanger(void)
767 {
768 #if defined(CONFIG_FB)
769 fb_unregister_client(>1x_fb_notifier);
770
771 #elif defined(CONFIG_HAS_EARLYSUSPEND)
772 unregister_early_suspend(>1x_early_suspend);
773 #endif
774 return 0;
775 }
776
777 #ifdef GTP_CONFIG_OF
778 static const struct of_device_id gt1x_match_table[] = {
779 {.compatible = "goodix,gt1x",},
780 { },
781 };
782 #endif
783
784 static const struct i2c_device_id gt1x_ts_id[] = {
785 {GTP_I2C_NAME, 0},
786 {}
787 };
788
789 static struct i2c_driver gt1x_ts_driver = {
790 .probe = gt1x_ts_probe,
791 .remove = gt1x_ts_remove,
792 .id_table = gt1x_ts_id,
793 .driver = {
794 .name = GTP_I2C_NAME,
795 #ifdef GTP_CONFIG_OF
796 .of_match_table = gt1x_match_table,
797 #endif
798 #if !defined(CONFIG_FB) && defined(CONFIG_PM)
799 .pm = >1x_ts_pm_ops,
800 #endif
801 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
802 },
803 };
804
805 /**
806 * gt1x_ts_init - Driver Install function.
807 * Return 0---succeed.
808 */
gt1x_ts_init(void)809 static int __init gt1x_ts_init(void)
810 {
811 GTP_DEBUG_FUNC();
812 GTP_DEBUG("GTP driver installing...");
813
814 return i2c_add_driver(>1x_ts_driver);
815 }
816
817 /**
818 * gt1x_ts_exit - Driver uninstall function.
819 * Return 0---succeed.
820 */
gt1x_ts_exit(void)821 static void __exit gt1x_ts_exit(void)
822 {
823 GTP_DEBUG_FUNC();
824 GTP_DEBUG("GTP driver exited.");
825 i2c_del_driver(>1x_ts_driver);
826 }
827
828 module_init(gt1x_ts_init);
829 module_exit(gt1x_ts_exit);
830
831 MODULE_DESCRIPTION("GTP Series Driver");
832 MODULE_LICENSE("GPL");
833 MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);
834