summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid.Huang <David.Huang@quantatw.com>2017-03-08 16:58:13 +0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-04-27 03:27:50 +0000
commitb299a3c6717dd93bf9f26e6c00ad13cd9dfd3fd3 (patch)
tree53241230b4965a0dac43862c3e41cd836b323d40
parentc2730ea9ebed95d2f53f0bcf971888bec3532314 (diff)
downloadchrome-ec-b299a3c6717dd93bf9f26e6c00ad13cd9dfd3fd3.tar.gz
Yuna: Change charge voltage for battery
Change battery charge voltage based on Cycle Count or State of Health for different battery. BRANCH=yuna BUG=b:37727454 TEST=Use console command "charger" to check charge voltage with different battery. Signed-off-by: David Huang <David.Huang@quantatw.com> Change-Id: Id9abfea643aefe1960b6045ec8a419a25579e551 Reviewed-on: https://chromium-review.googlesource.com/479611 Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r--board/yuna/board.h1
-rw-r--r--board/yuna/bq24707a.c210
-rw-r--r--board/yuna/bq24707a.h44
-rw-r--r--board/yuna/build.mk2
4 files changed, 255 insertions, 2 deletions
diff --git a/board/yuna/board.h b/board/yuna/board.h
index 5d0f283835..69ecd2e633 100644
--- a/board/yuna/board.h
+++ b/board/yuna/board.h
@@ -18,7 +18,6 @@
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER
#define CONFIG_CHARGER_V1
-#define CONFIG_CHARGER_BQ24707A
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHIPSET_CAN_THROTTLE
#define CONFIG_CHIPSET_HASWELL
diff --git a/board/yuna/bq24707a.c b/board/yuna/bq24707a.c
new file mode 100644
index 0000000000..7ac082554c
--- /dev/null
+++ b/board/yuna/bq24707a.c
@@ -0,0 +1,210 @@
+/* Copyright (c) 2012 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.
+ *
+ * TI bq24707A battery charger driver.
+ */
+
+#include "battery_smart.h"
+#include "battery.h"
+#include "bq24707a.h"
+#include "charger.h"
+#include "console.h"
+#include "common.h"
+#include "util.h"
+
+/* Console output macros */
+#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
+
+/* Sense resistor configurations and macros */
+#define DEFAULT_SENSE_RESISTOR 10
+#define R_SNS CONFIG_CHARGER_SENSE_RESISTOR
+#define R_AC CONFIG_CHARGER_SENSE_RESISTOR_AC
+#define REG_TO_CURRENT(REG, RS) ((REG) * DEFAULT_SENSE_RESISTOR / (RS))
+#define CURRENT_TO_REG(CUR, RS) ((CUR) * (RS) / DEFAULT_SENSE_RESISTOR)
+
+/*
+ * charge voltage bitmask: 0111 1111 1111 0000
+ * charge current bitmask: 0001 1111 1100 0000
+ * input current bitmask : 0001 1111 1000 0000
+ */
+static const struct charger_info bq24707a_charger_info = {
+ .name = "bq24707A",
+ .voltage_max = 19200,
+ .voltage_min = 1024,
+ .voltage_step = 16,
+ .current_max = REG_TO_CURRENT(0x1fc0, R_SNS),
+ .current_min = REG_TO_CURRENT(0x40, R_SNS),
+ .current_step = REG_TO_CURRENT(0x40, R_SNS),
+ .input_current_max = REG_TO_CURRENT(0x1F80, R_AC),
+ .input_current_min = REG_TO_CURRENT(0x80, R_AC),
+ .input_current_step = REG_TO_CURRENT(0x80, R_AC),
+};
+
+/* bq24707a specific interfaces */
+
+int charger_set_input_current(int input_current)
+{
+ return sbc_write(BQ24707_INPUT_CURRENT,
+ CURRENT_TO_REG(input_current, R_AC));
+}
+
+int charger_get_input_current(int *input_current)
+{
+ int rv;
+ int reg;
+
+ rv = sbc_read(BQ24707_INPUT_CURRENT, &reg);
+ if (rv)
+ return rv;
+
+ *input_current = REG_TO_CURRENT(reg, R_AC);
+
+ return EC_SUCCESS;
+}
+
+int charger_manufacturer_id(int *id)
+{
+ return sbc_read(BQ24707_MANUFACTURE_ID, id);
+}
+
+int charger_device_id(int *id)
+{
+ return sbc_read(BQ24707_DEVICE_ID, id);
+}
+
+int charger_get_option(int *option)
+{
+ return sbc_read(BQ24707_CHARGE_OPTION, option);
+}
+
+int charger_set_option(int option)
+{
+ return sbc_write(BQ24707_CHARGE_OPTION, option);
+}
+
+/* Charger interfaces */
+
+const struct charger_info *charger_get_info(void)
+{
+ return &bq24707a_charger_info;
+}
+
+int charger_get_status(int *status)
+{
+ int rv;
+ int option;
+
+ rv = charger_get_option(&option);
+ if (rv)
+ return rv;
+
+ /* Default status */
+ *status = CHARGER_LEVEL_2;
+
+ if (option & OPTION_CHARGE_INHIBIT)
+ *status |= CHARGER_CHARGE_INHIBITED;
+
+ return EC_SUCCESS;
+}
+
+int charger_set_mode(int mode)
+{
+ int rv;
+ int option;
+
+ rv = charger_get_option(&option);
+ if (rv)
+ return rv;
+
+ if (mode & CHARGE_FLAG_INHIBIT_CHARGE)
+ option |= OPTION_CHARGE_INHIBIT;
+ else
+ option &= ~OPTION_CHARGE_INHIBIT;
+ return charger_set_option(option);
+}
+
+int charger_get_current(int *current)
+{
+ int rv;
+ int reg;
+
+ rv = sbc_read(SB_CHARGING_CURRENT, &reg);
+ if (rv)
+ return rv;
+
+ *current = REG_TO_CURRENT(reg, R_SNS);
+ return EC_SUCCESS;
+}
+
+int charger_set_current(int current)
+{
+ current = charger_closest_current(current);
+
+ return sbc_write(SB_CHARGING_CURRENT, CURRENT_TO_REG(current, R_SNS));
+}
+
+int charger_get_voltage(int *voltage)
+{
+ return sbc_read(SB_CHARGING_VOLTAGE, voltage);
+}
+
+static int battery_charge_voltage_check(void)
+{
+ int cycle, fcc, dc, soh, rv, change = 0;
+ char device[10];
+
+ if (!battery_device_name(device, sizeof(device))) {
+ CPRINTF("Battery device name : %s", device);
+ if (!strcasecmp(device, "AC14B8K")) {
+ rv = battery_cycle_count(&cycle);
+ if (!rv && cycle >= 21) {
+ CPRINTF("Cycle change charge voltage\n");
+ change = 1;
+ return change;
+ }
+ } else if (!strcasecmp(device, "AC14B3K")) {
+ rv = battery_full_charge_capacity(&fcc);
+ rv &= battery_design_capacity(&dc);
+ if (!rv) {
+ soh = fcc*100/dc;
+ if (soh <= 95) {
+ CPRINTF("SOH change charge voltage\n");
+ change = 1;
+ return change;
+ }
+ }
+ }
+ }
+ return change;
+}
+
+int charger_set_voltage(int voltage)
+{
+ if (battery_charge_voltage_check()) {
+ if (voltage != 0) {
+ CPRINTF("Change charge voltage\n");
+ voltage = charger_closest_voltage(17000);
+ }
+ } else
+ voltage = charger_closest_voltage(voltage);
+
+ return sbc_write(SB_CHARGING_VOLTAGE, voltage);
+}
+
+/* Charging power state initialization */
+int charger_post_init(void)
+{
+ /*
+ * Note: bq24725 power on reset state is:
+ * watch dog timer = 175 sec
+ * input current limit = ~1/2 maximum setting
+ * charging voltage = 0 mV
+ * charging current = 0 mA
+ * IOUT = 20x adapter current sense
+ */
+
+ /* Set charger input current limit */
+ return charger_set_input_current(CONFIG_CHARGER_INPUT_CURRENT);
+}
diff --git a/board/yuna/bq24707a.h b/board/yuna/bq24707a.h
new file mode 100644
index 0000000000..744e991283
--- /dev/null
+++ b/board/yuna/bq24707a.h
@@ -0,0 +1,44 @@
+/* Copyright (c) 2012 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.
+ *
+ * TI bq24707A battery charger driver.
+ */
+
+#ifndef __CROS_EC_CHARGER_BQ24707A_H
+#define __CROS_EC_CHARGER_BQ24707A_H
+
+/* Chip specific commands */
+#define BQ24707_CHARGE_OPTION 0x12
+#define BQ24707_INPUT_CURRENT 0x3f
+#define BQ24707_MANUFACTURE_ID 0xfe
+#define BQ24707_DEVICE_ID 0xff
+
+/* ChargeOption 0x12 */
+#define OPTION_CHARGE_INHIBIT (1 << 0)
+#define OPTION_ACOC_THRESHOLD (3 << 1)
+#define OPTION_COMPARATOR_THRESHOLD (1 << 4)
+#define OPTION_IOUT_SELECTION (1 << 5)
+#define OPTION_IFAULT_HI_THRESHOLD (3 << 7)
+#define OPTION_EMI_FREQ_ENABLE (1 << 9)
+#define OPTION_EMI_FREQ_ADJ (1 << 10)
+#define OPTION_WATCHDOG_TIMER (3 << 13)
+#define OPTION_AOC_DELITCH_TIME (1 << 15)
+/* OPTION_ACOC_THRESHOLD */
+#define ACOC_THRESHOLD_DISABLE (0 << 1)
+#define ACOC_THRESHOLD_133X (1 << 1)
+#define ACOC_THRESHOLD_166X_DEFAULT (2 << 1)
+#define ACOC_THRESHOLD_222X (3 << 1)
+/* OPTION_IFAULT_HI_THRESHOLD */
+#define IFAULT_THRESHOLD_300MV (0 << 7)
+#define IFAULT_THRESHOLD_500MV (1 << 7)
+#define IFAULT_THRESHOLD_700MV_DEFAULT (2 << 7)
+#define IFAULT_THRESHOLD_900MV (3 << 7)
+/* OPTION_WATCHDOG_TIMER */
+#define CHARGE_WATCHDOG_DISABLE (0 << 13)
+#define CHARGE_WATCHDOG_44SEC (1 << 13)
+#define CHARGE_WATCHDOG_88SEC (2 << 13)
+#define CHARGE_WATCHDOG_175SEC_DEFAULT (3 << 13)
+
+#endif /* __CROS_EC_CHARGER_BQ24707A_H */
+
diff --git a/board/yuna/build.mk b/board/yuna/build.mk
index 887e527d1b..259c250ce4 100644
--- a/board/yuna/build.mk
+++ b/board/yuna/build.mk
@@ -9,4 +9,4 @@
# the IC is TI Stellaris LM4
CHIP:=lm4
-board-y=board.o battery.o led.o
+board-y=board.o battery.o led.o bq24707a.o