Skip to contentSkip to conversation

ALSA: msnd: add suspend/resume support

PATCH Applied Cássio Gabriel 2 participants 4 messages Apr 9 Sound

lore
Share & tools
lore
#0 lore raw

cover ALSA: msnd: add suspend/resume support

The msnd drivers still have no system-sleep callbacks, and the shared driver file still carries a FIXME for suspend/resume. Probe already depends on rebuilding volatile device state by resetting the DSP, uploading firmware, reinitializing shared memory, restoring mixer settings, and calibrating the ADC. Without matching PM callbacks, the driver has no defined way to recover that state after suspend.

This small series adds the missing suspend/resume support with the minimum scope needed for the current driver.

Patch 1 prepares the driver for PM by:
- accepting SNDRV_PCM_TRIGGER_SUSPEND in the PCM trigger callbacks
- factoring the IRQ enable/disable bodies and adding a helper that can quiesce or rearm the shared IRQ without disturbing irq_ref
- restoring cached master-volume values when mixer state is rebuilt after DSP reinitialization

Patch 2 adds the actual PM callbacks by:
- saving the current capture-source selection and msnd-side MIDI input state
- adding shared card suspend/resume helpers
- wiring those helpers into the ISA driver and the Pinnacle PnP card driver with the current callback signatures

The series intentionally does not add trigger-level PCM resume support. The driver can rebuild hardware state on system resume, but it does not preserve enough runtime queue state to justify advertising full SNDRV_PCM_INFO_RESUME semantics in this change.

---
Cássio Gabriel (2):
ALSA: msnd: prepare system sleep support
ALSA: msnd: add ISA and PnP system sleep callbacks

 sound/isa/msnd/msnd.c                | 72 ++++++++++++++++++---------
 sound/isa/msnd/msnd.h                |  3 ++
 sound/isa/msnd/msnd_pinnacle.c       | 95 +++++++++++++++++++++++++++++++++++-
 sound/isa/msnd/msnd_pinnacle_mixer.c |  4 ++
 4 files changed, 149 insertions(+), 25 deletions(-)

---
base-commit: 9f2a23bd5d30dc0968e56a2b6e5edb58aff1bc6d
change-id: 20260403-msnd-pm-support-e14d428ca426

Best regards,

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

PATCH 1/2 ALSA: msnd: prepare system sleep support

System suspend cannot work for msnd today because the PCM trigger paths reject SNDRV_PCM_TRIGGER_SUSPEND, and the driver has only refcounted IRQ helpers.

Add the small helpers needed by the PM callbacks and restore master volume from the cached ALSA mixer state when the DSP is reinitialized.

---
 sound/isa/msnd/msnd.c                | 72 ++++++++++++++++++++++++------------
 sound/isa/msnd/msnd.h                |  1 +
 sound/isa/msnd/msnd_pinnacle_mixer.c |  4 ++
 3 files changed, 54 insertions(+), 23 deletions(-)
sound/isa/msnd/msnd.c +49 -23
index 5e350234d572..77367e102fda 100644
@@ -127,11 +127,8 @@ int snd_msnd_upload_host(struct snd_msnd *dev, const u8 *bin, int len)
 }
 EXPORT_SYMBOL(snd_msnd_upload_host);
 
-int snd_msnd_enable_irq(struct snd_msnd *dev)
+static int __snd_msnd_enable_irq(struct snd_msnd *dev)
 {
-	if (dev->irq_ref++)
-		return 0;
-
 	dev_dbg(dev->card->dev, LOGNAME ": Enabling IRQ\n");
 
 	guard(spinlock_irqsave)(&dev->lock);
@@ -152,17 +149,9 @@ int snd_msnd_enable_irq(struct snd_msnd *dev)
 
 	return -EIO;
 }
-EXPORT_SYMBOL(snd_msnd_enable_irq);
 
