ryu: Try to clear CHARGE_DONE when the lid is just closed

For the transmitter to clear CHARGE_DONE, charging must be enabled.
Therefore, we should always enable charging when the lid is just closed.

BRANCH=ryu
BUG=None
TEST=Test on Ryu p1.

Signed-off-by: Vic Yang <victoryang@chromium.org>
Change-Id: I44f3d7c9e413a63be66ccf9695fea5411b2067b6
Reviewed-on: https://chromium-review.googlesource.com/231121
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Vic Yang
2014-11-20 13:20:37 -08:00
committed by chrome-internal-fetch
parent 99ec74d7d4
commit 33142ba9ac
2 changed files with 57 additions and 2 deletions

View File

@@ -9,24 +9,40 @@
#include "gpio.h"
#include "hooks.h"
#include "lid_switch.h"
#include "timer.h"
void inductive_charging_interrupt(enum gpio_signal signal)
{
int charger_enabled = gpio_get_level(GPIO_BASE_CHG_VDD_EN);
int charge_done = gpio_get_level(GPIO_CHARGE_DONE);
/* Always try to charge if the lid is just closed */
if (signal == GPIO_LID_OPEN)
charge_done = 0;
if (!charger_enabled || charge_done)
gpio_set_level(GPIO_CHARGE_EN, 0);
else
gpio_set_level(GPIO_CHARGE_EN, 1);
}
static void inductive_charging_lid_update(void)
static void inductive_charging_deferred_update(void)
{
int lid_open = lid_is_open();
gpio_set_level(GPIO_BASE_CHG_VDD_EN, !lid_open);
inductive_charging_interrupt(GPIO_LID_OPEN);
}
DECLARE_DEFERRED(inductive_charging_deferred_update);
static void inductive_charging_lid_update(void)
{
/*
* When the lid close signal changes, the coils might still be
* unaligned. Delay here to give the coils time to align before
* we try to clear CHARGE_DONE.
*/
hook_call_deferred(inductive_charging_deferred_update, 5 * SECOND);
}
DECLARE_HOOK(HOOK_LID_CHANGE, inductive_charging_lid_update, HOOK_PRIO_DEFAULT);
static void inductive_charging_init(void)

View File

@@ -15,6 +15,9 @@
#include "timer.h"
#include "util.h"
#define START_CHARGE_DELAY 5000 /* ms */
#define TEST_CHECK_CHARGE_DELAY (START_CHARGE_DELAY + 500) /* ms */
static void wait_for_lid_debounce(void)
{
while (lid_is_open() != gpio_get_level(GPIO_LID_OPEN))
@@ -34,13 +37,21 @@ static int test_lid(void)
gpio_set_level(GPIO_CHARGE_DONE, 0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
/* Close the lid. Transmitter should be enabled. */
/*
* Close the lid. The EC should wait for a second before
* enabling transmitter.
*/
set_lid_open(0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
msleep(TEST_CHECK_CHARGE_DELAY);
/* Transmitter should now be enabled. */
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 1);
/* Open the lid. Charging should stop. */
set_lid_open(1);
msleep(TEST_CHECK_CHARGE_DELAY);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
@@ -51,6 +62,7 @@ static int test_charge_done(void)
{
/* Close the lid to start charging */
set_lid_open(0);
msleep(TEST_CHECK_CHARGE_DELAY);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 1);
@@ -71,12 +83,14 @@ static int test_lid_open_during_charging(void)
{
/* Close the lid. Start charging. */
set_lid_open(0);
msleep(TEST_CHECK_CHARGE_DELAY);
gpio_set_level(GPIO_CHARGE_DONE, 0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 1);
/* Open the lid. Transmitter should be turned off. */
set_lid_open(1);
msleep(TEST_CHECK_CHARGE_DELAY);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
@@ -91,6 +105,30 @@ static int test_lid_open_during_charging(void)
return EC_SUCCESS;
}
static int test_clear_charge_done(void)
{
/* Lid is open initially. CHARGE_DONE is set. */
set_lid_open(1);
msleep(TEST_CHECK_CHARGE_DELAY);
gpio_set_level(GPIO_CHARGE_DONE, 1);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
/* Close the lid. Charging should start. */
set_lid_open(0);
msleep(TEST_CHECK_CHARGE_DELAY);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 1);
gpio_set_level(GPIO_CHARGE_DONE, 0);
/* Charge is done. */
gpio_set_level(GPIO_CHARGE_DONE, 1);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
return EC_SUCCESS;
}
void run_test(void)
{
test_reset();
@@ -98,6 +136,7 @@ void run_test(void)
RUN_TEST(test_lid);
RUN_TEST(test_charge_done);
RUN_TEST(test_lid_open_during_charging);
RUN_TEST(test_clear_charge_done);
test_print_result();
}