rcu: Maintain special bits at bottom of ->dynticks counter
[linux/fpc-iii.git] / drivers / input / misc / e3x0-button.c
blobe956cf1d273fe6dd65775b6b18356c73e4531a49
1 /*
2 * Copyright (c) 2014, National Instruments Corp. All rights reserved.
4 * Driver for NI Ettus Research USRP E3x0 Button Driver
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/device.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/input.h>
21 #include <linux/interrupt.h>
22 #include <linux/of.h>
23 #include <linux/slab.h>
25 static irqreturn_t e3x0_button_release_handler(int irq, void *data)
27 struct input_dev *idev = data;
29 input_report_key(idev, KEY_POWER, 0);
30 input_sync(idev);
32 return IRQ_HANDLED;
35 static irqreturn_t e3x0_button_press_handler(int irq, void *data)
37 struct input_dev *idev = data;
39 input_report_key(idev, KEY_POWER, 1);
40 pm_wakeup_event(idev->dev.parent, 0);
41 input_sync(idev);
43 return IRQ_HANDLED;
46 static int __maybe_unused e3x0_button_suspend(struct device *dev)
48 struct platform_device *pdev = to_platform_device(dev);
50 if (device_may_wakeup(dev))
51 enable_irq_wake(platform_get_irq_byname(pdev, "press"));
53 return 0;
56 static int __maybe_unused e3x0_button_resume(struct device *dev)
58 struct platform_device *pdev = to_platform_device(dev);
60 if (device_may_wakeup(dev))
61 disable_irq_wake(platform_get_irq_byname(pdev, "press"));
63 return 0;
66 static SIMPLE_DEV_PM_OPS(e3x0_button_pm_ops,
67 e3x0_button_suspend, e3x0_button_resume);
69 static int e3x0_button_probe(struct platform_device *pdev)
71 struct input_dev *input;
72 int irq_press, irq_release;
73 int error;
75 irq_press = platform_get_irq_byname(pdev, "press");
76 if (irq_press < 0) {
77 dev_err(&pdev->dev, "No IRQ for 'press', error=%d\n",
78 irq_press);
79 return irq_press;
82 irq_release = platform_get_irq_byname(pdev, "release");
83 if (irq_release < 0) {
84 dev_err(&pdev->dev, "No IRQ for 'release', error=%d\n",
85 irq_release);
86 return irq_release;
89 input = devm_input_allocate_device(&pdev->dev);
90 if (!input)
91 return -ENOMEM;
93 input->name = "NI Ettus Research USRP E3x0 Button Driver";
94 input->phys = "e3x0_button/input0";
95 input->dev.parent = &pdev->dev;
97 input_set_capability(input, EV_KEY, KEY_POWER);
99 error = devm_request_irq(&pdev->dev, irq_press,
100 e3x0_button_press_handler, 0,
101 "e3x0-button", input);
102 if (error) {
103 dev_err(&pdev->dev, "Failed to request 'press' IRQ#%d: %d\n",
104 irq_press, error);
105 return error;
108 error = devm_request_irq(&pdev->dev, irq_release,
109 e3x0_button_release_handler, 0,
110 "e3x0-button", input);
111 if (error) {
112 dev_err(&pdev->dev, "Failed to request 'release' IRQ#%d: %d\n",
113 irq_release, error);
114 return error;
117 error = input_register_device(input);
118 if (error) {
119 dev_err(&pdev->dev, "Can't register input device: %d\n", error);
120 return error;
123 device_init_wakeup(&pdev->dev, 1);
124 return 0;
127 #ifdef CONFIG_OF
128 static const struct of_device_id e3x0_button_match[] = {
129 { .compatible = "ettus,e3x0-button", },
132 MODULE_DEVICE_TABLE(of, e3x0_button_match);
133 #endif
135 static struct platform_driver e3x0_button_driver = {
136 .driver = {
137 .name = "e3x0-button",
138 .of_match_table = of_match_ptr(e3x0_button_match),
139 .pm = &e3x0_button_pm_ops,
141 .probe = e3x0_button_probe,
144 module_platform_driver(e3x0_button_driver);
146 MODULE_LICENSE("GPL v2");
147 MODULE_AUTHOR("Moritz Fischer <moritz.fischer@ettus.com>");
148 MODULE_DESCRIPTION("NI Ettus Research USRP E3x0 Button driver");
149 MODULE_ALIAS("platform:e3x0-button");