Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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