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>
22 struct pcap_chip
*pcap
;
23 struct input_dev
*input
;
26 /* PCAP2 interrupts us on keypress */
27 static irqreturn_t
pcap_keys_handler(int irq
, void *_pcap_keys
)
29 struct pcap_keys
*pcap_keys
= _pcap_keys
;
30 int pirq
= irq_to_pcap(pcap_keys
->pcap
, irq
);
33 ezx_pcap_read(pcap_keys
->pcap
, PCAP_REG_PSTAT
, &pstat
);
38 input_report_key(pcap_keys
->input
, KEY_POWER
, !pstat
);
41 input_report_key(pcap_keys
->input
, KEY_HP
, !pstat
);
45 input_sync(pcap_keys
->input
);
50 static int __devinit
pcap_keys_probe(struct platform_device
*pdev
)
53 struct pcap_keys
*pcap_keys
;
54 struct input_dev
*input_dev
;
56 pcap_keys
= kmalloc(sizeof(struct pcap_keys
), GFP_KERNEL
);
60 pcap_keys
->pcap
= dev_get_drvdata(pdev
->dev
.parent
);
62 input_dev
= input_allocate_device();
66 pcap_keys
->input
= input_dev
;
68 platform_set_drvdata(pdev
, pcap_keys
);
69 input_dev
->name
= pdev
->name
;
70 input_dev
->phys
= "pcap-keys/input0";
71 input_dev
->id
.bustype
= BUS_HOST
;
72 input_dev
->dev
.parent
= &pdev
->dev
;
74 __set_bit(EV_KEY
, input_dev
->evbit
);
75 __set_bit(KEY_POWER
, input_dev
->keybit
);
76 __set_bit(KEY_HP
, input_dev
->keybit
);
78 err
= input_register_device(input_dev
);
82 err
= request_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_ONOFF
),
83 pcap_keys_handler
, 0, "Power key", pcap_keys
);
87 err
= request_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_MIC
),
88 pcap_keys_handler
, 0, "Headphone button", pcap_keys
);
95 free_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_ONOFF
), pcap_keys
);
97 input_unregister_device(input_dev
);
100 input_free_device(input_dev
);
106 static int __devexit
pcap_keys_remove(struct platform_device
*pdev
)
108 struct pcap_keys
*pcap_keys
= platform_get_drvdata(pdev
);
110 free_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_ONOFF
), pcap_keys
);
111 free_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_MIC
), pcap_keys
);
113 input_unregister_device(pcap_keys
->input
);
119 static struct platform_driver pcap_keys_device_driver
= {
120 .probe
= pcap_keys_probe
,
121 .remove
= __devexit_p(pcap_keys_remove
),
124 .owner
= THIS_MODULE
,
128 static int __init
pcap_keys_init(void)
130 return platform_driver_register(&pcap_keys_device_driver
);
133 static void __exit
pcap_keys_exit(void)
135 platform_driver_unregister(&pcap_keys_device_driver
);
138 module_init(pcap_keys_init
);
139 module_exit(pcap_keys_exit
);
141 MODULE_DESCRIPTION("Motorola PCAP2 input events driver");
142 MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>");
143 MODULE_LICENSE("GPL");
144 MODULE_ALIAS("platform:pcap_keys");