summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYongBeum Ha <ybha@samsung.com>2018-12-20 08:54:49 +0900
committerchrome-bot <chrome-bot@chromium.org>2019-01-24 00:51:38 -0800
commitebb25bc556e399678189895b0371065e8c9507c0 (patch)
tree6f179932ebd77a447577fb94e4c79fd3d8c8ad54
parent544ba7da11eeeae342861b5ecfc72a50152a4711 (diff)
downloadchrome-ec-ebb25bc556e399678189895b0371065e8c9507c0.tar.gz
casta : Add battery information
Casta uses same battery as nautilus. BUG=b:122868858 BRANCH=octopus TEST=make -j buildall; flash EC & check battery information Change-Id: I55894821744d242958c2dcf31da355b315d9ac8f Signed-off-by: YongBeum Ha <ybha@samsung.com> Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/1385764 Reviewed-by: Philip Chen <philipchen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1430740 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--board/casta/battery.c122
-rw-r--r--board/casta/board.c43
-rw-r--r--board/casta/board.h5
3 files changed, 167 insertions, 3 deletions
diff --git a/board/casta/battery.c b/board/casta/battery.c
index 6cb4fc5743..7cb6dff4c6 100644
--- a/board/casta/battery.c
+++ b/board/casta/battery.c
@@ -6,9 +6,14 @@
*/
#include "battery_fuel_gauge.h"
+#include "battery_smart.h"
+#include "charge_state.h"
#include "common.h"
#include "util.h"
+#define CHARGING_VOLTAGE_MV_SAFE 8400
+#define CHARGING_CURRENT_MA_SAFE 1500
+
/*
* Battery info for all casta battery types. Note that the fields
* start_charging_min/max and charging_min/max are not used for the charger.
@@ -32,8 +37,121 @@
* address, mask, and disconnect value need to be provided.
*/
const struct board_batt_params board_battery_info[] = {
- /* TODO(b/119871861): Casta: battery datasheets and specs */
+ [BATTERY_SDI] = {
+ .fuel_gauge = {
+ .manuf_name = "SDI",
+ .device_name = "4402D51",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 0,
+ .reg_addr = 0x00,
+ .reg_mask = 0xc000,
+ .disconnect_val = 0x8000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8700,
+ .voltage_normal = 7700, /* mV */
+ .voltage_min = 6000, /* mV */
+ .precharge_current = 200, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 50,
+ .discharging_min_c = -20,
+ .discharging_max_c = 70,
+ },
+ },
};
BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
-const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_TYPE_COUNT;
+const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_SDI;
+
+int charger_profile_override(struct charge_state_data *curr)
+{
+ int current;
+ int voltage;
+ /* battery temp in 0.1 deg C */
+ int bat_temp_c;
+
+ /*
+ * Keep track of battery temperature range:
+ *
+ * ZONE_0 ZONE_1 ZONE_2 ZONE_3
+ * ---+------+--------+--------+------+--- Temperature (C)
+ * 0 5 12 45 50
+ */
+ enum {
+ TEMP_ZONE_0, /* 0 <= bat_temp_c <= 5 */
+ TEMP_ZONE_1, /* 5 < bat_temp_c <= 12 */
+ TEMP_ZONE_2, /* 12 < bat_temp_c <= 45 */
+ TEMP_ZONE_3, /* 45 < bat_temp_c <= 50 */
+ TEMP_ZONE_COUNT,
+ TEMP_OUT_OF_RANGE = TEMP_ZONE_COUNT
+ } temp_zone;
+
+ current = curr->requested_current;
+ voltage = curr->requested_voltage;
+ bat_temp_c = curr->batt.temperature - 2731;
+
+ /*
+ * If the temperature reading is bad, assume the temperature
+ * is out of allowable range.
+ */
+ if ((curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE) ||
+ (bat_temp_c < 0) || (bat_temp_c > 500))
+ temp_zone = TEMP_OUT_OF_RANGE;
+ else if (bat_temp_c <= 50)
+ temp_zone = TEMP_ZONE_0;
+ else if (bat_temp_c <= 120)
+ temp_zone = TEMP_ZONE_1;
+ else if (bat_temp_c <= 450)
+ temp_zone = TEMP_ZONE_2;
+ else
+ temp_zone = TEMP_ZONE_3;
+
+ switch (temp_zone) {
+ case TEMP_ZONE_0:
+ voltage = CHARGING_VOLTAGE_MV_SAFE;
+ current = CHARGING_CURRENT_MA_SAFE;
+ break;
+ case TEMP_ZONE_1:
+ current = CHARGING_CURRENT_MA_SAFE;
+ break;
+ case TEMP_ZONE_2:
+ break;
+ case TEMP_ZONE_3:
+ voltage = CHARGING_VOLTAGE_MV_SAFE;
+ break;
+ case TEMP_OUT_OF_RANGE:
+ /* Don't charge if outside of allowable temperature range */
+ current = 0;
+ voltage = 0;
+ curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE;
+ curr->state = ST_IDLE;
+ break;
+ }
+
+ curr->requested_voltage = MIN(curr->requested_voltage, voltage);
+ curr->requested_current = MIN(curr->requested_current, current);
+
+ 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)
+{
+ return EC_RES_INVALID_PARAM;
+}
+
+enum ec_status charger_profile_override_set_param(uint32_t param,
+ uint32_t value)
+{
+ return EC_RES_INVALID_PARAM;
+}
diff --git a/board/casta/board.c b/board/casta/board.c
index 124601fa75..bcea197537 100644
--- a/board/casta/board.c
+++ b/board/casta/board.c
@@ -88,6 +88,49 @@ const struct temp_sensor_t temp_sensors[] = {
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
+/*
+ * I2C callbacks to ensure bus free time for battery I2C transactions is at
+ * least 5ms.
+ */
+#define BATTERY_FREE_MIN_DELTA_US (5 * MSEC)
+static timestamp_t battery_last_i2c_time;
+
+static int is_battery_i2c(int port, int slave_addr)
+{
+ return (port == I2C_PORT_BATTERY) && (slave_addr == BATTERY_ADDR);
+}
+
+static int is_battery_port(int port)
+{
+ return (port == I2C_PORT_BATTERY);
+}
+
+void i2c_start_xfer_notify(int port, int slave_addr)
+{
+ unsigned int time_delta_us;
+
+ if (!is_battery_i2c(port, slave_addr))
+ return;
+
+ time_delta_us = time_since32(battery_last_i2c_time);
+ if (time_delta_us >= BATTERY_FREE_MIN_DELTA_US)
+ return;
+
+ usleep(BATTERY_FREE_MIN_DELTA_US - time_delta_us);
+}
+
+void i2c_end_xfer_notify(int port, int slave_addr)
+{
+ /*
+ * The bus free time needs to be maintained from last transaction
+ * on I2C bus to any device on it to the next transaction to battery.
+ */
+ if (!is_battery_port(port))
+ return;
+
+ battery_last_i2c_time = get_time();
+}
+
void board_overcurrent_event(int port, int is_overcurrented)
{
/* Sanity check the port. */
diff --git a/board/casta/board.h b/board/casta/board.h
index 8d83af75af..aa18f515b7 100644
--- a/board/casta/board.h
+++ b/board/casta/board.h
@@ -36,6 +36,9 @@
#define CONFIG_MKBP_EVENT
#define CONFIG_MKBP_USE_HOST_EVENT
+/* Battery W/A */
+#define CONFIG_I2C_XFER_BOARD_CALLBACK
+
#ifndef __ASSEMBLER__
#include "gpio_signal.h"
@@ -55,8 +58,8 @@ enum temp_sensor_id {
};
/* List of possible batteries */
-/* TODO(b/119871861): Casta: battery datasheets and specs */
enum battery_type {
+ BATTERY_SDI,
BATTERY_TYPE_COUNT,
};