-int snd_msnd_disable_irq(struct snd_msnd *dev)
+static int __snd_msnd_disable_irq(struct snd_msnd *dev)
 {
-	if (--dev->irq_ref > 0)
-		return 0;
-
-	if (dev->irq_ref < 0)
-		dev_dbg(dev->card->dev, LOGNAME ": IRQ ref count is %d\n",
-			dev->irq_ref);
-
 	dev_dbg(dev->card->dev, LOGNAME ": Disabling IRQ\n");
 
 	guard(spinlock_irqsave)(&dev->lock);
@@ -178,8 +167,39 @@ int snd_msnd_disable_irq(struct snd_msnd *dev)
 
 	return -EIO;
 }
+
+int snd_msnd_enable_irq(struct snd_msnd *dev)
+{
+	if (dev->irq_ref++)
+		return 0;
+
+	return __snd_msnd_enable_irq(dev);
+}
+EXPORT_SYMBOL(snd_msnd_enable_irq);
+
+int snd_msnd_disable_irq(struct snd_msnd *dev)
+{
+	if (--dev->irq_ref > 0)
+		return 0;
+
+	if (dev->irq_ref < 0)
+		dev_dbg(dev->card->dev, LOGNAME ": IRQ ref count is %d\n",
+			dev->irq_ref);
+
+	return __snd_msnd_disable_irq(dev);
+}
 EXPORT_SYMBOL(snd_msnd_disable_irq);
 
+int snd_msnd_force_irq(struct snd_msnd *dev, bool enable)
+{
+	if (!dev->irq_ref)
+		return 0;
+
+	return enable ? __snd_msnd_enable_irq(dev) :
+			__snd_msnd_disable_irq(dev);
+}
+EXPORT_SYMBOL(snd_msnd_force_irq);
+
 static inline long get_play_delay_jiffies(struct snd_msnd *chip, long size)
 {
 	long tmp = (size * HZ * chip->play_sample_size) / 8;
@@ -507,25 +527,27 @@ static int snd_msnd_playback_trigger(struct snd_pcm_substream *substream,
 				     int cmd)
 {
 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
-	int	result = 0;
 
-	if (cmd == SNDRV_PCM_TRIGGER_START) {
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
 		dev_dbg(chip->card->dev, "%s(START)\n", __func__);
 		chip->banksPlayed = 0;
 		set_bit(F_WRITING, &chip->flags);
 		snd_msnd_DAPQ(chip, 1);
-	} else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
+		break;
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
 		dev_dbg(chip->card->dev, "%s(STOP)\n", __func__);
-		/* interrupt diagnostic, comment this out later */
 		clear_bit(F_WRITING, &chip->flags);
 		snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_STOP);
-	} else {
+		break;
+	default:
 		dev_dbg(chip->card->dev, "%s(?????)\n", __func__);
-		result = -EINVAL;
+		return -EINVAL;
 	}
 
 	dev_dbg(chip->card->dev, "%s() ENDE\n", __func__);
-	return result;
+	return 0;
 }
 
 static snd_pcm_uframes_t
@@ -589,17 +611,22 @@ static int snd_msnd_capture_trigger(struct snd_pcm_substream *substream,
 {
 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
 
-	if (cmd == SNDRV_PCM_TRIGGER_START) {
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
 		chip->last_recbank = -1;
 		set_bit(F_READING, &chip->flags);
 		if (snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_START) == 0)
 			return 0;
 
 		clear_bit(F_READING, &chip->flags);
-	} else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
+		break;
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
 		clear_bit(F_READING, &chip->flags);
 		snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_STOP);
 		return 0;
+	default:
+		break;
 	}
 	return -EINVAL;
 }
@@ -668,4 +695,3 @@ EXPORT_SYMBOL(snd_msnd_pcm);
 
 MODULE_DESCRIPTION("Common routines for Turtle Beach Multisound drivers");
 MODULE_LICENSE("GPL");
-
sound/isa/msnd/msnd.h +1 -0
index 3d7810ed9186..b25beca25c0d 100644
@@ -280,6 +280,7 @@ int snd_msnd_upload_host(struct snd_msnd *chip,
 			     const u8 *bin, int len);
 int snd_msnd_enable_irq(struct snd_msnd *chip);
 int snd_msnd_disable_irq(struct snd_msnd *chip);
