diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/arm/imx233/powermgmt-imx233.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/firmware/target/arm/imx233/powermgmt-imx233.c b/firmware/target/arm/imx233/powermgmt-imx233.c index f2d1981f24..26fb57305b 100644 --- a/firmware/target/arm/imx233/powermgmt-imx233.c +++ b/firmware/target/arm/imx233/powermgmt-imx233.c | |||
@@ -68,16 +68,22 @@ void imx233_powermgmt_init(void) | |||
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | #if IMX233_SUBTARGET >= 3780 | 70 | #if IMX233_SUBTARGET >= 3780 |
71 | /* adjust arbitration between 4.2 and battery */ | ||
72 | BF_WR(POWER_DCDC4P2, CMPTRIP, 0); /* 85% */ | ||
73 | BF_WR(POWER_DCDC4P2, DROPOUT_CTRL, 0xe); /* select greater, 200 mV drop */ | ||
74 | #endif | ||
75 | |||
76 | #if IMX233_SUBTARGET >= 3700 | ||
71 | /* enable a few bits controlling the DC-DC as recommended by Freescale */ | 77 | /* enable a few bits controlling the DC-DC as recommended by Freescale */ |
72 | BF_SET(POWER_LOOPCTRL, TOGGLE_DIF); | 78 | BF_SET(POWER_LOOPCTRL, TOGGLE_DIF); |
73 | BF_SET(POWER_LOOPCTRL, EN_CM_HYST); | 79 | BF_SET(POWER_LOOPCTRL, EN_CM_HYST); |
74 | BF_CLR(POWER_LOOPCTRL, EN_RCSCALE); | 80 | BF_CLR(POWER_LOOPCTRL, EN_RCSCALE); |
75 | BF_SETV(POWER_LOOPCTRL, EN_RCSCALE, 1); | 81 | BF_SETV(POWER_LOOPCTRL, EN_RCSCALE, 1); |
76 | /* adjust arbitration between 4.2 and battery */ | 82 | /* make sure we are in a known state: disable charger */ |
77 | BF_WR(POWER_DCDC4P2, CMPTRIP, 0); /* 85% */ | ||
78 | BF_WR(POWER_DCDC4P2, DROPOUT_CTRL, 0xe); /* select greater, 200 mV drop */ | ||
79 | /* make sure we are in a known state: disable charger and 4p2 */ | ||
80 | BF_SET(POWER_CHARGE, PWD_BATTCHRG); | 83 | BF_SET(POWER_CHARGE, PWD_BATTCHRG); |
84 | #endif | ||
85 | #if IMX233_SUBTARGET >= 3780 | ||
86 | /* make sure we are in a known state: disable 4p2 */ | ||
81 | BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 0); | 87 | BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 0); |
82 | BF_WR(POWER_DCDC4P2, ENABLE_4P2, 0); | 88 | BF_WR(POWER_DCDC4P2, ENABLE_4P2, 0); |
83 | BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); | 89 | BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); |
@@ -91,7 +97,6 @@ void powermgmt_init_target(void) | |||
91 | 97 | ||
92 | void charging_algorithm_step(void) | 98 | void charging_algorithm_step(void) |
93 | { | 99 | { |
94 | #if IMX233_SUBTARGET >= 3780 | ||
95 | bool is_5v_present = usb_detect() == USB_INSERTED; | 100 | bool is_5v_present = usb_detect() == USB_INSERTED; |
96 | 101 | ||
97 | /* initial state & 5v -> battery transition */ | 102 | /* initial state & 5v -> battery transition */ |
@@ -101,9 +106,11 @@ void charging_algorithm_step(void) | |||
101 | logf("pwrmgmt: disable charger and 4p2"); | 106 | logf("pwrmgmt: disable charger and 4p2"); |
102 | /* 5V has been lost: disable 4p2 power rail */ | 107 | /* 5V has been lost: disable 4p2 power rail */ |
103 | BF_SET(POWER_CHARGE, PWD_BATTCHRG); | 108 | BF_SET(POWER_CHARGE, PWD_BATTCHRG); |
109 | #if IMX233_SUBTARGET >= 3780 | ||
104 | BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 0); | 110 | BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 0); |
105 | BF_WR(POWER_DCDC4P2, ENABLE_4P2, 0); | 111 | BF_WR(POWER_DCDC4P2, ENABLE_4P2, 0); |
106 | BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); | 112 | BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); |
113 | #endif | ||
107 | charge_state = DISCHARGING; | 114 | charge_state = DISCHARGING; |
108 | } | 115 | } |
109 | /* battery -> 5v transition */ | 116 | /* battery -> 5v transition */ |
@@ -111,17 +118,20 @@ void charging_algorithm_step(void) | |||
111 | { | 118 | { |
112 | logf("pwrmgmt: discharging -> trickle"); | 119 | logf("pwrmgmt: discharging -> trickle"); |
113 | logf("pwrmgmt: begin charging 4p2"); | 120 | logf("pwrmgmt: begin charging 4p2"); |
121 | #if IMX233_SUBTARGET >= 3780 | ||
114 | /* 5V has been detected: prepare 4.2V power rail for activation */ | 122 | /* 5V has been detected: prepare 4.2V power rail for activation */ |
115 | BF_WR(POWER_DCDC4P2, ENABLE_4P2, 1); | 123 | BF_WR(POWER_DCDC4P2, ENABLE_4P2, 1); |
116 | BF_SET(POWER_CHARGE, ENABLE_LOAD); | 124 | BF_SET(POWER_CHARGE, ENABLE_LOAD); |
117 | BF_WR(POWER_5VCTRL, CHARGE_4P2_ILIMIT, 1); | 125 | BF_WR(POWER_5VCTRL, CHARGE_4P2_ILIMIT, 1); |
118 | BF_CLR(POWER_5VCTRL, PWD_CHARGE_4P2);// FIXME: manual error ? | 126 | BF_CLR(POWER_5VCTRL, PWD_CHARGE_4P2);// FIXME: manual error ? |
119 | BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 1); | 127 | BF_WR(POWER_DCDC4P2, ENABLE_DCDC, 1); |
128 | #endif | ||
120 | timeout_4p2_ilimit_increase = current_tick + HZ / 100; | 129 | timeout_4p2_ilimit_increase = current_tick + HZ / 100; |
121 | charge_state = TRICKLE; | 130 | charge_state = TRICKLE; |
122 | } | 131 | } |
123 | else if(charge_state == TRICKLE && TIME_AFTER(current_tick, timeout_4p2_ilimit_increase)) | 132 | else if(charge_state == TRICKLE && TIME_AFTER(current_tick, timeout_4p2_ilimit_increase)) |
124 | { | 133 | { |
134 | #if IMX233_SUBTARGET >= 3780 | ||
125 | /* if 4.2V current limit has not reached 780mA, increase it slowly to | 135 | /* if 4.2V current limit has not reached 780mA, increase it slowly to |
126 | * charge the 4.2V capacitance */ | 136 | * charge the 4.2V capacitance */ |
127 | if(BF_RD(POWER_5VCTRL, CHARGE_4P2_ILIMIT) != 0x3f) | 137 | if(BF_RD(POWER_5VCTRL, CHARGE_4P2_ILIMIT) != 0x3f) |
@@ -132,6 +142,7 @@ void charging_algorithm_step(void) | |||
132 | } | 142 | } |
133 | /* we've reached the maximum, take action */ | 143 | /* we've reached the maximum, take action */ |
134 | else | 144 | else |
145 | #endif | ||
135 | { | 146 | { |
136 | logf("pwrmgmt: enable dcdc and charger"); | 147 | logf("pwrmgmt: enable dcdc and charger"); |
137 | logf("pwrmgmt: trickle -> charging"); | 148 | logf("pwrmgmt: trickle -> charging"); |
@@ -149,7 +160,10 @@ void charging_algorithm_step(void) | |||
149 | logf("pwrmgmt: charging timeout exceeded!"); | 160 | logf("pwrmgmt: charging timeout exceeded!"); |
150 | logf("pwrmgmt: charging -> error"); | 161 | logf("pwrmgmt: charging -> error"); |
151 | /* stop charging */ | 162 | /* stop charging */ |
163 | #if IMX233_SUBTARGET >= 3780 | ||
152 | BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); | 164 | BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); |
165 | #endif | ||
166 | BF_SET(POWER_CHARGE, PWD_BATTCHRG); | ||
153 | /* goto error state */ | 167 | /* goto error state */ |
154 | charge_state = CHARGE_STATE_ERROR; | 168 | charge_state = CHARGE_STATE_ERROR; |
155 | } | 169 | } |
@@ -165,10 +179,12 @@ void charging_algorithm_step(void) | |||
165 | logf("pwrmgmt: charging finished"); | 179 | logf("pwrmgmt: charging finished"); |
166 | logf("pwrmgmt: topoff -> disabled"); | 180 | logf("pwrmgmt: topoff -> disabled"); |
167 | /* stop charging */ | 181 | /* stop charging */ |
182 | #if IMX233_SUBTARGET >= 3780 | ||
183 | BF_SET(POWER_5VCTRL, PWD_CHARGE_4P2); | ||
184 | #endif | ||
168 | BF_SET(POWER_CHARGE, PWD_BATTCHRG); | 185 | BF_SET(POWER_CHARGE, PWD_BATTCHRG); |
169 | charge_state = CHARGE_STATE_DISABLED; | 186 | charge_state = CHARGE_STATE_DISABLED; |
170 | } | 187 | } |
171 | #endif | ||
172 | } | 188 | } |
173 | 189 | ||
174 | void charging_algorithm_close(void) | 190 | void charging_algorithm_close(void) |