aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/mxt1664s_dev.h
blob: 4fd4f89cb69b4b3b3064c9033f85b007392756a8 (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
/*
 *  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_1664S_DEV_H
#define __MXT_1664S_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 DETECT_MSG_MASK		0x80
#define PRESS_MSG_MASK		0x40
#define RELEASE_MSG_MASK	0x20
#define MOVE_MSG_MASK		0x10
#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

/* Debug cmds  */
#define MXT_PAGE_UP			0x01
#define MXT_PAGE_DOWN			0x02
#define MXT_DELTA_MODE		0x10
#define MXT_REFERENCE_MODE	0x11
#define MXT_CTE_MODE			0x31

/* Firmware name */
#define MXT_FW_NAME			"tsp_atmel/mXT1664S.fw"

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

/* Feature */
#define TSP_FIRMUP_ON_PROBE	1
#define TSP_BOOSTER		0
#define TSP_DEBUG_INFO	1
#define TSP_SEC_SYSFS	1
/* 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

#if TSP_SEC_SYSFS
#define TSP_BUF_SIZE 1024

#define TX_NUM		26
#define RX_NUM		14
#define NODE_NUM	(TX_NUM*RX_NUM)

#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,
};
#endif

#if TSP_BOOSTER
/* touch booster */
#define TOUCH_BOOSTER_TIME		3000
#define TOUCH_BOOSTER_LIMIT_CLK	500000
#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;
	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;
};
#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;

	unsigned int reference[NODE_NUM];
	unsigned int delta[NODE_NUM];
};
#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
#ifdef TSP_ITDEV
	int driver_paused;
	int debug_enabled;
	u16 last_read_addr;
#endif
	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 mutex lock;
	struct mxt_finger_info fingers[];
};


#if TSP_SEC_SYSFS
extern struct class *sec_class;
#endif

extern int  __devinit mxt_sysfs_init(struct i2c_client *client);

extern int mxt_read_mem(struct mxt_data *data, u16 reg, u8 len, u8 *buf);
extern int mxt_write_mem(struct mxt_data *data,	u16 reg, u8 len, const u8 *buf);
extern struct mxt_object *
	mxt_get_object_info(struct mxt_data *data, u8 object_type);
extern int mxt_read_object(struct mxt_data *data,
				u8 type, u8 offset, u8 *val);
extern int mxt_write_object(struct mxt_data *data,
				 u8 type, u8 offset, u8 val);

#endif /* __MXT_1664S_DEV_H */