summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-07-11 13:42:29 +0800
committerChromeBot <chrome-bot@google.com>2013-07-15 13:01:43 -0700
commita8047afbb10e47e0ad5422431244b903399a2783 (patch)
tree4e36c10ef19d225ee29eafcb80c84ef994d98ce3
parent1f6e5f8a1e074bd91acd3fc0b3de268495199c10 (diff)
downloadchrome-ec-a8047afbb10e47e0ad5422431244b903399a2783.tar.gz
Turn off boost when the battery is nearly full
Boost is consuming about 1W. To reduce power draw in S5, we should turn off boost when the battery is nearly full. The battery discharges slowly in this case, so we also need to turn boost back on when the battery level drops too low. BUG=chrome-os-partner:20768 TEST=In S5, see boost disabled when battery is charged to 98%. And see boost enabled when battery drops to 94%. TEST=When boost is disabled, power on the system. Check boost is enabled. BRANCH=Spring Change-Id: Ibc6a8af17bb6ce419abbcc8b693b7f90bf59839c Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/61557 Reviewed-by: Todd Broch <tbroch@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/board.c20
-rw-r--r--board/spring/usb_charging.c60
2 files changed, 56 insertions, 24 deletions
diff --git a/board/spring/board.c b/board/spring/board.c
index 3c700b0a73..2b80f462b7 100644
--- a/board/spring/board.c
+++ b/board/spring/board.c
@@ -302,26 +302,6 @@ int board_pmu_init(void)
}
#endif /* CONFIG_BOARD_PMU_INIT */
-int board_get_ac(void)
-{
- static int last_vbus;
- int vbus, vbus_good;
-
- if (!gpio_get_level(GPIO_BOOST_EN))
- return 0;
-
- /*
- * UVLO is 4.1V. We consider AC bad when its voltage drops below 4.2V
- * for two consecutive samples. This is to give PWM a chance to bring
- * voltage up.
- */
- vbus = adc_read_channel(ADC_CH_USB_VBUS_SNS);
- vbus_good = (vbus >= 4200 || last_vbus >= 4200);
- last_vbus = vbus;
-
- return vbus_good;
-}
-
static int set_led_color(enum led_state_t state)
{
int rv = EC_SUCCESS;
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c
index 56a5ef6655..7a33629618 100644
--- a/board/spring/usb_charging.c
+++ b/board/spring/usb_charging.c
@@ -84,6 +84,10 @@
#define CABLE_DET_POLL_MS 100
#define CABLE_DET_POLL_COUNT 6
+/* Battery level thresholds for S5 boost control */
+#define S5_BOOST_CTRL_LOWER_BOUND 94
+#define S5_BOOST_CTRL_UPPER_BOUND 98
+
static int current_dev_type = TSU6721_TYPE_NONE;
static int nominal_pwm_duty;
static int current_pwm_duty;
@@ -95,6 +99,8 @@ static int pending_dev_type_update;
static int pending_video_power_off;
static int restore_id_mux;
+static int s5_boost_ctrl;
+
static enum {
LIMIT_NORMAL,
LIMIT_AGGRESSIVE,
@@ -527,10 +533,31 @@ static int usb_need_boost(int dev_type)
return (dev_type != TSU6721_TYPE_NONE);
}
+static void usb_s5_manage_boost(void)
+{
+ int charge;
+ int boost = gpio_get_level(GPIO_BOOST_EN);
+
+ if (!usb_maybe_power_input(current_dev_type)) {
+ if (boost)
+ gpio_set_level(GPIO_BOOST_EN, 0);
+ return;
+ }
+
+ if (battery_state_of_charge(&charge))
+ return;
+
+ if (boost == 0 && charge <= S5_BOOST_CTRL_LOWER_BOUND)
+ gpio_set_level(GPIO_BOOST_EN, 1);
+ else if (boost == 1 && charge >= S5_BOOST_CTRL_UPPER_BOUND)
+ gpio_set_level(GPIO_BOOST_EN, 0);
+}
+
static void usb_boost_power_hook(int power_on)
{
- if (current_dev_type == TSU6721_TYPE_NONE)
- gpio_set_level(GPIO_BOOST_EN, power_on);
+ s5_boost_ctrl = !power_on;
+ if (power_on && usb_need_boost(current_dev_type))
+ gpio_set_level(GPIO_BOOST_EN, 1);
else if (current_dev_type & TSU6721_TYPE_JIG_UART_ON)
set_video_power(power_on);
}
@@ -673,11 +700,13 @@ DECLARE_DEFERRED(send_battery_key_deferred);
static void notify_dev_type_change(int dev_type)
{
+ int org_type = current_dev_type;
+
+ current_dev_type = dev_type;
usb_log_dev_type(dev_type);
- if (usb_has_power_input(current_dev_type) !=
+ if (usb_has_power_input(org_type) !=
usb_has_power_input(dev_type))
hook_notify(HOOK_AC_CHANGE);
- current_dev_type = dev_type;
hook_call_deferred(send_battery_key_deferred, BATTERY_KEY_DELAY);
}
@@ -840,6 +869,9 @@ void board_usb_charge_update(int force_update)
pending_dev_type_update = 0;
}
+ if (s5_boost_ctrl)
+ usb_s5_manage_boost();
+
/*
* Check device type except when:
* 1. Current device type is non-standard charger or undetermined
@@ -871,6 +903,26 @@ int board_get_usb_current_limit(void)
return PWM_MAPPING_A + PWM_MAPPING_B * current_pwm_duty;
}
+int board_get_ac(void)
+{
+ static int last_vbus;
+ int vbus, vbus_good;
+
+ if (!usb_maybe_power_input(current_dev_type))
+ return 0;
+
+ /*
+ * UVLO is 4.1V. We consider AC bad when its voltage drops below 4.2V
+ * for two consecutive samples. This is to give PWM a chance to bring
+ * voltage up.
+ */
+ vbus = adc_read_channel(ADC_CH_USB_VBUS_SNS);
+ vbus_good = (vbus >= 4200 || last_vbus >= 4200);
+ last_vbus = vbus;
+
+ return vbus_good;
+}
+
/*
* Console commands for debugging.
* TODO(victoryang): Remove after charging control is done.