示例#1
0
int kr3dm_acc_start(void)
{
	int result;
	struct device *dev_t;

	kr3dmacc_t accels; /* only for test */

	result = register_chrdev( KR3DM_MAJOR, "kr3dm", &kr3dm_acc_fops);

	if (result < 0)
	{
		return result;
	}

	kr3dm_acc_class = class_create (THIS_MODULE, "KR3DM-dev");

	if (IS_ERR(kr3dm_acc_class))
	{
		unregister_chrdev( KR3DM_MAJOR, "kr3dm" );
		return PTR_ERR( kr3dm_acc_class );
	}

	dev_t = device_create( kr3dm_acc_class, NULL, MKDEV(KR3DM_MAJOR, 0), "%s", "kr3dm");

	if (IS_ERR(dev_t))
	{
		return PTR_ERR(dev_t);
	}


	result = i2c_acc_kr3dm_init();

	if(result)
	{
		return result;
	}

	kr3dm_chip_init();
#if DEBUG
	printk("[KR3DM] read_xyz ==========================\n");
	kr3dm_read_accel_xyz( &accels );
	printk("[KR3DM] x = %d  /  y =  %d  /  z = %d\n", accels.x, accels.y, accels.z );
	printk("[KR3DM] ======================kr3dm_acc_start Ready for use !!!!! =============\n");
#endif
	return 0;
}
示例#2
0
int kr3dm_acc_start(void)
{
	int result;
	struct device *dev_t;
	
#ifdef SECURITY_HOLE_SUPPORT	
		int err;
		struct input_dev *input_dev;
#endif

	kr3dmacc_t accels; /* only for test */

	result = register_chrdev( KR3DM_MAJOR, "kr3dm", &kr3dm_acc_fops);

	if (result < 0)
	{
		return result;
	}

	kr3dm_acc_class = class_create (THIS_MODULE, "KR3DM-dev");

	if (IS_ERR(kr3dm_acc_class))
	{
		unregister_chrdev( KR3DM_MAJOR, "kr3dm" );
		return PTR_ERR( kr3dm_acc_class );
	}

	dev_t = device_create( kr3dm_acc_class, NULL, MKDEV(KR3DM_MAJOR, 0), "%s", "kr3dm");

	if (IS_ERR(dev_t))
	{
		return PTR_ERR(dev_t);
	}

#ifdef SECURITY_HOLE_SUPPORT	
		//mutex_init(&kr3dm.power_lock);
	
		/* hrtimer settings.  we poll for light values using a timer. */
		hrtimer_init(&kr3dm.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
		kr3dm.acc_poll_delay = ns_to_ktime(240 * NSEC_PER_MSEC);
		kr3dm.timer.function = kr3dm_timer_func;
	
		/* the timer just fires off a work queue request.  we need a thread
		   to read the i2c (can be slow and blocking). */
		kr3dm.wq = create_singlethread_workqueue("kr3dm_wq");
		if (!kr3dm.wq) {
			err = -ENOMEM;
			printk("%s: could not create workqueue\n", __func__);
			goto err_create_workqueue;
		}
		/* this is the thread function we run on the work queue */
		INIT_WORK(&kr3dm.work_acc, kr3dm_work_func_acc);
	
		/* allocate lightsensor-level input_device */
		input_dev = input_allocate_device();
		if (!input_dev) {
			printk("%s: could not allocate input device\n", __func__);
			err = -ENOMEM;
			goto err_input_allocate_device_light;
		}
		input_set_drvdata(input_dev, &kr3dm);
		input_dev->name = "accel";
	
	
		set_bit(EV_ABS, input_dev->evbit);	
		/* acceleration x-axis */
		input_set_capability(input_dev, EV_ABS, ABS_X);
		input_set_abs_params(input_dev, ABS_X, -1024, 1024, 0, 0);
		/* acceleration y-axis */
		input_set_capability(input_dev, EV_ABS, ABS_Y);
		input_set_abs_params(input_dev, ABS_Y, -1024, 1024, 0, 0);
		/* acceleration z-axis */
		input_set_capability(input_dev, EV_ABS, ABS_Z);
		input_set_abs_params(input_dev, ABS_Z, -1024, 1024, 0, 0);
	
		printk("registering lightsensor-level input device\n");
		err = input_register_device(input_dev);
		if (err < 0) {
			printk("%s: could not register input device\n", __func__);
			input_free_device(input_dev);
			goto err_input_register_device_light;
		}
		kr3dm.acc_input_dev = input_dev;
	
	
		err = sysfs_create_group(&input_dev->dev.kobj,&acc_attribute_group);
		if (err) {
			printk("Creating kr3dm attribute group failed");
			goto error_device;
		}
	
	//////////////////////////////////////////////////////////////////////////////
#endif	

	result = i2c_acc_kr3dm_init();

	if(result)
	{
		return result;
	}

	kr3dm_chip_init();
#if DEBUG
	printk("[KR3DM] read_xyz ==========================\n");
	kr3dm_read_accel_xyz( &accels );
	printk("[KR3DM] x = %d  /  y =  %d  /  z = %d\n", accels.x, accels.y, accels.z );
	printk("[KR3DM] ======================kr3dm_acc_start Ready for use !!!!! =============\n");
#endif
	return 0;

error_device:
	sysfs_remove_group(&input_dev->dev.kobj, &acc_attribute_group);
err_input_register_device_light:
	input_unregister_device(kr3dm.acc_input_dev);
err_input_allocate_device_light:	
	destroy_workqueue(kr3dm.wq);
err_create_workqueue:
	//mutex_destroy(&kr3dm.power_lock);
exit:
	return err;

}