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
330
331
332
|
/****************************************************************
*
* sn310m-touch.c : I2C Touchscreen driver (platform data struct)
*
* Copyright (c) 2013 SEMISENS Co.,Ltd
* http://www.semisens.com
*
****************************************************************/
#include <linux/device.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/slab.h>
#include <linux/hrtimer.h>
#include <asm/unaligned.h>
#include <linux/firmware.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <mach/wmt_iomux.h>
//----------------------------------------------
#include "sn310m-touch-pdata.h"
#include "sn310m-touch.h"
#include "touch.h"
//----------------------------------------------
unsigned char sn310m_id_tracking(struct touch *ts, unsigned char find_id);
//----------------------------------------------
// Touch i2c control function
//----------------------------------------------
int sn310m_i2c_read(struct i2c_client *client, unsigned char *cmd, unsigned int cmd_len, unsigned char *data, unsigned int len)
{
struct i2c_msg msg[2];
int ret = 0;
unsigned char i = 0;
unsigned char cmd_tmp[10] = {0, };
if((len == 0) || (data == NULL)) {
dev_err(&client->dev, "I2C read error: Null pointer or length == 0\n");
return -1;
}
memset(cmd_tmp, 0x00, sizeof(cmd_tmp));
if(cmd_len) {
for(i = 0; i < cmd_len; i++) {
cmd_tmp[i] = cmd[cmd_len -1 -i];
}
}
memset(msg, 0x00, sizeof(msg));
msg[0].addr = client->addr;
msg[0].flags = client->flags & I2C_M_TEN;
msg[0].len = cmd_len;
msg[0].buf = cmd_tmp;
msg[1].addr = client->addr;
msg[1].flags = client->flags & I2C_M_TEN;
msg[1].flags |= I2C_M_RD;
msg[1].len = len;
msg[1].buf = data;
if((ret = i2c_transfer(client->adapter, msg, 2)) != 2) {
dev_err(&client->dev, "I2C read error: (%d) reg: 0x%X len: %d\n", ret, cmd_tmp[0], len);
return -EIO;
}
return len;
}
int sn310m_i2c_write(struct i2c_client *client, unsigned char *cmd, unsigned int cmd_len, unsigned char *data, unsigned int len)
{
int ret = 0;
unsigned char block_data[10] = {0, };
unsigned char i = 0;
unsigned char cmd_tmp[10] = {0, };
if((cmd_len + len) >= sizeof(block_data)) {
dev_err(&client->dev, "I2C write error: wdata overflow reg: 0x%X len: %d\n", cmd[0], cmd_len + len);
return -1;
}
memset(block_data, 0x00, sizeof(block_data));
memset(cmd_tmp, 0x00, sizeof(cmd_tmp));
if(cmd_len) {
for(i = 0; i < cmd_len; i++) {
cmd_tmp[i] = cmd[cmd_len -1 -i];
}
}
if(cmd_len)
memcpy(&block_data[0], &cmd_tmp[0], cmd_len);
if(len)
memcpy(&block_data[cmd_len], &data[0], len);
if((ret = i2c_master_send(client, block_data, (cmd_len + len))) < 0) {
dev_err(&client->dev, "I2C write error: (%d) reg: 0x%X len: %d\n", ret, cmd[0], len);
return ret;
}
return len;
}
//----------------------------------------------
// Touch initialize & finalize function
//----------------------------------------------
int sn310m_input_open(struct input_dev *input)
{
struct touch *ts = input_get_drvdata(input);
dbg("%s\n", __func__);
ts->pdata->enable(ts);
return 0;
}
void sn310m_enable(struct touch *ts)
{
unsigned short cmd = REG_TS_STATUS;
unsigned int rdata = 0;
dbg("sn310m_enable++\n");
if(ts->disabled) {
while(!gpio_get_value(ts->pdata->irq_gpio))
ts->pdata->i2c_read(ts->client, (unsigned char *)&cmd, sizeof(cmd), (unsigned char *)&rdata, sizeof(rdata));
wmt_gpio_set_irq_type(ts->pdata->irq_gpio, IRQ_TYPE_EDGE_FALLING);
wmt_gpio_unmask_irq(ts->pdata->irq_gpio);
dbg("enable_irq (%d)\n",ts->irq);
ts->disabled = false;
}
dbg("sn310m_enable--\n");
}
void sn310m_disable(struct touch *ts)
{
dbg("sn310m_disable++\n");
if(!ts->disabled) {
//disable_irq(ts->irq);//wmt_gpio_mask_irq(ts->pdata->irq_gpio);//
wmt_gpio_mask_irq(ts->pdata->irq_gpio);
dbg("disable_irq(ts->irq);\n");
ts->disabled = true;
if(ts->pdata->event_clear){
ts->pdata->event_clear(ts);
}
}
dbg("sn310m_disable--");
}
int sn310m_early_probe(struct touch *ts)
{
// nothing to do...
return 0;
}
int sn310m_probe(struct touch *ts)
{
unsigned short cmd = REG_FIRMWARE_VERSION;
unsigned short rdata = 0;
if(ts->pdata->i2c_read(ts->client, (unsigned char *)&cmd, sizeof(cmd), (unsigned char *)&rdata, sizeof(rdata)) < 0) {
errlog("fail to get touch ic firmware version.\n");
return -1;
}
ts->fw_version = rdata;
dbg("touch ic firmware version : %d \n", rdata);
return 0;
}
//----------------------------------------------
// calibration function
//----------------------------------------------
int sn310m_calibration(struct touch *ts)
{
// nothing to do...
return 0;
}
#define SN310M_NATIVE_INTERFACE
#if defined(SN310M_NATIVE_INTERFACE)
#include <linux/syscalls.h>
extern int g_MiscInitialize;
#endif
//----------------------------------------------
// Touch data processing function
//----------------------------------------------
void sn310m_work(struct touch *ts)
{
unsigned char find_slot = 0;
unsigned short cmd = 0;
status_reg_u status;
data_reg_t data;
button_u button;
unsigned int ids = 0;
int i = 0;
mutex_lock(&ts->mutex);
cmd = REG_TS_STATUS;
ts->pdata->i2c_read(ts->client, (unsigned char *)&cmd, sizeof(cmd), (unsigned char *)&status.uint, sizeof(status_reg_u));
if(status.bits.ts_cnt <= ts->pdata->max_fingers) {
unsigned char cnt = 0;
if(ts->pdata->keycode && (status.bits.ts_cnt == 0)) {
button.bits.bt0_press = (status.bits.button & 0x01) ? 1 : 0;
button.bits.bt1_press = (status.bits.button & 0x02) ? 1 : 0;
button.bits.bt2_press = (status.bits.button & 0x04) ? 1 : 0;
button.bits.bt3_press = (status.bits.button & 0x08) ? 1 : 0;
ts->pdata->key_report(ts, button.ubyte);
}
for(cnt = 0; cnt < status.bits.ts_cnt; cnt++) {
unsigned int id;
unsigned int x;
unsigned int y;
unsigned int area;
unsigned int pressure;
cmd = REG_TS_DATA(cnt);
ts->pdata->i2c_read(ts->client, (unsigned char *)&cmd, sizeof(cmd), (unsigned char *)&data.packet0, sizeof(data_reg_t));
id = data.packet0 >> 12;
x = data.packet0 & 0xfff;
y = data.packet1 & 0xfff;
area = data.packet2 & 0xfff;
pressure = ((data.packet1 >> 8) & 0x00f0) + (data.packet2 >> 12);
dbg("DEBUG(%s) : cmd=%d, id=%d, x=%d, y=%d, area=%d, pressure=%d \n", __func__, cmd, id, x, y, area, pressure);
dbg("DEBUG(%s) : pkt0=%x pkt1=%x pkt2=%x \n", __func__, data.packet0, data.packet1, data.packet2);
if((x >= ts->pdata->abs_max_x) || (y >= ts->pdata->abs_max_y)) {
if(ts->pdata->event_clear)
ts->pdata->event_clear(ts);
dbg("ERROR(%s) : x(%d) or y(%d) value overflow!\n", __func__, x, y);
continue;
}
if(ts->pdata->id_max) {
if((id >= ts->pdata->id_max) || (id < ts->pdata->id_min)) {
if(ts->pdata->event_clear)
ts->pdata->event_clear(ts);
dbg("ERROR(%s) : id(%d) value overflow!\n", __func__, id);
continue;
}
if((find_slot = sn310m_id_tracking(ts, id)) == 0xFF) {
dbg("ERROR(%s) : Empty slot not found\n", __func__);
continue;
}
}
else {
if(id == 0)
continue;
find_slot = cnt;
}
if(ts->finger[find_slot].event == TS_EVENT_UNKNOWN)
ts->finger[find_slot].event = TS_EVENT_PRESS;
else if((ts->finger[find_slot].event == TS_EVENT_PRESS) || (ts->finger[find_slot].event == TS_EVENT_MOVE))
ts->finger[find_slot].event = TS_EVENT_MOVE;
if (ts->pdata->lcd_exchg) {
int tmp;
tmp = x;
x = y;
y = ts->pdata->abs_max_x - tmp;
}
ts->finger[find_slot].status = true;
ts->finger[find_slot].id = id;
ts->finger[find_slot].x = x;
ts->finger[find_slot].y = y;
ts->finger[find_slot].area = (ts->pdata->area_max < area) ? ts->pdata->area_max : area;
ts->finger[find_slot].pressure = (ts->pdata->press_max < pressure) ? ts->pdata->press_max : pressure;
ids |= 1 << find_slot;
}
}
for(i = 0; i < ts->pdata->max_fingers; i++) {
if(!(ids & (1 << i))) {
if(ts->finger[i].event != TS_EVENT_UNKNOWN) {
ts->finger[i].status = true;
ts->finger[i].event = TS_EVENT_RELEASE;
}
}
}
ts->pdata->report(ts);
mutex_unlock(&ts->mutex);
wmt_gpio_unmask_irq(ts->pdata->irq_gpio);
}
unsigned char sn310m_id_tracking(struct touch *ts, unsigned char find_id)
{
unsigned char find_slot = 0xFF;
int i = 0;
for(i = 0; i < ts->pdata->max_fingers; i++) {
if(ts->finger[i].id == find_id)
find_slot = i;
if((ts->finger[i].event == TS_EVENT_UNKNOWN) && (find_slot == 0xFF))
find_slot = i;
}
return find_slot;
}
//----------------------------------------------
// Firmware update Control function
//----------------------------------------------
int sn310m_flash_firmware(struct device *dev, const char *fw_name)
{
// nothing to do...
return 0;
}
|