Example #1
0
/**
 * All the device spefic initializations happen here.
 */
static NvS32 __init tegra_acc_probe(struct platform_device *pdev)
{
	struct tegra_acc_device_data *accelerometer = NULL;
	struct input_dev *input_dev = NULL;
	NvS32 err;
	NvBool ret;

	accelerometer = kzalloc(sizeof(*accelerometer), GFP_KERNEL);
	if (accelerometer == NULL) {
		err = -ENOMEM;
		pr_err("tegra_acc_probe: Failed to memory\n");
		goto allocate_dev_fail;
	}
	accel_dev = accelerometer;

	input_dev = input_allocate_device();
	if (input_dev == NULL) {
		err = -ENOMEM;
		pr_err("tegra_acc_probe: Failed to allocate input device\n");
		goto allocate_dev_fail;
	}
	g_input_dev = input_dev;

	ret = open_def_odm_accl();
	if (!ret) {
		pr_err("open_def_odm_accl failed\n");
		goto allocate_dev_fail;
	}

	//start the Int thread.
	accelerometer->task = kthread_create(tegra_acc_thread,
		accelerometer, "tegra_acc_thread");
	if (accelerometer->task == NULL) {
		err = -1;
		goto thread_create_failed;
	}
	wake_up_process(accelerometer->task);

	accelerometer->input_dev = input_dev;
	set_bit(EV_SYN, accelerometer->input_dev->evbit);
	set_bit(EV_KEY, accelerometer->input_dev->evbit);
	set_bit(EV_ABS, accelerometer->input_dev->evbit);

	input_set_abs_params(accelerometer->input_dev, ABS_X,
		accelerometer->min_data.x,
		accelerometer->max_data.x, 0, 0);
	input_set_abs_params(accelerometer->input_dev, ABS_Y,
		accelerometer->min_data.y,
		accelerometer->max_data.y, 0, 0);
	input_set_abs_params(accelerometer->input_dev, ABS_Z,
		accelerometer->min_data.z,
		accelerometer->max_data.z, 0, 0);

	platform_set_drvdata(pdev, accelerometer);

	input_dev->name = "accelerometer_tegra";
	err = input_register_device(input_dev);
	if (err) {
		pr_err("tegra_acc_probe: Unable to register %s\
				input device\n", input_dev->name);
		goto input_register_device_failed;
	}

	err = add_sysfs_entry();
	if (err) {
		pr_err("tegra_acc_probe: add_sysfs_entry failed\n");
		goto sysfs_failed;
	}

	printk(KERN_INFO DRIVER_NAME "successfully registered\n");
	return err;

sysfs_failed:
	input_unregister_device(input_dev);
input_register_device_failed:
	accelerometer->bThreadAlive = 0;
thread_create_failed:
	//KillThreadHere!
allocate_dev_fail:
	close_odm_accl();
	input_free_device(input_dev);
	kfree(accelerometer);
	accelerometer = 0;
	err = -ENOMEM;

	return err;
}
Example #2
0
/*---------------------------------------------------------------------------
	 platform device
   ---------------------------------------------------------------------------*/		  
