+ return check_sync(dap);
+}
+
+/** Executes all queued DAP operations. */
+static int swd_run(struct adiv5_dap *dap)
+{
+ int retval = swd_multidrop_select(dap);
+ if (retval != ERROR_OK)
+ return retval;
+
+ swd_finish_read(dap);
+
+ retval = swd_run_inner(dap);
+ if (retval != ERROR_OK) {
+ /* fault response */
+ dap->do_reconnect = true;
+ }
+
+ return retval;
+}
+
+/** Put the SWJ-DP back to JTAG mode */
+static void swd_quit(struct adiv5_dap *dap)
+{
+ const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
+ static bool done;
+
+ /* There is no difference if the sequence is sent at the last
+ * or the first swd_quit() call, send it just once */
+ if (done)
+ return;
+
+ done = true;
+ if (dap_is_multidrop(dap)) {
+ /* Emit the switch seq to dormant state regardless the state mirrored
+ * in swd_multidrop_in_swd_state. Doing so ensures robust operation
+ * in the case the variable is out of sync.
+ * Sending SWD_TO_DORMANT makes no change if the DP is already dormant. */
+ swd->switch_seq(SWD_TO_DORMANT);
+ swd_multidrop_in_swd_state = false;
+ /* Revisit!
+ * Leaving DPs in dormant state was tested and offers some safety
+ * against DPs mismatch in case of unintentional use of non-multidrop SWD.
+ * To put SWJ-DPs to power-on state issue
+ * swd->switch_seq(DORMANT_TO_JTAG);
+ */
+ } else {
+ if (dap->switch_through_dormant) {
+ swd->switch_seq(SWD_TO_DORMANT);
+ swd->switch_seq(DORMANT_TO_JTAG);
+ } else {
+ swd->switch_seq(SWD_TO_JTAG);
+ }