diff options
author | Wai-Hong Tam <waihong@google.com> | 2020-03-17 11:46:25 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-05-08 05:33:18 +0000 |
commit | 974de474ad4c4c86721ae6c4448875b85dc3234b (patch) | |
tree | ffb277505a96ef8de7a9eb16ae037a43c12ca2c5 /board/servo_v4 | |
parent | acce53e2ea4eb248a816f868a5b3817bbd4f83a0 (diff) | |
download | chrome-ec-974de474ad4c4c86721ae6c4448875b85dc3234b.tar.gz |
servo_v4: Add console commands to override the HPD pass-through
New console commands, like:
> usbc_action dp hpd ext # use the external HPD, no overridden
> usbc_action dp hpd h # override HPD to high, IRQ pass-through
> usbc_action dp hpd l # override HPD to low, no IRQ pass-through
> usbc_action dp hpd irq # send HPD IRQ
BRANCH=servo
BUG=b:153647984
TEST=Tried the new console commands.
Change-Id: I197efd1d03d906b99d7b82ad151865da44e321ea
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2143937
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'board/servo_v4')
-rw-r--r-- | board/servo_v4/board.c | 14 | ||||
-rw-r--r-- | board/servo_v4/board.h | 7 | ||||
-rw-r--r-- | board/servo_v4/usb_pd_config.h | 14 | ||||
-rw-r--r-- | board/servo_v4/usb_pd_policy.c | 46 |
4 files changed, 68 insertions, 13 deletions
diff --git a/board/servo_v4/board.c b/board/servo_v4/board.c index 5dc2b18ed5..559b9bb5b0 100644 --- a/board/servo_v4/board.c +++ b/board/servo_v4/board.c @@ -469,18 +469,24 @@ static void ccd_measure_sbu(void) hook_call_deferred(&ccd_measure_sbu_data, 100 * MSEC); } -void ccd_enable(int enable) +void ext_hpd_detection_enable(int enable) { if (enable) { - gpio_disable_interrupt(GPIO_DP_HPD); - hook_call_deferred(&ccd_measure_sbu_data, 0); - } else { timestamp_t now = get_time(); hpd_prev_level = gpio_get_level(GPIO_DP_HPD); hpd_prev_ts = now.val; gpio_enable_interrupt(GPIO_DP_HPD); + } else { + gpio_disable_interrupt(GPIO_DP_HPD); + } +} +void ccd_enable(int enable) +{ + if (enable) { + hook_call_deferred(&ccd_measure_sbu_data, 0); + } else { gpio_set_level(GPIO_SBU_MUX_EN, 0); hook_call_deferred(&ccd_measure_sbu_data, -1); } diff --git a/board/servo_v4/board.h b/board/servo_v4/board.h index 3362c40ef6..b89df7f9f4 100644 --- a/board/servo_v4/board.h +++ b/board/servo_v4/board.h @@ -244,6 +244,13 @@ int pd_set_rp_rd(int port, int cc_pull, int rp_value); int board_get_version(void); /** + * Enable or disable external HPD detection + * + * @param enable Enable external HPD detection if true, otherwise disable + */ +void ext_hpd_detection_enable(int enable); + +/** * Enable or disable CCD * * @param enable Enable CCD if true, otherwise disable diff --git a/board/servo_v4/usb_pd_config.h b/board/servo_v4/usb_pd_config.h index 2d189d6267..9d0a79cf2d 100644 --- a/board/servo_v4/usb_pd_config.h +++ b/board/servo_v4/usb_pd_config.h @@ -64,12 +64,14 @@ #define CC_POLARITY BIT(5) /* CC polarity */ /* Servo v4 DP alt-mode configuration */ -#define ALT_DP_ENABLE BIT(0) /* Enable DP alt-mode or not */ -#define ALT_DP_PIN_C BIT(1) /* Pin assignment C supported */ -#define ALT_DP_PIN_D BIT(2) /* Pin assignment D supported */ -#define ALT_DP_PIN_E BIT(3) /* Pin assignment E supported */ -#define ALT_DP_MF_PREF BIT(4) /* Multi-Function preferred */ -#define ALT_DP_PLUG BIT(5) /* Plug or receptacle */ +#define ALT_DP_ENABLE BIT(0) /* Enable DP alt-mode or not */ +#define ALT_DP_PIN_C BIT(1) /* Pin assignment C supported */ +#define ALT_DP_PIN_D BIT(2) /* Pin assignment D supported */ +#define ALT_DP_PIN_E BIT(3) /* Pin assignment E supported */ +#define ALT_DP_MF_PREF BIT(4) /* Multi-Function preferred */ +#define ALT_DP_PLUG BIT(5) /* Plug or receptacle */ +#define ALT_DP_OVERRIDE_HPD BIT(6) /* Override the HPD signal */ +#define ALT_DP_HPD_LVL BIT(7) /* HPD level if overridden */ /* TX uses SPI1 on PB3-4 for CHG port, SPI2 on PB 13-14 for DUT port */ #define SPI_REGS(p) ((p) ? STM32_SPI2_REGS : STM32_SPI1_REGS) diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c index 05769cc942..0e3658f618 100644 --- a/board/servo_v4/usb_pd_policy.c +++ b/board/servo_v4/usb_pd_policy.c @@ -900,10 +900,18 @@ static void set_typec_mux(int pin_cfg) value); } +static int get_hpd_level(void) +{ + if (alt_dp_config & ALT_DP_OVERRIDE_HPD) + return (alt_dp_config & ALT_DP_HPD_LVL) != 0; + else + return gpio_get_level(GPIO_DP_HPD); +} + static int dp_status(int port, uint32_t *payload) { int opos = PD_VDO_OPOS(payload[0]); - int hpd = gpio_get_level(GPIO_DP_HPD); + int hpd = get_hpd_level(); if (opos != OPOS) return 0; /* NAK */ @@ -1042,9 +1050,12 @@ static void do_cc(int cc_config_new) if ((cc_config & ~cc_config_new) & CC_DISABLE_DTS) { /* DTS-disabled -> DTS-enabled */ ccd_enable(1); + ext_hpd_detection_enable(0); } else if ((cc_config_new & ~cc_config) & CC_DISABLE_DTS) { /* DTS-enabled -> DTS-disabled */ ccd_enable(0); + if (!(alt_dp_config & ALT_DP_OVERRIDE_HPD)) + ext_hpd_detection_enable(1); } /* Accept new cc_config value */ @@ -1266,8 +1277,37 @@ static int cmd_dp_action(int argc, char *argv[]) } CPRINTS("Plug or receptacle: %d", (alt_dp_config & ALT_DP_PLUG) != 0); - } else if (!strcasecmp(argv[1], "help")) { - CPRINTS("Usage: usbc_action dp [enable|disable|mf|pins|plug]"); + } else if (!strcasecmp(argv[1], "hpd")) { + if (argc >= 3) { + if (!strncasecmp(argv[2], "ext", 3)) { + alt_dp_config &= ~ALT_DP_OVERRIDE_HPD; + ext_hpd_detection_enable(1); + } else if (!strncasecmp(argv[2], "h", 1)) { + alt_dp_config |= ALT_DP_OVERRIDE_HPD; + alt_dp_config |= ALT_DP_HPD_LVL; + /* + * Modify the HPD to high. Need to enable the + * external HPD signal monitoring. A monitor + * may send a IRQ at any time to notify DUT. + */ + ext_hpd_detection_enable(1); + pd_send_hpd(DUT, hpd_high); + } else if (!strncasecmp(argv[2], "l", 1)) { + alt_dp_config |= ALT_DP_OVERRIDE_HPD; + alt_dp_config &= ~ALT_DP_HPD_LVL; + ext_hpd_detection_enable(0); + pd_send_hpd(DUT, hpd_low); + } else if (!strcasecmp(argv[2], "irq")) { + pd_send_hpd(DUT, hpd_irq); + } + } + CPRINTS("HPD source: %s", + (alt_dp_config & ALT_DP_OVERRIDE_HPD) ? "overridden" + : "external"); + CPRINTS("HPD level: %d", get_hpd_level()); + } else if (!strcasecmp(argv[1], "help")) { + CPRINTS("Usage: usbc_action dp [enable|disable|hpd|mf|pins|" + "plug]"); } return EC_SUCCESS; |