From: Robert Jarzmik <robert.jarzmik@free.fr>
To: barebox@lists.infradead.org
Subject: [PATCH] ARM: mioa701: poweroff the board on long power press
Date: Sat, 18 Jan 2014 12:48:09 +0100 [thread overview]
Message-ID: <1390045689-23127-6-git-send-email-robert.jarzmik@free.fr> (raw)
In-Reply-To: <1390045689-23127-1-git-send-email-robert.jarzmik@free.fr>
When the board is on console, a way is added to manually power off the
board, on a long power key press (4s).
This enables to be able to poweroff the board whatever the state, and is
the only manual way (no mechanical possibility).
Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
arch/arm/boards/mioa701/Makefile | 2 +-
arch/arm/boards/mioa701/gpio0_poweroff.c | 81 ++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 1 deletion(-)
create mode 100644 arch/arm/boards/mioa701/gpio0_poweroff.c
diff --git a/arch/arm/boards/mioa701/Makefile b/arch/arm/boards/mioa701/Makefile
index 01c7a25..3072706 100644
--- a/arch/arm/boards/mioa701/Makefile
+++ b/arch/arm/boards/mioa701/Makefile
@@ -1,2 +1,2 @@
-obj-y += board.o
+obj-y += board.o gpio0_poweroff.o
lwl-y += lowlevel.o
diff --git a/arch/arm/boards/mioa701/gpio0_poweroff.c b/arch/arm/boards/mioa701/gpio0_poweroff.c
new file mode 100644
index 0000000..2054548
--- /dev/null
+++ b/arch/arm/boards/mioa701/gpio0_poweroff.c
@@ -0,0 +1,81 @@
+/*
+ * (C) 2011 Robert Jarzmik <robert.jarzmik@free.fr>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ */
+
+#include <clock.h>
+#include <common.h>
+#include <init.h>
+#include <gpio.h>
+#include <poller.h>
+
+#include "mioa701.h"
+
+#define POWEROFF_SECS (4 * SECOND)
+
+static void blink_led_keyboard(void)
+{
+ gpio_set_value(GPIO115_LED_nKeyboard, 0);
+ mdelay(400);
+ gpio_set_value(GPIO115_LED_nKeyboard, 1);
+ mdelay(400);
+}
+
+static void try_poweroff(void)
+{
+ int poweroff_released = 0;
+
+ blink_led_keyboard();
+ poweroff_released |= !gpio_get_value(GPIO0_KEY_POWER);
+ if (poweroff_released)
+ return;
+
+ gpio_set_value(GPIO115_LED_nKeyboard, 0);
+ mdelay(2000);
+ poweroff();
+}
+
+static void gpio0_poller_fn(struct poller_struct *poller)
+{
+ static uint64_t gpio0_start;
+ static bool gpio0_activated;
+
+ if (!gpio_get_value(GPIO0_KEY_POWER)) {
+ gpio0_activated = false;
+ return;
+ }
+
+ if (gpio0_activated) {
+ if (is_timeout_non_interruptible(gpio0_start, POWEROFF_SECS)) {
+ try_poweroff();
+ gpio0_activated = false;
+ }
+ } else {
+ gpio0_activated = true;
+ gpio0_start = get_time_ns();
+ }
+}
+
+static struct poller_struct gpio0_poller = {
+ .func = gpio0_poller_fn,
+};
+
+static int gpio0_poweroff_probe(void)
+{
+ return poller_register(&gpio0_poller);
+}
+
+device_initcall(gpio0_poweroff_probe);
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-01-18 11:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-18 11:48 [PATCH] ARM: mioa701: fix frequence speedup code Robert Jarzmik
2014-01-18 11:48 ` [PATCH] ARM: pxa: add reset source detection Robert Jarzmik
2014-01-18 11:48 ` [PATCH] ARM: pxa: add poweroff capability Robert Jarzmik
2014-01-18 11:48 ` [PATCH] ARM: mioa701 defconfig update Robert Jarzmik
2014-01-18 11:48 ` [PATCH] ARM: mioa701 change MTD layout Robert Jarzmik
2014-01-18 11:48 ` Robert Jarzmik [this message]
2014-01-20 15:38 ` [PATCH] ARM: mioa701: fix frequence speedup code Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1390045689-23127-6-git-send-email-robert.jarzmik@free.fr \
--to=robert.jarzmik@free.fr \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox