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;
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
/*
 * Set accelerometer registers.
 * [in] attrib: The register flag. 
 * [out] info: The value to be set into the register of accelerometer.
 * Returns NV_TRUE if successful, or NV_FALSE otherwise.
 */
NvBool NvOdmAccelerometerSetParameter(NvOdmAccelHandle hDevice, NvU8 attrib, NvU32 info)
{
    // Because there are only 8 bits for one accelerometer register.
    NvU8 LocalInfo = 0;
    LocalInfo = (NvU8)(info);
    // Due to the register length, we only accept the lowest 8 bits.
    NvOdmOsMemcpy(&LocalInfo, &info, sizeof(NvU8));
    //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerSetParameter +++\n");
    switch (attrib)
    {
        case XLR_CTL:
            //NvOdmOsDebugPrintf("set XLR_CTL = 0x%x\n", LocalInfo);
            hDevice->RegsWrite( hDevice, XLR_CTL, &LocalInfo, 1);
            break;
        case XLR_INTCONTROL:
            //NvOdmOsDebugPrintf("set XLR_INTCONTROL = 0x%x\n", LocalInfo);
            hDevice->RegsWrite( hDevice, XLR_INTCONTROL, &LocalInfo, 1);
            break;
        case XLR_INTCONTROL2:
            //NvOdmOsDebugPrintf("set XLR_INTCONTROL2 = 0x%x\n", LocalInfo);
            hDevice->RegsWrite( hDevice, XLR_INTCONTROL2, &LocalInfo, 1);
             break;
        case XLR_THRESHG:
            //NVODMACCELEROMETER_PRINTF("set XLR_THRESHG = 0x%x\n", LocalInfo);
            hDevice->RegsWrite( hDevice, XLR_THRESHG, &LocalInfo, 1);
            break;
        case XLR_THRESHC:
            hDevice->RegsWrite( hDevice, XLR_THRESHC, &LocalInfo, 1);
            break;
        case XLR_OFSX:
            hDevice->RegsWrite( hDevice, XLR_OFSX, &LocalInfo, 1);
            break;
        case XLR_OFSY:
            hDevice->RegsWrite( hDevice, XLR_OFSY, &LocalInfo, 1);
            break;
        case XLR_OFSZ:
            hDevice->RegsWrite( hDevice, XLR_OFSZ, &LocalInfo, 1);
            break;
        case XLR_DUR:
            hDevice->RegsWrite( hDevice, XLR_DUR, &LocalInfo, 1);
            break;
        case XLR_LATENT:
            hDevice->RegsWrite( hDevice, XLR_LATENT, &LocalInfo, 1);
            break;
        case XLR_INTVL:
            hDevice->RegsWrite( hDevice, XLR_INTVL, &LocalInfo, 1);
            break;
        default:
            //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerSetParameter DONT SUPPORT SUCH ATTRIBUTE ---\n");
            return NV_FALSE;
    }
    //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerSetParameter ---\n");
    return NV_TRUE;
}
static NvBool
NvOdmPeripheralReadPeripheral(
    NvOdmServicesI2cHandle hOdmI2c,
    NvU8 EepromInst,
    NvU8 Peripheral,
    NvU64 *pGuid,
    NvU8 *pEepromAddressListOffset,
    NvU32 *pNumAddress,
    NvOdmPeripheralClass *pClass)
{
    NvOdmI2cStatus Error;    
    NvU32 i;
    NvU8 ConnMemberIndex=0; // Offset to members in NvOdmPeripheralConnectivity
    NvU8 I2cAddr, Offset;
    NvU8 ReadBuffer[NVODM_QUERY_PERIPH_CONN_STRUCT_COMPRESSED];
    NvU8 NumAddrAndClass;

    // EepromInst*2, since 7-bit addressing
    I2cAddr = NVODM_QUERY_I2C_EEPROM_ADDRESS + (EepromInst << 1);

    /**
     * Calculate offset to pGuid in NvOdmPeripheralConnectivity Structure
     * 
     *  Offset = sizeof(eeprom Entry Header) + 
     *           sizeof(NvOdmPeripheralConnectivity)*peripheral + 
     *           pGuid offset    <-- First field, so this is 0
     */
    Offset = NVODM_QUERY_ENTRY_HEADER_SIZE + 
        sizeof(NvOdmPeripheralConnectivity)*Peripheral;

    for (i=0; i<NVODM_QUERY_PERIPH_CONN_STRUCT_COMPRESSED; i++)
    {
        Error = NvOdmPeripheralI2cRead8(
            hOdmI2c, I2cAddr, Offset, (NvU8 *)&ReadBuffer[i]);
        if (Error != NvOdmI2cStatus_Success)
        {
            return NV_FALSE;
        }
    }
    // Save pGuid entry
    NvOdmOsMemcpy(pGuid, &ReadBuffer[0], sizeof(NvU64));

    // Save EEPROM offset
    ConnMemberIndex += sizeof(NvU64); // Increment to next member
    *pEepromAddressListOffset = ReadBuffer[ConnMemberIndex];

    // Save pNumAddress & Class
    ConnMemberIndex += sizeof(NvU8); // Increment to next member
    NumAddrAndClass = ReadBuffer[ConnMemberIndex];
    *pNumAddress = (NvU32)((NumAddrAndClass >> 3) & 0x0000001F);
    *pClass = (NvOdmPeripheralClass)(NumAddrAndClass & 0x00000007);

    return NV_TRUE;
}
Esempio n. 7
0
static NvBool EETI_Suspend(NvOdmTouchDeviceHandle hDevice) {
    NvOdmTouchRawI2cData i2c_data;
    static const NvS8 eeti_sleep_cmd[] = {0x03, 0x05, 0x0a, 0x03, 0x03, 0x3f, 0x02, 0x00, 0x00, 0x00};

    NvOdmOsMemcpy(i2c_data.datum, eeti_sleep_cmd, 10);
    i2c_data.data_len = 10;

    EETI_RawI2cWrite(hDevice, &i2c_data);

    return NV_TRUE;
}
Esempio n. 8
0
static NvBool EETI_GetSample (EETI_TouchDevice* hTouch, NvOdmTouchCoordinateInfo* coord) {
    NvU8 Finger[EETI_MAX_READ_BYTES] = {0};

    NvU32 pinValue;
    NvU8 indx = 0;
    NvU8 i = 0;
    NvBool retval = NV_TRUE;
    NvU32 count = 0;
    NvOdmTouchRawI2cData *i2c_data = NULL;

    coord->fingerstate = NvOdmTouchSampleIgnore;
    coord->additionalInfo.Fingers = 0;
    i2c_data = (NvOdmTouchRawI2cData *)coord->pextrainfo;
    retval = EETI_GetTouchReport(hTouch, Finger, &count);

    if (retval == NV_FALSE)
        return retval;

    switch (Finger[0]) {
    case 0x01:
        break;
    case 0x03:
        if (i2c_data != NULL) {
            NvOdmOsMemcpy(i2c_data->datum, Finger, count);
            i2c_data->data_len = count;
        }
        break;
    case 0x04:
        indx = (Finger[1] & 0x7c) >> 2;
        tempReport[indx].fingerId = indx;
        tempReport[indx].state = Finger[1] & 0x1;
        tempReport[indx].x = ((NvU16)Finger[3] << 8) | (NvU16)Finger[2]; 
        tempReport[indx].y = ((NvU16)Finger[5] << 8) | (NvU16)Finger[4]; 
        tempReport[indx].z = (NvU16)Finger[6];
        coord->additionalInfo.Fingers = 4;
        coord->xcoord = coord->additionalInfo.multi_XYCoords[indx][0] = tempReport[indx].x;
        coord->ycoord = coord->additionalInfo.multi_XYCoords[indx][1] = tempReport[indx].y;
        coord->additionalInfo.Pressure[indx] = tempReport[indx].state;
#if 0
        NvOdmOsPrintf("indx = %d, x=%d, y=%d, z=%d\n",
                      indx,
                      coord->additionalInfo.multi_XYCoords[indx][0],
                      coord->additionalInfo.multi_XYCoords[indx][1],
                      coord->additionalInfo.Pressure[indx]);
#endif
        break;
    default:
        break;
    };

    return NV_TRUE;
}
Esempio n. 9
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;
}
NvBool
NvOdmMouseSendRequest(
    NvOdmMouseDeviceHandle hDevice, 
    NvU32 cmd, 
    NvU32 ExpectedResponseSize,
    NvU32 *NumPayLoad, 
    NvU8 *PayLoadBuf)
{
    NvError e;
    NvEcRequest *pRequest = hDevice->pRequest;
    NvEcResponse *pResponse = hDevice->pResponse;
    NvU32 Index = 0;

    do
    {
        // fill up request structure
        pRequest->PacketType = NvEcPacketType_Request;
        pRequest->RequestType = NvEcRequestResponseType_AuxDevice;
        pRequest->RequestSubtype = 
            ((NvEcRequestResponseSubtype) 
             (NV_DRF_NUM(NVEC,SUBTYPE,AUX_PORT_ID,hDevice->ValidMousePorts[Index]))) |
            ((NvEcRequestResponseSubtype) 
             NvEcAuxDeviceSubtype_SendCommand);
        pRequest->NumPayloadBytes = 2;
        pRequest->Payload[0] = cmd; // set the command
        pRequest->Payload[1] = ExpectedResponseSize;

        // Request to EC
        e = NvEcSendRequest(hDevice->hEc, pRequest, pResponse, sizeof(*pRequest),
                        sizeof(*pResponse));
        
        if (NvSuccess != e)
        {
            NVODMMOUSE_PRINTF(("NvEcSendRequest failed !!"));
            return NV_FALSE;
        }

        if (NvEcStatus_Success != pResponse->Status)
        {
            NVODMMOUSE_PRINTF(("EC response failed !!"));
            return NV_FALSE;
        }

        // store/process the Mouse response and return to the client driver
        *NumPayLoad = pResponse->NumPayloadBytes;
        NvOdmOsMemcpy(PayLoadBuf, &pResponse->Payload, *NumPayLoad);
    } while (hDevice->ValidMousePorts[++Index] != INVALID_MOUSE_PORT_ID);

    return NV_TRUE;
}
Esempio n. 11
0
NvBool EETI_GetCalibrationData(NvOdmTouchDeviceHandle hDevice, NvU32 NumOfCalibrationData, NvS32* pRawCoordBuffer) {
#if EETI_SCREEN_ANGLE
    //Portrait
    static const NvS32 RawCoordBuffer[] = {2054, 3624, 3937, 809, 3832, 6546, 453, 6528, 231, 890};
#else
    //Landscape
    static NvS32 RawCoordBuffer[] = {2054, 3624, 3832, 6546, 453, 6528, 231, 890, 3937, 809};
#endif

    if (NumOfCalibrationData*2 != (sizeof(RawCoordBuffer)/sizeof(NvS32))) {
        NVODMTOUCH_PRINTF(("WARNING: number of calibration data isn't matched\n"));
        return NV_FALSE;
    }

    NvOdmOsMemcpy(pRawCoordBuffer, RawCoordBuffer, sizeof(RawCoordBuffer));

    return NV_TRUE;
}
NvBool NvOdmMouseGetEventInfo(
    NvOdmMouseDeviceHandle hDevice,
    NvU32 *NumPayLoad,
    NvU8 *PayLoadBuf)
{
    NvError Status = NvSuccess;

    // Retrive the event info
    Status = NvEcGetEvent(hDevice->hEcEventRegister,
                          hDevice->pEvent,
                          sizeof(NvEcEvent));

    if (Status != NvSuccess)
        return NV_FALSE;

    /**
     * if compression is enabled, latch the first data byte whenever a full-size
     * packet is received; then insert the latched data whenever a compressed
     * packet is seen.
     */
    if (hDevice->CompressionEnabled && hDevice->pEvent->NumPayloadBytes == 3)
    {
        hDevice->CompressionState = hDevice->pEvent->Payload[0];
    }
    
    /**
     * fill in the payload and number of bytes
     */
    if (hDevice->CompressionEnabled && hDevice->pEvent->NumPayloadBytes == 2)
    {
        // compressed packet, so insert latched data at beginning
        *NumPayLoad = 3;
        PayLoadBuf[0] = hDevice->CompressionState;
        PayLoadBuf[1] = hDevice->pEvent->Payload[0];
        PayLoadBuf[2] = hDevice->pEvent->Payload[1];
    }
    else
    {
        *NumPayLoad = hDevice->pEvent->NumPayloadBytes;
        NvOdmOsMemcpy(PayLoadBuf, hDevice->pEvent->Payload, *NumPayLoad);
    }

    return NV_TRUE;
}
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;
}
static void GpioInterruptHandler(void *arg)
{
    NvU32 pinValue;
    NvU8 ret;
    NvU8 buffer[SENSOR_DATA_SIZE];
    NvU8 i;
    NvOdmEcompassHandle hDevice =  (NvOdmEcompassHandle)arg;
    NvOdmGpioGetState(hDevice->hGpioINT, hDevice->hPinINT, &pinValue);

    if (pinValue == 1)
    {
        ret=ReadReg(hDevice, AK8975_REG_ST1, buffer, SENSOR_DATA_SIZE);
        if (ret<0) {
            NVODMECOMPASS_PRINTF(("AKM8975 compass driver: I2C failed\n"));
            return;
        }
        /* Check ST bit */
        if ((buffer[0] & 0x01) != 0x01)
        {
            NVODMECOMPASS_PRINTF(("AKM8975 akm8975_work_func: ST is not set\n"));
            return;
        }
        /* Check ST2 bit */
        if (((buffer[7]&0x04)==0x04)||((buffer[7]&0x08)==0x08))
        {
            NVODMECOMPASS_PRINTF(("AKM8975 akm8975_work_func: Data is Fail\n"));
            return;
        }
        NvOdmOsMemcpy(ecompass_buffer,buffer,SENSOR_DATA_SIZE);
#if 0
        NVODMECOMPASS_PRINTF(("\n"));
        NVODMECOMPASS_PRINTF((" GPIO handle :\n"));
        for (i=0; i<SENSOR_DATA_SIZE; i++) {
            NVODMECOMPASS_PRINTF((" Reg %d : [%02x]\n",i,ecompass_buffer[i]));
        }
#endif
        NvOdmOsSemaphoreSignal(hDevice->SemaphoreForINT);
    }
    NvOdmGpioInterruptDone(hDevice->hGpioInterrupt);
    return;
}
// setting register
static NvBool Synaptics_OneTouch_WriteRegisterMulti(Synaptics_OneTouch_Device* hTouch, NvU8* buffer, NvU32 len)
{
	int i=0;
	NvOdmI2cStatus Error = NvOdmI2cStatus_Timeout;
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU8 *arr;

    arr = (NvU8*)NvOdmOsAlloc(len);
    if(arr ==NULL)
    {
    	NVODMTOUCH_PRINTF(("[ONETOUCH] cannot alloc memory (len=%d)\n",len));
		return NV_FALSE;
    }

    NvOdmOsMemcpy(&arr[0], buffer, len);// register address
    
    TransactionInfo.Address = hTouch->DeviceAddr;
    TransactionInfo.Buf = arr;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = len;
    
	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);
	}
    
    NvOdmOsFree(arr);
    
    if (Error != NvOdmI2cStatus_Success)
    {
        NVODMTOUCH_PRINTF(("[ONETOUCH] I2C Write Failure = %d (addr=0x%x)\n", Error, hTouch->DeviceAddr));
        return NV_FALSE;
    }
    
    return NV_TRUE;
}
Esempio n. 16
0
static bool star_accel_i2c_read_data( star_accel_device *accel, unsigned char reg, unsigned char* data, unsigned char len )
{
	NvOdmI2cStatus i2c_status;
    NvOdmI2cTransactionInfo info[2];
    unsigned char* transfer_data;

	transfer_data = (unsigned char*)NvOdmOsAlloc(len);

	#if STAR_ACCEL_DEBUG
	//printk("address = %#x\n", g_accel->i2c_address);
	#endif

    info[0].Address = g_accel->i2c_address;
    info[0].Buf = &reg;
    info[0].Flags = NVODM_I2C_IS_WRITE;
    info[0].NumBytes = 1;

    info[1].Address = ( g_accel->i2c_address | 0x01 );
    info[1].Buf = transfer_data;
    info[1].Flags = 0;
    info[1].NumBytes = len;

    do{
        i2c_status = NvOdmI2cTransaction( g_accel->h_gen2_i2c, info, 2, 400, 1000 );
    }while( i2c_status == NvOdmI2cStatus_Timeout );

    if( i2c_status != NvOdmI2cStatus_Success )
    {
        printk("[star driver] %s : i2c transaction error(Number= %d)!\n",__func__, i2c_status);
        goto err;
    }
    NvOdmOsMemcpy( data, transfer_data, len );
    NvOdmOsFree(transfer_data);
    return true;
err:
    NvOdmOsFree(transfer_data);
    return false;

}
Esempio n. 17
0
NvBool NvGyroAccelI2CSetRegs(NvOdmGyroAccelHandle hDevice, NvU8 offset, NvU8* value, NvU32 len)
{
	int i;  
        NvOdmI2cStatus i2c_status = NvOdmI2cStatus_Timeout;
	NvOdmI2cTransactionInfo TransactionInfo;

	if ((NULL == hDevice) || (NULL == value) || (len > 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;
	    NvOdmOsMemcpy(&s_WriteBuffer[1], value, len);

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

	    i2c_status = NvOdmI2cTransaction(hDevice->hOdmI2C, &TransactionInfo, 1, 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;
	}

	return NV_TRUE;
}
Esempio n. 18
0
/*
 * Set accelerometer registers.
 * [in] attrib: The register flag.
 * [out] info: The value to be set into the register of accelerometer.
 * Returns NV_TRUE if successful, or NV_FALSE otherwise.
 */
NvBool NvOdmGyroAccelSetParameter(NvOdmGyroAccelHandle hDevice, NvU8 attrib, NvU32 info)
{
	// Because there are only 8 bits for one accelerometer register.
	NvU8 LocalInfo = 0;
	LocalInfo = (NvU8)(info);
	// Due to the register length, we only accept the lowest 8 bits.
	NvOdmOsMemcpy(&LocalInfo, &info, sizeof(NvU8));
#if DEBUG_NV_ACCEL
	printk(" ## MPU3050 : %s attrib %x  =>  ", __FUNCTION__, attrib) ;
#endif

	switch (attrib) {
		/* case KIONIX_ACCEL_I2C_CTRL_REG1:
		   hDevice->RegsWrite( hDevice, KIONIX_ACCEL_I2C_CTRL_REG1, &LocalInfo, 1);
#if DEBUG_NV_ACCEL
printk("[%s] 1:  \n "__FUNCTION__) ;
#endif
break;*/
		default:
			printk("NV ODM ACCELEROMETER NvOdmGyroAccelSetParameter DONT SUPPORT SUCH ATTRIBUTE ---\n");
			return NV_FALSE;
	}
	return NV_TRUE;
}
Esempio n. 19
0
/*
 * Get acceleromter registers.
 * [in] attrib: The regsiter flag. 
 * [out] info: The value from register of accelerometer.
 * Returns NV_TRUE if successful, or NV_FALSE otherwise.
 */
NvBool NvOdmAccelerometerGetParameter(NvOdmAccelHandle hDevice, NvU8 attrib, NvU32* info)
{
    NvU8 LocalInfo = 0;
    NvS32 temp;

    //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerGetParameter +++\n");
    switch (attrib)
    {
        case XLR_DEVID:
            hDevice->RegsRead( hDevice, XLR_DEVID, &LocalInfo, 1);
            break;
        case XLR_WHOAMI:
            hDevice->RegsRead( hDevice, XLR_WHOAMI, &LocalInfo, 1);
            break;
        case XLR_STATUS:
            hDevice->RegsRead( hDevice, XLR_STATUS, &LocalInfo, 1);
            break;
        case XLR_INTSOURCE:
            hDevice->RegsRead( hDevice, XLR_INTSOURCE, &LocalInfo, 1);
            break;
        case XLR_CTL:
            hDevice->RegsRead( hDevice, XLR_CTL, &LocalInfo, 1);
            break;
        case XLR_INTCONTROL:
            hDevice->RegsRead( hDevice, XLR_INTCONTROL, &LocalInfo, 1);
            break;
        case XLR_INTCONTROL2:
            hDevice->RegsRead( hDevice, XLR_INTCONTROL2, &LocalInfo, 1);
            break;
        case XLR_DATAX:
            // Because it is a signed char.
            hDevice->RegsRead( hDevice, XLR_DATAX, &LocalInfo, 1);
            temp = (LocalInfo<128)?LocalInfo:(LocalInfo-256);
            NvOdmOsMemcpy(info, &temp, sizeof(NvU32));
            //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerGetParameter ---\n");
            return NV_TRUE;
        case XLR_DATAY:
            // Because it is a signed char.
            hDevice->RegsRead( hDevice, XLR_DATAY, &LocalInfo, 1);
            temp = (LocalInfo<128)?LocalInfo:(LocalInfo-256);
            NvOdmOsMemcpy(info, &temp, sizeof(NvU32));
            //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerGetParameter ---\n");
            return NV_TRUE;
        case XLR_DATAZ:
            // Because it is a signed char.
            hDevice->RegsRead( hDevice, XLR_DATAZ, &LocalInfo, 1);
            temp = (LocalInfo<128)?LocalInfo:(LocalInfo-256);
            NvOdmOsMemcpy(info, &temp, sizeof(NvU32));
            //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerGetParameter ---\n");
            return NV_TRUE;
        case XLR_MOREINFO:
            hDevice->RegsRead( hDevice, XLR_MOREINFO, &LocalInfo, 1);
            break;
        case XLR_THRESHG:
            hDevice->RegsRead( hDevice, XLR_THRESHG, &LocalInfo, 1);
            break;
        case XLR_THRESHC:
            hDevice->RegsRead( hDevice, XLR_THRESHC, &LocalInfo, 1);
            break;
        case XLR_OFSX:
            hDevice->RegsRead( hDevice, XLR_OFSX, &LocalInfo, 1);
            break;
        case XLR_OFSY:
            hDevice->RegsRead( hDevice, XLR_OFSY, &LocalInfo, 1);
            break;
        case XLR_OFSZ:
            hDevice->RegsRead( hDevice, XLR_OFSZ, &LocalInfo, 1);
            break;
        case XLR_DUR:
            hDevice->RegsRead( hDevice, XLR_DUR, &LocalInfo, 1);
            break;
        case XLR_LATENT:
            hDevice->RegsRead( hDevice, XLR_LATENT, &LocalInfo, 1);
            break;
        case XLR_INTVL:
            hDevice->RegsRead( hDevice, XLR_INTVL, &LocalInfo, 1);
            break;
        case XLR_SCALE:
            hDevice->RegsRead( hDevice, XLR_CTL, &LocalInfo, 1);            
            if ((LocalInfo&(0x01)) == 0)
            {
                LocalInfo = 2;
            }
            else
            {
                LocalInfo = 8;
            }
            break;
        case XLR_ROTATE:
            *info = 1;
            break;
        case XLR_GYRO:
            *info = 0;
            break;
        default:
            //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerGetParameter DONT SUPPORT SUCH ATTRIBUTE ---\n");
            return NV_FALSE;
    }
    *info = LocalInfo;
    //NVODMACCELEROMETER_PRINTF("NV ODM ACCELEROMETER NvOdmAccelerometerGetParameter ---\n");
    return NV_TRUE;
}
Esempio n. 20
0
NvBool EETI_Open (NvOdmTouchDeviceHandle* hDevice) {
    EETI_TouchDevice* hTouch;
    NvU32 i;
    NvU32 found = 0;
    NvU32 GpioPort = 0;
    NvU32 GpioPin = 0;
    NvU32 I2cInstance = 0;



    const NvOdmPeripheralConnectivity *pConnectivity = NULL;

    hTouch = NvOdmOsAlloc(sizeof(EETI_TouchDevice));
    if (!hTouch) return NV_FALSE;

    NvOdmOsMemset(hTouch, 0, sizeof(EETI_TouchDevice));
    NvOdmOsMemset(tempReport, 0, sizeof(struct fingerReport_s) * 4);

    /* set function pointers */
    InitOdmTouch(&hTouch->OdmTouch);

    pConnectivity = NvOdmPeripheralGetGuid(EETI_TOUCH_DEVICE_GUID);
    if (!pConnectivity) {
        NVODMTOUCH_PRINTF(("NvOdm Touch : pConnectivity is NULL Error \n"));
        goto fail;
    }

    if (pConnectivity->Class != NvOdmPeripheralClass_HCI) {
        NVODMTOUCH_PRINTF(("NvOdm Touch : didn't find any periperal in discovery query for touch device Error \n"));
        goto fail;
    }

    for (i = 0; i < pConnectivity->NumAddress; i++) {
        switch (pConnectivity->AddressList[i].Interface) {
        case NvOdmIoModule_I2c:
            hTouch->DeviceAddr = (pConnectivity->AddressList[i].Address << 1);
            I2cInstance = pConnectivity->AddressList[i].Instance;
            found |= 1;
            break;
        case NvOdmIoModule_Gpio:
            GpioPort = pConnectivity->AddressList[i].Instance;
            GpioPin = pConnectivity->AddressList[i].Address;
            found |= 2;
            break;
        case NvOdmIoModule_Vdd:
            hTouch->VddId = pConnectivity->AddressList[i].Address;
            found |= 4;
            break;
        default:
            break;
        }
    }

    if ((found & 3) != 3) {
        NVODMTOUCH_PRINTF(("NvOdm Touch : peripheral connectivity problem \n"));
        goto fail;
    }

    if ((found & 4) != 0) {
        if (NV_FALSE == EETI_PowerOnOff(&hTouch->OdmTouch, 1))
            goto fail;
    } else {
        hTouch->VddId = 0xFF; 
    }

    hTouch->hOdmI2c = NvOdmI2cOpen(NvOdmIoModule_I2c, I2cInstance);
    if (!hTouch->hOdmI2c) {
        NVODMTOUCH_PRINTF(("NvOdm Touch : NvOdmI2cOpen Error \n"));
        goto fail;
    }

    hTouch->hGpio = NvOdmGpioOpen();

    if (!hTouch->hGpio) {
        NVODMTOUCH_PRINTF(("NvOdm Touch : NvOdmGpioOpen Error \n"));
        goto fail;
    }

    hTouch->hPin = NvOdmGpioAcquirePinHandle(hTouch->hGpio, GpioPort, GpioPin);
    if (!hTouch->hPin) {
        NVODMTOUCH_PRINTF(("NvOdm Touch : Couldn't get GPIO pin \n"));
        goto fail;
    }

    NvOdmGpioConfig(hTouch->hGpio,
                    hTouch->hPin,
                    NvOdmGpioPinMode_InputData);

    NvOdmGpioGetState(hTouch->hGpio, hTouch->hPin, &i);

    /* set default capabilities */
    NvOdmOsMemcpy(&hTouch->Caps, &EETI_Capabilities, sizeof(NvOdmTouchCapabilities));

    /* set default I2C speed */
    hTouch->I2cClockSpeedKHz = EETI_I2C_SPEED_KHZ;
#if 1
    if (EETI_ProbeTouchDevice (hTouch) != NV_TRUE) {
        NvOdmOsPrintf("NvOdm Touch : Multitouch detection failure \n");
        goto fail;
    }
#endif
    hTouch->Caps.XMaxPosition = 32767;
    hTouch->Caps.YMaxPosition = 32767;

    *hDevice = &hTouch->OdmTouch;
    return NV_TRUE;

    fail:
    EETI_Close(&hTouch->OdmTouch);
    return NV_FALSE;
}
static NvBool
ReadReg(
    NvOdmEcompassHandle hDevice,
    NvU8 RegAddr,
    NvU8* value,
    NvU32 len)
{
	#if 0
    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;
	#else
	NvU32 i;
	NvOdmI2cStatus  status = NvOdmI2cStatus_Success;
	NvOdmI2cTransactionInfo TransactionInfo[2];
	
	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;
    }
	
	for (i=0; i<NVODMECOMPASS_I2C_RETRY_CNT; i++)
	{
		NvU32 TransactionCount = 0;
		
		s_WriteBuffer[0] = RegAddr;
		TransactionInfo[TransactionCount].Address = hDevice->nDevAddr;
		TransactionInfo[TransactionCount].Buf = &s_WriteBuffer[0];
		TransactionInfo[TransactionCount].Flags =
			NVODM_I2C_IS_WRITE | NVODM_I2C_USE_REPEATED_START;
		TransactionInfo[TransactionCount++].NumBytes = 1;
		
		s_ReadBuffer[0] = 0;
		TransactionInfo[TransactionCount].Address = (hDevice->nDevAddr | 0x1);
		TransactionInfo[TransactionCount].Buf = &s_ReadBuffer[0];
		TransactionInfo[TransactionCount].Flags = 0;
		TransactionInfo[TransactionCount++].NumBytes = len;	

		status = NvOdmI2cTransaction(hDevice->hOdmI2C, &TransactionInfo[0],
			TransactionCount, NVODMECOMPASS_I2C_SPEED_KHZ, NV_WAIT_INFINITE);	
		
		if (status == NvOdmI2cStatus_Success)
		{
			NvOdmOsMemcpy(value, &s_ReadBuffer[0], len);
			return NV_TRUE;
		}
	}
	
    // Transaction Error
    switch (status)
    {
        case NvOdmI2cStatus_Timeout:
            NVODMECOMPASS_PRINTF(("NvOdmEcompassI2cRead Failed: Timeout\n"));
            break;
        case NvOdmI2cStatus_SlaveNotFound:
        default:
            NVODMECOMPASS_PRINTF(("NvOdmEcompassI2cRead Failed: SlaveNotFound\n"));
            break;
    }
    return NV_FALSE;	
	#endif
}