diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2016-07-01 19:03:12 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-29 17:12:39 -0700 |
commit | d684e2a6782f2eba7939346b79ae5db3f96477e6 (patch) | |
tree | 67ef0611023210a389587b70cd47366c8d4afa8e | |
parent | 0f8a0fad8a4beb0036327d2781abed04983dba60 (diff) | |
download | chrome-ec-d684e2a6782f2eba7939346b79ae5db3f96477e6.tar.gz |
Amenia/Reef: Add software charge ramp for BC1.2 & nonstandard BC1.2
Setting the higher limit of input current for BC1.2 & nonstandard
BC1.2 devices than their maximum current rating results in an
anti-collapse. BD99955 does not have a way to do hardware charge
ramp or to detect the anti-collapse for these chargers. Hence added
code to support software charge ramp for BC1.2 & nonstandard BC1.2
so that the input current is set to maximum of the respective
charger.
BUG=chrome-os-partner:54990, chrome-os-partner:55517
BRANCH=none
TEST=Manually tested on Amenia & Reef. BC1.2 & nonstandard BC12
devices can negotiate their respective maximum current rating.
Change-Id: I0033b3662362bd7822ad01cf4360d18caabd5249
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/358106
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | board/amenia/board.c | 43 | ||||
-rw-r--r-- | board/amenia/board.h | 1 | ||||
-rw-r--r-- | board/amenia/ec.tasklist | 1 | ||||
-rw-r--r-- | board/reef/board.c | 43 | ||||
-rw-r--r-- | board/reef/board.h | 1 | ||||
-rw-r--r-- | board/reef/ec.tasklist | 1 | ||||
-rw-r--r-- | driver/charger/bd99955.c | 49 | ||||
-rw-r--r-- | driver/charger/bd99955.h | 10 |
8 files changed, 124 insertions, 25 deletions
diff --git a/board/amenia/board.c b/board/amenia/board.c index 7026903ab1..82bfb238b2 100644 --- a/board/amenia/board.c +++ b/board/amenia/board.c @@ -9,6 +9,7 @@ #include "als.h" #include "button.h" #include "charge_manager.h" +#include "charge_ramp.h" #include "charge_state.h" #include "charger.h" #include "chipset.h" @@ -361,6 +362,48 @@ void board_set_charge_limit(int port, int supplier, int charge_ma) CONFIG_CHARGER_INPUT_CURRENT)); } +/** + * Return whether ramping is allowed for given supplier + */ +int board_is_ramp_allowed(int supplier) +{ + /* Don't allow ramping in RO when write protected */ + if (system_get_image_copy() != SYSTEM_IMAGE_RW + && system_is_locked()) + return 0; + else + return (supplier == CHARGE_SUPPLIER_BC12_DCP || + supplier == CHARGE_SUPPLIER_BC12_SDP || + supplier == CHARGE_SUPPLIER_BC12_CDP || + supplier == CHARGE_SUPPLIER_OTHER); +} + +/** + * Return the maximum allowed input current + */ +int board_get_ramp_current_limit(int supplier, int sup_curr) +{ + return bd99955_get_bc12_ilim(supplier); +} + +/** + * Return if board is consuming full amount of input current + */ +int board_is_consuming_full_charge(void) +{ + int chg_perc = charge_get_percent(); + + return chg_perc > 2 && chg_perc < 95; +} + +/** + * Return if VBUS is sagging too low + */ +int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state) +{ + return charger_get_vbus_level() < BD99955_BC12_MIN_VOLTAGE; +} + /* Enable or disable input devices, based upon chipset state and tablet mode */ static void enable_input_devices(void) { diff --git a/board/amenia/board.h b/board/amenia/board.h index ac846ff42c..6b09c33e17 100644 --- a/board/amenia/board.h +++ b/board/amenia/board.h @@ -28,6 +28,7 @@ #define CONFIG_BOARD_VERSION #define CONFIG_BUTTON_COUNT 2 #define CONFIG_CHARGE_MANAGER +#define CONFIG_CHARGE_RAMP #define CONFIG_CHARGER #define CONFIG_CHARGER_V2 diff --git a/board/amenia/ec.tasklist b/board/amenia/ec.tasklist index 6abae5e7ba..b7ed91b073 100644 --- a/board/amenia/ec.tasklist +++ b/board/amenia/ec.tasklist @@ -19,6 +19,7 @@ #define CONFIG_TASK_LIST \ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(ALS, als_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(CHG_RAMP, chg_ramp_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(USB_CHG, usb_charger_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_NOTEST(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \ diff --git a/board/reef/board.c b/board/reef/board.c index 93dcb2dfeb..d7343e9ffe 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -10,6 +10,7 @@ #include "als.h" #include "button.h" #include "charge_manager.h" +#include "charge_ramp.h" #include "charge_state.h" #include "charger.h" #include "chipset.h" @@ -533,6 +534,48 @@ void board_set_charge_limit(int port, int supplier, int charge_ma) CONFIG_CHARGER_INPUT_CURRENT)); } +/** + * Return whether ramping is allowed for given supplier + */ +int board_is_ramp_allowed(int supplier) +{ + /* Don't allow ramping in RO when write protected */ + if (system_get_image_copy() != SYSTEM_IMAGE_RW + && system_is_locked()) + return 0; + else + return (supplier == CHARGE_SUPPLIER_BC12_DCP || + supplier == CHARGE_SUPPLIER_BC12_SDP || + supplier == CHARGE_SUPPLIER_BC12_CDP || + supplier == CHARGE_SUPPLIER_OTHER); +} + +/** + * Return the maximum allowed input current + */ +int board_get_ramp_current_limit(int supplier, int sup_curr) +{ + return bd99955_get_bc12_ilim(supplier); +} + +/** + * Return if board is consuming full amount of input current + */ +int board_is_consuming_full_charge(void) +{ + int chg_perc = charge_get_percent(); + + return chg_perc > 2 && chg_perc < 95; +} + +/** + * Return if VBUS is sagging too low + */ +int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state) +{ + return charger_get_vbus_level() < BD99955_BC12_MIN_VOLTAGE; +} + /* Enable or disable input devices, based upon chipset state and tablet mode */ static void enable_input_devices(void) { diff --git a/board/reef/board.h b/board/reef/board.h index 109eca8dcc..02efe5b454 100644 --- a/board/reef/board.h +++ b/board/reef/board.h @@ -40,6 +40,7 @@ /* Charger */ #define CONFIG_CHARGE_MANAGER +#define CONFIG_CHARGE_RAMP #define CONFIG_CHARGER #define CONFIG_CHARGER_V2 #define CONFIG_CHARGER_BD99955 diff --git a/board/reef/ec.tasklist b/board/reef/ec.tasklist index fe4d3eaa10..4ea21ebef8 100644 --- a/board/reef/ec.tasklist +++ b/board/reef/ec.tasklist @@ -23,6 +23,7 @@ #define CONFIG_TASK_LIST \ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(ALS, als_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(CHG_RAMP, chg_ramp_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(USB_CHG, usb_charger_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_NOTEST(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \ diff --git a/driver/charger/bd99955.c b/driver/charger/bd99955.c index d73669dbe9..2f0af04145 100644 --- a/driver/charger/bd99955.c +++ b/driver/charger/bd99955.c @@ -208,31 +208,6 @@ static int bd99955_get_bc12_device_type(enum bd99955_charge_port port) } } -static int bd99955_get_bc12_ilim(int charge_supplier) -{ - switch (charge_supplier) { - case CHARGE_SUPPLIER_BC12_CDP: - return 1500; - case CHARGE_SUPPLIER_BC12_DCP: - return 2000; - case CHARGE_SUPPLIER_BC12_SDP: - return 900; - case CHARGE_SUPPLIER_OTHER: - /* - * TODO: Setting the higher limit of current may result in an - * anti-collapse hence limiting the current to 1A. (If the - * charger response is slow or BD99955 cannot detect the type - * of the charger, anti-collapse status is not updated in the - * VBUS/VCC_STATUS register. Hence it is not possible to decide - * whether to overwrite the ILIM values to come out of the - * anti-collapse). - */ - return 1000; - default: - return 500; - } -} - static int bd99955_enable_usb_switch(enum bd99955_charge_port port, enum usb_switch setting) { @@ -824,6 +799,30 @@ int bd99955_get_battery_temp(int *temp_ptr) #endif #ifdef HAS_TASK_USB_CHG +int bd99955_get_bc12_ilim(int charge_supplier) +{ + switch (charge_supplier) { + case CHARGE_SUPPLIER_BC12_CDP: + return 1500; + case CHARGE_SUPPLIER_BC12_DCP: + return 2000; + case CHARGE_SUPPLIER_BC12_SDP: + return 900; + case CHARGE_SUPPLIER_OTHER: +#ifdef CONFIG_CHARGE_RAMP + return 2400; +#else + /* + * Setting the higher limit of current may result in an + * anti-collapse hence limiting the current to 1A. + */ + return 1000; +#endif + default: + return 500; + } +} + int bd99955_bc12_enable_charging(enum bd99955_charge_port port, int enable) { int rv; diff --git a/driver/charger/bd99955.h b/driver/charger/bd99955.h index e4c557eb1d..41334ecb1c 100644 --- a/driver/charger/bd99955.h +++ b/driver/charger/bd99955.h @@ -46,6 +46,14 @@ enum bd99955_charge_port { #define DISCHARGE_VSYSREG 8960 #define CHARGE_VSYSREG 6144 +/* + * BC1.2 minimum voltage threshold. + * BC1.2 charging port output voltage range is 4.75V to 5.25V, + * BD99955 Anti-Collapse Threshold Voltage Accuracy is -100mV to +100mV, + * and Delta of 50mV. + */ +#define BD99955_BC12_MIN_VOLTAGE 4600 + /* Battery Charger Commands */ #define BD99955_CMD_CHG_CURRENT 0x14 #define BD99955_CMD_CHG_VOLTAGE 0x15 @@ -301,6 +309,8 @@ static inline enum bd99955_charge_port bd99955_pd_port_to_chg_port(int port) int bd99955_is_vbus_provided(int port); /* Select input port from {VCC, VBUS, VCC&VBUS, NONE}. */ int bd99955_select_input_port(enum bd99955_charge_port port); +/* Get input current limit for BC1.2 suppliers */ +int bd99955_get_bc12_ilim(int charge_supplier); /* Enable/Disable charging triggered by BC1.2 */ int bd99955_bc12_enable_charging(enum bd99955_charge_port port, int enable); /* Interrupt handler for USB charger VBUS */ |