summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/spring/usb_charging.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c
index 4032a63bee..e644715d83 100644
--- a/board/spring/usb_charging.c
+++ b/board/spring/usb_charging.c
@@ -60,6 +60,9 @@
#define I_LIMIT_2400MA MA_TO_PWM(2400)
#define I_LIMIT_3000MA 0
+/* lower bound for PWM duty cycle : max charger current */
+#define I_LIMIT_MAX MA_TO_PWM(2500)
+
/* PWM control loop parameters */
#define PWM_CTRL_MAX_DUTY I_LIMIT_100MA /* Minimum current */
#define PWM_CTRL_BEGIN_OFFSET 90
@@ -357,8 +360,8 @@ int board_has_high_power_ac(void)
void board_pwm_duty_cycle(int percent)
{
- if (percent < 0)
- percent = 0;
+ if (percent < I_LIMIT_MAX)
+ percent = I_LIMIT_MAX;
if (percent > 100)
percent = 100;
@@ -406,12 +409,15 @@ static int board_pwm_get_next_lower(void)
if (current_pwm_duty > nominal_pwm_duty -
PWM_CTRL_OC_MARGIN &&
current_pwm_duty > over_current_pwm_duty &&
- current_pwm_duty > 0)
- return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN, 0);
+ current_pwm_duty > I_LIMIT_MAX)
+ return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN,
+ I_LIMIT_MAX);
return -1;
} else {
- if (current_pwm_duty > nominal_pwm_duty && current_pwm_duty > 0)
- return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN, 0);
+ if (current_pwm_duty > nominal_pwm_duty &&
+ current_pwm_duty > I_LIMIT_MAX)
+ return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN,
+ I_LIMIT_MAX);
else
return -1;
}
@@ -466,7 +472,7 @@ static void board_pwm_tweak(void)
CPRINTF("[%T PWM duty up %d%%]\n", current_pwm_duty);
} else if (board_pwm_check_vbus_high(vbus)) {
next = board_pwm_get_next_lower();
- if (next >= 0) {
+ if (next >= I_LIMIT_MAX) {
board_pwm_duty_cycle(next);
CPRINTF("[%T PWM duty down %d%%]\n", current_pwm_duty);
}