summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2016-07-29 19:33:20 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-08-05 02:00:43 -0700
commit2ea846e44ba9022584e6c6e88dab7961e77685d0 (patch)
tree51fbffe7485fe6edd971ad8c8bf246e620938364
parent661bc6e5c1a43fca3f746871cacba5bf182190fb (diff)
downloadchrome-ec-2ea846e44ba9022584e6c6e88dab7961e77685d0.tar.gz
g: fix rdd
This change fixes two issues. The first issue is that during rdd_init debug_detect is set to the value of DEBUG_STATE_MAP. Debug_detect should be the default map value of 0x420 which triggers an rdd interrupt when cc1 and cc2 both have a value of 011 or 001. This will detect when a debug cable is attached. ~debug_detect should detect when the cable is detached. The issue is after a soft reset DEBUG_STATE_MAP is not reset to the default value so on the next rdd_init debug_detect was set to whatever was DEBUG_STATE_MAP was last set to. If the debug cable is detected before the soft reset then DEBUG_STATE_MAP will have a value of ~debug_detect and when rdd_init is called then debug_detect will be initialized to that value of ~0x420. Now debug_detect does the opposite of what we expect it to do. debug_detect detects when the cable is detached and ~debug_detect detects when it is attached. rdd_interrupt is called cr50 reads cc1 and cc2 and sees that a debug accessory is attached so it sets DEBUG_STATE_MAP to ~debug_detect. Because debug_detect does the opposite of what is expected then it will trigger an interrupt when it detects a debug accessory. The debug accessory is already attached so an interrupt is triggered. It reads cc1 and cc2 sees the debug_accessory attached resets the map to ~debug_detect. This cycle continues until the watchdog resets the system. After this reset rdd_init reads the map to get debug_detect and it is 0x420 because that is how it was last set and then rdd works again. This change fixes this issue by defining DEBUG_DETECT to be 0x420 and not using the STATE_MAP value to do it. It also looks like when the EC is off and we change the value of the debug map, another RDD interrupt is triggered. Then it reads the debug state and resets the map again another interrupt is triggered. It continuously does this. This change adds a check to see that the RDD was trying to detect the state it currently senses before doing anything so the second interrupt will be ignored. BUG=chrome-os-partner:55793 BRANCH=none TEST=manual plug in a reworked suzyq Flash the EC verify a bunch of RDD interrupts aren't triggered and the reworked suzyq can be used. plug it in and out a couple of times to make sure everything works. Change-Id: I6f4e7b15cf9c53b965533df7fe23fae5b340f70d Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/364724 Commit-Ready: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r--chip/g/rdd.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/chip/g/rdd.c b/chip/g/rdd.c
index 37f8ec5d1c..eedf27d9db 100644
--- a/chip/g/rdd.c
+++ b/chip/g/rdd.c
@@ -14,7 +14,13 @@
#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
-static uint16_t debug_detect;
+/*
+ * The default PROG_DEBUG_STATE_MAP value. Used to tell the to controller send
+ * an interrupt when CC1/2 are detected to be in the defined voltage range of a
+ * debug accessory.
+ */
+#define DETECT_DEBUG 0x420
+#define DETECT_DISCONNECT (~DETECT_DEBUG & 0xffff)
int debug_cable_is_attached(void)
{
@@ -26,17 +32,28 @@ int debug_cable_is_attached(void)
void rdd_interrupt(void)
{
- if (debug_cable_is_attached()) {
+ int is_debug, current_map;
+
+ disable_sleep(SLEEP_MASK_RDD);
+
+ current_map = 0xffff & GREAD(RDD, PROG_DEBUG_STATE_MAP);
+ is_debug = debug_cable_is_attached();
+
+ if (is_debug && (current_map == DETECT_DEBUG)) {
CPRINTS("Debug Accessory connected");
- disable_sleep(SLEEP_MASK_RDD);
+
/* Detect when debug cable is disconnected */
- GWRITE(RDD, PROG_DEBUG_STATE_MAP, ~debug_detect);
+ GWRITE(RDD, PROG_DEBUG_STATE_MAP, DETECT_DISCONNECT);
+
rdd_attached();
- } else {
+ } else if (!is_debug && (current_map == DETECT_DISCONNECT)) {
CPRINTS("Debug Accessory disconnected");
+
/* Detect when debug cable is connected */
- GWRITE(RDD, PROG_DEBUG_STATE_MAP, debug_detect);
+ GWRITE(RDD, PROG_DEBUG_STATE_MAP, DETECT_DEBUG);
+
rdd_detached();
+
cflush();
enable_sleep(SLEEP_MASK_RDD);
}
@@ -52,7 +69,7 @@ void rdd_init(void)
clock_enable_module(MODULE_RDD, 1);
GWRITE(RDD, POWER_DOWN_B, 1);
- debug_detect = GREAD(RDD, PROG_DEBUG_STATE_MAP);
+ GWRITE(RDD, PROG_DEBUG_STATE_MAP, DETECT_DEBUG);
/* Initialize the debug state based on the current cc values */
rdd_interrupt();