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) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  Driver for Goodix Touchscreens
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Copyright (c) 2014 Red Hat Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  Copyright (c) 2015 K. Merker <merker@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *  This code is based on gt9xx.c authored by andrew@goodix.com:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *  2010 - 2012 Goodix Technology.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define GOODIX_GPIO_INT_NAME		"irq"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #define GOODIX_GPIO_RST_NAME		"reset"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #define GOODIX_MAX_HEIGHT		4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #define GOODIX_MAX_WIDTH		4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #define GOODIX_INT_TRIGGER		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #define GOODIX_CONTACT_SIZE		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define GOODIX_MAX_CONTACT_SIZE		9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define GOODIX_MAX_CONTACTS		10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define GOODIX_MAX_KEYS			7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define GOODIX_CONFIG_MIN_LENGTH	186
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define GOODIX_CONFIG_911_LENGTH	186
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define GOODIX_CONFIG_967_LENGTH	228
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #define GOODIX_CONFIG_GT9X_LENGTH	240
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define GOODIX_CONFIG_MAX_LENGTH	240
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) /* Register defines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define GOODIX_REG_COMMAND		0x8040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define GOODIX_CMD_SCREEN_OFF		0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define GOODIX_READ_COOR_ADDR		0x814E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define GOODIX_GT1X_REG_CONFIG_DATA	0x8050
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define GOODIX_GT9X_REG_CONFIG_DATA	0x8047
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define GOODIX_REG_ID			0x8140
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define GOODIX_BUFFER_STATUS_READY	BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #define GOODIX_HAVE_KEY			BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define GOODIX_BUFFER_STATUS_TIMEOUT	20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #define RESOLUTION_LOC		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #define MAX_CONTACTS_LOC	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define TRIGGER_LOC		6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) /* Our special handling for GPIO accesses through ACPI is x86 specific */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #if defined CONFIG_X86 && defined CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #define ACPI_GPIO_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) struct goodix_ts_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) enum goodix_irq_pin_access_method {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	IRQ_PIN_ACCESS_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	IRQ_PIN_ACCESS_GPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	IRQ_PIN_ACCESS_ACPI_GPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	IRQ_PIN_ACCESS_ACPI_METHOD,
^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) struct goodix_chip_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	u16 config_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	int config_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	int (*check_config)(struct goodix_ts_data *ts, const u8 *cfg, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	void (*calc_config_checksum)(struct goodix_ts_data *ts);
^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) struct goodix_chip_id {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	const char *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	const struct goodix_chip_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #define GOODIX_ID_MAX_LEN	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) struct goodix_ts_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	const struct goodix_chip_data *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	struct touchscreen_properties prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	unsigned int max_touch_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	unsigned int int_trigger_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	struct regulator *avdd28;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	struct regulator *vddio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	struct gpio_desc *gpiod_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	struct gpio_desc *gpiod_rst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	int gpio_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	int gpio_int_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	char id[GOODIX_ID_MAX_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	u16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	const char *cfg_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	bool reset_controller_at_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	bool load_cfg_from_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	struct completion firmware_loading_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	unsigned long irq_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	enum goodix_irq_pin_access_method irq_pin_access_method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	unsigned int contact_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	u8 config[GOODIX_CONFIG_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	unsigned short keymap[GOODIX_MAX_KEYS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static int goodix_check_cfg_8(struct goodix_ts_data *ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 			      const u8 *cfg, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) static int goodix_check_cfg_16(struct goodix_ts_data *ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 			       const u8 *cfg, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static void goodix_calc_cfg_checksum_8(struct goodix_ts_data *ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static void goodix_calc_cfg_checksum_16(struct goodix_ts_data *ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) static const struct goodix_chip_data gt1x_chip_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	.config_addr		= GOODIX_GT1X_REG_CONFIG_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	.config_len		= GOODIX_CONFIG_GT9X_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	.check_config		= goodix_check_cfg_16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	.calc_config_checksum	= goodix_calc_cfg_checksum_16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static const struct goodix_chip_data gt911_chip_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	.config_addr		= GOODIX_GT9X_REG_CONFIG_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	.config_len		= GOODIX_CONFIG_911_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	.check_config		= goodix_check_cfg_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	.calc_config_checksum	= goodix_calc_cfg_checksum_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) static const struct goodix_chip_data gt967_chip_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	.config_addr		= GOODIX_GT9X_REG_CONFIG_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	.config_len		= GOODIX_CONFIG_967_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	.check_config		= goodix_check_cfg_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	.calc_config_checksum	= goodix_calc_cfg_checksum_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) static const struct goodix_chip_data gt9x_chip_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	.config_addr		= GOODIX_GT9X_REG_CONFIG_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	.config_len		= GOODIX_CONFIG_GT9X_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	.check_config		= goodix_check_cfg_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	.calc_config_checksum	= goodix_calc_cfg_checksum_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) static const struct goodix_chip_id goodix_chip_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	{ .id = "1151", .data = &gt1x_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	{ .id = "5663", .data = &gt1x_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	{ .id = "5688", .data = &gt1x_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	{ .id = "917S", .data = &gt1x_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	{ .id = "9286", .data = &gt1x_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	{ .id = "911", .data = &gt911_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	{ .id = "9271", .data = &gt911_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	{ .id = "9110", .data = &gt911_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	{ .id = "9111", .data = &gt911_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	{ .id = "927", .data = &gt911_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	{ .id = "928", .data = &gt911_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	{ .id = "912", .data = &gt967_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	{ .id = "9147", .data = &gt967_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	{ .id = "967", .data = &gt967_chip_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) static const unsigned long goodix_irq_flags[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	IRQ_TYPE_EDGE_RISING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	IRQ_TYPE_EDGE_FALLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	IRQ_TYPE_LEVEL_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	IRQ_TYPE_LEVEL_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) static const struct dmi_system_id nine_bytes_report[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) #if defined(CONFIG_DMI) && defined(CONFIG_X86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		.ident = "Lenovo YogaBook",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		/* YB1-X91L/F and YB1-X90L/F */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 			DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9")
^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) #endif
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  * Those tablets have their x coordinate inverted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) static const struct dmi_system_id inverted_x_screen[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) #if defined(CONFIG_DMI) && defined(CONFIG_X86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		.ident = "Cube I15-TC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 			DMI_MATCH(DMI_SYS_VENDOR, "Cube"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 			DMI_MATCH(DMI_PRODUCT_NAME, "I15-TC")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) #endif
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)  * goodix_i2c_read - read data from a register of the i2c slave device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214)  * @client: i2c device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215)  * @reg: the register to read from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216)  * @buf: raw write data buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)  * @len: length of the buffer to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) static int goodix_i2c_read(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 			   u16 reg, u8 *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	struct i2c_msg msgs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	__be16 wbuf = cpu_to_be16(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	msgs[0].flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	msgs[0].addr  = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	msgs[0].len   = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	msgs[0].buf   = (u8 *)&wbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	msgs[1].flags = I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	msgs[1].addr  = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	msgs[1].len   = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	msgs[1].buf   = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	ret = i2c_transfer(client->adapter, msgs, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	return ret < 0 ? ret : (ret != ARRAY_SIZE(msgs) ? -EIO : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241)  * goodix_i2c_write - write data to a register of the i2c slave device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243)  * @client: i2c device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244)  * @reg: the register to write to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245)  * @buf: raw data buffer to write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246)  * @len: length of the buffer to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) static int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 			    unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	u8 *addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	struct i2c_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	addr_buf = kmalloc(len + 2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	if (!addr_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	addr_buf[0] = reg >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	addr_buf[1] = reg & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	memcpy(&addr_buf[2], buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	msg.flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	msg.addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	msg.buf = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	msg.len = len + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	ret = i2c_transfer(client->adapter, &msg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	kfree(addr_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	return ret < 0 ? ret : (ret != 1 ? -EIO : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) static int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	return goodix_i2c_write(client, reg, &value, sizeof(value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) static const struct goodix_chip_data *goodix_get_chip_data(const char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	for (i = 0; goodix_chip_ids[i].id; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		if (!strcmp(goodix_chip_ids[i].id, id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 			return goodix_chip_ids[i].data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	return &gt9x_chip_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	unsigned long max_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	int touch_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	u16 addr = GOODIX_READ_COOR_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	 * We are going to read 1-byte header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	 * ts->contact_size * max(1, touch_num) bytes of coordinates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	 * and 1-byte footer which contains the touch-key code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	const int header_contact_keycode_size = 1 + ts->contact_size + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	 * The 'buffer status' bit, which indicates that the data is valid, is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	 * not set as soon as the interrupt is raised, but slightly after.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	 * This takes around 10 ms to happen, so we poll for 20 ms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		error = goodix_i2c_read(ts->client, addr, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 					header_contact_keycode_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 			dev_err(&ts->client->dev, "I2C transfer error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 					error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		if (data[0] & GOODIX_BUFFER_STATUS_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 			touch_num = data[0] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			if (touch_num > ts->max_touch_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 				return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			if (touch_num > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 				addr += header_contact_keycode_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 				data += header_contact_keycode_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 				error = goodix_i2c_read(ts->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 						addr, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 						ts->contact_size *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 							(touch_num - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 				if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 					return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			return touch_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		usleep_range(1000, 2000); /* Poll every 1 - 2 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	} while (time_before(jiffies, max_timeout));
^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) 	 * The Goodix panel will send spurious interrupts after a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	 * 'finger up' event, which will always cause a timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	return -ENOMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) static void goodix_ts_report_touch_8b(struct goodix_ts_data *ts, u8 *coor_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	int id = coor_data[0] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	int input_x = get_unaligned_le16(&coor_data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	int input_y = get_unaligned_le16(&coor_data[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	int input_w = get_unaligned_le16(&coor_data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	input_mt_slot(ts->input_dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	touchscreen_report_pos(ts->input_dev, &ts->prop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 			       input_x, input_y, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	int id = coor_data[1] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	int input_x = get_unaligned_le16(&coor_data[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	int input_y = get_unaligned_le16(&coor_data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	int input_w = get_unaligned_le16(&coor_data[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	input_mt_slot(ts->input_dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	touchscreen_report_pos(ts->input_dev, &ts->prop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			       input_x, input_y, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) static void goodix_ts_report_key(struct goodix_ts_data *ts, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	int touch_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	u8 key_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	if (data[0] & GOODIX_HAVE_KEY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		touch_num = data[0] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		key_value = data[1 + ts->contact_size * touch_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		for (i = 0; i < GOODIX_MAX_KEYS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			if (key_value & BIT(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 				input_report_key(ts->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 						 ts->keymap[i], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		for (i = 0; i < GOODIX_MAX_KEYS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 			input_report_key(ts->input_dev, ts->keymap[i], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	}
^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)  * goodix_process_events - Process incoming events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399)  * @ts: our goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401)  * Called when the IRQ is triggered. Read the current device state, and push
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402)  * the input events to the user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) static void goodix_process_events(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	u8  point_data[2 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	int touch_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	touch_num = goodix_ts_read_input_report(ts, point_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	if (touch_num < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	goodix_ts_report_key(ts, point_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	for (i = 0; i < touch_num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		if (ts->contact_size == 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 			goodix_ts_report_touch_9b(ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 				&point_data[1 + ts->contact_size * i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			goodix_ts_report_touch_8b(ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 				&point_data[1 + ts->contact_size * i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	input_mt_sync_frame(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	input_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429)  * goodix_ts_irq_handler - The IRQ handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431)  * @irq: interrupt number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432)  * @dev_id: private data pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	struct goodix_ts_data *ts = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	goodix_process_events(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	if (goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		dev_err(&ts->client->dev, "I2C write end_cmd error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) static void goodix_free_irq(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	devm_free_irq(&ts->client->dev, ts->client->irq, ts);
^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) static int goodix_request_irq(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 					 NULL, goodix_ts_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 					 ts->irq_flags, ts->client->name, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) static int goodix_check_cfg_8(struct goodix_ts_data *ts, const u8 *cfg, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	int i, raw_cfg_len = len - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	u8 check_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	for (i = 0; i < raw_cfg_len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		check_sum += cfg[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	check_sum = (~check_sum) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	if (check_sum != cfg[raw_cfg_len]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 			"The checksum of the config fw is not correct");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	if (cfg[raw_cfg_len + 1] != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 			"Config fw must have Config_Fresh register set");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) static void goodix_calc_cfg_checksum_8(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	int i, raw_cfg_len = ts->chip->config_len - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	u8 check_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	for (i = 0; i < raw_cfg_len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		check_sum += ts->config[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	check_sum = (~check_sum) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	ts->config[raw_cfg_len] = check_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	ts->config[raw_cfg_len + 1] = 1; /* Set "config_fresh" bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) static int goodix_check_cfg_16(struct goodix_ts_data *ts, const u8 *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			       int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	int i, raw_cfg_len = len - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	u16 check_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	for (i = 0; i < raw_cfg_len; i += 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		check_sum += get_unaligned_be16(&cfg[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	check_sum = (~check_sum) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	if (check_sum != get_unaligned_be16(&cfg[raw_cfg_len])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			"The checksum of the config fw is not correct");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	if (cfg[raw_cfg_len + 2] != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			"Config fw must have Config_Fresh register set");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) static void goodix_calc_cfg_checksum_16(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	int i, raw_cfg_len = ts->chip->config_len - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	u16 check_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	for (i = 0; i < raw_cfg_len; i += 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		check_sum += get_unaligned_be16(&ts->config[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	check_sum = (~check_sum) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	put_unaligned_be16(check_sum, &ts->config[raw_cfg_len]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	ts->config[raw_cfg_len + 2] = 1; /* Set "config_fresh" bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  * goodix_check_cfg - Checks if config fw is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534)  * @ts: goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535)  * @cfg: firmware config data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) static int goodix_check_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	if (len < GOODIX_CONFIG_MIN_LENGTH ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	    len > GOODIX_CONFIG_MAX_LENGTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 			"The length of the config fw is not correct");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	return ts->chip->check_config(ts, cfg, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550)  * goodix_send_cfg - Write fw config to device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552)  * @ts: goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553)  * @cfg: config firmware to write to device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) static int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	error = goodix_check_cfg(ts, cfg, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		dev_err(&ts->client->dev, "Failed to write config data: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	dev_dbg(&ts->client->dev, "Config sent successfully.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	/* Let the firmware reconfigure itself, so sleep for 10ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	usleep_range(10000, 11000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) #ifdef ACPI_GPIO_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) static int goodix_pin_acpi_direction_input(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	acpi_handle handle = ACPI_HANDLE(&ts->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	status = acpi_evaluate_object(handle, "INTI", NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	return ACPI_SUCCESS(status) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) static int goodix_pin_acpi_output_method(struct goodix_ts_data *ts, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	acpi_handle handle = ACPI_HANDLE(&ts->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	status = acpi_execute_simple_method(handle, "INTO", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	return ACPI_SUCCESS(status) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) static int goodix_pin_acpi_direction_input(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		"%s called on device without ACPI support\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) static int goodix_pin_acpi_output_method(struct goodix_ts_data *ts, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		"%s called on device without ACPI support\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) static int goodix_irq_direction_output(struct goodix_ts_data *ts, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	switch (ts->irq_pin_access_method) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	case IRQ_PIN_ACCESS_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			"%s called without an irq_pin_access_method set\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	case IRQ_PIN_ACCESS_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		return gpiod_direction_output(ts->gpiod_int, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	case IRQ_PIN_ACCESS_ACPI_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		 * The IRQ pin triggers on a falling edge, so its gets marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		 * as active-low, use output_raw to avoid the value inversion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		return gpiod_direction_output_raw(ts->gpiod_int, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	case IRQ_PIN_ACCESS_ACPI_METHOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		return goodix_pin_acpi_output_method(ts, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	return -EINVAL; /* Never reached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) static int goodix_irq_direction_input(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	switch (ts->irq_pin_access_method) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	case IRQ_PIN_ACCESS_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 			"%s called without an irq_pin_access_method set\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	case IRQ_PIN_ACCESS_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		return gpiod_direction_input(ts->gpiod_int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	case IRQ_PIN_ACCESS_ACPI_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		return gpiod_direction_input(ts->gpiod_int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	case IRQ_PIN_ACCESS_ACPI_METHOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		return goodix_pin_acpi_direction_input(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	return -EINVAL; /* Never reached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) static int goodix_int_sync(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	error = goodix_irq_direction_output(ts, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	msleep(50);				/* T5: 50ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	error = goodix_irq_direction_input(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671)  * goodix_reset - Reset device during power on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673)  * @ts: goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) static int goodix_reset(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	/* begin select I2C slave addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	error = gpiod_direction_output(ts->gpiod_rst, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	msleep(20);				/* T2: > 10ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	/* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	error = goodix_irq_direction_output(ts, ts->client->addr == 0x14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	usleep_range(100, 2000);		/* T3: > 100us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	error = gpiod_direction_output(ts->gpiod_rst, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	usleep_range(6000, 10000);		/* T4: > 5ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	/* end select I2C slave addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	error = gpiod_direction_input(ts->gpiod_rst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	error = goodix_int_sync(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) #ifdef ACPI_GPIO_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) #include <asm/cpu_device_id.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) #include <asm/intel-family.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) static const struct x86_cpu_id baytrail_cpu_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT, X86_FEATURE_ANY, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) static inline bool is_byt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	const struct x86_cpu_id *id = x86_match_cpu(baytrail_cpu_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	return !!id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) static const struct acpi_gpio_params first_gpio = { 0, 0, false };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) static const struct acpi_gpio_params second_gpio = { 1, 0, false };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) static const struct acpi_gpio_mapping acpi_goodix_int_first_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	{ GOODIX_GPIO_INT_NAME "-gpios", &first_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	{ GOODIX_GPIO_RST_NAME "-gpios", &second_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) static const struct acpi_gpio_mapping acpi_goodix_int_last_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	{ GOODIX_GPIO_RST_NAME "-gpios", &first_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	{ GOODIX_GPIO_INT_NAME "-gpios", &second_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) static const struct acpi_gpio_mapping acpi_goodix_reset_only_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	{ GOODIX_GPIO_RST_NAME "-gpios", &first_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) static int goodix_resource(struct acpi_resource *ares, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	struct goodix_ts_data *ts = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	struct device *dev = &ts->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	struct acpi_resource_gpio *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	switch (ares->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	case ACPI_RESOURCE_TYPE_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		gpio = &ares->data.gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			if (ts->gpio_int_idx == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 				ts->gpio_int_idx = ts->gpio_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 				dev_err(dev, "More then one GpioInt resource, ignoring ACPI GPIO resources\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 				ts->gpio_int_idx = -2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		ts->gpio_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774)  * This function gets called in case we fail to get the irq GPIO directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775)  * because the ACPI tables lack GPIO-name to APCI _CRS index mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776)  * (no _DSD UUID daffd814-6eba-4d8c-8a91-bc9bbf4aa301 data).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777)  * In that case we add our own mapping and then goodix_get_gpio_config()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778)  * retries to get the GPIOs based on the added mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	const struct acpi_gpio_mapping *gpio_mapping = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	struct device *dev = &ts->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	LIST_HEAD(resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	ts->gpio_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	ts->gpio_int_idx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	ret = acpi_dev_get_resources(ACPI_COMPANION(dev), &resources,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 				     goodix_resource, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		dev_err(dev, "Error getting ACPI resources: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	acpi_dev_free_resource_list(&resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	if (ts->gpio_count == 2 && ts->gpio_int_idx == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_GPIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		gpio_mapping = acpi_goodix_int_first_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	} else if (ts->gpio_count == 2 && ts->gpio_int_idx == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_GPIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		gpio_mapping = acpi_goodix_int_last_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	} else if (ts->gpio_count == 1 && ts->gpio_int_idx == -1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		   acpi_has_method(ACPI_HANDLE(dev), "INTI") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		   acpi_has_method(ACPI_HANDLE(dev), "INTO")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		dev_info(dev, "Using ACPI INTI and INTO methods for IRQ pin access\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_METHOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		gpio_mapping = acpi_goodix_reset_only_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	} else if (is_byt() && ts->gpio_count == 2 && ts->gpio_int_idx == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		dev_info(dev, "No ACPI GpioInt resource, assuming that the GPIO order is reset, int\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_GPIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		gpio_mapping = acpi_goodix_int_last_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		dev_warn(dev, "Unexpected ACPI resources: gpio_count %d, gpio_int_idx %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 			 ts->gpio_count, ts->gpio_int_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	return devm_acpi_dev_add_driver_gpios(dev, gpio_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) #endif /* CONFIG_X86 && CONFIG_ACPI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830)  * goodix_get_gpio_config - Get GPIO config from ACPI/DT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832)  * @ts: goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) static int goodix_get_gpio_config(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	struct gpio_desc *gpiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	bool added_acpi_mappings = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	if (!ts->client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	dev = &ts->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	ts->avdd28 = devm_regulator_get(dev, "AVDD28");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	if (IS_ERR(ts->avdd28)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		error = PTR_ERR(ts->avdd28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 				"Failed to get AVDD28 regulator: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	ts->vddio = devm_regulator_get(dev, "VDDIO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	if (IS_ERR(ts->vddio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		error = PTR_ERR(ts->vddio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 				"Failed to get VDDIO regulator: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) retry_get_irq_gpio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	/* Get the interrupt GPIO pin number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_INT_NAME, GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	if (IS_ERR(gpiod)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		error = PTR_ERR(gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 			dev_dbg(dev, "Failed to get %s GPIO: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 				GOODIX_GPIO_INT_NAME, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	if (!gpiod && has_acpi_companion(dev) && !added_acpi_mappings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		added_acpi_mappings = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		if (goodix_add_acpi_gpio_mappings(ts) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 			goto retry_get_irq_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	ts->gpiod_int = gpiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	/* Get the reset line GPIO pin number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_RST_NAME, GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	if (IS_ERR(gpiod)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		error = PTR_ERR(gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 			dev_dbg(dev, "Failed to get %s GPIO: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 				GOODIX_GPIO_RST_NAME, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	ts->gpiod_rst = gpiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	switch (ts->irq_pin_access_method) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	case IRQ_PIN_ACCESS_ACPI_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		 * We end up here if goodix_add_acpi_gpio_mappings() has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		 * called devm_acpi_dev_add_driver_gpios() because the ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		 * tables did not contain name to index mappings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		 * Check that we successfully got both GPIOs after we've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		 * added our own acpi_gpio_mapping and if we did not get both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		 * GPIOs reset irq_pin_access_method to IRQ_PIN_ACCESS_NONE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		if (!ts->gpiod_int || !ts->gpiod_rst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 			ts->irq_pin_access_method = IRQ_PIN_ACCESS_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	case IRQ_PIN_ACCESS_ACPI_METHOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		if (!ts->gpiod_rst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 			ts->irq_pin_access_method = IRQ_PIN_ACCESS_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		if (ts->gpiod_int && ts->gpiod_rst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 			ts->reset_controller_at_probe = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 			ts->load_cfg_from_disk = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 			ts->irq_pin_access_method = IRQ_PIN_ACCESS_GPIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922)  * goodix_read_config - Read the embedded configuration of the panel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924)  * @ts: our goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926)  * Must be called during probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) static void goodix_read_config(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	int x_max, y_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	error = goodix_i2c_read(ts->client, ts->chip->config_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 				ts->config, ts->chip->config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		dev_warn(&ts->client->dev, "Error reading config: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 			 error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		ts->int_trigger_type = GOODIX_INT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		ts->max_touch_num = GOODIX_MAX_CONTACTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	ts->int_trigger_type = ts->config[TRIGGER_LOC] & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	ts->max_touch_num = ts->config[MAX_CONTACTS_LOC] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	x_max = get_unaligned_le16(&ts->config[RESOLUTION_LOC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	y_max = get_unaligned_le16(&ts->config[RESOLUTION_LOC + 2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	if (x_max && y_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		input_abs_set_max(ts->input_dev, ABS_MT_POSITION_X, x_max - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		input_abs_set_max(ts->input_dev, ABS_MT_POSITION_Y, y_max - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	ts->chip->calc_config_checksum(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957)  * goodix_read_version - Read goodix touchscreen version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959)  * @ts: our goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) static int goodix_read_version(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	u8 buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	char id_str[GOODIX_ID_MAX_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	error = goodix_i2c_read(ts->client, GOODIX_REG_ID, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		dev_err(&ts->client->dev, "read version failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	memcpy(id_str, buf, GOODIX_ID_MAX_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	id_str[GOODIX_ID_MAX_LEN] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	strscpy(ts->id, id_str, GOODIX_ID_MAX_LEN + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	ts->version = get_unaligned_le16(&buf[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	dev_info(&ts->client->dev, "ID %s, version: %04x\n", ts->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		 ts->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986)  * goodix_i2c_test - I2C test function to check if the device answers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988)  * @client: the i2c client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) static int goodix_i2c_test(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	int retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	u8 test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	while (retry++ < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		error = goodix_i2c_read(client, GOODIX_REG_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 					&test, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		dev_err(&client->dev, "i2c test failed attempt %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 			retry, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)  * goodix_configure_dev - Finish device initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  * @ts: our goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)  * Must be called from probe to finish initialization of the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)  * Contains the common initialization code for both devices that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)  * declare gpio pins and devices that do not. It is either called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)  * directly from probe or from request_firmware_wait callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) static int goodix_configure_dev(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	ts->int_trigger_type = GOODIX_INT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	ts->max_touch_num = GOODIX_MAX_CONTACTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	ts->input_dev = devm_input_allocate_device(&ts->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	if (!ts->input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		dev_err(&ts->client->dev, "Failed to allocate input device.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	ts->input_dev->name = "Goodix Capacitive TouchScreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	ts->input_dev->phys = "input/ts";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	ts->input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	ts->input_dev->id.vendor = 0x0416;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	if (kstrtou16(ts->id, 10, &ts->input_dev->id.product))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		ts->input_dev->id.product = 0x1001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	ts->input_dev->id.version = ts->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	ts->input_dev->keycode = ts->keymap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	ts->input_dev->keycodesize = sizeof(ts->keymap[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	ts->input_dev->keycodemax = GOODIX_MAX_KEYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	/* Capacitive Windows/Home button on some devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	for (i = 0; i < GOODIX_MAX_KEYS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		if (i == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 			ts->keymap[i] = KEY_LEFTMETA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 			ts->keymap[i] = KEY_F1 + (i - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		input_set_capability(ts->input_dev, EV_KEY, ts->keymap[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	/* Read configuration and apply touchscreen parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	goodix_read_config(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	/* Try overriding touchscreen parameters via device properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	touchscreen_parse_properties(ts->input_dev, true, &ts->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	if (!ts->prop.max_x || !ts->prop.max_y || !ts->max_touch_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 			"Invalid config (%d, %d, %d), using defaults\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 			ts->prop.max_x, ts->prop.max_y, ts->max_touch_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		ts->prop.max_x = GOODIX_MAX_WIDTH - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		ts->prop.max_y = GOODIX_MAX_HEIGHT - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		ts->max_touch_num = GOODIX_MAX_CONTACTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		input_abs_set_max(ts->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 				  ABS_MT_POSITION_X, ts->prop.max_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		input_abs_set_max(ts->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 				  ABS_MT_POSITION_Y, ts->prop.max_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	if (dmi_check_system(nine_bytes_report)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		ts->contact_size = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		dev_dbg(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 			"Non-standard 9-bytes report format quirk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	if (dmi_check_system(inverted_x_screen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		ts->prop.invert_x = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		dev_dbg(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 			"Applying 'inverted x screen' quirk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	error = input_mt_init_slots(ts->input_dev, ts->max_touch_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 				    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 			"Failed to initialize MT slots: %d", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	error = input_register_device(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		dev_err(&ts->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			"Failed to register input device: %d", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	ts->irq_flags = goodix_irq_flags[ts->int_trigger_type] | IRQF_ONESHOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	error = goodix_request_irq(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		dev_err(&ts->client->dev, "request IRQ failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)  * goodix_config_cb - Callback to finish device init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)  * @ts: our goodix_ts_data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)  * request_firmware_wait callback that finishes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  * initialization of the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static void goodix_config_cb(const struct firmware *cfg, void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	struct goodix_ts_data *ts = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	if (cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		/* send device configuration to the firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		error = goodix_send_cfg(ts, cfg->data, cfg->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 			goto err_release_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	goodix_configure_dev(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) err_release_cfg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	release_firmware(cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	complete_all(&ts->firmware_loading_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static void goodix_disable_regulators(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	struct goodix_ts_data *ts = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	regulator_disable(ts->vddio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	regulator_disable(ts->avdd28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) static int goodix_ts_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 			   const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	struct goodix_ts_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	dev_dbg(&client->dev, "I2C Address: 0x%02x\n", client->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		dev_err(&client->dev, "I2C check functionality failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	if (!ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	i2c_set_clientdata(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	init_completion(&ts->firmware_loading_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	ts->contact_size = GOODIX_CONTACT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	error = goodix_get_gpio_config(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	/* power up the controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	error = regulator_enable(ts->avdd28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 			"Failed to enable AVDD28 regulator: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	error = regulator_enable(ts->vddio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 			"Failed to enable VDDIO regulator: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		regulator_disable(ts->avdd28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	error = devm_add_action_or_reset(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 					 goodix_disable_regulators, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	if (ts->reset_controller_at_probe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		/* reset the controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		error = goodix_reset(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 			dev_err(&client->dev, "Controller reset failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	error = goodix_i2c_test(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		if (!ts->reset_controller_at_probe &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		    ts->irq_pin_access_method != IRQ_PIN_ACCESS_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 			/* Retry after a controller reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 			ts->reset_controller_at_probe = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 			goto reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		dev_err(&client->dev, "I2C communication failure: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	error = goodix_read_version(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		dev_err(&client->dev, "Read version failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	ts->chip = goodix_get_chip_data(ts->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	if (ts->load_cfg_from_disk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		/* update device config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 					      "goodix_%s_cfg.bin", ts->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		if (!ts->cfg_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 		error = request_firmware_nowait(THIS_MODULE, true, ts->cfg_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 						&client->dev, GFP_KERNEL, ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 						goodix_config_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 			dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 				"Failed to invoke firmware loader: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 				error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		error = goodix_configure_dev(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) static int goodix_ts_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	if (ts->load_cfg_from_disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		wait_for_completion(&ts->firmware_loading_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) static int __maybe_unused goodix_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	if (ts->load_cfg_from_disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		wait_for_completion(&ts->firmware_loading_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	/* We need gpio pins to suspend/resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	/* Free IRQ as IRQ pin is used as output in the suspend sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	goodix_free_irq(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	/* Output LOW on the INT pin for 5 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	error = goodix_irq_direction_output(ts, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		goodix_request_irq(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	usleep_range(5000, 6000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	error = goodix_i2c_write_u8(ts->client, GOODIX_REG_COMMAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 				    GOODIX_CMD_SCREEN_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		dev_err(&ts->client->dev, "Screen off command failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		goodix_irq_direction_input(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		goodix_request_irq(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	 * The datasheet specifies that the interval between sending screen-off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	 * command and wake-up should be longer than 58 ms. To avoid waking up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	 * sooner, delay 58ms here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	msleep(58);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) static int __maybe_unused goodix_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	u8 config_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	 * Exit sleep mode by outputting HIGH level to INT pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	 * for 2ms~5ms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	error = goodix_irq_direction_output(ts, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	usleep_range(2000, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	error = goodix_int_sync(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	error = goodix_i2c_read(ts->client, ts->chip->config_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 				&config_ver, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		dev_warn(dev, "Error reading config version: %d, resetting controller\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 			 error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	else if (config_ver != ts->config[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		dev_info(dev, "Config version mismatch %d != %d, resetting controller\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 			 config_ver, ts->config[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	if (error != 0 || config_ver != ts->config[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		error = goodix_reset(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			dev_err(dev, "Controller reset failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		error = goodix_send_cfg(ts, ts->config, ts->chip->config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	error = goodix_request_irq(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) static SIMPLE_DEV_PM_OPS(goodix_pm_ops, goodix_suspend, goodix_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) static const struct i2c_device_id goodix_ts_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	{ "GDIX1001:00", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) MODULE_DEVICE_TABLE(i2c, goodix_ts_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) static const struct acpi_device_id goodix_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	{ "GDIX1001", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	{ "GDIX1002", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) MODULE_DEVICE_TABLE(acpi, goodix_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) static const struct of_device_id goodix_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	{ .compatible = "goodix,gt1151" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	{ .compatible = "goodix,gt5663" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	{ .compatible = "goodix,gt5688" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	{ .compatible = "goodix,gt911" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	{ .compatible = "goodix,gt9110" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	{ .compatible = "goodix,gt912" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	{ .compatible = "goodix,gt9147" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	{ .compatible = "goodix,gt917s" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	{ .compatible = "goodix,gt927" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	{ .compatible = "goodix,gt9271" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	{ .compatible = "goodix,gt928" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	{ .compatible = "goodix,gt9286" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	{ .compatible = "goodix,gt967" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) MODULE_DEVICE_TABLE(of, goodix_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) static struct i2c_driver goodix_ts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	.probe = goodix_ts_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	.remove = goodix_ts_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	.id_table = goodix_ts_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		.name = "Goodix-TS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		.acpi_match_table = ACPI_PTR(goodix_acpi_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		.of_match_table = of_match_ptr(goodix_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		.pm = &goodix_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) module_i2c_driver(goodix_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) MODULE_AUTHOR("Bastien Nocera <hadess@hadess.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) MODULE_DESCRIPTION("Goodix touchscreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) MODULE_LICENSE("GPL v2");