aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/mxt540s_dev.h
blob: 5400c8349119ca839280091eb96fc3de820a7209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
 *  Copyright (C) 2010, Samsung Electronics Co. Ltd. All Rights Reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 */

#ifndef __MXT_540S_DEV_H
#define __MXT_540S_DEV_H

#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif

#define OBJECT_TABLE_ELEMENT_SIZE	6
#define OBJECT_TABLE_START_ADDRESS	7

#define CMD_RESET_OFFSET		0
#define CMD_BACKUP_OFFSET		1
#define CMD_CALIBRATE_OFFSET		2
#define CMD_REPORTATLL_OFFSET		3
#define CMD_DEBUG_CTRL_OFFSET		4
#define CMD_DIAGNOSTIC_OFFSET		5

#define MXT_T7_IDLE_ACQ_INT	0
#define MXT_T7_ACT_ACQ_INT	1

#define MXT_T9_CTRL 0
#define MXT_T9_ORIENT 9
#define MXT_T9_XRANGE_LSB	18
#define MXT_T9_XRANGE_MSB	19
#define MXT_T9_YRANGE_LSB	20
#define MXT_T9_YRANGE_MSB	21

#define DETECT_MSG_MASK		0x80
#define PRESS_MSG_MASK		0x40
#define RELEASE_MSG_MASK	0x20
#define MOVE_MSG_MASK		0x10
#define VECTOR_MSG_MASK		0x08
#define AMPLITUDE_MSG_MASK	0x04
#define SUPPRESS_MSG_MASK	0x02

/* Slave addresses */
#define MXT_APP_LOW		0x4a
#define MXT_APP_HIGH		0x4b
#define MXT_BOOT_LOW		0x26
#define MXT_BOOT_HIGH		0x27

#define MXT_BOOT_VALUE		0xa5
#define MXT_BACKUP_VALUE	0x55

/* Bootloader mode status */
#define MXT_WAITING_BOOTLOAD_CMD	0xc0
#define MXT_WAITING_FRAME_DATA		0x80
#define MXT_FRAME_CRC_CHECK		0x02
#define MXT_FRAME_CRC_FAIL		0x03
#define MXT_FRAME_CRC_PASS		0x04
#define MXT_APP_CRC_FAIL		0x40
#define MXT_BOOT_STATUS_MASK		0x3f

/* Bootloader ID */
#define MXT_BOOT_EXTENDED_ID		0x20
#define MXT_BOOT_ID_MASK		0x1f

/* Command to unlock bootloader */
#define MXT_UNLOCK_CMD_MSB		0xaa
#define MXT_UNLOCK_CMD_LSB		0xdc

#define ID_BLOCK_SIZE			7

#define MXT_STATE_INACTIVE		-1
#define MXT_STATE_RELEASE		0
#define MXT_STATE_PRESS			1
#define MXT_STATE_MOVE			2

/* Diagnostic cmds  */
#define MXT_DIAG_PAGE_UP		0x01
#define MXT_DIAG_PAGE_DOWN		0x02
#define MXT_DIAG_DELTA_MODE		0x10
#define MXT_DIAG_REFERENCE_MODE		0x11
#define MXT_DIAG_CTE_MODE		0x31
#define MXT_DIAG_IDENTIFICATION_MODE	0x80
#define MXT_DIAG_TOCH_THRESHOLD_MODE	0xF4

#define MXT_DIAG_MODE_MASK	0xFC
#define MXT_DIAGNOSTIC_MODE	0
#define MXT_DIAGNOSTIC_PAGE	1

/* Firmware name */
#define MXT_FW_NAME		"mXT540S.fw"
#define MXT_MAX_FW_PATH		255
#define MXT_CONFIG_VERSION_LENGTH	30

/* Firmware version */
#define MXT_FIRM_VERSION	0x10
#define MXT_FIRM_BUILD		0xAA

/* Touchscreen configuration infomation */
#define MXT_FW_MAGIC		0x4D3C2B1A
#define DUAL_CFG	1

/* Feature */
#define TSP_FIRMUP_ON_PROBE	1
#define TSP_BOOSTER		0
#define TSP_DEBUG_INFO	1
#define TSP_SEC_SYSFS	1
#if DUAL_CFG
#define TSP_INFORM_CHARGER	1
#else
#define TSP_INFORM_CHARGER	0
#endif
/* TSP_ITDEV feature just for atmel tunning app
* so it should be disabled after finishing tunning
* because it use other write permission. it will be cause
* failure of CTS
*/
#define TSP_ITDEV		1
#define TSP_USE_SHAPETOUCH	0

#if TSP_SEC_SYSFS
#define TSP_BUF_SIZE	 1024

#define NODE_NUM	540

#define NODE_PER_PAGE	64
#define DATA_PER_NODE	2

#define REF_MIN_VALUE	19744
#define REF_MAX_VALUE	28884

#define TSP_CMD_STR_LEN		32
#define TSP_CMD_RESULT_STR_LEN	512
#define TSP_CMD_PARAM_NUM	8

