summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233/powermgmt-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-07-07 17:29:41 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-07-07 17:36:21 +0200
commit3afcb53fb94b7bb937147236f338dd89afb781d0 (patch)
treefca31ca98a49047e49a0f317abdc00ede26599f3 /firmware/target/arm/imx233/powermgmt-imx233.c
parent659febc749627a92c59f2d765da59eb9c995c50d (diff)
downloadrockbox-3afcb53fb94b7bb937147236f338dd89afb781d0.tar.gz
rockbox-3afcb53fb94b7bb937147236f338dd89afb781d0.tar.bz2
rockbox-3afcb53fb94b7bb937147236f338dd89afb781d0.zip
imx233: rework power management
The current code was spreaded over power and powermgmt which made it behave strangely, especially since there are relationships between power management and frequency scaling. The new code makes sure power management is initialised before frequency scaling starts. It also makes sure to start from a known state, thus fixing potential issue when the bootloader stops in a trickle state where DCDC is improperly configured. Change-Id: Ibded2e590e108f6c98daa52d2cf1bd28763c8923
Diffstat (limited to 'firmware/target/arm/imx233/powermgmt-imx233.c')
-rw-r--r--firmware/target/arm/imx233/powermgmt-imx233.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/firmware/target/arm/imx233/powermgmt-imx233.c b/firmware/target/arm/imx233/powermgmt-imx233.c
index 8980124b33..9819406974 100644
--- a/firmware/target/arm/imx233/powermgmt-imx233.c
+++ b/firmware/target/arm/imx233/powermgmt-imx233.c
@@ -44,19 +44,46 @@ int _battery_voltage(void)
return BF_RD(POWER_BATTMONITOR, BATT_VAL) * 8;
}
-void powermgmt_init_target(void)
+void imx233_powermgmt_init(void)
{
imx233_power_set_charge_current(IMX233_CHARGE_CURRENT);
imx233_power_set_stop_current(IMX233_STOP_CURRENT);
-#if IMX233_SUBTARGET >= 3780
/* assume that adc_init was called and battery monitoring via LRADC setup */
BF_WR(POWER_BATTMONITOR, EN_BATADJ, 1);
+#if IMX233_SUBTARGET >= 3700
+ /* setup linear regulator offsets to 25 mV below to prevent contention between
+ * linear regulators and DCDC */
+ BF_WR(POWER_VDDDCTRL, LINREG_OFFSET, 2);
+ BF_WR(POWER_VDDACTRL, LINREG_OFFSET, 2);
+ BF_WR(POWER_VDDIOCTRL, LINREG_OFFSET, 2);
+ /* enable DCDC (more efficient) */
+ BF_SET(POWER_5VCTRL, ENABLE_DCDC);
+ BF_CLR(POWER_5VCTRL, DCDC_XFER);
+#else
+ BF_SET(POWER_5VCTRL, LINREG_OFFSET);
+ BF_SET(POWER_5VCTRL, EN_DCDC1);
+ BF_SET(POWER_5VCTRL, EN_DCDC2);
+#endif
+
+#if IMX233_SUBTARGET >= 3780
+ /* enable a few bits controlling the DC-DC as recommended by Freescale */
+ BF_SET(POWER_LOOPCTRL, TOGGLE_DIF);
+ BF_SET(POWER_LOOPCTRL, EN_CM_HYST);
+ BF_CLR(POWER_LOOPCTRL, EN_RCSCALE);
+ BF_SETV(POWER_LOOPCTRL, EN_RCSCALE, 1);
+ /* adjust arbitration between 4.2 and battery */
+ BF_WR(POWER_DCDC4P2, CMPTRIP, 0); /* 85% */
+ BF_WR(POWER_DCDC4P2, DROPOUT_CTRL, 0xe); /* select greater, 200 mV drop */
/* make sure we are in a known state: disable charger and 4p2 */
BF_SET(POWER_CHARGE, PWD_BATTCHRG);
BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 0);
BF_WR(POWER_DCDC4P2, ENABLE_4P2, 0);
BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2);
#endif
+}
+
+void powermgmt_init_target(void)
+{
charge_state = DISCHARGING;
}
@@ -106,9 +133,6 @@ void charging_algorithm_step(void)
{
logf("pwrmgmt: enable dcdc and charger");
logf("pwrmgmt: trickle -> charging");
- /* adjust arbitration between 4.2 and battery */
- BF_WR(POWER_DCDC4P2, CMPTRIP, 0); /* 85% */
- BF_WR(POWER_DCDC4P2, DROPOUT_CTRL, 0xe); /* select greater, 200 mV drop */
BF_CLR(POWER_5VCTRL, DCDC_XFER);
BF_SET(POWER_5VCTRL, ENABLE_DCDC);
/* enable battery charging */