From 536c1e34494afd508552ad29b07d08eeaa3e4b5f Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Thu, 31 Aug 2017 13:00:01 -0700 Subject: [PATCH] chip/g: Move Rdd keepalive to chip driver Previously, chip/g/rdd provided a method for an external console command to override the Rdd cable detect state. But since we'll be refactoring the 'ccd' command, it's tidier to move this to a console command inside the rdd driver itself. BUG=none BRANCH=cr50 TEST=manual, with no debug cable present rdd enable -> Rdd connect rdd -> keepalive rdd disable rdd -> connected (hasn't had a chance to run state machine) (wait <1 sec) rdd -> debouncing (wait 1 sec) -> Rdd disconnect Change-Id: I141eedf8070b4ad2c96cc5a364f4e37dc29bed70 Signed-off-by: Randall Spangler Reviewed-on: https://chromium-review.googlesource.com/647991 Reviewed-by: Aseda Aboagye Reviewed-by: Mary Ruthven --- board/cr50/rdd.c | 9 +-------- chip/g/rdd.c | 37 ++++++++++++++++++++++++------------- chip/g/rdd.h | 10 ---------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index db38fbcd52..5e260aa587 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -168,13 +168,6 @@ static int command_ccd(int argc, char **argv) usb_i2c_board_enable(); else usb_i2c_board_disable(); - } else if (!strcasecmp("keepalive", argv[1])) { - force_rdd_detect(val); - if (val) { - ccprintf("Warning CCD will remain " - "enabled until it is " - "explicitly disabled.\n"); - } } else return EC_ERROR_PARAM1; } @@ -197,7 +190,7 @@ static int command_ccd(int argc, char **argv) return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(ccd, command_ccd, - "[uart|i2c|keepalive] []", + "[uart|i2c] []", "Get/set the case closed debug state"); static int command_sys_rst(int argc, char **argv) diff --git a/chip/g/rdd.c b/chip/g/rdd.c index 5e5ed42f6d..57c4bd96b9 100644 --- a/chip/g/rdd.c +++ b/chip/g/rdd.c @@ -51,8 +51,8 @@ static int rdd_is_detected(void) void print_rdd_state(void) { - ccprintf("RDD: %s\n", - force_detected ? "forced enable" : device_state_name(state)); + ccprintf("Rdd: %s\n", + force_detected ? "keepalive" : device_state_name(state)); } /** @@ -60,7 +60,7 @@ void print_rdd_state(void) */ static void rdd_disconnect(void) { - CPRINTS("Debug accessory disconnect"); + CPRINTS("Rdd disconnect"); state = DEVICE_STATE_DISCONNECTED; /* @@ -92,7 +92,7 @@ static void rdd_connect(void) return; /* We were previously disconnected, so connect */ - CPRINTS("Debug accessory connect"); + CPRINTS("Rdd connect"); state = DEVICE_STATE_CONNECTED; /* Start pulling CCD_MODE_L low to enable the SBUx muxes */ @@ -227,16 +227,27 @@ void init_rdd_state(void) GWRITE_FIELD(RDD, INT_ENABLE, INTR_DEBUG_STATE_DETECTED, 1); } -void force_rdd_detect(int enable) +static int command_rdd_keepalive(int argc, char **argv) { - force_detected = enable; + if (argc == 1) { + print_rdd_state(); + return EC_SUCCESS; + } - /* - * If we're forcing detection, trigger then connect handler early. - * - * Otherwise, we'll revert to the normal logic of checking the RDD - * hardware CC state. - */ - if (force_detected) + if (!parse_bool(argv[1], &force_detected)) + return EC_ERROR_PARAM1; + + if (force_detected) { + /* Force Rdd detect */ + ccprintf("Forcing Rdd detect keepalive\n"); hook_call_deferred(&rdd_connect_data, 0); + } else { + /* Go back to actual hardware state */ + ccprintf("Using actual Rdd state\n"); + } + + return EC_SUCCESS; } +DECLARE_CONSOLE_COMMAND(rddkeepalive, command_rdd_keepalive, + "[BOOLEAN]", + "Get Rdd state or force keepalive"); diff --git a/chip/g/rdd.h b/chip/g/rdd.h index 4e25fe4293..1fd4f89152 100644 --- a/chip/g/rdd.h +++ b/chip/g/rdd.h @@ -11,16 +11,6 @@ */ void init_rdd_state(void); -/** - * Enable/disable forcing debug accessory detection. - * - * When enabled, the RDD module will assert CCD_MODE_L even if the CC value - * does not indicate a debug accessory is present. - * - * @param enable Enable (1) or disable (0) keepalive. - */ -void force_rdd_detect(int enable); - /** * Print debug accessory detect state */