Esempio n. 1
0
static int pmic_get(void *data, u64 *val)
{
    const NvOdmPeripheralConnectivity *con = NULL;
    int ldo_number;
    NvU32 millivolts;

    struct pmic_struct *pmic_info  = data;

    ldo_number = pmic_info->ldo_number;

    con = NvOdmPeripheralGetGuid(NV_ODM_GUID('a','l','l','p','o','w','e','r'));
    if (con == NULL){
        *val = 9999;
        printk("PMIC(debugfs) : query ERROR\n");
        return 0;
    }
        
    NvRmPmuGetVoltage(s_hRmGlobal, 
                con->AddressList[ldo_number].Address, &millivolts);

    if(millivolts){
        *val = 1;
        printk("PMIC(debugfs) : LDO%d (on)\n", 
                        ldo_number+1);
    }else{
        *val = 0;
        printk("PMIC(debugfs) : LDO%d (off)\n", 
                        ldo_number+1);
    }

    return 0;
}
Esempio n. 2
0
static void __init register_spi_ipc_devices(void)
{
	unsigned long instance = 0xFFFF;
	unsigned long cs = 0xFFFF;
	const NvOdmPeripheralConnectivity *pConnectivity = NULL;
	int i;

	pConnectivity =
		NvOdmPeripheralGetGuid(NV_ODM_GUID('s','p','i',' ','_','i','p','c'));
	if (!pConnectivity)
		return;

	for (i = 0; i < pConnectivity->NumAddress; i++) {
		switch (pConnectivity->AddressList[i].Interface) {
		case NvOdmIoModule_Spi:
			instance = pConnectivity->AddressList[i].Instance;
			cs = pConnectivity->AddressList[i].Address;
			break;
		default:
			break;
		}
	}

	if (instance == 0xffff || cs == 0xffff) {
		pr_err("%s: SPI IPC Protocol driver: Instance and CS are Invalid\n", __func__);
		return;
	}

	tegra_spi_ipc_devices[0].bus_num = instance;
	tegra_spi_ipc_devices[0].chip_select = cs;
	if (spi_register_board_info(tegra_spi_ipc_devices, ARRAY_SIZE(tegra_spi_ipc_devices)) != 0) {
		pr_err("%s: spi_register_board_info returned error\n", __func__);
	}
}
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;
    }
void
NvRmPrivPmuRailControl(
    NvRmDeviceHandle hRmDevice,
    NvU64 NvRailId,
    NvBool TurnOn)
{
    NvU32 RailAddress, TimeUs;
    const NvOdmPeripheralConnectivity* pPmuRail;
    NvRmPmuVddRailCapabilities RailCapabilities = {0};

    if (!s_PmuSupportedEnv)
        return;

    pPmuRail = NvOdmPeripheralGetGuid(NvRailId);

    NV_ASSERT(hRmDevice);
    NV_ASSERT(pPmuRail);
    NV_ASSERT(pPmuRail->NumAddress);

    RailAddress = pPmuRail->AddressList[0].Address;
    if (TurnOn)
    {
        NvRmPmuGetCapabilities(hRmDevice, RailAddress, &RailCapabilities);
        NvRmPmuSetVoltage(hRmDevice, RailAddress,
                          RailCapabilities.requestMilliVolts, &TimeUs);
    }
    else
    {
        NvRmPmuSetVoltage(
            hRmDevice, RailAddress, ODM_VOLTAGE_OFF, &TimeUs);
    }
    NvOsWaitUS(TimeUs);
}
Esempio n. 5
0
void NvRmPrivIoPowerControlInit(NvRmDeviceHandle hRmDeviceHandle)
{
    NvU32 i, v;
    NvU32 NoIoPwrMask = 0;
    const NvOdmPeripheralConnectivity* pPmuRail = NULL;

    if (NvRmPrivGetExecPlatform(hRmDeviceHandle) != ExecPlatform_Soc)
    {
        // Invalidate IO Power detect map if not SoC platform
        for (i = 0; i < NV_ARRAY_SIZE(s_IoPowerDetectMap); i++)
            s_IoPowerDetectMap[i].PmuRailAddress = NV_RAIL_ADDR_INVALID;
        return;
    }

    for (i = 0; i < NV_ARRAY_SIZE(s_IoPowerDetectMap); i++)
    {
        // Fill in PMU rail addresses in IO Power detect map
        pPmuRail = NvOdmPeripheralGetGuid(s_IoPowerDetectMap[i].PowerRailId);
        NV_ASSERT(pPmuRail && pPmuRail->NumAddress);
        s_IoPowerDetectMap[i].PmuRailAddress = pPmuRail->AddressList[0].Address;

        // Find all unpowered rails
        v = NvRmPrivPmuRailGetVoltage(
            hRmDeviceHandle, s_IoPowerDetectMap[i].PowerRailId);
        if (v == ODM_VOLTAGE_OFF)
            NoIoPwrMask |= s_IoPowerDetectMap[i].DisableRailMask;
    }

    // Latch already powered IO rails
    NvRmPrivIoPowerDetectLatch(hRmDeviceHandle);

    // Disable IO pads for unpowered rails
    if (NoIoPwrMask)
        NvRmPrivIoPowerControl(hRmDeviceHandle, NoIoPwrMask, NV_FALSE);
}
static void UsbPrivEnableVbus(NvDdkUsbPhy *pUsbPhy, NvBool Enable)
{
    const NvOdmPeripheralConnectivity *pConnectivity = NULL;
    NvRmPmuVddRailCapabilities RailCaps;
    NvU32 i;

    switch (pUsbPhy->Instance)
    {
        case 0:
            pConnectivity = NvOdmPeripheralGetGuid(NV_VDD_VBUS_ODM_ID);
            break;
        case 1:
            pConnectivity = NvOdmPeripheralGetGuid(NV_VDD_USB2_VBUS_ODM_ID);
            break;
        case 2:
            pConnectivity = NvOdmPeripheralGetGuid(NV_VDD_USB3_VBUS_ODM_ID);
            break;
        default:
            break;
    }

    if (pConnectivity != NULL)
    {
        for (i = 0; i < pConnectivity->NumAddress; i++)
        {
            // Search for the vdd rail entry
            if (pConnectivity->AddressList[i].Interface == NvOdmIoModule_Vdd)
            {
                NvRmPmuGetCapabilities(pUsbPhy->hRmDevice,
                            pConnectivity->AddressList[i].Address, &RailCaps);

                if (Enable)
                {
                    NvRmPmuSetVoltage(pUsbPhy->hRmDevice,
                            pConnectivity->AddressList[i].Address, RailCaps.requestMilliVolts, NULL);
                }
                else
                {
                    NvRmPmuSetVoltage(pUsbPhy->hRmDevice,
                            pConnectivity->AddressList[i].Address, ODM_VOLTAGE_OFF, NULL);
                }
            }
        }
    }
}
Esempio n. 7
0
static int __init touchLED_probe(struct platform_device *pdev)
{
    s_touchLED.conn = NvOdmPeripheralGetGuid( NV_ODM_GUID('t','o','u','c','h','L','E','D') );

    /* enable the power rail */
    s_touchLED.hPmu = NvOdmServicesPmuOpen();
    if( s_touchLED.conn->AddressList[0].Interface == NvOdmIoModule_Vdd )
    {
        NvOdmServicesPmuVddRailCapabilities cap;
        NvU32 settle_us;

        /* address is the vdd rail id */
        NvOdmServicesPmuGetCapabilities( s_touchLED.hPmu,
            s_touchLED.conn->AddressList[0].Address, &cap );

        s_touchLED.setVal = cap.requestMilliVolts;
        s_touchLED.maxVal = 100;    /*10.0mA*/

        /* set the rail volatage to the recommended */
        NvOdmServicesPmuSetVoltage( s_touchLED.hPmu,
            s_touchLED.conn->AddressList[0].Address, cap.requestMilliVolts,
            &settle_us );

        /* wait for rail to settle */
        NvOdmOsWaitUS( settle_us );
    }
    INIT_WORK(&s_touchLED.work, touchLED_timeout);

#ifdef TOUCH_LED_TIMER 
    hrtimer_init(&s_touchLED.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
    s_touchLED.timer.function = touchLED_timer_func;
    s_touchLED.delay = TOUCH_DELAY_SEC;
    hrtimer_start(&s_touchLED.timer, ktime_set(BOOT_DELAY_SEC, 0), HRTIMER_MODE_REL);
#endif

#ifdef CONFIG_HAS_EARLYSUSPEND
    s_touchLED.early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
    s_touchLED.early_suspend.suspend = touchLED_early_suspend;
    s_touchLED.early_suspend.resume = touchLED_late_resume;
    register_early_suspend(&s_touchLED.early_suspend);
#endif

    //20101104, [email protected], WLED set [START]
    if (sysfs_create_group(&pdev->dev.kobj, &star_wled_group)) {
        printk(KERN_ERR "[star touch led] sysfs_create_group ERROR\n");
    }
    //20101104, [email protected], WLED set [END]

    return 0;
}
Esempio n. 8
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;
}
Esempio n. 9
0
NvBool NvOdmVibStart(NvOdmVibDeviceHandle hDevice)
{
 	NvOdmPeripheralConnectivity const *conn;
        NvU64 guid;
              
        /* get the main panel */
        guid = VIBRATOR_GUID;

        /* get the connectivity info */
        conn = NvOdmPeripheralGetGuid(guid);
        if(conn == NULL)
        {
                return NV_FALSE;       
        }
        
        /* acquire GPIO pins */
        ghGpio = NvOdmGpioOpen();
        if (ghGpio == NULL)
        {
                return NV_FALSE;
        }
        
        if (ghVibGpioPin == NULL)
        {
                /* Search for the GPIO pin */
                if (conn->AddressList[0].Interface == NvOdmIoModule_Gpio)
                {
                     ghVibGpioPin = NvOdmGpioAcquirePinHandle(ghGpio, 
                           conn->AddressList[0].Instance,
                           conn->AddressList[0].Address);
                }
        }
        
        if (ghVibGpioPin == NULL)
        {
                return NV_FALSE;
        }

        NvOdmGpioSetState(ghGpio, ghVibGpioPin, 0x1);
        NvOdmGpioConfig(ghGpio, ghVibGpioPin, NvOdmGpioPinMode_Output);

        VIBE_TPS658620_I2cWrite8(TPS658620_PWM1_ADDR, hDevice->CurrentIndex);
        return NV_TRUE;
}
Esempio n. 10
0
NvU32
NvRmPrivPmuRailGetVoltage(
    NvRmDeviceHandle hRmDevice,
    NvU64 NvRailId)
{
    NvU32 RailAddress;
    const NvOdmPeripheralConnectivity* pPmuRail;
    NvU32 MilliVolts = NVRM_NO_PMU_DEFAULT_VOLTAGE;

    if (s_PmuSupportedEnv)
    {
        pPmuRail = NvOdmPeripheralGetGuid(NvRailId);

        NV_ASSERT(hRmDevice);
        NV_ASSERT(pPmuRail);
        NV_ASSERT(pPmuRail->NumAddress);

        RailAddress = pPmuRail->AddressList[0].Address;
        NvRmPmuGetVoltage(hRmDevice, RailAddress, &MilliVolts);
    }
    return MilliVolts;
}
Esempio n. 11
0
static ssize_t star_pmic_store(struct device *dev, 
            struct device_attribute *attr, char *buf, size_t count)
{
    u32 val = 0;

