From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from smtpbguseast2.qq.com ([54.204.34.130]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i3IZs-000770-65 for barebox@lists.infradead.org; Thu, 29 Aug 2019 11:26:58 +0000 Date: Thu, 29 Aug 2019 19:26:26 +0800 From: duhuanpeng Message-ID: <20190829112626.GA10723@router.tkernel.org>+62E1D69A51EA1B4C References: <20190829052808.25624-1-a.fatoum@pengutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190829052808.25624-1-a.fatoum@pengutronix.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: Re: [PATCH] input: add handler for reset and power key input events To: Ahmad Fatoum Cc: barebox@lists.infradead.org, Oleksij Rempel Hello, I merged this patch to my barebox. and test on my own board. 1. Abort barebox booting and enter the console. the board reboots immediately when I press the button without release. here is my .dts about this button: net { label = "board:LED1:system"; gpios = <&gpio 1 GPIO_ACTIVE_LOW>; default-state = "off"; barebox,default-trigger = "net"; }; 2. Panic. type 'go 888' make barebox panic. now I really need a 'reset' key. I press and releaes the key, and try to hold this key several seconds. no reaction. Is the 'reset' key designed for reset the board when something goes wrong? Regards, duhuanpeng On Thu, Aug 29, 2019 at 07:28:08AM +0200, Ahmad Fatoum wrote: > Kernel device trees may indicate linux,code = KEY_POWER or KEY_RESTART, > mostly for gpio-keys. Make barebox able to act on them by registering an > appropriate input notifier. > > Suggested-by: Oleksij Rempel > Signed-off-by: Ahmad Fatoum > --- > drivers/input/Kconfig | 6 ++++++ > drivers/input/Makefile | 1 + > drivers/input/specialkeys.c | 36 ++++++++++++++++++++++++++++++++++++ > 3 files changed, 43 insertions(+) > create mode 100644 drivers/input/specialkeys.c > > diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig > index 1f89ae3892dc..be061683fb0a 100644 > --- a/drivers/input/Kconfig > +++ b/drivers/input/Kconfig > @@ -64,4 +64,10 @@ config KEYBOARD_USB > help > This driver implements support for usb keyboard. > > +config INPUT_SPECIALKEYS > + bool "Special keys handler" > + select INPUT > + help > + Say Y here to handle key events like KEY_RESTART and KEY_POWER. > + > endmenu > diff --git a/drivers/input/Makefile b/drivers/input/Makefile > index e694a98d1087..36a4204d5308 100644 > --- a/drivers/input/Makefile > +++ b/drivers/input/Makefile > @@ -5,3 +5,4 @@ obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o > obj-$(CONFIG_KEYBOARD_TWL6030) += twl6030_pwrbtn.o > obj-$(CONFIG_KEYBOARD_IMX_KEYPAD) += imx_keypad.o > obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o > +obj-$(CONFIG_INPUT_SPECIALKEYS) += specialkeys.o > diff --git a/drivers/input/specialkeys.c b/drivers/input/specialkeys.c > new file mode 100644 > index 000000000000..51ee43218192 > --- /dev/null > +++ b/drivers/input/specialkeys.c > @@ -0,0 +1,36 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// Copyright (c) 2019 Ahmad Fatoum, Pengutronix > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +static void input_specialkeys_notify(struct input_notifier *in, > + struct input_event *ev) > +{ > + switch (ev->code) { > + case KEY_RESTART: > + pr_debug("code: %d. Triggering reset.\n", ev->code); > + restart_machine(); > + break; > + > + case KEY_POWER: > + pr_debug("code: %d. Triggering poweroff.\n", ev->code); > + poweroff_machine(); > + break; > + } > + > + pr_debug("ignoring code: %d\n", ev->code); > +} > + > +static struct input_notifier notifier; > + > +static int input_specialkeys_init(void) > +{ > + notifier.notify = input_specialkeys_notify; > + return input_register_notfier(¬ifier); > +} > +late_initcall(input_specialkeys_init); > -- > 2.23.0 > > > _______________________________________________ > barebox mailing list > barebox@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/barebox > _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox