コード例 #1
0
int odm_i2c_block_read(struct odm_i2c_dev *dev, unsigned char cmd, unsigned char **buffer)
{
	/* TODO: How to implement this ? */
	/* OK, let's read twice, first time we get the total number, then get all the block data */
	int i;
	unsigned char data_len = 0;
	unsigned char *read_buffer;

	NvOdmI2cStatus I2cStatus;
	NvOdmI2cTransactionInfo TransactionInfo[2];

	TransactionInfo[0].Flags = NVODM_I2C_IS_WRITE | NVODM_I2C_USE_REPEATED_START;
	TransactionInfo[0].Address = dev->address;
	TransactionInfo[0].Buf = &cmd;
	TransactionInfo[0].NumBytes = 1; 
	TransactionInfo[1].Flags = 0;
	TransactionInfo[1].Address = dev->address | 0x1;
	TransactionInfo[1].Buf = &data_len;
	TransactionInfo[1].NumBytes = 1;

	I2cStatus = NvOdmI2cTransaction(dev->i2c, TransactionInfo,
			2, dev->speed, dev->timeout);

	if (I2cStatus != NvOdmI2cStatus_Success || data_len <= 0) {
		return -EINVAL;
	}
	
	read_buffer = kzalloc(data_len+2, GFP_KERNEL); 
	if (!read_buffer) {
		return -ENOMEM;
	}
	TransactionInfo[0].Flags = NVODM_I2C_IS_WRITE | NVODM_I2C_USE_REPEATED_START;
	TransactionInfo[0].Address = dev->address;
	TransactionInfo[0].Buf = &cmd;
	TransactionInfo[0].NumBytes = 1; 
	TransactionInfo[1].Flags = 0;
	TransactionInfo[1].Address = dev->address | 0x1;
	TransactionInfo[1].Buf = read_buffer;
	TransactionInfo[1].NumBytes = data_len + 1;

	I2cStatus = NvOdmI2cTransaction(dev->i2c, TransactionInfo,
			2, dev->speed, dev->timeout);

	if (I2cStatus != NvOdmI2cStatus_Success) {
		kfree(read_buffer);
		return -EINVAL;
	}
	
	for (i = 0; i < data_len; i++) {
		read_buffer[i] = read_buffer[i+1];
	}
	read_buffer[i] = '\0';

	return 0;
}
コード例 #2
0
int odm_i2c_block_write(struct odm_i2c_dev *dev, unsigned char cmd, unsigned char *buffer, unsigned char buffer_len)
{
	unsigned int i;
	unsigned char *write_buffer;
	NvOdmI2cStatus I2cStatus;
	NvOdmI2cTransactionInfo TransactionInfo;

	write_buffer = kzalloc(buffer_len + 2, GFP_KERNEL);
	if (!write_buffer) {
		return -ENOMEM;
	}

	write_buffer[0] = cmd;
	write_buffer[1] = buffer_len;
	memcpy(write_buffer + 2, buffer, buffer_len);
	TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
	TransactionInfo.Address = dev->address;
	TransactionInfo.Buf = write_buffer;
	TransactionInfo.NumBytes = buffer_len+2;

	I2cStatus = NvOdmI2cTransaction(dev->i2c, &TransactionInfo,
			2, dev->speed, dev->timeout);
	
	kfree(write_buffer);
	return (I2cStatus == NvOdmI2cStatus_Success) ? 0 : -1;
}
コード例 #3
0
int odm_i2c_process_call(struct odm_i2c_dev *dev, unsigned char cmd, unsigned short int write_data, unsigned short int *read_data)
{
	unsigned char write_buffer[3];
	unsigned char read_buffer[2];
	NvOdmI2cStatus I2cStatus;
	NvOdmI2cTransactionInfo TransactionInfo[2];

	
	write_buffer[0] = cmd;
	write_buffer[1] = write_data & 0x00ff;
	write_buffer[2] = write_data >> 8;
	TransactionInfo[0].Flags = NVODM_I2C_IS_WRITE | NVODM_I2C_USE_REPEATED_START;
	TransactionInfo[0].Address = dev->address;
	TransactionInfo[0].Buf = write_buffer;
	TransactionInfo[0].NumBytes = 3;
	TransactionInfo[1].Flags = 0;
	TransactionInfo[1].Address = dev->address | 0x1;
	TransactionInfo[1].Buf = read_buffer;
	TransactionInfo[1].NumBytes = 2;

	I2cStatus = NvOdmI2cTransaction(dev->i2c, TransactionInfo,
			2, dev->speed, dev->timeout);

	if (I2cStatus != NvOdmI2cStatus_Success) {
		return -1;
	}
	
	*read_data = read_buffer[0] | (read_buffer[1] << 8);
	return 0;
}
コード例 #4
0
int odm_i2c_read_word(struct odm_i2c_dev *dev, unsigned char cmd, unsigned short int *data)
{
	unsigned char buffer[2];
	NvOdmI2cStatus I2cStatus;
	NvOdmI2cTransactionInfo TransactionInfo[2];

	TransactionInfo[0].Flags = NVODM_I2C_IS_WRITE | NVODM_I2C_USE_REPEATED_START;
	TransactionInfo[0].Address = dev->address;
	TransactionInfo[0].Buf = &cmd;
	TransactionInfo[0].NumBytes = 1;
	TransactionInfo[1].Flags = 0;
	TransactionInfo[1].Address = dev->address | 0x1;
	TransactionInfo[1].Buf = buffer;
	TransactionInfo[1].NumBytes = 2;

	I2cStatus = NvOdmI2cTransaction(dev->i2c, TransactionInfo,
			2, dev->speed, dev->timeout);

	if (I2cStatus != NvOdmI2cStatus_Success) {
		logd("I2cAddress=%d, I2cStatus=%d\r\n", dev->address, I2cStatus);
		return -EINVAL;
	}
	
	*data = buffer[0] | buffer[1] << 8;
	
	return 0;
}
コード例 #5
0
static bool star_accel_i2c_write_data( star_accel_device *accel, unsigned char reg, unsigned char* data, unsigned char len )
{
	NvOdmI2cStatus i2c_status;
	NvOdmI2cTransactionInfo info;
	unsigned char* transfer_data;

	transfer_data = (unsigned char*)NvOdmOsAlloc(len+1);
    transfer_data[0] = reg; 
    NvOdmOsMemcpy( &transfer_data[1], data, (size_t)len);

    info.Address = accel->i2c_address;
    info.Buf = transfer_data;
    info.Flags = NVODM_I2C_IS_WRITE;
    info.NumBytes = len+1;
	
	do{  
        i2c_status = NvOdmI2cTransaction( accel->h_gen2_i2c, &info, 1, 400, 1000 );
    }while(i2c_status == NvOdmI2cStatus_Timeout);

    if( i2c_status != NvOdmI2cStatus_Success )
    {    
        printk("[star accel driver] %s : i2c transaction error(Number = %d)!\n",__func__,i2c_status);
        goto err; 
    }    
    NvOdmOsFree(transfer_data); 
    return true;
err:
    NvOdmOsFree(transfer_data);
    return false;
}
static NvBool Synaptics_OneTouch_ReadRegisterOnce (Synaptics_OneTouch_Device* hTouch, NvU8* buffer, NvU32 len)
{
	int i=0;
	NvOdmI2cStatus Error = NvOdmI2cStatus_Timeout;
	NvOdmI2cTransactionInfo TransactionInfo;
        
    TransactionInfo.Address = hTouch->DeviceAddr | 0x1;	//read
    TransactionInfo.Buf = buffer;
    TransactionInfo.Flags = 0;
    TransactionInfo.NumBytes = len;

	for (i = 0; i < SYNAPTICS_I2C_RETRY_COUNT && Error != NvOdmI2cStatus_Success; i++)
	{
    	Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                &TransactionInfo,
                                1,		// transactioncnt
                                SYNAPTICS_I2C_SPEED_KHZ,
                                SYNAPTICS_I2C_TIMEOUT);
	}

	if (Error != NvOdmI2cStatus_Success)
	{
		NVODMTOUCH_PRINTF(("[ONETOUCH] I2C Read Failure = %d (addr=0x%x)\n", Error, hTouch->DeviceAddr));
		return NV_FALSE;
	}

	return NV_TRUE;
}
コード例 #7
0
static void Adt7461ReadAra(ADT7461PrivData* pPrivData)
{
    NvU32 i;
    NvU8 Buffer = 0;
    NvOdmI2cStatus status;    
    NvOdmI2cTransactionInfo TransactionInfo;

    NV_ASSERT(pPrivData);

    for (i = 0; i < ADT7461_ARA_RETRY_CNT; i++)
    {
        TransactionInfo.Address = (ADT7461_ARA | 0x1);
        TransactionInfo.Buf = &Buffer;
        TransactionInfo.Flags = 0;
        TransactionInfo.NumBytes = 1;

        status = NvOdmI2cTransaction(pPrivData->hOdmI2C, &TransactionInfo, 1,
                    ADT7461_I2C_SPEED_KHZ, ADT7461_I2C_TIMEOUT_MS);
        if ((status == NvOdmI2cStatus_SlaveNotFound) ||     // False alarm
            ((status == NvOdmI2cStatus_Success) &&
            ((Buffer & 0xFE) == (NvU8)pPrivData->DeviceI2cAddr))  // Cleared ARA
            )
            break;
    }
}
コード例 #8
0
static NvBool EETI_GetTouchReport (EETI_TouchDevice* hTouch, NvU8 *ReportData, NvU32 *len) {

    /* Issue i2c transaction to get multi-touch report from the controller */

    NvOdmI2cTransactionInfo TransactionInfo;
    NvOdmI2cStatus Error;    

    NvOdmOsMemset(ReportData, 0, EETI_MAX_READ_BYTES);

    TransactionInfo.Address = hTouch->DeviceAddr;
    TransactionInfo.Buf = ReportData;
    TransactionInfo.Flags = 0;
    TransactionInfo.NumBytes = EETI_MAX_READ_BYTES;

    do {
        Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                    &TransactionInfo,
                                    1,
                                    hTouch->I2cClockSpeedKHz,
                                    EETI_I2C_TIMEOUT);
    } while (Error == NvOdmI2cStatus_Timeout);

    *len = TransactionInfo.NumBytes;

    if (Error != NvOdmI2cStatus_Success) {
        NvOdmOsPrintf("error!\r\n");
        return NV_FALSE;
    }

    return NV_TRUE;

}
コード例 #9
0
NvBool NvAmbientsensorI2CGetLx(NvOdmALSHandle hDevice, NvU16* value)
{
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU16 byte_swap;
    if( (NULL == hDevice) || (NULL == value))
    {
        return NV_FALSE;
    }
    
    NvOdmOsMemset(s_ReadBuffer, 0, sizeof(s_ReadBuffer));    

    TransactionInfo.Address = (hDevice->nDevAddr| 0x1);
    TransactionInfo.Buf = s_ReadBuffer;
    TransactionInfo.Flags = 0;
    TransactionInfo.NumBytes = I2C_ALS_READ_PACKET_SIZE;

    //Read the data from the eeprom at the specified offset
    if(NvOdmI2cStatus_Success != NvOdmI2cTransaction(hDevice->hI2c, &TransactionInfo, 1, 400, I2C_ALS_TRANSACTION_TIMEOUT))
    {
        return NV_FALSE;
    };    

    byte_swap = s_ReadBuffer[0];
    s_ReadBuffer[0] = s_ReadBuffer[1];
    s_ReadBuffer[1] = byte_swap;

    *value = *( NvU16 *)s_ReadBuffer;
    return NV_TRUE;
}
コード例 #10
0
static NvBool star_proxi_write_reg(ProximityDevice* proximity, NvU8 reg, NvU8 val)
{
    NvOdmI2cStatus Error;
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 arr[2];

        arr[0] = reg;        // register address
        arr[1] = val;        // u16 value (lsb-msb)

        TransactionInfo.Address = proximity->i2c_address;
        TransactionInfo.Buf = arr;
        TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
        TransactionInfo.NumBytes = 2;

    do
    {
        Error = NvOdmI2cTransaction(proximity->gen2_i2c,
                                    &TransactionInfo,
                                    1,
                                    400,
                                    10);
    } while (Error == NvOdmI2cStatus_Timeout);

    if (Error != NvOdmI2cStatus_Success)
    {
        lprintk(D_PROXI,"I2C Write Failure = %d (addr=0x%x, reg=0x%x, val=0x%0x)\n", Error,
                           proximity->i2c_address, reg, val);
        return NV_FALSE;
    }

    return NV_TRUE;
}
コード例 #11
0
NvU32 EETI_RawI2cRead(NvOdmTouchDeviceHandle hDevice, NvOdmTouchRawI2cData *i2c_data) {
    EETI_TouchDevice* hTouch = (EETI_TouchDevice*)hDevice;

    NvOdmI2cTransactionInfo TransactionInfo;
    NvOdmI2cStatus Error;    

    if (i2c_data == NULL)
        return NV_FALSE;

    NvOdmOsMemset(i2c_data->datum, 0, EETI_MAX_READ_BYTES);

    TransactionInfo.Address = hTouch->DeviceAddr;
    TransactionInfo.Buf = i2c_data->datum;
    TransactionInfo.Flags = 0;
    TransactionInfo.NumBytes = EETI_MAX_READ_BYTES;

    do {
        Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                    &TransactionInfo,
                                    1,
                                    hTouch->I2cClockSpeedKHz,
                                    EETI_I2C_TIMEOUT);
    } while (Error == NvOdmI2cStatus_Timeout);

    if (Error != NvOdmI2cStatus_Success) {
        NvOdmOsPrintf("error!\r\n");
        return NV_FALSE;
    }

    i2c_data->data_len = TransactionInfo.NumBytes;

    return TransactionInfo.NumBytes;
}
コード例 #12
0
static NvBool EETI_ProbeTouchDevice (EETI_TouchDevice* hTouch) {
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 arr[EETI_MAX_READ_BYTES];
    NvOdmI2cStatus Error;    

    NvOdmOsMemset(arr, 0, EETI_MAX_READ_BYTES);

    arr[0] = 0x03;
    arr[1] = 0x01;
    arr[2] = (NvU8)'A';

    TransactionInfo.Address = hTouch->DeviceAddr;
    TransactionInfo.Buf = arr;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 3;

    Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                &TransactionInfo,
                                1,
                                hTouch->I2cClockSpeedKHz,
                                EETI_I2C_TIMEOUT);

    if (Error != NvOdmI2cStatus_Success) {
        return NV_FALSE;
    }
    return NV_TRUE;

}
コード例 #13
0
static NvBool I2C_Write (NvOdmVibDeviceHandle hOdmVibrate, NvU8 reg, NvU8 val)
{
    NvOdmI2cStatus Status;
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 arr[2];

    arr[0] = reg;
    arr[1] = val;

    TransactionInfo.Address = hOdmVibrate->DeviceAddr;
    TransactionInfo.Buf = arr;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 2;

    Status = NvOdmI2cTransaction(hOdmVibrate->hOdmI2c,
                                &TransactionInfo,
                                1,
                                TPS6586x_I2C_SPEED_KHZ,
                                NV_WAIT_INFINITE);

    if (Status != NvOdmI2cStatus_Success)
    {
        NV_ODM_TRACE(("I2C Write Failure = %d (addr=0x%x, reg=0x%x, val=0x%0x)\n", Status, hOdmVibrate->DeviceAddr, reg, val));

        return NV_FALSE;
    }

    return NV_TRUE;
}
コード例 #14
0
// Dummy write accelerometer in order to workaround a HW bug of ADL340
// Will Remove it once we use new accelerometer
static NvBool NvAccDummyI2CSetRegs(TPK_TouchDevice* hTouch)
{
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 arr[2];
    NvOdmI2cStatus Error;    

    arr[0] = 0x0;
    arr[1] = 0x0;

    TransactionInfo.Address = 0x3A;
    TransactionInfo.Buf = arr;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 2;

    // Write dummy data to accelerometer

    do
    {
        Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                    &TransactionInfo,
                                    1,
                                    hTouch->I2cClockSpeedKHz,
                                    TPK_I2C_TIMEOUT);
    } while (Error == NvOdmI2cStatus_Timeout);

    if (Error != NvOdmI2cStatus_Success)
    {
        //NvOdmOsDebugPrintf("error!\r\n");
        return NV_FALSE;
    }                        
    //NvOdmOsDebugPrintf("dummy!\r\n");
    return NV_TRUE;
}
コード例 #15
0
static NvBool I2C_Read(NvOdmVibDeviceHandle hOdmVibrate, NvU8 reg, NvU8 *val)
{
    NvU8 ReadBuffer = 0;
    NvOdmI2cStatus Status;    
    NvOdmI2cTransactionInfo TransactionInfo[2];
    
	ReadBuffer = reg & 0xFF;
	
    TransactionInfo[0].Address = hOdmVibrate->DeviceAddr;
    TransactionInfo[0].Buf = &ReadBuffer;
    TransactionInfo[0].Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo[0].NumBytes = 1;    
    TransactionInfo[1].Address = (hOdmVibrate->DeviceAddr | 0x1);
    TransactionInfo[1].Buf = &ReadBuffer;
    TransactionInfo[1].Flags = 0;
    TransactionInfo[1].NumBytes = 1;

  	Status = NvOdmI2cTransaction(hOdmVibrate->hOdmI2c,
  								&TransactionInfo[0], 
  								2, 
                                TPS6586x_I2C_SPEED_KHZ, 
                                NV_WAIT_INFINITE);
  	
	if (Status != NvOdmI2cStatus_Success)
    {
        NV_ODM_TRACE(("I2C Read Failure = %d (addr=0x%x, reg=0x%x)\n", Status, hOdmVibrate->DeviceAddr, reg));
        return NV_FALSE;
    }
	
    *val = ReadBuffer;
    return NV_TRUE;
}
コード例 #16
0
// set register address before read
static NvBool Synaptics_OneTouch_SetReadAddr (Synaptics_OneTouch_Device* hTouch)
{
	int i=0;
	NvOdmI2cStatus Error = NvOdmI2cStatus_Timeout;
	NvOdmI2cTransactionInfo TransactionInfo;

	NvU8 pReg[2];
	
	pReg[0]	=	OT_DATA_REG_START_ADDR_HIGH;
	pReg[1]	=	OT_DATA_REG_START_ADDR_LOW;
	
	// set register address
	TransactionInfo.Address = hTouch->DeviceAddr;
	TransactionInfo.Buf = (NvU8*)&pReg;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 2;

	for (i = 0; i < SYNAPTICS_I2C_RETRY_COUNT && Error != NvOdmI2cStatus_Success; i++)
	{
		Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                    &TransactionInfo,
                                    1,
                                    SYNAPTICS_I2C_SPEED_KHZ,
                                    SYNAPTICS_I2C_TIMEOUT);
	}

	if (Error != NvOdmI2cStatus_Success)
	{
		NVODMTOUCH_PRINTF(("[ONETOUCH] I2C Write Failure = %d (addr=0x%x)\n", Error, hTouch->DeviceAddr));
		return NV_FALSE;
	}

	return NV_TRUE;
}
コード例 #17
0
/*
 * Write I2C register function.
 * offset[Input]: I2C register offset of accelerometer.
 * value[Input]: register value you will write.
 * len[Input]: requested bytes.
 * Returns NV_TRUE if successful, or NV_FALSE otherwise.
 */
