From b28e92a855ea43b9003dd9bae73fefe3c304fd53 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 10 Sep 2013 16:20:13 +0800 Subject: [PATCH] kirby: Detect OTG dongle on EC boot This fixes the problem that after an EC reboot, OTG dongle stops working. BUG=chrome-os-partner:21964 TEST=Reboot EC and boot from OTG dongle. BRANCH=None Change-Id: Ieec43f612d01114d13afb40293acfd0b3e324e8c Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/168737 Reviewed-by: Vincent Palatin --- common/extpower_kirby.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/common/extpower_kirby.c b/common/extpower_kirby.c index ceb4220b4f..a10e42b1d3 100644 --- a/common/extpower_kirby.c +++ b/common/extpower_kirby.c @@ -26,15 +26,29 @@ int extpower_is_present(void) return !gpio_get_level(GPIO_AC_PRESENT_L); } +static void extpower_update_otg(void) +{ + int dev_type, is_otg; + + dev_type = tsu6721_get_device_type(); + is_otg = dev_type & TSU6721_TYPE_OTG; + + if (is_otg && !gpio_get_level(GPIO_BCHGR_OTG)) { + charger_enable_otg_power(1); + CPRINTF("[%T OTG power enabled]\n"); + } else if (!is_otg && gpio_get_level(GPIO_BCHGR_OTG)) { + charger_enable_otg_power(0); + CPRINTF("[%T OTG power disabled]\n"); + } +} + static void extpower_deferred(void) { - int int_val, dev_type, is_otg; + int int_val; int ac; static int last_ac = -1; int_val = tsu6721_get_interrupts(); - dev_type = tsu6721_get_device_type(); - is_otg = dev_type & TSU6721_TYPE_OTG; ac = extpower_is_present(); if (last_ac != ac) { @@ -45,13 +59,7 @@ static void extpower_deferred(void) if (!int_val) return; - if (is_otg && !gpio_get_level(GPIO_BCHGR_OTG)) { - charger_enable_otg_power(1); - CPRINTF("[%T OTG power enabled]\n"); - } else if (!is_otg && gpio_get_level(GPIO_BCHGR_OTG)) { - charger_enable_otg_power(0); - CPRINTF("[%T OTG power disabled]\n"); - } + extpower_update_otg(); } DECLARE_DEFERRED(extpower_deferred); @@ -60,9 +68,10 @@ DECLARE_DEFERRED(extpower_deferred); static void extpower_init(void) { - tsu6721_init(); + tsu6721_reset(); gpio_enable_interrupt(GPIO_USB_CHG_INT); gpio_enable_interrupt(GPIO_AC_PRESENT_L); + extpower_update_otg(); } DECLARE_HOOK(HOOK_INIT, extpower_init, HOOK_PRIO_LAST);