enum CMD_STATUS {
	CMD_STATUS_WAITING = 0,
	CMD_STATUS_RUNNING,
	CMD_STATUS_OK,
	CMD_STATUS_FAIL,
	CMD_STATUS_NOT_APPLICABLE,
};

enum {
	MXT_FW_FROM_BUILT_IN = 0,
	MXT_FW_FROM_UMS,
	MXT_FW_FROM_REQ_FW,
};
#endif

#if TSP_BOOSTER
#include <mach/cpufreq.h>
#include <mach/dev.h>
#define SEC_DVFS_LOCK_TIMEOUT	200
#define SEC_DVFS_LOCK_FREQ		800000
#define SEC_BUS_LOCK_FREQ		267160
#define SEC_BUS_LOCK_FREQ2	400200
#endif

struct mxt_object {
	u8 object_type;
	u16 start_address;
	u8 size;
	u8 instances;
	u8 num_report_ids;
} __packed;

struct mxt_info_block {
	u8 family_id;
	u8 variant_id;
	u8 version;
	u8 build;
	u8 matrix_xsize;
	u8 matrix_ysize;
	u8 object_num;
};

struct mxt_finger_info {
	s16 x;
	s16 y;
	s16 z;
	u16 w;
	s8 state;
#if TSP_USE_SHAPETOUCH
	int16_t component;
#endif
	u16 mcount;
};

struct mxt_report_id_map {
	u8 object_type;
	u8 instance;
};

#if TSP_BOOSTER
struct touch_booster {
	bool touch_cpu_lock_status;
	int cpu_lv;
	struct delayed_work dvfs_dwork;
	struct device *bus_dev;
	struct device *dev;
};
#endif

#if TSP_SEC_SYSFS
struct mxt_data_sysfs {
	struct list_head			cmd_list_head;
	u8			cmd_state;
	char			cmd[TSP_CMD_STR_LEN];
	int			cmd_param[TSP_CMD_PARAM_NUM];
	char			cmd_result[TSP_CMD_RESULT_STR_LEN];
	struct mutex			cmd_lock;
	bool			cmd_is_running;

	u16 reference[NODE_NUM];
	s16 delta[NODE_NUM];

	u32 ref_max_data;
	u32 ref_min_data;
	s16 delta_max_data;
	u16 delta_max_node;
	u8 fw_ver;
	u8 build_ver;
	u32 current_crc;
};
#endif

struct mxt_data {
	struct i2c_client *client;
	struct i2c_client *client_boot;
	struct input_dev *input_dev;
	const struct mxt_platform_data *pdata;
	struct mxt_info_block info;
	struct mxt_object *objects;
	struct mxt_report_id_map *rid_map;
#ifdef CONFIG_HAS_EARLYSUSPEND
	struct early_suspend early_suspend;
#endif
#if TSP_SEC_SYSFS
	struct mxt_data_sysfs *sysfs_data;
#endif
#if TSP_BOOSTER
	struct touch_booster booster;
#endif
#if DUAL_CFG
	const u8 *batt_cfg_raw_data;
	const u8 *ta_cfg_raw_data;
	u32 cfg_len;
#endif
#if TSP_INFORM_CHARGER
	struct mxt_callbacks callbacks;
	struct delayed_work noti_dwork;
	bool charging_mode;
#endif
#ifdef TSP_ITDEV
	int driver_paused;
	int debug_enabled;
	u16 last_read_addr;
#endif
	u8 tsp_ctrl;
	u8 max_report_id;
	u8 finger_report_id;
	u16 msg_proc;
	u16 cmd_proc;
	u16 msg_object_size;
	u32 x_dropbits:2;
	u32 y_dropbits:2;
	u32 finger_mask;
	int num_fingers;
	bool mxt_enabled;
	struct completion init_done;
#if TSP_USE_SHAPETOUCH
	int16_t sumsize;
#endif
	struct mutex lock;
	struct mxt_finger_info fingers[];
};

struct mxt_fw_image {
	__le32 magic_code;
	__le32 hdr_len;
	__le32 cfg_len;
	__le32 fw_len;
	__le32 cfg_crc;
	u8 fw_ver;
	u8 build_ver;
	u8 data[0];
} __packed;

struct mxt_cfg_data {
	u8 type;
	u8 instance;
	u8 size;
	u8 register_val[0];
} __packed;

struct mxt_fw_info {
	u8 fw_ver;
	u8 build_ver;
	u32 hdr_len;
	u32 cfg_len;
	u32 fw_len;
	u32 cfg_crc;
#if DUAL_CFG
	const u8 *batt_cfg_raw_data;
	const u8 *ta_cfg_raw_data;
#else
	const u8 *cfg_raw_data;
#endif
	const u8 *fw_raw_data;	/* start address of firmware data */
	struct mxt_data *data;
};

#if TSP_SEC_SYSFS
extern struct class *sec_class;
#endif

#if TSP_BOOSTER
void mxt_set_dvfs_on(struct mxt_data *data, bool en);
int mxt_init_dvfs(struct mxt_data *data);
#endif	/* TSP_BOOSTER */
#endif /* __MXT_540S_DEV_H */