[ALSA] cmipci: show actual chip name in card longname
[powerpc.git] / sound / pci / cmipci.c
index 0093cd1..315ba26 100644 (file)
@@ -57,7 +57,7 @@ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;    /* Index 0-MAX */
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable switches */
 static long mpu_port[SNDRV_CARDS];
-static long fm_port[SNDRV_CARDS];
+static long fm_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
 static int soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
 #ifdef SUPPORT_JOYSTICK
 static int joystick_port[SNDRV_CARDS];
@@ -424,7 +424,6 @@ struct cmipci {
 
        int chip_version;
        int max_channels;
-       unsigned int has_dual_dac: 1;
        unsigned int can_ac3_sw: 1;
        unsigned int can_ac3_hw: 1;
        unsigned int can_multi_ch: 1;
@@ -2139,15 +2138,7 @@ struct cmipci_switch_args {
                                         */
 };
 
-static int snd_cmipci_uswitch_info(struct snd_kcontrol *kcontrol,
-                                  struct snd_ctl_elem_info *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 1;
-       return 0;
-}
+#define snd_cmipci_uswitch_info                snd_ctl_boolean_mono_info
 
 static int _snd_cmipci_uswitch_get(struct snd_kcontrol *kcontrol,
                                   struct snd_ctl_elem_value *ucontrol,
@@ -2198,7 +2189,8 @@ static int _snd_cmipci_uswitch_put(struct snd_kcontrol *kcontrol,
                val = inb(cm->iobase + args->reg);
        else
                val = snd_cmipci_read(cm, args->reg);
-       change = (val & args->mask) != (ucontrol->value.integer.value[0] ? args->mask : 0);
+       change = (val & args->mask) != (ucontrol->value.integer.value[0] ? 
+                       args->mask_on : (args->mask & ~args->mask_on));
        if (change) {
                val &= ~args->mask;
                if (ucontrol->value.integer.value[0])
@@ -2632,46 +2624,40 @@ static void __devinit query_chip(struct cmipci *cm)
        if (! detect) {
                /* check reg 08h, bit 24-28 */
                detect = snd_cmipci_read(cm, CM_REG_CHFORMAT) & CM_CHIP_MASK1;
-               if (! detect) {
+               switch (detect) {
+               case 0:
                        cm->chip_version = 33;
-                       cm->max_channels = 2;
                        if (cm->do_soft_ac3)
                                cm->can_ac3_sw = 1;
                        else
                                cm->can_ac3_hw = 1;
-                       cm->has_dual_dac = 1;
-               } else {
+                       break;
+               case 1:
                        cm->chip_version = 37;
-                       cm->max_channels = 2;
                        cm->can_ac3_hw = 1;
-                       cm->has_dual_dac = 1;
+                       break;
+               default:
+                       cm->chip_version = 39;
+                       cm->can_ac3_hw = 1;
+                       break;
                }
+               cm->max_channels = 2;
        } else {
-               /* check reg 0Ch, bit 26 */
-               if (detect & CM_CHIP_8768) {
-                       cm->chip_version = 68;
-                       cm->max_channels = 8;
-                       cm->can_ac3_hw = 1;
-                       cm->has_dual_dac = 1;
-                       cm->can_multi_ch = 1;
-               } else if (detect & CM_CHIP_055) {
-                       cm->chip_version = 55;
-                       cm->max_channels = 6;
-                       cm->can_ac3_hw = 1;
-                       cm->has_dual_dac = 1;
-                       cm->can_multi_ch = 1;
-               } else if (detect & CM_CHIP_039) {
+               if (detect & CM_CHIP_039) {
                        cm->chip_version = 39;
                        if (detect & CM_CHIP_039_6CH) /* 4 or 6 channels */
                                cm->max_channels = 6;
                        else
                                cm->max_channels = 4;
-                       cm->can_ac3_hw = 1;
-                       cm->has_dual_dac = 1;
-                       cm->can_multi_ch = 1;
+               } else if (detect & CM_CHIP_8768) {
+                       cm->chip_version = 68;
+                       cm->max_channels = 8;
                } else {
-                       printk(KERN_ERR "chip %x version not supported\n", detect);
+                       cm->chip_version = 55;
+                       cm->max_channels = 6;
                }
+               cm->can_ac3_hw = 1;
+               cm->can_multi_ch = 1;
        }
 }
 
@@ -2778,10 +2764,17 @@ static int __devinit snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
        struct snd_opl3 *opl3;
        int err;
 
-       /* first try FM regs in PCI port range */
-       iosynth = cm->iobase + CM_REG_FM_PCI;
-       err = snd_opl3_create(cm->card, iosynth, iosynth + 2,
-                             OPL3_HW_OPL3, 1, &opl3);
+       if (!fm_port)
+               goto disable_fm;
+
+       if (cm->chip_version > 33) {
+               /* first try FM regs in PCI port range */
+               iosynth = cm->iobase + CM_REG_FM_PCI;
+               err = snd_opl3_create(cm->card, iosynth, iosynth + 2,
+                                     OPL3_HW_OPL3, 1, &opl3);
+       } else {
+               err = -EIO;
+       }
        if (err < 0) {
                /* then try legacy ports */
                val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK;
@@ -2792,7 +2785,7 @@ static int __devinit snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
                case 0x3C8: val |= CM_FMSEL_3C8; break;
                case 0x388: val |= CM_FMSEL_388; break;
                default:
-                           return 0;
+                       goto disable_fm;
                }
                snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
                /* enable FM */
@@ -2802,11 +2795,7 @@ static int __devinit snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
                                    OPL3_HW_OPL3, 0, &opl3) < 0) {
                        printk(KERN_ERR "cmipci: no OPL device at %#lx, "
                               "skipping...\n", iosynth);
-                       /* disable FM */
-                       snd_cmipci_write(cm, CM_REG_LEGACY_CTRL,
-                                        val & ~CM_FMSEL_MASK);
-                       snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
-                       return 0;
+                       goto disable_fm;
                }
        }
        if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
@@ -2814,6 +2803,11 @@ static int __devinit snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
                return err;
        }
        return 0;
+
+ disable_fm:
+       snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_FMSEL_MASK);
+       snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
+       return 0;
 }
 
 static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
@@ -2824,9 +2818,9 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
        static struct snd_device_ops ops = {
                .dev_free =     snd_cmipci_dev_free,
        };
-       unsigned int val = 0;
+       unsigned int val;
        long iomidi;
-       int integrated_midi;
+       int integrated_midi = 0;
        int pcm_index, pcm_spdif_index;
        static struct pci_device_id intel_82437vx[] = {
                { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
@@ -2862,7 +2856,7 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
        cm->iobase = pci_resource_start(pci, 0);
 
        if (request_irq(pci->irq, snd_cmipci_interrupt,
-                       IRQF_DISABLED|IRQF_SHARED, card->driver, cm)) {
+                       IRQF_SHARED, card->driver, cm)) {
                snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
                snd_cmipci_free(cm);
                return -EBUSY;
@@ -2926,15 +2920,54 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
                break;
        }
 
+       sprintf(card->shortname, "C-Media %s", card->driver);
+       if (cm->chip_version < 68) {
+               val = pci->device < 0x110 ? 8338 : 8738;
+               sprintf(card->longname,
+                       "C-Media CMI%d (model %d) at 0x%lx, irq %i",
+                       val, cm->chip_version, cm->iobase, cm->irq);
+       } else {
+               switch (snd_cmipci_read_b(cm, CM_REG_INT_HLDCLR + 3) & 0x03) {
+               case 0:
+                       val = 8769;
+                       break;
+               case 2:
+                       val = 8762;
+                       break;
+               default:
+                       switch ((pci->subsystem_vendor << 16) |
+                               pci->subsystem_device) {
+                       case 0x13f69761:
+                       case 0x584d3741:
+                       case 0x584d3751:
+                       case 0x584d3761:
+                       case 0x584d3771:
+                       case 0x72848384:
+                               val = 8770;
+                               break;
+                       default:
+                               val = 8768;
+                               break;
+                       }
+               }
+               sprintf(card->longname, "C-Media CMI%d at 0x%lx, irq %i",
+                       val, cm->iobase, cm->irq);
+       }
+
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, cm, &ops)) < 0) {
                snd_cmipci_free(cm);
                return err;
        }
 
-       integrated_midi = snd_cmipci_read_b(cm, CM_REG_MPU_PCI) != 0xff;
-       if (integrated_midi && mpu_port[dev] == 1)
-               iomidi = cm->iobase + CM_REG_MPU_PCI;
-       else {
+       val = 0;
+       if (cm->chip_version > 33 && mpu_port[dev] == 1) {
+               val = snd_cmipci_read_b(cm, CM_REG_MPU_PCI + 1);
+               if (val != 0x00 && val != 0xff) {
+                       iomidi = cm->iobase + CM_REG_MPU_PCI;
+                       integrated_midi = 1;
+               }
+       }
+       if (!integrated_midi) {
                iomidi = mpu_port[dev];
                switch (iomidi) {
                case 0x320: val = CM_VMPU_320; break;
@@ -2951,8 +2984,11 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
                }
        }
 
-       if ((err = snd_cmipci_create_fm(cm, fm_port[dev])) < 0)
-               return err;
+       if (cm->chip_version < 68) {
+               err = snd_cmipci_create_fm(cm, fm_port[dev]);
+               if (err < 0)
+                       return err;
+       }
 
        /* reset mixer */
        snd_cmipci_mixer_write(cm, 0, 0);
@@ -2964,11 +3000,9 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
        if ((err = snd_cmipci_pcm_new(cm, pcm_index)) < 0)
                return err;
        pcm_index++;
-       if (cm->has_dual_dac) {
-               if ((err = snd_cmipci_pcm2_new(cm, pcm_index)) < 0)
-                       return err;
-               pcm_index++;
-       }
+       if ((err = snd_cmipci_pcm2_new(cm, pcm_index)) < 0)
+               return err;
+       pcm_index++;
        if (cm->can_ac3_hw || cm->can_ac3_sw) {
                pcm_spdif_index = pcm_index;
                if ((err = snd_cmipci_pcm_spdif_new(cm, pcm_index)) < 0)
@@ -3052,15 +3086,6 @@ static int __devinit snd_cmipci_probe(struct pci_dev *pci,
        }
        card->private_data = cm;
 
-       sprintf(card->shortname, "C-Media PCI %s", card->driver);
-       sprintf(card->longname, "%s (model %d) at 0x%lx, irq %i",
-               card->shortname,
-               cm->chip_version,
-               cm->iobase,
-               cm->irq);
-
-       //snd_printd("%s is detected\n", card->longname);
-
        if ((err = snd_card_register(card)) < 0) {
                snd_card_free(card);
                return err;