Changeset 679 for GPL/trunk/alsa-kernel/pci/cmipci.c
- Timestamp:
- Mar 18, 2021, 8:57:36 PM (4 years ago)
- Location:
- GPL/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk
- Property svn:mergeinfo changed
/GPL/branches/uniaud32-linux-3.2.102 (added) merged: 611-614 /GPL/branches/uniaud32-next (added) merged: 615-678
- Property svn:mergeinfo changed
-
GPL/trunk/alsa-kernel/pci/cmipci.c
r598 r679 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 */ 19 5 */ 6 20 7 /* Does not work. Warning may block system in capture mode */ 21 8 /* #define USE_VAR48KRATE */ 22 9 23 #include < asm/io.h>10 #include <linux/io.h> 24 11 #include <linux/delay.h> 25 12 #include <linux/interrupt.h> … … 28 15 #include <linux/slab.h> 29 16 #include <linux/gameport.h> 30 #include <linux/module param.h>17 #include <linux/module.h> 31 18 #include <linux/mutex.h> 32 19 #include <sound/core.h> … … 41 28 #include <sound/initval.h> 42 29 30 #ifdef TARGET_OS2 31 #define KBUILD_MODNAME "cmipci" 32 #endif 43 33 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); 44 34 MODULE_DESCRIPTION("C-Media CMI8x38 PCI"); … … 49 39 "{C-Media,CMI8338B}}"); 50 40 51 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))41 #if IS_REACHABLE(CONFIG_GAMEPORT) 52 42 #define SUPPORT_JOYSTICK 1 53 43 #endif … … 55 45 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 56 46 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 57 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */ 58 static long mpu_port[SNDRV_CARDS]; 47 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */ 59 48 #ifndef TARGET_OS2 49 static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1}; 60 50 static long fm_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1}; 61 static intsoft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};51 static bool soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1}; 62 52 #else 63 static long fm_port[SNDRV_CARDS] = {0x388, -1,-1,-1,-1,-1,-1,-1}; 64 static int soft_ac3[SNDRV_CARDS] = {0,1,1,1,1,1,1,1}; 53 static long mpu_port[SNDRV_CARDS] = {0,1,1,1,1,1,1,1}; 54 static long fm_port[SNDRV_CARDS] = {0,1,1,1,1,1,1,1}; 55 static bool soft_ac3[SNDRV_CARDS] = {0,1,1,1,1,1,1,1}; 65 56 #endif 66 57 #ifdef SUPPORT_JOYSTICK … … 74 65 module_param_array(enable, bool, NULL, 0444); 75 66 MODULE_PARM_DESC(enable, "Enable C-Media PCI soundcard."); 76 module_param_ array(mpu_port, long, NULL, 0444);67 module_param_hw_array(mpu_port, long, ioport, NULL, 0444); 77 68 MODULE_PARM_DESC(mpu_port, "MPU-401 port."); 78 module_param_ array(fm_port, long, NULL, 0444);69 module_param_hw_array(fm_port, long, ioport, NULL, 0444); 79 70 MODULE_PARM_DESC(fm_port, "FM port."); 80 71 module_param_array(soft_ac3, bool, NULL, 0444); 81 MODULE_PARM_DESC(soft_ac3, "Sof ware-conversion of raw SPDIF packets (model 033 only).");72 MODULE_PARM_DESC(soft_ac3, "Software-conversion of raw SPDIF packets (model 033 only)."); 82 73 #ifdef SUPPORT_JOYSTICK 83 module_param_ array(joystick_port, int, NULL, 0444);74 module_param_hw_array(joystick_port, int, ioport, NULL, 0444); 84 75 MODULE_PARM_DESC(joystick_port, "Joystick port address."); 85 76 #endif … … 510 501 spinlock_t reg_lock; 511 502 512 #ifdef CONFIG_PM 503 #ifdef CONFIG_PM_SLEEP 513 504 unsigned int saved_regs[0x20]; 514 505 unsigned char saved_mixers[0x20]; … … 605 596 */ 606 597 607 static unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 };598 static const unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 }; 608 599 609 600 static unsigned int snd_cmipci_rate_freq(unsigned int rate) … … 662 653 663 654 /* 664 * Program pll register bits, I assume that the 8 registers 0xf8 up to 0xff665 * are mapped onto the 8 ADC/DAC sampling frequency which can be cho osen655 * Program pll register bits, I assume that the 8 registers 0xf8 up to 0xff 656 * are mapped onto the 8 ADC/DAC sampling frequency which can be chosen 666 657 * at the register CM_REG_FUNCTRL1 (0x04). 667 658 * Problem: other ways are also possible (any information about that?) … … 672 663 /* 673 664 * Guess that this programs at reg. 0x04 the pos 15:13/12:10 674 * for DSFC/ASFC (000 up to 111).665 * for DSFC/ASFC (000 up to 111). 675 666 */ 676 667 … … 684 675 } 685 676 #endif /* USE_VAR48KRATE */ 686 687 static int snd_cmipci_hw_params(struct snd_pcm_substream *substream,688 struct snd_pcm_hw_params *hw_params)689 {690 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));691 }692 677 693 678 static int snd_cmipci_playback2_hw_params(struct snd_pcm_substream *substream, … … 705 690 mutex_unlock(&cm->open_mutex); 706 691 } 707 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));692 return 0; 708 693 } 709 694 … … 716 701 } 717 702 718 static int snd_cmipci_hw_free(struct snd_pcm_substream *substream) 719 { 720 return snd_pcm_lib_free_pages(substream); 721 } 722 723 724 /* 725 */ 726 727 static unsigned int hw_channels[] = {1, 2, 4, 6, 8}; 728 static struct snd_pcm_hw_constraint_list hw_constraints_channels_4 = { 703 704 /* 705 */ 706 707 static const unsigned int hw_channels[] = {1, 2, 4, 6, 8}; 708 static const struct snd_pcm_hw_constraint_list hw_constraints_channels_4 = { 729 709 .count = 3, 730 710 .list = hw_channels, 731 711 .mask = 0, 732 712 }; 733 static struct snd_pcm_hw_constraint_list hw_constraints_channels_6 = {713 static const struct snd_pcm_hw_constraint_list hw_constraints_channels_6 = { 734 714 .count = 4, 735 715 .list = hw_channels, 736 716 .mask = 0, 737 717 }; 738 static struct snd_pcm_hw_constraint_list hw_constraints_channels_8 = {718 static const struct snd_pcm_hw_constraint_list hw_constraints_channels_8 = { 739 719 .count = 5, 740 720 .list = hw_channels, … … 802 782 rec->fmt |= 0x01; 803 783 if (rec->is_dac && set_dac_channels(cm, rec, runtime->channels) < 0) { 804 snd_printd("cannot set dac channels\n");784 dev_dbg(cm->card->dev, "cannot set dac channels\n"); 805 785 return -EINVAL; 806 786 } … … 833 813 cm->ctrl |= val; 834 814 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); 835 / /snd_printd("cmipci: functrl0 = %08x\n", cm->ctrl);815 /* dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl); */ 836 816 837 817 /* set sample rate */ … … 856 836 } 857 837 snd_cmipci_write(cm, CM_REG_FUNCTRL1, val); 858 //snd_printd("cmipci:functrl1 = %08x\n", val);838 dev_dbg(cm->card->dev, "functrl1 = %08x\n", val); 859 839 860 840 /* set format */ … … 872 852 } 873 853 snd_cmipci_write(cm, CM_REG_CHFORMAT, val); 874 //snd_printd("cmipci:chformat = %08x\n", val);854 dev_dbg(cm->card->dev, "chformat = %08x\n", val); 875 855 876 856 if (!rec->is_dac && cm->chip_version) { … … 910 890 /* enable channel */ 911 891 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); 912 //snd_printd("cmipci:functrl0 = %08x\n", cm->ctrl);892 dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl); 913 893 break; 914 894 case SNDRV_PCM_TRIGGER_STOP: … … 957 937 if (rem < rec->dma_size) 958 938 goto ok; 959 } 960 printk(KERN_ERR "cmipci:invalid PCM pointer: %#x\n", rem);939 } 940 dev_err(cm->card->dev, "invalid PCM pointer: %#x\n", rem); 961 941 return SNDRV_PCM_POS_XRUN; 962 942 ok: … … 1051 1031 } 1052 1032 1053 static struct snd_kcontrol_new snd_cmipci_spdif_default __devinitdata=1033 static const struct snd_kcontrol_new snd_cmipci_spdif_default = 1054 1034 { 1055 1035 .iface = SNDRV_CTL_ELEM_IFACE_PCM, … … 1078 1058 } 1079 1059 1080 static struct snd_kcontrol_new snd_cmipci_spdif_mask __devinitdata=1060 static const struct snd_kcontrol_new snd_cmipci_spdif_mask = 1081 1061 { 1082 1062 .access = SNDRV_CTL_ELEM_ACCESS_READ, … … 1125 1105 } 1126 1106 1127 static struct snd_kcontrol_new snd_cmipci_spdif_stream __devinitdata=1107 static const struct snd_kcontrol_new snd_cmipci_spdif_stream = 1128 1108 { 1129 1109 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, … … 1145 1125 unsigned int i; 1146 1126 1147 val = kmalloc(sizeof(*val), GFP_ ATOMIC);1127 val = kmalloc(sizeof(*val), GFP_KERNEL); 1148 1128 if (!val) 1149 1129 return -ENOMEM; … … 1308 1288 substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE && 1309 1289 substream->runtime->channels == 2); 1310 if (do_spdif && cm->can_ac3_hw) 1290 if (do_spdif && cm->can_ac3_hw) 1311 1291 do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO; 1312 1292 if ((err = setup_spdif_playback(cm, substream, do_spdif, do_ac3)) < 0) … … 1321 1301 int err, do_ac3; 1322 1302 1323 if (cm->can_ac3_hw) 1303 if (cm->can_ac3_hw) 1324 1304 do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO; 1325 1305 else … … 1390 1370 restore_mixer_state(cm); 1391 1371 snd_cmipci_silence_hack(cm, &cm->channel[0]); 1392 return snd_cmipci_hw_free(substream);1372 return 0; 1393 1373 } 1394 1374 … … 1397 1377 struct cmipci *cm = snd_pcm_substream_chip(substream); 1398 1378 snd_cmipci_silence_hack(cm, &cm->channel[1]); 1399 return snd_cmipci_hw_free(substream);1379 return 0; 1400 1380 } 1401 1381 … … 1439 1419 spin_unlock_irq(&cm->reg_lock); 1440 1420 1441 return snd_cmipci_hw_free(subs);1421 return 0; 1442 1422 } 1443 1423 … … 1483 1463 1484 1464 /* playback on channel A */ 1485 static struct snd_pcm_hardware snd_cmipci_playback =1465 static const struct snd_pcm_hardware snd_cmipci_playback = 1486 1466 { 1487 1467 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | … … 1503 1483 1504 1484 /* capture on channel B */ 1505 static struct snd_pcm_hardware snd_cmipci_capture =1485 static const struct snd_pcm_hardware snd_cmipci_capture = 1506 1486 { 1507 1487 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | … … 1523 1503 1524 1504 /* playback on channel B - stereo 16bit only? */ 1525 static struct snd_pcm_hardware snd_cmipci_playback2 =1505 static const struct snd_pcm_hardware snd_cmipci_playback2 = 1526 1506 { 1527 1507 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | … … 1543 1523 1544 1524 /* spdif playback on channel A */ 1545 static struct snd_pcm_hardware snd_cmipci_playback_spdif =1525 static const struct snd_pcm_hardware snd_cmipci_playback_spdif = 1546 1526 { 1547 1527 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | … … 1563 1543 1564 1544 /* spdif playback on channel A (32bit, IEC958 subframes) */ 1565 static struct snd_pcm_hardware snd_cmipci_playback_iec958_subframe =1545 static const struct snd_pcm_hardware snd_cmipci_playback_iec958_subframe = 1566 1546 { 1567 1547 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | … … 1583 1563 1584 1564 /* spdif capture on channel B */ 1585 static struct snd_pcm_hardware snd_cmipci_capture_spdif =1565 static const struct snd_pcm_hardware snd_cmipci_capture_spdif = 1586 1566 { 1587 1567 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | … … 1603 1583 }; 1604 1584 1605 static unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050,1585 static const unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050, 1606 1586 32000, 44100, 48000, 88200, 96000, 128000 }; 1607 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {1587 static const struct snd_pcm_hw_constraint_list hw_constraints_rates = { 1608 1588 .count = ARRAY_SIZE(rate_constraints), 1609 1589 .list = rate_constraints, … … 1844 1824 */ 1845 1825 1846 static struct snd_pcm_ops snd_cmipci_playback_ops = {1826 static const struct snd_pcm_ops snd_cmipci_playback_ops = { 1847 1827 .open = snd_cmipci_playback_open, 1848 1828 .close = snd_cmipci_playback_close, 1849 .ioctl = snd_pcm_lib_ioctl,1850 .hw_params = snd_cmipci_hw_params,1851 1829 .hw_free = snd_cmipci_playback_hw_free, 1852 1830 .prepare = snd_cmipci_playback_prepare, … … 1855 1833 }; 1856 1834 1857 static struct snd_pcm_ops snd_cmipci_capture_ops = {1835 static const struct snd_pcm_ops snd_cmipci_capture_ops = { 1858 1836 .open = snd_cmipci_capture_open, 1859 1837 .close = snd_cmipci_capture_close, 1860 .ioctl = snd_pcm_lib_ioctl,1861 .hw_params = snd_cmipci_hw_params,1862 .hw_free = snd_cmipci_hw_free,1863 1838 .prepare = snd_cmipci_capture_prepare, 1864 1839 .trigger = snd_cmipci_capture_trigger, … … 1866 1841 }; 1867 1842 1868 static struct snd_pcm_ops snd_cmipci_playback2_ops = {1843 static const struct snd_pcm_ops snd_cmipci_playback2_ops = { 1869 1844 .open = snd_cmipci_playback2_open, 1870 1845 .close = snd_cmipci_playback2_close, 1871 .ioctl = snd_pcm_lib_ioctl,1872 1846 .hw_params = snd_cmipci_playback2_hw_params, 1873 1847 .hw_free = snd_cmipci_playback2_hw_free, … … 1877 1851 }; 1878 1852 1879 static struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {1853 static const struct snd_pcm_ops snd_cmipci_playback_spdif_ops = { 1880 1854 .open = snd_cmipci_playback_spdif_open, 1881 1855 .close = snd_cmipci_playback_spdif_close, 1882 .ioctl = snd_pcm_lib_ioctl,1883 .hw_params = snd_cmipci_hw_params,1884 1856 .hw_free = snd_cmipci_playback_hw_free, 1885 1857 .prepare = snd_cmipci_playback_spdif_prepare, /* set up rate */ … … 1888 1860 }; 1889 1861 1890 static struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {1862 static const struct snd_pcm_ops snd_cmipci_capture_spdif_ops = { 1891 1863 .open = snd_cmipci_capture_spdif_open, 1892 1864 .close = snd_cmipci_capture_spdif_close, 1893 .ioctl = snd_pcm_lib_ioctl,1894 .hw_params = snd_cmipci_hw_params,1895 1865 .hw_free = snd_cmipci_capture_spdif_hw_free, 1896 1866 .prepare = snd_cmipci_capture_spdif_prepare, … … 1903 1873 */ 1904 1874 1905 static int __devinitsnd_cmipci_pcm_new(struct cmipci *cm, int device)1875 static int snd_cmipci_pcm_new(struct cmipci *cm, int device) 1906 1876 { 1907 1877 struct snd_pcm *pcm; … … 1920 1890 cm->pcm = pcm; 1921 1891 1922 snd_pcm_ lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,1923 snd_dma_pci_data(cm->pci), 64*1024, 128*1024);1924 1925 return 0; 1926 } 1927 1928 static int __devinitsnd_cmipci_pcm2_new(struct cmipci *cm, int device)1892 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, 1893 &cm->pci->dev, 64*1024, 128*1024); 1894 1895 return 0; 1896 } 1897 1898 static int snd_cmipci_pcm2_new(struct cmipci *cm, int device) 1929 1899 { 1930 1900 struct snd_pcm *pcm; … … 1942 1912 cm->pcm2 = pcm; 1943 1913 1944 snd_pcm_ lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,1945 snd_dma_pci_data(cm->pci), 64*1024, 128*1024);1946 1947 return 0; 1948 } 1949 1950 static int __devinitsnd_cmipci_pcm_spdif_new(struct cmipci *cm, int device)1914 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, 1915 &cm->pci->dev, 64*1024, 128*1024); 1916 1917 return 0; 1918 } 1919 1920 static int snd_cmipci_pcm_spdif_new(struct cmipci *cm, int device) 1951 1921 { 1952 1922 struct snd_pcm *pcm; … … 1965 1935 cm->pcm_spdif = pcm; 1966 1936 1967 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 1968 snd_dma_pci_data(cm->pci), 64*1024, 128*1024); 1937 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, 1938 &cm->pci->dev, 64*1024, 128*1024); 1939 1940 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, 1941 snd_pcm_alt_chmaps, cm->max_channels, 0, 1942 NULL); 1943 if (err < 0) 1944 return err; 1969 1945 1970 1946 return 0; … … 2044 2020 return 0; 2045 2021 } 2046 2022 2047 2023 static int snd_cmipci_get_volume(struct snd_kcontrol *kcontrol, 2048 2024 struct snd_ctl_elem_value *ucontrol) … … 2062 2038 if (reg.invert) 2063 2039 val = reg.mask - val; 2064 2040 ucontrol->value.integer.value[1] = val; 2065 2041 } 2066 2042 spin_unlock_irq(&cm->reg_lock); … … 2126 2102 return 0; 2127 2103 } 2128 2104 2129 2105 static int snd_cmipci_get_input_sw(struct snd_kcontrol *kcontrol, 2130 2106 struct snd_ctl_elem_value *ucontrol) … … 2290 2266 2291 2267 2292 static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata= {2268 static const struct snd_kcontrol_new snd_cmipci_mixers[] = { 2293 2269 CMIPCI_SB_VOL_STEREO("Master Playback Volume", SB_DSP4_MASTER_DEV, 3, 31), 2294 2270 CMIPCI_MIXER_SW_MONO("3D Control - Switch", CM_REG_MIXER1, CM_X3DEN_SHIFT, 0), … … 2394 2370 else 2395 2371 val = snd_cmipci_read(cm, args->reg); 2396 change = (val & args->mask) != (ucontrol->value.integer.value[0] ? 2372 change = (val & args->mask) != (ucontrol->value.integer.value[0] ? 2397 2373 args->mask_on : (args->mask & ~args->mask_on)); 2398 2374 if (change) { … … 2590 2566 /* same bit as spdi_phase */ 2591 2567 spin_lock_irq(&cm->reg_lock); 2592 ucontrol->value.enumerated.item[0] = 2568 ucontrol->value.enumerated.item[0] = 2593 2569 (snd_cmipci_read_b(cm, CM_REG_MISC) & CM_SPDIF_INVERSE) ? 1 : 0; 2594 2570 spin_unlock_irq(&cm->reg_lock); … … 2612 2588 2613 2589 /* both for CM8338/8738 */ 2614 static struct snd_kcontrol_new snd_cmipci_mixer_switches[] __devinitdata= {2590 static const struct snd_kcontrol_new snd_cmipci_mixer_switches[] = { 2615 2591 DEFINE_MIXER_SWITCH("Four Channel Mode", fourch), 2616 2592 { … … 2624 2600 2625 2601 /* for non-multichannel chips */ 2626 static struct snd_kcontrol_new snd_cmipci_nomulti_switch __devinitdata=2602 static const struct snd_kcontrol_new snd_cmipci_nomulti_switch = 2627 2603 DEFINE_MIXER_SWITCH("Exchange DAC", exchange_dac); 2628 2604 2629 2605 /* only for CM8738 */ 2630 static struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] __devinitdata= {2606 static const struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] = { 2631 2607 #if 0 /* controlled in pcm device */ 2632 2608 DEFINE_MIXER_SWITCH("IEC958 In Record", spdif_in), … … 2650 2626 2651 2627 /* only for model 033/037 */ 2652 static struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] __devinitdata= {2628 static const struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] = { 2653 2629 DEFINE_MIXER_SWITCH("IEC958 Mix Analog", spdif_dac_out), 2654 2630 DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase), … … 2657 2633 2658 2634 /* only for model 039 or later */ 2659 static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] __devinitdata= {2635 static const struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] = { 2660 2636 DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel2), 2661 2637 DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase2), … … 2670 2646 2671 2647 /* card control switches */ 2672 static struct snd_kcontrol_new snd_cmipci_modem_switch __devinitdata=2648 static const struct snd_kcontrol_new snd_cmipci_modem_switch = 2673 2649 DEFINE_CARD_SWITCH("Modem", modem); 2674 2650 2675 2651 2676 static int __devinitsnd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)2652 static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device) 2677 2653 { 2678 2654 struct snd_card *card; 2679 struct snd_kcontrol_new *sw;2655 const struct snd_kcontrol_new *sw; 2680 2656 struct snd_kcontrol *kctl; 2681 2657 unsigned int idx; … … 2783 2759 */ 2784 2760 2785 #ifdef CONFIG_PROC_FS 2786 static void snd_cmipci_proc_read(struct snd_info_entry *entry, 2761 static void snd_cmipci_proc_read(struct snd_info_entry *entry, 2787 2762 struct snd_info_buffer *buffer) 2788 2763 { … … 2802 2777 } 2803 2778 2804 static void __devinit snd_cmipci_proc_init(struct cmipci *cm) 2805 { 2806 struct snd_info_entry *entry; 2807 2808 if (! snd_card_proc_new(cm->card, "cmipci", &entry)) 2809 snd_info_set_text_ops(entry, cm, snd_cmipci_proc_read); 2810 } 2811 #else /* !CONFIG_PROC_FS */ 2812 static inline void snd_cmipci_proc_init(struct cmipci *cm) {} 2813 #endif 2814 2815 2816 static DEFINE_PCI_DEVICE_TABLE(snd_cmipci_ids) = { 2779 static void snd_cmipci_proc_init(struct cmipci *cm) 2780 { 2781 snd_card_ro_proc_new(cm->card, "cmipci", cm, snd_cmipci_proc_read); 2782 } 2783 2784 static const struct pci_device_id snd_cmipci_ids[] = { 2817 2785 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A), 0}, 2818 2786 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B), 0}, … … 2828 2796 * driver name is modified according to the chip model 2829 2797 */ 2830 static void __devinitquery_chip(struct cmipci *cm)2798 static void query_chip(struct cmipci *cm) 2831 2799 { 2832 2800 unsigned int detect; … … 2877 2845 2878 2846 #ifdef SUPPORT_JOYSTICK 2879 static int __devinitsnd_cmipci_create_gameport(struct cmipci *cm, int dev)2880 { 2881 static int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */2847 static int snd_cmipci_create_gameport(struct cmipci *cm, int dev) 2848 { 2849 static const int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */ 2882 2850 struct gameport *gp; 2883 2851 struct resource *r = NULL; … … 2900 2868 2901 2869 if (!r) { 2902 printk(KERN_WARNING "cmipci:cannot reserve joystick ports\n");2870 dev_warn(cm->card->dev, "cannot reserve joystick ports\n"); 2903 2871 return -EBUSY; 2904 2872 } … … 2906 2874 cm->gameport = gp = gameport_allocate_port(); 2907 2875 if (!gp) { 2908 printk(KERN_ERR "cmipci:cannot allocate memory for gameport\n");2876 dev_err(cm->card->dev, "cannot allocate memory for gameport\n"); 2909 2877 release_and_free_resource(r); 2910 2878 return -ENOMEM; … … 2970 2938 } 2971 2939 2972 static int __devinitsnd_cmipci_create_fm(struct cmipci *cm, long fm_port)2940 static int snd_cmipci_create_fm(struct cmipci *cm, long fm_port) 2973 2941 { 2974 2942 long iosynth; … … 3006 2974 if (snd_opl3_create(cm->card, iosynth, iosynth + 2, 3007 2975 OPL3_HW_OPL3, 0, &opl3) < 0) { 3008 printk(KERN_ERR "cmipci: no OPL device at %#lx, " 3009 "skipping...\n", iosynth); 2976 dev_err(cm->card->dev, 2977 "no OPL device at %#lx, skipping...\n", 2978 iosynth); 3010 2979 goto disable_fm; 3011 2980 } 3012 2981 } 3013 2982 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { 3014 printk(KERN_ERR "cmipci:cannot create OPL3 hwdep\n");2983 dev_err(cm->card->dev, "cannot create OPL3 hwdep\n"); 3015 2984 return err; 3016 2985 } … … 3023 2992 } 3024 2993 3025 static int __devinitsnd_cmipci_create(struct snd_card *card, struct pci_dev *pci,3026 2994 static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci, 2995 int dev, struct cmipci **rcmipci) 3027 2996 { 3028 2997 struct cmipci *cm; 3029 2998 int err; 3030 static struct snd_device_ops ops = {2999 static const struct snd_device_ops ops = { 3031 3000 .dev_free = snd_cmipci_dev_free, 3032 3001 }; … … 3036 3005 char modelstr[16]; 3037 3006 int pcm_index, pcm_spdif_index; 3038 static DEFINE_PCI_DEVICE_TABLE(intel_82437vx)= {3007 static const struct pci_device_id intel_82437vx[] = { 3039 3008 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) }, 3040 3009 {0}, … … 3070 3039 3071 3040 if (request_irq(pci->irq, snd_cmipci_interrupt, 3072 IRQF_SHARED, card->driver, cm)) {3073 snd_printk(KERN_ERR"unable to grab IRQ %d\n", pci->irq);3041 IRQF_SHARED, KBUILD_MODNAME, cm)) { 3042 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); 3074 3043 snd_cmipci_free(cm); 3075 3044 return -EBUSY; 3076 3045 } 3077 3046 cm->irq = pci->irq; 3047 card->sync_irq = cm->irq; 3078 3048 3079 3049 pci_set_master(cm->pci); … … 3133 3103 case PCI_DEVICE_ID_CMEDIA_CM8738: 3134 3104 case PCI_DEVICE_ID_CMEDIA_CM8738B: 3135 if (!pci_dev_present(intel_82437vx)) 3105 if (!pci_dev_present(intel_82437vx)) 3136 3106 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_TXVX); 3137 3107 break; … … 3183 3153 val = snd_cmipci_read_b(cm, CM_REG_MPU_PCI + 1); 3184 3154 if (val != 0x00 && val != 0xff) { 3185 iomidi = cm->iobase + CM_REG_MPU_PCI; 3155 if (mpu_port[dev]) 3156 iomidi = cm->iobase + CM_REG_MPU_PCI; 3186 3157 integrated_midi = 1; 3187 3158 } … … 3203 3174 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN); 3204 3175 if (inb(iomidi + 1) == 0xff) { 3205 snd_printk(KERN_ERR "cannot enable MPU-401 port" 3206 " at %#lx\n", iomidi); 3176 dev_err(cm->card->dev, 3177 "cannot enable MPU-401 port at %#lx\n", 3178 iomidi); 3207 3179 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, 3208 3180 CM_UART_EN); … … 3245 3217 iomidi, 3246 3218 (integrated_midi ? 3247 MPU401_INFO_INTEGRATED : 0), 3248 cm->irq, 0, &cm->rmidi)) < 0) { 3249 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi); 3219 MPU401_INFO_INTEGRATED : 0) | 3220 MPU401_INFO_IRQ_HOOK, 3221 -1, &cm->rmidi)) < 0) { 3222 dev_err(cm->card->dev, 3223 "no UART401 device at 0x%lx\n", iomidi); 3250 3224 } 3251 3225 } … … 3264 3238 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN); 3265 3239 3266 snd_card_set_dev(card, &pci->dev);3267 3268 3240 *rcmipci = cm; 3269 3241 return 0; … … 3275 3247 MODULE_DEVICE_TABLE(pci, snd_cmipci_ids); 3276 3248 3277 static int __devinitsnd_cmipci_probe(struct pci_dev *pci,3278 3249 static int snd_cmipci_probe(struct pci_dev *pci, 3250 const struct pci_device_id *pci_id) 3279 3251 { 3280 3252 static int dev; … … 3290 3262 } 3291 3263 3292 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 3264 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 3265 0, &card); 3293 3266 if (err < 0) 3294 3267 return err; … … 3308 3281 } 3309 3282 3310 if ((err = snd_cmipci_create(card, pci, dev, &cm)) < 0) {3311 snd_card_free(card);3312 return err;3313 } 3283 err = snd_cmipci_create(card, pci, dev, &cm); 3284 if (err < 0) 3285 goto free_card; 3286 3314 3287 card->private_data = cm; 3315 3288 3316 if ((err = snd_card_register(card)) < 0) {3317 snd_card_free(card);3318 return err;3319 } 3289 err = snd_card_register(card); 3290 if (err < 0) 3291 goto free_card; 3292 3320 3293 pci_set_drvdata(pci, card); 3321 3294 dev++; 3322 3295 return 0; 3323 3296 3324 } 3325 3326 static void __devexit snd_cmipci_remove(struct pci_dev *pci) 3297 free_card: 3298 snd_card_free(card); 3299 return err; 3300 } 3301 3302 static void snd_cmipci_remove(struct pci_dev *pci) 3327 3303 { 3328 3304 snd_card_free(pci_get_drvdata(pci)); 3329 pci_set_drvdata(pci, NULL); 3330 } 3331 3332 3333 #ifdef CONFIG_PM 3305 } 3306 3307 3308 #ifdef CONFIG_PM_SLEEP 3334 3309 /* 3335 3310 * power management 3336 3311 */ 3337 static unsigned char saved_regs[] = {3312 static const unsigned char saved_regs[] = { 3338 3313 CM_REG_FUNCTRL1, CM_REG_CHFORMAT, CM_REG_LEGACY_CTRL, CM_REG_MISC_CTRL, 3339 3314 CM_REG_MIXER0, CM_REG_MIXER1, CM_REG_MIXER2, CM_REG_MIXER3, CM_REG_PLL, … … 3343 3318 }; 3344 3319 3345 static unsigned char saved_mixers[] = {3320 static const unsigned char saved_mixers[] = { 3346 3321 SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1, 3347 3322 SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1, … … 3354 3329 }; 3355 3330 3356 static int snd_cmipci_suspend(struct pci_dev *pci, pm_message_t state)3357 { 3358 struct snd_card *card = pci_get_drvdata(pci);3331 static int snd_cmipci_suspend(struct device *dev) 3332 { 3333 struct snd_card *card = dev_get_drvdata(dev); 3359 3334 struct cmipci *cm = card->private_data; 3360 3335 int i; … … 3362 3337 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 3363 3338 3364 snd_pcm_suspend_all(cm->pcm);3365 snd_pcm_suspend_all(cm->pcm2);3366 snd_pcm_suspend_all(cm->pcm_spdif);3367 3368 3339 /* save registers */ 3369 3340 for (i = 0; i < ARRAY_SIZE(saved_regs); i++) … … 3374 3345 /* disable ints */ 3375 3346 snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0); 3376 3377 pci_disable_device(pci); 3378 pci_save_state(pci); 3379 pci_set_power_state(pci, pci_choose_state(pci, state)); 3380 return 0; 3381 } 3382 3383 static int snd_cmipci_resume(struct pci_dev *pci) 3384 { 3385 struct snd_card *card = pci_get_drvdata(pci); 3347 return 0; 3348 } 3349 3350 static int snd_cmipci_resume(struct device *dev) 3351 { 3352 struct snd_card *card = dev_get_drvdata(dev); 3386 3353 struct cmipci *cm = card->private_data; 3387 3354 int i; 3388 3389 pci_set_power_state(pci, PCI_D0);3390 pci_restore_state(pci);3391 if (pci_enable_device(pci) < 0) {3392 printk(KERN_ERR "cmipci: pci_enable_device failed, "3393 "disabling device\n");3394 snd_card_disconnect(card);3395 return -EIO;3396 }3397 pci_set_master(pci);3398 3355 3399 3356 /* reset / initialize to a sane state */ … … 3412 3369 return 0; 3413 3370 } 3414 #endif /* CONFIG_PM */ 3415 3416 static struct pci_driver driver = { 3417 .name = "C-Media PCI", 3371 3372 static SIMPLE_DEV_PM_OPS(snd_cmipci_pm, snd_cmipci_suspend, snd_cmipci_resume); 3373 #define SND_CMIPCI_PM_OPS &snd_cmipci_pm 3374 #else 3375 #define SND_CMIPCI_PM_OPS NULL 3376 #endif /* CONFIG_PM_SLEEP */ 3377 3378 static struct pci_driver cmipci_driver = { 3379 .name = KBUILD_MODNAME, 3418 3380 .id_table = snd_cmipci_ids, 3419 3381 .probe = snd_cmipci_probe, 3420 .remove = __devexit_p(snd_cmipci_remove), 3421 #ifdef CONFIG_PM 3422 .suspend = snd_cmipci_suspend, 3423 .resume = snd_cmipci_resume, 3424 #endif 3382 .remove = snd_cmipci_remove, 3383 .driver = { 3384 .pm = SND_CMIPCI_PM_OPS, 3385 }, 3425 3386 }; 3426 3387 3427 static int __init alsa_card_cmipci_init(void) 3428 { 3429 return pci_register_driver(&driver); 3430 } 3431 3432 static void __exit alsa_card_cmipci_exit(void) 3433 { 3434 pci_unregister_driver(&driver); 3435 } 3436 3437 module_init(alsa_card_cmipci_init) 3438 module_exit(alsa_card_cmipci_exit) 3388 module_pci_driver(cmipci_driver);
Note:
See TracChangeset
for help on using the changeset viewer.