static ssize_t ft5x0x_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
    int ret = 0;
    struct capts *ts = (struct capts *)dev_get_drvdata(dev);

    if (!strcmp(attr->attr.name, "ft5x0xPrintFlag")) {
        printk("buf[0]=%d, buf[1]=%d\n", buf[0], buf[1]);
        if (buf[0] == '0') ft5x0x_printk_enable_flag = 0;
        if (buf[0] == '1') ft5x0x_printk_enable_flag = 1;
        if (buf[0] == '2') {
            ft5x0x_printk_enable_flag=2;
            if(focaltechPdata2->power) {
                focaltechPdata2->power(0);
                msleep(50);
                focaltechPdata2->power(1);
                msleep(200);
            }
        }
        if (buf[0] == '3') {
            u8 data;
            ft5x0x_write_reg(0xa5, 0x03);
            printk("set reg[0xa5] = 0x03\n");
            msleep(20);
            ft5x0x_read_reg(0xa5, &data);
            printk("read back: reg[0xa5] = %d\n", data);
        }
    }
    return count;
}
Exemplo n.º 2
0
void ft5x0x_software_reset(struct touch_pdata *pdata)
{
	u8 data;
	ft5x0x_write_reg(0xa5, 0x03);
	printk("set reg[0xa5] = 0x03\n");
	msleep(20);
	ft5x0x_read_reg(0xa5, &data);
	printk("read back: reg[0xa5] = %d\n", data);
}
static void Ac_Detect_In_Touch_Driver(void)
{
    unsigned char ver;
    int ac_detect_flag_temp=0;
    ac_detect_flag_temp=focaltechPdata2->Ac_is_connect();
    ac_detect_flag_current=ac_detect_flag_temp;
    if(ac_detect_flag_current!=ac_detect_flag_old)
    {
        if(1==focaltechPdata2->Ac_is_connect())
            ft5x0x_write_reg(0xb2,0x1);
        else
            ft5x0x_write_reg(0xb2,0x0);
        ac_detect_flag_old=ac_detect_flag_current;
    }
    if(1==ft5x0x_printk_enable_flag)
    {
        ft5x0x_read_reg(0xb2, &ver);
        printk("reg 0xb2=%d\n",ver);
    }
}
static ssize_t ft5x0x_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	int ret = 0, i = 0, send_len = 0;
	static size_t length;	
	E_UPGRADE_ERR_TYPE err = ERR_REV_FILE_FAIL;
	static FTS_BYTE  *to_buf = NULL, *pre_to_buf = NULL, *free_to_buf = NULL;
	
	if (!strcmp(attr->attr.name, "ft5x0xPrintFlag")) {
		printk("buf[0]=%d, buf[1]=%d\n", buf[0], buf[1]);
		if (buf[0] == '0') ft5x0x_printk_enable_flag = 0;
		if (buf[0] == '1') ft5x0x_printk_enable_flag = 1;
		if (buf[0] == '2') {
			ft5x0x_printk_enable_flag=2;
			if(focaltechPdata2->power){
				focaltechPdata2->power(0);
				msleep(50);
				focaltechPdata2->power(1);
				msleep(200);
			}
		}
		if (buf[0] == '3') {
			u8 data;
			ft5x0x_write_reg(0xa5, 0x03);
			printk("set reg[0xa5] = 0x03\n");
			msleep(20);
			ft5x0x_read_reg(0xa5, &data);
			printk("read back: reg[0xa5] = %d\n", data);
    }
  }
	else if (!strcmp(attr->attr.name, "effect")) {    
       printk("buf[0]=%d, buf[1]=%d\n", buf[0], buf[1]);
  }
  else if (!strcmp(attr->attr.name, "upgrade")) {
	     if (length == 0) {        
	       if (free_to_buf == NULL) free_to_buf = (FTS_BYTE *)kmalloc((128*1024-20)*sizeof(FTS_BYTE), GFP_KERNEL);
         printk("start free_to_buf = 0x%x.\n", free_to_buf); 
         if (free_to_buf == NULL) {
           printk("Insufficient memory in upgrade!\n");
           length = 0;
           upgrade_result = ERR_REV_FILE_FAIL;
           return -ERR_REV_FILE_FAIL;
         }         
         pre_to_buf = free_to_buf;  
         to_buf = pre_to_buf;
         upgrade_result = ERR_IN_UPGRADE;  
	     }
	     memcpy(to_buf, buf, count);
	     
	     to_buf += count;
	     length += count;
	    
	   //  printk("upgrade data count = %d.\n", count); 
       //  printk("upgrade data length = %d.\n", length);  
	    
	     if (length > (128*1024-25)) {
	       upgrade_result = ERR_REV_FILE_FAIL;
	       printk("upgrade_result = %d.\n", ERR_REV_FILE_FAIL);
	       printk("end free_to_buf = 0x%x.\n", free_to_buf); 
	       length = 0;
	       if (free_to_buf != NULL) {
	         kfree(free_to_buf);
	         free_to_buf = NULL;
	       }	       
	       return ERR_REV_FILE_FAIL;
	     }     
      
	     if ((to_buf != NULL) && (*(to_buf-1)=='d') && (*(to_buf-2)=='n') && (*(to_buf-3)=='e')) {
	         for (i=0; i<length-3;) {
              if ((*pre_to_buf=='0') && (*(pre_to_buf+1)=='x')) {     
      	        if ((*(pre_to_buf+3)==',') && (*(pre_to_buf+4)==' ')) free_to_buf[send_len++] = char_to_hex('0', *(pre_to_buf+2));    
      	        else free_to_buf[send_len++] = char_to_hex(*(pre_to_buf+2), *(pre_to_buf+3));        
	    			    pre_to_buf += 5; 
      	        i += 5;
	    			  }
	    			  else {
	    			    pre_to_buf++;
	    			  	i++;
	    			  }	    			  		    				    			     			        	   
	    	   }
	    	  
	    	   for (i=0; i<10; i++) {
	    	     printk("free_to_buf[%d] = 0x%x.\n", i, free_to_buf[i]); 
	    	   }	    	  
	    	   for (i=send_len-1; i>=send_len-10; i--) {
	    	  	 printk("free_to_buf[%d] = 0x%x.\n", i, free_to_buf[i]); 
	    	   }
	    	 
	    	   for (i=0; i<5; i++) {
	    	     err = fts_ctpm_fw_upgrade(free_to_buf, send_len);
	    	     if (err == 0) break;
	       	 }
	    	   upgrade_result = err;
	    	   printk("upgrade status is %d.\n", err); 
	    	   printk("upgrade data send_len = %d.\n", send_len); 
	    	   printk("end free_to_buf = 0x%x.\n", free_to_buf); 
	    	   if (free_to_buf != NULL) {
	    	     kfree(free_to_buf);
	    	     free_to_buf = NULL;
	    	   }
	    	   length = 0;	    	      
	     }
	    // #endif                                
   } 
	return count; 
}
Exemplo n.º 5
0
static int ft5x0x_chip_init(struct i2c_client * client)
{
	int ret = 0;
	int w_value;
	char r_value;
	int err = -1;
	int reg;
	int i = 0, flag = 1;
	struct ft5x0x_data *ft5x0x_ts = i2c_get_clientdata(client);

	gpio_free(ft5x0x_ts->reset_gpio);
	err = gpio_request(ft5x0x_ts->reset_gpio, "ft5x0x rst");
	if (err) {
		DBG( "failed to request ft5x0x reset GPIO%d\n", ft5x0x_ts->reset_gpio);
		goto exit_alloc_gpio_rst_failed;
	}
	
#if defined (TOUCH_POWER_PIN)
#if defined (TOUCH_POWER_MUX_NAME)
    rk29_mux_api_set(TOUCH_POWER_MUX_NAME, TOUCH_POWER_MUX_MODE_GPIO);
#endif
	gpio_free(ft5x0x_ts->touch_en_gpio);
	err = gpio_request(ft5x0x_ts->touch_en_gpio, "ft5x0x power enable");
	if (err) {
		DBG( "failed to request ft5x0x power enable GPIO%d\n", ft5x0x_ts->touch_en_gpio);
		goto exit_alloc_gpio_power_failed;
	}
#endif

	//ft5x0x_chip_reset(ft5x0x_ts);
    gpio_direction_output(ft5x0x_ts->reset_gpio, 1);
    gpio_set_value(ft5x0x_ts->reset_gpio, 1);
	ft5x0x_power_en(ft5x0x_ts, 0);
	mdelay(50);
	ft5x0x_power_en(ft5x0x_ts, 1);
	mdelay(500);
    ft_cmd_write(0x07,0x00,0x00,0x00,1);
	mdelay(10);

	ret = ft5x0x_read_reg(client, 0xA8);//read touchpad ID for adjust touchkey place
	if (ret < 0) {
		printk(KERN_ERR "ft5x0x i2c rxdata failed\n");
		//goto out;
	}
	printk("ft5406 g_vid = 0x%X\n", ret);
	g_vid = ret;
#if 0
	reg = 0x88;
	w_value = 4; 
	ret = ft5x0x_write_reg(client, reg, w_value);    /* adjust sensitivity */
	if (ret < 0) {
		printk(KERN_ERR "ft5x0x i2c txdata failed\n");
	}
#endif
#if 1
	while (1) {
		reg = 0x88;
		w_value = 7; 
		ret = ft5x0x_write_reg(client, reg, w_value);    /* adjust frequency 70Hz */
		if (ret < 0) {
			printk(KERN_ERR "ft5x0x i2c txdata failed\n");
			//goto out;
		}

		r_value = ft5x0x_read_reg(client, reg);
		if (ret < 0) {
			printk(KERN_ERR "ft5x0x i2c rxdata failed\n");
			//goto out;
		}
		printk("r_value = %d\n, i = %d, flag = %d", r_value, i, flag);
		i++;

		if (w_value != r_value) {
			ret = -1;
			flag = 0;
			if (i > 5) { /* test 5 count */
				break;
			}
		} else {
			ret = 0;
			break;
		}
	}
#endif
	return ret;

exit_alloc_gpio_power_failed:
#if defined (TOUCH_POWER_PIN)
	gpio_free(ft5x0x_ts->touch_en_gpio);
#endif
exit_alloc_gpio_rst_failed:
    gpio_free(ft5x0x_ts->reset_gpio);
	printk("%s error\n",__FUNCTION__);
	return err;
}
Exemplo n.º 6
0
/*
[function]: 
    burn the FW to ctpm.
[parameters]:(ref. SPEC)
    pbt_buf[in]    :point to Head+FW ;
    dw_lenth[in]:the length of the FW + 6(the Head length);    
    bt_ecc[in]    :the ECC of the FW
[return]:
    ERR_OK        :no error;
    ERR_MODE    :fail to switch to UPDATE mode;
    ERR_READID    :read id fail;
    ERR_ERASE    :erase chip fail;
    ERR_STATUS    :status error;
    ERR_ECC        :ecc error.
*/
static E_UPGRADE_ERR_TYPE ft5x0x_fw_upgrade(struct ft5x0x_data *ft5x0x, u8* pbt_buf, int dw_lenth)
{
    int i = 0,j = 0,i_ret;
    int packet_number;
    int temp,lenght;
    u8 packet_buf[FTS_PACKET_LENGTH + 6];
    u8 auc_i2c_write_buf[10];
    u8 reg_val[2] = {0};
    u8 ctpm_id[2] = {0};
    u8 cmd[4];
    u8 bt_ecc;

    /*********Step 1:Reset  CTPM *****/
    /*write 0xaa to register 0xfc*/
    ft5x0x_write_reg(0xfc,0xaa);
    msleep(50);
    /*write 0x55 to register 0xfc*/
    ft5x0x_write_reg(0xfc,0x55);
    printk("[FTS] Step 1: Reset CTPM.\n");
    msleep(30);   

    /*********Step 2:Enter upgrade mode *****/
    auc_i2c_write_buf[0] = 0x55;
    auc_i2c_write_buf[1] = 0xaa;
    do{
        i ++;
        i_ret = byte_write(auc_i2c_write_buf, 2);
        mdelay(5);
    }while(i_ret <= 0 && i < 5 );
    msleep(20);
    
    /*********Step 3:check READ-ID**********/        
    if(ft5x0x->id == FT5606){
        ctpm_id[0] = FT56_CTPM_ID_L;
        ctpm_id[1] = FT56_CTPM_ID_H;
    }else{
        ctpm_id[0] = FT5X_CTPM_ID_L;
        ctpm_id[1] = FT5X_CTPM_ID_H;
    }

    cmd[0] = 0x90;
    cmd[1] = 0x00;
    cmd[2] = 0x00;
    cmd[3] = 0x00;
    cmd_write(cmd,4);
    byte_read(reg_val,2);
    if (reg_val[0] == ctpm_id[0] && reg_val[1] == ctpm_id[1]){
        printk("[FTS] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
    }else{
        printk("[FTS] ID_ERROR: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
        return ERR_READID;
    }

    cmd[0] = 0xcd;
    cmd_write(cmd,1);
    byte_read(reg_val,1);
    printk("[FTS] bootloader version = 0x%x\n", reg_val[0]);

    /******Step 4:erase app and panel paramenter area *********/
    cmd[0] = 0x61;
    cmd_write(cmd,1); //erase app area
    msleep(1500); 
    cmd[0] = 0x63;
    cmd_write(cmd,1); //erase panel parameter area
    msleep(100);
    printk("[FTS] Step 4: erase. \n");

    /*********Step 5:write firmware(FW) to ctpm flash*********/
    bt_ecc = 0;
    printk("[FTS] Step 5: start upgrade. \n");
    dw_lenth = dw_lenth - 8;
    packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
    packet_buf[0] = 0xbf;
    packet_buf[1] = 0x00;
    for (j=0;j<packet_number;j++){
        temp = j * FTS_PACKET_LENGTH;
        packet_buf[2] = (u8)(temp>>8);
        packet_buf[3] = (u8)temp;
        lenght = FTS_PACKET_LENGTH;
        packet_buf[4] = (u8)(lenght>>8);
        packet_buf[5] = (u8)lenght;

        for (i=0;i<FTS_PACKET_LENGTH;i++){
            packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i]; 
            bt_ecc ^= packet_buf[6+i];
        }
        
        byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
        mdelay(FTS_PACKET_LENGTH/6 + 1);
        if ((j * FTS_PACKET_LENGTH % 1024) == 0){
              printk("[FTS] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
        }
    }

    if ((dw_lenth) % FTS_PACKET_LENGTH > 0){
        temp = packet_number * FTS_PACKET_LENGTH;
        packet_buf[2] = (u8)(temp>>8);
        packet_buf[3] = (u8)temp;

        temp = (dw_lenth) % FTS_PACKET_LENGTH;
        packet_buf[4] = (u8)(temp>>8);
        packet_buf[5] = (u8)temp;

        for (i=0;i<temp;i++){
            packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i]; 
            bt_ecc ^= packet_buf[6+i];
        }

        byte_write(&packet_buf[0],temp+6);    
        mdelay(20);
    }