    val = simple_strtoul(buf, NULL, 10);
    if(val){
        NvOdmPeripheralConnectivity const *conn = NULL;
        NvOdmServicesPmuHandle hPmu;

        conn = NvOdmPeripheralGetGuid( NV_ODM_GUID('p','m','_','r','e','s','e','t') );
        hPmu = NvOdmServicesPmuOpen();

        if(!conn){
            printk("ERROR : invalid GUID\n");
            sprintf(buf, "PMIC reset fail\n");
            return (ssize_t)(strlen(buf) + 1); 
        }
        
        if( conn->AddressList[0].Interface == NvOdmIoModule_Vdd )
        {
            NvU32 settle_us;
        
            /* set the rail volatage to the recommended */
            NvOdmServicesPmuSetVoltage( hPmu,
                conn->AddressList[0].Address, NVODM_VOLTAGE_OFF, &settle_us );
        
            /* wait for rail to settle */
            NvOdmOsWaitUS( settle_us );
        }

        NvOdmServicesPmuClose(hPmu);
    }
    sprintf(buf, "PMIC reset\n");
    printk("PMIC reset\n");

    return (ssize_t)(strlen(buf) + 1);
}
Esempio n. 12
0
void NvRmPrivPmuLPxStateConfig(
    NvRmDeviceHandle hRmDevice,
    NvOdmSocPowerState state,
    NvBool enter)
{
    NvOdmPmuProperty PmuProperty = {0};
    NvBool HasPmuProperty = NvOdmQueryGetPmuProperty(&PmuProperty);
    const NvOdmPeripheralConnectivity* pCoreRail =
        NvOdmPeripheralGetGuid(NV_VDD_CORE_ODM_ID);

    NV_ASSERT(hRmDevice);
    NV_ASSERT(pCoreRail);
    NV_ASSERT(pCoreRail->NumAddress);

    // On platforms with combined cpu/core power request core power rail
    // should be controlled by the combined request only during deep sleep
    // - enable the On/Off control on entry, and disable on exit
    if (state == NvOdmSocPowerState_DeepSleep)
    {
    //  : AP20 need USB power work around
#if defined(CONFIG_MACH_STAR)
        if (HasPmuProperty)
#else
        if (HasPmuProperty && PmuProperty.CombinedPowerReq)
#endif
        {
            NvU32 level = enter ?
                ODM_VOLTAGE_ENABLE_EXT_ONOFF : ODM_VOLTAGE_DISABLE_EXT_ONOFF;
            NvRmPmuSetVoltage(hRmDevice, pCoreRail->AddressList[0].Address,
                              level, NULL);
        }
    }
    // Mask/Unmask PMU interrupt on entry/exit to/from suspend or deep sleep
    if ((state == NvOdmSocPowerState_Suspend) ||
        (state == NvOdmSocPowerState_DeepSleep))
        NvRmPrivPmuInterruptMask(hRmDevice, enter);
}
Esempio n. 13
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;
}
Esempio n. 14
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;
}
/**
 *  @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;
}
Esempio n. 16
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;
}
Esempio n. 17
0
int __devinit tegra_sdhci_simple_probe(struct platform_device *pdev)
{
	struct tegra_sdhci_simple *host;
	struct tegra_sdhci_simple_platform_data *pdata = pdev->dev.platform_data;
	NvOdmPeripheralConnectivity *pConn;
	NvU32 NumOfGuids = 1;
	NvU64 guid;
	NvU32 searchVals[4];
	const NvOdmPeripheralSearch searchAttrs[] = {
		NvOdmPeripheralSearch_PeripheralClass,
		NvOdmPeripheralSearch_IoModule,
		NvOdmPeripheralSearch_Instance,
		NvOdmPeripheralSearch_Address,
	};
	int i, ret = -ENODEV;

	pr_info("%s", __func__);
	if (pdev->id == -1) {
		dev_err(&pdev->dev, "dynamic instance assignment not allowed\n");
		return -ENODEV;
	}

	host = &tegra_sdhci_simple_host;

	/*
	 * Emulate NvOdmSdioOpen() to avoid heap usage and power on request
	 */
	searchVals[0] =  NvOdmPeripheralClass_Other;
	searchVals[1] =  NvOdmIoModule_Sdio;
	searchVals[2] =  pdev->id;
	searchVals[3] =  0;

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

	pConn = (NvOdmPeripheralConnectivity*)NvOdmPeripheralGetGuid(guid);
	if (pConn == NULL)
		goto err_odm;

	for (i = 0; i < pConn->NumAddress; i++)
	{
		if (pConn->AddressList[i].Interface == NvOdmIoModule_Vdd)
		{
			host->VddAddress = pConn->AddressList[i].Address;
			NvOdmServicesPmuGetCapabilities(host->hPmu,
							host->VddAddress,
							&host->VddRailCaps);
		}
	}
	host->hPmu = NvOdmServicesPmuOpen();
	if (host->hPmu == NULL) {
		pr_err("%s: failed to open PMU\n", __func__);
		goto err_odm;
	}

	for (i = 0; i < pdata->num_resources; i++) {
		if (pdata->resource &&
		    pdata->resource[i].flags & IORESOURCE_MEM &&
		    pdata->resource[i].end - pdata->resource[i].start > 0)
			break;
	}

	if (i >= pdata->num_resources) {
		dev_err(&pdev->dev, "no memory I/O resource provided\n");
		ret = -ENODEV;
		goto err_odm;
	}

	host->ioaddr = ioremap(pdata->resource[i].start,
			       pdata->resource[i].end -
					pdata->resource[i].start + 1);

	host->clk = clk_get_sys(pdata->clk_dev_name, NULL);
	if (!host->clk) {
		dev_err(&pdev->dev, "unable to get clock %s\n", pdata->clk_dev_name);
		ret = -ENODEV;
		goto err_ioremap;
	}

	host->pdev = pdev;
	host->pinmux = pdata->sdhci_pdata->pinmux;
	host->nr_pins = pdata->sdhci_pdata->nr_pins;
	if (pdata->sdhci_pdata->max_clk)
		host->max_clk = min_t(unsigned int, 52000000, pdata->sdhci_pdata->max_clk);
	else {
Esempio n. 18
0
static int headsetdet_probe(struct platform_device *pdev)
{
	struct gpio_switch_platform_data *pdata = pdev->dev.platform_data;
	struct headset_switch_data *switch_data;
	int ret = 0;
	NvS32 err = 0;

	struct input_dev *ip_dev;  
    struct input_dev *ip_dev_wake; 

    int i, j;
    NvU32 I2cInstance = 0;
    NvU32 pin[4], port[4];
    const NvOdmPeripheralConnectivity *pConnectivity = NULL;

    pConnectivity = NvOdmPeripheralGetGuid(HEADSET_GUID);

    for (i = 0, j = 0 ; i < pConnectivity->NumAddress; i++)
    {
        switch (pConnectivity->AddressList[i].Interface)
        {
            case NvOdmIoModule_Gpio:
                port[j] = pConnectivity->AddressList[i].Instance;
                pin[j] = pConnectivity->AddressList[i].Address;
                j++;
                break;
            //20101117, [email protected], gpio wakeup from LP1 [START]
            case NvOdmIoModule_Vdd:
                {
                    NvOdmServicesPmuVddRailCapabilities vddrailcap;

                    headset_h_pmu = NvOdmServicesPmuOpen();
                    headset_vdd_address = pConnectivity->AddressList[i].Address;
                    NvOdmServicesPmuGetCapabilities(headset_h_pmu, pConnectivity->AddressList[i].Address, &vddrailcap);
                    headset_vdd_voltage = vddrailcap.requestMilliVolts;
                }
                break;
            //20101117, [email protected], gpio wakeup from LP1 [END]
            default:
                break;
        }
    }

	if (!pdata)
		return -EBUSY;
	switch_data = kzalloc(sizeof(struct headset_switch_data), GFP_KERNEL);
	if (!switch_data)
		return -ENOMEM;

	switch_data->sdev.name = pdata->name;
	switch_data->gpio = pdata->gpio;
	switch_data->name_on = pdata->name_on;
	switch_data->name_off = pdata->name_off;
	switch_data->state_on = pdata->state_on;
	switch_data->state_off = pdata->state_off;
	switch_data->sdev.print_state = switch_gpio_print_state;


	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headsetdet_probe() => headset detection started..!!\n");	//20100421 [email protected] [LGE]

    ret = switch_dev_register(&switch_data->sdev);	//20100421 [email protected] Headset Detection by Headset Observer [LGE]
	if (ret < 0)
		goto err_switch_dev_register;

	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset detection - switch device registered..!!\n");	//20100421 [email protected] [LGE]


/*====================== nVidia GPIO Control(S) =======================*/

    s_hHeadsetHandle.hGpio = NvOdmGpioOpen();
    if (!s_hHeadsetHandle.hGpio)
    {
        lprintk(D_AUDIO, "%s: NvOdmGpioOpen Error \n", __func__);
        goto err_open_gpio_fail;
    }
	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset detection - NvOdmGpioOpen() success..!! : s_hHeadsetHandle.hGpio = %d, port[0] = %d, pin[0] = %d\n", s_hHeadsetHandle.hGpio, port[0], pin[0]);	//20100421 [email protected] [LGE]


    s_hHeadsetHandle.h_Headset_Detection = NvOdmGpioAcquirePinHandle(s_hHeadsetHandle.hGpio, port[0], pin[0]);
    if (!s_hHeadsetHandle.h_Headset_Detection)
    {
        lprintk(D_AUDIO, "%s: Couldn't NvOdmGpioAcquirePinHandle  pin \n", __func__);
        goto err_open_gpio_pin_acquire_fail;
    }
	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset detection - NvOdmGpioAcquirePinHandle() success..!!\n");	//20100421 [email protected] [LGE]


    NvOdmGpioConfig(s_hHeadsetHandle.hGpio, s_hHeadsetHandle.h_Headset_Detection, NvOdmGpioPinMode_InputData/*NvOdmGpioPinMode_InputInterruptHigh*/);
	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset detection - NvOdmGpioConfig() success..!! - NvOdmGpioPinMode_InputData");	//20100421 [email protected] [LGE]



    s_hHeadsetHandle.h_Hookkey_Detection = NvOdmGpioAcquirePinHandle(s_hHeadsetHandle.hGpio, port[1], pin[1]);
    if (!s_hHeadsetHandle.h_Hookkey_Detection)
    {
        lprintk(D_AUDIO, "%s:Couldn't NvOdmGpioAcquirePinHandle  pin \n", __func__);
        goto err_open_gpio_pin_acquire_fail;
    }

    NvOdmGpioConfig(s_hHeadsetHandle.hGpio, s_hHeadsetHandle.h_Hookkey_Detection, NvOdmGpioPinMode_InputData);
	ip_dev = input_allocate_device();
    
	switch_data->ip_dev = ip_dev;
	set_bit(EV_SYN, switch_data->ip_dev->evbit);
	set_bit(EV_KEY, switch_data->ip_dev->evbit);
	set_bit(KEY_HOOK, switch_data->ip_dev->keybit); 
	switch_data->ip_dev->name = "star_headset_hook";

    ip_dev_wake = input_allocate_device();
    switch_data->ip_dev_wake = ip_dev_wake;
	set_bit(EV_SYN, switch_data->ip_dev_wake->evbit);
	set_bit(EV_KEY, switch_data->ip_dev_wake->evbit);
	set_bit(KEY_VOLUMEDOWN, switch_data->ip_dev_wake->keybit); 
	switch_data->ip_dev_wake->name = "star_headset_wake";

		
	ret = input_register_device(switch_data->ip_dev);  
	INIT_DELAYED_WORK(&switch_data->hook_delayed_work, hook_det_work);
    if (NvOdmGpioInterruptRegister(s_hHeadsetHandle.hGpio, &s_hHeadsetHandle.hhookInterrupt,
        s_hHeadsetHandle.h_Hookkey_Detection, NvOdmGpioPinMode_InputInterruptAny, headset_hook_int_handler,
        switch_data, 0) == NV_FALSE)
    {
        lprintk(D_AUDIO, KERN_ERR "%s: cannot register interrupt.\n", __func__);
        goto err_get_interrupt_handler;
    }

	block_hook_int =1;
//20101005 [email protected] Gpio MicBias[START_LGE_LAB1]
#if defined(STAR_COUNTRY_KR)&& !defined(CONFIG_MACH_STAR_SKT_REV_A)
    s_hHeadsetHandle.h_Headset_MicBias = NvOdmGpioAcquirePinHandle(s_hHeadsetHandle.hGpio, port[2], pin[2]);
    if (!s_hHeadsetHandle.h_Headset_MicBias)
    {
        lprintk(D_AUDIO, "%s: Couldn't NvOdmGpioAcquirePinHandle  pin \n", __func__);
        goto err_open_gpio_pin_acquire_fail;
    }
	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset MicBias - NvOdmGpioAcquirePinHandle() success..!!\n");	//20100421 [email protected] [LGE]

    NvOdmGpioConfig(s_hHeadsetHandle.hGpio, s_hHeadsetHandle.h_Headset_MicBias, NvOdmGpioPinMode_Output);
	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset MicBias- NvOdmGpioConfig() success..!! - NvOdmGpioPinMode_Output");	//20100421 [email protected] [LGE]
#endif
//20101005 [email protected] Gpio MicBias[END_LGE_LAB1]

	INIT_WORK(&switch_data->work, headset_det_work);
    INIT_DELAYED_WORK(&switch_data->delayed_work, type_det_work);
	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset detection - INIT_WORK() & INIT_DELAYED_WORK() success..!!\n");	//20100421 [email protected] [LGE]

    if (NvOdmGpioInterruptRegister(s_hHeadsetHandle.hGpio, &s_hHeadsetHandle.hheadsetInterrupt,
        s_hHeadsetHandle.h_Headset_Detection, NvOdmGpioPinMode_InputInterruptAny/*NvOdmGpioPinMode_InputInterruptFallingEdge*//*NvOdmGpioPinMode_InputInterruptRisingEdge*/, headset_int_handler,
        switch_data, 0) == NV_FALSE)
    {
        lprintk(D_AUDIO, KERN_ERR "%s: cannot register interrupt.\n", __func__);
        goto err_get_interrupt_handler;
    }
	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset detection - NvOdmGpioInterruptRegister() success..!!\n");	//20100421 [email protected] [LGE]

    //20101125, [email protected], hookkey press is skipped When wakeup from LP1 [START]
    //wake_lock_init(&hook_det_lock, WAKE_LOCK_SUSPEND, "hook_det_wake");
    //20101125, [email protected], hookkey press is skipped When wakeup from LP1 [END]

/*====================== nVidia GPIO Control(E) =======================*/

	/* Perform initial detection */
	headset_sw_data = switch_data;

//P990_IFX_GB_PORTING_LGSI_START
//FIDO - GB Porting [09/08/2011] - Start
#if 1 //defined (STAR_OPERATOR_FIDO)
       wake_lock_init(&headset_wake_lock, WAKE_LOCK_SUSPEND, "headset_wlock");		 //20110425 [email protected] headset wake lock timeout
#endif
//FIDO - GB Porting [09/08/2011] - End
//P990_IFX_GB_PORTING_LGSI_END

	

	
	//headset_det_work(&switch_data->work);
	lprintk(D_AUDIO, KERN_ERR "##(Headset_det.c)## headset detection - headset_det_work() first detection - success..!!\n"); //20100421 [email protected] [LGE]	

	err = device_create_file(&pdev->dev, &dev_attr_detect);
    err = device_create_file(&pdev->dev, &dev_attr_block_hook);
    err = device_create_file(&pdev->dev, &dev_attr_factory_test);
	return 0;

err_open_gpio_fail:	
    switch_dev_unregister(&switch_data->sdev);
err_switch_dev_register:
	kfree(switch_data);
err_open_gpio_pin_acquire_fail:
	NvOdmGpioClose(s_hHeadsetHandle.hGpio);
err_get_interrupt_handler:
    NvOdmGpioReleasePinHandle(s_hHeadsetHandle.hGpio, s_hHeadsetHandle.h_Headset_Detection);
	
    NvOdmGpioReleasePinHandle(s_hHeadsetHandle.hGpio, s_hHeadsetHandle.h_Hookkey_Detection);	//20100421 [email protected] for Hookkey [LGE]
    

	return ret;
}
Esempio n. 19
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;
}
Esempio n. 20
0
static int vib_init( )
{
	const 	NvOdmPeripheralConnectivity *pcon;
	int 		err;
	NvBool 	found_gpio = NV_FALSE;
	int 		loop;

	g_vib = kzalloc( sizeof(*g_vib), GFP_KERNEL );
	if ( g_vib == NULL ) {
		err = -1;
		printk( "[%s] fail vib\n", __func__ );
		return err;
	}

 	pcon = ( NvOdmPeripheralConnectivity* ) NvOdmPeripheralGetGuid( NV_ODM_GUID('v','i','b','r','a','t','o','r') );
	for ( loop=0; loop< pcon->NumAddress; loop++ ) {
		switch ( pcon->AddressList[loop].Interface ) {
			case NvOdmIoModule_Gpio:
				g_vib->en_port = pcon->AddressList[loop].Instance;
	        	g_vib->en_pin = pcon->AddressList[loop].Address;
	        	found_gpio = NV_TRUE;
	        	break;

	    	case NvOdmIoModule_Vdd:
            	g_vib->vdd_id = pcon->AddressList[loop].Address;
            	DbgOut(( "VIB POWER %d\n", g_vib->vdd_id ));
				if ( vib_set_power_rail( g_vib->vdd_id,  NV_TRUE) != 0 )
					return -ENOSYS;
		        break;

			default:
		        break;
		} // end of switch

	} // end of for

	DbgOut(( "[ImmVibeSPI][%s] : vibrator Int Port = %c, Int Pin = %d\n", __func__, (g_vib->en_port+'a'), g_vib->en_pin ));

	g_vib->h_vib_gpio = NvOdmGpioOpen( );
	if( ! g_vib->h_vib_gpio ) {
		printk( "[ImmVibeSPI][%s] : Failed to open gpio\n", __func__ );
		err = - ENOSYS;
		return err;
	}

#ifdef MACH_STAR_REV_A
	g_vib->en_port = 'u' - 'a';
	g_vib->en_pin = 5;
#endif

#if defined ( CONFIG_MACH_STAR )
	g_vib->en_port = 'u' - 'a';
	g_vib->en_pin = 4;
#endif

	g_vib->h_vib_gpio_pin = NvOdmGpioAcquirePinHandle( g_vib->h_vib_gpio, g_vib->en_port, g_vib->en_pin );
	if ( ! g_vib->h_vib_gpio_pin ) {
    	printk( "[ImmVibeSPI][%s] : Failed to acquire the pin handle\n", __func__ );
    	err = -ENOSYS;
    	return err;
	}

	g_vib->hOdmPwm = NvOdmPwmOpen( );
	if ( ! g_vib->hOdmPwm ) {
		printk( "[ImmVibeSPI][%s] : Failed to acquire the PWM handle\n", __func__ );
		err = - ENOSYS;
		return err;
	}

	return 0;
}
Esempio n. 21
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;
}
Esempio n. 22
0
NvBool VIBE_TPS658620_I2cWrite8(NvU8 Addr, NvU8 Data)
{
    NvBool RetVal = NV_TRUE;
    NvU8 WriteBuffer[2];
    NvOdmI2cStatus status = NvOdmI2cStatus_Success;    
    NvOdmI2cTransactionInfo TransactionInfo;
    NvU32 DeviceAddr = (NvU32)TPS658620_DEVICE_ADDR;
    NvU32 i = 0;

    NvOdmIoModule I2cModule = NvOdmIoModule_I2c;
    NvU32 I2cInstance = 0;
    NvU32 I2cAddress  = 0;

    const NvOdmPeripheralConnectivity *pConnectivity = 
                           NvOdmPeripheralGetGuid(NV_ODM_GUID('t','p','s','6','5','8','6','x'));

    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;
        }
    }


    s_hOdmI2c = NvOdmI2cOpen(I2cModule, I2cInstance);
    if (!s_hOdmI2c)
    {
        RetVal = NV_FALSE;
        goto VIBE_TPS658620_I2cWrite8_exit;
    }


    DEBUG_VIBRATOR_TRACE(("[VIBE] : Open vibrate I2C success!\n"));

    WriteBuffer[0] = Addr & 0xFF;   // PMU offset
    //modify by ,set DPWM_MODE=0, fixed freq=250Hz ,duty cycle=0~127
    //WriteBuffer[1] = Data & 0xFF;   // written data
    WriteBuffer[1] = Data & 0x7F;   // written data

    TransactionInfo.Address = DeviceAddr;
    TransactionInfo.Buf = WriteBuffer;
    TransactionInfo.Flags = NVODM_I2C_IS_WRITE;
    TransactionInfo.NumBytes = 2;

    status = NvOdmI2cTransaction(s_hOdmI2c, &TransactionInfo, 1, 
                        TPS658620_I2C_SPEED_KHZ, NV_WAIT_INFINITE);

    if (status == NvOdmI2cStatus_Success)
    {
        RetVal = NV_TRUE;
        DEBUG_VIBRATOR_TRACE(("[VIBE] : Write vibrate I2C success!\n"));
    }
    else
    {
        RetVal = NV_FALSE;
        goto VIBE_TPS658620_I2cWrite8_exit;
        DEBUG_VIBRATOR_TRACE(("[VIBE] : Write vibrate I2C fail!\n"));
    }

    NvOdmI2cClose(s_hOdmI2c);
    s_hOdmI2c = NULL;
    return RetVal;

