summaryrefslogtreecommitdiff
path: root/include/charge_state.h
diff options
context:
space:
mode:
authorYH Lin <yueherngl@google.com>2023-05-11 20:47:00 +0000
committerYH Lin <yueherngl@google.com>2023-05-11 20:47:00 +0000
commit8641442366bd7c2c133e302a57f904dfac3c896b (patch)
treed0dca100ca02a89210decc54b7124d26bb75ef6a /include/charge_state.h
parente79a9dab1721c3d7da1475f3f802c4ea871a48ec (diff)
parent5df400b0377c9e1b5bb6cfc53ba7dfedde91f944 (diff)
downloadchrome-ec-8641442366bd7c2c133e302a57f904dfac3c896b.tar.gz
Merge remote-tracking branch cros/main into firmware-brya-14505.B-main
Generated by: util/update_release_branch.py --baseboard brya --relevant_paths_file baseboard/brya/relevant-paths.txt firmware-brya-14505.B-main Relevant changes: git log --oneline e79a9dab17..5df400b037 -- baseboard/brya board/agah board/anahera board/banshee board/brya board/crota board/felwinter board/gimble board/hades board/kano board/marasov board/mithrax board/omnigul board/osiris board/primus board/redrix board/taeko board/taniks board/vell board/volmar driver/bc12/pi3usb9201_public.* driver/charger/bq25710.* driver/ppc/nx20p348x.* driver/ppc/syv682x_public.* driver/retimer/bb_retimer_public.* driver/tcpm/nct38xx.* driver/tcpm/ps8xxx_public.* driver/tcpm/tcpci.* include/power/alderlake* include/intel_x86.h power/alderlake* power/intel_x86.c util/getversion.sh 76d2b9b1e4 battery: Deprecate CONFIG_BATTERY_LEVEL_NEAR_FULL 3d5b996f73 Hades: Fast forward DSW_PWROK to PCH_PWROK 56af450c1a Agah: Fast forward DSW_PWROK to PCH_PWROK b729eab7c7 charger: Move charger_state_v2.h into charge_state.h 47acf64182 charger: Rename charge_get_state() to led_pwr_get_state() 632c7c935a power/x86: Add dedicated interrupt handler for pwrok 0fff3a0bd4 omnigul: Add condition use Accel and Gyro by FWCONFIG. 7540daff3f driver/tcpm/nct38xx: Remove write to RO register 3f279f30d4 GPU: Rename DC_ATLEAST_SOC to DC_ATMOST_SOC BRANCH=None BUG=b:218332694 b:216485035 b:280818345 b:280351196 b:280001153 BUG=b:279918234 TEST=`emerge-[brya,hades,draco] chromeos-ec` Force-Relevant-Builds: all Change-Id: I19f2f6c5573d8c748ac63b488a808f10de352b1d Signed-off-by: YH Lin <yueherngl@google.com>
Diffstat (limited to 'include/charge_state.h')
-rw-r--r--include/charge_state.h232
1 files changed, 228 insertions, 4 deletions
diff --git a/include/charge_state.h b/include/charge_state.h
index dcf3430954..34576dc333 100644
--- a/include/charge_state.h
+++ b/include/charge_state.h
@@ -5,7 +5,13 @@
#ifndef __CROS_EC_CHARGE_STATE_H
#define __CROS_EC_CHARGE_STATE_H
+#include "battery.h"
+#include "battery_smart.h"
+#include "charger.h"
+#include "chipset.h"
#include "common.h"
+#include "ec_ec_comm_client.h"
+#include "ocpc.h"
#include "stdbool.h"
#include "timer.h"
@@ -26,7 +32,7 @@
#endif
/* Power states */
-enum charge_state {
+enum led_pwr_state {
/* Meta-state; unchanged from previous time through task loop */
PWR_STATE_UNCHANGE = 0,
/* Initializing charge state machine at boot */
@@ -61,7 +67,7 @@ enum charge_state {
/* Battery is responsive */
#define CHARGE_FLAG_BATT_RESPONSIVE BIT(2)
-/* Debugging constants, in the same order as enum charge_state. This string
+/* Debugging constants, in the same order as enum pwr_state. This string
* table was moved here to sync with enum above.
*/
#define CHARGE_STATE_NAME_TABLE \
@@ -72,10 +78,50 @@ enum charge_state {
}
/* End of CHARGE_STATE_NAME_TABLE macro */
+/*
+ * The values exported by charge_get_state() and charge_get_flags() are used
+ * only to control the LEDs (with one not-quite-correct exception). For V2
+ * we use a different set of states internally.
+ */
+enum charge_state_v2 {
+ ST_IDLE = 0,
+ ST_DISCHARGE,
+ ST_CHARGE,
+ ST_PRECHARGE,
+
+ NUM_STATES_V2
+};
+
+struct charge_state_data {
+ timestamp_t ts;
+ int ac;
+ int batt_is_charging;
+ struct charger_params chg;
+ struct batt_params batt;
+ enum charge_state_v2 state;
+ int requested_voltage;
+ int requested_current;
+ int desired_input_current;
+#ifdef CONFIG_CHARGER_OTG
+ int output_current;
+#endif
+#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
+ int input_voltage;
+#endif
+#ifdef CONFIG_OCPC
+ struct ocpc_data ocpc;
+#endif
+};
+
+struct sustain_soc {
+ int8_t lower;
+ int8_t upper;
+};
+
/**
* Return current charge state.
*/
-enum charge_state charge_get_state(void);
+enum led_pwr_state led_pwr_get_state(void);
/**
* Return current charge v2 state.
@@ -191,7 +237,185 @@ int charge_get_battery_temp(int idx, int *temp_ptr);
*/
const struct batt_params *charger_current_battery_params(void);
+/**
+ * Set the output current limit and voltage. This is used to provide power from
+ * the charger chip ("OTG" mode).
+ *
+ * @param chgnum Charger index to act upon
+ * @param ma Maximum current to provide in mA (0 to disable output).
+ * @param mv Voltage in mV (ignored if ma == 0).
+ * @return EC_SUCCESS or error
+ */
+int charge_set_output_current_limit(int chgnum, int ma, int mv);
+
+/**
+ * Set the charge input current limit. This value is stored and sent every
+ * time AC is applied.
+ *
+ * The input current limit is automatically derated by
+ * CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT (if configured), and is clamped to
+ * no less than CONFIG_CHARGER_MIN_INPUT_CURRENT_LIMIT mA (if configured).
+ *
+ * @param ma New input current limit in mA
+ * @param mv Negotiated charge voltage in mV.
+ * @return EC_SUCCESS or error
+ */
+int charge_set_input_current_limit(int ma, int mv);
+
+/**
+ * Set the desired manual charge current when in idle mode.
+ *
+ * @param curr_ma: Charge current in mA.
+ */
+void chgstate_set_manual_current(int curr_ma);
+
+/**
+ * Set the desired manual charge voltage when in idle mode.
+ *
+ * @param volt_mv: Charge voltage in mV.
+ */
+void chgstate_set_manual_voltage(int volt_mv);
+
+/**
+ * Board-specific routine to indicate if the base is connected.
+ */
+int board_is_base_connected(void);
+
+/**
+ * Board-specific routine to enable power distribution between lid and base
+ * (current can flow both ways).
+ */
+void board_enable_base_power(int enable);
+
+/**
+ * Board-specific routine to reset the base (in case it is unresponsive, e.g.
+ * if we told it to hibernate).
+ */
+void board_base_reset(void);
+
+/**
+ * Callback with which boards determine action on critical low battery
+ *
+ * The default implementation is provided in charge_state_v2.c. Overwrite it
+ * to customize it.
+ *
+ * @param curr Pointer to struct charge_state_data
+ * @return Action to take.
+ */
+enum critical_shutdown
+board_critical_shutdown_check(struct charge_state_data *curr);
+
+/**
+ * Callback to set battery level for shutdown
+ *
+ * A board can implement this to customize shutdown battery level at runtime.
+ *
+ * @return battery level for shutdown
+ */
+uint8_t board_set_battery_level_shutdown(void);
+
+/**
+ * Return system PLT power and battery's desired power.
+ *
+ * @return desired power in mW
+ */
+int charge_get_plt_plus_bat_desired_mw(void);
+
+/**
+ * Get the stable battery charging current. The current will be
+ * CHARGE_CURRENT_UNINITIALIZED if not yet stable.
+ *
+ * @return stable battery charging current in mA
+ */
+int charge_get_stable_current(void);
+
+/**
+ * Select which charger IC will actually be performing the charger switching.
+ *
+ * @param idx The index into the chg_chips table.
+ */
+void charge_set_active_chg_chip(int idx);
+
+/**
+ * Retrieve which charger IC is the active charger IC performing the charger
+ * switching.
+ */
+int charge_get_active_chg_chip(void);
+
+/**
+ * Set the stable current.
+ *
+ * @param ma: battery charging current in mA
+ */
+void charge_set_stable_current(int ma);
+
+/**
+ * Reset stable current counter stable_ts. Calling this function would set
+ * stable_current to CHARGE_CURRENT_UNINITIALIZED.
+ */
+void charge_reset_stable_current(void);
+
+/**
+ * Reset stable current counter stable_ts. Calling this function would set
+ * stable_current to CHARGE_CURRENT_UNINITIALIZED.
+ *
+ * @param us: sample stable current until us later.
+ */
+void charge_reset_stable_current_us(uint64_t us);
+
+/**
+ * Check if the battery charging current is stable by examining the timestamp.
+ *
+ * @return true if stable timestamp expired, false otherwise.
+ */
+bool charge_is_current_stable(void);
+
+/**
+ * Reset the OCPC internal state data and set the target VSYS to the current
+ * battery voltage for the auxiliary chargers.
+ */
+void trigger_ocpc_reset(void);
+
+/* Track problems in communicating with the battery or charger */
+enum problem_type {
+ PR_STATIC_UPDATE,
+ PR_SET_VOLTAGE,
+ PR_SET_CURRENT,
+ PR_SET_MODE,
+ PR_SET_INPUT_CURR,
+ PR_POST_INIT,
+ PR_CHG_FLAGS,
+ PR_BATT_FLAGS,
+ PR_CUSTOM,
+ PR_CFG_SEC_CHG,
+
+ NUM_PROBLEM_TYPES
+};
+
+void charge_problem(enum problem_type p, int v);
+
+struct charge_state_data *charge_get_status(void);
+
+enum ec_charge_control_mode get_chg_ctrl_mode(void);
+
+__test_only void reset_prev_disp_charge(void);
+
+/**
+ * Whether or not the charging progress was shown. Note, calling this function
+ * will reset the value to false.
+ *
+ * @return Whether or not the charging progress was printed to the console
+ */
+__test_only bool charging_progress_displayed(void);
+
+/**
+ * Callback for boards to request charger to enable bypass mode on/off.
+ *
+ * @return True for requesting bypass on. False for requesting bypass off.
+ */
+int board_should_charger_bypass(void);
+
/* Config Charger */
-#include "charge_state_v2.h"
+#include "charge_state.h"
#endif /* __CROS_EC_CHARGE_STATE_H */