blob: 73b13ebabe563e3d60a1d497ed7acd75488782d2 [file] [log] [blame]
Balaji Rao1851b062009-01-09 01:50:58 +01001/* NXP PCF50633 Input Driver
2 *
3 * (C) 2006-2008 by Openmoko, Inc.
4 * Author: Balaji Rao <balajirrao@openmoko.org>
5 * All rights reserved.
6 *
7 * Broken down from monstrous PCF50633 driver mainly by
8 * Harald Welte, Andy Green and Werner Almesberger
9 *
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.
14 *
15 */
16
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Balaji Rao1851b062009-01-09 01:50:58 +010024
25#include <linux/mfd/pcf50633/core.h>
26
27#define PCF50633_OOCSTAT_ONKEY 0x01
28#define PCF50633_REG_OOCSTAT 0x12
29#define PCF50633_REG_OOCMODE 0x10
30
31struct pcf50633_input {
32 struct pcf50633 *pcf;
33 struct input_dev *input_dev;
34};
35
36static void
37pcf50633_input_irq(int irq, void *data)
38{
39 struct pcf50633_input *input;
40 int onkey_released;
41
42 input = data;
43
44 /* We report only one event depending on the key press status */
45 onkey_released = pcf50633_reg_read(input->pcf, PCF50633_REG_OOCSTAT)
46 & PCF50633_OOCSTAT_ONKEY;
47
48 if (irq == PCF50633_IRQ_ONKEYF && !onkey_released)
49 input_report_key(input->input_dev, KEY_POWER, 1);
50 else if (irq == PCF50633_IRQ_ONKEYR && onkey_released)
51 input_report_key(input->input_dev, KEY_POWER, 0);
52
53 input_sync(input->input_dev);
54}
55
Bill Pemberton5298cc42012-11-23 21:38:25 -080056static int pcf50633_input_probe(struct platform_device *pdev)
Balaji Rao1851b062009-01-09 01:50:58 +010057{
58 struct pcf50633_input *input;
Balaji Rao1851b062009-01-09 01:50:58 +010059 struct input_dev *input_dev;
60 int ret;
61
62
63 input = kzalloc(sizeof(*input), GFP_KERNEL);
64 if (!input)
65 return -ENOMEM;
66
67 input_dev = input_allocate_device();
68 if (!input_dev) {
69 kfree(input);
70 return -ENOMEM;
71 }
72
73 platform_set_drvdata(pdev, input);
Lars-Peter Clausen68d641e2009-10-14 02:12:33 +040074 input->pcf = dev_to_pcf50633(pdev->dev.parent);
Balaji Rao1851b062009-01-09 01:50:58 +010075 input->input_dev = input_dev;
76
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);
81
82 ret = input_register_device(input_dev);
83 if (ret) {
84 input_free_device(input_dev);
85 kfree(input);
86 return ret;
87 }
Lars-Peter Clausen68d641e2009-10-14 02:12:33 +040088 pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYR,
Balaji Rao1851b062009-01-09 01:50:58 +010089 pcf50633_input_irq, input);
Lars-Peter Clausen68d641e2009-10-14 02:12:33 +040090 pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYF,
Balaji Rao1851b062009-01-09 01:50:58 +010091 pcf50633_input_irq, input);
92
93 return 0;
94}
95
Bill Pembertone2619cf2012-11-23 21:50:47 -080096static int pcf50633_input_remove(struct platform_device *pdev)
Balaji Rao1851b062009-01-09 01:50:58 +010097{
98 struct pcf50633_input *input = platform_get_drvdata(pdev);
99
100 pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYR);
101 pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYF);
102
103 input_unregister_device(input->input_dev);
104 kfree(input);
105
106 return 0;
107}
108
109static struct platform_driver pcf50633_input_driver = {
110 .driver = {
111 .name = "pcf50633-input",
112 },
113 .probe = pcf50633_input_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800114 .remove = pcf50633_input_remove,
Balaji Rao1851b062009-01-09 01:50:58 +0100115};
JJ Ding840a7462011-11-29 11:08:40 -0800116module_platform_driver(pcf50633_input_driver);
Balaji Rao1851b062009-01-09 01:50:58 +0100117
118MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
119MODULE_DESCRIPTION("PCF50633 input driver");
120MODULE_LICENSE("GPL");
121MODULE_ALIAS("platform:pcf50633-input");