blob: 4c60c70c4c102dd4564ff3f8a5350db4f9483c92 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Balaji Rao1851b062009-01-09 01:50:58 +01002/* NXP PCF50633 Input Driver
3 *
4 * (C) 2006-2008 by Openmoko, Inc.
5 * Author: Balaji Rao <balajirrao@openmoko.org>
6 * All rights reserved.
7 *
8 * Broken down from monstrous PCF50633 driver mainly by
9 * Harald Welte, Andy Green and Werner Almesberger
Balaji Rao1851b062009-01-09 01:50:58 +010010 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
Balaji Rao1851b062009-01-09 01:50:58 +010014#include <linux/device.h>
15#include <linux/platform_device.h>
16#include <linux/input.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Balaji Rao1851b062009-01-09 01:50:58 +010018
19#include <linux/mfd/pcf50633/core.h>
20
21#define PCF50633_OOCSTAT_ONKEY 0x01
22#define PCF50633_REG_OOCSTAT 0x12
23#define PCF50633_REG_OOCMODE 0x10
24
25struct pcf50633_input {
26 struct pcf50633 *pcf;
27 struct input_dev *input_dev;
28};
29
30static void
31pcf50633_input_irq(int irq, void *data)
32{
33 struct pcf50633_input *input;
34 int onkey_released;
35
36 input = data;
37
38 /* We report only one event depending on the key press status */
39 onkey_released = pcf50633_reg_read(input->pcf, PCF50633_REG_OOCSTAT)
40 & PCF50633_OOCSTAT_ONKEY;
41
42 if (irq == PCF50633_IRQ_ONKEYF && !onkey_released)
43 input_report_key(input->input_dev, KEY_POWER, 1);
44 else if (irq == PCF50633_IRQ_ONKEYR && onkey_released)
45 input_report_key(input->input_dev, KEY_POWER, 0);
46
47 input_sync(input->input_dev);
48}
49
Bill Pemberton5298cc42012-11-23 21:38:25 -080050static int pcf50633_input_probe(struct platform_device *pdev)
Balaji Rao1851b062009-01-09 01:50:58 +010051{
52 struct pcf50633_input *input;
Balaji Rao1851b062009-01-09 01:50:58 +010053 struct input_dev *input_dev;
54 int ret;
55
56
57 input = kzalloc(sizeof(*input), GFP_KERNEL);
58 if (!input)
59 return -ENOMEM;
60
61 input_dev = input_allocate_device();
62 if (!input_dev) {
63 kfree(input);
64 return -ENOMEM;
65 }
66
67 platform_set_drvdata(pdev, input);
Lars-Peter Clausen68d641e2009-10-14 02:12:33 +040068 input->pcf = dev_to_pcf50633(pdev->dev.parent);
Balaji Rao1851b062009-01-09 01:50:58 +010069 input->input_dev = input_dev;
70
71 input_dev->name = "PCF50633 PMU events";
72 input_dev->id.bustype = BUS_I2C;
73 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR);
74 set_bit(KEY_POWER, input_dev->keybit);
75
76 ret = input_register_device(input_dev);
77 if (ret) {
78 input_free_device(input_dev);
79 kfree(input);
80 return ret;
81 }
Lars-Peter Clausen68d641e2009-10-14 02:12:33 +040082 pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYR,
Balaji Rao1851b062009-01-09 01:50:58 +010083 pcf50633_input_irq, input);
Lars-Peter Clausen68d641e2009-10-14 02:12:33 +040084 pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYF,
Balaji Rao1851b062009-01-09 01:50:58 +010085 pcf50633_input_irq, input);
86
87 return 0;
88}
89
Bill Pembertone2619cf2012-11-23 21:50:47 -080090static int pcf50633_input_remove(struct platform_device *pdev)
Balaji Rao1851b062009-01-09 01:50:58 +010091{
92 struct pcf50633_input *input = platform_get_drvdata(pdev);
93
94 pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYR);
95 pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYF);
96
97 input_unregister_device(input->input_dev);
98 kfree(input);
99
100 return 0;
101}
102
103static struct platform_driver pcf50633_input_driver = {
104 .driver = {
105 .name = "pcf50633-input",
106 },
107 .probe = pcf50633_input_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800108 .remove = pcf50633_input_remove,
Balaji Rao1851b062009-01-09 01:50:58 +0100109};
JJ Ding840a7462011-11-29 11:08:40 -0800110module_platform_driver(pcf50633_input_driver);
Balaji Rao1851b062009-01-09 01:50:58 +0100111
112MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
113MODULE_DESCRIPTION("PCF50633 input driver");
114MODULE_LICENSE("GPL");
115MODULE_ALIAS("platform:pcf50633-input");