nilfs2: unbreak compat ioctl
[zen-stable.git] / drivers / input / misc / pcap_keys.c
blob99335c286250594933967ea3132aba3a948b4b4f
1 /*
2 * Input driver for PCAP events:
3 * * Power key
4 * * Headphone button
6 * Copyright (c) 2008,2009 Ilya Petrov <ilya.muromec@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/platform_device.h>
18 #include <linux/input.h>
19 #include <linux/mfd/ezx-pcap.h>
20 #include <linux/slab.h>
22 struct pcap_keys {
23 struct pcap_chip *pcap;
24 struct input_dev *input;
27 /* PCAP2 interrupts us on keypress */
28 static irqreturn_t pcap_keys_handler(int irq, void *_pcap_keys)
30 struct pcap_keys *pcap_keys = _pcap_keys;
31 int pirq = irq_to_pcap(pcap_keys->pcap, irq);
32 u32 pstat;
34 ezx_pcap_read(pcap_keys->pcap, PCAP_REG_PSTAT, &pstat);
35 pstat &= 1 << pirq;
37 switch (pirq) {
38 case PCAP_IRQ_ONOFF:
39 input_report_key(pcap_keys->input, KEY_POWER, !pstat);
40 break;
41 case PCAP_IRQ_MIC:
42 input_report_key(pcap_keys->input, KEY_HP, !pstat);
43 break;
46 input_sync(pcap_keys->input);
48 return IRQ_HANDLED;
51 static int __devinit pcap_keys_probe(struct platform_device *pdev)
53 int err = -ENOMEM;
54 struct pcap_keys *pcap_keys;
55 struct input_dev *input_dev;
57 pcap_keys = kmalloc(sizeof(struct pcap_keys), GFP_KERNEL);
58 if (!pcap_keys)
59 return err;
61 pcap_keys->pcap = dev_get_drvdata(pdev->dev.parent);
63 input_dev = input_allocate_device();
64 if (!input_dev)
65 goto fail;
67 pcap_keys->input = input_dev;
69 platform_set_drvdata(pdev, pcap_keys);
70 input_dev->name = pdev->name;
71 input_dev->phys = "pcap-keys/input0";
72 input_dev->id.bustype = BUS_HOST;
73 input_dev->dev.parent = &pdev->dev;
75 __set_bit(EV_KEY, input_dev->evbit);
76 __set_bit(KEY_POWER, input_dev->keybit);
77 __set_bit(KEY_HP, input_dev->keybit);
79 err = input_register_device(input_dev);
80 if (err)
81 goto fail_allocate;
83 err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF),
84 pcap_keys_handler, 0, "Power key", pcap_keys);
85 if (err)
86 goto fail_register;
88 err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC),
89 pcap_keys_handler, 0, "Headphone button", pcap_keys);
90 if (err)
91 goto fail_pwrkey;
93 return 0;
95 fail_pwrkey:
96 free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), pcap_keys);
97 fail_register:
98 input_unregister_device(input_dev);
99 goto fail;
100 fail_allocate:
101 input_free_device(input_dev);
102 fail:
103 kfree(pcap_keys);
104 return err;
107 static int __devexit pcap_keys_remove(struct platform_device *pdev)
109 struct pcap_keys *pcap_keys = platform_get_drvdata(pdev);
111 free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), pcap_keys);
112 free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC), pcap_keys);
114 input_unregister_device(pcap_keys->input);
115 kfree(pcap_keys);
117 return 0;
120 static struct platform_driver pcap_keys_device_driver = {
121 .probe = pcap_keys_probe,
122 .remove = __devexit_p(pcap_keys_remove),
123 .driver = {
124 .name = "pcap-keys",
125 .owner = THIS_MODULE,
129 static int __init pcap_keys_init(void)
131 return platform_driver_register(&pcap_keys_device_driver);
134 static void __exit pcap_keys_exit(void)
136 platform_driver_unregister(&pcap_keys_device_driver);
139 module_init(pcap_keys_init);
140 module_exit(pcap_keys_exit);
142 MODULE_DESCRIPTION("Motorola PCAP2 input events driver");
143 MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>");
144 MODULE_LICENSE("GPL");
145 MODULE_ALIAS("platform:pcap_keys");