treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / input / misc / pcap_keys.c
blobb5a53636d7e2e9aafe112aa78152aec47776da47
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Input driver for PCAP events:
4 * * Power key
5 * * Headphone button
7 * Copyright (c) 2008,2009 Ilya Petrov <ilya.muromec@gmail.com>
8 */
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>
17 struct pcap_keys {
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);
27 u32 pstat;
29 ezx_pcap_read(pcap_keys->pcap, PCAP_REG_PSTAT, &pstat);
30 pstat &= 1 << pirq;
32 switch (pirq) {
33 case PCAP_IRQ_ONOFF:
34 input_report_key(pcap_keys->input, KEY_POWER, !pstat);
35 break;
36 case PCAP_IRQ_MIC:
37 input_report_key(pcap_keys->input, KEY_HP, !pstat);
38 break;
41 input_sync(pcap_keys->input);
43 return IRQ_HANDLED;
46 static int pcap_keys_probe(struct platform_device *pdev)
48 int err = -ENOMEM;
49 struct pcap_keys *pcap_keys;
50 struct input_dev *input_dev;
52 pcap_keys = kmalloc(sizeof(struct pcap_keys), GFP_KERNEL);
53 if (!pcap_keys)
54 return err;
56 pcap_keys->pcap = dev_get_drvdata(pdev->dev.parent);
58 input_dev = input_allocate_device();
59 if (!input_dev)
60 goto fail;
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);
75 if (err)
76 goto fail_allocate;
78 err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF),
79 pcap_keys_handler, 0, "Power key", pcap_keys);
80 if (err)
81 goto fail_register;
83 err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC),
84 pcap_keys_handler, 0, "Headphone button", pcap_keys);
85 if (err)
86 goto fail_pwrkey;
88 return 0;
90 fail_pwrkey:
91 free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), pcap_keys);
92 fail_register:
93 input_unregister_device(input_dev);
94 goto fail;
95 fail_allocate:
96 input_free_device(input_dev);
97 fail:
98 kfree(pcap_keys);
99 return err;
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);
110 kfree(pcap_keys);
112 return 0;
115 static struct platform_driver pcap_keys_device_driver = {
116 .probe = pcap_keys_probe,
117 .remove = pcap_keys_remove,
118 .driver = {
119 .name = "pcap-keys",
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");