summaryrefslogtreecommitdiff
path: root/common/usb_charger.c
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-06-09 14:29:09 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-12 16:37:39 +0000
commit5b7cfac64e971a7e925d17a8b33e651a01e71707 (patch)
tree72ee34fae7f6bee5d2c8d781e5256fbceee3f8e1 /common/usb_charger.c
parent9941f088d7a56ba4ba7396d9221612b00143a3cc (diff)
downloadchrome-ec-5b7cfac64e971a7e925d17a8b33e651a01e71707.tar.gz
usb: pi3usb9281: Allow flexible chip configurations
Previously we supported using a single pi3usb9281 chip, or using two chips on the same i2c bus behind a mux. Now that we need to support a third configuration of multiple chips on different busses, it makes sense to be able to configure the configuration freely at the board level. BUG=chrome-os-partner:40920 TEST=Manual on samus_pd. Plug USB charger, verify detection is correct on both charge ports. BRANCH=None Change-Id: I120dcb1c3ceb6f013b92407effcd8cb66e7ffcce Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/276511 Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'common/usb_charger.c')
-rw-r--r--common/usb_charger.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/common/usb_charger.c b/common/usb_charger.c
index bb85fc3c7f..b003f415e4 100644
--- a/common/usb_charger.c
+++ b/common/usb_charger.c
@@ -16,6 +16,7 @@
#include "pi3usb9281.h"
#include "task.h"
#include "timer.h"
+#include "usb_charge.h"
#include "usb_pd.h"
/* Wait after a charger is detected to debounce pin contact order */
@@ -26,24 +27,36 @@
*/
#define USB_CHG_RESET_DELAY_MS 100
+int usb_charger_port_is_sourcing_vbus(int port)
+{
+ if (port == 0)
+ return gpio_get_level(GPIO_USB_C0_5V_EN);
+#if CONFIG_USB_PD_PORT_COUNT >= 2
+ else if (port == 1)
+ return gpio_get_level(GPIO_USB_C1_5V_EN);
+#endif
+ /* Not a valid port */
+ return 0;
+}
+
void usb_charger_task(void)
{
int port = (task_get_current() == TASK_ID_USB_CHG_P0 ? 0 : 1);
-#if (CONFIG_USB_PD_PORT_COUNT == 1)
- int vbus_source = GPIO_USB_C0_5V_EN;
-#else
- int vbus_source = (port == 0 ? GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN);
-#endif
+
int device_type, charger_status;
struct charge_port_info charge;
int type;
+
charge.voltage = USB_BC12_CHARGE_VOLTAGE;
+ /* Initialize chip and enable interrupts */
+ pi3usb9281_init(port);
+
while (1) {
/* Read interrupt register to clear on chip */
pi3usb9281_get_interrupts(port);
- if (gpio_get_level(vbus_source)) {
+ if (usb_charger_port_is_sourcing_vbus(port)) {
/* If we're sourcing VBUS then we're not charging */
device_type = charger_status = 0;
} else {