1 // SPDX-License-Identifier: GPL-2.0-only
3 * Input driver for PCAP events:
7 * Copyright (c) 2008,2009 Ilya Petrov <ilya.muromec@gmail.com>
10 #include <linux/module.h>
11 #include <linux/interrupt.h>
12 #include <linux/platform_device.h>
13 #include <linux/input.h>
14 #include <linux/mfd/ezx-pcap.h>
15 #include <linux/slab.h>
18 struct pcap_chip
*pcap
;
19 struct input_dev
*input
;
22 /* PCAP2 interrupts us on keypress */
23 static irqreturn_t
pcap_keys_handler(int irq
, void *_pcap_keys
)
25 struct pcap_keys
*pcap_keys
= _pcap_keys
;
26 int pirq
= irq_to_pcap(pcap_keys
->pcap
, irq
);
29 ezx_pcap_read(pcap_keys
->pcap
, PCAP_REG_PSTAT
, &pstat
);
34 input_report_key(pcap_keys
->input
, KEY_POWER
, !pstat
);
37 input_report_key(pcap_keys
->input
, KEY_HP
, !pstat
);
41 input_sync(pcap_keys
->input
);
46 static int pcap_keys_probe(struct platform_device
*pdev
)
49 struct pcap_keys
*pcap_keys
;
50 struct input_dev
*input_dev
;
52 pcap_keys
= kmalloc(sizeof(struct pcap_keys
), GFP_KERNEL
);
56 pcap_keys
->pcap
= dev_get_drvdata(pdev
->dev
.parent
);
58 input_dev
= input_allocate_device();
62 pcap_keys
->input
= input_dev
;
64 platform_set_drvdata(pdev
, pcap_keys
);
65 input_dev
->name
= pdev
->name
;
66 input_dev
->phys
= "pcap-keys/input0";
67 input_dev
->id
.bustype
= BUS_HOST
;
68 input_dev
->dev
.parent
= &pdev
->dev
;
70 __set_bit(EV_KEY
, input_dev
->evbit
);
71 __set_bit(KEY_POWER
, input_dev
->keybit
);
72 __set_bit(KEY_HP
, input_dev
->keybit
);
74 err
= input_register_device(input_dev
);
78 err
= request_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_ONOFF
),
79 pcap_keys_handler
, 0, "Power key", pcap_keys
);
83 err
= request_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_MIC
),
84 pcap_keys_handler
, 0, "Headphone button", pcap_keys
);
91 free_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_ONOFF
), pcap_keys
);
93 input_unregister_device(input_dev
);
96 input_free_device(input_dev
);
102 static int pcap_keys_remove(struct platform_device
*pdev
)
104 struct pcap_keys
*pcap_keys
= platform_get_drvdata(pdev
);
106 free_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_ONOFF
), pcap_keys
);
107 free_irq(pcap_to_irq(pcap_keys
->pcap
, PCAP_IRQ_MIC
), pcap_keys
);
109 input_unregister_device(pcap_keys
->input
);
115 static struct platform_driver pcap_keys_device_driver
= {
116 .probe
= pcap_keys_probe
,
117 .remove
= pcap_keys_remove
,
122 module_platform_driver(pcap_keys_device_driver
);
124 MODULE_DESCRIPTION("Motorola PCAP2 input events driver");
125 MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>");
126 MODULE_LICENSE("GPL");
127 MODULE_ALIAS("platform:pcap_keys");