NvBool Synaptics_OneTouch_EnableInterrupt (NvOdmOneTouchDeviceHandle hDevice, NvOdmOsSemaphoreHandle hIntSema)
{
	Synaptics_OneTouch_Device* hTouch = (Synaptics_OneTouch_Device*)hDevice;

	NV_ASSERT(hIntSema);

	NVODMTOUCH_PRINTF(("[ONETOUCH] Synaptics_OneTouch_EnableInterrupt\n"));

	/* can only be initialized once */
	if (hTouch->hGpioIntr || hTouch->hIntSema)
		return NV_FALSE;

	hTouch->hIntSema = hIntSema;    

	if (NvOdmGpioInterruptRegister(hTouch->hGpio, &hTouch->hGpioIntr,
		hTouch->hPin, NvOdmGpioPinMode_InputInterruptLow, Synaptics_OneTouch_GpioIsr,
		(void*)hTouch, SYNAPTICS_DEBOUNCE_TIME_MS) == NV_FALSE)
	{
		NVODMTOUCH_PRINTF(("[ONETOUCH] cannot register interrupt.\n"));
		return NV_FALSE;
	}

	if (!hTouch->hGpioIntr)
		return NV_FALSE;    

	return NV_TRUE;
}
static NvBool EETI_Resume(NvOdmTouchDeviceHandle hDevice) {
    EETI_TouchDevice* hTouch = (EETI_TouchDevice*)hDevice;

    if (hDevice == NULL) {
        return NV_FALSE;
    }
#if 0
    NvOdmGpioInterruptMask(hTouch->hGpioIntr, NV_TRUE);
    NvOdmGpioInterruptUnregister(hTouch->hGpio, hTouch->hPin, hTouch->hGpioIntr);
#endif
    NvOdmGpioConfig(hTouch->hGpio, hTouch->hPin, NvOdmGpioPinMode_Output);
    /* Send reset pulse to touch HW */
    NvOdmGpioSetState(hTouch->hGpio, hTouch->hPin, 1);
    NvOsWaitUS(50);
    NvOdmGpioSetState(hTouch->hGpio, hTouch->hPin, 0);
    NvOsSleepMS(50);       
    NvOdmGpioSetState(hTouch->hGpio, hTouch->hPin, 1);

    NvOdmGpioConfig(hTouch->hGpio, hTouch->hPin, NvOdmGpioPinMode_InputInterruptLow);
#if 0
    if (NvOdmGpioInterruptRegister(hTouch->hGpio, &hTouch->hGpioIntr,
                                   hTouch->hPin, NvOdmGpioPinMode_InputInterruptLow, EETI_GpioIsr,
                                   (void*)hTouch, EETI_DEBOUNCE_TIME_MS) == NV_FALSE) {
        return NV_FALSE;
    }
#endif
    return NV_TRUE;
}
NvOdmTmonIntrHandle
Adt7461IntrRegister(
    NvOdmTmonDeviceHandle hTmon,
    NvOdmTmonZoneID ZoneId,
    NvOdmInterruptHandler Callback,
    void* CallbackArg)
{
    NvU8 Data;
    ADT7461PrivData* pPrivData;
    const ADT7461ChannelInfo* pChannel;
    NvOdmServicesGpioIntrHandle hGpioIntr = NULL;

    NV_ASSERT(hTmon && hTmon->pPrivate && Callback && CallbackArg);
    pPrivData = hTmon->pPrivate;

    // No registration, if no GPIO pin available or interrupt already registred
    if (!pPrivData->hGpioPin || pPrivData->hGpioIntr)
        return NULL;

    // No registration for other than remote channel
    pChannel = &pPrivData->pDeviceInfo->Channels[(
        pPrivData->ConnectivityMap[ZoneId])];
    if (pChannel->ChannelId != ADT7461ChannelID_Remote)
        return NULL;

    // Register GPIO interrupt (will be enabled at SoC IC, but still disabled
    // at ADT7461 device)
    pPrivData->Callback = Callback;
    pPrivData->CallbackArg = CallbackArg;
    if (!NvOdmGpioInterruptRegister(
        pPrivData->hGpio, &hGpioIntr, pPrivData->hGpioPin,
        ADT7461_ODM_INTR_POLARITY, Adt7461Isr, (void *)pPrivData, 0))
    {
        pPrivData->Callback = NULL;
        pPrivData->CallbackArg = NULL;
        return NULL;
    }
    NV_ASSERT(hGpioIntr);
    pPrivData->hGpioIntr = hGpioIntr;
    
    // Finally enable ADT7461 device interrupt output (interrupt may or may
    // not be generated depending on temperature and limt settings).
#if PRE_ER_WORKAROUND
    Data = pPrivData->ShadowConfig | (ADT7461ConfigBits_IntrDisabled);
#else
    Data = pPrivData->ShadowConfig & (~ADT7461ConfigBits_IntrDisabled);
#endif
    if(!Adt7461WriteReg(pPrivData, &pPrivData->pDeviceInfo->Config, Data))
    {
        NvOdmGpioInterruptUnregister(
            pPrivData->hGpio, pPrivData->hGpioPin, hGpioIntr);
        pPrivData->Callback = NULL;
        pPrivData->CallbackArg = NULL;
        pPrivData->hGpioIntr = NULL;
        return NULL;
    }
    pPrivData->ShadowConfig = Data;

    return (NvOdmTmonIntrHandle)hGpioIntr;
}
NvBool EETI_EnableInterrupt (NvOdmTouchDeviceHandle hDevice, NvOdmOsSemaphoreHandle hIntSema) {
    EETI_TouchDevice* hTouch = (EETI_TouchDevice*)hDevice;
    NvOdmTouchCoordinateInfo coord;

    NV_ASSERT(hIntSema);

    /* can only be initialized once */
    if (hTouch->hGpioIntr || hTouch->hIntSema)
        return NV_FALSE;

    NvOdmOsMemset(&coord, 0, sizeof(NvOdmTouchCoordinateInfo));

    /* zero intr status */
    EETI_GetSample(hTouch, &coord);        

    hTouch->hIntSema = hIntSema;    

    if (NvOdmGpioInterruptRegister(hTouch->hGpio, &hTouch->hGpioIntr,
                                   hTouch->hPin, NvOdmGpioPinMode_InputInterruptLow, EETI_GpioIsr,
                                   (void*)hTouch, EETI_DEBOUNCE_TIME_MS) == NV_FALSE) {
        return NV_FALSE;
    }

    if (!hTouch->hGpioIntr)
        return NV_FALSE;

    return NV_TRUE;
}
Beispiel #5
0
/*
 * Connect semaphore with interrupt pins according to your configuration.
 */
