Ignore:
Timestamp:
Mar 18, 2021, 8:57:36 PM (4 years ago)
Author:
David Azarewicz
Message:

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/alsa-kernel/pci/cmipci.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 * Driver for C-Media CMI8338 and 8738 PCI soundcards.
    34 * 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 
    207/* Does not work. Warning may block system in capture mode */
    218/* #define USE_VAR48KRATE */
    229
    23 #include <asm/io.h>
     10#include <linux/io.h>
    2411#include <linux/delay.h>
    2512#include <linux/interrupt.h>
     
    2815#include <linux/slab.h>
    2916#include <linux/gameport.h>
    30 #include <linux/moduleparam.h>
     17#include <linux/module.h>
    3118#include <linux/mutex.h>
    3219#include <sound/core.h>
     
    4128#include <sound/initval.h>
    4229
     30#ifdef TARGET_OS2
     31#define KBUILD_MODNAME "cmipci"
     32#endif
    4333MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
    4434MODULE_DESCRIPTION("C-Media CMI8x38 PCI");
     
    4939                "{C-Media,CMI8338B}}");
    5040
    51 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
     41#if IS_REACHABLE(CONFIG_GAMEPORT)
    5242#define SUPPORT_JOYSTICK 1
    5343#endif
     
    5545static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    5646static 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];
     47static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable switches */
    5948#ifndef TARGET_OS2
     49static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1};
    6050static long fm_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
    61 static int soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
     51static bool soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
    6252#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};
     53static long mpu_port[SNDRV_CARDS] = {0,1,1,1,1,1,1,1};
     54static long fm_port[SNDRV_CARDS] = {0,1,1,1,1,1,1,1};
     55static bool soft_ac3[SNDRV_CARDS] = {0,1,1,1,1,1,1,1};
    6556#endif
    6657#ifdef SUPPORT_JOYSTICK
     
    7465module_param_array(enable, bool, NULL, 0444);
    7566MODULE_PARM_DESC(enable, "Enable C-Media PCI soundcard.");
    76 module_param_array(mpu_port, long, NULL, 0444);
     67module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
    7768MODULE_PARM_DESC(mpu_port, "MPU-401 port.");
    78 module_param_array(fm_port, long, NULL, 0444);
     69module_param_hw_array(fm_port, long, ioport, NULL, 0444);
    7970MODULE_PARM_DESC(fm_port, "FM port.");
    8071module_param_array(soft_ac3, bool, NULL, 0444);
    81 MODULE_PARM_DESC(soft_ac3, "Sofware-conversion of raw SPDIF packets (model 033 only).");
     72MODULE_PARM_DESC(soft_ac3, "Software-conversion of raw SPDIF packets (model 033 only).");
    8273#ifdef SUPPORT_JOYSTICK
    83 module_param_array(joystick_port, int, NULL, 0444);
     74module_param_hw_array(joystick_port, int, ioport, NULL, 0444);
    8475MODULE_PARM_DESC(joystick_port, "Joystick port address.");
    8576#endif
     
    510501        spinlock_t reg_lock;
    511502
    512 #ifdef CONFIG_PM
     503#ifdef CONFIG_PM_SLEEP
    513504        unsigned int saved_regs[0x20];
    514505        unsigned char saved_mixers[0x20];
     
    605596 */
    606597
    607 static unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 };
     598static const unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 };
    608599
    609600static unsigned int snd_cmipci_rate_freq(unsigned int rate)
     
    662653
    663654/*
    664  * Program pll register bits, I assume that the 8 registers 0xf8 upto 0xff
    665  * are mapped onto the 8 ADC/DAC sampling frequency which can be choosen
     655 * 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
    666657 * at the register CM_REG_FUNCTRL1 (0x04).
    667658 * Problem: other ways are also possible (any information about that?)
     
    672663        /*
    673664         * Guess that this programs at reg. 0x04 the pos 15:13/12:10
    674          * for DSFC/ASFC (000 upto 111).
     665         * for DSFC/ASFC (000 up to 111).
    675666         */
    676667
     
    684675}
    685676#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 }
    692677
    693678static int snd_cmipci_playback2_hw_params(struct snd_pcm_substream *substream,
     
    705690                mutex_unlock(&cm->open_mutex);
    706691        }
    707         return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
     692        return 0;
    708693}
    709694
     
    716701}
    717702
    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
     707static const unsigned int hw_channels[] = {1, 2, 4, 6, 8};
     708static const struct snd_pcm_hw_constraint_list hw_constraints_channels_4 = {
    729709        .count = 3,
    730710        .list = hw_channels,
    731711        .mask = 0,
    732712};
    733 static struct snd_pcm_hw_constraint_list hw_constraints_channels_6 = {
     713static const struct snd_pcm_hw_constraint_list hw_constraints_channels_6 = {
    734714        .count = 4,
    735715        .list = hw_channels,
    736716        .mask = 0,
    737717};
    738 static struct snd_pcm_hw_constraint_list hw_constraints_channels_8 = {
     718static const struct snd_pcm_hw_constraint_list hw_constraints_channels_8 = {
    739719        .count = 5,
    740720        .list = hw_channels,
     
    802782                rec->fmt |= 0x01;
    803783        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");
    805785                return -EINVAL;
    806786        }
     
    833813                cm->ctrl |= val;
    834814        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); */
    836816
    837817        /* set sample rate */
     
    856836        }
    857837        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);
    859839
    860840        /* set format */
     
    872852        }
    873853        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);
    875855
    876856        if (!rec->is_dac && cm->chip_version) {
     
    910890                /* enable channel */
    911891                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);
    913893                break;
    914894        case SNDRV_PCM_TRIGGER_STOP:
     
    957937                if (rem < rec->dma_size)
    958938                        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);
    961941        return SNDRV_PCM_POS_XRUN;
    962942ok:
     
    10511031}
    10521032
    1053 static struct snd_kcontrol_new snd_cmipci_spdif_default __devinitdata =
     1033static const struct snd_kcontrol_new snd_cmipci_spdif_default =
    10541034{
    10551035        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     
    10781058}
    10791059
    1080 static struct snd_kcontrol_new snd_cmipci_spdif_mask __devinitdata =
     1060static const struct snd_kcontrol_new snd_cmipci_spdif_mask =
    10811061{
    10821062        .access =       SNDRV_CTL_ELEM_ACCESS_READ,
     
    11251105}
    11261106
    1127 static struct snd_kcontrol_new snd_cmipci_spdif_stream __devinitdata =
     1107static const struct snd_kcontrol_new snd_cmipci_spdif_stream =
    11281108{
    11291109        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     
    11451125                unsigned int i;
    11461126
    1147                 val = kmalloc(sizeof(*val), GFP_ATOMIC);
     1127                val = kmalloc(sizeof(*val), GFP_KERNEL);
    11481128                if (!val)
    11491129                        return -ENOMEM;
     
    13081288                    substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE &&
    13091289                    substream->runtime->channels == 2);
    1310         if (do_spdif && cm->can_ac3_hw)
     1290        if (do_spdif && cm->can_ac3_hw) 
    13111291                do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO;
    13121292        if ((err = setup_spdif_playback(cm, substream, do_spdif, do_ac3)) < 0)
     
    13211301        int err, do_ac3;
    13221302
    1323         if (cm->can_ac3_hw)
     1303        if (cm->can_ac3_hw) 
    13241304                do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO;
    13251305        else
     
    13901370        restore_mixer_state(cm);
    13911371        snd_cmipci_silence_hack(cm, &cm->channel[0]);
    1392         return snd_cmipci_hw_free(substream);
     1372        return 0;
    13931373}
    13941374
     
    13971377        struct cmipci *cm = snd_pcm_substream_chip(substream);
    13981378        snd_cmipci_silence_hack(cm, &cm->channel[1]);
    1399         return snd_cmipci_hw_free(substream);
     1379        return 0;
    14001380}
    14011381
     
    14391419        spin_unlock_irq(&cm->reg_lock);
    14401420
    1441         return snd_cmipci_hw_free(subs);
     1421        return 0;
    14421422}
    14431423
     
    14831463
    14841464/* playback on channel A */
    1485 static struct snd_pcm_hardware snd_cmipci_playback =
     1465static const struct snd_pcm_hardware snd_cmipci_playback =
    14861466{
    14871467        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15031483
    15041484/* capture on channel B */
    1505 static struct snd_pcm_hardware snd_cmipci_capture =
     1485static const struct snd_pcm_hardware snd_cmipci_capture =
    15061486{
    15071487        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15231503
    15241504/* playback on channel B - stereo 16bit only? */
    1525 static struct snd_pcm_hardware snd_cmipci_playback2 =
     1505static const struct snd_pcm_hardware snd_cmipci_playback2 =
    15261506{
    15271507        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15431523
    15441524/* spdif playback on channel A */
    1545 static struct snd_pcm_hardware snd_cmipci_playback_spdif =
     1525static const struct snd_pcm_hardware snd_cmipci_playback_spdif =
    15461526{
    15471527        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15631543
    15641544/* spdif playback on channel A (32bit, IEC958 subframes) */
    1565 static struct snd_pcm_hardware snd_cmipci_playback_iec958_subframe =
     1545static const struct snd_pcm_hardware snd_cmipci_playback_iec958_subframe =
    15661546{
    15671547        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15831563
    15841564/* spdif capture on channel B */
    1585 static struct snd_pcm_hardware snd_cmipci_capture_spdif =
     1565static const struct snd_pcm_hardware snd_cmipci_capture_spdif =
    15861566{
    15871567        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    16031583};
    16041584
    1605 static unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050,
     1585static const unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050,
    16061586                        32000, 44100, 48000, 88200, 96000, 128000 };
    1607 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
     1587static const struct snd_pcm_hw_constraint_list hw_constraints_rates = {
    16081588                .count = ARRAY_SIZE(rate_constraints),
    16091589                .list = rate_constraints,
     
    18441824 */
    18451825
    1846 static struct snd_pcm_ops snd_cmipci_playback_ops = {
     1826static const struct snd_pcm_ops snd_cmipci_playback_ops = {
    18471827        .open =         snd_cmipci_playback_open,
    18481828        .close =        snd_cmipci_playback_close,
    1849         .ioctl =        snd_pcm_lib_ioctl,
    1850         .hw_params =    snd_cmipci_hw_params,
    18511829        .hw_free =      snd_cmipci_playback_hw_free,
    18521830        .prepare =      snd_cmipci_playback_prepare,
     
    18551833};
    18561834
    1857 static struct snd_pcm_ops snd_cmipci_capture_ops = {
     1835static const struct snd_pcm_ops snd_cmipci_capture_ops = {
    18581836        .open =         snd_cmipci_capture_open,
    18591837        .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,
    18631838        .prepare =      snd_cmipci_capture_prepare,
    18641839        .trigger =      snd_cmipci_capture_trigger,
     
    18661841};
    18671842
    1868 static struct snd_pcm_ops snd_cmipci_playback2_ops = {
     1843static const struct snd_pcm_ops snd_cmipci_playback2_ops = {
    18691844        .open =         snd_cmipci_playback2_open,
    18701845        .close =        snd_cmipci_playback2_close,
    1871         .ioctl =        snd_pcm_lib_ioctl,
    18721846        .hw_params =    snd_cmipci_playback2_hw_params,
    18731847        .hw_free =      snd_cmipci_playback2_hw_free,
     
    18771851};
    18781852
    1879 static struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
     1853static const struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
    18801854        .open =         snd_cmipci_playback_spdif_open,
    18811855        .close =        snd_cmipci_playback_spdif_close,
    1882         .ioctl =        snd_pcm_lib_ioctl,
    1883         .hw_params =    snd_cmipci_hw_params,
    18841856        .hw_free =      snd_cmipci_playback_hw_free,
    18851857        .prepare =      snd_cmipci_playback_spdif_prepare,      /* set up rate */
     
    18881860};
    18891861
    1890 static struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
     1862static const struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
    18911863        .open =         snd_cmipci_capture_spdif_open,
    18921864        .close =        snd_cmipci_capture_spdif_close,
    1893         .ioctl =        snd_pcm_lib_ioctl,
    1894         .hw_params =    snd_cmipci_hw_params,
    18951865        .hw_free =      snd_cmipci_capture_spdif_hw_free,
    18961866        .prepare =      snd_cmipci_capture_spdif_prepare,
     
    19031873 */
    19041874
    1905 static int __devinit snd_cmipci_pcm_new(struct cmipci *cm, int device)
     1875static int snd_cmipci_pcm_new(struct cmipci *cm, int device)
    19061876{
    19071877        struct snd_pcm *pcm;
     
    19201890        cm->pcm = pcm;
    19211891
    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 __devinit snd_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
     1898static int snd_cmipci_pcm2_new(struct cmipci *cm, int device)
    19291899{
    19301900        struct snd_pcm *pcm;
     
    19421912        cm->pcm2 = pcm;
    19431913
    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 __devinit snd_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
     1920static int snd_cmipci_pcm_spdif_new(struct cmipci *cm, int device)
    19511921{
    19521922        struct snd_pcm *pcm;
     
    19651935        cm->pcm_spdif = pcm;
    19661936
    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;
    19691945
    19701946        return 0;
     
    20442020        return 0;
    20452021}
    2046 
     2022 
    20472023static int snd_cmipci_get_volume(struct snd_kcontrol *kcontrol,
    20482024                                 struct snd_ctl_elem_value *ucontrol)
     
    20622038                if (reg.invert)
    20632039                        val = reg.mask - val;
    2064                  ucontrol->value.integer.value[1] = val;
     2040                ucontrol->value.integer.value[1] = val;
    20652041        }
    20662042        spin_unlock_irq(&cm->reg_lock);
     
    21262102        return 0;
    21272103}
    2128 
     2104 
    21292105static int snd_cmipci_get_input_sw(struct snd_kcontrol *kcontrol,
    21302106                                   struct snd_ctl_elem_value *ucontrol)
     
    22902266
    22912267
    2292 static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
     2268static const struct snd_kcontrol_new snd_cmipci_mixers[] = {
    22932269        CMIPCI_SB_VOL_STEREO("Master Playback Volume", SB_DSP4_MASTER_DEV, 3, 31),
    22942270        CMIPCI_MIXER_SW_MONO("3D Control - Switch", CM_REG_MIXER1, CM_X3DEN_SHIFT, 0),
     
    23942370        else
    23952371                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] ? 
    23972373                        args->mask_on : (args->mask & ~args->mask_on));
    23982374        if (change) {
     
    25902566        /* same bit as spdi_phase */
    25912567        spin_lock_irq(&cm->reg_lock);
    2592         ucontrol->value.enumerated.item[0] =
     2568        ucontrol->value.enumerated.item[0] = 
    25932569                (snd_cmipci_read_b(cm, CM_REG_MISC) & CM_SPDIF_INVERSE) ? 1 : 0;
    25942570        spin_unlock_irq(&cm->reg_lock);
     
    26122588
    26132589/* both for CM8338/8738 */
    2614 static struct snd_kcontrol_new snd_cmipci_mixer_switches[] __devinitdata = {
     2590static const struct snd_kcontrol_new snd_cmipci_mixer_switches[] = {
    26152591        DEFINE_MIXER_SWITCH("Four Channel Mode", fourch),
    26162592        {
     
    26242600
    26252601/* for non-multichannel chips */
    2626 static struct snd_kcontrol_new snd_cmipci_nomulti_switch __devinitdata =
     2602static const struct snd_kcontrol_new snd_cmipci_nomulti_switch =
    26272603DEFINE_MIXER_SWITCH("Exchange DAC", exchange_dac);
    26282604
    26292605/* only for CM8738 */
    2630 static struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] __devinitdata = {
     2606static const struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] = {
    26312607#if 0 /* controlled in pcm device */
    26322608        DEFINE_MIXER_SWITCH("IEC958 In Record", spdif_in),
     
    26502626
    26512627/* only for model 033/037 */
    2652 static struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] __devinitdata = {
     2628static const struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] = {
    26532629        DEFINE_MIXER_SWITCH("IEC958 Mix Analog", spdif_dac_out),
    26542630        DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase),
     
    26572633
    26582634/* only for model 039 or later */
    2659 static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] __devinitdata = {
     2635static const struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] = {
    26602636        DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel2),
    26612637        DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase2),
     
    26702646
    26712647/* card control switches */
    2672 static struct snd_kcontrol_new snd_cmipci_modem_switch __devinitdata =
     2648static const struct snd_kcontrol_new snd_cmipci_modem_switch =
    26732649DEFINE_CARD_SWITCH("Modem", modem);
    26742650
    26752651
    2676 static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
     2652static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
    26772653{
    26782654        struct snd_card *card;
    2679         struct snd_kcontrol_new *sw;
     2655        const struct snd_kcontrol_new *sw;
    26802656        struct snd_kcontrol *kctl;
    26812657        unsigned int idx;
     
    27832759 */
    27842760
    2785 #ifdef CONFIG_PROC_FS
    2786 static void snd_cmipci_proc_read(struct snd_info_entry *entry,
     2761static void snd_cmipci_proc_read(struct snd_info_entry *entry,
    27872762                                 struct snd_info_buffer *buffer)
    27882763{
     
    28022777}
    28032778
    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) = {
     2779static 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
     2784static const struct pci_device_id snd_cmipci_ids[] = {
    28172785        {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A), 0},
    28182786        {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B), 0},
     
    28282796 * driver name is modified according to the chip model
    28292797 */
    2830 static void __devinit query_chip(struct cmipci *cm)
     2798static void query_chip(struct cmipci *cm)
    28312799{
    28322800        unsigned int detect;
     
    28772845
    28782846#ifdef SUPPORT_JOYSTICK
    2879 static int __devinit snd_cmipci_create_gameport(struct cmipci *cm, int dev)
    2880 {
    2881         static int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */
     2847static int snd_cmipci_create_gameport(struct cmipci *cm, int dev)
     2848{
     2849        static const int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */
    28822850        struct gameport *gp;
    28832851        struct resource *r = NULL;
     
    29002868
    29012869        if (!r) {
    2902                 printk(KERN_WARNING "cmipci: cannot reserve joystick ports\n");
     2870                dev_warn(cm->card->dev, "cannot reserve joystick ports\n");
    29032871                return -EBUSY;
    29042872        }
     
    29062874        cm->gameport = gp = gameport_allocate_port();
    29072875        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");
    29092877                release_and_free_resource(r);
    29102878                return -ENOMEM;
     
    29702938}
    29712939
    2972 static int __devinit snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
     2940static int snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
    29732941{
    29742942        long iosynth;
     
    30062974                if (snd_opl3_create(cm->card, iosynth, iosynth + 2,
    30072975                                    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);
    30102979                        goto disable_fm;
    30112980                }
    30122981        }
    30132982        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");
    30152984                return err;
    30162985        }
     
    30232992}
    30242993
    3025 static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
    3026                                        int dev, struct cmipci **rcmipci)
     2994static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
     2995                             int dev, struct cmipci **rcmipci)
    30272996{
    30282997        struct cmipci *cm;
    30292998        int err;
    3030         static struct snd_device_ops ops = {
     2999        static const struct snd_device_ops ops = {
    30313000                .dev_free =     snd_cmipci_dev_free,
    30323001        };
     
    30363005        char modelstr[16];
    30373006        int pcm_index, pcm_spdif_index;
    3038         static DEFINE_PCI_DEVICE_TABLE(intel_82437vx) = {
     3007        static const struct pci_device_id intel_82437vx[] = {
    30393008                { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
    30403009                {0},
     
    30703039
    30713040        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);
    30743043                snd_cmipci_free(cm);
    30753044                return -EBUSY;
    30763045        }
    30773046        cm->irq = pci->irq;
     3047        card->sync_irq = cm->irq;
    30783048
    30793049        pci_set_master(cm->pci);
     
    31333103        case PCI_DEVICE_ID_CMEDIA_CM8738:
    31343104        case PCI_DEVICE_ID_CMEDIA_CM8738B:
    3135                 if (!pci_dev_present(intel_82437vx))
     3105                if (!pci_dev_present(intel_82437vx)) 
    31363106                        snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_TXVX);
    31373107                break;
     
    31833153                val = snd_cmipci_read_b(cm, CM_REG_MPU_PCI + 1);
    31843154                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;
    31863157                        integrated_midi = 1;
    31873158                }
     
    32033174                        snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN);
    32043175                        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);
    32073179                                snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1,
    32083180                                                     CM_UART_EN);
     
    32453217                                               iomidi,
    32463218                                               (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);
    32503224                }
    32513225        }
     
    32643238                snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
    32653239
    3266         snd_card_set_dev(card, &pci->dev);
    3267 
    32683240        *rcmipci = cm;
    32693241        return 0;
     
    32753247MODULE_DEVICE_TABLE(pci, snd_cmipci_ids);
    32763248
    3277 static int __devinit snd_cmipci_probe(struct pci_dev *pci,
    3278                                       const struct pci_device_id *pci_id)
     3249static int snd_cmipci_probe(struct pci_dev *pci,
     3250                            const struct pci_device_id *pci_id)
    32793251{
    32803252        static int dev;
     
    32903262        }
    32913263
    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);
    32933266        if (err < 0)
    32943267                return err;
     
    33083281        }
    33093282
    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
    33143287        card->private_data = cm;
    33153288
    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
    33203293        pci_set_drvdata(pci, card);
    33213294        dev++;
    33223295        return 0;
    33233296
    3324 }
    3325 
    3326 static void __devexit snd_cmipci_remove(struct pci_dev *pci)
     3297free_card:
     3298        snd_card_free(card);
     3299        return err;
     3300}
     3301
     3302static void snd_cmipci_remove(struct pci_dev *pci)
    33273303{
    33283304        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
    33343309/*
    33353310 * power management
    33363311 */
    3337 static unsigned char saved_regs[] = {
     3312static const unsigned char saved_regs[] = {
    33383313        CM_REG_FUNCTRL1, CM_REG_CHFORMAT, CM_REG_LEGACY_CTRL, CM_REG_MISC_CTRL,
    33393314        CM_REG_MIXER0, CM_REG_MIXER1, CM_REG_MIXER2, CM_REG_MIXER3, CM_REG_PLL,
     
    33433318};
    33443319
    3345 static unsigned char saved_mixers[] = {
     3320static const unsigned char saved_mixers[] = {
    33463321        SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1,
    33473322        SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1,
     
    33543329};
    33553330
    3356 static int snd_cmipci_suspend(struct pci_dev *pci, pm_message_t state)
    3357 {
    3358         struct snd_card *card = pci_get_drvdata(pci);
     3331static int snd_cmipci_suspend(struct device *dev)
     3332{
     3333        struct snd_card *card = dev_get_drvdata(dev);
    33593334        struct cmipci *cm = card->private_data;
    33603335        int i;
     
    33623337        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    33633338       
    3364         snd_pcm_suspend_all(cm->pcm);
    3365         snd_pcm_suspend_all(cm->pcm2);
    3366         snd_pcm_suspend_all(cm->pcm_spdif);
    3367 
    33683339        /* save registers */
    33693340        for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
     
    33743345        /* disable ints */
    33753346        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
     3350static int snd_cmipci_resume(struct device *dev)
     3351{
     3352        struct snd_card *card = dev_get_drvdata(dev);
    33863353        struct cmipci *cm = card->private_data;
    33873354        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);
    33983355
    33993356        /* reset / initialize to a sane state */
     
    34123369        return 0;
    34133370}
    3414 #endif /* CONFIG_PM */
    3415 
    3416 static struct pci_driver driver = {
    3417         .name = "C-Media PCI",
     3371
     3372static 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
     3378static struct pci_driver cmipci_driver = {
     3379        .name = KBUILD_MODNAME,
    34183380        .id_table = snd_cmipci_ids,
    34193381        .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        },
    34253386};
    34263387       
    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)
     3388module_pci_driver(cmipci_driver);
Note: See TracChangeset for help on using the changeset viewer.