VIBE_TPS658620_I2cWrite8_exit:
    DEBUG_VIBRATOR_TRACE(("[VIBE] : Open or Write vibrate I2C fail!\n"));
    NvOdmI2cClose(s_hOdmI2c);
    s_hOdmI2c = NULL;
    return RetVal;
}
Esempio n. 23
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;
}
static NvOdmPmuDevice*
GetPmuInstance(NvOdmPmuDeviceHandle hDevice)
{
    static NvOdmPmuDevice Pmu;
    static NvBool         first = NV_TRUE;

    if (first)
    {
        NvOdmOsMemset(&Pmu, 0, sizeof(Pmu));
        first = NV_FALSE;

        if (NvOdmPeripheralGetGuid(NV_ODM_GUID('t','p','s','6','5','8','6','x')))
        {
            //  fill in HAL functions here.
            Pmu.Hal = NV_TRUE;
            Pmu.pfnSetup = Tps6586xSetup;
            Pmu.pfnRelease = Tps6586xRelease;
            Pmu.pfnGetCaps = Tps6586xGetCapabilities;
            Pmu.pfnGetVoltage = Tps6586xGetVoltage;
            Pmu.pfnSetVoltage = Tps6586xSetVoltage;
            Pmu.pfnGetAcLineStatus = Tps6586xGetAcLineStatus;
            Pmu.pfnGetBatteryStatus = Tps6586xGetBatteryStatus;
            Pmu.pfnGetBatteryData = Tps6586xGetBatteryData;
            Pmu.pfnGetBatteryFullLifeTime = Tps6586xGetBatteryFullLifeTime;
            Pmu.pfnGetBatteryChemistry = Tps6586xGetBatteryChemistry;
            Pmu.pfnSetChargingCurrent = Tps6586xSetChargingCurrent;
            Pmu.pfnInterruptHandler = Tps6586xInterruptHandler;
            Pmu.pfnReadRtc = Tps6586xReadRtc;
            Pmu.pfnWriteRtc = Tps6586xWriteRtc;
            Pmu.pfnReadAlarm = Tps6586xReadAlarm;
            Pmu.pfnWriteAlarm = Tps6586xWriteAlarm;
            Pmu.pfnIsRtcInitialized = Tps6586xIsRtcInitialized;
        }
        else if (NvOdmPeripheralGetGuid(NV_ODM_GUID('p','c','f','_','p','m','u','0')))
        {
            
            Pmu.pfnSetup                  = Pcf50626Setup;
            Pmu.pfnRelease                = Pcf50626Release;
            Pmu.pfnGetCaps                = Pcf50626GetCapabilities;
            Pmu.pfnGetVoltage             = Pcf50626GetVoltage;
            Pmu.pfnSetVoltage             = Pcf50626SetVoltage;
            Pmu.pfnGetAcLineStatus        = Pcf50626GetAcLineStatus;
            Pmu.pfnGetBatteryStatus       = Pcf50626GetBatteryStatus;
            Pmu.pfnGetBatteryData         = Pcf50626GetBatteryData;
            Pmu.pfnGetBatteryFullLifeTime = Pcf50626GetBatteryFullLifeTime;
            Pmu.pfnGetBatteryChemistry    = Pcf50626GetBatteryChemistry;
            Pmu.pfnSetChargingCurrent     = Pcf50626SetChargingCurrent;
            Pmu.pfnInterruptHandler       = Pcf50626InterruptHandler;
            Pmu.pfnReadRtc                = Pcf50626RtcCountRead;
            Pmu.pfnWriteRtc               = Pcf50626RtcCountWrite;
            Pmu.pfnReadAlarm              = NULL;
            Pmu.pfnWriteAlarm             = NULL;
            Pmu.pfnIsRtcInitialized       = Pcf50626IsRtcInitialized;
            Pmu.pPrivate                  = NULL;            
            Pmu.Hal                       = NV_TRUE;  
            Pmu.Init                      = NV_FALSE;
        }
        else if (NvOdmPeripheralGetGuid(NV_ODM_GUID('m','a','x','8','9','0','7','b')))
        {

            Pmu.pfnSetup                  = Max8907bSetup;
            Pmu.pfnRelease                = Max8907bRelease;
            Pmu.pfnGetCaps                = Max8907bGetCapabilities;
            Pmu.pfnGetVoltage             = Max8907bGetVoltage;
            Pmu.pfnSetVoltage             = Max8907bSetVoltage;
            Pmu.pfnGetAcLineStatus        = Max8907bGetAcLineStatus;
            Pmu.pfnGetBatteryStatus       = Max8907bGetBatteryStatus;
            Pmu.pfnGetBatteryData         = Max8907bGetBatteryData;
            Pmu.pfnGetBatteryFullLifeTime = Max8907bGetBatteryFullLifeTime;
            Pmu.pfnGetBatteryChemistry    = Max8907bGetBatteryChemistry;
            Pmu.pfnSetChargingCurrent     = Max8907bSetChargingCurrent;
            Pmu.pfnInterruptHandler       = Max8907bInterruptHandler;
            Pmu.pfnReadRtc                = Max8907bRtcCountRead;
            Pmu.pfnWriteRtc               = Max8907bRtcCountWrite;
            Pmu.pfnReadAlarm              = NULL;
            Pmu.pfnWriteAlarm             = NULL;
            Pmu.pfnIsRtcInitialized       = Max8907bIsRtcInitialized;
            Pmu.pPrivate                  = NULL;
            Pmu.Hal                       = NV_TRUE;  
            Pmu.Init                      = NV_FALSE;
        }
    }

    if (hDevice && Pmu.Hal)
        return &Pmu;

    return NULL;
}
Esempio n. 25
0
static int __init proximity_probe(struct platform_device *pdev)
{
    int i, ret = 0;
    NvU32 I2cInstance = 0;
    const NvOdmPeripheralConnectivity *pConnectivity = NULL;
    NvU32 port = 0, pin = 0;
    struct device *dev = &pdev->dev;
	unsigned int pinvalue;

	atomic_set(&proxi_status, 1);
    pConnectivity = NvOdmPeripheralGetGuid(PROXIMITY_GUID);

    for (i = 0; i < pConnectivity->NumAddress; i++)
    {
        switch (pConnectivity->AddressList[i].Interface)
        {
            case NvOdmIoModule_I2c:
                s_proximity.i2c_address = (pConnectivity->AddressList[i].Address << 1);
                I2cInstance = pConnectivity->AddressList[i].Instance;
                break;
            case NvOdmIoModule_Gpio:
                port = pConnectivity->AddressList[i].Instance;
                pin = pConnectivity->AddressList[i].Address;
                break;
            case NvOdmIoModule_Vdd:
                s_proximity.vddId = pConnectivity->AddressList[i].Address;
                break;
            default:
                break;
        }
    }

	s_proximity.MVO = 0;
	#if defined(CONFIG_MACH_STAR_MDM_C)
	port = 'r' - 'a';//'a' - 'a';
	pin = 2;//0;
	#elif defined (CONFIG_MACH_STAR_REV_F) || defined (CONFIG_MACH_STAR_TMUS)
	port = 'w'-'a';
	pin = 2;
	#else
	#error PROXI_OUT PIN not assigned
	#endif

    lprintk(D_PROXI, "[star Proximity] start!!!--------------------------------------------------------------------------\n");

    s_proximity.proxi_out_gpio = NvOdmGpioOpen();
    if (!s_proximity.proxi_out_gpio)
    {
        lprintk(D_PROXI, "[star Proximity] gpio open fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
        ret = -ENOSYS;
        goto err_open_gpio_fail;
    }

    s_proximity.proxi_out_gpio_pin = NvOdmGpioAcquirePinHandle(s_proximity.proxi_out_gpio, port, pin);
    if (!s_proximity.proxi_out_gpio_pin)
    {
        lprintk(D_PROXI, "[star Proximity] gpio pin acquire fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
        ret = -ENOSYS;
        goto err_open_gpio_pin_acquire_fail;
    }

//    NvOdmGpioSetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, 0x1);
//    NvOdmGpioConfig(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, NvOdmGpioPinMode_InputData);
	#if 1

    INIT_WORK(&s_proximity.work, star_proxi_workqueue_func);

    s_proximity.gen2_i2c = NvOdmI2cPinMuxOpen(NvOdmIoModule_I2c, 1, NvOdmI2cPinMap_Config2);
    if (!s_proximity.gen2_i2c)
    {
        lprintk(D_PROXI, "[star Proximity] i2c open fail!\n");
        ret = -ENOSYS;
        goto err_open_i2c_handle_fail;
    }


    s_proximity.use_int_mode = true;
	#if 0
    NvOdmGpioConfig(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, NvOdmGpioPinMode_Output);
    NvOdmGpioSetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, 0x1);
		NvOdmOsWaitUS(100000);//100ms
   	NvOdmGpioGetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, &pinvalue);
	printk("interrupt pin level = %d\n----------------", pinvalue );
    NvOdmGpioSetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, 0x0);
		NvOdmOsWaitUS(100000);//100ms
   	NvOdmGpioGetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, &pinvalue);
	printk("interrupt pin level = %d\n----------------", pinvalue );
    NvOdmGpioSetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, 0x1);
		NvOdmOsWaitUS(100000);//100ms
   	NvOdmGpioGetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, &pinvalue);
	printk("interrupt pin level = %d\n----------------", pinvalue );
    NvOdmGpioSetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, 0x0);
		NvOdmOsWaitUS(100000);//100ms
   	NvOdmGpioGetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, &pinvalue);
	printk("interrupt pin level = %d\n----------------", pinvalue );
    NvOdmGpioSetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, 0x1);
		NvOdmOsWaitUS(100000);//100ms
   	NvOdmGpioGetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, &pinvalue);
	printk("interrupt pin level = %d\n----------------", pinvalue );
	#endif	

	#if 0 
	while(1)
	{
    	NvOdmGpioSetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, 0x1);
		NvOdmOsWaitUS(100000);//100ms
    	NvOdmGpioSetState(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, 0x0);
		NvOdmOsWaitUS(100000);//100ms
	}
	#endif

    NvOdmGpioConfig(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin, NvOdmGpioPinMode_InputData);

    if (s_proximity.use_int_mode == true) {
        if (NvOdmGpioInterruptRegister(s_proximity.proxi_out_gpio, &s_proximity.proxi_out_intr,
            s_proximity.proxi_out_gpio_pin, NvOdmGpioPinMode_InputInterruptLow, star_proxi_interrupt_handler, (void*)&s_proximity, 0) == NV_FALSE)
        {
            lprintk(D_PROXI, "[star Proximity] interrupt register fail!\n");
            ret = -ENOSYS;
            goto err_open_irq_handle_fail;
        }
    } else {
        if (NvOdmGpioInterruptRegister(s_proximity.proxi_out_gpio, &s_proximity.proxi_out_intr,
            s_proximity.proxi_out_gpio_pin, NvOdmGpioPinMode_InputInterruptFallingEdge, star_proxi_sleep_handler, (void*)&s_proximity, 0) == NV_FALSE)
        {
            lprintk(D_PROXI, "[star Proximity] interrupt register fail!\n");
            ret = -ENOSYS;
            goto err_open_irq_handle_fail;
        }

        hrtimer_init(&s_proximity.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        s_proximity.timer.function = star_proxi_timer_func;
        s_proximity.delay = PROXI_DEFAULT_DELAY_NS;
    }


    NvOdmGpioInterruptMask(s_proximity.proxi_out_intr, NV_TRUE);

    s_proximity.input_dev = input_allocate_device();
    if (!s_proximity.input_dev) {
        lprintk(D_PROXI, "[star Proximity] input device alloc fail!\n");
        ret = -ENOMEM;
        goto err_alloc_input_device_fail;
    }

    set_bit(EV_KEY, s_proximity.input_dev->evbit);
    set_bit(KEY_POWER, s_proximity.input_dev->keybit);
    set_bit(EV_ABS, s_proximity.input_dev->evbit);
    input_set_abs_params(s_proximity.input_dev, ABS_DISTANCE, 0, 1, 0, 0);
    s_proximity.input_dev->name = "proximity";
    ret = input_register_device(s_proximity.input_dev);
    if (ret) {
        lprintk(D_PROXI, "[star Proximity] input device register fail!\n");
        ret = -ENOMEM;
        goto err_alloc_input_device_fail;
    }

    if ((ret = sysfs_create_group(&dev->kobj, &star_proxi_group))) {
        lprintk(D_PROXI, "[star Proximity] sysfs_create_group fail!\n");
        ret = -ENOMEM;
        goto err_sysfs_group_fail;
    }

//    star_proxi_power_onoff(&s_proximity, true);

    return 0;

err_sysfs_group_fail:
    input_unregister_device(s_proximity.input_dev);
err_alloc_input_device_fail:
    NvOdmGpioInterruptUnregister(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin,
        s_proximity.proxi_out_intr);
err_open_irq_handle_fail:
    NvOdmI2cClose(s_proximity.gen2_i2c); 
err_open_i2c_handle_fail:
    NvOdmGpioReleasePinHandle(s_proximity.proxi_out_gpio, s_proximity.proxi_out_gpio_pin);
err_open_gpio_pin_acquire_fail:
    NvOdmGpioClose(s_proximity.proxi_out_gpio);
err_open_gpio_fail:

    return ret;

#endif
}
Esempio n. 26
0
static int __init muic_probe(struct platform_device *pdev)
{
    int i, j, ret;
#ifdef _MUIC_GPIO_I2C_
    int ret_val;
#else	
    NvU32 I2cInstance = 0;
#endif
#if defined(CONFIG_MACH_STAR_REV_D) || defined(CONFIG_MACH_STAR_REV_E) || defined(CONFIG_MACH_STAR_REV_F)
    NvU32 pin[5], port[5];
#else
    NvU32 pin[4], port[4];
#endif
    const NvOdmPeripheralConnectivity *pConnectivity = NULL;

    printk(KERN_INFO "muic_probe\n");

    pConnectivity = NvOdmPeripheralGetGuid(MUIC_GUID);

    for (i = 0, j = 0 ; i < pConnectivity->NumAddress; i++)
    {
        switch (pConnectivity->AddressList[i].Interface)
        {
#ifndef _MUIC_GPIO_I2C_
            case NvOdmIoModule_I2c:
                s_hMuicHandle.DeviceAddr = (pConnectivity->AddressList[i].Address << 1);
                I2cInstance = pConnectivity->AddressList[i].Instance;
                break;
#endif
            case NvOdmIoModule_Gpio:
                port[j] = pConnectivity->AddressList[i].Instance;
                pin[j] = pConnectivity->AddressList[i].Address;
                j++;
                break;
            default:
                break;
        }
    }

    s_hMuicHandle.hGpio = NvOdmGpioOpen();
    if (!s_hMuicHandle.hGpio)
    {
        lprintk(D_MUIC, "%s: NvOdmGpioOpen Error \n", __func__);
        goto err_open_gpio_fail;
    }

    s_hMuicHandle.h_INT_N_MUIC = NvOdmGpioAcquirePinHandle(s_hMuicHandle.hGpio, port[0], pin[0]);
    if (!s_hMuicHandle.h_INT_N_MUIC)
    {
        lprintk(D_MUIC, "%s: Couldn't NvOdmGpioAcquirePinHandle  pin \n", __func__);
        goto err_open_gpio_pin_acquire_fail;
    }

    s_hMuicHandle.h_AP20_UART_SW = NvOdmGpioAcquirePinHandle(s_hMuicHandle.hGpio, port[1], pin[1]);
    if (!s_hMuicHandle.h_AP20_UART_SW)
    {
        lprintk(D_MUIC, "%s:Couldn't NvOdmGpioAcquirePinHandle  pin \n", __func__);
        goto err_open_gpio_pin_acquire_fail;
    }

    s_hMuicHandle.h_IFX_UART_SW = NvOdmGpioAcquirePinHandle(s_hMuicHandle.hGpio, port[2], pin[2]);
    if (!s_hMuicHandle.h_IFX_UART_SW)
    {
        lprintk(D_MUIC, "%s:Couldn't NvOdmGpioAcquirePinHandle  pin \n", __func__);
        goto err_open_gpio_pin_acquire_fail;
    }

    s_hMuicHandle.h_USIF1_SW = NvOdmGpioAcquirePinHandle(s_hMuicHandle.hGpio, port[3], pin[3]);
    if (!s_hMuicHandle.h_USIF1_SW)
    {
        lprintk(D_MUIC, "%s: Couldn't NvOdmGpioAcquirePinHandle  pin \n", __func__);
        goto err_open_gpio_pin_acquire_fail;
    }

#if defined(CONFIG_MACH_STAR_REV_D) || defined(CONFIG_MACH_STAR_REV_E) || defined(CONFIG_MACH_STAR_REV_F)
    s_hMuicHandle.h_USB_VBUS_EN = NvOdmGpioAcquirePinHandle(s_hMuicHandle.hGpio, port[4], pin[4]);
    if (!s_hMuicHandle.h_USB_VBUS_EN)
    {
        lprintk(D_MUIC, "%s: Couldn't NvOdmGpioAcquirePinHandle  pin \n", __func__);
        goto err_open_gpio_pin_acquire_fail;
    }
#endif
    NvOdmGpioConfig(s_hMuicHandle.hGpio, s_hMuicHandle.h_INT_N_MUIC, NvOdmGpioPinMode_InputData);
    NvOdmGpioConfig(s_hMuicHandle.hGpio, s_hMuicHandle.h_AP20_UART_SW, NvOdmGpioPinMode_Output);
    NvOdmGpioConfig(s_hMuicHandle.hGpio, s_hMuicHandle.h_IFX_UART_SW, NvOdmGpioPinMode_Output);
    NvOdmGpioConfig(s_hMuicHandle.hGpio, s_hMuicHandle.h_USIF1_SW, NvOdmGpioPinMode_Output);
#if defined(CONFIG_MACH_STAR_REV_D) || defined(CONFIG_MACH_STAR_REV_E) || defined(CONFIG_MACH_STAR_REV_F)
    NvOdmGpioConfig(s_hMuicHandle.hGpio, s_hMuicHandle.h_USB_VBUS_EN, NvOdmGpioPinMode_Output);
#endif


#ifdef _MUIC_GPIO_I2C_
    ret_val = MUIC_Gpio_i2c_init(&s_hMuicHandle);
    if (ret_val < 0)
    {	
        lprintk(D_MUIC, "%s: MUIC_Gpio_i2c_init Error \n", __func__);
        goto err_open_i2c_handle;
    }
#else
    s_hMuicHandle.hOdmI2c = NvOdmI2cOpen(NvOdmIoModule_I2c, I2cInstance);
    if (!s_hMuicHandle.hOdmI2c)
    {
        lprintk(D_MUIC, "%s: NvOdmI2cOpen Error \n", __func__);
        goto err_open_i2c_handle;
    }
#endif
    wake_lock_init(&s_hMuicHandle.wlock, WAKE_LOCK_SUSPEND, "muic_active");

//20101117, [email protected], for autorun [START]
#ifdef CONFIG_USB_SUPPORT_LGE_ANDROID_AUTORUN
    s_hMuicHandle.sdev_autorun.name = DRIVER_NAME_FOR_AUTORUN;
    s_hMuicHandle.sdev_autorun.print_name = print_switch_name_for_autorun;
    s_hMuicHandle.sdev_autorun.print_state = print_switch_state_for_autorun;

    ret = switch_dev_register(&s_hMuicHandle.sdev_autorun);
    if (ret) {
        goto err_sdev_unregister;
    }
#endif
//20101117, [email protected], for autorun [END]

    INIT_DELAYED_WORK(&muic_wq, muic_wq_func);

    if (NvOdmGpioInterruptRegister(s_hMuicHandle.hGpio, &s_hMuicHandle.hGpioInterrupt,
                s_hMuicHandle.h_INT_N_MUIC, NvOdmGpioPinMode_InputInterruptFallingEdge , muic_interrupt_handler,
                (void*)&s_hMuicHandle, 0) == NV_FALSE) 

    {
        lprintk(D_MUIC, KERN_ERR "%s: cannot register interrupt.\n", __func__);
        goto err_get_interrupt_handler;
    }

    create_star_muic_proc_file();
    current_device = DEVICE_NONE;

    muic_initialize_max(RESET);

    
    //20100915, [email protected], move to late_initcall [START]     
#if 0		
    NvOdmOsSleepMS(400) ;
    MAX14526_Device_Detection();
#endif		
    //20100915, [email protected], move to late_initcall [STOP]  

    return 0;

err_get_interrupt_handler:
#ifndef _MUIC_GPIO_I2C_	
    NvOdmI2cClose(s_hMuicHandle.hOdmI2c);
#endif
//20101117, [email protected], for autorun [START]
#ifdef CONFIG_USB_SUPPORT_LGE_ANDROID_AUTORUN
err_sdev_unregister:
	switch_dev_unregister(&s_hMuicHandle.sdev_autorun);
#endif
//20101117, [email protected], for autorun [END]
err_open_i2c_handle:
    NvOdmGpioReleasePinHandle(s_hMuicHandle.hGpio, s_hMuicHandle.h_INT_N_MUIC);
    NvOdmGpioReleasePinHandle(s_hMuicHandle.hGpio, s_hMuicHandle.h_AP20_UART_SW);
    NvOdmGpioReleasePinHandle(s_hMuicHandle.hGpio, s_hMuicHandle.h_IFX_UART_SW);
    NvOdmGpioReleasePinHandle(s_hMuicHandle.hGpio, s_hMuicHandle.h_USIF1_SW);
#if defined(CONFIG_MACH_STAR_REV_D) || defined(CONFIG_MACH_STAR_REV_E) || defined(CONFIG_MACH_STAR_REV_F)
    NvOdmGpioReleasePinHandle(s_hMuicHandle.hGpio, s_hMuicHandle.h_USB_VBUS_EN);
#endif

err_open_gpio_pin_acquire_fail:
    NvOdmGpioClose(s_hMuicHandle.hGpio);
err_open_gpio_fail:

    return -ENOSYS;
}
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;
}
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;
    
    
}
Esempio n. 29
0
static int __init powerkey_probe(struct platform_device *pdev)
{
    int ret;
    NvU32 pin, port;
    const NvOdmPeripheralConnectivity *con = NULL;

//20101129, [email protected], idle current issue [START]
    //GPIO configuration
    s_touchMaker.gpioHandle = NvOdmGpioOpen();
    port = 'x'-'a';
    pin = 5;
    s_touchMaker.pinHandle = NvOdmGpioAcquirePinHandle(s_touchMaker.gpioHandle, 
                                                    port, pin);
    NvOdmGpioConfig(s_touchMaker.gpioHandle, s_touchMaker.pinHandle, 
                    NvOdmGpioPinMode_InputData);
//20101129, [email protected], idle current issue [END]


//20100610, [email protected], sleep status gpio for modem [START]
#ifdef AP_SUSPEND_STATUS
    //GPIO configuration
    s_modemCheck.gpioHandle = NvOdmGpioOpen();
    if (!s_modemCheck.gpioHandle)
    {
        printk(KERN_ERR "[star modem_chk] NvOdmGpioOpen Error \n");
        goto err_open_modem_chk_gpio_fail;
    }
    port = 'r'-'a';
    pin = 0;
    s_modemCheck.pinHandle = NvOdmGpioAcquirePinHandle(s_modemCheck.gpioHandle, 
                                                    port, pin);
    if (!s_modemCheck.pinHandle)
    {
        printk(KERN_ERR "[star modem_chk] NvOdmGpioAcquirePinHandle Error\n");
        goto err_modem_chk_gpio_pin_acquire_fail;
    }
    NvOdmGpioSetState(s_modemCheck.gpioHandle, s_modemCheck.pinHandle, 1);
    NvOdmGpioConfig(s_modemCheck.gpioHandle, s_modemCheck.pinHandle, 
                    NvOdmGpioPinMode_Output);
#endif
//20100610, [email protected], sleep status gpio for modem [END]

    memset(&s_powerkey, 0x00, sizeof(s_powerkey));

    //get query
    con = NvOdmPeripheralGetGuid(NV_ODM_GUID('p','o','w','e','r','k','e','y'));
    if(!con){
        printk(KERN_ERR "[star powerkey] ODM GUID Error \n");
        goto err_probe_fail;
    }

    if ( con->AddressList[0].Interface == NvOdmIoModule_Gpio){
        port = con->AddressList[0].Instance;
        pin = con->AddressList[0].Address;
    }else{
        printk(KERN_ERR "[star powerkey] cannot find ODM GUID \n");
        goto err_probe_fail;
    }
    
#ifdef POWERKEY_DELAYED_WORKQUEUE
    INIT_DELAYED_WORK(&s_powerkey.work, powerkey_handle);
    wake_lock_init(&s_powerkey.wlock, WAKE_LOCK_SUSPEND, "powerkey_delay");
#else
    INIT_WORK(&s_powerkey.work, powerkey_handle);
#endif

    //GPIO configuration
    s_powerkey.gpioHandle = NvOdmGpioOpen();
    if (!s_powerkey.gpioHandle)
    {
        printk(KERN_ERR "[star powerkey] NvOdmGpioOpen Error \n");
        goto err_open_gpio_fail;
    }
    s_powerkey.pinHandle = NvOdmGpioAcquirePinHandle(s_powerkey.gpioHandle, 
                                                    port, pin);
    if (!s_powerkey.pinHandle)
    {
        printk(KERN_ERR "[star powerkey] NvOdmGpioAcquirePinHandle Error\n");
        goto err_gpio_pin_acquire_fail;
    }
    //NvOdmGpioSetState(s_powerkey.gpioHandle, s_powerkey.pinHandle, 0);
    NvOdmGpioConfig(s_powerkey.gpioHandle, s_powerkey.pinHandle, 
                    NvOdmGpioPinMode_InputData);

    //GPIO interrupt registration
    if (NvOdmGpioInterruptRegister(s_powerkey.gpioHandle, &s_powerkey.intHandle,
            s_powerkey.pinHandle, NvOdmGpioPinMode_InputInterruptAny, 
            powerkey_interrupt_handler, (void*)&s_powerkey, 0) == NV_FALSE)
    {
        printk(KERN_ERR "[star Powerkey] interrupt registeration fail!\n");
        goto err_interrupt_register_fail;
    }

    // input device
    s_powerkey.inputDev = input_allocate_device();
    if (!s_powerkey.inputDev) {
        printk(KERN_ERR "[star Powerkey] input_allocate_device Error!\n");
        goto err_input_device_allocation_fail;
    }
    s_powerkey.inputDev->name = "powerkey";
    //s_powerkey.inputDev->id.bustype = BUS_HOST;
    s_powerkey.inputDev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR);
    set_bit(KEY_POWER, s_powerkey.inputDev->keybit);

    ret = input_register_device(s_powerkey.inputDev);
    if (ret) {
        printk(KERN_ERR "[star powerkey] input_register_device Error\n");
        goto err_input_device_register_fail;
    }

