NvBool NvAmbientsensorI2COpen(NvOdmServicesI2cHandle *hI2CDevice, NvU32 id)
{
    // Open I2C handle.
    *hI2CDevice = NvOdmI2cPinMuxOpen(NvOdmIoModule_I2c, id, NvOdmI2cPinMap_Config2);
    if (*hI2CDevice == NULL)
    {
        return NV_FALSE;
    }
    return NV_TRUE;
}
예제 #2
0
/*
 * Initialize I2C for accelerometer.
 */
NvBool NvGyroAccelI2COpen(NvOdmServicesI2cHandle* hI2CDevice, NvU32 id)
{
	// Open I2C handle.

	*hI2CDevice  =  NvOdmI2cPinMuxOpen(NvOdmIoModule_I2c, 1, NvOdmI2cPinMap_Config2);
	printk(" ## MPU3050 : NvGyroAccelI2COpen \n") ;

	if (*hI2CDevice == NULL) {
		printk(" ## MPU3050 NvGyroAccelI2COpen Error ##\n");
		return NV_FALSE;
	}

	return NV_TRUE;
}
예제 #3
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
}