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