mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 21:22:39 -05:00
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
This commit is contained in:
parent
659febc749
commit
3afcb53fb9
5 changed files with 32 additions and 27 deletions
|
|
@ -37,7 +37,6 @@ void tick_start(unsigned int interval_in_ms)
|
||||||
false, &tick_timer);
|
false, &tick_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void arbiter_init(struct channel_arbiter_t *a, unsigned count)
|
void arbiter_init(struct channel_arbiter_t *a, unsigned count)
|
||||||
{
|
{
|
||||||
mutex_init(&a->mutex);
|
mutex_init(&a->mutex);
|
||||||
|
|
|
||||||
|
|
@ -146,27 +146,6 @@ void imx233_power_init(void)
|
||||||
BF_SET(POWER_CTRL, ENIRQ_VDD5V_GT_VDDIO);
|
BF_SET(POWER_CTRL, ENIRQ_VDD5V_GT_VDDIO);
|
||||||
#endif
|
#endif
|
||||||
imx233_icoll_enable_interrupt(INT_SRC_VDD5V, true);
|
imx233_icoll_enable_interrupt(INT_SRC_VDD5V, true);
|
||||||
/* setup linear regulator offsets to 25 mV below to prevent contention between
|
|
||||||
* linear regulators and DCDC */
|
|
||||||
#if IMX233_SUBTARGET >= 3700
|
|
||||||
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);
|
|
||||||
#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);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void power_init(void)
|
void power_init(void)
|
||||||
|
|
|
||||||
|
|
@ -44,19 +44,46 @@ int _battery_voltage(void)
|
||||||
return BF_RD(POWER_BATTMONITOR, BATT_VAL) * 8;
|
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_charge_current(IMX233_CHARGE_CURRENT);
|
||||||
imx233_power_set_stop_current(IMX233_STOP_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 */
|
/* assume that adc_init was called and battery monitoring via LRADC setup */
|
||||||
BF_WR(POWER_BATTMONITOR, EN_BATADJ, 1);
|
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 */
|
/* make sure we are in a known state: disable charger and 4p2 */
|
||||||
BF_SET(POWER_CHARGE, PWD_BATTCHRG);
|
BF_SET(POWER_CHARGE, PWD_BATTCHRG);
|
||||||
BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 0);
|
BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 0);
|
||||||
BF_WR(POWER_DCDC4P2, ENABLE_4P2, 0);
|
BF_WR(POWER_DCDC4P2, ENABLE_4P2, 0);
|
||||||
BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2);
|
BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void powermgmt_init_target(void)
|
||||||
|
{
|
||||||
charge_state = DISCHARGING;
|
charge_state = DISCHARGING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,9 +133,6 @@ void charging_algorithm_step(void)
|
||||||
{
|
{
|
||||||
logf("pwrmgmt: enable dcdc and charger");
|
logf("pwrmgmt: enable dcdc and charger");
|
||||||
logf("pwrmgmt: trickle -> charging");
|
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_CLR(POWER_5VCTRL, DCDC_XFER);
|
||||||
BF_SET(POWER_5VCTRL, ENABLE_DCDC);
|
BF_SET(POWER_5VCTRL, ENABLE_DCDC);
|
||||||
/* enable battery charging */
|
/* enable battery charging */
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "powermgmt.h"
|
#include "powermgmt.h"
|
||||||
|
|
||||||
|
void imx233_powermgmt_init(void);
|
||||||
void powermgmt_init_target(void);
|
void powermgmt_init_target(void);
|
||||||
void charging_algorithm_step(void);
|
void charging_algorithm_step(void);
|
||||||
void charging_algorithm_close(void);
|
void charging_algorithm_close(void);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@
|
||||||
#include "backlight-target.h"
|
#include "backlight-target.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "fmradio_i2c.h"
|
#include "fmradio_i2c.h"
|
||||||
|
#include "powermgmt.h"
|
||||||
|
|
||||||
void imx233_chip_reset(void)
|
void imx233_chip_reset(void)
|
||||||
{
|
{
|
||||||
|
|
@ -132,6 +133,7 @@ void system_init(void)
|
||||||
imx233_lradc_init();
|
imx233_lradc_init();
|
||||||
imx233_power_init();
|
imx233_power_init();
|
||||||
imx233_i2c_init();
|
imx233_i2c_init();
|
||||||
|
imx233_powermgmt_init();
|
||||||
|
|
||||||
/* make sure auto-slow is disable now, we don't know at which frequency we
|
/* make sure auto-slow is disable now, we don't know at which frequency we
|
||||||
* are running and auto-slow could violate constraints on {xbus,hbus} */
|
* are running and auto-slow could violate constraints on {xbus,hbus} */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue