aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/cmipci.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/cmipci.c')
-rw-r--r--sound/pci/cmipci.c126
1 files changed, 71 insertions, 55 deletions
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 1eb3315d136..57e8e433d56 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -446,9 +446,6 @@ struct snd_stru_cmipci {
446 snd_kcontrol_t *mixer_res_ctl[CM_SAVED_MIXERS]; 446 snd_kcontrol_t *mixer_res_ctl[CM_SAVED_MIXERS];
447 int mixer_res_status[CM_SAVED_MIXERS]; 447 int mixer_res_status[CM_SAVED_MIXERS];
448 448
449 opl3_t *opl3;
450 snd_hwdep_t *opl3hwdep;
451
452 cmipci_pcm_t channel[2]; /* ch0 - DAC, ch1 - ADC or 2nd DAC */ 449 cmipci_pcm_t channel[2]; /* ch0 - DAC, ch1 - ADC or 2nd DAC */
453 450
454 /* external MIDI */ 451 /* external MIDI */
@@ -2686,8 +2683,7 @@ static int __devinit snd_cmipci_create_gameport(cmipci_t *cm, int dev)
2686 cm->gameport = gp = gameport_allocate_port(); 2683 cm->gameport = gp = gameport_allocate_port();
2687 if (!gp) { 2684 if (!gp) {
2688 printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n"); 2685 printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n");
2689 release_resource(r); 2686 release_and_free_resource(r);
2690 kfree_nocheck(r);
2691 return -ENOMEM; 2687 return -ENOMEM;
2692 } 2688 }
2693 gameport_set_name(gp, "C-Media Gameport"); 2689 gameport_set_name(gp, "C-Media Gameport");
@@ -2712,8 +2708,7 @@ static void snd_cmipci_free_gameport(cmipci_t *cm)
2712 cm->gameport = NULL; 2708 cm->gameport = NULL;
2713 2709
2714 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN); 2710 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
2715 release_resource(r); 2711 release_and_free_resource(r);
2716 kfree_nocheck(r);
2717 } 2712 }
2718} 2713}
2719#else 2714#else
@@ -2753,6 +2748,51 @@ static int snd_cmipci_dev_free(snd_device_t *device)
2753 return snd_cmipci_free(cm); 2748 return snd_cmipci_free(cm);
2754} 2749}
2755 2750
2751static int __devinit snd_cmipci_create_fm(cmipci_t *cm, long fm_port)
2752{
2753 long iosynth;
2754 unsigned int val;
2755 opl3_t *opl3;
2756 int err;
2757
2758 /* first try FM regs in PCI port range */
2759 iosynth = cm->iobase + CM_REG_FM_PCI;
2760 err = snd_opl3_create(cm->card, iosynth, iosynth + 2,
2761 OPL3_HW_OPL3, 1, &opl3);
2762 if (err < 0) {
2763 /* then try legacy ports */
2764 val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK;
2765 iosynth = fm_port;
2766 switch (iosynth) {
2767 case 0x3E8: val |= CM_FMSEL_3E8; break;
2768 case 0x3E0: val |= CM_FMSEL_3E0; break;
2769 case 0x3C8: val |= CM_FMSEL_3C8; break;
2770 case 0x388: val |= CM_FMSEL_388; break;
2771 default:
2772 return 0;
2773 }
2774 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2775 /* enable FM */
2776 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2777
2778 if (snd_opl3_create(cm->card, iosynth, iosynth + 2,
2779 OPL3_HW_OPL3, 0, &opl3) < 0) {
2780 printk(KERN_ERR "cmipci: no OPL device at %#lx, "
2781 "skipping...\n", iosynth);
2782 /* disable FM */
2783 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL,
2784 val & ~CM_FMSEL_MASK);
2785 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2786 return 0;
2787 }
2788 }
2789 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
2790 printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
2791 return err;
2792 }
2793 return 0;
2794}
2795
2756static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci, 2796static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2757 int dev, cmipci_t **rcmipci) 2797 int dev, cmipci_t **rcmipci)
2758{ 2798{
@@ -2762,8 +2802,8 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2762 .dev_free = snd_cmipci_dev_free, 2802 .dev_free = snd_cmipci_dev_free,
2763 }; 2803 };
2764 unsigned int val = 0; 2804 unsigned int val = 0;
2765 long iomidi = mpu_port[dev]; 2805 long iomidi;
2766 long iosynth = fm_port[dev]; 2806 int integrated_midi;
2767 int pcm_index, pcm_spdif_index; 2807 int pcm_index, pcm_spdif_index;
2768 static struct pci_device_id intel_82437vx[] = { 2808 static struct pci_device_id intel_82437vx[] = {
2769 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) }, 2809 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
@@ -2799,7 +2839,7 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2799 cm->iobase = pci_resource_start(pci, 0); 2839 cm->iobase = pci_resource_start(pci, 0);
2800 2840
2801 if (request_irq(pci->irq, snd_cmipci_interrupt, SA_INTERRUPT|SA_SHIRQ, card->driver, (void *)cm)) { 2841 if (request_irq(pci->irq, snd_cmipci_interrupt, SA_INTERRUPT|SA_SHIRQ, card->driver, (void *)cm)) {
2802 snd_printk("unable to grab IRQ %d\n", pci->irq); 2842 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2803 snd_cmipci_free(cm); 2843 snd_cmipci_free(cm);
2804 return -EBUSY; 2844 return -EBUSY;
2805 } 2845 }
@@ -2867,52 +2907,28 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2867 return err; 2907 return err;
2868 } 2908 }
2869 2909
2870 /* set MPU address */ 2910 integrated_midi = snd_cmipci_read_b(cm, CM_REG_MPU_PCI) != 0xff;
2871 switch (iomidi) { 2911 if (integrated_midi)
2872 case 0x320: val = CM_VMPU_320; break; 2912 iomidi = cm->iobase + CM_REG_MPU_PCI;
2873 case 0x310: val = CM_VMPU_310; break; 2913 else {
2874 case 0x300: val = CM_VMPU_300; break; 2914 iomidi = mpu_port[dev];
2875 case 0x330: val = CM_VMPU_330; break; 2915 switch (iomidi) {
2876 default: 2916 case 0x320: val = CM_VMPU_320; break;
2877 iomidi = 0; break; 2917 case 0x310: val = CM_VMPU_310; break;
2878 } 2918 case 0x300: val = CM_VMPU_300; break;
2879 if (iomidi > 0) { 2919 case 0x330: val = CM_VMPU_330; break;
2880 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val); 2920 default:
2881 /* enable UART */ 2921 iomidi = 0; break;
2882 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN); 2922 }
2883 } 2923 if (iomidi > 0) {
2884 2924 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2885 /* set FM address */ 2925 /* enable UART */
2886 val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK; 2926 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN);
2887 switch (iosynth) {
2888 case 0x3E8: val |= CM_FMSEL_3E8; break;
2889 case 0x3E0: val |= CM_FMSEL_3E0; break;
2890 case 0x3C8: val |= CM_FMSEL_3C8; break;
2891 case 0x388: val |= CM_FMSEL_388; break;
2892 default:
2893 iosynth = 0; break;
2894 }
2895 if (iosynth > 0) {
2896 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2897 /* enable FM */
2898 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2899
2900 if (snd_opl3_create(card, iosynth, iosynth + 2,
2901 OPL3_HW_OPL3, 0, &cm->opl3) < 0) {
2902 printk(KERN_ERR "cmipci: no OPL device at 0x%lx, skipping...\n", iosynth);
2903 iosynth = 0;
2904 } else {
2905 if ((err = snd_opl3_hwdep_new(cm->opl3, 0, 1, &cm->opl3hwdep)) < 0) {
2906 printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
2907 return err;
2908 }
2909 } 2927 }
2910 } 2928 }
2911 if (! iosynth) { 2929
2912 /* disable FM */ 2930 if ((err = snd_cmipci_create_fm(cm, fm_port[dev])) < 0)
2913 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val & ~CM_FMSEL_MASK); 2931 return err;
2914 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2915 }
2916 2932
2917 /* reset mixer */ 2933 /* reset mixer */
2918 snd_cmipci_mixer_write(cm, 0, 0); 2934 snd_cmipci_mixer_write(cm, 0, 0);
@@ -2941,7 +2957,7 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2941 2957
2942 if (iomidi > 0) { 2958 if (iomidi > 0) {
2943 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 2959 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
2944 iomidi, 0, 2960 iomidi, integrated_midi,
2945 cm->irq, 0, &cm->rmidi)) < 0) { 2961 cm->irq, 0, &cm->rmidi)) < 0) {
2946 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi); 2962 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi);
2947 } 2963 }