Beispiel #1
0
int pn544_send_for_mmi(char * pszBuf,unsigned short SendCnt)
{
	int ret=0;	
	mutex_lock(&pn544_info->mutex_mmi);
	ret = pn544_i2c_write(&pn544_client, pszBuf, SendCnt); 
	mutex_unlock(&pn544_info->mutex_mmi);
	return ret;
}
static int DoI2Coperation(char *cmd, int CmdNum, int cmdLength[], int cmdResLength[], int cmdWithTwoResponse)
{
    	int cmdResLengthIndex = 0;    

    	int i;
    	int ret = I2C_TEST_PASS;

   	for(i = 0; i < CmdNum; i++){
       	    i2c_log_in_test_case("[Nfc] CMD=%d\n", i);
	    ret = pn544_i2c_write(cmd, cmdLength[i]);
	    if(ret == I2C_TEST_NFC_FAIL)
	       return ret;	
	    cmd=cmd+CMD_COL;
	    msleep(200); 	
	    if(cmdResLength[cmdResLengthIndex]!=0){  //If a cmd is an Auto ACK, the chip will not response...
    	        ret= pn544_i2c_read(cmdResLength[cmdResLengthIndex]);
	        if(ret == I2C_TEST_NFC_FAIL)
	           return ret;	        
		cmdResLengthIndex++;
		if(i == cmdWithTwoResponse){ //If a cmd has 2 responses, do i2c_read again...here,only cmd3 has 2 responses...
	    	        ret = pn544_i2c_read(cmdResLength[cmdResLengthIndex]);
         	        if(ret == I2C_TEST_NFC_FAIL)
	                   return ret;
			cmdResLengthIndex++;
		}
		/*else {
		    printk("cmd %d has no 2 responses.\n", i);
		}*/
	    }
	    else {
		cmdResLengthIndex++;
		//printk("cmdResLengthIndex=%d\n", cmdResLengthIndex);
	    }	
	}

	return ret;
}
Beispiel #3
0
//to check if the i2c device is ok
static int pn544_i2c_device_probe(struct i2c_client *client)
{
    int ret = 0;
    int i = 0;
    int cmd_send_result = 0;
    u8 *cmd_reset = NULL;
    u8 *cmd_fwdld_first = NULL;
    u8 *cmd_receive = NULL;

    /* the following code is used for the pn544 reset cmd test
     * according to the pn544 SPEC 
     */
    cmd_reset = kzalloc(sizeof(u8) * PN544_RESET_SEND_SIZE, GFP_KERNEL);
    if(NULL == cmd_reset)
    {
        PN544_DEBUG("%s:cmd_reset alloc failed.\n", __func__);
        ret = -ENOMEM;
        goto err_cmd_reset_alloc; 
    }

    cmd_receive = kzalloc(sizeof(u8) * PN544_RESET_RECEIVE_SIZE, GFP_KERNEL);
    if(NULL == cmd_receive)
    {
        PN544_DEBUG("%s:cmd_receive alloc failed.\n", __func__);
        ret = -ENOMEM;
        goto err_cmd_receive_alloc; 
    }

    for (i = 0; i < PN544_RESET_SEND_TIMES; i++)
    {
        cmd_reset[0] = 0x05;
        cmd_reset[1] = 0xf9;
        cmd_reset[2] = 0x04;
        cmd_reset[3] = 0x00;
        cmd_reset[4] = 0xc3;
        cmd_reset[5] = 0xe5;
		 
        /* here we send a HCI based reset command to pn544 to reset it */	
        mdelay(100);	

        ret = pn544_i2c_write(client, cmd_reset, PN544_RESET_SEND_SIZE);
        if (ret < 0)
        {
            PN544_DEBUG("%s:write i2c failed, continue.\n", __func__);
            continue;
        }
        mdelay(5);

        PN544_DEBUG("%s:send cmd_reset to pn544\n", __func__);

        cmd_receive[0] = 0x00;
        cmd_receive[1] = 0x00;
        cmd_receive[2] = 0x00;
        cmd_receive[3] = 0x00;
		
	
        PN544_DEBUG("%s:ready to receive data\n", __func__);
        ret = pn544_i2c_read(client, cmd_receive, PN544_RESET_RECEIVE_SIZE);
        if(ret < 0)
        {
            PN544_DEBUG("%s:read i2c failed, continue.\n", __func__);
            continue;         
        }
              
        PN544_DEBUG("pn544 cmd_receive[0]=0x%x\n", cmd_receive[0]);
        PN544_DEBUG("pn544 cmd_receive[1]=0x%x\n", cmd_receive[1]);
        PN544_DEBUG("pn544 cmd_receive[2]=0x%x\n", cmd_receive[2]);
        PN544_DEBUG("pn544 cmd_receive[3]=0x%x\n", cmd_receive[3]);
	 

        /* the following check is according to pn544 SPEC */
        if ((cmd_receive[0]!= 0x03)
			|| (cmd_receive[1]!= 0xE6) 
			|| (cmd_receive[2]!= 0x17) 
			|| (cmd_receive[3]!= 0xA7))
        {
            PN544_DEBUG("%s:The reset cmd is not exec successful\n", __func__);
            ret = -ENODEV; 
            continue;
        }

        cmd_send_result = 1; 
        ret = 0;
        break;
    }

    if (1 == cmd_send_result)
    {
        PN544_DEBUG("%s, pn544 reset cmd response successfully.\n", __func__);
        ret = 0;
        goto err_cmd_reset;
    }

    //no response with reset cmd, we go to dlowad mode to test the i2c 
    if (!pdata->pn544_ven_reset || !pdata->pn544_fw_download_pull_high)
    {
        PN544_DEBUG("%s:func pull_high and ven_reset missing\n", __func__);

        ret = -ENODEV;
        goto err_cmd_reset;     
    } 

    pdata->pn544_fw_download_pull_high();
    pdata->pn544_ven_reset();

    cmd_fwdld_first = kzalloc(sizeof(u8) * PN544_FWDLD_FIRST_SEND_SIZE, GFP_KERNEL);
    if(NULL == cmd_fwdld_first)
    {
        PN544_DEBUG("%s:cmd_fwdld_first alloc failed.\n", __func__);

        ret = -ENOMEM; 
        goto err_cmd_fwdld_first_alloc; 
    }

    //the test cmd 0x010000
    cmd_fwdld_first[0] = 0x01;
    cmd_fwdld_first[1] = 0x00;
    cmd_fwdld_first[2] = 0x00;

    mdelay(100);
	
    ret = pn544_i2c_write(client, cmd_fwdld_first, PN544_FWDLD_FIRST_SEND_SIZE);
    if (ret < 0)
    {
        PN544_DEBUG("%s:pn544_i2c_write download cmd failed.\n", __func__);

        goto err_cmd_fwdld_first_send;
    }
    mdelay(5);

    if (!pdata->pn544_fw_download_pull_down)
    {
	 PN544_DEBUG("%s:func pull_down missing.\n", __func__);
        goto err_cmd_fwdld_first_send;
    }

    //here we should exit the download mode
    pdata->pn544_fw_download_pull_down();
    pdata->pn544_ven_reset();


err_cmd_fwdld_first_send:
	kfree(cmd_fwdld_first);
	
err_cmd_fwdld_first_alloc:	

err_cmd_reset:
	kfree(cmd_receive);
	
err_cmd_receive_alloc:
	kfree(cmd_reset);
	
err_cmd_reset_alloc:	

    return ret;			
}