//20100703, [email protected], PMIC reset [START]
    ret = sysfs_create_group(&pdev->dev.kobj, &star_pmic_group);
    if (ret) {
        printk(KERN_ERR "[star powerkey] sysfs_create_group ERROR\n");
        goto err_pmic_sysfs_fail;
    }
//20100703, [email protected], PMIC reset [END]
    
    ret = sysfs_create_group(&pdev->dev.kobj, &star_hwsku_group);
    if (ret) {
        printk(KERN_ERR "[star powerkey] sysfs_create_group ERROR\n");
        goto err_hwsku_sysfs_fail;
    }

//20101110, [email protected], Function for Warm-boot [START]
    ret = sysfs_create_group(&pdev->dev.kobj, &star_reset_group);
    if (ret) {
        printk(KERN_ERR "[star powerkey] sysfs_create_group ERROR\n");
        goto err_reset_sysfs_fail;
    }
//20101110, [email protected], Function for Warm-boot [END]

// 20110209 [email protected] disable gpio interrupt during power-off  [START] 
    ret = sysfs_create_group(&pdev->dev.kobj, &star_poweroff_group);
    if (ret) {
        printk(KERN_ERR "[star powerkey] sysfs_create_group <star_poweroff_group> ERROR\n");
        goto err_input_device_register_fail;
    }
