[PATCH] [UBUNTU:sound/pci/cs46xx/] #11149: Fix PM support for snd_cs46xx

crimsun at fungus.sh.nu crimsun at fungus.sh.nu
Mon Jun 12 22:25:49 UTC 2006


Subject: [PATCH] [UBUNTU:sound/pci/cs46xx/] #11149: Fix PM support for snd_cs46xx

UpstreamStatus: Added in upstream http://www.kernel.org/hg/linux-2.6/?cs=c7a4c2b71aa7

Patch from Takashi Iwai to fix suspend/resume for snd_cs46xx. Alerted
by Chuck Short.

This commit closes LP #11149.

Signed-off-by: Daniel T Chen <crimsun at ubuntu.com>

---

 include/sound/cs46xx.h        |    2 ++
 sound/pci/cs46xx/cs46xx.c     |    6 +++++-
 sound/pci/cs46xx/cs46xx_lib.c |   28 +++++++++++++++-------------
 3 files changed, 22 insertions(+), 14 deletions(-)

7449bc657bc4bbafb55fa246737af7f7b9d912e6
diff --git a/include/sound/cs46xx.h b/include/sound/cs46xx.h
index b0c0e19..1f0ae2e 100644
--- a/include/sound/cs46xx.h
+++ b/include/sound/cs46xx.h
@@ -1729,6 +1729,8 @@ int snd_cs46xx_create(snd_card_t *card,
 		      struct pci_dev *pci,
 		      int external_amp, int thinkpad,
 		      cs46xx_t **rcodec);
+int snd_cs46xx_suspend(struct pci_dev *pci, pm_message_t state);
+int snd_cs45xx_resume(struct pci_dev *pci);
 
 int snd_cs46xx_pcm(cs46xx_t *chip, int device, snd_pcm_t **rpcm);
 int snd_cs46xx_pcm_rear(cs46xx_t *chip, int device, snd_pcm_t **rpcm);
diff --git a/sound/pci/cs46xx/cs46xx.c b/sound/pci/cs46xx/cs46xx.c
index b9fff4e..f26e66e 100644
--- a/sound/pci/cs46xx/cs46xx.c
+++ b/sound/pci/cs46xx/cs46xx.c
@@ -98,6 +98,7 @@ static int __devinit snd_card_cs46xx_pro
 		snd_card_free(card);
 		return err;
 	}
+	card->private_data = chip;
 	chip->accept_valid = mmap_valid[dev];
 	if ((err = snd_cs46xx_pcm(chip, 0, NULL)) < 0) {
 		snd_card_free(card);
@@ -166,7 +167,10 @@ static struct pci_driver driver = {
 	.id_table = snd_cs46xx_ids,
 	.probe = snd_card_cs46xx_probe,
 	.remove = __devexit_p(snd_card_cs46xx_remove),
-	SND_PCI_PM_CALLBACKS
+#ifdef CONFIG_PM
+	.suspend = snd_cs46xx_suspend,
+	.resume = snd_cs46xx_resume,
+#endif
 };
 
 static int __init alsa_card_cs46xx_init(void)
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index b89450f..79268c3 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -3687,18 +3687,19 @@ static struct cs_card_type __devinitdata
  * APM support
  */
 #ifdef CONFIG_PM
-static int snd_cs46xx_suspend(snd_card_t *card, pm_message_t state)
+int snd_cs46xx_suspend(snd_card_t *card, pm_message_t state)
 {
-	cs46xx_t *chip = card->pm_private_data;
+	snd_card_t *card = pci_get_drvdata(pci);
+	cs46xx_t *chip = card->private_data;
 	int amp_saved;
 
+	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
 	snd_pcm_suspend_all(chip->pcm);
 	// chip->ac97_powerdown = snd_cs46xx_codec_read(chip, AC97_POWER_CONTROL);
 	// chip->ac97_general_purpose = snd_cs46xx_codec_read(chip, BA0_AC97_GENERAL_PURPOSE);
 
 	snd_ac97_suspend(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]);
-	if (chip->ac97[CS46XX_SECONDARY_CODEC_INDEX])
-		snd_ac97_suspend(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]);
+	snd_ac97_suspend(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]);
 
 	amp_saved = chip->amplifier;
 	/* turn off amp */
@@ -3707,17 +3708,20 @@ static int snd_cs46xx_suspend(snd_card_t
 	/* disable CLKRUN */
 	chip->active_ctrl(chip, -chip->amplifier);
 	chip->amplifier = amp_saved; /* restore the status */
-	pci_disable_device(chip->pci);
+	pci_disable_device(pci);
+	pci_save_state(pci);
 	return 0;
 }
 
-static int snd_cs46xx_resume(snd_card_t *card)
+int snd_cs46xx_resume(struct pci_dev *pci)
 {
-	cs46xx_t *chip = card->pm_private_data;
+	snd_card_t *card = pci_get_drvdata(pci);
+	cs46xx_t *chip = card->private_data;
 	int amp_saved;
 
-	pci_enable_device(chip->pci);
-	pci_set_master(chip->pci);
+	pci_restore_state(pci);
+	pci_enable_device(pci);
+	pci_set_master(pci);
 	amp_saved = chip->amplifier;
 	chip->amplifier = 0;
 	chip->active_ctrl(chip, 1); /* force to on */
@@ -3736,14 +3740,14 @@ static int snd_cs46xx_resume(snd_card_t 
 #endif
 
 	snd_ac97_resume(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]);
-	if (chip->ac97[CS46XX_SECONDARY_CODEC_INDEX])
-		snd_ac97_resume(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]);
+	snd_ac97_resume(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]);
 
 	if (amp_saved)
 		chip->amplifier_ctrl(chip, 1); /* turn amp on */
 	else
 		chip->active_ctrl(chip, -1); /* disable CLKRUN */
 	chip->amplifier = amp_saved;
+	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
 	return 0;
 }
 #endif /* CONFIG_PM */
@@ -3899,8 +3903,6 @@ int __devinit snd_cs46xx_create(snd_card
 	
 	snd_cs46xx_proc_init(card, chip);
 
-	snd_card_set_pm_callback(card, snd_cs46xx_suspend, snd_cs46xx_resume, chip);
-
 	chip->active_ctrl(chip, -1); /* disable CLKRUN */
 
 	snd_card_set_dev(card, &pci->dev);
-- 
1.1.3


-- 
Daniel T. Chen            crimsun at ubuntu.com
GPG key:   www.sh.nu/~crimsun/pubkey.gpg.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20060612/dcdb99da/attachment.sig>


More information about the kernel-team mailing list