summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2014-09-09 23:00:33 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-09-17 01:24:11 +0000
commitd86f672d145e31d587a26f9e15ea7df8a81c159f (patch)
tree59a50e6e8a7a88255358718a73f73ea50f1cfd63 /driver
parent5bc3dc3bbe8f062b39065678638b820de330dee2 (diff)
downloadchrome-ec-d86f672d145e31d587a26f9e15ea7df8a81c159f.tar.gz
Add support for BQ27742 battery gauge chip
This reuses most of the existing BQ27541 driver, but changed necessary parts to make it work. BUG=none TEST=Boot on Ryu. See battery charging. BRANCH=factory-ryu-6212.B Change-Id: I3a7325a821c81f84396bcc328036b6a5e7749a2e Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/217198 Reviewed-by: Alec Berg <alecaberg@chromium.org> (cherry picked from commit f44593e20bf61a2243d7baaae901c912ca798d75) Reviewed-on: https://chromium-review.googlesource.com/218413
Diffstat (limited to 'driver')
-rw-r--r--driver/battery/bq27541.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/driver/battery/bq27541.c b/driver/battery/bq27541.c
index dfa5fe01ba..11578037cc 100644
--- a/driver/battery/bq27541.c
+++ b/driver/battery/bq27541.c
@@ -2,17 +2,20 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
- * Battery driver for BQ27541.
+ * Battery driver for BQ27541/BQ27741/BQ27742.
*/
#include "battery.h"
#include "console.h"
#include "extpower.h"
+#include "hooks.h"
#include "i2c.h"
#include "util.h"
#define BQ27541_ADDR 0xaa
#define BQ27541_TYPE_ID 0x0541
+#define BQ27741_TYPE_ID 0x0741
+#define BQ27742_TYPE_ID 0x0742
#define REG_CTRL 0x00
#define REG_AT_RATE 0x02
@@ -42,6 +45,8 @@
#define REG_DEVICE_NAME 0x63
#define REG_PROTECTOR 0x6d
+static int battery_type_id;
+
static int bq27541_read(int offset, int *data)
{
return i2c_read16(I2C_PORT_BATTERY, BQ27541_ADDR, offset, data);
@@ -60,16 +65,25 @@ static int bq27541_write(int offset, int data)
int bq27541_probe(void)
{
int rv;
- int dev_type;
rv = bq27541_write(REG_CTRL, 0x1);
- rv |= bq27541_read(REG_CTRL, &dev_type);
+ rv |= bq27541_read(REG_CTRL, &battery_type_id);
if (rv)
return rv;
- return (dev_type == BQ27541_TYPE_ID) ? EC_SUCCESS : EC_ERROR_UNKNOWN;
+ if (battery_type_id == BQ27541_TYPE_ID ||
+ battery_type_id == BQ27741_TYPE_ID ||
+ battery_type_id == BQ27742_TYPE_ID)
+ return EC_SUCCESS;
+ return EC_ERROR_UNKNOWN;
}
+static void probe_type_id(void)
+{
+ bq27541_probe();
+}
+DECLARE_HOOK(HOOK_INIT, probe_type_id, HOOK_PRIO_DEFAULT);
+
int battery_device_name(char *device_name, int buf_size)
{
int rv, i, val;
@@ -175,7 +189,12 @@ static int battery_charging_allowed(int *allowed)
rv = bq27541_read(REG_FLAGS, &val);
if (rv)
return rv;
- *allowed = (val & 0x100);
+ if (battery_type_id == BQ27541_TYPE_ID ||
+ battery_type_id == BQ27741_TYPE_ID)
+ *allowed = (val & 0x100);
+ else /* BQ27742_TYPE_ID */
+ *allowed = (val & 0x8);
+
return EC_SUCCESS;
}