Update of /cvsroot/alsa/alsa-kernel/core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19034/core

Modified Files:
        control.c init.c sound.c 
Log Message:
Clean up of power-management codes.

- moved commonly used codes to the core layer.
- using the unified suspend/resume callbacks for PCI and ISA
- added snd_card_set_pm_callbacks() and snd_card_set_isa_pm_callbacks()
  as the registration functions.


Index: control.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/control.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- control.c   26 Jan 2004 11:48:40 -0000      1.41
+++ control.c   8 Apr 2004 16:34:59 -0000       1.42
@@ -995,6 +995,31 @@
        return 0;
 }
 
+/*
+ * change the power state
+ */
+static int snd_ctl_set_power_state(snd_card_t *card, unsigned int power_state)
+{
+       switch (power_state) {
+       case SNDRV_CTL_POWER_D0:
+       case SNDRV_CTL_POWER_D1:
+       case SNDRV_CTL_POWER_D2:
+               if (card->power_state != power_state)
+                       /* FIXME: pass the correct state value */
+                       card->pm_resume(card, 0);
+               break;
+       case SNDRV_CTL_POWER_D3hot:
+       case SNDRV_CTL_POWER_D3cold:
+               if (card->power_state != power_state)
+                       /* FIXME: pass the correct state value */
+                       card->pm_suspend(card, 0);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
 static int snd_ctl_ioctl(struct inode *inode, struct file *file,
                         unsigned int cmd, unsigned long arg)
 {
@@ -1038,9 +1063,9 @@
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
 #ifdef CONFIG_PM
-               if (card->set_power_state) {
+               if (card->pm_suspend && card->pm_resume) {
                        snd_power_lock(card);
-                       err = card->set_power_state(card, err);
+                       snd_ctl_set_power_state(card, err);
                        snd_power_unlock(card);
                } else
 #endif

Index: init.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/init.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- init.c      15 Mar 2004 19:31:01 -0000      1.44
+++ init.c      8 Apr 2004 16:34:59 -0000       1.45
@@ -26,6 +26,8 @@
 #include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/ctype.h>
+#include <linux/pci.h>
+#include <linux/pm.h>
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/info.h>
@@ -254,6 +256,12 @@
 
 #ifdef CONFIG_PM
        wake_up(&card->power_sleep);
+#ifdef CONFIG_ISA
+       if (card->pm_dev) {
+               pm_unregister(card->pm_dev);
+               card->pm_dev = NULL;
+       }
+#endif
 #endif
 
        /* wait, until all devices are ready for the free operation */
@@ -708,4 +716,93 @@
        remove_wait_queue(&card->power_sleep, &wait);
        return result;
 }
+
+/**
+ * snd_card_set_pm_callback - set the PCI power-management callbacks
+ * @card: soundcard structure
+ * @suspend: suspend callback function
+ * @resume: resume callback function
+ * @private_data: private data to pass to the callback functions
+ *
+ * Sets the power-management callback functions of the card.
+ * These callbacks are called from ALSA's common PCI suspend/resume
+ * handler and from the control API.
+ */
+int snd_card_set_pm_callback(snd_card_t *card,
+                            int (*suspend)(snd_card_t *, unsigned int),
+                            int (*resume)(snd_card_t *, unsigned int),
+                            void *private_data)
+{
+       card->pm_suspend = suspend;
+       card->pm_resume = resume;
+       card->pm_private_data = private_data;
+       return 0;
+}
+
+#ifdef CONFIG_ISA
+static int snd_isa_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
+{
+       snd_card_t *card = dev->data;
+
+       switch (rqst) {
+       case PM_SUSPEND:
+               /* FIXME: the correct state value? */
+               card->pm_suspend(card, 0);
+               break;
+       case PM_RESUME:
+               /* FIXME: the correct state value? */
+               card->pm_resume(card, 0);
+               break;
+       }
+       return 0;
+}
+
+/**
+ * snd_card_set_isa_pm_callback - set the ISA power-management callbacks
+ * @card: soundcard structure
+ * @suspend: suspend callback function
+ * @resume: resume callback function
+ * @private_data: private data to pass to the callback functions
+ *
+ * Registers the power-management and sets the lowlevel callbacks for
+ * the given ISA card.  These callbacks are called from the ALSA's
+ * common PM handler and from the control API.
+ */
+int snd_card_set_isa_pm_callback(snd_card_t *card,
+                                int (*suspend)(snd_card_t *, unsigned int),
+                                int (*resume)(snd_card_t *, unsigned int),
+                                void *private_data)
+{
+       card->pm_dev = pm_register(PM_ISA_DEV, 0, snd_isa_pm_callback);
+       if (! card->pm_dev)
+               return -ENOMEM;
+       card->pm_dev->data = card;
+       return snd_card_set_pm_callback(card, suspend, resume, private_data);
+}
+#endif
+
+#ifdef CONFIG_PCI
+int snd_card_pci_suspend(struct pci_dev *dev, u32 state)
+{
+       snd_card_t *card = pci_get_drvdata(dev);
+       if (! card || ! card->pm_suspend)
+               return 0;
+       if (card->power_state == SNDRV_CTL_POWER_D3hot)
+               return 0;
+       /* FIXME: correct state value? */
+       return card->pm_suspend(card, 0);
+}
+
+int snd_card_pci_resume(struct pci_dev *dev)
+{
+       snd_card_t *card = pci_get_drvdata(dev);
+       if (! card || ! card->pm_resume)
+               return 0;
+       if (card->power_state == SNDRV_CTL_POWER_D0)
+               return 0;
+       /* FIXME: correct state value? */
+       return card->pm_resume(card, 0);
+}
+#endif
+
 #endif /* CONFIG_PM */

Index: sound.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/sound.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- sound.c     7 Apr 2004 17:48:11 -0000       1.60
+++ sound.c     8 Apr 2004 16:34:59 -0000       1.61
@@ -466,6 +466,14 @@
 EXPORT_SYMBOL(snd_card_file_remove);
 #ifdef CONFIG_PM
 EXPORT_SYMBOL(snd_power_wait);
+EXPORT_SYMBOL(snd_card_set_pm_callback);
+#ifdef CONFIG_PCI
+EXPORT_SYMBOL(snd_card_pci_suspend);
+EXPORT_SYMBOL(snd_card_pci_resume);
+#endif
+#ifdef CONFIG_ISA
+EXPORT_SYMBOL(snd_card_set_isa_pm_callback);
+#endif
 #endif
   /* device.c */
 EXPORT_SYMBOL(snd_device_new);



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to