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 | |
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')
-rw-r--r-- | driver/mp4245.c | 24 | ||||
-rw-r--r-- | driver/mp4245.h | 20 |
2 files changed, 44 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; diff --git a/driver/mp4245.h b/driver/mp4245.h index bfa1c80d7a..b453ad2076 100644 --- a/driver/mp4245.h +++ b/driver/mp4245.h @@ -50,6 +50,17 @@ #define MP4245_VOUT_TO_MV(v) ((v * 1000) / MP4245_VOUT_1V) #define MP4245_IOUT_TO_MA(i) (((i & 0x7ff) * 1000) / BIT(6)) #define MP4245_ILIM_STEP_MA 50 +#define MP4245_VOUT_5V_DELAY_MS 10 + + +#define MP4245_MFR_STATUS_MASK_VOUT BIT(7) +#define MP4245_MFR_STATUS_MASK_IOUT BIT(6) +#define MP4245_MFR_STATUS_MASK_INPUT BIT(5) +#define MP4245_MFR_STATUS_MASK_TEMP BIT(4) +#define MP4245_MFR_STATUS_MASK_PG_STATUS BIT(3) +#define MP4245_MFR_STATUS_MASK_PG_ALT_EDGE BIT(2) +#define MP4245_MFR_STATUS_MASK_OTHER BIT(1) +#define MP4245_MFR_STATUS_MASK_UNKNOWN BIT(0) /** * MP4245 set output voltage level @@ -74,3 +85,12 @@ int mp4245_set_current_lim(int desired_ma); * @return i2c write result */ int mp4245_votlage_out_enable(int enable); + +/** + * MP4245 get Vbus voltage/current values + * + * @param *mv -> vbus voltage in mV + * @param *ma -> vbus current in mA + * @return i2c read results + */ +int mp3245_get_vbus(int *mv, int *ma); |