[PATCH 6/8] minnowboard-keys: Bind MinnowBoard buttons to arrow keys
From: Darren Hart
Date: Tue Jun 25 2013 - 21:54:52 EST
Configure the four buttons tied to the E6XX GPIO lines on the
MinnowBoard as keys using the gpio-keys-polled platform driver. From
left to right, bind them to LEFT, DOWN, UP, RIGHT, similar to the VI
directional keys.
This is separate from the minnowboard driver to provide users with the
flexibility to write kernel drivers for their own devices using these GPIO
lines.
Signed-off-by: Darren Hart <dvhart@xxxxxxxxxxxxxxx>
Cc: Matthew Garrett <matthew.garrett@xxxxxxxxxx>
Cc: Grant Likely <grant.likely@xxxxxxxxxx>
Cc: Linus Walleij <linus.walleij@xxxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Peter Waskiewicz <peter.p.waskiewicz.jr@xxxxxxxxx>
Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Cc: platform-driver-x86@xxxxxxxxxxxxxxx
---
drivers/platform/x86/Kconfig | 14 +++++
drivers/platform/x86/Makefile | 1 +
drivers/platform/x86/minnowboard-keys.c | 108 ++++++++++++++++++++++++++++++++
3 files changed, 123 insertions(+)
create mode 100644 drivers/platform/x86/minnowboard-keys.c
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index c8755cb..b9ff98c 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -50,6 +50,20 @@ config MINNOWBOARD_GPIO
If you have a MinnowBoard, and want to experiment with the GPIO,
say Y or M here.
+config MINNOWBOARD_KEYS
+ tristate "MinnowBoard GPIO Keys"
+ depends on MINNOWBOARD
+ depends on KEYBOARD_GPIO_POLLED
+ default n
+ ---help---
+ Configure the four buttons tied to the E6XX GPIO lines on the
+ MinnowBoard as keys using the gpio-keys-polled platform driver. From
+ left to right, bind them to LEFT, DOWN, UP, RIGHT, similar to the VI
+ directional keys.
+
+ If you have a MinnowBoard and want to use the buttons as arrow keys,
+ say Y or M here.
+
endif # MINNOWBOARD
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 4dac9f0..2f55903 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -4,6 +4,7 @@
#
obj-$(CONFIG_MINNOWBOARD) += minnowboard.o
obj-$(CONFIG_MINNOWBOARD_GPIO) += minnowboard-gpio.o
+obj-$(CONFIG_MINNOWBOARD_KEYS) += minnowboard-keys.o
obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o
obj-$(CONFIG_ASUS_WMI) += asus-wmi.o
obj-$(CONFIG_ASUS_NB_WMI) += asus-nb-wmi.o
diff --git a/drivers/platform/x86/minnowboard-keys.c b/drivers/platform/x86/minnowboard-keys.c
new file mode 100644
index 0000000..de96df1
--- /dev/null
+++ b/drivers/platform/x86/minnowboard-keys.c
@@ -0,0 +1,108 @@
+/*
+ * MinnowBoard Linux platform driver
+ * Copyright (c) 2013, Intel Corporation.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Author: Darren Hart <dvhart@xxxxxxxxxxxxxxx>
+ */
+
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <linux/minnowboard.h>
+#include "minnowboard-gpio.h"
+
+/* VI-style direction keys seem like as good as anything */
+#define GPIO_BTN0_KEY KEY_LEFT
+#define GPIO_BTN1_KEY KEY_DOWN
+#define GPIO_BTN2_KEY KEY_UP
+#define GPIO_BTN3_KEY KEY_RIGHT
+
+/* Timing in milliseconds */
+#define GPIO_DEBOUNCE 1
+#define BUTTON_POLL_INTERVAL 300
+
+/* gpio-keys platform device structures */
+static struct gpio_keys_button minnow_buttons[] = {
+ { .code = GPIO_BTN0_KEY, .gpio = GPIO_BTN0, .active_low = 1,
+ .desc = "minnow_btn0", .type = EV_KEY, .wakeup = 0,
+ .debounce_interval = GPIO_DEBOUNCE, .can_disable = true },
+ { .code = GPIO_BTN1_KEY, .gpio = GPIO_BTN1, .active_low = 1,
+ .desc = "minnow_btn1", .type = EV_KEY, .wakeup = 0,
+ .debounce_interval = GPIO_DEBOUNCE, .can_disable = true },
+ { .code = GPIO_BTN2_KEY, .gpio = GPIO_BTN2, .active_low = 1,
+ .desc = "minnow_btn2", .type = EV_KEY, .wakeup = 0,
+ .debounce_interval = GPIO_DEBOUNCE, .can_disable = true },
+ { .code = GPIO_BTN3_KEY, .gpio = GPIO_BTN3, .active_low = 1,
+ .desc = "minnow_btn3", .type = EV_KEY, .wakeup = 0,
+ .debounce_interval = GPIO_DEBOUNCE, .can_disable = true },
+};
+
+static const struct gpio_keys_platform_data minnow_buttons_platform_data = {
+ .buttons = minnow_buttons,
+ .nbuttons = ARRAY_SIZE(minnow_buttons),
+ .poll_interval = BUTTON_POLL_INTERVAL,
+ .rep = 1,
+ .enable = NULL,
+ .disable = NULL,
+ .name = "minnow_buttons",
+};
+
+static struct platform_device minnow_gpio_buttons = {
+ .name = "gpio-keys-polled",
+ .id = -1,
+ .dev = {
+ .platform_data = (void *) &minnow_buttons_platform_data,
+ },
+};
+
+static int __init minnow_keys_module_init(void)
+{
+ int err;
+
+ err = -ENODEV;
+ if (!minnow_detect())
+ goto out;
+
+#ifdef MODULE
+#ifdef CONFIG_MINNOWBOARD_MODULE
+ if (request_module("minnowboard"))
+ goto out;
+#endif
+#endif
+
+ /* Export GPIO buttons to sysfs */
+ err = platform_device_register(&minnow_gpio_buttons);
+ if (err) {
+ pr_err("Failed to register gpio-keys-polled platform device\n");
+ goto out;
+ }
+
+ out:
+ return err;
+}
+
+static void __exit minnow_keys_module_exit(void)
+{
+ platform_device_unregister(&minnow_gpio_buttons);
+}
+
+module_init(minnow_keys_module_init);
+module_exit(minnow_keys_module_exit);
+
+MODULE_LICENSE("GPL");
--
1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/