NvBool NvAccelerometerI2CSetRegs(NvOdmAccelHandle hDevice, NvU8 offset, NvU8* value, NvU32 len)
{
    NvOdmI2cTransactionInfo TransactionInfo;

    if( (NULL == hDevice) || (NULL == value) || (len > I2C_ACCELRATOR_PACKET_SIZE-1 ))
    {
        //NVODMACCELEROMETER_PRINTF("NvOdmI2c Set Regs Failed, max size is %d bytes\n", I2C_ACCELRATOR_PACKET_SIZE-1);
        return NV_FALSE;
    }
    
    NvOdmOsMemset(s_WriteBuffer, 0, sizeof(s_WriteBuffer));
    s_WriteBuffer[0] = offset;
    NvOdmOsMemcpy(&s_WriteBuffer[1], value, len);

    TransactionInfo.Address = hDevice->nDevAddr;
    TransactionInfo.Buf = s_WriteBuffer;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = len+1;

    // Write the accelerator offset (from where data is to be read).
    if(NvOdmI2cStatus_Success != NvOdmI2cTransaction(hDevice->hOdmI2C, &TransactionInfo, 1, 400, I2C_ACCELRATOR_TRANSACTION_TIMEOUT))
    {
        return NV_FALSE;
    };    
        
    return NV_TRUE;
}
コード例 #18
0
// setting register
static NvBool Synaptics_OneTouch_WriteRegister (Synaptics_OneTouch_Device* hTouch, NvU8 val)
{
	int i=0;
	NvOdmI2cStatus Error = NvOdmI2cStatus_Timeout;
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 arr[1];

    arr[0] = val;		// register address
    
    TransactionInfo.Address = hTouch->DeviceAddr;
    TransactionInfo.Buf = arr;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 1;
    
	for (i = 0; i < SYNAPTICS_I2C_RETRY_COUNT && Error != NvOdmI2cStatus_Success; i++)
    {
        Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                    &TransactionInfo,
                                    1,
                                    SYNAPTICS_I2C_SPEED_KHZ,
                                    SYNAPTICS_I2C_TIMEOUT);
	}

    if (Error != NvOdmI2cStatus_Success)
    {
        NVODMTOUCH_PRINTF(("[ONETOUCH] I2C Write Failure = %d (addr=0x%x, val=0x%0x)\n", Error, hTouch->DeviceAddr, val));
        return NV_FALSE;
    }

    return NV_TRUE;
}
コード例 #19
0
static NvBool TPK_WriteRegister (TPK_TouchDevice* hTouch, NvU8 reg, NvU8 val)
{
    NvOdmI2cStatus Error;
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 arr[2];
#if TPK_ADL340_WAR    
    // dummy write
    Error = NvAccDummyI2CSetRegs(hTouch);
#endif
    arr[0] = reg;
    arr[1] = val;
    
    TransactionInfo.Address = hTouch->DeviceAddr;
    TransactionInfo.Buf = arr;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 2;
    
    do
    {
        Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                    &TransactionInfo,
                                    1,
                                    hTouch->I2cClockSpeedKHz,
                                    TPK_I2C_TIMEOUT);
    } while (Error == NvOdmI2cStatus_Timeout); 

    if (Error != NvOdmI2cStatus_Success)
    {
        NVODMTOUCH_PRINTF(("I2C Write Failure = %d (addr=0x%x, reg=0x%x, val=0x%0x)\n", Error, 
                           hTouch->DeviceAddr, reg, val));
        return NV_FALSE;
    }
    return NV_TRUE;
}
コード例 #20
0
static NvBool
WriteReg(
    NvOdmAccelHandle hDevice,
    NvU8 RegAddr,
    NvU8* value,
    NvU32 len)
{
    NvOdmI2cTransactionInfo TransactionInfo;

    if ( (NULL == hDevice) || (NULL == value) ||
         (len > I2C_ACCELRATOR_PACKET_SIZE-1 ) )
    {
        NVODMACCELEROMETER_PRINTF((
            "NvOdmI2c Set Regs Failed, max size is %d bytes\n",
            I2C_ACCELRATOR_PACKET_SIZE-1));
        return NV_FALSE;
    }

    s_WriteBuffer[0] = RegAddr;
    NvOdmOsMemcpy(&s_WriteBuffer[1], value, len);

    TransactionInfo.Address = hDevice->nDevAddr;
    TransactionInfo.Buf = s_WriteBuffer;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = len+1;

    // Write the accelerator RegAddr (from where data is to be read).
    if (NvOdmI2cTransaction(hDevice->hOdmI2C, &TransactionInfo, 1, I2C_CLK_SPEED,
            I2C_ACCELRATOR_TRANSACTION_TIMEOUT) != NvOdmI2cStatus_Success)
        return NV_FALSE;

    return NV_TRUE;
}
コード例 #21
0
NvU32 EETI_RawI2cWrite(NvOdmTouchDeviceHandle hDevice, NvOdmTouchRawI2cData *i2c_data) {
    EETI_TouchDevice* hTouch = (EETI_TouchDevice*)hDevice;
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 arr[EETI_MAX_READ_BYTES];
    NvOdmI2cStatus Error;    

    NvOdmOsMemset(arr, 0, EETI_MAX_READ_BYTES);

    NvOdmOsMemcpy(arr, i2c_data->datum, i2c_data->data_len);

    TransactionInfo.Address = hTouch->DeviceAddr;
    TransactionInfo.Buf = arr;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = i2c_data->data_len;

    Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                &TransactionInfo,
                                1,
                                hTouch->I2cClockSpeedKHz,
                                EETI_I2C_TIMEOUT);

    if (Error != NvOdmI2cStatus_Success) {
        return 0;
    }

    return TransactionInfo.NumBytes;
}
コード例 #22
0
static NvBool TPK_ReadRegisterOnce (TPK_TouchDevice* hTouch, NvU8 reg, NvU8* buffer, NvU32 len)
{
    NvOdmI2cStatus Error;
    NvOdmI2cTransactionInfo TransactionInfo[2 * TPK_MAX_READS];
    int reads = (len+(TPK_MAX_PACKET_SIZE-1))/TPK_MAX_PACKET_SIZE;
    int left = len;
    int i;
    
    NV_ASSERT(len <= TPK_MAX_READ_BYTES);
#if TPK_ADL340_WAR    
    // dummy write
    Error = NvAccDummyI2CSetRegs(hTouch);
#endif
    ////////////////////////////////////////////////////////////////////////////
    // For multi-byte reads, the TPK panel supports just sending the first
    // address and then keep reading registers (non-standard SMBus operation).
    // The limit for I2C packets is 8 bytes, so we read up to 8 bytes per
    // multi-byte read transaction.
    ////////////////////////////////////////////////////////////////////////////

    for (i = 0; i < reads; i++)
    {
        int ind = i*2;

        TransactionInfo[ind].Address = hTouch->DeviceAddr;
        TransactionInfo[ind].Buf = &reg;
        TransactionInfo[ind].Flags = NVODM_I2C_IS_WRITE;
        TransactionInfo[ind].NumBytes = 1;

        ind++;

        TransactionInfo[ind].Address = hTouch->DeviceAddr | 0x1;
        TransactionInfo[ind].Buf = buffer + i*TPK_MAX_PACKET_SIZE;
        TransactionInfo[ind].Flags = 0;
        TransactionInfo[ind].NumBytes =
            left > TPK_MAX_PACKET_SIZE ? TPK_MAX_PACKET_SIZE : left;
        
        left -= TPK_MAX_PACKET_SIZE;
    }
    
    do
    {
        Error = NvOdmI2cTransaction(hTouch->hOdmI2c,
                                    TransactionInfo,
                                    reads * 2,
                                    hTouch->I2cClockSpeedKHz,
                                    TPK_I2C_TIMEOUT);
    } while (Error == NvOdmI2cStatus_Timeout);

    if (Error != NvOdmI2cStatus_Success)
    {
        NVODMTOUCH_PRINTF(("I2C Read Failure = %d (addr=0x%x, reg=0x%x)\n", Error,
                           hTouch->DeviceAddr, reg));
        return NV_FALSE;
    }

    return NV_TRUE;
}
コード例 #23
0
static NvBool
Adt7461ReadReg(
    ADT7461PrivData* pPrivData,
    const ADT7461RegisterInfo* pReg,
    NvU8* pData)
{
    NvU32 i;
    NvU8 Buffer = 0;
    NvOdmI2cStatus status;    
    NvOdmI2cTransactionInfo TransactionInfo[2];

    NV_ASSERT(pPrivData && pReg && pData);
    NV_ASSERT(pReg->RdAddr != ADT7461_INVALID_ADDR);

    // TODO: possible optimization - is shadow pointer matches register
    // address, just send one read transaction (can be done only if Read/Wr
    // Reg routines are serialized).

    for (i = 0; i < ADT7461_I2C_RETRY_CNT; i++)
    {
        Buffer = pReg->RdAddr;

        TransactionInfo[0].Address = pPrivData->DeviceI2cAddr;
        TransactionInfo[0].Buf = &Buffer;
        TransactionInfo[0].Flags = NVODM_I2C_IS_WRITE;
        TransactionInfo[0].NumBytes = 1;

        TransactionInfo[1].Address = (pPrivData->DeviceI2cAddr | 0x1);
        TransactionInfo[1].Buf = &Buffer;
        TransactionInfo[1].Flags = 0;
        TransactionInfo[1].NumBytes = 1;

        status = NvOdmI2cTransaction(pPrivData->hOdmI2C, &TransactionInfo[0], 2,
                    ADT7461_I2C_SPEED_KHZ, ADT7461_I2C_TIMEOUT_MS);
        if (status == NvOdmI2cStatus_Success)
            break;
    }

    switch (status)
    {
        case NvOdmI2cStatus_Success:
            pPrivData->ShadowRegPtr = pReg->RdAddr;
            *pData = Buffer;
            return NV_TRUE;

        case NvOdmI2cStatus_Timeout:
            NVODM_ADT7461_PRINTF(("ADT7461: ReadReg Timeout\n")); 
            return NV_FALSE;

         case NvOdmI2cStatus_SlaveNotFound:
         default:
            NVODM_ADT7461_PRINTF(("ADT7461: ReadReg SlaveNotFound\n"));
            return NV_FALSE;
    }
}
コード例 #24
0
static NvOdmI2cStatus
NvOdmPeripheralI2cRead8(
    NvOdmServicesI2cHandle hOdmI2c,
    NvU8 I2cAddr,
    NvU8 Offset,
    NvU8 *pData)
{
    NvU8 ReadBuffer[1];
    NvOdmI2cStatus Error;    
    NvOdmI2cTransactionInfo TransactionInfo;

    ReadBuffer[0] = Offset;

    TransactionInfo.Address = I2cAddr;
    TransactionInfo.Buf = ReadBuffer;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 1;

    Error = NvOdmI2cTransaction(
        hOdmI2c, &TransactionInfo, 1, NVODM_QUERY_I2C_CLOCK_SPEED, NV_WAIT_INFINITE);
    if (Error != NvOdmI2cStatus_Success)
    {
        return Error;
    }

    NvOdmOsMemset(ReadBuffer, 0, sizeof(ReadBuffer));  

    TransactionInfo.Address = (I2cAddr | 0x1);
    TransactionInfo.Buf = ReadBuffer;
    TransactionInfo.Flags = 0;
    TransactionInfo.NumBytes = 1;

    // Read data from ROM at the specified offset
    Error = NvOdmI2cTransaction(
        hOdmI2c, &TransactionInfo, 1, NVODM_QUERY_I2C_CLOCK_SPEED, NV_WAIT_INFINITE);
    if (Error != NvOdmI2cStatus_Success)
    {
        return Error;
    }
    *pData = ReadBuffer[0];
    return Error;
}
コード例 #25
0
static NvBool
ReadReg(
    NvOdmEcompassHandle hDevice,
    NvU8 RegAddr,
    NvU8* value,
    NvU32 len)
{
    NvOdmI2cTransactionInfo TransactionInfo;

    if ( (NULL == hDevice) || (NULL == value) ||
            (len > I2C_ECOMPASS_PACKET_SIZE-1 ) )
    {
        NVODMECOMPASS_PRINTF(("NvOdmI2c Get Regs Failed, max size is %d bytes\n", I2C_ECOMPASS_PACKET_SIZE-1));
        return NV_FALSE;
    }

    s_WriteBuffer[0] = RegAddr;
    TransactionInfo.Address = hDevice->nDevAddr;
    TransactionInfo.Buf = s_WriteBuffer;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 1;

    // Write the accelerometor RegAddr (from where data is to be read).
    if (NvOdmI2cTransaction(hDevice->hOdmI2C, &TransactionInfo, 1, NVODMECOMPASS_I2C_SPEED_KHZ,
                            I2C_ECOMPASS_TRANSACTION_TIMEOUT) != NvOdmI2cStatus_Success)
        return NV_FALSE;

    s_ReadBuffer[0] = 0;
    TransactionInfo.Address = (hDevice->nDevAddr| 0x1);
    TransactionInfo.Buf = s_ReadBuffer;
    TransactionInfo.Flags = 0;
    TransactionInfo.NumBytes = len;

    //Read the data from the eeprom at the specified RegAddr
    if (NvOdmI2cTransaction(hDevice->hOdmI2C, &TransactionInfo, 1, NVODMECOMPASS_I2C_SPEED_KHZ,
                            I2C_ECOMPASS_TRANSACTION_TIMEOUT) != NvOdmI2cStatus_Success)
        return NV_FALSE;

    NvOdmOsMemcpy(value, &s_ReadBuffer[0], len);
    return NV_TRUE;
}
コード例 #26
0
NvBool Max8907bI2cRead8(
   NvOdmPmuDeviceHandle hDevice,
   NvU8 Addr,
   NvU8 *Data)
{
    NvU32 i;
    NvU8 ReadBuffer = 0;
    NvOdmI2cStatus  status = NvOdmI2cStatus_Success;
    Max8907bPrivData *hPmu = (Max8907bPrivData*)hDevice->pPrivate;
    NvOdmI2cTransactionInfo TransactionInfo[2];

    for (i = 0; i < MAX8907B_I2C_RETRY_CNT; i++)
    {
        NvU32 TransactionCount = 0;
        // Write the PMU offset
        ReadBuffer = Addr & 0xFF;

        TransactionInfo[TransactionCount].Address = hPmu->DeviceAddr;
        TransactionInfo[TransactionCount].Buf = &ReadBuffer;
        TransactionInfo[TransactionCount].Flags =
            NVODM_I2C_IS_WRITE | NVODM_I2C_USE_REPEATED_START;
        TransactionInfo[TransactionCount++].NumBytes = 1;

        TransactionInfo[TransactionCount].Address = (hPmu->DeviceAddr | 0x1);
        TransactionInfo[TransactionCount].Buf = &ReadBuffer;
        TransactionInfo[TransactionCount].Flags = 0;
        TransactionInfo[TransactionCount++].NumBytes = 1;

        // Read data from PMU at the specified offset
        status = NvOdmI2cTransaction(hPmu->hOdmI2C, &TransactionInfo[0],
            TransactionCount, MAX8907B_I2C_SPEED_KHZ, NV_WAIT_INFINITE);

        if (status == NvOdmI2cStatus_Success)
        {
            *Data = ReadBuffer;
            return NV_TRUE;
        }
    }

    // Transaction Error
    switch (status)
    {
        case NvOdmI2cStatus_Timeout:
            NVODMPMU_PRINTF(("NvOdmPmuI2cRead8 Failed: Timeout\n"));
            break;
        case NvOdmI2cStatus_SlaveNotFound:
        default:
            NVODMPMU_PRINTF(("NvOdmPmuI2cRead8 Failed: SlaveNotFound\n"));
            break;
    }
    return NV_FALSE;
}
コード例 #27
0
/*
 * Read I2C register function.
 * offset[Input]: I2C register offset of accelerometer.
 * value[Output]: Fegister value you get.
 * len[Input]: Requested bytes.
 * Returns NV_TRUE if successful, or NV_FALSE otherwise.
 */
