summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/extpower_kirby.c31
1 files 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);