1 /* NXP PCF50633 Input Driver
3 * (C) 2006-2008 by Openmoko, Inc.
4 * Author: Balaji Rao <balajirrao@openmoko.org>
7 * Broken down from monstrous PCF50633 driver mainly by
8 * Harald Welte, Andy Green and Werner Almesberger
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/device.h>
21 #include <linux/platform_device.h>
22 #include <linux/input.h>
24 #include <linux/mfd/pcf50633/core.h>
26 #define PCF50633_OOCSTAT_ONKEY 0x01
27 #define PCF50633_REG_OOCSTAT 0x12
28 #define PCF50633_REG_OOCMODE 0x10
30 struct pcf50633_input {
32 struct input_dev *input_dev;
36 pcf50633_input_irq(int irq, void *data)
38 struct pcf50633_input *input;
43 /* We report only one event depending on the key press status */
44 onkey_released = pcf50633_reg_read(input->pcf, PCF50633_REG_OOCSTAT)
45 & PCF50633_OOCSTAT_ONKEY;
47 if (irq == PCF50633_IRQ_ONKEYF && !onkey_released)
48 input_report_key(input->input_dev, KEY_POWER, 1);
49 else if (irq == PCF50633_IRQ_ONKEYR && onkey_released)
50 input_report_key(input->input_dev, KEY_POWER, 0);
52 input_sync(input->input_dev);
55 static int __devinit pcf50633_input_probe(struct platform_device *pdev)
57 struct pcf50633_input *input;
58 struct pcf50633_subdev_pdata *pdata = pdev->dev.platform_data;
59 struct input_dev *input_dev;
63 input = kzalloc(sizeof(*input), GFP_KERNEL);
67 input_dev = input_allocate_device();
73 platform_set_drvdata(pdev, input);
74 input->pcf = pdata->pcf;
75 input->input_dev = input_dev;
77 input_dev->name = "PCF50633 PMU events";
78 input_dev->id.bustype = BUS_I2C;
79 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR);
80 set_bit(KEY_POWER, input_dev->keybit);
82 ret = input_register_device(input_dev);
84 input_free_device(input_dev);
88 pcf50633_register_irq(pdata->pcf, PCF50633_IRQ_ONKEYR,
89 pcf50633_input_irq, input);
90 pcf50633_register_irq(pdata->pcf, PCF50633_IRQ_ONKEYF,
91 pcf50633_input_irq, input);
96 static int __devexit pcf50633_input_remove(struct platform_device *pdev)
98 struct pcf50633_input *input = platform_get_drvdata(pdev);
100 pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYR);
101 pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYF);
103 input_unregister_device(input->input_dev);
109 static struct platform_driver pcf50633_input_driver = {
111 .name = "pcf50633-input",
113 .probe = pcf50633_input_probe,
114 .remove = __devexit_p(pcf50633_input_remove),
117 static int __init pcf50633_input_init(void)
119 return platform_driver_register(&pcf50633_input_driver);
121 module_init(pcf50633_input_init);
123 static void __exit pcf50633_input_exit(void)
125 platform_driver_unregister(&pcf50633_input_driver);
127 module_exit(pcf50633_input_exit);
129 MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
130 MODULE_DESCRIPTION("PCF50633 input driver");
131 MODULE_LICENSE("GPL");
132 MODULE_ALIAS("platform:pcf50633-input");