power: charge animation: support long key event without release

Change-Id: I9d7cd439376f2f4ff89ea6bfe3baedbeaa4deeb9
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
This commit is contained in:
Joseph Chen 2019-03-05 09:57:47 +08:00 committed by Jianhong Chen
parent 6787bf9f0a
commit 2e68f6b5f9
1 changed files with 30 additions and 7 deletions

View File

@ -35,7 +35,7 @@ DECLARE_GLOBAL_DATA_PTR;
#define IMAGE_RESET_IDX -1
#define IMAGE_SOC_100_IDX(n) ((n) - 2)
#define IMAGE_LOWPOWER_IDX(n) ((n) - 1)
#define SYSTEM_SUSPEND_DELAY_MS 5000
#define FUEL_GAUGE_POLL_MS 1000
#define LED_CHARGING_NAME "battery_charging"
@ -59,7 +59,8 @@ struct charge_animation_priv {
int image_num;
int auto_wakeup_key_state;
ulong auto_screen_off_timeout;
ulong auto_screen_off_timeout; /* ms */
ulong suspend_delay_timeout; /* ms */
};
/*
@ -170,7 +171,7 @@ static int check_key_press(struct udevice *dev)
* period timer is useless.
*/
#ifndef CONFIG_IRQ
static int system_suspend_enter(struct charge_animation_pdata *pdata)
static int system_suspend_enter(struct udevice *dev)
{
return 0;
}
@ -179,8 +180,23 @@ static void autowakeup_timer_init(struct udevice *dev, uint32_t seconds) {}
static void autowakeup_timer_uninit(void) {}
#else
static int system_suspend_enter(struct charge_animation_pdata *pdata)
static int system_suspend_enter(struct udevice *dev)
{
struct charge_animation_pdata *pdata = dev_get_platdata(dev);
struct charge_animation_priv *priv = dev_get_priv(dev);
/*
* When cpu is in wfi and we try to give a long key press event without
* key release, cpu would wakeup and enter wfi again immediately. So
* here is the problem: cpu can only wakeup when long key released.
*
* Actually, we want cpu can detect long key event without key release,
* so we give a suspend delay timeout for cpu to detect this.
*/
if (priv->suspend_delay_timeout &&
get_timer(priv->suspend_delay_timeout) <= SYSTEM_SUSPEND_DELAY_MS)
return 0;
if (pdata->system_suspend && IS_ENABLED(CONFIG_ARM_SMCCC)) {
printf("\nSystem suspend: ");
putc('0');
@ -209,8 +225,11 @@ static int system_suspend_enter(struct charge_animation_pdata *pdata)
} else {
printf("\nWfi\n");
wfi();
putc('1');
}
priv->suspend_delay_timeout = get_timer(0);
/*
* We must wait for key release event finish, otherwise
* we may read key state too early.
@ -362,7 +381,7 @@ static int charge_extrem_low_power(struct udevice *dev)
pdata->low_power_voltage, voltage);
/* System suspend */
system_suspend_enter(pdata);
system_suspend_enter(dev);
/* Update voltage */
voltage = fuel_gauge_get_voltage(fg);
@ -629,8 +648,7 @@ show_images:
priv->auto_screen_off_timeout = get_timer(0);
} else {
priv->auto_screen_off_timeout = 0;
system_suspend_enter(pdata);
system_suspend_enter(dev);
}
mdelay(5);
@ -673,14 +691,19 @@ show_images:
if (screen_on) {
charge_show_bmp(NULL); /* Turn off screen */
screen_on = false;
priv->suspend_delay_timeout = get_timer(0);
} else {
screen_on = true;
}
printf("screen %s\n", screen_on ? "on" : "off");
} else if (key_state == KEY_PRESS_LONG_DOWN) {
/* Set screen_on=true anyway when key long pressed */
if (!screen_on)
screen_on = true;
printf("screen %s\n", screen_on ? "on" : "off");
/* Is able to boot now ? */
if (soc < pdata->exit_charge_level) {
printf("soc=%d%%, threshold soc=%d%%\n",