All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] save sound mixer state over suspend
@ 2001-11-11 20:42 Kai Germaschewski
  2001-11-12  5:47 ` Pete Zaitcev
  0 siblings, 1 reply; 4+ messages in thread
From: Kai Germaschewski @ 2001-11-11 20:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Pete Zaitcev


The appended patch introduces two new functions to the ac97_codec 
handling: ac97_save_state() and ac97_restore_state().
These functions save/restore the mixer state over suspend. (So after 
resume the volume is the same it was before)

As an example, I changed the ymfpci driver to use the new functionality -
works fine here.

--Kai

diff -ur linux-2.4.15-pre2/drivers/sound/ac97_codec.c linux-2.4.15-pre2.x/drivers/sound/ac97_codec.c
--- linux-2.4.15-pre2/drivers/sound/ac97_codec.c	Sat Nov 10 19:08:12 2001
+++ linux-2.4.15-pre2.x/drivers/sound/ac97_codec.c	Sun Nov 11 20:39:15 2001
@@ -1019,4 +1019,31 @@
 }
 
 EXPORT_SYMBOL(ac97_set_adc_rate);
+
+int ac97_save_state(struct ac97_codec *codec)
+{
+	return 0;	
+}
+
+EXPORT_SYMBOL(ac97_save_state);
+
+int ac97_restore_state(struct ac97_codec *codec)
+{
+	int i;
+	unsigned int left, right, val;
+
+	for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
+		if (!supported_mixer(codec, i)) 
+			continue;
+
+		val = codec->mixer_state[i];
+		right = val >> 8;
+		left = val  & 0xff;
+		codec->write_mixer(codec, i, left, right);
+	}
+	return 0;
+}
+
+EXPORT_SYMBOL(ac97_restore_state);
+
 MODULE_LICENSE("GPL");
diff -ur linux-2.4.15-pre2/drivers/sound/ymfpci.c linux-2.4.15-pre2.x/drivers/sound/ymfpci.c
--- linux-2.4.15-pre2/drivers/sound/ymfpci.c	Wed Oct 24 22:51:49 2001
+++ linux-2.4.15-pre2.x/drivers/sound/ymfpci.c	Sun Nov 11 20:40:46 2001
@@ -1824,7 +1824,7 @@
 	}
 
 	unit = NULL;	/* gcc warns */
-	for (list = ymf_devs.next; list != &ymf_devs; list = list->next) {
+	list_for_each(list, &ymf_devs) {
 		unit = list_entry(list, ymfpci_t, ymf_devs);
 		if (((unit->dev_audio ^ minor) & ~0x0F) == 0)
 			break;
@@ -1935,7 +1935,7 @@
 	struct list_head *list;
 	ymfpci_t *unit;
 
-	for (list = ymf_devs.next; list != &ymf_devs; list = list->next) {
+	list_for_each(list, &ymf_devs) {
 		unit = list_entry(list, ymfpci_t, ymf_devs);
 		for (i = 0; i < NR_AC97; i++) {
 			if (unit->ac97_codec[i] != NULL &&
@@ -1990,16 +1990,25 @@
 
 static int ymf_suspend(struct pci_dev *pcidev, u32 unused)
 {
+	int i;
 	struct ymf_unit *unit = pci_get_drvdata(pcidev);
 	unsigned long flags;
 	struct ymf_dmabuf *dmabuf;
 	struct list_head *p;
 	struct ymf_state *state;
+	struct ac97_codec *codec;
 
 	spin_lock_irqsave(&unit->reg_lock, flags);
 
 	unit->suspended = 1;
 
+	for (i = 0; i < NR_AC97; i++) {
+		codec = unit->ac97_codec[i];
+		if (!codec)
+			continue;
+		ac97_save_state(codec);
+	}
+
 	list_for_each(p, &unit->states) {
 		state = list_entry(p, struct ymf_state, chain);
 
@@ -2024,13 +2033,22 @@
 
 static int ymf_resume(struct pci_dev *pcidev)
 {
+	int i;
 	struct ymf_unit *unit = pci_get_drvdata(pcidev);
 	unsigned long flags;
 	struct list_head *p;
 	struct ymf_state *state;
+	struct ac97_codec *codec;
 
 	ymfpci_aclink_reset(unit->pci);
 	ymfpci_codec_ready(unit, 0, 1);		/* prints diag if not ready. */
+
+	for (i = 0; i < NR_AC97; i++) {
+		codec = unit->ac97_codec[i];
+		if (!codec)
+			continue;
+		ac97_restore_state(codec);
+	}
 
 #ifdef CONFIG_SOUND_YMFPCI_LEGACY
 	/* XXX At this time the legacy registers are probably deprogrammed. */
diff -ur linux-2.4.15-pre2/include/linux/ac97_codec.h linux-2.4.15-pre2.x/include/linux/ac97_codec.h
--- linux-2.4.15-pre2/include/linux/ac97_codec.h	Sun Nov 11 13:12:47 2001
+++ linux-2.4.15-pre2.x/include/linux/ac97_codec.h	Sun Nov 11 20:40:29 2001
@@ -239,6 +239,7 @@
 extern int ac97_probe_codec(struct ac97_codec *);
 extern unsigned int ac97_set_adc_rate(struct ac97_codec *codec, unsigned int rate);
 extern unsigned int ac97_set_dac_rate(struct ac97_codec *codec, unsigned int rate);
-
+extern int ac97_save_state(struct ac97_codec *codec);
+extern int ac97_restore_state(struct ac97_codec *codec);
 
 #endif /* _AC97_CODEC_H_ */





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-11-12  8:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-11-11 20:42 [PATCH] save sound mixer state over suspend Kai Germaschewski
2001-11-12  5:47 ` Pete Zaitcev
2001-11-12  6:03   ` Jeff Garzik
2001-11-12  8:40     ` Kai Germaschewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.