summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2017-11-27 11:11:14 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-12-05 22:43:45 -0800
commit9c4008e35c291017c7a0ffbe96e1e5d9df8a0e5a (patch)
treebe29cf3f63098c673b122425c09521816dea318a
parent9300c0d470f3d266465731b941075f6d0a321636 (diff)
downloadchrome-ec-9c4008e35c291017c7a0ffbe96e1e5d9df8a0e5a.tar.gz
ppc: Add common APIs.
It'll be easier to add support for new PPCs if we make a generic API. BUG=None BRANCH=None TEST=make -j buildall Change-Id: I9aac1750eb4c163eb2b94aa8975c797f86d0a25a Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/791499 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--common/usb_charger.c5
-rw-r--r--driver/ppc/sn5s330.c25
-rw-r--r--include/config.h6
-rw-r--r--include/usbc_ppc.h40
4 files changed, 76 insertions, 0 deletions
diff --git a/common/usb_charger.c b/common/usb_charger.c
index 2cd9cfbcd3..1c01695d0e 100644
--- a/common/usb_charger.c
+++ b/common/usb_charger.c
@@ -20,6 +20,7 @@
#include "task.h"
#include "usb_charge.h"
#include "usb_pd.h"
+#include "usbc_ppc.h"
static void update_vbus_supplier(int port, int vbus_level)
{
@@ -38,11 +39,15 @@ static void update_vbus_supplier(int port, int vbus_level)
}
}
+#ifndef CONFIG_USBC_PPC
#ifdef CONFIG_USB_PD_5V_EN_ACTIVE_LOW
#define USB_5V_EN(port) !gpio_get_level(GPIO_USB_C##port##_5V_EN_L)
#else
#define USB_5V_EN(port) gpio_get_level(GPIO_USB_C##port##_5V_EN)
#endif
+#else /* defined(CONFIG_USBC_PPC) */
+#define USB_5V_EN(port) ppc_is_sourcing_vbus(port)
+#endif /* !defined(CONFIG_USBC_PPC) */
int usb_charger_port_is_sourcing_vbus(int port)
{
diff --git a/driver/ppc/sn5s330.c b/driver/ppc/sn5s330.c
index 9871209e76..05cb9eac14 100644
--- a/driver/ppc/sn5s330.c
+++ b/driver/ppc/sn5s330.c
@@ -439,3 +439,28 @@ static void sn5s330_init(void)
}
}
DECLARE_HOOK(HOOK_INIT, sn5s330_init, HOOK_PRIO_INIT_I2C + 1);
+
+int ppc_is_sourcing_vbus(int port)
+{
+ int is_sourcing_vbus;
+ int rv;
+
+ rv = sn5s330_is_pp_fet_enabled(port, SN5S330_PP1, &is_sourcing_vbus);
+ if (rv) {
+ CPRINTS("C%d: Failed to determine source FET status! (%d)",
+ port, rv);
+ return 0;
+ }
+
+ return is_sourcing_vbus;
+}
+
+int ppc_vbus_sink_enable(int port, int enable)
+{
+ return sn5s330_pp_fet_enable(port, SN5S330_PP2, !!enable);
+}
+
+int ppc_vbus_source_enable(int port, int enable)
+{
+ return sn5s330_pp_fet_enable(port, SN5S330_PP1, !!enable);
+}
diff --git a/include/config.h b/include/config.h
index 6d89ba5f66..bb4584b0b6 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3097,6 +3097,12 @@
#endif
/*****************************************************************************/
+/* Define CONFIG_USBC_PPC if board has a USB Type-C Power Path Controller. */
+#if defined(CONFIG_USBC_PPC_SN5S330)
+#define CONFIG_USBC_PPC
+#endif /* "has a PPC" */
+
+/*****************************************************************************/
/*
* Define CONFIG_USB_PD_VBUS_MEASURE_CHARGER if the charger on the board
* supports VBUS measurement.
diff --git a/include/usbc_ppc.h b/include/usbc_ppc.h
new file mode 100644
index 0000000000..0af3e766e3
--- /dev/null
+++ b/include/usbc_ppc.h
@@ -0,0 +1,40 @@
+/* Copyright 2017 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.
+ */
+
+#ifndef __CROS_EC_USBC_PPC_H
+#define __CROS_EC_USBC_PPC_H
+
+#include "common.h"
+
+
+/* Common APIs for USB Type-C Power Path Controllers (PPC) */
+
+/**
+ * Is the port sourcing Vbus?
+ *
+ * @param port: The type c port.
+ * @return 1 if sourcing Vbus, 0 if not.
+ */
+int ppc_is_sourcing_vbus(int port);
+
+/**
+ * Allow current to flow into the system.
+ *
+ * @param port: The Type-C port's FET to open.
+ * @param enable: 1: Turn on the FET, 0: turn off the FET.
+ * @return EC_SUCCESS on success, error otherwise.
+ */
+int ppc_vbus_sink_enable(int port, int enable);
+
+/**
+ * Allow current out of the system.
+ *
+ * @param port: The Type-C port's FET to open.
+ * @param enable: 1: Turn on the FET, 0: turn off the FET.
+ * @return EC_SUCCESS on success, error otherwise.
+ */
+int ppc_vbus_source_enable(int port, int enable);
+
+#endif /* !defined(__CROS_EC_USBC_PPC_H) */