diff options
author | Dino Li <dino.li@ite.com.tw> | 2016-05-06 14:52:53 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-05-18 01:27:55 -0700 |
commit | 2388211bd74fab4b93e90831e6a323650d6438aa (patch) | |
tree | caf475764221132270ac8c699c690b0a550c1a70 | |
parent | f2d57a8972f89f089f80dd0e4efeb6806d71806c (diff) | |
download | chrome-ec-2388211bd74fab4b93e90831e6a323650d6438aa.tar.gz |
board: it83xx_evb: support PD EVB
The change is made to combine EC & PD's board code.
Signed-off-by: Dino Li <dino.li@ite.com.tw>
BRANCH=none
BUG=none
TEST=We can verify PD module on PD EVB and run this board code
on EC EVB as well.
Change-Id: I92f6ad41643b0536fd78d24026374265cfcf37ea
Reviewed-on: https://chromium-review.googlesource.com/342489
Commit-Ready: Dino Li <dino0303@gmail.com>
Tested-by: Dino Li <dino0303@gmail.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | board/it83xx_evb/board.c | 86 | ||||
-rw-r--r-- | board/it83xx_evb/board.h | 64 | ||||
-rw-r--r-- | board/it83xx_evb/build.mk | 3 | ||||
-rw-r--r-- | board/it83xx_evb/ec.tasklist | 4 | ||||
-rw-r--r-- | board/it83xx_evb/gpio.inc | 21 | ||||
-rw-r--r-- | board/it83xx_evb/usb_pd_policy.c | 335 |
6 files changed, 469 insertions, 44 deletions
diff --git a/board/it83xx_evb/board.c b/board/it83xx_evb/board.c index b63f6b9dcb..7c8dec6af4 100644 --- a/board/it83xx_evb/board.c +++ b/board/it83xx_evb/board.c @@ -2,13 +2,14 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -/* IT8380 development board configuration */ +/* IT83xx development board configuration */ #include "adc.h" #include "adc_chip.h" #include "clock.h" #include "common.h" #include "console.h" +#include "it83xx_pd.h" #include "ec2i_chip.h" #include "fan.h" #include "gpio.h" @@ -28,8 +29,72 @@ #include "task.h" #include "timer.h" #include "uart.h" +#include "usb_pd.h" +#include "usb_pd_tcpm.h" #include "util.h" +#if IT83XX_PD_EVB +int board_get_battery_soc(void) +{ + return 100; +} + +const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { + {-1, -1, &it83xx_tcpm_drv}, + {-1, -1, &it83xx_tcpm_drv}, +}; + +void board_pd_vconn_ctrl(int port, int cc_pin, int enabled) +{ + int cc1_enabled = 0, cc2_enabled = 0; + + if (cc_pin) + cc2_enabled = enabled; + else + cc1_enabled = enabled; + + if (port) { + gpio_set_level(GPIO_USBPD_PORTB_CC2_VCONN, cc2_enabled); + gpio_set_level(GPIO_USBPD_PORTB_CC1_VCONN, cc1_enabled); + } else { + gpio_set_level(GPIO_USBPD_PORTA_CC2_VCONN, cc2_enabled); + gpio_set_level(GPIO_USBPD_PORTA_CC1_VCONN, cc1_enabled); + } +} + +void board_pd_vbus_ctrl(int port, int enabled) +{ + if (port) { + gpio_set_level(GPIO_USBPD_PORTB_VBUS_INPUT, !enabled); + gpio_set_level(GPIO_USBPD_PORTB_VBUS_OUTPUT, enabled); + if (!enabled) { + gpio_set_level(GPIO_USBPD_PORTB_VBUS_DROP, 1); + udelay(MSEC); + } + gpio_set_level(GPIO_USBPD_PORTB_VBUS_DROP, 0); + } else { + gpio_set_level(GPIO_USBPD_PORTA_VBUS_INPUT, !enabled); + gpio_set_level(GPIO_USBPD_PORTA_VBUS_OUTPUT, enabled); + if (!enabled) { + gpio_set_level(GPIO_USBPD_PORTA_VBUS_DROP, 1); + udelay(MSEC); + } + gpio_set_level(GPIO_USBPD_PORTA_VBUS_DROP, 0); + } +} +#else +/* EC EVB */ +#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) +void pd_task(void) +{ + CPRINTF("EC EVB so PD task (ID%x) is suspended all the time.\n", + task_get_current()); + + while (1) + task_wait_event(-1); +} +#endif + #include "gpio_list.h" /* @@ -40,12 +105,6 @@ */ const struct pwm_t pwm_channels[] = { {7, 0, 30000, PWM_PRESCALER_C4}, - {1, PWM_CONFIG_ACTIVE_LOW, 1000, PWM_PRESCALER_C6}, - {2, 0, 200, PWM_PRESCALER_C7}, - {3, PWM_CONFIG_ACTIVE_LOW, 1000, PWM_PRESCALER_C6}, - {4, 0, 30000, PWM_PRESCALER_C4}, - {5, PWM_CONFIG_ACTIVE_LOW, 200, PWM_PRESCALER_C7}, - {0, PWM_CONFIG_ACTIVE_LOW, 1000, PWM_PRESCALER_C6}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); @@ -182,14 +241,8 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); /* ADC channels. Must be in the exactly same order as in enum adc_channel. */ const struct adc_t adc_channels[] = { /* Convert to mV (3000mV/1024). */ - {"adc_ch0", 3000, 1024, 0, 0}, - {"adc_ch1", 3000, 1024, 0, 1}, - {"adc_ch2", 3000, 1024, 0, 2}, - {"adc_ch3", 3000, 1024, 0, 3}, - {"adc_ch4", 3000, 1024, 0, 4}, - {"adc_ch5", 3000, 1024, 0, 5}, - {"adc_ch6", 3000, 1024, 0, 6}, - {"adc_ch7", 3000, 1024, 0, 7}, + {"ADC_VBUSSA", 3000, 1024, 0, 0}, /*GPI0*/ + {"ADC_VBUSSB", 3000, 1024, 0, 1}, /*GPI1*/ }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); @@ -229,9 +282,6 @@ const struct i2c_port_t i2c_ports[] = { {"battery", IT83XX_I2C_CH_C, 100, GPIO_I2C_C_SCL, GPIO_I2C_C_SDA}, {"evb-1", IT83XX_I2C_CH_A, 100, GPIO_I2C_A_SCL, GPIO_I2C_A_SDA}, {"evb-2", IT83XX_I2C_CH_B, 100, GPIO_I2C_B_SCL, GPIO_I2C_B_SDA}, -#ifndef CONFIG_UART_HOST - {"opt-3", IT83XX_I2C_CH_D, 100, GPIO_I2C_D_SCL, GPIO_I2C_D_SDA}, -#endif {"opt-4", IT83XX_I2C_CH_E, 100, GPIO_I2C_E_SCL, GPIO_I2C_E_SDA}, }; diff --git a/board/it83xx_evb/board.h b/board/it83xx_evb/board.h index b2cf093968..9b8fa5fe21 100644 --- a/board/it83xx_evb/board.h +++ b/board/it83xx_evb/board.h @@ -3,11 +3,14 @@ * found in the LICENSE file. */ -/* IT8380 development board configuration */ +/* IT83xx development board configuration */ #ifndef __CROS_EC_BOARD_H #define __CROS_EC_BOARD_H +/* NOTE: 0->ec evb, non-zero->pd evb */ +#define IT83XX_PD_EVB 0 + /* Optional features */ #define CONFIG_BATTERY_SMART #define CONFIG_BOARD_VERSION @@ -25,6 +28,22 @@ #define CONFIG_SPI_FLASH_PORT 0 #define CONFIG_UART_HOST +#if IT83XX_PD_EVB +/* PD */ +#define CONFIG_USB_PD_ALT_MODE +#define CONFIG_USB_PD_ALT_MODE_DFP +#define CONFIG_USB_PD_CHECK_MAX_REQUEST_ALLOWED +#define CONFIG_USB_PD_CUSTOM_VDM +#define CONFIG_USB_PD_DUAL_ROLE +#define CONFIG_USB_PD_PORT_COUNT 2 +#define CONFIG_USB_PD_TCPM_ITE83XX +#define CONFIG_USB_PD_TRY_SRC +#define CONFIG_USB_POWER_DELIVERY +#define CONFIG_USBC_VCONN +#define CONFIG_USBC_VCONN_SWAP +#undef CONFIG_UART_HOST +#endif + /* Optional console commands */ #define CONFIG_CMD_FLASH #define CONFIG_CMD_SCRATCHPAD @@ -48,27 +67,13 @@ enum pwm_channel { PWM_CH_FAN, - PWM_CH_1, - PWM_CH_2, - PWM_CH_3, - PWM_CH_4, - PWM_CH_5, - PWM_CH_7, - /* Number of PWM channels */ PWM_CH_COUNT }; enum adc_channel { - ADC_CH_0, - ADC_CH_1, - ADC_CH_2, - ADC_CH_3, - ADC_CH_4, - ADC_CH_5, - ADC_CH_6, - ADC_CH_7, - + ADC_VBUSSA, + ADC_VBUSSB, /* Number of ADC channels */ ADC_CH_COUNT }; @@ -117,5 +122,30 @@ enum ec2i_setting { EC2I_SETTING_COUNT }; +#if IT83XX_PD_EVB +/* Define typical operating power and max power */ +#define PD_OPERATING_POWER_MW 15000 +#define PD_MAX_POWER_MW 60000 +#define PD_MAX_CURRENT_MA 3000 +/* Try to negotiate to 20V since i2c noise problems should be fixed. */ +#define PD_MAX_VOLTAGE_MV 20000 +/* start as a sink in case we have no other power supply/battery */ +#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED +/* TODO: determine the following board specific type-C power constants */ +/* + * delay to turn on the power supply max is ~16ms. + * delay to turn off the power supply max is about ~180ms. + */ +#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */ +#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */ + +/* delay to turn on/off vconn */ +#define PD_VCONN_SWAP_DELAY 5000 /* us */ + +int board_get_battery_soc(void); +void board_pd_vconn_ctrl(int port, int cc_pin, int enabled); +void board_pd_vbus_ctrl(int port, int enabled); +#endif + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/it83xx_evb/build.mk b/board/it83xx_evb/build.mk index 83f36b09b1..0f3e2d9017 100644 --- a/board/it83xx_evb/build.mk +++ b/board/it83xx_evb/build.mk @@ -5,7 +5,8 @@ # # Board specific files build -# the IC is ITE 8380 +# the IC is ITE IT8390/IT8320 CHIP:=it83xx board-y=board.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o diff --git a/board/it83xx_evb/ec.tasklist b/board/it83xx_evb/ec.tasklist index 6db02cfa8a..bc2aa978d7 100644 --- a/board/it83xx_evb/ec.tasklist +++ b/board/it83xx_evb/ec.tasklist @@ -21,4 +21,6 @@ TASK_ALWAYS(CONSOLE, console_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \ - TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) + TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(PD_C1, pd_task, NULL, LARGER_TASK_STACK_SIZE) diff --git a/board/it83xx_evb/gpio.inc b/board/it83xx_evb/gpio.inc index 51c9167b92..b14cfc8287 100644 --- a/board/it83xx_evb/gpio.inc +++ b/board/it83xx_evb/gpio.inc @@ -16,8 +16,20 @@ GPIO_INT(WP_L, PIN(E, 1), GPIO_INT_BOTH, switch_inter GPIO_INT(UART1_RX, PIN(B, 0), GPIO_INT_FALLING, uart_deepsleep_interrupt) /* UART1 RX input */ #endif -GPIO(CAPS_LED, PIN(H, 1), GPIO_OUT_LOW) -GPIO(SCRO_LED, PIN(H, 2), GPIO_OUT_LOW) +#if IT83XX_PD_EVB +GPIO(USBPD_HVLDO, PIN(A, 1), GPIO_OUT_LOW) +GPIO(USBPD_PORTB_CC1_VCONN, PIN(A, 2), GPIO_OUT_LOW) +GPIO(USBPD_PORTB_CC2_VCONN, PIN(A, 3), GPIO_OUT_LOW) +GPIO(USBPD_PORTB_VBUS_INPUT, PIN(A, 4), GPIO_OUT_HIGH) +GPIO(USBPD_PORTB_VBUS_OUTPUT, PIN(A, 5), GPIO_OUT_LOW) +GPIO(USBPD_PORTB_VBUS_DROP, PIN(A, 6), GPIO_OUT_LOW) +GPIO(USBPD_PORTA_CC1_VCONN, PIN(C, 4), GPIO_OUT_LOW) +GPIO(USBPD_PORTA_CC2_VCONN, PIN(C, 6), GPIO_OUT_LOW) +GPIO(USBPD_PORTA_VBUS_INPUT, PIN(D, 0), GPIO_OUT_HIGH) +GPIO(USBPD_PORTA_VBUS_OUTPUT, PIN(D, 1), GPIO_OUT_LOW) +GPIO(USBPD_PORTA_VBUS_DROP, PIN(E, 5), GPIO_OUT_LOW) +#endif + GPIO(PCH_SMI_L, PIN(D, 3), GPIO_OUT_HIGH) GPIO(PCH_SCI_L, PIN(D, 4), GPIO_OUT_HIGH) GPIO(GATE_A20_H, PIN(B, 5), GPIO_OUT_HIGH) @@ -42,9 +54,6 @@ GPIO(I2C_E_SDA, PIN(E, 7), GPIO_INPUT) #ifdef CONFIG_UART_HOST GPIO(UART2_SIN1, PIN(H, 1), GPIO_INPUT) GPIO(UART2_SOUT1, PIN(H, 2), GPIO_INPUT) -#else -GPIO(I2C_D_SCL, PIN(H, 1), GPIO_INPUT) -GPIO(I2C_D_SDA, PIN(H, 2), GPIO_INPUT) #endif /* KSO/KSI pins can be used as GPIO input. */ @@ -58,8 +67,6 @@ UNIMPLEMENTED(ENTERING_RW) ALTERNATE(PIN_MASK(B, 0x03), 1, MODULE_UART, GPIO_PULL_UP) /* UART1 */ #ifdef CONFIG_UART_HOST ALTERNATE(PIN_MASK(H, 0x06), 1, MODULE_UART, 0) /* UART2 */ -#else -ALTERNATE(PIN_MASK(H, 0x06), 1, MODULE_I2C, 0) /* I2C D SCL/SDA H1/H2 */ #endif ALTERNATE(PIN_MASK(A, 0x40), 3, MODULE_SPI, 0) /* SSCK of SPI */ ALTERNATE(PIN_MASK(C, 0x28), 3, MODULE_SPI, 0) /* SMOSI/SMISO of SPI */ diff --git a/board/it83xx_evb/usb_pd_policy.c b/board/it83xx_evb/usb_pd_policy.c new file mode 100644 index 0000000000..b1c0fa3014 --- /dev/null +++ b/board/it83xx_evb/usb_pd_policy.c @@ -0,0 +1,335 @@ +/* Copyright 2016 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 "config.h" +#include "common.h" +#include "console.h" +#include "gpio.h" +#include "hooks.h" +#include "registers.h" +#include "system.h" +#include "task.h" +#include "timer.h" +#include "util.h" +#include "usb_mux.h" + +#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) +#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) + +#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ + PDO_FIXED_EXTERNAL | PDO_FIXED_COMM_CAP) + +/* Threshold voltage of VBUS provided (mV) */ +#define PD_VBUS_PROVIDED_THRESHOLD 3900 + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 1500, 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(4500, 14000, 10000), + PDO_VAR(4500, 14000, 3000), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); + +void pd_set_input_current_limit(int port, uint32_t max_ma, + uint32_t supply_voltage) +{ +} + +void typec_set_input_current_limit(int port, uint32_t max_ma, + uint32_t supply_voltage) +{ +} + +int pd_is_max_request_allowed(void) +{ + /* max voltage request allowed */ + return 1; +} + +int pd_is_valid_input_voltage(int mv) +{ + /* Any voltage less than the max is allowed */ + return 1; +} + +void pd_transition_voltage(int idx) +{ + /* No-operation: we are always 5V */ +} + +int pd_snk_is_vbus_provided(int port) +{ + int mv = adc_read_channel(port == USBPD_PORT_A ? + ADC_VBUSSA : ADC_VBUSSB); + + /* level shift voltage of VBUS > threshold */ + return (mv * 23 / 3) > PD_VBUS_PROVIDED_THRESHOLD; +} + +int pd_set_power_supply_ready(int port) +{ + /* provide VBUS */ + board_pd_vbus_ctrl(port, 1); + /* vbus provided or not */ + return !pd_snk_is_vbus_provided(port); +} + +void pd_power_supply_reset(int port) +{ + /* Kill VBUS */ + board_pd_vbus_ctrl(port, 0); +} + +int pd_board_checks(void) +{ + return EC_SUCCESS; +} + +int pd_check_power_swap(int port) +{ + /* TODO: use battery level to decide to accept/reject power swap + * Allow power swap as long as we are acting as a dual role device, + * otherwise assume our role is fixed (not in S0 or console command + * to fix our role). + */ + return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0; +} + +int pd_check_data_swap(int port, int data_role) +{ + /* Always allow data swap: we can be DFP or UFP for USB */ + return 1; +} + +int pd_check_vconn_swap(int port) +{ + /* + * VCONN is provided directly by the battery(PPVAR_SYS) + * but use the same rules as power swap + */ + return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0; +} + +void pd_execute_data_swap(int port, int data_role) +{ +} + +void pd_check_pr_role(int port, int pr_role, int flags) +{ + /* + * If partner is dual-role power and dualrole toggling is on, consider + * if a power swap is necessary. + */ + if ((flags & PD_FLAGS_PARTNER_DR_POWER) && + pd_get_dual_role() == PD_DRP_TOGGLE_ON) { + /* + * If we are source and partner is externally powered, + * swap to become a sink. + */ + if ((flags & PD_FLAGS_PARTNER_EXTPOWER) && + pr_role == PD_ROLE_SOURCE) + pd_request_power_swap(port); + } +} + +void pd_check_dr_role(int port, int dr_role, int flags) +{ + /* if the partner is a DRP (e.g. laptop), try to switch to UFP */ + if ((flags & PD_FLAGS_PARTNER_DR_DATA) && dr_role == PD_ROLE_DFP) + pd_request_data_swap(port); +} + +/* ----------------- 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]); + uint16_t dev_id = 0; + int is_rw; + + /* 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("version: %s\n", (char *)(payload+1)); + break; + case VDO_CMD_READ_INFO: + case VDO_CMD_SEND_INFO: + /* copy hash */ + if (cnt == 7) { + dev_id = VDO_INFO_HW_DEV_ID(payload[6]); + is_rw = VDO_INFO_IS_RW(payload[6]); + + CPRINTF("DevId:%d.%d SW:%d RW:%d\n", + HW_DEV_ID_MAJ(dev_id), + HW_DEV_ID_MIN(dev_id), + VDO_INFO_SW_DBG_VER(payload[6]), + is_rw); + } else if (cnt == 6) { + /* really old devices don't have last byte */ + pd_dev_store_rw_hash(port, dev_id, payload + 1, + SYSTEM_IMAGE_UNKNOWN); + } + break; + case VDO_CMD_CURRENT: + CPRINTF("Current: %dmA\n", payload[1]); + break; + case VDO_CMD_FLIP: + /* usb_mux_flip(port); */ + break; +#ifdef CONFIG_USB_PD_LOGGING + case VDO_CMD_GET_LOG: + pd_log_recv_vdm(port, cnt, payload); + break; +#endif /* CONFIG_USB_PD_LOGGING */ + } + + return 0; +} + +#ifdef CONFIG_USB_PD_ALT_MODE_DFP +static int dp_flags[CONFIG_USB_PD_PORT_COUNT]; +/* DP Status VDM as returned by UFP */ +static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT]; + +static void svdm_safe_dp_mode(int port) +{ + /* make DP interface safe until configure */ + dp_flags[port] = 0; + dp_status[port] = 0; + /* usb_mux_set(port, TYPEC_MUX_NONE, + USB_SWITCH_CONNECT, pd_get_polarity(port)); */ +} + +static int svdm_enter_dp_mode(int port, uint32_t mode_caps) +{ + /* Only enter mode if device is DFP_D capable */ + if (mode_caps & MODE_DP_SNK) { + svdm_safe_dp_mode(port); + return 0; + } + + return -1; +} + +static int svdm_dp_status(int port, uint32_t *payload) +{ + int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); + + payload[0] = VDO(USB_SID_DISPLAYPORT, 1, + CMD_DP_STATUS | VDO_OPOS(opos)); + payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */ + 0, /* HPD level ... not applicable */ + 0, /* exit DP? ... no */ + 0, /* usb mode? ... no */ + 0, /* multi-function ... no */ + (!!(dp_flags[port] & DP_FLAGS_DP_ON)), + 0, /* power low? ... no */ + (!!(dp_flags[port] & DP_FLAGS_DP_ON))); + return 2; +}; + +static int svdm_dp_config(int port, uint32_t *payload) +{ + int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); + /* int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]); */ + int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]); + + if (!pin_mode) + return 0; + + /* usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP, + USB_SWITCH_CONNECT, pd_get_polarity(port)); */ + + payload[0] = VDO(USB_SID_DISPLAYPORT, 1, + CMD_DP_CONFIG | VDO_OPOS(opos)); + payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */ + 1, /* DPv1.3 signaling */ + 2); /* UFP connected */ + return 2; +}; + +static void svdm_dp_post_config(int port) +{ + /* TODO: Figure out HPD */ +} + +static int svdm_dp_attention(int port, uint32_t *payload) +{ + /* TODO: Figure out HPD */ + return 1; +} + +static void svdm_exit_dp_mode(int port) +{ + /* TODO: Figure out HPD */ +} + +static int svdm_enter_gfu_mode(int port, uint32_t mode_caps) +{ + /* Always enter GFU mode */ + return 0; +} + +static void svdm_exit_gfu_mode(int port) +{ +} + +static int svdm_gfu_status(int port, uint32_t *payload) +{ + /* + * This is called after enter mode is successful, send unstructured + * VDM to read info. + */ + pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_READ_INFO, NULL, 0); + return 0; +} + +static int svdm_gfu_config(int port, uint32_t *payload) +{ + return 0; +} + +static int svdm_gfu_attention(int port, uint32_t *payload) +{ + return 0; +} + +const struct svdm_amode_fx supported_modes[] = { + { + .svid = USB_SID_DISPLAYPORT, + .enter = &svdm_enter_dp_mode, + .status = &svdm_dp_status, + .config = &svdm_dp_config, + .post_config = &svdm_dp_post_config, + .attention = &svdm_dp_attention, + .exit = &svdm_exit_dp_mode, + }, + { + .svid = USB_VID_GOOGLE, + .enter = &svdm_enter_gfu_mode, + .status = &svdm_gfu_status, + .config = &svdm_gfu_config, + .attention = &svdm_gfu_attention, + .exit = &svdm_exit_gfu_mode, + } +}; +const int supported_modes_cnt = ARRAY_SIZE(supported_modes); +#endif /* CONFIG_USB_PD_ALT_MODE_DFP */ |