Example #1
0
/**
 * Init function.
 * Allocates interrupt for power button and registers itself to input layer.
 */
static int __init retubutton_init(void)
{
	int irq;

	printk(KERN_INFO "Retu power button driver initialized\n");
	irq = RETU_INT_PWR;

	init_timer(&pwrbtn_timer);
	pwrbtn_timer.function = retubutton_timer_func;

	if (retu_request_irq(irq, &retubutton_irq, 0, "PwrOnX") < 0) {
		printk(KERN_ERR "%s@%s: Cannot allocate irq\n",
		       __FUNCTION__, __FILE__);
		return -EBUSY;
	}

	pwrbtn_dev = input_allocate_device();
	if (!pwrbtn_dev)
		return -ENOMEM;

	pwrbtn_dev->evbit[0] = BIT_MASK(EV_KEY);
	pwrbtn_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
	pwrbtn_dev->name = "retu-pwrbutton";

	return input_register_device(pwrbtn_dev);
}
Example #2
0
static int __init retu_headset_probe(struct platform_device *pdev)
{
	struct retu_headset *hs;
	int r;

	hs = kzalloc(sizeof(*hs), GFP_KERNEL);
	if (hs == NULL)
		return -ENOMEM;

	hs->pdev = pdev;

	hs->idev = input_allocate_device();
	if (hs->idev == NULL) {
		r = -ENOMEM;
		goto err1;
	}
	hs->idev->name = "retu-headset";
	hs->idev->dev.parent = &pdev->dev;
	set_bit(EV_KEY, hs->idev->evbit);
	set_bit(RETU_HEADSET_KEY, hs->idev->keybit);
	r = input_register_device(hs->idev);
	if (r < 0)
		goto err2;

	r = device_create_file(&pdev->dev, &dev_attr_hookdet);
	if (r < 0)
		goto err3;
	r = device_create_file(&pdev->dev, &dev_attr_enable);
	if (r < 0)
		goto err4;
	r = device_create_file(&pdev->dev, &dev_attr_enable_det);
	if (r < 0)
		goto err5;
	platform_set_drvdata(pdev, hs);

	spin_lock_init(&hs->lock);
	mutex_init(&hs->mutex);
	setup_timer(&hs->enable_timer, retu_headset_enable_timer,
		    (unsigned long) hs);
	setup_timer(&hs->detect_timer, retu_headset_detect_timer,
		    (unsigned long) hs);

	r = retu_request_irq(RETU_INT_HOOK, retu_headset_hook_interrupt,
			     (unsigned long) hs, "hookdet");
	if (r != 0) {
		dev_err(&pdev->dev, "hookdet IRQ not available\n");
		goto err6;
	}
	retu_disable_irq(RETU_INT_HOOK);
	return 0;
err6:
	device_remove_file(&pdev->dev, &dev_attr_enable_det);
err5:
	device_remove_file(&pdev->dev, &dev_attr_enable);
err4:
	device_remove_file(&pdev->dev, &dev_attr_hookdet);
err3:
	input_unregister_device(hs->idev);
err2:
	input_free_device(hs->idev);
err1:
	kfree(hs);
	return r;
}