fw/e1-tracer: e1_start/e1_stop of individual channel

Let's split the starting and stopping between the two channels.

This is a preparation for a future e1d-compatible mode where each
channel (direction) has its own USB interface and hence must be
individually started/stopped.

Related: OS#5733
Change-Id: I7492325352222269bf0ba1346511c7dfa99c4f64
diff --git a/firmware/ice40-riscv/e1-tracer/e1.c b/firmware/ice40-riscv/e1-tracer/e1.c
index dc2ae11..e3ae1ef 100644
--- a/firmware/ice40-riscv/e1-tracer/e1.c
+++ b/firmware/ice40-riscv/e1-tracer/e1.c
@@ -2,6 +2,7 @@
  * e1.c
  *
  * Copyright (C) 2019-2020  Sylvain Munaut <tnt@246tNt.com>
+ * Copyright (C) 2022  Harald Welte <laforge@osmocom.org>
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
@@ -276,53 +277,36 @@
 }
 
 void
-e1_start(void)
+e1_start(int chan)
 {
 	/* Reset FIFOs */
 #ifdef BIGBUF
-	e1f_reset(&g_e1.rx[0].fifo,    0, 1024);
-	e1f_reset(&g_e1.rx[1].fifo, 1024, 1024);
+	e1f_reset(&g_e1.rx[chan].fifo,    0, 1024);
 #else
-	e1f_reset(&g_e1.rx[0].fifo,   0, 128);
-	e1f_reset(&g_e1.rx[1].fifo, 128, 128);
+	e1f_reset(&g_e1.rx[chan].fifo,   0, 128);
 #endif
 
-	/* Enable Rx0 */
-	g_e1.rx[0].cr = E1_RX_CR_OVFL_CLR |
+	/* Enable Rx */
+	g_e1.rx[chan].cr = E1_RX_CR_OVFL_CLR |
 	                E1_RX_CR_MODE_MFA |
 	                E1_RX_CR_ENABLE;
-	e1_regs->rx[0].csr = g_e1.rx[0].cr;
-
-	/* Enable Rx1 */
-	g_e1.rx[1].cr = E1_RX_CR_OVFL_CLR |
-	                E1_RX_CR_MODE_MFA |
-	                E1_RX_CR_ENABLE;
-	e1_regs->rx[1].csr = g_e1.rx[1].cr;
+	e1_regs->rx[chan].csr = g_e1.rx[chan].cr;
 
 	/* State */
-	g_e1.rx[0].state = BOOT;
-	g_e1.rx[0].in_flight = 0;
-	g_e1.rx[0].flags = 0;
-
-	g_e1.rx[1].state = BOOT;
-	g_e1.rx[1].in_flight = 0;
-	g_e1.rx[1].flags = 0;
+	g_e1.rx[chan].state = BOOT;
+	g_e1.rx[chan].in_flight = 0;
+	g_e1.rx[chan].flags = 0;
 }
 
 void
-e1_stop()
+e1_stop(int chan)
 {
-	/* Disable RX0 */
-	g_e1.rx[0].cr = 0;
-	e1_regs->rx[0].csr = g_e1.rx[0].cr;
-
-	/* Disable RX1 */
-	g_e1.rx[1].cr = 0;
-	e1_regs->rx[1].csr = g_e1.rx[1].cr;
+	/* Disable RX */
+	g_e1.rx[chan].cr = 0;
+	e1_regs->rx[chan].csr = g_e1.rx[0].cr;
 
 	/* State */
-	g_e1.rx[0].state = IDLE;
-	g_e1.rx[1].state = IDLE;
+	g_e1.rx[chan].state = IDLE;
 }
 
 
diff --git a/firmware/ice40-riscv/e1-tracer/e1.h b/firmware/ice40-riscv/e1-tracer/e1.h
index b99c682..a310ffd 100644
--- a/firmware/ice40-riscv/e1-tracer/e1.h
+++ b/firmware/ice40-riscv/e1-tracer/e1.h
@@ -8,8 +8,8 @@
 #pragma once
 
 void e1_init();
-void e1_start();
-void e1_stop();
+void e1_start(int chan);
+void e1_stop(int chan);
 
 void e1_poll(void);
 
diff --git a/firmware/ice40-riscv/e1-tracer/usb_e1.c b/firmware/ice40-riscv/e1-tracer/usb_e1.c
index 3c577a4..80522e2 100644
--- a/firmware/ice40-riscv/e1-tracer/usb_e1.c
+++ b/firmware/ice40-riscv/e1-tracer/usb_e1.c
@@ -149,7 +149,8 @@
 		g_usb_e1.running = false;
 
 		/* Stop E1 */
-		e1_stop();
+		e1_stop(0);
+		e1_stop(1);
 
 		/* Disable end-points */
 		usb_ep_regs[1].in.status = 0;
@@ -187,7 +188,8 @@
 		usb_ep_regs[2].in.bd[1].csr = 0;
 
 		/* Start E1 */
-		e1_start();
+		e1_start(0);
+		e1_start(1);
 	}
 	else
 	{