diff options
author | Philip Chen <philipchen@google.com> | 2018-02-06 18:14:56 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-02-28 15:21:08 -0800 |
commit | 2f1e99bcef7165c051b08bc365ef6e1f689843e0 (patch) | |
tree | e8cb1da5a1225a8dbc48236d724f114684fafffb /driver | |
parent | 7a0a4d639304dde28fe3ce0b3963f1789603ed5d (diff) | |
download | chrome-ec-2f1e99bcef7165c051b08bc365ef6e1f689843e0.tar.gz |
charger/rt946x: Support BC 1.2
BUG=b:65446459
BRANCH=none
TEST=Charge Scarlet rev3 with SDP and DCP.
Change-Id: I84fb64953c380b96ec852dca2c981331801e4416
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/905399
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/charger/rt946x.c | 82 | ||||
-rw-r--r-- | driver/charger/rt946x.h | 23 |
2 files changed, 102 insertions, 3 deletions
diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c index c934d346de..d8f3065311 100644 --- a/driver/charger/rt946x.c +++ b/driver/charger/rt946x.c @@ -8,6 +8,7 @@ #include "battery.h" #include "battery_smart.h" #include "charger.h" +#include "charge_manager.h" #include "common.h" #include "compile_time_macros.h" #include "config.h" @@ -18,6 +19,7 @@ #include "rt946x.h" #include "task.h" #include "timer.h" +#include "usb_charge.h" #include "util.h" /* Console output macros */ @@ -82,7 +84,7 @@ enum rt946x_irq { static uint8_t rt946x_irqmask[RT946X_IRQ_COUNT] = { 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, #ifdef CONFIG_CHARGER_RT9467 - 0xFF, + 0xFC, #endif }; @@ -354,8 +356,12 @@ static int rt946x_init_setting(void) if (rv) return rv; #endif - /* Disable BC12 detection */ + /* Enable/Disable BC 1.2 detection */ +#ifdef HAS_TASK_USB_CHG + rv = rt946x_enable_bc12_detection(1); +#else rv = rt946x_enable_bc12_detection(0); +#endif if (rv) return rv; /* Disable WDT */ @@ -783,6 +789,78 @@ static void rt946x_init(void) } DECLARE_HOOK(HOOK_INIT, rt946x_init, HOOK_PRIO_INIT_I2C + 1); +#ifdef HAS_TASK_USB_CHG +static int rt946x_get_bc12_device_type(void) +{ + int reg; + + if (rt946x_read8(RT946X_REG_DPDM1, ®)) + return CHARGE_SUPPLIER_NONE; + + switch (reg & RT946X_MASK_BC12_TYPE) { + case RT946X_MASK_SDP: + return CHARGE_SUPPLIER_BC12_SDP; + case RT946X_MASK_CDP: + return CHARGE_SUPPLIER_BC12_CDP; + case RT946X_MASK_DCP: + return CHARGE_SUPPLIER_BC12_DCP; + default: + return CHARGE_SUPPLIER_NONE; + } +} + +static int rt946x_get_bc12_ilim(int charge_supplier) +{ + switch (charge_supplier) { + case CHARGE_SUPPLIER_BC12_CDP: + case CHARGE_SUPPLIER_BC12_DCP: + return 1500; + case CHARGE_SUPPLIER_BC12_SDP: + default: + return USB_CHARGER_MIN_CURR_MA; + } +} + +void rt946x_interrupt(enum gpio_signal signal) +{ + task_wake(TASK_ID_USB_CHG); +} + +void usb_charger_task(void *u) +{ + struct charge_port_info charge; + int bc12_type = CHARGE_SUPPLIER_NONE; + int reg = 0; + + charge.voltage = USB_CHARGER_VOLTAGE_MV; + + while (1) { + rt946x_read8(RT946X_REG_DPDMIRQ, ®); + + /* VBUS attach event */ + if (reg & RT946X_MASK_DPDMIRQ_ATTACH) { + bc12_type = rt946x_get_bc12_device_type(); + if (bc12_type != CHARGE_SUPPLIER_NONE) { + charge.current = + rt946x_get_bc12_ilim(bc12_type); + charge_manager_update_charge(bc12_type, + 0, &charge); + rt946x_enable_bc12_detection(0); + } + } + + /* VBUS detach event */ + if (reg & RT946X_MASK_DPDMIRQ_DETACH) { + charge.current = 0; + charge_manager_update_charge(bc12_type, 0, &charge); + rt946x_enable_bc12_detection(1); + } + + task_wait_event(-1); + } +} +#endif /* HAS_TASK_USB_CHG */ + /* Non-standard interface functions */ int rt946x_enable_charger_boost(int en) diff --git a/driver/charger/rt946x.h b/driver/charger/rt946x.h index 80f18bd4ee..a31415b136 100644 --- a/driver/charger/rt946x.h +++ b/driver/charger/rt946x.h @@ -219,7 +219,19 @@ #define RT946X_MASK_ADC_START (1 << RT946X_SHIFT_ADC_START) /* ========== CHGDPDM1 0x12 ============ */ -#define RT946X_MASK_USBCHGEN (1 << 7) +#define RT946X_SHIFT_USBCHGEN 7 +#define RT946X_SHIFT_DCP 2 +#define RT946X_SHIFT_CDP 1 +#define RT946X_SHIFT_SDP 0 + +#define RT946X_MASK_USBCHGEN (1 << RT946X_SHIFT_USBCHGEN) +#define RT946X_MASK_DCP (1 << RT946X_SHIFT_DCP) +#define RT946X_MASK_CDP (1 << RT946X_SHIFT_CDP) +#define RT946X_MASK_SDP (1 << RT946X_SHIFT_SDP) + +#define RT946X_MASK_BC12_TYPE (RT946X_MASK_DCP | \ + RT946X_MASK_CDP | \ + RT946X_MASK_SDP) /* ========== CHGCTRL18 0x1A ============ */ #define RT946X_SHIFT_IRCMP_RES 3 @@ -260,6 +272,12 @@ #define RT946X_MASK_CHG_VBATOV (1 << RT946X_SHIFT_CHG_VBATOV) #define RT946X_MASK_CHG_VBUSOV (1 << RT946X_SHIFT_CHG_VBUSOV) +/* ========== DPDMIRQ 0x66 ============ */ +#ifdef CONFIG_CHARGER_RT9467 +#define RT946X_MASK_DPDMIRQ_ATTACH 0x01 +#define RT946X_MASK_DPDMIRQ_DETACH 0x02 +#endif + /* ========== Variant-specific configuration ============ */ #if defined(CONFIG_CHARGER_RT9466) #define RT946X_CHARGER_NAME "rt9466" @@ -273,6 +291,9 @@ /* RT946x specific interface functions */ +/* Interrupt handler for rt946x */ +void rt946x_interrupt(enum gpio_signal signal); + /* Enable/Disable rt946x (in charger or boost mode) */ int rt946x_enable_charger_boost(int en); |