1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014, National Instruments Corp. All rights reserved.
5 * Driver for NI Ettus Research USRP E3x0 Button Driver
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>
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);
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);
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"));
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"));
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
;
67 irq_press
= platform_get_irq_byname(pdev
, "press");
71 irq_release
= platform_get_irq_byname(pdev
, "release");
75 input
= devm_input_allocate_device(&pdev
->dev
);
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
);
89 dev_err(&pdev
->dev
, "Failed to request 'press' IRQ#%d: %d\n",
94 error
= devm_request_irq(&pdev
->dev
, irq_release
,
95 e3x0_button_release_handler
, 0,
96 "e3x0-button", input
);
98 dev_err(&pdev
->dev
, "Failed to request 'release' IRQ#%d: %d\n",
103 error
= input_register_device(input
);
105 dev_err(&pdev
->dev
, "Can't register input device: %d\n", error
);
109 device_init_wakeup(&pdev
->dev
, 1);
114 static const struct of_device_id e3x0_button_match
[] = {
115 { .compatible
= "ettus,e3x0-button", },
118 MODULE_DEVICE_TABLE(of
, e3x0_button_match
);
121 static struct platform_driver e3x0_button_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");