]> err.no Git - linux-2.6/blobdiff - sound/pci/es1968.c
[ALSA] hda-codec - Add entry for Epox EP-5LDA+ GLi
[linux-2.6] / sound / pci / es1968.c
index 021862d28f2b5d9d8bb567a8f94697d7972284c5..dd465a186e119eb6233aa8268fb3fd2123c1560e 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/pci.h>
+#include <linux/dma-mapping.h>
 #include <linux/slab.h>
 #include <linux/gameport.h>
 #include <linux/moduleparam.h>
+#include <linux/mutex.h>
+
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/mpu401.h>
@@ -176,7 +179,7 @@ MODULE_PARM_DESC(joystick, "Enable joystick.");
 
 /* Values for the ESM_LEGACY_AUDIO_CONTROL */
 
-#define ESS_ENABLE_AUDIO       0x8000
+#define ESS_DISABLE_AUDIO      0x8000
 #define ESS_ENABLE_SERIAL_IRQ  0x4000
 #define IO_ADRESS_ALIAS                0x0020
 #define MPU401_IRQ_ENABLE      0x0010
@@ -195,7 +198,7 @@ MODULE_PARM_DESC(joystick, "Enable joystick.");
 #define DMA_TDMA               0x0100
 #define DMA_PCPCI              0x0200
 #define POST_WRITE             0x0080
-#define ISA_TIMING             0x0040
+#define PCI_TIMING             0x0040
 #define SWAP_LR                        0x0020
 #define SUBTR_DECODE           0x0002
 
@@ -569,7 +572,7 @@ struct es1968 {
        u16 maestro_map[32];
        int bobclient;          /* active timer instancs */
        int bob_freq;           /* timer frequency */
-       struct semaphore memory_mutex;  /* memory lock */
+       struct mutex memory_mutex;      /* memory lock */
 
        /* APU states */
        unsigned char apu[NR_APUS];
@@ -727,7 +730,7 @@ static void __apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 dat
        apu_data_set(chip, data);
 }
 
-static inline void apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 data)
+static void apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 data)
 {
        unsigned long flags;
        spin_lock_irqsave(&chip->reg_lock, flags);
@@ -743,7 +746,7 @@ static u16 __apu_get_register(struct es1968 *chip, u16 channel, u8 reg)
        return __maestro_read(chip, IDR0_DATA_PORT);
 }
 
-static inline u16 apu_get_register(struct es1968 *chip, u16 channel, u8 reg)
+static u16 apu_get_register(struct es1968 *chip, u16 channel, u8 reg)
 {
        unsigned long flags;
        u16 v;
@@ -1356,13 +1359,13 @@ static int calc_available_memory_size(struct es1968 *chip)
        struct list_head *p;
        int max_size = 0;
        
-       down(&chip->memory_mutex);
+       mutex_lock(&chip->memory_mutex);
        list_for_each(p, &chip->buf_list) {
                struct esm_memory *buf = list_entry(p, struct esm_memory, list);
                if (buf->empty && buf->buf.bytes > max_size)
                        max_size = buf->buf.bytes;
        }
-       up(&chip->memory_mutex);
+       mutex_unlock(&chip->memory_mutex);
        if (max_size >= 128*1024)
                max_size = 127*1024;
        return max_size;
@@ -1375,20 +1378,20 @@ static struct esm_memory *snd_es1968_new_memory(struct es1968 *chip, int size)
        struct list_head *p;
        
        size = ((size + ESM_MEM_ALIGN - 1) / ESM_MEM_ALIGN) * ESM_MEM_ALIGN;
-       down(&chip->memory_mutex);
+       mutex_lock(&chip->memory_mutex);
        list_for_each(p, &chip->buf_list) {
                buf = list_entry(p, struct esm_memory, list);
                if (buf->empty && buf->buf.bytes >= size)
                        goto __found;
        }
-       up(&chip->memory_mutex);
+       mutex_unlock(&chip->memory_mutex);
        return NULL;
 
 __found:
        if (buf->buf.bytes > size) {
                struct esm_memory *chunk = kmalloc(sizeof(*chunk), GFP_KERNEL);
                if (chunk == NULL) {
-                       up(&chip->memory_mutex);
+                       mutex_unlock(&chip->memory_mutex);
                        return NULL;
                }
                chunk->buf = buf->buf;
@@ -1400,7 +1403,7 @@ __found:
                list_add(&chunk->list, &buf->list);
        }
        buf->empty = 0;
-       up(&chip->memory_mutex);
+       mutex_unlock(&chip->memory_mutex);
        return buf;
 }
 
@@ -1409,7 +1412,7 @@ static void snd_es1968_free_memory(struct es1968 *chip, struct esm_memory *buf)
 {
        struct esm_memory *chunk;
 
-       down(&chip->memory_mutex);
+       mutex_lock(&chip->memory_mutex);
        buf->empty = 1;
        if (buf->list.prev != &chip->buf_list) {
                chunk = list_entry(buf->list.prev, struct esm_memory, list);
@@ -1428,7 +1431,7 @@ static void snd_es1968_free_memory(struct es1968 *chip, struct esm_memory *buf)
                        kfree(chunk);
                }
        }
-       up(&chip->memory_mutex);
+       mutex_unlock(&chip->memory_mutex);
 }
 
 static void snd_es1968_free_dmabuf(struct es1968 *chip)
