V4L/DVB (4474): On some cases, depth were not returned.
[powerpc.git] / sound / pci / ens1370.c
index ff86fab..a8a601f 100644 (file)
@@ -35,6 +35,8 @@
 #include <linux/slab.h>
 #include <linux/gameport.h>
 #include <linux/moduleparam.h>
+#include <linux/mutex.h>
+
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/pcm.h>
@@ -90,6 +92,10 @@ static int joystick_port[SNDRV_CARDS];
 static int joystick[SNDRV_CARDS];
 #endif
 #endif
+#ifdef CHIP1371
+static int spdif[SNDRV_CARDS];
+static int lineio[SNDRV_CARDS];
+#endif
 
 module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for Ensoniq AudioPCI soundcard.");
@@ -106,6 +112,12 @@ module_param_array(joystick, bool, NULL, 0444);
 MODULE_PARM_DESC(joystick, "Enable joystick.");
 #endif
 #endif /* SUPPORT_JOYSTICK */
+#ifdef CHIP1371
+module_param_array(spdif, int, NULL, 0444);
+MODULE_PARM_DESC(spdif, "S/PDIF output (-1 = none, 0 = auto, 1 = force).");
+module_param_array(lineio, int, NULL, 0444);
+MODULE_PARM_DESC(lineio, "Line In to Rear Out (0 = auto, 1 = force).");
+#endif
 
 /* ES1371 chip ID */
 /* This is a little confusing because all ES1371 compatible chips have the
@@ -369,7 +381,7 @@ MODULE_PARM_DESC(joystick, "Enable joystick.");
 
 struct ensoniq {
        spinlock_t reg_lock;
-       struct semaphore src_mutex;
+       struct mutex src_mutex;
 
        int irq;
 
@@ -599,7 +611,7 @@ static void snd_es1371_codec_write(struct snd_ac97 *ac97,
        struct ensoniq *ensoniq = ac97->private_data;
        unsigned int t, x;
 
-       down(&ensoniq->src_mutex);
+       mutex_lock(&ensoniq->src_mutex);
        for (t = 0; t < POLL_COUNT; t++) {
                if (!(inl(ES_REG(ensoniq, 1371_CODEC)) & ES_1371_CODEC_WIP)) {
                        /* save the current state for latter */
@@ -624,11 +636,11 @@ static void snd_es1371_codec_write(struct snd_ac97 *ac97,
                        /* restore SRC reg */
                        snd_es1371_wait_src_ready(ensoniq);
                        outl(x, ES_REG(ensoniq, 1371_SMPRATE));
-                       up(&ensoniq->src_mutex);
+                       mutex_unlock(&ensoniq->src_mutex);
                        return;
                }
        }
-       up(&ensoniq->src_mutex);
+       mutex_unlock(&ensoniq->src_mutex);
        snd_printk(KERN_ERR "codec write timeout at 0x%lx [0x%x]\n",
                   ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
 }
