Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 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 */ |
Hans de Goede | 09182ed | 2021-09-20 21:08:53 -0700 | [diff] [blame] | 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 | |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 30 | #define GOODIX_REG_COMMAND 0x8040 |
| 31 | #define GOODIX_CMD_SCREEN_OFF 0x05 |
| 32 | |
Hans de Goede | 09182ed | 2021-09-20 21:08:53 -0700 | [diff] [blame] | 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 | |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 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 |
Hans de Goede | 09182ed | 2021-09-20 21:08:53 -0700 | [diff] [blame] | 54 | #define GOODIX_REG_BAK_REF 0x99D0 |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 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 | const struct goodix_chip_data *chip; |
Hans de Goede | 09182ed | 2021-09-20 21:08:53 -0700 | [diff] [blame] | 80 | const char *firmware_name; |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 81 | 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 Goede | a2fd46c | 2021-12-06 23:15:09 -0800 | [diff] [blame] | 90 | enum gpiod_flags gpiod_rst_flags; |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 91 | char id[GOODIX_ID_MAX_LEN + 1]; |
Hans de Goede | 20e3172 | 2021-09-20 21:08:44 -0700 | [diff] [blame] | 92 | char cfg_name[64]; |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 93 | u16 version; |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 94 | 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 Goede | 09182ed | 2021-09-20 21:08:53 -0700 | [diff] [blame] | 102 | u8 main_clk[GOODIX_MAIN_CLK_LEN]; |
| 103 | int bak_ref_len; |
| 104 | u8 *bak_ref; |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len); |
| 108 | int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, int len); |
| 109 | int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value); |
| 110 | int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len); |
| 111 | int goodix_int_sync(struct goodix_ts_data *ts); |
Hans de Goede | 209bda4 | 2021-09-20 21:08:26 -0700 | [diff] [blame] | 112 | int goodix_reset_no_int_sync(struct goodix_ts_data *ts); |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 113 | |
Hans de Goede | 09182ed | 2021-09-20 21:08:53 -0700 | [diff] [blame] | 114 | int goodix_firmware_check(struct goodix_ts_data *ts); |
| 115 | bool goodix_handle_fw_request(struct goodix_ts_data *ts); |
| 116 | void goodix_save_bak_ref(struct goodix_ts_data *ts); |
| 117 | |
Hans de Goede | a2233cb | 2021-09-20 21:08:18 -0700 | [diff] [blame] | 118 | #endif |