+int snd_msnd_force_irq(struct snd_msnd *chip, bool enable);
 void snd_msnd_dsp_halt(struct snd_msnd *chip, struct file *file);
 int snd_msnd_DAPQ(struct snd_msnd *chip, int start);
 int snd_msnd_DARQ(struct snd_msnd *chip, int start);
sound/isa/msnd/msnd_pinnacle_mixer.c +4 -0
index ec354483b9f8..8ca987221753 100644
@@ -310,6 +310,10 @@ EXPORT_SYMBOL(snd_msndmix_new);
 
 void snd_msndmix_setup(struct snd_msnd *dev)
 {
+	writew(dev->left_levels[MSND_MIXER_VOLUME],
+	       dev->SMA + SMA_wCurrMastVolLeft);
+	writew(dev->right_levels[MSND_MIXER_VOLUME],
+	       dev->SMA + SMA_wCurrMastVolRight);
 	update_pot(MSND_MIXER_LINE, bInPotPos, HDEXAR_IN_SET_POTS);
 	update_potm(MSND_MIXER_AUX, bAuxPotPos, HDEXAR_AUX_SET_POTS);
 	update_volm(MSND_MIXER_PCM, wCurrPlayVol);
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 ALSA: msnd: add ISA and PnP system sleep callbacks

In reply to Cássio Gabriel

The msnd drivers do not implement system sleep callbacks today, so they have no defined way to recover DSP state after suspend.

Add common card suspend/resume helpers, rerun the DSP initialization path on resume, restore the cached capture-source state, and rearm the shared IRQ for already-open users.

---
 sound/isa/msnd/msnd.h          |  2 +
 sound/isa/msnd/msnd_pinnacle.c | 95 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 2 deletions(-)
sound/isa/msnd/msnd.h +2 -0
index b25beca25c0d..56a700e6a5cb 100644
@@ -253,6 +253,8 @@ struct snd_msnd {
 	spinlock_t mixer_lock;
 	int nresets;
 	unsigned recsrc;
+	u8 pm_recsrc;
+	bool pm_mpu_input;
 #define LEVEL_ENTRIES 32
 	int left_levels[LEVEL_ENTRIES];
 	int right_levels[LEVEL_ENTRIES];
sound/isa/msnd/msnd_pinnacle.c +93 -2

125 lines not on this page · raw message

Signature · 1 line
2.53.0
Applied
#3 lore raw
In reply to Cássio Gabriel
Quoted 30 lines · Cássio Gabriel

The msnd drivers still have no system-sleep callbacks, and the shared driver file still carries a FIXME for suspend/resume. Probe already depends on rebuilding volatile device state by resetting the DSP, uploading firmware, reinitializing shared memory, restoring mixer settings, and calibrating the ADC. Without matching PM callbacks, the driver has no defined way to recover that state after suspend.

This small series adds the missing suspend/resume support with the minimum scope needed for the current driver.

Patch 1 prepares the driver for PM by:
- accepting SNDRV_PCM_TRIGGER_SUSPEND in the PCM trigger callbacks
- factoring the IRQ enable/disable bodies and adding a helper that can quiesce or rearm the shared IRQ without disturbing irq_ref
- restoring cached master-volume values when mixer state is rebuilt after DSP reinitialization

Patch 2 adds the actual PM callbacks by:
- saving the current capture-source selection and msnd-side MIDI input state
- adding shared card suspend/resume helpers
- wiring those helpers into the ISA driver and the Pinnacle PnP card driver with the current callback signatures

The series intentionally does not add trigger-level PCM resume support. The driver can rebuild hardware state on system resume, but it does not preserve enough runtime queue state to justify advertising full SNDRV_PCM_INFO_RESUME semantics in this change.

Quoted 5 lines

---
Cássio Gabriel (2):
ALSA: msnd: prepare system sleep support
ALSA: msnd: add ISA and PnP system sleep callbacks

Applied both patches to for-next branch. Thanks.

Takashi