@@ -640,7 +652,7 @@ static unsigned short snd_es1371_codec_read(struct snd_ac97 *ac97,
        unsigned int t, x, fail = 0;
 
       __again:
-       down(&ensoniq->src_mutex);
+       mutex_lock(&ensoniq->src_mutex);
        for (t = 0; t < POLL_COUNT; t++) {
                if (!(inl(ES_REG(ensoniq, 1371_CODEC)) & ES_1371_CODEC_WIP)) {
                        /* save the current state for latter */
@@ -673,11 +685,11 @@ static unsigned short snd_es1371_codec_read(struct snd_ac97 *ac97,
                        /* now wait for the stinkin' data (RDY) */
                        for (t = 0; t < POLL_COUNT; t++) {
                                if ((x = inl(ES_REG(ensoniq, 1371_CODEC))) & ES_1371_CODEC_RDY) {
-                                       up(&ensoniq->src_mutex);
+                                       mutex_unlock(&ensoniq->src_mutex);
                                        return ES_1371_CODEC_READ(x);
                                }
                        }
-                       up(&ensoniq->src_mutex);
+                       mutex_unlock(&ensoniq->src_mutex);
                        if (++fail > 10) {
                                snd_printk(KERN_ERR "codec read timeout (final) "
                                           "at 0x%lx, reg = 0x%x [0x%x]\n",
@@ -688,7 +700,7 @@ static unsigned short snd_es1371_codec_read(struct snd_ac97 *ac97,
                        goto __again;
                }
        }
-       up(&ensoniq->src_mutex);
+       mutex_unlock(&ensoniq->src_mutex);
        snd_printk(KERN_ERR "es1371: codec read timeout at 0x%lx [0x%x]\n",
                   ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
        return 0;
@@ -707,7 +719,7 @@ static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate)
 {
        unsigned int n, truncm, freq, result;
 
-       down(&ensoniq->src_mutex);
+       mutex_lock(&ensoniq->src_mutex);
        n = rate / 3000;
        if ((1 << n) & ((1 << 15) | (1 << 13) | (1 << 11) | (1 << 9)))
                n--;
@@ -732,14 +744,14 @@ static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate)
        snd_es1371_src_write(ensoniq, ES_SMPREG_ADC + ES_SMPREG_VFREQ_FRAC, freq & 0x7fff);
        snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_ADC, n << 8);
        snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_ADC + 1, n << 8);
-       up(&ensoniq->src_mutex);
+       mutex_unlock(&ensoniq->src_mutex);
 }
 
 static void snd_es1371_dac1_rate(struct ensoniq * ensoniq, unsigned int rate)
 {
        unsigned int freq, r;
 
-       down(&ensoniq->src_mutex);
+       mutex_lock(&ensoniq->src_mutex);
        freq = ((rate << 15) + 1500) / 3000;
        r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE |
                                                   ES_1371_DIS_P2 | ES_1371_DIS_R1)) |
@@ -753,14 +765,14 @@ static void snd_es1371_dac1_rate(struct ensoniq * ensoniq, unsigned int rate)
        r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE |
                                                   ES_1371_DIS_P2 | ES_1371_DIS_R1));
        outl(r, ES_REG(ensoniq, 1371_SMPRATE));
-       up(&ensoniq->src_mutex);
+       mutex_unlock(&ensoniq->src_mutex);
 }
 
 static void snd_es1371_dac2_rate(struct ensoniq * ensoniq, unsigned int rate)
 {
        unsigned int freq, r;
 
-       down(&ensoniq->src_mutex);
+       mutex_lock(&ensoniq->src_mutex);
        freq = ((rate << 15) + 1500) / 3000;
        r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE |
                                                   ES_1371_DIS_P1 | ES_1371_DIS_R1)) |
@@ -775,7 +787,7 @@ static void snd_es1371_dac2_rate(struct ensoniq * ensoniq, unsigned int rate)
        r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE |
                                                   ES_1371_DIS_P1 | ES_1371_DIS_R1));
        outl(r, ES_REG(ensoniq, 1371_SMPRATE));
-       up(&ensoniq->src_mutex);
+       mutex_unlock(&ensoniq->src_mutex);
 }
 
 #endif /* CHIP1371 */
@@ -1608,7 +1620,7 @@ static struct {
        { .vid = PCI_ANY_ID, .did = PCI_ANY_ID }
 };
 
