diff options
-rw-r--r-- | board/kirby/board.c | 9 | ||||
-rw-r--r-- | board/kirby/board.h | 2 | ||||
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/charger_bq24192.c | 13 | ||||
-rw-r--r-- | common/extpower_kirby.c | 72 | ||||
-rw-r--r-- | include/charger.h | 6 |
6 files changed, 98 insertions, 5 deletions
diff --git a/board/kirby/board.c b/board/kirby/board.c index bea56ee462..87b3586877 100644 --- a/board/kirby/board.c +++ b/board/kirby/board.c @@ -32,16 +32,15 @@ const struct gpio_info gpio_list[] = { {"XPSHOLD", GPIO_E, (1<<5), GPIO_INT_RISING, gaia_power_event}, {"CHARGER_INT_L", GPIO_E, (1<<2), GPIO_INT_FALLING, NULL /*pmu_irq_handler*/}, - {"USB_CHG_INT", GPIO_E, (1<<15), GPIO_INT_RISING, - NULL /*extpower_interrupt*/}, + {"USB_CHG_INT", GPIO_E, (1<<15), GPIO_INT_FALLING, + extpower_interrupt}, {"USBPD_INT_L", GPIO_E, (1<<1), GPIO_INT_FALLING, NULL /*extpower_interrupt*/}, {"LID_OPEN", GPIO_E, (1<<6), GPIO_INT_BOTH, lid_interrupt}, {"SUSPEND_L", GPIO_E, (1<<3), GPIO_INT_BOTH, gaia_suspend_event}, {"SPI1_NSS", GPIO_A, (1<<4), GPIO_INT_BOTH | GPIO_PULL_UP, spi_event}, - {"AC_PRESENT_L", GPIO_A, (1<<1), GPIO_INT_BOTH, - NULL /*extpower_interrupt*/}, + {"AC_PRESENT_L", GPIO_A, (1<<1), GPIO_INT_BOTH, extpower_interrupt}, {"KB_IN00", GPIO_E, (1<<7), GPIO_KB_INPUT, keyboard_raw_gpio_interrupt}, {"KB_IN01", GPIO_E, (1<<8), GPIO_KB_INPUT, @@ -64,7 +63,7 @@ const struct gpio_info gpio_list[] = { {"CHARGER_EN_L", GPIO_B, (1<<8), GPIO_OUT_HIGH, NULL}, {"EC_INT", GPIO_C, (1<<9), GPIO_ODR_HIGH, NULL}, {"EC_INT2", GPIO_B, (1<<4), GPIO_ODR_HIGH, NULL}, - {"ID_MUX", GPIO_B, (1<<11), GPIO_ODR_HIGH, NULL}, + {"ID_MUX", GPIO_B, (1<<11), GPIO_ODR_LOW, NULL}, {"BCHGR_OTG", GPIO_B, (1<<12), GPIO_OUT_LOW, NULL}, {"BCHGR_PSEL", GPIO_B, (1<<14), GPIO_OUT_LOW, NULL}, {"EN_PP3300", GPIO_C, (1<<11), GPIO_OUT_LOW, NULL}, diff --git a/board/kirby/board.h b/board/kirby/board.h index 7cd7c87218..24d14d6459 100644 --- a/board/kirby/board.h +++ b/board/kirby/board.h @@ -17,11 +17,13 @@ #define CONFIG_CHIPSET_GAIA #undef CONFIG_CHIPSET_HAS_PP1350 #undef CONFIG_CHIPSET_HAS_PP5000 +#define CONFIG_EXTPOWER_KIRBY #define CONFIG_HOST_COMMAND_STATUS #define CONFIG_I2C #define CONFIG_KEYBOARD_PROTOCOL_MKBP #define CONFIG_SPI #define CONFIG_PWM +#define CONFIG_USB_SWITCH_TSU6721 #ifndef __ASSEMBLER__ diff --git a/common/build.mk b/common/build.mk index fbc78039b5..fa3ad7b24e 100644 --- a/common/build.mk +++ b/common/build.mk @@ -41,6 +41,7 @@ common-$(CONFIG_PMU_TPS65090)+=pmu_tps65090.o common-$(CONFIG_EOPTION)+=eoption.o common-$(CONFIG_EXTPOWER_FALCO)+=extpower_falco.o common-$(CONFIG_EXTPOWER_GPIO)+=extpower_gpio.o +common-$(CONFIG_EXTPOWER_KIRBY)+=extpower_kirby.o common-$(CONFIG_EXTPOWER_SPRING)+=extpower_spring.o common-$(CONFIG_FLASH)+=flash_common.o common-$(CONFIG_FMAP)+=fmap.o diff --git a/common/charger_bq24192.c b/common/charger_bq24192.c index 8939cc9e71..377af57665 100644 --- a/common/charger_bq24192.c +++ b/common/charger_bq24192.c @@ -9,6 +9,7 @@ #include "charger_bq24192.h" #include "common.h" #include "console.h" +#include "gpio.h" #include "hooks.h" #include "i2c.h" #include "printf.h" @@ -57,6 +58,18 @@ static int bq24192_watchdog_reset(void) bq24192_write(BQ24192_REG_POWER_ON_CFG, val); } +int charger_enable_otg_power(int enabled) +{ + int val, rv; + + gpio_set_level(GPIO_BCHGR_OTG, enabled); + rv = bq24192_read(BQ24192_REG_POWER_ON_CFG, &val); + if (rv) + return rv; + val = (val & ~0x30) | (enabled ? 0x20 : 0x10); + return bq24192_write(BQ24192_REG_POWER_ON_CFG, val); +} + int charger_set_input_current(int input_current) { int i, value, rv; diff --git a/common/extpower_kirby.c b/common/extpower_kirby.c new file mode 100644 index 0000000000..ceb4220b4f --- /dev/null +++ b/common/extpower_kirby.c @@ -0,0 +1,72 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* USB charging control for kirby board */ + +#include "battery.h" +#include "charger.h" +#include "chipset.h" +#include "console.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" +#include "task.h" +#include "timer.h" +#include "tsu6721.h" +#include "util.h" + +/* Console output macros */ +#define CPUTS(outstr) cputs(CC_USBCHARGE, outstr) +#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) + +int extpower_is_present(void) +{ + return !gpio_get_level(GPIO_AC_PRESENT_L); +} + +static void extpower_deferred(void) +{ + int int_val, dev_type, is_otg; + 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) { + last_ac = ac; + hook_notify(HOOK_AC_CHANGE); + } + + 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"); + } +} +DECLARE_DEFERRED(extpower_deferred); + +/*****************************************************************************/ +/* Hooks */ + +static void extpower_init(void) +{ + tsu6721_init(); + gpio_enable_interrupt(GPIO_USB_CHG_INT); + gpio_enable_interrupt(GPIO_AC_PRESENT_L); +} +DECLARE_HOOK(HOOK_INIT, extpower_init, HOOK_PRIO_LAST); + +void extpower_interrupt(enum gpio_signal signal) +{ + hook_call_deferred(extpower_deferred, 0); +} diff --git a/include/charger.h b/include/charger.h index 9b75bb95b2..c3c2b06cd4 100644 --- a/include/charger.h +++ b/include/charger.h @@ -45,6 +45,12 @@ int charger_get_status(int *status); int charger_set_mode(int mode); /** + * For chargers that are able to supply 5V output power for OTG dongle, this + * function enables or disables 5V power output. + */ +int charger_enable_otg_power(int enabled); + +/** * Return the closest match the charger can supply to the requested current. * * @param current Requested current in mA. |