focaltech_common.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. *
  3. * FocalTech fts TouchScreen driver.
  4. *
  5. * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved.
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. /*****************************************************************************
  18. *
  19. * File Name: focaltech_common.h
  20. *
  21. * Author: Focaltech Driver Team
  22. *
  23. * Created: 2016-08-16
  24. *
  25. * Abstract:
  26. *
  27. * Reference:
  28. *
  29. *****************************************************************************/
  30. #ifndef __LINUX_FOCALTECH_COMMON_H__
  31. #define __LINUX_FOCALTECH_COMMON_H__
  32. #include "focaltech_config.h"
  33. /*****************************************************************************
  34. * Macro definitions using #define
  35. *****************************************************************************/
  36. #define FTS_DRIVER_VERSION "Focaltech V3.2 20200422"
  37. #define BYTE_OFF_0(x) (u8)((x) & 0xFF)
  38. #define BYTE_OFF_8(x) (u8)(((x) >> 8) & 0xFF)
  39. #define BYTE_OFF_16(x) (u8)(((x) >> 16) & 0xFF)
  40. #define BYTE_OFF_24(x) (u8)(((x) >> 24) & 0xFF)
  41. #define FLAGBIT(x) (0x00000001 << (x))
  42. #define FLAGBITS(x, y) ((0xFFFFFFFF >> (32 - (y) - 1)) & (0xFFFFFFFF << (x)))
  43. #define FLAG_ICSERIALS_LEN 8
  44. #define FLAG_HID_BIT 10
  45. #define FLAG_IDC_BIT 11
  46. #define IC_SERIALS(type) ((type) & FLAGBITS(0, FLAG_ICSERIALS_LEN-1))
  47. #define IC_TO_SERIALS(x) ((x) & FLAGBITS(0, FLAG_ICSERIALS_LEN-1))
  48. #define FTS_CHIP_IDC(type) (((type) & FLAGBIT(FLAG_IDC_BIT)) == FLAGBIT(FLAG_IDC_BIT))
  49. #define FTS_HID_SUPPORTTED(type) (((type) & FLAGBIT(FLAG_HID_BIT)) == FLAGBIT(FLAG_HID_BIT))
  50. #define FILE_NAME_LENGTH 128
  51. #define ENABLE 1
  52. #define DISABLE 0
  53. #define VALID 1
  54. #define INVALID 0
  55. #define FTS_CMD_START1 0x55
  56. #define FTS_CMD_START2 0xAA
  57. #define FTS_CMD_START_DELAY 12
  58. #define FTS_CMD_READ_ID 0x90
  59. #define FTS_CMD_READ_ID_LEN 4
  60. #define FTS_CMD_READ_ID_LEN_INCELL 1
  61. #define FTS_CMD_READ_FW_CONF 0xA8
  62. /*register address*/
  63. #define FTS_REG_INT_CNT 0x8F
  64. #define FTS_REG_FLOW_WORK_CNT 0x91
  65. #define FTS_REG_WORKMODE 0x00
  66. #define FTS_REG_WORKMODE_FACTORY_VALUE 0x40
  67. #define FTS_REG_WORKMODE_WORK_VALUE 0x00
  68. #define FTS_REG_ESDCHECK_DISABLE 0x8D
  69. #define FTS_REG_CHIP_ID 0xA3
  70. #define FTS_REG_CHIP_ID2 0x9F
  71. #define FTS_REG_POWER_MODE 0xA5
  72. #define FTS_REG_POWER_MODE_SLEEP 0x03
  73. #define FTS_REG_FW_VER 0xA6
  74. #define FTS_REG_VENDOR_ID 0xA8
  75. #define FTS_REG_LCD_BUSY_NUM 0xAB
  76. #define FTS_REG_FACE_DEC_MODE_EN 0xB0
  77. #define FTS_REG_FACTORY_MODE_DETACH_FLAG 0xB4
  78. #define FTS_REG_FACE_DEC_MODE_STATUS 0x01
  79. #define FTS_REG_IDE_PARA_VER_ID 0xB5
  80. #define FTS_REG_IDE_PARA_STATUS 0xB6
  81. #define FTS_REG_GLOVE_MODE_EN 0xC0
  82. #define FTS_REG_COVER_MODE_EN 0xC1
  83. #define FTS_REG_REPORT_RATE 0x88
  84. #define FTS_REG_CHARGER_MODE_EN 0x8B
  85. #define FTS_REG_GESTURE_EN 0xD0
  86. #define FTS_REG_GESTURE_OUTPUT_ADDRESS 0xD3
  87. #define FTS_REG_MODULE_ID 0xE3
  88. #define FTS_REG_LIC_VER 0xE4
  89. #define FTS_REG_ESD_SATURATE 0xED
  90. #define FTS_SYSFS_ECHO_ON(buf) (buf[0] == '1')
  91. #define FTS_SYSFS_ECHO_OFF(buf) (buf[0] == '0')
  92. #define kfree_safe(pbuf) do {\
  93. if (pbuf) {\
  94. kfree(pbuf);\
  95. pbuf = NULL;\
  96. }\
  97. } while(0)
  98. /*****************************************************************************
  99. * Alternative mode (When something goes wrong,
  100. * the modules may be able to solve the problem.)
  101. *****************************************************************************/
  102. /*
  103. * point report check
  104. * default: disable
  105. */
  106. #define FTS_POINT_REPORT_CHECK_EN 0
  107. /*****************************************************************************
  108. * Global variable or extern global variabls/functions
  109. *****************************************************************************/
  110. struct ft_chip_t {
  111. u64 type;
  112. u8 chip_idh;
  113. u8 chip_idl;
  114. u8 rom_idh;
  115. u8 rom_idl;
  116. u8 pb_idh;
  117. u8 pb_idl;
  118. u8 bl_idh;
  119. u8 bl_idl;
  120. };
  121. struct ts_ic_info {
  122. bool is_incell;
  123. bool hid_supported;
  124. struct ft_chip_t ids;
  125. };
  126. /*****************************************************************************
  127. * DEBUG function define here
  128. *****************************************************************************/
  129. #if FTS_DEBUG_EN
  130. #define FTS_DEBUG(fmt, args...) do { \
  131. printk("[FTS_TS]%s:"fmt"\n", __func__, ##args); \
  132. } while (0)
  133. #define FTS_FUNC_ENTER() do { \
  134. printk("[FTS_TS]%s: Enter\n", __func__); \
  135. } while (0)
  136. #define FTS_FUNC_EXIT() do { \
  137. printk("[FTS_TS]%s: Exit(%d)\n", __func__, __LINE__); \
  138. } while (0)
  139. #else /* #if FTS_DEBUG_EN*/
  140. #define FTS_DEBUG(fmt, args...)
  141. #define FTS_FUNC_ENTER()
  142. #define FTS_FUNC_EXIT()
  143. #endif
  144. #define FTS_INFO(fmt, args...) do { \
  145. printk(KERN_INFO "[FTS_TS/I]%s:"fmt"\n", __func__, ##args); \
  146. } while (0)
  147. #define FTS_ERROR(fmt, args...) do { \
  148. printk(KERN_ERR "[FTS_TS/E]%s:"fmt"\n", __func__, ##args); \
  149. } while (0)
  150. #endif /* __LINUX_FOCALTECH_COMMON_H__ */