.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for C-Media CMI8338 and 8738 PCI soundcards. |
---|
3 | 4 | * Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de> |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify |
---|
6 | | - * it under the terms of the GNU General Public License as published by |
---|
7 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
8 | | - * (at your option) any later version. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, |
---|
11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | | - * GNU General Public License for more details. |
---|
14 | | - * |
---|
15 | | - * You should have received a copy of the GNU General Public License |
---|
16 | | - * along with this program; if not, write to the Free Software |
---|
17 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | 5 | */ |
---|
19 | 6 | |
---|
20 | 7 | /* Does not work. Warning may block system in capture mode */ |
---|
.. | .. |
---|
55 | 42 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
---|
56 | 43 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
---|
57 | 44 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */ |
---|
58 | | -static long mpu_port[SNDRV_CARDS]; |
---|
| 45 | +static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1}; |
---|
59 | 46 | static long fm_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1}; |
---|
60 | 47 | static bool soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1}; |
---|
61 | 48 | #ifdef SUPPORT_JOYSTICK |
---|
.. | .. |
---|
315 | 302 | #define CM_MICGAINZ 0x01 /* mic boost */ |
---|
316 | 303 | #define CM_MICGAINZ_SHIFT 0 |
---|
317 | 304 | |
---|
318 | | -#define CM_REG_MIXER3 0x24 |
---|
319 | 305 | #define CM_REG_AUX_VOL 0x26 |
---|
320 | 306 | #define CM_VAUXL_MASK 0xf0 |
---|
321 | 307 | #define CM_VAUXR_MASK 0x0f |
---|
.. | .. |
---|
599 | 585 | * calculate frequency |
---|
600 | 586 | */ |
---|
601 | 587 | |
---|
602 | | -static unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 }; |
---|
| 588 | +static const unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 }; |
---|
603 | 589 | |
---|
604 | 590 | static unsigned int snd_cmipci_rate_freq(unsigned int rate) |
---|
605 | 591 | { |
---|
.. | .. |
---|
679 | 665 | } |
---|
680 | 666 | #endif /* USE_VAR48KRATE */ |
---|
681 | 667 | |
---|
682 | | -static int snd_cmipci_hw_params(struct snd_pcm_substream *substream, |
---|
683 | | - struct snd_pcm_hw_params *hw_params) |
---|
684 | | -{ |
---|
685 | | - return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
---|
686 | | -} |
---|
687 | | - |
---|
688 | 668 | static int snd_cmipci_playback2_hw_params(struct snd_pcm_substream *substream, |
---|
689 | 669 | struct snd_pcm_hw_params *hw_params) |
---|
690 | 670 | { |
---|
.. | .. |
---|
699 | 679 | cm->opened[CM_CH_PLAY] = CM_OPEN_PLAYBACK_MULTI; |
---|
700 | 680 | mutex_unlock(&cm->open_mutex); |
---|
701 | 681 | } |
---|
702 | | - return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
---|
| 682 | + return 0; |
---|
703 | 683 | } |
---|
704 | 684 | |
---|
705 | 685 | static void snd_cmipci_ch_reset(struct cmipci *cm, int ch) |
---|
.. | .. |
---|
708 | 688 | snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset); |
---|
709 | 689 | snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset); |
---|
710 | 690 | udelay(10); |
---|
711 | | -} |
---|
712 | | - |
---|
713 | | -static int snd_cmipci_hw_free(struct snd_pcm_substream *substream) |
---|
714 | | -{ |
---|
715 | | - return snd_pcm_lib_free_pages(substream); |
---|
716 | 691 | } |
---|
717 | 692 | |
---|
718 | 693 | |
---|
.. | .. |
---|
1384 | 1359 | setup_spdif_playback(cm, substream, 0, 0); |
---|
1385 | 1360 | restore_mixer_state(cm); |
---|
1386 | 1361 | snd_cmipci_silence_hack(cm, &cm->channel[0]); |
---|
1387 | | - return snd_cmipci_hw_free(substream); |
---|
| 1362 | + return 0; |
---|
1388 | 1363 | } |
---|
1389 | 1364 | |
---|
1390 | 1365 | static int snd_cmipci_playback2_hw_free(struct snd_pcm_substream *substream) |
---|
1391 | 1366 | { |
---|
1392 | 1367 | struct cmipci *cm = snd_pcm_substream_chip(substream); |
---|
1393 | 1368 | snd_cmipci_silence_hack(cm, &cm->channel[1]); |
---|
1394 | | - return snd_cmipci_hw_free(substream); |
---|
| 1369 | + return 0; |
---|
1395 | 1370 | } |
---|
1396 | 1371 | |
---|
1397 | 1372 | /* capture */ |
---|
.. | .. |
---|
1433 | 1408 | snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); |
---|
1434 | 1409 | spin_unlock_irq(&cm->reg_lock); |
---|
1435 | 1410 | |
---|
1436 | | - return snd_cmipci_hw_free(subs); |
---|
| 1411 | + return 0; |
---|
1437 | 1412 | } |
---|
1438 | 1413 | |
---|
1439 | 1414 | |
---|
.. | .. |
---|
1841 | 1816 | static const struct snd_pcm_ops snd_cmipci_playback_ops = { |
---|
1842 | 1817 | .open = snd_cmipci_playback_open, |
---|
1843 | 1818 | .close = snd_cmipci_playback_close, |
---|
1844 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
1845 | | - .hw_params = snd_cmipci_hw_params, |
---|
1846 | 1819 | .hw_free = snd_cmipci_playback_hw_free, |
---|
1847 | 1820 | .prepare = snd_cmipci_playback_prepare, |
---|
1848 | 1821 | .trigger = snd_cmipci_playback_trigger, |
---|
.. | .. |
---|
1852 | 1825 | static const struct snd_pcm_ops snd_cmipci_capture_ops = { |
---|
1853 | 1826 | .open = snd_cmipci_capture_open, |
---|
1854 | 1827 | .close = snd_cmipci_capture_close, |
---|
1855 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
1856 | | - .hw_params = snd_cmipci_hw_params, |
---|
1857 | | - .hw_free = snd_cmipci_hw_free, |
---|
1858 | 1828 | .prepare = snd_cmipci_capture_prepare, |
---|
1859 | 1829 | .trigger = snd_cmipci_capture_trigger, |
---|
1860 | 1830 | .pointer = snd_cmipci_capture_pointer, |
---|
.. | .. |
---|
1863 | 1833 | static const struct snd_pcm_ops snd_cmipci_playback2_ops = { |
---|
1864 | 1834 | .open = snd_cmipci_playback2_open, |
---|
1865 | 1835 | .close = snd_cmipci_playback2_close, |
---|
1866 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
1867 | 1836 | .hw_params = snd_cmipci_playback2_hw_params, |
---|
1868 | 1837 | .hw_free = snd_cmipci_playback2_hw_free, |
---|
1869 | 1838 | .prepare = snd_cmipci_capture_prepare, /* channel B */ |
---|
.. | .. |
---|
1874 | 1843 | static const struct snd_pcm_ops snd_cmipci_playback_spdif_ops = { |
---|
1875 | 1844 | .open = snd_cmipci_playback_spdif_open, |
---|
1876 | 1845 | .close = snd_cmipci_playback_spdif_close, |
---|
1877 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
1878 | | - .hw_params = snd_cmipci_hw_params, |
---|
1879 | 1846 | .hw_free = snd_cmipci_playback_hw_free, |
---|
1880 | 1847 | .prepare = snd_cmipci_playback_spdif_prepare, /* set up rate */ |
---|
1881 | 1848 | .trigger = snd_cmipci_playback_trigger, |
---|
.. | .. |
---|
1885 | 1852 | static const struct snd_pcm_ops snd_cmipci_capture_spdif_ops = { |
---|
1886 | 1853 | .open = snd_cmipci_capture_spdif_open, |
---|
1887 | 1854 | .close = snd_cmipci_capture_spdif_close, |
---|
1888 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
1889 | | - .hw_params = snd_cmipci_hw_params, |
---|
1890 | 1855 | .hw_free = snd_cmipci_capture_spdif_hw_free, |
---|
1891 | 1856 | .prepare = snd_cmipci_capture_spdif_prepare, |
---|
1892 | 1857 | .trigger = snd_cmipci_capture_trigger, |
---|
.. | .. |
---|
1914 | 1879 | strcpy(pcm->name, "C-Media PCI DAC/ADC"); |
---|
1915 | 1880 | cm->pcm = pcm; |
---|
1916 | 1881 | |
---|
1917 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
---|
1918 | | - snd_dma_pci_data(cm->pci), 64*1024, 128*1024); |
---|
| 1882 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
---|
| 1883 | + &cm->pci->dev, 64*1024, 128*1024); |
---|
1919 | 1884 | |
---|
1920 | 1885 | return 0; |
---|
1921 | 1886 | } |
---|
.. | .. |
---|
1936 | 1901 | strcpy(pcm->name, "C-Media PCI 2nd DAC"); |
---|
1937 | 1902 | cm->pcm2 = pcm; |
---|
1938 | 1903 | |
---|
1939 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
---|
1940 | | - snd_dma_pci_data(cm->pci), 64*1024, 128*1024); |
---|
| 1904 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
---|
| 1905 | + &cm->pci->dev, 64*1024, 128*1024); |
---|
1941 | 1906 | |
---|
1942 | 1907 | return 0; |
---|
1943 | 1908 | } |
---|
.. | .. |
---|
1959 | 1924 | strcpy(pcm->name, "C-Media PCI IEC958"); |
---|
1960 | 1925 | cm->pcm_spdif = pcm; |
---|
1961 | 1926 | |
---|
1962 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
---|
1963 | | - snd_dma_pci_data(cm->pci), 64*1024, 128*1024); |
---|
| 1927 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
---|
| 1928 | + &cm->pci->dev, 64*1024, 128*1024); |
---|
1964 | 1929 | |
---|
1965 | 1930 | err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
---|
1966 | 1931 | snd_pcm_alt_chmaps, cm->max_channels, 0, |
---|
.. | .. |
---|
2290 | 2255 | } |
---|
2291 | 2256 | |
---|
2292 | 2257 | |
---|
2293 | | -static struct snd_kcontrol_new snd_cmipci_mixers[] = { |
---|
| 2258 | +static const struct snd_kcontrol_new snd_cmipci_mixers[] = { |
---|
2294 | 2259 | CMIPCI_SB_VOL_STEREO("Master Playback Volume", SB_DSP4_MASTER_DEV, 3, 31), |
---|
2295 | 2260 | CMIPCI_MIXER_SW_MONO("3D Control - Switch", CM_REG_MIXER1, CM_X3DEN_SHIFT, 0), |
---|
2296 | 2261 | CMIPCI_SB_VOL_STEREO("PCM Playback Volume", SB_DSP4_PCM_DEV, 3, 31), |
---|
.. | .. |
---|
2601 | 2566 | } |
---|
2602 | 2567 | |
---|
2603 | 2568 | /* both for CM8338/8738 */ |
---|
2604 | | -static struct snd_kcontrol_new snd_cmipci_mixer_switches[] = { |
---|
| 2569 | +static const struct snd_kcontrol_new snd_cmipci_mixer_switches[] = { |
---|
2605 | 2570 | DEFINE_MIXER_SWITCH("Four Channel Mode", fourch), |
---|
2606 | 2571 | { |
---|
2607 | 2572 | .name = "Line-In Mode", |
---|
.. | .. |
---|
2613 | 2578 | }; |
---|
2614 | 2579 | |
---|
2615 | 2580 | /* for non-multichannel chips */ |
---|
2616 | | -static struct snd_kcontrol_new snd_cmipci_nomulti_switch = |
---|
| 2581 | +static const struct snd_kcontrol_new snd_cmipci_nomulti_switch = |
---|
2617 | 2582 | DEFINE_MIXER_SWITCH("Exchange DAC", exchange_dac); |
---|
2618 | 2583 | |
---|
2619 | 2584 | /* only for CM8738 */ |
---|
2620 | | -static struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] = { |
---|
| 2585 | +static const struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] = { |
---|
2621 | 2586 | #if 0 /* controlled in pcm device */ |
---|
2622 | 2587 | DEFINE_MIXER_SWITCH("IEC958 In Record", spdif_in), |
---|
2623 | 2588 | DEFINE_MIXER_SWITCH("IEC958 Out", spdif_out), |
---|
.. | .. |
---|
2639 | 2604 | }; |
---|
2640 | 2605 | |
---|
2641 | 2606 | /* only for model 033/037 */ |
---|
2642 | | -static struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] = { |
---|
| 2607 | +static const struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] = { |
---|
2643 | 2608 | DEFINE_MIXER_SWITCH("IEC958 Mix Analog", spdif_dac_out), |
---|
2644 | 2609 | DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase), |
---|
2645 | 2610 | DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel1), |
---|
2646 | 2611 | }; |
---|
2647 | 2612 | |
---|
2648 | 2613 | /* only for model 039 or later */ |
---|
2649 | | -static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] = { |
---|
| 2614 | +static const struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] = { |
---|
2650 | 2615 | DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel2), |
---|
2651 | 2616 | DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase2), |
---|
2652 | 2617 | { |
---|
.. | .. |
---|
2659 | 2624 | }; |
---|
2660 | 2625 | |
---|
2661 | 2626 | /* card control switches */ |
---|
2662 | | -static struct snd_kcontrol_new snd_cmipci_modem_switch = |
---|
| 2627 | +static const struct snd_kcontrol_new snd_cmipci_modem_switch = |
---|
2663 | 2628 | DEFINE_CARD_SWITCH("Modem", modem); |
---|
2664 | 2629 | |
---|
2665 | 2630 | |
---|
2666 | 2631 | static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device) |
---|
2667 | 2632 | { |
---|
2668 | 2633 | struct snd_card *card; |
---|
2669 | | - struct snd_kcontrol_new *sw; |
---|
| 2634 | + const struct snd_kcontrol_new *sw; |
---|
2670 | 2635 | struct snd_kcontrol *kctl; |
---|
2671 | 2636 | unsigned int idx; |
---|
2672 | 2637 | int err; |
---|
.. | .. |
---|
2792 | 2757 | |
---|
2793 | 2758 | static void snd_cmipci_proc_init(struct cmipci *cm) |
---|
2794 | 2759 | { |
---|
2795 | | - struct snd_info_entry *entry; |
---|
2796 | | - |
---|
2797 | | - if (! snd_card_proc_new(cm->card, "cmipci", &entry)) |
---|
2798 | | - snd_info_set_text_ops(entry, cm, snd_cmipci_proc_read); |
---|
| 2760 | + snd_card_ro_proc_new(cm->card, "cmipci", cm, snd_cmipci_proc_read); |
---|
2799 | 2761 | } |
---|
2800 | 2762 | |
---|
2801 | 2763 | static const struct pci_device_id snd_cmipci_ids[] = { |
---|
.. | .. |
---|
2863 | 2825 | #ifdef SUPPORT_JOYSTICK |
---|
2864 | 2826 | static int snd_cmipci_create_gameport(struct cmipci *cm, int dev) |
---|
2865 | 2827 | { |
---|
2866 | | - static int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */ |
---|
| 2828 | + static const int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */ |
---|
2867 | 2829 | struct gameport *gp; |
---|
2868 | 2830 | struct resource *r = NULL; |
---|
2869 | 2831 | int i, io_port = 0; |
---|
.. | .. |
---|
3013 | 2975 | { |
---|
3014 | 2976 | struct cmipci *cm; |
---|
3015 | 2977 | int err; |
---|
3016 | | - static struct snd_device_ops ops = { |
---|
| 2978 | + static const struct snd_device_ops ops = { |
---|
3017 | 2979 | .dev_free = snd_cmipci_dev_free, |
---|
3018 | 2980 | }; |
---|
3019 | 2981 | unsigned int val; |
---|
.. | .. |
---|
3061 | 3023 | return -EBUSY; |
---|
3062 | 3024 | } |
---|
3063 | 3025 | cm->irq = pci->irq; |
---|
| 3026 | + card->sync_irq = cm->irq; |
---|
3064 | 3027 | |
---|
3065 | 3028 | pci_set_master(cm->pci); |
---|
3066 | 3029 | |
---|
.. | .. |
---|
3168 | 3131 | if (cm->chip_version >= 39) { |
---|
3169 | 3132 | val = snd_cmipci_read_b(cm, CM_REG_MPU_PCI + 1); |
---|
3170 | 3133 | if (val != 0x00 && val != 0xff) { |
---|
3171 | | - iomidi = cm->iobase + CM_REG_MPU_PCI; |
---|
| 3134 | + if (mpu_port[dev]) |
---|
| 3135 | + iomidi = cm->iobase + CM_REG_MPU_PCI; |
---|
3172 | 3136 | integrated_midi = 1; |
---|
3173 | 3137 | } |
---|
3174 | 3138 | } |
---|
.. | .. |
---|
3324 | 3288 | /* |
---|
3325 | 3289 | * power management |
---|
3326 | 3290 | */ |
---|
3327 | | -static unsigned char saved_regs[] = { |
---|
| 3291 | +static const unsigned char saved_regs[] = { |
---|
3328 | 3292 | CM_REG_FUNCTRL1, CM_REG_CHFORMAT, CM_REG_LEGACY_CTRL, CM_REG_MISC_CTRL, |
---|
3329 | | - CM_REG_MIXER0, CM_REG_MIXER1, CM_REG_MIXER2, CM_REG_MIXER3, CM_REG_PLL, |
---|
| 3293 | + CM_REG_MIXER0, CM_REG_MIXER1, CM_REG_MIXER2, CM_REG_AUX_VOL, CM_REG_PLL, |
---|
3330 | 3294 | CM_REG_CH0_FRAME1, CM_REG_CH0_FRAME2, |
---|
3331 | 3295 | CM_REG_CH1_FRAME1, CM_REG_CH1_FRAME2, CM_REG_EXT_MISC, |
---|
3332 | 3296 | CM_REG_INT_STATUS, CM_REG_INT_HLDCLR, CM_REG_FUNCTRL0, |
---|
3333 | 3297 | }; |
---|
3334 | 3298 | |
---|
3335 | | -static unsigned char saved_mixers[] = { |
---|
| 3299 | +static const unsigned char saved_mixers[] = { |
---|
3336 | 3300 | SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1, |
---|
3337 | 3301 | SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1, |
---|
3338 | 3302 | SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1, |
---|
.. | .. |
---|
3351 | 3315 | |
---|
3352 | 3316 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
---|
3353 | 3317 | |
---|
3354 | | - snd_pcm_suspend_all(cm->pcm); |
---|
3355 | | - snd_pcm_suspend_all(cm->pcm2); |
---|
3356 | | - snd_pcm_suspend_all(cm->pcm_spdif); |
---|
3357 | | - |
---|
3358 | 3318 | /* save registers */ |
---|
3359 | 3319 | for (i = 0; i < ARRAY_SIZE(saved_regs); i++) |
---|
3360 | 3320 | cm->saved_regs[i] = snd_cmipci_read(cm, saved_regs[i]); |
---|