1 #include <linux/interrupt.h>
4 #include <linux/sched.h>
5 #include <linux/kthread.h>
6 #include <linux/rtpm_prio.h>
7 #include <linux/wait.h>
8 #include <linux/time.h>
9 #include <linux/delay.h>
10 #include "tpd_custom_tm1896.h"
11 #include "cust_gpio_usage.h"
14 #include <mach/mt_pm_ldo.h>
15 #include <mach/mt_typedefs.h>
16 #include <mach/mt_boot.h>
19 #ifdef TPD_UPDATE_FIRMWARE
21 #include <asm/uaccess.h>
22 #include <linux/namei.h>
23 #include <linux/vmalloc.h>
25 static struct i2c_client
*g_client
= NULL
;
26 static ssize_t
update_firmware_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,char *buf
);
27 static ssize_t
update_firmware_store(struct kobject
*kobj
, struct kobj_attribute
*attr
, const char *buf
, size_t count
);
29 static int ts_firmware_file(void);
30 static int i2c_update_firmware(struct i2c_client
*client
);
32 /* we changed the mode of these files and directories
33 * the meet the requirements of Android Gingerbread CTS tests
35 static struct kobj_attribute update_firmware_attribute
= {
36 .attr
= {.name
= "update_firmware", .mode
= 0664},
37 .show
= update_firmware_show
,
38 .store
= update_firmware_store
,
40 #endif /* TPD_UPDATE_FIRMWARE */
43 #ifdef TPD_HAVE_BUTTON
44 static int tpd_keys_local
[TPD_KEY_COUNT
] = TPD_KEYS
;
45 static int tpd_keys_dim_local
[TPD_KEY_COUNT
][4] = TPD_KEYS_DIM
;
47 #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
48 static int tpd_wb_start_local
[TPD_WARP_CNT
] = TPD_WARP_START
;
49 static int tpd_wb_end_local
[TPD_WARP_CNT
] = TPD_WARP_END
;
51 #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
52 static int tpd_calmat_local
[8] = TPD_CALIBRATION_MATRIX
;
53 static int tpd_def_calmat_local
[8] = TPD_CALIBRATION_MATRIX
;
65 struct function_descriptor
{
71 #define FUNCTION_VERSION(x) ((x >> 5) & 3)
72 #define INTERRUPT_SOURCE_COUNT(x) (x & 7)
79 struct i2c_client
*client
;
80 struct work_struct work
;
81 struct point
*cur_points
;
82 struct point
*pre_points
;
89 extern struct tpd_device
*tpd
;
90 static struct tpd_data
*ts
= NULL
;
91 static struct workqueue_struct
*mtk_tpd_wq
;
92 static struct function_descriptor fd_01
;
93 static struct function_descriptor fd_34
;
97 #define FD_ADDR_MAX 0xE9
98 #define FD_ADDR_MIN 0x05
99 #define FD_BYTE_COUNT 6
102 /* Function extern */
103 static void tpd_eint_handler(void);
105 extern void mt65xx_eint_unmask(unsigned int line
);
106 extern void mt65xx_eint_mask(unsigned int line
);
107 extern void mt65xx_eint_set_hw_debounce(kal_uint8 eintno
, kal_uint32 ms
);
108 extern kal_uint32
mt65xx_eint_set_sens(kal_uint8 eintno
, kal_bool sens
);
109 extern void mt65xx_eint_registration(kal_uint8 eintno
, kal_bool Dbounce_En
, kal_bool ACT_Polarity
, void (EINT_FUNC_PTR
)(void), kal_bool auto_umask
);
111 static int __devinit
tpd_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
);
112 static int tpd_detect(struct i2c_client
*client
, int kind
, struct i2c_board_info
*info
);
113 static int __devexit
tpd_remove(struct i2c_client
*client
);
114 static void tpd_work_func(struct work_struct
*work
);
115 static int tpd_i2c_read_data(struct i2c_client
*client
, u8 command
, char *buf
, int count
);
116 static int tpd_i2c_write_byte_data(struct i2c_client
*client
, u8 command
, u8 data
);
117 static void tpd_down(int x
, int y
, int p
);
118 static void tpd_up(int x
, int y
);
119 static int tpd_power(struct i2c_client
*client
, int on
);
120 static void tpd_clear_interrupt(struct i2c_client
*client
);
123 static const struct i2c_device_id tpd_id
[] = {{TPD_DEVICE
,0},{}};
124 unsigned short force
[] = {0,0xE0,I2C_CLIENT_END
,I2C_CLIENT_END
};
125 static const unsigned short * const forces
[] = { force
, NULL
};
126 //static struct i2c_client_address_data addr_data = { .forces = forces, };
127 static struct i2c_board_info __initdata i2c_tpd
={ I2C_BOARD_INFO("mtk-tpd", (0xE0>>1))};
130 static struct i2c_driver tpd_i2c_driver
= {
133 .owner
= THIS_MODULE
,
136 .remove
= __devexit_p(tpd_remove
),
138 .detect
= tpd_detect
,
139 .address_list
= (const unsigned short*) forces
,
140 //.address_data = &addr_data,
143 static int tpd_i2c_read_data(struct i2c_client
*client
, u8 command
, char *buf
, int count
)
146 u16 old_flag
= client
->addr
;
148 client
->addr
= client
->addr
& I2C_MASK_FLAG
| I2C_WR_FLAG
| I2C_RS_FLAG
;
151 ret
= i2c_master_send(client
, buf
, (count
<< 8 | 1));
153 client
->addr
= old_flag
;
156 static int tpd_i2c_write_byte_data(struct i2c_client
*client
, u8 command
, u8 data
)
159 u8 buf
[2] = {command
, data
};
161 ret
= i2c_master_send(client
, buf
, 2);
165 static void tpd_down(int x
, int y
, int p
)
167 input_report_abs(tpd
->dev
, ABS_PRESSURE
, p
);
168 input_report_key(tpd
->dev
, BTN_TOUCH
, 1);
169 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
, 1);
170 input_report_abs(tpd
->dev
, ABS_MT_POSITION_X
, x
);
171 input_report_abs(tpd
->dev
, ABS_MT_POSITION_Y
, y
);
172 input_mt_sync(tpd
->dev
);
174 #ifdef TPD_HAVE_BUTTON
175 if (NORMAL_BOOT
!= boot_mode
)
181 //printk("D[%4d %4d %4d]\n", x, y, p);
182 TPD_DOWN_DEBUG_TRACK(x
,y
);
185 static void tpd_up(int x
, int y
)
187 input_report_abs(tpd
->dev
, ABS_PRESSURE
, 0);
188 input_report_key(tpd
->dev
, BTN_TOUCH
, 0);
189 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
, 0);
190 input_report_abs(tpd
->dev
, ABS_MT_POSITION_X
, x
);
191 input_report_abs(tpd
->dev
, ABS_MT_POSITION_Y
, y
);
192 input_mt_sync(tpd
->dev
);
194 #ifdef TPD_HAVE_BUTTON
195 if (NORMAL_BOOT
!= boot_mode
)
201 //printk("U[%4d %4d %4d]\n", x, y, 0);
202 TPD_UP_DEBUG_TRACK(x
,y
);
206 static void tpd_work_func(struct work_struct
*work
)
209 u8 finger_status
= 0;
210 u8 finger_status_reg
= 0;
211 u8 loop
= ts
->data_length
/ 8;
212 u8 fsr_len
= (ts
->points_supported
+ 3) / 4;
213 u8
*pdata
= ts
->data
;
214 u8
*finger_reg
= NULL
;
215 struct point
*ppt
= NULL
;
217 tpd_clear_interrupt(ts
->client
);
219 for (i
= 0; i
< loop
; i
++) {
220 tpd_i2c_read_data(ts
->client
, ts
->data_base
+ 8*i
, ts
->data
+ 8*i
, 8);
223 if (ts
->data_length
% 8) {
224 tpd_i2c_read_data(ts
->client
, ts
->data_base
+ 8*i
, ts
->data
+ 8*i
, ts
->data_length
% 8);
227 for (i
= 0; i
< ts
->points_supported
; i
++) {
229 finger_status_reg
= pdata
[i
/ 4];
231 finger_status
= (finger_status_reg
>> ((i
% 4) * 2)) & 3;
233 ppt
= &ts
->cur_points
[i
];
234 ppt
->status
= finger_status
;
237 finger_reg
= &pdata
[fsr_len
+ 5 * i
];
239 ppt
->raw_x
= ppt
->x
= (finger_reg
[0] << 4) | (finger_reg
[2] & 0x0F);
240 ppt
->raw_y
= ppt
->y
= (finger_reg
[1] << 4) | ((finger_reg
[2] >> 4) & 0x0F);
241 ppt
->z
= finger_reg
[4];
243 #ifdef TPD_HAVE_CALIBRATION
244 tpd_calibrate(&ppt
->x
, &ppt
->y
);
247 //printk("finger [%d] status [%d] ", i, finger_status);
248 tpd_down(ppt
->x
, ppt
->y
, ppt
->z
);
249 TPD_EM_PRINT(ppt
->raw_x
, ppt
->raw_y
, ppt
->x
, ppt
->y
, ppt
->z
, 1);
252 ppt
= &ts
->pre_points
[i
];
254 //printk("finger [%d] status [%d] ", i, ppt->status);
255 tpd_up(ppt
->x
, ppt
->y
);
256 TPD_EM_PRINT(ppt
->raw_x
, ppt
->raw_y
, ppt
->x
, ppt
->y
, ppt
->z
, 0);
260 input_sync(tpd
->dev
);
262 ppt
= ts
->pre_points
;
263 ts
->pre_points
= ts
->cur_points
;
264 ts
->cur_points
= ppt
;
267 static void tpd_eint_handler(void)
269 TPD_DEBUG("TPD interrupt has been triggered\n");
270 queue_work(mtk_tpd_wq
, &ts
->work
);
273 static int tpd_power(struct i2c_client
*client
, int on
)
281 ret
= tpd_i2c_write_byte_data(client
, fd_01
.controlBase
, 0x80);/*sensor on*/
284 TPD_DMESG("Error sensor can not wake up\n");
288 ret
= tpd_i2c_write_byte_data(client
, fd_01
.commandBase
, 0x01);/*touchscreen reset*/
291 TPD_DMESG("Error chip can not reset\n");
295 msleep(200); /* wait for device reset; */
299 ret
= tpd_i2c_write_byte_data(client
, fd_01
.controlBase
, 0x81); /* set touchscreen to deep sleep mode*/
302 TPD_DMESG("Error touch can not enter very-low power state\n");
310 static int tpd_detect (struct i2c_client
*client
, int kind
, struct i2c_board_info
*info
)
312 strcpy(info
->type
, TPD_DEVICE
);
316 static int __devexit
tpd_remove(struct i2c_client
*client
)
318 TPD_DEBUG("TPD removed\n");
322 static void tpd_clear_interrupt(struct i2c_client
*client
)
325 for( i
= 5; i
>0 ; i
--)
327 if(i2c_smbus_read_byte_data(ts
->client
, 0x14) >= 0)
334 static int tpd_rmi4_read_pdt(struct tpd_data
*ts
)
340 struct function_descriptor fd
;
342 for (fd_reg
= FD_ADDR_MAX
; fd_reg
>= FD_ADDR_MIN
; fd_reg
-= FD_BYTE_COUNT
)
344 ret
= tpd_i2c_read_data(ts
->client
, fd_reg
, &fd
, FD_BYTE_COUNT
);
346 TPD_DMESG("Error I2C read failed querying RMI4 $%02X capabilities\n", ts
->client
->addr
);
349 if (!fd
.functionNumber
)
353 TPD_DMESG("Error Read %d functions from PDT\n", fd
.functionNumber
);
359 switch (fd
.functionNumber
) {
361 fd_34
.queryBase
= fd
.queryBase
;
362 fd_34
.dataBase
= fd
.dataBase
;
365 case 0x01: /* Interrupt */
366 fd_01
.queryBase
= fd
.queryBase
;
367 fd_01
.dataBase
= fd
.dataBase
;
368 fd_01
.commandBase
= fd
.commandBase
;
369 fd_01
.controlBase
= fd
.controlBase
;
373 ts
->data_base
= fd
.dataBase
;
374 ret
= tpd_i2c_read_data(ts
->client
, fd
.queryBase
+1, &query
, 1);
376 TPD_DMESG("Error reading F11 query registers\n");
379 ts
->points_supported
= (query
& 7) + 1;
380 if (ts
->points_supported
== 6)
381 ts
->points_supported
= 10;
383 ts
->pre_points
= kzalloc(ts
->points_supported
* sizeof(struct point
), GFP_KERNEL
);
384 if (ts
->pre_points
== NULL
) {
385 TPD_DMESG("Error zalloc failed!\n");
390 ts
->cur_points
= kzalloc(ts
->points_supported
* sizeof(struct point
), GFP_KERNEL
);
391 if (ts
->cur_points
== NULL
) {
392 TPD_DMESG("Error zalloc failed!\n");
397 ts
->data_length
= ((ts
->points_supported
+ 3) / 4) + 5 * ts
->points_supported
;
398 ts
->data
= kzalloc(ts
->data_length
, GFP_KERNEL
);
399 if (ts
->data
== NULL
) {
400 TPD_DMESG("Error zalloc failed!\n");
405 TPD_DEBUG("%d fingers\n", ts
->points_supported
);
408 case 0x30: /* GPIO */
411 ts->f30.data_offset = fd.dataBase;
412 ts->f30.interrupt_offset = interruptCount / 8;
413 ts->f30.interrupt_mask = ((1 < INTERRUPT_SOURCE_COUNT(fd.intSrc)) - 1) << (interruptCount % 8);
415 ret = i2c_transfer(ts->client->adapter, query_i2c_msg, 2);
417 printk(KERN_ERR "Error reading F30 query registers\n");
420 ts->f30.points_supported = query[1] & 0x1F;
421 ts->f30.data_length = data_length = (ts->f30.points_supported + 7) / 8;*/
433 static int tpd_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
437 //char product_id[6] = {0};
439 #ifdef TPD_POWER_SOURCE_CUSTOM
440 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
442 hwPowerOn(MT65XX_POWER_LDO_VGP2
, VOL_2800
, "TP");
444 #ifdef TPD_POWER_SOURCE_1800
445 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
449 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
450 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
451 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
453 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
454 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
455 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
458 ts
= kzalloc(sizeof(*ts
), GFP_KERNEL
);
461 TPD_DMESG("Error zalloc failed!\n");
463 goto err_alloc_data_failed
;
467 i2c_set_clientdata(client
, ts
);
469 ret
= tpd_rmi4_read_pdt(ts
);
472 TPD_DMESG("Empty PDT\n");
474 TPD_DMESG("Error identifying device (%d)\n", ret
);
476 goto err_pdt_read_failed
;
479 ret
= tpd_power(client
, 1);
482 TPD_DMESG("Error poweron failed\n");
483 goto err_power_on_failed
;
486 tpd_clear_interrupt(client
);
488 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
))
490 TPD_DMESG("Error need I2C_FUNC_I2C\n");
492 goto err_check_functionality_failed
;
495 mtk_tpd_wq
= create_singlethread_workqueue("mtk_tpd_wq");
498 TPD_DMESG("Error Could not create work queue mtk_tpd_wq: no memory");
500 goto error_wq_creat_failed
;
503 INIT_WORK(&ts
->work
, tpd_work_func
);
505 #ifdef TPD_UPDATE_FIRMWARE
506 for (i
= 0 ; i
< 3; i
++)
508 ret
= ts_firmware_file();
514 #endif /* TPD_UPDATE_FIRMWARE */
516 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_EINT
);
517 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
518 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_ENABLE
);
519 mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN
, GPIO_PULL_UP
);
521 //mt65xx_eint_set_sens(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_SENSITIVE);
522 //mt65xx_eint_set_hw_debounce(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_CN);
523 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, CUST_EINT_TOUCH_PANEL_TYPE
, tpd_eint_handler
, 1);
524 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
528 TPD_DMESG("%s: Touch Panel Device Probe %s\n", __func__
, (ret
< 0) ? "FAIL" : "PASS");
533 err_check_functionality_failed
:
535 error_wq_creat_failed
:
541 err_alloc_data_failed
:
546 #ifdef TPD_UPDATE_FIRMWARE
548 unsigned char m_QueryBase
;
549 unsigned char m_CommandBase
;
550 unsigned char m_ControlBase
;
551 unsigned char m_DataBase
;
552 unsigned char m_IntSourceCount
;
556 static int RMI4_read_PDT(struct i2c_client
*client
)
559 struct RMI4_FDT temp_buf
;
560 struct RMI4_FDT m_PdtF34Flash
;
561 struct RMI4_FDT m_PdtF01Common
;
562 struct i2c_msg msg
[2];
563 unsigned short start_addr
;
566 memset(&m_PdtF34Flash
,0,sizeof(struct RMI4_FDT
));
567 memset(&m_PdtF01Common
,0,sizeof(struct RMI4_FDT
));
569 for(start_addr
= 0xe9; start_addr
> 10; start_addr
-= sizeof(struct RMI4_FDT
))
571 msg
[0].addr
= client
->addr
;
574 msg
[0].buf
= (unsigned char *)&start_addr
;
575 msg
[1].addr
= client
->addr
;
576 msg
[1].flags
= I2C_M_RD
;
577 msg
[1].len
= sizeof(struct RMI4_FDT
);
578 msg
[1].buf
= (unsigned char *)&temp_buf
;
580 if(i2c_transfer(client
->adapter
, msg
, 2) < 0)
582 printk("%s:%d: read RIM4 PDT error!\n",__FUNCTION__
,__LINE__
);
586 if(temp_buf
.m_ID
== 0x34)
588 memcpy(&m_PdtF34Flash
,&temp_buf
,sizeof(struct RMI4_FDT
));
590 else if(temp_buf
.m_ID
== 0x01)
592 memcpy(&m_PdtF01Common
,&temp_buf
,sizeof(struct RMI4_FDT
));
594 else if (temp_buf
.m_ID
== 0) //end of PDT
600 if((m_PdtF01Common
.m_CommandBase
!= fd_01
.commandBase
) || (m_PdtF34Flash
.m_QueryBase
!= fd_34
.queryBase
))
602 printk("%s:%d: RIM4 PDT has changed!!!\n",__FUNCTION__
,__LINE__
);
604 ret
= tpd_rmi4_read_pdt(ts
);
607 printk("read pdt error:!\n");
618 //to be improved .......
619 int RMI4_wait_attn_hw(struct i2c_client
* client
,int udleay
)
626 ret
= i2c_smbus_read_byte_data(client
,fd_34
.dataBase
+18);//read Flash Control
627 // Clear the attention assertion by reading the interrupt status register
628 i2c_smbus_read_byte_data(client
,fd_01
.dataBase
+1);//read the irq Interrupt Status
629 }while(loop_count
++ < 0x10 && (ret
!= 0x80));
631 if(loop_count
>= 0x10)
633 TPD_DEBUG("RMI4 wait attn timeout:ret=0x%x\n",ret
);
639 int RMI4_disable_program_hw(struct i2c_client
*client
)
642 unsigned int loop_count
=0;
644 printk("RMI4 disable program...\n");
645 // Issue a reset command
646 i2c_smbus_write_byte_data(client
,fd_01
.commandBase
,0x01);
648 // Wait for ATTN to be asserted to see if device is in idle state
649 RMI4_wait_attn_hw(client
,20);
651 // Read F01 Status flash prog, ensure the 6th bit is '0'
653 cdata
= i2c_smbus_read_byte_data(client
,fd_01
.dataBase
);
655 } while(((cdata
& 0x40) != 0) && (loop_count
++ < 10));
657 //Rescan the Page Description Table
658 return RMI4_read_PDT(client
);
661 static int RMI4_enable_program(struct i2c_client
*client
)
663 unsigned short bootloader_id
= 0 ;
665 printk("RMI4 enable program...\n");
666 // Read and write bootload ID
667 bootloader_id
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
);
668 i2c_smbus_write_word_data(client
,fd_34
.dataBase
+2,bootloader_id
);//write Block Data 0
670 // Issue Enable flash command
671 if(i2c_smbus_write_byte_data(client
, fd_34
.dataBase
+18, 0x0F) < 0) //write Flash Control
673 TPD_DEBUG("RMI enter flash mode error\n");
676 ret
= RMI4_wait_attn_hw(client
,12);
678 //Rescan the Page Description Table
679 RMI4_read_PDT(client
);
683 static unsigned long ExtractLongFromHeader(const unsigned char* SynaImage
)
685 return((unsigned long)SynaImage
[0] +
686 (unsigned long)SynaImage
[1]*0x100 +
687 (unsigned long)SynaImage
[2]*0x10000 +
688 (unsigned long)SynaImage
[3]*0x1000000);
691 static int RMI4_check_firmware(struct i2c_client
*client
,const unsigned char *pgm_data
)
693 unsigned long checkSumCode
;
694 unsigned long m_firmwareImgSize
;
695 unsigned long m_configImgSize
;
696 unsigned short m_bootloadImgID
;
697 unsigned short bootloader_id
;
698 const unsigned char *SynaFirmware
;
699 unsigned char m_firmwareImgVersion
;
700 unsigned short UI_block_count
;
701 unsigned short CONF_block_count
;
702 unsigned short fw_block_size
;
704 SynaFirmware
= pgm_data
;
705 checkSumCode
= ExtractLongFromHeader(&(SynaFirmware
[0]));
706 m_bootloadImgID
= (unsigned int)SynaFirmware
[4] + (unsigned int)SynaFirmware
[5]*0x100;
707 m_firmwareImgVersion
= SynaFirmware
[7];
708 m_firmwareImgSize
= ExtractLongFromHeader(&(SynaFirmware
[8]));
709 m_configImgSize
= ExtractLongFromHeader(&(SynaFirmware
[12]));
711 UI_block_count
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
+5);//read Firmware Block Count 0
712 fw_block_size
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
+3);//read Block Size 0
713 CONF_block_count
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
+7);//read Configuration Block Count 0
714 bootloader_id
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
);
716 return (m_firmwareImgVersion
!= 0 || bootloader_id
== m_bootloadImgID
) ? 0 : -1;
721 static int RMI4_write_image(struct i2c_client
*client
,unsigned char type_cmd
,const unsigned char *pgm_data
)
723 unsigned short block_size
;
724 unsigned short img_blocks
;
725 unsigned short block_index
;
726 const unsigned char * p_data
;
729 block_size
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
+3);//read Block Size 0
734 img_blocks
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
+5); //read UI Firmware
737 img_blocks
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
+7); //read Configuration Block Count 0
740 TPD_DEBUG("image type error\n");
746 for(block_index
= 0; block_index
< img_blocks
; ++block_index
)
749 // Write Block Number
750 if(i2c_smbus_write_word_data(client
, fd_34
.dataBase
,block_index
) < 0)
752 TPD_DEBUG("write block number error\n");
756 for(i
=0;i
<block_size
;i
++)
758 if(i2c_smbus_write_byte_data(client
, fd_34
.dataBase
+2+i
, *(p_data
+i
)) < 0) //write Block Data
760 TPD_DEBUG("RMI4_write_image: block %d data 0x%x error\n",block_index
,*p_data
);
766 p_data
+= block_size
;
768 // Issue Write Firmware or configuration Block command
769 if(i2c_smbus_write_word_data(client
, fd_34
.dataBase
+18, type_cmd
) < 0) //write Flash Control
771 TPD_DEBUG("issue write command error\n");
775 // Wait ATTN. Read Flash Command register and check error
776 if(RMI4_wait_attn_hw(client
,5) != 0)
788 static int RMI4_program_configuration(struct i2c_client
*client
,const unsigned char *pgm_data
)
791 unsigned short block_size
;
792 unsigned short ui_blocks
;
794 printk("\nRMI4 program Config firmware...\n");
795 block_size
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
+3);//read Block Size 0
796 ui_blocks
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
+5); //read Firmware Block Count 0
798 if(RMI4_write_image(client
, 0x06,pgm_data
+ui_blocks
*block_size
) < 0)
800 TPD_DEBUG("write configure image error\n");
804 ret
= i2c_smbus_read_byte_data(client
,fd_34
.dataBase
+18); //read Flash Control
805 return ((ret
& 0xF0) == 0x80 ? 0 : ret
);
808 static int RMI4_program_firmware(struct i2c_client
*client
,const unsigned char *pgm_data
)
811 unsigned short bootloader_id
;
813 printk("RMI4 program UI firmware...\n");
815 //read and write back bootloader ID
816 bootloader_id
= i2c_smbus_read_word_data(client
,fd_34
.queryBase
);
817 i2c_smbus_write_word_data(client
,fd_34
.dataBase
+2, bootloader_id
); //write Block Data0
819 //issue erase commander
820 if(i2c_smbus_write_byte_data(client
, fd_34
.dataBase
+18, 0x03) < 0) //write Flash Control
822 TPD_DEBUG("RMI4_program_firmware error, erase firmware error \n");
825 RMI4_wait_attn_hw(client
,300);
828 if((ret
= i2c_smbus_read_byte_data(client
,fd_34
.dataBase
+18)) != 0x80) //check Flash Control
834 if( RMI4_write_image(client
,0x02,pgm_data
) <0 )
836 TPD_DEBUG("write UI firmware error!\n");
840 ret
= i2c_smbus_read_byte_data(client
,fd_34
.dataBase
+18); //read Flash Control
841 return ((ret
& 0xF0) == 0x80 ? 0 : ret
);
844 static int synaptics_download(struct i2c_client
*client
,const unsigned char *pgm_data
)
848 ret
= RMI4_read_PDT(client
);
851 printk("RMI page func check error\n");
855 ret
= RMI4_enable_program(client
);
858 printk("%s:%d:RMI enable program error,return...\n",__FUNCTION__
,__LINE__
);
862 ret
= RMI4_check_firmware(client
,pgm_data
);
865 printk("%s:%d:RMI check firmware error,return...\n",__FUNCTION__
,__LINE__
);
869 ret
= RMI4_program_firmware(client
, pgm_data
+ 0x100);
872 printk("%s:%d:RMI program firmware error,return...",__FUNCTION__
,__LINE__
);
876 RMI4_program_configuration(client
, pgm_data
+ 0x100);
877 return RMI4_disable_program_hw(client
);
880 RMI4_disable_program_hw(client
);
881 printk("%s:%d:error,return ....",__FUNCTION__
,__LINE__
);
886 static int i2c_update_firmware(struct i2c_client
*client
)
890 struct inode
*inode
= NULL
;
894 const char filename
[]="/sdcard/update/synaptics.img";
899 filp
= filp_open(filename
, O_RDONLY
, S_IRUSR
);
902 printk("%s: file %s filp_open error\n", __FUNCTION__
,filename
);
909 printk("%s: File Operation Method Error\n", __FUNCTION__
);
910 filp_close(filp
, NULL
);
915 inode
= filp
->f_path
.dentry
->d_inode
;
918 printk("%s: Get inode from filp failed\n", __FUNCTION__
);
919 filp_close(filp
, NULL
);
925 length
= i_size_read(inode
->i_mapping
->host
);
926 if (!( length
> 0 && length
< 62*1024 ))
928 printk("file size error\n");
929 filp_close(filp
, NULL
);
934 /* allocation buff size */
935 buf
= vmalloc(length
+(length
%2)); /* buf size if even */
938 printk("alloctation memory failed\n");
939 filp_close(filp
, NULL
);
945 if (filp
->f_op
->read(filp
, buf
, length
, &filp
->f_pos
) != length
)
947 printk("%s: file read error\n", __FUNCTION__
);
948 filp_close(filp
, NULL
);
954 ret
= synaptics_download(client
,buf
);
956 filp_close(filp
, NULL
);
962 static int ts_firmware_file(void)
965 struct kobject
*kobject_ts
;
966 kobject_ts
= kobject_create_and_add("touch_screen", NULL
);
969 printk("create kobjetct error!\n");
973 ret
= sysfs_create_file(kobject_ts
, &update_firmware_attribute
.attr
);
975 kobject_put(kobject_ts
);
976 printk("create file error\n");
983 * The "update_firmware" file where a static variable is read from and written to.
985 static ssize_t
update_firmware_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,char *buf
)
990 static ssize_t
update_firmware_store(struct kobject
*kobj
, struct kobj_attribute
*attr
, const char *buf
, size_t count
)
994 printk("#################update_firmware_store######################\n");
996 if ( (buf
[0] == '2')&&(buf
[1] == '\0') )
998 /* driver detect its device */
999 ret
= i2c_smbus_read_byte_data(g_client
, fd_01
.queryBase
);
1000 printk("The if of synaptics device is : %d\n",ret
);
1002 disable_irq(g_client
->irq
);
1005 ret
= i2c_update_firmware(g_client
);
1006 enable_irq(g_client
->irq
);
1010 printk("Update firmware failed!\n");
1015 printk("Update firmware success!\n");
1016 arm_pm_restart(0,&ret
);
1025 static int tpd_local_init(void)
1027 TPD_DMESG("TM1896 I2C Touchscreen Driver (Built %s @ %s)\n", __DATE__
, __TIME__
);
1029 if(i2c_add_driver(&tpd_i2c_driver
)!=0)
1031 TPD_DMESG("Error unable to add i2c driver.\n");
1035 #ifdef TPD_HAVE_BUTTON
1036 tpd_button_setting(TPD_KEY_COUNT
, tpd_keys_local
, tpd_keys_dim_local
);// initialize tpd button data
1039 #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
1041 memcpy(tpd_wb_start
, tpd_wb_start_local
, TPD_WARP_CNT
*4);
1042 memcpy(tpd_wb_end
, tpd_wb_start_local
, TPD_WARP_CNT
*4);
1045 #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
1046 memcpy(tpd_calmat
, tpd_def_calmat_local
, 8*4);
1047 memcpy(tpd_def_calmat
, tpd_def_calmat_local
, 8*4);
1050 boot_mode
= get_boot_mode();
1051 if (boot_mode
== 3) boot_mode
= NORMAL_BOOT
;
1053 TPD_DMESG("end %s, %d\n", __FUNCTION__
, __LINE__
);
1058 static int tpd_resume(struct i2c_client
*client
)
1060 TPD_DEBUG("TPD wake up\n");
1063 #ifdef TPD_CLOSE_POWER_IN_SLEEP
1064 hwPowerOn(TPD_POWER_SOURCE,VOL_3300,"TP");
1067 mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO);
1068 mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT);
1069 mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ONE);
1073 mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
1074 mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
1075 mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ZERO);
1077 mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
1078 mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
1079 mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE);
1082 tpd_power(ts
->client
, 1);
1083 tpd_clear_interrupt(ts
->client
);
1085 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1090 static int tpd_suspend(struct i2c_client
*client
, pm_message_t message
)
1092 TPD_DEBUG("TPD enter sleep\n");
1093 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
1095 tpd_power(ts
->client
, 0);
1098 #ifdef TPD_CLOSE_POWER_IN_SLEEP
1099 hwPowerDown(TPD_POWER_SOURCE,"TP");
1101 i2c_smbus_write_i2c_block_data(i2c_client, 0xA5, 1, &data); //TP enter sleep mode
1103 mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO);
1104 mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT);
1105 mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ZERO);
1115 static struct tpd_driver_t tpd_device_driver
= {
1116 .tpd_device_name
= "tm1896",
1117 .tpd_local_init
= tpd_local_init
,
1118 .suspend
= tpd_suspend
,
1119 .resume
= tpd_resume
,
1120 #ifdef TPD_HAVE_BUTTON
1121 .tpd_have_button
= 1,
1123 .tpd_have_button
= 0,
1127 static int __init
tpd_driver_init(void)
1129 TPD_DMESG("TM1896 touch panel driver init\n");
1130 i2c_register_board_info(0, &i2c_tpd
, 1);
1131 if(tpd_driver_add(&tpd_device_driver
) < 0)
1132 TPD_DMESG("Error Add TM1896 driver failed\n");
1136 static void __exit
tpd_driver_exit(void)
1138 TPD_DMESG("TM1896 touch panel driver exit\n");
1139 tpd_driver_remove(&tpd_device_driver
);
1142 module_init(tpd_driver_init
);
1143 module_exit(tpd_driver_exit
);
1145 MODULE_DESCRIPTION("Mediatek TM1896 Driver");