Skip to contentSkip to conversation

ALSA: add suspend/resume support for InterWave ISA cards

PATCH Superseded Cássio Gabriel 2 participants 5 messages Apr 7 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ALSA: add suspend/resume support for InterWave ISA cards

This 2-patch series wires up suspend and resume support for the InterWave ISA drivers and their PnP front-end around the shared GUS PM helpers.

The first patch adds a small TEA6330T helper so the InterWave STB variant can restore its cached external mixer state after resume.

The second patch adds ISA and PnP PM callbacks to snd-interwave and restores the remaining InterWave-specific state that the generic GUS resume path does not cover, including the GF1 board registers and the detected memory layout.

The resume path intentionally does not rerun probe-time DRAM/ROM detection. As with the shared GUS PM support, this does not guarantee preservation of sample RAM contents across suspend.

---
Cássio Gabriel (2):
ALSA: tea6330t: add mixer state restore helper
ALSA: interwave: add ISA and PnP suspend and resume callbacks

 include/sound/tea6330t.h  |   1 +
 sound/i2c/tea6330t.c      |  33 +++++++++
 sound/isa/gus/interwave.c | 178 +++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 185 insertions(+), 27 deletions(-)

---
base-commit: 4e5929ff6b2f373527fdfb0727a3dd7a31d83a9f
change-id: 20260406-alsa-interwave-pm-609259dbdf02

Best regards,

Signature · 1 line
Cássio Gabriel <[email protected]>
#1 lore raw

PATCH 1/2 ALSA: tea6330t: add mixer state restore helper

The InterWave STB variant uses a TEA6330T mixer on its private I2C bus. The mixer state is cached in software, but there is no helper to push that register image back to hardware after system resume.

Add a small restore helper that reapplies the cached TEA6330T register image to the device so board drivers can restore the external mixer state as part of their PM resume path.

---
 include/sound/tea6330t.h |  1 +
 sound/i2c/tea6330t.c     | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
include/sound/tea6330t.h +1 -0
index 1c77b78f6533..3a34033d2aa3 100644
@@ -12,5 +12,6 @@
 int snd_tea6330t_detect(struct snd_i2c_bus *bus, int equalizer);
 int snd_tea6330t_update_mixer(struct snd_card *card, struct snd_i2c_bus *bus,
 			      int equalizer, int fader);
+int snd_tea6330t_restore_mixer(struct snd_i2c_bus *bus);
 
 #endif /* __SOUND_TEA6330T_H */
