Skip to contentSkip to conversation

ALSA: emu10k1: more improvements related to uploading firmware to the E-MU dock

PATCH In review Oswald Buddenhagen 2 participants 6 messages Apr 28, 2024 Sound

lore
Share & tools
lore
#0 lore raw

v2 cover ALSA: emu10k1: more improvements related to uploading firmware to the E-MU dock

---
v2:
- split off from more critical part of the series
- re-ordered two commits to reduce diff churn
---
This patch series needs to be applied on top of the patch titled "ALSA:
emu10k1: make E-MU FPGA writes potentially more reliable".

Oswald Buddenhagen (4):
ALSA: emu10k1: simplify E-MU card FPGA reset sequence
ALSA: emu10k1: make snd_emu1010_load_firmware_entry() void
ALSA: emu10k1: move snd_emu1010_load_firmware_entry() to io.c
ALSA: emu10k1: move code for entering E-MU card FPGA programming mode

 include/sound/emu10k1.h          |  1 +
 sound/pci/emu10k1/emu10k1_main.c | 75 ++------------------------------
 sound/pci/emu10k1/io.c           | 53 ++++++++++++++++++++++
 3 files changed, 57 insertions(+), 72 deletions(-)

base-commit: ed93395844979f6bf2e1fbfcda38d1718289b426
prerequisite-patch-id: 5a07270251912fd31f913bda4de46fd8321d7960
prerequisite-patch-id: 573260da563ac3c9ba18383044a52f2cb00c1096
prerequisite-patch-id: 6268ce55ab58f0cffb3a3a19cac962780731affe
prerequisite-patch-id: a7ede4bf7174c7b93861dc58125fbf7debabebd8
prerequisite-patch-id: 8572ac7b03d12a9d8ad49ffe7a599e5ad89cd267
prerequisite-patch-id: 6f08dff99ebc501ac93d7e1c28f707ade2384b12

Signature · 1 line
2.44.0.701.g2cf7baacf3.dirty
#1 lore raw

PATCH v2 1/4 ALSA: emu10k1: simplify E-MU card FPGA reset sequence

Firstly, it is pointless to explicitly disable the power to the dock prior to resetting the FPGA, as the latter will do the former anyway.

Secondly, it doesn't make much sense to check whether the FPGA is already programmed. It's much simpler to just presume it is, and issue the self-reset command. If it isn't, the effect isn't worse than the checks themselves. As a side effect, we lose the info if the reset fails, but there is no plausible way how that could happen unless the card burns out while operating, and in that case we'll detect a firmware upload failure a bit later anyway.

---
 sound/pci/emu10k1/emu10k1_main.c | 25 +++----------------------
 1 file changed, 3 insertions(+), 22 deletions(-)
sound/pci/emu10k1/emu10k1_main.c +3 -22
index 8ccc0178360c..353dd3b61c61 100644
@@ -864,28 +864,9 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
 
 	snd_emu1010_fpga_lock(emu);
 
-	/* Disable 48Volt power to Audio Dock */
-	snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0);
-
-	/* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */
-	snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
-	dev_dbg(emu->card->dev, "reg1 = 0x%x\n", reg);
-	if ((reg & 0x3f) == 0x15) {
-		/* FPGA netlist already present so clear it */
-		/* Return to programming mode */
-
-		snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_HANA);
-	}
-	snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
-	dev_dbg(emu->card->dev, "reg2 = 0x%x\n", reg);
-	if ((reg & 0x3f) == 0x15) {
-		/* FPGA failed to return to programming mode */
-		dev_info(emu->card->dev,
-			 "emu1010: FPGA failed to return to programming mode\n");
-		return -ENODEV;
-	}
-	dev_info(emu->card->dev, "emu1010: EMU_HANA_ID = 0x%x\n", reg);
-
+	dev_info(emu->card->dev, "emu1010: Loading Hana Firmware\n");
+	snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG,
+			       EMU_HANA_FPGA_CONFIG_HANA);
 	err = snd_emu1010_load_firmware(emu, 0, &emu->firmware);
 	if (err < 0) {
 		dev_info(emu->card->dev, "emu1010: Loading Firmware failed\n");
Signature · 1 line
2.44.0.701.g2cf7baacf3.dirty
#2 lore raw

PATCH v2 2/4 ALSA: emu10k1: make snd_emu1010_load_firmware_entry() void

In reply to Oswald Buddenhagen

There is only one call site, and there we already know that we actually have a firmware.

---
 sound/pci/emu10k1/emu10k1_main.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
sound/pci/emu10k1/emu10k1_main.c +3 -7
index 353dd3b61c61..ec010971a220 100644
@@ -652,17 +652,14 @@ static int snd_emu10k1_cardbus_init(struct snd_emu10k1 *emu)
 	return 0;
 }
 