NvBool NvGyroAccelI2CGetRegs(NvOdmGyroAccelHandle hDevice, NvU8 offset, NvU8* value, NvU32 len)
{
        int i;
        NvOdmI2cStatus i2c_status = NvOdmI2cStatus_Timeout;
	NvOdmI2cTransactionInfo TransactionInfo[2];

// LGE_CHANGE_S [] 2011-05-28, [LGE_AP20] sensors: I2C recovery
	if (reboot == 1)
		return NV_FALSE;
// LGE_CHANGE_E [] 2011-05-28, [LGE_AP20] sensors: I2C recovery

	if ((NULL == hDevice) || (NULL == value) || (len > I2C_GYROACCEL_PACKET_SIZE-1)) {
		printk("NvOdmI2c Get Regs Failed, max size is %d bytes\n", I2C_GYROACCEL_PACKET_SIZE-1);
		return NV_FALSE;
	}

        for (i = 0; i < TIMEOUT && i2c_status != NvOdmI2cStatus_Success; i++)
        {
	    NvOdmOsMemset(s_WriteBuffer, 0, sizeof(s_WriteBuffer));
	    s_WriteBuffer[0] = offset;

	    TransactionInfo[0].Address = hDevice->nDevAddr;
	    TransactionInfo[0].Buf = s_WriteBuffer;
	    TransactionInfo[0].Flags = NVODM_I2C_IS_WRITE;
	    TransactionInfo[0].NumBytes = 1;

	    NvOdmOsMemset(s_ReadBuffer, 0, sizeof(s_ReadBuffer));

	    TransactionInfo[1].Address = (hDevice->nDevAddr| 0x1);
	    TransactionInfo[1].Buf = s_ReadBuffer;
	    TransactionInfo[1].Flags = 0;
	    TransactionInfo[1].NumBytes = len;

	    i2c_status = NvOdmI2cTransaction(hDevice->hOdmI2C, TransactionInfo, 2, 400, I2C_GYROACCEL_TRANSACTION_TIMEOUT);
            if ((i % 2) == 1)
                mdelay(1);
        }

	if (i2c_status != NvOdmI2cStatus_Success) {
	    printk(" ## MPU3050 _ Give up!! NvGyroAccelI2CSetRegs failed: register %d \n", offset);

           //reboot sensors
           reboot = 1;
		
            return NV_FALSE;
	}

        NvOdmOsMemcpy(value, &s_ReadBuffer[0], len);
	return NV_TRUE;
}
コード例 #28
0
/* Send byte protocol*/
int odm_i2c_send_byte(struct odm_i2c_dev *dev, unsigned char data)
{
	NvOdmI2cTransactionInfo TransactionInfo;
	NvOdmI2cStatus I2cStatus;

	TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
	TransactionInfo.Address = dev->address;
	TransactionInfo.Buf = &data;
	TransactionInfo.NumBytes = 1;

	I2cStatus = NvOdmI2cTransaction(dev->i2c, &TransactionInfo, 
			1, dev->speed, dev->timeout);

	return (I2cStatus == NvOdmI2cStatus_Success) ? 0 : -1;
}
コード例 #29
0
int odm_i2c_receive_byte(struct odm_i2c_dev *dev,  unsigned char *data)
{
	NvOdmI2cTransactionInfo TransactionInfo;
	NvOdmI2cStatus I2cStatus;

	TransactionInfo.Flags = 0;
	TransactionInfo.Address = dev->address;
	TransactionInfo.Buf = data;
	TransactionInfo.NumBytes = 1;

	I2cStatus = NvOdmI2cTransaction(dev->i2c, &TransactionInfo, 
			1, dev->speed, dev->timeout);
	
	return (I2cStatus == NvOdmI2cStatus_Success) ? 0 : -1;
}
コード例 #30
0
ファイル: star_muic.c プロジェクト: Feeyo/LG_Optimus2X
static NvBool MUIC_Reg_Write (Muic_Device* hMuicHandle, NvU8 reg, NvU8 val)
{
#ifdef _MUIC_GPIO_I2C_
    unsigned char data[2] = {0,};
    NvBool ret = NV_FALSE;
    data[0] = reg;
    data[1] = val;

    if ( simi2c_write(hMuicHandle,0x44,data,2,1) < 1)
    {
        printk("i2c read error\n");
        return ret;
    }

    return NV_TRUE;
#else
    NvOdmI2cStatus Error;
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 arr[2];

    arr[0] = reg;        // register address
    arr[1] =val;        // u16 value (lsb-msb)

    TransactionInfo.Address = hMuicHandle->DeviceAddr;
    TransactionInfo.Buf = arr;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 2;

    do
    {
        Error = NvOdmI2cTransaction(hMuicHandle->hOdmI2c,
                &TransactionInfo,
                1,
                MUIC_I2C_SPEED_KHZ,
                MUIC_I2C_TIMEOUT);
    } while (Error == NvOdmI2cStatus_Timeout); 

    if (Error != NvOdmI2cStatus_Success)
    {
        NVODMMUIC_PRINTF(("I2C Write Failure = %d (addr=0x%x, reg=0x%x, val=0x%0x)\n", Error, 
                    hMuicHandle->DeviceAddr, reg, val));
        return NV_FALSE;
    }

    return NV_TRUE;
#endif
}