sound/i2c/tea6330t.c +33 -0
index e8c50a036bea..3e413929d3ea 100644
@@ -358,3 +358,36 @@ int snd_tea6330t_update_mixer(struct snd_card *card,
 
 EXPORT_SYMBOL(snd_tea6330t_detect);
 EXPORT_SYMBOL(snd_tea6330t_update_mixer);
+
+int snd_tea6330t_restore_mixer(struct snd_i2c_bus *bus)
+{
+	struct snd_i2c_device *device;
+	struct tea6330t *tea;
+	unsigned char bytes[7];
+	unsigned int idx;
+	int err;
+
+	if (!bus)
+		return -EINVAL;
+
+	list_for_each_entry(device, &bus->devices, list) {
+		if (device->addr != TEA6330T_ADDR)
+			continue;
+
+		tea = device->private_data;
+		if (!tea)
+			return -EINVAL;
+
+		snd_i2c_lock(bus);
+		bytes[0] = TEA6330T_SADDR_VOLUME_LEFT;
+		for (idx = 0; idx < 6; idx++)
+			bytes[idx + 1] = tea->regs[idx];
+		err = snd_i2c_sendbytes(device, bytes, 7);
+		snd_i2c_unlock(bus);
+
+		return err < 0 ? err : 0;
+	}
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL(snd_tea6330t_restore_mixer);
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 1/2] ALSA: tea6330t: add mixer state restore helper

sound/i2c/tea6330t.c int snd_tea6330t_update_mixer(struct snd_card *card, · line 360

Quoted 8 lines · Cássio Gabriel
sound/i2c/tea6330t.c +0 -0
index e8c50a036bea..3e413929d3ea 100644
@@ -358,3 +358,36 @@ int snd_tea6330t_update_mixer(struct snd_card *card,
 
 EXPORT_SYMBOL(snd_tea6330t_detect);
 EXPORT_SYMBOL(snd_tea6330t_update_mixer);

Oh we need a cleanup to put EXPORT_SYMBOL() after each function. (It should be a different patch, though.)

Quoted 19 lines
sound/i2c/tea6330t.c +19 -0
+
+int snd_tea6330t_restore_mixer(struct snd_i2c_bus *bus)
+{
+	struct snd_i2c_device *device;
+	struct tea6330t *tea;
+	unsigned char bytes[7];
+	unsigned int idx;
+	int err;
+
+	if (!bus)
+		return -EINVAL;
+
+	list_for_each_entry(device, &bus->devices, list) {
+		if (device->addr != TEA6330T_ADDR)
+			continue;
+
+		tea = device->private_data;
+		if (!tea)
+			return -EINVAL;

sound/i2c/tea6330t.c int snd_tea6330t_update_mixer(struct snd_card *card, · line 389

Quoted 10 lines
sound/i2c/tea6330t.c +10 -0
+
+		snd_i2c_lock(bus);
+		bytes[0] = TEA6330T_SADDR_VOLUME_LEFT;
+		for (idx = 0; idx < 6; idx++)
+			bytes[idx + 1] = tea->regs[idx];
+		err = snd_i2c_sendbytes(device, bytes, 7);
+		snd_i2c_unlock(bus);
+
+		return err < 0 ? err : 0;
+	}

I think snd_i2c_lock() should cover the whole loop for the race at linked list traversal.

thanks,

Takashi

#3 lore raw

Re: [PATCH 1/2] ALSA: tea6330t: add mixer state restore helper

Quoted 8 lines · Takashi Iwai
Quoted 6 lines · Cássio Gabriel
sound/i2c/tea6330t.c +0 -0
index e8c50a036bea..3e413929d3ea 100644
@@ -358,3 +358,36 @@ int snd_tea6330t_update_mixer(struct snd_card *card,
 
Quoted 5 lines

sound/i2c/tea6330t.c int snd_tea6330t_update_mixer(struct snd_card *card, · line 360

Quoted 2 lines
sound/i2c/tea6330t.c +0 -0
 EXPORT_SYMBOL(snd_tea6330t_detect);
 EXPORT_SYMBOL(snd_tea6330t_update_mixer);

Oh we need a cleanup to put EXPORT_SYMBOL() after each function. (It should be a different patch, though.)

Right, I'll do it.

Quoted 24 lines
Quoted 24 lines
sound/i2c/tea6330t.c +24 -0
+
+int snd_tea6330t_restore_mixer(struct snd_i2c_bus *bus)
+{
+	struct snd_i2c_device *device;
+	struct tea6330t *tea;
+	unsigned char bytes[7];
+	unsigned int idx;
+	int err;
+
+	if (!bus)
+		return -EINVAL;
+
+	list_for_each_entry(device, &bus->devices, list) {
+		if (device->addr != TEA6330T_ADDR)
+			continue;
+
+		tea = device->private_data;
+		if (!tea)
+			return -EINVAL;
+
+		snd_i2c_lock(bus);
+		bytes[0] = TEA6330T_SADDR_VOLUME_LEFT;
+		for (idx = 0; idx < 6; idx++)
+			bytes[idx + 1] = tea->regs[idx];
Quoted 8 lines

sound/i2c/tea6330t.c int snd_tea6330t_update_mixer(struct snd_card *card, · line 389

Quoted 5 lines
sound/i2c/tea6330t.c +5 -0
+		err = snd_i2c_sendbytes(device, bytes, 7);
+		snd_i2c_unlock(bus);
+
+		return err < 0 ? err : 0;
+	}

I think snd_i2c_lock() should cover the whole loop for the race at linked list traversal.

I'll fix in v2.

Quoted 3 lines

thanks,

Takashi

Signature · 2 lines
Thanks,
Cássio
#4 lore raw

PATCH 2/2 ALSA: interwave: add ISA and PnP suspend and resume callbacks

In reply to Cássio Gabriel

interwave still leaves both its ISA and PnP PM callbacks disabled even though the shared GUS suspend and resume path now exists.

This board needs InterWave-specific glue around the shared GUS PM path. The attached WSS codec has its own register image that must be saved and restored across suspend, the InterWave-specific GF1 compatibility, decode, MPU401, and emulation settings must be rewritten after the shared GF1 resume path reinitializes the chip, and the probe-detected InterWave memory layout must be restored without rerunning the destructive DRAM/ROM detection path.

Track the optional STB TEA6330T bus at probe time, restore its cached mixer state after resume, add resume-safe helpers for the InterWave register and memory-configuration state, and wire both the ISA and PnP front-ends up to the shared GUS PM helpers.

The resume path intentionally restores only the cached hardware setup. It does not attempt to preserve sample RAM contents across suspend.

---
 sound/isa/gus/interwave.c | 178 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 151 insertions(+), 27 deletions(-)
sound/isa/gus/interwave.c +151 -27
index 18adcd35e117..616c11e51a2f 100644
@@ -96,6 +96,7 @@ struct snd_interwave {
 	struct snd_gus_card *gus;
 	struct snd_wss *wss;
 #ifdef SNDRV_STB
+	struct snd_i2c_bus *i2c_bus;
 	struct resource *i2c_res;
 #endif
 	unsigned short gus_status_reg;
@@ -363,18 +364,30 @@ struct rom_hdr {
 	/* 511 */ unsigned char csum;
 };
 
-static void snd_interwave_detect_memory(struct snd_gus_card *gus)
+static const unsigned int snd_interwave_memory_configs[] = {
+	0x00000001, 0x00000101, 0x01010101, 0x00000401,
+	0x04040401, 0x00040101, 0x04040101, 0x00000004,
+	0x00000404, 0x04040404, 0x00000010, 0x00001010,
+	0x10101010
+};
+
+static int snd_interwave_find_memory_config(unsigned int lmct)
 {
-	static const unsigned int lmc[13] =
-	{
-		0x00000001, 0x00000101, 0x01010101, 0x00000401,
-		0x04040401, 0x00040101, 0x04040101, 0x00000004,
-		0x00000404, 0x04040404, 0x00000010, 0x00001010,
-		0x10101010
-	};
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(snd_interwave_memory_configs); i++) {
+		if (lmct == snd_interwave_memory_configs[i])
+			return i;
+	}
+
+	return -EINVAL;
+}
 
+static void snd_interwave_detect_memory(struct snd_gus_card *gus)
+{
 	int bank_pos, pages;
 	unsigned int i, lmct;
+	int lmc_cfg;
 	int psizes[4];
 	unsigned char iwave[8];
 	unsigned char csum;
@@ -399,17 +412,20 @@ static void snd_interwave_detect_memory(struct snd_gus_card *gus)
 #if 0
 		dev_dbg(gus->card->dev, "lmct = 0x%08x\n", lmct);
 #endif
-		for (i = 0; i < ARRAY_SIZE(lmc); i++)
-			if (lmct == lmc[i]) {
+		lmc_cfg = snd_interwave_find_memory_config(lmct);
+		if (lmc_cfg >= 0) {
 #if 0
-				dev_dbg(gus->card->dev, "found !!! %i\n", i);
+			dev_dbg(gus->card->dev, "found !!! %i\n", lmc_cfg);
 #endif
-				snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i);
-				snd_interwave_bank_sizes(gus, psizes);
-				break;
-			}
-		if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode)
-			 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2);
+			snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG,
+					(snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) |
+					lmc_cfg);
+			snd_interwave_bank_sizes(gus, psizes);
+		} else if (!gus->gf1.enh_mode) {
+			snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG,
+					(snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) |
+					2);
+		}
 		for (i = 0; i < 4; i++) {
 			gus->gf1.mem_alloc.banks_8[i].address =
 			    gus->gf1.mem_alloc.banks_16[i].address = i << 22;
@@ -454,24 +470,66 @@ static void snd_interwave_detect_memory(struct snd_gus_card *gus)
 		snd_interwave_reset(gus);
 }
 
+static void __snd_interwave_restore_regs(struct snd_gus_card *gus)
+{
+	snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f);
+	snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49);
+	snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11);
+	snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00);
+	snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30);
+	snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00);
+}
+
+static void snd_interwave_restore_regs(struct snd_gus_card *gus)
+{
+	scoped_guard(spinlock_irqsave, &gus->reg_lock)
+		__snd_interwave_restore_regs(gus);
+}
+
+static void snd_interwave_restore_memory(struct snd_gus_card *gus)
+{
+	unsigned short mem_cfg;
+	unsigned int lmct = 0;
+	int i, lmc_cfg;
+
+	if (!gus->gf1.memory)
+		return;
+
+	for (i = 0; i < 4; i++)
+		lmct |= (gus->gf1.mem_alloc.banks_16[i].size >> 18) << (i * 8);
+
+	lmc_cfg = snd_interwave_find_memory_config(lmct);
+	if (lmc_cfg < 0) {
+		if (!gus->gf1.enh_mode) {
+			lmc_cfg = 2;
+		} else {
+			dev_warn(gus->card->dev,
+				 "cannot restore InterWave memory layout 0x%08x\n",
+				 lmct);
+			return;
+		}
+	}
+
+	scoped_guard(spinlock_irqsave, &gus->reg_lock) {
+		mem_cfg = snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG);
+		mem_cfg = (mem_cfg & 0xfff0) | lmc_cfg;
+		mem_cfg = (mem_cfg & 0xff1f) | (4 << 5);
+		snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, mem_cfg);
+	}
+}
+
 static void snd_interwave_init(int dev, struct snd_gus_card *gus)
 {
-	/* ok.. some InterWave specific initialization */
+	/* Probe-time setup also clears the timer control register. */
 	scoped_guard(spinlock_irqsave, &gus->reg_lock) {
 		snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00);
-		snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f);
-		snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49);
-		snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11);
-		snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00);
-		snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30);
-		snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00);
+		__snd_interwave_restore_regs(gus);
 	}
 	gus->equal_irq = 1;
 	gus->codec_flag = 1;
 	gus->interwave = 1;
 	gus->max_flag = 1;
 	gus->joystick_dac = joystick_dac[dev];