-static int snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu,
+static void snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu,
 				     const struct firmware *fw_entry)
 {
 	int n, i;
 	u16 reg;
 	u8 value;
 	__always_unused u16 write_post;
 
-	if (!fw_entry)
-		return -EIO;
-
 	/* The FPGA is a Xilinx Spartan IIE XC2S50E */
 	/* On E-MU 0404b it is a Xilinx Spartan III XC3S50 */
 	/* GPIO7 -> FPGA PGMN
@@ -694,8 +691,6 @@ static int snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu,
 	outw(0x10, emu->port + A_GPIO);
 	write_post = inw(emu->port + A_GPIO);
 	spin_unlock_irq(&emu->emu_lock);
-
-	return 0;
 }
 
 /* firmware file names, per model, init-fw and dock-fw (optional) */
@@ -729,7 +724,8 @@ static int snd_emu1010_load_firmware(struct snd_emu10k1 *emu, int dock,
 			return err;
 	}
 
-	return snd_emu1010_load_firmware_entry(emu, *fw);
+	snd_emu1010_load_firmware_entry(emu, *fw);
+	return 0;
 }
 
 static void snd_emu1010_load_dock_firmware(struct snd_emu10k1 *emu)
Signature · 1 line
2.44.0.701.g2cf7baacf3.dirty
#3 lore raw

PATCH v2 3/4 ALSA: emu10k1: move snd_emu1010_load_firmware_entry() to io.c

In reply to Oswald Buddenhagen

It is a low-level I/O access function, so io.c is the natural place for it.

While we're moving the code, reduce the scope of some variables, use compound assignment operators, and add/adjust some comments.

---
 include/sound/emu10k1.h          |  1 +
 sound/pci/emu10k1/emu10k1_main.c | 41 ---------------------------
 sound/pci/emu10k1/io.c           | 48 ++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 41 deletions(-)
include/sound/emu10k1.h +1 -0
index 234b5baea69c..2856f4717c93 100644
@@ -1843,6 +1843,7 @@ void snd_emu1010_fpga_link_dst_src_write(struct snd_emu10k1 *emu, u32 dst, u32 s
 u32 snd_emu1010_fpga_link_dst_src_read(struct snd_emu10k1 *emu, u32 dst);
 int snd_emu1010_get_raw_rate(struct snd_emu10k1 *emu, u8 src);
 void snd_emu1010_update_clock(struct snd_emu10k1 *emu);
+void snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu, const struct firmware *fw_entry);
 unsigned int snd_emu10k1_efx_read(struct snd_emu10k1 *emu, unsigned int pc);
 void snd_emu10k1_intr_enable(struct snd_emu10k1 *emu, unsigned int intrenb);
 void snd_emu10k1_intr_disable(struct snd_emu10k1 *emu, unsigned int intrenb);
sound/pci/emu10k1/emu10k1_main.c +0 -41

47 lines not on this page · raw message

sound/pci/emu10k1/io.c +48 -0

54 lines not on this page · raw message

Signature · 1 line
2.44.0.701.g2cf7baacf3.dirty
#4 lore raw

PATCH v2 4/4 ALSA: emu10k1: move code for entering E-MU card FPGA programming mode

In reply to Oswald Buddenhagen

... into snd_emu1010_load_firmware_entry(). This makes it clearer that these steps belong together tightly, as implied by prior commits.