NvBool NvAccelerometerConnectSemaphore(NvOdmAccelHandle hDevice)
{
    NvOdmGpioPinMode mode; 
    NvOdmInterruptHandler callback = (NvOdmInterruptHandler)GpioInterruptHandler;
         
    hDevice->hGpioINT = (NvOdmServicesGpioHandle)NvOdmGpioOpen();
    if(!(hDevice->hGpioINT))
    {
        //NVODMACCELEROMETER_PRINTF("NvOdm Accelerometer : NvOdmGpioOpen Error \n");
        return NV_FALSE;
    }

    hDevice->hPinINT = NvOdmGpioAcquirePinHandle(hDevice->hGpioINT, 
                                                 hDevice->GPIOPortINT, 
                                                 hDevice->GPIOPinINT);

    hDevice->SemaphoreForINT = NvOdmOsSemaphoreCreate(0);

    if(!(hDevice->SemaphoreForINT))
    {
        //NVODMACCELEROMETER_PRINTF("NvOdm Accelerometer : NvOdmOsSemaphoreCreate Error \n");
        NvOdmGpioClose(hDevice->hGpioINT);
        return NV_FALSE;
    }
          
    mode = NvOdmGpioPinMode_InputInterruptHigh;
    
    if (NvOdmGpioInterruptRegister(hDevice->hGpioINT, &hDevice->hGpioInterrupt,
        hDevice->hPinINT, mode, callback, hDevice, NV_DEBOUNCE_TIME_MS) == NV_FALSE)
    {
        return NV_FALSE;
    }

    if(!(hDevice->hGpioInterrupt))
    {
        //NVODMACCELEROMETER_PRINTF("NvOdm Accelerometer : NvOdmGpioInterruptRegister Error \n");
        NvOdmGpioClose(hDevice->hGpioINT);
        NvOdmOsSemaphoreDestroy(hDevice->SemaphoreForINT);
        return NV_FALSE;
    }
    
    return NV_TRUE;
}
static NvBool ConnectSemaphore(NvOdmEcompassHandle hDevice)
{
    NvOdmGpioPinMode mode;
    NvOdmInterruptHandler callback =
        (NvOdmInterruptHandler)GpioInterruptHandler;

    hDevice->hGpioINT = (NvOdmServicesGpioHandle)NvOdmGpioOpen();
    if (!(hDevice->hGpioINT))
    {
        NVODMECOMPASS_PRINTF(("AKM8975 compass driver: NvOdmGpioOpenError \n"));
        return NV_FALSE;
    }

    hDevice->hPinINT = NvOdmGpioAcquirePinHandle(hDevice->hGpioINT,
                           hDevice->GPIOPortINT,
                           hDevice->GPIOPinINT);
    hDevice->SemaphoreForINT = NvOdmOsSemaphoreCreate(0);

    if (!(hDevice->SemaphoreForINT))
    {
        NVODMECOMPASS_PRINTF(( "AKM8975 compass driver: NvOdmOsSemaphoreCreate Error \n"));
        NvOdmGpioClose(hDevice->hGpioINT);
        return NV_FALSE;
    }

    mode = NvOdmGpioPinMode_InputInterruptHigh;
    if (NvOdmGpioInterruptRegister(hDevice->hGpioINT,
        &hDevice->hGpioInterrupt, hDevice->hPinINT, mode, callback,
        hDevice, NV_DEBOUNCE_TIME_MS) == NV_FALSE)
    {
        return NV_FALSE;
    }
	
    if (!(hDevice->hGpioInterrupt))
    {
        NVODMECOMPASS_PRINTF(("AKM8975 compass driver: NvOdm Ecompass NvOdmGpioInterruptRegister Error \n"));
        NvOdmGpioClose(hDevice->hGpioINT);
        NvOdmOsSemaphoreDestroy(hDevice->SemaphoreForINT);
        return NV_FALSE;
    }
    return NV_TRUE;
}
Beispiel #7
0
NvBool NvGyroAccelConnectSemaphore(NvOdmGyroAccelHandle hDevice)
{
	NvOdmGpioPinMode mode;
	NvOdmInterruptHandler callback = (NvOdmInterruptHandler)GpioInterruptHandler;
	printk(" ## MPU3050 : NvGyroAccelConnectSemaphore \n") ;
	hDevice->hGpioINT = (NvOdmServicesGpioHandle)NvOdmGpioOpen();

	if (!(hDevice->hGpioINT)) {
		printk("## NvOdm GyroAccel : NvOdmGpioOpen Error ##  \n");
		return NV_FALSE;
	}

	hDevice->hPinINT = NvOdmGpioAcquirePinHandle(hDevice->hGpioINT,
			hDevice->GPIOPortINT,
			hDevice->GPIOPinINT);

	hDevice->SemaphoreForINT = NvOdmOsSemaphoreCreate(0);

	if (!(hDevice->SemaphoreForINT)) {
		printk("## NvOdm GyroAccel : NvOdmOsSemaphoreCreate Error ## \n");
		NvOdmGpioClose(hDevice->hGpioINT);
		return NV_FALSE;
	}

	mode = NvOdmGpioPinMode_InputInterruptHigh;

	if (NvOdmGpioInterruptRegister(hDevice->hGpioINT, &hDevice->hGpioInterrupt,
				hDevice->hPinINT, mode, callback, hDevice, NV_DEBOUNCE_TIME_MS) == NV_FALSE)
	{
		printk("NvOdm GyroAccel : cannot register interrupt.\n") ;
		return NV_FALSE;
	}

	if (!(hDevice->hGpioInterrupt)) {
		NvOdmGpioClose(hDevice->hGpioINT);
		NvOdmOsSemaphoreDestroy(hDevice->SemaphoreForINT);
		return NV_FALSE;
	}

	return NV_TRUE;
}
Beispiel #8
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;
}
Beispiel #9
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;
}
Beispiel #10
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
}
Beispiel #11
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;
}
Beispiel #12
0
static int headset_switch_probe(struct platform_device *pdev)
{
	struct gpio_switch_platform_data *pdata = pdev->dev.platform_data;
	struct gpio_switch_data *switch_data;
	int ret = 0;
    NvU32 states;


	if (!pdata)
		return -EBUSY;

	switch_data = kzalloc(sizeof(struct gpio_switch_data), GFP_KERNEL);
	if (!switch_data)
		return -ENOMEM;

	switch_data->sdev.name = pdata->name;
	switch_data->gpio = pdata->gpio;
    //switch_data->pin = pdata->pin;
	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_headset_print_state;


    ret = switch_dev_register(&switch_data->sdev);
	if (ret < 0)
		goto err_switch_dev_register;


    if( !s_hGpio )
    {
        s_hGpio = NvOdmGpioOpen();
        if( !s_hGpio )
        {
            goto err_request_gpio;
        }
    }    

    s_hHeadphoneGpioPin = NvOdmGpioAcquirePinHandle(s_hGpio, 'w'-'a', 2);
            //switch_data->gpio, switch_data->pin);

    NvOdmGpioConfig( s_hGpio, s_hHeadphoneGpioPin, NvOdmGpioPinMode_InputData);


	INIT_WORK(&switch_data->work, headset_switch_work);

    //create thread
    if( !g_hDetectEventSema )
        g_hDetectEventSema  = NvOdmOsSemaphoreCreate(0);
    g_DetectThread_exit = 0;
    if( !g_hDetectThread )
        g_hDetectThread = NvOdmOsThreadCreate( (NvOdmOsThreadFunction)DetectThreadFun,
                            (void*)switch_data);

    // headphone ISR      
    if (!NvOdmGpioInterruptRegister(
        s_hGpio, &s_hGpioIntr_Headphone, s_hHeadphoneGpioPin,
        NvOdmGpioPinMode_InputInterruptLow, headset_irq_handler, (void*)switch_data, 0))
    {
        return NV_FALSE;
    }
  

    //detect headphone right now
    NvOdmGpioGetState(s_hGpio,s_hHeadphoneGpioPin,&states);
    if( !states )
    {
            gHeadsetInsertStatus = HEADSET_STATUS_REMOVE;
            NvOdmGpioConfig(s_hGpio,s_hHeadphoneGpioPin,NvOdmGpioPinMode_InputInterruptHigh );
    }
    else
    {
            gHeadsetInsertStatus = HEADSET_STATUS_INSERT;
            NvOdmGpioConfig(s_hGpio,s_hHeadphoneGpioPin,NvOdmGpioPinMode_InputInterruptLow );               
    } 

	/* Perform initial detection */
	//headset_switch_work(&switch_data->work);


	return 0;


err_request_gpio:
    switch_dev_unregister(&switch_data->sdev);
err_switch_dev_register:
	kfree(switch_data);

	return ret;
}
static int h2w_switch_probe(struct platform_device *pdev)
{
	struct h2w_switch_dev *hsdev;

	logd("h2w_switch_probe() IN\r\n");

	hsdev = kzalloc(sizeof(struct h2w_switch_dev), GFP_KERNEL);
	if (!hsdev) {
		loge("err_alloc_hsdev\r\n");
		goto err_alloc_hsdev;
	}
	
	hsdev->gpio = NvOdmGpioOpen();
	if (!hsdev->gpio) {
		loge("err open gpio\r\n");
		goto err_open_gpio;
	}
	hsdev->hp_det_pin = NvOdmGpioAcquirePinHandle(hsdev->gpio, HP_DET_GPIO_PORT, HP_DET_GPIO_PIN);
	if (!hsdev->hp_det_pin) {
		loge("err acquire detect pin handle\r\n");
		goto err_acquire_det_pin;
	}
	NvOdmGpioConfig(hsdev->gpio, hsdev->hp_det_pin, NvOdmGpioPinMode_InputData);

#ifdef CONFIG_SWITCH_DOCK_H2W
	hsdev->dock_hp_det_pin = NvOdmGpioAcquirePinHandle(hsdev->gpio, DOCK_HP_DET_GPIO_PORT, DOCK_HP_DET_GPIO_PIN);
	if (!hsdev->dock_hp_det_pin) {
		loge("err acquire dock headphone detect pin handle");
		goto err_acquire_dock_det_pin;
	}
	NvOdmGpioConfig(hsdev->gpio, hsdev->dock_hp_det_pin, NvOdmGpioPinMode_InputData);
#endif

	hsdev->sdev.name = "h2w";
	hsdev->sdev.print_name = h2w_switch_print_name;
	hsdev->sdev.print_state = h2w_switch_print_state;
	if (switch_dev_register(&hsdev->sdev)) {
		loge("err register switch device\r\n");
		goto err_register_sdev;
	}
	
	hsdev->workqueue = create_singlethread_workqueue("h2w_switch");
	if (!hsdev->workqueue) {
		goto err_create_workqueue;
	}
	
	INIT_WORK(&hsdev->work, h2w_switch_work);
	
	

	#if !TIMER_DEALER
	/* Enable the interrupt at last */
	if ((NvOdmGpioInterruptRegister(hsdev->gpio, &hsdev->hp_det_irq, hsdev->hp_det_pin,
			NvOdmGpioPinMode_InputInterruptAny, h2w_switch_irq_isr, hsdev, IRQ_DEBOUNCE) 
			== NV_FALSE) || (hsdev->hp_det_irq == NULL)) {
		logd("err register irq\r\n");
		goto err_register_irq;
	}
	#endif

#ifdef CONFIG_SWITCH_DOCK_H2W
	#if !TIMER_DEALER
	/* Enable the dock hp detect interrupt */
	if ((NvOdmGpioInterruptRegister(hsdev->gpio, &hsdev->dock_hp_det_irq, hsdev->dock_hp_det_pin,
			NvOdmGpioPinMode_InputInterruptAny, dock_h2w_switch_irq_isr, hsdev, IRQ_DEBOUNCE)
			== NV_FALSE) || (hsdev->dock_hp_det_irq == NULL)) {
		loge("err register dock hp irq\r\n");
		goto err_register_dock_hp_irq;
	}
	#endif
#endif

	platform_set_drvdata(pdev, hsdev);
	p_switch_dev=hsdev;
	#if !TIMER_DEALER
	/* After all we simulate a isr */
	queue_work(hsdev->workqueue, &hsdev->work);
	#endif
	
	#if TIMER_DEALER
	init_timer(&hsdev->timer);
	hsdev->timer.function = h2w_switch_timer_func;
	hsdev->timer.data = hsdev;
	mod_timer(&hsdev->timer, jiffies + msecs_to_jiffies(2000));
	
	{
	hsdev->hp_det_ups=0;
	hsdev->hp_det_downs=0;
	hsdev->hp_det_pinstate=0;
	int state;
	int counts=80;
	while(counts)
	{
		NvOdmGpioGetState(hsdev->gpio, hsdev->hp_det_pin, &state);
		if(state){hsdev->hp_det_ups++;hsdev->hp_det_downs=0;}
		else {hsdev->hp_det_downs++;hsdev->hp_det_ups=0;}
		msleep(10);
		
		if(hsdev->hp_det_downs>=5)
		{
			hsdev->hp_det_pinstate=0;
			switch_set_state(&hsdev->sdev, !hsdev->hp_det_pinstate);
			logd("h2w_switch_timer_func headphone detect low~ \n");
			break;
		}
		else if(hsdev->hp_det_ups>=5)
		{
			hsdev->hp_det_pinstate=1;
			switch_set_state(&hsdev->sdev, !hsdev->hp_det_pinstate);
			logd("h2w_switch_timer_func headphone detect high~ \n");
			break;
		}
		counts--;
	}
	if(counts==0){logd("h2w_switch_timer_func headphone detect failed \n");};
	hsdev->hp_det_ups=0;
	hsdev->hp_det_downs=0;
	
	#ifdef CONFIG_SWITCH_DOCK_H2W
	hsdev->dock_hp_det_ups=0;
	hsdev->dock_hp_det_downs=0;
	hsdev->dock_hp_det_pinstate=0;
	counts=80;
	while(counts)
	{
		NvOdmGpioGetState(hsdev->gpio, hsdev->dock_hp_det_pin, &state);
		if(state){hsdev->dock_hp_det_ups++;hsdev->dock_hp_det_downs=0;}
		else {hsdev->dock_hp_det_downs++;hsdev->dock_hp_det_ups=0;}
		msleep(10);
		
		if(hsdev->dock_hp_det_downs>=5)
		{
			hsdev->dock_hp_det_pinstate=0;
			switch_set_state(&hsdev->sdev, hsdev->dock_hp_det_pinstate);
			logd("h2w_switch_timer_func dock headphone detect low~ \n");
			break;
		}
		else if(hsdev->dock_hp_det_ups>=5)
		{
			hsdev->dock_hp_det_pinstate=1;
			switch_set_state(&hsdev->sdev, hsdev->dock_hp_det_pinstate);
			logd("h2w_switch_timer_func dock headphone detect high~ \n");
			break;
		}
		counts--;
	}
	if(counts==0){logd("h2w_switch_timer_func dock headphone detect failed \n");};
	hsdev->dock_hp_det_ups=0;
	hsdev->dock_hp_det_downs=0;
	#endif
	}
	#endif
	
	logd("h2w_switch_probe() OUT\r\n");
	return 0;

#ifdef CONFIG_SWITCH_DOCK_H2W
err_register_dock_hp_irq:
	NvOdmGpioInterruptUnregister(hsdev->gpio, hsdev->hp_det_pin, hsdev->hp_det_irq);
#endif
err_register_irq:
	destroy_workqueue(hsdev->workqueue);
err_create_workqueue:
	switch_dev_unregister(&hsdev->sdev);
err_register_sdev:
#ifdef CONFIG_SWITCH_DOCK_H2W
	NvOdmGpioReleasePinHandle(hsdev->gpio, hsdev->dock_hp_det_pin);
err_acquire_dock_det_pin:
#endif
	NvOdmGpioReleasePinHandle(hsdev->gpio, hsdev->hp_det_pin);
err_acquire_det_pin:
	NvOdmGpioClose(hsdev->gpio);
err_open_gpio:
	kfree(hsdev);
err_alloc_hsdev:
	
	logd("h2w_switch_probe failed\r\n");
	return -1;
}
Beispiel #14
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;
}
Beispiel #15
0
static int __init star_hall_probe( struct platform_device *pdev )
{
	int err = 0;
	struct device *dev = &pdev->dev;
	struct star_hall_platform_data *pdata;
	atomic_set( &sensing_hall, 1 );
	printk("[HALLIC] probing hall ic driver\n");

	g_hall = kzalloc( sizeof(*g_hall), GFP_KERNEL );
	if(g_hall == NULL)
	{
		err = -1;
		printk("[HALLIC] Fail to alloc the memory for HALL IC\n");
		goto error;
	}

	/*g_hall->h_hall_pmu = NvOdmServicesPmuOpen();
	if(!g_hall->h_hall_pmu)
	{
		err = -1;
		printk("[HALL:%s] Fail to Open the pmu!\n", __func__);
		goto error;
	}*/

/*
	if (star_hall_set_power_rail(12, NV_TRUE) != 0)
	{
		err = -1;
		goto error;
	}
*/
	pdata	=	pdev->dev.platform_data;
	if(pdata){
		g_hall->gpio = pdata->gpio;
		g_hall->irqflags = pdata->irqflags;
		g_hall->power = pdata->power;
	}

	if(g_hall->power)
	{
		if(g_hall->power("vddio_sys", 1) != 0)
		{
			err = -1;
			printk(KERN_ERR"Error to power control vddio_sys of HALL IC\n");
			goto error;
		}
	}
	power_enabled = true;
/*
	g_hall->h_hall_gpio = NvOdmGpioOpen();
	if(!g_hall->h_hall_gpio)
	{
		printk("[HALL:%s] Fail to open gpio\n", __func__);
		err = -1;
		goto error;
	}

	g_hall->hall_intr_port = 'u' - 'a';
	g_hall->hall_intr_pin  = 5;

	g_hall->h_hall_gpio_pin = NvOdmGpioAcquirePinHandle(g_hall->h_hall_gpio, g_hall->hall_intr_port, g_hall->hall_intr_pin );
	if( !g_hall->h_hall_gpio_pin )
	{
		printk("[HALL:%s] Fail to acquire pin handle!\n", __func__);
		err = -1;
		goto error;
	}

	NvOdmGpioConfig(g_hall->h_hall_gpio, g_hall->h_hall_gpio_pin, NvOdmGpioPinMode_InputData);
*/
	g_hall->is_int_mode = true;

	tegra_gpio_enable(g_hall->gpio);
	gpio_request(g_hall->gpio, "star_hall");
	gpio_direction_input(g_hall->gpio); 

	if( !g_hall->is_int_mode ){	
	//for polling mode
		INIT_DELAYED_WORK(&g_hall->delayed_work_hall, star_hall_work_func);
		schedule_delayed_work(&g_hall->delayed_work_hall, 100 );
	} else{
	//int mode
#if 0
        if (NvOdmGpioInterruptRegister(g_hall->h_hall_gpio, &(g_hall->h_hall_intr),
            g_hall->h_hall_gpio_pin, NvOdmGpioPinMode_InputInterruptAny, /*NvOdmGpioPinMode_InputInterruptFallingEdge,*/ star_hall_intr_handler, (void*)&g_hall, 0) == NV_FALSE){
			printk("[HALL:%s] Fail to register hall's interrupt\n", __func__ );	
			goto err_irq_request;
		} 
#endif
		err = request_irq(gpio_to_irq(g_hall->gpio), star_hall_intr_handler, g_hall->irqflags, pdev->name, dev);
		if(err)
		{
			printk(KERN_ERR"Error to request_irq failed of HALL IC\n");
			goto err_irq_request;
		}
	}

	g_hall->input_device = input_allocate_device();
	if(!g_hall->input_device){
		printk(KERN_ERR"Error to allocate the input device of HALL IC\n");
		err = -ENOMEM;
		goto err_irq_request;
	}

	set_bit(EV_KEY, g_hall->input_device->evbit);
	set_bit(KEY_POWER, g_hall->input_device->keybit);
	set_bit(EV_ABS, g_hall->input_device->evbit);
	input_set_abs_params(g_hall->input_device, ABS_HAT2X, 0, 1, 0, 0);
	g_hall->input_device->name = "hall_ic";
	err = input_register_device(g_hall->input_device);
	
	if(err){
		printk(KERN_ERR"error to register the input device of hall\n");
		err = -ENOMEM;
		goto err_irq_request;
	}
		
	err = sysfs_create_group(&dev->kobj, &star_hall_group );
	if(err){
		printk(KERN_ERR"error to create sys file system of HALL IC\n");
		err = -ENOMEM;
		goto err_irq_request;
	}
	DBGHALL("probe: ok\n");		

	return 0;

error:
	return err;
err_irq_request:
	gpio_free(gpio_to_irq(g_hall->gpio));
	return err;
}
Beispiel #16
0
static int __init star_hall_probe( struct platform_device *pdev )
{
	int err = 0;
	struct device *dev = &pdev->dev;
	atomic_set( &sensing_hall, 1 );
	printk("\n================================================================\n");
	printk("[HALL:%s] probing hall ic driver\n", __func__);
	printk("================================================================\n");

	g_hall = kzalloc( sizeof(*g_hall), GFP_KERNEL );
	if(g_hall == NULL)
	{
		err = -1;
		printk("[HALL:%s] Fail to alloc the memory for HALL IC\n",__func__);
		goto error;
	}

	/*g_hall->h_hall_pmu = NvOdmServicesPmuOpen();
	if(!g_hall->h_hall_pmu)
	{
		err = -1;
		printk("[HALL:%s] Fail to Open the pmu!\n", __func__);
		goto error;
	}*/

	if (star_hall_set_power_rail(12, NV_TRUE) != 0)
    {
		err = -1;
		goto error;
	}

	g_hall->h_hall_gpio = NvOdmGpioOpen();
	if(!g_hall->h_hall_gpio)
	{
		printk("[HALL:%s] Fail to open gpio\n", __func__);
		err = -1;
		goto error;
	}

	g_hall->is_int_mode = true;

	g_hall->hall_intr_port = 'u' - 'a';
	g_hall->hall_intr_pin  = 5;

	g_hall->h_hall_gpio_pin = NvOdmGpioAcquirePinHandle(g_hall->h_hall_gpio, g_hall->hall_intr_port, g_hall->hall_intr_pin );
	if( !g_hall->h_hall_gpio_pin )
	{
		printk("[HALL:%s] Fail to acquire pin handle!\n", __func__);
		err = -1;
		goto error;
	}

	NvOdmGpioConfig(g_hall->h_hall_gpio, g_hall->h_hall_gpio_pin, NvOdmGpioPinMode_InputData);
	
//	NvOdmGpioConfig( g_hall->h_hall_gpio, g_hall->hall_intr_port, NvOdmGpioPinMode_InputData );
	if( !g_hall->is_int_mode ){	
	//for polling mode
		INIT_DELAYED_WORK(&g_hall->delayed_work_hall, star_hall_work_func);
		schedule_delayed_work(&g_hall->delayed_work_hall, 100 );
	} else{
	//int mode
	#if 0
		if(NvOdmGpioInterruptRegister(g_hall->h_hall_gpio, &g_hall->h_hall_intr, g_hall->h_hall_gpio_pin, 
		NvOdmGpioPinMode_InputInterruptFallingEdge, star_hall_intr_handler, (void*)g_hall, 0 ) == NV_FALSE ){
			printk("[HALL:%s] Fail to register hall's interrupt\n", __func__ );	
			goto err_irq_request;
		} 
	#endif
        if (NvOdmGpioInterruptRegister(g_hall->h_hall_gpio, &(g_hall->h_hall_intr),
            g_hall->h_hall_gpio_pin, NvOdmGpioPinMode_InputInterruptAny, /*NvOdmGpioPinMode_InputInterruptFallingEdge,*/ star_hall_intr_handler, (void*)&g_hall, 0) == NV_FALSE){
			printk("[HALL:%s] Fail to register hall's interrupt\n", __func__ );	
			goto err_irq_request;
		} 
	}

	g_hall->input_device = input_allocate_device();
	if(!g_hall->input_device){
		printk("Error to allocate the input device of HALL IC\n");
		err = -ENOMEM;
		goto err_irq_request;
	}
	set_bit(EV_KEY, g_hall->input_device->evbit);
	set_bit(KEY_POWER, g_hall->input_device->keybit);
	set_bit(EV_ABS, g_hall->input_device->evbit);
	input_set_abs_params(g_hall->input_device, ABS_HAT2X, 0, 1, 0, 0);
	g_hall->input_device->name = "hall_ic";
	err = input_register_device(g_hall->input_device);
	if(err){
		printk("error to register the input device of hall\n");
		err = -ENOMEM;
		goto err_irq_request;
	}
	err = sysfs_create_group(&dev->kobj, &star_hall_group );
	if(err){
		printk("error to create sys file system\n");
		err = -ENOMEM;
		goto err_irq_request;
	}

	g_hall->sdev.name = "dock";
	switch_dev_register(&g_hall->sdev);

	return 0;

error:
	return err;
err_irq_request:
	NvOdmGpioClose(g_hall->h_hall_gpio);
	return err;
}
static int h2w_switch_probe(struct platform_device *pdev)
{
	struct h2w_switch_dev *hsdev;
	struct switch_h2w_platform_data *pdata;

	logd("h2w_switch_probe\n");

	pdata = pdev->dev.platform_data;
	if (pdata == NULL) {
		loge("pdata=NULL\n");
		return -EFAULT;
	}

	hsdev = kzalloc(sizeof(struct h2w_switch_dev), GFP_KERNEL);
	if (!hsdev) {
		loge("err_alloc_hsdev\n");
		goto err_alloc_hsdev;
	}
	hsdev->have_dock_hp = pdata->have_dock_hp;
	hsdev->hp_det_active_low = pdata->hp_det_active_low;

	hsdev->gpio = NvOdmGpioOpen();
	if (!hsdev->gpio) {
		loge("err open gpio\n");
		goto err_open_gpio;
	}
	hsdev->hp_det_pin = NvOdmGpioAcquirePinHandle(hsdev->gpio, 
			pdata->hp_det_port, pdata->hp_det_pin);
	if (!hsdev->hp_det_pin) {
		loge("err acquire detect pin handle\n");
		goto err_acquire_det_pin;
	}
	NvOdmGpioConfig(hsdev->gpio, hsdev->hp_det_pin, NvOdmGpioPinMode_InputData);

	if (pdata->have_dock_hp) {
		hsdev->dock_hp_det_active_low = pdata->dock_hp_det_active_low;
		hsdev->dock_hp_det_pin = NvOdmGpioAcquirePinHandle(hsdev->gpio, 
				pdata->dock_hp_det_port, pdata->dock_hp_det_pin);
		if (!hsdev->dock_hp_det_pin) {
			loge("err acquire dock headphone detect pin handle\n");
			goto err_acquire_dock_det_pin;
		}
		NvOdmGpioConfig(hsdev->gpio, hsdev->dock_hp_det_pin, NvOdmGpioPinMode_InputData);
	}

	hsdev->sdev.name = H2W_SWITCH_DEV_NAME;
	hsdev->sdev.print_name = h2w_switch_print_name;
	hsdev->sdev.print_state = h2w_switch_print_state;
	if (switch_dev_register(&hsdev->sdev)) {
		loge("err register switch device\n");
		goto err_register_sdev;
	}
	
	hsdev->workqueue = create_singlethread_workqueue("h2w_switch");
	if (!hsdev->workqueue) {
		loge("create_singlethread_workqueue\n");
		goto err_create_workqueue;
	}
	INIT_WORK(&hsdev->work, h2w_switch_work);

	/* Enable the interrupt at last */
	if ((NvOdmGpioInterruptRegister(hsdev->gpio, &hsdev->hp_det_irq, hsdev->hp_det_pin,
			NvOdmGpioPinMode_InputInterruptAny, h2w_switch_irq_isr, hsdev, IRQ_DEBOUNCE) 
			== NV_FALSE) || (hsdev->hp_det_irq == NULL)) {
		loge("err register irq\n");
		goto err_register_irq;
	}

	/* Enable the dock hp detect interrupt */
	if (hsdev->have_dock_hp) {
		if ((NvOdmGpioInterruptRegister(hsdev->gpio, &hsdev->dock_hp_det_irq, hsdev->dock_hp_det_pin,
				NvOdmGpioPinMode_InputInterruptAny, dock_h2w_switch_irq_isr, hsdev, IRQ_DEBOUNCE)
				== NV_FALSE) || (hsdev->dock_hp_det_irq == NULL)) {
			loge("err register dock hp irq\n");
			goto err_register_dock_hp_irq;
		}
	}

	platform_set_drvdata(pdev, hsdev);

	/* After all we simulate a isr */
	queue_work(hsdev->workqueue, &hsdev->work);
	logd("h2w_switch_probe success\n");
	return 0;

err_register_dock_hp_irq:
	NvOdmGpioInterruptUnregister(hsdev->gpio, hsdev->hp_det_pin, hsdev->hp_det_irq);
err_register_irq:
	destroy_workqueue(hsdev->workqueue);
err_create_workqueue:
	switch_dev_unregister(&hsdev->sdev);
err_register_sdev:
	NvOdmGpioReleasePinHandle(hsdev->gpio, hsdev->dock_hp_det_pin);
err_acquire_dock_det_pin:
	NvOdmGpioReleasePinHandle(hsdev->gpio, hsdev->hp_det_pin);
err_acquire_det_pin:
	NvOdmGpioClose(hsdev->gpio);
err_open_gpio:
	kfree(hsdev);
err_alloc_hsdev:
	loge("h2w_switch_probe failed\n");
	return -1;
}