summaryrefslogtreecommitdiff
path: root/include/battery.h
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-11-06 13:13:37 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-12-02 22:03:51 +0000
commitc0ec787ba10dd3ef5fc089cf1449468ec45ff668 (patch)
tree23c74570671da8750b1f299b6c9c7df1fe032943 /include/battery.h
parent5a3c90d5db8ce869cad977ed143a198e221689ae (diff)
downloadchrome-ec-c0ec787ba10dd3ef5fc089cf1449468ec45ff668.tar.gz
Add battery_get_params()
The charge state machine asks for all of this stuff at the same time anyway. Bundling it into a single function removes a number of redundant (and painfully slow) I2C reads. Also refactor the battery debug command so it doesn't have so many local variables all in one function; it was consuming considerably more stack space than any other debug command. Spring still needs low-level access to the smart battery, so move the two functions it needs directly into the Spring implementation. BUG=chrome-os-partner:20881 BRANCH=none TEST=charge/discharge rambi, pit and spring; watch debug messages and LED and output of 'battery' debug command. All should behave the same as before. Then run 'taskinfo' and see that the console task has at least 20 bytes unused. Change-Id: I951b569542e28bbbb58853d62b57b0aaaf183e3f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/177797
Diffstat (limited to 'include/battery.h')
-rw-r--r--include/battery.h94
1 files changed, 26 insertions, 68 deletions
diff --git a/include/battery.h b/include/battery.h
index b5056cf9d4..cb2a5c32ef 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -38,11 +38,27 @@ struct batt_params {
int temperature; /* Temperature in 0.1 K */
int state_of_charge; /* State of charge (percent, 0-100) */
int voltage; /* Battery voltage (mV) */
- int current; /* Battery current (mA) */
+ int current; /* Battery current (mA); negative=discharging */
int desired_voltage; /* Charging voltage desired by battery (mV) */
int desired_current; /* Charging current desired by battery (mA) */
+ int flags; /* Flags */
};
+/* Flags for batt_params */
+
+/* Battery wants to be charged */
+#define BATT_FLAG_WANT_CHARGE (1 << 0)
+
+/* Battery is responsive (talking to us via I2C) */
+#define BATT_FLAG_RESPONSIVE (1 << 1)
+
+/* Able to talk to battery, but it won't tell us voltage or charge percent */
+#define BATT_FLAG_BAD_VOLTAGE (1 << 2)
+#define BATT_FLAG_BAD_CHARGE_PERCENT (1 << 3)
+
+/* Battery couldn't tell us every params we want */
+#define BATT_FLAG_BAD_ANY (1 << 4)
+
/* Working temperature ranges in degrees C */
struct battery_temperature_ranges {
int8_t start_charging_min_c;
@@ -70,6 +86,15 @@ struct battery_info {
const struct battery_info *battery_get_info(void);
/**
+ * Get current battery parameters.
+ *
+ * Error conditions are reported via batt.flags.
+ *
+ * @param batt Destination for battery data
+ */
+void battery_get_params(struct batt_params *batt);
+
+/**
* Modify battery parameters to match vendor charging profile.
*
* @param batt Battery parameters to modify
@@ -121,22 +146,6 @@ int battery_is_in_10mw_mode(int *val);
int battery_set_10mw_mode(int enabled);
/**
- * Read battery temperature.
- *
- * @param deci_kelvin Destination for battery temperature in units of 0.1 K
- * @return non-zero if error.
- */
-int battery_temperature(int *deci_kelvin);
-
-/**
- * Read battery voltage.
- *
- * @param voltage Destination for voltage in mW
- * @return non-zero if error.
- */
-int battery_voltage(int *voltage);
-
-/**
* Read nominal voltage battery is designed to supply.
*
* @param voltage Destination for voltage in mW
@@ -145,48 +154,6 @@ int battery_voltage(int *voltage);
int battery_design_voltage(int *voltage);
/**
- * Read charging voltage desired by battery.
- *
- * @param voltage Destination for voltage in mV.
- * @return non-zero if error.
- */
-int battery_desired_voltage(int *voltage);
-
-/**
- * Read battery discharging current.
- *
- * @param current Destination for discharge current in mA; negative
- * value indicates charging.
- * @return non-zero if error.
- */
-int battery_current(int *current);
-
-/**
- * Read averaged battery discharging current.
- *
- * @param current Destination for discharge current in mA; negative
- * value indicates charging.
- * @return non-zero if error.
- */
-int battery_average_current(int *current);
-
-/**
- * Read charging current desired by battery.
- *
- * @param current Destination for current in mA.
- * @return non-zero if error.
- */
-int battery_desired_current(int *current);
-
-/**
- * Read battery relative state of charge.
- *
- * @param percent Destination for charge in percent
- * @return non-zero if error.
- */
-int battery_state_of_charge(int *percent);
-
-/**
* Read absolute state of charge.
*
* @param percent Destination for charge in percent
@@ -257,14 +224,6 @@ int battery_time_to_full(int *minutes);
int battery_time_at_rate(int rate, int *minutes);
/**
- * Check if battery allows charging.
- *
- * @param allowed Non-zero if charging allowed; zero if not allowed.
- * @return non-zero if error.
- */
-int battery_charging_allowed(int *allowed);
-
-/**
* Read battery status.
*
* @param status Destination for status; see STATUS_* in battery_smart.h.
@@ -326,4 +285,3 @@ int battery_device_chemistry(char *dest, int size);
int battery_manufacturer_date(int *year, int *month, int *day);
#endif /* __CROS_EC_BATTERY_H */
-