diff options
author | Scott Collyer <scollyer@google.com> | 2020-06-15 21:19:35 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-20 09:11:59 +0000 |
commit | 319603690cc3b9143e730434cf5f79faba3445b1 (patch) | |
tree | a35c04d906315cf50a4cda152a9cf8628e1bb7b5 /driver/mp4245.c | |
parent | 28e7a812d26ab801dfc260164c3195a9eed12950 (diff) | |
download | chrome-ec-319603690cc3b9143e730434cf5f79faba3445b1.tar.gz |
mp4245: Add a function to retrieve vbus and ibus
This CL adds an api to the driver to retrieve VBUS information. This
can be used by other layers for checking vbus transitions.
BUG=b:169312229
BRANCH=None
TEST=verfied vbus reading matches what was on the scope.
Signed-off-by: Scott Collyer <scollyer@google.com>
Change-Id: I1fba62361a64c3a38ba23574e5516441610c38f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2267632
Tested-by: Scott Collyer <scollyer@chromium.org>
Commit-Queue: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'driver/mp4245.c')
-rw-r--r-- | driver/mp4245.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/driver/mp4245.c b/driver/mp4245.c index 9ab56fe894..5963ebed6e 100644 --- a/driver/mp4245.c +++ b/driver/mp4245.c @@ -53,6 +53,30 @@ int mp4245_votlage_out_enable(int enable) MP4245_CMD_OPERATION, cmd_val); } +int mp3245_get_vbus(int *mv, int *ma) +{ + int vbus = 0; + int ibus = 0; + int rv; + + /* Get Vbus/Ibus raw measurements */ + rv = i2c_read16(I2C_PORT_MP4245, MP4245_SLAVE_ADDR, + MP4245_CMD_READ_VOUT, &vbus); + rv |= i2c_read16(I2C_PORT_MP4245, MP4245_SLAVE_ADDR, + MP4245_CMD_READ_IOUT, &ibus); + + if (rv == EC_SUCCESS) { + /* Convert Vbus/Ibus to mV/mA */ + vbus = MP4245_VOUT_TO_MV(vbus); + ibus = MP4245_IOUT_TO_MA(ibus); + } + + *mv = vbus; + *ma = ibus; + + return rv; +} + struct mp4245_info { uint8_t cmd; uint8_t len; |