summaryrefslogtreecommitdiff
path: root/include/ocpc.h
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2020-04-03 17:18:53 -0700
committerJustin TerAvest <teravest@chromium.org>2020-06-02 17:25:42 +0000
commit7229fab3bb2d4c1983dab388210eb894855aec7d (patch)
tree2e7dae00b9ed961f5929cc982f8aa0057f918c94 /include/ocpc.h
parentdba753130cd341c047afd652ab28a2b099dde9ee (diff)
downloadchrome-ec-7229fab3bb2d4c1983dab388210eb894855aec7d.tar.gz
OCPC: Configure VSYS via secondary charger IC
This commit adds the bulk of the work in getting OCPC functional. Since the secondary charger IC cannot directly sense the current entering the battery, with OCPC, we recruit the EC to do this work instead. Essentially, VSYS needs to be chosen such that we induce the desired current in the battery while also accounting for losses in the system between the output of the secondary charger IC and the battery. To start, a board needs to define the following CONFIG_* option: CONFIG_OCPC_DEF_RBATT_MOHMS This should be at least the R_ds(on) resistance of the BFET and the series sense resistance. The board should also define CONFIG_OCPC. With the combined system resistance, we can calculate the VSYS required to induce the desired current. However, we will also use a PID control loop to help drive our VSYS target to what it should actually be accounting for our error. The PID constants were found by tuning on a waddledoo board. It remains to be seen whether or not these will differ on a board to board basis. BUG=b:148980016,b:147440290 BRANCH=None TEST=Enable on waddledoo, verify that we can charge the battery from the sub-board. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: Icd323546836fe41fa1fcc7c3b6071d822663ed05 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2135964 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'include/ocpc.h')
-rw-r--r--include/ocpc.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/ocpc.h b/include/ocpc.h
index c5c41470cb..9dbd372ae5 100644
--- a/include/ocpc.h
+++ b/include/ocpc.h
@@ -13,9 +13,47 @@
#define PRIMARY_CHARGER 0
#define SECONDARY_CHARGER 1
+#define OCPC_UNINIT 0xdededede
+
struct ocpc_data {
/* Index into chg_chips[] table for the charger IC that is switching. */
int active_chg_chip;
+
+ int combined_rsys_rbatt_mo; /* System resistance b/w output and Vbatt */
+
+ /* ADC values */
+ int primary_vbus_mv; /* VBUS measured by the primary charger IC */
+ int primary_ibus_ma; /* IBUS measrued by the primary charger IC */
+ int secondary_vbus_mv; /* VBUS measured by the secondary charger IC */
+ int secondary_ibus_ma; /* IBUS measure by the secondary charger IC */
+
+ /* PID values */
+ int last_error;
+ int integral;
+ int last_vsys;
};
+/** Set the VSYS target for the secondary charger IC.
+ *
+ * @param curr: Pointer to desired_input_current
+ * @param ocpc: Pointer to OCPC data
+ * @param voltage_mv: The desired voltage
+ * @param current_ma: The desired current
+ * @return EC_SUCCESS on success, error otherwise.
+ */
+int ocpc_config_secondary_charger(int *desired_input_current,
+ struct ocpc_data *ocpc,
+ int voltage_mv, int current_ma);
+
+/** Get the runtime data from the various ADCs.
+ *
+ * @param ocpc: Pointer to OCPC data
+ */
+void ocpc_get_adcs(struct ocpc_data *ocpc);
+
+/* Set the PID constants for the charging loop */
+__overridable void ocpc_get_pid_constants(int *kp, int *kp_div,
+ int *ki, int *ki_div,
+ int *kd, int *kd_div);
+
#endif /* __CROS_EC_OCPC_H */