blob: 02065d1c326354a87aa3f1270c7435115d621223 [file] [log] [blame]
Hans de Goedea2233cb2021-09-20 21:08:18 -07001/* 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 */
Hans de Goede09182ed2021-09-20 21:08:53 -070013#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
Hans de Goedea2233cb2021-09-20 21:08:18 -070030#define GOODIX_REG_COMMAND 0x8040
31#define GOODIX_CMD_SCREEN_OFF 0x05
32
Hans de Goede09182ed2021-09-20 21:08:53 -070033#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
Hans de Goedea2233cb2021-09-20 21:08:18 -070050#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
Hans de Goede09182ed2021-09-20 21:08:53 -070054#define GOODIX_REG_BAK_REF 0x99D0
Hans de Goedea2233cb2021-09-20 21:08:18 -070055
56#define GOODIX_ID_MAX_LEN 4
57#define GOODIX_CONFIG_MAX_LENGTH 240
58#define GOODIX_MAX_KEYS 7
59
60enum 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
67struct goodix_ts_data;
68
69struct 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
76struct goodix_ts_data {
77 struct i2c_client *client;
78 struct input_dev *input_dev;
79 const struct goodix_chip_data *chip;
Hans de Goede09182ed2021-09-20 21:08:53 -070080 const char *firmware_name;
Hans de Goedea2233cb2021-09-20 21:08:18 -070081 struct touchscreen_properties prop;
82 unsigned int max_touch_num;
83 unsigned int int_trigger_type;
84 struct regulator *avdd28;
85 struct regulator *vddio;
86 struct gpio_desc *gpiod_int;
87 struct gpio_desc *gpiod_rst;
88 int gpio_count;
89 int gpio_int_idx;
Hans de Goedea2fd46c2021-12-06 23:15:09 -080090 enum gpiod_flags gpiod_rst_flags;
Hans de Goedea2233cb2021-09-20 21:08:18 -070091 char id[GOODIX_ID_MAX_LEN + 1];
Hans de Goede20e31722021-09-20 21:08:44 -070092 char cfg_name[64];
Hans de Goedea2233cb2021-09-20 21:08:18 -070093 u16 version;
Hans de Goedea2233cb2021-09-20 21:08:18 -070094 bool reset_controller_at_probe;
95 bool load_cfg_from_disk;
96 struct completion firmware_loading_complete;
97 unsigned long irq_flags;
98 enum goodix_irq_pin_access_method irq_pin_access_method;
99 unsigned int contact_size;
100 u8 config[GOODIX_CONFIG_MAX_LENGTH];
101 unsigned short keymap[GOODIX_MAX_KEYS];
Hans de Goede09182ed2021-09-20 21:08:53 -0700102 u8 main_clk[GOODIX_MAIN_CLK_LEN];
103 int bak_ref_len;
104 u8 *bak_ref;
Hans de Goedea2233cb2021-09-20 21:08:18 -0700105};
106
107int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len);
108int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, int len);
109int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value);
110int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len);
111int goodix_int_sync(struct goodix_ts_data *ts);
Hans de Goede209bda42021-09-20 21:08:26 -0700112int goodix_reset_no_int_sync(struct goodix_ts_data *ts);
Hans de Goedea2233cb2021-09-20 21:08:18 -0700113
Hans de Goede09182ed2021-09-20 21:08:53 -0700114int goodix_firmware_check(struct goodix_ts_data *ts);
115bool goodix_handle_fw_request(struct goodix_ts_data *ts);
116void goodix_save_bak_ref(struct goodix_ts_data *ts);
117
Hans de Goedea2233cb2021-09-20 21:08:18 -0700118#endif