diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2014-10-09 15:18:45 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-10-10 06:54:22 +0000 |
commit | ac2b30d1e74f4cf2e956db58d13fbaffd61cb3aa (patch) | |
tree | a1ad61486ae58baa478ce566686f53afb8e3eda7 /driver | |
parent | 358aeb287778d40ae6d57157ec2b9117a69070fe (diff) | |
download | chrome-ec-ac2b30d1e74f4cf2e956db58d13fbaffd61cb3aa.tar.gz |
pi3usb9281: Add function for translating registers to current limit
Decode Pericom registers to current limits.
BUG=chrome-os-partner:32003
TEST=Manual on samus_pd. Insert 1A Apple charger, verify current limit
is correctly detected as 1A.
BRANCH=samus
Change-Id: I310d9f22cef80e97c1734e6a56f0034ebe01df31
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222638
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/pi3usb9281.h | 3 | ||||
-rw-r--r-- | driver/usb_switch_pi3usb9281.c | 22 |
2 files changed, 25 insertions, 0 deletions
diff --git a/driver/pi3usb9281.h b/driver/pi3usb9281.h index ebcd333d80..d26295b846 100644 --- a/driver/pi3usb9281.h +++ b/driver/pi3usb9281.h @@ -74,6 +74,9 @@ int pi3usb9281_get_device_type(uint8_t chip_idx); /* Get attached charger status. */ int pi3usb9281_get_charger_status(uint8_t chip_idx); +/* Get charger current limit based on device type and charger status. */ +int pi3usb9281_get_ilim(int device_type, int charger_status); + /* Set switch configuration to manual. */ int pi3usb9281_set_switch_manual(uint8_t chip_idx, int val); diff --git a/driver/usb_switch_pi3usb9281.c b/driver/usb_switch_pi3usb9281.c index b7a82a2e09..78580fc7a8 100644 --- a/driver/usb_switch_pi3usb9281.c +++ b/driver/usb_switch_pi3usb9281.c @@ -119,6 +119,28 @@ int pi3usb9281_get_charger_status(uint8_t chip_idx) return pi3usb9281_read(chip_idx, PI3USB9281_REG_CHG_STATUS) & 0x1f; } +int pi3usb9281_get_ilim(int device_type, int charger_status) +{ + /* Limit USB port current. 500mA for not listed types. */ + int current_limit_ma = 500; + + if (charger_status & PI3USB9281_CHG_CAR_TYPE1 || + charger_status & PI3USB9281_CHG_CAR_TYPE2) + current_limit_ma = 3000; + else if (charger_status & PI3USB9281_CHG_APPLE_1A) + current_limit_ma = 1000; + else if (charger_status & PI3USB9281_CHG_APPLE_2A) + current_limit_ma = 2000; + else if (charger_status & PI3USB9281_CHG_APPLE_2_4A) + current_limit_ma = 2400; + else if (device_type & PI3USB9281_TYPE_CDP) + current_limit_ma = 1500; + else if (device_type & PI3USB9281_TYPE_DCP) + current_limit_ma = 1500; + + return current_limit_ma; +} + int pi3usb9281_get_vbus(uint8_t chip_idx) { int vbus = pi3usb9281_read(chip_idx, PI3USB9281_REG_VBUS); |