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.
This commit is contained in:
Andreas Eversberg 2012-01-25 12:19:23 +01:00 committed by Harald Welte
parent be142a0c2a
commit a6c98a79b2
2 changed files with 17 additions and 11 deletions

View File

@ -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);
}

View File

@ -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;