summaryrefslogtreecommitdiff
path: root/board/servo_v4/usb_pd_policy.c
diff options
context:
space:
mode:
authorScott <scollyer@chromium.org>2016-12-08 09:39:11 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-12-21 00:43:27 -0800
commit167f7e51d8e7693a277077d6c24294d2997e1c55 (patch)
tree1d127bb025b4d2095d41c15a3f90066f1543034f /board/servo_v4/usb_pd_policy.c
parent7ed9a96cd7247e66d60464bb7737c139d71e7395 (diff)
downloadchrome-ec-167f7e51d8e7693a277077d6c24294d2997e1c55.tar.gz
servo_v4: Added initial USB PD support for both CHG/DUT ports
- CHG port can connect as SNK at different voltage levels - DUT port presents as SNK only - DUT port uses fixed polarity since it has a fixed cable - Not supporting ALT or ALT_DP modes in terms of svdm messages at this point. - No support yet for USB mux. BUG=chromium:571476 BRANCH=None TEST=Manual CHG port: Tested with Zinger and Plankton and 5/12/20V VBUS levels. DUT port: Tested against Reef and verified that port reached SNK_READY. Change-Id: Idbdc963ba077a14efad9eea3b047f35a5a605bd6 Signed-off-by: Scott <scollyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/419117 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'board/servo_v4/usb_pd_policy.c')
-rw-r--r--board/servo_v4/usb_pd_policy.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c
new file mode 100644
index 0000000000..7b496eaf53
--- /dev/null
+++ b/board/servo_v4/usb_pd_policy.c
@@ -0,0 +1,184 @@
+/* Copyright (c) 2014 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.
+ */
+
+#include "atomic.h"
+#include "charge_manager.h"
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "i2c.h"
+#include "registers.h"
+#include "system.h"
+#include "task.h"
+#include "timer.h"
+#include "util.h"
+#include "usb_mux.h"
+#include "usb_pd.h"
+
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+
+/* Define typical operating power and max power */
+/*#define OPERATING_POWER_MW 15000 */
+/*#define MAX_POWER_MW 60000 */
+/*#define MAX_CURRENT_MA 3000 */
+
+#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\
+ PDO_FIXED_COMM_CAP)
+
+const uint32_t pd_src_pdo[] = {
+ PDO_FIXED(5000, 900, PDO_FIXED_FLAGS),
+};
+const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo);
+
+const uint32_t pd_snk_pdo[] = {
+ PDO_FIXED(5000, 500, PDO_FIXED_FLAGS),
+ PDO_BATT(4750, 21000, 15000),
+ PDO_VAR(4750, 21000, 3000),
+};
+const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
+
+int pd_is_valid_input_voltage(int mv)
+{
+ /* Any voltage less than the max is allowed */
+ return 1;
+}
+
+void pd_transition_voltage(int idx)
+{
+ /*
+ * TODO(crosbug.com/p/60794): Most likely this function is a don't care
+ * for servo_v4 since VBUS provided to the DUT port has just an on/off
+ * control. For now leave it as a no-op.
+ */
+}
+
+int pd_set_power_supply_ready(int port)
+{
+ /*
+ * TODO(crosbug.com/p/60794): Will likely need to set the GPIOs
+ * DUT_CHG_EN and HOST_OR_CHG_CTL which control whether DUT port
+ * provides VBUS from Host or CHG port.
+ */
+ return EC_SUCCESS; /* we are ready */
+}
+
+void pd_power_supply_reset(int port)
+{
+ /*
+ * TODO(crosbug.com/p/60794): Will need to set the GPIOs
+ * DUT_CHG_EN and HOST_OR_CHG_CTL which control whether DUT port
+ * provides VBUS from Host or CHG port.
+ */
+}
+
+void pd_set_input_current_limit(int port, uint32_t max_ma,
+ uint32_t supply_voltage)
+{
+ /*
+ * TODO(crosbug.com/p/60794): Placeholder for now so that can compile
+ * with USB PD support.
+ */
+}
+
+void typec_set_input_current_limit(int port, uint32_t max_ma,
+ uint32_t supply_voltage)
+{
+ /*
+ * TODO(crosbug.com/p/60794): Placeholder for now so that can compile
+ * with USB PD support.
+ */
+}
+
+int pd_snk_is_vbus_provided(int port)
+{
+
+ return gpio_get_level(port ? GPIO_USB_DET_PP_DUT :
+ GPIO_USB_DET_PP_CHG);
+}
+
+int pd_board_checks(void)
+{
+ return EC_SUCCESS;
+}
+
+int pd_check_power_swap(int port)
+{
+ /*
+ * TODO(crosbug.com/p/60792): CHG port can't do a power swap as it's SNK
+ * only. DUT port should be able to support a power role swap, but VBUS
+ * will need to be present. For now, don't allow swaps on either port.
+ */
+ return 0;
+}
+
+int pd_check_data_swap(int port, int data_role)
+{
+ /* Servo can allow data role swaps */
+ return 1;
+}
+
+void pd_execute_data_swap(int port, int data_role)
+{
+ /* Should we do something here? */
+}
+
+void pd_check_pr_role(int port, int pr_role, int flags)
+{
+ /*
+ * TODO(crosbug.com/p/60792): CHG port can't do a power swap as it's SNK
+ * only. DUT port should be able to support a power role swap, but VBUS
+ * will need to be present. For now, don't allow swaps on either port.
+ */
+
+}
+
+void pd_check_dr_role(int port, int dr_role, int flags)
+{
+ /*
+ * TODO(crosbug.com/p/60792): CHG port is SNK only and should not need
+ * to change from default UFP role. DUT port behavior needs to be
+ * flushed out. Don't request any data role change for either port for
+ * now.
+ */
+}
+
+
+/* ----------------- Vendor Defined Messages ------------------ */
+const struct svdm_response svdm_rsp = {
+ .identity = NULL,
+ .svids = NULL,
+ .modes = NULL,
+};
+
+int pd_custom_vdm(int port, int cnt, uint32_t *payload,
+ uint32_t **rpayload)
+{
+ int cmd = PD_VDO_CMD(payload[0]);
+
+ /* make sure we have some payload */
+ if (cnt == 0)
+ return 0;
+
+ switch (cmd) {
+ case VDO_CMD_VERSION:
+ /* guarantee last byte of payload is null character */
+ *(payload + cnt - 1) = 0;
+ CPRINTF("ver: %s\n", (char *)(payload+1));
+ break;
+ case VDO_CMD_CURRENT:
+ CPRINTF("Current: %dmA\n", payload[1]);
+ break;
+ }
+
+ return 0;
+}
+
+
+
+const struct svdm_amode_fx supported_modes[] = {};
+const int supported_modes_cnt = ARRAY_SIZE(supported_modes);