summaryrefslogtreecommitdiff
path: root/board/amenia/battery.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/amenia/battery.c')
-rw-r--r--board/amenia/battery.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/board/amenia/battery.c b/board/amenia/battery.c
new file mode 100644
index 0000000000..a931ff3d91
--- /dev/null
+++ b/board/amenia/battery.c
@@ -0,0 +1,95 @@
+/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Battery pack vendor provided charging profile
+ */
+
+#include "battery.h"
+#include "battery_smart.h"
+#include "charge_state.h"
+#include "console.h"
+#include "ec_commands.h"
+#include "gpio.h"
+#include "i2c.h"
+#include "util.h"
+
+/* Shutdown mode parameter to write to manufacturer access register */
+#define PARAM_CUT_OFF_LOW 0x10
+#define PARAM_CUT_OFF_HIGH 0x00
+
+/* Battery info for BQ40Z55 */
+static const struct battery_info info = {
+ .voltage_max = 8700, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6100,
+ .precharge_current = 200, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+};
+
+const struct battery_info *battery_get_info(void)
+{
+ static struct battery_info batt_info;
+
+ if (battery_is_present() == BP_YES)
+ return &info;
+
+ /* Use voltage_max for voltage min if battery is not present */
+ batt_info = info;
+ batt_info.voltage_min = batt_info.voltage_max;
+ return &batt_info;
+}
+
+int board_cut_off_battery(void)
+{
+ int rv;
+ uint8_t buf[3];
+
+ /* Ship mode command must be sent twice to take effect */
+ buf[0] = SB_MANUFACTURER_ACCESS & 0xff;
+ buf[1] = PARAM_CUT_OFF_LOW;
+ buf[2] = PARAM_CUT_OFF_HIGH;
+
+ i2c_lock(I2C_PORT_BATTERY, 1);
+ rv = i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
+ I2C_XFER_SINGLE);
+ rv |= i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
+ I2C_XFER_SINGLE);
+ i2c_lock(I2C_PORT_BATTERY, 0);
+
+ return rv;
+}
+
+#ifdef CONFIG_BATTERY_PRESENT_CUSTOM
+/*
+ * Physical detection of battery.
+ */
+enum battery_present battery_is_present(void)
+{
+ enum battery_present batt_pres;
+ const struct batt_params *batt = charger_current_battery_params();
+
+ /* The GPIO is low when the battery is physically present */
+ batt_pres = gpio_get_level(GPIO_BAT_PRESENT_L) ? BP_NO : BP_YES;
+
+ /*
+ * Make sure battery status is implemented, I2C transactions are
+ * success & the battery status is Initialized to find out if it
+ * is a working battery and it is not in the cut-off mode.
+ *
+ * FETs are turned off after Power Shutdown time.
+ * The device will wake up when a voltage is applied to PACK.
+ * Battery status will be inactive until it is initialized.
+ */
+ if (batt_pres == BP_YES && !(batt->flags & BATT_FLAG_BAD_STATUS))
+ if (!(batt->status & STATUS_INITIALIZED))
+ batt_pres = BP_NO;
+
+ return batt_pres;
+}
+#endif