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

    r612 r615  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *   ALSA driver for Intel ICH (i8x0) chipsets
     
    45 *      Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
    56 *
    6  *
    77 *   This code also contains alpha support for SiS 735 chipsets provided
    88 *   by Mike Pieper <mptei@users.sourceforge.net>. We have no datasheet
    99 *   for SiS735, so the code is not fully functional.
    1010 *
    11  *
    12  *   This program is free software; you can redistribute it and/or modify
    13  *   it under the terms of the GNU General Public License as published by
    14  *   the Free Software Foundation; either version 2 of the License, or
    15  *   (at your option) any later version.
    16  *
    17  *   This program is distributed in the hope that it will be useful,
    18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  *   GNU General Public License for more details.
    21  *
    22  *   You should have received a copy of the GNU General Public License
    23  *   along with this program; if not, write to the Free Software
    24  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    25 
    26  *
     11
    2712 */     
    2813
    2914#ifdef TARGET_OS2
    3015#define KBUILD_MODNAME "intel8x0"
     16#include <linux/ktime.h>
     17extern ktime_t ktime_get(void);
    3118#endif
    3219
    33 #include <asm/io.h>
     20#include <linux/io.h>
    3421#include <linux/delay.h>
    3522#include <linux/interrupt.h>
     
    4330#include <sound/info.h>
    4431#include <sound/initval.h>
    45 /* for 440MX workaround */
    46 #include <asm/pgtable.h>
    47 #include <asm/cacheflush.h>
    48 
    49 #ifdef CONFIG_KVM_GUEST
    50 #include <linux/kvm_para.h>
    51 #else
    52 #define kvm_para_available() (0)
    53 #endif
    5432
    5533MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
     
    8462static int ac97_clock;
    8563static char *ac97_quirk;
    86 static int buggy_semaphore;
     64static bool buggy_semaphore;
    8765static int buggy_irq = -1; /* auto-check */
    88 static int xbox;
     66static bool xbox;
    8967static int spdif_aclink = -1;
    9068static int inside_vm = -1;
     
    10078module_param(buggy_semaphore, bool, 0444);
    10179MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores.");
    102 module_param(buggy_irq, bool, 0444);
     80module_param(buggy_irq, bint, 0444);
    10381MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
    10482module_param(xbox, bool, 0444);
     
    10684module_param(spdif_aclink, int, 0444);
    10785MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
    108 module_param(inside_vm, bool, 0444);
     86module_param(inside_vm, bint, 0444);
    10987MODULE_PARM_DESC(inside_vm, "KVM/Parallels optimization.");
    11088
    11189/* just for backward compatibility */
    112 //static int enable;
     90//static bool enable;
    11391module_param(enable, bool, 0444);
    11492//static int joystick;
     
    360338        unsigned int ichd;                      /* ich device number */
    361339        unsigned long reg_offset;               /* offset to bmaddr */
    362         u32 *bdbar;                             /* CPU address (32bit) */
     340        __le32 *bdbar;                          /* CPU address (32bit) */
    363341        unsigned int bdbar_addr;                /* PCI bus address (32bit) */
    364342        struct snd_pcm_substream *substream;
     
    383361        struct ac97_pcm *pcm;
    384362        int pcm_open_flag;
    385         unsigned int page_attr_changed: 1;
    386363        unsigned int suspended: 1;
    387364};
     
    435412};
    436413
    437 static DEFINE_PCI_DEVICE_TABLE(snd_intel8x0_ids) = {
     414static const struct pci_device_id snd_intel8x0_ids[] = {
    438415        { PCI_VDEVICE(INTEL, 0x2415), DEVICE_INTEL },   /* 82801AA */
    439416        { PCI_VDEVICE(INTEL, 0x2425), DEVICE_INTEL },   /* 82901AB */
     
    552529         * reset the semaphore. So even if you don't get the semaphore, still
    553530         * continue the access. We don't need the semaphore anyway. */
    554         snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
     531        dev_err(chip->card->dev,
     532                "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
    555533                        igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
    556534        iagetword(chip, 0);     /* clear semaphore flag */
     
    558536        return -EBUSY;
    559537}
    560  
     538
    561539static void snd_intel8x0_codec_write(struct snd_ac97 *ac97,
    562540                                     unsigned short reg,
     
    567545        if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
    568546                if (! chip->in_ac97_init)
    569                         snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
     547                        dev_err(chip->card->dev,
     548                                "codec_write %d: semaphore is not ready for register 0x%x\n",
     549                                ac97->num, reg);
    570550        }
    571551        iaputword(chip, reg + ac97->num * 0x80, val);
     
    581561        if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
    582562                if (! chip->in_ac97_init)
    583                         snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
     563                        dev_err(chip->card->dev,
     564                                "codec_read %d: semaphore is not ready for register 0x%x\n",
     565                                ac97->num, reg);
    584566                res = 0xffff;
    585567        } else {
     
    590572                                  ~(chip->codec_ready_bits | ICH_GSCI));
    591573                        if (! chip->in_ac97_init)
    592                                 snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
     574                                dev_err(chip->card->dev,
     575                                        "codec_read %d: read timeout for register 0x%x\n",
     576                                        ac97->num, reg);
    593577                        res = 0xffff;
    594578                }
     
    597581}
    598582
    599 static void __devinit snd_intel8x0_codec_read_test(struct intel8x0 *chip,
    600                                                   unsigned int codec)
     583static void snd_intel8x0_codec_read_test(struct intel8x0 *chip,
     584                                        unsigned int codec)
    601585{
    602586        unsigned int tmp;
     
    624608        }
    625609        if (! chip->in_ac97_init)
    626                 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n");
     610                dev_warn(chip->card->dev, "AC97 codec ready timeout.\n");
    627611        return -EBUSY;
    628612}
     
    636620                udelay(1);
    637621        if (! time && ! chip->in_ac97_init)
    638                 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n");
     622                dev_warn(chip->card->dev, "ali_codec_semaphore timeout\n");
    639623        return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
    640624}
     
    679663{
    680664        int idx;
    681         u32 *bdbar = ichdev->bdbar;
     665        __le32 *bdbar = ichdev->bdbar;
    682666        unsigned long port = ichdev->reg_offset;
    683667
     
    705689                                                     ichdev->fragsize >> ichdev->pos_shift);
    706690#if 0
    707                         printk(KERN_DEBUG "bdbar[%i] = 0x%x [0x%x]\n",
     691                        dev_dbg(chip->card->dev, "bdbar[%i] = 0x%x [0x%x]\n",
    708692                               idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
    709693#endif
     
    717701        ichdev->position = 0;
    718702#if 0
    719         printk(KERN_DEBUG "lvi_frag = %i, frags = %i, period_size = 0x%x, "
    720                "period_size1 = 0x%x\n",
     703        dev_dbg(chip->card->dev,
     704                "lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
    721705               ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
    722706               ichdev->fragsize1);
     
    725709        iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
    726710}
    727 
    728 #ifdef __i386__
    729 /*
    730  * Intel 82443MX running a 100MHz processor system bus has a hardware bug,
    731  * which aborts PCI busmaster for audio transfer.  A workaround is to set
    732  * the pages as non-cached.  For details, see the errata in
    733  *      http://download.intel.com/design/chipsets/specupdt/24505108.pdf
    734  */
    735 static void fill_nocache(void *buf, int size, int nocache)
    736 {
    737         size = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
    738         if (nocache)
    739                 set_pages_uc(virt_to_page(buf), size);
    740         else
    741                 set_pages_wb(virt_to_page(buf), size);
    742 }
    743 #else
    744 #define fill_nocache(buf, size, nocache) do { ; } while (0)
    745 #endif
    746711
    747712/*
     
    786751                ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
    787752#if 0
    788         printk(KERN_DEBUG "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, "
    789                "all = 0x%x, 0x%x\n",
     753        dev_dbg(chip->card->dev,
     754                "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
    790755               ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
    791756               ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
     
    852817        case SNDRV_PCM_TRIGGER_RESUME:
    853818                ichdev->suspended = 0;
    854                 /* fallthru */
     819                /* fall through */
    855820        case SNDRV_PCM_TRIGGER_START:
    856821        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     
    860825        case SNDRV_PCM_TRIGGER_SUSPEND:
    861826                ichdev->suspended = 1;
    862                 /* fallthru */
     827                /* fall through */
    863828        case SNDRV_PCM_TRIGGER_STOP:
    864829                val = 0;
     
    894859        case SNDRV_PCM_TRIGGER_RESUME:
    895860                ichdev->suspended = 0;
    896                 /* fallthru */
     861                /* fall through */
    897862        case SNDRV_PCM_TRIGGER_START:
    898863        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     
    911876        case SNDRV_PCM_TRIGGER_SUSPEND:
    912877                ichdev->suspended = 1;
    913                 /* fallthru */
     878                /* fall through */
    914879        case SNDRV_PCM_TRIGGER_STOP:
    915880        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
     
    940905        struct intel8x0 *chip = snd_pcm_substream_chip(substream);
    941906        struct ichdev *ichdev = get_ichdev(substream);
    942         struct snd_pcm_runtime *runtime = substream->runtime;
    943907        int dbl = params_rate(hw_params) > 48000;
    944908        int err;
    945909
    946         if (chip->fix_nocache && ichdev->page_attr_changed) {
    947                 fill_nocache(runtime->dma_area, runtime->dma_bytes, 0); /* clear */
    948                 ichdev->page_attr_changed = 0;
    949         }
    950910        err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    951911        if (err < 0)
    952912                return err;
    953         if (chip->fix_nocache) {
    954                 if (runtime->dma_area && ! ichdev->page_attr_changed) {
    955                         fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
    956                         ichdev->page_attr_changed = 1;
    957                 }
    958         }
    959913        if (ichdev->pcm_open_flag) {
    960914                snd_ac97_pcm_close(ichdev->pcm);
     
    976930static int snd_intel8x0_hw_free(struct snd_pcm_substream *substream)
    977931{
    978         struct intel8x0 *chip = snd_pcm_substream_chip(substream);
    979932        struct ichdev *ichdev = get_ichdev(substream);
    980933
     
    982935                snd_ac97_pcm_close(ichdev->pcm);
    983936                ichdev->pcm_open_flag = 0;
    984         }
    985         if (chip->fix_nocache && ichdev->page_attr_changed) {
    986                 fill_nocache(substream->runtime->dma_area, substream->runtime->dma_bytes, 0);
    987                 ichdev->page_attr_changed = 0;
    988937        }
    989938        return snd_pcm_lib_free_pages(substream);
     
    11171066}
    11181067
    1119 static struct snd_pcm_hardware snd_intel8x0_stream =
     1068static const struct snd_pcm_hardware snd_intel8x0_stream =
    11201069{
    11211070        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    11381087};
    11391088
    1140 static unsigned int channels4[] = {
     1089static const unsigned int channels4[] = {
    11411090        2, 4,
    11421091};
    11431092
    1144 static struct snd_pcm_hw_constraint_list hw_constraints_channels4 = {
     1093static const struct snd_pcm_hw_constraint_list hw_constraints_channels4 = {
    11451094        .count = ARRAY_SIZE(channels4),
    11461095        .list = channels4,
     
    11481097};
    11491098
    1150 static unsigned int channels6[] = {
     1099static const unsigned int channels6[] = {
    11511100        2, 4, 6,
    11521101};
    11531102
    1154 static struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
     1103static const struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
    11551104        .count = ARRAY_SIZE(channels6),
    11561105        .list = channels6,
     
    11581107};
    11591108
    1160 static unsigned int channels8[] = {
     1109static const unsigned int channels8[] = {
    11611110        2, 4, 6, 8,
    11621111};
    11631112
    1164 static struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
     1113static const struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
    11651114        .count = ARRAY_SIZE(channels8),
    11661115        .list = channels8,
     
    13691318#endif
    13701319
    1371 static struct snd_pcm_ops snd_intel8x0_playback_ops = {
     1320static const struct snd_pcm_ops snd_intel8x0_playback_ops = {
    13721321        .open =         snd_intel8x0_playback_open,
    13731322        .close =        snd_intel8x0_playback_close,
     
    13801329};
    13811330
    1382 static struct snd_pcm_ops snd_intel8x0_capture_ops = {
     1331static const struct snd_pcm_ops snd_intel8x0_capture_ops = {
    13831332        .open =         snd_intel8x0_capture_open,
    13841333        .close =        snd_intel8x0_capture_close,
     
    13911340};
    13921341
    1393 static struct snd_pcm_ops snd_intel8x0_capture_mic_ops = {
     1342static const struct snd_pcm_ops snd_intel8x0_capture_mic_ops = {
    13941343        .open =         snd_intel8x0_mic_open,
    13951344        .close =        snd_intel8x0_mic_close,
     
    14021351};
    14031352
    1404 static struct snd_pcm_ops snd_intel8x0_capture_mic2_ops = {
     1353static const struct snd_pcm_ops snd_intel8x0_capture_mic2_ops = {
    14051354        .open =         snd_intel8x0_mic2_open,
    14061355        .close =        snd_intel8x0_mic2_close,
     
    14131362};
    14141363
    1415 static struct snd_pcm_ops snd_intel8x0_capture2_ops = {
     1364static const struct snd_pcm_ops snd_intel8x0_capture2_ops = {
    14161365        .open =         snd_intel8x0_capture2_open,
    14171366        .close =        snd_intel8x0_capture2_close,
     
    14241373};
    14251374
    1426 static struct snd_pcm_ops snd_intel8x0_spdif_ops = {
     1375static const struct snd_pcm_ops snd_intel8x0_spdif_ops = {
    14271376        .open =         snd_intel8x0_spdif_open,
    14281377        .close =        snd_intel8x0_spdif_close,
     
    14351384};
    14361385
    1437 static struct snd_pcm_ops snd_intel8x0_ali_playback_ops = {
     1386static const struct snd_pcm_ops snd_intel8x0_ali_playback_ops = {
    14381387        .open =         snd_intel8x0_playback_open,
    14391388        .close =        snd_intel8x0_playback_close,
     
    14461395};
    14471396
    1448 static struct snd_pcm_ops snd_intel8x0_ali_capture_ops = {
     1397static const struct snd_pcm_ops snd_intel8x0_ali_capture_ops = {
    14491398        .open =         snd_intel8x0_capture_open,
    14501399        .close =        snd_intel8x0_capture_close,
     
    14571406};
    14581407
    1459 static struct snd_pcm_ops snd_intel8x0_ali_capture_mic_ops = {
     1408static const struct snd_pcm_ops snd_intel8x0_ali_capture_mic_ops = {
    14601409        .open =         snd_intel8x0_mic_open,
    14611410        .close =        snd_intel8x0_mic_close,
     
    14681417};
    14691418
    1470 static struct snd_pcm_ops snd_intel8x0_ali_ac97spdifout_ops = {
     1419static const struct snd_pcm_ops snd_intel8x0_ali_ac97spdifout_ops = {
    14711420        .open =         snd_intel8x0_ali_ac97spdifout_open,
    14721421        .close =        snd_intel8x0_ali_ac97spdifout_close,
     
    15051454struct ich_pcm_table {
    15061455        char *suffix;
    1507         struct snd_pcm_ops *playback_ops;
    1508         struct snd_pcm_ops *capture_ops;
     1456        const struct snd_pcm_ops *playback_ops;
     1457        const struct snd_pcm_ops *capture_ops;
    15091458        size_t prealloc_size;
    15101459        size_t prealloc_max_size;
     
    15121461};
    15131462
    1514 static int __devinit snd_intel8x0_pcm1(struct intel8x0 *chip, int device,
    1515                                        struct ich_pcm_table *rec)
     1463#define intel8x0_dma_type(chip) \
     1464        ((chip)->fix_nocache ? SNDRV_DMA_TYPE_DEV_UC : SNDRV_DMA_TYPE_DEV)
     1465
     1466static int snd_intel8x0_pcm1(struct intel8x0 *chip, int device,
     1467                             struct ich_pcm_table *rec)
    15161468{
    15171469        struct snd_pcm *pcm;
     
    15421494        chip->pcm[device] = pcm;
    15431495
    1544         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
     1496        snd_pcm_lib_preallocate_pages_for_all(pcm, intel8x0_dma_type(chip),
    15451497                                              snd_dma_pci_data(chip->pci),
    15461498                                              rec->prealloc_size, rec->prealloc_max_size);
    15471499
     1500        if (rec->playback_ops &&
     1501            rec->playback_ops->open == snd_intel8x0_playback_open) {
     1502                struct snd_pcm_chmap *chmap;
     1503                int chs = 2;
     1504                if (chip->multi8)
     1505                        chs = 8;
     1506                else if (chip->multi6)
     1507                        chs = 6;
     1508                else if (chip->multi4)
     1509                        chs = 4;
     1510                err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
     1511                                             snd_pcm_alt_chmaps, chs, 0,
     1512                                             &chmap);
     1513                if (err < 0)
     1514                        return err;
     1515                chmap->channel_mask = SND_PCM_CHMAP_MASK_2468;
     1516                chip->ac97[0]->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
     1517        }
     1518
    15481519        return 0;
    15491520}
    15501521
    1551 static struct ich_pcm_table intel_pcms[] __devinitdata = {
     1522static struct ich_pcm_table intel_pcms[] = {
    15521523        {
    15531524                .playback_ops = &snd_intel8x0_playback_ops,
     
    15861557};
    15871558
    1588 static struct ich_pcm_table nforce_pcms[] __devinitdata = {
     1559static struct ich_pcm_table nforce_pcms[] = {
    15891560        {
    15901561                .playback_ops = &snd_intel8x0_playback_ops,
     
    16091580};
    16101581
    1611 static struct ich_pcm_table ali_pcms[] __devinitdata = {
     1582static struct ich_pcm_table ali_pcms[] = {
    16121583        {
    16131584                .playback_ops = &snd_intel8x0_ali_playback_ops,
     
    16411612};
    16421613
    1643 static int __devinit snd_intel8x0_pcm(struct intel8x0 *chip)
     1614static int snd_intel8x0_pcm(struct intel8x0 *chip)
    16441615{
    16451616        int i, tblsize, device, err;
     
    17041675}
    17051676
    1706 static struct ac97_pcm ac97_pcm_defs[] __devinitdata = {
     1677static const struct ac97_pcm ac97_pcm_defs[] = {
    17071678        /* front PCM */
    17081679        {
     
    17741745};
    17751746
    1776 static struct ac97_quirk ac97_quirks[] __devinitdata = {
     1747static const struct ac97_quirk ac97_quirks[] = {
    17771748        {
    17781749                .subvendor = 0x0e11,
     
    17921763                .name = "Compaq Evo D510C",
    17931764                .type = AC97_TUNE_HP_ONLY
    1794         },
    1795         {
     1765        },
     1766        {
    17961767                .subvendor = 0x0e11,
    17971768                .subdevice = 0x0860,
     
    21242095        },
    21252096        {
    2126                 .subvendor = 0x107B,
    2127                 .subdevice = 0x0111,
    2128                 .name = "Gateway 2000 ICH2/AD1885",
    2129                 .type = AC97_TUNE_HP_ONLY
    2130         },
    2131         {
    21322097                .subvendor = 0x8086,
    21332098                .subdevice = 0x2000,
     
    21872152};
    21882153
    2189 static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
    2190                                         const char *quirk_override)
     2154static int snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
     2155                              const char *quirk_override)
    21912156{
    21922157        struct snd_ac97_bus *pbus;
     
    22172182                        chip->spdif_idx = ICHD_SPBAR;
    22182183                        break;
    2219                 };
     2184                }
    22202185        }
    22212186
     
    22812246                if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
    22822247                        if (err != -EACCES)
    2283                                 snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i);
     2248                                dev_err(chip->card->dev,
     2249                                        "Unable to initialize codec #%d\n", i);
    22842250                        if (i == 0)
    22852251                                goto __err;
     
    23862352static struct snd_pci_quirk ich_chip_reset_mode[] = {
    23872353        SND_PCI_QUIRK(0x1014, 0x051f, "Thinkpad R32", 1),
    2388         { } /* end */
     2354        {0} /* end */
    23892355};
    23902356
     
    24332399                schedule_timeout_uninterruptible(1);
    24342400        } while (time_after_eq(end_time, jiffies));
    2435         snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n",
     2401        dev_err(chip->card->dev, "AC'97 warm reset still in progress? [0x%x]\n",
    24362402                   igetdword(chip, ICHREG(GLOB_CNT)));
    24372403        return -EIO;
     
    24772443                if (! status) {
    24782444                        /* no codec is found */
    2479                         snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]\n",
     2445                        dev_err(chip->card->dev,
     2446                                "codec_ready: codec is not ready [0x%x]\n",
    24802447                                   igetdword(chip, ICHREG(GLOB_STA)));
    24812448                        return -EIO;
     
    25412508                schedule_timeout_uninterruptible(1);
    25422509        }
    2543         snd_printk(KERN_ERR "AC'97 reset failed.\n");
     2510        dev_err(chip->card->dev, "AC'97 reset failed.\n");
    25442511        if (probing)
    25452512                return -EIO;
     
    25852552                }
    25862553                if (timeout == 0)
    2587                         printk(KERN_ERR "intel8x0: reset of registers failed?\n");
     2554                        dev_err(chip->card->dev, "reset of registers failed?\n");
    25882555        }
    25892556        /* initialize Buffer Descriptor Lists */
     
    26182585        if (chip->irq >= 0)
    26192586                free_irq(chip->irq, chip);
    2620         if (chip->bdbars.area) {
    2621                 if (chip->fix_nocache)
    2622                         fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0);
     2587        if (chip->bdbars.area)
    26232588                snd_dma_free_pages(&chip->bdbars);
    2624         }
    26252589        if (chip->addr)
    26262590                pci_iounmap(chip->pci, chip->addr);
     
    26332597}
    26342598
    2635 #ifdef CONFIG_PM
     2599#ifdef CONFIG_PM_SLEEP
    26362600/*
    26372601 * power management
    26382602 */
    2639 static int intel8x0_suspend(struct pci_dev *pci, pm_message_t state)
    2640 {
    2641         struct snd_card *card = pci_get_drvdata(pci);
     2603static int intel8x0_suspend(struct device *dev)
     2604{
     2605        struct snd_card *card = dev_get_drvdata(dev);
    26422606        struct intel8x0 *chip = card->private_data;
    26432607        int i;
    26442608
    26452609        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    2646         for (i = 0; i < chip->pcm_devs; i++)
    2647                 snd_pcm_suspend_all(chip->pcm[i]);
    2648         /* clear nocache */
    2649         if (chip->fix_nocache) {
    2650                 for (i = 0; i < chip->bdbars_count; i++) {
    2651                         struct ichdev *ichdev = &chip->ichd[i];
    2652                         if (ichdev->substream && ichdev->page_attr_changed) {
    2653                                 struct snd_pcm_runtime *runtime = ichdev->substream->runtime;
    2654                                 if (runtime->dma_area)
    2655                                         fill_nocache(runtime->dma_area, runtime->dma_bytes, 0);
    2656                         }
    2657                 }
    2658         }
    26592610        for (i = 0; i < chip->ncodecs; i++)
    26602611                snd_ac97_suspend(chip->ac97[i]);
     
    26662617                chip->irq = -1;
    26672618        }
    2668         pci_disable_device(pci);
    2669         pci_save_state(pci);
    2670         /* The call below may disable built-in speaker on some laptops
    2671          * after S2RAM.  So, don't touch it.
    2672          */
    2673         /* pci_set_power_state(pci, pci_choose_state(pci, state)); */
    26742619        return 0;
    26752620}
    26762621
    2677 static int intel8x0_resume(struct pci_dev *pci)
    2678 {
    2679         struct snd_card *card = pci_get_drvdata(pci);
     2622static int intel8x0_resume(struct device *dev)
     2623{
     2624        struct pci_dev *pci = to_pci_dev(dev);
     2625        struct snd_card *card = dev_get_drvdata(dev);
    26802626        struct intel8x0 *chip = card->private_data;
    26812627        int i;
    26822628
    2683         pci_set_power_state(pci, PCI_D0);
    2684         pci_restore_state(pci);
    2685         if (pci_enable_device(pci) < 0) {
    2686                 printk(KERN_ERR "intel8x0: pci_enable_device failed, "
    2687                        "disabling device\n");
    2688                 snd_card_disconnect(card);
    2689                 return -EIO;
    2690         }
    2691         pci_set_master(pci);
    26922629        snd_intel8x0_chip_init(chip, 0);
    26932630        if (request_irq(pci->irq, snd_intel8x0_interrupt,
    26942631                        IRQF_SHARED, KBUILD_MODNAME, chip)) {
    2695                 printk(KERN_ERR "intel8x0: unable to grab IRQ %d, "
    2696                        "disabling device\n", pci->irq);
     2632                dev_err(dev, "unable to grab IRQ %d, disabling device\n",
     2633                        pci->irq);
    26972634                snd_card_disconnect(card);
    26982635                return -EIO;
     
    27112648        }
    27122649
    2713         /* refill nocache */
    2714         if (chip->fix_nocache)
    2715                 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
    2716 
    27172650        for (i = 0; i < chip->ncodecs; i++)
    27182651                snd_ac97_resume(chip->ac97[i]);
    2719 
    2720         /* refill nocache */
    2721         if (chip->fix_nocache) {
    2722                 for (i = 0; i < chip->bdbars_count; i++) {
    2723                         struct ichdev *ichdev = &chip->ichd[i];
    2724                         if (ichdev->substream && ichdev->page_attr_changed) {
    2725                                 struct snd_pcm_runtime *runtime = ichdev->substream->runtime;
    2726                                 if (runtime->dma_area)
    2727                                         fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
    2728                         }
    2729                 }
    2730         }
    27312652
    27322653        /* resume status */
     
    27472668        return 0;
    27482669}
    2749 #endif /* CONFIG_PM */
     2670
     2671static SIMPLE_DEV_PM_OPS(intel8x0_pm, intel8x0_suspend, intel8x0_resume);
     2672#define INTEL8X0_PM_OPS &intel8x0_pm
     2673#else
     2674#define INTEL8X0_PM_OPS NULL
     2675#endif /* CONFIG_PM_SLEEP */
    27502676
    27512677#define INTEL8X0_TESTBUF_SIZE   32768   /* enough large for one shot */
    27522678
    2753 static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
     2679static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
    27542680{
    27552681        struct snd_pcm_substream *subs;
     
    27582684        unsigned long pos, pos1, t;
    27592685        int civ, timeout = 1000, attempt = 1;
     2686#ifndef TARGET_OS2
     2687        ktime_t start_time, stop_time;
     2688#else
    27602689        struct timespec start_time, stop_time;
     2690#endif
    27612691
    27622692        if (chip->ac97_bus->clock != 48000)
     
    27662696        subs = chip->pcm[0]->streams[0].substream;
    27672697        if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
    2768                 snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n");
     2698                dev_warn(chip->card->dev,
     2699                         "no playback buffer allocated - aborting measure ac97 clock\n");
    27692700                return;
    27702701        }
     
    27762707        /* set rate */
    27772708        if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
    2778                 snd_printk(KERN_ERR "cannot set ac97 rate: clock = %d\n", chip->ac97_bus->clock);
     2709                dev_err(chip->card->dev, "cannot set ac97 rate: clock = %d\n",
     2710                        chip->ac97_bus->clock);
    27792711                return;
    27802712        }
     
    27902722                iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
    27912723        }
     2724#ifndef TARGET_OS2
     2725        start_time = ktime_get();
     2726#else
    27922727        do_posix_clock_monotonic_gettime(&start_time);
     2728#endif
    27932729        spin_unlock_irq(&chip->reg_lock);
    27942730        msleep(50);
     
    28142750        }
    28152751        chip->in_measurement = 0;
     2752#ifndef TARGET_OS2
     2753        stop_time = ktime_get();
     2754#else
    28162755        do_posix_clock_monotonic_gettime(&stop_time);
     2756#endif
    28172757        /* stop */
    28182758        if (chip->device_type == DEVICE_ALI) {
     
    28302770
    28312771        if (pos == 0) {
    2832                 snd_printk(KERN_ERR "intel8x0: measure - unreliable DMA position..\n");
     2772                dev_err(chip->card->dev,
     2773                        "measure - unreliable DMA position..\n");
    28332774              __retry:
    28342775                if (attempt < 3) {
     
    28412782
    28422783        pos /= 4;
     2784#ifndef TARGET_OS2
     2785        t = ktime_us_delta(stop_time, start_time);
     2786#else
    28432787        t = stop_time.tv_sec - start_time.tv_sec;
    28442788        t *= 1000000;
    28452789        t += (stop_time.tv_nsec - start_time.tv_nsec) / 1000;
    2846         printk(KERN_INFO "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
     2790        dprintf(("%s: measured %lu usecs (%lu samples)\n", __func__, t, pos));
     2791#endif
     2792        dev_info(chip->card->dev,
     2793                 "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
    28472794        if (t == 0) {
    2848                 snd_printk(KERN_ERR "intel8x0: ?? calculation error..\n");
     2795                dev_err(chip->card->dev, "?? calculation error..\n");
    28492796                goto __retry;
    28502797        }
     
    28532800        if (pos < 40000 || pos >= 60000) {
    28542801                /* abnormal value. hw problem? */
    2855                 printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos);
     2802                dev_info(chip->card->dev, "measured clock %ld rejected\n", pos);
    28562803                goto __retry;
    28572804        } else if (pos > 40500 && pos < 41500)
     
    28652812                chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
    28662813      __end:
    2867         printk(KERN_INFO "intel8x0: clocking to %d\n", chip->ac97_bus->clock);
     2814        dev_info(chip->card->dev, "clocking to %d\n", chip->ac97_bus->clock);
    28682815        snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0);
    28692816}
    28702817
    2871 static struct snd_pci_quirk intel8x0_clock_list[] __devinitdata = {
     2818static struct snd_pci_quirk intel8x0_clock_list[] = {
    28722819        SND_PCI_QUIRK(0x0e11, 0x008a, "AD1885", 41000),
    28732820        SND_PCI_QUIRK(0x1014, 0x0581, "AD1981B", 48000),
     
    28792826};
    28802827
    2881 static int __devinit intel8x0_in_clock_list(struct intel8x0 *chip)
     2828static int intel8x0_in_clock_list(struct intel8x0 *chip)
    28822829{
    28832830        struct pci_dev *pci = chip->pci;
     
    28872834        if (!wl)
    28882835                return 0;
    2889         printk(KERN_INFO "intel8x0: white list rate for %04x:%04x is %i\n",
     2836        dev_info(chip->card->dev, "white list rate for %04x:%04x is %i\n",
    28902837               pci->subsystem_vendor, pci->subsystem_device, wl->value);
    28912838        chip->ac97_bus->clock = wl->value;
     
    28932840}
    28942841
    2895 #ifdef CONFIG_PROC_FS
    28962842static void snd_intel8x0_proc_read(struct snd_info_entry * entry,
    28972843                                   struct snd_info_buffer *buffer)
     
    29282874}
    29292875
    2930 static void __devinit snd_intel8x0_proc_init(struct intel8x0 * chip)
    2931 {
    2932         struct snd_info_entry *entry;
    2933 
    2934         if (! snd_card_proc_new(chip->card, "intel8x0", &entry))
    2935                 snd_info_set_text_ops(entry, chip, snd_intel8x0_proc_read);
    2936 }
    2937 #else
    2938 #define snd_intel8x0_proc_init(x)
    2939 #endif
     2876static void snd_intel8x0_proc_init(struct intel8x0 *chip)
     2877{
     2878        snd_card_ro_proc_new(chip->card, "intel8x0", chip,
     2879                             snd_intel8x0_proc_read);
     2880}
    29402881
    29412882static int snd_intel8x0_dev_free(struct snd_device *device)
     
    29572898};
    29582899
    2959 static int __devinit snd_intel8x0_inside_vm(struct pci_dev *pci)
     2900static int snd_intel8x0_inside_vm(struct pci_dev *pci)
    29602901{
    29612902        int result  = inside_vm;
     
    29682909        }
    29692910
    2970         /* detect KVM and Parallels virtual environments */
    2971         result = kvm_para_available();
    2972 #ifdef X86_FEATURE_HYPERVISOR
    2973         result = result || boot_cpu_has(X86_FEATURE_HYPERVISOR);
    2974 #endif
    2975         if (!result)
    2976                 goto fini;
    2977 
    29782911        /* check for known (emulated) devices */
    2979         if (pci->subsystem_vendor == 0x1af4 &&
    2980             pci->subsystem_device == 0x1100) {
     2912        result = 0;
     2913        if (pci->subsystem_vendor == PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
     2914            pci->subsystem_device == PCI_SUBDEVICE_ID_QEMU) {
    29812915                /* KVM emulated sound, PCI SSID: 1af4:1100 */
    29822916                msg = "enable KVM";
     2917                result = 1;
    29832918        } else if (pci->subsystem_vendor == 0x1ab8) {
    29842919                /* Parallels VM emulated sound, PCI SSID: 1ab8:xxxx */
    29852920                msg = "enable Parallels VM";
    2986         } else {
    2987                 msg = "disable (unknown or VT-d) VM";
    2988                 result = 0;
     2921                result = 1;
    29892922        }
    29902923
    29912924fini:
    29922925        if (msg != NULL)
    2993                 printk(KERN_INFO "intel8x0: %s optimization\n", msg);
     2926                dev_info(&pci->dev, "%s optimization\n", msg);
    29942927
    29952928        return result;
    29962929}
    29972930
    2998 static int __devinit snd_intel8x0_create(struct snd_card *card,
    2999                                         struct pci_dev *pci,
    3000                                         unsigned long device_type,
    3001                                          struct intel8x0 ** r_intel8x0)
     2931static int snd_intel8x0_create(struct snd_card *card,
     2932                              struct pci_dev *pci,
     2933                              unsigned long device_type,
     2934                               struct intel8x0 **r_intel8x0)
    30022935{
    30032936        struct intel8x0 *chip;
     
    30652998        chip->inside_vm = snd_intel8x0_inside_vm(pci);
    30662999
     3000        /*
     3001         * Intel 82443MX running a 100MHz processor system bus has a hardware
     3002         * bug, which aborts PCI busmaster for audio transfer.  A workaround
     3003         * is to set the pages as non-cached.  For details, see the errata in
     3004         *     http://download.intel.com/design/chipsets/specupdt/24505108.pdf
     3005         */
    30673006        if (pci->vendor == PCI_VENDOR_ID_INTEL &&
    30683007            pci->device == PCI_DEVICE_ID_INTEL_440MX)
     
    30863025                chip->addr = pci_iomap(pci, 0, 0);
    30873026        if (!chip->addr) {
    3088                 snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
     3027                dev_err(card->dev, "AC'97 space ioremap problem\n");
    30893028                snd_intel8x0_free(chip);
    30903029                return -EIO;
     
    30943033        else
    30953034                chip->bmaddr = pci_iomap(pci, 1, 0);
     3035
     3036 port_inited:
    30963037        if (!chip->bmaddr) {
    3097                 snd_printk(KERN_ERR "Controller space ioremap problem\n");
     3038                dev_err(card->dev, "Controller space ioremap problem\n");
    30983039                snd_intel8x0_free(chip);
    30993040                return -EIO;
    31003041        }
    3101 
    3102  port_inited:
    31033042        chip->bdbars_count = bdbars[device_type];
    31043043
     
    31363075        /* allocate buffer descriptor lists */
    31373076        /* the start of each lists must be aligned to 8 bytes */
    3138         if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
     3077        if (snd_dma_alloc_pages(intel8x0_dma_type(chip), snd_dma_pci_data(pci),
    31393078                                chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
    31403079                                &chip->bdbars) < 0) {
    31413080                snd_intel8x0_free(chip);
    3142                 snd_printk(KERN_ERR "intel8x0: cannot allocate buffer descriptors\n");
     3081                dev_err(card->dev, "cannot allocate buffer descriptors\n");
    31433082                return -ENOMEM;
    31443083        }
    31453084        /* tables must be aligned to 8 bytes here, but the kernel pages
    31463085           are much bigger, so we don't care (on i386) */
    3147         /* workaround for 440MX */
    3148         if (chip->fix_nocache)
    3149                 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
    31503086        int_sta_masks = 0;
    31513087        for (i = 0; i < chip->bdbars_count; i++) {
    31523088                ichdev = &chip->ichd[i];
    3153                 ichdev->bdbar = ((u32 *)chip->bdbars.area) +
     3089                ichdev->bdbar = ((__le32 *)chip->bdbars.area) +
    31543090                        (i * ICH_MAX_FRAGS * 2);
    31553091                ichdev->bdbar_addr = chip->bdbars.addr +
     
    31943130        if (request_irq(pci->irq, snd_intel8x0_interrupt,
    31953131                        IRQF_SHARED, KBUILD_MODNAME, chip)) {
    3196                 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
     3132                dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
    31973133                snd_intel8x0_free(chip);
    31983134                return -EBUSY;
     
    32053141        }
    32063142
    3207         snd_card_set_dev(card, &pci->dev);
    3208 
    32093143        *r_intel8x0 = chip;
    32103144        return 0;
     
    32143148        unsigned int id;
    32153149        const char *s;
    3216 } shortnames[] __devinitdata = {
     3150} shortnames[] = {
    32173151        { PCI_DEVICE_ID_INTEL_82801AA_5, "Intel 82801AA-ICH" },
    32183152        { PCI_DEVICE_ID_INTEL_82801AB_5, "Intel 82901AB-ICH0" },
     
    32403174};
    32413175
    3242 #ifdef NOT_USED
    3243 static struct snd_pci_quirk spdif_aclink_defaults[] __devinitdata = {
     3176static struct snd_pci_quirk spdif_aclink_defaults[] = {
    32443177        SND_PCI_QUIRK(0x147b, 0x1c1a, "ASUS KN8", 1),
    32453178        {0} /* end */
    32463179};
    3247 #endif
    32483180
    32493181/* look up white/black list for SPDIF over ac-link */
    3250 static int __devinit check_default_spdif_aclink(struct pci_dev *pci)
     3182static int check_default_spdif_aclink(struct pci_dev *pci)
    32513183{
    32523184#ifndef TARGET_OS2
     
    32563188        if (w) {
    32573189                if (w->value)
    3258                         snd_printdd(KERN_INFO "intel8x0: Using SPDIF over "
    3259                                     "AC-Link for %s\n", w->name);
     3190                        dev_dbg(&pci->dev,
     3191                                "Using SPDIF over AC-Link for %s\n",
     3192                                    snd_pci_quirk_name(w));
    32603193                else
    3261                         snd_printdd(KERN_INFO "intel8x0: Using integrated "
    3262                                     "SPDIF DMA for %s\n", w->name);
     3194                        dev_dbg(&pci->dev,
     3195                                "Using integrated SPDIF DMA for %s\n",
     3196                                    snd_pci_quirk_name(w));
    32633197                return w->value;
    32643198        }
     
    32673201}
    32683202
    3269 static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
    3270                                         const struct pci_device_id *pci_id)
     3203static int snd_intel8x0_probe(struct pci_dev *pci,
     3204                              const struct pci_device_id *pci_id)
    32713205{
    32723206        struct snd_card *card;
     
    32753209        struct shortname_table *name;
    32763210
    3277         err = snd_card_create(index, id, THIS_MODULE, 0, &card);
     3211        err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
    32783212        if (err < 0)
    32793213                return err;
     
    33503284}
    33513285
    3352 static void __devexit snd_intel8x0_remove(struct pci_dev *pci)
     3286static void snd_intel8x0_remove(struct pci_dev *pci)
    33533287{
    33543288        snd_card_free(pci_get_drvdata(pci));
    3355         pci_set_drvdata(pci, NULL);
    3356 }
    3357 
    3358 static struct pci_driver driver = {
     3289}
     3290
     3291static struct pci_driver intel8x0_driver = {
    33593292        .name = KBUILD_MODNAME,
    33603293        .id_table = snd_intel8x0_ids,
    33613294        .probe = snd_intel8x0_probe,
    3362         .remove = __devexit_p(snd_intel8x0_remove),
    3363 #ifdef CONFIG_PM
    3364         .suspend = intel8x0_suspend,
    3365         .resume = intel8x0_resume,
    3366 #endif
    3367 };
    3368 
    3369 
    3370 static int __init alsa_card_intel8x0_init(void)
    3371 {
    3372         return pci_register_driver(&driver);
    3373 }
    3374 
    3375 static void __exit alsa_card_intel8x0_exit(void)
    3376 {
    3377         pci_unregister_driver(&driver);
    3378 }
    3379 
    3380 module_init(alsa_card_intel8x0_init)
    3381 module_exit(alsa_card_intel8x0_exit)
     3295        .remove = snd_intel8x0_remove,
     3296        .driver = {
     3297                .pm = INTEL8X0_PM_OPS,
     3298        },
     3299};
     3300
     3301module_pci_driver(intel8x0_driver);
Note: See TracChangeset for help on using the changeset viewer.