Ignore:
Timestamp:
Jan 1, 2021, 5:31:48 AM (5 years ago)
Author:
Paul Smedley
Message:

Add source for uniaud32 based on code from linux kernel 5.4.86

Location:
GPL/branches/uniaud32-next
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-next/alsa-kernel/pci/cmipci.c

    r612 r615  
     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
    185 */
    196 
     
    218/* #define USE_VAR48KRATE */
    229
    23 #ifdef TARGET_OS2
    24 #define KBUILD_MODNAME "cmipci"
    25 #endif
    26 
    27 #include <asm/io.h>
     10#include <linux/io.h>
    2811#include <linux/delay.h>
    2912#include <linux/interrupt.h>
     
    4528#include <sound/initval.h>
    4629
     30#ifdef TARGET_OS2
     31#define KBUILD_MODNAME "cmipci"
     32#endif
    4733MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
    4834MODULE_DESCRIPTION("C-Media CMI8x38 PCI");
     
    5339                "{C-Media,CMI8338B}}");
    5440
    55 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
     41#if IS_REACHABLE(CONFIG_GAMEPORT)
    5642#define SUPPORT_JOYSTICK 1
    5743#endif
     
    5945static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    6046static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    61 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable switches */
     47static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable switches */
    6248static long mpu_port[SNDRV_CARDS];
    6349#ifndef TARGET_OS2
    6450static long fm_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
    65 static int soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
     51static bool soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
    6652#else
    6753static long fm_port[SNDRV_CARDS] = {0x388, -1,-1,-1,-1,-1,-1,-1};
    68 static int soft_ac3[SNDRV_CARDS] = {0,1,1,1,1,1,1,1};
     54static bool soft_ac3[SNDRV_CARDS] = {0,1,1,1,1,1,1,1};
    6955#endif
    7056#ifdef SUPPORT_JOYSTICK
     
    7864module_param_array(enable, bool, NULL, 0444);
    7965MODULE_PARM_DESC(enable, "Enable C-Media PCI soundcard.");
    80 module_param_array(mpu_port, long, NULL, 0444);
     66module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
    8167MODULE_PARM_DESC(mpu_port, "MPU-401 port.");
    82 module_param_array(fm_port, long, NULL, 0444);
     68module_param_hw_array(fm_port, long, ioport, NULL, 0444);
    8369MODULE_PARM_DESC(fm_port, "FM port.");
    8470module_param_array(soft_ac3, bool, NULL, 0444);
    8571MODULE_PARM_DESC(soft_ac3, "Software-conversion of raw SPDIF packets (model 033 only).");
    8672#ifdef SUPPORT_JOYSTICK
    87 module_param_array(joystick_port, int, NULL, 0444);
     73module_param_hw_array(joystick_port, int, ioport, NULL, 0444);
    8874MODULE_PARM_DESC(joystick_port, "Joystick port address.");
    8975#endif
     
    514500        spinlock_t reg_lock;
    515501
    516 #ifdef CONFIG_PM
     502#ifdef CONFIG_PM_SLEEP
    517503        unsigned int saved_regs[0x20];
    518504        unsigned char saved_mixers[0x20];
     
    729715 */
    730716
    731 static unsigned int hw_channels[] = {1, 2, 4, 6, 8};
    732 static struct snd_pcm_hw_constraint_list hw_constraints_channels_4 = {
     717static const unsigned int hw_channels[] = {1, 2, 4, 6, 8};
     718static const struct snd_pcm_hw_constraint_list hw_constraints_channels_4 = {
    733719        .count = 3,
    734720        .list = hw_channels,
    735721        .mask = 0,
    736722};
    737 static struct snd_pcm_hw_constraint_list hw_constraints_channels_6 = {
     723static const struct snd_pcm_hw_constraint_list hw_constraints_channels_6 = {
    738724        .count = 4,
    739725        .list = hw_channels,
    740726        .mask = 0,
    741727};
    742 static struct snd_pcm_hw_constraint_list hw_constraints_channels_8 = {
     728static const struct snd_pcm_hw_constraint_list hw_constraints_channels_8 = {
    743729        .count = 5,
    744730        .list = hw_channels,
     
    806792                rec->fmt |= 0x01;
    807793        if (rec->is_dac && set_dac_channels(cm, rec, runtime->channels) < 0) {
    808                 snd_printd("cannot set dac channels\n");
     794                dev_dbg(cm->card->dev, "cannot set dac channels\n");
    809795                return -EINVAL;
    810796        }
     
    837823                cm->ctrl |= val;
    838824        snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl);
    839         //snd_printd("cmipci: functrl0 = %08x\n", cm->ctrl);
     825        /* dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl); */
    840826
    841827        /* set sample rate */
     
    860846        }
    861847        snd_cmipci_write(cm, CM_REG_FUNCTRL1, val);
    862         //snd_printd("cmipci: functrl1 = %08x\n", val);
     848        dev_dbg(cm->card->dev, "functrl1 = %08x\n", val);
    863849
    864850        /* set format */
     
    876862        }
    877863        snd_cmipci_write(cm, CM_REG_CHFORMAT, val);
    878         //snd_printd("cmipci: chformat = %08x\n", val);
     864        dev_dbg(cm->card->dev, "chformat = %08x\n", val);
    879865
    880866        if (!rec->is_dac && cm->chip_version) {
     
    914900                /* enable channel */
    915901                snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl);
    916                 //snd_printd("cmipci: functrl0 = %08x\n", cm->ctrl);
     902                dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl);
    917903                break;
    918904        case SNDRV_PCM_TRIGGER_STOP:
     
    962948                        goto ok;
    963949        }
    964         printk(KERN_ERR "cmipci: invalid PCM pointer: %#x\n", rem);
     950        dev_err(cm->card->dev, "invalid PCM pointer: %#x\n", rem);
    965951        return SNDRV_PCM_POS_XRUN;
    966952ok:
     
    10551041}
    10561042
    1057 static struct snd_kcontrol_new snd_cmipci_spdif_default __devinitdata =
     1043static const struct snd_kcontrol_new snd_cmipci_spdif_default =
    10581044{
    10591045        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     
    10821068}
    10831069
    1084 static struct snd_kcontrol_new snd_cmipci_spdif_mask __devinitdata =
     1070static const struct snd_kcontrol_new snd_cmipci_spdif_mask =
    10851071{
    10861072        .access =       SNDRV_CTL_ELEM_ACCESS_READ,
     
    11291115}
    11301116
    1131 static struct snd_kcontrol_new snd_cmipci_spdif_stream __devinitdata =
     1117static const struct snd_kcontrol_new snd_cmipci_spdif_stream =
    11321118{
    11331119        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     
    11491135                unsigned int i;
    11501136
    1151                 val = kmalloc(sizeof(*val), GFP_ATOMIC);
     1137                val = kmalloc(sizeof(*val), GFP_KERNEL);
    11521138                if (!val)
    11531139                        return -ENOMEM;
     
    14871473
    14881474/* playback on channel A */
    1489 static struct snd_pcm_hardware snd_cmipci_playback =
     1475static const struct snd_pcm_hardware snd_cmipci_playback =
    14901476{
    14911477        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15071493
    15081494/* capture on channel B */
    1509 static struct snd_pcm_hardware snd_cmipci_capture =
     1495static const struct snd_pcm_hardware snd_cmipci_capture =
    15101496{
    15111497        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15271513
    15281514/* playback on channel B - stereo 16bit only? */
    1529 static struct snd_pcm_hardware snd_cmipci_playback2 =
     1515static const struct snd_pcm_hardware snd_cmipci_playback2 =
    15301516{
    15311517        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15471533
    15481534/* spdif playback on channel A */
    1549 static struct snd_pcm_hardware snd_cmipci_playback_spdif =
     1535static const struct snd_pcm_hardware snd_cmipci_playback_spdif =
    15501536{
    15511537        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15671553
    15681554/* spdif playback on channel A (32bit, IEC958 subframes) */
    1569 static struct snd_pcm_hardware snd_cmipci_playback_iec958_subframe =
     1555static const struct snd_pcm_hardware snd_cmipci_playback_iec958_subframe =
    15701556{
    15711557        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    15871573
    15881574/* spdif capture on channel B */
    1589 static struct snd_pcm_hardware snd_cmipci_capture_spdif =
     1575static const struct snd_pcm_hardware snd_cmipci_capture_spdif =
    15901576{
    15911577        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    16071593};
    16081594
    1609 static unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050,
     1595static const unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050,
    16101596                        32000, 44100, 48000, 88200, 96000, 128000 };
    1611 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
     1597static const struct snd_pcm_hw_constraint_list hw_constraints_rates = {
    16121598                .count = ARRAY_SIZE(rate_constraints),
    16131599                .list = rate_constraints,
     
    18481834 */
    18491835
    1850 static struct snd_pcm_ops snd_cmipci_playback_ops = {
     1836static const struct snd_pcm_ops snd_cmipci_playback_ops = {
    18511837        .open =         snd_cmipci_playback_open,
    18521838        .close =        snd_cmipci_playback_close,
     
    18591845};
    18601846
    1861 static struct snd_pcm_ops snd_cmipci_capture_ops = {
     1847static const struct snd_pcm_ops snd_cmipci_capture_ops = {
    18621848        .open =         snd_cmipci_capture_open,
    18631849        .close =        snd_cmipci_capture_close,
     
    18701856};
    18711857
    1872 static struct snd_pcm_ops snd_cmipci_playback2_ops = {
     1858static const struct snd_pcm_ops snd_cmipci_playback2_ops = {
    18731859        .open =         snd_cmipci_playback2_open,
    18741860        .close =        snd_cmipci_playback2_close,
     
    18811867};
    18821868
    1883 static struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
     1869static const struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
    18841870        .open =         snd_cmipci_playback_spdif_open,
    18851871        .close =        snd_cmipci_playback_spdif_close,
     
    18921878};
    18931879
    1894 static struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
     1880static const struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
    18951881        .open =         snd_cmipci_capture_spdif_open,
    18961882        .close =        snd_cmipci_capture_spdif_close,
     
    19071893 */
    19081894
    1909 static int __devinit snd_cmipci_pcm_new(struct cmipci *cm, int device)
     1895static int snd_cmipci_pcm_new(struct cmipci *cm, int device)
    19101896{
    19111897        struct snd_pcm *pcm;
     
    19301916}
    19311917
    1932 static int __devinit snd_cmipci_pcm2_new(struct cmipci *cm, int device)
     1918static int snd_cmipci_pcm2_new(struct cmipci *cm, int device)
    19331919{
    19341920        struct snd_pcm *pcm;
     
    19521938}
    19531939
    1954 static int __devinit snd_cmipci_pcm_spdif_new(struct cmipci *cm, int device)
     1940static int snd_cmipci_pcm_spdif_new(struct cmipci *cm, int device)
    19551941{
    19561942        struct snd_pcm *pcm;
     
    19711957        snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
    19721958                                              snd_dma_pci_data(cm->pci), 64*1024, 128*1024);
     1959
     1960        err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
     1961                                     snd_pcm_alt_chmaps, cm->max_channels, 0,
     1962                                     NULL);
     1963        if (err < 0)
     1964                return err;
    19731965
    19741966        return 0;
     
    20662058                if (reg.invert)
    20672059                        val = reg.mask - val;
    2068                  ucontrol->value.integer.value[1] = val;
     2060                ucontrol->value.integer.value[1] = val;
    20692061        }
    20702062        spin_unlock_irq(&cm->reg_lock);
     
    22942286
    22952287
    2296 static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
     2288static struct snd_kcontrol_new snd_cmipci_mixers[] = {
    22972289        CMIPCI_SB_VOL_STEREO("Master Playback Volume", SB_DSP4_MASTER_DEV, 3, 31),
    22982290        CMIPCI_MIXER_SW_MONO("3D Control - Switch", CM_REG_MIXER1, CM_X3DEN_SHIFT, 0),
     
    26162608
    26172609/* both for CM8338/8738 */
    2618 static struct snd_kcontrol_new snd_cmipci_mixer_switches[] __devinitdata = {
     2610static struct snd_kcontrol_new snd_cmipci_mixer_switches[] = {
    26192611        DEFINE_MIXER_SWITCH("Four Channel Mode", fourch),
    26202612        {
     
    26282620
    26292621/* for non-multichannel chips */
    2630 static struct snd_kcontrol_new snd_cmipci_nomulti_switch __devinitdata =
     2622static struct snd_kcontrol_new snd_cmipci_nomulti_switch =
    26312623DEFINE_MIXER_SWITCH("Exchange DAC", exchange_dac);
    26322624
    26332625/* only for CM8738 */
    2634 static struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] __devinitdata = {
     2626static struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] = {
    26352627#if 0 /* controlled in pcm device */
    26362628        DEFINE_MIXER_SWITCH("IEC958 In Record", spdif_in),
     
    26542646
    26552647/* only for model 033/037 */
    2656 static struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] __devinitdata = {
     2648static struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] = {
    26572649        DEFINE_MIXER_SWITCH("IEC958 Mix Analog", spdif_dac_out),
    26582650        DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase),
     
    26612653
    26622654/* only for model 039 or later */
    2663 static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] __devinitdata = {
     2655static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] = {
    26642656        DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel2),
    26652657        DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase2),
     
    26742666
    26752667/* card control switches */
    2676 static struct snd_kcontrol_new snd_cmipci_modem_switch __devinitdata =
     2668static struct snd_kcontrol_new snd_cmipci_modem_switch =
    26772669DEFINE_CARD_SWITCH("Modem", modem);
    26782670
    26792671
    2680 static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
     2672static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
    26812673{
    26822674        struct snd_card *card;
     
    27872779 */
    27882780
    2789 #ifdef CONFIG_PROC_FS
    27902781static void snd_cmipci_proc_read(struct snd_info_entry *entry,
    27912782                                 struct snd_info_buffer *buffer)
     
    28062797}
    28072798
    2808 static void __devinit snd_cmipci_proc_init(struct cmipci *cm)
    2809 {
    2810         struct snd_info_entry *entry;
    2811 
    2812         if (! snd_card_proc_new(cm->card, "cmipci", &entry))
    2813                 snd_info_set_text_ops(entry, cm, snd_cmipci_proc_read);
    2814 }
    2815 #else /* !CONFIG_PROC_FS */
    2816 static inline void snd_cmipci_proc_init(struct cmipci *cm) {}
    2817 #endif
    2818 
    2819 
    2820 static DEFINE_PCI_DEVICE_TABLE(snd_cmipci_ids) = {
     2799static void snd_cmipci_proc_init(struct cmipci *cm)
     2800{
     2801        snd_card_ro_proc_new(cm->card, "cmipci", cm, snd_cmipci_proc_read);
     2802}
     2803
     2804static const struct pci_device_id snd_cmipci_ids[] = {
    28212805        {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A), 0},
    28222806        {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B), 0},
     
    28322816 * driver name is modified according to the chip model
    28332817 */
    2834 static void __devinit query_chip(struct cmipci *cm)
     2818static void query_chip(struct cmipci *cm)
    28352819{
    28362820        unsigned int detect;
     
    28812865
    28822866#ifdef SUPPORT_JOYSTICK
    2883 static int __devinit snd_cmipci_create_gameport(struct cmipci *cm, int dev)
     2867static int snd_cmipci_create_gameport(struct cmipci *cm, int dev)
    28842868{
    28852869        static int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */
     
    29042888
    29052889        if (!r) {
    2906                 printk(KERN_WARNING "cmipci: cannot reserve joystick ports\n");
     2890                dev_warn(cm->card->dev, "cannot reserve joystick ports\n");
    29072891                return -EBUSY;
    29082892        }
     
    29102894        cm->gameport = gp = gameport_allocate_port();
    29112895        if (!gp) {
    2912                 printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n");
     2896                dev_err(cm->card->dev, "cannot allocate memory for gameport\n");
    29132897                release_and_free_resource(r);
    29142898                return -ENOMEM;
     
    29742958}
    29752959
    2976 static int __devinit snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
     2960static int snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
    29772961{
    29782962        long iosynth;
     
    30102994                if (snd_opl3_create(cm->card, iosynth, iosynth + 2,
    30112995                                    OPL3_HW_OPL3, 0, &opl3) < 0) {
    3012                         printk(KERN_ERR "cmipci: no OPL device at %#lx, "
    3013                                "skipping...\n", iosynth);
     2996                        dev_err(cm->card->dev,
     2997                                "no OPL device at %#lx, skipping...\n",
     2998                                iosynth);
    30142999                        goto disable_fm;
    30153000                }
    30163001        }
    30173002        if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
    3018                 printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
     3003                dev_err(cm->card->dev, "cannot create OPL3 hwdep\n");
    30193004                return err;
    30203005        }
     
    30273012}
    30283013
    3029 static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
    3030                                        int dev, struct cmipci **rcmipci)
     3014static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
     3015                             int dev, struct cmipci **rcmipci)
    30313016{
    30323017        struct cmipci *cm;
     
    30403025        char modelstr[16];
    30413026        int pcm_index, pcm_spdif_index;
    3042         static DEFINE_PCI_DEVICE_TABLE(intel_82437vx) = {
     3027        static const struct pci_device_id intel_82437vx[] = {
    30433028                { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
    30443029                {0},
     
    30753060        if (request_irq(pci->irq, snd_cmipci_interrupt,
    30763061                        IRQF_SHARED, KBUILD_MODNAME, cm)) {
    3077                 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
     3062                dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
    30783063                snd_cmipci_free(cm);
    30793064                return -EBUSY;
     
    32073192                        snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN);
    32083193                        if (inb(iomidi + 1) == 0xff) {
    3209                                 snd_printk(KERN_ERR "cannot enable MPU-401 port"
    3210                                            " at %#lx\n", iomidi);
     3194                                dev_err(cm->card->dev,
     3195                                        "cannot enable MPU-401 port at %#lx\n",
     3196                                        iomidi);
    32113197                                snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1,
    32123198                                                     CM_UART_EN);
     
    32523238                                               MPU401_INFO_IRQ_HOOK,
    32533239                                               -1, &cm->rmidi)) < 0) {
    3254                         printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi);
     3240                        dev_err(cm->card->dev,
     3241                                "no UART401 device at 0x%lx\n", iomidi);
    32553242                }
    32563243        }
     
    32693256                snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
    32703257
    3271         snd_card_set_dev(card, &pci->dev);
    3272 
    32733258        *rcmipci = cm;
    32743259        return 0;
     
    32803265MODULE_DEVICE_TABLE(pci, snd_cmipci_ids);
    32813266
    3282 static int __devinit snd_cmipci_probe(struct pci_dev *pci,
    3283                                       const struct pci_device_id *pci_id)
     3267static int snd_cmipci_probe(struct pci_dev *pci,
     3268                            const struct pci_device_id *pci_id)
    32843269{
    32853270        static int dev;
     
    32953280        }
    32963281
    3297         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     3282        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     3283                           0, &card);
    32983284        if (err < 0)
    32993285                return err;
     
    33133299        }
    33143300
    3315         if ((err = snd_cmipci_create(card, pci, dev, &cm)) < 0) {
    3316                 snd_card_free(card);
    3317                 return err;
    3318         }
     3301        err = snd_cmipci_create(card, pci, dev, &cm);
     3302        if (err < 0)
     3303                goto free_card;
     3304
    33193305        card->private_data = cm;
    33203306
    3321         if ((err = snd_card_register(card)) < 0) {
    3322                 snd_card_free(card);
    3323                 return err;
    3324         }
     3307        err = snd_card_register(card);
     3308        if (err < 0)
     3309                goto free_card;
     3310
    33253311        pci_set_drvdata(pci, card);
    33263312        dev++;
    33273313        return 0;
    33283314
    3329 }
    3330 
    3331 static void __devexit snd_cmipci_remove(struct pci_dev *pci)
     3315free_card:
     3316        snd_card_free(card);
     3317        return err;
     3318}
     3319
     3320static void snd_cmipci_remove(struct pci_dev *pci)
    33323321{
    33333322        snd_card_free(pci_get_drvdata(pci));
    3334         pci_set_drvdata(pci, NULL);
    3335 }
    3336 
    3337 
    3338 #ifdef CONFIG_PM
     3323}
     3324
     3325
     3326#ifdef CONFIG_PM_SLEEP
    33393327/*
    33403328 * power management
     
    33593347};
    33603348
    3361 static int snd_cmipci_suspend(struct pci_dev *pci, pm_message_t state)
    3362 {
    3363         struct snd_card *card = pci_get_drvdata(pci);
     3349static int snd_cmipci_suspend(struct device *dev)
     3350{
     3351        struct snd_card *card = dev_get_drvdata(dev);
    33643352        struct cmipci *cm = card->private_data;
    33653353        int i;
     
    33673355        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    33683356       
    3369         snd_pcm_suspend_all(cm->pcm);
    3370         snd_pcm_suspend_all(cm->pcm2);
    3371         snd_pcm_suspend_all(cm->pcm_spdif);
    3372 
    33733357        /* save registers */
    33743358        for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
     
    33793363        /* disable ints */
    33803364        snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0);
    3381 
    3382         pci_disable_device(pci);
    3383         pci_save_state(pci);
    3384         pci_set_power_state(pci, pci_choose_state(pci, state));
    3385         return 0;
    3386 }
    3387 
    3388 static int snd_cmipci_resume(struct pci_dev *pci)
    3389 {
    3390         struct snd_card *card = pci_get_drvdata(pci);
     3365        return 0;
     3366}
     3367
     3368static int snd_cmipci_resume(struct device *dev)
     3369{
     3370        struct snd_card *card = dev_get_drvdata(dev);
    33913371        struct cmipci *cm = card->private_data;
    33923372        int i;
    3393 
    3394         pci_set_power_state(pci, PCI_D0);
    3395         pci_restore_state(pci);
    3396         if (pci_enable_device(pci) < 0) {
    3397                 printk(KERN_ERR "cmipci: pci_enable_device failed, "
    3398                        "disabling device\n");
    3399                 snd_card_disconnect(card);
    3400                 return -EIO;
    3401         }
    3402         pci_set_master(pci);
    34033373
    34043374        /* reset / initialize to a sane state */
     
    34173387        return 0;
    34183388}
    3419 #endif /* CONFIG_PM */
    3420 
    3421 static struct pci_driver driver = {
     3389
     3390static SIMPLE_DEV_PM_OPS(snd_cmipci_pm, snd_cmipci_suspend, snd_cmipci_resume);
     3391#define SND_CMIPCI_PM_OPS       &snd_cmipci_pm
     3392#else
     3393#define SND_CMIPCI_PM_OPS       NULL
     3394#endif /* CONFIG_PM_SLEEP */
     3395
     3396static struct pci_driver cmipci_driver = {
    34223397        .name = KBUILD_MODNAME,
    34233398        .id_table = snd_cmipci_ids,
    34243399        .probe = snd_cmipci_probe,
    3425         .remove = __devexit_p(snd_cmipci_remove),
    3426 #ifdef CONFIG_PM
    3427         .suspend = snd_cmipci_suspend,
    3428         .resume = snd_cmipci_resume,
    3429 #endif
     3400        .remove = snd_cmipci_remove,
     3401        .driver = {
     3402                .pm = SND_CMIPCI_PM_OPS,
     3403        },
    34303404};
    34313405       
    3432 static int __init alsa_card_cmipci_init(void)
    3433 {
    3434         return pci_register_driver(&driver);
    3435 }
    3436 
    3437 static void __exit alsa_card_cmipci_exit(void)
    3438 {
    3439         pci_unregister_driver(&driver);
    3440 }
    3441 
    3442 module_init(alsa_card_cmipci_init)
    3443 module_exit(alsa_card_cmipci_exit)
     3406module_pci_driver(cmipci_driver);
Note: See TracChangeset for help on using the changeset viewer.