// 20110209 [email protected] disable gpio interrupt during power-off  [END] 

    return 0;
err_reset_sysfs_fail:    
    sysfs_remove_group(&pdev->dev.kobj, &star_hwsku_group);
err_hwsku_sysfs_fail:
    sysfs_remove_group(&pdev->dev.kobj, &star_pmic_group);
err_pmic_sysfs_fail:
    input_unregister_device(s_powerkey.inputDev);

err_input_device_register_fail: 
    input_free_device(s_powerkey.inputDev);    
err_input_device_allocation_fail: 
    NvOdmGpioInterruptUnregister(s_powerkey.gpioHandle, s_powerkey.pinHandle,
        s_powerkey.intHandle);    
err_interrupt_register_fail:  
    NvOdmGpioReleasePinHandle(s_powerkey.gpioHandle, s_powerkey.pinHandle);
err_gpio_pin_acquire_fail:
    NvOdmGpioClose(s_powerkey.gpioHandle);  

err_open_gpio_fail:
#ifdef POWERKEY_DELAYED_WORKQUEUE
    wake_lock_destroy(&s_powerkey.wlock);
#endif

err_probe_fail:

//20100610, [email protected], sleep status gpio for modem [START]
#ifdef AP_SUSPEND_STATUS
    NvOdmGpioReleasePinHandle(s_modemCheck.gpioHandle, s_modemCheck.pinHandle);
