imx233: add new power debug screen

This screen allows to put the device in a special mode where:
- charging is disabled
- device only draws power from 5V (thus battery is untouched)
This is useful to measure the device consumption by measuring directly
the usb power consumption.

Change-Id: I2716ced0a5bb33c3c9a2607f2d17a0ce02f5689c
This commit is contained in:
Amaury Pouly 2016-05-02 21:56:20 +01:00
parent 2dcc9fc39f
commit cdca7cee71

View file

@ -26,6 +26,7 @@
#include "lcd.h" #include "lcd.h"
#include "font.h" #include "font.h"
#include "adc.h" #include "adc.h"
#include "usb.h"
#include "power-imx233.h" #include "power-imx233.h"
#include "clkctrl-imx233.h" #include "clkctrl-imx233.h"
#include "powermgmt-imx233.h" #include "powermgmt-imx233.h"
@ -45,6 +46,7 @@
#include "regs/usbphy.h" #include "regs/usbphy.h"
#include "regs/timrot.h" #include "regs/timrot.h"
#include "regs/power.h"
#define ACT_NONE 0 #define ACT_NONE 0
#define ACT_CANCEL 1 #define ACT_CANCEL 1
@ -418,6 +420,91 @@ bool dbg_hw_info_powermgmt(void)
} }
} }
bool dbg_hw_info_power2(void)
{
lcd_setfont(FONT_SYSFIXED);
bool holding_select = false;
int select_hold_time = 0;
while(1)
{
int button = my_get_action(HZ / 10);
if(button == ACT_NEXT || button == ACT_PREV)
{
lcd_setfont(FONT_UI);
return true;
}
else if(button == ACT_CANCEL)
{
lcd_setfont(FONT_UI);
return false;
}
button = my_get_status();
if(button == ACT_OK && !holding_select)
{
holding_select = true;
select_hold_time = current_tick;
}
else if(button != ACT_OK && holding_select)
{
holding_select = false;
}
/* disable feature if unsafe: we need 4.2 and dcdc fully operational */
bool feat_safe = usb_detect() == USB_INSERTED && BF_RD(POWER_DCDC4P2, ENABLE_DCDC)
&& BF_RD(POWER_DCDC4P2, ENABLE_4P2) && BF_RD(POWER_5VCTRL, ENABLE_DCDC)
&& !BF_RD(POWER_5VCTRL, PWD_CHARGE_4P2);
bool batt_disabled = (BF_RD(POWER_DCDC4P2, DROPOUT_CTRL) == 0xc);
if(holding_select && TIME_AFTER(current_tick, select_hold_time + HZ))
{
if(batt_disabled)
{
BF_CLR(POWER_CHARGE, PWD_BATTCHRG); /* enable charger again */
BF_WR(POWER_DCDC4P2, DROPOUT_CTRL(0xe)); /* select greater, 200 mV drop */
}
else if(feat_safe)
{
BF_WR(POWER_DCDC4P2, DROPOUT_CTRL(0xc)); /* always select 4.2, 200 mV drop */
BF_SET(POWER_CHARGE, PWD_BATTCHRG); /* disable charger */
}
holding_select = false;
/* return to the beginning of the loop to gather more information
* about HW state before displaying it */
continue;
}
lcd_clear_display();
if(!batt_disabled)
{
lcd_putsf(0, 0, "Hold select for 1 sec");
lcd_putsf(0, 1, "to disable battery");
lcd_putsf(0, 1, "and battery charger.");
lcd_putsf(0, 2, "The device will run");
lcd_putsf(0, 3, "entirely from USB.");
lcd_putsf(0, 5, "WARNING");
lcd_putsf(0, 6, "This is a debug");
lcd_putsf(0, 7, "feature !");
if(!feat_safe)
{
lcd_putsf(0, 9, "NOTE: unavailable");
lcd_putsf(0, 10, "Plug USB to enable.");
}
}
else
{
lcd_putsf(0, 0, "Battery is DISABLED.");
lcd_putsf(0, 1, "Hold select for 1 sec");
lcd_putsf(0, 2, "to renable battery.");
lcd_putsf(0, 4, "WARNING");
lcd_putsf(0, 5, "Do not unplug USB !");
}
lcd_update();
yield();
}
}
bool dbg_hw_info_rtc(void) bool dbg_hw_info_rtc(void)
{ {
lcd_setfont(FONT_SYSFIXED); lcd_setfont(FONT_SYSFIXED);
@ -1105,6 +1192,7 @@ static struct
{"dma", dbg_hw_info_dma}, {"dma", dbg_hw_info_dma},
{"lradc", dbg_hw_info_lradc}, {"lradc", dbg_hw_info_lradc},
{"power", dbg_hw_info_power}, {"power", dbg_hw_info_power},
{"power2", dbg_hw_info_power2},
{"powermgmt", dbg_hw_info_powermgmt}, {"powermgmt", dbg_hw_info_powermgmt},
{"rtc", dbg_hw_info_rtc}, {"rtc", dbg_hw_info_rtc},
{"dcp", dbg_hw_info_dcp}, {"dcp", dbg_hw_info_dcp},