summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-01-14 14:18:08 -0700
committerCommit Bot <commit-bot@chromium.org>2020-01-28 20:22:22 +0000
commit4eb3a5fe699247a5767ae38c66c75872f4afc575 (patch)
tree81787f2f54ff3470ce326047213abfae234b50a1 /include
parentd9a869beb6e1778cec38dcce64f289aba353a8d5 (diff)
downloadchrome-ec-4eb3a5fe699247a5767ae38c66c75872f4afc575.tar.gz
Charger: Create charger driver structure
With upcoming boards which use multiple charger chips, the EC codebase needs to be changed to assume chargers may have different I2C ports. This commit creates the driver structure and wrapper functions, which for now are hard-coded to chip 0 for equivalent behavior with previous code. A general charger config is created for all boards in charger.c for now, which uses the build information to fill in the structure. All boards will default to defining CONFIG_CHARGER_SINGLE_CHIP, which in turn defines a CHARGER_SOLO which can be used by drivers which have code that needs to determine charger numbers. For boards which have multiple chips, they may undefine this config and should generate build errors if their driver is still using the hardcoded charger reference of CHARGER_SOLO. Older drivers may continue using CHARGER_SOLO in non-static functions until they're needed in a multiple charger board. For boards which may be supporting different I2C configurations for the charger over board versions, they may define CONFIG_CHARGER_RUNTIME_CONFIG to fill in these fields after boot. BRANCH=none BUG=b:147672225 TEST=builds, chargers on hatch and octopus work Change-Id: I390ede494226252e512595c48099fa1288ffe93e Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2008451 Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/charger.h158
-rw-r--r--include/config.h9
2 files changed, 132 insertions, 35 deletions
diff --git a/include/charger.h b/include/charger.h
index 342f6a7b48..6aebf3b94c 100644
--- a/include/charger.h
+++ b/include/charger.h
@@ -40,6 +40,86 @@ struct charger_params {
int flags;
};
+struct charger_drv {
+ /* Function to call during HOOK_INIT after i2c init */
+ void (*init)(int chgnum);
+
+ /* Power state machine post init */
+ enum ec_error_list (*post_init)(int chgnum);
+
+ /* Get charger information */
+ const struct charger_info * (*get_info)(int chgnum);
+
+ /* Get smart battery charger status. Supported flags may vary. */
+ enum ec_error_list (*get_status)(int chgnum, int *status);
+
+ /* Set smart battery charger mode. Supported modes may vary. */
+ enum ec_error_list (*set_mode)(int chgnum, int mode);
+
+ /*
+ * For chargers that are able to supply output power for OTG dongle,
+ * this function enables or disables power output.
+ */
+ enum ec_error_list (*enable_otg_power)(int chgnum, int enabled);
+
+ /*
+ * Sets OTG current limit and voltage (independent of whether OTG
+ * power is currently enabled).
+ */
+ enum ec_error_list (*set_otg_current_voltage)(int chgnum,
+ int output_current,
+ int output_voltage);
+
+ /* Get/set charge current limit in mA */
+ enum ec_error_list (*get_current)(int chgnum, int *current);
+ enum ec_error_list (*set_current)(int chgnum, int current);
+
+ /* Get/set charge voltage limit in mV */
+ enum ec_error_list (*get_voltage)(int chgnum, int *voltage);
+ enum ec_error_list (*set_voltage)(int chgnum, int voltage);
+
+ /* Discharge battery when on AC power. */
+ enum ec_error_list (*discharge_on_ac)(int chgnum, int enable);
+
+ /* Get the VBUS voltage (mV) from the charger */
+ int (*get_vbus_voltage)(int chgnum, int port);
+
+ /* Set desired input current value */
+ enum ec_error_list (*set_input_current)(int chgnum, int input_current);
+
+ /* Get actual input current value */
+ enum ec_error_list (*get_input_current)(int chgnum, int *input_current);
+
+ enum ec_error_list (*manufacturer_id)(int chgnum, int *id);
+ enum ec_error_list (*device_id)(int chgnum, int *id);
+ enum ec_error_list (*get_option)(int chgnum, int *option);
+ enum ec_error_list (*set_option)(int chgnum, int option);
+
+ /* Charge ramp functions */
+ enum ec_error_list (*set_hw_ramp)(int chgnum, int enable);
+ int (*ramp_is_stable)(int chgnum);
+ int (*ramp_is_detected)(int chgnum);
+ int (*ramp_get_current_limit)(int chgnum);
+};
+
+struct charger_config_t {
+ int i2c_port;
+ uint16_t i2c_addr_flags;
+ const struct charger_drv *drv;
+};
+
+/* TODO(b/147672225): structure should be defined in board.c files */
+#ifndef CONFIG_CHARGER_RUNTIME_CONFIG
+extern const struct charger_config_t chg_chips[];
+#else
+extern struct charger_config_t chg_chips[];
+#endif
+extern const unsigned int chg_cnt;
+
+#ifdef CONFIG_CHARGER_SINGLE_CHIP
+#define CHARGER_SOLO 0
+#endif
+
/* Get the current charger_params. Failures are reported in .flags */
void charger_get_params(struct charger_params *chg);
@@ -52,23 +132,48 @@ void charger_get_params(struct charger_params *chg);
/* All of the above CHG_FLAG_BAD_* bits */
#define CHG_FLAG_BAD_ANY 0x0000001f
+/**
+ * Return the closest match the charger can supply to the requested current.
+ *
+ * @param current Requested current in mA.
+ *
+ * @return Current the charger will actually supply if <current> is requested.
+ */
+int charger_closest_current(int current);
+
+/**
+ * Return the closest match the charger can supply to the requested voltage.
+ *
+ * @param voltage Requested voltage in mV.
+ *
+ * @return Voltage the charger will actually supply if <voltage> is requested.
+ */
+int charger_closest_voltage(int voltage);
+
+/* Driver wrapper functions */
+
+/*
+ * TODO(b/147672225): charger_* functions should take chip arg, hardcode
+ * calls into driver to 0 for now.
+ */
+
/* Power state machine post init */
-int charger_post_init(void);
+enum ec_error_list charger_post_init(void);
/* Get charger information. */
const struct charger_info *charger_get_info(void);
/* Get smart battery charger status. Supported flags may vary. */
-int charger_get_status(int *status);
+enum ec_error_list charger_get_status(int *status);
/* Set smart battery charger mode. Supported modes may vary. */
-int charger_set_mode(int mode);
+enum ec_error_list charger_set_mode(int mode);
/**
* For chargers that are able to supply output power for OTG dongle, this
* function enables or disables power output.
*/
-int charger_enable_otg_power(int enabled);
+enum ec_error_list charger_enable_otg_power(int enabled);
/**
* Sets OTG current limit and voltage (independent of whether OTG power is
@@ -86,7 +191,8 @@ int charger_enable_otg_power(int enabled);
*
* @return EC_SUCCESS on success, an error otherwise.
*/
-int charger_set_otg_current_voltage(int output_current, int output_voltage);
+enum ec_error_list charger_set_otg_current_voltage(int output_current,
+ int output_voltage);
/**
* Is the charger sourcing VBUS / OTG power?
@@ -96,34 +202,16 @@ int charger_set_otg_current_voltage(int output_current, int output_voltage);
*/
int charger_is_sourcing_otg_power(int port);
-/**
- * Return the closest match the charger can supply to the requested current.
- *
- * @param current Requested current in mA.
- *
- * @return Current the charger will actually supply if <current> is requested.
- */
-int charger_closest_current(int current);
-
-/**
- * Return the closest match the charger can supply to the requested voltage.
- *
- * @param voltage Requested voltage in mV.
- *
- * @return Voltage the charger will actually supply if <voltage> is requested.
- */
-int charger_closest_voltage(int voltage);
-
/* Get/set charge current limit in mA */
-int charger_get_current(int *current);
-int charger_set_current(int current);
+enum ec_error_list charger_get_current(int *current);
+enum ec_error_list charger_set_current(int current);
/* Get/set charge voltage limit in mV */
-int charger_get_voltage(int *voltage);
-int charger_set_voltage(int voltage);
+enum ec_error_list charger_get_voltage(int *voltage);
+enum ec_error_list charger_set_voltage(int voltage);
/* Discharge battery when on AC power. */
-int charger_discharge_on_ac(int enable);
+enum ec_error_list charger_discharge_on_ac(int enable);
/* Get the VBUS voltage (mV) from the charger */
int charger_get_vbus_voltage(int port);
@@ -140,20 +228,20 @@ int charger_get_system_power(void);
/* Other parameters that may be charger-specific, but are common so far. */
/* Set desired input current value */
-int charger_set_input_current(int input_current);
+enum ec_error_list charger_set_input_current(int input_current);
/*
* Get actual input current value.
* Actual input current may be less than the desired input current set
* due to current ratings of the wall adapter.
*/
-int charger_get_input_current(int *input_current);
+enum ec_error_list charger_get_input_current(int *input_current);
-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);
+enum ec_error_list charger_manufacturer_id(int *id);
+enum ec_error_list charger_device_id(int *id);
+enum ec_error_list charger_get_option(int *option);
+enum ec_error_list charger_set_option(int option);
+enum ec_error_list charger_set_hw_ramp(int enable);
/* Print all charger info for debugging purposes */
void print_charger_debug(void);
diff --git a/include/config.h b/include/config.h
index 823210d2d7..5f3e4a0c4b 100644
--- a/include/config.h
+++ b/include/config.h
@@ -798,6 +798,15 @@
#undef CONFIG_CHARGER_RT9467
#undef CONFIG_CHARGER_SY21612
+/* Allow run-time completion of the charger driver structure */
+#undef CONFIG_CHARGER_RUNTIME_CONFIG
+
+/*
+ * Board has only one charger chip (default, undef when board contains multiple
+ * charger chips
+ */
+#define CONFIG_CHARGER_SINGLE_CHIP
+
/*
* Enable the CHG_EN at initialization to turn-on the BGATE which allows voltage
* to be applied to the battery PACK & wakes the battery if it is in shipmode.