err_modem_chk_gpio_pin_acquire_fail:
    NvOdmGpioClose(s_modemCheck.gpioHandle); 
err_open_modem_chk_gpio_fail:
#endif
//20100610, [email protected], sleep status gpio for modem [END]
    return -ENOSYS;
}
Esempio n. 30
0
static int pmic_set(void *data, u64 val)
{
    u32 settling_time;
    const NvOdmPeripheralConnectivity *con = NULL;
    int ldo_number;
    int j;
    NvU32 millivolts;
    NvU32 loop_count = MAX_REFCOUNT_LOOP;
    NvRmPmuVddRailCapabilities rail;
    
    struct pmic_struct *pmic_info  = data;

    ldo_number = pmic_info->ldo_number;

    printk("PMIC(debugfs) : WARNING!! reference counter will be broken\n");

    con = NvOdmPeripheralGetGuid(NV_ODM_GUID('a','l','l','p','o','w','e','r'));
    if (con == NULL){
        printk("PMIC(debugfs) : query ERROR\n");
        return 0;
    }

    if(ldo_number == 2){
        printk("PMIC(debugfs) : skip LDO2 test, always on!!!\n");
        return 0;
    }


    NvRmPmuGetVoltage(s_hRmGlobal, 
                con->AddressList[ldo_number].Address, &millivolts);
    if(val){
        if(millivolts){
            printk("PMIC(debugfs) : LDO%d already turned on\n"
                    , ldo_number+1);
            return 0;
        }
        NvRmPmuGetCapabilities(s_hRmGlobal,
                con->AddressList[ldo_number].Address, &rail);
        for(j=MAX_REFCOUNT_LOOP;j>powerRefCount[ldo_number];j--){
            NvRmPmuSetVoltage(s_hRmGlobal,
                    con->AddressList[ldo_number].Address,
                    rail.requestMilliVolts, &settling_time);
        }
        printk("PMIC(debugfs) : LDO%d turn on\n", 
                ldo_number+1);
        //udelay(settling_time);
    }else{
        if(!millivolts){
            printk("PMIC(debugfs) : LDO%d already turned off\n", 
                    ldo_number+1);
            return 0;
        }
        
        while(millivolts && loop_count--){
            NvRmPmuSetVoltage(s_hRmGlobal,
                    con->AddressList[ldo_number].Address, NVODM_VOLTAGE_OFF,
                    &settling_time);
            NvRmPmuGetVoltage(s_hRmGlobal,
                con->AddressList[ldo_number].Address, &millivolts);
            if(!millivolts){
                powerRefCount[ldo_number]=loop_count;
                printk("PMIC(debugfs) : LDO%d turn off\n", 
                        ldo_number+1);
            }
        }
        //udelay(settling_time);
    }
    return 0;
}