-
 }
 
 static const struct snd_kcontrol_new snd_interwave_controls[] = {
@@ -724,6 +782,7 @@ static int snd_interwave_probe(struct snd_card *card, int dev,
 		err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1);
 		if (err < 0)
 			return err;
+		iwcard->i2c_bus = i2c_bus;
 	}
 #endif
 
@@ -828,10 +887,59 @@ static int snd_interwave_isa_probe(struct device *pdev,
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int snd_interwave_card_suspend(struct snd_card *card)
+{
+	struct snd_interwave *iwcard = card->private_data;
+
+	iwcard->wss->suspend(iwcard->wss);
+	return snd_gus_suspend(iwcard->gus);
+}
+
+static int snd_interwave_card_resume(struct snd_card *card)
+{
+	struct snd_interwave *iwcard = card->private_data;
+	int err;
+
+	err = snd_gus_resume(iwcard->gus);
+	if (err < 0)
+		return err;
+
+	snd_interwave_restore_regs(iwcard->gus);
+	snd_interwave_restore_memory(iwcard->gus);
+	iwcard->wss->resume(iwcard->wss);
+#ifdef SNDRV_STB
+	if (iwcard->i2c_bus) {
+		err = snd_tea6330t_restore_mixer(iwcard->i2c_bus);
+		if (err < 0)
+			dev_warn(card->dev,
+				 "failed to restore TEA6330T mixer state: %d\n",
+				 err);
+	}
+#endif
+
+	return 0;
+}
+
+static int snd_interwave_isa_suspend(struct device *pdev, unsigned int dev,
+				     pm_message_t state)
+{
+	return snd_interwave_card_suspend(dev_get_drvdata(pdev));
+}
+
+static int snd_interwave_isa_resume(struct device *pdev, unsigned int dev)
+{
+	return snd_interwave_card_resume(dev_get_drvdata(pdev));
+}
+#endif
+
 static struct isa_driver snd_interwave_driver = {
 	.match		= snd_interwave_isa_match,
 	.probe		= snd_interwave_isa_probe,
-	/* FIXME: suspend,resume */
+#ifdef CONFIG_PM
+	.suspend	= snd_interwave_isa_suspend,
+	.resume		= snd_interwave_isa_resume,
+#endif
 	.driver		= {
 		.name	= INTERWAVE_DRIVER
 	},
@@ -871,12 +979,28 @@ static int snd_interwave_pnp_detect(struct pnp_card_link *pcard,
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int snd_interwave_pnpc_suspend(struct pnp_card_link *pcard,
+				      pm_message_t state)
+{
+	return snd_interwave_card_suspend(pnp_get_card_drvdata(pcard));
+}
+
+static int snd_interwave_pnpc_resume(struct pnp_card_link *pcard)
+{
+	return snd_interwave_card_resume(pnp_get_card_drvdata(pcard));
+}
+#endif
+
 static struct pnp_card_driver interwave_pnpc_driver = {
 	.flags = PNP_DRIVER_RES_DISABLE,
 	.name = INTERWAVE_PNP_DRIVER,
 	.id_table = snd_interwave_pnpids,
 	.probe = snd_interwave_pnp_detect,
-	/* FIXME: suspend,resume */
+#ifdef CONFIG_PM
+	.suspend	= snd_interwave_pnpc_suspend,
+	.resume		= snd_interwave_pnpc_resume,
+#endif
 };
 
 #endif /* CONFIG_PNP */
Signature · 1 line
2.53.0