xref: /linux/drivers/input/touchscreen/goodix.h (revision 16018c0d27eda6a7f69dafa750d23770fb46b00f)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __GOODIX_H__
3 #define __GOODIX_H__
4 
5 #include <linux/gpio/consumer.h>
6 #include <linux/i2c.h>
7 #include <linux/input.h>
8 #include <linux/input/mt.h>
9 #include <linux/input/touchscreen.h>
10 #include <linux/regulator/consumer.h>
11 
12 /* Register defines */
13 #define GOODIX_REG_MISCTL_DSP_CTL		0x4010
14 #define GOODIX_REG_MISCTL_SRAM_BANK		0x4048
15 #define GOODIX_REG_MISCTL_MEM_CD_EN		0x4049
16 #define GOODIX_REG_MISCTL_CACHE_EN		0x404B
17 #define GOODIX_REG_MISCTL_TMR0_EN		0x40B0
18 #define GOODIX_REG_MISCTL_SWRST			0x4180
19 #define GOODIX_REG_MISCTL_CPU_SWRST_PULSE	0x4184
20 #define GOODIX_REG_MISCTL_BOOTCTL		0x4190
21 #define GOODIX_REG_MISCTL_BOOT_OPT		0x4218
22 #define GOODIX_REG_MISCTL_BOOT_CTL		0x5094
23 
24 #define GOODIX_REG_FW_SIG			0x8000
25 #define GOODIX_FW_SIG_LEN			10
26 
27 #define GOODIX_REG_MAIN_CLK			0x8020
28 #define GOODIX_MAIN_CLK_LEN			6
29 
30 #define GOODIX_REG_COMMAND			0x8040
31 #define GOODIX_CMD_SCREEN_OFF			0x05
32 
33 #define GOODIX_REG_SW_WDT			0x8041
34 
35 #define GOODIX_REG_REQUEST			0x8043
36 #define GOODIX_RQST_RESPONDED			0x00
37 #define GOODIX_RQST_CONFIG			0x01
38 #define GOODIX_RQST_BAK_REF			0x02
39 #define GOODIX_RQST_RESET			0x03
40 #define GOODIX_RQST_MAIN_CLOCK			0x04
41 /*
42  * Unknown request which gets send by the controller aprox.
43  * every 34 seconds once it is up and running.
44  */
45 #define GOODIX_RQST_UNKNOWN			0x06
46 #define GOODIX_RQST_IDLE			0xFF
47 
48 #define GOODIX_REG_STATUS			0x8044
49 
50 #define GOODIX_GT1X_REG_CONFIG_DATA		0x8050
51 #define GOODIX_GT9X_REG_CONFIG_DATA		0x8047
52 #define GOODIX_REG_ID				0x8140
53 #define GOODIX_READ_COOR_ADDR			0x814E
54 #define GOODIX_REG_BAK_REF			0x99D0
55 
56 #define GOODIX_ID_MAX_LEN			4
57 #define GOODIX_CONFIG_MAX_LENGTH		240
58 #define GOODIX_MAX_KEYS				7
59 
60 enum goodix_irq_pin_access_method {
61 	IRQ_PIN_ACCESS_NONE,
62 	IRQ_PIN_ACCESS_GPIO,
63 	IRQ_PIN_ACCESS_ACPI_GPIO,
64 	IRQ_PIN_ACCESS_ACPI_METHOD,
65 };
66 
67 struct goodix_ts_data;
68 
69 struct goodix_chip_data {
70 	u16 config_addr;
71 	int config_len;
72 	int (*check_config)(struct goodix_ts_data *ts, const u8 *cfg, int len);
73 	void (*calc_config_checksum)(struct goodix_ts_data *ts);
74 };
75 
76 struct goodix_ts_data {
77 	struct i2c_client *client;
78 	struct input_dev *input_dev;
79 	struct input_dev *input_pen;
80 	const struct goodix_chip_data *chip;
81 	const char *firmware_name;
82 	struct touchscreen_properties prop;
83 	unsigned int max_touch_num;
84 	unsigned int int_trigger_type;
85 	struct regulator *avdd28;
86 	struct regulator *vddio;
87 	struct gpio_desc *gpiod_int;
88 	struct gpio_desc *gpiod_rst;
89 	int gpio_count;
90 	int gpio_int_idx;
91 	enum gpiod_flags gpiod_rst_flags;
92 	char id[GOODIX_ID_MAX_LEN + 1];
93 	char cfg_name[64];
94 	u16 version;
95 	bool reset_controller_at_probe;
96 	bool load_cfg_from_disk;
97 	struct completion firmware_loading_complete;
98 	unsigned long irq_flags;
99 	enum goodix_irq_pin_access_method irq_pin_access_method;
100 	unsigned int contact_size;
101 	u8 config[GOODIX_CONFIG_MAX_LENGTH];
102 	unsigned short keymap[GOODIX_MAX_KEYS];
103 	u8 main_clk[GOODIX_MAIN_CLK_LEN];
104 	int bak_ref_len;
105 	u8 *bak_ref;
106 };
107 
108 int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len);
109 int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, int len);
110 int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value);
111 int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len);
112 int goodix_int_sync(struct goodix_ts_data *ts);
113 int goodix_reset_no_int_sync(struct goodix_ts_data *ts);
114 
115 int goodix_firmware_check(struct goodix_ts_data *ts);
116 bool goodix_handle_fw_request(struct goodix_ts_data *ts);
117 void goodix_save_bak_ref(struct goodix_ts_data *ts);
118 
119 #endif
120