2 * Touchscreen driver for Melfas MMS-200 series
4 * Copyright (C) 2013 Melfas Inc.
5 * Author: DVK team <dvk@melfas.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/i2c.h>
19 #include <linux/input.h>
20 #include <linux/slab.h>
21 #include <linux/gpio.h>
22 #include <linux/sched.h>
23 #include <linux/kthread.h>
24 #include <linux/bitops.h>
25 #include <linux/kernel.h>
26 #include <linux/byteorder/generic.h>
27 #ifdef CONFIG_HAS_EARLYSUSPEND
28 #include <linux/earlysuspend.h>
30 #include <linux/interrupt.h>
31 #include <linux/time.h>
32 #include <linux/rtpm_prio.h>
33 #include <linux/proc_fs.h>
34 #include <linux/jiffies.h>
35 #include <linux/firmware.h>
36 #include <linux/earlysuspend.h>
37 #include <linux/irq.h>
38 #include <linux/input/mt.h>
39 #include <linux/cdev.h>
41 #include <linux/completion.h>
42 #include <linux/init.h>
44 #include <asm/uaccess.h>
45 #include <cust_eint.h>
46 #include <asm/unaligned.h>
47 #include <mach/eint.h>
48 #include <mach/mt_typedefs.h>
49 #include <mach/mt_pm_ldo.h>
50 #include <linux/types.h>
51 #include <linux/dma-mapping.h>
54 #include <mach/mt_boot.h>
58 #include <mach/mt_boot.h>
62 #include "mms200_ts.h"
64 #define TPD_POWER_SOURCE_CUSTOM MT6323_POWER_LDO_VGP1
66 #define TP_DEV_NAME "mms200"
67 #define I2C_RETRY_CNT 5 //Fixed value
68 #define DOWNLOAD_RETRY_CNT 5 //Fixed value
69 #define MELFAS_DOWNLOAD 1 //Fixed value
71 #define PRESS_KEY 1 //Fixed value
72 #define RELEASE_KEY 0 //Fixed value
75 MMS244 RMI register map
77 #define TS_READ_LEN_ADDR 0x0F
78 #define TS_READ_START_ADDR 0x10
79 #define TS_READ_REGS_LEN 66
80 #define TS_WRITE_REGS_LEN 16
81 #define TS_TSP_REV_ADDR 0xc0
82 #define TS_HARDWARE_REV_ADDR 0xc1
83 #define TS_COMPATIBILITY_GRU_ADDR 0xc2
84 #define TS_FIRMWARE_REV_ADDR 0xc3
85 #define TS_CHIP_INFO_ADDR 0xc4
86 #define TS_MANUFACTURER_INFO_ADDR 0xc5
91 #define TS_TYPE_TRULY 0x02
92 #define TS_TYPE_BIEL 0x10
93 #define TS_TYPE_UNKNOWN 0xff
98 #define MELFAS_HW_REVISON 0x01
99 #define MELFAS_TURLY_H1_FW_VERSION 0x04
100 #define MELFAS_TURLY_H2_FW_VERSION 0xf8
101 #define MELFAS_TURLY_H3_FW_VERSION 0x12
102 #define MELFAS_BIEL_H1_FW_VERSION 0x06
103 #define MELFAS_BIEL_H2_FW_VERSION 0x09
105 #define TS_READ_HW_VER_ADDR 0xF1 //Model Dependent
106 #define TS_READ_SW_VER_ADDR 0xF5 //Model Dependent
108 #define MELFAS_MAX_TRANSACTION_LENGTH 66
109 #define MELFAS_MAX_I2C_TRANSFER_SIZE 7
110 #define MELFAS_I2C_DEVICE_ADDRESS_LEN 1
111 #define MELFAS_I2C_MASTER_CLOCK 100
112 #define MELFAS_I2C_ADDRESS 0x20
117 #define MELFAS_ESD_ERROR 0x0F
118 #define TS_MAX_TOUCH 10
119 #define MMS244_CHIP 0x14
121 static int melfas_tpd_flag
= 0;
122 static u8
* DMAbuffer_va
= NULL
;
123 static dma_addr_t DMAbuffer_pa
= NULL
;
124 static int interrupt_count
= 0;
126 static u8 tp_factory_id_cmd
= TS_TYPE_UNKNOWN
;
127 static u8 hardware_ver
= 0;
129 typedef struct muti_touch_info
135 unsigned int pressed
;
138 static struct muti_touch_info g_Mtouch_info
[TS_MAX_TOUCH
];
141 enum tp_finger_status
{
147 static int finger_status
[TS_MAX_TOUCH
] = {FINGER_UNKNOWN
};
149 #define TPD_HAVE_BUTTON
150 #ifdef TPD_HAVE_BUTTON
151 #define TPD_KEY_COUNT 3
152 #define TPD_KEYS {KEY_BACK, KEY_HOMEPAGE ,KEY_MENU}
153 #define TPD_KEYS_DIM {{200,1980,100,80},\
156 static int tpd_keys_local
[TPD_KEY_COUNT
] = TPD_KEYS
;
157 static int tpd_keys_dim_local
[TPD_KEY_COUNT
][4] = TPD_KEYS_DIM
;
161 static DECLARE_WAIT_QUEUE_HEAD(melfas_waiter
);
162 //static DEFINE_MUTEX(melfas_tp_mutex);
164 struct i2c_client
*melfas_i2c_client
= NULL
;
166 static const struct i2c_device_id melfas_tpd_id
[] = {{TP_DEV_NAME
,0},{}};
167 static struct i2c_board_info __initdata melfas_i2c_tpd
={ I2C_BOARD_INFO(TP_DEV_NAME
, MELFAS_I2C_ADDRESS
)};
169 static int melfas_tpd_i2c_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
);
170 static int melfas_tpd_i2c_remove(struct i2c_client
*client
);
171 static int melfas_tpd_i2c_detect(struct i2c_client
*client
, struct i2c_board_info
*info
);
172 extern int isc_fw_download(struct i2c_client
*client
, const U8
*data
, size_t len
);
173 static int melfas_i2c_read(struct i2c_client
*client
, U16 addr
, U16 len
, U8
*rxbuf
);
174 int melfas_i2c_DMAread(struct i2c_client
*client
, U16 addr
, U16 len
, U8
*rxbuf
);
175 int melfas_i2c_DMAwrite(struct i2c_client
*client
, U16 addr
, U16 len
, U8
*txbuf
);
177 static void melfas_ts_release_all_finger(void);
180 extern struct tpd_device
*tpd
;
182 static struct i2c_driver melfas_tpd_i2c_driver
=
184 .probe
= melfas_tpd_i2c_probe
,
185 .remove
= melfas_tpd_i2c_remove
,
186 .detect
= melfas_tpd_i2c_detect
,
187 .driver
.name
= "mtk-tpd",
188 .id_table
= melfas_tpd_id
,
189 #ifndef CONFIG_HAS_EARLYSUSPEND
190 .suspend
= melfas_ts_suspend
,
191 .resume
= melfas_ts_resume
,
197 PR 460136,turly and biel touchpanel compatibility,Firmware update series
204 const u8 MELFAS_biel_h1_binary
[] = {
205 #include "MCH_TDIABLOX_B_R01_V06.mfsb.h"
207 const u8 MELFAS_biel_h2_binary
[] = {
208 //#include "MCH_TDIABLOX_B_R02_V07.mfsb.h"
209 #include "MCH_TDIABLOX_B_R02_V09.mfsb.h"
211 const u8 MELFAS_turly_h1_binary
[] = {
212 #include "MCH_TDIABLOX_R01_V04.mfsb.h"
214 const u8 MELFAS_turly_h2_binary
[] = {
215 #include "MCH_TDIABLOX_T_R02_VF8.mfsb.h"
217 const u8 MELFAS_turly_h3_binary
[] = {
218 #include "MCH_TDIABLOX_T_R03_V12.mfsb.h"
224 #define TP_SYSFS_SUPPORT
225 #ifdef TP_SYSFS_SUPPORT
226 static ssize_t
TP_value_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
233 ret
= melfas_i2c_read(melfas_i2c_client
, 0xc1, 1, &val
[0]);
234 ret
= melfas_i2c_read(melfas_i2c_client
, 0xc2, 1, &val
[1]);
235 ret
= melfas_i2c_read(melfas_i2c_client
, 0xc3, 1, &val
[2]);
236 ret
= melfas_i2c_read(melfas_i2c_client
, 0xc4, 1, &val
[3]);
237 ret
= melfas_i2c_read(melfas_i2c_client
, 0xc5, 1, &val
[4]);
238 ret
= melfas_i2c_read(melfas_i2c_client
, 0xc0, 1, &val
[5]);
240 s
+= sprintf(s
, "TP, mms244_ts, hardware version: %x \n", val
[0]);
241 s
+= sprintf(s
, "TP, mms244_ts, 0xC2: %x \n", val
[1]);
242 s
+= sprintf(s
, "TP, mms244_ts, firmware version: %x \n", val
[2]);
243 s
+= sprintf(s
, "TP, mms244_ts, 0xC4: %x \n", val
[3]);
244 s
+= sprintf(s
, "TP, mms244_ts, manufacture info: %x \n", val
[4]);
245 s
+= sprintf(s
, "TP, mms244_ts, 0xC0: %x \n", val
[5]);
249 kal_uint8 TPD_DBG
= 0;
250 static ssize_t
TP_value_store(struct kobject
*kobj
, struct kobj_attribute
*attr
,
251 const char *buf
, size_t n
)
256 char cmd_str
[16] = {0};
258 sscanf(buf
, "%s %d", (char *)&cmd_str
, &val
);
260 if(strcmp(cmd_str
, "DEBUG") == 0) {
271 static ssize_t
debug_touch_show(struct device
*dev
,
272 struct device_attribute
*attr
, const char *buf
)
276 s
+= sprintf(s
, "TP finger status:%d %d %d %d %d \n",
277 finger_status
[0],finger_status
[1],finger_status
[2],
278 finger_status
[3],finger_status
[4]);
279 s
+= sprintf(s
, "TP finger status:%d %d %d %d %d \n",
280 finger_status
[5],finger_status
[6],finger_status
[7],
281 finger_status
[8],finger_status
[9]);
285 static ssize_t
debug_touch_store(struct kobject
*kobj
,
286 struct kobj_attribute
*attr
, const char *buf
, size_t n
)
290 if (sscanf(buf
, "%d", &save
)==0) {
291 printk(KERN_ERR
"%s -- invalid save string '%s'...\n",
299 static DEVICE_ATTR(debug_touch
, 0664, debug_touch_show
, debug_touch_store
);
301 PR 457838 series,cts permission issue
303 static DEVICE_ATTR(TP_DEBUG
, 0644, TP_value_show
, TP_value_store
);
305 static struct attribute
*TP_sysfs_attrs
[] = {
306 &dev_attr_TP_DEBUG
.attr
,
307 &dev_attr_debug_touch
.attr
,
310 static struct attribute_group TP_attr_group
= {
311 .attrs
= TP_sysfs_attrs
,
315 struct kobject
*TP_ctrl_kobj
;
316 static int TP_sysfs_init(void)
318 TP_ctrl_kobj
= kobject_create_and_add("TP", NULL
);
322 return sysfs_create_group(TP_ctrl_kobj
, &TP_attr_group
);
325 static void TP_sysfs_exit(void)
327 sysfs_remove_group(TP_ctrl_kobj
, &TP_attr_group
);
328 kobject_put(TP_ctrl_kobj
);
334 void touchkey_handler(u8 key
, bool on
)
340 TPD_DMESG("MMS_TOUCH_KEY_EVENT BACK, %d \n",on
);
341 input_report_key(tpd
->dev
, KEY_BACK
, on
);
345 TPD_DMESG("MMS_TOUCH_KEY_EVENT HOME, %d \n",on
);
346 input_report_key(tpd
->dev
, KEY_HOMEPAGE
, on
);
350 TPD_DMESG("MMS_TOUCH_KEY_EVENT MENU, %d \n",on
);
351 input_report_key(tpd
->dev
, KEY_MENU
, on
);
361 esd performance revise
362 if some esd error happened,then we reset the tp
363 chip factory think 50 ms dalay is acceptable
365 static void esd_rest_tp(void)
367 //TPD_DEBUG("==========tp have inter esd =============\n");
368 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
369 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
370 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
371 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
373 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
374 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
375 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
378 static int melfas_touch_event_handler(void *unused
)
381 u8 buf
[TS_READ_REGS_LEN
] = { 0 };
382 int i
, read_num
, fingerID
, Touch_Type
= 0, touchState
= 0;//, keyID = 0;
385 struct sched_param param
= { .sched_priority
= RTPM_PRIO_TPD
};
387 sched_setscheduler(current
, SCHED_RR
, ¶m
);
390 //mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
391 set_current_state(TASK_INTERRUPTIBLE
);
392 wait_event_interruptible(melfas_waiter
, melfas_tpd_flag
!= 0);
395 set_current_state(TASK_RUNNING
);
397 melfas_i2c_read(melfas_i2c_client
, TS_READ_LEN_ADDR
, 1, buf
);
399 //TPD_DMESG("melfas,read_num = %d\n",read_num);
400 //TPD_DMESG("melfas,interrupt_count = %d \n",interrupt_count);
403 int siganl rest issue,filter some error packets
405 if (((read_num
% 6)!= 0) || (read_num
> 60)) {
406 //mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
407 TPD_DMESG("illegal read_num : %d\n", read_num
);
408 melfas_ts_release_all_finger();
414 melfas_i2c_read(melfas_i2c_client
, TS_READ_START_ADDR
, read_num
, buf
);
415 else if (read_num
> 8)
416 melfas_i2c_DMAread(melfas_i2c_client
, TS_READ_START_ADDR
, read_num
, buf
);
419 if(buf
[0] == MELFAS_ESD_ERROR
) {
420 //mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
421 TPD_DMESG("ESD error!\n");
422 melfas_ts_release_all_finger();
427 for (i
= 0; i
< read_num
; i
= i
+ FINGER_EVENT_SZ
) {
428 Touch_Type
= (buf
[i
] >> 5) & 0x03;
429 //TPD_DMESG("%s : touch type = %d, buf[i] = %x \n",__FUNCTION__,Touch_Type, buf[i]);
430 /* touch type is panel */
431 if (Touch_Type
== MMS_TOUCH_KEY_EVENT
) {
432 touchkey_handler((buf
[i
] & 0x0f),(bool)(buf
[i
] & 0x80));
435 fingerID
= (buf
[i
] & 0x0F) - 1;
436 touchState
= ((buf
[i
] & 0x80) >> 7);
438 if ((fingerID
< 0) || (fingerID
>TS_MAX_TOUCH
)) {
439 TPD_DMESG("illegal finger id (id: %d)\n", fingerID
);
442 if (!touchState
&& !g_Mtouch_info
[fingerID
].pressed
) {
443 TPD_DMESG("Wrong touch release (id: %d)\n", fingerID
);
447 g_Mtouch_info
[fingerID
].pos_x
= (uint16_t)(buf
[i
+ 2] |
448 ((buf
[i
+ 1] & 0xf) << 8));
449 g_Mtouch_info
[fingerID
].pos_y
= (uint16_t)(buf
[i
+ 3] |
450 (((buf
[i
+ 1] >> 4 ) & 0xf) << 8));
451 g_Mtouch_info
[fingerID
].area
= buf
[i
+ 4];
453 g_Mtouch_info
[fingerID
].pressure
= buf
[i
+ 5];
455 g_Mtouch_info
[fingerID
].pressure
= 0;
456 //g_Mtouch_info[fingerID].pressed = pressed;
457 g_Mtouch_info
[fingerID
].pressed
= touchState
;
458 g_Mtouch_info
[fingerID
].updated
= true;
460 /*TPD_DMESG("[MMS200]: Touch ID: %d, State : %d, x: %d, y: %d, z: %d w: %d\n",
463 g_Mtouch_info[i].pos_x,
464 g_Mtouch_info[i].pos_y,
465 g_Mtouch_info[i].pressure,
466 g_Mtouch_info[i].area);*/
471 for (id
= 0; id
< TS_MAX_TOUCH
; id
++) {
472 if (!g_Mtouch_info
[id
].updated
)
474 g_Mtouch_info
[id
].updated
= false;
476 if (g_Mtouch_info
[id
].pressed
) {
477 input_mt_slot(tpd
->dev
, id
);
478 input_report_key(tpd
->dev
, BTN_TOUCH
, 1);
479 input_report_abs(tpd
->dev
, ABS_MT_TRACKING_ID
, id
+2);
481 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
,
482 g_Mtouch_info
[id
].area
);
483 input_report_abs(tpd
->dev
, ABS_MT_POSITION_X
,
484 g_Mtouch_info
[id
].pos_x
);
485 input_report_abs(tpd
->dev
, ABS_MT_POSITION_Y
,
486 g_Mtouch_info
[id
].pos_y
);
487 finger_status
[id
] = FINGER_DOWN
;
489 else if (!g_Mtouch_info
[id
].pressed
) {
490 input_mt_slot(tpd
->dev
, id
);
491 input_report_abs(tpd
->dev
, ABS_MT_TRACKING_ID
, -1);
492 finger_status
[id
] = FINGER_UP
;
497 if ( (tpd
!= NULL
) && (tpd
->dev
!= NULL
) )
498 input_sync(tpd
->dev
);
502 the delay advised by yida.yu
505 //mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
506 } while ( !kthread_should_stop() );
512 static void melfas_i2c_tpd_eint_interrupt_handler(void)
514 //TPD_DMESG_PRINT_INT;
517 wake_up_interruptible(&melfas_waiter
);
520 int melfas_i2c_write_bytes( struct i2c_client
*client
, U16 addr
, int len
, U32
*txbuf
)
522 u8 buffer
[MELFAS_MAX_TRANSACTION_LENGTH
]={0};
529 .addr
= ((client
->addr
&I2C_MASK_FLAG
)|(I2C_ENEXT_FLAG
)),
532 .timing
= MELFAS_I2C_MASTER_CLOCK
,
539 //TPD_DMESG("i2c_write_bytes to device %02X address %04X len %d\n", client->addr, addr, len );
545 buffer
[0] = (u8
)addr
+offset
;
547 if ( left
> MELFAS_MAX_I2C_TRANSFER_SIZE
)
549 memcpy( &buffer
[MELFAS_I2C_DEVICE_ADDRESS_LEN
], &txbuf
[offset
], MELFAS_MAX_I2C_TRANSFER_SIZE
);
550 msg
.len
= MELFAS_MAX_TRANSACTION_LENGTH
;
551 left
-= MELFAS_MAX_I2C_TRANSFER_SIZE
;
552 offset
+= MELFAS_MAX_I2C_TRANSFER_SIZE
;
556 memcpy( &buffer
[MELFAS_I2C_DEVICE_ADDRESS_LEN
], &txbuf
[offset
], left
);
557 msg
.len
= left
+ MELFAS_I2C_DEVICE_ADDRESS_LEN
;
561 //TPD_DMESG("byte left %d offset %d\n", left, offset );
563 while ( i2c_transfer( client
->adapter
, &msg
, 1 ) != 1 )
567 if ( retry
== I2C_RETRY_CNT
)
569 TPD_DMESG("I2C write 0x%X%X length=%d failed\n", buffer
[0], buffer
[1], len
);
573 //TPD_DMESG("I2C write retry %d addr 0x%X%X\n", retry, buffer[0], buffer[1]);
582 static int melfas_i2c_read(struct i2c_client
*client
, U16 addr
, U16 len
, U8
*rxbuf
)
584 u8 buffer
[MELFAS_I2C_DEVICE_ADDRESS_LEN
]={0};
589 struct i2c_msg msg
[2] =
592 .addr
= ((client
->addr
&I2C_MASK_FLAG
)|(I2C_ENEXT_FLAG
)),
595 .len
= MELFAS_I2C_DEVICE_ADDRESS_LEN
,
596 .timing
= MELFAS_I2C_MASTER_CLOCK
599 .addr
= ((client
->addr
&I2C_MASK_FLAG
)|(I2C_ENEXT_FLAG
)),
601 .timing
= MELFAS_I2C_MASTER_CLOCK
608 //TPD_DMESG("i2c_read_bytes to device %02X address %04X len %d\n", client->addr, addr, len );
612 buffer
[0] = (u8
)addr
+offset
;
614 msg
[1].buf
= &rxbuf
[offset
];
616 if ( left
> MELFAS_MAX_TRANSACTION_LENGTH
)
618 msg
[1].len
= MELFAS_MAX_TRANSACTION_LENGTH
;
619 left
-= MELFAS_MAX_TRANSACTION_LENGTH
;
620 offset
+= MELFAS_MAX_TRANSACTION_LENGTH
;
630 while ( i2c_transfer( client
->adapter
, &msg
[0], 2 ) != 2 )
634 if ( retry
== I2C_RETRY_CNT
)
636 TPD_DMESG("I2C read 0x%X length=%d failed\n", addr
+ offset
, len
);
637 TPD_DMESG("I2C read 0x%X length=%d failed\n", addr
+ offset
, len
);
646 int melfas_i2c_DMAread(struct i2c_client
*client
, U16 addr
, U16 len
, U8
*rxbuf
)
650 struct i2c_msg msg
[] = {
652 .addr
= client
->addr
& I2C_MASK_FLAG
| I2C_ENEXT_FLAG
,
658 .addr
= client
->addr
& I2C_MASK_FLAG
| I2C_ENEXT_FLAG
| I2C_DMA_FLAG
,
664 for (retry
= 0; retry
< I2C_RETRY_CNT
; retry
++) {
665 if (i2c_transfer(client
->adapter
, msg
, 2) == 2)
668 TPD_DMESG("Line %d, i2c_transfer error, retry = %d\n", __LINE__
, retry
);
670 if (retry
== I2C_RETRY_CNT
) {
671 printk(KERN_ERR
"i2c_read_block retry over %d\n",I2C_RETRY_CNT
);
676 rxbuf
[i
]=DMAbuffer_va
[i
];
680 int melfas_i2c_DMA_RW_isc(struct i2c_client
*client
,
687 struct i2c_msg msg
[] = {
689 .addr
= client
->addr
& I2C_MASK_FLAG
| I2C_ENEXT_FLAG
| I2C_DMA_FLAG
,
701 DMAbuffer_va
[i
] = txbuf
[i
];
704 for (retry
= 0; retry
< I2C_RETRY_CNT
; retry
++)
706 if (i2c_transfer(client
->adapter
, msg
, 1) == 1)
709 TPD_DMESG("Line %d, i2c_transfer error, retry = %d\n", __LINE__
, retry
);
711 if (retry
== I2C_RETRY_CNT
) {
712 printk(KERN_ERR
"i2c_read_block retry over %d\n",I2C_RETRY_CNT
);
716 else if (rw
== 2)//read
720 DMAbuffer_va
[i
] = txbuf
[i
];
723 for (retry
= 0; retry
< I2C_RETRY_CNT
; retry
++)
725 if (i2c_transfer(client
->adapter
, msg
, 1) == 1)
728 TPD_DMESG("Line %d, i2c_transfer error, retry = %d\n", __LINE__
, retry
);
730 if (retry
== I2C_RETRY_CNT
) {
731 printk(KERN_ERR
"i2c_read_block retry over %d\n",I2C_RETRY_CNT
);
735 msg
[0].flags
= I2C_M_RD
;
737 for (retry
= 0; retry
< I2C_RETRY_CNT
; retry
++)
739 if (i2c_transfer(client
->adapter
, msg
, 1) == 1)
742 TPD_DMESG("Line %d, i2c_transfer error, retry = %d\n", __LINE__
, retry
);
744 if (retry
== I2C_RETRY_CNT
) {
745 printk(KERN_ERR
"i2c_read_block retry over %d\n",I2C_RETRY_CNT
);
750 rxbuf
[i
] = DMAbuffer_va
[i
];
757 compatibility with all hardware ver for T&B
758 Turly firmware history
762 Biel firmware history
766 int melfas_check_firmware(struct i2c_client
*client
)
772 TPD_DMESG("[melfas_tpd]: i2c addr is 0x%02x",client
->addr
);
773 ret
= melfas_i2c_read(client
, 0xc3, 1, &val
[0]);
774 ret
= melfas_i2c_read(client
, 0xc4, 1, &val
[1]);
775 ret
= melfas_i2c_read(client
, 0xc0, 1, &val
[3]);
776 ret
= melfas_i2c_read(client
, 0xc2, 1, &val
[5]);
777 ret
= melfas_i2c_read(client
, 0xc1, 1, &val
[4]);
779 hardware_ver
= val
[4];
784 ret
= melfas_i2c_read(client
, 0xc5, 1, &val
[2]);
787 tp_factory_id_cmd
= val
[2];
788 TPD_DMESG("[melfas_tpd]: 0Xc3[0x%02x],0Xc4[0x%02x],0Xc5[0x%02x]",
789 val
[0], val
[1],val
[2]);
790 if (tp_factory_id_cmd
== TS_TYPE_TRULY
) {
791 if (hardware_ver
== 1) {
792 if (val
[0] < MELFAS_TURLY_H1_FW_VERSION
)
796 } else if (hardware_ver
== 2) {
797 if (val
[0] < MELFAS_TURLY_H2_FW_VERSION
)
801 } else if (hardware_ver
== 3) {
802 if (val
[0] < MELFAS_TURLY_H3_FW_VERSION
)
807 } else if (tp_factory_id_cmd
== TS_TYPE_BIEL
) {
808 if (hardware_ver
== 1) {
809 if (val
[0] < MELFAS_BIEL_H1_FW_VERSION
)
813 } else if (hardware_ver
== 2) {
814 if (val
[0] < MELFAS_BIEL_H2_FW_VERSION
)
821 TPD_DMESG("[melfas_tpd]: MMS_FW_VERSION is 0x%02x, IC version is 0x%02x\n",
822 MELFAS_TURLY_H2_FW_VERSION
,val
[0]);
827 TPD_DMESG("[melfas_tpd] %s,%d: i2c read fail[%d] \n", __FUNCTION__
, __LINE__
, ret
);
835 extern void mms_fw_update_controller(const struct firmware
*fw
,
836 struct i2c_client
*client
);
837 struct firmware fw_info_turly_h3
=
839 .size
= sizeof(MELFAS_turly_h3_binary
),
840 .data
= &MELFAS_turly_h3_binary
[0],
843 struct firmware fw_info_turly_h2
=
845 .size
= sizeof(MELFAS_turly_h2_binary
),
846 .data
= &MELFAS_turly_h2_binary
[0],
849 struct firmware fw_info_turly_h1
=
851 .size
= sizeof(MELFAS_turly_h1_binary
),
852 .data
= &MELFAS_turly_h1_binary
[0],
855 struct firmware fw_info_biel_h1
=
857 .size
= sizeof(MELFAS_biel_h1_binary
),
858 .data
= &MELFAS_biel_h1_binary
[0],
861 struct firmware fw_info_biel_h2
=
863 .size
= sizeof(MELFAS_biel_h2_binary
),
864 .data
= &MELFAS_biel_h2_binary
[0],
867 static int melfas_firmware_update(struct i2c_client
*client
)
870 ret
= melfas_check_firmware(client
);
874 //MELFAS_binary = kstrdup(fw_name,GFP_KERNEL);
875 //ret = request_firmware_nowait(THIS_MODULE, true, fw_name, &client->dev,
876 // GFP_KERNEL, client, mms_fw_update_controller);
877 if (tp_factory_id_cmd
== TS_TYPE_TRULY
) {
878 if (hardware_ver
== 1) {
879 TPD_DMESG("[melfas_tpd] MELFAS_bin_len = %x\n",
880 fw_info_turly_h1
.size
);
881 TPD_DMESG("[melfas_tpd] MELFAS_bin = %x, addr = %p\n",
882 fw_info_turly_h1
.data
[0],
883 fw_info_turly_h1
.data
);
884 mms_fw_update_controller(&fw_info_turly_h1
,client
);
885 } else if (hardware_ver
== 2) {
886 TPD_DMESG("[melfas_tpd] MELFAS_bin_len = %x\n",
887 fw_info_turly_h2
.size
);
888 TPD_DMESG("[melfas_tpd] MELFAS_bin = %x, addr = %p\n",
889 fw_info_turly_h2
.data
[0],
890 fw_info_turly_h2
.data
);
891 mms_fw_update_controller(&fw_info_turly_h2
,client
);
892 } else if (hardware_ver
== 3) {
893 TPD_DMESG("[melfas_tpd] MELFAS_bin_len = %x\n",
894 fw_info_turly_h3
.size
);
895 TPD_DMESG("[melfas_tpd] MELFAS_bin = %x, addr = %p\n",
896 fw_info_turly_h3
.data
[0],
897 fw_info_turly_h3
.data
);
898 mms_fw_update_controller(&fw_info_turly_h3
,client
);
900 } else if (tp_factory_id_cmd
== TS_TYPE_BIEL
) {
901 if (hardware_ver
== 1) {
902 TPD_DMESG("[melfas_tpd] MELFAS_bin_len = %x\n",
903 fw_info_biel_h1
.size
);
904 TPD_DMESG("[melfas_tpd] MELFAS_bin = %x, addr = %p\n",
905 fw_info_biel_h1
.data
[0],fw_info_biel_h1
.data
);
906 mms_fw_update_controller(&fw_info_biel_h1
,client
);
907 } else if (hardware_ver
== 2) {
908 TPD_DMESG("[melfas_tpd] MELFAS_bin_len = %x\n",
909 fw_info_biel_h2
.size
);
910 TPD_DMESG("[melfas_tpd] MELFAS_bin = %x, addr = %p\n",
911 fw_info_biel_h2
.data
[0],fw_info_biel_h2
.data
);
912 mms_fw_update_controller(&fw_info_biel_h2
,client
);
920 void mms_reboot(void)
922 TPD_DMESG("mms_reboot\n");
923 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
925 //init CE //GPIO_CTP_RST_PIN, is CE
926 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
927 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
928 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
929 //init EINT, mask CTP EINT //GPIO_CTP_EINT_PIN, is RSTB
930 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
931 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_EINT
);
932 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
933 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_ENABLE
);
934 mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN
, GPIO_PULL_DOWN
);
935 msleep(10); //dummy delay here
937 //turn on VDD33, LDP_VGP4
938 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_3300
, "TP");
939 msleep(20); //tce, min is 0, max is ?
942 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
943 msleep(50); //tpor, min is 1, max is 5
946 mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN
, GPIO_PULL_UP
);
947 msleep(50);//t boot_core, typicl is 20, max is 25ms
952 struct completion mms200_init_done
;
954 static int melfas_tpd_i2c_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
961 struct task_struct
*thread
= NULL
;
963 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
965 //init_completion(&mms200_init_done);
967 #if 1//def TP_SYSFS_SUPPORT
968 //TP sysfs debug support
973 if(DMAbuffer_va
== NULL
)
974 DMAbuffer_va
= (u8
*)dma_alloc_coherent(NULL
, 4096,&DMAbuffer_pa
, GFP_KERNEL
);
976 TPD_DMESG("dma_alloc_coherent va = 0x%p, pa = 0x%08x \n",DMAbuffer_va
,DMAbuffer_pa
);
979 TPD_DMESG("Allocate DMA I2C Buffer failed!\n");
986 melfas_i2c_client
= client
;
988 if (melfas_firmware_update(client
) < 0)
990 //if firmware update failed, reset IC
994 thread
= kthread_run(melfas_touch_event_handler
, 0, TPD_DEVICE
);
998 err
= PTR_ERR(thread
);
999 TPD_DMESG(TPD_DEVICE
"[melfas_tpd] failed to create kernel thread: %d\n", err
);
1001 mt_eint_set_sens(CUST_EINT_TOUCH_PANEL_NUM
, 0);
1002 //mt65xx_eint_set_sens(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_SENSITIVE);
1003 mt_eint_set_hw_debounce(CUST_EINT_TOUCH_PANEL_NUM
, CUST_EINT_TOUCH_PANEL_DEBOUNCE_CN
);
1004 //mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_EN, CUST_EINT_POLARITY_LOW, melfas_i2c_tpd_eint_interrupt_handler, 1);
1005 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, CUST_EINTF_TRIGGER_FALLING
, melfas_i2c_tpd_eint_interrupt_handler
, 1);
1006 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1010 /*try 3 times handshake*/
1013 i_ret
= melfas_i2c_read(melfas_i2c_client
, MMS_CHIP_INFO
, 1, &chip_info
);
1016 } while( (i_ret
< 0) && (try_count
<= 3) );
1017 TPD_DMESG("[melfas_tpd] communication times is %d\n", try_count
);
1020 if (chip_info
== MMS244_CHIP
)
1021 TPD_DMESG("[melfas_tpd] MMS-244 was probed successfully \n");
1023 sometimes tp do not work,so add rst operation
1026 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1029 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1032 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1034 tpd_load_status
= 1;
1039 static int melfas_tpd_i2c_remove(struct i2c_client
*client
)
1041 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1043 dma_free_coherent(NULL
, 4096, DMAbuffer_va
, DMAbuffer_pa
);
1044 DMAbuffer_va
= NULL
;
1047 input_mt_destroy_slots(tpd
->dev
);
1052 static int melfas_tpd_i2c_detect(struct i2c_client
*client
,
1053 struct i2c_board_info
*info
)
1055 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1056 strcpy(info
->type
, "mtk-tpd");
1059 static int melfas_tpd_local_init(void)
1062 TPD_DMESG("[melfas_tpd] end %s, %d\n", __FUNCTION__
, __LINE__
);
1063 if(i2c_add_driver(&melfas_tpd_i2c_driver
)!= 0) {
1064 TPD_DMESG("[melfas_tpd] unable to add i2c driver.\n");
1067 if(tpd_load_status
== 0) {
1068 TPD_DMESG("[melfas_tpd] add error touch panel driver.\n");
1069 i2c_del_driver(&melfas_tpd_i2c_driver
);
1072 #ifdef TPD_HAVE_BUTTON
1073 tpd_button_setting(TPD_KEY_COUNT
, tpd_keys_local
, tpd_keys_dim_local
);
1076 input_mt_init_slots(tpd
->dev
, TS_MAX_TOUCH
, 1);
1084 static void melfas_ts_release_all_finger(void)
1087 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1088 for (i
= 0; i
< TS_MAX_TOUCH
; i
++)
1090 input_mt_slot(tpd
->dev
, i
);
1091 input_mt_report_slot_state(tpd
->dev
, MT_TOOL_FINGER
, false);
1093 input_sync(tpd
->dev
);
1097 TP freeze workaround
1099 static void special_ts_release_all_finger(void)
1102 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1103 for(i
=0; i
< TS_MAX_TOUCH
; i
++){
1104 input_mt_slot(tpd
->dev
, i
);
1105 input_report_abs(tpd
->dev
, ABS_MT_TRACKING_ID
, -1);
1107 input_sync(tpd
->dev
);
1109 for(i
=0; i
< TS_MAX_TOUCH
; i
++){
1110 input_mt_slot(tpd
->dev
, i
);
1111 input_report_key(tpd
->dev
, BTN_TOUCH
, 1);
1112 input_report_abs(tpd
->dev
, ABS_MT_TRACKING_ID
, i
+2);
1114 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
,
1116 input_report_abs(tpd
->dev
, ABS_MT_POSITION_X
,
1118 input_report_abs(tpd
->dev
, ABS_MT_POSITION_Y
,
1121 input_sync(tpd
->dev
);
1123 for(i
=0; i
< TS_MAX_TOUCH
; i
++){
1124 input_mt_slot(tpd
->dev
, i
);
1125 input_report_abs(tpd
->dev
, ABS_MT_TRACKING_ID
, -1);
1127 input_sync(tpd
->dev
);
1129 static void melfas_ts_release_all_finger(void)
1132 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1133 for(i
=0; i
< TS_MAX_TOUCH
; i
++){
1134 input_mt_slot(tpd
->dev
, i
);
1135 input_report_abs(tpd
->dev
, ABS_MT_TRACKING_ID
, -1);
1137 input_sync(tpd
->dev
);
1142 add power on/off operation
1144 #ifdef CONFIG_HAS_EARLYSUSPEND
1145 static void melfas_tpd_early_suspend(struct early_suspend
*h
)
1147 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1148 //mutex_lock(&melfas_tp_mutex);
1150 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
1152 /*hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP");
1154 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1156 special_ts_release_all_finger();
1157 //mutex_unlock(&melfas_tp_mutex);
1160 static void melfas_tpd_late_resume(struct early_suspend
*h
)
1163 //struct melfas_ts_data *ts = i2c_get_clientdata(client);
1164 //mutex_lock(&melfas_tp_mutex);
1165 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1166 /*hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_3300, "TP");
1169 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1172 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1173 //mutex_unlock(&melfas_tp_mutex);
1177 static struct tpd_driver_t melfas_tpd_device_driver
=
1179 .tpd_device_name
= "melfas_mms200",
1180 .tpd_local_init
= melfas_tpd_local_init
,
1181 #ifdef CONFIG_HAS_EARLYSUSPEND
1182 .suspend
= melfas_tpd_early_suspend
,
1183 .resume
= melfas_tpd_late_resume
,
1185 #ifdef TPD_HAVE_BUTTON
1186 .tpd_have_button
= 1,
1188 .tpd_have_button
= 0,
1192 /* called when loaded into kernel */
1193 static int __init
melfas_tpd_driver_init(void)
1195 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1197 i2c_register_board_info(0, &melfas_i2c_tpd
, 1);
1198 if ( tpd_driver_add(&melfas_tpd_device_driver
) < 0)
1199 TPD_DMESG("[melfas_tpd] add generic driver failed\n");
1204 /* should never be called */
1205 static void __exit
melfas_tpd_driver_exit(void)
1207 TPD_DMESG("[melfas_tpd] %s\n", __func__
);
1208 tpd_driver_remove(&melfas_tpd_device_driver
);
1212 module_init(melfas_tpd_driver_init
);
1213 module_exit(melfas_tpd_driver_exit
);