summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2016-12-14 10:58:32 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-01-02 14:04:12 -0800
commit63ca2d693f39bdf8cad3f92234f4c757df20e87d (patch)
tree1bc47795ed25d303e82be603d400a493e38a2c0b
parentfd498b77c5adb8ac4b17770b99797ab6ce90d0d7 (diff)
downloadchrome-ec-63ca2d693f39bdf8cad3f92234f4c757df20e87d.tar.gz
charger_profile: Add common code for charger profile override
Added common code for charger profile override for fast charging. Fast charging configs can be defined in the respective board battery file and use the common code for imposing the custom data. BUG=chrome-os-partner:59393 BRANCH=none TEST=Enabled the config on Reef. Manually overrode the temperature and voltage. Observed correct charge profile config is selected for each tests. Change-Id: I075d271258470b98d38e4d5395d749469d3fd469 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/407928 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r--board/reef/battery.c250
-rw-r--r--board/reef/board.h1
-rw-r--r--common/build.mk1
-rw-r--r--common/charge_state_v2.c1
-rw-r--r--common/charger_profile_override.c194
-rw-r--r--include/charge_state_v2.h23
-rw-r--r--include/charger_profile_override.h92
-rw-r--r--include/config.h8
8 files changed, 391 insertions, 179 deletions
diff --git a/board/reef/battery.c b/board/reef/battery.c
index 64cd90cd97..307b44c115 100644
--- a/board/reef/battery.c
+++ b/board/reef/battery.c
@@ -10,6 +10,7 @@
#include "bd9995x.h"
#include "charge_ramp.h"
#include "charge_state.h"
+#include "charger_profile_override.h"
#include "console.h"
#include "ec_commands.h"
#include "extpower.h"
@@ -26,21 +27,87 @@ enum battery_type {
BATTERY_TYPE_COUNT,
};
+enum temp_range {
+ TEMP_RANGE_0,
+ TEMP_RANGE_1,
+ TEMP_RANGE_2,
+ TEMP_RANGE_3,
+ TEMP_RANGE_4,
+};
+
struct board_batt_params {
char *manuf_name;
int ship_mode_reg;
int ship_mode_data;
struct battery_info batt_info;
+ const struct fast_charge_params *fast_chg_params;
int (*batt_init)(void);
};
#define DEFAULT_BATTERY_TYPE BATTERY_SONY_CORP
#define SONY_DISCHARGE_DISABLE_FET_BIT (0x01 << 13)
+/* keep track of previous charge profile info */
+static const struct fast_charge_profile *prev_chg_profile_info;
+
static enum battery_present batt_pres_prev = BP_NOT_SURE;
static enum battery_type board_battery_type = BATTERY_TYPE_COUNT;
+static const struct fast_charge_profile fast_charge_smp_cos4870_info[] = {
+ /* < 0C */
+ [TEMP_RANGE_0] = {
+ .temp_c = TEMPC_TENTHS_OF_DEG(-1),
+ .current_mA = {
+ [VOLTAGE_RANGE_LOW] = 0,
+ [VOLTAGE_RANGE_HIGH] = 0,
+ },
+ },
+
+ /* 0C >= && <=15C */
+ [TEMP_RANGE_1] = {
+ .temp_c = TEMPC_TENTHS_OF_DEG(15),
+ .current_mA = {
+ [VOLTAGE_RANGE_LOW] = 944,
+ [VOLTAGE_RANGE_HIGH] = 472,
+ },
+ },
+
+ /* 15C > && <=20C */
+ [TEMP_RANGE_2] = {
+ .temp_c = TEMPC_TENTHS_OF_DEG(20),
+ .current_mA = {
+ [VOLTAGE_RANGE_LOW] = 1416,
+ [VOLTAGE_RANGE_HIGH] = 1416,
+ },
+ },
+
+ /* 20C > && <=45C */
+ [TEMP_RANGE_3] = {
+ .temp_c = TEMPC_TENTHS_OF_DEG(45),
+ .current_mA = {
+ [VOLTAGE_RANGE_LOW] = 3300,
+ [VOLTAGE_RANGE_HIGH] = 3300,
+ },
+ },
+
+ /* > 45C */
+ [TEMP_RANGE_4] = {
+ .temp_c = TEMPC_TENTHS_OF_DEG(CHARGER_PROF_TEMP_C_LAST_RANGE),
+ .current_mA = {
+ [VOLTAGE_RANGE_LOW] = 0,
+ [VOLTAGE_RANGE_HIGH] = 0,
+ },
+ },
+};
+
+static const struct fast_charge_params fast_chg_params_smp_cos4870 = {
+ .total_temp_ranges = ARRAY_SIZE(fast_charge_smp_cos4870_info),
+ .default_temp_range_profile = TEMP_RANGE_2,
+ .vtg_low_limit_mV = 8000,
+ .chg_profile_info = &fast_charge_smp_cos4870_info[0],
+};
+
static int batt_smp_cos4870_init(void)
{
int batt_status;
@@ -71,6 +138,12 @@ static const struct board_batt_params info[] = {
.ship_mode_data = 0xC574,
.batt_init = batt_sony_corp_init,
+ /*
+ * Add fast charging params info for BQ40z555
+ * (TODO: crosbug.com/p/59904)
+ */
+ .fast_chg_params = &fast_chg_params_smp_cos4870,
+
/* Battery info for BQ40z555 (TODO: crosbug.com/p/59904) */
.batt_info = {
.voltage_max = 8700, /* mV */
@@ -99,6 +172,9 @@ static const struct board_batt_params info[] = {
.ship_mode_data = 0x0010,
.batt_init = batt_smp_cos4870_init,
+ /* Fast charging params info for BQ40Z55 */
+ .fast_chg_params = &fast_chg_params_smp_cos4870,
+
/* Battery info for BQ40Z55 */
.batt_info = {
.voltage_max = 8700, /* mV */
@@ -119,6 +195,7 @@ static const struct board_batt_params info[] = {
.discharging_max_c = 60,
},
},
+
/* SMP C22N1626 BATTERY battery specific configurations */
[BATTERY_SMP_C22N1626] = {
.manuf_name = "AS1FNZD3KD",
@@ -126,6 +203,9 @@ static const struct board_batt_params info[] = {
.ship_mode_data = 0x0010,
.batt_init = batt_smp_cos4870_init,
+ /* Fast charging params info for BQ40Z55 */
+ .fast_chg_params = &fast_chg_params_smp_cos4870,
+
/* Battery info for BQ40Z55 */
.batt_info = {
.voltage_max = 8800, /* mV */
@@ -146,6 +226,7 @@ static const struct board_batt_params info[] = {
.discharging_max_c = 60,
},
},
+
/* CPT C22N1626 BATTERY battery specific configurations */
[BATTERY_CPT_C22N1626] = {
.manuf_name = "AS1FOAD3KD",
@@ -153,6 +234,9 @@ static const struct board_batt_params info[] = {
.ship_mode_data = 0x0010,
.batt_init = batt_smp_cos4870_init,
+ /* Fast charging params info for BQ40Z55 */
+ .fast_chg_params = &fast_chg_params_smp_cos4870,
+
/* Battery info for BQ40Z55 */
.batt_info = {
.voltage_max = 8800, /* mV */
@@ -191,6 +275,7 @@ static inline enum battery_present battery_hw_present(void)
/* Get type of the battery connected on the board */
static int board_get_battery_type(void)
{
+ const struct fast_charge_params *chg_params;
char name[32];
int i;
@@ -203,6 +288,11 @@ static int board_get_battery_type(void)
}
}
+ /* Initialize fast charging parameters */
+ chg_params = board_get_batt_params()->fast_chg_params;
+ prev_chg_profile_info = &chg_params->chg_profile_info[
+ chg_params->default_temp_range_profile];
+
return board_battery_type;
}
@@ -296,10 +386,6 @@ enum battery_disconnect_state battery_get_disconnect_state(void)
return BATTERY_NOT_DISCONNECTED;
}
-#ifdef CONFIG_CHARGER_PROFILE_OVERRIDE
-
-static int fast_charging_allowed = 1;
-
static int charger_should_discharge_on_ac(struct charge_state_data *curr)
{
/* can not discharge on AC without battery */
@@ -348,29 +434,8 @@ static int charger_should_discharge_on_ac(struct charge_state_data *curr)
* Return the next poll period in usec, or zero to use the default (which is
* state dependent).
*/
-
-/* TODO: crosbug.com/p/59904 */
int charger_profile_override(struct charge_state_data *curr)
{
- /* temp in 0.1 deg C */
- int temp_c = curr->batt.temperature - 2731;
- /* keep track of last temperature range for hysteresis */
- static enum {
- TEMP_RANGE_1,
- TEMP_RANGE_2,
- TEMP_RANGE_3,
- TEMP_RANGE_4,
- TEMP_RANGE_5,
- } temp_range = TEMP_RANGE_3;
- /* keep track of last voltage range for hysteresis */
- static enum {
- VOLTAGE_RANGE_LOW,
- VOLTAGE_RANGE_HIGH,
- } voltage_range = VOLTAGE_RANGE_LOW;
-
- /* Current and previous battery voltage */
- int batt_voltage;
- static int prev_batt_voltage;
int disch_on_ac = charger_should_discharge_on_ac(curr);
charger_discharge_on_ac(disch_on_ac);
@@ -380,139 +445,12 @@ int charger_profile_override(struct charge_state_data *curr)
return 0;
}
- /*
- * Determine temperature range. The five ranges are:
- * < 0C
- * 0C>= <=15C
- * 15C> <=20C
- * 20C> <=45C
- * > 45C
- *
- * If temp reading was bad, use last range.
- */
- if (!(curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE)) {
- if (temp_c < 0)
- temp_range = TEMP_RANGE_1;
- else if (temp_c <= 150)
- temp_range = TEMP_RANGE_2;
- else if (temp_c <= 200)
- temp_range = TEMP_RANGE_3;
- else if (temp_c <= 450)
- temp_range = TEMP_RANGE_4;
- else
- temp_range = TEMP_RANGE_5;
- }
-
- /*
- * If battery voltage reading is bad, use the last reading.
- */
- if (curr->batt.flags & BATT_FLAG_BAD_VOLTAGE) {
- batt_voltage = prev_batt_voltage;
- } else {
- batt_voltage = prev_batt_voltage = curr->batt.voltage;
- if (batt_voltage <= 8000)
- voltage_range = VOLTAGE_RANGE_LOW;
- else if (batt_voltage > 8000)
- voltage_range = VOLTAGE_RANGE_HIGH;
- }
-
- /*
- * If we are not charging or we aren't using fast charging profiles,
- * then do not override desired current and voltage.
- */
- if (curr->state != ST_CHARGE || !fast_charging_allowed)
- return 0;
-
- /*
- * Okay, impose our custom will:
- *
- * When battery is < 0C:
- * CC at 0mA @ 0V
- * CV at 0V
- *
- * When battery is 0-15C:
- * CC at 944mA until 8.0V @ 8.7V
- * CC at 472mA @ 8.7V
- * CV at 8.7V
- *
- * When battery is 15-20C:
- * CC at 1416mA @ 8.7V
- * CV at 8.7V
- *
- * When battery is 20-45C:
- * CC at 3300mA @ 8.7V
- * CV at 8.7V
- *
- * When battery is > 45C:
- * CC at 0mA @ 0V
- * CV at 0V
- */
- switch (temp_range) {
- case TEMP_RANGE_2:
- if (voltage_range == VOLTAGE_RANGE_HIGH)
- curr->requested_current = 472;
- else
- curr->requested_current = 944;
- curr->requested_voltage = 8700;
- break;
- case TEMP_RANGE_3:
- curr->requested_current = 1416;
- curr->requested_voltage = 8700;
- break;
- case TEMP_RANGE_4:
- curr->requested_current = 3300;
- curr->requested_voltage = 8700;
- break;
- case TEMP_RANGE_1:
- case TEMP_RANGE_5:
- default:
- curr->requested_current = 0;
- curr->requested_voltage = 0;
- break;
- }
-
- return 0;
-}
-
-/* Customs options controllable by host command. */
-#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0)
-
-enum ec_status charger_profile_override_get_param(uint32_t param,
- uint32_t *value)
-{
- if (param == PARAM_FASTCHARGE) {
- *value = fast_charging_allowed;
- return EC_RES_SUCCESS;
- }
- return EC_RES_INVALID_PARAM;
-}
-
-enum ec_status charger_profile_override_set_param(uint32_t param,
- uint32_t value)
-{
- if (param == PARAM_FASTCHARGE) {
- fast_charging_allowed = value;
- return EC_RES_SUCCESS;
- }
- return EC_RES_INVALID_PARAM;
-}
-
-static int command_fastcharge(int argc, char **argv)
-{
- if (argc > 1 && !parse_bool(argv[1], &fast_charging_allowed))
- return EC_ERROR_PARAM1;
-
- ccprintf("fastcharge %s\n", fast_charging_allowed ? "on" : "off");
-
- return EC_SUCCESS;
+ return charger_profile_override_common(curr,
+ board_get_batt_params()->fast_chg_params,
+ &prev_chg_profile_info,
+ board_get_batt_params()->batt_info.voltage_max);
}
-DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge,
- "[on|off]",
- "Get or set fast charging profile");
-
-#endif /* CONFIG_CHARGER_PROFILE_OVERRIDE */
-
/*
* Physical detection of battery.
*/
diff --git a/board/reef/board.h b/board/reef/board.h
index 1a26a887f0..87bd09f6f7 100644
--- a/board/reef/board.h
+++ b/board/reef/board.h
@@ -66,6 +66,7 @@
#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1
#define CONFIG_USB_CHARGER
#define CONFIG_CHARGER_PROFILE_OVERRIDE
+#define CONFIG_CHARGER_PROFILE_OVERRIDE_COMMON
#define CONFIG_CHARGE_MANAGER_EXTERNAL_POWER_LIMIT
/* USB-A config */
diff --git a/common/build.mk b/common/build.mk
index 329324d848..df17dd0f22 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -34,6 +34,7 @@ common-$(CONFIG_CASE_CLOSED_DEBUG)+=case_closed_debug.o
common-$(CONFIG_CHARGE_MANAGER)+=charge_manager.o
common-$(CONFIG_CHARGE_RAMP)+=charge_ramp.o
common-$(CONFIG_CHARGER)+=charger.o
+common-$(CONFIG_CHARGER_PROFILE_OVERRIDE_COMMON)+=charger_profile_override.o
common-$(CONFIG_CHARGER_V1)+=charge_state_v1.o
common-$(CONFIG_CHARGER_V2)+=charge_state_v2.o
common-$(CONFIG_CMD_I2CWEDGE)+=i2c_wedge.o
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 1ec4ca44ab..94dd210972 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -8,6 +8,7 @@
#include "battery.h"
#include "battery_smart.h"
#include "charge_manager.h"
+#include "charger_profile_override.h"
#include "charge_state.h"
#include "charger.h"
#include "chipset.h"
diff --git a/common/charger_profile_override.c b/common/charger_profile_override.c
new file mode 100644
index 0000000000..ac5339f868
--- /dev/null
+++ b/common/charger_profile_override.c
@@ -0,0 +1,194 @@
+/* Copyright 2016 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.
+ *
+ * Charger profile override for fast charging
+ */
+
+#include "charger_profile_override.h"
+#include "console.h"
+#include "ec_commands.h"
+#include "util.h"
+
+#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE_TEST
+static int fast_charge_test_on;
+static int test_flag_temp;
+static int test_flag_vtg;
+static int test_temp_c;
+static int test_vtg_mV = -1;
+#endif
+
+static int fast_charging_allowed = 1;
+
+int charger_profile_override_common(struct charge_state_data *curr,
+ const struct fast_charge_params *fast_chg_params,
+ const struct fast_charge_profile **prev_chg_prof_info,
+ int batt_vtg_max)
+{
+ /* temp in 0.1 deg C */
+ int temp_c = curr->batt.temperature - 2731;
+ enum fast_chg_voltage_ranges voltage_range;
+ int temp_ranges = fast_chg_params->total_temp_ranges;
+ const struct fast_charge_profile *chg_profile_info =
+ fast_chg_params->chg_profile_info;
+
+#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE_TEST
+ if (fast_charge_test_on && test_vtg_mV != -1) {
+ temp_c = TEMPC_TENTHS_OF_DEG(test_temp_c);
+ curr->batt.voltage = test_vtg_mV;
+
+ if (test_flag_temp)
+ curr->batt.flags |= BATT_FLAG_BAD_TEMPERATURE;
+ else
+ curr->batt.flags &= BATT_FLAG_BAD_TEMPERATURE;
+
+ if (test_flag_vtg)
+ curr->batt.flags |= BATT_FLAG_BAD_VOLTAGE;
+ else
+ curr->batt.flags &= BATT_FLAG_BAD_VOLTAGE;
+ }
+#endif
+
+ /*
+ * Determine temperature range.
+ * If temp reading was bad, use last range.
+ */
+ if (!(curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE)) {
+ while (chg_profile_info && temp_ranges) {
+ if (temp_c <= chg_profile_info->temp_c) {
+ *prev_chg_prof_info = chg_profile_info;
+ break;
+ }
+ chg_profile_info++;
+ temp_ranges--;
+ }
+
+ /* Invalid charge profile selected */
+ if (!chg_profile_info || !temp_ranges)
+ return -1;
+ }
+
+ /*
+ * If the battery voltage reading is bad or the battery voltage is
+ * greater than or equal to the lower limit or the battery voltage is
+ * not in the charger profile voltage range, consider battery has high
+ * voltage range so that we charge at lower current limit.
+ */
+ if (!(curr->batt.flags & BATT_FLAG_BAD_VOLTAGE) &&
+ curr->batt.voltage < fast_chg_params->vtg_low_limit_mV)
+ voltage_range = VOLTAGE_RANGE_LOW;
+ else
+ voltage_range = VOLTAGE_RANGE_HIGH;
+
+ /*
+ * If we are not charging or we aren't using fast charging profiles,
+ * then do not override desired current and voltage.
+ */
+ if (curr->state != ST_CHARGE || !fast_charging_allowed)
+ return 0;
+
+ /*
+ * Okay, impose our custom will:
+ */
+ curr->requested_current =
+ (*prev_chg_prof_info)->current_mA[voltage_range];
+ curr->requested_voltage = curr->requested_current ? batt_vtg_max : 0;
+
+#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE_TEST
+ if (fast_charge_test_on)
+ ccprintf("Fast charge profile i=%dmA, v=%dmV\n",
+ curr->requested_current, curr->requested_voltage);
+#endif
+
+ return 0;
+}
+
+/* Customs options controllable by host command. */
+#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0)
+
+enum ec_status charger_profile_override_get_param(uint32_t param,
+ uint32_t *value)
+{
+ if (param == PARAM_FASTCHARGE) {
+ *value = fast_charging_allowed;
+ return EC_RES_SUCCESS;
+ }
+ return EC_RES_INVALID_PARAM;
+}
+
+enum ec_status charger_profile_override_set_param(uint32_t param,
+ uint32_t value)
+{
+ if (param == PARAM_FASTCHARGE) {
+ fast_charging_allowed = value;
+ return EC_RES_SUCCESS;
+ }
+ return EC_RES_INVALID_PARAM;
+}
+
+#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE
+static int command_fastcharge(int argc, char **argv)
+{
+ if (argc > 1 && !parse_bool(argv[1], &fast_charging_allowed))
+ return EC_ERROR_PARAM1;
+
+ ccprintf("fastcharge %s\n", fast_charging_allowed ? "on" : "off");
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge,
+ "[on|off]",
+ "Get or set fast charging profile");
+#endif
+
+/*
+ * Manipulate the temperature and voltage values and check if the correct
+ * fast charging profile is selected.
+ */
+#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE_TEST
+static int command_fastcharge_test(int argc, char **argv)
+{
+ char *e;
+ int test_on;
+
+ if (argc > 1 && !parse_bool(argv[1], &test_on))
+ return EC_ERROR_PARAM2;
+
+ /* Check if only tuurn printf message on / off */
+ if (argc == 2) {
+ fast_charge_test_on = test_on;
+ test_vtg_mV = -1;
+
+ return EC_SUCCESS;
+ }
+
+ /* Validate the input parameters */
+ if ((test_on && argc != 6) || !test_on)
+ return EC_ERROR_PARAM_COUNT;
+
+ test_flag_temp = strtoi(argv[2], &e, 0);
+ if (*e || test_flag_temp > 1 || test_flag_temp < 0)
+ return EC_ERROR_PARAM3;
+
+ test_flag_vtg = strtoi(argv[3], &e, 0);
+ if (*e || test_flag_vtg > 1 || test_flag_vtg < 0)
+ return EC_ERROR_PARAM4;
+
+ test_temp_c = strtoi(argv[4], &e, 0);
+ if (*e)
+ return EC_ERROR_PARAM5;
+
+ test_vtg_mV = strtoi(argv[5], &e, 0);
+ if (*e || test_vtg_mV < 0) {
+ test_vtg_mV = -1;
+ return EC_ERROR_PARAM6;
+ }
+
+ fast_charge_test_on = 1;
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(fastchgtest, command_fastcharge_test,
+ "off | on tempflag[1|0] vtgflag[1|0] temp_c vtg_mV",
+ "Check if fastcharge profile works");
+#endif
diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h
index 70ca47f6d3..e908758371 100644
--- a/include/charge_state_v2.h
+++ b/include/charge_state_v2.h
@@ -40,29 +40,6 @@ struct charge_state_data {
int desired_input_current;
};
-/*
- * Optional customization.
- *
- * On input, the struct reflects the default behavior. The function can make
- * changes to the state, requested_voltage, or requested_current.
- *
- * Return value:
- * >0 Desired time in usec for this poll period.
- * 0 Use the default poll period (which varies with the state).
- * <0 An error occurred. The poll time will be shorter than usual. Too
- * many errors in a row may trigger some corrective action.
- */
-int charger_profile_override(struct charge_state_data *);
-
-/*
- * Access to custom profile params through host commands.
- * What this does is up to the implementation.
- */
-enum ec_status charger_profile_override_get_param(uint32_t param,
- uint32_t *value);
-enum ec_status charger_profile_override_set_param(uint32_t param,
- uint32_t value);
-
/**
* Set the charge input current limit. This value is stored and sent every
* time AC is applied.
diff --git a/include/charger_profile_override.h b/include/charger_profile_override.h
new file mode 100644
index 0000000000..ba2ef09a4e
--- /dev/null
+++ b/include/charger_profile_override.h
@@ -0,0 +1,92 @@
+/* Copyright 2016 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.
+ *
+ * Charger profile override for fast charging
+ */
+
+#ifndef __CROS_EC_CHARGER_PROFILE_OVERRIDE_H
+#define __CROS_EC_CHARGER_PROFILE_OVERRIDE_H
+
+#include "charge_state_v2.h"
+
+#define TEMPC_TENTHS_OF_DEG(c) ((c) * 10)
+
+#define CHARGER_PROF_TEMP_C_LAST_RANGE 0xFFFF
+
+enum fast_chg_voltage_ranges {
+ VOLTAGE_RANGE_LOW,
+ VOLTAGE_RANGE_HIGH,
+ VOLTAGE_RANGE_NUM,
+};
+
+/* Charge profile override info */
+struct fast_charge_profile {
+ /* temperature in 10ths of a degree C */
+ int temp_c;
+ /* charge current at lower & higher battery voltage limit in mA */
+ int current_mA[VOLTAGE_RANGE_NUM];
+};
+
+/* Charge profile override parameters */
+struct fast_charge_params {
+ /* Total temperature ranges of the charge profile */
+ const int total_temp_ranges;
+ /* Default temperature range of the charge profile */
+ const int default_temp_range_profile;
+ /*
+ * Lower limit of battery voltage in mV
+ * If the battery voltage reading is bad or the battery voltage is
+ * greater than or equal to the lower limit or the battery voltage is
+ * not in the charger profile voltage range, consider battery has high
+ * voltage range so that we charge at lower current limit.
+ */
+ const int vtg_low_limit_mV;
+ const struct fast_charge_profile *chg_profile_info;
+};
+
+/**
+ * Optional customization of charger profile override for fast charging.
+ *
+ * On input, the struct reflects the default behavior. The function can make
+ * changes to the state, requested_voltage, or requested_current.
+ *
+ * @param curr Charge state machine data.
+ *
+ * @return
+ * >0 Desired time in usec for this poll period.
+ * 0 Use the default poll period (which varies with the state).
+ * <0 An error occurred. The poll time will be shorter than usual.
+ * Too many errors in a row may trigger some corrective action.
+ */
+int charger_profile_override(struct charge_state_data *curr);
+
+/**
+ * Common code of charger profile override for fast charging.
+ *
+ * @param curr Charge state machine data.
+ * @param fast_chg_params Fast charge profile parameters.
+ * @param prev_chg_prof_info Previous charge profile info.
+ * @param batt_vtg_max Maximum battery voltage.
+ *
+ * @return
+ * >0 Desired time in usec for this poll period.
+ * 0 Use the default poll period (which varies with the state).
+ * <0 An error occurred. The poll time will be shorter than usual.
+ * Too many errors in a row may trigger some corrective action.
+ */
+int charger_profile_override_common(struct charge_state_data *curr,
+ const struct fast_charge_params *fast_chg_params,
+ const struct fast_charge_profile **prev_chg_prof_info,
+ int batt_vtg_max);
+
+/*
+ * Access to custom profile params through host commands.
+ * What this does is up to the implementation.
+ */
+enum ec_status charger_profile_override_get_param(uint32_t param,
+ uint32_t *value);
+enum ec_status charger_profile_override_set_param(uint32_t param,
+ uint32_t value);
+
+#endif /* __CROS_EC_CHARGER_PROFILE_OVERRIDE_H */
diff --git a/include/config.h b/include/config.h
index 5d48812c27..15679582f8 100644
--- a/include/config.h
+++ b/include/config.h
@@ -510,6 +510,12 @@
*/
#undef CONFIG_CHARGER_PROFILE_OVERRIDE
+/*
+ * Common code for charger profile override. Should be used with
+ * CONFIG_CHARGER_PROFILE_OVERRIDE.
+ */
+#undef CONFIG_CHARGER_PROFILE_OVERRIDE_COMMON
+
/* Value of the charge sense resistor, in mOhms */
#undef CONFIG_CHARGER_SENSE_RESISTOR
@@ -607,6 +613,8 @@
#undef CONFIG_CMD_BUTTON
#define CONFIG_CMD_CHARGER
#undef CONFIG_CMD_CHARGER_ADC_AMON_BMON
+#undef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE
+#undef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE_TEST
#undef CONFIG_CMD_CHARGER_PSYS
#define CONFIG_CMD_CHARGE_SUPPLIER_INFO
#undef CONFIG_CMD_CHGRAMP