---
 include/sound/emu10k1.h          | 2 +-
 sound/pci/emu10k1/emu10k1_main.c | 7 +------
 sound/pci/emu10k1/io.c           | 7 ++++++-
 3 files changed, 8 insertions(+), 8 deletions(-)
include/sound/emu10k1.h +1 -1
index 2856f4717c93..b83862259eec 100644
@@ -1843,7 +1843,7 @@ void snd_emu1010_fpga_link_dst_src_write(struct snd_emu10k1 *emu, u32 dst, u32 s
 u32 snd_emu1010_fpga_link_dst_src_read(struct snd_emu10k1 *emu, u32 dst);
 int snd_emu1010_get_raw_rate(struct snd_emu10k1 *emu, u8 src);
 void snd_emu1010_update_clock(struct snd_emu10k1 *emu);
-void snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu, const struct firmware *fw_entry);
+void snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu, int dock, const struct firmware *fw_entry);
 unsigned int snd_emu10k1_efx_read(struct snd_emu10k1 *emu, unsigned int pc);
 void snd_emu10k1_intr_enable(struct snd_emu10k1 *emu, unsigned int intrenb);
 void snd_emu10k1_intr_disable(struct snd_emu10k1 *emu, unsigned int intrenb);
sound/pci/emu10k1/emu10k1_main.c +1 -6
index c8aa4143ac4f..5b8a5ba825bd 100644
@@ -683,7 +683,7 @@ static int snd_emu1010_load_firmware(struct snd_emu10k1 *emu, int dock,
 			return err;
 	}
 
-	snd_emu1010_load_firmware_entry(emu, *fw);
+	snd_emu1010_load_firmware_entry(emu, dock, *fw);
 	return 0;
 }
 
@@ -699,9 +699,6 @@ static void snd_emu1010_load_dock_firmware(struct snd_emu10k1 *emu)
 	msleep(200);
 
 	dev_info(emu->card->dev, "emu1010: Loading Audio Dock Firmware\n");
-	/* Return to Audio Dock programming mode */
-	snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG,
-			       EMU_HANA_FPGA_CONFIG_AUDIODOCK);
 	err = snd_emu1010_load_firmware(emu, 1, &emu->dock_fw);
 	if (err < 0)
 		return;
@@ -820,8 +817,6 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
 	snd_emu1010_fpga_lock(emu);
 
 	dev_info(emu->card->dev, "emu1010: Loading Hana Firmware\n");
-	snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG,
-			       EMU_HANA_FPGA_CONFIG_HANA);
 	err = snd_emu1010_load_firmware(emu, 0, &emu->firmware);
 	if (err < 0) {
 		dev_info(emu->card->dev, "emu1010: Loading Firmware failed\n");
sound/pci/emu10k1/io.c +6 -1
index fafa299efa5c..b60ab5671e00 100644
@@ -422,7 +422,7 @@ void snd_emu1010_update_clock(struct snd_emu10k1 *emu)
 	snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, leds);
 }
 
-void snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu,
+void snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu, int dock,
 				     const struct firmware *fw_entry)
 {
 	__always_unused u16 write_post;
@@ -440,6 +440,11 @@ void snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu,
 	// GPO6 -> FPGA CCLK & FPGA input
 	// GPO5 -> FPGA DIN (dual function)
 
+	// If the FPGA is already programmed, return it to programming mode
+	snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG,
+			       dock ? EMU_HANA_FPGA_CONFIG_AUDIODOCK :
+				      EMU_HANA_FPGA_CONFIG_HANA);
+
 	// Assert reset line for 100uS
 	outw(0x00, emu->port + A_GPIO);
 	write_post = inw(emu->port + A_GPIO);
Signature · 1 line
2.44.0.701.g2cf7baacf3.dirty
#5 lore raw
In reply to Oswald Buddenhagen
Quoted 8 lines · Oswald Buddenhagen

---
v2:
- split off from more critical part of the series
- re-ordered two commits to reduce diff churn
---
This patch series needs to be applied on top of the patch titled "ALSA:
emu10k1: make E-MU FPGA writes potentially more reliable".

Applied to for-next branch (on top of the previous set).

Takashi