@@ -2193,14 +2196,11 @@ static void snd_es1968_chip_init(struct es1968 *chip)
        /* Config Reg A */
        pci_read_config_word(pci, ESM_CONFIG_A, &w);
 
-       /*      Use TDMA for now. TDMA works on all boards, so while its
-        *      not the most efficient its the simplest. */
        w &= ~DMA_CLEAR;        /* Clear DMA bits */
-       w |= DMA_TDMA;          /* TDMA on */
        w &= ~(PIC_SNOOP1 | PIC_SNOOP2);        /* Clear Pic Snoop Mode Bits */
        w &= ~SAFEGUARD;        /* Safeguard off */
        w |= POST_WRITE;        /* Posted write */
-       w |= ISA_TIMING;        /* ISA timing on */
+       w |= PCI_TIMING;        /* PCI timing on */
        /* XXX huh?  claims to be reserved.. */
        w &= ~SWAP_LR;          /* swap left/right 
                                   seems to only have effect on SB
@@ -2241,7 +2241,7 @@ static void snd_es1968_chip_init(struct es1968 *chip)
 
        pci_read_config_word(pci, ESM_LEGACY_AUDIO_CONTROL, &w);
 
-       w &= ~ESS_ENABLE_AUDIO; /* Disable Legacy Audio */
+       w |= ESS_DISABLE_AUDIO; /* Disable Legacy Audio */
        w &= ~ESS_ENABLE_SERIAL_IRQ;    /* Disable SIRQ */
        w &= ~(0x1f);           /* disable mpu irq/io, game port, fm, SB */
 
@@ -2378,33 +2378,38 @@ static void snd_es1968_start_irq(struct es1968 *chip)
 /*
  * PM support
  */
-static int es1968_suspend(struct snd_card *card, pm_message_t state)
+static int es1968_suspend(struct pci_dev *pci, pm_message_t state)
 {
-       struct es1968 *chip = card->pm_private_data;
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct es1968 *chip = card->private_data;
 
        if (! chip->do_pm)
                return 0;
 
        chip->in_suspend = 1;
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
        snd_pcm_suspend_all(chip->pcm);
        snd_ac97_suspend(chip->ac97);
        snd_es1968_bob_stop(chip);
        snd_es1968_set_acpi(chip, ACPI_D3);
-       pci_disable_device(chip->pci);
+       pci_disable_device(pci);
+       pci_save_state(pci);
        return 0;
 }
 
-static int es1968_resume(struct snd_card *card)
+static int es1968_resume(struct pci_dev *pci)
 {
-       struct es1968 *chip = card->pm_private_data;
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct es1968 *chip = card->private_data;
        struct list_head *p;
 
        if (! chip->do_pm)
                return 0;
 
        /* restore all our config */
-       pci_enable_device(chip->pci);
-       pci_set_master(chip->pci);
+       pci_restore_state(pci);
+       pci_enable_device(pci);
+       pci_set_master(pci);
        snd_es1968_chip_init(chip);
 
        /* need to restore the base pointers.. */ 
@@ -2434,6 +2439,7 @@ static int es1968_resume(struct snd_card *card)
        if (chip->bobclient)
                snd_es1968_bob_start(chip);
 
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
        chip->in_suspend = 0;
        return 0;
 }
@@ -2556,8 +2562,8 @@ static int __devinit snd_es1968_create(struct snd_card *card,
        if ((err = pci_enable_device(pci)) < 0)
                return err;
        /* check, if we can restrict PCI DMA transfers to 28 bits */
-       if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
-           pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
+       if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
+           pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) {
                snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
                pci_disable_device(pci);
                return -ENXIO;
@@ -2576,7 +2582,7 @@ static int __devinit snd_es1968_create(struct snd_card *card,
        INIT_LIST_HEAD(&chip->buf_list);
        INIT_LIST_HEAD(&chip->substream_list);
        spin_lock_init(&chip->ac97_lock);
-       init_MUTEX(&chip->memory_mutex);
+       mutex_init(&chip->memory_mutex);
        tasklet_init(&chip->hwvol_tq, es1968_update_hw_volume, (unsigned long)chip);
        chip->card = card;
        chip->pci = pci;
@@ -2631,9 +2637,6 @@ static int __devinit snd_es1968_create(struct snd_card *card,
 
        snd_es1968_chip_init(chip);
 
-       if (chip->do_pm)
-               snd_card_set_pm_callback(card, es1968_suspend, es1968_resume, chip);
-
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
                snd_es1968_free(chip);
                return err;
@@ -2683,6 +2686,7 @@ static int __devinit snd_es1968_probe(struct pci_dev *pci,
                snd_card_free(card);
                return err;
        }
+       card->private_data = chip;
 
        switch (chip->type) {
        case TYPE_MAESTRO2E:
@@ -2760,7 +2764,10 @@ static struct pci_driver driver = {
        .id_table = snd_es1968_ids,
        .probe = snd_es1968_probe,
        .remove = __devexit_p(snd_es1968_remove),
-       SND_PCI_PM_CALLBACKS
+#ifdef CONFIG_PM
+       .suspend = es1968_suspend,
+       .resume = es1968_resume,
+#endif
 };
 
 static int __init alsa_card_es1968_init(void)