2 * Input driver for PCAP events:
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>
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
);
34 ezx_pcap_read(pcap_keys
->pcap
, PCAP_REG_PSTAT
, &pstat
);
39 input_report_key(pcap_keys
->input
, KEY_POWER
, !pstat
);
42 input_report_key(pcap_keys
->input
, KEY_HP
, !pstat
);
46 input_sync(pcap_keys
->input
);
51 static int __devinit
pcap_keys_probe(struct platform_device
*pdev
)
54 struct pcap_keys
*pcap_keys
;
55 struct input_dev
*input_dev
;
57 pcap_keys
= kmalloc(sizeof(struct pcap_keys
), GFP_KERNEL
);
61 pcap_keys
->pcap
= dev_get_drvdata(pdev
->dev
.parent
);
63 input_dev
= input_allocate_device();
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
);
83 err
= request_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_ONOFF
),
84 pcap_keys_handler
, 0, "Power key", pcap_keys
);
88 err
= request_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_MIC
),
89 pcap_keys_handler
, 0, "Headphone button", pcap_keys
);
96 free_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_ONOFF
), pcap_keys
);
98 input_unregister_device(input_dev
);
101 input_free_device(input_dev
);
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
);
120 static struct platform_driver pcap_keys_device_driver
= {
121 .probe
= pcap_keys_probe
,
122 .remove
= __devexit_p(pcap_keys_remove
),
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");