diff options
author | Andrew McRae <amcrae@google.com> | 2019-11-08 15:47:56 +1100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-11-14 04:31:44 +0000 |
commit | 86a7e2f4b791ec02da9403781b21ae19e3e6cb1e (patch) | |
tree | b084704c52b7ecb05d424e53c8cbad9ccca4fe27 /driver/ina3221.h | |
parent | a4972e187c6ce582aa54dbfce6039fd2239e4bbd (diff) | |
download | chrome-ec-86a7e2f4b791ec02da9403781b21ae19e3e6cb1e.tar.gz |
ec: Add driver for TI INA3221 voltage sensors.
Add driver for TI INA3221 voltage sensors.
Puff has several of these devices, and the EC has access to them.
BRANCH=none
BUG=b:144132145
TEST=EC buildall, tests
Change-Id: I37efd6ce7f154339f002c633e5daf6a18fef05aa
Signed-off-by: Andrew McRae <amcrae@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1903629
Reviewed-by: Shelley Chen <shchen@chromium.org>
Reviewed-by: Andrew McRae <amcrae@chromium.org>
Tested-by: Andrew McRae <amcrae@chromium.org>
Commit-Queue: Andrew McRae <amcrae@chromium.org>
Diffstat (limited to 'driver/ina3221.h')
-rw-r--r-- | driver/ina3221.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/driver/ina3221.h b/driver/ina3221.h new file mode 100644 index 0000000000..4d8c8211b4 --- /dev/null +++ b/driver/ina3221.h @@ -0,0 +1,55 @@ +/* Copyright 2019 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 INA3221 Current/Power monitor driver. + */ + +#ifndef __CROS_EC_INA3221_H +#define __CROS_EC_INA3221_H + +#define INA3221_REG_CONFIG 0x00 +#define INA3221_REG_MASK 0x0F + +/* + * Common bits are: + * Reset + * average = 1 + * conversion time = 1.1 ms + * mode = shunt and bus, continuous. + */ +#define INA3221_CONFIG_BASE 0x8127 + +/* Bus voltage: lower 3 bits clear, LSB = 8 mV */ +#define INA3221_BUS_MV(reg) (reg) +/* Shunt voltage: lower 3 bits clear, LSB = 40 uV */ +#define INA3221_SHUNT_UV(reg) ((reg) * (40/8)) + +enum ina3221_channel { + INA3221_CHAN_1 = 0, + INA3221_CHAN_2 = 1, + INA3221_CHAN_3 = 2, + INA3221_CHAN_COUNT = 3 +}; + +/* Registers for each channel */ +enum ina3221_register { + INA3221_SHUNT_VOLT = 0, + INA3221_BUS_VOLT = 1, + INA3221_CRITICAL = 2, + INA3221_WARNING = 3, + INA3221_MAX_REG = 4 +}; + +/* Configuration table - defined in board file. */ +struct ina3221_t { + int port; /* I2C port index */ + uint8_t address; /* I2C address */ + const char *name[INA3221_CHAN_COUNT]; /* Channel names */ +}; + +/* External config in board file */ +extern const struct ina3221_t ina3221[]; +extern const unsigned int ina3221_count; + +#endif /* __CROS_EC_INA3221_H */ |