1
|
/*
|
2
|
* drivers/input/touchscreen/sitronix_i2c_touch.c
|
3
|
*
|
4
|
* Touchscreen driver for Sitronix (I2C bus)
|
5
|
*
|
6
|
* Copyright (C) 2011 Sitronix Technology Co., Ltd.
|
7
|
* Rudy Huang <rudy_huang@sitronix.com.tw>
|
8
|
*/
|
9
|
/*
|
10
|
* This program is free software; you can redistribute it and/or modify it
|
11
|
* under the terms of the GNU General Public License as published by the Free
|
12
|
* Software Foundation; either version 2 of the License, or (at your option)
|
13
|
* any later version.
|
14
|
*/
|
15
|
#include <linux/version.h>
|
16
|
#include <linux/module.h>
|
17
|
#include <linux/delay.h>
|
18
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
19
|
#include <linux/earlysuspend.h>
|
20
|
#endif // CONFIG_HAS_EARLYSUSPEND
|
21
|
#include "sitronix_i2c_touch.h"
|
22
|
#ifdef SITRONIX_FW_UPGRADE_FEATURE
|
23
|
#include <linux/cdev.h>
|
24
|
#include <asm/uaccess.h>
|
25
|
#ifdef SITRONIX_PERMISSION_THREAD
|
26
|
#include <linux/fs.h>
|
27
|
#include <linux/fcntl.h>
|
28
|
#include <linux/syscalls.h>
|
29
|
#endif // SITRONIX_PERMISSION_THREAD
|
30
|
#endif // SITRONIX_FW_UPGRADE_FEATURE
|
31
|
#include <linux/i2c.h>
|
32
|
#include <linux/input.h>
|
33
|
#ifdef SITRONIX_SUPPORT_MT_SLOT
|
34
|
#include <linux/input/mt.h>
|
35
|
#endif // SITRONIX_SUPPORT_MT_SLOT
|
36
|
#include <linux/interrupt.h>
|
37
|
#include <linux/slab.h> // to be compatible with linux kernel 3.2.15
|
38
|
#include <linux/gpio.h>
|
39
|
//#include <mach/gpio.h>
|
40
|
#ifdef SITRONIX_MONITOR_THREAD
|
41
|
#include <linux/kthread.h>
|
42
|
#endif // SITRONIX_MONITOR_THREAD
|
43
|
//#include <linux/sp_capture.h>
|
44
|
|
45
|
|
46
|
#include <linux/kthread.h>
|
47
|
#include <linux/path.h>
|
48
|
#include <linux/namei.h>
|
49
|
#include <linux/of_gpio.h>
|
50
|
|
51
|
#ifdef SITRONIX_MULTI_SLAVE_ADDR
|
52
|
#if defined(CONFIG_MACH_OMAP4_PANDA)
|
53
|
#include <plat/gpio.h>
|
54
|
#endif //defined(CONFIG_MACH_OMAP4_PANDA)
|
55
|
#endif // SITRONIX_MULTI_SLAVE_ADDR
|
56
|
|
57
|
#define DRIVER_AUTHOR "Sitronix, Inc."
|
58
|
#define DRIVER_NAME "sitronix"
|
59
|
#define DRIVER_DESC "Sitronix I2C touch"
|
60
|
#define DRIVER_DATE "20150827"
|
61
|
#define DRIVER_MAJOR 2
|
62
|
#define DRIVER_MINOR 9
|
63
|
#define DRIVER_PATCHLEVEL 17
|
64
|
#define NAME_SIZE 20
|
65
|
|
66
|
MODULE_AUTHOR("Petitk Kao<petitk_kao@sitronix.com.tw>");
|
67
|
MODULE_DESCRIPTION("Sitronix I2C multitouch panels");
|
68
|
MODULE_LICENSE("GPL");
|
69
|
struct ctp_config_info{
|
70
|
int input_type;
|
71
|
char *name;
|
72
|
int int_number;
|
73
|
};
|
74
|
|
75
|
|
76
|
struct ctp_config_info config_info = {
|
77
|
.input_type = 1,
|
78
|
.name = NULL,
|
79
|
.int_number = 0,
|
80
|
};
|
81
|
|
82
|
#define CTP_IRQ_NUMBER (config_info.int_number)
|
83
|
#define CTP_IRQ_MODE (IRQF_TRIGGER_FALLING)
|
84
|
#define CTP_NAME ("sitronix")
|
85
|
//#define SCREEN_MAX_X (screen_max_x)
|
86
|
#define SCREEN_MAX_Y (screen_max_y)
|
87
|
#define PRESS_MAX (255)
|
88
|
|
89
|
#if 0
|
90
|
static int screen_max_x = 0;
|
91
|
static int screen_max_y = 0;
|
92
|
static int revert_x_flag = 0;
|
93
|
static int revert_y_flag = 0;
|
94
|
static int exchange_x_y_flag = 0;
|
95
|
#endif
|
96
|
static __u32 twi_id = 0;
|
97
|
//static char irq_pin_name[8];
|
98
|
|
99
|
|
100
|
char sitronix_sensor_key_status = 0;
|
101
|
struct sitronix_sensor_key_t sitronix_sensor_key_array[] = {
|
102
|
{KEY_BACK}, // bit 0
|
103
|
{KEY_HOME}, // bit 1
|
104
|
{KEY_MENU}, // bit 2
|
105
|
};
|
106
|
#ifdef SITRONIX_AA_KEY
|
107
|
char sitronix_aa_key_status = 0;
|
108
|
|
109
|
#ifdef SITRONIX_KEY_BOUNDARY_MANUAL_SPECIFY
|
110
|
#define SITRONIX_TOUCH_RESOLUTION_X 480 /* max of X value in display area */
|
111
|
#define SITRONIX_TOUCH_RESOLUTION_Y 854 /* max of Y value in display area */
|
112
|
#define SITRONIX_TOUCH_GAP_Y 10 /* Gap between bottom of display and top of touch key */
|
113
|
#define SITRONIX_TOUCH_MAX_Y 915 /* resolution of y axis of touch ic */
|
114
|
struct sitronix_AA_key sitronix_aa_key_array[] = {
|
115
|
{15, 105, SITRONIX_TOUCH_RESOLUTION_Y + SITRONIX_TOUCH_GAP_Y, SITRONIX_TOUCH_MAX_Y, KEY_MENU}, /* MENU */
|
116
|
{135, 225, SITRONIX_TOUCH_RESOLUTION_Y + SITRONIX_TOUCH_GAP_Y, SITRONIX_TOUCH_MAX_Y, KEY_HOME},
|
117
|
{255, 345, SITRONIX_TOUCH_RESOLUTION_Y + SITRONIX_TOUCH_GAP_Y, SITRONIX_TOUCH_MAX_Y, KEY_BACK}, /* KEY_EXIT */
|
118
|
{375, 465, SITRONIX_TOUCH_RESOLUTION_Y + SITRONIX_TOUCH_GAP_Y, SITRONIX_TOUCH_MAX_Y, KEY_SEARCH},
|
119
|
};
|
120
|
#else
|
121
|
#define SCALE_KEY_HIGH_Y 15
|
122
|
struct sitronix_AA_key sitronix_aa_key_array[] = {
|
123
|
{0, 0, 0, 0, KEY_MENU}, /* MENU */
|
124
|
{0, 0, 0, 0, KEY_HOME},
|
125
|
{0, 0, 0, 0, KEY_BACK}, /* KEY_EXIT */
|
126
|
{0, 0, 0, 0, KEY_SEARCH},
|
127
|
};
|
128
|
#endif // SITRONIX_KEY_BOUNDARY_MANUAL_SPECIFY
|
129
|
#endif // SITRONIX_AA_KEY
|
130
|
struct rst_pin_ctrl{
|
131
|
struct i2c_client *client;
|
132
|
struct pinctrl *pinctrl;
|
133
|
struct pinctrl_state *rst_pin_ts_active;
|
134
|
struct pinctrl_state *rst_pin_ts_suspend;
|
135
|
struct pinctrl_state *rst_pin_ts_release;
|
136
|
|
137
|
};
|
138
|
struct sitronix_ts_data {
|
139
|
struct i2c_client *client;
|
140
|
struct input_dev *input_dev;
|
141
|
struct input_dev *keyevent_input;
|
142
|
int use_irq;
|
143
|
#ifndef SITRONIX_INT_POLLING_MODE
|
144
|
struct work_struct work;
|
145
|
#else
|
146
|
struct delayed_work work;
|
147
|
#endif // SITRONIX_INT_POLLING_MODE
|
148
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
149
|
struct early_suspend early_suspend;
|
150
|
#endif // CONFIG_HAS_EARLYSUSPEND
|
151
|
uint8_t fw_revision[4];
|
152
|
int resolution_x;
|
153
|
int resolution_y;
|
154
|
uint8_t max_touches;
|
155
|
uint8_t touch_protocol_type;
|
156
|
uint8_t pixel_length;
|
157
|
uint8_t chip_id;
|
158
|
#ifdef SITRONIX_MONITOR_THREAD
|
159
|
uint8_t enable_monitor_thread;
|
160
|
uint8_t RawCRC_enabled;
|
161
|
int (*sitronix_mt_fp)(void *);
|
162
|
#endif // SITRONIX_MONITOR_THREAD
|
163
|
uint8_t Num_X;
|
164
|
uint8_t Num_Y;
|
165
|
uint8_t sensing_mode;
|
166
|
int suspend_state;
|
167
|
spinlock_t irq_lock;
|
168
|
u8 irq_is_disable;
|
169
|
int irq_gpio;
|
170
|
u32 irq_gpio_flags;
|
171
|
int reset_gpio;
|
172
|
u32 reset_gpio_flags;
|
173
|
//int irq;
|
174
|
#if (CTP_AP_SP_SYNC_WAY != CTP_AP_SP_SYNC_NONE)
|
175
|
// gavin TOUCH_DRIVE_T sitronix_driver_ops;
|
176
|
#endif
|
177
|
|
178
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
179
|
struct work_struct sitronix_io_sync_work;
|
180
|
#endif
|
181
|
};
|
182
|
|
183
|
#if (CTP_AP_SP_SYNC_WAY != CTP_AP_SP_SYNC_NONE)
|
184
|
static struct sitronix_ts_data *gSitronixPtr = NULL;
|
185
|
#endif
|
186
|
|
187
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
188
|
//static struct gpio_config sitronix_sync_io;
|
189
|
static struct timer_list ctp_sync_timer;
|
190
|
static int ctp_sync_io_last_status = 1;
|
191
|
static int ctp_sync_pulse_count = 0;
|
192
|
static spinlock_t ctp_sync_lock;
|
193
|
static struct workqueue_struct *sitronix_io_sync_workqueue = NULL;
|
194
|
#endif
|
195
|
|
196
|
static int i2cErrorCount = 0;
|
197
|
|
198
|
#ifdef SITRONIX_MONITOR_THREAD
|
199
|
static struct task_struct * SitronixMonitorThread = NULL;
|
200
|
static int gMonitorThreadSleepInterval = 300; // 0.3 sec
|
201
|
static atomic_t iMonitorThreadPostpone = ATOMIC_INIT(0);
|
202
|
|
203
|
static uint8_t PreCheckData[4] ;
|
204
|
static int StatusCheckCount = 0;
|
205
|
static int sitronix_ts_delay_monitor_thread_start = DELAY_MONITOR_THREAD_START_PROBE;
|
206
|
#endif // SITRONIX_MONITOR_THREAD
|
207
|
|
208
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
209
|
static void sitronix_ts_early_suspend(struct early_suspend *h);
|
210
|
static void sitronix_ts_late_resume(struct early_suspend *h);
|
211
|
#endif // CONFIG_HAS_EARLYSUSPEND
|
212
|
|
213
|
static struct sitronix_ts_data sitronix_ts_gpts = {0};
|
214
|
static struct rst_pin_ctrl *rst_pin;
|
215
|
static atomic_t sitronix_ts_irq_on = ATOMIC_INIT(0);
|
216
|
static atomic_t sitronix_ts_in_int = ATOMIC_INIT(0);
|
217
|
#ifdef SITRONIX_SYSFS
|
218
|
static bool sitronix_ts_sysfs_created = false;
|
219
|
static bool sitronix_ts_sysfs_using = false;
|
220
|
#endif // SITRONIX_SYSFS
|
221
|
|
222
|
static void sitronix_ts_reset_ic(void);
|
223
|
//static int sitronix_ts_disable_int(struct sitronix_ts_data *ts, uint8_t value);
|
224
|
|
225
|
#ifdef ST_UPGRADE_FIRMWARE
|
226
|
extern int st_upgrade_fw(void);
|
227
|
#endif //ST_UPGRADE_FIRMWARE
|
228
|
|
229
|
#ifdef ST_TEST_RAW
|
230
|
extern int st_drv_test_raw();
|
231
|
#endif //ST_TEST_RAW
|
232
|
|
233
|
#ifdef SITRONIX_FW_UPGRADE_FEATURE
|
234
|
#ifdef SITRONIX_PERMISSION_THREAD
|
235
|
SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode);
|
236
|
static struct task_struct * SitronixPermissionThread = NULL;
|
237
|
static int sitronix_ts_delay_permission_thread_start = 1000;
|
238
|
|
239
|
static int sitronix_ts_permission_thread(void *data)
|
240
|
{
|
241
|
int ret = 0;
|
242
|
int retry = 0;
|
243
|
mm_segment_t fs = get_fs();
|
244
|
set_fs(KERNEL_DS);
|
245
|
|
246
|
DbgMsg("%s start\n", __FUNCTION__);
|
247
|
do{
|
248
|
DbgMsg("delay %d ms\n", sitronix_ts_delay_permission_thread_start);
|
249
|
msleep(sitronix_ts_delay_permission_thread_start);
|
250
|
ret = sys_fchmodat(AT_FDCWD, "/dev/"SITRONIX_I2C_TOUCH_DEV_NAME , 0666);
|
251
|
if(ret < 0)
|
252
|
printk("fail to execute sys_fchmodat, ret = %d\n", ret);
|
253
|
if(retry++ > 10)
|
254
|
break;
|
255
|
}while(ret == -ENOENT);
|
256
|
set_fs(fs);
|
257
|
DbgMsg("%s exit\n", __FUNCTION__);
|
258
|
return 0;
|
259
|
}
|
260
|
#endif // SITRONIX_PERMISSION_THREAD
|
261
|
|
262
|
int sitronix_release(struct inode *, struct file *);
|
263
|
int sitronix_open(struct inode *, struct file *);
|
264
|
ssize_t sitronix_write(struct file *file, const char *buf, size_t count, loff_t *ppos);
|
265
|
ssize_t sitronix_read(struct file *file, char *buf, size_t count, loff_t *ppos);
|
266
|
long sitronix_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
|
267
|
static struct cdev sitronix_cdev;
|
268
|
static struct class *sitronix_class;
|
269
|
static int sitronix_major = 0;
|
270
|
|
271
|
int sitronix_open(struct inode *inode, struct file *filp)
|
272
|
{
|
273
|
return 0;
|
274
|
}
|
275
|
EXPORT_SYMBOL(sitronix_open);
|
276
|
|
277
|
int sitronix_release(struct inode *inode, struct file *filp)
|
278
|
{
|
279
|
return 0;
|
280
|
}
|
281
|
EXPORT_SYMBOL(sitronix_release);
|
282
|
|
283
|
ssize_t sitronix_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
|
284
|
{
|
285
|
int ret;
|
286
|
char *tmp;
|
287
|
|
288
|
if(!(sitronix_ts_gpts.client))
|
289
|
return -EIO;
|
290
|
|
291
|
if (count > 8192)
|
292
|
count = 8192;
|
293
|
|
294
|
tmp = (char *)kmalloc(count,GFP_KERNEL);
|
295
|
if (tmp==NULL)
|
296
|
return -ENOMEM;
|
297
|
if (copy_from_user(tmp,buf,count)) {
|
298
|
kfree(tmp);
|
299
|
return -EFAULT;
|
300
|
}
|
301
|
UpgradeMsg("writing %zu bytes.\n", count);
|
302
|
|
303
|
ret = i2c_master_send(sitronix_ts_gpts.client, tmp, count);
|
304
|
kfree(tmp);
|
305
|
return ret;
|
306
|
}
|
307
|
EXPORT_SYMBOL(sitronix_write);
|
308
|
|
309
|
ssize_t sitronix_read(struct file *file, char *buf, size_t count, loff_t *ppos)
|
310
|
{
|
311
|
char *tmp;
|
312
|
int ret;
|
313
|
|
314
|
if(!(sitronix_ts_gpts.client))
|
315
|
return -EIO;
|
316
|
|
317
|
if (count > 8192)
|
318
|
count = 8192;
|
319
|
|
320
|
tmp = (char *)kmalloc(count,GFP_KERNEL);
|
321
|
if (tmp==NULL)
|
322
|
return -ENOMEM;
|
323
|
|
324
|
UpgradeMsg("reading %zu bytes.\n", count);
|
325
|
|
326
|
ret = i2c_master_recv(sitronix_ts_gpts.client, tmp, count);
|
327
|
if (ret >= 0)
|
328
|
ret = copy_to_user(buf,tmp,count)?-EFAULT:ret;
|
329
|
kfree(tmp);
|
330
|
return ret;
|
331
|
}
|
332
|
EXPORT_SYMBOL(sitronix_read);
|
333
|
|
334
|
static int sitronix_ts_resume(struct i2c_client *client);
|
335
|
static int sitronix_ts_suspend(struct i2c_client *client);
|
336
|
void sitronix_ts_reprobe(void);
|
337
|
long sitronix_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
338
|
{
|
339
|
int err = 0;
|
340
|
int retval = 0;
|
341
|
uint8_t temp[4];
|
342
|
|
343
|
if (!(sitronix_ts_gpts.client))
|
344
|
return -EIO;
|
345
|
|
346
|
if (_IOC_TYPE(cmd) != SMT_IOC_MAGIC) return -ENOTTY;
|
347
|
if (_IOC_NR(cmd) > SMT_IOC_MAXNR) return -ENOTTY;
|
348
|
if (_IOC_DIR(cmd) & _IOC_READ)
|
349
|
err = !access_ok(VERIFY_WRITE,(void __user *)arg,\
|
350
|
_IOC_SIZE(cmd));
|
351
|
else if (_IOC_DIR(cmd) & _IOC_WRITE)
|
352
|
err = !access_ok(VERIFY_READ,(void __user *)arg,\
|
353
|
_IOC_SIZE(cmd));
|
354
|
if (err) return -EFAULT;
|
355
|
|
356
|
switch(cmd) {
|
357
|
case IOCTL_SMT_GET_DRIVER_REVISION:
|
358
|
UpgradeMsg("IOCTL_SMT_GET_DRIVER_REVISION\n");
|
359
|
temp[0] = SITRONIX_TOUCH_DRIVER_VERSION;
|
360
|
if(copy_to_user((uint8_t __user *)arg, &temp[0], 1)){
|
361
|
UpgradeMsg("fail to get driver version\n");
|
362
|
retval = -EFAULT;
|
363
|
}
|
364
|
break;
|
365
|
case IOCTL_SMT_GET_FW_REVISION:
|
366
|
UpgradeMsg("IOCTL_SMT_GET_FW_REVISION\n");
|
367
|
if(copy_to_user((uint8_t __user *)arg, &(sitronix_ts_gpts.fw_revision[0]), 4))
|
368
|
retval = -EFAULT;
|
369
|
break;
|
370
|
case IOCTL_SMT_ENABLE_IRQ:
|
371
|
UpgradeMsg("IOCTL_SMT_ENABLE_IRQ\n");
|
372
|
//sitronix_ts_disable_int(&sitronix_ts_gpts, 0);
|
373
|
if(!atomic_read(&sitronix_ts_in_int)){
|
374
|
if(!atomic_read(&sitronix_ts_irq_on)){
|
375
|
atomic_set(&sitronix_ts_irq_on, 1);
|
376
|
enable_irq(sitronix_ts_gpts.client->irq);
|
377
|
#ifdef SITRONIX_MONITOR_THREAD
|
378
|
if(sitronix_ts_gpts.enable_monitor_thread == 1){
|
379
|
if(!SitronixMonitorThread){
|
380
|
atomic_set(&iMonitorThreadPostpone,1);
|
381
|
SitronixMonitorThread = kthread_run(sitronix_ts_gpts.sitronix_mt_fp,"Sitronix","Monitorthread");
|
382
|
if(IS_ERR(SitronixMonitorThread))
|
383
|
SitronixMonitorThread = NULL;
|
384
|
}
|
385
|
}
|
386
|
#endif // SITRONIX_MONITOR_THREAD
|
387
|
}
|
388
|
}
|
389
|
break;
|
390
|
case IOCTL_SMT_DISABLE_IRQ:
|
391
|
UpgradeMsg("IOCTL_SMT_DISABLE_IRQ\n");
|
392
|
//sitronix_ts_disable_int(&sitronix_ts_gpts, 1);
|
393
|
#ifndef SITRONIX_INT_POLLING_MODE
|
394
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
|
395
|
//gavin flush_work_sync(&sitronix_ts_gpts.work);
|
396
|
#endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
|
397
|
#else
|
398
|
cancel_delayed_work_sync(&sitronix_ts_gpts.work);
|
399
|
#endif
|
400
|
if(atomic_read(&sitronix_ts_irq_on)){
|
401
|
atomic_set(&sitronix_ts_irq_on, 0);
|
402
|
disable_irq_nosync(sitronix_ts_gpts.client->irq);
|
403
|
#ifdef SITRONIX_MONITOR_THREAD
|
404
|
if(sitronix_ts_gpts.enable_monitor_thread == 1){
|
405
|
if(SitronixMonitorThread){
|
406
|
kthread_stop(SitronixMonitorThread);
|
407
|
SitronixMonitorThread = NULL;
|
408
|
}
|
409
|
}
|
410
|
#endif // SITRONIX_MONITOR_THREAD
|
411
|
}
|
412
|
break;
|
413
|
case IOCTL_SMT_RESUME:
|
414
|
UpgradeMsg("IOCTL_SMT_RESUME\n");
|
415
|
sitronix_ts_resume(sitronix_ts_gpts.client);
|
416
|
break;
|
417
|
case IOCTL_SMT_SUSPEND:
|
418
|
UpgradeMsg("IOCTL_SMT_SUSPEND\n");
|
419
|
sitronix_ts_suspend(sitronix_ts_gpts.client);
|
420
|
break;
|
421
|
case IOCTL_SMT_HW_RESET:
|
422
|
UpgradeMsg("IOCTL_SMT_HW_RESET\n");
|
423
|
sitronix_ts_reset_ic();
|
424
|
break;
|
425
|
case IOCTL_SMT_REPROBE:
|
426
|
UpgradeMsg("IOCTL_SMT_REPROBE\n");
|
427
|
sitronix_ts_reprobe();
|
428
|
break;
|
429
|
#ifdef ST_TEST_RAW
|
430
|
case IOCTL_SMT_RAW_TEST:
|
431
|
UpgradeMsg("IOCTL_SMT_RAW_TEST\n");
|
432
|
retval = - st_drv_test_raw();
|
433
|
break;
|
434
|
#endif
|
435
|
default:
|
436
|
retval = -ENOTTY;
|
437
|
}
|
438
|
|
439
|
return retval;
|
440
|
}
|
441
|
EXPORT_SYMBOL(sitronix_ioctl);
|
442
|
#endif // SITRONIX_FW_UPGRADE_FEATURE
|
443
|
|
444
|
static void sitronix_ts_reset_ic(void)
|
445
|
{
|
446
|
printk("%s\n", __FUNCTION__);
|
447
|
#if 0
|
448
|
struct sitronix_i2c_touch_platform_data *pdata;
|
449
|
uint8_t rc;
|
450
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
451
|
rc = gpio_request(pdata->reset_gpio, "reset_gpio");
|
452
|
|
453
|
gpio_direction_output(pdata->reset_gpio, 0);
|
454
|
msleep(3);
|
455
|
gpio_direction_output(pdata->reset_gpio, 1);
|
456
|
msleep(150);
|
457
|
#endif
|
458
|
#if 0
|
459
|
printk("%s\n", __FUNCTION__);
|
460
|
__gpio_set_value(config_info.wakeup_gpio.gpio, 0);
|
461
|
msleep(3);
|
462
|
__gpio_set_value(config_info.wakeup_gpio.gpio, 1);
|
463
|
msleep(SITRONIX_TS_CHANGE_MODE_DELAY);
|
464
|
#endif
|
465
|
}
|
466
|
|
467
|
static int sitronix_i2c_read_bytes(struct i2c_client *client, u8 addr, u8 *rxbuf, int len)
|
468
|
{
|
469
|
int ret = 0;
|
470
|
u8 txbuf = addr;
|
471
|
//printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
472
|
#if defined(SITRONIX_I2C_COMBINED_MESSAGE)
|
473
|
struct i2c_msg msg[2] = {
|
474
|
{
|
475
|
.addr = client->addr,
|
476
|
.flags = 0,
|
477
|
.len = 1,
|
478
|
.buf = &txbuf,
|
479
|
},
|
480
|
{
|
481
|
.addr = client->addr,
|
482
|
.flags = I2C_M_RD,
|
483
|
.len = len,
|
484
|
.buf = rxbuf,
|
485
|
},
|
486
|
};
|
487
|
#endif // defined(SITRONIX_I2C_COMBINED_MESSAGE)
|
488
|
|
489
|
if(rxbuf == NULL)
|
490
|
return -1;
|
491
|
#if defined(SITRONIX_I2C_COMBINED_MESSAGE)
|
492
|
ret = i2c_transfer(client->adapter, &msg[0], 2);
|
493
|
#elif defined(SITRONIX_I2C_SINGLE_MESSAGE)
|
494
|
ret = i2c_master_send(client, &txbuf, 1);
|
495
|
if (ret < 0){
|
496
|
printk("write 0x%x error (%d)\n", addr, ret);
|
497
|
return ret;
|
498
|
}
|
499
|
ret = i2c_master_recv(client, rxbuf, len);
|
500
|
#endif // defined(SITRONIX_I2C_COMBINED_MESSAGE)
|
501
|
if (ret < 0){
|
502
|
DbgMsg("read 0x%x error (%d)\n", addr, ret);
|
503
|
return ret;
|
504
|
}
|
505
|
return 0;
|
506
|
}
|
507
|
|
508
|
static int sitronix_i2c_write_bytes(struct i2c_client *client, u8 *txbuf, int len)
|
509
|
{
|
510
|
int ret = 0;
|
511
|
//printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
512
|
#if defined(SITRONIX_I2C_COMBINED_MESSAGE)
|
513
|
struct i2c_msg msg[1] = {
|
514
|
{
|
515
|
.addr = client->addr,
|
516
|
.flags = 0,
|
517
|
.len = len,
|
518
|
.buf = txbuf,
|
519
|
},
|
520
|
};
|
521
|
#endif // defined(SITRONIX_I2C_COMBINED_MESSAGE)
|
522
|
|
523
|
if(txbuf == NULL)
|
524
|
return -1;
|
525
|
#if defined(SITRONIX_I2C_COMBINED_MESSAGE)
|
526
|
ret = i2c_transfer(client->adapter, &msg[0], 1);
|
527
|
#elif defined(SITRONIX_I2C_SINGLE_MESSAGE)
|
528
|
ret = i2c_master_send(client, txbuf, len);
|
529
|
#endif // defined(SITRONIX_I2C_COMBINED_MESSAGE)
|
530
|
if (ret < 0){
|
531
|
printk("write 0x%x error (%d)\n", *txbuf, ret);
|
532
|
return ret;
|
533
|
}
|
534
|
return 0;
|
535
|
}
|
536
|
|
537
|
static int sitronix_get_fw_revision(struct sitronix_ts_data *ts)
|
538
|
{
|
539
|
int ret = 0;
|
540
|
uint8_t buffer[4];
|
541
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
542
|
|
543
|
ret = sitronix_i2c_read_bytes(ts->client, FIRMWARE_REVISION_3, buffer, 4);
|
544
|
if (ret < 0){
|
545
|
printk("read fw revision error (%d)\n", ret);
|
546
|
return ret;
|
547
|
}else{
|
548
|
memcpy(ts->fw_revision, buffer, 4);
|
549
|
printk("fw revision (hex) = %x %x %x %x\n", buffer[0], buffer[1], buffer[2], buffer[3]);
|
550
|
}
|
551
|
return 0;
|
552
|
}
|
553
|
static int sitronix_get_max_touches(struct sitronix_ts_data *ts)
|
554
|
{
|
555
|
int ret = 0;
|
556
|
uint8_t buffer[1];
|
557
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
558
|
|
559
|
ret = sitronix_i2c_read_bytes(ts->client, MAX_NUM_TOUCHES, buffer, 1);
|
560
|
if (ret < 0){
|
561
|
printk("read max touches error (%d)\n", ret);
|
562
|
return ret;
|
563
|
}else{
|
564
|
ts->max_touches = buffer[0];
|
565
|
if (ts->max_touches > SITRONIX_MAX_SUPPORTED_POINT)
|
566
|
ts->max_touches = SITRONIX_MAX_SUPPORTED_POINT;
|
567
|
printk("max touches = %d \n",ts->max_touches);
|
568
|
}
|
569
|
return 0;
|
570
|
}
|
571
|
|
572
|
static int sitronix_get_protocol_type(struct sitronix_ts_data *ts)
|
573
|
{
|
574
|
int ret = 0;
|
575
|
uint8_t buffer[1];
|
576
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
577
|
|
578
|
if(ts->chip_id <= 3){
|
579
|
ret = sitronix_i2c_read_bytes(ts->client, I2C_PROTOCOL, buffer, 1);
|
580
|
if (ret < 0){
|
581
|
printk("read i2c protocol error (%d)\n", ret);
|
582
|
return ret;
|
583
|
}else{
|
584
|
ts->touch_protocol_type = buffer[0] & I2C_PROTOCOL_BMSK;
|
585
|
printk("i2c protocol = %d \n", ts->touch_protocol_type);
|
586
|
ts->sensing_mode = (buffer[0] & (ONE_D_SENSING_CONTROL_BMSK << ONE_D_SENSING_CONTROL_SHFT)) >> ONE_D_SENSING_CONTROL_SHFT;
|
587
|
printk("sensing mode = %d \n", ts->sensing_mode);
|
588
|
}
|
589
|
}else{
|
590
|
ts->touch_protocol_type = SITRONIX_A_TYPE;
|
591
|
printk("i2c protocol = %d \n", ts->touch_protocol_type);
|
592
|
ret = sitronix_i2c_read_bytes(ts->client, 0xf0, buffer, 1);
|
593
|
if (ret < 0){
|
594
|
printk("read sensing mode error (%d)\n", ret);
|
595
|
return ret;
|
596
|
}else{
|
597
|
ts->sensing_mode = (buffer[0] & ONE_D_SENSING_CONTROL_BMSK);
|
598
|
printk("sensing mode = %d \n", ts->sensing_mode);
|
599
|
}
|
600
|
}
|
601
|
return 0;
|
602
|
}
|
603
|
|
604
|
static int sitronix_get_resolution(struct sitronix_ts_data *ts)
|
605
|
{
|
606
|
/*
|
607
|
int ret = 0;
|
608
|
uint8_t buffer[4];
|
609
|
int newResX = 800;
|
610
|
int newResY = 480;
|
611
|
|
612
|
buffer[0] = XY_RESOLUTION_HIGH;
|
613
|
buffer[1] = (newResX>>8)<<4 | (newResY>>8);
|
614
|
buffer[2] = (newResX&0xFF);
|
615
|
buffer[3] = (newResY&0xFF);
|
616
|
|
617
|
ret = sitronix_i2c_write_bytes(ts->client, buffer, 4);
|
618
|
if (ret < 0){
|
619
|
printk("set resolution error (%d)\n", ret);
|
620
|
return ret;
|
621
|
}else{
|
622
|
ts->resolution_x = newResX;
|
623
|
ts->resolution_y = newResY;
|
624
|
printk("resolution = %d x %d\n", ts->resolution_x, ts->resolution_y);
|
625
|
}
|
626
|
*/
|
627
|
int ret = 0;
|
628
|
uint8_t buffer[4];
|
629
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
630
|
ret = sitronix_i2c_read_bytes(ts->client, XY_RESOLUTION_HIGH, buffer, 3);
|
631
|
if (ret < 0){
|
632
|
printk("read resolution error (%d)\n", ret);
|
633
|
return ret;
|
634
|
}else{
|
635
|
ts->resolution_x = ((buffer[0] & (X_RES_H_BMSK << X_RES_H_SHFT)) << 4) | buffer[1];
|
636
|
ts->resolution_y = ((buffer[0] & Y_RES_H_BMSK) << 8) | buffer[2];
|
637
|
printk("resolution = %d x %d\n", ts->resolution_x, ts->resolution_y);
|
638
|
}
|
639
|
return 0;
|
640
|
|
641
|
}
|
642
|
|
643
|
static int sitronix_ts_get_CHIP_ID(struct sitronix_ts_data *ts)
|
644
|
{
|
645
|
int ret = 0;
|
646
|
uint8_t buffer[3];
|
647
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
648
|
|
649
|
DbgMsg("%s\n", __FUNCTION__);
|
650
|
|
651
|
ret = sitronix_i2c_read_bytes(ts->client, CHIP_ID, buffer, 3);
|
652
|
if (ret < 0){
|
653
|
printk("read Chip ID error (%d)\n", ret);
|
654
|
return ret;
|
655
|
}else{
|
656
|
if(buffer[0] == 0){
|
657
|
if(buffer[1] + buffer[2] > 32)
|
658
|
ts->chip_id = 2;
|
659
|
else
|
660
|
ts->chip_id = 0;
|
661
|
}else
|
662
|
ts->chip_id = buffer[0];
|
663
|
ts->Num_X = buffer[1];
|
664
|
ts->Num_Y = buffer[2];
|
665
|
printk("Chip ID = %d\n", ts->chip_id);
|
666
|
printk("Num_X = %d\n", ts->Num_X);
|
667
|
printk("Num_Y = %d\n", ts->Num_Y);
|
668
|
}
|
669
|
|
670
|
return 0;
|
671
|
}
|
672
|
|
673
|
static int sitronix_ts_set_powerdown_bit(struct sitronix_ts_data *ts, int value)
|
674
|
{
|
675
|
int ret = 0;
|
676
|
uint8_t buffer[2];
|
677
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
678
|
|
679
|
DbgMsg("%s, value = %d\n", __FUNCTION__, value);
|
680
|
ret = sitronix_i2c_read_bytes(ts->client, DEVICE_CONTROL_REG, buffer, 1);
|
681
|
if (ret < 0){
|
682
|
printk("read device control status error (%d)\n", ret);
|
683
|
return ret;
|
684
|
}else{
|
685
|
DbgMsg("dev status = %d \n", buffer[0]);
|
686
|
}
|
687
|
|
688
|
if(value == 0)
|
689
|
buffer[1] = buffer[0] & 0xfd;
|
690
|
else
|
691
|
buffer[1] = buffer[0] | 0x2;
|
692
|
|
693
|
buffer[0] = DEVICE_CONTROL_REG;
|
694
|
ret = sitronix_i2c_write_bytes(ts->client, buffer, 2);
|
695
|
if (ret < 0){
|
696
|
printk("write power down error (%d)\n", ret);
|
697
|
return ret;
|
698
|
}
|
699
|
|
700
|
return 0;
|
701
|
}
|
702
|
|
703
|
#if 0
|
704
|
static int sitronix_ts_disable_int(struct sitronix_ts_data *ts, uint8_t value)
|
705
|
{
|
706
|
int ret = 0;
|
707
|
uint8_t buffer[2];
|
708
|
sitronix_i2c_protocol_map *i2c_ptcl;
|
709
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
710
|
|
711
|
DbgMsg("%s, value = %d\n", __FUNCTION__, value);
|
712
|
i2c_ptcl = (ts->chip_id > 3)? &sitronix_i2c_ptcl_v2 : &sitronix_i2c_ptcl_v1;
|
713
|
|
714
|
ret = sitronix_i2c_read_bytes(ts->client, i2c_ptcl->dis_coord_flag.offset, buffer, 1);
|
715
|
if (ret < 0){
|
716
|
printk("read disable coord. flag error (%d)\n", ret);
|
717
|
return ret;
|
718
|
}
|
719
|
|
720
|
buffer[1] = buffer[0] & ~(i2c_ptcl->dis_coord_flag.bmsk << i2c_ptcl->dis_coord_flag.shft);
|
721
|
buffer[1] |= value;
|
722
|
|
723
|
buffer[0] = i2c_ptcl->dis_coord_flag.offset;
|
724
|
ret = sitronix_i2c_write_bytes(ts->client, buffer, 2);
|
725
|
if (ret < 0){
|
726
|
printk("write disable coord. flag error (%d)\n", ret);
|
727
|
return ret;
|
728
|
}
|
729
|
return 0;
|
730
|
}
|
731
|
#endif
|
732
|
static int sitronix_ts_get_touch_info(struct sitronix_ts_data *ts)
|
733
|
{
|
734
|
int ret = 0;
|
735
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
736
|
ret = sitronix_get_resolution(ts);
|
737
|
if(ret < 0)
|
738
|
return ret;
|
739
|
ret = sitronix_ts_get_CHIP_ID(ts);
|
740
|
if(ret < 0)
|
741
|
return ret;
|
742
|
ret = sitronix_get_fw_revision(ts);
|
743
|
if(ret < 0)
|
744
|
return ret;
|
745
|
ret = sitronix_get_protocol_type(ts);
|
746
|
if(ret < 0)
|
747
|
return ret;
|
748
|
ret = sitronix_get_max_touches(ts);
|
749
|
if(ret < 0)
|
750
|
return ret;
|
751
|
|
752
|
if((ts->fw_revision[0] == 0) && (ts->fw_revision[1] == 0)){
|
753
|
if(ts->touch_protocol_type == SITRONIX_RESERVED_TYPE_0){
|
754
|
ts->touch_protocol_type = SITRONIX_B_TYPE;
|
755
|
printk("i2c protocol (revised) = %d \n", ts->touch_protocol_type);
|
756
|
}
|
757
|
}
|
758
|
if(ts->touch_protocol_type == SITRONIX_A_TYPE)
|
759
|
ts->pixel_length = PIXEL_DATA_LENGTH_A;
|
760
|
else if(ts->touch_protocol_type == SITRONIX_B_TYPE){
|
761
|
ts->pixel_length = PIXEL_DATA_LENGTH_B;
|
762
|
ts->max_touches = 2;
|
763
|
printk("max touches (revised) = %d \n", ts->max_touches);
|
764
|
}
|
765
|
|
766
|
#ifdef SITRONIX_MONITOR_THREAD
|
767
|
ts->RawCRC_enabled = 0;
|
768
|
if(ts->chip_id > 3){
|
769
|
ts->enable_monitor_thread = 1;
|
770
|
ts->RawCRC_enabled = 1;
|
771
|
}else if(ts->chip_id == 3){
|
772
|
ts->enable_monitor_thread = 1;
|
773
|
//if(((ts->fw_revision[2] << 8) | ts->fw_revision[3]) >= (9 << 8 | 3))
|
774
|
if(((ts->fw_revision[2] << 8) | ts->fw_revision[3]) >= (6 << 8 | 3))
|
775
|
ts->RawCRC_enabled = 1;
|
776
|
}else
|
777
|
ts->enable_monitor_thread = 0;
|
778
|
#endif // SITRONIX_MONITOR_THREAD
|
779
|
|
780
|
return 0;
|
781
|
}
|
782
|
|
783
|
static int sitronix_ts_get_device_status(struct i2c_client *client, uint8_t *err_code, uint8_t *dev_status)
|
784
|
{
|
785
|
int ret = 0;
|
786
|
uint8_t buffer[8];
|
787
|
printk("%s,line=%d\n",__FUNCTION__,__LINE__);
|
788
|
DbgMsg("%s\n", __FUNCTION__);
|
789
|
ret = sitronix_i2c_read_bytes(client, STATUS_REG, buffer, 8);
|
790
|
if (ret < 0){
|
791
|
printk("read status reg error (%d)\n", ret);
|
792
|
return ret;
|
793
|
}else{
|
794
|
printk("status reg = %d \n", buffer[0]);
|
795
|
}
|
796
|
|
797
|
*err_code = (buffer[0] & 0xf0) >> 4;
|
798
|
*dev_status = buffer[0] & 0xf;
|
799
|
|
800
|
return 0;
|
801
|
}
|
802
|
|
803
|
#ifdef SITRONIX_IDENTIFY_ID
|
804
|
static int sitronix_ts_Enhance_Function_control(struct sitronix_ts_data *ts, uint8_t *value)
|
805
|
{
|
806
|
int ret = 0;
|
807
|
uint8_t buffer[1];
|
808
|
|
809
|
DbgMsg("%s\n", __FUNCTION__);
|
810
|
ret = sitronix_i2c_read_bytes(ts->client, 0xF0, buffer, 1);
|
811
|
if (ret < 0){
|
812
|
printk("read Enhance Functions status error (%d)\n", ret);
|
813
|
return ret;
|
814
|
}else{
|
815
|
DbgMsg("Enhance Functions status = %d \n", buffer[0]);
|
816
|
}
|
817
|
|
818
|
*value = buffer[0] & 0x4;
|
819
|
|
820
|
return 0;
|
821
|
}
|
822
|
|
823
|
static int sitronix_ts_FW_Bank_Select(struct sitronix_ts_data *ts, uint8_t value)
|
824
|
{
|
825
|
int ret = 0;
|
826
|
uint8_t buffer[2];
|
827
|
|
828
|
DbgMsg("%s\n", __FUNCTION__);
|
829
|
ret = sitronix_i2c_read_bytes(ts->client, 0xF1, buffer, 1);
|
830
|
if (ret < 0){
|
831
|
printk("read FW Bank Select status error (%d)\n", ret);
|
832
|
return ret;
|
833
|
}else{
|
834
|
DbgMsg("FW Bank Select status = %d \n", buffer[0]);
|
835
|
}
|
836
|
|
837
|
buffer[1] = ((buffer[0] & 0xfc) | value);
|
838
|
buffer[0] = 0xF1;
|
839
|
ret = sitronix_i2c_write_bytes(ts->client, buffer, 2);
|
840
|
if (ret < 0){
|
841
|
printk("send FW Bank Select command error (%d)\n", ret);
|
842
|
return ret;
|
843
|
}
|
844
|
|
845
|
return 0;
|
846
|
}
|
847
|
|
848
|
static int sitronix_get_id_info(struct sitronix_ts_data *ts, uint8_t *id_info)
|
849
|
{
|
850
|
int ret = 0;
|
851
|
uint8_t buffer[4];
|
852
|
|
853
|
ret = sitronix_i2c_read_bytes(ts->client, 0x0C, buffer, 4);
|
854
|
if (ret < 0){
|
855
|
printk("read id info error (%d)\n", ret);
|
856
|
return ret;
|
857
|
}else{
|
858
|
memcpy(id_info, buffer, 4);
|
859
|
}
|
860
|
return 0;
|
861
|
}
|
862
|
|
863
|
static int sitronix_ts_identify(struct sitronix_ts_data *ts)
|
864
|
{
|
865
|
int ret = 0;
|
866
|
uint8_t id[4];
|
867
|
uint8_t Enhance_Function = 0;
|
868
|
|
869
|
ret = sitronix_ts_FW_Bank_Select(ts, 1);
|
870
|
if(ret < 0)
|
871
|
return ret;
|
872
|
ret = sitronix_ts_Enhance_Function_control(ts, &Enhance_Function);
|
873
|
if(ret < 0)
|
874
|
return ret;
|
875
|
if(Enhance_Function == 0x4){
|
876
|
ret = sitronix_get_id_info(ts, &id[0]);
|
877
|
if(ret < 0)
|
878
|
return ret;
|
879
|
printk("id (hex) = %x %x %x %x\n", id[0], id[1], id[2], id[3]);
|
880
|
if((id[0] == 1)&&(id[1] == 2)&&(id[2] == 0xb)&&(id[3] == 1)){
|
881
|
return 0;
|
882
|
}else{
|
883
|
printk("Error: It is not Sitronix IC\n");
|
884
|
return -1;
|
885
|
}
|
886
|
}else{
|
887
|
printk("Error: Can not get ID of Sitronix IC\n");
|
888
|
return -1;
|
889
|
}
|
890
|
}
|
891
|
#endif // SITRONIX_IDENTIFY_ID
|
892
|
|
893
|
#ifdef SITRONIX_MONITOR_THREAD
|
894
|
static int sitronix_set_raw_data_type(struct sitronix_ts_data *ts)
|
895
|
{
|
896
|
int ret = 0;
|
897
|
uint8_t buffer[2] = {0};
|
898
|
|
899
|
ret = sitronix_i2c_read_bytes(ts->client, DEVICE_CONTROL_REG, buffer, 1);
|
900
|
if (ret < 0){
|
901
|
DbgMsg("read DEVICE_CONTROL_REG error (%d)\n", ret);
|
902
|
return ret;
|
903
|
}else{
|
904
|
DbgMsg("read DEVICE_CONTROL_REG status = %d \n", buffer[0]);
|
905
|
}
|
906
|
if(ts->sensing_mode == SENSING_BOTH_NOT){
|
907
|
buffer[1] = ((buffer[0] & 0xf3) | (0x01 << 2));
|
908
|
}else{
|
909
|
buffer[1] = (buffer[0] & 0xf3);
|
910
|
}
|
911
|
buffer[0] = DEVICE_CONTROL_REG;
|
912
|
ret = sitronix_i2c_write_bytes(ts->client, buffer, 2);
|
913
|
if (ret < 0){
|
914
|
DbgMsg("write DEVICE_CONTROL_REG error (%d)\n", ret);
|
915
|
return ret;
|
916
|
}
|
917
|
return 0;
|
918
|
}
|
919
|
|
920
|
static int sitronix_ts_monitor_thread(void *data)
|
921
|
{
|
922
|
int ret = 0;
|
923
|
uint8_t buffer[4] = { 0, 0, 0, 0 };
|
924
|
int result = 0;
|
925
|
int once = 1;
|
926
|
uint8_t raw_data_ofs = 0;
|
927
|
|
928
|
DbgMsg("%s:\n", __FUNCTION__);
|
929
|
|
930
|
printk("delay %d ms\n", sitronix_ts_delay_monitor_thread_start);
|
931
|
msleep(sitronix_ts_delay_monitor_thread_start);
|
932
|
while(!kthread_should_stop()){
|
933
|
DbgMsg("%s:\n", "Sitronix_ts_monitoring 2222");
|
934
|
if(atomic_read(&iMonitorThreadPostpone)){
|
935
|
atomic_set(&iMonitorThreadPostpone,0);
|
936
|
}else{
|
937
|
if(once == 1){
|
938
|
ret = sitronix_set_raw_data_type(&sitronix_ts_gpts);
|
939
|
if (ret < 0)
|
940
|
goto exit_i2c_invalid;
|
941
|
|
942
|
if((sitronix_ts_gpts.sensing_mode == SENSING_BOTH) || (sitronix_ts_gpts.sensing_mode == SENSING_X_ONLY)){
|
943
|
raw_data_ofs = 0x40;
|
944
|
}else if(sitronix_ts_gpts.sensing_mode == SENSING_Y_ONLY){
|
945
|
raw_data_ofs = 0x40 + sitronix_ts_gpts.Num_X * 2;
|
946
|
}else{
|
947
|
raw_data_ofs = 0x40;
|
948
|
}
|
949
|
|
950
|
once = 0;
|
951
|
}
|
952
|
if(raw_data_ofs != 0x40){
|
953
|
ret = sitronix_i2c_read_bytes(sitronix_ts_gpts.client, 0x40, buffer, 1);
|
954
|
if (ret < 0){
|
955
|
DbgMsg("read raw data error (%d)\n", ret);
|
956
|
result = 0;
|
957
|
goto exit_i2c_invalid;
|
958
|
}
|
959
|
}
|
960
|
ret = sitronix_i2c_read_bytes(sitronix_ts_gpts.client, raw_data_ofs, buffer, 4);
|
961
|
if (ret < 0){
|
962
|
DbgMsg("read raw data error (%d)\n", ret);
|
963
|
result = 0;
|
964
|
goto exit_i2c_invalid;
|
965
|
}else{
|
966
|
DbgMsg("%dD data h%x-%x = 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", (sitronix_ts_gpts.sensing_mode == SENSING_BOTH_NOT ? 2:1), raw_data_ofs, raw_data_ofs + 3, buffer[0], buffer[1], buffer[2], buffer[3]);
|
967
|
//printk("%dD data h%x-%x = 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", (sitronix_ts_gpts.sensing_mode == SENSING_BOTH_NOT ? 2:1), raw_data_ofs, raw_data_ofs + 3, buffer[0], buffer[1], buffer[2], buffer[3]);
|
968
|
result = 1;
|
969
|
if ((PreCheckData[0] == buffer[0]) && (PreCheckData[1] == buffer[1]) &&
|
970
|
(PreCheckData[2] == buffer[2]) && (PreCheckData[3] == buffer[3]))
|
971
|
StatusCheckCount ++;
|
972
|
else
|
973
|
StatusCheckCount =0;
|
974
|
PreCheckData[0] = buffer[0];
|
975
|
PreCheckData[1] = buffer[1];
|
976
|
PreCheckData[2] = buffer[2];
|
977
|
PreCheckData[3] = buffer[3];
|
978
|
if (3 <= StatusCheckCount){
|
979
|
DbgMsg("IC Status doesn't update! \n");
|
980
|
result = -1;
|
981
|
StatusCheckCount = 0;
|
982
|
}
|
983
|
}
|
984
|
if (-1 == result){
|
985
|
printk("Chip abnormal, reset it!\n");
|
986
|
sitronix_ts_reset_ic();
|
987
|
i2cErrorCount = 0;
|
988
|
StatusCheckCount = 0;
|
989
|
if(sitronix_ts_gpts.RawCRC_enabled == 0){
|
990
|
ret = sitronix_set_raw_data_type(&sitronix_ts_gpts);
|
991
|
if (ret < 0)
|
992
|
goto exit_i2c_invalid;
|
993
|
}
|
994
|
}
|
995
|
exit_i2c_invalid:
|
996
|
if(0 == result){
|
997
|
i2cErrorCount ++;
|
998
|
if ((2 <= i2cErrorCount)){
|
999
|
printk("I2C abnormal, reset it!\n");
|
1000
|
sitronix_ts_reset_ic();
|
1001
|
if(sitronix_ts_gpts.RawCRC_enabled == 0)
|
1002
|
sitronix_set_raw_data_type(&sitronix_ts_gpts);
|
1003
|
i2cErrorCount = 0;
|
1004
|
StatusCheckCount = 0;
|
1005
|
}
|
1006
|
}else
|
1007
|
i2cErrorCount = 0;
|
1008
|
}
|
1009
|
msleep(gMonitorThreadSleepInterval);
|
1010
|
}
|
1011
|
DbgMsg("%s exit\n", __FUNCTION__);
|
1012
|
return 0;
|
1013
|
}
|
1014
|
|
1015
|
static int sitronix_ts_monitor_thread_v2(void *data)
|
1016
|
{
|
1017
|
int ret = 0;
|
1018
|
uint8_t buffer[1] = {0};
|
1019
|
int result = 0;
|
1020
|
|
1021
|
DbgMsg("%s:\n", __FUNCTION__);
|
1022
|
|
1023
|
printk("delay %d ms\n", sitronix_ts_delay_monitor_thread_start);
|
1024
|
msleep(sitronix_ts_delay_monitor_thread_start);
|
1025
|
while(!kthread_should_stop()){
|
1026
|
DbgMsg("%s:\n", "Sitronix_ts_monitoring");
|
1027
|
if(atomic_read(&iMonitorThreadPostpone)){
|
1028
|
atomic_set(&iMonitorThreadPostpone,0);
|
1029
|
}else{
|
1030
|
ret = sitronix_i2c_read_bytes(sitronix_ts_gpts.client, 0xA, buffer, 1);
|
1031
|
if (ret < 0){
|
1032
|
DbgMsg("read Raw CRC error (%d)\n", ret);
|
1033
|
result = 0;
|
1034
|
goto exit_i2c_invalid;
|
1035
|
}else{
|
1036
|
DbgMsg("Raw CRC = 0x%02x\n", buffer[0]);
|
1037
|
//printk("Raw CRC = 0x%02x\n", buffer[0]);
|
1038
|
result = 1;
|
1039
|
if (PreCheckData[0] == buffer[0])
|
1040
|
StatusCheckCount ++;
|
1041
|
else
|
1042
|
StatusCheckCount =0;
|
1043
|
PreCheckData[0] = buffer[0];
|
1044
|
if (3 <= StatusCheckCount){
|
1045
|
DbgMsg("IC Status doesn't update! \n");
|
1046
|
result = -1;
|
1047
|
StatusCheckCount = 0;
|
1048
|
}
|
1049
|
}
|
1050
|
if (-1 == result){
|
1051
|
printk("Chip abnormal, reset it!\n");
|
1052
|
sitronix_ts_reset_ic();
|
1053
|
i2cErrorCount = 0;
|
1054
|
StatusCheckCount = 0;
|
1055
|
}
|
1056
|
exit_i2c_invalid:
|
1057
|
if(0 == result){
|
1058
|
i2cErrorCount ++;
|
1059
|
if ((2 <= i2cErrorCount)){
|
1060
|
printk("I2C abnormal, reset it!\n");
|
1061
|
sitronix_ts_reset_ic();
|
1062
|
i2cErrorCount = 0;
|
1063
|
StatusCheckCount = 0;
|
1064
|
}
|
1065
|
}else
|
1066
|
i2cErrorCount = 0;
|
1067
|
}
|
1068
|
msleep(gMonitorThreadSleepInterval);
|
1069
|
}
|
1070
|
DbgMsg("%s exit\n", __FUNCTION__);
|
1071
|
return 0;
|
1072
|
}
|
1073
|
#endif // SITRONIX_MONITOR_THREAD
|
1074
|
|
1075
|
static inline void sitronix_ts_pen_down(struct input_dev *input_dev, int id, u16 x, u16 y)
|
1076
|
{
|
1077
|
//printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
1078
|
|
1079
|
#ifdef SITRONIX_SUPPORT_MT_SLOT
|
1080
|
input_mt_slot(input_dev, id);
|
1081
|
input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, true);
|
1082
|
#ifndef SITRONIX_SWAP_XY
|
1083
|
input_report_abs(input_dev, ABS_MT_POSITION_X, x);
|
1084
|
input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
|
1085
|
#else
|
1086
|
input_report_abs(input_dev, ABS_MT_POSITION_X, y);
|
1087
|
input_report_abs(input_dev, ABS_MT_POSITION_Y, x);
|
1088
|
#endif // SITRONIX_SWAP_XY
|
1089
|
#else
|
1090
|
input_report_abs(input_dev, ABS_MT_TRACKING_ID, id);
|
1091
|
#ifndef SITRONIX_SWAP_XY
|
1092
|
input_report_abs(input_dev, ABS_MT_POSITION_X, x);
|
1093
|
input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
|
1094
|
#else
|
1095
|
input_report_abs(input_dev, ABS_MT_POSITION_X, y);
|
1096
|
input_report_abs(input_dev, ABS_MT_POSITION_Y, x);
|
1097
|
#endif // SITRONIX_SWAP_XY
|
1098
|
input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, 10);
|
1099
|
input_report_abs(input_dev, ABS_MT_WIDTH_MAJOR, 10);
|
1100
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
|
1101
|
input_report_abs(input_dev, ABS_MT_PRESSURE, 10);
|
1102
|
#endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
|
1103
|
input_mt_sync(input_dev);
|
1104
|
#endif // SITRONIX_SUPPORT_MT_SLOT
|
1105
|
DbgMsg("[%d](%d, %d)+\n", id, x, y);
|
1106
|
}
|
1107
|
|
1108
|
static inline void sitronix_ts_pen_up(struct input_dev *input_dev, int id)
|
1109
|
{
|
1110
|
//printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
1111
|
|
1112
|
#ifdef SITRONIX_SUPPORT_MT_SLOT
|
1113
|
input_mt_slot(input_dev, id);
|
1114
|
input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false);
|
1115
|
#else // for android 2.1
|
1116
|
input_report_abs(input_dev, ABS_MT_TRACKING_ID, id);
|
1117
|
input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, 0);
|
1118
|
input_report_abs(input_dev, ABS_MT_WIDTH_MAJOR, 0);
|
1119
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
|
1120
|
input_report_abs(input_dev, ABS_MT_PRESSURE, 0);
|
1121
|
#endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
|
1122
|
#endif // SITRONIX_SUPPORT_MT_SLOT
|
1123
|
DbgMsg("[%d]-\n", id);
|
1124
|
}
|
1125
|
|
1126
|
static inline void sitronix_ts_handle_sensor_key(struct input_dev *input_dev, struct sitronix_sensor_key_t *key_array, char *pre_key_status, char cur_key_status, int key_count)
|
1127
|
{
|
1128
|
|
1129
|
int i = 0;
|
1130
|
for(i = 0; i < key_count; i++){
|
1131
|
if(cur_key_status & (1 << i)){
|
1132
|
DbgMsg("sensor key[%d] down\n", i);
|
1133
|
//printk("kkk down now key %d \n",cur_key_status);
|
1134
|
input_report_key(input_dev, key_array[i].code, 1);
|
1135
|
|
1136
|
input_sync(input_dev);
|
1137
|
}else{
|
1138
|
if(*pre_key_status & (1 << i)){
|
1139
|
//printk("kkk up now key %d \n",cur_key_status);
|
1140
|
DbgMsg("sensor key[%d] up\n", i);
|
1141
|
input_report_key(input_dev, key_array[i].code, 0);
|
1142
|
input_sync(input_dev);
|
1143
|
}
|
1144
|
}
|
1145
|
}
|
1146
|
*pre_key_status = cur_key_status;
|
1147
|
}
|
1148
|
|
1149
|
#ifdef SITRONIX_AA_KEY
|
1150
|
static inline void sitronix_ts_handle_aa_key(struct input_dev *input_dev, struct sitronix_AA_key *key_array, char *pre_key_status, char cur_key_status, int key_count)
|
1151
|
{
|
1152
|
|
1153
|
int i = 0;
|
1154
|
for(i = 0; i < key_count; i++){
|
1155
|
if(cur_key_status & (1 << i)){
|
1156
|
DbgMsg("aa key[%d] down\n", i);
|
1157
|
input_report_key(input_dev, key_array[i].code, 1);
|
1158
|
input_sync(input_dev);
|
1159
|
}else{
|
1160
|
if(*pre_key_status & (1 << i)){
|
1161
|
DbgMsg("aa key[%d] up\n", i);
|
1162
|
input_report_key(input_dev, key_array[i].code, 0);
|
1163
|
input_sync(input_dev);
|
1164
|
}
|
1165
|
}
|
1166
|
}
|
1167
|
*pre_key_status = cur_key_status;
|
1168
|
}
|
1169
|
#endif // SITRONIX_AA_KEY
|
1170
|
|
1171
|
#ifdef SITRONIX_GESTURE
|
1172
|
|
1173
|
static void sitronix_gesture_func(struct input_dev *input_dev,int id)
|
1174
|
{
|
1175
|
if(id == G_PALM)
|
1176
|
{
|
1177
|
printk("Gesture for Palm to suspend \n");
|
1178
|
input_report_key(input_dev,KEY_POWER,1);// KEY_LEFT, 1);
|
1179
|
input_sync(input_dev);
|
1180
|
input_report_key(input_dev, KEY_POWER, 0);
|
1181
|
input_sync(input_dev);
|
1182
|
}
|
1183
|
}
|
1184
|
|
1185
|
|
1186
|
|
1187
|
#endif
|
1188
|
|
1189
|
#ifdef SITRONIX_SMART_WAKE_UP
|
1190
|
static int swk_flag = 0;
|
1191
|
static void sitronix_swk_set_swk_enable(struct sitronix_ts_data *ts)
|
1192
|
{
|
1193
|
|
1194
|
int ret = 0;
|
1195
|
unsigned char buffer[2] = {0};
|
1196
|
ret = sitronix_i2c_read_bytes(ts->client, MISC_CONTROL, buffer, 1);
|
1197
|
if(ret == 0)
|
1198
|
{
|
1199
|
buffer[1] = buffer[0] | 0x80;
|
1200
|
buffer[0] = MISC_CONTROL;
|
1201
|
sitronix_i2c_write_bytes(ts->client, buffer, 2);
|
1202
|
|
1203
|
msleep(500);
|
1204
|
}
|
1205
|
|
1206
|
|
1207
|
}
|
1208
|
static void sitronix_swk_func(struct input_dev *input_dev, int id)
|
1209
|
{
|
1210
|
if(id == DOUBLE_CLICK || id == SINGLE_CLICK)
|
1211
|
{
|
1212
|
if(swk_flag == 1)
|
1213
|
{
|
1214
|
//do wake up here
|
1215
|
printk("Smark Wake Up by Double click! \n");
|
1216
|
input_report_key(input_dev, KEY_POWER, 1);
|
1217
|
input_sync(input_dev);
|
1218
|
input_report_key(input_dev, KEY_POWER, 0);
|
1219
|
input_sync(input_dev);
|
1220
|
swk_flag = 0;
|
1221
|
}
|
1222
|
}
|
1223
|
else if(id == TOP_TO_DOWN_SLIDE)
|
1224
|
{
|
1225
|
printk("Smark Wake Up by TOP_TO_DOWN_SLIDE \n");
|
1226
|
//do wake up here
|
1227
|
}
|
1228
|
else if(id == DOWN_TO_UP_SLIDE)
|
1229
|
{
|
1230
|
printk("Smark Wake Up by DOWN_TO_UP_SLIDE \n");
|
1231
|
//do wake up here
|
1232
|
}
|
1233
|
else if(id == LEFT_TO_RIGHT_SLIDE)
|
1234
|
{
|
1235
|
printk("Smark Wake Up by LEFT_TO_RIGHT_SLIDE \n");
|
1236
|
//do wake up here
|
1237
|
}
|
1238
|
else if(id == RIGHT_TO_LEFT_SLIDE)
|
1239
|
{
|
1240
|
printk("Smark Wake Up by RIGHT_TO_LEFT_SLIDE \n");
|
1241
|
//do wake up here
|
1242
|
}
|
1243
|
}
|
1244
|
#endif //SITRONIX_SMART_WAKE_UP
|
1245
|
|
1246
|
static void sitronix_ts_work_func(struct work_struct *work)
|
1247
|
{
|
1248
|
int i;
|
1249
|
#ifdef SITRONIX_AA_KEY
|
1250
|
int j;
|
1251
|
char aa_key_status = 0;
|
1252
|
#endif // SITRONIX_AA_KEY
|
1253
|
int ret;
|
1254
|
|
1255
|
|
1256
|
#ifndef SITRONIX_INT_POLLING_MODE
|
1257
|
struct sitronix_ts_data *ts = container_of(work, struct sitronix_ts_data, work);
|
1258
|
#else
|
1259
|
struct sitronix_ts_data *ts = container_of(to_delayed_work(work), struct sitronix_ts_data, work);
|
1260
|
#endif // SITRONIX_INT_POLLING_MODE
|
1261
|
u16 x, y;
|
1262
|
uint8_t buffer[1+ SITRONIX_MAX_SUPPORTED_POINT * PIXEL_DATA_LENGTH_A] = {0};
|
1263
|
uint8_t PixelCount = 0;
|
1264
|
|
1265
|
DbgMsg("%s\n", __FUNCTION__);
|
1266
|
//printk("%s,line=%d\n,use_irq=%d,irq_num=%d,",__FUNCTION__,__LINE__,ts->use_irq,ts->client->irq);
|
1267
|
atomic_set(&sitronix_ts_in_int, 1);
|
1268
|
|
1269
|
#ifdef SITRONIX_GESTURE
|
1270
|
if(!ts->suspend_state)
|
1271
|
{
|
1272
|
ret = sitronix_i2c_read_bytes(ts->client, FINGERS, buffer, 1);
|
1273
|
printk("SITRONIX_GESTURE ret:%d ,value:0x%X\n",ret,buffer[0]);
|
1274
|
buffer[0] &= 0xF;
|
1275
|
if((ret == 0 && buffer[0] == G_PALM))
|
1276
|
{
|
1277
|
sitronix_gesture_func(ts->keyevent_input,buffer[0]);
|
1278
|
goto exit_invalid_data;
|
1279
|
}
|
1280
|
}
|
1281
|
#endif
|
1282
|
|
1283
|
#ifdef SITRONIX_SMART_WAKE_UP
|
1284
|
if(ts->suspend_state){
|
1285
|
//2.9.15 petitk add
|
1286
|
ret = sitronix_i2c_read_bytes(ts->client, SMART_WAKE_UP_REG, buffer, 1);
|
1287
|
if(ret ==0 && buffer[0] !=SWK_NO)
|
1288
|
{
|
1289
|
sitronix_swk_func(ts->keyevent_input, buffer[0]);
|
1290
|
goto exit_invalid_data;
|
1291
|
}
|
1292
|
}
|
1293
|
#endif //SITRONIX_SMART_WAKE_UP
|
1294
|
|
1295
|
ret = sitronix_i2c_read_bytes(ts->client, KEYS_REG, buffer, 1 + ts->max_touches * ts->pixel_length);
|
1296
|
if (ret < 0) {
|
1297
|
printk("read finger error (%d)\n", ret);
|
1298
|
i2cErrorCount++;
|
1299
|
goto exit_invalid_data;
|
1300
|
}
|
1301
|
|
1302
|
for(i = 0; i < ts->max_touches; i++){
|
1303
|
if(buffer[1 + i * ts->pixel_length + XY_COORD_H] & 0x80){
|
1304
|
|
1305
|
x = (u16)(buffer[1 + i * ts->pixel_length + XY_COORD_H] & 0x70) << 4 | buffer[1 + i * ts->pixel_length + X_COORD_L];
|
1306
|
y = (u16)(buffer[1 + i * ts->pixel_length + XY_COORD_H] & 0x07) << 8 | buffer[1 + i * ts->pixel_length + Y_COORD_L];
|
1307
|
//printk("%s:line=%d,x=%d,y=%d\n",__FUNCTION__,__LINE__,x,y);
|
1308
|
#ifndef SITRONIX_AA_KEY
|
1309
|
PixelCount++;
|
1310
|
//if (SpToAp_CheckState() == SP_STATE_IN_GETPIN)
|
1311
|
// SpToAp_InsertTpPixel(TP_PIXEL_TYPE_DOWN, i, x, y);
|
1312
|
//else
|
1313
|
sitronix_ts_pen_down(ts->input_dev, i, x, y);
|
1314
|
#else
|
1315
|
#ifdef SITRONIX_KEY_BOUNDARY_MANUAL_SPECIFY
|
1316
|
if(y < SITRONIX_TOUCH_RESOLUTION_Y){
|
1317
|
#else
|
1318
|
if(y < (ts->resolution_y - ts->resolution_y / SCALE_KEY_HIGH_Y)){
|
1319
|
#endif // SITRONIX_KEY_BOUNDARY_MANUAL_SPECIFY
|
1320
|
PixelCount++;
|
1321
|
sitronix_ts_pen_down(ts->input_dev, i, x, y);
|
1322
|
//DbgMsg("AREA_DISPLAY\n");
|
1323
|
}else{
|
1324
|
for(j = 0; j < (sizeof(sitronix_aa_key_array)/sizeof(struct sitronix_AA_key)); j++){
|
1325
|
if((x >= sitronix_aa_key_array[j].x_low) &&
|
1326
|
(x <= sitronix_aa_key_array[j].x_high) &&
|
1327
|
(y >= sitronix_aa_key_array[j].y_low) &&
|
1328
|
(y <= sitronix_aa_key_array[j].y_high)){
|
1329
|
aa_key_status |= (1 << j);
|
1330
|
//DbgMsg("AREA_KEY [%d]\n", j);
|
1331
|
break;
|
1332
|
}
|
1333
|
}
|
1334
|
}
|
1335
|
#endif // SITRONIX_AA_KEY
|
1336
|
}else{
|
1337
|
//sitronix_ts_pen_up(ts->input_dev, i);
|
1338
|
}
|
1339
|
}
|
1340
|
if(PixelCount == 0)
|
1341
|
{
|
1342
|
// if (SpToAp_CheckState() == SP_STATE_IN_GETPIN)
|
1343
|
// SpToAp_InsertTpPixel(TP_PIXEL_TYPE_UP,0, 0, 0);
|
1344
|
// else
|
1345
|
sitronix_ts_pen_up(ts->input_dev, 0);
|
1346
|
}
|
1347
|
|
1348
|
|
1349
|
input_report_key(ts->input_dev, BTN_TOUCH, PixelCount > 0);
|
1350
|
input_sync(ts->input_dev);
|
1351
|
|
1352
|
sitronix_ts_handle_sensor_key(ts->keyevent_input, sitronix_sensor_key_array, &sitronix_sensor_key_status, buffer[0], (sizeof(sitronix_sensor_key_array)/sizeof(struct sitronix_sensor_key_t)));
|
1353
|
#ifdef SITRONIX_AA_KEY
|
1354
|
sitronix_ts_handle_aa_key(ts->keyevent_input, sitronix_aa_key_array, &sitronix_aa_key_status, aa_key_status, (sizeof(sitronix_aa_key_array)/sizeof(struct sitronix_AA_key)));
|
1355
|
#endif // SITRONIX_AA_KEY
|
1356
|
|
1357
|
exit_invalid_data:
|
1358
|
#ifdef SITRONIX_INT_POLLING_MODE
|
1359
|
if(PixelCount > 0){
|
1360
|
#ifdef SITRONIX_MONITOR_THREAD
|
1361
|
if(ts->enable_monitor_thread == 1){
|
1362
|
atomic_set(&iMonitorThreadPostpone,1);
|
1363
|
}
|
1364
|
#endif // SITRONIX_MONITOR_THREAD
|
1365
|
schedule_delayed_work(&ts->work, msecs_to_jiffies(INT_POLLING_MODE_INTERVAL));
|
1366
|
}else{
|
1367
|
#ifdef CONFIG_HARDIRQS_SW_RESEND
|
1368
|
printk("Please not set HARDIRQS_SW_RESEND to prevent kernel from sending SW IRQ\n");
|
1369
|
#endif // CONFIG_HARDIRQS_SW_RESEND
|
1370
|
if (ts->use_irq){
|
1371
|
atomic_set(&sitronix_ts_irq_on, 1);
|
1372
|
enable_irq(ts->client->irq);
|
1373
|
}
|
1374
|
}
|
1375
|
#endif // SITRONIX_INT_POLLING_MODE
|
1376
|
#if defined(SITRONIX_LEVEL_TRIGGERED)
|
1377
|
if (ts->use_irq){
|
1378
|
atomic_set(&sitronix_ts_irq_on, 1);
|
1379
|
enable_irq(ts->client->irq);
|
1380
|
}
|
1381
|
#endif // defined(SITRONIX_LEVEL_TRIGGERED)
|
1382
|
if ((2 <= i2cErrorCount)){
|
1383
|
printk("I2C abnormal in work_func(), reset it!\n");
|
1384
|
sitronix_ts_reset_ic();
|
1385
|
i2cErrorCount = 0;
|
1386
|
#ifdef SITRONIX_MONITOR_THREAD
|
1387
|
if(ts->enable_monitor_thread == 1){
|
1388
|
StatusCheckCount = 0;
|
1389
|
if(ts->RawCRC_enabled == 0)
|
1390
|
sitronix_set_raw_data_type(&sitronix_ts_gpts);
|
1391
|
}
|
1392
|
#endif // SITRONIX_MONITOR_THREAD
|
1393
|
}
|
1394
|
atomic_set(&sitronix_ts_in_int, 0);
|
1395
|
|
1396
|
}
|
1397
|
|
1398
|
static irqreturn_t sitronix_ts_irq_handler(int irq, void *dev_id)
|
1399
|
{
|
1400
|
struct sitronix_ts_data *ts = dev_id;
|
1401
|
printk("%s,line=%d\n",__FUNCTION__,__LINE__);
|
1402
|
DbgMsg("%s\n", __FUNCTION__);
|
1403
|
atomic_set(&sitronix_ts_in_int, 1);
|
1404
|
#if defined(SITRONIX_LEVEL_TRIGGERED) || defined(SITRONIX_INT_POLLING_MODE)
|
1405
|
atomic_set(&sitronix_ts_irq_on, 0);
|
1406
|
disable_irq_nosync(ts->client->irq);
|
1407
|
#endif // defined(SITRONIX_LEVEL_TRIGGERED) || defined(SITRONIX_INT_POLLING_MODE)
|
1408
|
#ifdef SITRONIX_MONITOR_THREAD
|
1409
|
if(ts->enable_monitor_thread == 1){
|
1410
|
atomic_set(&iMonitorThreadPostpone,1);
|
1411
|
}
|
1412
|
#endif // SITRONIX_MONITOR_THREAD
|
1413
|
#ifndef SITRONIX_INT_POLLING_MODE
|
1414
|
schedule_work(&ts->work);
|
1415
|
#else
|
1416
|
schedule_delayed_work(&ts->work, msecs_to_jiffies(0));
|
1417
|
#endif // SITRONIX_INT_POLLING_MODE
|
1418
|
return IRQ_HANDLED;
|
1419
|
}
|
1420
|
|
1421
|
#ifdef SITRONIX_SYSFS
|
1422
|
static ssize_t sitronix_ts_reprobe_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
1423
|
{
|
1424
|
printk("sitronix_ts_reprobe_store!!!!!\n");
|
1425
|
sitronix_ts_sysfs_using = true;
|
1426
|
sitronix_ts_reprobe();
|
1427
|
sitronix_ts_sysfs_using = false;
|
1428
|
return count;
|
1429
|
}
|
1430
|
|
1431
|
static DEVICE_ATTR(reprobe, 0220, NULL, sitronix_ts_reprobe_store);
|
1432
|
|
1433
|
static struct attribute *sitronix_ts_attrs_v0[] = {
|
1434
|
&dev_attr_reprobe.attr,
|
1435
|
NULL,
|
1436
|
};
|
1437
|
|
1438
|
static struct attribute_group sitronix_ts_attr_group_v0 = {
|
1439
|
.name = "sitronix_ts_attrs",
|
1440
|
.attrs = sitronix_ts_attrs_v0,
|
1441
|
};
|
1442
|
|
1443
|
static int sitronix_ts_create_sysfs_entry(struct i2c_client *client)
|
1444
|
{
|
1445
|
int err;
|
1446
|
|
1447
|
err = sysfs_create_group(&(client->dev.kobj), &sitronix_ts_attr_group_v0);
|
1448
|
if (err) {
|
1449
|
dev_warn(&client->dev, "%s(%u): sysfs_create_group() failed!\n", __FUNCTION__, __LINE__);
|
1450
|
}
|
1451
|
return err;
|
1452
|
}
|
1453
|
|
1454
|
static void sitronix_ts_destroy_sysfs_entry(struct i2c_client *client)
|
1455
|
{
|
1456
|
sysfs_remove_group(&(client->dev.kobj), &sitronix_ts_attr_group_v0);
|
1457
|
|
1458
|
return;
|
1459
|
}
|
1460
|
#endif // SITRONIX_SYSFS
|
1461
|
|
1462
|
/*******************************************************
|
1463
|
Function:
|
1464
|
Disable IRQ Function.
|
1465
|
|
1466
|
Input:
|
1467
|
data: i2c client private struct.
|
1468
|
|
1469
|
Output:
|
1470
|
None.
|
1471
|
*******************************************************/
|
1472
|
void sitronix_irq_disable(struct sitronix_ts_data *data)
|
1473
|
{
|
1474
|
unsigned long irqflags;
|
1475
|
int ret;
|
1476
|
|
1477
|
DbgMsg("%s ---start!---\n", __func__);
|
1478
|
spin_lock_irqsave(&data->irq_lock, irqflags);
|
1479
|
if (!data->irq_is_disable) {
|
1480
|
data->irq_is_disable = 1;
|
1481
|
//ret = input_set_int_enable(&(config_info.input_type), 0);
|
1482
|
if (ret < 0)
|
1483
|
ErrorMsg("%s irq disable failed\n", __func__);
|
1484
|
}
|
1485
|
spin_unlock_irqrestore(&data->irq_lock, irqflags);
|
1486
|
}
|
1487
|
|
1488
|
/*******************************************************
|
1489
|
Function:
|
1490
|
Disable IRQ Function.
|
1491
|
|
1492
|
Input:
|
1493
|
data: i2c client private struct.
|
1494
|
|
1495
|
Output:
|
1496
|
None.
|
1497
|
*******************************************************/
|
1498
|
void sitronix_irq_enable(struct sitronix_ts_data *data)
|
1499
|
{
|
1500
|
unsigned long irqflags = 0;
|
1501
|
int ret;
|
1502
|
|
1503
|
DbgMsg("%s ---start!---\n", __func__);
|
1504
|
|
1505
|
spin_lock_irqsave(&data->irq_lock, irqflags);
|
1506
|
if (data->irq_is_disable) {
|
1507
|
data->irq_is_disable = 0;
|
1508
|
//ret = input_set_int_enable(&(config_info.input_type), 1);
|
1509
|
if (ret < 0)
|
1510
|
ErrorMsg("%s irq enable failed\n", __func__);
|
1511
|
}
|
1512
|
spin_unlock_irqrestore(&data->irq_lock, irqflags);
|
1513
|
}
|
1514
|
|
1515
|
|
1516
|
#if (CTP_AP_SP_SYNC_WAY != CTP_AP_SP_SYNC_NONE)
|
1517
|
int sitronix_touch_reinit(void)
|
1518
|
{
|
1519
|
if(gSitronixPtr == NULL)
|
1520
|
return -1;
|
1521
|
printk("%s\n",__func__);
|
1522
|
sitronix_irq_enable(gSitronixPtr);
|
1523
|
return 0;
|
1524
|
}
|
1525
|
|
1526
|
int sitronix_touch_uninit(void)
|
1527
|
{
|
1528
|
if(gSitronixPtr == NULL)
|
1529
|
return -1;
|
1530
|
printk("%s\n",__func__);
|
1531
|
sitronix_irq_disable(gSitronixPtr);
|
1532
|
while(cancel_work_sync(&gSitronixPtr->work));
|
1533
|
//flush_workqueue(sitronix_wq);
|
1534
|
return 0;
|
1535
|
}
|
1536
|
#endif
|
1537
|
|
1538
|
#if (CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
1539
|
#define CTP_SYNC_IO_OUT 1
|
1540
|
#define CTP_SYNC_IO_IN 0
|
1541
|
#if 0
|
1542
|
|
1543
|
static int ap_sp_sync_gpio(struct gpio_config gpio, int direction, int value)
|
1544
|
{
|
1545
|
//int status = 0;
|
1546
|
int ret = 0;
|
1547
|
|
1548
|
if(0 != gpio_request(gpio.gpio, "ctp_sync_io")) {
|
1549
|
ErrorMsg("ap_sp_sync_gpio gpio_request is failed\n");
|
1550
|
return -1;
|
1551
|
}
|
1552
|
|
1553
|
if(CTP_SYNC_IO_OUT == direction)
|
1554
|
{
|
1555
|
if (0 != gpio_direction_output(gpio.gpio, value)) {
|
1556
|
ErrorMsg(KERN_ERR "ap_sp_sync_gpio gpio set err!");
|
1557
|
return -1;
|
1558
|
}
|
1559
|
}
|
1560
|
else if(CTP_SYNC_IO_IN == direction)
|
1561
|
{
|
1562
|
if (0 != gpio_direction_input(gpio.gpio)) {
|
1563
|
ErrorMsg(KERN_ERR "ap_sp_sync_gpio gpio set err!");
|
1564
|
return -1;
|
1565
|
}
|
1566
|
ret = __gpio_get_value(gpio.gpio);
|
1567
|
}
|
1568
|
|
1569
|
gpio_free(gpio.gpio);
|
1570
|
|
1571
|
return ret;
|
1572
|
}
|
1573
|
#endif
|
1574
|
|
1575
|
static void sitronix_io_sync_work_func(struct work_struct *work)
|
1576
|
{
|
1577
|
int pin_val = 0xff;
|
1578
|
unsigned long irqflags;
|
1579
|
printk("%s:line=%d,",__FUNCTION__,__LINE__);
|
1580
|
// pin_val = ap_sp_sync_gpio(sitronix_sync_io,CTP_SYNC_IO_IN,0);
|
1581
|
//printk("P:%d\n",pin_val);
|
1582
|
if(0 == pin_val)
|
1583
|
{
|
1584
|
spin_lock_irqsave(&ctp_sync_lock,irqflags);
|
1585
|
ctp_sync_pulse_count++;
|
1586
|
if(1 == ctp_sync_io_last_status)
|
1587
|
{
|
1588
|
ctp_sync_io_last_status = 0;
|
1589
|
}
|
1590
|
spin_unlock_irqrestore(&ctp_sync_lock,irqflags);
|
1591
|
|
1592
|
}
|
1593
|
else if(1 == pin_val)
|
1594
|
{
|
1595
|
if(!ctp_sync_io_last_status)
|
1596
|
{
|
1597
|
printk("C:%d\n",ctp_sync_pulse_count);
|
1598
|
if((ctp_sync_pulse_count > 1) && (ctp_sync_pulse_count < 4)) //tp switch to sp siginal
|
1599
|
{
|
1600
|
printk("U\n");
|
1601
|
sitronix_touch_uninit();//\B4˺\AF\CA\FD\BB\E1\D7\E8\C8\FB\D0\E8Ҫ\D4ٿ\AAһ\B8\F6\B9\A4\D7\F7\B6\D3\C1\D0?
|
1602
|
}
|
1603
|
else if((ctp_sync_pulse_count > 3) && (ctp_sync_pulse_count < 6)) //tp switch to ap siginal
|
1604
|
{
|
1605
|
printk("R\n");
|
1606
|
sitronix_touch_reinit();
|
1607
|
}
|
1608
|
}
|
1609
|
spin_lock_irqsave(&ctp_sync_lock,irqflags);
|
1610
|
ctp_sync_io_last_status = 1;
|
1611
|
ctp_sync_pulse_count = 0;
|
1612
|
spin_unlock_irqrestore(&ctp_sync_lock,irqflags);
|
1613
|
|
1614
|
}
|
1615
|
|
1616
|
}
|
1617
|
|
1618
|
void ctp_sync_timer_func(unsigned long data)
|
1619
|
{
|
1620
|
printk("%s:line=%d,",__FUNCTION__,__LINE__);
|
1621
|
|
1622
|
queue_work(sitronix_io_sync_workqueue, &gSitronixPtr->sitronix_io_sync_work);
|
1623
|
|
1624
|
mod_timer(&ctp_sync_timer,jiffies+HZ/50);
|
1625
|
}
|
1626
|
#endif
|
1627
|
|
1628
|
#define SITRONIX_COORDS_ARR_SIZE 4
|
1629
|
#define MAX_BUTTONS 4
|
1630
|
#define PROP_NAME_SIZE 24
|
1631
|
|
1632
|
|
1633
|
static int sitronix_ts_get_dt_coords(struct device *dev, char *name,
|
1634
|
struct sitronix_i2c_touch_platform_data *pdata)
|
1635
|
{
|
1636
|
struct property *prop;
|
1637
|
struct device_node *np = dev->of_node;
|
1638
|
int rc;
|
1639
|
u32 coords[SITRONIX_COORDS_ARR_SIZE];
|
1640
|
printk("%s,%d\n",__FUNCTION__,__LINE__);
|
1641
|
|
1642
|
prop = of_find_property(np, name, NULL);
|
1643
|
if (!prop)
|
1644
|
return -EINVAL;
|
1645
|
if (!prop->value)
|
1646
|
return -ENODATA;
|
1647
|
|
1648
|
rc = of_property_read_u32_array(np, name, coords,
|
1649
|
SITRONIX_COORDS_ARR_SIZE);
|
1650
|
if (rc && (rc != -EINVAL)) {
|
1651
|
dev_err(dev, "Unable to read %s\n", name);
|
1652
|
return rc;
|
1653
|
}
|
1654
|
|
1655
|
if (!strcmp(name, "sitronix,panel-coords")) {
|
1656
|
pdata->panel_minx = coords[0];
|
1657
|
pdata->panel_miny = coords[1];
|
1658
|
pdata->panel_maxx = coords[2];
|
1659
|
pdata->panel_maxy = coords[3];
|
1660
|
printk("%s:panel-coords,minx=%d,miny=%d,maxx=%d,maxy=%d\n",__FUNCTION__,\
|
1661
|
pdata->panel_minx,pdata->panel_miny,pdata->panel_maxx,pdata->panel_maxy);
|
1662
|
} else if (!strcmp(name, "sitronix,display-coords")) {
|
1663
|
pdata->x_min = coords[0];
|
1664
|
pdata->y_min = coords[1];
|
1665
|
pdata->x_max = coords[2];
|
1666
|
pdata->y_max = coords[3];
|
1667
|
printk("%s:display-coords,minx=%d,miny=%d,maxx=%d,maxy=%d\n",__FUNCTION__,\
|
1668
|
pdata->panel_minx,pdata->panel_miny,pdata->panel_maxx,pdata->panel_maxy);
|
1669
|
} else {
|
1670
|
dev_err(dev, "unsupported property %s\n", name);
|
1671
|
return -EINVAL;
|
1672
|
}
|
1673
|
|
1674
|
return 0;
|
1675
|
}
|
1676
|
#if 1
|
1677
|
|
1678
|
static int sitronix_parse_dt(struct device *dev,
|
1679
|
struct sitronix_i2c_touch_platform_data *pdata)
|
1680
|
{
|
1681
|
int rc;
|
1682
|
struct device_node *np = dev->of_node;
|
1683
|
struct property *prop;
|
1684
|
u32 temp_val, num_buttons;
|
1685
|
u32 button_map[MAX_BUTTONS];
|
1686
|
//char prop_name[PROP_NAME_SIZE];
|
1687
|
//int i, read_cfg_num;
|
1688
|
|
1689
|
printk("%s,%d\n",__FUNCTION__,__LINE__);
|
1690
|
|
1691
|
pdata->name = "sitronix";
|
1692
|
rc = sitronix_ts_get_dt_coords(dev, "sitronix,panel-coords", pdata);
|
1693
|
if (rc && (rc != -EINVAL))
|
1694
|
return rc;
|
1695
|
|
1696
|
rc = sitronix_ts_get_dt_coords(dev, "sitronix,display-coords", pdata);
|
1697
|
if (rc)
|
1698
|
return rc;
|
1699
|
|
1700
|
pdata->i2c_pull_up = of_property_read_bool(np, "sitronix,i2c-pull-up");
|
1701
|
|
1702
|
pdata->no_force_update = of_property_read_bool(np,
|
1703
|
"sitronix,no-force-update");
|
1704
|
|
1705
|
pdata->enable_power_off = of_property_read_bool(np,
|
1706
|
"sitronix,enable-power-off");
|
1707
|
pdata->fw_vkey_support = of_property_read_bool(np,
|
1708
|
"sitronix,fw-vkey-support");
|
1709
|
/* reset, irq gpio info */
|
1710
|
pdata->reset_gpio = of_get_named_gpio_flags(np, "sitronix,reset-gpios",
|
1711
|
0,
|
1712
|
&pdata->reset_gpio_flags);
|
1713
|
if (pdata->reset_gpio < 0)
|
1714
|
return pdata->reset_gpio;
|
1715
|
|
1716
|
pdata->irq_gpio = of_get_named_gpio_flags(np, "sitronix,interrupt-gpios",
|
1717
|
0, &pdata->irq_gpio_flags);
|
1718
|
printk("%s,pdata->irq_gpio=%d\n",__FUNCTION__,pdata->irq_gpio);
|
1719
|
if (pdata->irq_gpio < 0)
|
1720
|
return pdata->irq_gpio;
|
1721
|
|
1722
|
rc = of_property_read_string(np, "sitronix,product-id",
|
1723
|
&pdata->product_id);
|
1724
|
if (rc && (rc != -EINVAL)) {
|
1725
|
dev_err(dev, "Failed to parse product_id.");
|
1726
|
return -EINVAL;
|
1727
|
}
|
1728
|
|
1729
|
rc = of_property_read_u32(np, "sitronix,num_max_touches",
|
1730
|
&pdata->num_max_touches);
|
1731
|
if (rc && (rc != -EINVAL)) {
|
1732
|
dev_err(dev, "Failed to parse num_max_touches.");
|
1733
|
return -EINVAL;
|
1734
|
}
|
1735
|
|
1736
|
rc = of_property_read_u32(np, "sitronix,soft_rst_dly",
|
1737
|
&pdata->soft_rst_dly);
|
1738
|
if (rc && (rc != -EINVAL)) {
|
1739
|
dev_err(dev, "Failed to parse soft reset delay.");
|
1740
|
return -EINVAL;
|
1741
|
}
|
1742
|
|
1743
|
rc = of_property_read_string(np, "sitronix,fw_name", &pdata->fw_name);
|
1744
|
if (rc && (rc != -EINVAL)) {
|
1745
|
dev_err(dev, "Failed to parse firmware name.\n");
|
1746
|
return -EINVAL;
|
1747
|
}
|
1748
|
|
1749
|
prop = of_find_property(np, "sitronix,button-map", NULL);
|
1750
|
if (prop) {
|
1751
|
num_buttons = prop->length / sizeof(temp_val);
|
1752
|
if (num_buttons > MAX_BUTTONS)
|
1753
|
return -EINVAL;
|
1754
|
|
1755
|
rc = of_property_read_u32_array(np,
|
1756
|
"sitronix,button-map", button_map,
|
1757
|
num_buttons);
|
1758
|
if (rc) {
|
1759
|
dev_err(dev, "Unable to read key codes\n");
|
1760
|
return rc;
|
1761
|
}
|
1762
|
}
|
1763
|
#if 0
|
1764
|
read_cfg_num = 0;
|
1765
|
for (i = 0; i < GOODIX_MAX_CFG_GROUP; i++) {
|
1766
|
snprintf(prop_name, sizeof(prop_name), "sitronix,cfg-data%d", i);
|
1767
|
prop = of_find_property(np, prop_name,
|
1768
|
&pdata->config_data_len[i]);
|
1769
|
if (!prop || !prop->value) {
|
1770
|
pdata->config_data_len[i] = 0;
|
1771
|
pdata->config_data[i] = NULL;
|
1772
|
continue;
|
1773
|
}
|
1774
|
pdata->config_data[i] = devm_kzalloc(dev,
|
1775
|
GTP_CONFIG_MAX_LENGTH +
|
1776
|
GTP_ADDR_LENGTH,
|
1777
|
GFP_KERNEL);
|
1778
|
if (!pdata->config_data[i]) {
|
1779
|
dev_err(dev,
|
1780
|
"Not enough memory for panel config data %d\n",
|
1781
|
i);
|
1782
|
return -ENOMEM;
|
1783
|
}
|
1784
|
pdata->config_data[i][0] = GTP_REG_CONFIG_DATA >> 8;
|
1785
|
pdata->config_data[i][1] = GTP_REG_CONFIG_DATA & 0xff;
|
1786
|
memcpy(&pdata->config_data[i][GTP_ADDR_LENGTH],
|
1787
|
prop->value, pdata->config_data_len[i]);
|
1788
|
read_cfg_num++;
|
1789
|
}
|
1790
|
dev_info(dev, "%d config data read from device tree.\n", read_cfg_num);
|
1791
|
#endif
|
1792
|
return 0;
|
1793
|
}
|
1794
|
#endif
|
1795
|
|
1796
|
|
1797
|
#if 0//power
|
1798
|
static int sitronix_power_on(struct goodix_ts_data *ts)
|
1799
|
{
|
1800
|
|
1801
|
if (ts->power_on) {
|
1802
|
dev_info(&ts->client->dev,
|
1803
|
"Device already power on\n");
|
1804
|
return 0;
|
1805
|
}
|
1806
|
ts->power_on = true; //[DEBUG] Modify TCT-NB Tianhongwei 05/05/2014 power off ic when sleepin if the gesture is disabled
|
1807
|
return 0;
|
1808
|
}
|
1809
|
|
1810
|
static int goodix_power_off(struct goodix_ts_data *ts)
|
1811
|
{
|
1812
|
if (!ts->power_on) {
|
1813
|
dev_info(&ts->client->dev,
|
1814
|
"Device already power off\n");
|
1815
|
return 0;
|
1816
|
}
|
1817
|
ts->power_on = false;
|
1818
|
return 0;
|
1819
|
}
|
1820
|
|
1821
|
|
1822
|
static int sitronix_power_init(struct goodix_ts_data *ts)
|
1823
|
{
|
1824
|
|
1825
|
#if 0
|
1826
|
ts->vdd = regulator_get(&ts->client->dev, "vdd");
|
1827
|
if (IS_ERR(ts->vdd)) {
|
1828
|
ret = PTR_ERR(ts->vdd);
|
1829
|
dev_info(&ts->client->dev,
|
1830
|
"Regulator get failed vdd ret=%d\n", ret);
|
1831
|
}
|
1832
|
|
1833
|
ts->vcc_i2c = regulator_get(&ts->client->dev, "vcc_i2c");/*[BUGFIX]-MOD by TCTNB.XQJ,09/18/2013,FR-514195,GT915 tp MIATA development,i2c,only for compil*/
|
1834
|
if (IS_ERR(ts->vcc_i2c)) {
|
1835
|
ret = PTR_ERR(ts->vcc_i2c);
|
1836
|
dev_info(&ts->client->dev,
|
1837
|
"Regulator get failed vcc_i2c ret=%d\n", ret);
|
1838
|
}
|
1839
|
#endif
|
1840
|
|
1841
|
return 0;
|
1842
|
}
|
1843
|
|
1844
|
|
1845
|
static int sitronix_power_deinit(struct goodix_ts_data *ts)
|
1846
|
{
|
1847
|
regulator_put(ts->vdd);
|
1848
|
regulator_put(ts->vcc_i2c);
|
1849
|
return 0;
|
1850
|
}
|
1851
|
#endif
|
1852
|
|
1853
|
|
1854
|
|
1855
|
#if 0
|
1856
|
static int sit_pinctrl_init(struct rst_pin_ctrl *akm)
|
1857
|
{
|
1858
|
struct i2c_client *client = akm->client;;
|
1859
|
|
1860
|
printk("##gavin %s,line=%d\n",__FUNCTION__,__LINE__);
|
1861
|
akm->pinctrl = devm_pinctrl_get(&client->dev);
|
1862
|
|
1863
|
if (IS_ERR_OR_NULL(akm->pinctrl)) {
|
1864
|
dev_err(&client->dev, "Failed to get pinctrl\n");
|
1865
|
return PTR_ERR(akm->pinctrl);
|
1866
|
}
|
1867
|
//pmx_ts_active","pmx_ts_suspend","pmx_ts_release";
|
1868
|
akm->rst_pin_ts_active = pinctrl_lookup_state(akm->pinctrl, "pmx_ts_active");
|
1869
|
if (IS_ERR_OR_NULL(akm->rst_pin_ts_active)) {
|
1870
|
dev_err(&client->dev, "Failed to look up rst_pin_ts_active state\n");
|
1871
|
return PTR_ERR(akm->rst_pin_ts_active);
|
1872
|
}
|
1873
|
|
1874
|
akm->rst_pin_ts_suspend = pinctrl_lookup_state(akm->pinctrl, "pmx_ts_suspend");
|
1875
|
if (IS_ERR_OR_NULL(akm->rst_pin_ts_suspend)) {
|
1876
|
dev_err(&client->dev, "Failed to look up rst_pin_ts_suspend state\n");
|
1877
|
return PTR_ERR(akm->rst_pin_ts_suspend);
|
1878
|
}
|
1879
|
|
1880
|
akm->rst_pin_ts_release = pinctrl_lookup_state(akm->pinctrl, "pmx_ts_release");
|
1881
|
if (IS_ERR_OR_NULL(akm->rst_pin_ts_release)) {
|
1882
|
dev_err(&client->dev, "Failed to look up rst_pin_ts_release state\n");
|
1883
|
return PTR_ERR(akm->rst_pin_ts_release);
|
1884
|
}
|
1885
|
|
1886
|
return 0;
|
1887
|
}
|
1888
|
|
1889
|
|
1890
|
#endif
|
1891
|
static int sitronix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
1892
|
{
|
1893
|
int i;
|
1894
|
int ret = 0;
|
1895
|
uint16_t max_x = 0, max_y = 0;
|
1896
|
uint8_t err_code = 0;
|
1897
|
uint8_t dev_status = 0;
|
1898
|
uint8_t rc;
|
1899
|
struct sitronix_i2c_touch_platform_data *pdata;
|
1900
|
//struct sitronix_ts_data *sitronix_ts_gpts;
|
1901
|
|
1902
|
printk("%s,%d\n",__FUNCTION__,__LINE__);
|
1903
|
|
1904
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
|
1905
|
{
|
1906
|
ret = -ENODEV;
|
1907
|
goto err_check_functionality_failed;
|
1908
|
}
|
1909
|
|
1910
|
pdata = devm_kzalloc(&client->dev,
|
1911
|
sizeof(struct sitronix_i2c_touch_platform_data),
|
1912
|
GFP_KERNEL);
|
1913
|
if (!pdata)
|
1914
|
{
|
1915
|
dev_err(&client->dev,"GTP Failed to allocate memory for pdata\n");
|
1916
|
return -ENOMEM;
|
1917
|
}
|
1918
|
ret = sitronix_parse_dt(&client->dev, pdata);
|
1919
|
if (ret)
|
1920
|
return ret;
|
1921
|
|
1922
|
|
1923
|
sitronix_ts_gpts.irq_gpio = pdata->irq_gpio;
|
1924
|
sitronix_ts_gpts.reset_gpio = pdata->reset_gpio;
|
1925
|
#if 0//for touchscreen reset
|
1926
|
sitronix_ts_reset_ic();
|
1927
|
#else
|
1928
|
printk("%s,line=%d,pdata->reset_gpio =%d\n", __FUNCTION__,__LINE__,pdata->reset_gpio);
|
1929
|
rc = gpio_request(pdata->reset_gpio, "reset_gpio");
|
1930
|
//if (rc)
|
1931
|
//ret rc;
|
1932
|
gpio_direction_output(sitronix_ts_gpts.reset_gpio, 0);
|
1933
|
msleep(3);
|
1934
|
gpio_direction_output(sitronix_ts_gpts.reset_gpio, 1);
|
1935
|
msleep(150);
|
1936
|
#if 0//for reset pin test
|
1937
|
for(i = 0;i<10;i++)
|
1938
|
{
|
1939
|
gpio_direction_output(sitronix_ts_gpts.reset_gpio, 0);
|
1940
|
usleep(3);
|
1941
|
gpio_direction_output(sitronix_ts_gpts.reset_gpio, 1);
|
1942
|
usleep(3);
|
1943
|
}
|
1944
|
#endif
|
1945
|
//rc = gpio_request(pdata->reset_gpio, "reset_gpio");
|
1946
|
//if (rc)
|
1947
|
//ret rc;
|
1948
|
//gpio_direction_output(pdata->reset_gpio, 0);
|
1949
|
//msleep(3);
|
1950
|
//gpio_direction_output(pdata->reset_gpio, 1);
|
1951
|
//msleep(150);
|
1952
|
#endif
|
1953
|
|
1954
|
sitronix_ts_gpts.client = client;
|
1955
|
#ifdef ST_UPGRADE_FIRMWARE
|
1956
|
#ifdef ST_FIREWARE_FILE
|
1957
|
kthread_run(st_upgrade_fw, "Sitronix", "sitronix_update");
|
1958
|
#else
|
1959
|
st_upgrade_fw();
|
1960
|
#endif //ST_FIREWARE_FILE
|
1961
|
|
1962
|
#endif //ST_UPGRADE_FIRMWARE
|
1963
|
|
1964
|
|
1965
|
if(((ret = sitronix_ts_get_device_status(client, &err_code, &dev_status)) < 0) || (dev_status == 0x6) || ((err_code == 0x8)&&(dev_status == 0x0))){
|
1966
|
if((dev_status == 0x6) || ((err_code == 0x8)&&(dev_status == 0x0))){
|
1967
|
sitronix_ts_gpts.client = client;
|
1968
|
}
|
1969
|
ret = -EPERM;
|
1970
|
goto err_device_info_error;
|
1971
|
}
|
1972
|
sitronix_ts_gpts.client = client;
|
1973
|
sitronix_ts_gpts.suspend_state = 0;
|
1974
|
i2c_set_clientdata(client, &sitronix_ts_gpts);
|
1975
|
if((ret = sitronix_ts_get_touch_info(&sitronix_ts_gpts)) < 0)
|
1976
|
goto err_device_info_error;
|
1977
|
|
1978
|
|
1979
|
#if 0//for touchscreen irq
|
1980
|
printk("%s:pdata->irq_gpio=%d\n",__FUNCTION__,pdata->irq_gpio);
|
1981
|
client->irq=pdata->irq_gpio;
|
1982
|
printk("gpio num:%d, irq num:%d\n",CTP_IRQ_NUMBER,client->irq);
|
1983
|
#else
|
1984
|
|
1985
|
#if 0
|
1986
|
ret = gpio_request(pdata->irq_gpio, "GTP_INT_IRQ");
|
1987
|
if (ret < 0)
|
1988
|
{
|
1989
|
GTP_ERROR("Failed to request GPIO:%d, ERRNO:%d",
|
1990
|
(s32) pdata->irq_gpio, ret);
|
1991
|
ret = -ENODEV;
|
1992
|
}
|
1993
|
else
|
1994
|
{
|
1995
|
printk("%s:pdata->irq_gpio=%d\n",__FUNCTION__,pdata->irq_gpio);
|
1996
|
ret = gpio_direction_input(pdata->irq_gpio);
|
1997
|
if (ret < 0)
|
1998
|
gpio_free(pdata->irq_gpio);
|
1999
|
client->irq = gpio_to_irq(pdata->irq_gpio);
|
2000
|
}
|
2001
|
printk("gpio num:%d, irq num:%d\n",CTP_IRQ_NUMBER,client->irq);
|
2002
|
|
2003
|
#else
|
2004
|
ret = gpio_request(sitronix_ts_gpts.irq_gpio, "GTP_INT_IRQ");
|
2005
|
if (ret < 0)
|
2006
|
{
|
2007
|
GTP_ERROR("Failed to request GPIO:%d, ERRNO:%d",
|
2008
|
(s32) sitronix_ts_gpts.irq_gpio, ret);
|
2009
|
ret = -ENODEV;
|
2010
|
}
|
2011
|
else
|
2012
|
{
|
2013
|
printk("%s:sitronix_ts_gpts.irq_gpio =%d\n",__FUNCTION__,sitronix_ts_gpts.irq_gpio);
|
2014
|
ret = gpio_direction_input(sitronix_ts_gpts.irq_gpio);
|
2015
|
if (ret < 0)
|
2016
|
gpio_free(sitronix_ts_gpts.irq_gpio);
|
2017
|
sitronix_ts_gpts.client->irq = gpio_to_irq(sitronix_ts_gpts.irq_gpio);
|
2018
|
}
|
2019
|
printk("gpio num:%d, irq num:%d\n",CTP_IRQ_NUMBER,sitronix_ts_gpts.client->irq);
|
2020
|
#endif
|
2021
|
|
2022
|
//client->irq = gpio_to_irq(CTP_IRQ_NUMBER);
|
2023
|
//DbgMsg("gpio num:%d, irq num:%d\n",CTP_IRQ_NUMBER,client->irq);
|
2024
|
#endif
|
2025
|
|
2026
|
|
2027
|
#ifdef SITRONIX_IDENTIFY_ID
|
2028
|
if((ret = sitronix_ts_identify(&sitronix_ts_gpts)) < 0)
|
2029
|
goto err_device_info_error;
|
2030
|
#endif // SITRONIX_IDENTIFY_ID
|
2031
|
|
2032
|
#ifndef SITRONIX_INT_POLLING_MODE
|
2033
|
INIT_WORK(&(sitronix_ts_gpts.work), sitronix_ts_work_func);
|
2034
|
#else
|
2035
|
INIT_DELAYED_WORK(&(sitronix_ts_gpts.work), sitronix_ts_work_func);
|
2036
|
#endif // SITRONIX_INT_POLLING_MODE
|
2037
|
|
2038
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
2039
|
INIT_WORK(&sitronix_ts_gpts.sitronix_io_sync_work, sitronix_io_sync_work_func);
|
2040
|
#endif
|
2041
|
|
2042
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
2043
|
sitronix_io_sync_workqueue= create_singlethread_workqueue("sitronix_io_sync_workqueue");
|
2044
|
if (!sitronix_io_sync_workqueue) {
|
2045
|
ErrorMsg("Creat sitronix_io_sync_workqueue workqueue failed.\n");
|
2046
|
goto err_device_info_error;
|
2047
|
}
|
2048
|
#endif
|
2049
|
|
2050
|
#ifdef SITRONIX_MONITOR_THREAD
|
2051
|
if(sitronix_ts_gpts.enable_monitor_thread == 1){
|
2052
|
//== Add thread to monitor chip
|
2053
|
atomic_set(&iMonitorThreadPostpone,1);
|
2054
|
sitronix_ts_gpts.sitronix_mt_fp = sitronix_ts_gpts.RawCRC_enabled? sitronix_ts_monitor_thread_v2 : sitronix_ts_monitor_thread;
|
2055
|
SitronixMonitorThread = kthread_run(sitronix_ts_gpts.sitronix_mt_fp,"Sitronix","Monitorthread");
|
2056
|
if(IS_ERR(SitronixMonitorThread))
|
2057
|
SitronixMonitorThread = NULL;
|
2058
|
}
|
2059
|
#endif // SITRONIX_MONITOR_THREAD
|
2060
|
|
2061
|
sitronix_ts_gpts.input_dev = input_allocate_device();
|
2062
|
if (sitronix_ts_gpts.input_dev == NULL){
|
2063
|
printk("Can not allocate memory for input device.");
|
2064
|
ret = -ENOMEM;
|
2065
|
goto err_input_dev_alloc_failed;
|
2066
|
}
|
2067
|
|
2068
|
sitronix_ts_gpts.input_dev->name = SITRONIX_I2C_TOUCH_MT_INPUT_DEV_NAME;
|
2069
|
sitronix_ts_gpts.input_dev->dev.parent = &client->dev;
|
2070
|
sitronix_ts_gpts.input_dev->id.bustype = BUS_I2C;
|
2071
|
|
2072
|
set_bit(EV_KEY, sitronix_ts_gpts.input_dev->evbit);
|
2073
|
set_bit(BTN_TOUCH, sitronix_ts_gpts.input_dev->keybit);
|
2074
|
set_bit(EV_ABS, sitronix_ts_gpts.input_dev->evbit);
|
2075
|
#if 1
|
2076
|
sitronix_ts_gpts.keyevent_input = input_allocate_device();
|
2077
|
if (sitronix_ts_gpts.keyevent_input == NULL){
|
2078
|
printk("Can not allocate memory for key input device.");
|
2079
|
ret = -ENOMEM;
|
2080
|
goto err_input_dev_alloc_failed;
|
2081
|
}
|
2082
|
sitronix_ts_gpts.keyevent_input->name = SITRONIX_I2C_TOUCH_KEY_INPUT_DEV_NAME;
|
2083
|
sitronix_ts_gpts.keyevent_input->dev.parent = &client->dev;
|
2084
|
set_bit(EV_KEY, sitronix_ts_gpts.keyevent_input->evbit);
|
2085
|
for(i = 0; i < (sizeof(sitronix_sensor_key_array)/sizeof(struct sitronix_sensor_key_t)); i++){
|
2086
|
set_bit(sitronix_sensor_key_array[i].code, sitronix_ts_gpts.keyevent_input->keybit);
|
2087
|
}
|
2088
|
#endif
|
2089
|
#ifdef SITRONIX_SMART_WAKE_UP
|
2090
|
set_bit(KEY_POWER, sitronix_ts_gpts.keyevent_input->keybit);
|
2091
|
#endif //SITRONIX_SMART_WAKE_UP
|
2092
|
|
2093
|
#ifndef SITRONIX_AA_KEY
|
2094
|
max_x = sitronix_ts_gpts.resolution_x;
|
2095
|
max_y = sitronix_ts_gpts.resolution_y;
|
2096
|
#else
|
2097
|
#ifdef SITRONIX_KEY_BOUNDARY_MANUAL_SPECIFY
|
2098
|
for(i = 0; i < (sizeof(sitronix_aa_key_array)/sizeof(struct sitronix_AA_key)); i++){
|
2099
|
set_bit(sitronix_aa_key_array[i].code, sitronix_ts_gpts.keyevent_input->keybit);
|
2100
|
}
|
2101
|
max_x = SITRONIX_TOUCH_RESOLUTION_X;
|
2102
|
max_y = SITRONIX_TOUCH_RESOLUTION_Y;
|
2103
|
#else
|
2104
|
for(i = 0; i < (sizeof(sitronix_aa_key_array)/sizeof(struct sitronix_AA_key)); i++){
|
2105
|
sitronix_aa_key_array[i].x_low = ((sitronix_ts_gpts.resolution_x / (sizeof(sitronix_aa_key_array)/sizeof(struct sitronix_AA_key)) ) * i ) + 15;
|
2106
|
sitronix_aa_key_array[i].x_high = ((sitronix_ts_gpts.resolution_x / (sizeof(sitronix_aa_key_array)/sizeof(struct sitronix_AA_key)) ) * (i + 1)) - 15;
|
2107
|
sitronix_aa_key_array[i].y_low = sitronix_ts_gpts.resolution_y - sitronix_ts_gpts.resolution_y / SCALE_KEY_HIGH_Y;
|
2108
|
sitronix_aa_key_array[i].y_high = sitronix_ts_gpts.resolution_y;
|
2109
|
DbgMsg("key[%d] %d, %d, %d, %d\n", i, sitronix_aa_key_array[i].x_low, sitronix_aa_key_array[i].x_high, sitronix_aa_key_array[i].y_low, sitronix_aa_key_array[i].y_high);
|
2110
|
set_bit(sitronix_aa_key_array[i].code, sitronix_ts_gpts.keyevent_input->keybit);
|
2111
|
}
|
2112
|
max_x = sitronix_ts_gpts.resolution_x;
|
2113
|
max_y = sitronix_ts_gpts.resolution_y - sitronix_ts_gpts.resolution_y / SCALE_KEY_HIGH_Y;
|
2114
|
#endif // SITRONIX_KEY_BOUNDARY_MANUAL_SPECIFY
|
2115
|
#endif // SITRONIX_AA_KEY
|
2116
|
|
2117
|
#if 0
|
2118
|
ret = input_register_device(sitronix_ts_gpts.keyevent_input);
|
2119
|
if(ret < 0){
|
2120
|
printk("Can not register key input device.\n");
|
2121
|
goto err_input_register_device_failed;
|
2122
|
}
|
2123
|
#endif
|
2124
|
|
2125
|
#ifdef SITRONIX_SUPPORT_MT_SLOT
|
2126
|
input_mt_init_slots(sitronix_ts_gpts.input_dev, sitronix_ts_gpts.max_touches);
|
2127
|
#else
|
2128
|
__set_bit(ABS_X, sitronix_ts_gpts.input_dev->absbit);
|
2129
|
__set_bit(ABS_Y, sitronix_ts_gpts.input_dev->absbit);
|
2130
|
__set_bit(ABS_MT_TOUCH_MAJOR, sitronix_ts_gpts.input_dev->absbit);
|
2131
|
__set_bit(ABS_MT_WIDTH_MAJOR, sitronix_ts_gpts.input_dev->absbit);
|
2132
|
__set_bit(ABS_MT_POSITION_X, sitronix_ts_gpts.input_dev->absbit);
|
2133
|
__set_bit(ABS_MT_POSITION_Y, sitronix_ts_gpts.input_dev->absbit);
|
2134
|
__set_bit(ABS_MT_TOOL_TYPE, sitronix_ts_gpts.input_dev->absbit);
|
2135
|
__set_bit(ABS_MT_BLOB_ID, sitronix_ts_gpts.input_dev->absbit);
|
2136
|
__set_bit(ABS_MT_TRACKING_ID, sitronix_ts_gpts.input_dev->absbit);
|
2137
|
|
2138
|
input_set_abs_params(sitronix_ts_gpts.input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
|
2139
|
input_set_abs_params(sitronix_ts_gpts.input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
|
2140
|
input_set_abs_params(sitronix_ts_gpts.input_dev, ABS_MT_TRACKING_ID, 0, sitronix_ts_gpts.max_touches, 0, 0);
|
2141
|
input_set_abs_params(sitronix_ts_gpts.input_dev, ABS_PRESSURE, 0, 255, 0, 0);
|
2142
|
#endif // SITRONIX_SUPPORT_MT_SLOT
|
2143
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
2144
|
#ifndef SITRONIX_SWAP_XY
|
2145
|
input_set_abs_params(sitronix_ts_gpts.input_dev, ABS_MT_POSITION_X, 0, max_x, 0, 0);
|
2146
|
input_set_abs_params(sitronix_ts_gpts.input_dev, ABS_MT_POSITION_Y, 0, max_y, 0, 0);
|
2147
|
#else
|
2148
|
input_set_abs_params(sitronix_ts_gpts.input_dev, ABS_MT_POSITION_X, 0, max_y, 0, 0);
|
2149
|
input_set_abs_params(sitronix_ts_gpts.input_dev, ABS_MT_POSITION_Y, 0, max_x, 0, 0);
|
2150
|
#endif // SITRONIX_SWAP_XY
|
2151
|
|
2152
|
ret = input_register_device(sitronix_ts_gpts.input_dev);
|
2153
|
if(ret < 0){
|
2154
|
printk("Can not register input device.\n");
|
2155
|
goto err_input_register_device_failed;
|
2156
|
}
|
2157
|
|
2158
|
if (sitronix_ts_gpts.client->irq){
|
2159
|
dev_info(&client->dev, "irq = %d\n", sitronix_ts_gpts.client->irq);
|
2160
|
#ifdef SITRONIX_LEVEL_TRIGGERED
|
2161
|
//#define IRQF_TRIGGER_NONE 0x00000000
|
2162
|
//#define IRQF_TRIGGER_RISING 0x00000001
|
2163
|
//#define IRQF_TRIGGER_FALLING 0x00000002
|
2164
|
//#define IRQF_TRIGGER_HIGH 0x00000004
|
2165
|
//#define IRQF_TRIGGER_LOW 0x00000008
|
2166
|
|
2167
|
//ret = request_irq(client->irq, sitronix_ts_irq_handler, IRQF_TRIGGER_LOW | IRQF_DISABLED, client->name, &sitronix_ts_gpts);
|
2168
|
//ret = request_irq(sitronix_ts_gpts.client->irq, sitronix_ts_irq_handler, IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING , SITRONIX_I2C_TOUCH_DRV_NAME, &sitronix_ts_gpts);
|
2169
|
//ret = request_irq(sitronix_ts_gpts.client->irq, sitronix_ts_irq_handler, IRQF_TRIGGER_RISING |IRQF_DISABLED , client->name, &sitronix_ts_gpts);
|
2170
|
ret = request_irq(sitronix_ts_gpts.client->irq, sitronix_ts_irq_handler, IRQF_TRIGGER_FALLING, client->name, &sitronix_ts_gpts);
|
2171
|
#else
|
2172
|
ret = request_irq(sitronix_ts_gpts.client->irq, sitronix_ts_irq_handler, IRQF_TRIGGER_FALLING ,SITRONIX_I2C_TOUCH_DRV_NAME, &sitronix_ts_gpts);
|
2173
|
//ret = request_irq(client->irq, sitronix_ts_irq_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED, client->name, &sitronix_ts_gpts);
|
2174
|
|
2175
|
#endif // SITRONIX_LEVEL_TRIGGERED
|
2176
|
if (ret == 0){
|
2177
|
atomic_set(&sitronix_ts_irq_on, 1);
|
2178
|
sitronix_ts_gpts.use_irq = 1;
|
2179
|
}else{
|
2180
|
dev_err(&client->dev, "request_irq failed\n");
|
2181
|
goto err_request_irq_failed;
|
2182
|
}
|
2183
|
}
|
2184
|
|
2185
|
|
2186
|
#ifdef SITRONIX_SYSFS
|
2187
|
if(!sitronix_ts_sysfs_created){
|
2188
|
ret = sitronix_ts_create_sysfs_entry(client);
|
2189
|
if(ret < 0)
|
2190
|
goto err_create_sysfs_failed;
|
2191
|
sitronix_ts_sysfs_created = true;
|
2192
|
}
|
2193
|
#endif // SITRONIX_SYSFS
|
2194
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
2195
|
|
2196
|
|
2197
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
2198
|
sitronix_ts_gpts.early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
|
2199
|
sitronix_ts_gpts.early_suspend.suspend = sitronix_ts_early_suspend;
|
2200
|
sitronix_ts_gpts.early_suspend.resume = sitronix_ts_late_resume;
|
2201
|
register_early_suspend(&sitronix_ts_gpts.early_suspend);
|
2202
|
#endif // CONFIG_HAS_EARLYSUSPEND
|
2203
|
|
2204
|
//20160624 for pinctrl
|
2205
|
#if 0
|
2206
|
rst_pin = kzalloc(sizeof(struct rst_pin_ctrl), GFP_KERNEL);
|
2207
|
if (!rst_pin) {
|
2208
|
dev_err(&client->dev,"%s: memory allocation failed.", __func__);
|
2209
|
//err = -ENOMEM;
|
2210
|
//goto exit1;
|
2211
|
}
|
2212
|
rst_pin->client = client;
|
2213
|
if (!sit_pinctrl_init(rst_pin))
|
2214
|
{
|
2215
|
printk("##gavin select active state for rst pin\n");
|
2216
|
ret = pinctrl_select_state(rst_pin->pinctrl, rst_pin->rst_pin_ts_active);
|
2217
|
if (ret) {
|
2218
|
dev_err(&client->dev, "Can't select pinctrl state\n");
|
2219
|
//goto exit2;
|
2220
|
}
|
2221
|
}
|
2222
|
#endif
|
2223
|
|
2224
|
//#ifdef ST_UPGRADE_FIRMWARE
|
2225
|
//#ifdef ST_FIREWARE_FILE
|
2226
|
// kthread_run(st_upgrade_fw, "Sitronix", "sitronix_update");
|
2227
|
//#else
|
2228
|
// st_upgrade_fw();
|
2229
|
//#endif //ST_FIREWARE_FILE
|
2230
|
|
2231
|
//#endif //ST_UPGRADE_FIRMWARE
|
2232
|
|
2233
|
|
2234
|
#ifdef ST_TEST_RAW
|
2235
|
st_drv_test_raw();
|
2236
|
#endif //ST_TEST_RAW
|
2237
|
|
2238
|
//add touch pannel prepare switch to sp interface
|
2239
|
#if (CTP_AP_SP_SYNC_WAY != CTP_AP_SP_SYNC_NONE)
|
2240
|
//sitronix_ts_gpts.sitronix_driver_ops.touch_device_name = CTP_NAME;
|
2241
|
//sitronix_ts_gpts.sitronix_driver_ops.touch_pannel_reinit = sitronix_touch_reinit;
|
2242
|
//sitronix_ts_gpts.sitronix_driver_ops.touch_pannel_uninit = sitronix_touch_uninit;
|
2243
|
//gSitronixPtr = &sitronix_ts_gpts;
|
2244
|
#endif
|
2245
|
|
2246
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_APP)
|
2247
|
// touch_panel_driver_add(&gSitronixPtr->sitronix_driver_ops);
|
2248
|
#endif
|
2249
|
printk("%s,line=%d\n", __FUNCTION__,__LINE__);
|
2250
|
|
2251
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
2252
|
//spin_lock_init(&ctp_sync_lock);
|
2253
|
//init_timer(&ctp_sync_timer);
|
2254
|
//ctp_sync_timer.expires = jiffies + HZ/50;
|
2255
|
//ctp_sync_timer.function = ctp_sync_timer_func;
|
2256
|
//add_timer(&ctp_sync_timer); //crash
|
2257
|
#endif
|
2258
|
|
2259
|
return 0;
|
2260
|
err_create_sysfs_failed:
|
2261
|
err_request_irq_failed:
|
2262
|
#ifdef SITRONIX_SYSFS
|
2263
|
input_unregister_device(sitronix_ts_gpts.input_dev);
|
2264
|
input_unregister_device(sitronix_ts_gpts.keyevent_input);
|
2265
|
#endif // SITRONIX_SYSFS
|
2266
|
err_input_register_device_failed:
|
2267
|
err_input_dev_alloc_failed:
|
2268
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
2269
|
destroy_workqueue(sitronix_io_sync_workqueue);
|
2270
|
#endif
|
2271
|
|
2272
|
if(sitronix_ts_gpts.input_dev)
|
2273
|
input_free_device(sitronix_ts_gpts.input_dev);
|
2274
|
if(sitronix_ts_gpts.keyevent_input)
|
2275
|
input_free_device(sitronix_ts_gpts.keyevent_input);
|
2276
|
#ifdef SITRONIX_MONITOR_THREAD
|
2277
|
if(sitronix_ts_gpts.enable_monitor_thread == 1){
|
2278
|
if(SitronixMonitorThread){
|
2279
|
kthread_stop(SitronixMonitorThread);
|
2280
|
SitronixMonitorThread = NULL;
|
2281
|
}
|
2282
|
}
|
2283
|
#endif // SITRONIX_MONITOR_THREAD
|
2284
|
err_device_info_error:
|
2285
|
err_check_functionality_failed:
|
2286
|
|
2287
|
return ret;
|
2288
|
}
|
2289
|
|
2290
|
static int sitronix_ts_remove(struct i2c_client *client)
|
2291
|
{
|
2292
|
struct sitronix_ts_data *ts = i2c_get_clientdata(client);
|
2293
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
2294
|
unregister_early_suspend(&ts->early_suspend);
|
2295
|
#endif // CONFIG_HAS_EARLYSUSPEND
|
2296
|
#ifdef SITRONIX_SYSFS
|
2297
|
if(!sitronix_ts_sysfs_using){
|
2298
|
sitronix_ts_destroy_sysfs_entry(client);
|
2299
|
sitronix_ts_sysfs_created = false;
|
2300
|
}
|
2301
|
#endif // SITRONIX_SYSFS
|
2302
|
#ifdef SITRONIX_MONITOR_THREAD
|
2303
|
if(ts->enable_monitor_thread == 1){
|
2304
|
if(SitronixMonitorThread){
|
2305
|
kthread_stop(SitronixMonitorThread);
|
2306
|
SitronixMonitorThread = NULL;
|
2307
|
}
|
2308
|
}
|
2309
|
#endif // SITRONIX_MONITOR_THREAD
|
2310
|
i2c_set_clientdata(client, NULL);
|
2311
|
if (ts->use_irq)
|
2312
|
free_irq(client->irq, ts);
|
2313
|
if(ts->input_dev)
|
2314
|
input_unregister_device(ts->input_dev);
|
2315
|
if(ts->keyevent_input)
|
2316
|
input_unregister_device(ts->keyevent_input);
|
2317
|
return 0;
|
2318
|
}
|
2319
|
|
2320
|
static int sitronix_ts_suspend(struct i2c_client *client)
|
2321
|
{
|
2322
|
int ret;
|
2323
|
struct sitronix_ts_data *ts = i2c_get_clientdata(client);
|
2324
|
|
2325
|
DbgMsg("%s\n", __FUNCTION__);
|
2326
|
//2.9.15 petitk add
|
2327
|
#ifdef SITRONIX_SMART_WAKE_UP
|
2328
|
sitronix_swk_set_swk_enable(ts);
|
2329
|
swk_flag = 1;
|
2330
|
#endif //SITRONIX_SMART_WAKE_UP
|
2331
|
|
2332
|
#ifdef SITRONIX_MONITOR_THREAD
|
2333
|
if(ts->enable_monitor_thread == 1){
|
2334
|
if(SitronixMonitorThread){
|
2335
|
kthread_stop(SitronixMonitorThread);
|
2336
|
SitronixMonitorThread = NULL;
|
2337
|
}
|
2338
|
sitronix_ts_delay_monitor_thread_start = DELAY_MONITOR_THREAD_START_RESUME;
|
2339
|
}
|
2340
|
#endif // SITRONIX_MONITOR_THREAD
|
2341
|
if(ts->use_irq){
|
2342
|
atomic_set(&sitronix_ts_irq_on, 0);
|
2343
|
// disable_irq_nosync(ts->client->irq);
|
2344
|
}
|
2345
|
ts->suspend_state = 1;
|
2346
|
|
2347
|
ret = sitronix_ts_set_powerdown_bit(ts, 1);
|
2348
|
if(ts->chip_id == 2){
|
2349
|
#ifdef CONFIG_ARCH_MSM
|
2350
|
// gpio_tlmm_config(GPIO_CFG(SITRONIX_INT_GPIO, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
|
2351
|
// gpio_set_value(SITRONIX_INT_GPIO, 1);
|
2352
|
#else
|
2353
|
#if 0
|
2354
|
gpio_direction_output(irq_to_gpio(client->irq), 1);
|
2355
|
#endif
|
2356
|
#endif // CONFIG_ARCH_MSM
|
2357
|
}
|
2358
|
DbgMsg("%s return\n", __FUNCTION__);
|
2359
|
|
2360
|
return 0;
|
2361
|
}
|
2362
|
|
2363
|
static int sitronix_ts_resume(struct i2c_client *client)
|
2364
|
{
|
2365
|
int ret;
|
2366
|
struct sitronix_ts_data *ts = i2c_get_clientdata(client);
|
2367
|
|
2368
|
DbgMsg("%s\n", __FUNCTION__);
|
2369
|
|
2370
|
if(ts->chip_id == 2){
|
2371
|
#ifdef CONFIG_ARCH_MSM
|
2372
|
//gpio_set_value(SITRONIX_INT_GPIO, 0);
|
2373
|
//gpio_tlmm_config(GPIO_CFG(SITRONIX_INT_GPIO, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
|
2374
|
#else
|
2375
|
#if 0
|
2376
|
ret = irq_to_gpio(client->irq);
|
2377
|
gpio_set_value(ret, 0);
|
2378
|
gpio_direction_input(ret);
|
2379
|
#endif
|
2380
|
#endif // CONFIG_ARCH_MSM
|
2381
|
}else{
|
2382
|
//ret = sitronix_ts_set_powerdown_bit(ts, 0);
|
2383
|
}
|
2384
|
|
2385
|
ts->suspend_state = 0;
|
2386
|
if(ts->use_irq){
|
2387
|
atomic_set(&sitronix_ts_irq_on, 1);
|
2388
|
enable_irq(ts->client->irq);
|
2389
|
}
|
2390
|
#ifdef SITRONIX_MONITOR_THREAD
|
2391
|
if(ts->enable_monitor_thread == 1){
|
2392
|
atomic_set(&iMonitorThreadPostpone,1);
|
2393
|
SitronixMonitorThread = kthread_run(sitronix_ts_gpts.sitronix_mt_fp,"Sitronix","Monitorthread");
|
2394
|
if(IS_ERR(SitronixMonitorThread))
|
2395
|
SitronixMonitorThread = NULL;
|
2396
|
}
|
2397
|
#endif // SITRONIX_MONITOR_THREAD
|
2398
|
DbgMsg("%s return\n", __FUNCTION__);
|
2399
|
|
2400
|
return 0;
|
2401
|
}
|
2402
|
|
2403
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
2404
|
static void sitronix_ts_early_suspend(struct early_suspend *h)
|
2405
|
{
|
2406
|
struct sitronix_ts_data *ts;
|
2407
|
DbgMsg("%s\n", __FUNCTION__);
|
2408
|
ts = container_of(h, struct sitronix_ts_data, early_suspend);
|
2409
|
sitronix_ts_suspend(ts->client);
|
2410
|
}
|
2411
|
|
2412
|
static void sitronix_ts_late_resume(struct early_suspend *h)
|
2413
|
{
|
2414
|
struct sitronix_ts_data *ts;
|
2415
|
DbgMsg("%s\n", __FUNCTION__);
|
2416
|
ts = container_of(h, struct sitronix_ts_data, early_suspend);
|
2417
|
sitronix_ts_resume(ts->client);
|
2418
|
}
|
2419
|
#endif // CONFIG_HAS_EARLYSUSPEND
|
2420
|
|
2421
|
static const struct i2c_device_id sitronix_ts_id[] = {
|
2422
|
{ SITRONIX_I2C_TOUCH_DRV_NAME, 0 },
|
2423
|
{ }
|
2424
|
};
|
2425
|
#ifdef SITRONIX_MULTI_SLAVE_ADDR
|
2426
|
static int sitronix_ts_detect(struct i2c_client *client, struct i2c_board_info *info)
|
2427
|
{
|
2428
|
uint8_t buffer[8];
|
2429
|
sitronix_ts_reset_ic();
|
2430
|
printk("%s: bus = %d\n", __FUNCTION__, client->adapter->nr);
|
2431
|
if((client->adapter->nr == twi_id) && (!sitronix_i2c_read_bytes(client, STATUS_REG, buffer, 8))){
|
2432
|
printk("detect successed\n");
|
2433
|
strlcpy(info->type, SITRONIX_I2C_TOUCH_DRV_NAME, strlen(SITRONIX_I2C_TOUCH_DRV_NAME)+1);
|
2434
|
return 0;
|
2435
|
}else{
|
2436
|
printk("detect failed\n");
|
2437
|
return -ENODEV;
|
2438
|
}
|
2439
|
}
|
2440
|
|
2441
|
const unsigned short sitronix_i2c_addr[] = {0x20, 0x38, 0x55, 0x70, 0x60, I2C_CLIENT_END};
|
2442
|
#endif // SITRONIX_MULTI_SLAVE_ADDR
|
2443
|
|
2444
|
|
2445
|
|
2446
|
static struct of_device_id sitronix_match_table[] = {
|
2447
|
{ .compatible = "sitronix,st1633i", },
|
2448
|
{ },
|
2449
|
};
|
2450
|
|
2451
|
#if 1// (!defined(CONFIG_FB) && !defined(CONFIG_HAS_EARLYSUSPEND))
|
2452
|
static const struct dev_pm_ops sitronix_ts_dev_pm_ops = {
|
2453
|
.suspend = sitronix_ts_suspend,
|
2454
|
.resume = sitronix_ts_resume,
|
2455
|
};
|
2456
|
#else
|
2457
|
static const struct dev_pm_ops sitronix_ts_dev_pm_ops = {
|
2458
|
.suspend = sitronix_ts_suspend_rst,////20160614 for pinctrl
|
2459
|
.resume = sitronix_ts_resume_rst,
|
2460
|
};
|
2461
|
#endif
|
2462
|
static struct i2c_driver sitronix_ts_driver = {
|
2463
|
#ifdef SITRONIX_MULTI_SLAVE_ADDR
|
2464
|
.class = I2C_CLASS_HWMON,
|
2465
|
#endif // SITRONIX_MULTI_SLAVE_ADDR
|
2466
|
.probe = sitronix_ts_probe,
|
2467
|
.remove = sitronix_ts_remove,
|
2468
|
.id_table = sitronix_ts_id,
|
2469
|
.driver = {
|
2470
|
.name = SITRONIX_I2C_TOUCH_DRV_NAME,
|
2471
|
.owner = THIS_MODULE,
|
2472
|
.of_match_table = sitronix_match_table,
|
2473
|
#if CONFIG_PM
|
2474
|
.suspend = NULL,
|
2475
|
.resume = NULL,//fts_resume,
|
2476
|
#endif
|
2477
|
},
|
2478
|
#ifdef SITRONIX_MULTI_SLAVE_ADDR
|
2479
|
//.address_list = sitronix_i2c_addr,
|
2480
|
.detect = sitronix_ts_detect,
|
2481
|
#endif // SITRONIX_MULTI_SLAVE_ADDR
|
2482
|
};
|
2483
|
|
2484
|
#ifdef SITRONIX_FW_UPGRADE_FEATURE
|
2485
|
static struct file_operations nc_fops = {
|
2486
|
.owner = THIS_MODULE,
|
2487
|
.write = sitronix_write,
|
2488
|
.read = sitronix_read,
|
2489
|
.open = sitronix_open,
|
2490
|
.unlocked_ioctl = sitronix_ioctl,
|
2491
|
.release = sitronix_release,
|
2492
|
};
|
2493
|
#endif // SITRONIX_FW_UPGRADE_FEATURE
|
2494
|
void sitronix_ts_reprobe(void)
|
2495
|
{
|
2496
|
int retval = 0;
|
2497
|
printk("sitronix call reprobe!\n");
|
2498
|
i2c_del_driver(&sitronix_ts_driver);
|
2499
|
retval = i2c_add_driver(&sitronix_ts_driver);
|
2500
|
if(retval < 0)
|
2501
|
printk("fail to reprobe driver!\n");
|
2502
|
}
|
2503
|
|
2504
|
#ifdef CONFIG_ARCH_SUNXI
|
2505
|
/**
|
2506
|
* ctp_print_info - sysconfig print function
|
2507
|
* return value:
|
2508
|
*
|
2509
|
*/
|
2510
|
void sitronix_print_info(struct ctp_config_info info)
|
2511
|
{
|
2512
|
DbgMsg("info.ctp_used:%d\n",info.ctp_used);
|
2513
|
DbgMsg("info.twi_id:%d\n",info.twi_id);
|
2514
|
DbgMsg("info.screen_max_x:%d\n",info.screen_max_x);
|
2515
|
DbgMsg("info.screen_max_y:%d\n",info.screen_max_y);
|
2516
|
DbgMsg("info.revert_x_flag:%d\n",info.revert_x_flag);
|
2517
|
DbgMsg("info.revert_y_flag:%d\n",info.revert_y_flag);
|
2518
|
DbgMsg("info.exchange_x_y_flag:%d\n",info.exchange_x_y_flag);
|
2519
|
DbgMsg("info.irq_gpio_number:%d\n",info.irq_gpio.gpio);
|
2520
|
DbgMsg("info.wakeup_gpio_number:%d\n",info.wakeup_gpio.gpio);
|
2521
|
}
|
2522
|
|
2523
|
|
2524
|
static int ctp_get_system_config(void)
|
2525
|
{
|
2526
|
sitronix_print_info(config_info);
|
2527
|
twi_id = config_info.twi_id;
|
2528
|
screen_max_x = config_info.screen_max_x;
|
2529
|
screen_max_y = config_info.screen_max_y;
|
2530
|
revert_x_flag = config_info.revert_x_flag;
|
2531
|
revert_y_flag = config_info.revert_y_flag;
|
2532
|
exchange_x_y_flag = config_info.exchange_x_y_flag;
|
2533
|
if((screen_max_x == 0) || (screen_max_y == 0)){
|
2534
|
ErrorMsg("%s:read config error!\n",__func__);
|
2535
|
return 0;
|
2536
|
}
|
2537
|
return 1;
|
2538
|
}
|
2539
|
#endif
|
2540
|
|
2541
|
static int __init sitronix_ts_init(void)
|
2542
|
{
|
2543
|
|
2544
|
#ifdef CONFIG_ARCH_SUNXI
|
2545
|
s32 ret = -1;
|
2546
|
#endif
|
2547
|
s32 ret_iic = -2;
|
2548
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
2549
|
//script_item_u val;
|
2550
|
//script_item_value_type_e type;
|
2551
|
//int pin_val = 0;
|
2552
|
#endif
|
2553
|
#ifdef SITRONIX_FW_UPGRADE_FEATURE
|
2554
|
int result;
|
2555
|
int err = 0;
|
2556
|
dev_t devno = MKDEV(sitronix_major, 0);
|
2557
|
#endif // SITRONIX_FW_UPGRADE_FEATURE
|
2558
|
|
2559
|
#if(CTP_AP_SP_SYNC_WAY & CTP_AP_SP_SYNC_GPIO)
|
2560
|
//type = script_get_item("ctp_para", "ctp_sync_io", &val);
|
2561
|
//if(SCIRPT_ITEM_VALUE_TYPE_PIO != type) {
|
2562
|
// ErrorMsg("%s: ctp_sync_io script_get_item err. \n",__func__ );
|
2563
|
//}
|
2564
|
//else
|
2565
|
{
|
2566
|
printk("ctp_sync_io get ok\n");
|
2567
|
//sitronix_sync_io = val.gpio;
|
2568
|
}
|
2569
|
|
2570
|
//ap_sp_sync_gpio(sitronix_sync_io, CTP_SYNC_IO_IN, pin_val);
|
2571
|
#endif
|
2572
|
#ifdef CONFIG_ARCH_SUNXI
|
2573
|
DbgMsg("****************************************************************\n");
|
2574
|
if (0)//(input_fetch_sysconfig_para(&(config_info.input_type)))
|
2575
|
{
|
2576
|
ErrorMsg("%s: ctp_fetch_sysconfig_para err.\n", __func__);
|
2577
|
return 0;
|
2578
|
}
|
2579
|
else
|
2580
|
{
|
2581
|
//ret = input_init_platform_resource(&(config_info.input_type));
|
2582
|
if (0 != ret) {
|
2583
|
ErrorMsg("%s:ctp_ops.init_platform_resource err. \n", __func__);
|
2584
|
}
|
2585
|
}
|
2586
|
|
2587
|
if(config_info.ctp_used == 0)
|
2588
|
{
|
2589
|
ErrorMsg("*** ctp_used set to 0 !\n");
|
2590
|
ErrorMsg("*** if use ctp,please put the sys_config.fex ctp_used set to 1. \n");
|
2591
|
return 0;
|
2592
|
}
|
2593
|
|
2594
|
if(!ctp_get_system_config())
|
2595
|
{
|
2596
|
ErrorMsg("%s:read config fail!\n",__func__);
|
2597
|
return ret;
|
2598
|
}
|
2599
|
DbgMsg("%s\n",__func__);
|
2600
|
|
2601
|
//input_set_power_enable(&(config_info.input_type), 1);
|
2602
|
|
2603
|
//sunxi_gpio_to_name(CTP_IRQ_NUMBER,irq_pin_name);
|
2604
|
|
2605
|
//sitronix_i2c_driver.detect = ctp_detect;
|
2606
|
#endif
|
2607
|
|
2608
|
printk("Sitronix touch driver %d.%d.%d\n", DRIVER_MAJOR, DRIVER_MINOR, DRIVER_PATCHLEVEL);
|
2609
|
printk("Release date: %s\n", DRIVER_DATE);
|
2610
|
#ifdef SITRONIX_FW_UPGRADE_FEATURE
|
2611
|
result = alloc_chrdev_region(&devno, 0, 1, SITRONIX_I2C_TOUCH_DEV_NAME);
|
2612
|
if(result < 0){
|
2613
|
printk("fail to allocate chrdev (%d) \n", result);
|
2614
|
return 0;
|
2615
|
}
|
2616
|
sitronix_major = MAJOR(devno);
|
2617
|
cdev_init(&sitronix_cdev, &nc_fops);
|
2618
|
sitronix_cdev.owner = THIS_MODULE;
|
2619
|
sitronix_cdev.ops = &nc_fops;
|
2620
|
err = cdev_add(&sitronix_cdev, devno, 1);
|
2621
|
if(err){
|
2622
|
printk("fail to add cdev (%d) \n", err);
|
2623
|
return 0;
|
2624
|
}
|
2625
|
printk("%s,%d\n",__FUNCTION__,__LINE__);
|
2626
|
|
2627
|
sitronix_class = class_create(THIS_MODULE, SITRONIX_I2C_TOUCH_DEV_NAME);
|
2628
|
if (IS_ERR(sitronix_class)) {
|
2629
|
result = PTR_ERR(sitronix_class);
|
2630
|
unregister_chrdev(sitronix_major, SITRONIX_I2C_TOUCH_DEV_NAME);
|
2631
|
printk("fail to create class (%d) \n", result);
|
2632
|
return result;
|
2633
|
}
|
2634
|
printk("%s,%d\n",__FUNCTION__,__LINE__);
|
2635
|
device_create(sitronix_class, NULL, MKDEV(sitronix_major, 0), NULL, SITRONIX_I2C_TOUCH_DEV_NAME);
|
2636
|
#ifdef SITRONIX_PERMISSION_THREAD
|
2637
|
SitronixPermissionThread = kthread_run(sitronix_ts_permission_thread,"Sitronix","Permissionthread");
|
2638
|
if(IS_ERR(SitronixPermissionThread))
|
2639
|
SitronixPermissionThread = NULL;
|
2640
|
#endif // SITRONIX_PERMISSION_THREAD
|
2641
|
#endif // SITRONIX_FW_UPGRADE_FEATURE
|
2642
|
|
2643
|
ret_iic= i2c_add_driver(&sitronix_ts_driver);
|
2644
|
printk("IIC ADD DRIVER %s,ret_iic=%d\n",__FUNCTION__,ret_iic);
|
2645
|
|
2646
|
return ret_iic;
|
2647
|
//return i2c_add_driver(&sitronix_ts_driver);
|
2648
|
}
|
2649
|
|
2650
|
static void __exit sitronix_ts_exit(void)
|
2651
|
{
|
2652
|
#ifdef SITRONIX_FW_UPGRADE_FEATURE
|
2653
|
dev_t dev_id = MKDEV(sitronix_major, 0);
|
2654
|
#endif // SITRONIX_FW_UPGRADE_FEATURE
|
2655
|
i2c_del_driver(&sitronix_ts_driver);
|
2656
|
#ifdef SITRONIX_FW_UPGRADE_FEATURE
|
2657
|
cdev_del(&sitronix_cdev);
|
2658
|
|
2659
|
device_destroy(sitronix_class, dev_id); //delete device node under /dev
|
2660
|
class_destroy(sitronix_class); //delete class created by us
|
2661
|
unregister_chrdev_region(dev_id, 1);
|
2662
|
#ifdef SITRONIX_PERMISSION_THREAD
|
2663
|
if(SitronixPermissionThread)
|
2664
|
SitronixPermissionThread = NULL;
|
2665
|
#endif // SITRONIX_PERMISSION_THREAD
|
2666
|
#endif // SITRONIX_FW_UPGRADE_FEATURE
|
2667
|
}
|
2668
|
|
2669
|
module_init(sitronix_ts_init);
|
2670
|
module_exit(sitronix_ts_exit);
|
2671
|
|
2672
|
MODULE_DESCRIPTION("Sitronix Multi-Touch Driver");
|
2673
|
MODULE_LICENSE("GPL");
|
2674
|
|
2675
|
|
2676
|
#if defined(ST_TEST_RAW) || defined(ST_UPGRADE_FIRMWARE)
|
2677
|
|
2678
|
static int st_i2c_read_direct(st_u8 *rxbuf, int len)
|
2679
|
{
|
2680
|
|
2681
|
int ret = 0;
|
2682
|
ret = i2c_master_recv(sitronix_ts_gpts.client, rxbuf, len);
|
2683
|
|
2684
|
if (ret < 0){
|
2685
|
stmsg("read direct error (%d)\n", ret);
|
2686
|
return ret;
|
2687
|
}
|
2688
|
return len;
|
2689
|
}
|
2690
|
|
2691
|
static int st_i2c_read_bytes(st_u8 addr, st_u8 *rxbuf, int len)
|
2692
|
{
|
2693
|
|
2694
|
int ret = 0;
|
2695
|
st_u8 txbuf = addr;
|
2696
|
|
2697
|
ret = i2c_master_send(sitronix_ts_gpts.client, &txbuf, 1);
|
2698
|
if (ret < 0){
|
2699
|
stmsg("write 0x%x error (%d)\n", addr, ret);
|
2700
|
return ret;
|
2701
|
}
|
2702
|
ret = i2c_master_recv(sitronix_ts_gpts.client, rxbuf, len);
|
2703
|
|
2704
|
if (ret < 0){
|
2705
|
stmsg("read 0x%x error (%d)\n", addr, ret);
|
2706
|
return ret;
|
2707
|
}
|
2708
|
return len;
|
2709
|
}
|
2710
|
|
2711
|
static int st_i2c_write_bytes(st_u8 *txbuf, int len)
|
2712
|
{
|
2713
|
|
2714
|
int ret = 0;
|
2715
|
if(txbuf == NULL)
|
2716
|
return -1;
|
2717
|
|
2718
|
ret = i2c_master_send(sitronix_ts_gpts.client, txbuf, len);
|
2719
|
if (ret < 0){
|
2720
|
stmsg("write 0x%x error (%d)\n", *txbuf, ret);
|
2721
|
return ret;
|
2722
|
}
|
2723
|
return len;
|
2724
|
}
|
2725
|
#endif
|
2726
|
|
2727
|
#ifdef ST_UPGRADE_FIRMWARE
|
2728
|
static int st_get_device_status(void)
|
2729
|
{
|
2730
|
int ret = 0;
|
2731
|
st_u8 buffer[8];
|
2732
|
|
2733
|
ret = st_i2c_read_bytes(STATUS_REG, buffer, 8);
|
2734
|
if (ret < 0){
|
2735
|
stmsg("read status reg error (%d)\n", ret);
|
2736
|
return ret;
|
2737
|
}else{
|
2738
|
stmsg("status reg = %d\n", buffer[0]);
|
2739
|
}
|
2740
|
|
2741
|
|
2742
|
return buffer[0];
|
2743
|
}
|
2744
|
|
2745
|
static int st_check_device_status(int ck1,int ck2,int delay)
|
2746
|
{
|
2747
|
int maxTimes = 100;
|
2748
|
int isInStauts = 0;
|
2749
|
int status = -1;
|
2750
|
while(maxTimes-->0 && isInStauts==0)
|
2751
|
{
|
2752
|
status = st_get_device_status();
|
2753
|
if(status == ck1 || status == ck2)
|
2754
|
isInStauts=1;
|
2755
|
st_msleep(delay);
|
2756
|
}
|
2757
|
if(isInStauts==0)
|
2758
|
return -1;
|
2759
|
else
|
2760
|
return 0;
|
2761
|
}
|
2762
|
|
2763
|
static int st_power_up(void)
|
2764
|
{
|
2765
|
st_u8 reset[2];
|
2766
|
reset[0] = 2;
|
2767
|
reset[1] = 0;
|
2768
|
return st_i2c_write_bytes(reset,2);
|
2769
|
}
|
2770
|
int st_isp_off(void)
|
2771
|
{
|
2772
|
unsigned char data[8];
|
2773
|
int rt = 0;
|
2774
|
|
2775
|
stmsg("ISP off\n");
|
2776
|
memset(data, 0, sizeof(data));
|
2777
|
data[0] = ISP_CMD_RESET;
|
2778
|
|
2779
|
rt += st_i2c_write_bytes(data,sizeof(data));
|
2780
|
|
2781
|
if(rt < 0)
|
2782
|
{
|
2783
|
stmsg("ISP off error\n");
|
2784
|
return -1;
|
2785
|
}
|
2786
|
st_msleep(300);
|
2787
|
|
2788
|
|
2789
|
return st_check_device_status(0,4,10);
|
2790
|
}
|
2791
|
static int st_isp_on(void)
|
2792
|
{
|
2793
|
unsigned char IspKey[] = {0,'S',0,'T',0,'X',0,'_',0,'F',0,'W',0,'U',0,'P'};
|
2794
|
unsigned char i;
|
2795
|
int icStatus = st_get_device_status();
|
2796
|
|
2797
|
stmsg("ISP on\n");
|
2798
|
|
2799
|
if(icStatus <0)
|
2800
|
return -1;
|
2801
|
if(icStatus == 0x6)
|
2802
|
return 0;
|
2803
|
else if(icStatus == 0x5)
|
2804
|
st_power_up();
|
2805
|
|
2806
|
for(i=0;i<sizeof(IspKey); i+=2)
|
2807
|
{
|
2808
|
if(st_i2c_write_bytes(&IspKey[i],2) < 0)
|
2809
|
{
|
2810
|
stmsg("Entering ISP fail.\n");
|
2811
|
return -1;
|
2812
|
}
|
2813
|
}
|
2814
|
st_msleep(150); //This delay is very important for ISP mode changing.
|
2815
|
//Do not remove this delay arbitrarily.
|
2816
|
return st_check_device_status(6,99,10);
|
2817
|
}
|
2818
|
|
2819
|
static int st_irq_off(void)
|
2820
|
{
|
2821
|
if (sitronix_ts_gpts.use_irq){
|
2822
|
atomic_set(&sitronix_ts_irq_on, 0);
|
2823
|
disable_irq_nosync(sitronix_ts_gpts.client->irq);
|
2824
|
}
|
2825
|
return 0;
|
2826
|
}
|
2827
|
static int st_irq_on(void)
|
2828
|
{
|
2829
|
if (sitronix_ts_gpts.use_irq)
|
2830
|
{
|
2831
|
atomic_set(&sitronix_ts_irq_on, 1);
|
2832
|
enable_irq(sitronix_ts_gpts.client->irq);
|
2833
|
}
|
2834
|
return 0;
|
2835
|
}
|
2836
|
|
2837
|
unsigned short st_flash_get_checksum(unsigned char *Buf, unsigned short ValidDataSize)
|
2838
|
{
|
2839
|
unsigned short Checksum;
|
2840
|
int i;
|
2841
|
|
2842
|
Checksum = 0;
|
2843
|
for(i = 0; i < ValidDataSize; i++)
|
2844
|
Checksum += (unsigned short)Buf[i];
|
2845
|
|
2846
|
return Checksum;
|
2847
|
}
|
2848
|
|
2849
|
static int st_flash_unlock(void)
|
2850
|
{
|
2851
|
unsigned char PacketData[ISP_PACKET_SIZE];
|
2852
|
|
2853
|
int retryCount=0;
|
2854
|
int isSuccess=0;
|
2855
|
while(isSuccess==0 && retryCount++ < 2)
|
2856
|
{
|
2857
|
memset(PacketData,0,ISP_PACKET_SIZE);
|
2858
|
PacketData[0] = ISP_CMD_UNLOCK;
|
2859
|
if(st_i2c_write_bytes(PacketData,ISP_PACKET_SIZE) == ISP_PACKET_SIZE)
|
2860
|
{
|
2861
|
if(retryCount > 1)
|
2862
|
st_msleep(150);
|
2863
|
|
2864
|
if(st_i2c_read_direct(PacketData,ISP_PACKET_SIZE) == ISP_PACKET_SIZE)
|
2865
|
{
|
2866
|
if(PacketData[0] == ISP_CMD_READY)
|
2867
|
isSuccess = 1;
|
2868
|
}
|
2869
|
else
|
2870
|
st_msleep(50);
|
2871
|
}
|
2872
|
|
2873
|
if(isSuccess ==0)
|
2874
|
{
|
2875
|
stmsg("Read ISP_Unlock_Ready packet fail retry : %d\n",retryCount);
|
2876
|
//MSLEEP(30);
|
2877
|
}
|
2878
|
|
2879
|
|
2880
|
}
|
2881
|
|
2882
|
if(isSuccess == 0)
|
2883
|
{
|
2884
|
stmsg("Read ISP_Unlock_Ready packet fail.\n");
|
2885
|
return -1;
|
2886
|
}
|
2887
|
|
2888
|
return 0;
|
2889
|
}
|
2890
|
|
2891
|
int st_flash_erase_page(unsigned short PageNumber)
|
2892
|
{
|
2893
|
unsigned char PacketData[ISP_PACKET_SIZE];
|
2894
|
|
2895
|
int retryCount=0;
|
2896
|
int isSuccess=0;
|
2897
|
while(isSuccess==0 && retryCount++ < 2)
|
2898
|
{
|
2899
|
memset(PacketData,0,ISP_PACKET_SIZE);
|
2900
|
PacketData[0] = ISP_CMD_ERASE;
|
2901
|
PacketData[2] = (unsigned char)PageNumber;
|
2902
|
if(st_i2c_write_bytes(PacketData,ISP_PACKET_SIZE) == ISP_PACKET_SIZE)
|
2903
|
{
|
2904
|
//if(retryCount > 1)
|
2905
|
st_msleep(150);
|
2906
|
|
2907
|
if(st_i2c_read_direct(PacketData,ISP_PACKET_SIZE) == ISP_PACKET_SIZE)
|
2908
|
{
|
2909
|
if(PacketData[0] == ISP_CMD_READY)
|
2910
|
isSuccess = 1;
|
2911
|
}
|
2912
|
else
|
2913
|
{
|
2914
|
//time out
|
2915
|
st_msleep(50);
|
2916
|
}
|
2917
|
}
|
2918
|
|
2919
|
if(isSuccess ==0)
|
2920
|
{
|
2921
|
stmsg("Read ISP_Erase_Ready packet fail with page %d retry : %d\n",PageNumber,retryCount);
|
2922
|
//MSLEEP(30);
|
2923
|
}
|
2924
|
|
2925
|
|
2926
|
}
|
2927
|
|
2928
|
if(isSuccess == 0)
|
2929
|
{
|
2930
|
stmsg("Read ISP_Erase_Ready packet fail.\n");
|
2931
|
return -1;
|
2932
|
}
|
2933
|
|
2934
|
return 0;
|
2935
|
}
|
2936
|
|
2937
|
static int st_flash_read_page(unsigned char *Buf,unsigned short PageNumber)
|
2938
|
{
|
2939
|
unsigned char PacketData[ISP_PACKET_SIZE];
|
2940
|
short ReadNumByte;
|
2941
|
short ReadLength;
|
2942
|
|
2943
|
ReadNumByte = 0;
|
2944
|
memset(PacketData,0,ISP_PACKET_SIZE);
|
2945
|
PacketData[0] = ISP_CMD_READ_FLASH;
|
2946
|
PacketData[2] = (unsigned char)PageNumber;
|
2947
|
if(st_i2c_write_bytes(PacketData,ISP_PACKET_SIZE) != ISP_PACKET_SIZE)
|
2948
|
{
|
2949
|
stmsg("Send ISP_Read_Flash packet fail.\n");
|
2950
|
return -1;
|
2951
|
}
|
2952
|
|
2953
|
while(ReadNumByte < ST_FLASH_PAGE_SIZE)
|
2954
|
{
|
2955
|
if((ReadLength = st_i2c_read_direct(Buf+ReadNumByte,ISP_PACKET_SIZE)) != ISP_PACKET_SIZE)
|
2956
|
{
|
2957
|
stmsg("ISP read page data fail.\n");
|
2958
|
return -1;
|
2959
|
}
|
2960
|
if(ReadLength == 0)
|
2961
|
break;
|
2962
|
ReadNumByte += ReadLength;
|
2963
|
}
|
2964
|
return ReadNumByte;
|
2965
|
}
|
2966
|
|
2967
|
static int st_flash_write_page(unsigned char *Buf,unsigned short PageNumber)
|
2968
|
{
|
2969
|
unsigned char PacketData[ISP_PACKET_SIZE];
|
2970
|
short WriteNumByte;
|
2971
|
short WriteLength;
|
2972
|
unsigned short Checksum;
|
2973
|
unsigned char RetryCount;
|
2974
|
|
2975
|
RetryCount = 0;
|
2976
|
while(RetryCount++ < 1)
|
2977
|
{
|
2978
|
WriteNumByte = 0;
|
2979
|
memset(PacketData,0,ISP_PACKET_SIZE);
|
2980
|
Checksum = st_flash_get_checksum(Buf,ST_FLASH_PAGE_SIZE);
|
2981
|
|
2982
|
PacketData[0] = ISP_CMD_WRITE_FLASH;
|
2983
|
PacketData[2] = (unsigned char)PageNumber;
|
2984
|
PacketData[4] = (unsigned char)(Checksum & 0xFF);
|
2985
|
PacketData[5] = (unsigned char)(Checksum >> 8);
|
2986
|
if(st_i2c_write_bytes(PacketData,ISP_PACKET_SIZE) != ISP_PACKET_SIZE )
|
2987
|
{
|
2988
|
stmsg("Send ISP_Write_Flash packet fail.\n");
|
2989
|
return -1;
|
2990
|
}
|
2991
|
PacketData[0] = ISP_CMD_SEND_DATA;
|
2992
|
while(WriteNumByte < ST_FLASH_PAGE_SIZE)
|
2993
|
{
|
2994
|
WriteLength = ST_FLASH_PAGE_SIZE - WriteNumByte;
|
2995
|
if(WriteLength > 7)
|
2996
|
WriteLength = 7;
|
2997
|
memcpy(&PacketData[1],&Buf[WriteNumByte],WriteLength);
|
2998
|
if(st_i2c_write_bytes(PacketData,ISP_PACKET_SIZE) != ISP_PACKET_SIZE)
|
2999
|
{
|
3000
|
stmsg("Send ISP_Write_Flash_Data packet error.\n");
|
3001
|
return -1;
|
3002
|
}
|
3003
|
WriteNumByte += WriteLength;
|
3004
|
}
|
3005
|
|
3006
|
st_msleep(150);
|
3007
|
if(st_i2c_read_direct(PacketData,ISP_PACKET_SIZE) != ISP_PACKET_SIZE)
|
3008
|
{
|
3009
|
stmsg("ISP get \"Write Data Ready Packet\" fail.\n");
|
3010
|
return -1;
|
3011
|
}
|
3012
|
if(PacketData[0] != ISP_CMD_READY)
|
3013
|
{
|
3014
|
stmsg("Command ID of \"Write Data Ready Packet\" error.\n");
|
3015
|
return -1;
|
3016
|
}
|
3017
|
|
3018
|
if((PacketData[2] & 0x10) != 0)
|
3019
|
{
|
3020
|
stmsg("Error occurs during write page data into flash. Error Code = 0x%X\n",PacketData[2]);
|
3021
|
return -1;
|
3022
|
}
|
3023
|
|
3024
|
break;
|
3025
|
}
|
3026
|
|
3027
|
return WriteNumByte;
|
3028
|
}
|
3029
|
|
3030
|
int st_flash_write(unsigned char *Buf, int Offset, int NumByte)
|
3031
|
{
|
3032
|
unsigned short StartPage;
|
3033
|
unsigned short PageOffset;
|
3034
|
int WriteNumByte;
|
3035
|
short WriteLength;
|
3036
|
//unsigned char TempBuf[ST_FLASH_PAGE_SIZE];
|
3037
|
unsigned char * TempBuf;
|
3038
|
int retry = 0;
|
3039
|
int isSuccess = 0;
|
3040
|
|
3041
|
TempBuf = kzalloc(ST_FLASH_PAGE_SIZE, GFP_KERNEL);
|
3042
|
if (TempBuf == NULL)
|
3043
|
{
|
3044
|
printk("Alloc GFP_KERNEL memory failed.");
|
3045
|
return -ENOMEM;
|
3046
|
}
|
3047
|
|
3048
|
|
3049
|
|
3050
|
stmsg("Write flash offset:0x%X , length:0x%X\n",Offset,NumByte);
|
3051
|
|
3052
|
WriteNumByte = 0;
|
3053
|
if(NumByte == 0)
|
3054
|
return WriteNumByte;
|
3055
|
|
3056
|
if((Offset + NumByte) > ST_FLASH_SIZE)
|
3057
|
NumByte = ST_FLASH_SIZE - Offset;
|
3058
|
|
3059
|
StartPage = Offset / ST_FLASH_PAGE_SIZE;
|
3060
|
PageOffset = Offset % ST_FLASH_PAGE_SIZE;
|
3061
|
while(NumByte > 0)
|
3062
|
{
|
3063
|
if((PageOffset != 0) || (NumByte < ST_FLASH_PAGE_SIZE))
|
3064
|
{
|
3065
|
if(st_flash_read_page(TempBuf,StartPage) < 0)
|
3066
|
return -1;
|
3067
|
}
|
3068
|
|
3069
|
WriteLength = ST_FLASH_PAGE_SIZE - PageOffset;
|
3070
|
if(NumByte < WriteLength)
|
3071
|
WriteLength = NumByte;
|
3072
|
memcpy(&TempBuf[PageOffset],Buf,WriteLength);
|
3073
|
|
3074
|
retry = 0;
|
3075
|
isSuccess = 0;
|
3076
|
while(retry++ <2 && isSuccess ==0)
|
3077
|
{
|
3078
|
if(st_flash_unlock() >= 0 && st_flash_erase_page(StartPage) >= 0)
|
3079
|
{
|
3080
|
stmsg("write page:%d\n",StartPage);
|
3081
|
if(st_flash_unlock() >= 0 && st_flash_write_page(TempBuf,StartPage) >= 0)
|
3082
|
isSuccess =1;
|
3083
|
}
|
3084
|
isSuccess =1;
|
3085
|
|
3086
|
if(isSuccess==0)
|
3087
|
stmsg("FIOCTL_IspPageWrite write page %d retry: %d\n",StartPage,retry);
|
3088
|
}
|
3089
|
if(isSuccess==0)
|
3090
|
{
|
3091
|
stmsg("FIOCTL_IspPageWrite write page %d error\n",StartPage);
|
3092
|
return -1;
|
3093
|
}
|
3094
|
else
|
3095
|
StartPage++;
|
3096
|
|
3097
|
NumByte -= WriteLength;
|
3098
|
Buf += WriteLength;
|
3099
|
WriteNumByte += WriteLength;
|
3100
|
PageOffset = 0;
|
3101
|
}
|
3102
|
return WriteNumByte;
|
3103
|
}
|
3104
|
|
3105
|
#ifdef ST_FIREWARE_FILE
|
3106
|
static int st_check_fs_mounted(st_char *path_name)
|
3107
|
{
|
3108
|
struct path root_path;
|
3109
|
struct path path;
|
3110
|
int err;
|
3111
|
err = kern_path("/", LOOKUP_FOLLOW, &root_path);
|
3112
|
|
3113
|
if (err)
|
3114
|
return -1;
|
3115
|
|
3116
|
err = kern_path(path_name, LOOKUP_FOLLOW, &path);
|
3117
|
|
3118
|
if (err)
|
3119
|
return -1;
|
3120
|
|
3121
|
return 0;
|
3122
|
|
3123
|
}
|
3124
|
static int st_load_cfg_from_file(unsigned st_char *buf)
|
3125
|
{
|
3126
|
int j;
|
3127
|
struct st_file *cfg_fp;
|
3128
|
mm_segment_t fs;
|
3129
|
int fileSize = 0;
|
3130
|
|
3131
|
cfg_fp = st_filp_open(ST_CFG_PATH, O_RDWR,0666);
|
3132
|
if(IS_ERR(cfg_fp)){
|
3133
|
stmsg("Test: filp_open error!!. %d\n",j);
|
3134
|
}else
|
3135
|
{
|
3136
|
fs = get_fs();
|
3137
|
set_fs(get_ds());
|
3138
|
|
3139
|
fileSize = cfg_fp->f_op->read(cfg_fp,buf,ST_FW_LEN,&cfg_fp->f_pos);
|
3140
|
set_fs(fs);
|
3141
|
st_filp_close(cfg_fp,NULL);
|
3142
|
}
|
3143
|
return fileSize;
|
3144
|
}
|
3145
|
|
3146
|
static int st_load_fw_from_file(unsigned st_char *buf)
|
3147
|
{
|
3148
|
int i,j;
|
3149
|
struct st_file *fw_fp;
|
3150
|
mm_segment_t fs;
|
3151
|
int fileSize = 0;
|
3152
|
|
3153
|
for(j=0;j<10;j++)
|
3154
|
{
|
3155
|
st_msleep(1000);
|
3156
|
stmsg("Wati for FS %d\n", j);
|
3157
|
|
3158
|
if (st_check_fs_mounted(ST_FW_DIR) == 0)
|
3159
|
{
|
3160
|
stmsg("%s mounted ~!!!!\n",ST_FW_DIR);
|
3161
|
fileSize = 1;
|
3162
|
break;
|
3163
|
}
|
3164
|
}
|
3165
|
if(fileSize ==0)
|
3166
|
{
|
3167
|
stmsg("%s don't mounted ~!!!!\n",ST_FW_DIR);
|
3168
|
return -1;
|
3169
|
}
|
3170
|
for(j=0;j<10;j++)
|
3171
|
{
|
3172
|
st_msleep(1000);
|
3173
|
fileSize = 0;
|
3174
|
fw_fp = st_filp_open(ST_FW_PATH, O_RDWR,0666);
|
3175
|
if(IS_ERR(fw_fp)){
|
3176
|
stmsg("Test: filp_open error!!. %d\n",j);
|
3177
|
fileSize = 0;
|
3178
|
}else
|
3179
|
{
|
3180
|
fileSize = 0;
|
3181
|
fs = get_fs();
|
3182
|
set_fs(get_ds());
|
3183
|
//f->f_op->read(f,buf,ROM_SIZE,&f->f_pos);
|
3184
|
fileSize = fw_fp->f_op->read(fw_fp,buf,ST_FW_LEN,&fw_fp->f_pos);
|
3185
|
set_fs(fs);
|
3186
|
stmsg("fw file size:0x%X\n",fileSize);
|
3187
|
//for(i=0;i<0x10;i++)
|
3188
|
// stmsg("Test: data is %X",buf[i]);
|
3189
|
st_filp_close(fw_fp,NULL);
|
3190
|
break;
|
3191
|
}
|
3192
|
}
|
3193
|
return fileSize;
|
3194
|
}
|
3195
|
|
3196
|
unsigned char fw_buf[ST_FW_LEN];
|
3197
|
unsigned char cfg_buf[ST_CFG_LEN];
|
3198
|
#else
|
3199
|
unsigned char fw_buf[] = SITRONIX_FW;
|
3200
|
unsigned char cfg_buf[] = SITRONIX_CFG;
|
3201
|
#endif //ST_FIREWARE_FILE
|
3202
|
|
3203
|
|
3204
|
static int st_get_fw_info_offset(int fwSize,unsigned st_char *buf)
|
3205
|
{
|
3206
|
int i=0;
|
3207
|
for(i=fwSize-ST_FW_INFO_LEN-4;i>=4;i--)
|
3208
|
{
|
3209
|
if( buf[i] == 0x54 &&
|
3210
|
buf[i+1] == 0x46 &&
|
3211
|
buf[i+2] == 0x49 &&
|
3212
|
buf[i+3] == 0x32 )
|
3213
|
{
|
3214
|
stmsg("TOUCH_FW_INFO offset = 0x%X\n",i+4);
|
3215
|
return i+4;
|
3216
|
}
|
3217
|
}
|
3218
|
stmsg("can't find TOUCH_FW_INFO offset\n");
|
3219
|
return -1;
|
3220
|
}
|
3221
|
static int st_compare_array(unsigned st_char *b1,unsigned st_char *b2,int len)
|
3222
|
{
|
3223
|
int i=0;
|
3224
|
for(i=0;i<len;i++)
|
3225
|
if(b1[i] != b2[i])
|
3226
|
return -1;
|
3227
|
return 0;
|
3228
|
}
|
3229
|
|
3230
|
unsigned char fw_check[ST_FLASH_PAGE_SIZE];
|
3231
|
|
3232
|
int st_upgrade_fw(void)
|
3233
|
{
|
3234
|
int rt=0;
|
3235
|
int fwSize =0;
|
3236
|
int cfgSize =0;
|
3237
|
int fwInfoOff = 0;
|
3238
|
int powerfulWrite = 0;
|
3239
|
|
3240
|
#ifdef ST_FIREWARE_FILE
|
3241
|
fwSize = st_load_fw_from_file(fw_buf);
|
3242
|
|
3243
|
cfgSize = st_load_cfg_from_file(cfg_buf);
|
3244
|
#else
|
3245
|
fwSize = sizeof(fw_buf);
|
3246
|
cfgSize = sizeof(cfg_buf);
|
3247
|
stmsg("fwSize 0x%X,cfgsize 0x%X\n",fwSize,cfgSize);
|
3248
|
#endif //ST_FIREWARE_FILE
|
3249
|
|
3250
|
cfgSize = min(cfgSize,ST_CFG_LEN);
|
3251
|
if(fwSize != 0)
|
3252
|
{
|
3253
|
fwInfoOff = st_get_fw_info_offset(fwSize,fw_buf);
|
3254
|
if(fwInfoOff <0)
|
3255
|
fwSize = 0;
|
3256
|
}
|
3257
|
|
3258
|
if(fwSize ==0 && cfgSize ==0)
|
3259
|
{
|
3260
|
stmsg("can't find FW or CFG , cancel upgrade\n");
|
3261
|
return -1;
|
3262
|
}
|
3263
|
|
3264
|
if(st_get_device_status() == 0x6)
|
3265
|
powerfulWrite = 1;
|
3266
|
|
3267
|
st_irq_off();
|
3268
|
|
3269
|
rt = st_isp_on();
|
3270
|
if(rt !=0)
|
3271
|
{
|
3272
|
stmsg("ISP on fail\n");
|
3273
|
goto ST_IRQ_ON;
|
3274
|
}
|
3275
|
|
3276
|
if(powerfulWrite ==0 &&(fwSize !=0 || cfgSize!=0))
|
3277
|
{
|
3278
|
//check fw and cfg
|
3279
|
int checkOff = (0x3F00 / ST_FLASH_PAGE_SIZE) *ST_FLASH_PAGE_SIZE;
|
3280
|
if(st_flash_read_page(fw_check,0x3F00 / ST_FLASH_PAGE_SIZE)< 0 )
|
3281
|
{
|
3282
|
stmsg("read flash fail , cancel upgrade\n");
|
3283
|
rt = -1;
|
3284
|
goto ST_ISP_OFF;
|
3285
|
}
|
3286
|
|
3287
|
if(fwSize !=0)
|
3288
|
{
|
3289
|
if(0 == st_compare_array(fw_check+(fwInfoOff-checkOff),fw_buf+fwInfoOff,ST_FW_INFO_LEN) )
|
3290
|
{
|
3291
|
stmsg("fw compare :same\n");
|
3292
|
fwSize = 0;
|
3293
|
}
|
3294
|
|
3295
|
}
|
3296
|
|
3297
|
if(cfgSize !=0)
|
3298
|
{
|
3299
|
if(0 == st_compare_array(fw_check+(ST_CFG_OFFSET-checkOff),cfg_buf,cfgSize) )
|
3300
|
{
|
3301
|
stmsg("cfg compare :same\n");
|
3302
|
cfgSize = 0;
|
3303
|
}
|
3304
|
else
|
3305
|
stmsg("cfg compare : different\n");
|
3306
|
|
3307
|
}
|
3308
|
|
3309
|
}
|
3310
|
|
3311
|
if(cfgSize !=0)
|
3312
|
st_flash_write(cfg_buf,ST_CFG_OFFSET,cfgSize);
|
3313
|
|
3314
|
if(fwSize !=0)
|
3315
|
st_flash_write(fw_buf,0,fwSize);
|
3316
|
|
3317
|
ST_ISP_OFF:
|
3318
|
rt = st_isp_off();
|
3319
|
ST_IRQ_ON:
|
3320
|
st_irq_on();
|
3321
|
return rt;
|
3322
|
}
|
3323
|
#endif //ST_UPGRADE_FIRMWARE
|
3324
|
|
3325
|
|
3326
|
#ifdef ST_TEST_RAW
|
3327
|
st_int st_drv_Get_2D_Length(st_int tMode[])
|
3328
|
{
|
3329
|
if(tMode[0] ==0)
|
3330
|
return tMode[1];
|
3331
|
else
|
3332
|
return tMode[2];
|
3333
|
}
|
3334
|
st_int st_drv_Get_2D_Count(st_int tMode[])
|
3335
|
{
|
3336
|
if(tMode[0] == 0)
|
3337
|
return tMode[2];
|
3338
|
else
|
3339
|
return tMode[1];
|
3340
|
}
|
3341
|
|
3342
|
st_int st_drv_Get_2D_RAW(st_int tMode[],st_int rawJ[],st_int gsMode)
|
3343
|
{
|
3344
|
st_int count =st_drv_Get_2D_Count(tMode);
|
3345
|
st_int length = st_drv_Get_2D_Length(tMode);
|
3346
|
st_int maxTimes = 40;
|
3347
|
st_int dataCount=0;
|
3348
|
st_int times = maxTimes;
|
3349
|
|
3350
|
st_u8 raw[0x40];
|
3351
|
memset(raw,0,0x40);
|
3352
|
st_int i=0;
|
3353
|
st_int j=0;
|
3354
|
st_int index;
|
3355
|
st_int keyAddCount = (tMode[3] >0)? 1:0;
|
3356
|
st_int rawI;
|
3357
|
st_int errorCount = 0;
|
3358
|
st_u8 isFillData[MAX_SENSOR_COUNT];
|
3359
|
memset(isFillData,0,count+keyAddCount);
|
3360
|
|
3361
|
//stmsg("isFill 0 : %d",isFillData[0]);
|
3362
|
while(dataCount != (count+keyAddCount) && times-- >0)
|
3363
|
{
|
3364
|
st_i2c_read_bytes(0x40,raw,0x40);
|
3365
|
//stmsg("%X %X %X data:%d key:%d",raw[0],raw[1],raw[2],dataCount,tMode[3]);
|
3366
|
if(raw[0] == 6)
|
3367
|
{
|
3368
|
int index = raw[2];
|
3369
|
//stmsg("isFill %d : %d %d , %d",index,isFillData[index],dataCount,count+keyAddCount);
|
3370
|
if(isFillData[index] ==0)
|
3371
|
{
|
3372
|
//stmsg("index %d",index);
|
3373
|
isFillData[index] = 1;
|
3374
|
dataCount++;
|
3375
|
//index = index*length;
|
3376
|
for(i=0;i<length;i++)
|
3377
|
{
|
3378
|
rawI = raw[4+2*i]*0x100 + raw[5+2*i];
|
3379
|
stmsg("Sensor RAW %d,%d = %d",index,i,rawI);
|
3380
|
if(rawI > MAX_RAW_LIMIT || rawI < MIN_RAW_LIMIT)
|
3381
|
{
|
3382
|
stmsg("Error: Sensor RAW %d,%d = %d out of limity (%d,%d)",index,i,rawI,MIN_RAW_LIMIT,MAX_RAW_LIMIT);
|
3383
|
errorCount++;
|
3384
|
}
|
3385
|
//rawI[index+i] = raw[4+2*i]*0x100 + raw[5+2*i];
|
3386
|
}
|
3387
|
}
|
3388
|
}
|
3389
|
else if(raw[0]==7)
|
3390
|
{
|
3391
|
//key
|
3392
|
//stmsg("key");
|
3393
|
if(isFillData[count] ==0)
|
3394
|
{
|
3395
|
isFillData[count] = 1 ;
|
3396
|
dataCount++;
|
3397
|
for(i=0;i<tMode[3];i++)
|
3398
|
{
|
3399
|
rawI = raw[4+2*i]*0x100 + raw[5+2*i];
|
3400
|
//stmsg("Key RAW %d = %d",i,rawI);
|
3401
|
if(rawI > MAX_RAW_LIMIT || rawI < MIN_RAW_LIMIT)
|
3402
|
{
|
3403
|
stmsg("Error: Key RAW %d = %d out of limity ",i,rawI,MIN_RAW_LIMIT,MAX_RAW_LIMIT);
|
3404
|
errorCount++;
|
3405
|
}
|
3406
|
//rawI[count*length+i] = raw[4+2*i]*0x100 + raw[5+2*i];
|
3407
|
|
3408
|
}
|
3409
|
}
|
3410
|
}
|
3411
|
}
|
3412
|
|
3413
|
if(times <=0)
|
3414
|
{
|
3415
|
stmsg("Get 2D RAW fail!");
|
3416
|
return -1;
|
3417
|
}
|
3418
|
return errorCount;
|
3419
|
}
|
3420
|
int st_drv_test_raw()
|
3421
|
{
|
3422
|
stmsg("start of st_drv_test_raw");
|
3423
|
st_int result = 0;
|
3424
|
st_u8 buf[8];
|
3425
|
st_int sensorCount =0;
|
3426
|
st_int raw_J[MAX_SENSOR_COUNT];
|
3427
|
|
3428
|
/////////////////////////////
|
3429
|
//check status
|
3430
|
memset(buf,0,8);
|
3431
|
if( st_i2c_read_bytes(1,buf,8) <0)
|
3432
|
{
|
3433
|
stmsg("get status fail");
|
3434
|
return -1;
|
3435
|
}
|
3436
|
|
3437
|
stmsg("status :0x%X",buf[0]);
|
3438
|
if(buf[0] != 0 && buf[0] != 4)
|
3439
|
{
|
3440
|
stmsg("can't test in this status");
|
3441
|
result = -1;
|
3442
|
goto st_drv_notest;
|
3443
|
}
|
3444
|
//////////////////////////////
|
3445
|
//go develop page
|
3446
|
memset(buf,0,8);
|
3447
|
st_i2c_read_bytes(0xFF, buf,8);
|
3448
|
if(buf[1] != 0x53 || buf[2] != 0x54 || buf[3] != 0x50 || buf[4] != 0x41)
|
3449
|
{
|
3450
|
stmsg("ic check fail , not sitronix protocol type");
|
3451
|
goto st_drv_notest;
|
3452
|
}
|
3453
|
|
3454
|
buf[0] = buf[6];
|
3455
|
buf[1] = buf[7];
|
3456
|
st_i2c_write_bytes(buf,2);
|
3457
|
|
3458
|
st_i2c_read_bytes(0xFF,buf,2);
|
3459
|
stmsg("page 0x%X",buf[0]);
|
3460
|
if(buf[0] != 0xEF)
|
3461
|
{
|
3462
|
stmsg("change page fail");
|
3463
|
goto st_drv_notest;
|
3464
|
}
|
3465
|
///////////////////////////////
|
3466
|
//get tmode
|
3467
|
st_int tMode[4];
|
3468
|
tMode[0] = TX_ASSIGNMENT; //tx is ?
|
3469
|
st_i2c_read_bytes(0xF5,buf,3);
|
3470
|
tMode[1] = buf[0]; //x
|
3471
|
tMode[2] = buf[1]; //y
|
3472
|
tMode[3] = buf[2]&0xf; // key
|
3473
|
|
3474
|
sensorCount = tMode[1]+tMode[2]+tMode[3];
|
3475
|
|
3476
|
stmsg("sensor count:%d %d %d",tMode[1],tMode[2],tMode[3]);
|
3477
|
//////////////////////////////
|
3478
|
//get raw and judge
|
3479
|
result = st_drv_Get_2D_RAW(tMode,raw_J,0);
|
3480
|
if(result !=0)
|
3481
|
{
|
3482
|
stmsg("Error: Test fail with %d sensor",result);
|
3483
|
result = -1;
|
3484
|
}
|
3485
|
else
|
3486
|
{
|
3487
|
stmsg("Test successed!");
|
3488
|
}
|
3489
|
//////////////////////////////
|
3490
|
//reset
|
3491
|
buf[0] = 2;
|
3492
|
buf[1] = 1;
|
3493
|
st_i2c_write_bytes(buf,2);
|
3494
|
|
3495
|
st_msleep(100);
|
3496
|
st_drv_notest:
|
3497
|
return result;
|
3498
|
}
|
3499
|
#endif //ST_TEST_RAW
|