summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2018-04-02 15:08:09 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-04-10 19:12:47 -0700
commitc8814430d65c440950446c573db0932707f02c89 (patch)
treef4c97fef2f67d4db2b0c6aba41306a3cca5278fe
parent98c4ef1870216332da90d255f524f087953451a8 (diff)
downloadchrome-ec-c8814430d65c440950446c573db0932707f02c89.tar.gz
yorp: add more USB-C power logic
* TCPC reset * PPC input charging (current/voltage limits) * PPC output charging * VBUS presence detection BRANCH=none BUG=b:74127309,b:77458917,b:77579760 TEST=yorp C1 can negotiate 20V at 3A Change-Id: Ifa84071be1617a060a217d00bc102d836edffe95 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/991081
-rw-r--r--board/yorp/board.c68
-rw-r--r--board/yorp/usb_pd_policy.c49
-rw-r--r--driver/tcpm/ps8xxx.h3
3 files changed, 106 insertions, 14 deletions
diff --git a/board/yorp/board.c b/board/yorp/board.c
index 6842221d32..c1b1a9ac27 100644
--- a/board/yorp/board.c
+++ b/board/yorp/board.c
@@ -8,6 +8,8 @@
#include "adc.h"
#include "adc_chip.h"
#include "battery.h"
+#include "charge_manager.h"
+#include "charge_state.h"
#include "common.h"
#include "driver/accel_kionix.h"
#include "driver/accelgyro_lsm6dsm.h"
@@ -34,6 +36,9 @@
#include "usbc_ppc.h"
#include "util.h"
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
#define USB_PD_PORT_ANX7447 0
#define USB_PD_PORT_PS8751 1
@@ -195,19 +200,76 @@ enum adc_channel board_get_vbus_adc(int port)
*/
void board_reset_pd_mcu(void)
{
- /* TODO(b/74127309): Flesh out USB code */
+
+ /* Assert reset to TCPC1 (PS8751) for required delay (1ms) */
+ gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 0);
+ msleep(PS8XXX_RESET_DELAY_MS);
+ gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 1);
+
+ /* ANX7447 does not have a reset pin. */
}
int board_set_active_charge_port(int port)
{
- /* TODO(b/74127309): Flesh out USB code */
+ int is_real_port = (port >= 0 &&
+ port < CONFIG_USB_PD_PORT_COUNT);
+ int i;
+
+ if (!is_real_port && port != CHARGE_PORT_NONE)
+ return EC_ERROR_INVAL;
+
+
+ if (port == CHARGE_PORT_NONE) {
+ CPRINTSUSB("Disabling all charger ports");
+
+ /* Disable all ports. */
+ for (i = 0; i < ppc_cnt; i++) {
+ /*
+ * Do not return early if one fails otherwise we can
+ * get into a boot loop assertion failure.
+ */
+ if (ppc_vbus_sink_enable(i, 0))
+ CPRINTSUSB("Disabling C%d as sink failed.", i);
+ }
+
+ return EC_SUCCESS;
+ }
+
+ CPRINTSUSB("New charge port: C%d", port);
+
+ /* Check if the port is sourcing VBUS. */
+ if (ppc_is_sourcing_vbus(port)) {
+ CPRINTFUSB("Skip enable C%d", port);
+ return EC_ERROR_INVAL;
+ }
+
+ /*
+ * Turn off the other ports' sink path FETs, before enabling the
+ * requested charge port.
+ */
+ for (i = 0; i < ppc_cnt; i++) {
+ if (i == port)
+ continue;
+
+ if (ppc_vbus_sink_enable(i, 0))
+ CPRINTSUSB("C%d: sink path disable failed.", i);
+ }
+
+ /* Enable requested charge port. */
+ if (ppc_vbus_sink_enable(port, 1)) {
+ CPRINTSUSB("C%d: sink path enable failed.", port);
+ return EC_ERROR_UNKNOWN;
+ }
+
return EC_SUCCESS;
}
void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
- /* TODO(b/74127309): Flesh out USB code */
+ charge_set_input_current_limit(MAX(charge_ma,
+ CONFIG_CHARGER_INPUT_CURRENT),
+ charge_mv);
}
void board_tcpc_init(void)
diff --git a/board/yorp/usb_pd_policy.c b/board/yorp/usb_pd_policy.c
index 93ad7dfa40..0d7db82725 100644
--- a/board/yorp/usb_pd_policy.c
+++ b/board/yorp/usb_pd_policy.c
@@ -115,12 +115,46 @@ int pd_is_valid_input_voltage(int mv)
void pd_power_supply_reset(int port)
{
- /* TODO(b/74127309): Flesh out USB code */
+ int prev_en;
+
+ prev_en = ppc_is_sourcing_vbus(port);
+
+ /* Disable VBUS. */
+ ppc_vbus_source_enable(port, 0);
+
+ /* Enable discharge if we were previously sourcing 5V */
+ if (prev_en)
+ pd_set_vbus_discharge(port, 1);
+
+#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
+ /* Give back the current quota we are no longer using */
+ charge_manager_source_port(port, 0);
+#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */
+
+ /* Notify host of power info change. */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
}
int pd_set_power_supply_ready(int port)
{
- /* TODO(b/74127309): Flesh out USB code */
+ int rv;
+
+ /* Disable charging. */
+ rv = ppc_vbus_sink_enable(port, 0);
+ if (rv)
+ return rv;
+
+ pd_set_vbus_discharge(port, 0);
+
+ /* Provide Vbus. */
+ rv = ppc_vbus_source_enable(port, 1);
+ if (rv)
+ return rv;
+
+#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
+ /* Ensure we advertise the proper available current quota */
+ charge_manager_source_port(port, 1);
+#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */
/* Notify host of power info change. */
pd_send_host_event(PD_EVENT_POWER_CHANGE);
@@ -135,19 +169,12 @@ void pd_transition_voltage(int idx)
void typec_set_source_current_limit(int port, int rp)
{
- /* TODO(b/74127309): Flesh out USB code */
-}
-
-int pd_snk_is_vbus_provided(int port)
-{
- /* TODO(b/74127309): Flesh out USB code */
- return 0;
+ ppc_set_vbus_source_current_limit(port, rp);
}
int board_vbus_source_enabled(int port)
{
- /* TODO(b/74127309): Flesh out USB code */
- return 0;
+ return ppc_is_sourcing_vbus(port);
}
/* ----------------- Vendor Defined Messages ------------------ */
diff --git a/driver/tcpm/ps8xxx.h b/driver/tcpm/ps8xxx.h
index a9660843ee..6c66210982 100644
--- a/driver/tcpm/ps8xxx.h
+++ b/driver/tcpm/ps8xxx.h
@@ -14,6 +14,9 @@
#define PS8751_I2C_ADDR3 0x56
#define PS8751_I2C_ADDR4 0x96
+/* Minimum Delay for reset assertion */
+#define PS8XXX_RESET_DELAY_MS 1
+
#define PS8751_BIST_TIMER_FREQ 15000000
#define PS8751_BIST_DELAY_MS 50