summaryrefslogtreecommitdiff
path: root/components/drivers/input/misc
diff options
context:
space:
mode:
Diffstat (limited to 'components/drivers/input/misc')
-rw-r--r--components/drivers/input/misc/Kconfig12
-rw-r--r--components/drivers/input/misc/SConscript18
-rw-r--r--components/drivers/input/misc/button-e3x0.c115
3 files changed, 145 insertions, 0 deletions
diff --git a/components/drivers/input/misc/Kconfig b/components/drivers/input/misc/Kconfig
new file mode 100644
index 0000000000..0928bc3f42
--- /dev/null
+++ b/components/drivers/input/misc/Kconfig
@@ -0,0 +1,12 @@
+menuconfig RT_INPUT_MISC
+ bool "Misc"
+ default n
+
+config RT_INPUT_MISC_BUTTON_E3X0
+ bool "NI Ettus Research USRP E3xx Button support"
+ depends on RT_INPUT_MISC
+ default n
+
+if RT_INPUT_MISC
+ osource "$(SOC_DM_INPUT_MISC_DIR)/Kconfig"
+endif
diff --git a/components/drivers/input/misc/SConscript b/components/drivers/input/misc/SConscript
new file mode 100644
index 0000000000..6b80c70aca
--- /dev/null
+++ b/components/drivers/input/misc/SConscript
@@ -0,0 +1,18 @@
+from building import *
+
+group = []
+
+if not GetDepend(['RT_INPUT_MISC']):
+ Return('group')
+
+cwd = GetCurrentDir()
+CPPPATH = [cwd + '/../../include']
+
+src = []
+
+if GetDepend(['RT_INPUT_MISC_BUTTON_E3X0']):
+ src += ['button-e3x0.c']
+
+group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/drivers/input/misc/button-e3x0.c b/components/drivers/input/misc/button-e3x0.c
new file mode 100644
index 0000000000..2c09a54016
--- /dev/null
+++ b/components/drivers/input/misc/button-e3x0.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-3-08 GuEe-GUI the first version
+ */
+
+#include <rthw.h>
+#include <rtthread.h>
+#include <rtdevice.h>
+
+struct e3x0_button
+{
+ struct rt_input_device parent;
+
+ int press_irq, release_irq;
+};
+
+static void e3x0_button_press_isr(int irqno, void *param)
+{
+ struct e3x0_button *btn = param;
+
+ rt_input_report_key(&btn->parent, KEY_POWER, 1);
+ rt_input_sync(&btn->parent);
+}
+
+static void e3x0_button_release_isr(int irqno, void *param)
+{
+ struct e3x0_button *btn = param;
+
+ rt_input_report_key(&btn->parent, KEY_POWER, 0);
+ rt_input_sync(&btn->parent);
+}
+
+static rt_err_t e3x0_button_probe(struct rt_platform_device *pdev)
+{
+ rt_err_t err;
+ struct rt_device *dev = &pdev->parent;
+ struct e3x0_button *btn = rt_calloc(1, sizeof(*btn));
+
+ if (!btn)
+ {
+ return -RT_ENOMEM;
+ }
+
+ if ((btn->press_irq = rt_dm_dev_get_irq_by_name(dev, "press")) < 0)
+ {
+ err = btn->press_irq;
+ goto _fail;
+ }
+
+ if ((btn->release_irq = rt_dm_dev_get_irq_by_name(dev, "release")) < 0)
+ {
+ err = btn->release_irq;
+ goto _fail;
+ }
+
+ rt_input_set_capability(&btn->parent, EV_KEY, KEY_POWER);
+
+ if ((err = rt_input_device_register(&btn->parent)))
+ {
+ goto _fail;
+ }
+
+ dev->user_data = btn;
+
+ rt_hw_interrupt_install(btn->press_irq, e3x0_button_press_isr, btn, "button-e3x0-press");
+ rt_hw_interrupt_umask(btn->press_irq);
+
+ rt_hw_interrupt_install(btn->release_irq, e3x0_button_release_isr, btn, "button-e3x0-release");
+ rt_hw_interrupt_umask(btn->release_irq);
+
+ return RT_EOK;
+
+_fail:
+ rt_free(btn);
+
+ return err;
+}
+
+static rt_err_t e3x0_button_remove(struct rt_platform_device *pdev)
+{
+ struct e3x0_button *btn = pdev->parent.user_data;
+
+ rt_hw_interrupt_mask(btn->press_irq);
+ rt_pic_detach_irq(btn->press_irq, btn);
+
+ rt_hw_interrupt_mask(btn->release_irq);
+ rt_pic_detach_irq(btn->release_irq, btn);
+
+ rt_input_device_unregister(&btn->parent);
+
+ rt_free(btn);
+
+ return RT_EOK;
+}
+
+static const struct rt_ofw_node_id e3x0_button_ofw_ids[] =
+{
+ { .compatible = "ettus,e3x0-button" },
+ { /* sentinel */ }
+};
+
+static struct rt_platform_driver e3x0_button_driver =
+{
+ .name = "e3x0-button",
+ .ids = e3x0_button_ofw_ids,
+
+ .probe = e3x0_button_probe,
+ .remove = e3x0_button_remove,
+};
+RT_PLATFORM_DRIVER_EXPORT(e3x0_button_driver);