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/ens1370.c

    r607 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Driver for Ensoniq ES1370/ES1371 AudioPCI soundcard
    34 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
    45 *                   Thomas Sailer <sailer@ife.ee.ethz.ch>
    5  *
    6  *   This program is free software; you can redistribute it and/or modify
    7  *   it under the terms of the GNU General Public License as published by
    8  *   the Free Software Foundation; either version 2 of the License, or
    9  *   (at your option) any later version.
    10  *
    11  *   This program is distributed in the hope that it will be useful,
    12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  *   GNU General Public License for more details.
    15  *
    16  *   You should have received a copy of the GNU General Public License
    17  *   along with this program; if not, write to the Free Software
    18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    19  *
    206 */
    217
     
    239 * for ens1371 only ( FIXME )
    2410 * derived from cs4281.c, atiixp.c and via82xx.c
    25  * using http://www.alsa-project.org/~tiwai/writing-an-alsa-driver/
     11 * using http://www.alsa-project.org/~tiwai/writing-an-alsa-driver/ 
    2612 * by Kurt J. Bosch
    2713 */
    2814
    29 #include <asm/io.h>
     15#include <linux/io.h>
    3016#include <linux/delay.h>
    3117#include <linux/interrupt.h>
     
    3420#include <linux/slab.h>
    3521#include <linux/gameport.h>
    36 #include <linux/moduleparam.h>
     22#include <linux/module.h>
    3723#include <linux/mutex.h>
    3824
     
    5642#ifdef CHIP1370
    5743#define DRIVER_NAME "ENS1370"
     44#define CHIP_NAME "ES1370" /* it can be ENS but just to keep compatibility... */
    5845#else
    5946#define DRIVER_NAME "ENS1371"
    60 #endif
    61 
    62 
     47#define CHIP_NAME "ES1371"
     48#endif
     49
     50
     51#ifdef TARGET_OS2
     52#define KBUILD_MODNAME "ens137x"
     53#endif
    6354MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Thomas Sailer <sailer@ife.ee.ethz.ch>");
    6455MODULE_LICENSE("GPL");
     
    7869#endif
    7970
    80 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
     71#if IS_REACHABLE(CONFIG_GAMEPORT)
    8172#define SUPPORT_JOYSTICK
    8273#endif
     
    8475static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    8576static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    86 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable switches */
     77static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable switches */
    8778#ifdef SUPPORT_JOYSTICK
    8879#ifdef CHIP1371
    8980static int joystick_port[SNDRV_CARDS];
    9081#else
    91 static int joystick[SNDRV_CARDS];
     82static bool joystick[SNDRV_CARDS];
    9283#endif
    9384#endif
     
    10596#ifdef SUPPORT_JOYSTICK
    10697#ifdef CHIP1371
    107 module_param_array(joystick_port, int, NULL, 0444);
     98module_param_hw_array(joystick_port, int, ioport, NULL, 0444);
    10899MODULE_PARM_DESC(joystick_port, "Joystick port address.");
    109100#else
     
    230221#define   ES_1371_CODEC_RDY        (1<<31)      /* codec ready */
    231222#define   ES_1371_CODEC_WIP        (1<<30)      /* codec register access in progress */
     223#define   EV_1938_CODEC_MAGIC      (1<<26)
    232224#define   ES_1371_CODEC_PIRD       (1<<23)      /* codec read/write select register */
    233225#define   ES_1371_CODEC_WRITE(a,d) ((((a)&0x7f)<<16)|(((d)&0xffff)<<0))
     
    444436static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id);
    445437
    446 static DEFINE_PCI_DEVICE_TABLE(snd_audiopci_ids) = {
     438static const struct pci_device_id snd_audiopci_ids[] = {
    447439#ifdef CHIP1370
    448440        { PCI_VDEVICE(ENSONIQ, 0x5000), 0, },   /* ES1370 */
     
    465457
    466458#ifdef CHIP1370
    467 static unsigned int snd_es1370_fixed_rates[] =
     459static const unsigned int snd_es1370_fixed_rates[] =
    468460        {5512, 11025, 22050, 44100};
    469 static struct snd_pcm_hw_constraint_list snd_es1370_hw_constraints_rates = {
    470         .count = 4,
     461static const struct snd_pcm_hw_constraint_list snd_es1370_hw_constraints_rates = {
     462        .count = 4, 
    471463        .list = snd_es1370_fixed_rates,
    472464        .mask = 0,
    473465};
    474 static struct snd_ratnum es1370_clock = {
     466static const struct snd_ratnum es1370_clock = {
    475467        .num = ES_1370_SRCLOCK,
    476         .den_min = 29,
     468        .den_min = 29, 
    477469        .den_max = 353,
    478470        .den_step = 1,
    479471};
    480 static struct snd_pcm_hw_constraint_ratnums snd_es1370_hw_constraints_clock = {
     472static const struct snd_pcm_hw_constraint_ratnums snd_es1370_hw_constraints_clock = {
    481473        .nrats = 1,
    482474        .rats = &es1370_clock,
    483475};
    484476#else
    485 static struct snd_ratden es1371_dac_clock = {
     477static const struct snd_ratden es1371_dac_clock = {
    486478        .num_min = 3000 * (1 << 15),
    487479        .num_max = 48000 * (1 << 15),
     
    489481        .den = 1 << 15,
    490482};
    491 static struct snd_pcm_hw_constraint_ratdens snd_es1371_hw_constraints_dac_clock = {
     483static const struct snd_pcm_hw_constraint_ratdens snd_es1371_hw_constraints_dac_clock = {
    492484        .nrats = 1,
    493485        .rats = &es1371_dac_clock,
    494486};
    495 static struct snd_ratnum es1371_adc_clock = {
     487static const struct snd_ratnum es1371_adc_clock = {
    496488        .num = 48000 << 15,
    497         .den_min = 32768,
     489        .den_min = 32768, 
    498490        .den_max = 393216,
    499491        .den_step = 1,
    500492};
    501 static struct snd_pcm_hw_constraint_ratnums snd_es1371_hw_constraints_adc_clock = {
     493static const struct snd_pcm_hw_constraint_ratnums snd_es1371_hw_constraints_adc_clock = {
    502494        .nrats = 1,
    503495        .rats = &es1371_adc_clock,
     
    523515                cond_resched();
    524516        }
    525         snd_printk(KERN_ERR "wait src ready timeout 0x%lx [0x%x]\n",
     517        dev_err(ensoniq->card->dev, "wait src ready timeout 0x%lx [0x%x]\n",
    526518                   ES_REG(ensoniq, 1371_SMPRATE), r);
    527519        return 0;
     
    585577
    586578#if 0
    587         printk(KERN_DEBUG
     579        dev_dbg(ensoniq->card->dev,
    588580               "CODEC WRITE: reg = 0x%x, val = 0x%x (0x%x), creg = 0x%x\n",
    589581               reg, val, ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC));
     
    596588                schedule_timeout_uninterruptible(1);
    597589        } while (time_after(end_time, jiffies));
    598         snd_printk(KERN_ERR "codec write timeout, status = 0x%x\n",
     590        dev_err(ensoniq->card->dev, "codec write timeout, status = 0x%x\n",
    599591                   inl(ES_REG(ensoniq, STATUS)));
    600592}
     
    603595
    604596#ifdef CHIP1371
     597
     598static inline bool is_ev1938(struct ensoniq *ensoniq)
     599{
     600        return ensoniq->pci->device == 0x8938;
     601}
    605602
    606603static void snd_es1371_codec_write(struct snd_ac97 *ac97,
     
    608605{
    609606        struct ensoniq *ensoniq = ac97->private_data;
    610         unsigned int t, x;
    611 
     607        unsigned int t, x, flag;
     608
     609        flag = is_ev1938(ensoniq) ? EV_1938_CODEC_MAGIC : 0;
    612610        mutex_lock(&ensoniq->src_mutex);
    613611        for (t = 0; t < POLL_COUNT; t++) {
     
    631629                                        break;
    632630                        }
    633                         outl(ES_1371_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1371_CODEC));
     631                        outl(ES_1371_CODEC_WRITE(reg, val) | flag,
     632                             ES_REG(ensoniq, 1371_CODEC));
    634633                        /* restore SRC reg */
    635634                        snd_es1371_wait_src_ready(ensoniq);
     
    640639        }
    641640        mutex_unlock(&ensoniq->src_mutex);
    642         snd_printk(KERN_ERR "codec write timeout at 0x%lx [0x%x]\n",
     641        dev_err(ensoniq->card->dev, "codec write timeout at 0x%lx [0x%x]\n",
    643642                   ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
    644643}
     
    648647{
    649648        struct ensoniq *ensoniq = ac97->private_data;
    650         unsigned int t, x, fail = 0;
    651 
     649        unsigned int t, x, flag, fail = 0;
     650
     651        flag = is_ev1938(ensoniq) ? EV_1938_CODEC_MAGIC : 0;
    652652      __again:
    653653        mutex_lock(&ensoniq->src_mutex);
     
    672672                                        break;
    673673                        }
    674                         outl(ES_1371_CODEC_READS(reg), ES_REG(ensoniq, 1371_CODEC));
     674                        outl(ES_1371_CODEC_READS(reg) | flag,
     675                             ES_REG(ensoniq, 1371_CODEC));
    675676                        /* restore SRC reg */
    676677                        snd_es1371_wait_src_ready(ensoniq);
     
    684685                        for (t = 0; t < POLL_COUNT; t++) {
    685686                                if ((x = inl(ES_REG(ensoniq, 1371_CODEC))) & ES_1371_CODEC_RDY) {
     687                                        if (is_ev1938(ensoniq)) {
     688                                                for (t = 0; t < 100; t++)
     689                                                        inl(ES_REG(ensoniq, CONTROL));
     690                                                x = inl(ES_REG(ensoniq, 1371_CODEC));
     691                                        }
    686692                                        mutex_unlock(&ensoniq->src_mutex);
    687693                                        return ES_1371_CODEC_READ(x);
     
    690696                        mutex_unlock(&ensoniq->src_mutex);
    691697                        if (++fail > 10) {
    692                                 snd_printk(KERN_ERR "codec read timeout (final) "
    693                                            "at 0x%lx, reg = 0x%x [0x%x]\n",
     698                                dev_err(ensoniq->card->dev,
     699                                        "codec read timeout (final) at 0x%lx, reg = 0x%x [0x%x]\n",
    694700                                           ES_REG(ensoniq, 1371_CODEC), reg,
    695701                                           inl(ES_REG(ensoniq, 1371_CODEC)));
     
    700706        }
    701707        mutex_unlock(&ensoniq->src_mutex);
    702         snd_printk(KERN_ERR "es1371: codec read timeout at 0x%lx [0x%x]\n",
     708        dev_err(ensoniq->card->dev, "codec read timeout at 0x%lx [0x%x]\n",
    703709                   ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
    704710        return 0;
     
    716722static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate)
    717723{
    718         unsigned int n, truncm, freq, result;
     724        unsigned int n, truncm, freq;
    719725
    720726        mutex_lock(&ensoniq->src_mutex);
     
    724730        truncm = (21 * n - 1) | 1;
    725731        freq = ((48000UL << 15) / rate) * n;
    726         result = (48000UL << 15) / (freq / n);
    727732        if (rate >= 24000) {
    728733                if (truncm > 239)
     
    855860 */
    856861
    857 static int snd_ensoniq_hw_params(struct snd_pcm_substream *substream,
    858                                  struct snd_pcm_hw_params *hw_params)
    859 {
    860         return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    861 }
    862 
    863 static int snd_ensoniq_hw_free(struct snd_pcm_substream *substream)
    864 {
    865         return snd_pcm_lib_free_pages(substream);
    866 }
    867 
    868862static int snd_ensoniq_playback1_prepare(struct snd_pcm_substream *substream)
    869863{
     
    10431037}
    10441038
    1045 static struct snd_pcm_hardware snd_ensoniq_playback1 =
     1039static const struct snd_pcm_hardware snd_ensoniq_playback1 =
    10461040{
    10471041        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    10551049#else
    10561050                                (SNDRV_PCM_RATE_KNOT |  /* 5512Hz rate */
    1057                                  SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_22050 |
     1051                                 SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_22050 | 
    10581052                                 SNDRV_PCM_RATE_44100),
    10591053#endif
     
    10701064};
    10711065
    1072 static struct snd_pcm_hardware snd_ensoniq_playback2 =
     1066static const struct snd_pcm_hardware snd_ensoniq_playback2 =
    10731067{
    10741068        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
    10751069                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
    1076                                  SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE |
     1070                                 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE | 
    10771071                                 SNDRV_PCM_INFO_SYNC_START),
    10781072        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
     
    10901084};
    10911085
    1092 static struct snd_pcm_hardware snd_ensoniq_capture =
     1086static const struct snd_pcm_hardware snd_ensoniq_capture =
    10931087{
    10941088        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    12111205}
    12121206
    1213 static struct snd_pcm_ops snd_ensoniq_playback1_ops = {
     1207static const struct snd_pcm_ops snd_ensoniq_playback1_ops = {
    12141208        .open =         snd_ensoniq_playback1_open,
    12151209        .close =        snd_ensoniq_playback1_close,
    1216         .ioctl =        snd_pcm_lib_ioctl,
    1217         .hw_params =    snd_ensoniq_hw_params,
    1218         .hw_free =      snd_ensoniq_hw_free,
    12191210        .prepare =      snd_ensoniq_playback1_prepare,
    12201211        .trigger =      snd_ensoniq_trigger,
     
    12221213};
    12231214
    1224 static struct snd_pcm_ops snd_ensoniq_playback2_ops = {
     1215static const struct snd_pcm_ops snd_ensoniq_playback2_ops = {
    12251216        .open =         snd_ensoniq_playback2_open,
    12261217        .close =        snd_ensoniq_playback2_close,
    1227         .ioctl =        snd_pcm_lib_ioctl,
    1228         .hw_params =    snd_ensoniq_hw_params,
    1229         .hw_free =      snd_ensoniq_hw_free,
    12301218        .prepare =      snd_ensoniq_playback2_prepare,
    12311219        .trigger =      snd_ensoniq_trigger,
     
    12331221};
    12341222
    1235 static struct snd_pcm_ops snd_ensoniq_capture_ops = {
     1223static const struct snd_pcm_ops snd_ensoniq_capture_ops = {
    12361224        .open =         snd_ensoniq_capture_open,
    12371225        .close =        snd_ensoniq_capture_close,
    1238         .ioctl =        snd_pcm_lib_ioctl,
    1239         .hw_params =    snd_ensoniq_hw_params,
    1240         .hw_free =      snd_ensoniq_hw_free,
    12411226        .prepare =      snd_ensoniq_capture_prepare,
    12421227        .trigger =      snd_ensoniq_trigger,
     
    12441229};
    12451230
    1246 static int __devinit snd_ensoniq_pcm(struct ensoniq * ensoniq, int device,
    1247                                      struct snd_pcm ** rpcm)
     1231static const struct snd_pcm_chmap_elem surround_map[] = {
     1232        { .channels = 1,
     1233          .map = { SNDRV_CHMAP_MONO } },
     1234        { .channels = 2,
     1235          .map = { SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
     1236        {0}
     1237};
     1238
     1239static int snd_ensoniq_pcm(struct ensoniq *ensoniq, int device)
    12481240{
    12491241        struct snd_pcm *pcm;
    12501242        int err;
    12511243
    1252         if (rpcm)
    1253                 *rpcm = NULL;
    1254 #ifdef CHIP1370
    1255         err = snd_pcm_new(ensoniq->card, "ES1370/1", device, 1, 1, &pcm);
    1256 #else
    1257         err = snd_pcm_new(ensoniq->card, "ES1371/1", device, 1, 1, &pcm);
    1258 #endif
     1244        err = snd_pcm_new(ensoniq->card, CHIP_NAME "/1", device, 1, 1, &pcm);
    12591245        if (err < 0)
    12601246                return err;
     
    12691255        pcm->private_data = ensoniq;
    12701256        pcm->info_flags = 0;
    1271 #ifdef CHIP1370
    1272         strcpy(pcm->name, "ES1370 DAC2/ADC");
     1257        strcpy(pcm->name, CHIP_NAME " DAC2/ADC");
     1258        ensoniq->pcm1 = pcm;
     1259
     1260        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
     1261                                       &ensoniq->pci->dev, 64*1024, 128*1024);
     1262
     1263#ifdef CHIP1370
     1264        err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
     1265                                     surround_map, 2, 0, NULL);
    12731266#else
    1274         strcpy(pcm->name, "ES1371 DAC2/ADC");
    1275 #endif
    1276         ensoniq->pcm1 = pcm;
    1277 
    1278         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
    1279                                               snd_dma_pci_data(ensoniq->pci), 64*1024, 128*1024);
    1280 
    1281         if (rpcm)
    1282                 *rpcm = pcm;
    1283         return 0;
    1284 }
    1285 
    1286 static int __devinit snd_ensoniq_pcm2(struct ensoniq * ensoniq, int device,
    1287                                       struct snd_pcm ** rpcm)
     1267        err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
     1268                                     snd_pcm_std_chmaps, 2, 0, NULL);
     1269#endif
     1270        return err;
     1271}
     1272
     1273static int snd_ensoniq_pcm2(struct ensoniq *ensoniq, int device)
    12881274{
    12891275        struct snd_pcm *pcm;
    12901276        int err;
    12911277
    1292         if (rpcm)
    1293                 *rpcm = NULL;
    1294 #ifdef CHIP1370
    1295         err = snd_pcm_new(ensoniq->card, "ES1370/2", device, 1, 0, &pcm);
    1296 #else
    1297         err = snd_pcm_new(ensoniq->card, "ES1371/2", device, 1, 0, &pcm);
    1298 #endif
     1278        err = snd_pcm_new(ensoniq->card, CHIP_NAME "/2", device, 1, 0, &pcm);
    12991279        if (err < 0)
    13001280                return err;
     
    13071287        pcm->private_data = ensoniq;
    13081288        pcm->info_flags = 0;
    1309 #ifdef CHIP1370
    1310         strcpy(pcm->name, "ES1370 DAC1");
     1289        strcpy(pcm->name, CHIP_NAME " DAC1");
     1290        ensoniq->pcm2 = pcm;
     1291
     1292        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
     1293                                       &ensoniq->pci->dev, 64*1024, 128*1024);
     1294
     1295#ifdef CHIP1370
     1296        err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
     1297                                     snd_pcm_std_chmaps, 2, 0, NULL);
    13111298#else
    1312         strcpy(pcm->name, "ES1371 DAC1");
    1313 #endif
    1314         ensoniq->pcm2 = pcm;
    1315 
    1316         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
    1317                                               snd_dma_pci_data(ensoniq->pci), 64*1024, 128*1024);
    1318 
    1319         if (rpcm)
    1320                 *rpcm = pcm;
    1321         return 0;
     1299        err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
     1300                                     surround_map, 2, 0, NULL);
     1301#endif
     1302        return err;
    13221303}
    13231304
     
    14561437
    14571438/* spdif controls */
    1458 static struct snd_kcontrol_new snd_es1371_mixer_spdif[] __devinitdata = {
     1439static const struct snd_kcontrol_new snd_es1371_mixer_spdif[] = {
    14591440        ES1371_SPDIF(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH)),
    14601441        {
     
    15181499}
    15191500
    1520 static struct snd_kcontrol_new snd_ens1373_rear __devinitdata =
     1501static const struct snd_kcontrol_new snd_ens1373_rear =
    15211502{
    15221503        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     
    15361517       
    15371518        spin_lock_irq(&ensoniq->reg_lock);
    1538         if ((ensoniq->ctrl & ES_1371_GPIO_OUTM) >= 4)
     1519        if (ensoniq->ctrl & ES_1371_GPIO_OUT(4))
    15391520                val = 1;
    15401521        ucontrol->value.integer.value[0] = val;
     
    15631544}
    15641545
    1565 static struct snd_kcontrol_new snd_ens1373_line __devinitdata =
     1546static const struct snd_kcontrol_new snd_ens1373_line =
    15661547{
    15671548        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     
    15851566
    15861567static int es1371_quirk_lookup(struct ensoniq *ensoniq,
    1587                                 struct es1371_quirk *list)
     1568                               const struct es1371_quirk *list)
    15881569{
    15891570        while (list->vid != (unsigned short)PCI_ANY_ID) {
     
    15971578}
    15981579
    1599 static struct es1371_quirk es1371_spdif_present[] __devinitdata = {
     1580static const struct es1371_quirk es1371_spdif_present[] = {
    16001581        { .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_C },
    16011582        { .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_D },
     
    16061587};
    16071588
    1608 static struct snd_pci_quirk ens1373_line_quirk[] __devinitdata = {
     1589static const struct snd_pci_quirk ens1373_line_quirk[] = {
    16091590        SND_PCI_QUIRK_ID(0x1274, 0x2000), /* GA-7DXR */
    16101591        SND_PCI_QUIRK_ID(0x1458, 0xa000), /* GA-8IEXP */
     
    16121593};
    16131594
    1614 static int __devinit snd_ensoniq_1371_mixer(struct ensoniq *ensoniq,
    1615                                             int has_spdif, int has_line)
     1595static int snd_ensoniq_1371_mixer(struct ensoniq *ensoniq,
     1596                                  int has_spdif, int has_line)
    16161597{
    16171598        struct snd_card *card = ensoniq->card;
     
    16191600        struct snd_ac97_template ac97;
    16201601        int err;
    1621         static struct snd_ac97_bus_ops ops = {
     1602        static const struct snd_ac97_bus_ops ops = {
    16221603                .write = snd_es1371_codec_write,
    16231604                .read = snd_es1371_codec_read,
     
    17211702 */
    17221703
    1723 static struct snd_kcontrol_new snd_es1370_controls[2] __devinitdata = {
     1704static const struct snd_kcontrol_new snd_es1370_controls[2] = {
    17241705ENSONIQ_CONTROL("PCM 0 Output also on Line-In Jack", ES_1370_XCTL0),
    17251706ENSONIQ_CONTROL("Mic +5V bias", ES_1370_XCTL1)
     
    17341715}
    17351716
    1736 static int __devinit snd_ensoniq_1370_mixer(struct ensoniq * ensoniq)
     1717static int snd_ensoniq_1370_mixer(struct ensoniq *ensoniq)
    17371718{
    17381719        struct snd_card *card = ensoniq->card;
     
    17681749
    17691750#ifdef CHIP1371
    1770 static int __devinit snd_ensoniq_get_joystick_port(int dev)
     1751static int snd_ensoniq_get_joystick_port(struct ensoniq *ensoniq, int dev)
    17711752{
    17721753        switch (joystick_port[dev]) {
     
    17801761
    17811762        default:
    1782                 printk(KERN_ERR "ens1371: invalid joystick port %#x", joystick_port[dev]);
     1763                dev_err(ensoniq->card->dev,
     1764                        "invalid joystick port %#x", joystick_port[dev]);
    17831765                return 0;
    17841766        }
    17851767}
    17861768#else
    1787 static inline int snd_ensoniq_get_joystick_port(int dev)
     1769static int snd_ensoniq_get_joystick_port(struct ensoniq *ensoniq, int dev)
    17881770{
    17891771        return joystick[dev] ? 0x200 : 0;
     
    17911773#endif
    17921774
    1793 static int __devinit snd_ensoniq_create_gameport(struct ensoniq *ensoniq, int dev)
     1775static int snd_ensoniq_create_gameport(struct ensoniq *ensoniq, int dev)
    17941776{
    17951777        struct gameport *gp;
    17961778        int io_port;
    17971779
    1798         io_port = snd_ensoniq_get_joystick_port(dev);
     1780        io_port = snd_ensoniq_get_joystick_port(ensoniq, dev);
    17991781
    18001782        switch (io_port) {
     
    18071789                                break;
    18081790                if (io_port > 0x218) {
    1809                         printk(KERN_WARNING "ens137x: no gameport ports available\n");
     1791                        dev_warn(ensoniq->card->dev,
     1792                                 "no gameport ports available\n");
    18101793                        return -EBUSY;
    18111794                }
     
    18141797        default:
    18151798                if (!request_region(io_port, 8, "ens137x: gameport")) {
    1816                         printk(KERN_WARNING "ens137x: gameport io port 0x%#x in use\n",
     1799                        dev_warn(ensoniq->card->dev,
     1800                                 "gameport io port %#x in use\n",
    18171801                               io_port);
    18181802                        return -EBUSY;
     
    18231807        ensoniq->gameport = gp = gameport_allocate_port();
    18241808        if (!gp) {
    1825                 printk(KERN_ERR "ens137x: cannot allocate memory for gameport\n");
     1809                dev_err(ensoniq->card->dev,
     1810                        "cannot allocate memory for gameport\n");
    18261811                release_region(io_port, 8);
    18271812                return -ENOMEM;
     
    18661851 */
    18671852
    1868 static void snd_ensoniq_proc_read(struct snd_info_entry *entry,
     1853static void snd_ensoniq_proc_read(struct snd_info_entry *entry, 
    18691854                                  struct snd_info_buffer *buffer)
    18701855{
    18711856        struct ensoniq *ensoniq = entry->private_data;
    18721857
    1873 #ifdef CHIP1370
    1874         snd_iprintf(buffer, "Ensoniq AudioPCI ES1370\n\n");
    1875 #else
    1876         snd_iprintf(buffer, "Ensoniq AudioPCI ES1371\n\n");
    1877 #endif
     1858        snd_iprintf(buffer, "Ensoniq AudioPCI " CHIP_NAME "\n\n");
    18781859        snd_iprintf(buffer, "Joystick enable  : %s\n",
    18791860                    ensoniq->ctrl & ES_JYSTK_EN ? "on" : "off");
     
    18891870}
    18901871
    1891 static void __devinit snd_ensoniq_proc_init(struct ensoniq * ensoniq)
    1892 {
    1893         struct snd_info_entry *entry;
    1894 
    1895         if (! snd_card_proc_new(ensoniq->card, "audiopci", &entry))
    1896                 snd_info_set_text_ops(entry, ensoniq, snd_ensoniq_proc_read);
     1872static void snd_ensoniq_proc_init(struct ensoniq *ensoniq)
     1873{
     1874        snd_card_ro_proc_new(ensoniq->card, "audiopci", ensoniq,
     1875                             snd_ensoniq_proc_read);
    18971876}
    18981877
     
    19131892        outl(0, ES_REG(ensoniq, SERIAL));       /* clear serial interface */
    19141893#endif
    1915         if (ensoniq->irq >= 0)
    1916                 synchronize_irq(ensoniq->irq);
    1917         pci_set_power_state(ensoniq->pci, 3);
     1894        pci_set_power_state(ensoniq->pci, PCI_D3hot);
    19181895      __hw_end:
    19191896#ifdef CHIP1370
     
    19361913
    19371914#ifdef CHIP1371
    1938 static struct snd_pci_quirk es1371_amplifier_hack[] __devinitdata = {
     1915static const struct snd_pci_quirk es1371_amplifier_hack[] = {
    19391916        SND_PCI_QUIRK_ID(0x107b, 0x2150),       /* Gateway Solo 2150 */
    19401917        SND_PCI_QUIRK_ID(0x13bd, 0x100c),       /* EV1938 on Mebius PC-MJ100V */
     
    19441921};
    19451922
    1946 static struct es1371_quirk es1371_ac97_reset_hack[] = {
     1923static const struct es1371_quirk es1371_ac97_reset_hack[] = {
    19471924        { .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_C },
    19481925        { .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_D },
     
    20151992        outb(0x00, ES_REG(ensoniq, UART_RES));
    20161993        outl(ensoniq->cssr, ES_REG(ensoniq, STATUS));
    2017         synchronize_irq(ensoniq->irq);
    2018 }
    2019 
    2020 #ifdef CONFIG_PM
    2021 static int snd_ensoniq_suspend(struct pci_dev *pci, pm_message_t state)
    2022 {
    2023         struct snd_card *card = pci_get_drvdata(pci);
     1994}
     1995
     1996#ifdef CONFIG_PM_SLEEP
     1997static int snd_ensoniq_suspend(struct device *dev)
     1998{
     1999        struct snd_card *card = dev_get_drvdata(dev);
    20242000        struct ensoniq *ensoniq = card->private_data;
    20252001       
    20262002        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    20272003
    2028         snd_pcm_suspend_all(ensoniq->pcm1);
    2029         snd_pcm_suspend_all(ensoniq->pcm2);
    2030        
    20312004#ifdef CHIP1371
    20322005        snd_ac97_suspend(ensoniq->u.es1371.ac97);
     
    20412014        snd_ak4531_suspend(ensoniq->u.es1370.ak4531);
    20422015#endif 
    2043 
    2044         pci_disable_device(pci);
    2045         pci_save_state(pci);
    2046         pci_set_power_state(pci, pci_choose_state(pci, state));
    2047         return 0;
    2048 }
    2049 
    2050 static int snd_ensoniq_resume(struct pci_dev *pci)
    2051 {
    2052         struct snd_card *card = pci_get_drvdata(pci);
     2016        return 0;
     2017}
     2018
     2019static int snd_ensoniq_resume(struct device *dev)
     2020{
     2021        struct snd_card *card = dev_get_drvdata(dev);
    20532022        struct ensoniq *ensoniq = card->private_data;
    2054 
    2055         pci_set_power_state(pci, PCI_D0);
    2056         pci_restore_state(pci);
    2057         if (pci_enable_device(pci) < 0) {
    2058                 printk(KERN_ERR DRIVER_NAME ": pci_enable_device failed, "
    2059                        "disabling device\n");
    2060                 snd_card_disconnect(card);
    2061                 return -EIO;
    2062         }
    2063         pci_set_master(pci);
    20642023
    20652024        snd_ensoniq_chip_init(ensoniq);
     
    20732032        return 0;
    20742033}
    2075 #endif /* CONFIG_PM */
    2076 
    2077 
    2078 static int __devinit snd_ensoniq_create(struct snd_card *card,
    2079                                      struct pci_dev *pci,
    2080                                      struct ensoniq ** rensoniq)
     2034
     2035static SIMPLE_DEV_PM_OPS(snd_ensoniq_pm, snd_ensoniq_suspend, snd_ensoniq_resume);
     2036#define SND_ENSONIQ_PM_OPS      &snd_ensoniq_pm
     2037#else
     2038#define SND_ENSONIQ_PM_OPS      NULL
     2039#endif /* CONFIG_PM_SLEEP */
     2040
     2041static int snd_ensoniq_create(struct snd_card *card,
     2042                              struct pci_dev *pci,
     2043                              struct ensoniq **rensoniq)
    20812044{
    20822045        struct ensoniq *ensoniq;
    20832046        int err;
    2084         static struct snd_device_ops ops = {
     2047        static const struct snd_device_ops ops = {
    20852048                .dev_free =     snd_ensoniq_dev_free,
    20862049        };
     
    21062069        ensoniq->port = pci_resource_start(pci, 0);
    21072070        if (request_irq(pci->irq, snd_audiopci_interrupt, IRQF_SHARED,
    2108                         "Ensoniq AudioPCI", ensoniq)) {
    2109                 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
     2071                        KBUILD_MODNAME, ensoniq)) {
     2072                dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
    21102073                snd_ensoniq_free(ensoniq);
    21112074                return -EBUSY;
    21122075        }
    21132076        ensoniq->irq = pci->irq;
    2114 #ifdef CHIP1370
    2115         if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
     2077        card->sync_irq = ensoniq->irq;
     2078#ifdef CHIP1370
     2079        if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev,
    21162080                                16, &ensoniq->dma_bug) < 0) {
    2117                 snd_printk(KERN_ERR "unable to allocate space for phantom area - dma_bug\n");
     2081                dev_err(card->dev, "unable to allocate space for phantom area - dma_bug\n");
    21182082                snd_ensoniq_free(ensoniq);
    21192083                return -EBUSY;
     
    21532117
    21542118        snd_ensoniq_proc_init(ensoniq);
    2155 
    2156         snd_card_set_dev(card, &pci->dev);
    21572119
    21582120        *rensoniq = ensoniq;
     
    23212283}
    23222284
    2323 static struct snd_rawmidi_ops snd_ensoniq_midi_output =
     2285static const struct snd_rawmidi_ops snd_ensoniq_midi_output =
    23242286{
    23252287        .open =         snd_ensoniq_midi_output_open,
     
    23282290};
    23292291
    2330 static struct snd_rawmidi_ops snd_ensoniq_midi_input =
     2292static const struct snd_rawmidi_ops snd_ensoniq_midi_input =
    23312293{
    23322294        .open =         snd_ensoniq_midi_input_open,
     
    23352297};
    23362298
    2337 static int __devinit snd_ensoniq_midi(struct ensoniq * ensoniq, int device,
    2338                                       struct snd_rawmidi **rrawmidi)
     2299static int snd_ensoniq_midi(struct ensoniq *ensoniq, int device)
    23392300{
    23402301        struct snd_rawmidi *rmidi;
    23412302        int err;
    23422303
    2343         if (rrawmidi)
    2344                 *rrawmidi = NULL;
    23452304        if ((err = snd_rawmidi_new(ensoniq->card, "ES1370/1", device, 1, 1, &rmidi)) < 0)
    23462305                return err;
    2347 #ifdef CHIP1370
    2348         strcpy(rmidi->name, "ES1370");
    2349 #else
    2350         strcpy(rmidi->name, "ES1371");
    2351 #endif
     2306        strcpy(rmidi->name, CHIP_NAME);
    23522307        snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_ensoniq_midi_output);
    23532308        snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_ensoniq_midi_input);
     
    23562311        rmidi->private_data = ensoniq;
    23572312        ensoniq->rmidi = rmidi;
    2358         if (rrawmidi)
    2359                 *rrawmidi = rmidi;
    23602313        return 0;
    23612314}
     
    24002353}
    24012354
    2402 static int __devinit snd_audiopci_probe(struct pci_dev *pci,
    2403                                         const struct pci_device_id *pci_id)
     2355static int snd_audiopci_probe(struct pci_dev *pci,
     2356                              const struct pci_device_id *pci_id)
    24042357{
    24052358        static int dev;
    24062359        struct snd_card *card;
    24072360        struct ensoniq *ensoniq;
    2408         int err, pcm_devs[2];
     2361        int err;
    24092362
    24102363        if (dev >= SNDRV_CARDS)
     
    24152368        }
    24162369
    2417         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     2370        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     2371                           0, &card);
    24182372        if (err < 0)
    24192373                return err;
     
    24252379        card->private_data = ensoniq;
    24262380
    2427         pcm_devs[0] = 0; pcm_devs[1] = 1;
    24282381#ifdef CHIP1370
    24292382        if ((err = snd_ensoniq_1370_mixer(ensoniq)) < 0) {
     
    24382391        }
    24392392#endif
    2440         if ((err = snd_ensoniq_pcm(ensoniq, 0, NULL)) < 0) {
     2393        if ((err = snd_ensoniq_pcm(ensoniq, 0)) < 0) {
    24412394                snd_card_free(card);
    24422395                return err;
    24432396        }
    2444         if ((err = snd_ensoniq_pcm2(ensoniq, 1, NULL)) < 0) {
     2397        if ((err = snd_ensoniq_pcm2(ensoniq, 1)) < 0) {
    24452398                snd_card_free(card);
    24462399                return err;
    24472400        }
    2448         if ((err = snd_ensoniq_midi(ensoniq, 0, NULL)) < 0) {
     2401        if ((err = snd_ensoniq_midi(ensoniq, 0)) < 0) {
    24492402                snd_card_free(card);
    24502403                return err;
     
    24722425}
    24732426
    2474 static void __devexit snd_audiopci_remove(struct pci_dev *pci)
     2427static void snd_audiopci_remove(struct pci_dev *pci)
    24752428{
    24762429        snd_card_free(pci_get_drvdata(pci));
    2477         pci_set_drvdata(pci, NULL);
    2478 }
    2479 
    2480 static struct pci_driver driver = {
    2481         .name = DRIVER_NAME,
     2430}
     2431
     2432static struct pci_driver ens137x_driver = {
     2433        .name = KBUILD_MODNAME,
    24822434        .id_table = snd_audiopci_ids,
    24832435        .probe = snd_audiopci_probe,
    2484         .remove = __devexit_p(snd_audiopci_remove),
    2485 #ifdef CONFIG_PM
    2486         .suspend = snd_ensoniq_suspend,
    2487         .resume = snd_ensoniq_resume,
    2488 #endif
     2436        .remove = snd_audiopci_remove,
     2437        .driver = {
     2438                .pm = SND_ENSONIQ_PM_OPS,
     2439        },
    24892440};
    24902441       
    2491 #ifdef CHIP1370
    2492 static int __init alsa_card_ens1370_init(void)
    2493 {
    2494         return pci_register_driver(&driver);
    2495 }
    2496 
    2497 static void __exit alsa_card_ens1370_exit(void)
    2498 {
    2499         pci_unregister_driver(&driver);
    2500 }
    2501 module_init(alsa_card_ens1370_init)
    2502 module_exit(alsa_card_ens1370_exit)
    2503 #endif
    2504 
    2505 #ifdef CHIP1371
    2506 static int __init alsa_card_ens1371_init(void)
    2507 {
    2508         return pci_register_driver(&driver);
    2509 }
    2510 
    2511 static void __exit alsa_card_ens1371_exit(void)
    2512 {
    2513         pci_unregister_driver(&driver);
    2514 }
    2515 module_init(alsa_card_ens1371_init)
    2516 module_exit(alsa_card_ens1371_exit)
    2517 #endif
    2518 
    2519 
     2442module_pci_driver(ens137x_driver);
Note: See TracChangeset for help on using the changeset viewer.