mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-31 02:51:26 +00:00
glados: isl9237: add HW charge ramping
Add HW charge ramping option and enable on glados. Modify charge_manager to enable/disable HW charge ramping when option is defined. Unfortunately, the isl9237 doesn't have a way to determine what the input current limit has settled on, so the EC will always report the max input current for that supplier. BUG=chrome-os-partner:47335 BRANCH=none TEST=plug in CDP, SDP, DCP, type-C, and PD charger. Make sure we ramp to a reasonable value for the correct suppliers. Make sure we don't ramp for type-C and PD chargers. Change-Id: Ib541fa0be48d8f4d261c71b853b0ee72b2adbf6b Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/311301 Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
@@ -321,6 +321,40 @@ void board_set_charge_limit(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_PROPRIETARY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the maximum allowed input current
|
||||
*/
|
||||
int board_get_ramp_current_limit(int supplier, int sup_curr)
|
||||
{
|
||||
switch (supplier) {
|
||||
case CHARGE_SUPPLIER_BC12_DCP:
|
||||
return 2000;
|
||||
case CHARGE_SUPPLIER_BC12_SDP:
|
||||
return 1000;
|
||||
case CHARGE_SUPPLIER_BC12_CDP:
|
||||
case CHARGE_SUPPLIER_PROPRIETARY:
|
||||
return sup_curr;
|
||||
default:
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable or disable input devices, based upon chipset state and tablet mode */
|
||||
static void enable_input_devices(void)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define CONFIG_BOARD_VERSION
|
||||
#define CONFIG_BUTTON_COUNT 2
|
||||
#define CONFIG_CHARGE_MANAGER
|
||||
#define CONFIG_CHARGE_RAMP_HW
|
||||
|
||||
#define CONFIG_CHARGER
|
||||
#define CONFIG_CHARGER_V2
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "battery.h"
|
||||
#include "charge_manager.h"
|
||||
#include "charge_ramp.h"
|
||||
#include "charger.h"
|
||||
#include "console.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
@@ -511,6 +512,10 @@ static void charge_manager_refresh(void)
|
||||
new_port, new_supplier, new_charge_current,
|
||||
registration_time[new_port]);
|
||||
#else
|
||||
#ifdef CONFIG_CHARGE_RAMP_HW
|
||||
/* Enable or disable charge ramp */
|
||||
charger_set_hw_ramp(board_is_ramp_allowed(new_supplier));
|
||||
#endif
|
||||
board_set_charge_limit(new_charge_current);
|
||||
#endif
|
||||
CPRINTS("CL: p%d s%d i%d v%d", new_port, new_supplier,
|
||||
|
||||
@@ -259,6 +259,23 @@ int charger_post_init(void)
|
||||
/* Hardware current ramping (aka ICO: Input Current Optimizer) */
|
||||
|
||||
#ifdef CONFIG_CHARGE_RAMP_HW
|
||||
int charger_set_hw_ramp(int enable)
|
||||
{
|
||||
int val, rv;
|
||||
|
||||
rv = i2c_read8(I2C_PORT_CHARGER, BQ2589X_ADDR, BQ2589X_REG_CFG1, &val);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
if (enable)
|
||||
val |= BQ2589X_CFG1_ICO_EN;
|
||||
else
|
||||
val &= ~BQ2589X_CFG1_ICO_EN;
|
||||
|
||||
return i2c_write8(I2C_PORT_CHARGER, BQ2589X_ADDR, BQ2589X_REG_CFG1,
|
||||
val);
|
||||
}
|
||||
|
||||
int chg_ramp_is_stable(void)
|
||||
{
|
||||
int val, rv;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
/* REG02 : first configuration register bit definitions */
|
||||
#define BQ2589X_CFG1_CONV_START (1<<7)
|
||||
#define BQ2589X_CFG1_ICO_EN (1<<4)
|
||||
#define BQ2589X_CFG1_AUTO_DPDM_EN (1<<0)
|
||||
|
||||
/* REG03 : second configuration register bit definitions */
|
||||
|
||||
@@ -216,15 +216,30 @@ int charger_set_voltage(int voltage)
|
||||
|
||||
int charger_post_init(void)
|
||||
{
|
||||
int rv, reg;
|
||||
|
||||
#ifdef CONFIG_TRICKLE_CHARGING
|
||||
int rv;
|
||||
const struct battery_info *bi = battery_get_info();
|
||||
|
||||
rv = raw_write16(ISL9237_REG_SYS_VOLTAGE_MIN, bi->voltage_min);
|
||||
if (rv)
|
||||
return rv;
|
||||
#endif
|
||||
return EC_SUCCESS;
|
||||
|
||||
rv = charger_get_option(®);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
#ifdef CONFIG_CHARGE_RAMP_HW
|
||||
/* Set input voltage regulation reference voltage for charge ramp */
|
||||
reg &= ~ISL9237_C0_VREG_REF_MASK;
|
||||
reg |= ISL9237_C0_VREG_REF_4200;
|
||||
#else
|
||||
/* Disable voltage regulation loop to disable charge ramp */
|
||||
reg |= ISL9237_C0_DISABLE_VREG;
|
||||
#endif
|
||||
|
||||
return charger_set_option(reg);
|
||||
}
|
||||
|
||||
int charger_discharge_on_ac(int enable)
|
||||
@@ -245,6 +260,50 @@ int charger_discharge_on_ac(int enable)
|
||||
return raw_write16(ISL9237_REG_CONTROL1, control1);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hardware current ramping */
|
||||
|
||||
#ifdef CONFIG_CHARGE_RAMP_HW
|
||||
int charger_set_hw_ramp(int enable)
|
||||
{
|
||||
int rv, reg;
|
||||
|
||||
rv = charger_get_option(®);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
/* HW ramp is controlled by input voltage regulation reference bits */
|
||||
if (enable)
|
||||
reg &= ~ISL9237_C0_DISABLE_VREG;
|
||||
else
|
||||
reg |= ISL9237_C0_DISABLE_VREG;
|
||||
|
||||
return charger_set_option(reg);
|
||||
}
|
||||
|
||||
int chg_ramp_is_stable(void)
|
||||
{
|
||||
/*
|
||||
* Since ISL cannot read the current limit that the ramp has settled
|
||||
* on, then we can never consider the ramp stable, because we never
|
||||
* know what the stable limit is.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chg_ramp_is_detected(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int chg_ramp_get_current_limit(void)
|
||||
{
|
||||
/* ISL doesn't have a way to get this info */
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_CHARGE_RAMP_HW */
|
||||
|
||||
|
||||
#ifdef CONFIG_CHARGER_PSYS
|
||||
static void charger_enable_psys(void)
|
||||
{
|
||||
|
||||
@@ -111,6 +111,7 @@ int charger_manufacturer_id(int *id);
|
||||
int charger_device_id(int *id);
|
||||
int charger_get_option(int *option);
|
||||
int charger_set_option(int option);
|
||||
int charger_set_hw_ramp(int enable);
|
||||
|
||||
/* Print all charger info for debugging purposes */
|
||||
void print_charger_debug(void);
|
||||
|
||||
Reference in New Issue
Block a user