summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2012-01-25 12:19:23 +0100
committerHarald Welte <laforge@gnumonks.org>2012-01-28 13:15:48 +0100
commita6c98a79b29e964268ab2debd7ebd7fd2daf709d (patch)
tree70bded30105f058e8d9ca75d4fc29d11ee6e2511
parentbe142a0c2a7b18682775126a19203ab5411688a4 (diff)
Hold function for power button to turn off the phone
In order to allow applications to use the power button, the keypad handler will wait half a second if the key is pressed and hold, until the power is turned off. This way the application does not need to handle it. The power off function will then wait until the button is released, so the phone will not start again while the button is still pressed.
-rw-r--r--src/target/firmware/abb/twl3025.c11
-rw-r--r--src/target/firmware/calypso/keypad.c17
2 files changed, 17 insertions, 11 deletions
diff --git a/src/target/firmware/abb/twl3025.c b/src/target/firmware/abb/twl3025.c
index 564c34ba..2e06199c 100644
--- a/src/target/firmware/abb/twl3025.c
+++ b/src/target/firmware/abb/twl3025.c
@@ -105,13 +105,6 @@ static void twl3025_irq(enum irq_nr nr)
case IRQ_EXTERNAL: // charger in/out, pwrbtn, adc done
src = twl3025_reg_read(ITSTATREG);
// printd("itstatreg 0x%02x\n", src);
- if (src & 0x04) {
- /* poll PWON status and power off the phone when the
- * powerbutton has been released (otherwise it will
- * poweron immediately again) */
- while (!(twl3025_reg_read(VRPCSTS) & 0x10)) { };
- twl3025_power_off();
- }
if (src & 0x08)
handle_charger();
if (src & 0x20)
@@ -193,6 +186,10 @@ static void twl3025_wait_ibic_access(void)
void twl3025_power_off(void)
{
+ /* poll PWON status and power off the phone when the
+ * powerbutton has been released (otherwise it will
+ * poweron immediately again) */
+ while (!(twl3025_reg_read(VRPCSTS) & 0x10)) { };
twl3025_reg_write(VRPCDEV, 0x01);
}
diff --git a/src/target/firmware/calypso/keypad.c b/src/target/firmware/calypso/keypad.c
index fd4e0ff2..f2dea9df 100644
--- a/src/target/firmware/calypso/keypad.c
+++ b/src/target/firmware/calypso/keypad.c
@@ -31,6 +31,7 @@
#include <calypso/irq.h>
#include <abb/twl3025.h>
+#include <comm/timer.h>
#define KBR_LATCH_REG 0xfffe480a
@@ -44,16 +45,13 @@ void emit_key(uint8_t key, uint8_t state)
{
printf("key=%u %s\n", key, state == PRESSED ? "pressed" : "released");
- if (state == RELEASED)
- if (key == KEY_POWER)
- twl3025_power_off();
-
if(key_handler) {
key_handler(key, state);
}
}
volatile uint32_t lastbuttons = 0;
+unsigned long power_hold = 0;
#define BTN_TO_KEY(name) \
((diff & BTN_##name) == BTN_##name) \
@@ -67,6 +65,17 @@ void dispatch_buttons(uint32_t buttons)
{
uint8_t state;
+ if ((buttons & BTN_POWER)) {
+ /* hold button 500ms to shut down */
+ if ((lastbuttons & BTN_POWER)) {
+ unsigned long elapsed = jiffies - power_hold;
+ if (elapsed > 50)
+ twl3025_power_off();
+ power_hold++;
+ } else
+ power_hold = jiffies;
+ }
+
if (buttons == lastbuttons)
return;