-static int snd_ensoniq_1371_mixer(struct ensoniq * ensoniq)
+static int snd_ensoniq_1371_mixer(struct ensoniq * ensoniq, int has_spdif, int has_line)
 {
        struct snd_card *card = ensoniq->card;
        struct snd_ac97_bus *pbus;
@@ -1630,12 +1642,15 @@ static int snd_ensoniq_1371_mixer(struct ensoniq * ensoniq)
        if ((err = snd_ac97_mixer(pbus, &ac97, &ensoniq->u.es1371.ac97)) < 0)
                return err;
        for (idx = 0; es1371_spdif_present[idx].vid != (unsigned short)PCI_ANY_ID; idx++)
-               if (ensoniq->pci->vendor == es1371_spdif_present[idx].vid &&
-                   ensoniq->pci->device == es1371_spdif_present[idx].did &&
-                   ensoniq->rev == es1371_spdif_present[idx].rev) {
+               if ((ensoniq->pci->vendor == es1371_spdif_present[idx].vid &&
+                    ensoniq->pci->device == es1371_spdif_present[idx].did &&
+                    ensoniq->rev == es1371_spdif_present[idx].rev) || has_spdif > 0) {
                        struct snd_kcontrol *kctl;
                        int i, index = 0; 
 
+                        if (has_spdif < 0)
+                                break;
+
                        ensoniq->spdif_default = ensoniq->spdif_stream =
                                SNDRV_PCM_DEFAULT_CON_SPDIF;
                        outl(ensoniq->spdif_default, ES_REG(ensoniq, CHANNEL_STATUS));
@@ -1664,7 +1679,8 @@ static int snd_ensoniq_1371_mixer(struct ensoniq * ensoniq)
        if (((ensoniq->subsystem_vendor_id == 0x1274) &&
            (ensoniq->subsystem_device_id == 0x2000)) || /* GA-7DXR */
            ((ensoniq->subsystem_vendor_id == 0x1458) &&
-           (ensoniq->subsystem_device_id == 0xa000))) { /* GA-8IEXP */
+           (ensoniq->subsystem_device_id == 0xa000)) || /* GA-8IEXP */
+           has_line > 0) {
                 err = snd_ctl_add(card, snd_ctl_new1(&snd_ens1373_line, ensoniq));
                 if (err < 0)
                         return err;
@@ -1899,7 +1915,7 @@ static void __devinit snd_ensoniq_proc_init(struct ensoniq * ensoniq)
        struct snd_info_entry *entry;
 
        if (! snd_card_proc_new(ensoniq->card, "audiopci", &entry))
-               snd_info_set_text_ops(entry, ensoniq, 1024, snd_ensoniq_proc_read);
+               snd_info_set_text_ops(entry, ensoniq, snd_ensoniq_proc_read);
 }
 
 /*
@@ -2047,6 +2063,13 @@ static int snd_ensoniq_suspend(struct pci_dev *pci, pm_message_t state)
 #ifdef CHIP1371        
        snd_ac97_suspend(ensoniq->u.es1371.ac97);
 #else
+       /* try to reset AK4531 */
+       outw(ES_1370_CODEC_WRITE(AK4531_RESET, 0x02), ES_REG(ensoniq, 1370_CODEC));
+       inw(ES_REG(ensoniq, 1370_CODEC));
+       udelay(100);
+       outw(ES_1370_CODEC_WRITE(AK4531_RESET, 0x03), ES_REG(ensoniq, 1370_CODEC));
+       inw(ES_REG(ensoniq, 1370_CODEC));
+       udelay(100);
        snd_ak4531_suspend(ensoniq->u.es1370.ak4531);
 #endif 
        pci_set_power_state(pci, PCI_D3hot);
@@ -2102,7 +2125,7 @@ static int __devinit snd_ensoniq_create(struct snd_card *card,
                return -ENOMEM;
        }
        spin_lock_init(&ensoniq->reg_lock);
-       init_MUTEX(&ensoniq->src_mutex);
+       mutex_init(&ensoniq->src_mutex);
        ensoniq->card = card;
        ensoniq->pci = pci;
        ensoniq->irq = -1;
@@ -2112,7 +2135,7 @@ static int __devinit snd_ensoniq_create(struct snd_card *card,
                return err;
        }
        ensoniq->port = pci_resource_start(pci, 0);
-       if (request_irq(pci->irq, snd_audiopci_interrupt, SA_INTERRUPT|SA_SHIRQ,
+       if (request_irq(pci->irq, snd_audiopci_interrupt, IRQF_DISABLED|IRQF_SHARED,
                        "Ensoniq AudioPCI", ensoniq)) {
                snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
                snd_ensoniq_free(ensoniq);
@@ -2449,7 +2472,7 @@ static int __devinit snd_audiopci_probe(struct pci_dev *pci,
        }
 #endif
 #ifdef CHIP1371
-       if ((err = snd_ensoniq_1371_mixer(ensoniq)) < 0) {
+       if ((err = snd_ensoniq_1371_mixer(ensoniq, spdif[dev], lineio[dev])) < 0) {
                snd_card_free(card);
                return err;
        }