goodix.h 3.5 KB

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