treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / input / misc / e3x0-button.c
blobe2fde6e1553fb57b70bfb109155810e86fcc92b3
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2014, National Instruments Corp. All rights reserved.
5 * Driver for NI Ettus Research USRP E3x0 Button Driver
6 */
8 #include <linux/device.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/input.h>
13 #include <linux/interrupt.h>
14 #include <linux/of.h>
15 #include <linux/slab.h>
17 static irqreturn_t e3x0_button_release_handler(int irq, void *data)
19 struct input_dev *idev = data;
21 input_report_key(idev, KEY_POWER, 0);
22 input_sync(idev);
24 return IRQ_HANDLED;
27 static irqreturn_t e3x0_button_press_handler(int irq, void *data)
29 struct input_dev *idev = data;
31 input_report_key(idev, KEY_POWER, 1);
32 pm_wakeup_event(idev->dev.parent, 0);
33 input_sync(idev);
35 return IRQ_HANDLED;
38 static int __maybe_unused e3x0_button_suspend(struct device *dev)
40 struct platform_device *pdev = to_platform_device(dev);
42 if (device_may_wakeup(dev))
43 enable_irq_wake(platform_get_irq_byname(pdev, "press"));
45 return 0;
48 static int __maybe_unused e3x0_button_resume(struct device *dev)
50 struct platform_device *pdev = to_platform_device(dev);
52 if (device_may_wakeup(dev))
53 disable_irq_wake(platform_get_irq_byname(pdev, "press"));
55 return 0;
58 static SIMPLE_DEV_PM_OPS(e3x0_button_pm_ops,
59 e3x0_button_suspend, e3x0_button_resume);
61 static int e3x0_button_probe(struct platform_device *pdev)
63 struct input_dev *input;
64 int irq_press, irq_release;
65 int error;
67 irq_press = platform_get_irq_byname(pdev, "press");
68 if (irq_press < 0)
69 return irq_press;
71 irq_release = platform_get_irq_byname(pdev, "release");
72 if (irq_release < 0)
73 return irq_release;
75 input = devm_input_allocate_device(&pdev->dev);
76 if (!input)
77 return -ENOMEM;
79 input->name = "NI Ettus Research USRP E3x0 Button Driver";
80 input->phys = "e3x0_button/input0";
81 input->dev.parent = &pdev->dev;
83 input_set_capability(input, EV_KEY, KEY_POWER);
85 error = devm_request_irq(&pdev->dev, irq_press,
86 e3x0_button_press_handler, 0,
87 "e3x0-button", input);
88 if (error) {
89 dev_err(&pdev->dev, "Failed to request 'press' IRQ#%d: %d\n",
90 irq_press, error);
91 return error;
94 error = devm_request_irq(&pdev->dev, irq_release,
95 e3x0_button_release_handler, 0,
96 "e3x0-button", input);
97 if (error) {
98 dev_err(&pdev->dev, "Failed to request 'release' IRQ#%d: %d\n",
99 irq_release, error);
100 return error;
103 error = input_register_device(input);
104 if (error) {
105 dev_err(&pdev->dev, "Can't register input device: %d\n", error);
106 return error;
109 device_init_wakeup(&pdev->dev, 1);
110 return 0;
113 #ifdef CONFIG_OF
114 static const struct of_device_id e3x0_button_match[] = {
115 { .compatible = "ettus,e3x0-button", },
118 MODULE_DEVICE_TABLE(of, e3x0_button_match);
119 #endif
121 static struct platform_driver e3x0_button_driver = {
122 .driver = {
123 .name = "e3x0-button",
124 .of_match_table = of_match_ptr(e3x0_button_match),
125 .pm = &e3x0_button_pm_ops,
127 .probe = e3x0_button_probe,
130 module_platform_driver(e3x0_button_driver);
132 MODULE_LICENSE("GPL v2");
133 MODULE_AUTHOR("Moritz Fischer <moritz.fischer@ettus.com>");
134 MODULE_DESCRIPTION("NI Ettus Research USRP E3x0 Button driver");
135 MODULE_ALIAS("platform:e3x0-button");