xref: /OK3568_Linux_fs/kernel/drivers/input/touchscreen/focaltech_touch_ft5436/focaltech_common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
31 #ifndef __LINUX_FOCALTECH_COMMON_H__
32 #define __LINUX_FOCALTECH_COMMON_H__
33 
34 #include "focaltech_config.h"
35 
36 /*****************************************************************************
37 * Macro definitions using #define
38 *****************************************************************************/
39 #define FTS_DRIVER_VERSION                  "Focaltech V3.1 20190807"
40 
41 #define BYTE_OFF_0(x)           (u8)((x) & 0xFF)
42 #define BYTE_OFF_8(x)           (u8)(((x) >> 8) & 0xFF)
43 #define BYTE_OFF_16(x)          (u8)(((x) >> 16) & 0xFF)
44 #define BYTE_OFF_24(x)          (u8)(((x) >> 24) & 0xFF)
45 #define FLAGBIT(x)              (0x00000001 << (x))
46 #define FLAGBITS(x, y)          ((0xFFFFFFFF >> (32 - (y) - 1)) & (0xFFFFFFFF << (x)))
47 
48 #define FLAG_ICSERIALS_LEN      8
49 #define FLAG_HID_BIT            10
50 #define FLAG_IDC_BIT            11
51 
52 #define IC_SERIALS              (FTS_CHIP_TYPE & FLAGBITS(0, FLAG_ICSERIALS_LEN-1))
53 #define IC_TO_SERIALS(x)        ((x) & FLAGBITS(0, FLAG_ICSERIALS_LEN-1))
54 #define FTS_CHIP_IDC            ((FTS_CHIP_TYPE & FLAGBIT(FLAG_IDC_BIT)) == FLAGBIT(FLAG_IDC_BIT))
55 #define FTS_HID_SUPPORTTED      ((FTS_CHIP_TYPE & FLAGBIT(FLAG_HID_BIT)) == FLAGBIT(FLAG_HID_BIT))
56 
57 #define FTS_CHIP_TYPE_MAPPING {{0x02, 0x54, 0x22, 0x54, 0x22, 0x00, 0x00, 0x54, 0x2C}}
58 
59 #define FILE_NAME_LENGTH                    128
60 #define ENABLE                              1
61 #define DISABLE                             0
62 #define VALID                               1
63 #define INVALID                             0
64 #define FTS_CMD_START1                      0x55
65 #define FTS_CMD_START2                      0xAA
66 #define FTS_CMD_START_DELAY                 12
67 #define FTS_CMD_READ_ID                     0x90
68 #define FTS_CMD_READ_ID_LEN                 4
69 #define FTS_CMD_READ_ID_LEN_INCELL          1
70 /*register address*/
71 #define FTS_REG_INT_CNT                     0x8F
72 #define FTS_REG_FLOW_WORK_CNT               0x91
73 #define FTS_REG_WORKMODE                    0x00
74 #define FTS_REG_WORKMODE_FACTORY_VALUE      0x40
75 #define FTS_REG_WORKMODE_WORK_VALUE         0x00
76 #define FTS_REG_ESDCHECK_DISABLE            0x8D
77 #define FTS_REG_CHIP_ID                     0xA3
78 #define FTS_REG_CHIP_ID2                    0x9F
79 #define FTS_REG_POWER_MODE                  0xA5
80 #define FTS_REG_POWER_MODE_SLEEP            0x03
81 #define FTS_REG_FW_VER                      0xA6
82 #define FTS_REG_VENDOR_ID                   0xA8
83 #define FTS_REG_LCD_BUSY_NUM                0xAB
84 #define FTS_REG_FACE_DEC_MODE_EN            0xB0
85 #define FTS_REG_FACTORY_MODE_DETACH_FLAG    0xB4
86 #define FTS_REG_FACE_DEC_MODE_STATUS        0x01
87 #define FTS_REG_IDE_PARA_VER_ID             0xB5
88 #define FTS_REG_IDE_PARA_STATUS             0xB6
89 #define FTS_REG_GLOVE_MODE_EN               0xC0
90 #define FTS_REG_COVER_MODE_EN               0xC1
91 #define FTS_REG_CHARGER_MODE_EN             0x8B
92 #define FTS_REG_GESTURE_EN                  0xD0
93 #define FTS_REG_GESTURE_OUTPUT_ADDRESS      0xD3
94 #define FTS_REG_MODULE_ID                   0xE3
95 #define FTS_REG_LIC_VER                     0xE4
96 #define FTS_REG_ESD_SATURATE                0xED
97 
98 #define FTS_SYSFS_ECHO_ON(buf)      (buf[0] == '1')
99 #define FTS_SYSFS_ECHO_OFF(buf)     (buf[0] == '0')
100 
101 #define kfree_safe(pbuf) do {\
102     if (pbuf) {\
103         kfree(pbuf);\
104         pbuf = NULL;\
105     }\
106 } while(0)
107 
108 /*****************************************************************************
109 *  Alternative mode (When something goes wrong, the modules may be able to solve the problem.)
110 *****************************************************************************/
111 /*
112  * point report check
113  * default: disable
114  */
115 #define FTS_POINT_REPORT_CHECK_EN               0
116 
117 /*****************************************************************************
118 * Global variable or extern global variabls/functions
119 *****************************************************************************/
120 struct ft_chip_t {
121     u64 type;
122     u8 chip_idh;
123     u8 chip_idl;
124     u8 rom_idh;
125     u8 rom_idl;
126     u8 pb_idh;
127     u8 pb_idl;
128     u8 bl_idh;
129     u8 bl_idl;
130 };
131 
132 struct ts_ic_info {
133     bool is_incell;
134     bool hid_supported;
135     struct ft_chip_t ids;
136 };
137 
138 /*****************************************************************************
139 * DEBUG function define here
140 *****************************************************************************/
141 #if FTS_DEBUG_EN
142 #define FTS_DEBUG(fmt, args...) do { \
143     printk("[FTS_TS]%s:"fmt"\n", __func__, ##args); \
144 } while (0)
145 
146 #define FTS_FUNC_ENTER() do { \
147     printk("[FTS_TS]%s: Enter\n", __func__); \
148 } while (0)
149 
150 #define FTS_FUNC_EXIT() do { \
151     printk("[FTS_TS]%s: Exit(%d)\n", __func__, __LINE__); \
152 } while (0)
153 #else /* #if FTS_DEBUG_EN*/
154 #define FTS_DEBUG(fmt, args...)
155 #define FTS_FUNC_ENTER()
156 #define FTS_FUNC_EXIT()
157 #endif
158 
159 #define FTS_INFO(fmt, args...) do { \
160     printk(KERN_INFO "[FTS_TS/I]%s:"fmt"\n", __func__, ##args); \
161 } while (0)
162 
163 #define FTS_ERROR(fmt, args...) do { \
164     printk(KERN_ERR "[FTS_TS/E]%s:"fmt"\n", __func__, ##args); \
165 } while (0)
166 #endif /* __LINUX_FOCALTECH_COMMON_H__ */
167