2 * Copyright (C) 2009 Motorola, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/input.h>
23 #include <linux/slab.h>
24 #include <linux/spi/cpcap.h>
25 #include <linux/spi/cpcap-regbits.h>
29 struct cpcap_key_data {
30 struct input_dev *input_dev;
31 struct cpcap_device *cpcap;
34 static int cpcap_key_probe(struct platform_device *pdev)
37 struct cpcap_key_data *key;
39 if (pdev->dev.platform_data == NULL) {
40 dev_err(&pdev->dev, "no platform_data\n");
44 key = kzalloc(sizeof(*key), GFP_KERNEL);
48 key->cpcap = pdev->dev.platform_data;
50 key->input_dev = input_allocate_device();
51 if (key->input_dev == NULL) {
52 dev_err(&pdev->dev, "can't allocate input device\n");
57 set_bit(EV_KEY, key->input_dev->evbit);
58 set_bit(KEY_MEDIA, key->input_dev->keybit);
59 set_bit(KEY_END, key->input_dev->keybit);
61 key->input_dev->name = "cpcap-key";
63 err = input_register_device(key->input_dev);
65 dev_err(&pdev->dev, "could not register input device.\n");
69 platform_set_drvdata(pdev, key);
70 cpcap_set_keydata(key->cpcap, key);
72 dev_info(&pdev->dev, "CPCAP key device probed\n");
77 input_free_device(key->input_dev);
83 static int __exit cpcap_key_remove(struct platform_device *pdev)
85 struct cpcap_key_data *key = platform_get_drvdata(pdev);
87 input_unregister_device(key->input_dev);
88 input_free_device(key->input_dev);
94 void cpcap_broadcast_key_event(struct cpcap_device *cpcap,
95 unsigned int code, int value)
97 struct cpcap_key_data *key = cpcap_get_keydata(cpcap);
99 if (key && key->input_dev)
100 input_report_key(key->input_dev, code, value);
102 EXPORT_SYMBOL(cpcap_broadcast_key_event);
104 static struct platform_driver cpcap_key_driver = {
105 .probe = cpcap_key_probe,
106 .remove = __exit_p(cpcap_key_remove),
109 .owner = THIS_MODULE,
113 static int __init cpcap_key_init(void)
115 return platform_driver_register(&cpcap_key_driver);
117 module_init(cpcap_key_init);
119 static void __exit cpcap_key_exit(void)
121 platform_driver_unregister(&cpcap_key_driver);
123 module_exit(cpcap_key_exit);
125 MODULE_ALIAS("platform:cpcap_key");
126 MODULE_DESCRIPTION("CPCAP KEY driver");
127 MODULE_AUTHOR("Motorola");
128 MODULE_LICENSE("GPL");