0001
0002 #ifndef __GOODIX_H__
0003 #define __GOODIX_H__
0004
0005 #include <linux/gpio/consumer.h>
0006 #include <linux/i2c.h>
0007 #include <linux/input.h>
0008 #include <linux/input/mt.h>
0009 #include <linux/input/touchscreen.h>
0010 #include <linux/regulator/consumer.h>
0011
0012
0013 #define GOODIX_REG_MISCTL_DSP_CTL 0x4010
0014 #define GOODIX_REG_MISCTL_SRAM_BANK 0x4048
0015 #define GOODIX_REG_MISCTL_MEM_CD_EN 0x4049
0016 #define GOODIX_REG_MISCTL_CACHE_EN 0x404B
0017 #define GOODIX_REG_MISCTL_TMR0_EN 0x40B0
0018 #define GOODIX_REG_MISCTL_SWRST 0x4180
0019 #define GOODIX_REG_MISCTL_CPU_SWRST_PULSE 0x4184
0020 #define GOODIX_REG_MISCTL_BOOTCTL 0x4190
0021 #define GOODIX_REG_MISCTL_BOOT_OPT 0x4218
0022 #define GOODIX_REG_MISCTL_BOOT_CTL 0x5094
0023
0024 #define GOODIX_REG_FW_SIG 0x8000
0025 #define GOODIX_FW_SIG_LEN 10
0026
0027 #define GOODIX_REG_MAIN_CLK 0x8020
0028 #define GOODIX_MAIN_CLK_LEN 6
0029
0030 #define GOODIX_REG_COMMAND 0x8040
0031 #define GOODIX_CMD_SCREEN_OFF 0x05
0032
0033 #define GOODIX_REG_SW_WDT 0x8041
0034
0035 #define GOODIX_REG_REQUEST 0x8043
0036 #define GOODIX_RQST_RESPONDED 0x00
0037 #define GOODIX_RQST_CONFIG 0x01
0038 #define GOODIX_RQST_BAK_REF 0x02
0039 #define GOODIX_RQST_RESET 0x03
0040 #define GOODIX_RQST_MAIN_CLOCK 0x04
0041
0042
0043
0044
0045 #define GOODIX_RQST_UNKNOWN 0x06
0046 #define GOODIX_RQST_IDLE 0xFF
0047
0048 #define GOODIX_REG_STATUS 0x8044
0049
0050 #define GOODIX_GT1X_REG_CONFIG_DATA 0x8050
0051 #define GOODIX_GT9X_REG_CONFIG_DATA 0x8047
0052 #define GOODIX_REG_ID 0x8140
0053 #define GOODIX_READ_COOR_ADDR 0x814E
0054 #define GOODIX_REG_BAK_REF 0x99D0
0055
0056 #define GOODIX_ID_MAX_LEN 4
0057 #define GOODIX_CONFIG_MAX_LENGTH 240
0058 #define GOODIX_MAX_KEYS 7
0059
0060 enum goodix_irq_pin_access_method {
0061 IRQ_PIN_ACCESS_NONE,
0062 IRQ_PIN_ACCESS_GPIO,
0063 IRQ_PIN_ACCESS_ACPI_GPIO,
0064 IRQ_PIN_ACCESS_ACPI_METHOD,
0065 };
0066
0067 struct goodix_ts_data;
0068
0069 struct goodix_chip_data {
0070 u16 config_addr;
0071 int config_len;
0072 int (*check_config)(struct goodix_ts_data *ts, const u8 *cfg, int len);
0073 void (*calc_config_checksum)(struct goodix_ts_data *ts);
0074 };
0075
0076 struct goodix_ts_data {
0077 struct i2c_client *client;
0078 struct input_dev *input_dev;
0079 struct input_dev *input_pen;
0080 const struct goodix_chip_data *chip;
0081 const char *firmware_name;
0082 struct touchscreen_properties prop;
0083 unsigned int max_touch_num;
0084 unsigned int int_trigger_type;
0085 struct regulator *avdd28;
0086 struct regulator *vddio;
0087 struct gpio_desc *gpiod_int;
0088 struct gpio_desc *gpiod_rst;
0089 int gpio_count;
0090 int gpio_int_idx;
0091 enum gpiod_flags gpiod_rst_flags;
0092 char id[GOODIX_ID_MAX_LEN + 1];
0093 char cfg_name[64];
0094 u16 version;
0095 bool reset_controller_at_probe;
0096 bool load_cfg_from_disk;
0097 int pen_input_registered;
0098 struct completion firmware_loading_complete;
0099 unsigned long irq_flags;
0100 enum goodix_irq_pin_access_method irq_pin_access_method;
0101 unsigned int contact_size;
0102 u8 config[GOODIX_CONFIG_MAX_LENGTH];
0103 unsigned short keymap[GOODIX_MAX_KEYS];
0104 u8 main_clk[GOODIX_MAIN_CLK_LEN];
0105 int bak_ref_len;
0106 u8 *bak_ref;
0107 };
0108
0109 int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len);
0110 int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, int len);
0111 int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value);
0112 int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len);
0113 int goodix_int_sync(struct goodix_ts_data *ts);
0114 int goodix_reset_no_int_sync(struct goodix_ts_data *ts);
0115
0116 int goodix_firmware_check(struct goodix_ts_data *ts);
0117 bool goodix_handle_fw_request(struct goodix_ts_data *ts);
0118 void goodix_save_bak_ref(struct goodix_ts_data *ts);
0119
0120 #endif