1 //#define TPD_HAVE_BUTTON
4 #include <linux/interrupt.h>
7 #include <linux/i2c-dev.h>
8 #include <linux/cdev.h>
9 #include <linux/sched.h>
10 #include <linux/kthread.h>
11 #include <linux/rtpm_prio.h>
12 #include <linux/wait.h>
13 #include <linux/time.h>
14 #include <linux/delay.h>
15 #include <mach/mt_pm_ldo.h>
16 //#include <mach/mt6575_pll.h>
17 #include <linux/dma-mapping.h>
19 #ifdef TPD_GPT_TIMER_RESUME
20 #include <mach/hardware.h>
21 #include <mach/mt_gpt.h>
22 #include <linux/timer.h>
24 #include "tpd_custom_ft5x06.h"
26 #include "cust_gpio_usage.h"
28 //#define FTS_APK_DEBUG
30 //#define FTS_AUTO_UPGRADE
31 #if defined(SYSFS_DEBUG) || defined(FTS_AUTO_UPGRADE)
32 #include "ft5x06_ex_fun.h"
35 #define TPD_INFO(fmt, arg...) printk("[tpd info:5x06]" "[%s]" fmt "\r\n", __FUNCTION__ ,##arg)
40 #define TPD_DEBUG(fmt, arg...) printk("[tpd debug:5x06]" "[%s]" fmt "\r\n", __FUNCTION__ ,##arg)
41 #define TPD_DMESG(fmt, arg...) printk("[tpd dmesg:5x06]" "[%s]" fmt "\r\n", __FUNCTION__ ,##arg)
43 #define TPD_DEBUG(fmt, arg...)
44 #define TPD_DMESG(fmt, arg...)
47 extern struct tpd_device
*tpd
;
49 struct i2c_client
*i2c_client
= NULL
;
50 struct task_struct
*thread
= NULL
;
52 static DECLARE_WAIT_QUEUE_HEAD(waiter
);
54 static void tpd_eint_interrupt_handler(void);
56 static int tpd_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
);
57 static int tpd_detect(struct i2c_client
*client
, struct i2c_board_info
*info
);
58 static int tpd_remove(struct i2c_client
*client
);
59 static int touch_event_handler(void *unused
);
61 static int tpd_flag
= 0;
62 static int point_num
= 0;
63 static int p_point_num
= 0;
65 #define TPD_CLOSE_POWER_IN_SLEEP
70 #define DEVICE_MODE 0x00
72 #define TD_STATUS 0x02
73 #define FW_ID_ADDR 0xA6
78 #define FINGER_NUM_MAX 10
81 int y
[FINGER_NUM_MAX
];
82 int x
[FINGER_NUM_MAX
];
83 int p
[FINGER_NUM_MAX
];
87 static const struct i2c_device_id tpd_id
[] = {{"mtk-tpd",0},{}};
89 #if defined(E1910) && !defined(TP_CFG_FOR_E1910_SMT)
90 unsigned short force
[] = {0,0x72,I2C_CLIENT_END
,I2C_CLIENT_END
};
91 static const unsigned short * const forces
[] = { force
, NULL
};
92 //static struct i2c_client_address_data addr_data = { .forces = forces, };
93 static struct i2c_board_info __initdata i2c_tpd
= { I2C_BOARD_INFO("mtk-tpd", (0x72>>1))};
95 unsigned short force
[] = {0,0x70,I2C_CLIENT_END
,I2C_CLIENT_END
};
96 static const unsigned short * const forces
[] = { force
, NULL
};
97 //static struct i2c_client_address_data addr_data = { .forces = forces, };
98 static struct i2c_board_info __initdata i2c_tpd
= { I2C_BOARD_INFO("mtk-tpd", (0x70>>1))};
101 static struct kobject
*touchdebug_kobj
;
102 static struct kobject
*touchdebug_kobj_info
;
103 static int sensitivity_level
= 1;
104 static int EnableWakeUp
= 0;
106 /* Waiting for deivce resume and write back touch sensitivity level */
107 static struct timer_list sensitivity_write_timer
;
109 /* Touch panel resume delay */
110 #define TOUCH_RESUME_INTERVAL 500
112 /* Workqueue for set touch sensitivity level */
113 static struct workqueue_struct
*sensitivity_wq
;
114 static struct work_struct
*sensitivity_work
;
116 struct sensitivity_mapping
{
122 TOUCH_SENSITIVITY_SYMBOL_HIGH
= 0,
123 TOUCH_SENSITIVITY_SYMBOL_MEDIUM
,
124 TOUCH_SENSITIVITY_SYMBOL_LOW
,
125 TOUCH_SENSITIVITY_SYMBOL_COUNT
,
128 static struct sensitivity_mapping sensitivity_table
[] = {
129 {TOUCH_SENSITIVITY_SYMBOL_HIGH
, 14},
130 {TOUCH_SENSITIVITY_SYMBOL_MEDIUM
, 16},
131 {TOUCH_SENSITIVITY_SYMBOL_LOW
, 19},
134 #define TOUCH_SENSITIVITY_SYMBOL_DEFAULT TOUCH_SENSITIVITY_SYMBOL_MEDIUM;
136 #define I2C_DEV_NUMBER 8
137 #define DRIVER_DEV_NAME "fts_ts"
148 struct i2c_client
*client
;
149 struct input_dev
*input_dev
;
152 struct i2c_msg_formal
{
153 __u16 addr
; /* slave address */
155 #define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
156 #define I2C_M_RD 0x0001 /* read data, from slave to master */
157 #define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */
158 #define I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
159 #define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
160 #define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
161 #define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
162 __u16 len
; /* msg length */
163 __u8
*buf
; /* pointer to msg data */
166 static struct fts_dev ts_dev
;
168 #include <mach/mt_boot.h>
169 static int boot_mode
= 0;
171 #ifdef TPD_HAVE_BUTTON
172 extern void tpd_button(unsigned int x
, unsigned int y
, unsigned int down
);
175 #define TPD_KEYS {KEY_HOME,KEY_MENU,KEY_BACK,KEY_SEARCH}
176 #define TPD_KEYS_DIM {{30,850,60,100},{180,850,60,100},{320,850,60,100},{450,850,60,100}}
177 #define TPD_KEY_COUNT 4
179 #define TPD_KEYS {KEY_HOME,KEY_MENU,KEY_BACK}
180 #define TPD_KEYS_DIM {{80,850,60,100},{240,850,60,100},{400,850,60,100}}
181 #define TPD_KEY_COUNT 3
184 static int tpd_keys_local
[TPD_KEY_COUNT
] = TPD_KEYS
;
185 static int tpd_keys_dim_local
[TPD_KEY_COUNT
][4] = TPD_KEYS_DIM
;
188 #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
189 //static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX;
190 static int tpd_calmat_driver
[8] = {0};
191 static int tpd_def_calmat_local_normal
[8] = TPD_CALIBRATION_MATRIX_ROTATION_NORMAL
;
192 static int tpd_def_calmat_local_factory
[8] = TPD_CALIBRATION_MATRIX_ROTATION_FACTORY
;
195 static struct i2c_driver tpd_i2c_driver
= {
196 .driver
.name
= "mtk-tpd",
198 .remove
= tpd_remove
,
200 .detect
= tpd_detect
,
201 .address_list
= (const unsigned short*) forces
,
205 static unsigned short i2c_addr
[] = {0x72};
208 static u8
*gpDMABuf_va
= NULL
;
209 static u32 gpDMABuf_pa
= 0;
211 int fts_dma_i2c_read(struct i2c_client
*client
, u16 addr
, int len
, u32 rxbuf
)
216 struct i2c_msg msg
[2] =
219 .addr
= client
->addr
,
226 .addr
= client
->addr
,
227 .ext_flag
= (client
->ext_flag
| I2C_ENEXT_FLAG
| I2C_DMA_FLAG
),
237 if ((u8
*)rxbuf
== NULL
)
240 ret
= i2c_transfer(client
->adapter
, &msg
[0], 2);
242 dev_err(&client
->dev
, "%s i2c dma read error.\n", __func__
);
247 static ssize_t
fts_i2cdev_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*offset
)
251 /* struct fts_info *ts = ts_dev.ts; */
252 struct i2c_client
*client
= ts_dev
.ts
->client
;
254 TPD_DMESG("called\n");
259 tmp
= kmalloc(count
, GFP_KERNEL
);
263 pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n",
264 iminor(file
->f_path
.dentry
->d_inode
), count
);
266 ret
= i2c_master_recv(client
, tmp
, count
);
268 ret
= copy_to_user(buf
, tmp
, count
) ? -EFAULT
: ret
;
273 static ssize_t
fts_i2cdev_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*offset
)
277 /* struct fts_info *ts = ts_dev.ts; */
278 struct i2c_client
*client
= ts_dev
.ts
->client
;
280 TPD_DMESG("called\n");
285 tmp = memdup_user(buf, count);
289 tmp
= kmalloc(count
,GFP_KERNEL
);
292 if (copy_from_user(tmp
,buf
,count
)) {
297 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n",
298 iminor(file
->f_path
.dentry
->d_inode
), count
);
300 ret
= i2c_master_send(client
, tmp
, count
);
305 static int i2cdev_check(struct device
*dev
, void *addrp
)
307 struct i2c_client
*client
= i2c_verify_client(dev
);
308 /* struct fts_info *ts = ts_dev.ts; */
310 TPD_DMESG("called\n");
312 if (!client
|| client
->addr
!= *(unsigned int *)addrp
)
315 return dev
->driver
? -EBUSY
: 0;
318 static int i2cdev_check_addr(struct i2c_adapter
*adapter
, unsigned int addr
)
320 return device_for_each_child(&adapter
->dev
, &addr
, i2cdev_check
);
323 static noinline
int i2cdev_ioctl_rdrw(struct i2c_client
*client
,
326 struct i2c_rdwr_ioctl_data rdwr_arg
;
327 struct i2c_msg
*rdwr_pa
, *rdwr_pa_tmp
;
328 struct i2c_msg_formal
*rdwr_pa_formal
;
329 u8 __user
**data_ptrs
;
331 /* struct fts_info *ts = ts_dev.ts; */
333 TPD_DMESG("called\n");
335 if (copy_from_user(&rdwr_arg
,
336 (struct i2c_rdwr_ioctl_data __user
*)arg
,
340 /* Put an arbitrary limit on the number of messages that can
342 if (rdwr_arg
.nmsgs
> I2C_RDRW_IOCTL_MAX_MSGS
)
345 rdwr_pa
= kmalloc(rdwr_arg
.nmsgs
* sizeof(struct i2c_msg
), GFP_KERNEL
);
349 rdwr_pa_formal
= kmalloc(rdwr_arg
.nmsgs
* sizeof(struct i2c_msg_formal
), GFP_KERNEL
);
353 if (copy_from_user(rdwr_pa_formal
, rdwr_arg
.msgs
,
354 rdwr_arg
.nmsgs
* sizeof(struct i2c_msg_formal
))) {
359 data_ptrs
= kmalloc(rdwr_arg
.nmsgs
* sizeof(u8 __user
*), GFP_KERNEL
);
360 if (data_ptrs
== NULL
) {
362 kfree(rdwr_pa_formal
);
367 for (i
= 0, rdwr_pa_tmp
= rdwr_pa
; i
< rdwr_arg
.nmsgs
; i
++, rdwr_pa_tmp
++) {
368 rdwr_pa_tmp
->addr
= rdwr_pa_formal
->addr
;
369 rdwr_pa_tmp
->flags
= rdwr_pa_formal
->flags
;
370 rdwr_pa_tmp
->len
= rdwr_pa_formal
->len
;
371 rdwr_pa_tmp
->timing
= client
->timing
;
372 rdwr_pa_tmp
->ext_flag
= 0;
374 /* Limit the size of the message to a sane amount;
375 * and don't let length change either. */
376 if ((rdwr_pa
[i
].len
> 8192) ||
377 (rdwr_pa
[i
].flags
& I2C_M_RECV_LEN
)) {
381 data_ptrs
[i
] = (u8 __user
*)rdwr_pa_formal
[i
].buf
;
383 rdwr_pa
[i
].buf
= kmalloc(rdwr_pa
[i
].len
, GFP_KERNEL
);
384 if (rdwr_pa
[i
].buf
== NULL
) {
388 if (copy_from_user(rdwr_pa
[i
].buf
, data_ptrs
[i
],
390 ++i
; /* Needs to be kfreed too */
395 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
396 if (IS_ERR(rdwr_pa[i].buf)) {
397 res = PTR_ERR(rdwr_pa[i].buf);
404 for (j
= 0; j
< i
; ++j
)
405 kfree(rdwr_pa
[j
].buf
);
408 kfree(rdwr_pa_formal
);
412 res
= i2c_transfer(client
->adapter
, rdwr_pa
, rdwr_arg
.nmsgs
);
414 if (res
>= 0 && (rdwr_pa
[i
].flags
& I2C_M_RD
)) {
415 if (copy_to_user(data_ptrs
[i
], rdwr_pa
[i
].buf
,
419 kfree(rdwr_pa
[i
].buf
);
423 kfree(rdwr_pa_formal
);
427 static noinline
int i2cdev_ioctl_smbus(struct i2c_client
*client
,
430 struct i2c_smbus_ioctl_data data_arg
;
431 union i2c_smbus_data temp
;
434 if (copy_from_user(&data_arg
,
435 (struct i2c_smbus_ioctl_data __user
*) arg
,
436 sizeof(struct i2c_smbus_ioctl_data
)))
438 if ((data_arg
.size
!= I2C_SMBUS_BYTE
) &&
439 (data_arg
.size
!= I2C_SMBUS_QUICK
) &&
440 (data_arg
.size
!= I2C_SMBUS_BYTE_DATA
) &&
441 (data_arg
.size
!= I2C_SMBUS_WORD_DATA
) &&
442 (data_arg
.size
!= I2C_SMBUS_PROC_CALL
) &&
443 (data_arg
.size
!= I2C_SMBUS_BLOCK_DATA
) &&
444 (data_arg
.size
!= I2C_SMBUS_I2C_BLOCK_BROKEN
) &&
445 (data_arg
.size
!= I2C_SMBUS_I2C_BLOCK_DATA
) &&
446 (data_arg
.size
!= I2C_SMBUS_BLOCK_PROC_CALL
)) {
447 dev_dbg(&client
->adapter
->dev
,
448 "size out of range (%x) in ioctl I2C_SMBUS.\n",
452 /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1,
453 so the check is valid if size==I2C_SMBUS_QUICK too. */
454 if ((data_arg
.read_write
!= I2C_SMBUS_READ
) &&
455 (data_arg
.read_write
!= I2C_SMBUS_WRITE
)) {
456 dev_dbg(&client
->adapter
->dev
,
457 "read_write out of range (%x) in ioctl I2C_SMBUS.\n",
458 data_arg
.read_write
);
462 /* Note that command values are always valid! */
464 if ((data_arg
.size
== I2C_SMBUS_QUICK
) ||
465 ((data_arg
.size
== I2C_SMBUS_BYTE
) &&
466 (data_arg
.read_write
== I2C_SMBUS_WRITE
)))
467 /* These are special: we do not use data */
468 return i2c_smbus_xfer(client
->adapter
, client
->addr
,
469 client
->flags
, data_arg
.read_write
,
470 data_arg
.command
, data_arg
.size
, NULL
);
472 if (data_arg
.data
== NULL
) {
473 dev_dbg(&client
->adapter
->dev
,
474 "data is NULL pointer in ioctl I2C_SMBUS.\n");
478 if ((data_arg
.size
== I2C_SMBUS_BYTE_DATA
) ||
479 (data_arg
.size
== I2C_SMBUS_BYTE
))
480 datasize
= sizeof(data_arg
.data
->byte
);
481 else if ((data_arg
.size
== I2C_SMBUS_WORD_DATA
) ||
482 (data_arg
.size
== I2C_SMBUS_PROC_CALL
))
483 datasize
= sizeof(data_arg
.data
->word
);
484 else /* size == smbus block, i2c block, or block proc. call */
485 datasize
= sizeof(data_arg
.data
->block
);
487 if ((data_arg
.size
== I2C_SMBUS_PROC_CALL
) ||
488 (data_arg
.size
== I2C_SMBUS_BLOCK_PROC_CALL
) ||
489 (data_arg
.size
== I2C_SMBUS_I2C_BLOCK_DATA
) ||
490 (data_arg
.read_write
== I2C_SMBUS_WRITE
)) {
491 if (copy_from_user(&temp
, data_arg
.data
, datasize
))
494 if (data_arg
.size
== I2C_SMBUS_I2C_BLOCK_BROKEN
) {
495 /* Convert old I2C block commands to the new
496 convention. This preserves binary compatibility. */
497 data_arg
.size
= I2C_SMBUS_I2C_BLOCK_DATA
;
498 if (data_arg
.read_write
== I2C_SMBUS_READ
)
499 temp
.block
[0] = I2C_SMBUS_BLOCK_MAX
;
501 res
= i2c_smbus_xfer(client
->adapter
, client
->addr
, client
->flags
,
502 data_arg
.read_write
, data_arg
.command
, data_arg
.size
, &temp
);
503 if (!res
&& ((data_arg
.size
== I2C_SMBUS_PROC_CALL
) ||
504 (data_arg
.size
== I2C_SMBUS_BLOCK_PROC_CALL
) ||
505 (data_arg
.read_write
== I2C_SMBUS_READ
))) {
506 if (copy_to_user(data_arg
.data
, &temp
, datasize
))
512 static long fts_i2cdev_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
514 struct i2c_client
*client
= ts_dev
.ts
->client
;
516 /* struct fts_info *ts = ts_dev.ts; */
518 TPD_DMESG( "ioctl, cmd=0x%02x, arg=0x%02lx\n", cmd
, arg
);
522 case I2C_SLAVE_FORCE
:
523 /* NOTE: devices set up to work with "new style" drivers
524 * can't use I2C_SLAVE, even when the device node is not
525 * bound to a driver. Only I2C_SLAVE_FORCE will work.
527 * Setting the PEC flag here won't affect kernel drivers,
528 * which will be using the i2c_client node registered with
529 * the driver model core. Likewise, when that client has
530 * the PEC flag already set, the i2c-dev driver won't see
531 * (or use) this setting.
534 (((client
->flags
& I2C_M_TEN
) == 0) && arg
> 0x7f))
536 if (cmd
== I2C_SLAVE
&& i2cdev_check_addr(client
->adapter
, arg
))
538 /* REVISIT: address could become busy later */
543 client
->flags
|= I2C_M_TEN
;
545 client
->flags
&= ~I2C_M_TEN
;
549 client
->flags
|= I2C_CLIENT_PEC
;
551 client
->flags
&= ~I2C_CLIENT_PEC
;
554 funcs
= i2c_get_functionality(client
->adapter
);
555 return put_user(funcs
, (unsigned long __user
*)arg
);
558 return i2cdev_ioctl_rdrw(client
, arg
);
561 return i2cdev_ioctl_smbus(client
, arg
);
564 client
->adapter
->retries
= arg
;
567 /* For historical reasons, user-space sets the timeout
568 * value in units of 10 ms.
570 client
->adapter
->timeout
= msecs_to_jiffies(arg
* 10);
573 /* NOTE: returning a fault code here could cause trouble
574 * in buggy userspace code. Some old kernel bugs returned
575 * zero in this case, and userspace code might accidentally
576 * have depended on that bug.
583 static int fts_i2cdev_open(struct inode
*inode
, struct file
*file
)
586 /* struct fts_info *ts = ts_dev.ts; */
588 TPD_DMESG("called\n");
591 disable_irq(ts_dev
.ts
->client
->irq
);
592 printk("[i2c-8] [fts_i2cdev_open][success]\n");
595 printk("[i2c-8] [fts_i2cdev_open][fail]\n");
602 static int fts_i2cdev_release(struct inode
*inode
, struct file
*file
)
605 /* struct fts_info *ts = ts_dev.ts; */
608 struct i2c_client *client = file->private_data;
610 i2c_put_adapter(client->adapter);
612 file->private_data = NULL;
614 TPD_DMESG("called\n");
616 enable_irq(ts_dev
.ts
->client
->irq
);
623 static const struct file_operations fts_fops
= {
624 .owner
= THIS_MODULE
,
625 //.llseek = no_llseek,
626 .read
= fts_i2cdev_read
,
627 .write
= fts_i2cdev_write
,
628 .unlocked_ioctl
= fts_i2cdev_ioctl
,
629 .open
= fts_i2cdev_open
,
630 .release
= fts_i2cdev_release
,
633 int fts_i2cdev_init(struct fts_info
*ts
)
639 memset(&ts_dev
, 0, sizeof(struct fts_dev
));
641 ret
= alloc_chrdev_region(&ts_dev
.dev
, 0, 1, DRIVER_DEV_NAME
);
643 TPD_DMESG("Unable to get a dynamic major for %s.\n", DRIVER_DEV_NAME
);
647 cdev_init(&ts_dev
.cdev
, &fts_fops
);
648 ts_dev
.cdev
.owner
= THIS_MODULE
;
649 ret
= cdev_add(&ts_dev
.cdev
, ts_dev
.dev
, 1);
651 TPD_DMESG("Unable to register character device !\n");
655 ts_dev
.class = class_create(THIS_MODULE
, DRIVER_DEV_NAME
);
657 if(IS_ERR(ts_dev
.class)){
658 TPD_DMESG("Unable to register i2c device class !\n");
659 ret
= PTR_ERR(ts_dev
.class);
663 dev
= device_create(ts_dev
.class, NULL
, ts_dev
.dev
, NULL
, "i2c-%d", I2C_DEV_NUMBER
);
666 TPD_DMESG("Failed to create device !\n");
676 class_destroy(ts_dev
.class);
678 cdev_del(&ts_dev
.cdev
);
680 unregister_chrdev_region(ts_dev
.dev
, 1);
685 void fts_i2cdev_exit(void)
688 cdev_del(&ts_dev
.cdev
);
689 unregister_chrdev_region(ts_dev
.dev
, 1);
690 device_destroy(ts_dev
.class, ts_dev
.dev
);
691 class_destroy(ts_dev
.class);
694 int myatoi(const char *a
)
698 while(*a
>= '0' && *a
<= '9')
699 s
= (s
<< 3) + (s
<< 1) + *a
++ - '0';
703 static void sensitivity_set_func(struct work_struct
*work
)
705 uint8_t wdata
[1] = {0};
708 TPD_INFO("sensitivity_set_func value:%d\n", sensitivity_level
);
710 wdata
[0] = sensitivity_table
[sensitivity_level
].value
;
711 ret
= ft5x0x_write_reg(i2c_client
, 0x80, wdata
[0]);
713 TPD_INFO("Can not write sensitivity\n");
716 #ifdef MODIFY_SCANRATE_TO_DEFAULT_VALUE
717 /* Modify scan rate to default value */
719 ret
= ft5x0x_write_reg(i2c_client
, 0x89, wdata
[0]);
721 TPD_INFO("Can not write scan rate\n");
728 static void sensitivity_func(long unsigned unused
)
730 TPD_INFO("sensitivity_func \n");
732 queue_work(sensitivity_wq
, sensitivity_work
);
737 static ssize_t
firmware_show(struct kobject
*kobj
,
738 struct kobj_attribute
*attr
,
741 unsigned char reg_version
= 0;
742 i2c_smbus_read_i2c_block_data(i2c_client
, FW_ID_ADDR
, 1, ®_version
);
743 return sprintf(buf
, "FT0-%x0-13032500\n", reg_version
);
746 static ssize_t
wakeup_store(struct kobject
*kobj
,
747 struct kobj_attribute
*attr
,
748 const char * buf
, size_t n
)
753 symbol
= myatoi(buf
);
754 if (EnableWakeUp
!= symbol
) {
755 EnableWakeUp
= symbol
;
756 /* Modify wake up mode:
761 ret
= ft5x0x_write_reg(i2c_client
, 0xac, EnableWakeUp
);
763 TPD_INFO("Can not write wake up mode\n");
766 TPD_INFO("wakeup_store value:%d\n", EnableWakeUp
);
771 static ssize_t
wakeup_show(struct kobject
*kobj
,
772 struct kobj_attribute
*attr
,
775 return sprintf(buf
, "%d\n", EnableWakeUp
);
778 static ssize_t
sensitivity_store(struct kobject
*kobj
,
779 struct kobj_attribute
*attr
,
780 const char * buf
, size_t n
)
782 uint8_t wdata
[1] = {0};
786 symbol
= myatoi(buf
);
787 sensitivity_level
= symbol
;
788 TPD_INFO("sensitive_store value:%d\n", symbol
);
790 wdata
[0] = sensitivity_table
[symbol
].value
;
792 ret
= ft5x0x_write_reg(i2c_client
, 0x80, wdata
[0]);
794 TPD_INFO("Can not write sensitivity\n");
799 static ssize_t
sensitivity_show(struct kobject
*kobj
,
800 struct kobj_attribute
*attr
,
803 uint8_t rdata
[1] = {0};
806 if (!i2c_smbus_read_i2c_block_data(i2c_client
, 0x80, 1, rdata
)) {
810 for (i
= 0; i
< TOUCH_SENSITIVITY_SYMBOL_COUNT
; i
++) {
811 if (sensitivity_table
[i
].value
== rdata
[0]) {
812 symbol
= sensitivity_table
[i
].symbol
;
819 TPD_INFO("touch sensitivity default value\n");
820 symbol
= TOUCH_SENSITIVITY_SYMBOL_DEFAULT
;
823 return sprintf(buf
, "%d\n", symbol
);
826 static struct kobj_attribute firmware_attr
= { \
828 .name
= __stringify(firmware
), \
831 .show
= firmware_show
, \
834 static struct kobj_attribute wakeup_attr
= { \
836 .name
= __stringify(wakeup
), \
839 .show
= wakeup_show
, \
840 .store
= wakeup_store
, \
843 static struct kobj_attribute sensitivity_attr
= { \
845 .name
= __stringify(sensitivity
), \
848 .show
= sensitivity_show
, \
849 .store
= sensitivity_store
, \
852 static struct attribute
* g
[] = {
853 &sensitivity_attr
.attr
,
858 static struct attribute
* g_info
[] = {
863 static struct attribute_group attr_group
= {
867 static struct attribute_group attr_group_info
= {
871 static void tpd_down(int x
, int y
, int p
) {
873 #ifdef TPD_HAVE_BUTTON
874 #if defined(TP_CFG_FOR_E1910_SMT) || defined(ROTATION_FOR_E1910_CQ)
875 if(MTK_LCM_PHYSICAL_ROTATION
== 270 || MTK_LCM_PHYSICAL_ROTATION
== 90)
877 #if defined(TP_HEIGHT)
878 if(boot_mode
!=NORMAL_BOOT
&& x
>=TP_HEIGHT
) {
881 if(boot_mode
!=NORMAL_BOOT
&& x
>=TPD_RES_Y
) {
891 #if defined(TP_HEIGHT)
892 if(boot_mode
!=NORMAL_BOOT
&& y
>=TP_HEIGHT
) {
895 if(boot_mode
!=NORMAL_BOOT
&& y
>=TPD_RES_Y
) {
905 // input_report_abs(tpd->dev, ABS_PRESSURE, p);
906 input_report_key(tpd
->dev
, BTN_TOUCH
, 1);
907 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
, 1);
909 #if defined(TP_CFG_FOR_E1910_SMT) || defined(ROTATION_FOR_E1910_CQ)
910 if(boot_mode
!=NORMAL_BOOT
&& (MTK_LCM_PHYSICAL_ROTATION
== 270 || MTK_LCM_PHYSICAL_ROTATION
== 90) )
920 input_report_abs(tpd
->dev
, ABS_MT_POSITION_X
, x
);
921 input_report_abs(tpd
->dev
, ABS_MT_POSITION_Y
, y
);
922 TPD_DEBUG("D[%4d %4d %4d] ", x
, y
, p
);
923 TPD_EM_PRINT(x
, y
, x
, y
, p
-1, 1);
924 input_mt_sync(tpd
->dev
);
925 TPD_DOWN_DEBUG_TRACK(x
,y
);
928 static void tpd_up(int x
, int y
,int p
) {
929 //input_report_abs(tpd->dev, ABS_PRESSURE, 0);
930 input_report_key(tpd
->dev
, BTN_TOUCH
, 0);
931 //input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 0);
932 //input_report_abs(tpd->dev, ABS_MT_POSITION_X, x);
933 //input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y);
934 //printk("U[%4d %4d %4d] ", x, y, 0);
935 TPD_EM_PRINT(x
, y
, x
, y
, 0, 0);
936 input_mt_sync(tpd
->dev
);
937 TPD_UP_DEBUG_TRACK(x
,y
);
940 static int tpd_touchinfo(struct touch_info
*cinfo
, struct touch_info
*pinfo
)
943 char *data
= gpDMABuf_va
;
944 u16 high_byte
,low_byte
;
946 p_point_num
= point_num
;
947 memcpy(pinfo
, cinfo
, sizeof(struct touch_info
));
948 memset(cinfo
, 0, sizeof(struct touch_info
));
950 fts_dma_i2c_read(i2c_client
, 0x00, 64, gpDMABuf_pa
);
951 //TPD_DEBUG("FW version=%x]\n",data[24]);
953 //TPD_DEBUG("received raw data from touch panel as following:\n");
954 //TPD_DEBUG("[data[0]=%x,data[1]= %x ,data[2]=%x ,data[3]=%x ,data[4]=%x ,data[5]=%x]\n",data[0],data[1],data[2],data[3],data[4],data[5]);
955 //TPD_DEBUG("[data[9]=%x,data[10]= %x ,data[11]=%x ,data[12]=%x]\n",data[9],data[10],data[11],data[12]);
956 //TPD_DEBUG("[data[15]=%x,data[16]= %x ,data[17]=%x ,data[18]=%x]\n",data[15],data[16],data[17],data[18]);
958 /* Device Mode[2:0] == 0 :Normal operating Mode*/
959 if((data
[0] & 0x70) != 0) return false;
961 /*get the number of the touch points*/
962 point_num
= data
[2] & 0x0f;
964 TPD_DEBUG("point_num =%d\n",point_num
);
966 if(FINGER_NUM_MAX
< point_num
)
968 TPD_DEBUG("point_num is error\n");
972 // if(point_num == 0) return false;
974 //TPD_DEBUG("Procss raw data...\n");
977 for(i
= 0; i
< point_num
; i
++)
979 cinfo
->p
[i
] = data
[3+6*i
] >> 6; //event flag
981 /*get the X coordinate, 2 bytes*/
982 high_byte
= data
[3+6*i
];
985 low_byte
= data
[3+6*i
+ 1];
986 cinfo
->x
[i
] = high_byte
|low_byte
;
988 //cinfo->x[i] = cinfo->x[i] * 480 >> 11; //calibra
989 /*get the Y coordinate, 2 bytes*/
990 high_byte
= data
[3+6*i
+2];
993 low_byte
= data
[3+6*i
+3];
994 cinfo
->y
[i
] = high_byte
|low_byte
;
996 //cinfo->y[i]= cinfo->y[i] * 800 >> 11;
999 #if defined(TPD_RES_X) && defined(TP_WIDTH)
1000 cinfo
->x
[i
] = cinfo
->x
[i
]*TP_WIDTH
/TPD_RES_X
;
1002 #if defined(TPD_RES_Y) && defined(TP_HEIGHT)
1003 cinfo
->y
[i
] = cinfo
->y
[i
]*TP_HEIGHT
/TPD_RES_Y
;
1006 TPD_DEBUG(" cinfo->x[i=%d] = %d, cinfo->y[i] = %d, cinfo->p[i] = %d\n", i
,cinfo
->x
[i
], cinfo
->y
[i
], cinfo
->p
[i
]);
1009 //TPD_DEBUG(" cinfo->x[0] = %d, cinfo->y[0] = %d, cinfo->p[0] = %d\n", cinfo->x[0], cinfo->y[0], cinfo->p[0]);
1010 //TPD_DEBUG(" cinfo->x[1] = %d, cinfo->y[1] = %d, cinfo->p[1] = %d\n", cinfo->x[1], cinfo->y[1], cinfo->p[1]);
1011 //TPD_DEBUG(" cinfo->x[2]= %d, cinfo->y[2]= %d, cinfo->p[2] = %d\n", cinfo->x[2], cinfo->y[2], cinfo->p[2]);
1013 #if defined(SMT_TP_CONFIG)
1014 for(i
= 0; i
< point_num
; i
++)
1016 cinfo
->x
[i
] = cinfo
->x
[i
] *36/51;//5.1CM/5.4CM
1017 cinfo
->y
[i
] = cinfo
->y
[i
] *27/37;//7.4CM/9.0CM
1021 #if 0/*!defined(TP_CFG_FOR_E1910_SMT) && !defined(ROTATION_FOR_E1910_CQ)*/
1022 if(MTK_LCM_PHYSICAL_ROTATION
== 270 || MTK_LCM_PHYSICAL_ROTATION
== 90)
1024 for(i
= 0; i
< point_num
; i
++)
1029 cinfo
->x
[i
] = TPD_RES_X
-cinfo
->y
[i
];
1033 TPD_DEBUG("rot cinfo->x[0] = %d, cinfo->y[0] = %d, cinfo->p[0] = %d\n", cinfo
->x
[0], cinfo
->y
[0], cinfo
->p
[0]);
1034 TPD_DEBUG("rot cinfo->x[1] = %d, cinfo->y[1] = %d, cinfo->p[1] = %d\n", cinfo
->x
[1], cinfo
->y
[1], cinfo
->p
[1]);
1041 /*Coordination mapping*/
1042 static void tpd_calibrate_driver(int *x
, int *y
)
1046 TPD_DEBUG("Call tpd_calibrate of this driver ..\n");
1047 tx
= ((tpd_calmat_driver
[0] * (*x
)) + (tpd_calmat_driver
[1] * (*y
)) + (tpd_calmat_driver
[2])) >> 12;
1048 *y
= ((tpd_calmat_driver
[3] * (*x
)) + (tpd_calmat_driver
[4] * (*y
)) + (tpd_calmat_driver
[5])) >> 12;
1052 static int touch_event_handler(void *unused
)
1054 struct touch_info cinfo
, pinfo
;
1059 struct sched_param param
= { .sched_priority
= RTPM_PRIO_TPD
};
1060 sched_setscheduler(current
, SCHED_RR
, ¶m
);
1064 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1065 set_current_state(TASK_INTERRUPTIBLE
);
1066 wait_event_interruptible(waiter
,tpd_flag
!=0);
1070 set_current_state(TASK_RUNNING
);
1072 if (tpd_touchinfo(&cinfo
, &pinfo
))
1074 TPD_DEBUG("point_num = %d\n",point_num
);
1079 tpd_down(cinfo
.x
[0], cinfo
.y
[0], 1);
1082 tpd_down(cinfo
.x
[1], cinfo
.y
[1], 1);
1084 tpd_down(cinfo
.x
[2], cinfo
.y
[2], 1);
1089 //tpd_down(cinfo.x[i], cinfo.y[i], 1);
1090 input_x
= cinfo
.x
[i
];
1091 input_y
= cinfo
.y
[i
];
1092 tpd_calibrate_driver(&input_x
, &input_y
);
1093 tpd_down(input_x
, input_y
, 1);
1098 TPD_DEBUG("press --->\n");
1103 TPD_DEBUG("release --->\n");
1108 while(i
<p_point_num
){
1109 tpd_up(pinfo
.x
[i
], pinfo
.y
[i
], 1);
1115 tpd_up(pinfo
.x
[0], pinfo
.y
[0], 1);
1119 #ifdef TPD_HAVE_BUTTON
1120 if(boot_mode
!=NORMAL_BOOT
&& tpd
->btn_state
)
1122 tpd_button(pinfo
.x
[0], pinfo
.y
[0], 0);
1128 input_sync(tpd
->dev
);
1131 }while(!kthread_should_stop());
1136 static int tpd_detect (struct i2c_client
*client
, struct i2c_board_info
*info
)
1138 TPD_DEBUG("tpd_detect\n");
1139 strcpy(info
->type
, TPD_DEVICE
);
1143 static void tpd_eint_interrupt_handler(void)
1145 TPD_DEBUG("TPD interrupt has been triggered\n");
1147 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
1148 wake_up_interruptible(&waiter
);
1151 static void tpd_gpio_config(void)
1154 mt_set_gpio_pull_enable(GPIO_CTP_RST_PIN
, GPIO_PULL_ENABLE
);
1155 mt_set_gpio_pull_select(GPIO_CTP_RST_PIN
, GPIO_PULL_UP
);
1156 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1157 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1158 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1160 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_EINT
);
1161 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
1162 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_ENABLE
);
1163 mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN
, GPIO_PULL_UP
);
1168 static int tpd_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
1170 int retval
= TPD_OK
;
1173 struct fts_info
*ts
;
1176 i2c_client
= client
;
1177 TPD_INFO("tpd_probe\n");
1181 #ifdef TPD_CLOSE_POWER_IN_SLEEP
1183 #ifdef TPD_POWER_SOURCE_CUSTOM
1184 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
1187 hwPowerOn(TPD_POWER_SOURCE
, VOL_2800
, "TP");
1189 hwPowerOn(TPD_POWER_SOURCE
, TPD_LDO_VOL
, "TP");
1190 #endif //TPD_LDO_VOL
1192 #ifdef TPD_POWER_SOURCE_1800
1193 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
1196 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1200 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1201 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1202 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1203 TPD_INFO("TPD_CLOSE_POWER_IN_SLEEP\n");
1204 for(i
= 0; i
< 2; i
++) /*Do Power on again to avoid tp bug*/
1206 #ifdef TPD_POWER_SOURCE_CUSTOM
1207 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
1209 hwPowerDown(TPD_POWER_SOURCE
, "TP");
1211 #ifdef TPD_POWER_SOURCE_1800
1212 hwPowerDown(TPD_POWER_SOURCE_1800
, "TP");
1214 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1216 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1218 #ifdef TPD_POWER_SOURCE_CUSTOM
1219 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
1221 hwPowerOn(TPD_POWER_SOURCE
, VOL_2800
, "TP");
1223 #ifdef TPD_POWER_SOURCE_1800
1224 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
1232 #ifdef TPD_POWER_SOURCE_CUSTOM
1233 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
1235 hwPowerDown(TPD_POWER_SOURCE
, "TP");
1237 #ifdef TPD_POWER_SOURCE_1800
1238 hwPowerDown(TPD_POWER_SOURCE_1800
, "TP");
1241 TPD_INFO("tpd power on!\n");
1242 #ifdef TPD_POWER_SOURCE_CUSTOM
1243 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
1246 hwPowerOn(TPD_POWER_SOURCE
, VOL_2800
, "TP");
1248 hwPowerOn(TPD_POWER_SOURCE
, TPD_LDO_VOL
, "TP");
1249 #endif //TPD_LDO_VOL
1251 #ifdef TPD_POWER_SOURCE_1800
1252 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
1257 mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO);
1258 mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT);
1259 mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ONE);
1262 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1263 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1264 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1267 TPD_INFO("addr:0x%02x",i2c_client
->addr
);
1269 if((i2c_smbus_read_i2c_block_data(i2c_client
, FW_ID_ADDR
, 1, &data
))< 0)
1272 for(i
= 0; i
< sizeof(i2c_addr
)/ sizeof(i2c_addr
[0]); i
++)
1274 i2c_client
->addr
= i2c_addr
[i
];
1275 TPD_INFO("addr:0x%02x",i2c_client
->addr
);
1276 if((i2c_smbus_read_i2c_block_data(i2c_client
, 0x00, 1, &data
))>= 0)
1278 goto i2c_transfer_sucess
;
1283 TPD_INFO("I2C transfer error, line: %d\n", __LINE__
);
1287 i2c_transfer_sucess
:
1289 tpd_load_status
= 1;
1291 touchdebug_kobj
= kobject_create_and_add("Touch", NULL
);
1292 if (touchdebug_kobj
== NULL
)
1293 TPD_INFO("%s: subsystem_register failed\n", __func__
);
1295 if (sysfs_create_group(touchdebug_kobj
, &attr_group
))
1296 TPD_INFO("%s:sysfs_create_group failed\n", __func__
);
1298 touchdebug_kobj_info
= kobject_create_and_add("dev-info_touch", NULL
);
1299 if (touchdebug_kobj_info
== NULL
)
1300 TPD_INFO("%s: subsystem_register failed\n", __func__
);
1302 if (sysfs_create_group(touchdebug_kobj_info
, &attr_group_info
))
1303 TPD_INFO("%s:sysfs_create_group failed\n", __func__
);
1305 sensitivity_work
= kzalloc(sizeof(typeof(*sensitivity_work
)), GFP_KERNEL
);
1306 if (!sensitivity_work
) {
1307 TPD_INFO("create work queue error, line: %d\n", __LINE__
);
1310 INIT_WORK(sensitivity_work
, sensitivity_set_func
);
1312 sensitivity_wq
= create_singlethread_workqueue("sensitivity_wq");
1313 if (!sensitivity_wq
) {
1314 kfree(sensitivity_work
);
1315 TPD_INFO("create thread error, line: %d\n", __LINE__
);
1318 setup_timer(&sensitivity_write_timer
, sensitivity_func
, 0);
1320 thread
= kthread_run(touch_event_handler
, 0, TPD_DEVICE
);
1323 retval
= PTR_ERR(thread
);
1324 TPD_DMESG(TPD_DEVICE
" failed to create kernel thread: %d\n", retval
);
1327 //mt_eint_set_sens(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_SENSITIVE);
1329 mt_eint_set_hw_debounce(CUST_EINT_TOUCH_PANEL_NUM
, CUST_EINT_TOUCH_PANEL_DEBOUNCE_CN
);
1330 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, CUST_EINT_TOUCH_PANEL_TYPE
, tpd_eint_interrupt_handler
, 1);
1331 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1334 ts
= kzalloc (sizeof(struct fts_info
), GFP_KERNEL
);
1338 ts
->client
= client
;
1339 i2c_set_clientdata(client
, ts
);
1341 err
= fts_i2cdev_init(ts
);
1343 TPD_DMESG("[i2c-8][Fail]\n");
1345 TPD_DMESG("[i2c-8][Success]\n");
1348 ft5x0x_create_sysfs(i2c_client
);
1351 #ifdef FTS_APK_DEBUG
1352 ft5x0x_create_apk_debug_channel(i2c_client
);
1354 #ifdef FTS_AUTO_UPGRADE
1355 fts_ctpm_auto_upgrade(i2c_client
);
1357 TPD_DMESG("Touch Panel Device Probe %s\n", (retval
< TPD_OK
) ? "FAIL" : "PASS");
1358 TPD_DMESG("[i2c-8] i2c_client->timing:%d\n", i2c_client
->timing
);
1362 static int tpd_remove(struct i2c_client
*client
)
1364 struct fts_info
*ts
= i2c_get_clientdata(client
);
1365 #ifdef FTS_APK_DEBUG
1366 ft5x0x_release_apk_debug_channel();
1369 ft5x0x_release_sysfs(client
);
1371 TPD_INFO("TPD removed\n");
1373 del_timer_sync(&sensitivity_write_timer
);
1374 cancel_work_sync(sensitivity_work
);
1375 destroy_workqueue(sensitivity_wq
);
1376 kfree(sensitivity_work
);
1385 static int tpd_local_init(void)
1387 TPD_DMESG("Focaltech FT5x06 I2C Touchscreen Driver (Built %s @ %s)\n", __DATE__
, __TIME__
);
1389 gpDMABuf_va
= (u8
*)dma_alloc_coherent(NULL
, 64, &gpDMABuf_pa
, GFP_KERNEL
);
1391 DBG("[Error] Allocate DMA I2C Buffer failed!\n");
1394 boot_mode
= get_boot_mode();
1395 if(boot_mode
==3) boot_mode
= NORMAL_BOOT
;
1396 #ifdef TPD_HAVE_BUTTON
1397 tpd_button_setting(TPD_KEY_COUNT
, tpd_keys_local
, tpd_keys_dim_local
);// initialize tpd button data
1400 if(i2c_add_driver(&tpd_i2c_driver
)!=0)
1402 TPD_DMESG("unable to add i2c driver.\n");
1406 #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
1408 if (FACTORY_BOOT
== get_boot_mode())
1410 TPD_INFO("Factory mode is detected! \n");
1411 memcpy(tpd_calmat_driver
, tpd_def_calmat_local_factory
, sizeof(tpd_calmat_driver
));
1415 TPD_INFO("Normal mode is detected! \n");
1416 memcpy(tpd_calmat_driver
, tpd_def_calmat_local_normal
, sizeof(tpd_calmat_driver
));
1421 input_set_abs_params(tpd
->dev
, ABS_MT_TRACKING_ID
, 0, FINGER_NUM_MAX
-1, 0, 0);//for linux3.8
1423 TPD_DMESG("end %s, %d\n", __FUNCTION__
, __LINE__
);
1429 #ifdef TPD_GPT_TIMER_RESUME
1431 void ctp_thread_wakeup(UINT16 i
)
1433 //printk("**** ctp_thread_wakeup****\n" );
1434 GPT_NUM gpt_num
= GPT6
;
1435 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1439 void CTP_Thread_XGPTConfig(void)
1442 GPT_NUM gpt_num
= GPT6
;
1443 GPT_CLK_SRC clkSrc
= GPT_CLK_SRC_RTC
;
1444 //GPT_CLK_DIV clkDiv = GPT_CLK_DIV_128;
1445 GPT_CLK_DIV clkDiv
= GPT_CLK_DIV_64
;
1447 //printk("***CTP_Thread_XGPTConfig***\n" );
1449 GPT_Init (gpt_num
, ctp_thread_wakeup
);
1450 config
.num
= gpt_num
;
1451 config
.mode
= GPT_REPEAT
;
1452 config
.clkSrc
= clkSrc
;
1453 config
.clkDiv
= clkDiv
;
1454 //config.u4Timeout = 10*128;
1455 config
.u4CompareL
= 256; // 10s : 512*64=32768
1456 config
.u4CompareH
= 0;
1457 config
.bIrqEnable
= TRUE
;
1459 if (GPT_Config(config
) == FALSE
)
1468 static void tpd_resume(struct early_suspend
*h
)
1470 /* int retval = TPD_OK; */
1472 int ret
= 0;/* retry_num = 0, */
1474 TPD_INFO("TPD wake up\n");
1476 if (!EnableWakeUp
) {
1477 #ifdef TPD_GPT_TIMER_RESUME
1478 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
1480 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1481 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1482 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1485 #ifdef TPD_POWER_SOURCE_CUSTOM
1486 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
1488 hwPowerDown(TPD_POWER_SOURCE
, "TP");
1490 #ifdef TPD_POWER_SOURCE_1800
1491 hwPowerDown(TPD_POWER_SOURCE_1800
, "TP");
1493 #ifdef TPD_POWER_SOURCE_CUSTOM
1494 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
1497 hwPowerOn(TPD_POWER_SOURCE
, VOL_2800
, "TP");
1499 hwPowerOn(TPD_POWER_SOURCE
, TPD_LDO_VOL
, "TP");
1500 #endif //TPD_LDO_VOL
1502 #ifdef TPD_POWER_SOURCE_1800
1503 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
1506 CTP_Thread_XGPTConfig();
1508 #ifdef TPD_CLOSE_POWER_IN_SLEEP
1509 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1511 #ifdef TPD_POWER_SOURCE_CUSTOM
1512 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
1515 hwPowerOn(TPD_POWER_SOURCE
, VOL_2800
, "TP");
1517 hwPowerOn(TPD_POWER_SOURCE
, TPD_LDO_VOL
, "TP");
1518 #endif //TPD_LDO_VOL
1520 #ifdef TPD_POWER_SOURCE_1800
1521 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
1524 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1526 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1529 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1530 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1531 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1535 #ifdef TPD_POWER_SOURCE_CUSTOM
1536 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
1538 hwPowerOn(TPD_POWER_SOURCE
, VOL_2800
, "TP");
1540 #ifdef TPD_POWER_SOURCE_1800
1541 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
1545 if((ret
= i2c_smbus_read_i2c_block_data(i2c_client
, FW_ID_ADDR
, 1, &data
))< 0)
1547 TPD_DEBUG("i2c transf error before reset :ret=%d,retry_num == %d\n",ret
,retry_num
);
1549 #ifdef TPD_POWER_SOURCE_CUSTOM
1550 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
1552 hwPowerDown(TPD_POWER_SOURCE
, "TP");
1554 #ifdef TPD_POWER_SOURCE_1800
1555 hwPowerDown(TPD_POWER_SOURCE_1800
, "TP");
1560 TPD_DEBUG("i2c transfer success after reset :ret=%d,retry_num == %d\n",ret
,retry_num
);
1564 }while(retry_num
< 10);
1566 if((ret
= i2c_smbus_read_i2c_block_data(i2c_client
, FW_ID_ADDR
, 1, &data
))< 0)
1568 TPD_DEBUG("i2c transf error before reset :ret=%d,retry_num == %d\n",ret
,retry_num
);
1570 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1571 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1572 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1575 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1576 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1577 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1579 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1580 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1581 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1584 if((ret
= i2c_smbus_read_i2c_block_data(i2c_client
, FW_ID_ADDR
, 1, &data
))< 0)
1586 TPD_DEBUG("i2c transf error after reset :ret = %d,retry_num == %d\n",ret
,retry_num
);
1590 TPD_DEBUG("i2c transfer success after reset :ret = %d,retry_num == %d\n",ret
,retry_num
);
1593 TPD_DEBUG("retry_num == %d\n",retry_num
);
1596 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1597 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1598 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1601 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1602 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1603 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1605 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1606 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1607 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1610 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1614 ret
= ft5x0x_write_reg(i2c_client
, 0xab, data
);
1616 TPD_INFO("Resume can not write 0xAB\n");
1619 mod_timer(&sensitivity_write_timer
,
1620 jiffies
+ msecs_to_jiffies(TOUCH_RESUME_INTERVAL
));
1622 /* return retval; */
1625 static void tpd_suspend(struct early_suspend
*h
)
1627 /* int retval = TPD_OK; */
1628 static char data
= 0x3;
1631 TPD_INFO("TPD enter sleep\n");
1633 if (!EnableWakeUp
) {
1634 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
1635 #ifdef TPD_CLOSE_POWER_IN_SLEEP
1636 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1638 #ifdef TPD_POWER_SOURCE_CUSTOM
1639 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
1641 hwPowerDown(TPD_POWER_SOURCE
, "TP");
1643 #ifdef TPD_POWER_SOURCE_1800
1644 hwPowerDown(TPD_POWER_SOURCE_1800
, "TP");
1647 ft5x0x_write_reg(i2c_client
, 0xA5, data
); //TP enter sleep mode
1649 mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO);
1650 mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT);
1651 mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ZERO);
1656 ret
= ft5x0x_write_reg(i2c_client
, 0xab, data
);
1658 TPD_INFO("Suspend can not write 0xAB\n");
1660 /* return retval; */
1664 static struct tpd_driver_t tpd_device_driver
= {
1665 .tpd_device_name
= "FT5x06",
1666 .tpd_local_init
= tpd_local_init
,
1667 .suspend
= tpd_suspend
,
1668 .resume
= tpd_resume
,
1669 #ifdef TPD_HAVE_BUTTON
1670 .tpd_have_button
= 1,
1672 .tpd_have_button
= 0,
1676 /* called when loaded into kernel */
1677 static int __init
tpd_driver_init(void) {
1678 TPD_DEBUG("MediaTek FT5x06 touch panel driver init\n");
1679 i2c_register_board_info(TPD_I2C_NUMBER
, &i2c_tpd
, 1);
1680 if(tpd_driver_add(&tpd_device_driver
) < 0)
1681 TPD_DMESG("add FT5x06 driver failed\n");
1686 /* should never be called */
1687 static void __exit
tpd_driver_exit(void) {
1688 TPD_DMESG("MediaTek FT5x06 touch panel driver exit\n");
1689 //input_unregister_device(tpd->dev);
1690 tpd_driver_remove(&tpd_device_driver
);
1693 module_init(tpd_driver_init
);
1694 module_exit(tpd_driver_exit
);