power: charge animation: clean up code
Change-Id: I0d76d7ad28ef3683bbc78f36d4a0f00d5517e2fa Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
This commit is contained in:
parent
1b3009debe
commit
ebe3d004b5
|
|
@ -32,7 +32,10 @@
|
||||||
|
|
||||||
DECLARE_GLOBAL_DATA_PTR;
|
DECLARE_GLOBAL_DATA_PTR;
|
||||||
|
|
||||||
#define IMAGE_SHOW_RESET -1
|
#define IMAGE_RESET_IDX -1
|
||||||
|
#define IMAGE_SOC_100_IDX(n) ((n) - 2)
|
||||||
|
#define IMAGE_LOWPOWER_IDX(n) ((n) - 1)
|
||||||
|
|
||||||
#define FUEL_GAUGE_POLL_MS 1000
|
#define FUEL_GAUGE_POLL_MS 1000
|
||||||
|
|
||||||
#define LED_CHARGING_NAME "battery_charging"
|
#define LED_CHARGING_NAME "battery_charging"
|
||||||
|
|
@ -143,7 +146,7 @@ static int check_key_press(struct udevice *dev)
|
||||||
|
|
||||||
/* Fixup key state for following cases */
|
/* Fixup key state for following cases */
|
||||||
if (pdata->auto_wakeup_interval) {
|
if (pdata->auto_wakeup_interval) {
|
||||||
if (pdata->auto_wakeup_screen_invert) {
|
if (pdata->auto_wakeup_screen_invert) {
|
||||||
if (priv->auto_wakeup_key_state == KEY_PRESS_DOWN) {
|
if (priv->auto_wakeup_key_state == KEY_PRESS_DOWN) {
|
||||||
/* Value is updated in timer interrupt */
|
/* Value is updated in timer interrupt */
|
||||||
priv->auto_wakeup_key_state = KEY_PRESS_NONE;
|
priv->auto_wakeup_key_state = KEY_PRESS_NONE;
|
||||||
|
|
@ -216,6 +219,7 @@ static int system_suspend_enter(struct charge_animation_pdata *pdata)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timer_irq_handler(int irq, void *data)
|
static void timer_irq_handler(int irq, void *data)
|
||||||
{
|
{
|
||||||
struct udevice *dev = data;
|
struct udevice *dev = data;
|
||||||
|
|
@ -387,7 +391,7 @@ static int charge_animation_show(struct udevice *dev)
|
||||||
ulong show_start = 0, charge_start = 0, debug_start = 0;
|
ulong show_start = 0, charge_start = 0, debug_start = 0;
|
||||||
ulong delta;
|
ulong delta;
|
||||||
ulong ms = 0, sec = 0;
|
ulong ms = 0, sec = 0;
|
||||||
int start_idx = 0, show_idx = -1, old_show_idx = IMAGE_SHOW_RESET;
|
int start_idx = 0, show_idx = -1, old_show_idx = IMAGE_RESET_IDX;
|
||||||
int soc, voltage, current, key_state;
|
int soc, voltage, current, key_state;
|
||||||
int i, charging = 1, ret;
|
int i, charging = 1, ret;
|
||||||
int boot_mode;
|
int boot_mode;
|
||||||
|
|
@ -496,8 +500,8 @@ static int charge_animation_show(struct udevice *dev)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Most fuel gauge is I2C interface, it shouldn't be interrupted
|
* Most fuel gauge is I2C interface, it shouldn't be interrupted
|
||||||
* during tansfer. The power key event depends on interrupt, so
|
* during transfer. The power key event depends on interrupt, so
|
||||||
* so we should disable local irq when update fuel gauge.
|
* we should disable local irq when update fuel gauge.
|
||||||
*/
|
*/
|
||||||
local_irq_disable();
|
local_irq_disable();
|
||||||
|
|
||||||
|
|
@ -537,8 +541,8 @@ static int charge_animation_show(struct udevice *dev)
|
||||||
printf("get current failed: %d\n", current);
|
printf("get current failed: %d\n", current);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
first_poll_fg = 0;
|
|
||||||
|
|
||||||
|
first_poll_fg = 0;
|
||||||
local_irq_enable();
|
local_irq_enable();
|
||||||
|
|
||||||
show_images:
|
show_images:
|
||||||
|
|
@ -550,7 +554,8 @@ show_images:
|
||||||
debug_start = get_timer(0);
|
debug_start = get_timer(0);
|
||||||
if (get_timer(debug_start) > 20000) {
|
if (get_timer(debug_start) > 20000) {
|
||||||
debug_start = get_timer(0);
|
debug_start = get_timer(0);
|
||||||
printf("[%8ld]: soc=%d%%, vol=%dmv, c=%dma, online=%d, screen_on=%d\n",
|
printf("[%8ld]: soc=%d%%, vol=%dmv, c=%dma, "
|
||||||
|
"online=%d, screen_on=%d\n",
|
||||||
get_timer(0)/1000, soc, voltage,
|
get_timer(0)/1000, soc, voltage,
|
||||||
current, charging, screen_on);
|
current, charging, screen_on);
|
||||||
}
|
}
|
||||||
|
|
@ -570,24 +575,24 @@ show_images:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Auto turn on screen when voltage higher than Vol screen on.
|
* Auto turn on screen when voltage higher than Vol screen on.
|
||||||
* 'ever_lowpower_screen_off' means enter while loop with
|
* 'ever_lowpower_screen_off' means enter the while(1) loop with
|
||||||
* screen off.
|
* screen off.
|
||||||
*/
|
*/
|
||||||
if ((ever_lowpower_screen_off) &&
|
if ((ever_lowpower_screen_off) &&
|
||||||
(voltage > pdata->screen_on_voltage)) {
|
(voltage > pdata->screen_on_voltage)) {
|
||||||
ever_lowpower_screen_off = false;
|
ever_lowpower_screen_off = false;
|
||||||
screen_on = true;
|
screen_on = true;
|
||||||
show_idx = IMAGE_SHOW_RESET;
|
show_idx = IMAGE_RESET_IDX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IMAGE_SHOW_RESET means show_idx show be update by start_idx.
|
* IMAGE_RESET_IDX means show_idx show be update by start_idx.
|
||||||
* When short key pressed event trigged, we will set show_idx
|
* When short key pressed event trigged, we will set show_idx
|
||||||
* as IMAGE_SHOW_RESET which updates images index from start_idx
|
* as IMAGE_RESET_IDX which updates images index from start_idx
|
||||||
* that calculate by current soc.
|
* that calculate by current soc.
|
||||||
*/
|
*/
|
||||||
if (show_idx == IMAGE_SHOW_RESET) {
|
if (show_idx == IMAGE_RESET_IDX) {
|
||||||
for (i = 0; i < image_num - 2; i++) {
|
for (i = 0; i < IMAGE_SOC_100_IDX(image_num); i++) {
|
||||||
/* Find out which image we start to show */
|
/* Find out which image we start to show */
|
||||||
if ((soc >= image[i].soc) &&
|
if ((soc >= image[i].soc) &&
|
||||||
(soc < image[i + 1].soc)) {
|
(soc < image[i + 1].soc)) {
|
||||||
|
|
@ -596,7 +601,7 @@ show_images:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (soc >= 100) {
|
if (soc >= 100) {
|
||||||
start_idx = image_num - 2;
|
start_idx = IMAGE_SOC_100_IDX(image_num);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -619,7 +624,7 @@ show_images:
|
||||||
debug("SHOW: %s\n", image[show_idx].name);
|
debug("SHOW: %s\n", image[show_idx].name);
|
||||||
charge_show_bmp(image[show_idx].name);
|
charge_show_bmp(image[show_idx].name);
|
||||||
}
|
}
|
||||||
/* Re calculate timeout to off screen */
|
/* Re-calculate timeout to off screen */
|
||||||
if (priv->auto_screen_off_timeout == 0)
|
if (priv->auto_screen_off_timeout == 0)
|
||||||
priv->auto_screen_off_timeout = get_timer(0);
|
priv->auto_screen_off_timeout = get_timer(0);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -635,8 +640,8 @@ show_images:
|
||||||
show_start = get_timer(0);
|
show_start = get_timer(0);
|
||||||
/* Update to next image */
|
/* Update to next image */
|
||||||
show_idx++;
|
show_idx++;
|
||||||
if (show_idx > (image_num - 2))
|
if (show_idx > IMAGE_SOC_100_IDX(image_num))
|
||||||
show_idx = IMAGE_SHOW_RESET;
|
show_idx = IMAGE_RESET_IDX;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("step4 (%d)... \n", screen_on);
|
debug("step4 (%d)... \n", screen_on);
|
||||||
|
|
@ -649,21 +654,15 @@ show_images:
|
||||||
*/
|
*/
|
||||||
key_state = check_key_press(dev);
|
key_state = check_key_press(dev);
|
||||||
if (key_state == KEY_PRESS_DOWN) {
|
if (key_state == KEY_PRESS_DOWN) {
|
||||||
old_show_idx = IMAGE_SHOW_RESET;
|
|
||||||
|
|
||||||
/* NULL means show nothing, ie. turn off screen */
|
|
||||||
if (screen_on)
|
|
||||||
charge_show_bmp(NULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clear current image index, and show image
|
* Clear current image index, and show image
|
||||||
* from start_idx
|
* from start_idx
|
||||||
*/
|
*/
|
||||||
show_idx = IMAGE_SHOW_RESET;
|
old_show_idx = IMAGE_RESET_IDX;
|
||||||
|
show_idx = IMAGE_RESET_IDX;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We turn off screen by charge_show_bmp(NULL), so we
|
* Reverse the screen state
|
||||||
* should tell while loop to stop show images any more.
|
|
||||||
*
|
*
|
||||||
* If screen_on=false, means this short key pressed
|
* If screen_on=false, means this short key pressed
|
||||||
* event turn on the screen and we need show images.
|
* event turn on the screen and we need show images.
|
||||||
|
|
@ -671,12 +670,14 @@ show_images:
|
||||||
* If screen_on=true, means this short key pressed
|
* If screen_on=true, means this short key pressed
|
||||||
* event turn off the screen and we never show images.
|
* event turn off the screen and we never show images.
|
||||||
*/
|
*/
|
||||||
if (screen_on)
|
if (screen_on) {
|
||||||
|
charge_show_bmp(NULL); /* Turn off screen */
|
||||||
screen_on = false;
|
screen_on = false;
|
||||||
else
|
} else {
|
||||||
screen_on = true;
|
screen_on = true;
|
||||||
|
}
|
||||||
} else if (key_state == KEY_PRESS_LONG_DOWN) {
|
} else if (key_state == KEY_PRESS_LONG_DOWN) {
|
||||||
/* Only long pressed while screen off needs screen_on true */
|
/* Set screen_on=true anyway when key long pressed */
|
||||||
if (!screen_on)
|
if (!screen_on)
|
||||||
screen_on = true;
|
screen_on = true;
|
||||||
|
|
||||||
|
|
@ -685,7 +686,7 @@ show_images:
|
||||||
printf("soc=%d%%, threshold soc=%d%%\n",
|
printf("soc=%d%%, threshold soc=%d%%\n",
|
||||||
soc, pdata->exit_charge_level);
|
soc, pdata->exit_charge_level);
|
||||||
printf("Low power, unable to boot, charging...\n");
|
printf("Low power, unable to boot, charging...\n");
|
||||||
show_idx = image_num - 1;
|
show_idx = IMAGE_LOWPOWER_IDX(image_num);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -693,7 +694,7 @@ show_images:
|
||||||
printf("voltage=%dmv, threshold voltage=%dmv\n",
|
printf("voltage=%dmv, threshold voltage=%dmv\n",
|
||||||
voltage, pdata->exit_charge_voltage);
|
voltage, pdata->exit_charge_voltage);
|
||||||
printf("Low power, unable to boot, charging...\n");
|
printf("Low power, unable to boot, charging...\n");
|
||||||
show_idx = image_num - 1;
|
show_idx = IMAGE_LOWPOWER_IDX(image_num);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -738,11 +739,10 @@ static const struct dm_charge_display_ops charge_animation_ops = {
|
||||||
static int charge_animation_probe(struct udevice *dev)
|
static int charge_animation_probe(struct udevice *dev)
|
||||||
{
|
{
|
||||||
struct charge_animation_priv *priv = dev_get_priv(dev);
|
struct charge_animation_priv *priv = dev_get_priv(dev);
|
||||||
struct udevice *fg, *pmic, *rtc;
|
|
||||||
int ret, soc;
|
int ret, soc;
|
||||||
|
|
||||||
/* Get PMIC: used for power off system */
|
/* Get PMIC: used for power off system */
|
||||||
ret = uclass_get_device(UCLASS_PMIC, 0, &pmic);
|
ret = uclass_get_device(UCLASS_PMIC, 0, &priv->pmic);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (ret == -ENODEV)
|
if (ret == -ENODEV)
|
||||||
printf("Can't find PMIC\n");
|
printf("Can't find PMIC\n");
|
||||||
|
|
@ -750,10 +750,9 @@ static int charge_animation_probe(struct udevice *dev)
|
||||||
printf("Get UCLASS PMIC failed: %d\n", ret);
|
printf("Get UCLASS PMIC failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
priv->pmic = pmic;
|
|
||||||
|
|
||||||
/* Get fuel gauge: used for charging */
|
/* Get fuel gauge: used for charging */
|
||||||
ret = uclass_get_device(UCLASS_FG, 0, &fg);
|
ret = uclass_get_device(UCLASS_FG, 0, &priv->fg);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (ret == -ENODEV)
|
if (ret == -ENODEV)
|
||||||
debug("Can't find FG\n");
|
debug("Can't find FG\n");
|
||||||
|
|
@ -761,17 +760,15 @@ static int charge_animation_probe(struct udevice *dev)
|
||||||
debug("Get UCLASS FG failed: %d\n", ret);
|
debug("Get UCLASS FG failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
priv->fg = fg;
|
|
||||||
|
|
||||||
/* Get rtc: used for power on */
|
/* Get rtc: used for power on */
|
||||||
ret = uclass_get_device(UCLASS_RTC, 0, &rtc);
|
ret = uclass_get_device(UCLASS_RTC, 0, &priv->rtc);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (ret == -ENODEV)
|
if (ret == -ENODEV)
|
||||||
debug("Can't find RTC\n");
|
debug("Can't find RTC\n");
|
||||||
else
|
else
|
||||||
debug("Get UCLASS RTC failed: %d\n", ret);
|
debug("Get UCLASS RTC failed: %d\n", ret);
|
||||||
}
|
}
|
||||||
priv->rtc = rtc;
|
|
||||||
|
|
||||||
/* Get PWRKEY: used for wakeup and turn off/on LCD */
|
/* Get PWRKEY: used for wakeup and turn off/on LCD */
|
||||||
if (key_read(KEY_POWER) == KEY_NOT_EXIST) {
|
if (key_read(KEY_POWER) == KEY_NOT_EXIST) {
|
||||||
|
|
@ -780,7 +777,7 @@ static int charge_animation_probe(struct udevice *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize charge current */
|
/* Initialize charge current */
|
||||||
soc = fuel_gauge_get_soc(fg);
|
soc = fuel_gauge_get_soc(priv->fg);
|
||||||
if (soc < 0 || soc > 100) {
|
if (soc < 0 || soc > 100) {
|
||||||
debug("get soc failed: %d\n", soc);
|
debug("get soc failed: %d\n", soc);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,18 @@
|
||||||
#define _CHARGE_ANIMATION_H_
|
#define _CHARGE_ANIMATION_H_
|
||||||
|
|
||||||
struct charge_animation_pdata {
|
struct charge_animation_pdata {
|
||||||
int android_charge;
|
int android_charge; /* android charge, 1: enable, 0: disable */
|
||||||
int uboot_charge;
|
int uboot_charge; /* u-boot charge, 1: enable, 0: disable */
|
||||||
|
|
||||||
int exit_charge_voltage;
|
int exit_charge_voltage;/* lowest voltage allowed to exit charging */
|
||||||
int exit_charge_level;
|
int exit_charge_level; /* lowest soc level allowed to exit charging */
|
||||||
int low_power_voltage;
|
int low_power_voltage; /* below this voltage, force system into charge mode anyway */
|
||||||
int screen_on_voltage;
|
int screen_on_voltage; /* lowest voltage allowed to turn on screen */
|
||||||
|
|
||||||
int system_suspend;
|
int system_suspend; /* enter ATF system suspend, 1: enable, 0: disable */
|
||||||
int auto_wakeup_interval;
|
int auto_wakeup_interval;/* timeout seconds to auto wakeup system */
|
||||||
int auto_wakeup_screen_invert;
|
int auto_wakeup_screen_invert;/* auto wakeup system, 1: enable, 0: disable */
|
||||||
int auto_off_screen_interval;
|
int auto_off_screen_interval;/* timeout seconds to auto turn off screen */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue