NvBool NvOdmEcompassOpen(NvOdmEcompassHandle* hDevice)
{
	NvU32 i;
	NvOdmEcompassHandle	hEcompass;
	NvOdmIoModule IoModule = NvOdmIoModule_I2c;
	const NvOdmPeripheralConnectivity *pConnectivity;
	NvBool FoundGpio = NV_FALSE, FoundI2cModule = NV_FALSE;

	hEcompass = NvOdmOsAlloc(sizeof(NvOdmEcompass));
	if (hEcompass == NULL)
	{
		NVODMECOMPASS_PRINTF(("AKM8975 compass driver: Open fail\n"));
		return NV_FALSE;
	}
	NvOdmOsMemset(hEcompass,0,sizeof(NvOdmEcompass));
	hEcompass->nBusType = NV_ECOMPASS_BUS_I2C;
	
	// Info of ecompass with current setting
	
    pConnectivity = (NvOdmPeripheralConnectivity*)NvOdmPeripheralGetGuid(
                        ECOMPASS_GUID);
    if (!pConnectivity)
    {
        NvOdmOsDebugPrintf(("NvOdmPeripheralGetGuid doesn't detect\
           AKM8975/B device\n"));
        goto error;
    }
예제 #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;
}
NvOdmUsbUlpiHandle NvOdmUsbUlpiOpen(NvU32 Instance)
{
    NvOdmUsbUlpi*pDevice = NULL;
    NvU32 ClockInstances[MAX_CLOCKS];
    NvU32 ClockFrequencies[MAX_CLOCKS];
    NvU32 NumClocks;

    pDevice = NvOdmOsAlloc(sizeof(NvOdmUsbUlpi));
    if(pDevice == NULL)
		return NULL;
    
    if(!NvOdmExternalClockConfig(SMSC3317GUID, NV_FALSE, ClockInstances,
					ClockFrequencies, &NumClocks))
    {
        NV_DRIVER_TRACE (("ERROR NvOdmUsbUlpiOpen: "
				"NvOdmExternalClockConfig fail\n"));
        goto ExitUlpiOdm;
    }
    NvOdmOsSleepMS(10);

    if (!s_hGpio)
        s_hGpio = NvOdmGpioOpen();
    if (!s_hGpio)
    {
        NV_DRIVER_TRACE (("ERROR NvOdmUsbUlpiOpen: "
				"Not able to open gpio handle\n"));
        goto ExitUlpiOdm;
    }

    if (!s_hResetPin)
        s_hResetPin = NvOdmGpioAcquirePinHandle(s_hGpio, ULPI_RESET_PORT,
							ULPI_RESET_PIN);
    if (!s_hResetPin)
    {
        NvOdmGpioClose(s_hGpio);
        s_hGpio = NULL;
        NV_DRIVER_TRACE (("ERROR NvOdmGpioAcquirePinHandle: "
					"Not able to Acq pinhandle\n"));
        goto ExitUlpiOdm;
    }

    // Pull high on RESETB ( 22nd pin of smsc3315) 
    // config as out put pin
    NvOdmGpioConfig(s_hGpio,s_hResetPin, NvOdmGpioPinMode_Output);
    // Set low to write high on ULPI_RESETB pin
    NvOdmGpioSetState(s_hGpio, s_hResetPin, 0x01);
    NvOdmGpioSetState(s_hGpio, s_hResetPin, 0x0);
    NvOdmOsSleepMS(5);
    NvOdmGpioSetState(s_hGpio, s_hResetPin, 0x01);

    pDevice->CurrentGUID = SMSC3317GUID;
    return pDevice;

ExitUlpiOdm:
    NvOdmOsFree(pDevice);
    return NULL;
}
NvBool NvOdmBatteryDeviceOpen(NvOdmBatteryDeviceHandle *hDevice,
                              NvOdmOsSemaphoreHandle *hOdmSemaphore)
{
    NvOdmBatteryDevice *pBattContext = NULL;
    NvU32 i;
    NvError NvStatus = NvError_Success;
    NvU32 PinState;

    pBattContext = NvOdmOsAlloc(sizeof(NvOdmBatteryDevice));
    if (!pBattContext)
    {
        NvOsDebugPrintf(("NvOdmOsAlloc failed to allocate pBattContext."));
        return NV_FALSE;
    }

    NvOdmOsMemset(pBattContext, 0, sizeof(NvOdmBatteryDevice));
    NvStatus = NvRmOpen(&pBattContext->hRm, 0);
    if (NvStatus != NvError_Success)
        goto Cleanup;

    NvStatus = NvRmGpioOpen(pBattContext->hRm, &pBattContext->hGpio);
    if (NvStatus != NvError_Success)
        goto Cleanup;

    pBattContext->pGpioPinInfo = NvOdmQueryGpioPinMap(
                                     NvOdmGpioPinGroup_Battery,
                                     0,
                                     &pBattContext->PinCount);
    if (pBattContext->pGpioPinInfo == NULL)
    {
        goto Cleanup;
    }
    for (i = 0; i < pBattContext->PinCount; i++ )
    {
        /*Need the pin 1 to be set to Output for charging of the battery. */
        if (i == 1)
        {
            NvRmGpioAcquirePinHandle(
                        pBattContext->hGpio,
                        pBattContext->pGpioPinInfo[i].Port,
                        pBattContext->pGpioPinInfo[i].Pin,
                        &pBattContext->hPin);
            if (!pBattContext->hPin)
            {
                goto Cleanup;
            }
            NvRmGpioConfigPins(pBattContext->hGpio, &pBattContext->hPin, 1, NvRmGpioPinMode_Output);
            PinState = NvRmGpioPinState_Low;
            NvRmGpioWritePins(pBattContext->hGpio, &pBattContext->hPin, &PinState,1);
        }
    }
    *hDevice = pBattContext;
    return NV_TRUE;
Cleanup:
    NvOdmBatteryDeviceClose(pBattContext);
    return NV_FALSE;
}
예제 #5
0
NvOdmUartHandle NvOdmUartOpen(NvU32 Instance)
{
    NvOdmUart *pDevice = NULL;
    NvOdmPeripheralConnectivity *pConnectivity;
    NvU32 NumOfGuids = 1;
    NvU64 guid;
    NvU32 searchVals[2];
    const NvOdmPeripheralSearch searchAttrs[] =
    {
        NvOdmPeripheralSearch_IoModule,
        NvOdmPeripheralSearch_Instance,
    };
    
    searchVals[0] =  NvOdmIoModule_Uart;
    searchVals[1] =  Instance;

    NumOfGuids = NvOdmPeripheralEnumerate(
                                                    searchAttrs,
                                                    searchVals,
                                                    2,
                                                    &guid,
                                                    NumOfGuids); 

    pConnectivity = (NvOdmPeripheralConnectivity *)NvOdmPeripheralGetGuid(guid);
    if (pConnectivity == NULL)
        goto ExitUartOdm;
    
    pDevice = NvOdmOsAlloc(sizeof(NvOdmUart));
    if(pDevice == NULL)
        goto ExitUartOdm;
    
    pDevice->hPmu = NvOdmServicesPmuOpen();
    if(pDevice->hPmu == NULL)
    {
        goto ExitUartOdm;
    }

    // Switch On UART Interface

    pDevice->pConnectivity = pConnectivity;
   
    return pDevice;

ExitUartOdm:
    NvOdmOsFree(pDevice);
    pDevice = NULL;
    
    return NULL;
}
// 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;
}
예제 #7
0
NvOdmUsbUlpiHandle NvOdmUsbUlpiOpen(NvU32 Instance)
{
    NvOdmUsbUlpi *pDevice = NULL;
    NvU32 ClockInstances[MAX_CLOCKS];
    NvU32 ClockFrequencies[MAX_CLOCKS];
    NvU32 NumClocks;
    NvOdmServicesGpioHandle hGpio;
    NvOdmGpioPinHandle hResetPin;
    NvU32 Port = NVODM_PORT('v');
    NvU32 Pin = 1;

    pDevice = NvOdmOsAlloc(sizeof(NvOdmUsbUlpi));
    if (pDevice == NULL)
        return NULL;

    if(!NvOdmExternalClockConfig(SMSC3317GUID, NV_FALSE,
                                 ClockInstances, ClockFrequencies, &NumClocks))
    {
        NvOdmOsDebugPrintf("NvOdmUsbUlpiOpen: NvOdmExternalClockConfig fail\n");
        goto ExitUlpiOdm;
    }
    NvOdmOsSleepMS(10);
    // Pull high on RESETB ( 22nd pin of smsc3315)
    hGpio = NvOdmGpioOpen();
    hResetPin = NvOdmGpioAcquirePinHandle(hGpio, Port, Pin);
    // config as out put pin
    NvOdmGpioConfig(hGpio,hResetPin, NvOdmGpioPinMode_Output);
    // Set low to write high on ULPI_RESETB pin
    NvOdmGpioSetState(hGpio, hResetPin, 0x01);
    NvOdmGpioSetState(hGpio, hResetPin, 0x0);
    NvOdmOsSleepMS(5);
    NvOdmGpioSetState(hGpio, hResetPin, 0x01);

    pDevice->CurrentGUID = SMSC3317GUID;
    return pDevice;

ExitUlpiOdm:
    NvOdmOsFree(pDevice);
    return NULL;
}
예제 #8
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;

}
NvBool
NvOdmMouseDeviceOpen(
    NvOdmMouseDeviceHandle *hDevice)
{
    NvOdmMouseDevice *hMouseDev = NULL;
    NvBool ret = NV_FALSE;
    NvU32 InstanceId = 0, count = 0, MousePort = 0, i = 0;
#if WAKE_FROM_MOUSE
    NvError err = NvError_Success;
    NvEcRequest Request = {0};
    NvEcResponse Response = {0};
#endif

    // Allocate memory for request type structure
    hMouseDev = (NvOdmMouseDevice *)NvOdmOsAlloc(sizeof(NvOdmMouseDevice));
    if (!hMouseDev)
    {
        ret = NV_FALSE;
        NVODMMOUSE_PRINTF(("NvOdmOsAlloc failed to allocate hMouseDev!!"));
        goto fail_safe;
    }
    NvOdmOsMemset(hMouseDev, 0, sizeof(NvOdmMouseDevice));

    // open channel to the EC
    if ((NvEcOpen(&hMouseDev->hEc, InstanceId)) != NvSuccess)
    {
        ret = NV_FALSE;
        NVODMMOUSE_PRINTF(("NvEcOpen failed !!"));
        goto fail_safe;
    }

    hMouseDev->pRequest = NULL;
    hMouseDev->pResponse = NULL;
    hMouseDev->pEvent = NULL;
    hMouseDev->CompressionEnabled = NV_FALSE;
    hMouseDev->CompressionState = 0x0;

    do
    {
        hMouseDev->ValidMousePorts[count] = INVALID_MOUSE_PORT_ID;
        count++;
    } while (count <= MAX_NUM_MOUSE_PORTS);

    // Allocate memory for request type structure
    hMouseDev->pRequest = NvOdmOsAlloc(sizeof(NvEcRequest));
    if (!hMouseDev->pRequest)
    {
        ret = NV_FALSE;
        NVODMMOUSE_PRINTF(("NvOdmOsAlloc failed to allocate pRequest!!"));
        goto fail_safe;
    }
    NvOdmOsMemset(hMouseDev->pRequest, 0, sizeof(NvEcRequest));

    // Allocate memory for response type structure
    hMouseDev->pResponse = NvOdmOsAlloc(sizeof(NvEcResponse));
    if (!hMouseDev->pResponse)
    {
        ret = NV_FALSE;
        NVODMMOUSE_PRINTF(("NvOdmOsAlloc failed to allocate pResponse!!"));
        goto fail_safe;
    }
    NvOdmOsMemset(hMouseDev->pResponse, 0, sizeof(NvEcResponse));

    // Allocate memory for event type structure
    hMouseDev->pEvent = NvOdmOsAlloc(sizeof(NvEcEvent));
    if (!hMouseDev->pEvent)
    {
        ret = NV_FALSE;
        NVODMMOUSE_PRINTF(("NvOdmOsAlloc failed to allocate pEvent!!"));
        goto fail_safe;
    }
    NvOdmOsMemset(hMouseDev->pEvent, 0, sizeof(NvEcEvent));

    MousePort = MOUSE_PS2_PORT_ID_0;
    count = CMD_MAX_RETRIES + 1; i = 0;
    while (count--)
    {
        // fill up request structure
        Request.PacketType = NvEcPacketType_Request;
        Request.RequestType = NvEcRequestResponseType_AuxDevice;
        Request.RequestSubtype = 
            ((NvEcRequestResponseSubtype) 
             (NV_DRF_NUM(NVEC,SUBTYPE,AUX_PORT_ID,MousePort))) |
            ((NvEcRequestResponseSubtype) 
             NvEcAuxDeviceSubtype_SendCommand);
        Request.NumPayloadBytes = 2;
        Request.Payload[0] = 0xFF; // set the reset command
        Request.Payload[1] = 3;

        // Request to EC
        err = NvEcSendRequest(hMouseDev->hEc, &Request, &Response, sizeof(Request),
                        sizeof(Response));

        if (NvSuccess != err)
        {
            NVODMMOUSE_PRINTF(("NvEcSendRequest failed !!"));
            break;
        }

        // mouse not found
        if (NvEcStatus_Success != Response.Status)
        {
            NVODMMOUSE_PRINTF(("EC response failed !!"));
            if (MousePort != MOUSE_PS2_PORT_ID_1)
            {
                count = CMD_MAX_RETRIES + 1;
                MousePort = MOUSE_PS2_PORT_ID_1;
                continue;
            }
            break;
        }

        if (Response.NumPayloadBytes != 3)
            continue;

        // success
        if (Response.Payload[0] == 0xFA)
        {
            hMouseDev->ValidMousePorts[i] = MousePort;
            if (MousePort != MOUSE_PS2_PORT_ID_1)
            {
                count = CMD_MAX_RETRIES + 1;
                MousePort = MOUSE_PS2_PORT_ID_1;
                i++;
                continue;
            }
            break;
        }
    }

#if WAKE_FROM_MOUSE
    i = 0;
    do
    {
        /* enable mouse as wake up source */
        Request.PacketType = NvEcPacketType_Request;
        Request.RequestType = NvEcRequestResponseType_AuxDevice;
        Request.RequestSubtype = ((NvEcRequestResponseSubtype) 
             (NV_DRF_NUM(NVEC,SUBTYPE,AUX_PORT_ID,hMouseDev->ValidMousePorts[i]))) |
             (NvEcRequestResponseSubtype)
             NvEcAuxDeviceSubtype_ConfigureWake;
        Request.NumPayloadBytes = 2;
        Request.Payload[0] = NVEC_AUX_DEVICE_WAKE_ENABLE_0_ACTION_ENABLE;
        Request.Payload[1] = NVEC_AUX_DEVICE_EVENT_TYPE_0_ANY_EVENT_ENABLE;

        err = NvEcSendRequest(
                    hMouseDev->hEc,
                    &Request,
                    &Response,
                    sizeof(Request),
                    sizeof(Response));
        if (err != NvError_Success)
        {
            ret = NV_FALSE;
            goto fail_safe;
        }

        if (Response.Status != NvEcStatus_Success)
        {
            ret = NV_FALSE;
            goto fail_safe;
        }
    } while (hMouseDev->ValidMousePorts[++i] != INVALID_MOUSE_PORT_ID);
#endif

    *hDevice = (NvOdmMouseDeviceHandle)hMouseDev;
    ret = NV_TRUE;
    return ret;

fail_safe:
    NvOdmMouseDeviceClose((NvOdmMouseDeviceHandle)hMouseDev);
    hMouseDev = NULL;
    return ret;
}
예제 #10
0
NvOdmSdioHandle NvOdmSdioOpen(NvU32 Instance)
{
    static NvOdmSdio *pDevice = NULL;
    NvOdmServicesGpioHandle hGpioTemp = NULL;
    NvOdmPeripheralConnectivity *pConnectivity;
    NvU32 NumOfGuids = 1;
    NvU64 guid;
    NvU32 searchVals[4];
    const NvU32 *pOdmConfigs;
    NvU32 NumOdmConfigs;
    NvBool Status = NV_TRUE;
    const NvOdmPeripheralSearch searchAttrs[] =
    {
        NvOdmPeripheralSearch_PeripheralClass,
        NvOdmPeripheralSearch_IoModule,
        NvOdmPeripheralSearch_Instance,
        NvOdmPeripheralSearch_Address,
    };
    NvOdmBoardInfo BoardInfo;
    NvBool status = NV_FALSE;
    
    searchVals[0] =  NvOdmPeripheralClass_Other;
    searchVals[1] =  NvOdmIoModule_Sdio;
    searchVals[2] =  Instance;

    NvOdmQueryPinMux(NvOdmIoModule_Sdio, &pOdmConfigs, &NumOdmConfigs); 
    if ((Instance == 0) && (pOdmConfigs[0] == NvOdmSdioPinMap_Config1))
    {
        // sdio is connected to sdio2 slot.  
        searchVals[3] =  NvOdmSdioDiscoveryAddress_1;
    }
    else
    {
        // sdio is connected to wifi module.
        searchVals[3] =  NvOdmSdioDiscoveryAddress_0;
    }

    NumOfGuids = NvOdmPeripheralEnumerate(searchAttrs,
                                          searchVals,
                                          4,
                                          &guid,
                                          NumOfGuids);

    // Get the peripheral connectivity information
    pConnectivity = (NvOdmPeripheralConnectivity *)NvOdmPeripheralGetGuid(guid);
    if (pConnectivity == NULL)
        return NULL;

    pDevice = NvOdmOsAlloc(sizeof(NvOdmSdio));
    if(pDevice == NULL)
        return (pDevice);

    pDevice->hPmu = NvOdmServicesPmuOpen();
    if(pDevice->hPmu == NULL)
    {
        NvOdmOsFree(pDevice);
        pDevice = NULL;
        return (NULL);
    }

    if (pConnectivity->Guid == WLAN_GUID)
    {
        // WARNING: This function *cannot* be called before RmOpen().
        status = NvOdmPeripheralGetBoardInfo((BOARD_ID_E951), &BoardInfo);
        if (NV_TRUE != status)
        {
            // whistler should have E951 Module, if it is not presnt return NULL Handle.
            NvOdmServicesPmuClose(pDevice->hPmu);
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            NvOdmOsDebugPrintf(("No E951 Detected"));
            return (pDevice);
        }
    }

    pDevice->pConnectivity = pConnectivity;
    NvOdmSetPowerOnSdio(pDevice, NV_TRUE);

    if (pConnectivity->Guid == WLAN_GUID)
    {
        // Getting the OdmGpio Handle
        hGpioTemp = NvOdmGpioOpen();
        if (hGpioTemp == NULL)
        {
            NvOdmServicesPmuClose(pDevice->hPmu);
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            return (pDevice);
        }
    
        // Search for the Vdd rail and set the proper volage to the rail.
        if (pConnectivity->AddressList[1].Interface == NvOdmIoModule_Gpio)
        {
             // Acquiring Pin Handles for Power Pin
             pDevice->hPwrPin= NvOdmGpioAcquirePinHandle(hGpioTemp, 
                   pConnectivity->AddressList[1].Instance,
                   pConnectivity->AddressList[1].Address);
        }
         
        if (pConnectivity->AddressList[2].Interface == NvOdmIoModule_Gpio)
        {
             // Acquiring Pin Handles for Reset Pin
             pDevice->hResetPin= NvOdmGpioAcquirePinHandle(hGpioTemp, 
                   pConnectivity->AddressList[2].Instance,
                   pConnectivity->AddressList[2].Address);
        }

        // Setting the ON/OFF pin to output mode.
        NvOdmGpioConfig(hGpioTemp, pDevice->hPwrPin, NvOdmGpioPinMode_Output);
        NvOdmGpioConfig(hGpioTemp, pDevice->hResetPin, NvOdmGpioPinMode_Output);

        // Setting the Output Pin to Low
        NvOdmGpioSetState(hGpioTemp, pDevice->hPwrPin, 0x0);
        NvOdmGpioSetState(hGpioTemp, pDevice->hResetPin, 0x0);

        pDevice->hGpio = hGpioTemp;

        Status = SdioOdmWlanSetPowerOn(pDevice, NV_TRUE);
        if (Status != NV_TRUE)
        {
            NvOdmServicesPmuClose(pDevice->hPmu);
            NvOdmGpioReleasePinHandle(pDevice->hGpio, pDevice->hPwrPin);
            NvOdmGpioReleasePinHandle(pDevice->hGpio, pDevice->hResetPin);    
            NvOdmGpioClose(pDevice->hGpio);   
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            return (pDevice);
        }
    }
    pDevice->PoweredOn = NV_TRUE;
    pDevice->Instance = Instance;
    NV_DRIVER_TRACE(("Open SDIO%d", Instance));
    return pDevice;
}
예제 #11
0
NvOdmSdioHandle NvOdmSdioOpen(NvU32 Instance)
{
    static NvOdmSdio *pDevice = NULL;
    NvOdmServicesGpioHandle hGpioTemp = NULL;
    NvOdmPeripheralConnectivity *pConnectivity;
    NvU32 NumOfGuids = 1;
    NvU64 guid;
    NvU32 searchVals[2];
    const NvU32 *pOdmConfigs;
    NvU32 NumOdmConfigs;
    NvBool Status = NV_TRUE;
    NvU32 DutyCycle;
    NvU32 gRequestedFreqHzOrPeriod;
    NvU32 ReturnedFreq;
    const NvOdmPeripheralSearch searchAttrs[] =
    {
        NvOdmPeripheralSearch_IoModule,
        NvOdmPeripheralSearch_Instance,
    };

    searchVals[0] =  NvOdmIoModule_Sdio;
    searchVals[1] =  Instance;

    NvOdmQueryPinMux(NvOdmIoModule_Sdio, &pOdmConfigs, &NumOdmConfigs);
    if (Instance >= NumOdmConfigs )
        return NULL;
    if( pOdmConfigs[Instance] == 0 )
        return NULL;

    NumOfGuids = NvOdmPeripheralEnumerate(
                     searchAttrs,
                     searchVals,
                     2,
                     &guid,
                     NumOfGuids);


    // Get the peripheral connectivity information
    pConnectivity = (NvOdmPeripheralConnectivity *)NvOdmPeripheralGetGuid(guid);
    if (pConnectivity == NULL)
        return NULL;

    pDevice = NvOdmOsAlloc(sizeof(NvOdmSdio));
    pDevice->hPmu = NULL;
    if(pDevice == NULL)
        return (pDevice);

    if (pDevice->hPmu == NULL)
    {
        pDevice->hPmu = NvOdmServicesPmuOpen();
        if(pDevice->hPmu == NULL)
        {
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            return (NULL);
        }
    }

    pDevice->pConnectivity = pConnectivity;
    NvOdmSetPowerOnSdio(pDevice, NV_TRUE);

    if (pConnectivity->Guid == WLAN_GUID)
    {
        // Getting the OdmGpio Handle
        hGpioTemp = NvOdmGpioOpen();
        if (hGpioTemp == NULL)
        {
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            return (pDevice);
        }

        // Search for the Vdd rail and set the proper volage to the rail.
        /*
                if (pConnectivity->AddressList[1].Interface == NvOdmIoModule_Gpio)
                {
                     // Acquiring Pin Handles for Power Pin
                     pDevice->hPwrPin= NvOdmGpioAcquirePinHandle(hGpioTemp,
                           pConnectivity->AddressList[1].Instance,
                           pConnectivity->AddressList[1].Address);
                }
        */// Sam ---
        if (pConnectivity->AddressList[2].Interface == NvOdmIoModule_Gpio)
        {
            // Acquiring Pin Handles for Reset Pin
            pDevice->hResetPin= NvOdmGpioAcquirePinHandle(hGpioTemp,
                                pConnectivity->AddressList[2].Instance,
                                pConnectivity->AddressList[2].Address);
        }

        // Setting the ON/OFF pin to output mode.
        //NvOdmGpioConfig(hGpioTemp, pDevice->hPwrPin, NvOdmGpioPinMode_Output);// Sam ---
        NvOdmGpioConfig(hGpioTemp, pDevice->hResetPin, NvOdmGpioPinMode_Output);

        // Setting the Output Pin to Low
        //NvOdmGpioSetState(hGpioTemp, pDevice->hPwrPin, 0x0); //Sam ---
        NvOdmGpioSetState(hGpioTemp, pDevice->hResetPin, 0x0);

        pDevice->hGpio = hGpioTemp;

        s_hOdmPwm = NvOdmPwmOpen();
        gRequestedFreqHzOrPeriod = 32000;	//32KHz
        DutyCycle = 3211264;

        NvOdmPwmConfig(s_hOdmPwm, NvOdmPwmOutputId_Blink, NvOdmPwmMode_Blink_32KHzClockOutput,
                       DutyCycle, &gRequestedFreqHzOrPeriod, &ReturnedFreq);

        Status = SdioOdmWlanSetPowerOn(pDevice, NV_TRUE);
        if (Status != NV_TRUE)
        {
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            return (pDevice);
        }
    }
    pDevice->PoweredOn = NV_TRUE;
    pDevice->Instance = Instance;
    NV_DRIVER_TRACE(("Open SDIO%d", Instance));
    return pDevice;
}
예제 #12
0
//-----------------------------------------------------------------
//--------------------------------New API--------------------------
//-----------------------------------------------------------------
NvBool
NvOdmGyroAccelOpen(NvOdmGyroAccelHandle* hDevice)
{
	NvU32 i;
	NvBool foundGpio = NV_FALSE, foundI2cModule = NV_FALSE;
	const NvOdmPeripheralConnectivity *pConnectivity;
	NvOdmGyroAccelHandle  hGyro;
	NvU32    reg_val = 0 ;
#if 1
	printk(" ## MPU3050 : [NvOdmGyroOpen:%d] \n",__LINE__) ;
#endif

	hGyro = NvOdmOsAlloc(sizeof(NvOdmGyro));
	if (hGyro == NULL) {
		printk("Error Allocating NvOdmAccel. \n");
		return NV_FALSE;
	}
	NvOdmOsMemset(hGyro, 0, sizeof(NvOdmGyro));

	hGyro->hPmu = NULL;
	hGyro->hOdmI2C =  NULL;

	hGyro->hPmu = NvOdmServicesPmuOpen();
	if (!hGyro->hPmu) {
		printk("NvOdmServicesPmuOpen Error \n");
		goto error;
	}

	pConnectivity = (NvOdmPeripheralConnectivity*)NvOdmPeripheralGetGuid(NV_ODM_GUID('g','y','r','o','s','c','o','p'));
	if (!pConnectivity) {
		printk("NvOdmPeripheralGetGuid doesn't detect gyro_accel device\n");
		goto error;
	}

	if(pConnectivity->Class != NvOdmPeripheralClass_Other) {
		goto error;
	}

	for (i = 0; i < pConnectivity->NumAddress; i++) {
		switch(pConnectivity->AddressList[i].Interface) {
			case NvOdmIoModule_I2c:
				hGyro->I2CChannelId = pConnectivity->AddressList[i].Instance;
				hGyro->nDevAddr = (pConnectivity->AddressList[i].Address << 1);
				foundI2cModule = NV_TRUE;
				foundGpio = NV_TRUE; //test
#if 1
				printk("## MPU3050 I2CChannelId = %x. ## \n", hGyro->I2CChannelId);
				printk("## MPU3050 i2c address = %x. ## \n", hGyro->nDevAddr);
#endif
				break;
				/*
				   case NvOdmIoModule_Gpio:
				   hGyro->GPIOPortINT = pConnectivity->AddressList[i].Instance;
				   hGyro->GPIOPinINT = pConnectivity->AddressList[i].Address;
				   foundGpio = NV_TRUE;
#if 1
printk("## MPU3050 GPIOPortINT = %x. ## \n",hGyro->GPIOPortINT);
printk("## MPU3050 GPIOPinINT = %x. ## \n", hGyro->GPIOPinINT);
#endif
break;*/
			case NvOdmIoModule_Vdd:
				hGyro->VddId = pConnectivity->AddressList[i].Address;
#if 1
				printk("## MPU3050 NvOdmIoModule_VddId = %x. ## \n", hGyro->VddId);
#endif
				// Power on accelerometer according to Vddid
				NvGyroAccelSetPowerRail(hGyro->hPmu, hGyro->VddId, NV_TRUE);
				break;
			default:
				break;
		}
	}

	if (foundGpio != NV_TRUE || foundI2cModule != NV_TRUE) {
		printk("GyroAccel : didn't find any periperal in discovery query for touch device Error \n");
		goto error;
	}

	// Set up I2C bus.
	if (NV_FALSE == NvGyroAccelI2COpen(&hGyro->hOdmI2C, hGyro->I2CChannelId)) {
		printk("GyroAccel : NvGyroAccelI2COpen Error \n");
		goto error;
	};
	printk(" ##1## GyroAccel : NvGyroAccelI2COpen check1 \n");
	hGyro->RegsRead = NvGyroAccelI2CGetRegs;
	hGyro->RegsWrite = NvGyroAccelI2CSetRegs;
	printk(" ##2## GyroAccel : NvGyroAccelI2COpen check2 \n");
	/*
		if(NV_FALSE == NvGyroAccelConnectSemaphore(hGyro))
		{
		printk("GyroAccel : NvGyroAccelConnectSemaphore Error \n");

		goto error;
		}
		*/

	*hDevice = hGyro;
	return NV_TRUE;
error:
	// Release all of resources requested.
	if (NULL != hGyro) {
		NvGyroAccelSetPowerRail(hGyro->hPmu, hGyro->VddId, NV_FALSE);
		NvOdmServicesPmuClose(hGyro->hPmu);
		hGyro->hPmu = NULL;
		NvGyroAccelI2CClose(hGyro->hOdmI2C);
		hGyro->hOdmI2C = NULL;
		NvOdmOsFree(hGyro);
		*hDevice = NULL;
	}
	return NV_FALSE;
}
NvBool Pcf50626Setup(NvOdmPmuDeviceHandle hDevice)
{
    NvOdmIoModule I2cModule = NvOdmIoModule_I2c;
    NvU32  I2cInstance = 0;
    NvU32  I2cAddress  = 0;    
    NvU32  i           = 0;
    NvBool status      = NV_FALSE;
    
    const NvOdmPeripheralConnectivity *pConnectivity = 
                           NvOdmPeripheralGetGuid(PMUGUID);
    
    NV_ASSERT(hDevice);

    
    pPrivData = (Pcf50626PrivData*) NvOdmOsAlloc(sizeof(Pcf50626PrivData));
    if (pPrivData == NULL)
    {
        NVODMPMU_PRINTF(("Error Allocating Pcf50626PrivData. \n"));
        return NV_FALSE;
    }
    NvOdmOsMemset(pPrivData, 0, sizeof(Pcf50626PrivData));
    hDevice->pPrivate = pPrivData;

    ((Pcf50626PrivData*)hDevice->pPrivate)->supplyRefCntTable = NvOdmOsAlloc(sizeof(NvU32) * PCF50626PmuSupply_Num);
    if (((Pcf50626PrivData*)hDevice->pPrivate)->supplyRefCntTable == NULL)
    {     
        NVODMPMU_PRINTF(("Error Allocating RefCntTable. \n"));
        goto fail;
    }
        
    // memset
    for (i = 0; i < PCF50626PmuSupply_Num; i++)
    {
        ((Pcf50626PrivData*)hDevice->pPrivate)->supplyRefCntTable[i] = 0;
    }


    if (pConnectivity != NULL) // PMU is in database
    {        
        for (i = 0; i < pConnectivity->NumAddress; i ++)
        {
            if (pConnectivity->AddressList[i].Interface == NvOdmIoModule_I2c_Pmu)
            {
                I2cModule   = NvOdmIoModule_I2c_Pmu;
                I2cInstance = pConnectivity->AddressList[i].Instance;
                I2cAddress  = pConnectivity->AddressList[i].Address;
                break;
            }
        }

        NV_ASSERT(I2cModule  == NvOdmIoModule_I2c_Pmu);
        NV_ASSERT(I2cAddress != 0);

        ((Pcf50626PrivData*)hDevice->pPrivate)->hOdmI2C = NvOdmI2cOpen(I2cModule, I2cInstance);
        if (!((Pcf50626PrivData*)hDevice->pPrivate)->hOdmI2C)
        {
            NVODMPMU_PRINTF(("[NVODM PMU]Pcf50626Setup: Error Open I2C device. \n"));     
            NVODMPMU_PRINTF(("[NVODM PMU]Please check PMU device I2C settings. \n"));  
            goto fail;        
        }
        
        ((Pcf50626PrivData*)hDevice->pPrivate)->DeviceAddr = I2cAddress;
        ((Pcf50626PrivData*)hDevice->pPrivate)->hOdmPmuSevice = NvOdmServicesPmuOpen();
        if (!((Pcf50626PrivData*)hDevice->pPrivate)->hOdmPmuSevice)
        {
            NVODMPMU_PRINTF(("[NVODM PMU]Pcf50626Setup: Error Open PMU Odm service. \n"));
            goto fail;        
        }
    }   
    else
    {
        // if PMU is not presented in the database, then the platform is PMU-less.
        NVODMPMU_PRINTF(("[NVODM PMU]Pcf50626Setup: The system did not doscover PMU fromthe data base. \n"));     
        NVODMPMU_PRINTF(("[NVODM PMU]Pcf50626Setup: If this is not intended, please check the peripheral database for PMU settings. \n"));     
        goto fail;
    }
    
    if (!Pcf50626BatteryChargerSetup(hDevice))
    {
        NVODMPMU_PRINTF(("[NVODM PMU]Pcf50626Setup: Pcf50626BatteryChargerSetup() failed. \n"));
        goto fail;
    }

    //Check battery presence
    if (!Pcf50626BatteryChargerCBCMainBatt(hDevice,&((Pcf50626PrivData*)hDevice->pPrivate)->battPresence))
    {
        NVODMPMU_PRINTF(("[NVODM PMU]Pcf50626Setup: Pcf50626BatteryChargerCBCMainBatt() failed. \n"));
        goto fail;
    }
    
    // The interrupt assumes not supported until pcf50626InterruptHandler() is called. 
    ((Pcf50626PrivData*)hDevice->pPrivate)->pmuInterruptSupported = NV_FALSE;

    // setup the interrupt any way.
    if (!Pcf50626SetupInterrupt(hDevice, &((Pcf50626PrivData*)hDevice->pPrivate)->pmuStatus))
    {
        NVODMPMU_PRINTF(("[NVODM PMU]Pcf50626Setup: Pcf50626SetupInterrupt() failed. \n"));
        goto fail;
    }

    // Check battery Fullness
    if (((Pcf50626PrivData*)hDevice->pPrivate)->battPresence == NV_TRUE)
    {   
        if (!Pcf50626BatteryChargerCBCBattFul(hDevice,&status))
        {
            NVODMPMU_PRINTF(("[NVODM PMU]Pcf50626Setup: Pcf50626BatteryChargerCBCBattFul() failed. \n"));
            goto fail;
        }

        ((Pcf50626PrivData*)hDevice->pPrivate)->pmuStatus.batFull = status;
    }
    else
    {
        ((Pcf50626PrivData*)hDevice->pPrivate)->pmuStatus.batFull = NV_FALSE;
    }

    return NV_TRUE;

fail:
    Pcf50626Release(hDevice);
    return NV_FALSE;
    
    
}
NvBool Synaptics_OneTouch_Open (NvOdmOneTouchDeviceHandle* hDevice, NvOdmOsSemaphoreHandle* hIntSema)
{
    Synaptics_OneTouch_Device* hTouch = (Synaptics_OneTouch_Device*)0;
    NvU32 i;
    NvU32 found = 0;
    NvU32 I2cInstance = 0;
    const NvOdmPeripheralConnectivity *pConnectivity = NULL;

    NVODMTOUCH_PRINTF(("[Touch Driver] Synaptics_OneTouch_Open\n"));
		
    hTouch = NvOdmOsAlloc(sizeof(Synaptics_OneTouch_Device));

    if (!hTouch) return NV_FALSE;

    NvOdmOsMemset(hTouch, 0, sizeof(Synaptics_OneTouch_Device));

    /* set function pointers */
    Synaptics_OneTouch_InitOdmTouch(&hTouch->OdmOneTouch);

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

    if (pConnectivity->Class != NvOdmPeripheralClass_HCI)
    {
        NVODMTOUCH_PRINTF(("[ONETOUCH] 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);
                hTouch->I2CInstance = pConnectivity->AddressList[i].Instance;
                found |= 1;

                NVODMTOUCH_PRINTF(("[ONETOUCH] i2c address = %x.\n", hTouch->DeviceAddr));
                break;
            case NvOdmIoModule_Gpio:
                hTouch->GpioPort = pConnectivity->AddressList[i].Instance;
                hTouch->GpioPin = pConnectivity->AddressList[i].Address;
                found |= 2;
                break;
            case NvOdmIoModule_Vdd:
                hTouch->VddId = pConnectivity->AddressList[i].Address;
                found |= 4;
                break;
			case NvOdmIoModule_I2c_Pmu:
				hTouch->I2cVddId = pConnectivity->AddressList[i].Address;
				break;
            default:
                break;
        }
    }

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

    if ((found & 4) != 0)
    {
// 20101120 [email protected] power off when Onetouch close    
#if defined(CONFIG_MACH_STAR_SKT_REV_E) || defined(CONFIG_MACH_STAR_SKT_REV_F)
        if (NV_FALSE == Synaptics_OneTouch_PowerOnOff(&hTouch->OdmOneTouch, 1))
	    	goto fail;   
#endif 
    }
    else
    {
        NVODMTOUCH_PRINTF(("[ONETOUCH] Synaptics Power fail \n"));
        hTouch->VddId = 0xFF; 
    }

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

    hTouch->hGpio = NvOdmGpioOpen();

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

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

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

    /* set default I2C speed */
    hTouch->I2cClockSpeedKHz = SYNAPTICS_I2C_SPEED_KHZ;
    NVODMTOUCH_PRINTF(("[ONETOUCH] i2c speed = %d\n", hTouch->I2cClockSpeedKHz));
	
    /* initialize */
    if(!Synaptics_OneTouch_Init(hTouch))	 goto fail;

    *hDevice = &hTouch->OdmOneTouch;
    if (Synaptics_OneTouch_EnableInterrupt(*hDevice, *hIntSema) == NV_FALSE)
          goto fail;

    return NV_TRUE;

 fail:
    Synaptics_OneTouch_Close(&hTouch->OdmOneTouch);
    return NV_FALSE;
}
예제 #15
0
NvOdmUsbUlpiHandle NvOdmUsbUlpiOpen(NvU32 Instance)
{
    NvOdmUsbUlpi*pDevice = NULL;
    NvU32 ClockInstances[MAX_CLOCKS];
    NvU32 ClockFrequencies[MAX_CLOCKS];
    NvU32 NumClocks;
#if defined(CONFIG_TEGRA_ODM_BETELGEUSE)
/* paul */
    NvOdmInterruptHandler IntrHandler = (NvOdmInterruptHandler)UsbCurLimitGpioInterruptHandler;
/* end */
#endif
    pDevice = NvOdmOsAlloc(sizeof(NvOdmUsbUlpi));
    if(pDevice == NULL)
		return NULL;
    
    if(!NvOdmExternalClockConfig(SMSC3317GUID, NV_FALSE, ClockInstances,
					ClockFrequencies, &NumClocks))
    {
        NV_DRIVER_TRACE (("ERROR NvOdmUsbUlpiOpen: "
				"NvOdmExternalClockConfig fail\n"));
        goto ExitUlpiOdm;
    }
    NvOdmOsSleepMS(10);

    if (!s_hGpio)
        s_hGpio = NvOdmGpioOpen();
    if (!s_hGpio)
    {
        NV_DRIVER_TRACE (("ERROR NvOdmUsbUlpiOpen: "
				"Not able to open gpio handle\n"));
        goto ExitUlpiOdm;
    }

    if (!s_hResetPin)
        s_hResetPin = NvOdmGpioAcquirePinHandle(s_hGpio, ULPI_RESET_PORT,
							ULPI_RESET_PIN);
    if (!s_hResetPin)
    {
        NvOdmGpioClose(s_hGpio);
        s_hGpio = NULL;
        NV_DRIVER_TRACE (("ERROR NvOdmGpioAcquirePinHandle: "
					"Not able to Acq pinhandle\n"));
        goto ExitUlpiOdm;
    }

#if defined(CONFIG_TEGRA_ODM_BETELGEUSE)
    if (!s_hOvrrCurPin)
        s_hOvrrCurPin = NvOdmGpioAcquirePinHandle(s_hGpio, ULPI_OVRCURR_PORT,
							ULPI_OVRCURR_PIN);

    if (!s_hOvrrCurPin)
    {
        NvOdmGpioClose(s_hGpio);
        s_hGpio = NULL;
        NV_DRIVER_TRACE (("ERROR NvOdmGpioAcquirePinHandle: "
					"Not able to Acq pinhandle\n"));
        goto ExitUlpiOdm;
    }
    NvOdmGpioConfig(s_hGpio,s_hOvrrCurPin, NvOdmGpioPinMode_InputData);
#endif

    // Pull high on RESETB ( 22nd pin of smsc3315) 
    // config as out put pin
    NvOdmGpioConfig(s_hGpio,s_hResetPin, NvOdmGpioPinMode_Output);

    // Set low to write high on ULPI_RESETB pin
    NvOdmGpioSetState(s_hGpio, s_hResetPin, 0x01);
    NvOdmGpioSetState(s_hGpio, s_hResetPin, 0x0);
    NvOdmOsSleepMS(5);
    NvOdmGpioSetState(s_hGpio, s_hResetPin, 0x01);

#if defined(BUG_CONFIG_TEGRA_ODM_BETELGEUSE)
/* paul merge smith begin */

    /* create mutex for usb over current detect */
    NvOsMutexCreate(&usbCurrLimit_lock);

#if 0
    /* create /proc/usbCurrLimitInfo for user space read */ /* S_IRUGO */
    create_proc_read_entry("usbCurrLimitInfo", S_IRWXUGO, NULL, tegra_usbCurrLimit_read_proc, NULL);
#else

    procfile_init();
    
#endif
    /* register interrupt handler for GPIO_PU3 status */
    if (NvOdmGpioInterruptRegister(s_hGpio, &IntrHandle,
        	s_hOvrrCurPin, NvOdmGpioPinMode_InputInterruptLow,
        	IntrHandler, (void *)NULL, 0) == NV_FALSE)
    {
		NV_DRIVER_TRACE (("ERROR NvOdmGpioInterruptRegister: "
					"Not able to register intr hdlr for s_hCurLimitPin\n"));
    }

/* paul merge smith end */
#endif

    pDevice->CurrentGUID = SMSC3317GUID;
    return pDevice;

ExitUlpiOdm:
    NvOdmOsFree(pDevice);
    return NULL;
}
NvBool NvOdmKeyboardInit(void)
{
    NvError NvStatus = NvError_Success;
    NvEcRequest Request = {0};
    NvEcResponse Response = {0};

    /* get nvec handle */
    NvStatus = NvEcOpen(&s_NvEcHandle, 0 /* instance */);
    if (NvStatus != NvError_Success)
    {
        goto fail;
    }

    /* reset the EC to start the keyboard scanning */
    Request.PacketType = NvEcPacketType_Request;
    Request.RequestType = NvEcRequestResponseType_Keyboard;
    Request.RequestSubtype = (NvEcRequestResponseSubtype) NvEcKeyboardSubtype_Enable;
    Request.NumPayloadBytes = 0;

    NvStatus = NvEcSendRequest(s_NvEcHandle, &Request, &Response, sizeof(Request), sizeof(Response));
    if (NvStatus != NvError_Success)
    {
        goto cleanup;
    }

    /* check if command passed */
    if (Response.Status != NvEcStatus_Success)
    {
        goto cleanup;
    }

#if WAKE_FROM_KEYBOARD
	hOdm = NvOdmOsAlloc(sizeof(NvOdmKbdContext));
	if (!hOdm) {
		goto cleanup;
	}

	/* Check the supported GPIOs */
	hOdm->GpioPinInfo = NvOdmQueryGpioPinMap(NvOdmGpioPinGroup_EmbeddedController,
					0, &hOdm->PinCount);

	NvRmGpioAcquirePinHandle(s_hGpioGlobal,
		hOdm->GpioPinInfo->Port,
		hOdm->GpioPinInfo->Pin,
		&hOdm->hPin);
	if (!hOdm->hPin) {
		goto cleanup;
	}

	/* register to receive GPIO events */
	NvStatus = NvRmGpioInterruptRegister(s_hGpioGlobal,
		s_hRmGlobal,
		hOdm->hPin,
		(NvOsInterruptHandler)GpioInterruptHandler,
		NvRmGpioPinMode_InputData,
		hOdm,
		&hOdm->GpioIntrHandle,
		DEBOUNCE_TIME_MS);
	if (NvStatus != NvError_Success) {
		goto cleanup;
	}

	NvStatus = NvRmGpioInterruptEnable(hOdm->GpioIntrHandle);
	if (NvStatus != NvError_Success) {
		goto cleanup;
	}

	/* enable keyboard as wake up source */
	Request.PacketType = NvEcPacketType_Request;
	Request.RequestType = NvEcRequestResponseType_Keyboard;
	Request.RequestSubtype = (NvEcRequestResponseSubtype)
	NvEcKeyboardSubtype_ConfigureWake;
	Request.NumPayloadBytes = 2;
	Request.Payload[0] = NVEC_KEYBOARD_WAKE_ENABLE_0_ACTION_ENABLE;
	Request.Payload[1] = NVEC_KEYBOARD_EVENT_TYPE_0_ANY_KEY_PRESS_ENABLE;

	NvStatus = NvEcSendRequest(s_NvEcHandle,
		&Request,
		&Response,
		sizeof(Request),
		sizeof(Response));
	if (NvStatus != NvError_Success) {
		goto cleanup;
        }

	if (Response.Status != NvEcStatus_Success) {
		goto cleanup;
	}

        /* enable key reporting on wake up */
	Request.PacketType = NvEcPacketType_Request;
	Request.RequestType = NvEcRequestResponseType_Keyboard;
	Request.RequestSubtype = (NvEcRequestResponseSubtype)
	NvEcKeyboardSubtype_ConfigureWakeKeyReport;
	Request.NumPayloadBytes = 1;
	Request.Payload[0] = NVEC_KEYBOARD_REPORT_WAKE_KEY_0_ACTION_ENABLE;

	NvStatus = NvEcSendRequest(s_NvEcHandle,
		&Request,
		&Response,
		sizeof(Request),
		sizeof(Response));
	if (NvStatus != NvError_Success) {
		goto cleanup;
        }

	if (Response.Status != NvEcStatus_Success) {
		goto cleanup;
	}
#endif

    /* create semaphore which can be used to send scan codes to the clients */
    s_hKbcKeyScanRecvSema = NvOdmOsSemaphoreCreate(0);
    if (!s_hKbcKeyScanRecvSema)
    {
        goto cleanup;
    }

    /* register for keyboard events */
    NvStatus = NvEcRegisterForEvents(
                    s_NvEcHandle,       // nvec handle
                    &s_hEcEventRegistration,
                    (NvOsSemaphoreHandle)s_hKbcKeyScanRecvSema,
                    sizeof(EventTypes)/sizeof(NvEcEventType),
                    EventTypes, // receive keyboard scan codes
                    1,          // currently buffer only 1 packet from ECI at a time
                    sizeof(NvEcEvent));
    if (NvStatus != NvError_Success)
    {
        goto cleanup;
    }

    /* success */
    return NV_TRUE;

cleanup:
#if WAKE_FROM_KEYBOARD
	NvRmGpioInterruptUnregister(s_hGpioGlobal, s_hRmGlobal, hOdm->GpioIntrHandle);
	hOdm->GpioIntrHandle = NULL;
	NvRmGpioReleasePinHandles(s_hGpioGlobal, &hOdm->hPin, hOdm->PinCount);
	NvOdmOsFree(hOdm);
	hOdm = NULL;
#endif
    (void)NvEcUnregisterForEvents(s_hEcEventRegistration);
    s_hEcEventRegistration = NULL;

    NvOdmOsSemaphoreDestroy(s_hKbcKeyScanRecvSema);
    s_hKbcKeyScanRecvSema = NULL;

    NvEcClose(s_NvEcHandle);
fail:
    s_NvEcHandle = NULL;

    return NV_FALSE;
}
예제 #17
0
NvOdmSdioHandle NvOdmSdioOpen(NvU32 Instance)
{
    static NvOdmSdio *pDevice = NULL;
    NvOdmServicesGpioHandle hGpioTemp = NULL;
    const NvOdmPeripheralConnectivity *pConnectivity;
    NvU32 NumOfGuids = 1;
    NvU64 guid;
    NvU32 searchVals[2];
    const NvU32 *pOdmConfigs;
    NvU32 NumOdmConfigs;
    NvBool Status = NV_TRUE;
    const NvOdmPeripheralSearch searchAttrs[] =
    {
        NvOdmPeripheralSearch_IoModule,
        NvOdmPeripheralSearch_Instance,
    };

    searchVals[0] =  NvOdmIoModule_Sdio;
    searchVals[1] =  Instance;

    NvOdmQueryPinMux(NvOdmIoModule_Sdio, &pOdmConfigs, &NumOdmConfigs);
    if (Instance >= NumOdmConfigs )
        return NULL;
    if( pOdmConfigs[Instance] == 0 )
        return NULL;

    NumOfGuids = NvOdmPeripheralEnumerate(searchAttrs, searchVals,
                                          2, &guid, NumOfGuids);


    // Get the peripheral connectivity information
    pConnectivity = NvOdmPeripheralGetGuid(guid);
    if (pConnectivity == NULL)
        return NULL;

    pDevice = NvOdmOsAlloc(sizeof(NvOdmSdio));
    pDevice->hPmu = NULL;
    if(pDevice == NULL)
        return (pDevice);

    if (pDevice->hPmu == NULL)
    {
        pDevice->hPmu = NvOdmServicesPmuOpen();
        if(pDevice->hPmu == NULL)
        {
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            return (NULL);
        }
    }

    pDevice->pConnectivity = pConnectivity;
    NvOdmSetPowerOnSdio(pDevice, NV_TRUE);

    if (pConnectivity->Guid == WLAN_GUID)
    {
        // Getting the OdmGpio Handle
        hGpioTemp = NvOdmGpioOpen();
        if (hGpioTemp == NULL)
        {
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            return (pDevice);
        }

        // Search for the Vdd rail and set the proper volage to the rail.
        if (pConnectivity->AddressList[1].Interface == NvOdmIoModule_Gpio)
        {
             // Acquiring Pin Handles for Power Pin
             pDevice->hPwrPin= NvOdmGpioAcquirePinHandle(hGpioTemp,
                   pConnectivity->AddressList[1].Instance,
                   pConnectivity->AddressList[1].Address);
        }

        if (pConnectivity->AddressList[2].Interface == NvOdmIoModule_Gpio)
        {
             // Acquiring Pin Handles for Reset Pin
             pDevice->hResetPin= NvOdmGpioAcquirePinHandle(hGpioTemp,
                   pConnectivity->AddressList[2].Instance,
                   pConnectivity->AddressList[2].Address);
        }

        // Setting the ON/OFF pin to output mode.
        NvOdmGpioConfig(hGpioTemp, pDevice->hPwrPin, NvOdmGpioPinMode_Output);
        NvOdmGpioConfig(hGpioTemp, pDevice->hResetPin, NvOdmGpioPinMode_Output);

        // Setting the Output Pin to Low
        NvOdmGpioSetState(hGpioTemp, pDevice->hPwrPin, 0x0);
        NvOdmGpioSetState(hGpioTemp, pDevice->hResetPin, 0x0);

        pDevice->hGpio = hGpioTemp;

        Status = SdioOdmWlanPower(pDevice, NV_TRUE);
        if (Status != NV_TRUE)
        {
            NvOdmOsFree(pDevice);
            pDevice = NULL;
            return (pDevice);
        }
    }
    pDevice->PoweredOn = NV_TRUE;
    pDevice->Instance = Instance;
    return pDevice;
}
예제 #18
0
/**
 *  @brief Allocates a handle to the device. Configures the PWM
 *   control to the Vibro motor with default values. To change
 *   the amplitude and frequency use NvOdmVibrateSetParameter API.
 *  @param hOdmVibrate  [IN] Opaque handle to the device.
 *  @return  NV_TRUE on success and NV_FALSE on error
 */
NvBool
NvOdmVibOpen(NvOdmVibDeviceHandle *hOdmVibrate)
{

#if 1	/* yuyang(20100615):Create I2C handle */
	const NvOdmPeripheralConnectivity *pConnectivity = NULL;
    NvU32 Index = 0;
    NvU32 I2cInstance = 0;

    NV_ASSERT(hOdmVibrate);

    /* Allocate the handle */
    (*hOdmVibrate) = (NvOdmVibDeviceHandle)NvOdmOsAlloc(sizeof(NvOdmVibDevice));
    if (*hOdmVibrate == NULL)
    {
        NV_ODM_TRACE(("Error Allocating NvOdmPmuDevice. \n"));
        return NV_FALSE;
    }
    NvOsMemset((*hOdmVibrate), 0, sizeof(NvOdmVibDevice));

    /* Get the PMU handle */
    (*hOdmVibrate)->hOdmServicePmuDevice = NvOdmServicesPmuOpen();

    if (!(*hOdmVibrate)->hOdmServicePmuDevice)
    {
        NV_ODM_TRACE(("Error Opening Pmu device. \n"));
        NvOdmOsFree(*hOdmVibrate);
        *hOdmVibrate = NULL;
        return NV_FALSE;
    }

    // Get the peripheral connectivity information
    pConnectivity = NvOdmPeripheralGetGuid(VIBRATE_DEVICE_GUID);
    if (pConnectivity == NULL)
    {
        NV_ODM_TRACE(("Error pConnectivity NULL. \n"));
        return NV_FALSE;
    }

	for (Index = 0; Index < pConnectivity->NumAddress; ++Index)
    {
        switch (pConnectivity->AddressList[Index].Interface)
        {
			case NvOdmIoModule_I2c:
                (*hOdmVibrate)->DeviceAddr = (pConnectivity->AddressList[Index].Address);
                I2cInstance = pConnectivity->AddressList[Index].Instance;
                NV_ODM_TRACE("%s: hTouch->DeviceAddr = 0x%x, I2cInstance = %x\n", __func__, (*hOdmVibrate)->DeviceAddr, I2cInstance); 
                break;
            case NvOdmIoModule_Vdd:
                (*hOdmVibrate)->VddId = pConnectivity->AddressList[Index].Address;
                NvOdmServicesPmuGetCapabilities((*hOdmVibrate)->hOdmServicePmuDevice, (*hOdmVibrate)->VddId, &((*hOdmVibrate)->RailCaps));
                break;
            default:
                break;
        }
    }

	(*hOdmVibrate)->hOdmI2c = NvOdmI2cOpen(NvOdmIoModule_I2c_Pmu, I2cInstance);

	if (!(*hOdmVibrate)->hOdmI2c)
    {
        NV_ODM_TRACE(("NvOdm Touch : NvOdmI2cOpen Error \n"));
        return NV_FALSE;
    }
#else
    const NvOdmPeripheralConnectivity *pConnectivity = NULL;
    NvU32 Index = 0;

    NV_ASSERT(hOdmVibrate);

    /* Allocate the handle */
    (*hOdmVibrate) = (NvOdmVibDeviceHandle)NvOdmOsAlloc(sizeof(NvOdmVibDevice));
    if (*hOdmVibrate == NULL)
    {
        NV_ODM_TRACE(("Error Allocating NvOdmPmuDevice. \n"));
        return NV_FALSE;
    }
    NvOsMemset((*hOdmVibrate), 0, sizeof(NvOdmVibDevice));

    /* Get the PMU handle */
    (*hOdmVibrate)->hOdmServicePmuDevice = NvOdmServicesPmuOpen();
    if (!(*hOdmVibrate)->hOdmServicePmuDevice)
    {
        NV_ODM_TRACE(("Error Opening Pmu device. \n"));
        NvOdmOsFree(*hOdmVibrate);
        *hOdmVibrate = NULL;
        return NV_FALSE;
    }

        // Get the peripheral connectivity information
    pConnectivity = NvOdmPeripheralGetGuid(VIBRATE_DEVICE_GUID);
    if (pConnectivity == NULL)
        return NV_FALSE;

        // Search for the Vdd rail and set the proper volage to the rail.
    for (Index = 0; Index < pConnectivity->NumAddress; ++Index)
    {
        if (pConnectivity->AddressList[Index].Interface == NvOdmIoModule_Vdd)
        {
            (*hOdmVibrate)->VddId = pConnectivity->AddressList[Index].Address;
            NvOdmServicesPmuGetCapabilities((*hOdmVibrate)->hOdmServicePmuDevice, (*hOdmVibrate)->VddId, &((*hOdmVibrate)->RailCaps));
            break;
        }
    }
#endif	/* __yuyang(20100615) */

    return NV_TRUE;
}
/**
 *  @brief Allocates a handle to the device. Configures the PWM
 *   control to the Vibro motor with default values. To change
 *   the amplitude and frequency use NvOdmVibrateSetParameter API.
 *  @param hOdmVibrate  [IN] Opaque handle to the device.
 *  @return  NV_TRUE on success and NV_FALSE on error
 */
NvBool
NvOdmVibOpen(NvOdmVibDeviceHandle *hOdmVibrate)
{
    const NvOdmPeripheralConnectivity *pConnectivity = NULL;
    NvU32 Index = 0;

    NV_ASSERT(hOdmVibrate);

    /* Allocate the handle */
    (*hOdmVibrate) = (NvOdmVibDeviceHandle)NvOdmOsAlloc(sizeof(NvOdmVibDevice));
    if (*hOdmVibrate == NULL)
    {
        NV_ODM_TRACE(("Error Allocating NvOdmPmuDevice. \n"));
        return NV_FALSE;
    }
    NvOsMemset((*hOdmVibrate), 0, sizeof(NvOdmVibDevice));
#if (defined(CONFIG_7546Y_V10))    /*HZJ ADD FOR VIBRATE*/
   (*hOdmVibrate)->vibrate_gpio= NvOdmGpioOpen();
	if (!(*hOdmVibrate)->vibrate_gpio) {
		NV_ODM_TRACE("err open gpio vibrate hzj added\r\n");
		kfree(*hOdmVibrate);
		return -1;
	}	

   	(*hOdmVibrate)->vibrate_pin = NvOdmGpioAcquirePinHandle((*hOdmVibrate)->vibrate_gpio, VIBRATE_DET_ENABLE_PORT, VIBRATE_DET_ENABLE_PIN);
	if (!(*hOdmVibrate)->vibrate_pin) {
		NV_ODM_TRACE("err acquire detect pin handle vibrate\r\n");
		NvOdmGpioClose((*hOdmVibrate)->vibrate_gpio);
		return -1;
	}

	NvOdmGpioConfig((*hOdmVibrate)->vibrate_gpio, (*hOdmVibrate)->vibrate_pin, NvOdmGpioPinMode_Output);
  /*End Hzj aded*/ 
   (*hOdmVibrate)->vibrate_segpio= NvOdmGpioOpen();
	if (!(*hOdmVibrate)->vibrate_segpio) {
		NV_ODM_TRACE("err open gpio vibrate hzj added\r\n");
		kfree(*hOdmVibrate);
		return -1;
	}

   	(*hOdmVibrate)->vibrate_sepin = NvOdmGpioAcquirePinHandle((*hOdmVibrate)->vibrate_segpio, VIBRATE_SE_PORT, VIBRATE_SE_PIN);
	if (!(*hOdmVibrate)->vibrate_sepin) {
		NV_ODM_TRACE("err acquire detect pin handle vibrate\r\n");
		NvOdmGpioClose((*hOdmVibrate)->vibrate_segpio);
		return -1;
	}

	NvOdmGpioConfig((*hOdmVibrate)->vibrate_segpio, (*hOdmVibrate)->vibrate_sepin, NvOdmGpioPinMode_Output);
  
#endif
    /* Get the PMU handle */
    (*hOdmVibrate)->hOdmServicePmuDevice = NvOdmServicesPmuOpen();
    if (!(*hOdmVibrate)->hOdmServicePmuDevice)
    {
        NV_ODM_TRACE(("Error Opening Pmu device. \n"));
        NvOdmOsFree(*hOdmVibrate);
        *hOdmVibrate = NULL;
        return NV_FALSE;
    }

        // Get the peripheral connectivity information
    pConnectivity = NvOdmPeripheralGetGuid(VIBRATE_DEVICE_GUID);
    if (pConnectivity == NULL)
        return NV_FALSE;

        // Search for the Vdd rail and set the proper volage to the rail.
    for (Index = 0; Index < pConnectivity->NumAddress; ++Index)
    {
        if (pConnectivity->AddressList[Index].Interface == NvOdmIoModule_Vdd)
        {
            (*hOdmVibrate)->VddId = pConnectivity->AddressList[Index].Address;
            NvOdmServicesPmuGetCapabilities((*hOdmVibrate)->hOdmServicePmuDevice, (*hOdmVibrate)->VddId, &((*hOdmVibrate)->RailCaps));
            break;
        }
    }

    return NV_TRUE;
}
예제 #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;
}
예제 #21
0
NvBool Adt7461Init(NvOdmTmonDeviceHandle hTmon)
{
    NvU8 Data;
    NvBool ExtRange;
    NvU32 i = 0;
    NvU32 I2cInstance = 0;
    NvOdmIoModule I2cModule = NvOdmIoModule_Num;    // Inavlid module
    const ADT7461RegisterInfo* pReg = NULL;
    ADT7461PrivData* pPrivData = NULL;
    
    NV_ASSERT(hTmon && hTmon->pConn && hTmon->pConn->AddressList);
    
    // Allocate and clear priavte data
    pPrivData = (ADT7461PrivData*) NvOdmOsAlloc(sizeof(ADT7461PrivData));
    if (pPrivData == NULL)
    {
        NVODM_ADT7461_PRINTF(("ADT7461: Error Allocating PrivData. \n"));
        return NV_FALSE;
    }
    NvOdmOsMemset(pPrivData, 0, sizeof(ADT7461PrivData));
    hTmon->pPrivate = pPrivData;

    // Register for PMU services
    pPrivData->hOdmPmuSevice = NvOdmServicesPmuOpen();
    if (pPrivData->hOdmPmuSevice == NULL)
    {
        NVODM_ADT7461_PRINTF(("ADT7461: Error Open PMU service. \n"));
        goto fail;
    }

    // Register for GPIO services
    pPrivData->hGpio = NvOdmGpioOpen();
    if (pPrivData->hOdmPmuSevice == NULL)
    {
        NVODM_ADT7461_PRINTF(("ADT7461: Error Open GPIO service. \n"));
        goto fail;
    }

    /*
     * Parse connectivity data: turn On power to the device, acquire I2C
     * interface and GPIO interrupt (optional); map device channels to
     * thermal zones
     */
    for (i = 0; i < hTmon->pConn->NumAddress; i ++)
    {
        const NvOdmIoAddress* pIoAddress = &hTmon->pConn->AddressList[i];
        if (pIoAddress->Interface == NvOdmIoModule_I2c_Pmu)
        {
            I2cModule   = NvOdmIoModule_I2c_Pmu;
            I2cInstance = pIoAddress->Instance;
            NV_ASSERT(pIoAddress->Address != 0);
            pPrivData->DeviceI2cAddr = pIoAddress->Address;
        }
        else if (pIoAddress->Interface == NvOdmIoModule_Tsense)
        {
            NV_ASSERT(pIoAddress->Instance < NvOdmTmonZoneID_Num);
            NV_ASSERT(pIoAddress->Address < ADT7461ChannelID_Num);
            pPrivData->ConnectivityMap[pIoAddress->Instance] =
                pIoAddress->Address;
        }
        else if (pIoAddress->Interface == NvOdmIoModule_Vdd)
        {
            NvU32 usec = 0;
            NvU32 RailAddress = pIoAddress->Address;
            NvOdmServicesPmuVddRailCapabilities RailCapabilities;
            NvOdmServicesPmuGetCapabilities(
                pPrivData->hOdmPmuSevice, RailAddress, &RailCapabilities);
            NvOdmServicesPmuSetVoltage(pPrivData->hOdmPmuSevice, RailAddress,
                              RailCapabilities.requestMilliVolts, &usec);
            NvOdmOsWaitUS(usec + (ADT7461_POWERUP_DELAY_MS * 1000));
        }
        else if (pIoAddress->Interface == NvOdmIoModule_Gpio)
        {
            NvU32 port = pIoAddress->Instance;
            NvU32 pin = pIoAddress->Address;
            pPrivData->hGpioPin = NvOdmGpioAcquirePinHandle(
                pPrivData->hGpio, port, pin);
        }

    }
    NV_ASSERT(I2cModule == NvOdmIoModule_I2c_Pmu);
    pPrivData->hOdmI2C = NvOdmI2cOpen(I2cModule, I2cInstance);
    if (pPrivData->hOdmI2C == NULL)
    {
        NVODM_ADT7461_PRINTF(("ADT7461: Error Open I2C device. \n"));     
        goto fail;
    }

    /*
     * Initialize device info and configuration. Force standby mode to avoid
     * glitch on shutdown comparator output when temperature range and/or
     * comparator limit is changing during initialization. The Adt7461Run()
     * call from the hal that follows initialization will switch device to
     * run mode and re-start temperature monitoring (note that out of limit
     * interrupt is always masked during and after initialization)
     */
    pPrivData->pDeviceInfo = &s_Adt7461Info;
    pPrivData->ShadowRegPtr = ADT7461_INVALID_ADDR;

    pReg = &pPrivData->pDeviceInfo->Config;
    if (!Adt7461ReadReg(pPrivData, pReg, &Data))
        goto fail;
    if ((Data & ADT7461ConfigBits_ExtendedRange) !=
        (ADT7461_INITIAL_CONFIG & ADT7461ConfigBits_ExtendedRange))
    {
        // Only switch from standard to extended range is supported
        NV_ASSERT((Data & ADT7461ConfigBits_ExtendedRange) == 0);
        Data |= ADT7461ConfigBits_Standby;
        if(!Adt7461WriteReg(pPrivData, pReg, Data))
            goto fail;
    }
    Data = ADT7461_INITIAL_CONFIG | ADT7461ConfigBits_Standby;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;
    pPrivData->ShadowConfig = Data;
#if PRE_ER_GMT_THERMALSENSOR
    ExtRange = 0; /* not support ADT thermal sensor*/
#else
    ExtRange = ((Data & ADT7461ConfigBits_ExtendedRange) != 0);	
#endif
    // Program shutdown comparators settings
    Data = ADT7461_T_VALUE_TO_DATA(
        ExtRange, ADT7461_ODM_LOCAL_COMPARATOR_LIMIT_VALUE);
    pReg = &pPrivData->pDeviceInfo->Channels[
        ADT7461ChannelID_Local].ComparatorLimit;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;

    Data = ADT7461_T_VALUE_TO_DATA(
        ExtRange, ADT7461_ODM_REMOTE_COMPARATOR_LIMIT_VALUE);
    pReg = &pPrivData->pDeviceInfo->Channels[
        ADT7461ChannelID_Remote].ComparatorLimit;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;

    // Set interrupt limits to the range boundaries to prevent out of limit
    // interrupt
    Data = ADT7461_T_VALUE_TO_DATA(
        ExtRange, ADT7461_T_RANGE_LIMIT_HIGH(ExtRange)); 
    pReg = &pPrivData->pDeviceInfo->Channels[
        ADT7461ChannelID_Local].IntrLimitHigh;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;
    pReg = &pPrivData->pDeviceInfo->Channels[
        ADT7461ChannelID_Remote].IntrLimitHigh;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;

    Data = ADT7461_T_VALUE_TO_DATA(
            ExtRange, ADT7461_T_RANGE_LIMIT_LOW(ExtRange));
    pReg = &pPrivData->pDeviceInfo->Channels[
        ADT7461ChannelID_Local].IntrLimitLow;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;
    pReg = &pPrivData->pDeviceInfo->Channels[
        ADT7461ChannelID_Remote].IntrLimitLow;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;

    // Set initial rate
    Data = ADT7461_INITIAL_RATE_SETTING;  
    pReg = &pPrivData->pDeviceInfo->Rate;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;
    pPrivData->ShadowRate = Data;

    // Set remote channel offset (8-bit 2's complement value for any range)
    Data = ((NvU8)ADT7461_ODM_REMOTE_OFFSET_VALUE);
    pReg = &pPrivData->pDeviceInfo->Channels[
        ADT7461ChannelID_Remote].Toffset;
    if(!Adt7461WriteReg(pPrivData, pReg, Data))
        goto fail;

    // Read ADT7461 status and ARA (clear pending Alert interrupt, if any)
    pReg = &pPrivData->pDeviceInfo->Status;
    if (!Adt7461ReadReg(pPrivData, pReg, &Data))
        goto fail;
    // TODO: check open remote circuit error

    Adt7461ReadAra(pPrivData);

    return NV_TRUE;

fail:
    Adt7461FreePrivData(pPrivData);
    hTmon->pPrivate = NULL;
    return NV_FALSE;
}
예제 #22
0
//-----------------------------------------------------------------
//--------------------------------New API--------------------------
//-----------------------------------------------------------------
NvBool
NvOdmAccelOpen(NvOdmAccelHandle* hDevice)
{
    NvU32    test_val;
    NvU32 i;
    NvBool foundGpio = NV_FALSE, foundI2cModule = NV_FALSE;
    const NvOdmPeripheralConnectivity *pConnectivity;
    NvOdmAccelHandle  hAccel;

    hAccel = NvOdmOsAlloc(sizeof(NvOdmAccel));
    if (hAccel == NULL)
    {
        //NVODMACCELEROMETER_PRINTF("Error Allocating NvOdmAccel. \n");
        return NV_FALSE;
    }
    NvOdmOsMemset(hAccel, 0, sizeof(NvOdmAccel));

    hAccel->hPmu = NULL;
    hAccel->hOdmI2C =  NULL;
    hAccel->nBusType = NV_ACCELEROMETER_BUS_I2C;
    
    // Chip init cfg info here, here just a sample for common interrupt now!
    // This part will move to a configuration table later.
    // Start here.
    // Only enable common interrupt
    // Enable common and single tap at the same time.
    hAccel->CtrlRegsList[0].RegAddr = XLR_CTL; //0x12
    hAccel->CtrlRegsList[0].RegValue = 0x20;
    hAccel->CtrlRegsList[1].RegAddr = XLR_INTCONTROL; //0x13
    hAccel->CtrlRegsList[1].RegValue = 0xF3;  // modify so that sw is compatible
    hAccel->CtrlRegsList[2].RegAddr = XLR_INTCONTROL2; //0x14
    hAccel->CtrlRegsList[2].RegValue = 0xe0;
    hAccel->CtrlRegsList[3].RegAddr = XLR_THRESHG; //0x1C
    hAccel->CtrlRegsList[3].RegValue = NV_ADI340_ACCELEROMETER_NORMAL_THRESHOLD;
    hAccel->CtrlRegsList[4].RegAddr = XLR_OFSX; //0x1E
    hAccel->CtrlRegsList[4].RegValue = 0;
    hAccel->CtrlRegsList[5].RegAddr = XLR_OFSY; //0x1F
    hAccel->CtrlRegsList[5].RegValue = 0;
    hAccel->CtrlRegsList[6].RegAddr = XLR_OFSZ; //0x20
    hAccel->CtrlRegsList[6].RegValue = 0;
    hAccel->CtrlRegsList[7].RegAddr = XLR_THRESHC; //0x1D
    hAccel->CtrlRegsList[7].RegValue = NV_ADI340_ACCELEROMETER_TAP_THRESHOLD;
    hAccel->CtrlRegsList[8].RegAddr = XLR_DUR; //0x21
    hAccel->CtrlRegsList[8].RegValue = 0x40;
    hAccel->CtrlRegsList[9].RegAddr = XLR_LATENT; //0x22
    hAccel->CtrlRegsList[9].RegValue = 0xff;
    hAccel->CtrlRegsList[10].RegAddr = XLR_INTVL; //0x23
    hAccel->CtrlRegsList[10].RegValue = 0;
    hAccel->CtrlRegsList[11].RegAddr = XLR_INTCONTROL2; //0x14
    hAccel->CtrlRegsList[11].RegValue = 0xe1;
    hAccel->CtrlRegsList[12].RegAddr = XLR_INTCONTROL2; //0x14
    hAccel->CtrlRegsList[12].RegValue = 0xe0;
    hAccel->nLength = 13;
    // Stop here.
    // Info of accelerometer with current setting.
    hAccel->Caption.MaxForceInGs = 2000;
    hAccel->Caption.MaxTapTimeDeltaInUs = 255;
    hAccel->Caption.NumMotionThresholds = 1;
    hAccel->Caption.SupportsFreefallInt = 0;
    hAccel->Caption.MaxSampleRate = 100;
    hAccel->Caption.MinSampleRate = 3;
    hAccel->PowerState = NvOdmAccelPower_Fullrun;
    hAccel->AxisXMapping = NvOdmAccelAxis_X;
    hAccel->AxisXDirection = 1;
    hAccel->AxisYMapping = NvOdmAccelAxis_Y;
    hAccel->AxisYDirection = 1;
    hAccel->AxisZMapping = NvOdmAccelAxis_Z;
    hAccel->AxisZDirection = -1;
    
    hAccel->hPmu = NvOdmServicesPmuOpen();
    if (!hAccel->hPmu)
    {
        //NVODMACCELEROMETER_PRINTF("NvOdmServicesPmuOpen Error \n");
        goto error;
    }
    
    pConnectivity = (NvOdmPeripheralConnectivity*)NvOdmPeripheralGetGuid(NV_ODM_GUID('a','c','c','e','l','e','r','o'));
    if (!pConnectivity)
    {
        NvOdmOsDebugPrintf("NvOdmPeripheralGetGuid doesn't detect accelerometer device\n");
        goto error;
    }
 
    if(pConnectivity->Class != NvOdmPeripheralClass_Other)
    {
        goto error;
    }
        
    for( i = 0; i < pConnectivity->NumAddress; i++)
    {
        switch(pConnectivity->AddressList[i].Interface)
        {
            case NvOdmIoModule_I2c:
                hAccel->I2CChannelId = pConnectivity->AddressList[i].Instance;
                hAccel->nDevAddr = (NvU8)pConnectivity->AddressList[i].Address;
                foundI2cModule = NV_TRUE;
                break;
            case NvOdmIoModule_Gpio:
                hAccel->GPIOPortINT = pConnectivity->AddressList[i].Instance;
                hAccel->GPIOPinINT = pConnectivity->AddressList[i].Address;
                foundGpio = NV_TRUE;
                break;
            case NvOdmIoModule_Vdd:
                hAccel->VddId = pConnectivity->AddressList[i].Address;
                // Power on accelerometer according to Vddid
                NvAccelerometerSetPowerRail(hAccel->hPmu, hAccel->VddId, NV_TRUE);
                break;
            default:
                break;
        }
    }

    if(foundGpio != NV_TRUE || foundI2cModule != NV_TRUE)
    {
        //NVODMACCELEROMETER_PRINTF("Accelerometer : didn't find any periperal in discovery query for touch device Error \n");
        goto error;
    }

    
    // Set up I2C bus.
    if(NV_FALSE == NvAccelerometerI2COpen(&hAccel->hOdmI2C, hAccel->I2CChannelId))
    {
        goto error;
    };
    hAccel->RegsRead  = NvAccelerometerI2CGetRegs;
    hAccel->RegsWrite = NvAccelerometerI2CSetRegs;
    
    NvOdmAccelerometerGetParameter(hAccel, XLR_WHOAMI, &test_val);
    if(XLR_IDNUM != test_val)
    {
        goto error;
    }
    
    NvOdmAccelerometerGetParameter(hAccel, XLR_DEVID, &test_val);
    if (test_val == XLR_NEWCHIPID)
    {
        // This chip is ADXL345
        //NvOdmOsDebugPrintf("This chip is ADXL345!!!\n");
        hAccel->CtrlRegsList[4].RegValue = 0x0A; // offset X
        hAccel->CtrlRegsList[5].RegValue = 0x0B; // offset Y
        hAccel->CtrlRegsList[6].RegValue = 0x14; // offset Z
    }
    //NVODMACCELEROMETER_PRINTF("ID is 0x%x\n", test_val);
    
    /* We don't know the reset state of the accelerometer. So, program the
     * accelerometer to disable generation of interrupts.
     *  
     *  Write to INTCONTROL register to disable genetration of the interrupts.
     *  Write to INTCONTROL2 to clear the already latched interrupts.
     */
    NvOdmAccelerometerSetParameter(hAccel, XLR_ATTR_INTCONTROL, 0x0);
    NvOdmAccelerometerSetParameter(hAccel, XLR_ATTR_INTCONTROL2, 0x1);
    if(NV_FALSE == NvAccelerometerConnectSemaphore(hAccel))
    {
        goto error;
    }
    
    //init accelerometer
    for(i=0; i<hAccel->nLength; i++)
    {
            NvOdmAccelerometerSetParameter(hAccel,
                                           hAccel->CtrlRegsList[i].RegAddr, 
                                           hAccel->CtrlRegsList[i].RegValue);
    }
    // Set up event.
    
    //NvOdmAccelerometerGetParameter(XLR_SCALE, hAccel);
    *hDevice = hAccel;
    return NV_TRUE;
    error:
        // Release all of resources requested.
        if(NULL != hAccel)
        {
            NvAccelerometerSetPowerRail(hAccel->hPmu, hAccel->VddId, NV_FALSE);
            NvOdmServicesPmuClose(hAccel->hPmu);
            hAccel->hPmu = NULL;
            NvAccelerometerI2CClose(hAccel->hOdmI2C);
            hAccel->hOdmI2C = NULL;
            NvOdmOsFree(hAccel);
            *hDevice = NULL;
        }
        return NV_FALSE;
}