summaryrefslogtreecommitdiff
path: root/board/plankton
diff options
context:
space:
mode:
Diffstat (limited to 'board/plankton')
-rw-r--r--board/plankton/board.c798
-rw-r--r--board/plankton/board.h114
-rw-r--r--board/plankton/build.mk14
-rw-r--r--board/plankton/ec.tasklist12
-rw-r--r--board/plankton/gpio.inc78
-rw-r--r--board/plankton/usb_pd_config.h158
-rw-r--r--board/plankton/usb_pd_policy.c291
-rw-r--r--board/plankton/vif_override.xml3
8 files changed, 0 insertions, 1468 deletions
diff --git a/board/plankton/board.c b/board/plankton/board.c
deleted file mode 100644
index a361f5fff3..0000000000
--- a/board/plankton/board.c
+++ /dev/null
@@ -1,798 +0,0 @@
-/* Copyright 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.
- */
-/* Plankton board configuration */
-
-#include "adc.h"
-#include "common.h"
-#include "console.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "i2c.h"
-#include "ina2xx.h"
-#include "pca9534.h"
-#include "registers.h"
-#include "system.h"
-#include "task.h"
-#include "timer.h"
-#include "usb_pd.h"
-#include "util.h"
-
-void button_event(enum gpio_signal signal);
-void hpd_event(enum gpio_signal signal);
-void vbus_event(enum gpio_signal signal);
-#include "gpio_list.h"
-
-static volatile uint64_t hpd_prev_ts;
-static volatile int hpd_prev_level;
-static volatile int hpd_possible_irq;
-
-/* Detect the type of cable used (either single CC or double) */
-enum typec_cable {
- TYPEC_CABLE_NONE,
- TYPEC_CABLE_CHECK,
- TYPEC_CABLE_SINGLE_CC,
- TYPEC_CABLE_DOUBLE_CC
-};
-static enum typec_cable cable;
-
-static int active_cc;
-static int host_mode;
-static int drp_enable;
-
-static int sn75dp130_dpcd_init(void);
-
-/**
- * Hotplug detect deferred task
- *
- * Called after level change on hpd GPIO to evaluate (and debounce) what event
- * has occurred. There are 3 events that occur on HPD:
- * 1. low : downstream display sink is deattached
- * 2. high : downstream display sink is attached
- * 3. irq : downstream display sink signalling an interrupt.
- *
- * The debounce times for these various events are:
- * HPD_USTREAM_DEBOUNCE_LVL : min pulse width of level value.
- * HPD_USTREAM_DEBOUNCE_IRQ : min pulse width of IRQ low pulse.
- *
- * lvl(n-2) lvl(n-1) lvl prev_delta now_delta event
- * ----------------------------------------------------
- * 1 0 1 <IRQ n/a low glitch (ignore)
- * 1 0 1 >IRQ <LVL irq
- * x 0 1 n/a >LVL high
- * 0 1 0 <LVL n/a high glitch (ignore)
- * x 1 0 n/a >LVL low
- */
-
-void hpd_lvl_deferred(void)
-{
- int level = gpio_get_level(GPIO_DPSRC_HPD);
- int dp_mode = !gpio_get_level(GPIO_USBC_SS_USB_MODE);
-
- if (level != hpd_prev_level) {
- /* Stable level changed. Send HPD event */
- hpd_prev_level = level;
- if (dp_mode)
- pd_send_hpd(0, level ? hpd_high : hpd_low);
- /* Configure redriver's back side */
- if (level)
- sn75dp130_dpcd_init();
-
- }
-
- /* Send queued IRQ if the cable is attached */
- if (hpd_possible_irq && level && dp_mode)
- pd_send_hpd(0, hpd_irq);
- hpd_possible_irq = 0;
-
-}
-DECLARE_DEFERRED(hpd_lvl_deferred);
-
-void hpd_event(enum gpio_signal signal)
-{
- timestamp_t now = get_time();
- int level = gpio_get_level(signal);
- uint64_t cur_delta = now.val - hpd_prev_ts;
-
- /* Record low pulse */
- if (cur_delta >= HPD_USTREAM_DEBOUNCE_IRQ && level)
- hpd_possible_irq = 1;
-
- /* store current time */
- hpd_prev_ts = now.val;
-
- /* All previous hpd level events need to be re-triggered */
- hook_call_deferred(&hpd_lvl_deferred_data,
- HPD_USTREAM_DEBOUNCE_LVL);
-}
-
-/* Debounce time for voltage buttons */
-#define BUTTON_DEBOUNCE_US (100 * MSEC)
-
-static enum gpio_signal button_pressed;
-
-static int fake_pd_disconnected;
-static int fake_pd_host_mode;
-static int fake_pd_disconnect_duration_us;
-
-enum usbc_action {
- USBC_ACT_5V_TO_DUT,
- USBC_ACT_12V_TO_DUT,
- USBC_ACT_20V_TO_DUT,
- USBC_ACT_DEVICE,
- USBC_ACT_USBDP_TOGGLE,
- USBC_ACT_USB_EN,
- USBC_ACT_DP_EN,
- USBC_ACT_MUX_FLIP,
- USBC_ACT_CABLE_POLARITY0,
- USBC_ACT_CABLE_POLARITY1,
- USBC_ACT_CCD_EN,
- USBC_ACT_DRP_TOGGLE,
-
- /* Number of USBC actions */
- USBC_ACT_COUNT
-};
-
-enum board_src_cap src_cap_mapping[USBC_ACT_COUNT] =
-{
- [USBC_ACT_5V_TO_DUT] = SRC_CAP_5V,
- [USBC_ACT_12V_TO_DUT] = SRC_CAP_12V,
- [USBC_ACT_20V_TO_DUT] = SRC_CAP_20V,
-};
-
-/**
- * Set the active CC line. The non-active CC line will be left in
- * High-Z, and we will fake the ADC reading for it.
- */
-static void set_active_cc(int cc)
-{
- active_cc = cc;
-
- /*
- * If DRP mode is enabled, then set both CC lines based
- * on the current value of host_mode. If DRP mode is
- * disabled then only set the active CC line.
- */
- /* Pull-up on CC2 */
- gpio_set_flags(GPIO_USBC_CC2_HOST,
- ((cc || drp_enable) && host_mode) ?
- GPIO_OUT_HIGH : GPIO_INPUT);
- /* Pull-down on CC2 */
- gpio_set_flags(GPIO_USBC_CC2_DEVICE_ODL,
- ((cc || drp_enable) && !host_mode) ?
- GPIO_OUT_LOW : GPIO_INPUT);
- /* Pull-up on CC1 */
- gpio_set_flags(GPIO_USBC_CC1_HOST,
- ((!cc || drp_enable) && host_mode) ?
- GPIO_OUT_HIGH : GPIO_INPUT);
- /* Pull-down on CC1 */
- gpio_set_flags(GPIO_USBC_CC1_DEVICE_ODL,
- ((!cc || drp_enable) && !host_mode) ?
- GPIO_OUT_LOW : GPIO_INPUT);
-}
-
-/**
- * Detect type-C cable type. Toggle the active CC line until a type-C connection
- * is detected. If a type-C connection can be made in both polarities, then we
- * have a double CC cable, otherwise we have a single CC cable.
- */
-static void detect_cc_cable(void);
-DECLARE_DEFERRED(detect_cc_cable);
-
-static void detect_cc_cable(void)
-{
- /*
- * Delay long enough to guarantee a type-C disconnect will be seen and
- * a new connection will be made made.
- */
- hook_call_deferred(&detect_cc_cable_data,
- PD_T_CC_DEBOUNCE + PD_T_SAFE_0V);
-
- switch (cable) {
- case TYPEC_CABLE_NONE:
- /* When no cable attached, toggle active CC line */
- if (pd_is_connected(0))
- cable = TYPEC_CABLE_CHECK;
- set_active_cc(!active_cc);
- break;
- case TYPEC_CABLE_CHECK:
- /* If we still have a connection, we have a double CC cable */
- cable = pd_is_connected(0) ? TYPEC_CABLE_DOUBLE_CC :
- TYPEC_CABLE_SINGLE_CC;
- /* Flip back to original polarity and enable PD comms */
- set_active_cc(!active_cc);
- pd_comm_enable(0, 1);
- break;
- case TYPEC_CABLE_SINGLE_CC:
- case TYPEC_CABLE_DOUBLE_CC:
- /* Check for disconnection and disable PD comms */
- if (!pd_is_connected(0)) {
- cable = TYPEC_CABLE_NONE;
- pd_comm_enable(0, 0);
- }
- break;
- }
-}
-
-static void fake_disconnect_end(void)
-{
- fake_pd_disconnected = 0;
- board_pd_set_host_mode(fake_pd_host_mode);
-
- /* Restart CC cable detection */
- hook_call_deferred(&detect_cc_cable_data, 500*MSEC);
-}
-DECLARE_DEFERRED(fake_disconnect_end);
-
-static void fake_disconnect_start(void)
-{
- /* Cancel detection of CC cable */
- hook_call_deferred(&detect_cc_cable_data, -1);
-
- /* Record the current host mode */
- fake_pd_host_mode = !gpio_get_level(GPIO_USBC_CHARGE_EN);
- /* Disable VBUS */
- gpio_set_level(GPIO_VBUS_CHARGER_EN, 0);
- gpio_set_level(GPIO_USBC_VSEL_0, 0);
- gpio_set_level(GPIO_USBC_VSEL_1, 0);
- /* High Z for no pull-up or pull-down resistor on CC1 and CC2 */
- gpio_set_flags(GPIO_USBC_CC2_HOST, GPIO_INPUT);
- gpio_set_flags(GPIO_USBC_CC2_DEVICE_ODL, GPIO_INPUT);
- gpio_set_flags(GPIO_USBC_CC1_HOST, GPIO_INPUT);
- gpio_set_flags(GPIO_USBC_CC1_DEVICE_ODL, GPIO_INPUT);
-
- fake_pd_disconnected = 1;
-
- hook_call_deferred(&fake_disconnect_end_data,
- fake_pd_disconnect_duration_us);
-}
-DECLARE_DEFERRED(fake_disconnect_start);
-
-/**
- * Enable or disable dualrole mode operation. By default Plankton has
- * dualrole mode disabled and attempts to connect in a sink role. Console
- * commands/button presses can cause it to switch to source_only/sink_only
- * modes.
- */
-static void update_usbc_dual_role(int dual_role)
-{
- if (dual_role == PD_DRP_TOGGLE_ON) {
- drp_enable = 1;
- /*
- * Cable detect is not needed when operating in dualrole mode
- * since both CC lines are used and SRC/SNK changes are dictated
- * by the USB PD protocol state machine.
- */
- hook_call_deferred(&detect_cc_cable_data, -1);
- /* Need to make sure both CC lines are set for SNK or SRC. */
- set_active_cc(host_mode);
- /* Ensure that PD communication is enabled. */
- pd_comm_enable(0, 1);
- } else {
- drp_enable = 0;
- /*
- * Dualrole mode is not active, resume cable detect function
- * which controls which CC line is active.
- */
- hook_call_deferred(&detect_cc_cable_data, 0);
- }
- /* Update dual role setting used in USB PD protocol state machine */
- pd_set_dual_role(0, dual_role);
- cprintf(CC_USBPD, "DRP = %d, host_mode = %d\n", drp_enable, host_mode);
-}
-
-static void set_usbc_action(enum usbc_action act)
-{
- int need_soft_reset;
- int was_usb_mode;
-
- switch (act) {
- case USBC_ACT_5V_TO_DUT:
- case USBC_ACT_12V_TO_DUT:
- case USBC_ACT_20V_TO_DUT:
- need_soft_reset = gpio_get_level(GPIO_VBUS_CHARGER_EN);
- board_set_source_cap(src_cap_mapping[act]);
- update_usbc_dual_role(PD_DRP_FORCE_SOURCE);
- if (need_soft_reset)
- pd_soft_reset();
- break;
- case USBC_ACT_DEVICE:
- update_usbc_dual_role(PD_DRP_FORCE_SINK);
- break;
- case USBC_ACT_USBDP_TOGGLE:
- was_usb_mode = gpio_get_level(GPIO_USBC_SS_USB_MODE);
- gpio_set_level(GPIO_USBC_SS_USB_MODE, !was_usb_mode);
- gpio_set_level(GPIO_CASE_CLOSE_EN, !was_usb_mode);
- if (!gpio_get_level(GPIO_DPSRC_HPD))
- break;
- /*
- * DP cable is connected. Send HPD event according to USB/DP
- * mux state.
- */
- if (!was_usb_mode) {
- pd_send_hpd(0, hpd_low);
- } else {
- pd_send_hpd(0, hpd_high);
- pd_send_hpd(0, hpd_irq);
- }
- break;
- case USBC_ACT_USB_EN:
- gpio_set_level(GPIO_USBC_SS_USB_MODE, 1);
- break;
- case USBC_ACT_DP_EN:
- gpio_set_level(GPIO_USBC_SS_USB_MODE, 0);
- break;
- case USBC_ACT_MUX_FLIP:
- /*
- * For a single CC cable, send custom VDM to flip
- * USB polarity only. For double CC cable, actually
- * disconnect and reconnect with opposite polarity.
- */
- if (cable == TYPEC_CABLE_SINGLE_CC) {
- pd_send_vdm(0, USB_VID_GOOGLE, VDO_CMD_FLIP, NULL, 0);
- gpio_set_level(GPIO_USBC_POLARITY,
- !gpio_get_level(GPIO_USBC_POLARITY));
- } else if (cable == TYPEC_CABLE_DOUBLE_CC) {
- /*
- * Fake a disconnection for long enough to guarantee
- * that we disconnect.
- */
- hook_call_deferred(&fake_disconnect_start_data, -1);
- hook_call_deferred(&fake_disconnect_end_data, -1);
- fake_pd_disconnect_duration_us = PD_T_SAFE_0V;
- hook_call_deferred(&fake_disconnect_start_data, 0);
- set_active_cc(!active_cc);
- }
- break;
- case USBC_ACT_CABLE_POLARITY0:
- gpio_set_level(GPIO_USBC_POLARITY, 0);
- break;
- case USBC_ACT_CABLE_POLARITY1:
- gpio_set_level(GPIO_USBC_POLARITY, 1);
- break;
- case USBC_ACT_CCD_EN:
- pd_send_vdm(0, USB_VID_GOOGLE, VDO_CMD_CCD_EN, NULL, 0);
- /* Switch to USB mode when enable CCD. */
- gpio_set_level(GPIO_USBC_SS_USB_MODE, 1);
- /* Reset RFU polarity MUX */
- gpio_set_level(GPIO_CASE_CLOSE_EN, 0);
- gpio_set_level(GPIO_CASE_CLOSE_DFU_L, 0);
- gpio_set_level(GPIO_CASE_CLOSE_EN, 1);
- gpio_set_level(GPIO_CASE_CLOSE_DFU_L, 1);
- break;
- case USBC_ACT_DRP_TOGGLE:
- /* Toggle dualrole mode setting. */
- update_usbc_dual_role(drp_enable ?
- PD_DRP_TOGGLE_OFF : PD_DRP_TOGGLE_ON);
- break;
- default:
- break;
- }
-}
-
-/* has Pull-up */
-static int prev_dbg20v = 1;
-
-static void button_dbg20v_deferred(void);
-DECLARE_DEFERRED(button_dbg20v_deferred);
-
-static void enable_dbg20v_poll(void)
-{
- hook_call_deferred(&button_dbg20v_deferred_data, 10 * MSEC);
-}
-
-/* Handle debounced button press */
-static void button_deferred(void)
-{
- if (button_pressed == GPIO_DBG_20V_TO_DUT_L) {
- enable_dbg20v_poll();
- if (gpio_get_level(GPIO_DBG_20V_TO_DUT_L) == prev_dbg20v)
- return;
- else
- prev_dbg20v = !prev_dbg20v;
- }
- /* bounce ? */
- if (gpio_get_level(button_pressed) != 0)
- return;
-
- switch (button_pressed) {
- case GPIO_DBG_5V_TO_DUT_L:
- set_usbc_action(USBC_ACT_5V_TO_DUT);
- break;
- case GPIO_DBG_12V_TO_DUT_L:
- set_usbc_action(USBC_ACT_12V_TO_DUT);
- break;
- case GPIO_DBG_20V_TO_DUT_L:
- set_usbc_action(USBC_ACT_20V_TO_DUT);
- break;
- case GPIO_DBG_CHG_TO_DEV_L:
- set_usbc_action(USBC_ACT_DEVICE);
- break;
- case GPIO_DBG_USB_TOGGLE_L:
- set_usbc_action(USBC_ACT_USBDP_TOGGLE);
- if (gpio_get_level(GPIO_USBC_SS_USB_MODE))
- board_maybe_reset_usb_hub();
- break;
- case GPIO_DBG_MUX_FLIP_L:
- set_usbc_action(USBC_ACT_MUX_FLIP);
- break;
- case GPIO_DBG_CASE_CLOSE_EN_L:
- set_usbc_action(USBC_ACT_CCD_EN);
- break;
- default:
- break;
- }
-
- ccprintf("Button %d = %d\n",
- button_pressed, gpio_get_level(button_pressed));
-}
-DECLARE_DEFERRED(button_deferred);
-
-void button_event(enum gpio_signal signal)
-{
- button_pressed = signal;
- /* reset debounce time */
- hook_call_deferred(&button_deferred_data, BUTTON_DEBOUNCE_US);
-}
-
-static void button_dbg20v_deferred(void)
-{
- if (gpio_get_level(GPIO_DBG_20V_TO_DUT_L) == 0)
- button_event(GPIO_DBG_20V_TO_DUT_L);
- else
- enable_dbg20v_poll();
-}
-
-void vbus_event(enum gpio_signal signal)
-{
- ccprintf("VBUS! =%d\n", gpio_get_level(signal));
- task_wake(TASK_ID_PD_C0);
-}
-
-/* ADC channels */
-const struct adc_t adc_channels[] = {
- /* USB PD CC lines sensing. Converted to mV (3300mV/4096). */
- [ADC_CH_CC1_PD] = {"CC1_PD", 3300, 4096, 0, STM32_AIN(0)},
- [ADC_CH_CC2_PD] = {"CC2_PD", 3300, 4096, 0, STM32_AIN(4)},
-};
-BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
-
-/* I2C ports */
-const struct i2c_port_t i2c_ports[] = {
- {"master", I2C_PORT_MASTER, 100,
- GPIO_MASTER_I2C_SCL, GPIO_MASTER_I2C_SDA},
-};
-const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
-
-/* 8-bit address */
-#define SN75DP130_I2C_ADDR_FLAGS 0x2e
-/*
- * Pin number for active-high reset from PCA9534 to CMOS pull-down to
- * SN75DP130's RSTN (active-low)
- */
-#define REDRIVER_RST_PIN 0x1
-
-static int sn75dp130_i2c_write(uint8_t index, uint8_t value)
-{
- return i2c_write8(I2C_PORT_MASTER, SN75DP130_I2C_ADDR_FLAGS,
- index, value);
-}
-
-/**
- * Reset redriver.
- *
- * Note, MUST set SW15 to 'PD' in order to control i2c from PD-MCU. This can
- * NOT be done via software.
- */
-static int sn75dp130_reset(void)
-{
- int rv;
-
- rv = pca9534_config_pin(I2C_PORT_MASTER, 0x20,
- REDRIVER_RST_PIN, PCA9534_OUTPUT);
- /* Assert (its active high) */
- rv |= pca9534_set_level(I2C_PORT_MASTER, 0x20,
- REDRIVER_RST_PIN, 1);
- /* datasheet recommends > 100usec */
- usleep(200);
-
- /* De-assert */
- rv |= pca9534_set_level(I2C_PORT_MASTER, 0x20,
- REDRIVER_RST_PIN, 0);
- /* datasheet recommends > 400msec */
- usleep(450 * MSEC);
- return rv;
-}
-
-static int sn75dp130_dpcd_init(void)
-{
- int i, rv;
-
- /* set upper & middle DPCD addr ... constant for writes below */
- rv = sn75dp130_i2c_write(0x1c, 0x0);
- rv |= sn75dp130_i2c_write(0x1d, 0x1);
-
- /* link_bw_set: 5.4gbps */
- rv |= sn75dp130_i2c_write(0x1e, 0x0);
- rv |= sn75dp130_i2c_write(0x1f, 0x14);
-
- /* lane_count_set: 4 */
- rv |= sn75dp130_i2c_write(0x1e, 0x1);
- rv |= sn75dp130_i2c_write(0x1f, 0x4);
-
- /*
- * Force Link voltage level & pre-emphasis by writing each of the lane's
- * DPCD config registers 103-106h accordingly.
- */
- for (i = 0x3; i < 0x7; i++) {
- rv |= sn75dp130_i2c_write(0x1e, i);
- rv |= sn75dp130_i2c_write(0x1f, 0x3);
- }
- return rv;
-}
-
-static int sn75dp130_redriver_init(void)
-{
- int rv;
-
- rv = sn75dp130_reset();
-
- /* Disable squelch detect */
- rv |= sn75dp130_i2c_write(0x3, 0x1a);
- /* Disable link training on re-driver source side */
- rv |= sn75dp130_i2c_write(0x4, 0x0);
-
- /* Can only configure DPCD portion of redriver in presence of an HPD */
- if (gpio_get_level(GPIO_DPSRC_HPD))
- sn75dp130_dpcd_init();
-
- return rv;
-}
-
-static int cmd_usbc_action(int argc, char *argv[])
-{
- enum usbc_action act;
-
- if (argc != 2)
- return EC_ERROR_PARAM_COUNT;
-
- if (!strcasecmp(argv[1], "5v"))
- act = USBC_ACT_5V_TO_DUT;
- else if (!strcasecmp(argv[1], "12v"))
- act = USBC_ACT_12V_TO_DUT;
- else if (!strcasecmp(argv[1], "20v"))
- act = USBC_ACT_20V_TO_DUT;
- else if (!strcasecmp(argv[1], "ccd"))
- act = USBC_ACT_CCD_EN;
- else if (!strcasecmp(argv[1], "dev"))
- act = USBC_ACT_DEVICE;
- else if (!strcasecmp(argv[1], "usb"))
- act = USBC_ACT_USB_EN;
- else if (!strcasecmp(argv[1], "dp"))
- act = USBC_ACT_DP_EN;
- else if (!strcasecmp(argv[1], "flip"))
- act = USBC_ACT_MUX_FLIP;
- else if (!strcasecmp(argv[1], "pol0"))
- act = USBC_ACT_CABLE_POLARITY0;
- else if (!strcasecmp(argv[1], "pol1"))
- act = USBC_ACT_CABLE_POLARITY1;
- else if (!strcasecmp(argv[1], "drp"))
- act = USBC_ACT_DRP_TOGGLE;
- else
- return EC_ERROR_PARAM1;
-
- set_usbc_action(act);
-
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(usbc_action, cmd_usbc_action,
- "<5v|12v|20v|ccd|dev|usb|dp|flip|pol0|pol1|drp>",
- "Set Plankton type-C port state");
-
-int board_in_hub_mode(void)
-{
- int ret;
- int level;
-
- ret = pca9534_config_pin(I2C_PORT_MASTER, 0x20,
- 6, PCA9534_INPUT);
- if (ret)
- return -1;
- ret = pca9534_get_level(I2C_PORT_MASTER, 0x20,
- 6, &level);
- if (ret)
- return -1;
- return level;
-}
-
-static int board_usb_hub_reset(void)
-{
- int ret;
-
- ret = pca9534_config_pin(I2C_PORT_MASTER, 0x20,
- 7, PCA9534_OUTPUT);
- if (ret)
- return ret;
- ret = pca9534_set_level(I2C_PORT_MASTER, 0x20,
- 7, 0);
- if (ret)
- return ret;
- usleep(100 * MSEC);
- return pca9534_set_level(I2C_PORT_MASTER, 0x20,
- 7, 1);
-}
-
-void board_maybe_reset_usb_hub(void)
-{
- if (board_in_hub_mode() == 1)
- board_usb_hub_reset();
-}
-
-static int cmd_usb_hub_reset(int argc, char *argv[])
-{
- return board_usb_hub_reset();
-}
-DECLARE_CONSOLE_COMMAND(hub_reset, cmd_usb_hub_reset,
- NULL, "Reset USB hub");
-
-static void board_usb_hub_reset_no_return(void)
-{
- board_usb_hub_reset();
-}
-DECLARE_DEFERRED(board_usb_hub_reset_no_return);
-
-static int board_pd_fake_disconnected(void)
-{
- return fake_pd_disconnected;
-}
-
-int board_fake_pd_adc_read(int cc)
-{
- if (fake_pd_disconnected) {
- /* Always disconnected */
- return fake_pd_host_mode ? 3000 : 0;
- } else {
- if (drp_enable) {
- /* Always read the req CC line when in drp mode */
- return adc_read_channel(cc ? ADC_CH_CC2_PD :
- ADC_CH_CC1_PD);
- } else {
- /*
- * Only read the active CC line, fake disconnected
- * on other CC line. */
- if (active_cc == cc)
- return adc_read_channel(cc ? ADC_CH_CC2_PD :
- ADC_CH_CC1_PD);
- else
- return host_mode ? 3000 : 0;
- }
- }
-}
-
-/* Set fake PD pull-up/pull-down */
-static void board_update_fake_adc_value(int host_mode)
-{
- fake_pd_host_mode = host_mode;
-}
-
-void board_pd_set_host_mode(int enable)
-{
- if (!drp_enable)
- cprintf(CC_USBPD, "Host mode: %d\n", enable);
-
- if (board_pd_fake_disconnected()) {
- board_update_fake_adc_value(enable);
- return;
- }
-
- /* if host mode changed, reset cable type */
- if (host_mode != enable) {
- host_mode = enable;
- cable = TYPEC_CABLE_NONE;
- }
-
- if (enable) {
- /* Source mode, disable charging */
- gpio_set_level(GPIO_USBC_CHARGE_EN, 0);
-
- /* Set CC lines */
- set_active_cc(active_cc);
- } else {
- /* Device mode, disable VBUS */
- gpio_set_level(GPIO_VBUS_CHARGER_EN, 0);
- gpio_set_level(GPIO_USBC_VSEL_0, 0);
- gpio_set_level(GPIO_USBC_VSEL_1, 0);
-
- /* Set CC lines */
- set_active_cc(active_cc);
-
- /* Enable charging */
- gpio_set_level(GPIO_USBC_CHARGE_EN, 1);
- }
-}
-
-static void board_init(void)
-{
- timestamp_t now = get_time();
- hpd_prev_level = gpio_get_level(GPIO_DPSRC_HPD);
- hpd_prev_ts = now.val;
- gpio_enable_interrupt(GPIO_DPSRC_HPD);
-
- /* Start up with dualrole mode off */
- drp_enable = 0;
-
- /* Enable interrupts on VBUS transitions. */
- gpio_enable_interrupt(GPIO_VBUS_WAKE);
-
- /* Enable button interrupts. */
- gpio_enable_interrupt(GPIO_DBG_5V_TO_DUT_L);
- gpio_enable_interrupt(GPIO_DBG_12V_TO_DUT_L);
- gpio_enable_interrupt(GPIO_DBG_CHG_TO_DEV_L);
- gpio_enable_interrupt(GPIO_DBG_USB_TOGGLE_L);
- gpio_enable_interrupt(GPIO_DBG_MUX_FLIP_L);
- gpio_enable_interrupt(GPIO_DBG_CASE_CLOSE_EN_L);
-
- /* TODO(crosbug.com/33761): poll DBG_20V_TO_DUT_L */
- enable_dbg20v_poll();
-
- ina2xx_init(0, 0x399f, INA2XX_CALIB_1MA(10 /* mOhm */));
- sn75dp130_redriver_init();
-
- /* Initialize USB hub */
- if (system_get_reset_flags() & EC_RESET_FLAG_POWER_ON)
- hook_call_deferred(&board_usb_hub_reset_no_return_data,
- 500 * MSEC);
-
- /* Start detecting CC cable type */
- hook_call_deferred(&detect_cc_cable_data, SECOND);
-}
-DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-
-static int cmd_fake_disconnect(int argc, char *argv[])
-{
- int delay_ms, duration_ms;
- char *e;
-
- if (argc < 3)
- return EC_ERROR_PARAM_COUNT;
-
- delay_ms = strtoi(argv[1], &e, 0);
- if (*e || delay_ms < 0)
- return EC_ERROR_PARAM1;
- duration_ms = strtoi(argv[2], &e, 0);
- if (*e || duration_ms < 0)
- return EC_ERROR_PARAM2;
-
- /* Cancel any pending function calls */
- hook_call_deferred(&fake_disconnect_start_data, -1);
- hook_call_deferred(&fake_disconnect_end_data, -1);
-
- fake_pd_disconnect_duration_us = duration_ms * MSEC;
- hook_call_deferred(&fake_disconnect_start_data, delay_ms * MSEC);
-
- ccprintf("Fake disconnect for %d ms starting in %d ms.\n",
- duration_ms, delay_ms);
-
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(fakedisconnect, cmd_fake_disconnect,
- "<delay_ms> <duration_ms>", NULL);
-
-static void trigger_dfu_release(void)
-{
- gpio_set_level(GPIO_CASE_CLOSE_DFU_L, 1);
- ccprintf("Deasserting CASE_CLOSE_DFU_L.\n");
-}
-DECLARE_DEFERRED(trigger_dfu_release);
-
-static int cmd_trigger_dfu(int argc, char *argv[])
-{
- gpio_set_level(GPIO_CASE_CLOSE_DFU_L, 0);
- ccprintf("Asserting CASE_CLOSE_DFU_L.\n");
- ccprintf("If you expect to see DFU debug but it doesn't show up,\n");
- ccprintf("try flipping the USB type-C cable.\n");
- hook_call_deferred(&trigger_dfu_release_data, 1500 * MSEC);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(dfu, cmd_trigger_dfu, NULL, NULL);
diff --git a/board/plankton/board.h b/board/plankton/board.h
deleted file mode 100644
index 39ab706cd2..0000000000
--- a/board/plankton/board.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/* Copyright 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.
- */
-
-/* Plankton board configuration */
-
-#ifndef __CROS_EC_BOARD_H
-#define __CROS_EC_BOARD_H
-
-/* 48 MHz SYSCLK clock frequency */
-#define CPU_CLOCK 48000000
-
-/* the UART console is on USART2 (PA14/PA15) */
-#undef CONFIG_UART_CONSOLE
-#define CONFIG_UART_CONSOLE 2
-
-/* Optional features */
-#define CONFIG_STM_HWTIMER32
-#define CONFIG_USB_POWER_DELIVERY
-#define CONFIG_USB_PD_TCPMV1
-#define CONFIG_USB_PD_ALT_MODE
-#define CONFIG_USB_PD_COMM_DISABLED
-#define CONFIG_USB_PD_CUSTOM_PDO
-#define CONFIG_USB_PD_DUAL_ROLE
-#define CONFIG_USB_PD_DYNAMIC_SRC_CAP
-#define CONFIG_USB_PD_IDENTITY_HW_VERS 1
-#define CONFIG_USB_PD_IDENTITY_SW_VERS 1
-#define CONFIG_USB_PD_INTERNAL_COMP
-#define CONFIG_USB_PD_PORT_MAX_COUNT 1
-#define CONFIG_USB_PD_TCPC
-#define CONFIG_USB_PD_TCPM_STUB
-#define CONFIG_USB_PD_VBUS_DETECT_GPIO
-#define CONFIG_ADC
-#define CONFIG_HW_CRC
-#define CONFIG_I2C
-#define CONFIG_I2C_CONTROLLER
-#define CONFIG_INA219
-#define CONFIG_IO_EXPANDER_PCA9534
-#undef CONFIG_WATCHDOG_HELP
-#undef CONFIG_LID_SWITCH
-#undef CONFIG_TASK_PROFILING
-
-/* I2C ports configuration */
-#define I2C_PORT_MASTER 1
-
-/* USB configuration */
-#define CONFIG_USB_PID 0x500c
-#define CONFIG_USB_BCD_DEV 0x0001 /* v 0.01 */
-
-/*
- * Allow dangerous commands all the time, since we don't have a write protect
- * switch.
- */
-#define CONFIG_SYSTEM_UNLOCKED
-
-#ifndef __ASSEMBLER__
-
-/* Timer selection */
-#define TIM_CLOCK32 2
-#define TIM_ADC 3
-
-#include "gpio_signal.h"
-
-/* ADC signal */
-enum adc_channel {
- ADC_CH_CC1_PD = 0,
- ADC_CH_CC2_PD,
- /* Number of ADC channels */
- ADC_CH_COUNT
-};
-
-enum board_src_cap {
- SRC_CAP_5V = 0,
- SRC_CAP_12V,
- SRC_CAP_20V,
-};
-
-/* 3.0A Rp */
-#define PD_SRC_VNC PD_SRC_3_0_VNC_MV
-#define PD_SNK_RD_THRESHOLD PD_SRC_3_0_RD_THRESH_MV
-
-/* delay necessary for the voltage transition on the power supply */
-#define PD_POWER_SUPPLY_TURN_ON_DELAY 50000 /* us */
-#define PD_POWER_SUPPLY_TURN_OFF_DELAY 50000 /* us */
-
-/* Define typical operating power and max power */
-#define PD_OPERATING_POWER_MW 5000
-#define PD_MAX_POWER_MW 60000
-#define PD_MAX_CURRENT_MA 3000
-#define PD_MAX_VOLTAGE_MV 20000
-
-/* Set USB PD source capability */
-void board_set_source_cap(enum board_src_cap cap);
-
-/* Reset USB hub if USB hub is switched to type-C port */
-void board_maybe_reset_usb_hub(void);
-
-/* Get fake ADC reading */
-int board_fake_pd_adc_read(int cc);
-
-/* Set pull-up/pull-down on CC lines */
-void board_pd_set_host_mode(int enable);
-
-/*
- * Whether the board is in USB hub mode or not
- *
- * @return 1 when in hub mode, 0 when not, and -1 on error.
- */
-int board_in_hub_mode(void);
-
-#endif /* !__ASSEMBLER__ */
-
-#endif /* __CROS_EC_BOARD_H */
diff --git a/board/plankton/build.mk b/board/plankton/build.mk
deleted file mode 100644
index 89a01e629b..0000000000
--- a/board/plankton/build.mk
+++ /dev/null
@@ -1,14 +0,0 @@
-# -*- makefile -*-
-# Copyright 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.
-#
-# Board specific files build
-
-# the IC is STmicro STM32F072CBU6
-CHIP:=stm32
-CHIP_FAMILY:=stm32f0
-CHIP_VARIANT:=stm32f07x
-
-board-y=board.o
-board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
diff --git a/board/plankton/ec.tasklist b/board/plankton/ec.tasklist
deleted file mode 100644
index 41fc047d6a..0000000000
--- a/board/plankton/ec.tasklist
+++ /dev/null
@@ -1,12 +0,0 @@
-/* Copyright 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.
- */
-
-/**
- * See CONFIG_TASK_LIST in config.h for details.
- */
-#define CONFIG_TASK_LIST \
- TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE)
diff --git a/board/plankton/gpio.inc b/board/plankton/gpio.inc
deleted file mode 100644
index 9c618dbaa6..0000000000
--- a/board/plankton/gpio.inc
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- mode:c -*-
- *
- * Copyright 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.
- */
-
-/* Declare symbolic names for all the GPIOs that we care about.
- * Note: Those with interrupt handlers must be declared first. */
-
-GPIO_INT(VBUS_WAKE, PIN(B, 5), GPIO_INT_BOTH, vbus_event)
-GPIO_INT(DPSRC_HPD, PIN(B, 13), GPIO_INT_BOTH, hpd_event)
-GPIO_INT(DBG_12V_TO_DUT_L, PIN(B, 14), GPIO_INT_FALLING, button_event)
-GPIO_INT(DBG_5V_TO_DUT_L, PIN(B, 8), GPIO_INT_FALLING, button_event)
-GPIO_INT(DBG_CHG_TO_DEV_L, PIN(F, 1), GPIO_INT_FALLING, button_event)
-GPIO_INT(DBG_USB_TOGGLE_L, PIN(F, 0), GPIO_INT_FALLING, button_event)
-GPIO_INT(DBG_CASE_CLOSE_EN_L, PIN(B, 12), GPIO_INT_FALLING, button_event)
-GPIO_INT(DBG_MUX_FLIP_L, PIN(B, 15), GPIO_INT_FALLING, button_event)
-
-/* TODO(crosbug.com/p/33761) : This interrupt is double booked w/ HPD */
-GPIO(DBG_20V_TO_DUT_L, PIN(C, 13), GPIO_INPUT)
-
-/* PD RX/TX */
-GPIO(USBC_PD_REF, PIN(A, 1), GPIO_ANALOG)
-GPIO(USBC_CC1_PD, PIN(A, 0), GPIO_ANALOG)
-GPIO(USBC_CC1_TX_EN, PIN(A, 3), GPIO_OUT_LOW)
-GPIO(USBC_CC2_PD, PIN(A, 4), GPIO_ANALOG)
-GPIO(USBC_CC2_TX_EN, PIN(B, 2), GPIO_OUT_LOW)
-GPIO(USBC_CC_TX_DATA, PIN(A, 6), GPIO_OUT_LOW)
-
-#if 0
-/* Alternate functions */
-GPIO(USBC_TX_CLKOUT, PIN(B, 9), GPIO_OUT_LOW)
-GPIO(USBC_TX_CLKIN, PIN(A, 5), GPIO_OUT_LOW)
-#endif
-
-/* USB-C Power and muxes control */
-GPIO(USBC_CHARGE_EN, PIN(A, 8), GPIO_OUT_HIGH)
-GPIO(USBC_CC1_DEVICE_ODL, PIN(A, 9), GPIO_OUT_LOW)
-GPIO(USBC_CC1_HOST, PIN(A, 2), GPIO_INPUT)
-GPIO(USBC_CC2_DEVICE_ODL, PIN(B, 7), GPIO_OUT_LOW)
-GPIO(USBC_CC2_HOST, PIN(B, 6), GPIO_INPUT)
-GPIO(USBC_POLARITY, PIN(B, 1), GPIO_OUT_HIGH)
-GPIO(USBC_SS_USB_MODE, PIN(B, 3), GPIO_OUT_LOW)
-GPIO(USB_CC1_VCONN_EN_L, PIN(A, 11), GPIO_OUT_HIGH)
-GPIO(USB_CC2_VCONN_EN_L, PIN(A, 12), GPIO_OUT_HIGH)
-
-GPIO(VBUS_CHARGER_EN, PIN(B, 0), GPIO_OUT_LOW)
-/* VSEL_0/1: 0/0 = 5V, 1/0 = 12V, 1/1 = 20V */
-GPIO(USBC_VSEL_1, PIN(A, 10), GPIO_OUT_LOW)
-GPIO(USBC_VSEL_0, PIN(C, 14), GPIO_OUT_LOW)
-
-/* Case closed debugging */
-GPIO(CASE_CLOSE_EN, PIN(A, 7), GPIO_OUT_LOW)
-GPIO(CASE_CLOSE_DFU_L, PIN(A, 13), GPIO_OUT_HIGH)
-GPIO(DEBUG_TOGGLE, PIN(B, 4), GPIO_OUT_LOW)
-
-/* Alternate functions */
-#if 0
-GPIO(UART_TX, PIN(A, 14), GPIO_OUT_LOW)
-GPIO(UART_RX, PIN(A, 15), GPIO_OUT_LOW)
-#endif
-
-/*
- * I2C pins should be configured as inputs until I2C module is
- * initialized. This will avoid driving the lines unintentionally.
- */
-GPIO(MASTER_I2C_SCL, PIN(B, 10), GPIO_INPUT)
-GPIO(MASTER_I2C_SDA, PIN(B, 11), GPIO_INPUT)
-
-/* Unimplemented signals which we need to emulate for now */
-UNIMPLEMENTED(ENTERING_RW)
-UNIMPLEMENTED(WP_L)
-
-ALTERNATE(PIN_MASK(A, 0x0020), 0, MODULE_USB_PD, 0) /* SPI1: SCK(PA5) */
-ALTERNATE(PIN_MASK(B, 0x0200), 2, MODULE_USB_PD, 0) /* TIM17_CH1: (PB9) */
-ALTERNATE(PIN_MASK(A, 0xC000), 1, MODULE_UART, 0) /* USART2: PA14/PA15 */
-ALTERNATE(PIN_MASK(B, 0x0C00), 1, MODULE_I2C, 0) /* I2C MASTER:PB10/11 */
diff --git a/board/plankton/usb_pd_config.h b/board/plankton/usb_pd_config.h
deleted file mode 100644
index fca6484069..0000000000
--- a/board/plankton/usb_pd_config.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/* Copyright 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.
- */
-
-/* USB Power delivery board configuration */
-
-#ifndef __CROS_EC_USB_PD_CONFIG_H
-#define __CROS_EC_USB_PD_CONFIG_H
-
-#include "board.h"
-
-/* Timer selection for baseband PD communication */
-#define TIM_CLOCK_PD_TX_C0 17
-#define TIM_CLOCK_PD_RX_C0 1
-
-#define TIM_CLOCK_PD_TX(p) TIM_CLOCK_PD_TX_C0
-#define TIM_CLOCK_PD_RX(p) TIM_CLOCK_PD_RX_C0
-
-/* Timer channel */
-#define TIM_RX_CCR_C0 1
-#define TIM_TX_CCR_C0 1
-
-/* RX timer capture/compare register */
-#define TIM_CCR_C0 (&STM32_TIM_CCRx(TIM_CLOCK_PD_RX_C0, TIM_RX_CCR_C0))
-#define TIM_RX_CCR_REG(p) TIM_CCR_C0
-
-/* TX and RX timer register */
-#define TIM_REG_TX_C0 (STM32_TIM_BASE(TIM_CLOCK_PD_TX_C0))
-#define TIM_REG_RX_C0 (STM32_TIM_BASE(TIM_CLOCK_PD_RX_C0))
-#define TIM_REG_TX(p) TIM_REG_TX_C0
-#define TIM_REG_RX(p) TIM_REG_RX_C0
-
-/* use the hardware accelerator for CRC */
-#define CONFIG_HW_CRC
-
-/* TX is using SPI1 on PA4-7 */
-#define SPI_REGS(p) STM32_SPI1_REGS
-
-static inline void spi_enable_clock(int port)
-{
- STM32_RCC_APB2ENR |= STM32_RCC_PB2_SPI1;
-}
-
-#define DMAC_SPI_TX(p) STM32_DMAC_CH3
-
-/* RX is using COMP1 triggering TIM1 CH1 */
-#define CMP1OUTSEL STM32_COMP_CMP1OUTSEL_TIM1_IC1
-#define CMP2OUTSEL 0
-
-#define TIM_TX_CCR_IDX(p) TIM_TX_CCR_C0
-#define TIM_RX_CCR_IDX(p) TIM_RX_CCR_C0
-#define TIM_CCR_CS 1
-#define EXTI_COMP_MASK(p) BIT(21)
-#define IRQ_COMP STM32_IRQ_COMP
-/* triggers packet detection on comparator falling edge */
-#define EXTI_XTSR STM32_EXTI_FTSR
-
-#define DMAC_TIM_RX(p) STM32_DMAC_CH2
-
-/* the pins used for communication need to be hi-speed */
-static inline void pd_set_pins_speed(int port)
-{
- /* 40 MHz pin speed on SPI1 (PA5/6) and CC1_TX_EN (PA3) */
- STM32_GPIO_OSPEEDR(GPIO_A) |= 0x00003CC0;
- /* 40 MHz pin speed on TIM17_CH1 (PB9) and CC2_TX_EN (PB2) */
- STM32_GPIO_OSPEEDR(GPIO_B) |= 0x000C0030;
-}
-
-/* Reset SPI peripheral used for TX */
-static inline void pd_tx_spi_reset(int port)
-{
- /* Reset SPI1 */
- STM32_RCC_APB2RSTR |= BIT(12);
- STM32_RCC_APB2RSTR &= ~BIT(12);
-}
-
-/* Drive the CC line from the TX block */
-static inline void pd_tx_enable(int port, int polarity)
-{
- /* put SPI function on TX pin */
- /* PA6 is SPI1 MISO */
- gpio_set_alternate_function(GPIO_A, 0x0040, 0);
-
- /* set the polarity */
- gpio_set_level(GPIO_USBC_CC1_TX_EN, !polarity);
- gpio_set_level(GPIO_USBC_CC2_TX_EN, polarity);
-}
-
-/* Put the TX driver in Hi-Z state */
-static inline void pd_tx_disable(int port, int polarity)
-{
- /* output low on SPI TX to disable the FET */
- /* PA6 is SPI1_MISO */
- STM32_GPIO_MODER(GPIO_A) = (STM32_GPIO_MODER(GPIO_A)
- & ~(3 << (2*6)))
- | (1 << (2*6));
- /* put the low level reference in Hi-Z */
- gpio_set_level(GPIO_USBC_CC1_TX_EN, 0);
- gpio_set_level(GPIO_USBC_CC2_TX_EN, 0);
-}
-
-/* we know the plug polarity, do the right configuration */
-static inline void pd_select_polarity(int port, int polarity)
-{
- /* use the right comparator non inverted input for COMP1 */
- STM32_COMP_CSR = (STM32_COMP_CSR & ~STM32_COMP_CMP1INSEL_MASK)
- | STM32_COMP_CMP1EN
- | (polarity ?
- STM32_COMP_CMP1INSEL_INM4 :
- STM32_COMP_CMP1INSEL_INM6);
- gpio_set_level(GPIO_USBC_POLARITY, polarity);
-}
-
-/* Initialize pins used for TX and put them in Hi-Z */
-static inline void pd_tx_init(void)
-{
- /* Configure SCK pin */
- gpio_config_module(MODULE_USB_PD, 1);
-}
-
-static inline void pd_set_host_mode(int port, int enable)
-{
- board_pd_set_host_mode(enable);
-}
-
-/**
- * Initialize various GPIOs and interfaces to safe state at start of pd_task.
- *
- * These include:
- * VBUS, charge path based on power role.
- * Physical layer CC transmit.
- * VCONNs disabled.
- *
- * @param port USB-C port number
- * @param power_role Power role of device
- */
-static inline void pd_config_init(int port, uint8_t power_role)
-{
- /*
- * Set CC pull resistors, and charge_en and vbus_en GPIOs to match
- * the initial role.
- */
- pd_set_host_mode(port, power_role);
-
- /* Initialize TX pins and put them in Hi-Z */
- pd_tx_init();
-
- gpio_set_level(GPIO_USB_CC1_VCONN_EN_L, 1);
- gpio_set_level(GPIO_USB_CC2_VCONN_EN_L, 1);
-}
-
-static inline int pd_adc_read(int port, int cc)
-{
- return board_fake_pd_adc_read(cc);
-}
-
-#endif /* __CROS_EC_USB_PD_CONFIG_H */
diff --git a/board/plankton/usb_pd_policy.c b/board/plankton/usb_pd_policy.c
deleted file mode 100644
index 8cb24372a0..0000000000
--- a/board/plankton/usb_pd_policy.c
+++ /dev/null
@@ -1,291 +0,0 @@
-/* Copyright 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 "adc.h"
-#include "board.h"
-#include "common.h"
-#include "console.h"
-#include "cros_version.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "registers.h"
-#include "task.h"
-#include "timer.h"
-#include "util.h"
-#include "usb_pd.h"
-#include "usb_pd_tcpm.h"
-
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
-
-/* Acceptable margin between requested VBUS and measured value */
-#define MARGIN_MV 400 /* mV */
-
-#define PDO_FIXED_FLAGS (PDO_FIXED_DATA_SWAP | PDO_FIXED_UNCONSTRAINED |\
- PDO_FIXED_COMM_CAP)
-
-/* Source PDOs */
-const uint32_t pd_src_pdo[] = {
- PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS),
- PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS),
- PDO_FIXED(20000, 3000, PDO_FIXED_FLAGS),
-};
-static const int pd_src_pdo_cnts[] = {
- [SRC_CAP_5V] = 1,
- [SRC_CAP_12V] = 2,
- [SRC_CAP_20V] = 3,
-};
-
-static int pd_src_pdo_idx;
-
-/* Fake PDOs : we just want our pre-defined voltages */
-const uint32_t pd_snk_pdo[] = {
- PDO_FIXED(5000, 500, PDO_FIXED_FLAGS),
- PDO_FIXED(12000, 500, PDO_FIXED_FLAGS),
- PDO_FIXED(20000, 500, PDO_FIXED_FLAGS),
-};
-const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
-
-/* Whether alternate mode has been entered or not */
-static int alt_mode;
-
-void board_set_source_cap(enum board_src_cap cap)
-{
- pd_src_pdo_idx = cap;
-}
-
-int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port)
-{
- *src_pdo = pd_src_pdo;
- return pd_src_pdo_cnts[pd_src_pdo_idx];
-}
-
-void pd_set_input_current_limit(int port, uint32_t max_ma,
- uint32_t supply_voltage)
-{
- /* No battery, nothing to do */
- return;
-}
-
-__override void pd_transition_voltage(int idx)
-{
- gpio_set_level(GPIO_USBC_VSEL_0, idx >= 2);
- gpio_set_level(GPIO_USBC_VSEL_1, idx >= 3);
-}
-
-int pd_set_power_supply_ready(int port)
-{
- /* Output the correct voltage */
- gpio_set_level(GPIO_VBUS_CHARGER_EN, 1);
-
- return EC_SUCCESS;
-}
-
-void pd_power_supply_reset(int port)
-{
- /* Kill VBUS */
- gpio_set_level(GPIO_VBUS_CHARGER_EN, 0);
- gpio_set_level(GPIO_USBC_VSEL_0, 0);
- gpio_set_level(GPIO_USBC_VSEL_1, 0);
-}
-
-int pd_snk_is_vbus_provided(int port)
-{
- return gpio_get_level(GPIO_VBUS_WAKE);
-}
-
-__override int pd_board_checks(void)
-{
- static int was_connected = -1;
- if (was_connected != 1 && pd_is_connected(0))
- board_maybe_reset_usb_hub();
- was_connected = pd_is_connected(0);
- return EC_SUCCESS;
-}
-
-__override int pd_check_power_swap(int port)
-{
- /* Always allow power swap */
- return 1;
-}
-
-__override int pd_check_data_swap(int port,
- enum pd_data_role data_role)
-{
- /* Always allow data swap */
- return 1;
-}
-
-__override void pd_check_pr_role(int port,
- enum pd_power_role pr_role,
- int flags)
-{
-}
-
-__override void pd_check_dr_role(int port,
- enum pd_data_role dr_role,
- int flags)
-{
- /* If Plankton is in USB hub mode, always act as UFP */
- if (board_in_hub_mode() && dr_role == PD_ROLE_DFP &&
- (flags & PD_FLAGS_PARTNER_DR_DATA))
- pd_request_data_swap(port);
-}
-
-/* ----------------- Vendor Defined Messages ------------------ */
-const uint32_t vdo_idh = VDO_IDH(0, /* data caps as USB host */
- 0, /* data caps as USB device */
- IDH_PTYPE_AMA, /* Alternate mode */
- 1, /* supports alt modes */
- USB_VID_GOOGLE);
-
-const uint32_t vdo_product = VDO_PRODUCT(CONFIG_USB_PID, CONFIG_USB_BCD_DEV);
-
-const uint32_t vdo_ama = VDO_AMA(CONFIG_USB_PD_IDENTITY_HW_VERS,
- CONFIG_USB_PD_IDENTITY_SW_VERS,
- 0, 0, 0, 0, /* SS[TR][12] */
- 0, /* Vconn power */
- 0, /* Vconn power required */
- 1, /* Vbus power required */
- AMA_USBSS_BBONLY /* USB SS support */);
-
-static int svdm_response_identity(int port, uint32_t *payload)
-{
- payload[VDO_I(IDH)] = vdo_idh;
- payload[VDO_I(CSTAT)] = VDO_CSTAT(0);
- payload[VDO_I(PRODUCT)] = vdo_product;
- payload[VDO_I(AMA)] = vdo_ama;
- return VDO_I(AMA) + 1;
-}
-
-static int svdm_response_svids(int port, uint32_t *payload)
-{
- payload[1] = VDO_SVID(USB_SID_DISPLAYPORT, 0);
- return 2;
-}
-
-/*
- * Will only ever be a single mode for this UFP_D device as it has no real USB
- * support making it only PIN_E configureable
- */
-#define MODE_CNT 1
-#define OPOS 1
-
-const uint32_t vdo_dp_mode[MODE_CNT] = {
- VDO_MODE_DP(0, /* UFP pin cfg supported : none */
- MODE_DP_PIN_E, /* DFP pin cfg supported */
- 1, /* no usb2.0 signalling in AMode */
- CABLE_PLUG, /* its a plug */
- MODE_DP_V13, /* DPv1.3 Support, no Gen2 */
- MODE_DP_SNK) /* Its a sink only */
-};
-
-static int svdm_response_modes(int port, uint32_t *payload)
-{
- if (gpio_get_level(GPIO_USBC_SS_USB_MODE))
- return 0; /* nak */
-
- if (PD_VDO_VID(payload[0]) != USB_SID_DISPLAYPORT)
- return 0; /* nak */
-
- memcpy(payload + 1, vdo_dp_mode, sizeof(vdo_dp_mode));
- return MODE_CNT + 1;
-}
-
-static int dp_status(int port, uint32_t *payload)
-{
- int opos = PD_VDO_OPOS(payload[0]);
- int hpd = gpio_get_level(GPIO_DPSRC_HPD);
- if (opos != OPOS)
- return 0; /* nak */
-
- payload[1] = VDO_DP_STATUS(0, /* IRQ_HPD */
- (hpd == 1), /* HPD_HI|LOW */
- 0, /* request exit DP */
- 0, /* request exit USB */
- 0, /* MF pref */
- !gpio_get_level(GPIO_USBC_SS_USB_MODE),
- 0, /* power low */
- 0x2);
- return 2;
-}
-
-static int dp_config(int port, uint32_t *payload)
-{
- if (PD_DP_CFG_DPON(payload[1]))
- gpio_set_level(GPIO_USBC_SS_USB_MODE, 0);
- return 1;
-}
-
-int svdm_enter_mode(int port, uint32_t *payload)
-{
- int usb_mode = gpio_get_level(GPIO_USBC_SS_USB_MODE);
-
- /* SID & mode request is valid */
- if ((PD_VDO_VID(payload[0]) != USB_SID_DISPLAYPORT) ||
- (PD_VDO_OPOS(payload[0]) != OPOS))
- return 0; /* will generate NAK */
-
- if (usb_mode) {
- CPRINTS("Toggle USB_MODE if you want DP & re-connect");
- return 0;
- }
-
- alt_mode = OPOS;
- return 1;
-}
-
-int pd_alt_mode(int port, enum tcpci_msg_type type, uint16_t svid)
-{
- return alt_mode;
-}
-
-static int svdm_exit_mode(int port, uint32_t *payload)
-{
- alt_mode = 0;
- /*
- * Don't actually toggle GPIO_USBC_SS_USB_MODE since its manually
- * controlled by operator.
- */
- return 1; /* Must return ACK */
-}
-
-static struct amode_fx dp_fx = {
- .status = &dp_status,
- .config = &dp_config,
-};
-
-__override const struct svdm_response svdm_rsp = {
- .identity = &svdm_response_identity,
- .svids = &svdm_response_svids,
- .modes = &svdm_response_modes,
- .enter_mode = &svdm_enter_mode,
- .amode = &dp_fx,
- .exit_mode = &svdm_exit_mode,
-};
-
-__override int pd_custom_vdm(int port, int cnt, uint32_t *payload,
- uint32_t **rpayload)
-{
- int cmd = PD_VDO_CMD(payload[0]);
- int rsize = 1;
- CPRINTF("VDM/%d [%d] %08x\n", cnt, cmd, payload[0]);
-
- *rpayload = payload;
- switch (cmd) {
- case VDO_CMD_VERSION:
- memcpy(payload + 1, &current_image_data.version, 24);
- rsize = 7;
- break;
- default:
- rsize = 0;
- }
-
- CPRINTS("DONE");
- /* respond (positively) to the request */
- payload[0] |= VDO_SRC_RESPONDER;
-
- return rsize;
-}
diff --git a/board/plankton/vif_override.xml b/board/plankton/vif_override.xml
deleted file mode 100644
index 32736caf64..0000000000
--- a/board/plankton/vif_override.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<!-- Add VIF field overrides here. See genvif.c and the Vendor Info File
- Definition from the USB-IF.
--->