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>
This commit is contained in:
Vijay Hiremath
2016-07-01 19:03:12 -07:00
committed by chrome-bot
parent 0f8a0fad8a
commit d684e2a678
8 changed files with 124 additions and 25 deletions

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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) \

View File

@@ -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)
{

View File

@@ -40,6 +40,7 @@
/* Charger */
#define CONFIG_CHARGE_MANAGER
#define CONFIG_CHARGE_RAMP
#define CONFIG_CHARGER
#define CONFIG_CHARGER_V2
#define CONFIG_CHARGER_BD99955

View File

@@ -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) \

View File

@@ -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;

View File

@@ -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 */