| 1 | // SPDX-License-Identifier: GPL-2.0-or-later
|
|---|
| 2 | /*
|
|---|
| 3 | * ALSA driver for Intel ICH (i8x0) chipsets
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
|
|---|
| 6 | *
|
|---|
| 7 | * This code also contains alpha support for SiS 735 chipsets provided
|
|---|
| 8 | * by Mike Pieper <mptei@users.sourceforge.net>. We have no datasheet
|
|---|
| 9 | * for SiS735, so the code is not fully functional.
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | #ifdef TARGET_OS2
|
|---|
| 14 | #define KBUILD_MODNAME "intel8x0"
|
|---|
| 15 | #endif
|
|---|
| 16 |
|
|---|
| 17 | #include <linux/io.h>
|
|---|
| 18 | #include <linux/delay.h>
|
|---|
| 19 | #include <linux/interrupt.h>
|
|---|
| 20 | #include <linux/init.h>
|
|---|
| 21 | #include <linux/pci.h>
|
|---|
| 22 | #include <linux/slab.h>
|
|---|
| 23 | #include <linux/module.h>
|
|---|
| 24 | #include <sound/core.h>
|
|---|
| 25 | #include <sound/pcm.h>
|
|---|
| 26 | #include <sound/ac97_codec.h>
|
|---|
| 27 | #include <sound/info.h>
|
|---|
| 28 | #include <sound/initval.h>
|
|---|
| 29 |
|
|---|
| 30 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
|
|---|
| 31 | MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
|
|---|
| 32 | MODULE_LICENSE("GPL");
|
|---|
| 33 |
|
|---|
| 34 | static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
|
|---|
| 35 | static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
|
|---|
| 36 | static int ac97_clock;
|
|---|
| 37 | static char *ac97_quirk;
|
|---|
| 38 | static bool buggy_semaphore;
|
|---|
| 39 | static int buggy_irq = -1; /* auto-check */
|
|---|
| 40 | static bool xbox;
|
|---|
| 41 | static int spdif_aclink = -1;
|
|---|
| 42 | static int inside_vm = -1;
|
|---|
| 43 |
|
|---|
| 44 | module_param(index, int, 0444);
|
|---|
| 45 | MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
|
|---|
| 46 | module_param(id, charp, 0444);
|
|---|
| 47 | MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
|
|---|
| 48 | module_param(ac97_clock, int, 0444);
|
|---|
| 49 | MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = allowlist + auto-detect, 1 = force autodetect).");
|
|---|
| 50 | module_param(ac97_quirk, charp, 0444);
|
|---|
| 51 | MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
|
|---|
| 52 | module_param(buggy_semaphore, bool, 0444);
|
|---|
| 53 | MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores.");
|
|---|
| 54 | module_param(buggy_irq, bint, 0444);
|
|---|
| 55 | MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
|
|---|
| 56 | module_param(xbox, bool, 0444);
|
|---|
| 57 | MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
|
|---|
| 58 | module_param(spdif_aclink, int, 0444);
|
|---|
| 59 | MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
|
|---|
| 60 | module_param(inside_vm, bint, 0444);
|
|---|
| 61 | MODULE_PARM_DESC(inside_vm, "KVM/Parallels optimization.");
|
|---|
| 62 |
|
|---|
| 63 | /* just for backward compatibility */
|
|---|
| 64 | //static bool enable;
|
|---|
| 65 | module_param(enable, bool, 0444);
|
|---|
| 66 | //static int joystick;
|
|---|
| 67 | module_param(joystick, int, 0444);
|
|---|
| 68 |
|
|---|
| 69 | /*
|
|---|
| 70 | * Direct registers
|
|---|
| 71 | */
|
|---|
| 72 | enum { DEVICE_INTEL, DEVICE_INTEL_ICH4, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
|
|---|
| 73 |
|
|---|
| 74 | #define ICHREG(x) ICH_REG_##x
|
|---|
| 75 |
|
|---|
| 76 | #define DEFINE_REGSET(name,base) \
|
|---|
| 77 | enum { \
|
|---|
| 78 | ICH_REG_##name##_BDBAR = base + 0x0, /* dword - buffer descriptor list base address */ \
|
|---|
| 79 | ICH_REG_##name##_CIV = base + 0x04, /* byte - current index value */ \
|
|---|
| 80 | ICH_REG_##name##_LVI = base + 0x05, /* byte - last valid index */ \
|
|---|
| 81 | ICH_REG_##name##_SR = base + 0x06, /* byte - status register */ \
|
|---|
| 82 | ICH_REG_##name##_PICB = base + 0x08, /* word - position in current buffer */ \
|
|---|
| 83 | ICH_REG_##name##_PIV = base + 0x0a, /* byte - prefetched index value */ \
|
|---|
| 84 | ICH_REG_##name##_CR = base + 0x0b, /* byte - control register */ \
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /* busmaster blocks */
|
|---|
| 88 | DEFINE_REGSET(OFF, 0); /* offset */
|
|---|
| 89 | DEFINE_REGSET(PI, 0x00); /* PCM in */
|
|---|
| 90 | DEFINE_REGSET(PO, 0x10); /* PCM out */
|
|---|
| 91 | DEFINE_REGSET(MC, 0x20); /* Mic in */
|
|---|
| 92 |
|
|---|
| 93 | /* ICH4 busmaster blocks */
|
|---|
| 94 | DEFINE_REGSET(MC2, 0x40); /* Mic in 2 */
|
|---|
| 95 | DEFINE_REGSET(PI2, 0x50); /* PCM in 2 */
|
|---|
| 96 | DEFINE_REGSET(SP, 0x60); /* SPDIF out */
|
|---|
| 97 |
|
|---|
| 98 | /* values for each busmaster block */
|
|---|
| 99 |
|
|---|
| 100 | /* LVI */
|
|---|
| 101 | #define ICH_REG_LVI_MASK 0x1f
|
|---|
| 102 |
|
|---|
| 103 | /* SR */
|
|---|
| 104 | #define ICH_FIFOE 0x10 /* FIFO error */
|
|---|
| 105 | #define ICH_BCIS 0x08 /* buffer completion interrupt status */
|
|---|
| 106 | #define ICH_LVBCI 0x04 /* last valid buffer completion interrupt */
|
|---|
| 107 | #define ICH_CELV 0x02 /* current equals last valid */
|
|---|
| 108 | #define ICH_DCH 0x01 /* DMA controller halted */
|
|---|
| 109 |
|
|---|
| 110 | /* PIV */
|
|---|
| 111 | #define ICH_REG_PIV_MASK 0x1f /* mask */
|
|---|
| 112 |
|
|---|
| 113 | /* CR */
|
|---|
| 114 | #define ICH_IOCE 0x10 /* interrupt on completion enable */
|
|---|
| 115 | #define ICH_FEIE 0x08 /* fifo error interrupt enable */
|
|---|
| 116 | #define ICH_LVBIE 0x04 /* last valid buffer interrupt enable */
|
|---|
| 117 | #define ICH_RESETREGS 0x02 /* reset busmaster registers */
|
|---|
| 118 | #define ICH_STARTBM 0x01 /* start busmaster operation */
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 | /* global block */
|
|---|
| 122 | #define ICH_REG_GLOB_CNT 0x2c /* dword - global control */
|
|---|
| 123 | #define ICH_PCM_SPDIF_MASK 0xc0000000 /* s/pdif pcm slot mask (ICH4) */
|
|---|
| 124 | #define ICH_PCM_SPDIF_NONE 0x00000000 /* reserved - undefined */
|
|---|
| 125 | #define ICH_PCM_SPDIF_78 0x40000000 /* s/pdif pcm on slots 7&8 */
|
|---|
| 126 | #define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
|
|---|
| 127 | #define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
|
|---|
| 128 | #define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
|
|---|
| 129 | #define ICH_PCM_246_MASK 0x00300000 /* chan mask (not all chips) */
|
|---|
| 130 | #define ICH_PCM_8 0x00300000 /* 8 channels (not all chips) */
|
|---|
| 131 | #define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
|
|---|
| 132 | #define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
|
|---|
| 133 | #define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
|
|---|
| 134 | #define ICH_SIS_PCM_246_MASK 0x000000c0 /* 6 channels (SIS7012) */
|
|---|
| 135 | #define ICH_SIS_PCM_6 0x00000080 /* 6 channels (SIS7012) */
|
|---|
| 136 | #define ICH_SIS_PCM_4 0x00000040 /* 4 channels (SIS7012) */
|
|---|
| 137 | #define ICH_SIS_PCM_2 0x00000000 /* 2 channels (SIS7012) */
|
|---|
| 138 | #define ICH_TRIE 0x00000040 /* tertiary resume interrupt enable */
|
|---|
| 139 | #define ICH_SRIE 0x00000020 /* secondary resume interrupt enable */
|
|---|
| 140 | #define ICH_PRIE 0x00000010 /* primary resume interrupt enable */
|
|---|
| 141 | #define ICH_ACLINK 0x00000008 /* AClink shut off */
|
|---|
| 142 | #define ICH_AC97WARM 0x00000004 /* AC'97 warm reset */
|
|---|
| 143 | #define ICH_AC97COLD 0x00000002 /* AC'97 cold reset */
|
|---|
| 144 | #define ICH_GIE 0x00000001 /* GPI interrupt enable */
|
|---|
| 145 | #define ICH_REG_GLOB_STA 0x30 /* dword - global status */
|
|---|
| 146 | #define ICH_TRI 0x20000000 /* ICH4: tertiary (AC_SDIN2) resume interrupt */
|
|---|
| 147 | #define ICH_TCR 0x10000000 /* ICH4: tertiary (AC_SDIN2) codec ready */
|
|---|
| 148 | #define ICH_BCS 0x08000000 /* ICH4: bit clock stopped */
|
|---|
| 149 | #define ICH_SPINT 0x04000000 /* ICH4: S/PDIF interrupt */
|
|---|
| 150 | #define ICH_P2INT 0x02000000 /* ICH4: PCM2-In interrupt */
|
|---|
| 151 | #define ICH_M2INT 0x01000000 /* ICH4: Mic2-In interrupt */
|
|---|
| 152 | #define ICH_SAMPLE_CAP 0x00c00000 /* ICH4: sample capability bits (RO) */
|
|---|
| 153 | #define ICH_SAMPLE_16_20 0x00400000 /* ICH4: 16- and 20-bit samples */
|
|---|
| 154 | #define ICH_MULTICHAN_CAP 0x00300000 /* ICH4: multi-channel capability bits (RO) */
|
|---|
| 155 | #define ICH_SIS_TRI 0x00080000 /* SIS: tertiary resume irq */
|
|---|
| 156 | #define ICH_SIS_TCR 0x00040000 /* SIS: tertiary codec ready */
|
|---|
| 157 | #define ICH_MD3 0x00020000 /* modem power down semaphore */
|
|---|
| 158 | #define ICH_AD3 0x00010000 /* audio power down semaphore */
|
|---|
| 159 | #define ICH_RCS 0x00008000 /* read completion status */
|
|---|
| 160 | #define ICH_BIT3 0x00004000 /* bit 3 slot 12 */
|
|---|
| 161 | #define ICH_BIT2 0x00002000 /* bit 2 slot 12 */
|
|---|
| 162 | #define ICH_BIT1 0x00001000 /* bit 1 slot 12 */
|
|---|
| 163 | #define ICH_SRI 0x00000800 /* secondary (AC_SDIN1) resume interrupt */
|
|---|
| 164 | #define ICH_PRI 0x00000400 /* primary (AC_SDIN0) resume interrupt */
|
|---|
| 165 | #define ICH_SCR 0x00000200 /* secondary (AC_SDIN1) codec ready */
|
|---|
| 166 | #define ICH_PCR 0x00000100 /* primary (AC_SDIN0) codec ready */
|
|---|
| 167 | #define ICH_MCINT 0x00000080 /* MIC capture interrupt */
|
|---|
| 168 | #define ICH_POINT 0x00000040 /* playback interrupt */
|
|---|
| 169 | #define ICH_PIINT 0x00000020 /* capture interrupt */
|
|---|
| 170 | #define ICH_NVSPINT 0x00000010 /* nforce spdif interrupt */
|
|---|
| 171 | #define ICH_MOINT 0x00000004 /* modem playback interrupt */
|
|---|
| 172 | #define ICH_MIINT 0x00000002 /* modem capture interrupt */
|
|---|
| 173 | #define ICH_GSCI 0x00000001 /* GPI status change interrupt */
|
|---|
| 174 | #define ICH_REG_ACC_SEMA 0x34 /* byte - codec write semaphore */
|
|---|
| 175 | #define ICH_CAS 0x01 /* codec access semaphore */
|
|---|
| 176 | #define ICH_REG_SDM 0x80
|
|---|
| 177 | #define ICH_DI2L_MASK 0x000000c0 /* PCM In 2, Mic In 2 data in line */
|
|---|
| 178 | #define ICH_DI2L_SHIFT 6
|
|---|
| 179 | #define ICH_DI1L_MASK 0x00000030 /* PCM In 1, Mic In 1 data in line */
|
|---|
| 180 | #define ICH_DI1L_SHIFT 4
|
|---|
| 181 | #define ICH_SE 0x00000008 /* steer enable */
|
|---|
| 182 | #define ICH_LDI_MASK 0x00000003 /* last codec read data input */
|
|---|
| 183 |
|
|---|
| 184 | #define ICH_MAX_FRAGS 32 /* max hw frags */
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 | /*
|
|---|
| 188 | * registers for Ali5455
|
|---|
| 189 | */
|
|---|
| 190 |
|
|---|
| 191 | /* ALi 5455 busmaster blocks */
|
|---|
| 192 | DEFINE_REGSET(AL_PI, 0x40); /* ALi PCM in */
|
|---|
| 193 | DEFINE_REGSET(AL_PO, 0x50); /* Ali PCM out */
|
|---|
| 194 | DEFINE_REGSET(AL_MC, 0x60); /* Ali Mic in */
|
|---|
| 195 | DEFINE_REGSET(AL_CDC_SPO, 0x70); /* Ali Codec SPDIF out */
|
|---|
| 196 | DEFINE_REGSET(AL_CENTER, 0x80); /* Ali center out */
|
|---|
| 197 | DEFINE_REGSET(AL_LFE, 0x90); /* Ali center out */
|
|---|
| 198 | DEFINE_REGSET(AL_CLR_SPI, 0xa0); /* Ali Controller SPDIF in */
|
|---|
| 199 | DEFINE_REGSET(AL_CLR_SPO, 0xb0); /* Ali Controller SPDIF out */
|
|---|
| 200 | DEFINE_REGSET(AL_I2S, 0xc0); /* Ali I2S in */
|
|---|
| 201 | DEFINE_REGSET(AL_PI2, 0xd0); /* Ali PCM2 in */
|
|---|
| 202 | DEFINE_REGSET(AL_MC2, 0xe0); /* Ali Mic2 in */
|
|---|
| 203 |
|
|---|
| 204 | enum {
|
|---|
| 205 | ICH_REG_ALI_SCR = 0x00, /* System Control Register */
|
|---|
| 206 | ICH_REG_ALI_SSR = 0x04, /* System Status Register */
|
|---|
| 207 | ICH_REG_ALI_DMACR = 0x08, /* DMA Control Register */
|
|---|
| 208 | ICH_REG_ALI_FIFOCR1 = 0x0c, /* FIFO Control Register 1 */
|
|---|
| 209 | ICH_REG_ALI_INTERFACECR = 0x10, /* Interface Control Register */
|
|---|
| 210 | ICH_REG_ALI_INTERRUPTCR = 0x14, /* Interrupt control Register */
|
|---|
| 211 | ICH_REG_ALI_INTERRUPTSR = 0x18, /* Interrupt Status Register */
|
|---|
| 212 | ICH_REG_ALI_FIFOCR2 = 0x1c, /* FIFO Control Register 2 */
|
|---|
| 213 | ICH_REG_ALI_CPR = 0x20, /* Command Port Register */
|
|---|
| 214 | ICH_REG_ALI_CPR_ADDR = 0x22, /* ac97 addr write */
|
|---|
| 215 | ICH_REG_ALI_SPR = 0x24, /* Status Port Register */
|
|---|
| 216 | ICH_REG_ALI_SPR_ADDR = 0x26, /* ac97 addr read */
|
|---|
| 217 | ICH_REG_ALI_FIFOCR3 = 0x2c, /* FIFO Control Register 3 */
|
|---|
| 218 | ICH_REG_ALI_TTSR = 0x30, /* Transmit Tag Slot Register */
|
|---|
| 219 | ICH_REG_ALI_RTSR = 0x34, /* Receive Tag Slot Register */
|
|---|
| 220 | ICH_REG_ALI_CSPSR = 0x38, /* Command/Status Port Status Register */
|
|---|
| 221 | ICH_REG_ALI_CAS = 0x3c, /* Codec Write Semaphore Register */
|
|---|
| 222 | ICH_REG_ALI_HWVOL = 0xf0, /* hardware volume control/status */
|
|---|
| 223 | ICH_REG_ALI_I2SCR = 0xf4, /* I2S control/status */
|
|---|
| 224 | ICH_REG_ALI_SPDIFCSR = 0xf8, /* spdif channel status register */
|
|---|
| 225 | ICH_REG_ALI_SPDIFICS = 0xfc, /* spdif interface control/status */
|
|---|
| 226 | };
|
|---|
| 227 |
|
|---|
| 228 | #define ALI_CAS_SEM_BUSY 0x80000000
|
|---|
| 229 | #define ALI_CPR_ADDR_SECONDARY 0x100
|
|---|
| 230 | #define ALI_CPR_ADDR_READ 0x80
|
|---|
| 231 | #define ALI_CSPSR_CODEC_READY 0x08
|
|---|
| 232 | #define ALI_CSPSR_READ_OK 0x02
|
|---|
| 233 | #define ALI_CSPSR_WRITE_OK 0x01
|
|---|
| 234 |
|
|---|
| 235 | /* interrupts for the whole chip by interrupt status register finish */
|
|---|
| 236 |
|
|---|
| 237 | #define ALI_INT_MICIN2 (1<<26)
|
|---|
| 238 | #define ALI_INT_PCMIN2 (1<<25)
|
|---|
| 239 | #define ALI_INT_I2SIN (1<<24)
|
|---|
| 240 | #define ALI_INT_SPDIFOUT (1<<23) /* controller spdif out INTERRUPT */
|
|---|
| 241 | #define ALI_INT_SPDIFIN (1<<22)
|
|---|
| 242 | #define ALI_INT_LFEOUT (1<<21)
|
|---|
| 243 | #define ALI_INT_CENTEROUT (1<<20)
|
|---|
| 244 | #define ALI_INT_CODECSPDIFOUT (1<<19)
|
|---|
| 245 | #define ALI_INT_MICIN (1<<18)
|
|---|
| 246 | #define ALI_INT_PCMOUT (1<<17)
|
|---|
| 247 | #define ALI_INT_PCMIN (1<<16)
|
|---|
| 248 | #define ALI_INT_CPRAIS (1<<7) /* command port available */
|
|---|
| 249 | #define ALI_INT_SPRAIS (1<<5) /* status port available */
|
|---|
| 250 | #define ALI_INT_GPIO (1<<1)
|
|---|
| 251 | #define ALI_INT_MASK (ALI_INT_SPDIFOUT|ALI_INT_CODECSPDIFOUT|\
|
|---|
| 252 | ALI_INT_MICIN|ALI_INT_PCMOUT|ALI_INT_PCMIN)
|
|---|
| 253 |
|
|---|
| 254 | #define ICH_ALI_SC_RESET (1<<31) /* master reset */
|
|---|
| 255 | #define ICH_ALI_SC_AC97_DBL (1<<30)
|
|---|
| 256 | #define ICH_ALI_SC_CODEC_SPDF (3<<20) /* 1=7/8, 2=6/9, 3=10/11 */
|
|---|
| 257 | #define ICH_ALI_SC_IN_BITS (3<<18)
|
|---|
| 258 | #define ICH_ALI_SC_OUT_BITS (3<<16)
|
|---|
| 259 | #define ICH_ALI_SC_6CH_CFG (3<<14)
|
|---|
| 260 | #define ICH_ALI_SC_PCM_4 (1<<8)
|
|---|
| 261 | #define ICH_ALI_SC_PCM_6 (2<<8)
|
|---|
| 262 | #define ICH_ALI_SC_PCM_246_MASK (3<<8)
|
|---|
| 263 |
|
|---|
| 264 | #define ICH_ALI_SS_SEC_ID (3<<5)
|
|---|
| 265 | #define ICH_ALI_SS_PRI_ID (3<<3)
|
|---|
| 266 |
|
|---|
| 267 | #define ICH_ALI_IF_AC97SP (1<<21)
|
|---|
| 268 | #define ICH_ALI_IF_MC (1<<20)
|
|---|
| 269 | #define ICH_ALI_IF_PI (1<<19)
|
|---|
| 270 | #define ICH_ALI_IF_MC2 (1<<18)
|
|---|
| 271 | #define ICH_ALI_IF_PI2 (1<<17)
|
|---|
| 272 | #define ICH_ALI_IF_LINE_SRC (1<<15) /* 0/1 = slot 3/6 */
|
|---|
| 273 | #define ICH_ALI_IF_MIC_SRC (1<<14) /* 0/1 = slot 3/6 */
|
|---|
| 274 | #define ICH_ALI_IF_SPDF_SRC (3<<12) /* 00 = PCM, 01 = AC97-in, 10 = spdif-in, 11 = i2s */
|
|---|
| 275 | #define ICH_ALI_IF_AC97_OUT (3<<8) /* 00 = PCM, 10 = spdif-in, 11 = i2s */
|
|---|
| 276 | #define ICH_ALI_IF_PO_SPDF (1<<3)
|
|---|
| 277 | #define ICH_ALI_IF_PO (1<<1)
|
|---|
| 278 |
|
|---|
| 279 | /*
|
|---|
| 280 | *
|
|---|
| 281 | */
|
|---|
| 282 |
|
|---|
| 283 | enum {
|
|---|
| 284 | ICHD_PCMIN,
|
|---|
| 285 | ICHD_PCMOUT,
|
|---|
| 286 | ICHD_MIC,
|
|---|
| 287 | ICHD_MIC2,
|
|---|
| 288 | ICHD_PCM2IN,
|
|---|
| 289 | ICHD_SPBAR,
|
|---|
| 290 | ICHD_LAST = ICHD_SPBAR
|
|---|
| 291 | };
|
|---|
| 292 | enum {
|
|---|
| 293 | NVD_PCMIN,
|
|---|
| 294 | NVD_PCMOUT,
|
|---|
| 295 | NVD_MIC,
|
|---|
| 296 | NVD_SPBAR,
|
|---|
| 297 | NVD_LAST = NVD_SPBAR
|
|---|
| 298 | };
|
|---|
| 299 | enum {
|
|---|
| 300 | ALID_PCMIN,
|
|---|
| 301 | ALID_PCMOUT,
|
|---|
| 302 | ALID_MIC,
|
|---|
| 303 | ALID_AC97SPDIFOUT,
|
|---|
| 304 | ALID_SPDIFIN,
|
|---|
| 305 | ALID_SPDIFOUT,
|
|---|
| 306 | ALID_LAST = ALID_SPDIFOUT
|
|---|
| 307 | };
|
|---|
| 308 |
|
|---|
| 309 | #define get_ichdev(substream) (substream->runtime->private_data)
|
|---|
| 310 |
|
|---|
| 311 | struct ichdev {
|
|---|
| 312 | unsigned int ichd; /* ich device number */
|
|---|
| 313 | unsigned long reg_offset; /* offset to bmaddr */
|
|---|
| 314 | __le32 *bdbar; /* CPU address (32bit) */
|
|---|
| 315 | unsigned int bdbar_addr; /* PCI bus address (32bit) */
|
|---|
| 316 | struct snd_pcm_substream *substream;
|
|---|
| 317 | unsigned int physbuf; /* physical address (32bit) */
|
|---|
| 318 | unsigned int size;
|
|---|
| 319 | unsigned int fragsize;
|
|---|
| 320 | unsigned int fragsize1;
|
|---|
| 321 | unsigned int position;
|
|---|
| 322 | unsigned int pos_shift;
|
|---|
| 323 | unsigned int last_pos;
|
|---|
| 324 | int frags;
|
|---|
| 325 | int lvi;
|
|---|
| 326 | int lvi_frag;
|
|---|
| 327 | int civ;
|
|---|
| 328 | int ack;
|
|---|
| 329 | int ack_reload;
|
|---|
| 330 | unsigned int ack_bit;
|
|---|
| 331 | unsigned int roff_sr;
|
|---|
| 332 | unsigned int roff_picb;
|
|---|
| 333 | unsigned int int_sta_mask; /* interrupt status mask */
|
|---|
| 334 | unsigned int ali_slot; /* ALI DMA slot */
|
|---|
| 335 | struct ac97_pcm *pcm;
|
|---|
| 336 | int pcm_open_flag;
|
|---|
| 337 | unsigned int prepared:1;
|
|---|
| 338 | unsigned int suspended: 1;
|
|---|
| 339 | };
|
|---|
| 340 |
|
|---|
| 341 | struct intel8x0 {
|
|---|
| 342 | unsigned int device_type;
|
|---|
| 343 |
|
|---|
| 344 | int irq;
|
|---|
| 345 |
|
|---|
| 346 | void __iomem *addr;
|
|---|
| 347 | void __iomem *bmaddr;
|
|---|
| 348 |
|
|---|
| 349 | struct pci_dev *pci;
|
|---|
| 350 | struct snd_card *card;
|
|---|
| 351 |
|
|---|
| 352 | int pcm_devs;
|
|---|
| 353 | struct snd_pcm *pcm[6];
|
|---|
| 354 | struct ichdev ichd[6];
|
|---|
| 355 |
|
|---|
| 356 | unsigned multi4: 1,
|
|---|
| 357 | multi6: 1,
|
|---|
| 358 | multi8 :1,
|
|---|
| 359 | dra: 1,
|
|---|
| 360 | smp20bit: 1;
|
|---|
| 361 | unsigned in_ac97_init: 1,
|
|---|
| 362 | in_sdin_init: 1;
|
|---|
| 363 | unsigned in_measurement: 1; /* during ac97 clock measurement */
|
|---|
| 364 | unsigned fix_nocache: 1; /* workaround for 440MX */
|
|---|
| 365 | unsigned buggy_irq: 1; /* workaround for buggy mobos */
|
|---|
| 366 | unsigned xbox: 1; /* workaround for Xbox AC'97 detection */
|
|---|
| 367 | unsigned buggy_semaphore: 1; /* workaround for buggy codec semaphore */
|
|---|
| 368 | unsigned inside_vm: 1; /* enable VM optimization */
|
|---|
| 369 |
|
|---|
| 370 | int spdif_idx; /* SPDIF BAR index; *_SPBAR or -1 if use PCMOUT */
|
|---|
| 371 | unsigned int sdm_saved; /* SDM reg value */
|
|---|
| 372 |
|
|---|
| 373 | struct snd_ac97_bus *ac97_bus;
|
|---|
| 374 | struct snd_ac97 *ac97[3];
|
|---|
| 375 | unsigned int ac97_sdin[3];
|
|---|
| 376 | unsigned int max_codecs, ncodecs;
|
|---|
| 377 | const unsigned int *codec_bit;
|
|---|
| 378 | unsigned int codec_isr_bits;
|
|---|
| 379 | unsigned int codec_ready_bits;
|
|---|
| 380 |
|
|---|
| 381 | spinlock_t reg_lock;
|
|---|
| 382 |
|
|---|
| 383 | u32 bdbars_count;
|
|---|
| 384 | struct snd_dma_buffer bdbars;
|
|---|
| 385 | u32 int_sta_reg; /* interrupt status register */
|
|---|
| 386 | u32 int_sta_mask; /* interrupt status mask */
|
|---|
| 387 | };
|
|---|
| 388 |
|
|---|
| 389 | static const struct pci_device_id snd_intel8x0_ids[] = {
|
|---|
| 390 | { PCI_VDEVICE(INTEL, 0x2415), DEVICE_INTEL }, /* 82801AA */
|
|---|
| 391 | { PCI_VDEVICE(INTEL, 0x2425), DEVICE_INTEL }, /* 82901AB */
|
|---|
| 392 | { PCI_VDEVICE(INTEL, 0x2445), DEVICE_INTEL }, /* 82801BA */
|
|---|
| 393 | { PCI_VDEVICE(INTEL, 0x2485), DEVICE_INTEL }, /* ICH3 */
|
|---|
| 394 | { PCI_VDEVICE(INTEL, 0x24c5), DEVICE_INTEL_ICH4 }, /* ICH4 */
|
|---|
| 395 | { PCI_VDEVICE(INTEL, 0x24d5), DEVICE_INTEL_ICH4 }, /* ICH5 */
|
|---|
| 396 | { PCI_VDEVICE(INTEL, 0x25a6), DEVICE_INTEL_ICH4 }, /* ESB */
|
|---|
| 397 | { PCI_VDEVICE(INTEL, 0x266e), DEVICE_INTEL_ICH4 }, /* ICH6 */
|
|---|
| 398 | { PCI_VDEVICE(INTEL, 0x27de), DEVICE_INTEL_ICH4 }, /* ICH7 */
|
|---|
| 399 | { PCI_VDEVICE(INTEL, 0x2698), DEVICE_INTEL_ICH4 }, /* ESB2 */
|
|---|
| 400 | { PCI_VDEVICE(INTEL, 0x7195), DEVICE_INTEL }, /* 440MX */
|
|---|
| 401 | { PCI_VDEVICE(SI, 0x7012), DEVICE_SIS }, /* SI7012 */
|
|---|
| 402 | { PCI_VDEVICE(NVIDIA, 0x01b1), DEVICE_NFORCE }, /* NFORCE */
|
|---|
| 403 | { PCI_VDEVICE(NVIDIA, 0x003a), DEVICE_NFORCE }, /* MCP04 */
|
|---|
| 404 | { PCI_VDEVICE(NVIDIA, 0x006a), DEVICE_NFORCE }, /* NFORCE2 */
|
|---|
| 405 | { PCI_VDEVICE(NVIDIA, 0x0059), DEVICE_NFORCE }, /* CK804 */
|
|---|
| 406 | { PCI_VDEVICE(NVIDIA, 0x008a), DEVICE_NFORCE }, /* CK8 */
|
|---|
| 407 | { PCI_VDEVICE(NVIDIA, 0x00da), DEVICE_NFORCE }, /* NFORCE3 */
|
|---|
| 408 | { PCI_VDEVICE(NVIDIA, 0x00ea), DEVICE_NFORCE }, /* CK8S */
|
|---|
| 409 | { PCI_VDEVICE(NVIDIA, 0x026b), DEVICE_NFORCE }, /* MCP51 */
|
|---|
| 410 | { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
|
|---|
| 411 | { PCI_VDEVICE(AMD, 0x7445), DEVICE_INTEL }, /* AMD768 */
|
|---|
| 412 | { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
|
|---|
| 413 | { 0, }
|
|---|
| 414 | };
|
|---|
| 415 |
|
|---|
| 416 | MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
|
|---|
| 417 |
|
|---|
| 418 | /*
|
|---|
| 419 | * Lowlevel I/O - busmaster
|
|---|
| 420 | */
|
|---|
| 421 |
|
|---|
| 422 | static inline u8 igetbyte(struct intel8x0 *chip, u32 offset)
|
|---|
| 423 | {
|
|---|
| 424 | return ioread8(chip->bmaddr + offset);
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | static inline u16 igetword(struct intel8x0 *chip, u32 offset)
|
|---|
| 428 | {
|
|---|
| 429 | return ioread16(chip->bmaddr + offset);
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | static inline u32 igetdword(struct intel8x0 *chip, u32 offset)
|
|---|
| 433 | {
|
|---|
| 434 | return ioread32(chip->bmaddr + offset);
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | static inline void iputbyte(struct intel8x0 *chip, u32 offset, u8 val)
|
|---|
| 438 | {
|
|---|
| 439 | iowrite8(val, chip->bmaddr + offset);
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | static inline void iputword(struct intel8x0 *chip, u32 offset, u16 val)
|
|---|
| 443 | {
|
|---|
| 444 | iowrite16(val, chip->bmaddr + offset);
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | static inline void iputdword(struct intel8x0 *chip, u32 offset, u32 val)
|
|---|
| 448 | {
|
|---|
| 449 | iowrite32(val, chip->bmaddr + offset);
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | /*
|
|---|
| 453 | * Lowlevel I/O - AC'97 registers
|
|---|
| 454 | */
|
|---|
| 455 |
|
|---|
| 456 | static inline u16 iagetword(struct intel8x0 *chip, u32 offset)
|
|---|
| 457 | {
|
|---|
| 458 | return ioread16(chip->addr + offset);
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | static inline void iaputword(struct intel8x0 *chip, u32 offset, u16 val)
|
|---|
| 462 | {
|
|---|
| 463 | iowrite16(val, chip->addr + offset);
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | /*
|
|---|
| 467 | * Basic I/O
|
|---|
| 468 | */
|
|---|
| 469 |
|
|---|
| 470 | /*
|
|---|
| 471 | * access to AC97 codec via normal i/o (for ICH and SIS7012)
|
|---|
| 472 | */
|
|---|
| 473 |
|
|---|
| 474 | static int snd_intel8x0_codec_semaphore(struct intel8x0 *chip, unsigned int codec)
|
|---|
| 475 | {
|
|---|
| 476 | int time;
|
|---|
| 477 |
|
|---|
| 478 | if (codec > 2)
|
|---|
| 479 | return -EIO;
|
|---|
| 480 | if (chip->in_sdin_init) {
|
|---|
| 481 | /* we don't know the ready bit assignment at the moment */
|
|---|
| 482 | /* so we check any */
|
|---|
| 483 | codec = chip->codec_isr_bits;
|
|---|
| 484 | } else {
|
|---|
| 485 | codec = chip->codec_bit[chip->ac97_sdin[codec]];
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | /* codec ready ? */
|
|---|
| 489 | if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
|
|---|
| 490 | return -EIO;
|
|---|
| 491 |
|
|---|
| 492 | if (chip->buggy_semaphore)
|
|---|
| 493 | return 0; /* just ignore ... */
|
|---|
| 494 |
|
|---|
| 495 | /* Anyone holding a semaphore for 1 msec should be shot... */
|
|---|
| 496 | time = 100;
|
|---|
| 497 | do {
|
|---|
| 498 | if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
|
|---|
| 499 | return 0;
|
|---|
| 500 | udelay(10);
|
|---|
| 501 | } while (time--);
|
|---|
| 502 |
|
|---|
| 503 | /* access to some forbidden (non existent) ac97 registers will not
|
|---|
| 504 | * reset the semaphore. So even if you don't get the semaphore, still
|
|---|
| 505 | * continue the access. We don't need the semaphore anyway. */
|
|---|
| 506 | dev_err(chip->card->dev,
|
|---|
| 507 | "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
|
|---|
| 508 | igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
|
|---|
| 509 | iagetword(chip, 0); /* clear semaphore flag */
|
|---|
| 510 | /* I don't care about the semaphore */
|
|---|
| 511 | return -EBUSY;
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | static void snd_intel8x0_codec_write(struct snd_ac97 *ac97,
|
|---|
| 515 | unsigned short reg,
|
|---|
| 516 | unsigned short val)
|
|---|
| 517 | {
|
|---|
| 518 | struct intel8x0 *chip = ac97->private_data;
|
|---|
| 519 |
|
|---|
| 520 | if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
|
|---|
| 521 | if (! chip->in_ac97_init)
|
|---|
| 522 | dev_err(chip->card->dev,
|
|---|
| 523 | "codec_write %d: semaphore is not ready for register 0x%x\n",
|
|---|
| 524 | ac97->num, reg);
|
|---|
| 525 | }
|
|---|
| 526 | iaputword(chip, reg + ac97->num * 0x80, val);
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | static unsigned short snd_intel8x0_codec_read(struct snd_ac97 *ac97,
|
|---|
| 530 | unsigned short reg)
|
|---|
| 531 | {
|
|---|
| 532 | struct intel8x0 *chip = ac97->private_data;
|
|---|
| 533 | unsigned short res;
|
|---|
| 534 | unsigned int tmp;
|
|---|
| 535 |
|
|---|
| 536 | if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
|
|---|
| 537 | if (! chip->in_ac97_init)
|
|---|
| 538 | dev_err(chip->card->dev,
|
|---|
| 539 | "codec_read %d: semaphore is not ready for register 0x%x\n",
|
|---|
| 540 | ac97->num, reg);
|
|---|
| 541 | res = 0xffff;
|
|---|
| 542 | } else {
|
|---|
| 543 | res = iagetword(chip, reg + ac97->num * 0x80);
|
|---|
| 544 | tmp = igetdword(chip, ICHREG(GLOB_STA));
|
|---|
| 545 | if (tmp & ICH_RCS) {
|
|---|
| 546 | /* reset RCS and preserve other R/WC bits */
|
|---|
| 547 | iputdword(chip, ICHREG(GLOB_STA), tmp &
|
|---|
| 548 | ~(chip->codec_ready_bits | ICH_GSCI));
|
|---|
| 549 | if (! chip->in_ac97_init)
|
|---|
| 550 | dev_err(chip->card->dev,
|
|---|
| 551 | "codec_read %d: read timeout for register 0x%x\n",
|
|---|
| 552 | ac97->num, reg);
|
|---|
| 553 | res = 0xffff;
|
|---|
| 554 | }
|
|---|
| 555 | }
|
|---|
| 556 | return res;
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | static void snd_intel8x0_codec_read_test(struct intel8x0 *chip,
|
|---|
| 560 | unsigned int codec)
|
|---|
| 561 | {
|
|---|
| 562 | unsigned int tmp;
|
|---|
| 563 |
|
|---|
| 564 | if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) {
|
|---|
| 565 | iagetword(chip, codec * 0x80);
|
|---|
| 566 | tmp = igetdword(chip, ICHREG(GLOB_STA));
|
|---|
| 567 | if (tmp & ICH_RCS) {
|
|---|
| 568 | /* reset RCS and preserve other R/WC bits */
|
|---|
| 569 | iputdword(chip, ICHREG(GLOB_STA), tmp &
|
|---|
| 570 | ~(chip->codec_ready_bits | ICH_GSCI));
|
|---|
| 571 | }
|
|---|
| 572 | }
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | /*
|
|---|
| 576 | * access to AC97 for Ali5455
|
|---|
| 577 | */
|
|---|
| 578 | static int snd_intel8x0_ali_codec_ready(struct intel8x0 *chip, int mask)
|
|---|
| 579 | {
|
|---|
| 580 | int count = 0;
|
|---|
| 581 | for (count = 0; count < 0x7f; count++) {
|
|---|
| 582 | int val = igetbyte(chip, ICHREG(ALI_CSPSR));
|
|---|
| 583 | if (val & mask)
|
|---|
| 584 | return 0;
|
|---|
| 585 | }
|
|---|
| 586 | if (! chip->in_ac97_init)
|
|---|
| 587 | dev_warn(chip->card->dev, "AC97 codec ready timeout.\n");
|
|---|
| 588 | return -EBUSY;
|
|---|
| 589 | }
|
|---|
| 590 |
|
|---|
| 591 | static int snd_intel8x0_ali_codec_semaphore(struct intel8x0 *chip)
|
|---|
| 592 | {
|
|---|
| 593 | int time = 100;
|
|---|
| 594 | if (chip->buggy_semaphore)
|
|---|
| 595 | return 0; /* just ignore ... */
|
|---|
| 596 | while (--time && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
|
|---|
| 597 | udelay(1);
|
|---|
| 598 | if (! time && ! chip->in_ac97_init)
|
|---|
| 599 | dev_warn(chip->card->dev, "ali_codec_semaphore timeout\n");
|
|---|
| 600 | return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | static unsigned short snd_intel8x0_ali_codec_read(struct snd_ac97 *ac97, unsigned short reg)
|
|---|
| 604 | {
|
|---|
| 605 | struct intel8x0 *chip = ac97->private_data;
|
|---|
| 606 | unsigned short data = 0xffff;
|
|---|
| 607 |
|
|---|
| 608 | if (snd_intel8x0_ali_codec_semaphore(chip))
|
|---|
| 609 | goto __err;
|
|---|
| 610 | reg |= ALI_CPR_ADDR_READ;
|
|---|
| 611 | if (ac97->num)
|
|---|
| 612 | reg |= ALI_CPR_ADDR_SECONDARY;
|
|---|
| 613 | iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
|
|---|
| 614 | if (snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_READ_OK))
|
|---|
| 615 | goto __err;
|
|---|
| 616 | data = igetword(chip, ICHREG(ALI_SPR));
|
|---|
| 617 | __err:
|
|---|
| 618 | return data;
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | static void snd_intel8x0_ali_codec_write(struct snd_ac97 *ac97, unsigned short reg,
|
|---|
| 622 | unsigned short val)
|
|---|
| 623 | {
|
|---|
| 624 | struct intel8x0 *chip = ac97->private_data;
|
|---|
| 625 |
|
|---|
| 626 | if (snd_intel8x0_ali_codec_semaphore(chip))
|
|---|
| 627 | return;
|
|---|
| 628 | iputword(chip, ICHREG(ALI_CPR), val);
|
|---|
| 629 | if (ac97->num)
|
|---|
| 630 | reg |= ALI_CPR_ADDR_SECONDARY;
|
|---|
| 631 | iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
|
|---|
| 632 | snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_WRITE_OK);
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 | /*
|
|---|
| 637 | * DMA I/O
|
|---|
| 638 | */
|
|---|
| 639 | static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ichdev)
|
|---|
| 640 | {
|
|---|
| 641 | int idx;
|
|---|
| 642 | __le32 *bdbar = ichdev->bdbar;
|
|---|
| 643 | unsigned long port = ichdev->reg_offset;
|
|---|
| 644 |
|
|---|
| 645 | iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
|
|---|
| 646 | if (ichdev->size == ichdev->fragsize) {
|
|---|
| 647 | ichdev->ack_reload = ichdev->ack = 2;
|
|---|
| 648 | ichdev->fragsize1 = ichdev->fragsize >> 1;
|
|---|
| 649 | for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
|
|---|
| 650 | bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
|
|---|
| 651 | bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
|
|---|
| 652 | ichdev->fragsize1 >> ichdev->pos_shift);
|
|---|
| 653 | bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
|
|---|
| 654 | bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
|
|---|
| 655 | ichdev->fragsize1 >> ichdev->pos_shift);
|
|---|
| 656 | }
|
|---|
| 657 | ichdev->frags = 2;
|
|---|
| 658 | } else {
|
|---|
| 659 | ichdev->ack_reload = ichdev->ack = 1;
|
|---|
| 660 | ichdev->fragsize1 = ichdev->fragsize;
|
|---|
| 661 | for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
|
|---|
| 662 | bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf +
|
|---|
| 663 | (((idx >> 1) * ichdev->fragsize) %
|
|---|
| 664 | ichdev->size));
|
|---|
| 665 | bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
|
|---|
| 666 | ichdev->fragsize >> ichdev->pos_shift);
|
|---|
| 667 | #if 0
|
|---|
| 668 | dev_dbg(chip->card->dev, "bdbar[%i] = 0x%x [0x%x]\n",
|
|---|
| 669 | idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
|
|---|
| 670 | #endif
|
|---|
| 671 | }
|
|---|
| 672 | ichdev->frags = ichdev->size / ichdev->fragsize;
|
|---|
| 673 | }
|
|---|
| 674 | iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
|
|---|
| 675 | ichdev->civ = 0;
|
|---|
| 676 | iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
|
|---|
| 677 | ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
|
|---|
| 678 | ichdev->position = 0;
|
|---|
| 679 | #if 0
|
|---|
| 680 | dev_dbg(chip->card->dev,
|
|---|
| 681 | "lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
|
|---|
| 682 | ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
|
|---|
| 683 | ichdev->fragsize1);
|
|---|
| 684 | #endif
|
|---|
| 685 | /* clear interrupts */
|
|---|
| 686 | iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 | /*
|
|---|
| 690 | * Interrupt handler
|
|---|
| 691 | */
|
|---|
| 692 |
|
|---|
| 693 | static inline void snd_intel8x0_update(struct intel8x0 *chip, struct ichdev *ichdev)
|
|---|
| 694 | {
|
|---|
| 695 | unsigned long port = ichdev->reg_offset;
|
|---|
| 696 | unsigned long flags;
|
|---|
| 697 | int status, civ, i, step;
|
|---|
| 698 | int ack = 0;
|
|---|
| 699 |
|
|---|
| 700 | if (!(ichdev->prepared || chip->in_measurement) || ichdev->suspended)
|
|---|
| 701 | return;
|
|---|
| 702 |
|
|---|
| 703 | spin_lock_irqsave(&chip->reg_lock, flags);
|
|---|
| 704 | status = igetbyte(chip, port + ichdev->roff_sr);
|
|---|
| 705 | civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
|
|---|
| 706 | if (!(status & ICH_BCIS)) {
|
|---|
| 707 | step = 0;
|
|---|
| 708 | } else if (civ == ichdev->civ) {
|
|---|
| 709 | // snd_printd("civ same %d\n", civ);
|
|---|
| 710 | step = 1;
|
|---|
| 711 | ichdev->civ++;
|
|---|
| 712 | ichdev->civ &= ICH_REG_LVI_MASK;
|
|---|
| 713 | } else {
|
|---|
| 714 | step = civ - ichdev->civ;
|
|---|
| 715 | if (step < 0)
|
|---|
| 716 | step += ICH_REG_LVI_MASK + 1;
|
|---|
| 717 | // if (step != 1)
|
|---|
| 718 | // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
|
|---|
| 719 | ichdev->civ = civ;
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 | ichdev->position += step * ichdev->fragsize1;
|
|---|
| 723 | if (! chip->in_measurement)
|
|---|
| 724 | ichdev->position %= ichdev->size;
|
|---|
| 725 | ichdev->lvi += step;
|
|---|
| 726 | ichdev->lvi &= ICH_REG_LVI_MASK;
|
|---|
| 727 | iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
|
|---|
| 728 | for (i = 0; i < step; i++) {
|
|---|
| 729 | ichdev->lvi_frag++;
|
|---|
| 730 | ichdev->lvi_frag %= ichdev->frags;
|
|---|
| 731 | ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
|
|---|
| 732 | #if 0
|
|---|
| 733 | dev_dbg(chip->card->dev,
|
|---|
| 734 | "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
|
|---|
| 735 | ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
|
|---|
| 736 | ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
|
|---|
| 737 | inl(port + 4), inb(port + ICH_REG_OFF_CR));
|
|---|
| 738 | #endif
|
|---|
| 739 | if (--ichdev->ack == 0) {
|
|---|
| 740 | ichdev->ack = ichdev->ack_reload;
|
|---|
| 741 | ack = 1;
|
|---|
| 742 | }
|
|---|
| 743 | }
|
|---|
| 744 | spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|---|
| 745 | if (ack && ichdev->substream) {
|
|---|
| 746 | snd_pcm_period_elapsed(ichdev->substream);
|
|---|
| 747 | }
|
|---|
| 748 | iputbyte(chip, port + ichdev->roff_sr,
|
|---|
| 749 | status & (ICH_FIFOE | ICH_BCIS | ICH_LVBCI));
|
|---|
| 750 | }
|
|---|
| 751 |
|
|---|
| 752 | static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id)
|
|---|
| 753 | {
|
|---|
| 754 | struct intel8x0 *chip = dev_id;
|
|---|
| 755 | struct ichdev *ichdev;
|
|---|
| 756 | unsigned int status;
|
|---|
| 757 | unsigned int i;
|
|---|
| 758 |
|
|---|
| 759 | status = igetdword(chip, chip->int_sta_reg);
|
|---|
| 760 | if (status == 0xffffffff) /* we are not yet resumed */
|
|---|
| 761 | return IRQ_NONE;
|
|---|
| 762 |
|
|---|
| 763 | if ((status & chip->int_sta_mask) == 0) {
|
|---|
| 764 | if (status) {
|
|---|
| 765 | /* ack */
|
|---|
| 766 | iputdword(chip, chip->int_sta_reg, status);
|
|---|
| 767 | if (! chip->buggy_irq)
|
|---|
| 768 | status = 0;
|
|---|
| 769 | }
|
|---|
| 770 | return IRQ_RETVAL(status);
|
|---|
| 771 | }
|
|---|
| 772 |
|
|---|
| 773 | for (i = 0; i < chip->bdbars_count; i++) {
|
|---|
| 774 | ichdev = &chip->ichd[i];
|
|---|
| 775 | if (status & ichdev->int_sta_mask)
|
|---|
| 776 | snd_intel8x0_update(chip, ichdev);
|
|---|
| 777 | }
|
|---|
| 778 |
|
|---|
| 779 | /* ack them */
|
|---|
| 780 | iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
|
|---|
| 781 |
|
|---|
| 782 | return IRQ_HANDLED;
|
|---|
| 783 | }
|
|---|
| 784 |
|
|---|
| 785 | /*
|
|---|
| 786 | * PCM part
|
|---|
| 787 | */
|
|---|
| 788 |
|
|---|
| 789 | static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
|---|
| 790 | {
|
|---|
| 791 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 792 | struct ichdev *ichdev = get_ichdev(substream);
|
|---|
| 793 | unsigned char val = 0;
|
|---|
| 794 | unsigned long port = ichdev->reg_offset;
|
|---|
| 795 |
|
|---|
| 796 | switch (cmd) {
|
|---|
| 797 | case SNDRV_PCM_TRIGGER_RESUME:
|
|---|
| 798 | ichdev->suspended = 0;
|
|---|
| 799 | fallthrough;
|
|---|
| 800 | case SNDRV_PCM_TRIGGER_START:
|
|---|
| 801 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|---|
| 802 | val = ICH_IOCE | ICH_STARTBM;
|
|---|
| 803 | ichdev->last_pos = ichdev->position;
|
|---|
| 804 | break;
|
|---|
| 805 | case SNDRV_PCM_TRIGGER_SUSPEND:
|
|---|
| 806 | ichdev->suspended = 1;
|
|---|
| 807 | fallthrough;
|
|---|
| 808 | case SNDRV_PCM_TRIGGER_STOP:
|
|---|
| 809 | val = 0;
|
|---|
| 810 | break;
|
|---|
| 811 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|---|
| 812 | val = ICH_IOCE;
|
|---|
| 813 | break;
|
|---|
| 814 | default:
|
|---|
| 815 | return -EINVAL;
|
|---|
| 816 | }
|
|---|
| 817 | iputbyte(chip, port + ICH_REG_OFF_CR, val);
|
|---|
| 818 | if (cmd == SNDRV_PCM_TRIGGER_STOP) {
|
|---|
| 819 | /* wait until DMA stopped */
|
|---|
| 820 | while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
|
|---|
| 821 | /* reset whole DMA things */
|
|---|
| 822 | iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
|
|---|
| 823 | }
|
|---|
| 824 | return 0;
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | static int snd_intel8x0_ali_trigger(struct snd_pcm_substream *substream, int cmd)
|
|---|
| 828 | {
|
|---|
| 829 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 830 | struct ichdev *ichdev = get_ichdev(substream);
|
|---|
| 831 | unsigned long port = ichdev->reg_offset;
|
|---|
| 832 | static const int fiforeg[] = {
|
|---|
| 833 | ICHREG(ALI_FIFOCR1), ICHREG(ALI_FIFOCR2), ICHREG(ALI_FIFOCR3)
|
|---|
| 834 | };
|
|---|
| 835 | unsigned int val, fifo;
|
|---|
| 836 |
|
|---|
| 837 | val = igetdword(chip, ICHREG(ALI_DMACR));
|
|---|
| 838 | switch (cmd) {
|
|---|
| 839 | case SNDRV_PCM_TRIGGER_RESUME:
|
|---|
| 840 | ichdev->suspended = 0;
|
|---|
| 841 | fallthrough;
|
|---|
| 842 | case SNDRV_PCM_TRIGGER_START:
|
|---|
| 843 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|---|
| 844 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|---|
| 845 | /* clear FIFO for synchronization of channels */
|
|---|
| 846 | fifo = igetdword(chip, fiforeg[ichdev->ali_slot / 4]);
|
|---|
| 847 | fifo &= ~(0xff << (ichdev->ali_slot % 4));
|
|---|
| 848 | fifo |= 0x83 << (ichdev->ali_slot % 4);
|
|---|
| 849 | iputdword(chip, fiforeg[ichdev->ali_slot / 4], fifo);
|
|---|
| 850 | }
|
|---|
| 851 | iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
|
|---|
| 852 | val &= ~(1 << (ichdev->ali_slot + 16)); /* clear PAUSE flag */
|
|---|
| 853 | /* start DMA */
|
|---|
| 854 | iputdword(chip, ICHREG(ALI_DMACR), val | (1 << ichdev->ali_slot));
|
|---|
| 855 | break;
|
|---|
| 856 | case SNDRV_PCM_TRIGGER_SUSPEND:
|
|---|
| 857 | ichdev->suspended = 1;
|
|---|
| 858 | fallthrough;
|
|---|
| 859 | case SNDRV_PCM_TRIGGER_STOP:
|
|---|
| 860 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|---|
| 861 | /* pause */
|
|---|
| 862 | iputdword(chip, ICHREG(ALI_DMACR), val | (1 << (ichdev->ali_slot + 16)));
|
|---|
| 863 | iputbyte(chip, port + ICH_REG_OFF_CR, 0);
|
|---|
| 864 | while (igetbyte(chip, port + ICH_REG_OFF_CR))
|
|---|
| 865 | ;
|
|---|
| 866 | if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
|
|---|
| 867 | break;
|
|---|
| 868 | /* reset whole DMA things */
|
|---|
| 869 | iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
|
|---|
| 870 | /* clear interrupts */
|
|---|
| 871 | iputbyte(chip, port + ICH_REG_OFF_SR,
|
|---|
| 872 | igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
|
|---|
| 873 | iputdword(chip, ICHREG(ALI_INTERRUPTSR),
|
|---|
| 874 | igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ichdev->int_sta_mask);
|
|---|
| 875 | break;
|
|---|
| 876 | default:
|
|---|
| 877 | return -EINVAL;
|
|---|
| 878 | }
|
|---|
| 879 | return 0;
|
|---|
| 880 | }
|
|---|
| 881 |
|
|---|
| 882 | static int snd_intel8x0_hw_params(struct snd_pcm_substream *substream,
|
|---|
| 883 | struct snd_pcm_hw_params *hw_params)
|
|---|
| 884 | {
|
|---|
| 885 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 886 | struct ichdev *ichdev = get_ichdev(substream);
|
|---|
| 887 | int dbl = params_rate(hw_params) > 48000;
|
|---|
| 888 | int err;
|
|---|
| 889 |
|
|---|
| 890 | if (ichdev->pcm_open_flag) {
|
|---|
| 891 | snd_ac97_pcm_close(ichdev->pcm);
|
|---|
| 892 | ichdev->pcm_open_flag = 0;
|
|---|
| 893 | ichdev->prepared = 0;
|
|---|
| 894 | }
|
|---|
| 895 | err = snd_ac97_pcm_open(ichdev->pcm, params_rate(hw_params),
|
|---|
| 896 | params_channels(hw_params),
|
|---|
| 897 | ichdev->pcm->r[dbl].slots);
|
|---|
| 898 | if (err >= 0) {
|
|---|
| 899 | ichdev->pcm_open_flag = 1;
|
|---|
| 900 | /* Force SPDIF setting */
|
|---|
| 901 | if (ichdev->ichd == ICHD_PCMOUT && chip->spdif_idx < 0)
|
|---|
| 902 | snd_ac97_set_rate(ichdev->pcm->r[0].codec[0], AC97_SPDIF,
|
|---|
| 903 | params_rate(hw_params));
|
|---|
| 904 | }
|
|---|
| 905 | return err;
|
|---|
| 906 | }
|
|---|
| 907 |
|
|---|
| 908 | static int snd_intel8x0_hw_free(struct snd_pcm_substream *substream)
|
|---|
| 909 | {
|
|---|
| 910 | struct ichdev *ichdev = get_ichdev(substream);
|
|---|
| 911 |
|
|---|
| 912 | if (ichdev->pcm_open_flag) {
|
|---|
| 913 | snd_ac97_pcm_close(ichdev->pcm);
|
|---|
| 914 | ichdev->pcm_open_flag = 0;
|
|---|
| 915 | ichdev->prepared = 0;
|
|---|
| 916 | }
|
|---|
| 917 | return 0;
|
|---|
| 918 | }
|
|---|
| 919 |
|
|---|
| 920 | static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,
|
|---|
| 921 | struct snd_pcm_runtime *runtime)
|
|---|
| 922 | {
|
|---|
| 923 | unsigned int cnt;
|
|---|
| 924 | int dbl = runtime->rate > 48000;
|
|---|
| 925 |
|
|---|
| 926 | spin_lock_irq(&chip->reg_lock);
|
|---|
| 927 | switch (chip->device_type) {
|
|---|
| 928 | case DEVICE_ALI:
|
|---|
| 929 | cnt = igetdword(chip, ICHREG(ALI_SCR));
|
|---|
| 930 | cnt &= ~ICH_ALI_SC_PCM_246_MASK;
|
|---|
| 931 | if (runtime->channels == 4 || dbl)
|
|---|
| 932 | cnt |= ICH_ALI_SC_PCM_4;
|
|---|
| 933 | else if (runtime->channels == 6)
|
|---|
| 934 | cnt |= ICH_ALI_SC_PCM_6;
|
|---|
| 935 | iputdword(chip, ICHREG(ALI_SCR), cnt);
|
|---|
| 936 | break;
|
|---|
| 937 | case DEVICE_SIS:
|
|---|
| 938 | cnt = igetdword(chip, ICHREG(GLOB_CNT));
|
|---|
| 939 | cnt &= ~ICH_SIS_PCM_246_MASK;
|
|---|
| 940 | if (runtime->channels == 4 || dbl)
|
|---|
| 941 | cnt |= ICH_SIS_PCM_4;
|
|---|
| 942 | else if (runtime->channels == 6)
|
|---|
| 943 | cnt |= ICH_SIS_PCM_6;
|
|---|
| 944 | iputdword(chip, ICHREG(GLOB_CNT), cnt);
|
|---|
| 945 | break;
|
|---|
| 946 | default:
|
|---|
| 947 | cnt = igetdword(chip, ICHREG(GLOB_CNT));
|
|---|
| 948 | cnt &= ~(ICH_PCM_246_MASK | ICH_PCM_20BIT);
|
|---|
| 949 | if (runtime->channels == 4 || dbl)
|
|---|
| 950 | cnt |= ICH_PCM_4;
|
|---|
| 951 | else if (runtime->channels == 6)
|
|---|
| 952 | cnt |= ICH_PCM_6;
|
|---|
| 953 | else if (runtime->channels == 8)
|
|---|
| 954 | cnt |= ICH_PCM_8;
|
|---|
| 955 | if (chip->device_type == DEVICE_NFORCE) {
|
|---|
| 956 | /* reset to 2ch once to keep the 6 channel data in alignment,
|
|---|
| 957 | * to start from Front Left always
|
|---|
| 958 | */
|
|---|
| 959 | if (cnt & ICH_PCM_246_MASK) {
|
|---|
| 960 | iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
|
|---|
| 961 | spin_unlock_irq(&chip->reg_lock);
|
|---|
| 962 | msleep(50); /* grrr... */
|
|---|
| 963 | spin_lock_irq(&chip->reg_lock);
|
|---|
| 964 | }
|
|---|
| 965 | } else if (chip->device_type == DEVICE_INTEL_ICH4) {
|
|---|
| 966 | if (runtime->sample_bits > 16)
|
|---|
| 967 | cnt |= ICH_PCM_20BIT;
|
|---|
| 968 | }
|
|---|
| 969 | iputdword(chip, ICHREG(GLOB_CNT), cnt);
|
|---|
| 970 | break;
|
|---|
| 971 | }
|
|---|
| 972 | spin_unlock_irq(&chip->reg_lock);
|
|---|
| 973 | }
|
|---|
| 974 |
|
|---|
| 975 | static int snd_intel8x0_pcm_prepare(struct snd_pcm_substream *substream)
|
|---|
| 976 | {
|
|---|
| 977 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 978 | struct snd_pcm_runtime *runtime = substream->runtime;
|
|---|
| 979 | struct ichdev *ichdev = get_ichdev(substream);
|
|---|
| 980 |
|
|---|
| 981 | ichdev->physbuf = runtime->dma_addr;
|
|---|
| 982 | ichdev->size = snd_pcm_lib_buffer_bytes(substream);
|
|---|
| 983 | ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
|
|---|
| 984 | if (ichdev->ichd == ICHD_PCMOUT) {
|
|---|
| 985 | snd_intel8x0_setup_pcm_out(chip, runtime);
|
|---|
| 986 | if (chip->device_type == DEVICE_INTEL_ICH4)
|
|---|
| 987 | ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
|
|---|
| 988 | }
|
|---|
| 989 | snd_intel8x0_setup_periods(chip, ichdev);
|
|---|
| 990 | ichdev->prepared = 1;
|
|---|
| 991 | return 0;
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *substream)
|
|---|
| 995 | {
|
|---|
| 996 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 997 | struct ichdev *ichdev = get_ichdev(substream);
|
|---|
| 998 | size_t ptr1, ptr;
|
|---|
| 999 | int civ, timeout = 10;
|
|---|
| 1000 | unsigned int position;
|
|---|
| 1001 |
|
|---|
| 1002 | spin_lock(&chip->reg_lock);
|
|---|
| 1003 | do {
|
|---|
| 1004 | civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
|
|---|
| 1005 | ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
|
|---|
| 1006 | position = ichdev->position;
|
|---|
| 1007 | if (ptr1 == 0) {
|
|---|
| 1008 | udelay(10);
|
|---|
| 1009 | continue;
|
|---|
| 1010 | }
|
|---|
| 1011 | if (civ != igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV))
|
|---|
| 1012 | continue;
|
|---|
| 1013 |
|
|---|
| 1014 | /* IO read operation is very expensive inside virtual machine
|
|---|
| 1015 | * as it is emulated. The probability that subsequent PICB read
|
|---|
| 1016 | * will return different result is high enough to loop till
|
|---|
| 1017 | * timeout here.
|
|---|
| 1018 | * Same CIV is strict enough condition to be sure that PICB
|
|---|
| 1019 | * is valid inside VM on emulated card. */
|
|---|
| 1020 | if (chip->inside_vm)
|
|---|
| 1021 | break;
|
|---|
| 1022 | if (ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
|
|---|
| 1023 | break;
|
|---|
| 1024 | } while (timeout--);
|
|---|
| 1025 | ptr = ichdev->last_pos;
|
|---|
| 1026 | if (ptr1 != 0) {
|
|---|
| 1027 | ptr1 <<= ichdev->pos_shift;
|
|---|
| 1028 | ptr = ichdev->fragsize1 - ptr1;
|
|---|
| 1029 | ptr += position;
|
|---|
| 1030 | if (ptr < ichdev->last_pos) {
|
|---|
| 1031 | unsigned int pos_base, last_base;
|
|---|
| 1032 | pos_base = position / ichdev->fragsize1;
|
|---|
| 1033 | last_base = ichdev->last_pos / ichdev->fragsize1;
|
|---|
| 1034 | /* another sanity check; ptr1 can go back to full
|
|---|
| 1035 | * before the base position is updated
|
|---|
| 1036 | */
|
|---|
| 1037 | if (pos_base == last_base)
|
|---|
| 1038 | ptr = ichdev->last_pos;
|
|---|
| 1039 | }
|
|---|
| 1040 | }
|
|---|
| 1041 | ichdev->last_pos = ptr;
|
|---|
| 1042 | spin_unlock(&chip->reg_lock);
|
|---|
| 1043 | if (ptr >= ichdev->size)
|
|---|
| 1044 | return 0;
|
|---|
| 1045 | return bytes_to_frames(substream->runtime, ptr);
|
|---|
| 1046 | }
|
|---|
| 1047 |
|
|---|
| 1048 | static const struct snd_pcm_hardware snd_intel8x0_stream =
|
|---|
| 1049 | {
|
|---|
| 1050 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
|
|---|
| 1051 | SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
|---|
| 1052 | SNDRV_PCM_INFO_MMAP_VALID |
|
|---|
| 1053 | SNDRV_PCM_INFO_PAUSE |
|
|---|
| 1054 | SNDRV_PCM_INFO_RESUME),
|
|---|
| 1055 | .formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|---|
| 1056 | .rates = SNDRV_PCM_RATE_48000,
|
|---|
| 1057 | .rate_min = 48000,
|
|---|
| 1058 | .rate_max = 48000,
|
|---|
| 1059 | .channels_min = 2,
|
|---|
| 1060 | .channels_max = 2,
|
|---|
| 1061 | .buffer_bytes_max = 128 * 1024,
|
|---|
| 1062 | .period_bytes_min = 32,
|
|---|
| 1063 | .period_bytes_max = 128 * 1024,
|
|---|
| 1064 | .periods_min = 1,
|
|---|
| 1065 | .periods_max = 1024,
|
|---|
| 1066 | .fifo_size = 0,
|
|---|
| 1067 | };
|
|---|
| 1068 |
|
|---|
| 1069 | static const unsigned int channels4[] = {
|
|---|
| 1070 | 2, 4,
|
|---|
| 1071 | };
|
|---|
| 1072 |
|
|---|
| 1073 | static const struct snd_pcm_hw_constraint_list hw_constraints_channels4 = {
|
|---|
| 1074 | .count = ARRAY_SIZE(channels4),
|
|---|
| 1075 | .list = channels4,
|
|---|
| 1076 | .mask = 0,
|
|---|
| 1077 | };
|
|---|
| 1078 |
|
|---|
| 1079 | static const unsigned int channels6[] = {
|
|---|
| 1080 | 2, 4, 6,
|
|---|
| 1081 | };
|
|---|
| 1082 |
|
|---|
| 1083 | static const struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
|
|---|
| 1084 | .count = ARRAY_SIZE(channels6),
|
|---|
| 1085 | .list = channels6,
|
|---|
| 1086 | .mask = 0,
|
|---|
| 1087 | };
|
|---|
| 1088 |
|
|---|
| 1089 | static const unsigned int channels8[] = {
|
|---|
| 1090 | 2, 4, 6, 8,
|
|---|
| 1091 | };
|
|---|
| 1092 |
|
|---|
| 1093 | static const struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
|
|---|
| 1094 | .count = ARRAY_SIZE(channels8),
|
|---|
| 1095 | .list = channels8,
|
|---|
| 1096 | .mask = 0,
|
|---|
| 1097 | };
|
|---|
| 1098 |
|
|---|
| 1099 | static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
|
|---|
| 1100 | {
|
|---|
| 1101 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1102 | struct snd_pcm_runtime *runtime = substream->runtime;
|
|---|
| 1103 | int err;
|
|---|
| 1104 |
|
|---|
| 1105 | ichdev->substream = substream;
|
|---|
| 1106 | runtime->hw = snd_intel8x0_stream;
|
|---|
| 1107 | runtime->hw.rates = ichdev->pcm->rates;
|
|---|
| 1108 | snd_pcm_limit_hw_rates(runtime);
|
|---|
| 1109 | if (chip->device_type == DEVICE_SIS) {
|
|---|
| 1110 | runtime->hw.buffer_bytes_max = 64*1024;
|
|---|
| 1111 | runtime->hw.period_bytes_max = 64*1024;
|
|---|
| 1112 | }
|
|---|
| 1113 | err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
|
|---|
| 1114 | if (err < 0)
|
|---|
| 1115 | return err;
|
|---|
| 1116 | runtime->private_data = ichdev;
|
|---|
| 1117 | return 0;
|
|---|
| 1118 | }
|
|---|
| 1119 |
|
|---|
| 1120 | static int snd_intel8x0_playback_open(struct snd_pcm_substream *substream)
|
|---|
| 1121 | {
|
|---|
| 1122 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1123 | struct snd_pcm_runtime *runtime = substream->runtime;
|
|---|
| 1124 | int err;
|
|---|
| 1125 |
|
|---|
| 1126 | err = snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMOUT]);
|
|---|
| 1127 | if (err < 0)
|
|---|
| 1128 | return err;
|
|---|
| 1129 |
|
|---|
| 1130 | if (chip->multi8) {
|
|---|
| 1131 | runtime->hw.channels_max = 8;
|
|---|
| 1132 | snd_pcm_hw_constraint_list(runtime, 0,
|
|---|
| 1133 | SNDRV_PCM_HW_PARAM_CHANNELS,
|
|---|
| 1134 | &hw_constraints_channels8);
|
|---|
| 1135 | } else if (chip->multi6) {
|
|---|
| 1136 | runtime->hw.channels_max = 6;
|
|---|
| 1137 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
|
|---|
| 1138 | &hw_constraints_channels6);
|
|---|
| 1139 | } else if (chip->multi4) {
|
|---|
| 1140 | runtime->hw.channels_max = 4;
|
|---|
| 1141 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
|
|---|
| 1142 | &hw_constraints_channels4);
|
|---|
| 1143 | }
|
|---|
| 1144 | if (chip->dra) {
|
|---|
| 1145 | snd_ac97_pcm_double_rate_rules(runtime);
|
|---|
| 1146 | }
|
|---|
| 1147 | if (chip->smp20bit) {
|
|---|
| 1148 | runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE;
|
|---|
| 1149 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
|
|---|
| 1150 | }
|
|---|
| 1151 | return 0;
|
|---|
| 1152 | }
|
|---|
| 1153 |
|
|---|
| 1154 | static int snd_intel8x0_playback_close(struct snd_pcm_substream *substream)
|
|---|
| 1155 | {
|
|---|
| 1156 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1157 |
|
|---|
| 1158 | chip->ichd[ICHD_PCMOUT].substream = NULL;
|
|---|
| 1159 | return 0;
|
|---|
| 1160 | }
|
|---|
| 1161 |
|
|---|
| 1162 | static int snd_intel8x0_capture_open(struct snd_pcm_substream *substream)
|
|---|
| 1163 | {
|
|---|
| 1164 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1165 |
|
|---|
| 1166 | return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMIN]);
|
|---|
| 1167 | }
|
|---|
| 1168 |
|
|---|
| 1169 | static int snd_intel8x0_capture_close(struct snd_pcm_substream *substream)
|
|---|
| 1170 | {
|
|---|
| 1171 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1172 |
|
|---|
| 1173 | chip->ichd[ICHD_PCMIN].substream = NULL;
|
|---|
| 1174 | return 0;
|
|---|
| 1175 | }
|
|---|
| 1176 |
|
|---|
| 1177 | static int snd_intel8x0_mic_open(struct snd_pcm_substream *substream)
|
|---|
| 1178 | {
|
|---|
| 1179 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1180 |
|
|---|
| 1181 | return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC]);
|
|---|
| 1182 | }
|
|---|
| 1183 |
|
|---|
| 1184 | static int snd_intel8x0_mic_close(struct snd_pcm_substream *substream)
|
|---|
| 1185 | {
|
|---|
| 1186 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1187 |
|
|---|
| 1188 | chip->ichd[ICHD_MIC].substream = NULL;
|
|---|
| 1189 | return 0;
|
|---|
| 1190 | }
|
|---|
| 1191 |
|
|---|
| 1192 | static int snd_intel8x0_mic2_open(struct snd_pcm_substream *substream)
|
|---|
| 1193 | {
|
|---|
| 1194 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1195 |
|
|---|
| 1196 | return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC2]);
|
|---|
| 1197 | }
|
|---|
| 1198 |
|
|---|
| 1199 | static int snd_intel8x0_mic2_close(struct snd_pcm_substream *substream)
|
|---|
| 1200 | {
|
|---|
| 1201 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1202 |
|
|---|
| 1203 | chip->ichd[ICHD_MIC2].substream = NULL;
|
|---|
| 1204 | return 0;
|
|---|
| 1205 | }
|
|---|
| 1206 |
|
|---|
| 1207 | static int snd_intel8x0_capture2_open(struct snd_pcm_substream *substream)
|
|---|
| 1208 | {
|
|---|
| 1209 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1210 |
|
|---|
| 1211 | return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCM2IN]);
|
|---|
| 1212 | }
|
|---|
| 1213 |
|
|---|
| 1214 | static int snd_intel8x0_capture2_close(struct snd_pcm_substream *substream)
|
|---|
| 1215 | {
|
|---|
| 1216 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1217 |
|
|---|
| 1218 | chip->ichd[ICHD_PCM2IN].substream = NULL;
|
|---|
| 1219 | return 0;
|
|---|
| 1220 | }
|
|---|
| 1221 |
|
|---|
| 1222 | static int snd_intel8x0_spdif_open(struct snd_pcm_substream *substream)
|
|---|
| 1223 | {
|
|---|
| 1224 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1225 | int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
|
|---|
| 1226 |
|
|---|
| 1227 | return snd_intel8x0_pcm_open(substream, &chip->ichd[idx]);
|
|---|
| 1228 | }
|
|---|
| 1229 |
|
|---|
| 1230 | static int snd_intel8x0_spdif_close(struct snd_pcm_substream *substream)
|
|---|
| 1231 | {
|
|---|
| 1232 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1233 | int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
|
|---|
| 1234 |
|
|---|
| 1235 | chip->ichd[idx].substream = NULL;
|
|---|
| 1236 | return 0;
|
|---|
| 1237 | }
|
|---|
| 1238 |
|
|---|
| 1239 | static int snd_intel8x0_ali_ac97spdifout_open(struct snd_pcm_substream *substream)
|
|---|
| 1240 | {
|
|---|
| 1241 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1242 | unsigned int val;
|
|---|
| 1243 |
|
|---|
| 1244 | spin_lock_irq(&chip->reg_lock);
|
|---|
| 1245 | val = igetdword(chip, ICHREG(ALI_INTERFACECR));
|
|---|
| 1246 | val |= ICH_ALI_IF_AC97SP;
|
|---|
| 1247 | iputdword(chip, ICHREG(ALI_INTERFACECR), val);
|
|---|
| 1248 | /* also needs to set ALI_SC_CODEC_SPDF correctly */
|
|---|
| 1249 | spin_unlock_irq(&chip->reg_lock);
|
|---|
| 1250 |
|
|---|
| 1251 | return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_AC97SPDIFOUT]);
|
|---|
| 1252 | }
|
|---|
| 1253 |
|
|---|
| 1254 | static int snd_intel8x0_ali_ac97spdifout_close(struct snd_pcm_substream *substream)
|
|---|
| 1255 | {
|
|---|
| 1256 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1257 | unsigned int val;
|
|---|
| 1258 |
|
|---|
| 1259 | chip->ichd[ALID_AC97SPDIFOUT].substream = NULL;
|
|---|
| 1260 | spin_lock_irq(&chip->reg_lock);
|
|---|
| 1261 | val = igetdword(chip, ICHREG(ALI_INTERFACECR));
|
|---|
| 1262 | val &= ~ICH_ALI_IF_AC97SP;
|
|---|
| 1263 | iputdword(chip, ICHREG(ALI_INTERFACECR), val);
|
|---|
| 1264 | spin_unlock_irq(&chip->reg_lock);
|
|---|
| 1265 |
|
|---|
| 1266 | return 0;
|
|---|
| 1267 | }
|
|---|
| 1268 |
|
|---|
| 1269 | #if 0 // NYI
|
|---|
| 1270 | static int snd_intel8x0_ali_spdifin_open(struct snd_pcm_substream *substream)
|
|---|
| 1271 | {
|
|---|
| 1272 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1273 |
|
|---|
| 1274 | return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFIN]);
|
|---|
| 1275 | }
|
|---|
| 1276 |
|
|---|
| 1277 | static int snd_intel8x0_ali_spdifin_close(struct snd_pcm_substream *substream)
|
|---|
| 1278 | {
|
|---|
| 1279 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1280 |
|
|---|
| 1281 | chip->ichd[ALID_SPDIFIN].substream = NULL;
|
|---|
| 1282 | return 0;
|
|---|
| 1283 | }
|
|---|
| 1284 |
|
|---|
| 1285 | static int snd_intel8x0_ali_spdifout_open(struct snd_pcm_substream *substream)
|
|---|
| 1286 | {
|
|---|
| 1287 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1288 |
|
|---|
| 1289 | return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFOUT]);
|
|---|
| 1290 | }
|
|---|
| 1291 |
|
|---|
| 1292 | static int snd_intel8x0_ali_spdifout_close(struct snd_pcm_substream *substream)
|
|---|
| 1293 | {
|
|---|
| 1294 | struct intel8x0 *chip = snd_pcm_substream_chip(substream);
|
|---|
| 1295 |
|
|---|
| 1296 | chip->ichd[ALID_SPDIFOUT].substream = NULL;
|
|---|
| 1297 | return 0;
|
|---|
| 1298 | }
|
|---|
| 1299 | #endif
|
|---|
| 1300 |
|
|---|
| 1301 | static const struct snd_pcm_ops snd_intel8x0_playback_ops = {
|
|---|
| 1302 | .open = snd_intel8x0_playback_open,
|
|---|
| 1303 | .close = snd_intel8x0_playback_close,
|
|---|
| 1304 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1305 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1306 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1307 | .trigger = snd_intel8x0_pcm_trigger,
|
|---|
| 1308 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1309 | };
|
|---|
| 1310 |
|
|---|
| 1311 | static const struct snd_pcm_ops snd_intel8x0_capture_ops = {
|
|---|
| 1312 | .open = snd_intel8x0_capture_open,
|
|---|
| 1313 | .close = snd_intel8x0_capture_close,
|
|---|
| 1314 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1315 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1316 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1317 | .trigger = snd_intel8x0_pcm_trigger,
|
|---|
| 1318 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1319 | };
|
|---|
| 1320 |
|
|---|
| 1321 | static const struct snd_pcm_ops snd_intel8x0_capture_mic_ops = {
|
|---|
| 1322 | .open = snd_intel8x0_mic_open,
|
|---|
| 1323 | .close = snd_intel8x0_mic_close,
|
|---|
| 1324 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1325 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1326 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1327 | .trigger = snd_intel8x0_pcm_trigger,
|
|---|
| 1328 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1329 | };
|
|---|
| 1330 |
|
|---|
| 1331 | static const struct snd_pcm_ops snd_intel8x0_capture_mic2_ops = {
|
|---|
| 1332 | .open = snd_intel8x0_mic2_open,
|
|---|
| 1333 | .close = snd_intel8x0_mic2_close,
|
|---|
| 1334 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1335 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1336 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1337 | .trigger = snd_intel8x0_pcm_trigger,
|
|---|
| 1338 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1339 | };
|
|---|
| 1340 |
|
|---|
| 1341 | static const struct snd_pcm_ops snd_intel8x0_capture2_ops = {
|
|---|
| 1342 | .open = snd_intel8x0_capture2_open,
|
|---|
| 1343 | .close = snd_intel8x0_capture2_close,
|
|---|
| 1344 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1345 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1346 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1347 | .trigger = snd_intel8x0_pcm_trigger,
|
|---|
| 1348 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1349 | };
|
|---|
| 1350 |
|
|---|
| 1351 | static const struct snd_pcm_ops snd_intel8x0_spdif_ops = {
|
|---|
| 1352 | .open = snd_intel8x0_spdif_open,
|
|---|
| 1353 | .close = snd_intel8x0_spdif_close,
|
|---|
| 1354 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1355 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1356 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1357 | .trigger = snd_intel8x0_pcm_trigger,
|
|---|
| 1358 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1359 | };
|
|---|
| 1360 |
|
|---|
| 1361 | static const struct snd_pcm_ops snd_intel8x0_ali_playback_ops = {
|
|---|
| 1362 | .open = snd_intel8x0_playback_open,
|
|---|
| 1363 | .close = snd_intel8x0_playback_close,
|
|---|
| 1364 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1365 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1366 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1367 | .trigger = snd_intel8x0_ali_trigger,
|
|---|
| 1368 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1369 | };
|
|---|
| 1370 |
|
|---|
| 1371 | static const struct snd_pcm_ops snd_intel8x0_ali_capture_ops = {
|
|---|
| 1372 | .open = snd_intel8x0_capture_open,
|
|---|
| 1373 | .close = snd_intel8x0_capture_close,
|
|---|
| 1374 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1375 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1376 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1377 | .trigger = snd_intel8x0_ali_trigger,
|
|---|
| 1378 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1379 | };
|
|---|
| 1380 |
|
|---|
| 1381 | static const struct snd_pcm_ops snd_intel8x0_ali_capture_mic_ops = {
|
|---|
| 1382 | .open = snd_intel8x0_mic_open,
|
|---|
| 1383 | .close = snd_intel8x0_mic_close,
|
|---|
| 1384 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1385 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1386 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1387 | .trigger = snd_intel8x0_ali_trigger,
|
|---|
| 1388 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1389 | };
|
|---|
| 1390 |
|
|---|
| 1391 | static const struct snd_pcm_ops snd_intel8x0_ali_ac97spdifout_ops = {
|
|---|
| 1392 | .open = snd_intel8x0_ali_ac97spdifout_open,
|
|---|
| 1393 | .close = snd_intel8x0_ali_ac97spdifout_close,
|
|---|
| 1394 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1395 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1396 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1397 | .trigger = snd_intel8x0_ali_trigger,
|
|---|
| 1398 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1399 | };
|
|---|
| 1400 |
|
|---|
| 1401 | #if 0 // NYI
|
|---|
| 1402 | static struct snd_pcm_ops snd_intel8x0_ali_spdifin_ops = {
|
|---|
| 1403 | .open = snd_intel8x0_ali_spdifin_open,
|
|---|
| 1404 | .close = snd_intel8x0_ali_spdifin_close,
|
|---|
| 1405 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1406 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1407 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1408 | .trigger = snd_intel8x0_pcm_trigger,
|
|---|
| 1409 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1410 | };
|
|---|
| 1411 |
|
|---|
| 1412 | static struct snd_pcm_ops snd_intel8x0_ali_spdifout_ops = {
|
|---|
| 1413 | .open = snd_intel8x0_ali_spdifout_open,
|
|---|
| 1414 | .close = snd_intel8x0_ali_spdifout_close,
|
|---|
| 1415 | .hw_params = snd_intel8x0_hw_params,
|
|---|
| 1416 | .hw_free = snd_intel8x0_hw_free,
|
|---|
| 1417 | .prepare = snd_intel8x0_pcm_prepare,
|
|---|
| 1418 | .trigger = snd_intel8x0_pcm_trigger,
|
|---|
| 1419 | .pointer = snd_intel8x0_pcm_pointer,
|
|---|
| 1420 | };
|
|---|
| 1421 | #endif // NYI
|
|---|
| 1422 |
|
|---|
| 1423 | struct ich_pcm_table {
|
|---|
| 1424 | char *suffix;
|
|---|
| 1425 | const struct snd_pcm_ops *playback_ops;
|
|---|
| 1426 | const struct snd_pcm_ops *capture_ops;
|
|---|
| 1427 | size_t prealloc_size;
|
|---|
| 1428 | size_t prealloc_max_size;
|
|---|
| 1429 | int ac97_idx;
|
|---|
| 1430 | };
|
|---|
| 1431 |
|
|---|
| 1432 | #define intel8x0_dma_type(chip) \
|
|---|
| 1433 | ((chip)->fix_nocache ? SNDRV_DMA_TYPE_DEV_UC : SNDRV_DMA_TYPE_DEV)
|
|---|
| 1434 |
|
|---|
| 1435 | static int snd_intel8x0_pcm1(struct intel8x0 *chip, int device,
|
|---|
| 1436 | const struct ich_pcm_table *rec)
|
|---|
| 1437 | {
|
|---|
| 1438 | struct snd_pcm *pcm;
|
|---|
| 1439 | int err;
|
|---|
| 1440 | char name[32];
|
|---|
| 1441 |
|
|---|
| 1442 | if (rec->suffix)
|
|---|
| 1443 | sprintf(name, "Intel ICH - %s", rec->suffix);
|
|---|
| 1444 | else
|
|---|
| 1445 | strcpy(name, "Intel ICH");
|
|---|
| 1446 | err = snd_pcm_new(chip->card, name, device,
|
|---|
| 1447 | rec->playback_ops ? 1 : 0,
|
|---|
| 1448 | rec->capture_ops ? 1 : 0, &pcm);
|
|---|
| 1449 | if (err < 0)
|
|---|
| 1450 | return err;
|
|---|
| 1451 |
|
|---|
| 1452 | if (rec->playback_ops)
|
|---|
| 1453 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
|
|---|
| 1454 | if (rec->capture_ops)
|
|---|
| 1455 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
|
|---|
| 1456 |
|
|---|
| 1457 | pcm->private_data = chip;
|
|---|
| 1458 | pcm->info_flags = 0;
|
|---|
| 1459 | if (rec->suffix)
|
|---|
| 1460 | sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
|
|---|
| 1461 | else
|
|---|
| 1462 | strcpy(pcm->name, chip->card->shortname);
|
|---|
| 1463 | chip->pcm[device] = pcm;
|
|---|
| 1464 |
|
|---|
| 1465 | snd_pcm_set_managed_buffer_all(pcm, intel8x0_dma_type(chip),
|
|---|
| 1466 | &chip->pci->dev,
|
|---|
| 1467 | rec->prealloc_size, rec->prealloc_max_size);
|
|---|
| 1468 |
|
|---|
| 1469 | if (rec->playback_ops &&
|
|---|
| 1470 | rec->playback_ops->open == snd_intel8x0_playback_open) {
|
|---|
| 1471 | struct snd_pcm_chmap *chmap;
|
|---|
| 1472 | int chs = 2;
|
|---|
| 1473 | if (chip->multi8)
|
|---|
| 1474 | chs = 8;
|
|---|
| 1475 | else if (chip->multi6)
|
|---|
| 1476 | chs = 6;
|
|---|
| 1477 | else if (chip->multi4)
|
|---|
| 1478 | chs = 4;
|
|---|
| 1479 | err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
|
|---|
| 1480 | snd_pcm_alt_chmaps, chs, 0,
|
|---|
| 1481 | &chmap);
|
|---|
| 1482 | if (err < 0)
|
|---|
| 1483 | return err;
|
|---|
| 1484 | chmap->channel_mask = SND_PCM_CHMAP_MASK_2468;
|
|---|
| 1485 | chip->ac97[0]->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
|
|---|
| 1486 | }
|
|---|
| 1487 |
|
|---|
| 1488 | return 0;
|
|---|
| 1489 | }
|
|---|
| 1490 |
|
|---|
| 1491 | static const struct ich_pcm_table intel_pcms[] = {
|
|---|
| 1492 | {
|
|---|
| 1493 | .playback_ops = &snd_intel8x0_playback_ops,
|
|---|
| 1494 | .capture_ops = &snd_intel8x0_capture_ops,
|
|---|
| 1495 | .prealloc_size = 64 * 1024,
|
|---|
| 1496 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1497 | },
|
|---|
| 1498 | {
|
|---|
| 1499 | .suffix = "MIC ADC",
|
|---|
| 1500 | .capture_ops = &snd_intel8x0_capture_mic_ops,
|
|---|
| 1501 | .prealloc_size = 0,
|
|---|
| 1502 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1503 | .ac97_idx = ICHD_MIC,
|
|---|
| 1504 | },
|
|---|
| 1505 | {
|
|---|
| 1506 | .suffix = "MIC2 ADC",
|
|---|
| 1507 | .capture_ops = &snd_intel8x0_capture_mic2_ops,
|
|---|
| 1508 | .prealloc_size = 0,
|
|---|
| 1509 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1510 | .ac97_idx = ICHD_MIC2,
|
|---|
| 1511 | },
|
|---|
| 1512 | {
|
|---|
| 1513 | .suffix = "ADC2",
|
|---|
| 1514 | .capture_ops = &snd_intel8x0_capture2_ops,
|
|---|
| 1515 | .prealloc_size = 0,
|
|---|
| 1516 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1517 | .ac97_idx = ICHD_PCM2IN,
|
|---|
| 1518 | },
|
|---|
| 1519 | {
|
|---|
| 1520 | .suffix = "IEC958",
|
|---|
| 1521 | .playback_ops = &snd_intel8x0_spdif_ops,
|
|---|
| 1522 | .prealloc_size = 64 * 1024,
|
|---|
| 1523 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1524 | .ac97_idx = ICHD_SPBAR,
|
|---|
| 1525 | },
|
|---|
| 1526 | };
|
|---|
| 1527 |
|
|---|
| 1528 | static const struct ich_pcm_table nforce_pcms[] = {
|
|---|
| 1529 | {
|
|---|
| 1530 | .playback_ops = &snd_intel8x0_playback_ops,
|
|---|
| 1531 | .capture_ops = &snd_intel8x0_capture_ops,
|
|---|
| 1532 | .prealloc_size = 64 * 1024,
|
|---|
| 1533 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1534 | },
|
|---|
| 1535 | {
|
|---|
| 1536 | .suffix = "MIC ADC",
|
|---|
| 1537 | .capture_ops = &snd_intel8x0_capture_mic_ops,
|
|---|
| 1538 | .prealloc_size = 0,
|
|---|
| 1539 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1540 | .ac97_idx = NVD_MIC,
|
|---|
| 1541 | },
|
|---|
| 1542 | {
|
|---|
| 1543 | .suffix = "IEC958",
|
|---|
| 1544 | .playback_ops = &snd_intel8x0_spdif_ops,
|
|---|
| 1545 | .prealloc_size = 64 * 1024,
|
|---|
| 1546 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1547 | .ac97_idx = NVD_SPBAR,
|
|---|
| 1548 | },
|
|---|
| 1549 | };
|
|---|
| 1550 |
|
|---|
| 1551 | static const struct ich_pcm_table ali_pcms[] = {
|
|---|
| 1552 | {
|
|---|
| 1553 | .playback_ops = &snd_intel8x0_ali_playback_ops,
|
|---|
| 1554 | .capture_ops = &snd_intel8x0_ali_capture_ops,
|
|---|
| 1555 | .prealloc_size = 64 * 1024,
|
|---|
| 1556 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1557 | },
|
|---|
| 1558 | {
|
|---|
| 1559 | .suffix = "MIC ADC",
|
|---|
| 1560 | .capture_ops = &snd_intel8x0_ali_capture_mic_ops,
|
|---|
| 1561 | .prealloc_size = 0,
|
|---|
| 1562 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1563 | .ac97_idx = ALID_MIC,
|
|---|
| 1564 | },
|
|---|
| 1565 | {
|
|---|
| 1566 | .suffix = "IEC958",
|
|---|
| 1567 | .playback_ops = &snd_intel8x0_ali_ac97spdifout_ops,
|
|---|
| 1568 | /* .capture_ops = &snd_intel8x0_ali_spdifin_ops, */
|
|---|
| 1569 | .prealloc_size = 64 * 1024,
|
|---|
| 1570 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1571 | .ac97_idx = ALID_AC97SPDIFOUT,
|
|---|
| 1572 | },
|
|---|
| 1573 | #if 0 // NYI
|
|---|
| 1574 | {
|
|---|
| 1575 | .suffix = "HW IEC958",
|
|---|
| 1576 | .playback_ops = &snd_intel8x0_ali_spdifout_ops,
|
|---|
| 1577 | .prealloc_size = 64 * 1024,
|
|---|
| 1578 | .prealloc_max_size = 128 * 1024,
|
|---|
| 1579 | },
|
|---|
| 1580 | #endif
|
|---|
| 1581 | };
|
|---|
| 1582 |
|
|---|
| 1583 | static int snd_intel8x0_pcm(struct intel8x0 *chip)
|
|---|
| 1584 | {
|
|---|
| 1585 | int i, tblsize, device, err;
|
|---|
| 1586 | const struct ich_pcm_table *tbl, *rec;
|
|---|
| 1587 |
|
|---|
| 1588 | switch (chip->device_type) {
|
|---|
| 1589 | case DEVICE_INTEL_ICH4:
|
|---|
| 1590 | tbl = intel_pcms;
|
|---|
| 1591 | tblsize = ARRAY_SIZE(intel_pcms);
|
|---|
| 1592 | if (spdif_aclink)
|
|---|
| 1593 | tblsize--;
|
|---|
| 1594 | break;
|
|---|
| 1595 | case DEVICE_NFORCE:
|
|---|
| 1596 | tbl = nforce_pcms;
|
|---|
| 1597 | tblsize = ARRAY_SIZE(nforce_pcms);
|
|---|
| 1598 | if (spdif_aclink)
|
|---|
| 1599 | tblsize--;
|
|---|
| 1600 | break;
|
|---|
| 1601 | case DEVICE_ALI:
|
|---|
| 1602 | tbl = ali_pcms;
|
|---|
| 1603 | tblsize = ARRAY_SIZE(ali_pcms);
|
|---|
| 1604 | break;
|
|---|
| 1605 | default:
|
|---|
| 1606 | tbl = intel_pcms;
|
|---|
| 1607 | tblsize = 2;
|
|---|
| 1608 | break;
|
|---|
| 1609 | }
|
|---|
| 1610 |
|
|---|
| 1611 | device = 0;
|
|---|
| 1612 | for (i = 0; i < tblsize; i++) {
|
|---|
| 1613 | rec = tbl + i;
|
|---|
| 1614 | if (i > 0 && rec->ac97_idx) {
|
|---|
| 1615 | /* activate PCM only when associated AC'97 codec */
|
|---|
| 1616 | if (! chip->ichd[rec->ac97_idx].pcm)
|
|---|
| 1617 | continue;
|
|---|
| 1618 | }
|
|---|
| 1619 | err = snd_intel8x0_pcm1(chip, device, rec);
|
|---|
| 1620 | if (err < 0)
|
|---|
| 1621 | return err;
|
|---|
| 1622 | device++;
|
|---|
| 1623 | }
|
|---|
| 1624 |
|
|---|
| 1625 | chip->pcm_devs = device;
|
|---|
| 1626 | return 0;
|
|---|
| 1627 | }
|
|---|
| 1628 |
|
|---|
| 1629 |
|
|---|
| 1630 | /*
|
|---|
| 1631 | * Mixer part
|
|---|
| 1632 | */
|
|---|
| 1633 |
|
|---|
| 1634 | static void snd_intel8x0_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
|
|---|
| 1635 | {
|
|---|
| 1636 | struct intel8x0 *chip = bus->private_data;
|
|---|
| 1637 | chip->ac97_bus = NULL;
|
|---|
| 1638 | }
|
|---|
| 1639 |
|
|---|
| 1640 | static void snd_intel8x0_mixer_free_ac97(struct snd_ac97 *ac97)
|
|---|
| 1641 | {
|
|---|
| 1642 | struct intel8x0 *chip = ac97->private_data;
|
|---|
| 1643 | chip->ac97[ac97->num] = NULL;
|
|---|
| 1644 | }
|
|---|
| 1645 |
|
|---|
| 1646 | static const struct ac97_pcm ac97_pcm_defs[] = {
|
|---|
| 1647 | /* front PCM */
|
|---|
| 1648 | {
|
|---|
| 1649 | .exclusive = 1,
|
|---|
| 1650 | .r = { {
|
|---|
| 1651 | .slots = (1 << AC97_SLOT_PCM_LEFT) |
|
|---|
| 1652 | (1 << AC97_SLOT_PCM_RIGHT) |
|
|---|
| 1653 | (1 << AC97_SLOT_PCM_CENTER) |
|
|---|
| 1654 | (1 << AC97_SLOT_PCM_SLEFT) |
|
|---|
| 1655 | (1 << AC97_SLOT_PCM_SRIGHT) |
|
|---|
| 1656 | (1 << AC97_SLOT_LFE)
|
|---|
| 1657 | },
|
|---|
| 1658 | {
|
|---|
| 1659 | .slots = (1 << AC97_SLOT_PCM_LEFT) |
|
|---|
| 1660 | (1 << AC97_SLOT_PCM_RIGHT) |
|
|---|
| 1661 | (1 << AC97_SLOT_PCM_LEFT_0) |
|
|---|
| 1662 | (1 << AC97_SLOT_PCM_RIGHT_0)
|
|---|
| 1663 | }
|
|---|
| 1664 | }
|
|---|
| 1665 | },
|
|---|
| 1666 | /* PCM IN #1 */
|
|---|
| 1667 | {
|
|---|
| 1668 | .stream = 1,
|
|---|
| 1669 | .exclusive = 1,
|
|---|
| 1670 | .r = { {
|
|---|
| 1671 | .slots = (1 << AC97_SLOT_PCM_LEFT) |
|
|---|
| 1672 | (1 << AC97_SLOT_PCM_RIGHT)
|
|---|
| 1673 | }
|
|---|
| 1674 | }
|
|---|
| 1675 | },
|
|---|
| 1676 | /* MIC IN #1 */
|
|---|
| 1677 | {
|
|---|
| 1678 | .stream = 1,
|
|---|
| 1679 | .exclusive = 1,
|
|---|
| 1680 | .r = { {
|
|---|
| 1681 | .slots = (1 << AC97_SLOT_MIC)
|
|---|
| 1682 | }
|
|---|
| 1683 | }
|
|---|
| 1684 | },
|
|---|
| 1685 | /* S/PDIF PCM */
|
|---|
| 1686 | {
|
|---|
| 1687 | .exclusive = 1,
|
|---|
| 1688 | .spdif = 1,
|
|---|
| 1689 | .r = { {
|
|---|
| 1690 | .slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
|
|---|
| 1691 | (1 << AC97_SLOT_SPDIF_RIGHT2)
|
|---|
| 1692 | }
|
|---|
| 1693 | }
|
|---|
| 1694 | },
|
|---|
| 1695 | /* PCM IN #2 */
|
|---|
| 1696 | {
|
|---|
| 1697 | .stream = 1,
|
|---|
| 1698 | .exclusive = 1,
|
|---|
| 1699 | .r = { {
|
|---|
| 1700 | .slots = (1 << AC97_SLOT_PCM_LEFT) |
|
|---|
| 1701 | (1 << AC97_SLOT_PCM_RIGHT)
|
|---|
| 1702 | }
|
|---|
| 1703 | }
|
|---|
| 1704 | },
|
|---|
| 1705 | /* MIC IN #2 */
|
|---|
| 1706 | {
|
|---|
| 1707 | .stream = 1,
|
|---|
| 1708 | .exclusive = 1,
|
|---|
| 1709 | .r = { {
|
|---|
| 1710 | .slots = (1 << AC97_SLOT_MIC)
|
|---|
| 1711 | }
|
|---|
| 1712 | }
|
|---|
| 1713 | },
|
|---|
| 1714 | };
|
|---|
| 1715 |
|
|---|
| 1716 | static const struct ac97_quirk ac97_quirks[] = {
|
|---|
| 1717 | {
|
|---|
| 1718 | .subvendor = 0x0e11,
|
|---|
| 1719 | .subdevice = 0x000e,
|
|---|
| 1720 | .name = "Compaq Deskpro EN", /* AD1885 */
|
|---|
| 1721 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1722 | },
|
|---|
| 1723 | {
|
|---|
| 1724 | .subvendor = 0x0e11,
|
|---|
| 1725 | .subdevice = 0x008a,
|
|---|
| 1726 | .name = "Compaq Evo W4000", /* AD1885 */
|
|---|
| 1727 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1728 | },
|
|---|
| 1729 | {
|
|---|
| 1730 | .subvendor = 0x0e11,
|
|---|
| 1731 | .subdevice = 0x00b8,
|
|---|
| 1732 | .name = "Compaq Evo D510C",
|
|---|
| 1733 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1734 | },
|
|---|
| 1735 | {
|
|---|
| 1736 | .subvendor = 0x0e11,
|
|---|
| 1737 | .subdevice = 0x0860,
|
|---|
| 1738 | .name = "HP/Compaq nx7010",
|
|---|
| 1739 | .type = AC97_TUNE_MUTE_LED
|
|---|
| 1740 | },
|
|---|
| 1741 | {
|
|---|
| 1742 | .subvendor = 0x1014,
|
|---|
| 1743 | .subdevice = 0x0534,
|
|---|
| 1744 | .name = "ThinkPad X31",
|
|---|
| 1745 | .type = AC97_TUNE_INV_EAPD
|
|---|
| 1746 | },
|
|---|
| 1747 | {
|
|---|
| 1748 | .subvendor = 0x1014,
|
|---|
| 1749 | .subdevice = 0x1f00,
|
|---|
| 1750 | .name = "MS-9128",
|
|---|
| 1751 | .type = AC97_TUNE_ALC_JACK
|
|---|
| 1752 | },
|
|---|
| 1753 | {
|
|---|
| 1754 | .subvendor = 0x1014,
|
|---|
| 1755 | .subdevice = 0x0267,
|
|---|
| 1756 | .name = "IBM NetVista A30p", /* AD1981B */
|
|---|
| 1757 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1758 | },
|
|---|
| 1759 | {
|
|---|
| 1760 | .subvendor = 0x1025,
|
|---|
| 1761 | .subdevice = 0x0082,
|
|---|
| 1762 | .name = "Acer Travelmate 2310",
|
|---|
| 1763 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1764 | },
|
|---|
| 1765 | {
|
|---|
| 1766 | .subvendor = 0x1025,
|
|---|
| 1767 | .subdevice = 0x0083,
|
|---|
| 1768 | .name = "Acer Aspire 3003LCi",
|
|---|
| 1769 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1770 | },
|
|---|
| 1771 | {
|
|---|
| 1772 | .subvendor = 0x1028,
|
|---|
| 1773 | .subdevice = 0x00d8,
|
|---|
| 1774 | .name = "Dell Precision 530", /* AD1885 */
|
|---|
| 1775 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1776 | },
|
|---|
| 1777 | {
|
|---|
| 1778 | .subvendor = 0x1028,
|
|---|
| 1779 | .subdevice = 0x010d,
|
|---|
| 1780 | .name = "Dell", /* which model? AD1885 */
|
|---|
| 1781 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1782 | },
|
|---|
| 1783 | {
|
|---|
| 1784 | .subvendor = 0x1028,
|
|---|
| 1785 | .subdevice = 0x0126,
|
|---|
| 1786 | .name = "Dell Optiplex GX260", /* AD1981A */
|
|---|
| 1787 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1788 | },
|
|---|
| 1789 | {
|
|---|
| 1790 | .subvendor = 0x1028,
|
|---|
| 1791 | .subdevice = 0x012c,
|
|---|
| 1792 | .name = "Dell Precision 650", /* AD1981A */
|
|---|
| 1793 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1794 | },
|
|---|
| 1795 | {
|
|---|
| 1796 | .subvendor = 0x1028,
|
|---|
| 1797 | .subdevice = 0x012d,
|
|---|
| 1798 | .name = "Dell Precision 450", /* AD1981B*/
|
|---|
| 1799 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1800 | },
|
|---|
| 1801 | {
|
|---|
| 1802 | .subvendor = 0x1028,
|
|---|
| 1803 | .subdevice = 0x0147,
|
|---|
| 1804 | .name = "Dell", /* which model? AD1981B*/
|
|---|
| 1805 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1806 | },
|
|---|
| 1807 | {
|
|---|
| 1808 | .subvendor = 0x1028,
|
|---|
| 1809 | .subdevice = 0x0151,
|
|---|
| 1810 | .name = "Dell Optiplex GX270", /* AD1981B */
|
|---|
| 1811 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1812 | },
|
|---|
| 1813 | {
|
|---|
| 1814 | .subvendor = 0x1028,
|
|---|
| 1815 | .subdevice = 0x014e,
|
|---|
| 1816 | .name = "Dell D800", /* STAC9750/51 */
|
|---|
| 1817 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1818 | },
|
|---|
| 1819 | {
|
|---|
| 1820 | .subvendor = 0x1028,
|
|---|
| 1821 | .subdevice = 0x0163,
|
|---|
| 1822 | .name = "Dell Unknown", /* STAC9750/51 */
|
|---|
| 1823 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1824 | },
|
|---|
| 1825 | {
|
|---|
| 1826 | .subvendor = 0x1028,
|
|---|
| 1827 | .subdevice = 0x016a,
|
|---|
| 1828 | .name = "Dell Inspiron 8600", /* STAC9750/51 */
|
|---|
| 1829 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1830 | },
|
|---|
| 1831 | {
|
|---|
| 1832 | .subvendor = 0x1028,
|
|---|
| 1833 | .subdevice = 0x0182,
|
|---|
| 1834 | .name = "Dell Latitude D610", /* STAC9750/51 */
|
|---|
| 1835 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1836 | },
|
|---|
| 1837 | {
|
|---|
| 1838 | .subvendor = 0x1028,
|
|---|
| 1839 | .subdevice = 0x0186,
|
|---|
| 1840 | .name = "Dell Latitude D810", /* cf. Malone #41015 */
|
|---|
| 1841 | .type = AC97_TUNE_HP_MUTE_LED
|
|---|
| 1842 | },
|
|---|
| 1843 | {
|
|---|
| 1844 | .subvendor = 0x1028,
|
|---|
| 1845 | .subdevice = 0x0188,
|
|---|
| 1846 | .name = "Dell Inspiron 6000",
|
|---|
| 1847 | .type = AC97_TUNE_HP_MUTE_LED /* cf. Malone #41015 */
|
|---|
| 1848 | },
|
|---|
| 1849 | {
|
|---|
| 1850 | .subvendor = 0x1028,
|
|---|
| 1851 | .subdevice = 0x0189,
|
|---|
| 1852 | .name = "Dell Inspiron 9300",
|
|---|
| 1853 | .type = AC97_TUNE_HP_MUTE_LED
|
|---|
| 1854 | },
|
|---|
| 1855 | {
|
|---|
| 1856 | .subvendor = 0x1028,
|
|---|
| 1857 | .subdevice = 0x0191,
|
|---|
| 1858 | .name = "Dell Inspiron 8600",
|
|---|
| 1859 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1860 | },
|
|---|
| 1861 | {
|
|---|
| 1862 | .subvendor = 0x103c,
|
|---|
| 1863 | .subdevice = 0x006d,
|
|---|
| 1864 | .name = "HP zv5000",
|
|---|
| 1865 | .type = AC97_TUNE_MUTE_LED /*AD1981B*/
|
|---|
| 1866 | },
|
|---|
| 1867 | { /* FIXME: which codec? */
|
|---|
| 1868 | .subvendor = 0x103c,
|
|---|
| 1869 | .subdevice = 0x00c3,
|
|---|
| 1870 | .name = "HP xw6000",
|
|---|
| 1871 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1872 | },
|
|---|
| 1873 | {
|
|---|
| 1874 | .subvendor = 0x103c,
|
|---|
| 1875 | .subdevice = 0x088c,
|
|---|
| 1876 | .name = "HP nc8000",
|
|---|
| 1877 | .type = AC97_TUNE_HP_MUTE_LED
|
|---|
| 1878 | },
|
|---|
| 1879 | {
|
|---|
| 1880 | .subvendor = 0x103c,
|
|---|
| 1881 | .subdevice = 0x0890,
|
|---|
| 1882 | .name = "HP nc6000",
|
|---|
| 1883 | .type = AC97_TUNE_MUTE_LED
|
|---|
| 1884 | },
|
|---|
| 1885 | {
|
|---|
| 1886 | .subvendor = 0x103c,
|
|---|
| 1887 | .subdevice = 0x129d,
|
|---|
| 1888 | .name = "HP xw8000",
|
|---|
| 1889 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1890 | },
|
|---|
| 1891 | {
|
|---|
| 1892 | .subvendor = 0x103c,
|
|---|
| 1893 | .subdevice = 0x0938,
|
|---|
| 1894 | .name = "HP nc4200",
|
|---|
| 1895 | .type = AC97_TUNE_HP_MUTE_LED
|
|---|
| 1896 | },
|
|---|
| 1897 | {
|
|---|
| 1898 | .subvendor = 0x103c,
|
|---|
| 1899 | .subdevice = 0x099c,
|
|---|
| 1900 | .name = "HP nx6110/nc6120",
|
|---|
| 1901 | .type = AC97_TUNE_HP_MUTE_LED
|
|---|
| 1902 | },
|
|---|
| 1903 | {
|
|---|
| 1904 | .subvendor = 0x103c,
|
|---|
| 1905 | .subdevice = 0x0944,
|
|---|
| 1906 | .name = "HP nc6220",
|
|---|
| 1907 | .type = AC97_TUNE_HP_MUTE_LED
|
|---|
| 1908 | },
|
|---|
| 1909 | {
|
|---|
| 1910 | .subvendor = 0x103c,
|
|---|
| 1911 | .subdevice = 0x0934,
|
|---|
| 1912 | .name = "HP nc8220",
|
|---|
| 1913 | .type = AC97_TUNE_HP_MUTE_LED
|
|---|
| 1914 | },
|
|---|
| 1915 | {
|
|---|
| 1916 | .subvendor = 0x103c,
|
|---|
| 1917 | .subdevice = 0x12f1,
|
|---|
| 1918 | .name = "HP xw8200", /* AD1981B*/
|
|---|
| 1919 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1920 | },
|
|---|
| 1921 | {
|
|---|
| 1922 | .subvendor = 0x103c,
|
|---|
| 1923 | .subdevice = 0x12f2,
|
|---|
| 1924 | .name = "HP xw6200",
|
|---|
| 1925 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1926 | },
|
|---|
| 1927 | {
|
|---|
| 1928 | .subvendor = 0x103c,
|
|---|
| 1929 | .subdevice = 0x3008,
|
|---|
| 1930 | .name = "HP xw4200", /* AD1981B*/
|
|---|
| 1931 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1932 | },
|
|---|
| 1933 | {
|
|---|
| 1934 | .subvendor = 0x104d,
|
|---|
| 1935 | .subdevice = 0x8144,
|
|---|
| 1936 | .name = "Sony",
|
|---|
| 1937 | .type = AC97_TUNE_INV_EAPD
|
|---|
| 1938 | },
|
|---|
| 1939 | {
|
|---|
| 1940 | .subvendor = 0x104d,
|
|---|
| 1941 | .subdevice = 0x8197,
|
|---|
| 1942 | .name = "Sony S1XP",
|
|---|
| 1943 | .type = AC97_TUNE_INV_EAPD
|
|---|
| 1944 | },
|
|---|
| 1945 | {
|
|---|
| 1946 | .subvendor = 0x104d,
|
|---|
| 1947 | .subdevice = 0x81c0,
|
|---|
| 1948 | .name = "Sony VAIO VGN-T350P", /*AD1981B*/
|
|---|
| 1949 | .type = AC97_TUNE_INV_EAPD
|
|---|
| 1950 | },
|
|---|
| 1951 | {
|
|---|
| 1952 | .subvendor = 0x104d,
|
|---|
| 1953 | .subdevice = 0x81c5,
|
|---|
| 1954 | .name = "Sony VAIO VGN-B1VP", /*AD1981B*/
|
|---|
| 1955 | .type = AC97_TUNE_INV_EAPD
|
|---|
| 1956 | },
|
|---|
| 1957 | {
|
|---|
| 1958 | .subvendor = 0x1043,
|
|---|
| 1959 | .subdevice = 0x80f3,
|
|---|
| 1960 | .name = "ASUS ICH5/AD1985",
|
|---|
| 1961 | .type = AC97_TUNE_AD_SHARING
|
|---|
| 1962 | },
|
|---|
| 1963 | {
|
|---|
| 1964 | .subvendor = 0x10cf,
|
|---|
| 1965 | .subdevice = 0x11c3,
|
|---|
| 1966 | .name = "Fujitsu-Siemens E4010",
|
|---|
| 1967 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1968 | },
|
|---|
| 1969 | {
|
|---|
| 1970 | .subvendor = 0x10cf,
|
|---|
| 1971 | .subdevice = 0x1225,
|
|---|
| 1972 | .name = "Fujitsu-Siemens T3010",
|
|---|
| 1973 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1974 | },
|
|---|
| 1975 | {
|
|---|
| 1976 | .subvendor = 0x10cf,
|
|---|
| 1977 | .subdevice = 0x1253,
|
|---|
| 1978 | .name = "Fujitsu S6210", /* STAC9750/51 */
|
|---|
| 1979 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1980 | },
|
|---|
| 1981 | {
|
|---|
| 1982 | .subvendor = 0x10cf,
|
|---|
| 1983 | .subdevice = 0x127d,
|
|---|
| 1984 | .name = "Fujitsu Lifebook P7010",
|
|---|
| 1985 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1986 | },
|
|---|
| 1987 | {
|
|---|
| 1988 | .subvendor = 0x10cf,
|
|---|
| 1989 | .subdevice = 0x127e,
|
|---|
| 1990 | .name = "Fujitsu Lifebook C1211D",
|
|---|
| 1991 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1992 | },
|
|---|
| 1993 | {
|
|---|
| 1994 | .subvendor = 0x10cf,
|
|---|
| 1995 | .subdevice = 0x12ec,
|
|---|
| 1996 | .name = "Fujitsu-Siemens 4010",
|
|---|
| 1997 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 1998 | },
|
|---|
| 1999 | {
|
|---|
| 2000 | .subvendor = 0x10cf,
|
|---|
| 2001 | .subdevice = 0x12f2,
|
|---|
| 2002 | .name = "Fujitsu-Siemens Celsius H320",
|
|---|
| 2003 | .type = AC97_TUNE_SWAP_HP
|
|---|
| 2004 | },
|
|---|
| 2005 | {
|
|---|
| 2006 | .subvendor = 0x10f1,
|
|---|
| 2007 | .subdevice = 0x2665,
|
|---|
| 2008 | .name = "Fujitsu-Siemens Celsius", /* AD1981? */
|
|---|
| 2009 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2010 | },
|
|---|
| 2011 | {
|
|---|
| 2012 | .subvendor = 0x10f1,
|
|---|
| 2013 | .subdevice = 0x2885,
|
|---|
| 2014 | .name = "AMD64 Mobo", /* ALC650 */
|
|---|
| 2015 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2016 | },
|
|---|
| 2017 | {
|
|---|
| 2018 | .subvendor = 0x10f1,
|
|---|
| 2019 | .subdevice = 0x2895,
|
|---|
| 2020 | .name = "Tyan Thunder K8WE",
|
|---|
| 2021 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2022 | },
|
|---|
| 2023 | {
|
|---|
| 2024 | .subvendor = 0x10f7,
|
|---|
| 2025 | .subdevice = 0x834c,
|
|---|
| 2026 | .name = "Panasonic CF-R4",
|
|---|
| 2027 | .type = AC97_TUNE_HP_ONLY,
|
|---|
| 2028 | },
|
|---|
| 2029 | {
|
|---|
| 2030 | .subvendor = 0x110a,
|
|---|
| 2031 | .subdevice = 0x0056,
|
|---|
| 2032 | .name = "Fujitsu-Siemens Scenic", /* AD1981? */
|
|---|
| 2033 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2034 | },
|
|---|
| 2035 | {
|
|---|
| 2036 | .subvendor = 0x11d4,
|
|---|
| 2037 | .subdevice = 0x5375,
|
|---|
| 2038 | .name = "ADI AD1985 (discrete)",
|
|---|
| 2039 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2040 | },
|
|---|
| 2041 | {
|
|---|
| 2042 | .subvendor = 0x1462,
|
|---|
| 2043 | .subdevice = 0x5470,
|
|---|
| 2044 | .name = "MSI P4 ATX 645 Ultra",
|
|---|
| 2045 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2046 | },
|
|---|
| 2047 | {
|
|---|
| 2048 | .subvendor = 0x161f,
|
|---|
| 2049 | .subdevice = 0x202f,
|
|---|
| 2050 | .name = "Gateway M520",
|
|---|
| 2051 | .type = AC97_TUNE_INV_EAPD
|
|---|
| 2052 | },
|
|---|
| 2053 | {
|
|---|
| 2054 | .subvendor = 0x161f,
|
|---|
| 2055 | .subdevice = 0x203a,
|
|---|
| 2056 | .name = "Gateway 4525GZ", /* AD1981B */
|
|---|
| 2057 | .type = AC97_TUNE_INV_EAPD
|
|---|
| 2058 | },
|
|---|
| 2059 | {
|
|---|
| 2060 | .subvendor = 0x1734,
|
|---|
| 2061 | .subdevice = 0x0088,
|
|---|
| 2062 | .name = "Fujitsu-Siemens D1522", /* AD1981 */
|
|---|
| 2063 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2064 | },
|
|---|
| 2065 | {
|
|---|
| 2066 | .subvendor = 0x8086,
|
|---|
| 2067 | .subdevice = 0x2000,
|
|---|
| 2068 | .mask = 0xfff0,
|
|---|
| 2069 | .name = "Intel ICH5/AD1985",
|
|---|
| 2070 | .type = AC97_TUNE_AD_SHARING
|
|---|
| 2071 | },
|
|---|
| 2072 | {
|
|---|
| 2073 | .subvendor = 0x8086,
|
|---|
| 2074 | .subdevice = 0x4000,
|
|---|
| 2075 | .mask = 0xfff0,
|
|---|
| 2076 | .name = "Intel ICH5/AD1985",
|
|---|
| 2077 | .type = AC97_TUNE_AD_SHARING
|
|---|
| 2078 | },
|
|---|
| 2079 | {
|
|---|
| 2080 | .subvendor = 0x8086,
|
|---|
| 2081 | .subdevice = 0x4856,
|
|---|
| 2082 | .name = "Intel D845WN (82801BA)",
|
|---|
| 2083 | .type = AC97_TUNE_SWAP_HP
|
|---|
| 2084 | },
|
|---|
| 2085 | {
|
|---|
| 2086 | .subvendor = 0x8086,
|
|---|
| 2087 | .subdevice = 0x4d44,
|
|---|
| 2088 | .name = "Intel D850EMV2", /* AD1885 */
|
|---|
| 2089 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2090 | },
|
|---|
| 2091 | {
|
|---|
| 2092 | .subvendor = 0x8086,
|
|---|
| 2093 | .subdevice = 0x4d56,
|
|---|
| 2094 | .name = "Intel ICH/AD1885",
|
|---|
| 2095 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2096 | },
|
|---|
| 2097 | {
|
|---|
| 2098 | .subvendor = 0x8086,
|
|---|
| 2099 | .subdevice = 0x6000,
|
|---|
| 2100 | .mask = 0xfff0,
|
|---|
| 2101 | .name = "Intel ICH5/AD1985",
|
|---|
| 2102 | .type = AC97_TUNE_AD_SHARING
|
|---|
| 2103 | },
|
|---|
| 2104 | {
|
|---|
| 2105 | .subvendor = 0x8086,
|
|---|
| 2106 | .subdevice = 0xe000,
|
|---|
| 2107 | .mask = 0xfff0,
|
|---|
| 2108 | .name = "Intel ICH5/AD1985",
|
|---|
| 2109 | .type = AC97_TUNE_AD_SHARING
|
|---|
| 2110 | },
|
|---|
| 2111 | #if 0 /* FIXME: this seems wrong on most boards */
|
|---|
| 2112 | {
|
|---|
| 2113 | .subvendor = 0x8086,
|
|---|
| 2114 | .subdevice = 0xa000,
|
|---|
| 2115 | .mask = 0xfff0,
|
|---|
| 2116 | .name = "Intel ICH5/AD1985",
|
|---|
| 2117 | .type = AC97_TUNE_HP_ONLY
|
|---|
| 2118 | },
|
|---|
| 2119 | #endif
|
|---|
| 2120 | {0} /* terminator */
|
|---|
| 2121 | };
|
|---|
| 2122 |
|
|---|
| 2123 | static int snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
|
|---|
| 2124 | const char *quirk_override)
|
|---|
| 2125 | {
|
|---|
| 2126 | struct snd_ac97_bus *pbus;
|
|---|
| 2127 | struct snd_ac97_template ac97;
|
|---|
| 2128 | int err;
|
|---|
| 2129 | unsigned int i, codecs;
|
|---|
| 2130 | unsigned int glob_sta = 0;
|
|---|
| 2131 | const struct snd_ac97_bus_ops *ops;
|
|---|
| 2132 | static const struct snd_ac97_bus_ops standard_bus_ops = {
|
|---|
| 2133 | .write = snd_intel8x0_codec_write,
|
|---|
| 2134 | .read = snd_intel8x0_codec_read,
|
|---|
| 2135 | };
|
|---|
| 2136 | static const struct snd_ac97_bus_ops ali_bus_ops = {
|
|---|
| 2137 | .write = snd_intel8x0_ali_codec_write,
|
|---|
| 2138 | .read = snd_intel8x0_ali_codec_read,
|
|---|
| 2139 | };
|
|---|
| 2140 |
|
|---|
| 2141 | chip->spdif_idx = -1; /* use PCMOUT (or disabled) */
|
|---|
| 2142 | if (!spdif_aclink) {
|
|---|
| 2143 | switch (chip->device_type) {
|
|---|
| 2144 | case DEVICE_NFORCE:
|
|---|
| 2145 | chip->spdif_idx = NVD_SPBAR;
|
|---|
| 2146 | break;
|
|---|
| 2147 | case DEVICE_ALI:
|
|---|
| 2148 | chip->spdif_idx = ALID_AC97SPDIFOUT;
|
|---|
| 2149 | break;
|
|---|
| 2150 | case DEVICE_INTEL_ICH4:
|
|---|
| 2151 | chip->spdif_idx = ICHD_SPBAR;
|
|---|
| 2152 | break;
|
|---|
| 2153 | }
|
|---|
| 2154 | }
|
|---|
| 2155 |
|
|---|
| 2156 | chip->in_ac97_init = 1;
|
|---|
| 2157 |
|
|---|
| 2158 | memset(&ac97, 0, sizeof(ac97));
|
|---|
| 2159 | ac97.private_data = chip;
|
|---|
| 2160 | ac97.private_free = snd_intel8x0_mixer_free_ac97;
|
|---|
| 2161 | ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
|
|---|
| 2162 | if (chip->xbox)
|
|---|
| 2163 | ac97.scaps |= AC97_SCAP_DETECT_BY_VENDOR;
|
|---|
| 2164 | if (chip->device_type != DEVICE_ALI) {
|
|---|
| 2165 | glob_sta = igetdword(chip, ICHREG(GLOB_STA));
|
|---|
| 2166 | ops = &standard_bus_ops;
|
|---|
| 2167 | chip->in_sdin_init = 1;
|
|---|
| 2168 | codecs = 0;
|
|---|
| 2169 | for (i = 0; i < chip->max_codecs; i++) {
|
|---|
| 2170 | if (! (glob_sta & chip->codec_bit[i]))
|
|---|
| 2171 | continue;
|
|---|
| 2172 | if (chip->device_type == DEVICE_INTEL_ICH4) {
|
|---|
| 2173 | snd_intel8x0_codec_read_test(chip, codecs);
|
|---|
| 2174 | chip->ac97_sdin[codecs] =
|
|---|
| 2175 | igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
|
|---|
| 2176 | if (snd_BUG_ON(chip->ac97_sdin[codecs] >= 3))
|
|---|
| 2177 | chip->ac97_sdin[codecs] = 0;
|
|---|
| 2178 | } else
|
|---|
| 2179 | chip->ac97_sdin[codecs] = i;
|
|---|
| 2180 | codecs++;
|
|---|
| 2181 | }
|
|---|
| 2182 | chip->in_sdin_init = 0;
|
|---|
| 2183 | if (! codecs)
|
|---|
| 2184 | codecs = 1;
|
|---|
| 2185 | } else {
|
|---|
| 2186 | ops = &ali_bus_ops;
|
|---|
| 2187 | codecs = 1;
|
|---|
| 2188 | /* detect the secondary codec */
|
|---|
| 2189 | for (i = 0; i < 100; i++) {
|
|---|
| 2190 | unsigned int reg = igetdword(chip, ICHREG(ALI_RTSR));
|
|---|
| 2191 | if (reg & 0x40) {
|
|---|
| 2192 | codecs = 2;
|
|---|
| 2193 | break;
|
|---|
| 2194 | }
|
|---|
| 2195 | iputdword(chip, ICHREG(ALI_RTSR), reg | 0x40);
|
|---|
| 2196 | udelay(1);
|
|---|
| 2197 | }
|
|---|
| 2198 | }
|
|---|
| 2199 | err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus);
|
|---|
| 2200 | if (err < 0)
|
|---|
| 2201 | goto __err;
|
|---|
| 2202 | pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
|
|---|
| 2203 | if (ac97_clock >= 8000 && ac97_clock <= 48000)
|
|---|
| 2204 | pbus->clock = ac97_clock;
|
|---|
| 2205 | /* FIXME: my test board doesn't work well with VRA... */
|
|---|
| 2206 | if (chip->device_type == DEVICE_ALI)
|
|---|
| 2207 | pbus->no_vra = 1;
|
|---|
| 2208 | else
|
|---|
| 2209 | pbus->dra = 1;
|
|---|
| 2210 | chip->ac97_bus = pbus;
|
|---|
| 2211 | chip->ncodecs = codecs;
|
|---|
| 2212 |
|
|---|
| 2213 | ac97.pci = chip->pci;
|
|---|
| 2214 | for (i = 0; i < codecs; i++) {
|
|---|
| 2215 | ac97.num = i;
|
|---|
| 2216 | err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i]);
|
|---|
| 2217 | if (err < 0) {
|
|---|
| 2218 | if (err != -EACCES)
|
|---|
| 2219 | dev_err(chip->card->dev,
|
|---|
| 2220 | "Unable to initialize codec #%d\n", i);
|
|---|
| 2221 | if (i == 0)
|
|---|
| 2222 | goto __err;
|
|---|
| 2223 | }
|
|---|
| 2224 | }
|
|---|
| 2225 | /* tune up the primary codec */
|
|---|
| 2226 | snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
|
|---|
| 2227 | /* enable separate SDINs for ICH4 */
|
|---|
| 2228 | if (chip->device_type == DEVICE_INTEL_ICH4)
|
|---|
| 2229 | pbus->isdin = 1;
|
|---|
| 2230 | /* find the available PCM streams */
|
|---|
| 2231 | i = ARRAY_SIZE(ac97_pcm_defs);
|
|---|
| 2232 | if (chip->device_type != DEVICE_INTEL_ICH4)
|
|---|
| 2233 | i -= 2; /* do not allocate PCM2IN and MIC2 */
|
|---|
| 2234 | if (chip->spdif_idx < 0)
|
|---|
| 2235 | i--; /* do not allocate S/PDIF */
|
|---|
| 2236 | err = snd_ac97_pcm_assign(pbus, i, ac97_pcm_defs);
|
|---|
| 2237 | if (err < 0)
|
|---|
| 2238 | goto __err;
|
|---|
| 2239 | chip->ichd[ICHD_PCMOUT].pcm = &pbus->pcms[0];
|
|---|
| 2240 | chip->ichd[ICHD_PCMIN].pcm = &pbus->pcms[1];
|
|---|
| 2241 | chip->ichd[ICHD_MIC].pcm = &pbus->pcms[2];
|
|---|
| 2242 | if (chip->spdif_idx >= 0)
|
|---|
| 2243 | chip->ichd[chip->spdif_idx].pcm = &pbus->pcms[3];
|
|---|
| 2244 | if (chip->device_type == DEVICE_INTEL_ICH4) {
|
|---|
| 2245 | chip->ichd[ICHD_PCM2IN].pcm = &pbus->pcms[4];
|
|---|
| 2246 | chip->ichd[ICHD_MIC2].pcm = &pbus->pcms[5];
|
|---|
| 2247 | }
|
|---|
| 2248 | /* enable separate SDINs for ICH4 */
|
|---|
| 2249 | if (chip->device_type == DEVICE_INTEL_ICH4) {
|
|---|
| 2250 | struct ac97_pcm *pcm = chip->ichd[ICHD_PCM2IN].pcm;
|
|---|
| 2251 | u8 tmp = igetbyte(chip, ICHREG(SDM));
|
|---|
| 2252 | tmp &= ~(ICH_DI2L_MASK|ICH_DI1L_MASK);
|
|---|
| 2253 | if (pcm) {
|
|---|
| 2254 | tmp |= ICH_SE; /* steer enable for multiple SDINs */
|
|---|
| 2255 | tmp |= chip->ac97_sdin[0] << ICH_DI1L_SHIFT;
|
|---|
| 2256 | for (i = 1; i < 4; i++) {
|
|---|
| 2257 | if (pcm->r[0].codec[i]) {
|
|---|
| 2258 | tmp |= chip->ac97_sdin[pcm->r[0].codec[1]->num] << ICH_DI2L_SHIFT;
|
|---|
| 2259 | break;
|
|---|
| 2260 | }
|
|---|
| 2261 | }
|
|---|
| 2262 | } else {
|
|---|
| 2263 | tmp &= ~ICH_SE; /* steer disable */
|
|---|
| 2264 | }
|
|---|
| 2265 | iputbyte(chip, ICHREG(SDM), tmp);
|
|---|
| 2266 | }
|
|---|
| 2267 | if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
|
|---|
| 2268 | chip->multi4 = 1;
|
|---|
| 2269 | if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) {
|
|---|
| 2270 | chip->multi6 = 1;
|
|---|
| 2271 | if (chip->ac97[0]->flags & AC97_HAS_8CH)
|
|---|
| 2272 | chip->multi8 = 1;
|
|---|
| 2273 | }
|
|---|
| 2274 | }
|
|---|
| 2275 | if (pbus->pcms[0].r[1].rslots[0]) {
|
|---|
| 2276 | chip->dra = 1;
|
|---|
| 2277 | }
|
|---|
| 2278 | if (chip->device_type == DEVICE_INTEL_ICH4) {
|
|---|
| 2279 | if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
|
|---|
| 2280 | chip->smp20bit = 1;
|
|---|
| 2281 | }
|
|---|
| 2282 | if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
|
|---|
| 2283 | /* 48kHz only */
|
|---|
| 2284 | chip->ichd[chip->spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
|
|---|
| 2285 | }
|
|---|
| 2286 | if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
|
|---|
| 2287 | /* use slot 10/11 for SPDIF */
|
|---|
| 2288 | u32 val;
|
|---|
| 2289 | val = igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK;
|
|---|
| 2290 | val |= ICH_PCM_SPDIF_1011;
|
|---|
| 2291 | iputdword(chip, ICHREG(GLOB_CNT), val);
|
|---|
| 2292 | snd_ac97_update_bits(chip->ac97[0], AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
|
|---|
| 2293 | }
|
|---|
| 2294 | chip->in_ac97_init = 0;
|
|---|
| 2295 | return 0;
|
|---|
| 2296 |
|
|---|
| 2297 | __err:
|
|---|
| 2298 | /* clear the cold-reset bit for the next chance */
|
|---|
| 2299 | if (chip->device_type != DEVICE_ALI)
|
|---|
| 2300 | iputdword(chip, ICHREG(GLOB_CNT),
|
|---|
| 2301 | igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
|
|---|
| 2302 | return err;
|
|---|
| 2303 | }
|
|---|
| 2304 |
|
|---|
| 2305 |
|
|---|
| 2306 | /*
|
|---|
| 2307 | *
|
|---|
| 2308 | */
|
|---|
| 2309 |
|
|---|
| 2310 | static void do_ali_reset(struct intel8x0 *chip)
|
|---|
| 2311 | {
|
|---|
| 2312 | iputdword(chip, ICHREG(ALI_SCR), ICH_ALI_SC_RESET);
|
|---|
| 2313 | iputdword(chip, ICHREG(ALI_FIFOCR1), 0x83838383);
|
|---|
| 2314 | iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
|
|---|
| 2315 | iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
|
|---|
| 2316 | iputdword(chip, ICHREG(ALI_INTERFACECR),
|
|---|
| 2317 | ICH_ALI_IF_PI|ICH_ALI_IF_PO);
|
|---|
| 2318 | iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
|
|---|
| 2319 | iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
|
|---|
| 2320 | }
|
|---|
| 2321 |
|
|---|
| 2322 | #ifdef CONFIG_SND_AC97_POWER_SAVE
|
|---|
| 2323 | static const struct snd_pci_quirk ich_chip_reset_mode[] = {
|
|---|
| 2324 | SND_PCI_QUIRK(0x1014, 0x051f, "Thinkpad R32", 1),
|
|---|
| 2325 | {0} /* end */
|
|---|
| 2326 | };
|
|---|
| 2327 |
|
|---|
| 2328 | static int snd_intel8x0_ich_chip_cold_reset(struct intel8x0 *chip)
|
|---|
| 2329 | {
|
|---|
| 2330 | unsigned int cnt;
|
|---|
| 2331 | /* ACLink on, 2 channels */
|
|---|
| 2332 |
|
|---|
| 2333 | if (snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
|
|---|
| 2334 | return -EIO;
|
|---|
| 2335 |
|
|---|
| 2336 | cnt = igetdword(chip, ICHREG(GLOB_CNT));
|
|---|
| 2337 | cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
|
|---|
| 2338 |
|
|---|
| 2339 | /* do cold reset - the full ac97 powerdown may leave the controller
|
|---|
| 2340 | * in a warm state but actually it cannot communicate with the codec.
|
|---|
| 2341 | */
|
|---|
| 2342 | iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_AC97COLD);
|
|---|
| 2343 | cnt = igetdword(chip, ICHREG(GLOB_CNT));
|
|---|
| 2344 | udelay(10);
|
|---|
| 2345 | iputdword(chip, ICHREG(GLOB_CNT), cnt | ICH_AC97COLD);
|
|---|
| 2346 | msleep(1);
|
|---|
| 2347 | return 0;
|
|---|
| 2348 | }
|
|---|
| 2349 | #define snd_intel8x0_ich_chip_can_cold_reset(chip) \
|
|---|
| 2350 | (!snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
|
|---|
| 2351 | #else
|
|---|
| 2352 | #define snd_intel8x0_ich_chip_cold_reset(chip) 0
|
|---|
| 2353 | #define snd_intel8x0_ich_chip_can_cold_reset(chip) (0)
|
|---|
| 2354 | #endif
|
|---|
| 2355 |
|
|---|
| 2356 | static int snd_intel8x0_ich_chip_reset(struct intel8x0 *chip)
|
|---|
| 2357 | {
|
|---|
| 2358 | unsigned long end_time;
|
|---|
| 2359 | unsigned int cnt;
|
|---|
| 2360 | /* ACLink on, 2 channels */
|
|---|
| 2361 | cnt = igetdword(chip, ICHREG(GLOB_CNT));
|
|---|
| 2362 | cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
|
|---|
| 2363 | /* finish cold or do warm reset */
|
|---|
| 2364 | cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
|
|---|
| 2365 | iputdword(chip, ICHREG(GLOB_CNT), cnt);
|
|---|
| 2366 | end_time = (jiffies + (HZ / 4)) + 1;
|
|---|
| 2367 | do {
|
|---|
| 2368 | if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
|
|---|
| 2369 | return 0;
|
|---|
| 2370 | schedule_timeout_uninterruptible(1);
|
|---|
| 2371 | } while (time_after_eq(end_time, jiffies));
|
|---|
| 2372 | dev_err(chip->card->dev, "AC'97 warm reset still in progress? [0x%x]\n",
|
|---|
| 2373 | igetdword(chip, ICHREG(GLOB_CNT)));
|
|---|
| 2374 | return -EIO;
|
|---|
| 2375 | }
|
|---|
| 2376 |
|
|---|
| 2377 | static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
|
|---|
| 2378 | {
|
|---|
| 2379 | unsigned long end_time;
|
|---|
| 2380 | unsigned int status, nstatus;
|
|---|
| 2381 | unsigned int cnt;
|
|---|
| 2382 | int err;
|
|---|
| 2383 |
|
|---|
| 2384 | /* put logic to right state */
|
|---|
| 2385 | /* first clear status bits */
|
|---|
| 2386 | status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
|
|---|
| 2387 | if (chip->device_type == DEVICE_NFORCE)
|
|---|
| 2388 | status |= ICH_NVSPINT;
|
|---|
| 2389 | cnt = igetdword(chip, ICHREG(GLOB_STA));
|
|---|
| 2390 | iputdword(chip, ICHREG(GLOB_STA), cnt & status);
|
|---|
| 2391 |
|
|---|
| 2392 | #ifdef CONFIG_SND_AC97_POWER_SAVE
|
|---|
| 2393 | if (snd_intel8x0_ich_chip_can_cold_reset(chip))
|
|---|
| 2394 | err = snd_intel8x0_ich_chip_cold_reset(chip);
|
|---|
| 2395 | else
|
|---|
| 2396 | #endif
|
|---|
| 2397 | err = snd_intel8x0_ich_chip_reset(chip);
|
|---|
| 2398 | if (err < 0)
|
|---|
| 2399 | return err;
|
|---|
| 2400 |
|
|---|
| 2401 | if (probing) {
|
|---|
| 2402 | /* wait for any codec ready status.
|
|---|
| 2403 | * Once it becomes ready it should remain ready
|
|---|
| 2404 | * as long as we do not disable the ac97 link.
|
|---|
| 2405 | */
|
|---|
| 2406 | end_time = jiffies + HZ;
|
|---|
| 2407 | do {
|
|---|
| 2408 | status = igetdword(chip, ICHREG(GLOB_STA)) &
|
|---|
| 2409 | chip->codec_isr_bits;
|
|---|
| 2410 | if (status)
|
|---|
| 2411 | break;
|
|---|
| 2412 | schedule_timeout_uninterruptible(1);
|
|---|
| 2413 | } while (time_after_eq(end_time, jiffies));
|
|---|
| 2414 | if (! status) {
|
|---|
| 2415 | /* no codec is found */
|
|---|
| 2416 | dev_err(chip->card->dev,
|
|---|
| 2417 | "codec_ready: codec is not ready [0x%x]\n",
|
|---|
| 2418 | igetdword(chip, ICHREG(GLOB_STA)));
|
|---|
| 2419 | return -EIO;
|
|---|
| 2420 | }
|
|---|
| 2421 |
|
|---|
| 2422 | /* wait for other codecs ready status. */
|
|---|
| 2423 | end_time = jiffies + HZ / 4;
|
|---|
| 2424 | while (status != chip->codec_isr_bits &&
|
|---|
| 2425 | time_after_eq(end_time, jiffies)) {
|
|---|
| 2426 | schedule_timeout_uninterruptible(1);
|
|---|
| 2427 | status |= igetdword(chip, ICHREG(GLOB_STA)) &
|
|---|
| 2428 | chip->codec_isr_bits;
|
|---|
| 2429 | }
|
|---|
| 2430 |
|
|---|
| 2431 | } else {
|
|---|
| 2432 | /* resume phase */
|
|---|
| 2433 | int i;
|
|---|
| 2434 | status = 0;
|
|---|
| 2435 | for (i = 0; i < chip->ncodecs; i++)
|
|---|
| 2436 | if (chip->ac97[i])
|
|---|
| 2437 | status |= chip->codec_bit[chip->ac97_sdin[i]];
|
|---|
| 2438 | /* wait until all the probed codecs are ready */
|
|---|
| 2439 | end_time = jiffies + HZ;
|
|---|
| 2440 | do {
|
|---|
| 2441 | nstatus = igetdword(chip, ICHREG(GLOB_STA)) &
|
|---|
| 2442 | chip->codec_isr_bits;
|
|---|
| 2443 | if (status == nstatus)
|
|---|
| 2444 | break;
|
|---|
| 2445 | schedule_timeout_uninterruptible(1);
|
|---|
| 2446 | } while (time_after_eq(end_time, jiffies));
|
|---|
| 2447 | }
|
|---|
| 2448 |
|
|---|
| 2449 | if (chip->device_type == DEVICE_SIS) {
|
|---|
| 2450 | /* unmute the output on SIS7012 */
|
|---|
| 2451 | iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
|
|---|
| 2452 | }
|
|---|
| 2453 | if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
|
|---|
| 2454 | /* enable SPDIF interrupt */
|
|---|
| 2455 | unsigned int val;
|
|---|
| 2456 | pci_read_config_dword(chip->pci, 0x4c, &val);
|
|---|
| 2457 | val |= 0x1000000;
|
|---|
| 2458 | pci_write_config_dword(chip->pci, 0x4c, val);
|
|---|
| 2459 | }
|
|---|
| 2460 | return 0;
|
|---|
| 2461 | }
|
|---|
| 2462 |
|
|---|
| 2463 | static int snd_intel8x0_ali_chip_init(struct intel8x0 *chip, int probing)
|
|---|
| 2464 | {
|
|---|
| 2465 | u32 reg;
|
|---|
| 2466 | int i = 0;
|
|---|
| 2467 |
|
|---|
| 2468 | reg = igetdword(chip, ICHREG(ALI_SCR));
|
|---|
| 2469 | if ((reg & 2) == 0) /* Cold required */
|
|---|
| 2470 | reg |= 2;
|
|---|
| 2471 | else
|
|---|
| 2472 | reg |= 1; /* Warm */
|
|---|
| 2473 | reg &= ~0x80000000; /* ACLink on */
|
|---|
| 2474 | iputdword(chip, ICHREG(ALI_SCR), reg);
|
|---|
| 2475 |
|
|---|
| 2476 | for (i = 0; i < HZ / 2; i++) {
|
|---|
| 2477 | if (! (igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ALI_INT_GPIO))
|
|---|
| 2478 | goto __ok;
|
|---|
| 2479 | schedule_timeout_uninterruptible(1);
|
|---|
| 2480 | }
|
|---|
| 2481 | dev_err(chip->card->dev, "AC'97 reset failed.\n");
|
|---|
| 2482 | if (probing)
|
|---|
| 2483 | return -EIO;
|
|---|
| 2484 |
|
|---|
| 2485 | __ok:
|
|---|
| 2486 | for (i = 0; i < HZ / 2; i++) {
|
|---|
| 2487 | reg = igetdword(chip, ICHREG(ALI_RTSR));
|
|---|
| 2488 | if (reg & 0x80) /* primary codec */
|
|---|
| 2489 | break;
|
|---|
| 2490 | iputdword(chip, ICHREG(ALI_RTSR), reg | 0x80);
|
|---|
| 2491 | schedule_timeout_uninterruptible(1);
|
|---|
| 2492 | }
|
|---|
| 2493 |
|
|---|
| 2494 | do_ali_reset(chip);
|
|---|
| 2495 | return 0;
|
|---|
| 2496 | }
|
|---|
| 2497 |
|
|---|
| 2498 | static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing)
|
|---|
| 2499 | {
|
|---|
| 2500 | unsigned int i, timeout;
|
|---|
| 2501 | int err;
|
|---|
| 2502 |
|
|---|
| 2503 | if (chip->device_type != DEVICE_ALI) {
|
|---|
| 2504 | err = snd_intel8x0_ich_chip_init(chip, probing);
|
|---|
| 2505 | if (err < 0)
|
|---|
| 2506 | return err;
|
|---|
| 2507 | iagetword(chip, 0); /* clear semaphore flag */
|
|---|
| 2508 | } else {
|
|---|
| 2509 | err = snd_intel8x0_ali_chip_init(chip, probing);
|
|---|
| 2510 | if (err < 0)
|
|---|
| 2511 | return err;
|
|---|
| 2512 | }
|
|---|
| 2513 |
|
|---|
| 2514 | /* disable interrupts */
|
|---|
| 2515 | for (i = 0; i < chip->bdbars_count; i++)
|
|---|
| 2516 | iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
|
|---|
| 2517 | /* reset channels */
|
|---|
| 2518 | for (i = 0; i < chip->bdbars_count; i++)
|
|---|
| 2519 | iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
|
|---|
| 2520 | for (i = 0; i < chip->bdbars_count; i++) {
|
|---|
| 2521 | timeout = 100000;
|
|---|
| 2522 | while (--timeout != 0) {
|
|---|
| 2523 | if ((igetbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset) & ICH_RESETREGS) == 0)
|
|---|
| 2524 | break;
|
|---|
| 2525 | }
|
|---|
| 2526 | if (timeout == 0)
|
|---|
| 2527 | dev_err(chip->card->dev, "reset of registers failed?\n");
|
|---|
| 2528 | }
|
|---|
| 2529 | /* initialize Buffer Descriptor Lists */
|
|---|
| 2530 | for (i = 0; i < chip->bdbars_count; i++)
|
|---|
| 2531 | iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset,
|
|---|
| 2532 | chip->ichd[i].bdbar_addr);
|
|---|
| 2533 | return 0;
|
|---|
| 2534 | }
|
|---|
| 2535 |
|
|---|
| 2536 | static int snd_intel8x0_free(struct intel8x0 *chip)
|
|---|
| 2537 | {
|
|---|
| 2538 | unsigned int i;
|
|---|
| 2539 |
|
|---|
| 2540 | if (chip->irq < 0)
|
|---|
| 2541 | goto __hw_end;
|
|---|
| 2542 | /* disable interrupts */
|
|---|
| 2543 | for (i = 0; i < chip->bdbars_count; i++)
|
|---|
| 2544 | iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
|
|---|
| 2545 | /* reset channels */
|
|---|
| 2546 | for (i = 0; i < chip->bdbars_count; i++)
|
|---|
| 2547 | iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
|
|---|
| 2548 | if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
|
|---|
| 2549 | /* stop the spdif interrupt */
|
|---|
| 2550 | unsigned int val;
|
|---|
| 2551 | pci_read_config_dword(chip->pci, 0x4c, &val);
|
|---|
| 2552 | val &= ~0x1000000;
|
|---|
| 2553 | pci_write_config_dword(chip->pci, 0x4c, val);
|
|---|
| 2554 | }
|
|---|
| 2555 | /* --- */
|
|---|
| 2556 |
|
|---|
| 2557 | __hw_end:
|
|---|
| 2558 | if (chip->irq >= 0)
|
|---|
| 2559 | free_irq(chip->irq, chip);
|
|---|
| 2560 | if (chip->bdbars.area)
|
|---|
| 2561 | snd_dma_free_pages(&chip->bdbars);
|
|---|
| 2562 | if (chip->addr)
|
|---|
| 2563 | pci_iounmap(chip->pci, chip->addr);
|
|---|
| 2564 | if (chip->bmaddr)
|
|---|
| 2565 | pci_iounmap(chip->pci, chip->bmaddr);
|
|---|
| 2566 | pci_release_regions(chip->pci);
|
|---|
| 2567 | pci_disable_device(chip->pci);
|
|---|
| 2568 | kfree(chip);
|
|---|
| 2569 | return 0;
|
|---|
| 2570 | }
|
|---|
| 2571 |
|
|---|
| 2572 | #ifdef CONFIG_PM_SLEEP
|
|---|
| 2573 | /*
|
|---|
| 2574 | * power management
|
|---|
| 2575 | */
|
|---|
| 2576 | static int intel8x0_suspend(struct device *dev)
|
|---|
| 2577 | {
|
|---|
| 2578 | struct snd_card *card = dev_get_drvdata(dev);
|
|---|
| 2579 | struct intel8x0 *chip = card->private_data;
|
|---|
| 2580 | int i;
|
|---|
| 2581 |
|
|---|
| 2582 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
|
|---|
| 2583 | for (i = 0; i < chip->ncodecs; i++)
|
|---|
| 2584 | snd_ac97_suspend(chip->ac97[i]);
|
|---|
| 2585 | if (chip->device_type == DEVICE_INTEL_ICH4)
|
|---|
| 2586 | chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
|
|---|
| 2587 |
|
|---|
| 2588 | if (chip->irq >= 0) {
|
|---|
| 2589 | free_irq(chip->irq, chip);
|
|---|
| 2590 | chip->irq = -1;
|
|---|
| 2591 | card->sync_irq = -1;
|
|---|
| 2592 | }
|
|---|
| 2593 | return 0;
|
|---|
| 2594 | }
|
|---|
| 2595 |
|
|---|
| 2596 | static int intel8x0_resume(struct device *dev)
|
|---|
| 2597 | {
|
|---|
| 2598 | struct pci_dev *pci = to_pci_dev(dev);
|
|---|
| 2599 | struct snd_card *card = dev_get_drvdata(dev);
|
|---|
| 2600 | struct intel8x0 *chip = card->private_data;
|
|---|
| 2601 | int i;
|
|---|
| 2602 |
|
|---|
| 2603 | snd_intel8x0_chip_init(chip, 0);
|
|---|
| 2604 | if (request_irq(pci->irq, snd_intel8x0_interrupt,
|
|---|
| 2605 | IRQF_SHARED, KBUILD_MODNAME, chip)) {
|
|---|
| 2606 | dev_err(dev, "unable to grab IRQ %d, disabling device\n",
|
|---|
| 2607 | pci->irq);
|
|---|
| 2608 | snd_card_disconnect(card);
|
|---|
| 2609 | return -EIO;
|
|---|
| 2610 | }
|
|---|
| 2611 | chip->irq = pci->irq;
|
|---|
| 2612 | card->sync_irq = chip->irq;
|
|---|
| 2613 |
|
|---|
| 2614 | /* re-initialize mixer stuff */
|
|---|
| 2615 | if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
|
|---|
| 2616 | /* enable separate SDINs for ICH4 */
|
|---|
| 2617 | iputbyte(chip, ICHREG(SDM), chip->sdm_saved);
|
|---|
| 2618 | /* use slot 10/11 for SPDIF */
|
|---|
| 2619 | iputdword(chip, ICHREG(GLOB_CNT),
|
|---|
| 2620 | (igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK) |
|
|---|
| 2621 | ICH_PCM_SPDIF_1011);
|
|---|
| 2622 | }
|
|---|
| 2623 |
|
|---|
| 2624 | for (i = 0; i < chip->ncodecs; i++)
|
|---|
| 2625 | snd_ac97_resume(chip->ac97[i]);
|
|---|
| 2626 |
|
|---|
| 2627 | /* resume status */
|
|---|
| 2628 | for (i = 0; i < chip->bdbars_count; i++) {
|
|---|
| 2629 | struct ichdev *ichdev = &chip->ichd[i];
|
|---|
| 2630 | unsigned long port = ichdev->reg_offset;
|
|---|
| 2631 | if (! ichdev->substream || ! ichdev->suspended)
|
|---|
| 2632 | continue;
|
|---|
| 2633 | if (ichdev->ichd == ICHD_PCMOUT)
|
|---|
| 2634 | snd_intel8x0_setup_pcm_out(chip, ichdev->substream->runtime);
|
|---|
| 2635 | iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
|
|---|
| 2636 | iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
|
|---|
| 2637 | iputbyte(chip, port + ICH_REG_OFF_CIV, ichdev->civ);
|
|---|
| 2638 | iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
|
|---|
| 2639 | }
|
|---|
| 2640 |
|
|---|
| 2641 | snd_power_change_state(card, SNDRV_CTL_POWER_D0);
|
|---|
| 2642 | return 0;
|
|---|
| 2643 | }
|
|---|
| 2644 |
|
|---|
| 2645 | static SIMPLE_DEV_PM_OPS(intel8x0_pm, intel8x0_suspend, intel8x0_resume);
|
|---|
| 2646 | #define INTEL8X0_PM_OPS &intel8x0_pm
|
|---|
| 2647 | #else
|
|---|
| 2648 | #define INTEL8X0_PM_OPS NULL
|
|---|
| 2649 | #endif /* CONFIG_PM_SLEEP */
|
|---|
| 2650 |
|
|---|
| 2651 | #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */
|
|---|
| 2652 |
|
|---|
| 2653 | static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
|
|---|
| 2654 | {
|
|---|
| 2655 | struct snd_pcm_substream *subs;
|
|---|
| 2656 | struct ichdev *ichdev;
|
|---|
| 2657 | unsigned long port;
|
|---|
| 2658 | unsigned long pos, pos1, t;
|
|---|
| 2659 | int civ, timeout = 1000, attempt = 1;
|
|---|
| 2660 | #ifndef TARGET_OS2
|
|---|
| 2661 | ktime_t start_time, stop_time;
|
|---|
| 2662 | #else
|
|---|
| 2663 | struct timespec start_time, stop_time;
|
|---|
| 2664 | #endif
|
|---|
| 2665 |
|
|---|
| 2666 | if (chip->ac97_bus->clock != 48000)
|
|---|
| 2667 | return; /* specified in module option */
|
|---|
| 2668 |
|
|---|
| 2669 | __again:
|
|---|
| 2670 | subs = chip->pcm[0]->streams[0].substream;
|
|---|
| 2671 | if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
|
|---|
| 2672 | dev_warn(chip->card->dev,
|
|---|
| 2673 | "no playback buffer allocated - aborting measure ac97 clock\n");
|
|---|
| 2674 | return;
|
|---|
| 2675 | }
|
|---|
| 2676 | ichdev = &chip->ichd[ICHD_PCMOUT];
|
|---|
| 2677 | ichdev->physbuf = subs->dma_buffer.addr;
|
|---|
| 2678 | ichdev->size = ichdev->fragsize = INTEL8X0_TESTBUF_SIZE;
|
|---|
| 2679 | ichdev->substream = NULL; /* don't process interrupts */
|
|---|
| 2680 |
|
|---|
| 2681 | /* set rate */
|
|---|
| 2682 | if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
|
|---|
| 2683 | dev_err(chip->card->dev, "cannot set ac97 rate: clock = %d\n",
|
|---|
| 2684 | chip->ac97_bus->clock);
|
|---|
| 2685 | return;
|
|---|
| 2686 | }
|
|---|
| 2687 | snd_intel8x0_setup_periods(chip, ichdev);
|
|---|
| 2688 | port = ichdev->reg_offset;
|
|---|
| 2689 | spin_lock_irq(&chip->reg_lock);
|
|---|
| 2690 | chip->in_measurement = 1;
|
|---|
| 2691 | /* trigger */
|
|---|
| 2692 | if (chip->device_type != DEVICE_ALI)
|
|---|
| 2693 | iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE | ICH_STARTBM);
|
|---|
| 2694 | else {
|
|---|
| 2695 | iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
|
|---|
| 2696 | iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
|
|---|
| 2697 | }
|
|---|
| 2698 | #ifndef TARGET_OS2
|
|---|
| 2699 | start_time = ktime_get();
|
|---|
| 2700 | #else
|
|---|
| 2701 | do_posix_clock_monotonic_gettime(&start_time);
|
|---|
| 2702 | #endif
|
|---|
| 2703 | spin_unlock_irq(&chip->reg_lock);
|
|---|
| 2704 | msleep(50);
|
|---|
| 2705 | spin_lock_irq(&chip->reg_lock);
|
|---|
| 2706 | /* check the position */
|
|---|
| 2707 | do {
|
|---|
| 2708 | civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
|
|---|
| 2709 | pos1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
|
|---|
| 2710 | if (pos1 == 0) {
|
|---|
| 2711 | udelay(10);
|
|---|
| 2712 | continue;
|
|---|
| 2713 | }
|
|---|
| 2714 | if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
|
|---|
| 2715 | pos1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
|
|---|
| 2716 | break;
|
|---|
| 2717 | } while (timeout--);
|
|---|
| 2718 | if (pos1 == 0) { /* oops, this value is not reliable */
|
|---|
| 2719 | pos = 0;
|
|---|
| 2720 | } else {
|
|---|
| 2721 | pos = ichdev->fragsize1;
|
|---|
| 2722 | pos -= pos1 << ichdev->pos_shift;
|
|---|
| 2723 | pos += ichdev->position;
|
|---|
| 2724 | }
|
|---|
| 2725 | chip->in_measurement = 0;
|
|---|
| 2726 | #ifndef TARGET_OS2
|
|---|
| 2727 | stop_time = ktime_get();
|
|---|
| 2728 | #else
|
|---|
| 2729 | do_posix_clock_monotonic_gettime(&stop_time);
|
|---|
| 2730 | #endif
|
|---|
| 2731 | /* stop */
|
|---|
| 2732 | if (chip->device_type == DEVICE_ALI) {
|
|---|
| 2733 | iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16));
|
|---|
| 2734 | iputbyte(chip, port + ICH_REG_OFF_CR, 0);
|
|---|
| 2735 | while (igetbyte(chip, port + ICH_REG_OFF_CR))
|
|---|
| 2736 | ;
|
|---|
| 2737 | } else {
|
|---|
| 2738 | iputbyte(chip, port + ICH_REG_OFF_CR, 0);
|
|---|
| 2739 | while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH))
|
|---|
| 2740 | ;
|
|---|
| 2741 | }
|
|---|
| 2742 | iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
|
|---|
| 2743 | spin_unlock_irq(&chip->reg_lock);
|
|---|
| 2744 |
|
|---|
| 2745 | if (pos == 0) {
|
|---|
| 2746 | dev_err(chip->card->dev,
|
|---|
| 2747 | "measure - unreliable DMA position..\n");
|
|---|
| 2748 | __retry:
|
|---|
| 2749 | if (attempt < 3) {
|
|---|
| 2750 | msleep(300);
|
|---|
| 2751 | attempt++;
|
|---|
| 2752 | goto __again;
|
|---|
| 2753 | }
|
|---|
| 2754 | goto __end;
|
|---|
| 2755 | }
|
|---|
| 2756 |
|
|---|
| 2757 | pos /= 4;
|
|---|
| 2758 | #ifndef TARGET_OS2
|
|---|
| 2759 | t = ktime_us_delta(stop_time, start_time);
|
|---|
| 2760 | #else
|
|---|
| 2761 | t = stop_time.tv_sec - start_time.tv_sec;
|
|---|
| 2762 | t *= 1000000;
|
|---|
| 2763 | t += (stop_time.tv_nsec - start_time.tv_nsec) / 1000;
|
|---|
| 2764 | dprintf(("%s: measured %lu usecs (%lu samples)\n", __func__, t, pos));
|
|---|
| 2765 | #endif
|
|---|
| 2766 | dev_info(chip->card->dev,
|
|---|
| 2767 | "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
|
|---|
| 2768 | if (t == 0) {
|
|---|
| 2769 | dev_err(chip->card->dev, "?? calculation error..\n");
|
|---|
| 2770 | goto __retry;
|
|---|
| 2771 | }
|
|---|
| 2772 | pos *= 1000;
|
|---|
| 2773 | pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
|
|---|
| 2774 | if (pos < 40000 || pos >= 60000) {
|
|---|
| 2775 | /* abnormal value. hw problem? */
|
|---|
| 2776 | dev_info(chip->card->dev, "measured clock %ld rejected\n", pos);
|
|---|
| 2777 | goto __retry;
|
|---|
| 2778 | } else if (pos > 40500 && pos < 41500)
|
|---|
| 2779 | /* first exception - 41000Hz reference clock */
|
|---|
| 2780 | chip->ac97_bus->clock = 41000;
|
|---|
| 2781 | else if (pos > 43600 && pos < 44600)
|
|---|
| 2782 | /* second exception - 44100HZ reference clock */
|
|---|
| 2783 | chip->ac97_bus->clock = 44100;
|
|---|
| 2784 | else if (pos < 47500 || pos > 48500)
|
|---|
| 2785 | /* not 48000Hz, tuning the clock.. */
|
|---|
| 2786 | chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
|
|---|
| 2787 | __end:
|
|---|
| 2788 | dev_info(chip->card->dev, "clocking to %d\n", chip->ac97_bus->clock);
|
|---|
| 2789 | snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0);
|
|---|
| 2790 | }
|
|---|
| 2791 |
|
|---|
| 2792 | static const struct snd_pci_quirk intel8x0_clock_list[] = {
|
|---|
| 2793 | SND_PCI_QUIRK(0x0e11, 0x008a, "AD1885", 41000),
|
|---|
| 2794 | SND_PCI_QUIRK(0x1014, 0x0581, "AD1981B", 48000),
|
|---|
| 2795 | SND_PCI_QUIRK(0x1028, 0x00be, "AD1885", 44100),
|
|---|
| 2796 | SND_PCI_QUIRK(0x1028, 0x0177, "AD1980", 48000),
|
|---|
| 2797 | SND_PCI_QUIRK(0x1028, 0x01ad, "AD1981B", 48000),
|
|---|
| 2798 | SND_PCI_QUIRK(0x1043, 0x80f3, "AD1985", 48000),
|
|---|
| 2799 | {0} /* terminator */
|
|---|
| 2800 | };
|
|---|
| 2801 |
|
|---|
| 2802 | static int intel8x0_in_clock_list(struct intel8x0 *chip)
|
|---|
| 2803 | {
|
|---|
| 2804 | struct pci_dev *pci = chip->pci;
|
|---|
| 2805 | const struct snd_pci_quirk *wl;
|
|---|
| 2806 |
|
|---|
| 2807 | wl = snd_pci_quirk_lookup(pci, intel8x0_clock_list);
|
|---|
| 2808 | if (!wl)
|
|---|
| 2809 | return 0;
|
|---|
| 2810 | dev_info(chip->card->dev, "allow list rate for %04x:%04x is %i\n",
|
|---|
| 2811 | pci->subsystem_vendor, pci->subsystem_device, wl->value);
|
|---|
| 2812 | chip->ac97_bus->clock = wl->value;
|
|---|
| 2813 | return 1;
|
|---|
| 2814 | }
|
|---|
| 2815 |
|
|---|
| 2816 | static void snd_intel8x0_proc_read(struct snd_info_entry * entry,
|
|---|
| 2817 | struct snd_info_buffer *buffer)
|
|---|
| 2818 | {
|
|---|
| 2819 | struct intel8x0 *chip = entry->private_data;
|
|---|
| 2820 | unsigned int tmp;
|
|---|
| 2821 |
|
|---|
| 2822 | snd_iprintf(buffer, "Intel8x0\n\n");
|
|---|
| 2823 | if (chip->device_type == DEVICE_ALI)
|
|---|
| 2824 | return;
|
|---|
| 2825 | tmp = igetdword(chip, ICHREG(GLOB_STA));
|
|---|
| 2826 | snd_iprintf(buffer, "Global control : 0x%08x\n", igetdword(chip, ICHREG(GLOB_CNT)));
|
|---|
| 2827 | snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
|
|---|
| 2828 | if (chip->device_type == DEVICE_INTEL_ICH4)
|
|---|
| 2829 | snd_iprintf(buffer, "SDM : 0x%08x\n", igetdword(chip, ICHREG(SDM)));
|
|---|
| 2830 | snd_iprintf(buffer, "AC'97 codecs ready :");
|
|---|
| 2831 | if (tmp & chip->codec_isr_bits) {
|
|---|
| 2832 | int i;
|
|---|
| 2833 | static const char *codecs[3] = {
|
|---|
| 2834 | "primary", "secondary", "tertiary"
|
|---|
| 2835 | };
|
|---|
| 2836 | for (i = 0; i < chip->max_codecs; i++)
|
|---|
| 2837 | if (tmp & chip->codec_bit[i])
|
|---|
| 2838 | snd_iprintf(buffer, " %s", codecs[i]);
|
|---|
| 2839 | } else
|
|---|
| 2840 | snd_iprintf(buffer, " none");
|
|---|
| 2841 | snd_iprintf(buffer, "\n");
|
|---|
| 2842 | if (chip->device_type == DEVICE_INTEL_ICH4 ||
|
|---|
| 2843 | chip->device_type == DEVICE_SIS)
|
|---|
| 2844 | snd_iprintf(buffer, "AC'97 codecs SDIN : %i %i %i\n",
|
|---|
| 2845 | chip->ac97_sdin[0],
|
|---|
| 2846 | chip->ac97_sdin[1],
|
|---|
| 2847 | chip->ac97_sdin[2]);
|
|---|
| 2848 | }
|
|---|
| 2849 |
|
|---|
| 2850 | static void snd_intel8x0_proc_init(struct intel8x0 *chip)
|
|---|
| 2851 | {
|
|---|
| 2852 | snd_card_ro_proc_new(chip->card, "intel8x0", chip,
|
|---|
| 2853 | snd_intel8x0_proc_read);
|
|---|
| 2854 | }
|
|---|
| 2855 |
|
|---|
| 2856 | static int snd_intel8x0_dev_free(struct snd_device *device)
|
|---|
| 2857 | {
|
|---|
| 2858 | struct intel8x0 *chip = device->device_data;
|
|---|
| 2859 | return snd_intel8x0_free(chip);
|
|---|
| 2860 | }
|
|---|
| 2861 |
|
|---|
| 2862 | struct ich_reg_info {
|
|---|
| 2863 | unsigned int int_sta_mask;
|
|---|
| 2864 | unsigned int offset;
|
|---|
| 2865 | };
|
|---|
| 2866 |
|
|---|
| 2867 | static const unsigned int ich_codec_bits[3] = {
|
|---|
| 2868 | ICH_PCR, ICH_SCR, ICH_TCR
|
|---|
| 2869 | };
|
|---|
| 2870 | static const unsigned int sis_codec_bits[3] = {
|
|---|
| 2871 | ICH_PCR, ICH_SCR, ICH_SIS_TCR
|
|---|
| 2872 | };
|
|---|
| 2873 |
|
|---|
| 2874 | static int snd_intel8x0_inside_vm(struct pci_dev *pci)
|
|---|
| 2875 | {
|
|---|
| 2876 | int result = inside_vm;
|
|---|
| 2877 | char *msg = NULL;
|
|---|
| 2878 |
|
|---|
| 2879 | /* check module parameter first (override detection) */
|
|---|
| 2880 | if (result >= 0) {
|
|---|
| 2881 | msg = result ? "enable (forced) VM" : "disable (forced) VM";
|
|---|
| 2882 | goto fini;
|
|---|
| 2883 | }
|
|---|
| 2884 |
|
|---|
| 2885 | /* check for known (emulated) devices */
|
|---|
| 2886 | result = 0;
|
|---|
| 2887 | if (pci->subsystem_vendor == PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
|
|---|
| 2888 | pci->subsystem_device == PCI_SUBDEVICE_ID_QEMU) {
|
|---|
| 2889 | /* KVM emulated sound, PCI SSID: 1af4:1100 */
|
|---|
| 2890 | msg = "enable KVM";
|
|---|
| 2891 | result = 1;
|
|---|
| 2892 | } else if (pci->subsystem_vendor == 0x1ab8) {
|
|---|
| 2893 | /* Parallels VM emulated sound, PCI SSID: 1ab8:xxxx */
|
|---|
| 2894 | msg = "enable Parallels VM";
|
|---|
| 2895 | result = 1;
|
|---|
| 2896 | }
|
|---|
| 2897 |
|
|---|
| 2898 | fini:
|
|---|
| 2899 | if (msg != NULL)
|
|---|
| 2900 | dev_info(&pci->dev, "%s optimization\n", msg);
|
|---|
| 2901 |
|
|---|
| 2902 | return result;
|
|---|
| 2903 | }
|
|---|
| 2904 |
|
|---|
| 2905 | static int snd_intel8x0_create(struct snd_card *card,
|
|---|
| 2906 | struct pci_dev *pci,
|
|---|
| 2907 | unsigned long device_type,
|
|---|
| 2908 | struct intel8x0 **r_intel8x0)
|
|---|
| 2909 | {
|
|---|
| 2910 | struct intel8x0 *chip;
|
|---|
| 2911 | int err;
|
|---|
| 2912 | unsigned int i;
|
|---|
| 2913 | unsigned int int_sta_masks;
|
|---|
| 2914 | struct ichdev *ichdev;
|
|---|
| 2915 | static const struct snd_device_ops ops = {
|
|---|
| 2916 | .dev_free = snd_intel8x0_dev_free,
|
|---|
| 2917 | };
|
|---|
| 2918 |
|
|---|
| 2919 | static const unsigned int bdbars[] = {
|
|---|
| 2920 | 3, /* DEVICE_INTEL */
|
|---|
| 2921 | 6, /* DEVICE_INTEL_ICH4 */
|
|---|
| 2922 | 3, /* DEVICE_SIS */
|
|---|
| 2923 | 6, /* DEVICE_ALI */
|
|---|
| 2924 | 4, /* DEVICE_NFORCE */
|
|---|
| 2925 | };
|
|---|
| 2926 | static const struct ich_reg_info intel_regs[6] = {
|
|---|
| 2927 | { ICH_PIINT, 0 },
|
|---|
| 2928 | { ICH_POINT, 0x10 },
|
|---|
| 2929 | { ICH_MCINT, 0x20 },
|
|---|
| 2930 | { ICH_M2INT, 0x40 },
|
|---|
| 2931 | { ICH_P2INT, 0x50 },
|
|---|
| 2932 | { ICH_SPINT, 0x60 },
|
|---|
| 2933 | };
|
|---|
| 2934 | static const struct ich_reg_info nforce_regs[4] = {
|
|---|
| 2935 | { ICH_PIINT, 0 },
|
|---|
| 2936 | { ICH_POINT, 0x10 },
|
|---|
| 2937 | { ICH_MCINT, 0x20 },
|
|---|
| 2938 | { ICH_NVSPINT, 0x70 },
|
|---|
| 2939 | };
|
|---|
| 2940 | static const struct ich_reg_info ali_regs[6] = {
|
|---|
| 2941 | { ALI_INT_PCMIN, 0x40 },
|
|---|
| 2942 | { ALI_INT_PCMOUT, 0x50 },
|
|---|
| 2943 | { ALI_INT_MICIN, 0x60 },
|
|---|
| 2944 | { ALI_INT_CODECSPDIFOUT, 0x70 },
|
|---|
| 2945 | { ALI_INT_SPDIFIN, 0xa0 },
|
|---|
| 2946 | { ALI_INT_SPDIFOUT, 0xb0 },
|
|---|
| 2947 | };
|
|---|
| 2948 | const struct ich_reg_info *tbl;
|
|---|
| 2949 |
|
|---|
| 2950 | *r_intel8x0 = NULL;
|
|---|
| 2951 |
|
|---|
| 2952 | err = pci_enable_device(pci);
|
|---|
| 2953 | if (err < 0)
|
|---|
| 2954 | return err;
|
|---|
| 2955 |
|
|---|
| 2956 | chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
|---|
| 2957 | if (chip == NULL) {
|
|---|
| 2958 | pci_disable_device(pci);
|
|---|
| 2959 | return -ENOMEM;
|
|---|
| 2960 | }
|
|---|
| 2961 | spin_lock_init(&chip->reg_lock);
|
|---|
| 2962 | chip->device_type = device_type;
|
|---|
| 2963 | chip->card = card;
|
|---|
| 2964 | chip->pci = pci;
|
|---|
| 2965 | chip->irq = -1;
|
|---|
| 2966 |
|
|---|
| 2967 | /* module parameters */
|
|---|
| 2968 | chip->buggy_irq = buggy_irq;
|
|---|
| 2969 | chip->buggy_semaphore = buggy_semaphore;
|
|---|
| 2970 | if (xbox)
|
|---|
| 2971 | chip->xbox = 1;
|
|---|
| 2972 |
|
|---|
| 2973 | chip->inside_vm = snd_intel8x0_inside_vm(pci);
|
|---|
| 2974 |
|
|---|
| 2975 | /*
|
|---|
| 2976 | * Intel 82443MX running a 100MHz processor system bus has a hardware
|
|---|
| 2977 | * bug, which aborts PCI busmaster for audio transfer. A workaround
|
|---|
| 2978 | * is to set the pages as non-cached. For details, see the errata in
|
|---|
| 2979 | * http://download.intel.com/design/chipsets/specupdt/24505108.pdf
|
|---|
| 2980 | */
|
|---|
| 2981 | if (pci->vendor == PCI_VENDOR_ID_INTEL &&
|
|---|
| 2982 | pci->device == PCI_DEVICE_ID_INTEL_440MX)
|
|---|
| 2983 | chip->fix_nocache = 1; /* enable workaround */
|
|---|
| 2984 |
|
|---|
| 2985 | err = pci_request_regions(pci, card->shortname);
|
|---|
| 2986 | if (err < 0) {
|
|---|
| 2987 | kfree(chip);
|
|---|
| 2988 | pci_disable_device(pci);
|
|---|
| 2989 | return err;
|
|---|
| 2990 | }
|
|---|
| 2991 |
|
|---|
| 2992 | if (device_type == DEVICE_ALI) {
|
|---|
| 2993 | /* ALI5455 has no ac97 region */
|
|---|
| 2994 | chip->bmaddr = pci_iomap(pci, 0, 0);
|
|---|
| 2995 | goto port_inited;
|
|---|
| 2996 | }
|
|---|
| 2997 |
|
|---|
| 2998 | if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
|
|---|
| 2999 | chip->addr = pci_iomap(pci, 2, 0);
|
|---|
| 3000 | else
|
|---|
| 3001 | chip->addr = pci_iomap(pci, 0, 0);
|
|---|
| 3002 | if (!chip->addr) {
|
|---|
| 3003 | dev_err(card->dev, "AC'97 space ioremap problem\n");
|
|---|
| 3004 | snd_intel8x0_free(chip);
|
|---|
| 3005 | return -EIO;
|
|---|
| 3006 | }
|
|---|
| 3007 | if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
|
|---|
| 3008 | chip->bmaddr = pci_iomap(pci, 3, 0);
|
|---|
| 3009 | else
|
|---|
| 3010 | chip->bmaddr = pci_iomap(pci, 1, 0);
|
|---|
| 3011 |
|
|---|
| 3012 | port_inited:
|
|---|
| 3013 | if (!chip->bmaddr) {
|
|---|
| 3014 | dev_err(card->dev, "Controller space ioremap problem\n");
|
|---|
| 3015 | snd_intel8x0_free(chip);
|
|---|
| 3016 | return -EIO;
|
|---|
| 3017 | }
|
|---|
| 3018 | chip->bdbars_count = bdbars[device_type];
|
|---|
| 3019 |
|
|---|
| 3020 | /* initialize offsets */
|
|---|
| 3021 | switch (device_type) {
|
|---|
| 3022 | case DEVICE_NFORCE:
|
|---|
| 3023 | tbl = nforce_regs;
|
|---|
| 3024 | break;
|
|---|
| 3025 | case DEVICE_ALI:
|
|---|
| 3026 | tbl = ali_regs;
|
|---|
| 3027 | break;
|
|---|
| 3028 | default:
|
|---|
| 3029 | tbl = intel_regs;
|
|---|
| 3030 | break;
|
|---|
| 3031 | }
|
|---|
| 3032 | for (i = 0; i < chip->bdbars_count; i++) {
|
|---|
| 3033 | ichdev = &chip->ichd[i];
|
|---|
| 3034 | ichdev->ichd = i;
|
|---|
| 3035 | ichdev->reg_offset = tbl[i].offset;
|
|---|
| 3036 | ichdev->int_sta_mask = tbl[i].int_sta_mask;
|
|---|
| 3037 | if (device_type == DEVICE_SIS) {
|
|---|
| 3038 | /* SiS 7012 swaps the registers */
|
|---|
| 3039 | ichdev->roff_sr = ICH_REG_OFF_PICB;
|
|---|
| 3040 | ichdev->roff_picb = ICH_REG_OFF_SR;
|
|---|
| 3041 | } else {
|
|---|
| 3042 | ichdev->roff_sr = ICH_REG_OFF_SR;
|
|---|
| 3043 | ichdev->roff_picb = ICH_REG_OFF_PICB;
|
|---|
| 3044 | }
|
|---|
| 3045 | if (device_type == DEVICE_ALI)
|
|---|
| 3046 | ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
|
|---|
| 3047 | /* SIS7012 handles the pcm data in bytes, others are in samples */
|
|---|
| 3048 | ichdev->pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
|
|---|
| 3049 | }
|
|---|
| 3050 |
|
|---|
| 3051 | /* allocate buffer descriptor lists */
|
|---|
| 3052 | /* the start of each lists must be aligned to 8 bytes */
|
|---|
| 3053 | if (snd_dma_alloc_pages(intel8x0_dma_type(chip), &pci->dev,
|
|---|
| 3054 | chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
|
|---|
| 3055 | &chip->bdbars) < 0) {
|
|---|
| 3056 | snd_intel8x0_free(chip);
|
|---|
| 3057 | dev_err(card->dev, "cannot allocate buffer descriptors\n");
|
|---|
| 3058 | return -ENOMEM;
|
|---|
| 3059 | }
|
|---|
| 3060 | /* tables must be aligned to 8 bytes here, but the kernel pages
|
|---|
| 3061 | are much bigger, so we don't care (on i386) */
|
|---|
| 3062 | int_sta_masks = 0;
|
|---|
| 3063 | for (i = 0; i < chip->bdbars_count; i++) {
|
|---|
| 3064 | ichdev = &chip->ichd[i];
|
|---|
| 3065 | ichdev->bdbar = ((__le32 *)chip->bdbars.area) +
|
|---|
| 3066 | (i * ICH_MAX_FRAGS * 2);
|
|---|
| 3067 | ichdev->bdbar_addr = chip->bdbars.addr +
|
|---|
| 3068 | (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
|
|---|
| 3069 | int_sta_masks |= ichdev->int_sta_mask;
|
|---|
| 3070 | }
|
|---|
| 3071 | chip->int_sta_reg = device_type == DEVICE_ALI ?
|
|---|
| 3072 | ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
|
|---|
| 3073 | chip->int_sta_mask = int_sta_masks;
|
|---|
| 3074 |
|
|---|
| 3075 | pci_set_master(pci);
|
|---|
| 3076 |
|
|---|
| 3077 | switch(chip->device_type) {
|
|---|
| 3078 | case DEVICE_INTEL_ICH4:
|
|---|
| 3079 | /* ICH4 can have three codecs */
|
|---|
| 3080 | chip->max_codecs = 3;
|
|---|
| 3081 | chip->codec_bit = ich_codec_bits;
|
|---|
| 3082 | chip->codec_ready_bits = ICH_PRI | ICH_SRI | ICH_TRI;
|
|---|
| 3083 | break;
|
|---|
| 3084 | case DEVICE_SIS:
|
|---|
| 3085 | /* recent SIS7012 can have three codecs */
|
|---|
| 3086 | chip->max_codecs = 3;
|
|---|
| 3087 | chip->codec_bit = sis_codec_bits;
|
|---|
| 3088 | chip->codec_ready_bits = ICH_PRI | ICH_SRI | ICH_SIS_TRI;
|
|---|
| 3089 | break;
|
|---|
| 3090 | default:
|
|---|
| 3091 | /* others up to two codecs */
|
|---|
| 3092 | chip->max_codecs = 2;
|
|---|
| 3093 | chip->codec_bit = ich_codec_bits;
|
|---|
| 3094 | chip->codec_ready_bits = ICH_PRI | ICH_SRI;
|
|---|
| 3095 | break;
|
|---|
| 3096 | }
|
|---|
| 3097 | for (i = 0; i < chip->max_codecs; i++)
|
|---|
| 3098 | chip->codec_isr_bits |= chip->codec_bit[i];
|
|---|
| 3099 |
|
|---|
| 3100 | err = snd_intel8x0_chip_init(chip, 1);
|
|---|
| 3101 | if (err < 0) {
|
|---|
| 3102 | snd_intel8x0_free(chip);
|
|---|
| 3103 | return err;
|
|---|
| 3104 | }
|
|---|
| 3105 |
|
|---|
| 3106 | /* request irq after initializaing int_sta_mask, etc */
|
|---|
| 3107 | if (request_irq(pci->irq, snd_intel8x0_interrupt,
|
|---|
| 3108 | IRQF_SHARED, KBUILD_MODNAME, chip)) {
|
|---|
| 3109 | dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
|
|---|
| 3110 | snd_intel8x0_free(chip);
|
|---|
| 3111 | return -EBUSY;
|
|---|
| 3112 | }
|
|---|
| 3113 | chip->irq = pci->irq;
|
|---|
| 3114 | card->sync_irq = chip->irq;
|
|---|
| 3115 |
|
|---|
| 3116 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
|
|---|
| 3117 | if (err < 0) {
|
|---|
| 3118 | snd_intel8x0_free(chip);
|
|---|
| 3119 | return err;
|
|---|
| 3120 | }
|
|---|
| 3121 |
|
|---|
| 3122 | *r_intel8x0 = chip;
|
|---|
| 3123 | return 0;
|
|---|
| 3124 | }
|
|---|
| 3125 |
|
|---|
| 3126 | static struct shortname_table {
|
|---|
| 3127 | unsigned int id;
|
|---|
| 3128 | const char *s;
|
|---|
| 3129 | } shortnames[] = {
|
|---|
| 3130 | { PCI_DEVICE_ID_INTEL_82801AA_5, "Intel 82801AA-ICH" },
|
|---|
| 3131 | { PCI_DEVICE_ID_INTEL_82801AB_5, "Intel 82901AB-ICH0" },
|
|---|
| 3132 | { PCI_DEVICE_ID_INTEL_82801BA_4, "Intel 82801BA-ICH2" },
|
|---|
| 3133 | { PCI_DEVICE_ID_INTEL_440MX, "Intel 440MX" },
|
|---|
| 3134 | { PCI_DEVICE_ID_INTEL_82801CA_5, "Intel 82801CA-ICH3" },
|
|---|
| 3135 | { PCI_DEVICE_ID_INTEL_82801DB_5, "Intel 82801DB-ICH4" },
|
|---|
| 3136 | { PCI_DEVICE_ID_INTEL_82801EB_5, "Intel ICH5" },
|
|---|
| 3137 | { PCI_DEVICE_ID_INTEL_ESB_5, "Intel 6300ESB" },
|
|---|
| 3138 | { PCI_DEVICE_ID_INTEL_ICH6_18, "Intel ICH6" },
|
|---|
| 3139 | { PCI_DEVICE_ID_INTEL_ICH7_20, "Intel ICH7" },
|
|---|
| 3140 | { PCI_DEVICE_ID_INTEL_ESB2_14, "Intel ESB2" },
|
|---|
| 3141 | { PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
|
|---|
| 3142 | { PCI_DEVICE_ID_NVIDIA_MCP1_AUDIO, "NVidia nForce" },
|
|---|
| 3143 | { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
|
|---|
| 3144 | { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
|
|---|
| 3145 | { PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO, "NVidia CK8S" },
|
|---|
| 3146 | { PCI_DEVICE_ID_NVIDIA_CK804_AUDIO, "NVidia CK804" },
|
|---|
| 3147 | { PCI_DEVICE_ID_NVIDIA_CK8_AUDIO, "NVidia CK8" },
|
|---|
| 3148 | { 0x003a, "NVidia MCP04" },
|
|---|
| 3149 | { 0x746d, "AMD AMD8111" },
|
|---|
| 3150 | { 0x7445, "AMD AMD768" },
|
|---|
| 3151 | { 0x5455, "ALi M5455" },
|
|---|
| 3152 | { 0, NULL },
|
|---|
| 3153 | };
|
|---|
| 3154 |
|
|---|
| 3155 | static const struct snd_pci_quirk spdif_aclink_defaults[] = {
|
|---|
| 3156 | SND_PCI_QUIRK(0x147b, 0x1c1a, "ASUS KN8", 1),
|
|---|
| 3157 | {0} /* end */
|
|---|
| 3158 | };
|
|---|
| 3159 |
|
|---|
| 3160 | /* look up allow/deny list for SPDIF over ac-link */
|
|---|
| 3161 | static int check_default_spdif_aclink(struct pci_dev *pci)
|
|---|
| 3162 | {
|
|---|
| 3163 | const struct snd_pci_quirk *w;
|
|---|
| 3164 |
|
|---|
| 3165 | w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults);
|
|---|
| 3166 | if (w) {
|
|---|
| 3167 | if (w->value)
|
|---|
| 3168 | dev_dbg(&pci->dev,
|
|---|
| 3169 | "Using SPDIF over AC-Link for %s\n",
|
|---|
| 3170 | snd_pci_quirk_name(w));
|
|---|
| 3171 | else
|
|---|
| 3172 | dev_dbg(&pci->dev,
|
|---|
| 3173 | "Using integrated SPDIF DMA for %s\n",
|
|---|
| 3174 | snd_pci_quirk_name(w));
|
|---|
| 3175 | return w->value;
|
|---|
| 3176 | }
|
|---|
| 3177 | return 0;
|
|---|
| 3178 | }
|
|---|
| 3179 |
|
|---|
| 3180 | static int snd_intel8x0_probe(struct pci_dev *pci,
|
|---|
| 3181 | const struct pci_device_id *pci_id)
|
|---|
| 3182 | {
|
|---|
| 3183 | struct snd_card *card;
|
|---|
| 3184 | struct intel8x0 *chip;
|
|---|
| 3185 | int err;
|
|---|
| 3186 | struct shortname_table *name;
|
|---|
| 3187 |
|
|---|
| 3188 | err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
|
|---|
| 3189 | if (err < 0)
|
|---|
| 3190 | return err;
|
|---|
| 3191 |
|
|---|
| 3192 | if (spdif_aclink < 0)
|
|---|
| 3193 | spdif_aclink = check_default_spdif_aclink(pci);
|
|---|
| 3194 |
|
|---|
| 3195 | strcpy(card->driver, "ICH");
|
|---|
| 3196 | if (!spdif_aclink) {
|
|---|
| 3197 | switch (pci_id->driver_data) {
|
|---|
| 3198 | case DEVICE_NFORCE:
|
|---|
| 3199 | strcpy(card->driver, "NFORCE");
|
|---|
| 3200 | break;
|
|---|
| 3201 | case DEVICE_INTEL_ICH4:
|
|---|
| 3202 | strcpy(card->driver, "ICH4");
|
|---|
| 3203 | }
|
|---|
| 3204 | }
|
|---|
| 3205 |
|
|---|
| 3206 | strcpy(card->shortname, "Intel ICH");
|
|---|
| 3207 | for (name = shortnames; name->id; name++) {
|
|---|
| 3208 | if (pci->device == name->id) {
|
|---|
| 3209 | strcpy(card->shortname, name->s);
|
|---|
| 3210 | break;
|
|---|
| 3211 | }
|
|---|
| 3212 | }
|
|---|
| 3213 |
|
|---|
| 3214 | if (buggy_irq < 0) {
|
|---|
| 3215 | /* some Nforce[2] and ICH boards have problems with IRQ handling.
|
|---|
| 3216 | * Needs to return IRQ_HANDLED for unknown irqs.
|
|---|
| 3217 | */
|
|---|
| 3218 | if (pci_id->driver_data == DEVICE_NFORCE)
|
|---|
| 3219 | buggy_irq = 1;
|
|---|
| 3220 | else
|
|---|
| 3221 | buggy_irq = 0;
|
|---|
| 3222 | }
|
|---|
| 3223 |
|
|---|
| 3224 | err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip);
|
|---|
| 3225 | if (err < 0) {
|
|---|
| 3226 | snd_card_free(card);
|
|---|
| 3227 | return err;
|
|---|
| 3228 | }
|
|---|
| 3229 | card->private_data = chip;
|
|---|
| 3230 |
|
|---|
| 3231 | err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk);
|
|---|
| 3232 | if (err < 0) {
|
|---|
| 3233 | snd_card_free(card);
|
|---|
| 3234 | return err;
|
|---|
| 3235 | }
|
|---|
| 3236 | err = snd_intel8x0_pcm(chip);
|
|---|
| 3237 | if (err < 0) {
|
|---|
| 3238 | snd_card_free(card);
|
|---|
| 3239 | return err;
|
|---|
| 3240 | }
|
|---|
| 3241 |
|
|---|
| 3242 | snd_intel8x0_proc_init(chip);
|
|---|
| 3243 |
|
|---|
| 3244 | snprintf(card->longname, sizeof(card->longname),
|
|---|
| 3245 | "%s with %s at irq %i", card->shortname,
|
|---|
| 3246 | snd_ac97_get_short_name(chip->ac97[0]), chip->irq);
|
|---|
| 3247 |
|
|---|
| 3248 | if (ac97_clock == 0 || ac97_clock == 1) {
|
|---|
| 3249 | if (ac97_clock == 0) {
|
|---|
| 3250 | if (intel8x0_in_clock_list(chip) == 0)
|
|---|
| 3251 | intel8x0_measure_ac97_clock(chip);
|
|---|
| 3252 | } else {
|
|---|
| 3253 | intel8x0_measure_ac97_clock(chip);
|
|---|
| 3254 | }
|
|---|
| 3255 | }
|
|---|
| 3256 |
|
|---|
| 3257 | err = snd_card_register(card);
|
|---|
| 3258 | if (err < 0) {
|
|---|
| 3259 | snd_card_free(card);
|
|---|
| 3260 | return err;
|
|---|
| 3261 | }
|
|---|
| 3262 | pci_set_drvdata(pci, card);
|
|---|
| 3263 | return 0;
|
|---|
| 3264 | }
|
|---|
| 3265 |
|
|---|
| 3266 | static void snd_intel8x0_remove(struct pci_dev *pci)
|
|---|
| 3267 | {
|
|---|
| 3268 | snd_card_free(pci_get_drvdata(pci));
|
|---|
| 3269 | }
|
|---|
| 3270 |
|
|---|
| 3271 | static struct pci_driver intel8x0_driver = {
|
|---|
| 3272 | .name = KBUILD_MODNAME,
|
|---|
| 3273 | .id_table = snd_intel8x0_ids,
|
|---|
| 3274 | .probe = snd_intel8x0_probe,
|
|---|
| 3275 | .remove = snd_intel8x0_remove,
|
|---|
| 3276 | .driver = {
|
|---|
| 3277 | .pm = INTEL8X0_PM_OPS,
|
|---|
| 3278 | },
|
|---|
| 3279 | };
|
|---|
| 3280 |
|
|---|
| 3281 | module_pci_driver(intel8x0_driver);
|
|---|