static int __init star_motion_probe(struct platform_device *pdev)
{
     int err = 0;
	 unsigned char value = 0;
     struct device *dev = &pdev->dev;	 
	 struct star_motion_device *gyroscope_accel = NULL; 
	 struct input_dev *input_dev = NULL;

	 
	 printk("[MPU3050] ## [%s:%d]\n",__FUNCTION__, __LINE__);
	 
	 gyroscope_accel = kzalloc(sizeof(*gyroscope_accel), GFP_KERNEL);
	 star_motion_dev = gyroscope_accel;
	 
     printk(KERN_INFO"%s: probe start\n", __func__);
    
   /*---------------------------------------------------------------------------
       register i2c driver
     ---------------------------------------------------------------------------*/	 	
     #if 0  /*Star Feature*/
      err = i2c_add_driver(&gyro_i2c_driver);
     if(err < 0){
	    printk("************* LGE: gyro_i2c_test_client fail\n");
	    goto err_i2c_add_driver;
     }

     err = i2c_add_driver(&accel_i2c_driver);
     if(err < 0){
	    printk("************* LGE: accel_i2c_test_client fail\n");
	    goto err_i2c_add_driver;
     }	 
  	#endif
    

     /*---------------------------------------------------------------------------
       register misc device
     ---------------------------------------------------------------------------*/	 
       err = misc_register(&star_motion_misc_device);
       if (err) {
		printk(KERN_ERR"star_motion_misc_device register failed\n");
		goto exit_misc_device_register_failed;
	}

     /*---------------------------------------------------------------------------
       register input device
      ---------------------------------------------------------------------------*/
      star_motion_dev->input_dev = input_allocate_device();
      if(star_motion_dev->input_dev == NULL)
      {
           printk(KERN_ERR"star_motion_sesnor_probe: input_allocate_device (1) failed\n");
           goto err_input_allocate1;		
      }  

      star_motion_dev->input_dev->name = STAR_MOTION_INPUT_NAME;
  
       set_bit(EV_SYN,star_motion_dev->input_dev->evbit);	
	   set_bit(EV_REL,star_motion_dev->input_dev->evbit);

	   set_bit(REL_X,star_motion_dev->input_dev->relbit);  // TAP - Type 
	   set_bit(REL_Y,star_motion_dev->input_dev->relbit);  // TAP - Direction   
	   set_bit(REL_RX,star_motion_dev->input_dev->relbit);  // TILT - Roll
	   set_bit(REL_RY,star_motion_dev->input_dev->relbit);  // TILT - PITCH   
	   set_bit(REL_RZ,star_motion_dev->input_dev->relbit);  // TILT - Yaw
	   set_bit(REL_HWHEEL,star_motion_dev->input_dev->relbit); // SHAKE
	   set_bit(REL_DIAL,star_motion_dev->input_dev->relbit);   // SNAP - Direction 
	   set_bit(REL_WHEEL,star_motion_dev->input_dev->relbit);  // FLIP
  
       err = input_register_device(star_motion_dev->input_dev);
       if(err){
             printk(KERN_ERR"star_motion_sesnor_probe: input_allocate_device (1) failed \n");
             goto err_input_allocate1;		
       }

	/*---------------------------------------------------------------------------
		init. sysfs
	---------------------------------------------------------------------------*/			 
       if ((err = sysfs_create_group(&dev->kobj, &star_motion_group)))
       {
	    printk("[motion_sensor] sysfs_create_group FAIL \n");
	    goto err_sysfs_create;
      }

	/*---------------------------------------------------------------------------
		INIT_WORK 
	---------------------------------------------------------------------------*/		  			
	#if 1
	INIT_WORK(&star_motion_dev->tilt_work, motion_tilt_work_func);

    /*---------------------------------------------------------------------------
		init. workqueue 
	---------------------------------------------------------------------------*/		  			
	star_motion_dev->timer_wq = create_singlethread_workqueue("motion_timer_wq");
	if (!star_motion_dev->timer_wq) {
		printk("[motion_sensor] couldn't create timer queue\n");
		goto err_motion_timer_wq;
	}

   /*---------------------------------------------------------------------------
		init. timer
    ---------------------------------------------------------------------------*/
     // TILT POLLING TIMER 	 
     hrtimer_init(&star_motion_dev->timer[1], CLOCK_MONOTONIC, HRTIMER_MODE_REL);
     star_motion_dev->timer[1].function = motion_tilt_timer_func;
	#endif 
     /*---------------------------------------------------------------------------
       power 
     ---------------------------------------------------------------------------*/	
     #if 0
#if defined(CONFIG_MACH_LGE_STAR_REV_C)	
	 star_gyro_vio_reg = regulator_get(&pdev->dev, "vaux2");
	 if (star_gyro_vio_reg == NULL) {
		    printk(KERN_ERR": Failed to get motion power resources !! \n");
		    return -ENODEV;
	 }
#endif

	 star_motion_reg = regulator_get(&pdev->dev, "vmmc2");
	  if (star_motion_reg == NULL) {
		    printk(KERN_ERR": Failed to get motion power resources !! \n");
		    return -ENODEV;
	  } 
#endif
	  printk("[MPU3050] ## [%s:%d]\n",__FUNCTION__, __LINE__);

	  err = open_def_odm_gyro_accel();
		   if (!err) {
			   printk("open_def_odm_gyro_accel\n");
			   goto allocate_dev_fail;
		  }
	  printk("[MPU3050] ## [%s:%d]\n",__FUNCTION__, __LINE__);

	  
	mdelay(50);
	 //  Read WHO AM I	
	 value = 0;
	 //status = mpu3050_read_reg(mpu3050_i2c_client,MPU3050_GYRO_I2C_WHO_AM_I,&value);
	 NvGyroAccelI2CGetRegs(star_motion_dev->hOdmGyroAccel, MPU3050_GYRO_I2C_WHO_AM_I ,&value , 1 );
	 printk("[MPU3050] MPU3050_GYRO_I2C_WHO_AM_I : %x\n",value);
	 
	 // Read Product ID
	 value = 0;
	 //status = mpu3050_read_reg(mpu3050_i2c_client,MPU3050_GYRO_I2C_PRODUCT_ID,&value); 
	 NvGyroAccelI2CGetRegs(star_motion_dev->hOdmGyroAccel, MPU3050_GYRO_I2C_PRODUCT_ID ,&value , 1 );
	 printk("[MPU3050] MPU3050_GYRO_I2C_PRODUCT_ID : %x\n",value);

	 #if 0
	 err = open_def_odm_accl();
		   if (!err) {
			   printk("open_def_odm_gyro_accel\n");
			   goto allocate_dev_fail;
		  }
	  printk("[MPU3050] ## [%s:%d]\n",__FUNCTION__, __LINE__);	
	  #endif
	 // mpu3050_initialize();

	  //motion_sensor_power_on();
	  //twl4030_i2c_write_u8(0x13, 0x00,0x1b );
	  //msleep(100);	
	  
	 return 0;	
#if 0  /*Star Feature*/
err_i2c_add_driver:
    i2c_del_driver(&gyro_i2c_driver);
	i2c_del_driver(&accel_i2c_driver);
#endif
allocate_dev_fail:
       printk("##  sensor: allocated_device_failed\n");        
	close_odm_gyro_accel();
err_input_allocate1:   
       printk("##  sensor: input_device_failed\n");        
	input_unregister_device(star_motion_dev->input_dev);	
exit_misc_device_register_failed:
err_sysfs_create:
       printk("##  sensor: heaven motion misc_device_register_failed\n");        
err_motion_timer_wq:
       printk("##  sensor: timer_failed\n");        
	destroy_workqueue(star_motion_dev->timer_wq);
	return err;	

}
Example #3
0
/**Function to parse the values sent through sysfs and sets them accordingly
 */
void change_nvodm_accelerometer_settings(NvU32 command, NvS32 value)
{
	switch (command) {
	case COMMAND_LOG:
		accel_dev->show_log = (value == 0 ? NV_FALSE : NV_TRUE);
		break;
	case COMMAND_FREQUENCY:
		if (value <  3) {
			NvOdmAccelSetSampleRate(accel_dev->hOdmAcr,
				NvOdmAccelPower_Low);
			if (NvOdmAccelSetSampleRate(accel_dev->hOdmAcr, value)) {
				accel_dev->freq = value;
			}
		} else {
			NvOdmAccelSetSampleRate(accel_dev->hOdmAcr,
				NvOdmAccelPower_Fullrun);
			if (NvOdmAccelSetSampleRate(accel_dev->hOdmAcr, value)) {
				accel_dev->freq = value;
			}
		}
		break;
	case COMMAND_TIMETAP:
		if( value > 0) {
			NvOdmAccelSetIntEnable(accel_dev->hOdmAcr,
				NvOdmAccelInt_TapThreshold,
				NvOdmAccelAxis_All, 0, NV_TRUE);

			NvOdmAccelSetIntTimeThreshold(accel_dev->hOdmAcr,
				NvOdmAccelInt_TapThreshold, 0, value);
		} else {
			NvOdmAccelSetIntEnable(accel_dev->hOdmAcr,
				NvOdmAccelInt_TapThreshold,
				NvOdmAccelAxis_All, 0, NV_FALSE);
		}
		break;
	case COMMAND_FORCETAP:
		if( value > 0) {
			NvOdmAccelSetIntEnable(accel_dev->hOdmAcr,
				NvOdmAccelInt_TapThreshold,
				NvOdmAccelAxis_All, 0, NV_TRUE);

			NvOdmAccelSetIntForceThreshold(accel_dev->hOdmAcr,
				NvOdmAccelInt_TapThreshold, 0, value);
		} else {
			NvOdmAccelSetIntEnable(accel_dev->hOdmAcr,
				NvOdmAccelInt_TapThreshold,
				NvOdmAccelAxis_All, 0, NV_FALSE);
		}
		break;
	case COMMAND_FORCEMOTION:
		if (value > 0) {
			NvOdmAccelSetIntEnable(accel_dev->hOdmAcr,
				NvOdmAccelInt_MotionThreshold,
				NvOdmAccelAxis_All, 0, NV_TRUE);
			NvOdmAccelSetIntForceThreshold(accel_dev->hOdmAcr,
				NvOdmAccelInt_MotionThreshold, 0, value);
		} else {
			NvOdmAccelSetIntEnable(accel_dev->hOdmAcr,
				NvOdmAccelInt_MotionThreshold,
				NvOdmAccelAxis_All, 0, NV_FALSE);
		}
		break;
	case COMMAND_OPENCLOSE:
		if (value) {
			if (!accel_dev->hOdmAcr)
				open_def_odm_accl();
		} else {
			if (accel_dev->hOdmAcr)
				close_odm_accl();
		}
		break;
	default:
		break;
	}
}