Blame view

sound/pci/intel8x0.c 90.7 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  /*
   *   ALSA driver for Intel ICH (i8x0) chipsets
   *
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
4
   *	Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
   *
   *
   *   This code also contains alpha support for SiS 735 chipsets provided
   *   by Mike Pieper <mptei@users.sourceforge.net>. We have no datasheet
   *   for SiS735, so the code is not fully functional.
   *
   *
   *   This program is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation; either version 2 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License for more details.
   *
   *   You should have received a copy of the GNU General Public License
   *   along with this program; if not, write to the Free Software
   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  
   *
   */      
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include <asm/io.h>
  #include <linux/delay.h>
  #include <linux/interrupt.h>
  #include <linux/init.h>
  #include <linux/pci.h>
  #include <linux/slab.h>
  #include <linux/moduleparam.h>
  #include <sound/core.h>
  #include <sound/pcm.h>
  #include <sound/ac97_codec.h>
  #include <sound/info.h>
  #include <sound/initval.h>
  /* for 440MX workaround */
  #include <asm/pgtable.h>
  #include <asm/cacheflush.h>
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
43
  MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
46
47
48
49
50
51
52
53
54
  MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
  MODULE_LICENSE("GPL");
  MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
  		"{Intel,82901AB-ICH0},"
  		"{Intel,82801BA-ICH2},"
  		"{Intel,82801CA-ICH3},"
  		"{Intel,82801DB-ICH4},"
  		"{Intel,ICH5},"
  		"{Intel,ICH6},"
  		"{Intel,ICH7},"
  		"{Intel,6300ESB},"
c4c8ea948   Jason Gaston   [PATCH] intel8x0:...
55
  		"{Intel,ESB2},"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
57
58
59
  		"{Intel,MX440},"
  		"{SiS,SI7012},"
  		"{NVidia,nForce Audio},"
  		"{NVidia,nForce2 Audio},"
a2854dc5f   Alexander Beregalov   ALSA: sound/pci: ...
60
61
62
63
64
65
  		"{NVidia,nForce3 Audio},"
  		"{NVidia,MCP04},"
  		"{NVidia,MCP501},"
  		"{NVidia,CK804},"
  		"{NVidia,CK8},"
  		"{NVidia,CK8S},"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
  		"{AMD,AMD768},"
  		"{AMD,AMD8111},"
  	        "{ALI,M5455}}");
b7fe46220   Clemens Ladisch   [ALSA] highlander...
69
70
  static int index = SNDRV_DEFAULT_IDX1;	/* Index 0-MAX */
  static char *id = SNDRV_DEFAULT_STR1;	/* ID for this card */
6581f4e74   Takashi Iwai   [ALSA] Remove zer...
71
  static int ac97_clock;
b7fe46220   Clemens Ladisch   [ALSA] highlander...
72
73
  static char *ac97_quirk;
  static int buggy_semaphore;
beef08a54   Takashi Iwai   [ALSA] intel8x0 -...
74
  static int buggy_irq = -1; /* auto-check */
b7fe46220   Clemens Ladisch   [ALSA] highlander...
75
  static int xbox;
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
76
  static int spdif_aclink = -1;
b7fe46220   Clemens Ladisch   [ALSA] highlander...
77
78
  
  module_param(index, int, 0444);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
b7fe46220   Clemens Ladisch   [ALSA] highlander...
80
  module_param(id, charp, 0444);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
b7fe46220   Clemens Ladisch   [ALSA] highlander...
82
  module_param(ac97_clock, int, 0444);
2b3b5485a   Jaroslav Kysela   ALSA: intel8x0: i...
83
  MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = whitelist + auto-detect, 1 = force autodetect).");
b7fe46220   Clemens Ladisch   [ALSA] highlander...
84
  module_param(ac97_quirk, charp, 0444);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
  MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
b7fe46220   Clemens Ladisch   [ALSA] highlander...
86
  module_param(buggy_semaphore, bool, 0444);
a06147d22   Takashi Iwai   [ALSA] intel8x0 -...
87
  MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores.");
b7fe46220   Clemens Ladisch   [ALSA] highlander...
88
  module_param(buggy_irq, bool, 0444);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
  MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
b7fe46220   Clemens Ladisch   [ALSA] highlander...
90
  module_param(xbox, bool, 0444);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
  MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
92
93
  module_param(spdif_aclink, int, 0444);
  MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94

2b3e584b9   Takashi Iwai   [ALSA] Add dummy ...
95
96
  /* just for backward compatibility */
  static int enable;
698444f31   Takashi Iwai   [ALSA] Fix the ty...
97
  module_param(enable, bool, 0444);
2b3e584b9   Takashi Iwai   [ALSA] Add dummy ...
98
99
  static int joystick;
  module_param(joystick, int, 0444);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
  /*
   *  Direct registers
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  enum { DEVICE_INTEL, DEVICE_INTEL_ICH4, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
  
  #define ICHREG(x) ICH_REG_##x
  
  #define DEFINE_REGSET(name,base) \
  enum { \
  	ICH_REG_##name##_BDBAR	= base + 0x0,	/* dword - buffer descriptor list base address */ \
  	ICH_REG_##name##_CIV	= base + 0x04,	/* byte - current index value */ \
  	ICH_REG_##name##_LVI	= base + 0x05,	/* byte - last valid index */ \
  	ICH_REG_##name##_SR	= base + 0x06,	/* byte - status register */ \
  	ICH_REG_##name##_PICB	= base + 0x08,	/* word - position in current buffer */ \
  	ICH_REG_##name##_PIV	= base + 0x0a,	/* byte - prefetched index value */ \
  	ICH_REG_##name##_CR	= base + 0x0b,	/* byte - control register */ \
  };
  
  /* busmaster blocks */
  DEFINE_REGSET(OFF, 0);		/* offset */
  DEFINE_REGSET(PI, 0x00);	/* PCM in */
  DEFINE_REGSET(PO, 0x10);	/* PCM out */
  DEFINE_REGSET(MC, 0x20);	/* Mic in */
  
  /* ICH4 busmaster blocks */
  DEFINE_REGSET(MC2, 0x40);	/* Mic in 2 */
  DEFINE_REGSET(PI2, 0x50);	/* PCM in 2 */
  DEFINE_REGSET(SP, 0x60);	/* SPDIF out */
  
  /* values for each busmaster block */
  
  /* LVI */
  #define ICH_REG_LVI_MASK		0x1f
  
  /* SR */
  #define ICH_FIFOE			0x10	/* FIFO error */
  #define ICH_BCIS			0x08	/* buffer completion interrupt status */
  #define ICH_LVBCI			0x04	/* last valid buffer completion interrupt */
  #define ICH_CELV			0x02	/* current equals last valid */
  #define ICH_DCH				0x01	/* DMA controller halted */
  
  /* PIV */
  #define ICH_REG_PIV_MASK		0x1f	/* mask */
  
  /* CR */
  #define ICH_IOCE			0x10	/* interrupt on completion enable */
  #define ICH_FEIE			0x08	/* fifo error interrupt enable */
  #define ICH_LVBIE			0x04	/* last valid buffer interrupt enable */
  #define ICH_RESETREGS			0x02	/* reset busmaster registers */
  #define ICH_STARTBM			0x01	/* start busmaster operation */
  
  
  /* global block */
  #define ICH_REG_GLOB_CNT		0x2c	/* dword - global control */
  #define   ICH_PCM_SPDIF_MASK	0xc0000000	/* s/pdif pcm slot mask (ICH4) */
  #define   ICH_PCM_SPDIF_NONE	0x00000000	/* reserved - undefined */
  #define   ICH_PCM_SPDIF_78	0x40000000	/* s/pdif pcm on slots 7&8 */
  #define   ICH_PCM_SPDIF_69	0x80000000	/* s/pdif pcm on slots 6&9 */
  #define   ICH_PCM_SPDIF_1011	0xc0000000	/* s/pdif pcm on slots 10&11 */
  #define   ICH_PCM_20BIT		0x00400000	/* 20-bit samples (ICH4) */
4235a3178   Takashi Iwai   [ALSA] intel8x0 -...
160
161
  #define   ICH_PCM_246_MASK	0x00300000	/* chan mask (not all chips) */
  #define   ICH_PCM_8		0x00300000      /* 8 channels (not all chips) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  #define   ICH_PCM_6		0x00200000	/* 6 channels (not all chips) */
  #define   ICH_PCM_4		0x00100000	/* 4 channels (not all chips) */
  #define   ICH_PCM_2		0x00000000	/* 2 channels (stereo) */
  #define   ICH_SIS_PCM_246_MASK	0x000000c0	/* 6 channels (SIS7012) */
  #define   ICH_SIS_PCM_6		0x00000080	/* 6 channels (SIS7012) */
  #define   ICH_SIS_PCM_4		0x00000040	/* 4 channels (SIS7012) */
  #define   ICH_SIS_PCM_2		0x00000000	/* 2 channels (SIS7012) */
  #define   ICH_TRIE		0x00000040	/* tertiary resume interrupt enable */
  #define   ICH_SRIE		0x00000020	/* secondary resume interrupt enable */
  #define   ICH_PRIE		0x00000010	/* primary resume interrupt enable */
  #define   ICH_ACLINK		0x00000008	/* AClink shut off */
  #define   ICH_AC97WARM		0x00000004	/* AC'97 warm reset */
  #define   ICH_AC97COLD		0x00000002	/* AC'97 cold reset */
  #define   ICH_GIE		0x00000001	/* GPI interrupt enable */
  #define ICH_REG_GLOB_STA		0x30	/* dword - global status */
  #define   ICH_TRI		0x20000000	/* ICH4: tertiary (AC_SDIN2) resume interrupt */
  #define   ICH_TCR		0x10000000	/* ICH4: tertiary (AC_SDIN2) codec ready */
  #define   ICH_BCS		0x08000000	/* ICH4: bit clock stopped */
  #define   ICH_SPINT		0x04000000	/* ICH4: S/PDIF interrupt */
  #define   ICH_P2INT		0x02000000	/* ICH4: PCM2-In interrupt */
  #define   ICH_M2INT		0x01000000	/* ICH4: Mic2-In interrupt */
  #define   ICH_SAMPLE_CAP	0x00c00000	/* ICH4: sample capability bits (RO) */
  #define   ICH_SAMPLE_16_20	0x00400000	/* ICH4: 16- and 20-bit samples */
  #define   ICH_MULTICHAN_CAP	0x00300000	/* ICH4: multi-channel capability bits (RO) */
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
186
187
  #define   ICH_SIS_TRI		0x00080000	/* SIS: tertiary resume irq */
  #define   ICH_SIS_TCR		0x00040000	/* SIS: tertiary codec ready */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
  #define   ICH_MD3		0x00020000	/* modem power down semaphore */
  #define   ICH_AD3		0x00010000	/* audio power down semaphore */
  #define   ICH_RCS		0x00008000	/* read completion status */
  #define   ICH_BIT3		0x00004000	/* bit 3 slot 12 */
  #define   ICH_BIT2		0x00002000	/* bit 2 slot 12 */
  #define   ICH_BIT1		0x00001000	/* bit 1 slot 12 */
  #define   ICH_SRI		0x00000800	/* secondary (AC_SDIN1) resume interrupt */
  #define   ICH_PRI		0x00000400	/* primary (AC_SDIN0) resume interrupt */
  #define   ICH_SCR		0x00000200	/* secondary (AC_SDIN1) codec ready */
  #define   ICH_PCR		0x00000100	/* primary (AC_SDIN0) codec ready */
  #define   ICH_MCINT		0x00000080	/* MIC capture interrupt */
  #define   ICH_POINT		0x00000040	/* playback interrupt */
  #define   ICH_PIINT		0x00000020	/* capture interrupt */
  #define   ICH_NVSPINT		0x00000010	/* nforce spdif interrupt */
  #define   ICH_MOINT		0x00000004	/* modem playback interrupt */
  #define   ICH_MIINT		0x00000002	/* modem capture interrupt */
  #define   ICH_GSCI		0x00000001	/* GPI status change interrupt */
  #define ICH_REG_ACC_SEMA		0x34	/* byte - codec write semaphore */
  #define   ICH_CAS		0x01		/* codec access semaphore */
  #define ICH_REG_SDM		0x80
  #define   ICH_DI2L_MASK		0x000000c0	/* PCM In 2, Mic In 2 data in line */
  #define   ICH_DI2L_SHIFT	6
  #define   ICH_DI1L_MASK		0x00000030	/* PCM In 1, Mic In 1 data in line */
  #define   ICH_DI1L_SHIFT	4
  #define   ICH_SE		0x00000008	/* steer enable */
  #define   ICH_LDI_MASK		0x00000003	/* last codec read data input */
  
  #define ICH_MAX_FRAGS		32		/* max hw frags */
  
  
  /*
   * registers for Ali5455
   */
  
  /* ALi 5455 busmaster blocks */
  DEFINE_REGSET(AL_PI, 0x40);	/* ALi PCM in */
  DEFINE_REGSET(AL_PO, 0x50);	/* Ali PCM out */
  DEFINE_REGSET(AL_MC, 0x60);	/* Ali Mic in */
  DEFINE_REGSET(AL_CDC_SPO, 0x70);	/* Ali Codec SPDIF out */
  DEFINE_REGSET(AL_CENTER, 0x80);		/* Ali center out */
  DEFINE_REGSET(AL_LFE, 0x90);		/* Ali center out */
  DEFINE_REGSET(AL_CLR_SPI, 0xa0);	/* Ali Controller SPDIF in */
  DEFINE_REGSET(AL_CLR_SPO, 0xb0);	/* Ali Controller SPDIF out */
  DEFINE_REGSET(AL_I2S, 0xc0);	/* Ali I2S in */
  DEFINE_REGSET(AL_PI2, 0xd0);	/* Ali PCM2 in */
  DEFINE_REGSET(AL_MC2, 0xe0);	/* Ali Mic2 in */
  
  enum {
  	ICH_REG_ALI_SCR = 0x00,		/* System Control Register */
  	ICH_REG_ALI_SSR = 0x04,		/* System Status Register  */
  	ICH_REG_ALI_DMACR = 0x08,	/* DMA Control Register    */
  	ICH_REG_ALI_FIFOCR1 = 0x0c,	/* FIFO Control Register 1  */
  	ICH_REG_ALI_INTERFACECR = 0x10,	/* Interface Control Register */
  	ICH_REG_ALI_INTERRUPTCR = 0x14,	/* Interrupt control Register */
  	ICH_REG_ALI_INTERRUPTSR = 0x18,	/* Interrupt  Status Register */
  	ICH_REG_ALI_FIFOCR2 = 0x1c,	/* FIFO Control Register 2   */
  	ICH_REG_ALI_CPR = 0x20,		/* Command Port Register     */
  	ICH_REG_ALI_CPR_ADDR = 0x22,	/* ac97 addr write */
  	ICH_REG_ALI_SPR = 0x24,		/* Status Port Register      */
  	ICH_REG_ALI_SPR_ADDR = 0x26,	/* ac97 addr read */
  	ICH_REG_ALI_FIFOCR3 = 0x2c,	/* FIFO Control Register 3  */
  	ICH_REG_ALI_TTSR = 0x30,	/* Transmit Tag Slot Register */
  	ICH_REG_ALI_RTSR = 0x34,	/* Receive Tag Slot  Register */
  	ICH_REG_ALI_CSPSR = 0x38,	/* Command/Status Port Status Register */
  	ICH_REG_ALI_CAS = 0x3c,		/* Codec Write Semaphore Register */
  	ICH_REG_ALI_HWVOL = 0xf0,	/* hardware volume control/status */
  	ICH_REG_ALI_I2SCR = 0xf4,	/* I2S control/status */
  	ICH_REG_ALI_SPDIFCSR = 0xf8,	/* spdif channel status register  */
  	ICH_REG_ALI_SPDIFICS = 0xfc,	/* spdif interface control/status  */
  };
  
  #define ALI_CAS_SEM_BUSY	0x80000000
  #define ALI_CPR_ADDR_SECONDARY	0x100
  #define ALI_CPR_ADDR_READ	0x80
  #define ALI_CSPSR_CODEC_READY	0x08
  #define ALI_CSPSR_READ_OK	0x02
  #define ALI_CSPSR_WRITE_OK	0x01
  
  /* interrupts for the whole chip by interrupt status register finish */
   
  #define ALI_INT_MICIN2		(1<<26)
  #define ALI_INT_PCMIN2		(1<<25)
  #define ALI_INT_I2SIN		(1<<24)
  #define ALI_INT_SPDIFOUT	(1<<23)	/* controller spdif out INTERRUPT */
  #define ALI_INT_SPDIFIN		(1<<22)
  #define ALI_INT_LFEOUT		(1<<21)
  #define ALI_INT_CENTEROUT	(1<<20)
  #define ALI_INT_CODECSPDIFOUT	(1<<19)
  #define ALI_INT_MICIN		(1<<18)
  #define ALI_INT_PCMOUT		(1<<17)
  #define ALI_INT_PCMIN		(1<<16)
  #define ALI_INT_CPRAIS		(1<<7)	/* command port available */
  #define ALI_INT_SPRAIS		(1<<5)	/* status port available */
  #define ALI_INT_GPIO		(1<<1)
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
282
283
  #define ALI_INT_MASK		(ALI_INT_SPDIFOUT|ALI_INT_CODECSPDIFOUT|\
  				 ALI_INT_MICIN|ALI_INT_PCMOUT|ALI_INT_PCMIN)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
  
  #define ICH_ALI_SC_RESET	(1<<31)	/* master reset */
  #define ICH_ALI_SC_AC97_DBL	(1<<30)
  #define ICH_ALI_SC_CODEC_SPDF	(3<<20)	/* 1=7/8, 2=6/9, 3=10/11 */
  #define ICH_ALI_SC_IN_BITS	(3<<18)
  #define ICH_ALI_SC_OUT_BITS	(3<<16)
  #define ICH_ALI_SC_6CH_CFG	(3<<14)
  #define ICH_ALI_SC_PCM_4	(1<<8)
  #define ICH_ALI_SC_PCM_6	(2<<8)
  #define ICH_ALI_SC_PCM_246_MASK	(3<<8)
  
  #define ICH_ALI_SS_SEC_ID	(3<<5)
  #define ICH_ALI_SS_PRI_ID	(3<<3)
  
  #define ICH_ALI_IF_AC97SP	(1<<21)
  #define ICH_ALI_IF_MC		(1<<20)
  #define ICH_ALI_IF_PI		(1<<19)
  #define ICH_ALI_IF_MC2		(1<<18)
  #define ICH_ALI_IF_PI2		(1<<17)
  #define ICH_ALI_IF_LINE_SRC	(1<<15)	/* 0/1 = slot 3/6 */
  #define ICH_ALI_IF_MIC_SRC	(1<<14)	/* 0/1 = slot 3/6 */
  #define ICH_ALI_IF_SPDF_SRC	(3<<12)	/* 00 = PCM, 01 = AC97-in, 10 = spdif-in, 11 = i2s */
  #define ICH_ALI_IF_AC97_OUT	(3<<8)	/* 00 = PCM, 10 = spdif-in, 11 = i2s */
  #define ICH_ALI_IF_PO_SPDF	(1<<3)
  #define ICH_ALI_IF_PO		(1<<1)
  
  /*
   *  
   */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
  enum {
  	ICHD_PCMIN,
  	ICHD_PCMOUT,
  	ICHD_MIC,
  	ICHD_MIC2,
  	ICHD_PCM2IN,
  	ICHD_SPBAR,
  	ICHD_LAST = ICHD_SPBAR
  };
  enum {
  	NVD_PCMIN,
  	NVD_PCMOUT,
  	NVD_MIC,
  	NVD_SPBAR,
  	NVD_LAST = NVD_SPBAR
  };
  enum {
  	ALID_PCMIN,
  	ALID_PCMOUT,
  	ALID_MIC,
  	ALID_AC97SPDIFOUT,
  	ALID_SPDIFIN,
  	ALID_SPDIFOUT,
  	ALID_LAST = ALID_SPDIFOUT
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
338

6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
339
  #define get_ichdev(substream) (substream->runtime->private_data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340

6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
341
  struct ichdev {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
342
343
344
345
  	unsigned int ichd;			/* ich device number */
  	unsigned long reg_offset;		/* offset to bmaddr */
  	u32 *bdbar;				/* CPU address (32bit) */
  	unsigned int bdbar_addr;		/* PCI bus address (32bit) */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
346
  	struct snd_pcm_substream *substream;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
348
349
350
351
352
  	unsigned int physbuf;			/* physical address (32bit) */
          unsigned int size;
          unsigned int fragsize;
          unsigned int fragsize1;
          unsigned int position;
  	unsigned int pos_shift;
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
353
  	unsigned int last_pos;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
355
356
357
358
359
360
361
362
363
364
365
366
367
          int frags;
          int lvi;
          int lvi_frag;
  	int civ;
  	int ack;
  	int ack_reload;
  	unsigned int ack_bit;
  	unsigned int roff_sr;
  	unsigned int roff_picb;
  	unsigned int int_sta_mask;		/* interrupt status mask */
  	unsigned int ali_slot;			/* ALI DMA slot */
  	struct ac97_pcm *pcm;
  	int pcm_open_flag;
  	unsigned int page_attr_changed: 1;
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
368
  	unsigned int suspended: 1;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
369
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
370

6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
371
  struct intel8x0 {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
373
374
  	unsigned int device_type;
  
  	int irq;
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
375
376
  	void __iomem *addr;
  	void __iomem *bmaddr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
377
378
  
  	struct pci_dev *pci;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
379
  	struct snd_card *card;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
380
381
  
  	int pcm_devs;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
382
383
  	struct snd_pcm *pcm[6];
  	struct ichdev ichd[6];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
384
385
386
  
  	unsigned multi4: 1,
  		 multi6: 1,
4235a3178   Takashi Iwai   [ALSA] intel8x0 -...
387
  		 multi8 :1,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
388
389
390
391
392
393
394
395
  		 dra: 1,
  		 smp20bit: 1;
  	unsigned in_ac97_init: 1,
  		 in_sdin_init: 1;
  	unsigned in_measurement: 1;	/* during ac97 clock measurement */
  	unsigned fix_nocache: 1; 	/* workaround for 440MX */
  	unsigned buggy_irq: 1;		/* workaround for buggy mobos */
  	unsigned xbox: 1;		/* workaround for Xbox AC'97 detection */
a06147d22   Takashi Iwai   [ALSA] intel8x0 -...
396
  	unsigned buggy_semaphore: 1;	/* workaround for buggy codec semaphore */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
398
  
  	int spdif_idx;	/* SPDIF BAR index; *_SPBAR or -1 if use PCMOUT */
52b723888   Takashi Iwai   [ALSA] Fix resume...
399
  	unsigned int sdm_saved;	/* SDM reg value */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400

6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
401
402
  	struct snd_ac97_bus *ac97_bus;
  	struct snd_ac97 *ac97[3];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403
  	unsigned int ac97_sdin[3];
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
404
405
406
407
  	unsigned int max_codecs, ncodecs;
  	unsigned int *codec_bit;
  	unsigned int codec_isr_bits;
  	unsigned int codec_ready_bits;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
408
409
410
411
412
413
414
415
  
  	spinlock_t reg_lock;
  	
  	u32 bdbars_count;
  	struct snd_dma_buffer bdbars;
  	u32 int_sta_reg;		/* interrupt status register */
  	u32 int_sta_mask;		/* interrupt status mask */
  };
cebe41d4b   Alexey Dobriyan   sound: use DEFINE...
416
  static DEFINE_PCI_DEVICE_TABLE(snd_intel8x0_ids) = {
28d27aae9   Joe Perches   sound: Use PCI_VD...
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
  	{ PCI_VDEVICE(INTEL, 0x2415), DEVICE_INTEL },	/* 82801AA */
  	{ PCI_VDEVICE(INTEL, 0x2425), DEVICE_INTEL },	/* 82901AB */
  	{ PCI_VDEVICE(INTEL, 0x2445), DEVICE_INTEL },	/* 82801BA */
  	{ PCI_VDEVICE(INTEL, 0x2485), DEVICE_INTEL },	/* ICH3 */
  	{ PCI_VDEVICE(INTEL, 0x24c5), DEVICE_INTEL_ICH4 }, /* ICH4 */
  	{ PCI_VDEVICE(INTEL, 0x24d5), DEVICE_INTEL_ICH4 }, /* ICH5 */
  	{ PCI_VDEVICE(INTEL, 0x25a6), DEVICE_INTEL_ICH4 }, /* ESB */
  	{ PCI_VDEVICE(INTEL, 0x266e), DEVICE_INTEL_ICH4 }, /* ICH6 */
  	{ PCI_VDEVICE(INTEL, 0x27de), DEVICE_INTEL_ICH4 }, /* ICH7 */
  	{ PCI_VDEVICE(INTEL, 0x2698), DEVICE_INTEL_ICH4 }, /* ESB2 */
  	{ PCI_VDEVICE(INTEL, 0x7195), DEVICE_INTEL },	/* 440MX */
  	{ PCI_VDEVICE(SI, 0x7012), DEVICE_SIS },	/* SI7012 */
  	{ PCI_VDEVICE(NVIDIA, 0x01b1), DEVICE_NFORCE },	/* NFORCE */
  	{ PCI_VDEVICE(NVIDIA, 0x003a), DEVICE_NFORCE },	/* MCP04 */
  	{ PCI_VDEVICE(NVIDIA, 0x006a), DEVICE_NFORCE },	/* NFORCE2 */
  	{ PCI_VDEVICE(NVIDIA, 0x0059), DEVICE_NFORCE },	/* CK804 */
  	{ PCI_VDEVICE(NVIDIA, 0x008a), DEVICE_NFORCE },	/* CK8 */
  	{ PCI_VDEVICE(NVIDIA, 0x00da), DEVICE_NFORCE },	/* NFORCE3 */
  	{ PCI_VDEVICE(NVIDIA, 0x00ea), DEVICE_NFORCE },	/* CK8S */
  	{ PCI_VDEVICE(NVIDIA, 0x026b), DEVICE_NFORCE },	/* MCP51 */
  	{ PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL },	/* AMD8111 */
  	{ PCI_VDEVICE(AMD, 0x7445), DEVICE_INTEL },	/* AMD768 */
  	{ PCI_VDEVICE(AL, 0x5455), DEVICE_ALI },   /* Ali5455 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
440
441
442
443
444
445
446
447
  	{ 0, }
  };
  
  MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
  
  /*
   *  Lowlevel I/O - busmaster
   */
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
448
  static inline u8 igetbyte(struct intel8x0 *chip, u32 offset)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
449
  {
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
450
  	return ioread8(chip->bmaddr + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
451
  }
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
452
  static inline u16 igetword(struct intel8x0 *chip, u32 offset)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
  {
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
454
  	return ioread16(chip->bmaddr + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
  }
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
456
  static inline u32 igetdword(struct intel8x0 *chip, u32 offset)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
457
  {
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
458
  	return ioread32(chip->bmaddr + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
459
  }
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
460
  static inline void iputbyte(struct intel8x0 *chip, u32 offset, u8 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
461
  {
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
462
  	iowrite8(val, chip->bmaddr + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
463
  }
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
464
  static inline void iputword(struct intel8x0 *chip, u32 offset, u16 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
465
  {
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
466
  	iowrite16(val, chip->bmaddr + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
467
  }
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
468
  static inline void iputdword(struct intel8x0 *chip, u32 offset, u32 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
469
  {
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
470
  	iowrite32(val, chip->bmaddr + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471
472
473
474
475
  }
  
  /*
   *  Lowlevel I/O - AC'97 registers
   */
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
476
  static inline u16 iagetword(struct intel8x0 *chip, u32 offset)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
477
  {
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
478
  	return ioread16(chip->addr + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
479
  }
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
480
  static inline void iaputword(struct intel8x0 *chip, u32 offset, u16 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
481
  {
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
482
  	iowrite16(val, chip->addr + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
483
484
485
486
487
488
489
490
491
  }
  
  /*
   *  Basic I/O
   */
  
  /*
   * access to AC97 codec via normal i/o (for ICH and SIS7012)
   */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
492
  static int snd_intel8x0_codec_semaphore(struct intel8x0 *chip, unsigned int codec)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493
494
495
496
497
498
499
500
  {
  	int time;
  	
  	if (codec > 2)
  		return -EIO;
  	if (chip->in_sdin_init) {
  		/* we don't know the ready bit assignment at the moment */
  		/* so we check any */
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
501
  		codec = chip->codec_isr_bits;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
502
  	} else {
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
503
  		codec = chip->codec_bit[chip->ac97_sdin[codec]];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
504
505
506
507
508
  	}
  
  	/* codec ready ? */
  	if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
  		return -EIO;
a06147d22   Takashi Iwai   [ALSA] intel8x0 -...
509
510
  	if (chip->buggy_semaphore)
  		return 0; /* just ignore ... */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
511
512
513
514
515
516
517
  	/* Anyone holding a semaphore for 1 msec should be shot... */
  	time = 100;
        	do {
        		if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
        			return 0;
  		udelay(10);
  	} while (time--);
25985edce   Lucas De Marchi   Fix common misspe...
518
  	/* access to some forbidden (non existent) ac97 registers will not
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
519
520
  	 * reset the semaphore. So even if you don't get the semaphore, still
  	 * continue the access. We don't need the semaphore anyway. */
99b359ba1   Takashi Iwai   [ALSA] Add missin...
521
522
  	snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
523
524
525
526
527
528
  			igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
  	iagetword(chip, 0);	/* clear semaphore flag */
  	/* I don't care about the semaphore */
  	return -EBUSY;
  }
   
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
529
  static void snd_intel8x0_codec_write(struct snd_ac97 *ac97,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
531
532
  				     unsigned short reg,
  				     unsigned short val)
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
533
  	struct intel8x0 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
534
535
536
  	
  	if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
  		if (! chip->in_ac97_init)
99b359ba1   Takashi Iwai   [ALSA] Add missin...
537
538
  			snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x
  ", ac97->num, reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
539
540
541
  	}
  	iaputword(chip, reg + ac97->num * 0x80, val);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
542
  static unsigned short snd_intel8x0_codec_read(struct snd_ac97 *ac97,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
543
544
  					      unsigned short reg)
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
545
  	struct intel8x0 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
546
547
548
549
550
  	unsigned short res;
  	unsigned int tmp;
  
  	if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
  		if (! chip->in_ac97_init)
99b359ba1   Takashi Iwai   [ALSA] Add missin...
551
552
  			snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x
  ", ac97->num, reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
554
555
556
557
  		res = 0xffff;
  	} else {
  		res = iagetword(chip, reg + ac97->num * 0x80);
  		if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
  			/* reset RCS and preserve other R/WC bits */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
558
  			iputdword(chip, ICHREG(GLOB_STA), tmp &
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
559
  				  ~(chip->codec_ready_bits | ICH_GSCI));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
560
  			if (! chip->in_ac97_init)
99b359ba1   Takashi Iwai   [ALSA] Add missin...
561
562
  				snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x
  ", ac97->num, reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
563
564
565
566
567
  			res = 0xffff;
  		}
  	}
  	return res;
  }
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
568
569
  static void __devinit snd_intel8x0_codec_read_test(struct intel8x0 *chip,
  						   unsigned int codec)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
570
571
572
573
574
575
576
  {
  	unsigned int tmp;
  
  	if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) {
  		iagetword(chip, codec * 0x80);
  		if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
  			/* reset RCS and preserve other R/WC bits */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
577
  			iputdword(chip, ICHREG(GLOB_STA), tmp &
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
578
  				  ~(chip->codec_ready_bits | ICH_GSCI));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
579
580
581
582
583
584
585
  		}
  	}
  }
  
  /*
   * access to AC97 for Ali5455
   */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
586
  static int snd_intel8x0_ali_codec_ready(struct intel8x0 *chip, int mask)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
587
588
589
590
591
592
593
  {
  	int count = 0;
  	for (count = 0; count < 0x7f; count++) {
  		int val = igetbyte(chip, ICHREG(ALI_CSPSR));
  		if (val & mask)
  			return 0;
  	}
79ba34b94   Takashi Iwai   [ALSA] intel8x0 -...
594
595
596
  	if (! chip->in_ac97_init)
  		snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
597
598
  	return -EBUSY;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
599
  static int snd_intel8x0_ali_codec_semaphore(struct intel8x0 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
600
601
  {
  	int time = 100;
79ba34b94   Takashi Iwai   [ALSA] intel8x0 -...
602
603
  	if (chip->buggy_semaphore)
  		return 0; /* just ignore ... */
67d8a3c12   Roel Kluin   ALSA: alsa: time ...
604
  	while (--time && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
605
  		udelay(1);
79ba34b94   Takashi Iwai   [ALSA] intel8x0 -...
606
  	if (! time && ! chip->in_ac97_init)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
607
608
609
610
  		snd_printk(KERN_WARNING "ali_codec_semaphore timeout
  ");
  	return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
611
  static unsigned short snd_intel8x0_ali_codec_read(struct snd_ac97 *ac97, unsigned short reg)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
612
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
613
  	struct intel8x0 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
614
615
616
617
618
619
620
621
622
623
624
625
626
627
  	unsigned short data = 0xffff;
  
  	if (snd_intel8x0_ali_codec_semaphore(chip))
  		goto __err;
  	reg |= ALI_CPR_ADDR_READ;
  	if (ac97->num)
  		reg |= ALI_CPR_ADDR_SECONDARY;
  	iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
  	if (snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_READ_OK))
  		goto __err;
  	data = igetword(chip, ICHREG(ALI_SPR));
   __err:
  	return data;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
628
629
  static void snd_intel8x0_ali_codec_write(struct snd_ac97 *ac97, unsigned short reg,
  					 unsigned short val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
630
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
631
  	struct intel8x0 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
632
633
634
635
636
637
638
639
640
641
642
643
644
645
  
  	if (snd_intel8x0_ali_codec_semaphore(chip))
  		return;
  	iputword(chip, ICHREG(ALI_CPR), val);
  	if (ac97->num)
  		reg |= ALI_CPR_ADDR_SECONDARY;
  	iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
  	snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_WRITE_OK);
  }
  
  
  /*
   * DMA I/O
   */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
646
  static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ichdev) 
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
  {
  	int idx;
  	u32 *bdbar = ichdev->bdbar;
  	unsigned long port = ichdev->reg_offset;
  
  	iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
  	if (ichdev->size == ichdev->fragsize) {
  		ichdev->ack_reload = ichdev->ack = 2;
  		ichdev->fragsize1 = ichdev->fragsize >> 1;
  		for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
  			bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
  			bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  						     ichdev->fragsize1 >> ichdev->pos_shift);
  			bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
  			bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  						     ichdev->fragsize1 >> ichdev->pos_shift);
  		}
  		ichdev->frags = 2;
  	} else {
  		ichdev->ack_reload = ichdev->ack = 1;
  		ichdev->fragsize1 = ichdev->fragsize;
  		for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
669
670
671
  			bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf +
  						     (((idx >> 1) * ichdev->fragsize) %
  						      ichdev->size));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
672
673
  			bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  						     ichdev->fragsize >> ichdev->pos_shift);
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
674
  #if 0
14ab08610   Takashi Iwai   ALSA: intel8x0 - ...
675
676
  			printk(KERN_DEBUG "bdbar[%i] = 0x%x [0x%x]
  ",
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
677
678
  			       idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
679
680
681
682
683
684
685
686
687
  		}
  		ichdev->frags = ichdev->size / ichdev->fragsize;
  	}
  	iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
  	ichdev->civ = 0;
  	iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
  	ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
  	ichdev->position = 0;
  #if 0
14ab08610   Takashi Iwai   ALSA: intel8x0 - ...
688
689
690
691
692
  	printk(KERN_DEBUG "lvi_frag = %i, frags = %i, period_size = 0x%x, "
  	       "period_size1 = 0x%x
  ",
  	       ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
  	       ichdev->fragsize1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
693
694
695
696
697
698
699
700
701
702
  #endif
  	/* clear interrupts */
  	iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  }
  
  #ifdef __i386__
  /*
   * Intel 82443MX running a 100MHz processor system bus has a hardware bug,
   * which aborts PCI busmaster for audio transfer.  A workaround is to set
   * the pages as non-cached.  For details, see the errata in
631dd1a88   Justin P. Mattock   Update broken web...
703
   *	http://download.intel.com/design/chipsets/specupdt/24505108.pdf
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704
705
706
707
   */
  static void fill_nocache(void *buf, int size, int nocache)
  {
  	size = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
6d238cc4d   Arjan van de Ven   x86: convert CPA ...
708
709
710
711
  	if (nocache)
  		set_pages_uc(virt_to_page(buf), size);
  	else
  		set_pages_wb(virt_to_page(buf), size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
712
713
  }
  #else
6d238cc4d   Arjan van de Ven   x86: convert CPA ...
714
  #define fill_nocache(buf, size, nocache) do { ; } while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
715
716
717
718
719
  #endif
  
  /*
   *  Interrupt handler
   */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
720
  static inline void snd_intel8x0_update(struct intel8x0 *chip, struct ichdev *ichdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
721
722
  {
  	unsigned long port = ichdev->reg_offset;
883be7936   Takashi Iwai   [ALSA] intel8x0 -...
723
  	unsigned long flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
724
725
  	int status, civ, i, step;
  	int ack = 0;
883be7936   Takashi Iwai   [ALSA] intel8x0 -...
726
  	spin_lock_irqsave(&chip->reg_lock, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
  	status = igetbyte(chip, port + ichdev->roff_sr);
  	civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
  	if (!(status & ICH_BCIS)) {
  		step = 0;
  	} else if (civ == ichdev->civ) {
  		// snd_printd("civ same %d
  ", civ);
  		step = 1;
  		ichdev->civ++;
  		ichdev->civ &= ICH_REG_LVI_MASK;
  	} else {
  		step = civ - ichdev->civ;
  		if (step < 0)
  			step += ICH_REG_LVI_MASK + 1;
  		// if (step != 1)
  		//	snd_printd("step = %d, %d -> %d
  ", step, ichdev->civ, civ);
  		ichdev->civ = civ;
  	}
  
  	ichdev->position += step * ichdev->fragsize1;
  	if (! chip->in_measurement)
  		ichdev->position %= ichdev->size;
  	ichdev->lvi += step;
  	ichdev->lvi &= ICH_REG_LVI_MASK;
  	iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  	for (i = 0; i < step; i++) {
  		ichdev->lvi_frag++;
  		ichdev->lvi_frag %= ichdev->frags;
  		ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
757
  #if 0
14ab08610   Takashi Iwai   ALSA: intel8x0 - ...
758
759
760
  	printk(KERN_DEBUG "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, "
  	       "all = 0x%x, 0x%x
  ",
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
761
762
763
764
  	       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));
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
765
766
767
768
769
  		if (--ichdev->ack == 0) {
  			ichdev->ack = ichdev->ack_reload;
  			ack = 1;
  		}
  	}
883be7936   Takashi Iwai   [ALSA] intel8x0 -...
770
  	spin_unlock_irqrestore(&chip->reg_lock, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
771
772
773
774
775
776
  	if (ack && ichdev->substream) {
  		snd_pcm_period_elapsed(ichdev->substream);
  	}
  	iputbyte(chip, port + ichdev->roff_sr,
  		 status & (ICH_FIFOE | ICH_BCIS | ICH_LVBCI));
  }
7d12e780e   David Howells   IRQ: Maintain reg...
777
  static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
778
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
779
780
  	struct intel8x0 *chip = dev_id;
  	struct ichdev *ichdev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
  	unsigned int status;
  	unsigned int i;
  
  	status = igetdword(chip, chip->int_sta_reg);
  	if (status == 0xffffffff)	/* we are not yet resumed */
  		return IRQ_NONE;
  
  	if ((status & chip->int_sta_mask) == 0) {
  		if (status) {
  			/* ack */
  			iputdword(chip, chip->int_sta_reg, status);
  			if (! chip->buggy_irq)
  				status = 0;
  		}
  		return IRQ_RETVAL(status);
  	}
  
  	for (i = 0; i < chip->bdbars_count; i++) {
  		ichdev = &chip->ichd[i];
  		if (status & ichdev->int_sta_mask)
  			snd_intel8x0_update(chip, ichdev);
  	}
  
  	/* ack them */
  	iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
  	
  	return IRQ_HANDLED;
  }
  
  /*
   *  PCM part
   */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
813
  static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
814
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
815
816
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  	struct ichdev *ichdev = get_ichdev(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
817
818
819
820
  	unsigned char val = 0;
  	unsigned long port = ichdev->reg_offset;
  
  	switch (cmd) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
821
  	case SNDRV_PCM_TRIGGER_RESUME:
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
822
823
824
  		ichdev->suspended = 0;
  		/* fallthru */
  	case SNDRV_PCM_TRIGGER_START:
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
825
  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
826
  		val = ICH_IOCE | ICH_STARTBM;
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
827
  		ichdev->last_pos = ichdev->position;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
828
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
829
  	case SNDRV_PCM_TRIGGER_SUSPEND:
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
830
831
832
  		ichdev->suspended = 1;
  		/* fallthru */
  	case SNDRV_PCM_TRIGGER_STOP:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
833
834
835
836
837
  		val = 0;
  		break;
  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  		val = ICH_IOCE;
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
838
839
840
841
842
843
844
845
846
847
848
849
  	default:
  		return -EINVAL;
  	}
  	iputbyte(chip, port + ICH_REG_OFF_CR, val);
  	if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  		/* wait until DMA stopped */
  		while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
  		/* reset whole DMA things */
  		iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  	}
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
850
  static int snd_intel8x0_ali_trigger(struct snd_pcm_substream *substream, int cmd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
851
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
852
853
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  	struct ichdev *ichdev = get_ichdev(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
854
  	unsigned long port = ichdev->reg_offset;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
855
856
857
  	static int fiforeg[] = {
  		ICHREG(ALI_FIFOCR1), ICHREG(ALI_FIFOCR2), ICHREG(ALI_FIFOCR3)
  	};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
858
859
860
861
  	unsigned int val, fifo;
  
  	val = igetdword(chip, ICHREG(ALI_DMACR));
  	switch (cmd) {
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
862
863
864
  	case SNDRV_PCM_TRIGGER_RESUME:
  		ichdev->suspended = 0;
  		/* fallthru */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
865
866
  	case SNDRV_PCM_TRIGGER_START:
  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
867
868
869
870
871
872
873
874
875
  		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  			/* clear FIFO for synchronization of channels */
  			fifo = igetdword(chip, fiforeg[ichdev->ali_slot / 4]);
  			fifo &= ~(0xff << (ichdev->ali_slot % 4));  
  			fifo |= 0x83 << (ichdev->ali_slot % 4); 
  			iputdword(chip, fiforeg[ichdev->ali_slot / 4], fifo);
  		}
  		iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
  		val &= ~(1 << (ichdev->ali_slot + 16)); /* clear PAUSE flag */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
876
877
  		/* start DMA */
  		iputdword(chip, ICHREG(ALI_DMACR), val | (1 << ichdev->ali_slot));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
878
  		break;
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
879
880
881
  	case SNDRV_PCM_TRIGGER_SUSPEND:
  		ichdev->suspended = 1;
  		/* fallthru */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
882
883
  	case SNDRV_PCM_TRIGGER_STOP:
  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
884
885
  		/* pause */
  		iputdword(chip, ICHREG(ALI_DMACR), val | (1 << (ichdev->ali_slot + 16)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
886
887
888
889
890
891
892
893
  		iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  		while (igetbyte(chip, port + ICH_REG_OFF_CR))
  			;
  		if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  			break;
  		/* reset whole DMA things */
  		iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  		/* clear interrupts */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
894
895
  		iputbyte(chip, port + ICH_REG_OFF_SR,
  			 igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
896
897
898
899
900
901
902
903
  		iputdword(chip, ICHREG(ALI_INTERRUPTSR),
  			  igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ichdev->int_sta_mask);
  		break;
  	default:
  		return -EINVAL;
  	}
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
904
905
  static int snd_intel8x0_hw_params(struct snd_pcm_substream *substream,
  				  struct snd_pcm_hw_params *hw_params)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
906
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
907
908
909
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  	struct ichdev *ichdev = get_ichdev(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
  	int dbl = params_rate(hw_params) > 48000;
  	int err;
  
  	if (chip->fix_nocache && ichdev->page_attr_changed) {
  		fill_nocache(runtime->dma_area, runtime->dma_bytes, 0); /* clear */
  		ichdev->page_attr_changed = 0;
  	}
  	err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  	if (err < 0)
  		return err;
  	if (chip->fix_nocache) {
  		if (runtime->dma_area && ! ichdev->page_attr_changed) {
  			fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
  			ichdev->page_attr_changed = 1;
  		}
  	}
  	if (ichdev->pcm_open_flag) {
  		snd_ac97_pcm_close(ichdev->pcm);
  		ichdev->pcm_open_flag = 0;
  	}
  	err = snd_ac97_pcm_open(ichdev->pcm, params_rate(hw_params),
  				params_channels(hw_params),
  				ichdev->pcm->r[dbl].slots);
  	if (err >= 0) {
  		ichdev->pcm_open_flag = 1;
  		/* Force SPDIF setting */
  		if (ichdev->ichd == ICHD_PCMOUT && chip->spdif_idx < 0)
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
937
938
  			snd_ac97_set_rate(ichdev->pcm->r[0].codec[0], AC97_SPDIF,
  					  params_rate(hw_params));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
939
940
941
  	}
  	return err;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
942
  static int snd_intel8x0_hw_free(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
943
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
944
945
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  	struct ichdev *ichdev = get_ichdev(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
946
947
948
949
950
951
952
953
954
955
956
  
  	if (ichdev->pcm_open_flag) {
  		snd_ac97_pcm_close(ichdev->pcm);
  		ichdev->pcm_open_flag = 0;
  	}
  	if (chip->fix_nocache && ichdev->page_attr_changed) {
  		fill_nocache(substream->runtime->dma_area, substream->runtime->dma_bytes, 0);
  		ichdev->page_attr_changed = 0;
  	}
  	return snd_pcm_lib_free_pages(substream);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
957
958
  static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,
  				       struct snd_pcm_runtime *runtime)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
959
960
961
  {
  	unsigned int cnt;
  	int dbl = runtime->rate > 48000;
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
962
963
  
  	spin_lock_irq(&chip->reg_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
  	switch (chip->device_type) {
  	case DEVICE_ALI:
  		cnt = igetdword(chip, ICHREG(ALI_SCR));
  		cnt &= ~ICH_ALI_SC_PCM_246_MASK;
  		if (runtime->channels == 4 || dbl)
  			cnt |= ICH_ALI_SC_PCM_4;
  		else if (runtime->channels == 6)
  			cnt |= ICH_ALI_SC_PCM_6;
  		iputdword(chip, ICHREG(ALI_SCR), cnt);
  		break;
  	case DEVICE_SIS:
  		cnt = igetdword(chip, ICHREG(GLOB_CNT));
  		cnt &= ~ICH_SIS_PCM_246_MASK;
  		if (runtime->channels == 4 || dbl)
  			cnt |= ICH_SIS_PCM_4;
  		else if (runtime->channels == 6)
  			cnt |= ICH_SIS_PCM_6;
  		iputdword(chip, ICHREG(GLOB_CNT), cnt);
  		break;
  	default:
  		cnt = igetdword(chip, ICHREG(GLOB_CNT));
  		cnt &= ~(ICH_PCM_246_MASK | ICH_PCM_20BIT);
  		if (runtime->channels == 4 || dbl)
  			cnt |= ICH_PCM_4;
  		else if (runtime->channels == 6)
  			cnt |= ICH_PCM_6;
4235a3178   Takashi Iwai   [ALSA] intel8x0 -...
990
991
  		else if (runtime->channels == 8)
  			cnt |= ICH_PCM_8;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
  		if (chip->device_type == DEVICE_NFORCE) {
  			/* reset to 2ch once to keep the 6 channel data in alignment,
  			 * to start from Front Left always
  			 */
  			if (cnt & ICH_PCM_246_MASK) {
  				iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
  				spin_unlock_irq(&chip->reg_lock);
  				msleep(50); /* grrr... */
  				spin_lock_irq(&chip->reg_lock);
  			}
  		} else if (chip->device_type == DEVICE_INTEL_ICH4) {
  			if (runtime->sample_bits > 16)
  				cnt |= ICH_PCM_20BIT;
  		}
  		iputdword(chip, ICHREG(GLOB_CNT), cnt);
  		break;
  	}
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
1009
  	spin_unlock_irq(&chip->reg_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1010
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1011
  static int snd_intel8x0_pcm_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1012
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1013
1014
1015
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
  	struct ichdev *ichdev = get_ichdev(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1016
1017
1018
1019
  
  	ichdev->physbuf = runtime->dma_addr;
  	ichdev->size = snd_pcm_lib_buffer_bytes(substream);
  	ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1020
1021
  	if (ichdev->ichd == ICHD_PCMOUT) {
  		snd_intel8x0_setup_pcm_out(chip, runtime);
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
1022
  		if (chip->device_type == DEVICE_INTEL_ICH4)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1023
  			ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1024
1025
  	}
  	snd_intel8x0_setup_periods(chip, ichdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1026
1027
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1028
  static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1029
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1030
1031
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  	struct ichdev *ichdev = get_ichdev(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1032
  	size_t ptr1, ptr;
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
1033
  	int civ, timeout = 10;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
  	unsigned int position;
  
  	spin_lock(&chip->reg_lock);
  	do {
  		civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
  		ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
  		position = ichdev->position;
  		if (ptr1 == 0) {
  			udelay(10);
  			continue;
  		}
  		if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
  		    ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
  			break;
  	} while (timeout--);
f708eb1d7   Takashi Iwai   ALSA: intel8x0 - ...
1049
  	ptr = ichdev->last_pos;
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
1050
1051
1052
1053
  	if (ptr1 != 0) {
  		ptr1 <<= ichdev->pos_shift;
  		ptr = ichdev->fragsize1 - ptr1;
  		ptr += position;
f708eb1d7   Takashi Iwai   ALSA: intel8x0 - ...
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
  		if (ptr < ichdev->last_pos) {
  			unsigned int pos_base, last_base;
  			pos_base = position / ichdev->fragsize1;
  			last_base = ichdev->last_pos / ichdev->fragsize1;
  			/* another sanity check; ptr1 can go back to full
  			 * before the base position is updated
  			 */
  			if (pos_base == last_base)
  				ptr = ichdev->last_pos;
  		}
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
1064
  	}
f708eb1d7   Takashi Iwai   ALSA: intel8x0 - ...
1065
  	ichdev->last_pos = ptr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1066
1067
1068
1069
1070
  	spin_unlock(&chip->reg_lock);
  	if (ptr >= ichdev->size)
  		return 0;
  	return bytes_to_frames(substream->runtime, ptr);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1071
  static struct snd_pcm_hardware snd_intel8x0_stream =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
  {
  	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
  				 SNDRV_PCM_INFO_MMAP_VALID |
  				 SNDRV_PCM_INFO_PAUSE |
  				 SNDRV_PCM_INFO_RESUME),
  	.formats =		SNDRV_PCM_FMTBIT_S16_LE,
  	.rates =		SNDRV_PCM_RATE_48000,
  	.rate_min =		48000,
  	.rate_max =		48000,
  	.channels_min =		2,
  	.channels_max =		2,
  	.buffer_bytes_max =	128 * 1024,
  	.period_bytes_min =	32,
  	.period_bytes_max =	128 * 1024,
  	.periods_min =		1,
  	.periods_max =		1024,
  	.fifo_size =		0,
  };
  
  static unsigned int channels4[] = {
  	2, 4,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1095
  static struct snd_pcm_hw_constraint_list hw_constraints_channels4 = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1096
1097
1098
1099
1100
1101
1102
1103
  	.count = ARRAY_SIZE(channels4),
  	.list = channels4,
  	.mask = 0,
  };
  
  static unsigned int channels6[] = {
  	2, 4, 6,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1104
  static struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1105
1106
1107
1108
  	.count = ARRAY_SIZE(channels6),
  	.list = channels6,
  	.mask = 0,
  };
4235a3178   Takashi Iwai   [ALSA] intel8x0 -...
1109
1110
1111
1112
1113
1114
1115
1116
1117
  static unsigned int channels8[] = {
  	2, 4, 6, 8,
  };
  
  static struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
  	.count = ARRAY_SIZE(channels8),
  	.list = channels8,
  	.mask = 0,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1118
  static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1119
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1120
1121
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
  	int err;
  
  	ichdev->substream = substream;
  	runtime->hw = snd_intel8x0_stream;
  	runtime->hw.rates = ichdev->pcm->rates;
  	snd_pcm_limit_hw_rates(runtime);
  	if (chip->device_type == DEVICE_SIS) {
  		runtime->hw.buffer_bytes_max = 64*1024;
  		runtime->hw.period_bytes_max = 64*1024;
  	}
  	if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  		return err;
  	runtime->private_data = ichdev;
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1137
  static int snd_intel8x0_playback_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1138
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1139
1140
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1141
1142
1143
1144
1145
  	int err;
  
  	err = snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMOUT]);
  	if (err < 0)
  		return err;
4235a3178   Takashi Iwai   [ALSA] intel8x0 -...
1146
1147
1148
1149
1150
1151
  	if (chip->multi8) {
  		runtime->hw.channels_max = 8;
  		snd_pcm_hw_constraint_list(runtime, 0,
  						SNDRV_PCM_HW_PARAM_CHANNELS,
  						&hw_constraints_channels8);
  	} else if (chip->multi6) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1152
  		runtime->hw.channels_max = 6;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1153
1154
  		snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  					   &hw_constraints_channels6);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1155
1156
  	} else if (chip->multi4) {
  		runtime->hw.channels_max = 4;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1157
1158
  		snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  					   &hw_constraints_channels4);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
  	}
  	if (chip->dra) {
  		snd_ac97_pcm_double_rate_rules(runtime);
  	}
  	if (chip->smp20bit) {
  		runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE;
  		snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
  	}
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1169
  static int snd_intel8x0_playback_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1170
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1171
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1172
1173
1174
1175
  
  	chip->ichd[ICHD_PCMOUT].substream = NULL;
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1176
  static int snd_intel8x0_capture_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1177
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1178
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1179
1180
1181
  
  	return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMIN]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1182
  static int snd_intel8x0_capture_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1183
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1184
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1185
1186
1187
1188
  
  	chip->ichd[ICHD_PCMIN].substream = NULL;
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1189
  static int snd_intel8x0_mic_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1190
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1191
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1192
1193
1194
  
  	return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1195
  static int snd_intel8x0_mic_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1196
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1197
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1198
1199
1200
1201
  
  	chip->ichd[ICHD_MIC].substream = NULL;
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1202
  static int snd_intel8x0_mic2_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1203
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1204
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1205
1206
1207
  
  	return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC2]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1208
  static int snd_intel8x0_mic2_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1209
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1210
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1211
1212
1213
1214
  
  	chip->ichd[ICHD_MIC2].substream = NULL;
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1215
  static int snd_intel8x0_capture2_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1216
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1217
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1218
1219
1220
  
  	return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCM2IN]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1221
  static int snd_intel8x0_capture2_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1222
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1223
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1224
1225
1226
1227
  
  	chip->ichd[ICHD_PCM2IN].substream = NULL;
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1228
  static int snd_intel8x0_spdif_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1229
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1230
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1231
1232
1233
1234
  	int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
  
  	return snd_intel8x0_pcm_open(substream, &chip->ichd[idx]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1235
  static int snd_intel8x0_spdif_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1236
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1237
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1238
1239
1240
1241
1242
  	int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
  
  	chip->ichd[idx].substream = NULL;
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1243
  static int snd_intel8x0_ali_ac97spdifout_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1244
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1245
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
  	unsigned int val;
  
  	spin_lock_irq(&chip->reg_lock);
  	val = igetdword(chip, ICHREG(ALI_INTERFACECR));
  	val |= ICH_ALI_IF_AC97SP;
  	iputdword(chip, ICHREG(ALI_INTERFACECR), val);
  	/* also needs to set ALI_SC_CODEC_SPDF correctly */
  	spin_unlock_irq(&chip->reg_lock);
  
  	return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_AC97SPDIFOUT]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1257
  static int snd_intel8x0_ali_ac97spdifout_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1258
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1259
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
  	unsigned int val;
  
  	chip->ichd[ALID_AC97SPDIFOUT].substream = NULL;
  	spin_lock_irq(&chip->reg_lock);
  	val = igetdword(chip, ICHREG(ALI_INTERFACECR));
  	val &= ~ICH_ALI_IF_AC97SP;
  	iputdword(chip, ICHREG(ALI_INTERFACECR), val);
  	spin_unlock_irq(&chip->reg_lock);
  
  	return 0;
  }
1a183131f   Takashi Iwai   [ALSA] intel8x0 -...
1271
  #if 0 // NYI
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1272
  static int snd_intel8x0_ali_spdifin_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1273
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1274
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1275
1276
1277
  
  	return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFIN]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1278
  static int snd_intel8x0_ali_spdifin_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1279
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1280
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1281
1282
1283
1284
  
  	chip->ichd[ALID_SPDIFIN].substream = NULL;
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1285
  static int snd_intel8x0_ali_spdifout_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1286
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1287
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1288
1289
1290
  
  	return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFOUT]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1291
  static int snd_intel8x0_ali_spdifout_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1292
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1293
  	struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1294
1295
1296
1297
1298
  
  	chip->ichd[ALID_SPDIFOUT].substream = NULL;
  	return 0;
  }
  #endif
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1299
  static struct snd_pcm_ops snd_intel8x0_playback_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1300
1301
1302
1303
1304
1305
1306
1307
1308
  	.open =		snd_intel8x0_playback_open,
  	.close =	snd_intel8x0_playback_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_pcm_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1309
  static struct snd_pcm_ops snd_intel8x0_capture_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1310
1311
1312
1313
1314
1315
1316
1317
1318
  	.open =		snd_intel8x0_capture_open,
  	.close =	snd_intel8x0_capture_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_pcm_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1319
  static struct snd_pcm_ops snd_intel8x0_capture_mic_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1320
1321
1322
1323
1324
1325
1326
1327
1328
  	.open =		snd_intel8x0_mic_open,
  	.close =	snd_intel8x0_mic_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_pcm_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1329
  static struct snd_pcm_ops snd_intel8x0_capture_mic2_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1330
1331
1332
1333
1334
1335
1336
1337
1338
  	.open =		snd_intel8x0_mic2_open,
  	.close =	snd_intel8x0_mic2_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_pcm_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1339
  static struct snd_pcm_ops snd_intel8x0_capture2_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1340
1341
1342
1343
1344
1345
1346
1347
1348
  	.open =		snd_intel8x0_capture2_open,
  	.close =	snd_intel8x0_capture2_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_pcm_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1349
  static struct snd_pcm_ops snd_intel8x0_spdif_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1350
1351
1352
1353
1354
1355
1356
1357
1358
  	.open =		snd_intel8x0_spdif_open,
  	.close =	snd_intel8x0_spdif_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_pcm_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1359
  static struct snd_pcm_ops snd_intel8x0_ali_playback_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1360
1361
1362
1363
1364
1365
1366
1367
1368
  	.open =		snd_intel8x0_playback_open,
  	.close =	snd_intel8x0_playback_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_ali_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1369
  static struct snd_pcm_ops snd_intel8x0_ali_capture_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1370
1371
1372
1373
1374
1375
1376
1377
1378
  	.open =		snd_intel8x0_capture_open,
  	.close =	snd_intel8x0_capture_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_ali_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1379
  static struct snd_pcm_ops snd_intel8x0_ali_capture_mic_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1380
1381
1382
1383
1384
1385
1386
1387
1388
  	.open =		snd_intel8x0_mic_open,
  	.close =	snd_intel8x0_mic_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_ali_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1389
  static struct snd_pcm_ops snd_intel8x0_ali_ac97spdifout_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1390
1391
1392
1393
1394
1395
1396
1397
1398
  	.open =		snd_intel8x0_ali_ac97spdifout_open,
  	.close =	snd_intel8x0_ali_ac97spdifout_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_ali_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
1a183131f   Takashi Iwai   [ALSA] intel8x0 -...
1399
  #if 0 // NYI
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1400
  static struct snd_pcm_ops snd_intel8x0_ali_spdifin_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1401
1402
1403
1404
1405
1406
1407
1408
1409
  	.open =		snd_intel8x0_ali_spdifin_open,
  	.close =	snd_intel8x0_ali_spdifin_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_pcm_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1410
  static struct snd_pcm_ops snd_intel8x0_ali_spdifout_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
  	.open =		snd_intel8x0_ali_spdifout_open,
  	.close =	snd_intel8x0_ali_spdifout_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_intel8x0_hw_params,
  	.hw_free =	snd_intel8x0_hw_free,
  	.prepare =	snd_intel8x0_pcm_prepare,
  	.trigger =	snd_intel8x0_pcm_trigger,
  	.pointer =	snd_intel8x0_pcm_pointer,
  };
  #endif // NYI
  
  struct ich_pcm_table {
  	char *suffix;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1424
1425
  	struct snd_pcm_ops *playback_ops;
  	struct snd_pcm_ops *capture_ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1426
1427
1428
1429
  	size_t prealloc_size;
  	size_t prealloc_max_size;
  	int ac97_idx;
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1430
1431
  static int __devinit snd_intel8x0_pcm1(struct intel8x0 *chip, int device,
  				       struct ich_pcm_table *rec)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1432
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1433
  	struct snd_pcm *pcm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
  	int err;
  	char name[32];
  
  	if (rec->suffix)
  		sprintf(name, "Intel ICH - %s", rec->suffix);
  	else
  		strcpy(name, "Intel ICH");
  	err = snd_pcm_new(chip->card, name, device,
  			  rec->playback_ops ? 1 : 0,
  			  rec->capture_ops ? 1 : 0, &pcm);
  	if (err < 0)
  		return err;
  
  	if (rec->playback_ops)
  		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
  	if (rec->capture_ops)
  		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
  
  	pcm->private_data = chip;
  	pcm->info_flags = 0;
  	if (rec->suffix)
  		sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
  	else
  		strcpy(pcm->name, chip->card->shortname);
  	chip->pcm[device] = pcm;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1459
1460
  	snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  					      snd_dma_pci_data(chip->pci),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
  					      rec->prealloc_size, rec->prealloc_max_size);
  
  	return 0;
  }
  
  static struct ich_pcm_table intel_pcms[] __devinitdata = {
  	{
  		.playback_ops = &snd_intel8x0_playback_ops,
  		.capture_ops = &snd_intel8x0_capture_ops,
  		.prealloc_size = 64 * 1024,
  		.prealloc_max_size = 128 * 1024,
  	},
  	{
  		.suffix = "MIC ADC",
  		.capture_ops = &snd_intel8x0_capture_mic_ops,
  		.prealloc_size = 0,
  		.prealloc_max_size = 128 * 1024,
  		.ac97_idx = ICHD_MIC,
  	},
  	{
  		.suffix = "MIC2 ADC",
  		.capture_ops = &snd_intel8x0_capture_mic2_ops,
  		.prealloc_size = 0,
  		.prealloc_max_size = 128 * 1024,
  		.ac97_idx = ICHD_MIC2,
  	},
  	{
  		.suffix = "ADC2",
  		.capture_ops = &snd_intel8x0_capture2_ops,
  		.prealloc_size = 0,
  		.prealloc_max_size = 128 * 1024,
  		.ac97_idx = ICHD_PCM2IN,
  	},
  	{
  		.suffix = "IEC958",
  		.playback_ops = &snd_intel8x0_spdif_ops,
  		.prealloc_size = 64 * 1024,
  		.prealloc_max_size = 128 * 1024,
  		.ac97_idx = ICHD_SPBAR,
  	},
  };
  
  static struct ich_pcm_table nforce_pcms[] __devinitdata = {
  	{
  		.playback_ops = &snd_intel8x0_playback_ops,
  		.capture_ops = &snd_intel8x0_capture_ops,
  		.prealloc_size = 64 * 1024,
  		.prealloc_max_size = 128 * 1024,
  	},
  	{
  		.suffix = "MIC ADC",
  		.capture_ops = &snd_intel8x0_capture_mic_ops,
  		.prealloc_size = 0,
  		.prealloc_max_size = 128 * 1024,
  		.ac97_idx = NVD_MIC,
  	},
  	{
  		.suffix = "IEC958",
  		.playback_ops = &snd_intel8x0_spdif_ops,
  		.prealloc_size = 64 * 1024,
  		.prealloc_max_size = 128 * 1024,
  		.ac97_idx = NVD_SPBAR,
  	},
  };
  
  static struct ich_pcm_table ali_pcms[] __devinitdata = {
  	{
  		.playback_ops = &snd_intel8x0_ali_playback_ops,
  		.capture_ops = &snd_intel8x0_ali_capture_ops,
  		.prealloc_size = 64 * 1024,
  		.prealloc_max_size = 128 * 1024,
  	},
  	{
  		.suffix = "MIC ADC",
  		.capture_ops = &snd_intel8x0_ali_capture_mic_ops,
  		.prealloc_size = 0,
  		.prealloc_max_size = 128 * 1024,
  		.ac97_idx = ALID_MIC,
  	},
  	{
  		.suffix = "IEC958",
  		.playback_ops = &snd_intel8x0_ali_ac97spdifout_ops,
1a183131f   Takashi Iwai   [ALSA] intel8x0 -...
1543
  		/* .capture_ops = &snd_intel8x0_ali_spdifin_ops, */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
  		.prealloc_size = 64 * 1024,
  		.prealloc_max_size = 128 * 1024,
  		.ac97_idx = ALID_AC97SPDIFOUT,
  	},
  #if 0 // NYI
  	{
  		.suffix = "HW IEC958",
  		.playback_ops = &snd_intel8x0_ali_spdifout_ops,
  		.prealloc_size = 64 * 1024,
  		.prealloc_max_size = 128 * 1024,
  	},
  #endif
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1557
  static int __devinit snd_intel8x0_pcm(struct intel8x0 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1558
1559
1560
1561
1562
1563
1564
1565
  {
  	int i, tblsize, device, err;
  	struct ich_pcm_table *tbl, *rec;
  
  	switch (chip->device_type) {
  	case DEVICE_INTEL_ICH4:
  		tbl = intel_pcms;
  		tblsize = ARRAY_SIZE(intel_pcms);
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
1566
1567
  		if (spdif_aclink)
  			tblsize--;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1568
1569
1570
1571
  		break;
  	case DEVICE_NFORCE:
  		tbl = nforce_pcms;
  		tblsize = ARRAY_SIZE(nforce_pcms);
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
1572
1573
  		if (spdif_aclink)
  			tblsize--;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
  		break;
  	case DEVICE_ALI:
  		tbl = ali_pcms;
  		tblsize = ARRAY_SIZE(ali_pcms);
  		break;
  	default:
  		tbl = intel_pcms;
  		tblsize = 2;
  		break;
  	}
  
  	device = 0;
  	for (i = 0; i < tblsize; i++) {
  		rec = tbl + i;
  		if (i > 0 && rec->ac97_idx) {
  			/* activate PCM only when associated AC'97 codec */
  			if (! chip->ichd[rec->ac97_idx].pcm)
  				continue;
  		}
  		err = snd_intel8x0_pcm1(chip, device, rec);
  		if (err < 0)
  			return err;
  		device++;
  	}
  
  	chip->pcm_devs = device;
  	return 0;
  }
  	
  
  /*
   *  Mixer part
   */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1607
  static void snd_intel8x0_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1608
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1609
  	struct intel8x0 *chip = bus->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1610
1611
  	chip->ac97_bus = NULL;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1612
  static void snd_intel8x0_mixer_free_ac97(struct snd_ac97 *ac97)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1613
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
1614
  	struct intel8x0 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
  	chip->ac97[ac97->num] = NULL;
  }
  
  static struct ac97_pcm ac97_pcm_defs[] __devinitdata = {
  	/* front PCM */
  	{
  		.exclusive = 1,
  		.r = {	{
  				.slots = (1 << AC97_SLOT_PCM_LEFT) |
  					 (1 << AC97_SLOT_PCM_RIGHT) |
  					 (1 << AC97_SLOT_PCM_CENTER) |
  					 (1 << AC97_SLOT_PCM_SLEFT) |
  					 (1 << AC97_SLOT_PCM_SRIGHT) |
  					 (1 << AC97_SLOT_LFE)
  			},
  			{
  				.slots = (1 << AC97_SLOT_PCM_LEFT) |
  					 (1 << AC97_SLOT_PCM_RIGHT) |
  					 (1 << AC97_SLOT_PCM_LEFT_0) |
  					 (1 << AC97_SLOT_PCM_RIGHT_0)
  			}
  		}
  	},
  	/* PCM IN #1 */
  	{
  		.stream = 1,
  		.exclusive = 1,
  		.r = {	{
  				.slots = (1 << AC97_SLOT_PCM_LEFT) |
  					 (1 << AC97_SLOT_PCM_RIGHT)
  			}
  		}
  	},
  	/* MIC IN #1 */
  	{
  		.stream = 1,
  		.exclusive = 1,
  		.r = {	{
  				.slots = (1 << AC97_SLOT_MIC)
  			}
  		}
  	},
  	/* S/PDIF PCM */
  	{
  		.exclusive = 1,
  		.spdif = 1,
  		.r = {	{
  				.slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
  					 (1 << AC97_SLOT_SPDIF_RIGHT2)
  			}
  		}
  	},
  	/* PCM IN #2 */
  	{
  		.stream = 1,
  		.exclusive = 1,
  		.r = {	{
  				.slots = (1 << AC97_SLOT_PCM_LEFT) |
  					 (1 << AC97_SLOT_PCM_RIGHT)
  			}
  		}
  	},
  	/* MIC IN #2 */
  	{
  		.stream = 1,
  		.exclusive = 1,
  		.r = {	{
  				.slots = (1 << AC97_SLOT_MIC)
  			}
  		}
  	},
  };
  
  static struct ac97_quirk ac97_quirks[] __devinitdata = {
0d9ac27af   Takashi Iwai   [ALSA] intel8x0 -...
1689
1690
1691
1692
1693
1694
          {
  		.subvendor = 0x0e11,
  		.subdevice = 0x000e,
  		.name = "Compaq Deskpro EN",	/* AD1885 */
  		.type = AC97_TUNE_HP_ONLY
          },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1695
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1696
1697
  		.subvendor = 0x0e11,
  		.subdevice = 0x008a,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1698
1699
1700
1701
  		.name = "Compaq Evo W4000",	/* AD1885 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1702
1703
  		.subvendor = 0x0e11,
  		.subdevice = 0x00b8,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1704
1705
1706
1707
  		.name = "Compaq Evo D510C",
  		.type = AC97_TUNE_HP_ONLY
  	},
          {
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1708
1709
  		.subvendor = 0x0e11,
  		.subdevice = 0x0860,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1710
1711
1712
1713
  		.name = "HP/Compaq nx7010",
  		.type = AC97_TUNE_MUTE_LED
          },
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1714
  		.subvendor = 0x1014,
9c77b846e   Daniel T Chen   ALSA: intel8x0: M...
1715
1716
1717
1718
1719
1720
  		.subdevice = 0x0534,
  		.name = "ThinkPad X31",
  		.type = AC97_TUNE_INV_EAPD
  	},
  	{
  		.subvendor = 0x1014,
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1721
  		.subdevice = 0x1f00,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1722
1723
1724
1725
  		.name = "MS-9128",
  		.type = AC97_TUNE_ALC_JACK
  	},
  	{
5d529390d   Takashi Iwai   [ALSA] intel8x0 -...
1726
1727
1728
1729
  		.subvendor = 0x1014,
  		.subdevice = 0x0267,
  		.name = "IBM NetVista A30p",	/* AD1981B */
  		.type = AC97_TUNE_HP_ONLY
b6a370b6f   Takashi Iwai   [ALSA] intel8x0 -...
1730
1731
1732
1733
1734
1735
  	},
  	{
  		.subvendor = 0x1025,
  		.subdevice = 0x0082,
  		.name = "Acer Travelmate 2310",
  		.type = AC97_TUNE_HP_ONLY
5d529390d   Takashi Iwai   [ALSA] intel8x0 -...
1736
1737
  	},
  	{
72c8986ca   Dick Streefland   [ALSA] intel8x0 -...
1738
1739
1740
1741
1742
1743
  		.subvendor = 0x1025,
  		.subdevice = 0x0083,
  		.name = "Acer Aspire 3003LCi",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1744
1745
  		.subvendor = 0x1028,
  		.subdevice = 0x00d8,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1746
1747
1748
1749
  		.name = "Dell Precision 530",	/* AD1885 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1750
1751
  		.subvendor = 0x1028,
  		.subdevice = 0x010d,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1752
1753
1754
1755
  		.name = "Dell",	/* which model?  AD1885 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1756
1757
  		.subvendor = 0x1028,
  		.subdevice = 0x0126,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1758
1759
1760
1761
  		.name = "Dell Optiplex GX260",	/* AD1981A */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1762
1763
  		.subvendor = 0x1028,
  		.subdevice = 0x012c,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1764
1765
1766
1767
  		.name = "Dell Precision 650",	/* AD1981A */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1768
1769
  		.subvendor = 0x1028,
  		.subdevice = 0x012d,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1770
1771
1772
1773
  		.name = "Dell Precision 450",	/* AD1981B*/
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1774
1775
  		.subvendor = 0x1028,
  		.subdevice = 0x0147,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1776
1777
1778
1779
  		.name = "Dell",	/* which model?  AD1981B*/
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1780
  		.subvendor = 0x1028,
c9fe51c49   Chris Ball   [ALSA] intel8x0: ...
1781
1782
1783
1784
1785
1786
  		.subdevice = 0x0151,
  		.name = "Dell Optiplex GX270",  /* AD1981B */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
  		.subvendor = 0x1028,
1781a9af1   Daniel T Chen   [ALSA] sound/pci/...
1787
1788
1789
1790
1791
1792
  		.subdevice = 0x014e,
  		.name = "Dell D800", /* STAC9750/51 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
  		.subvendor = 0x1028,
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1793
  		.subdevice = 0x0163,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1794
1795
1796
1797
  		.name = "Dell Unknown",	/* STAC9750/51 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6d6f91562   Karoly Lorentey   [ALSA] intel8x0 -...
1798
  		.subvendor = 0x1028,
c82834251   Daniel T Chen   ALSA: Intel8x0: A...
1799
1800
1801
  		.subdevice = 0x016a,
  		.name = "Dell Inspiron 8600",	/* STAC9750/51 */
  		.type = AC97_TUNE_HP_ONLY
0613a5945   Daniel T Chen   ALSA: ac97: Apply...
1802
1803
1804
1805
1806
1807
  	},
  	{
  		.subvendor = 0x1028,
  		.subdevice = 0x0182,
  		.name = "Dell Latitude D610",	/* STAC9750/51 */
  		.type = AC97_TUNE_HP_ONLY
c82834251   Daniel T Chen   ALSA: Intel8x0: A...
1808
1809
1810
  	},
  	{
  		.subvendor = 0x1028,
8286c53e5   Daniel T Chen   [ALSA] Include qu...
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
  		.subdevice = 0x0186,
  		.name = "Dell Latitude D810", /* cf. Malone #41015 */
  		.type = AC97_TUNE_HP_MUTE_LED
  	},
  	{
  		.subvendor = 0x1028,
  		.subdevice = 0x0188,
  		.name = "Dell Inspiron 6000",
  		.type = AC97_TUNE_HP_MUTE_LED /* cf. Malone #41015 */
  	},
  	{
  		.subvendor = 0x1028,
f21169aa8   Daniel T Chen   ALSA: intel8x0: A...
1823
1824
1825
1826
1827
1828
  		.subdevice = 0x0189,
  		.name = "Dell Inspiron 9300",
  		.type = AC97_TUNE_HP_MUTE_LED
  	},
  	{
  		.subvendor = 0x1028,
6d6f91562   Karoly Lorentey   [ALSA] intel8x0 -...
1829
1830
1831
1832
1833
  		.subdevice = 0x0191,
  		.name = "Dell Inspiron 8600",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1834
1835
  		.subvendor = 0x103c,
  		.subdevice = 0x006d,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1836
1837
1838
1839
  		.name = "HP zv5000",
  		.type = AC97_TUNE_MUTE_LED	/*AD1981B*/
  	},
  	{	/* FIXME: which codec? */
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1840
1841
  		.subvendor = 0x103c,
  		.subdevice = 0x00c3,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1842
1843
1844
1845
  		.name = "HP xw6000",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1846
1847
  		.subvendor = 0x103c,
  		.subdevice = 0x088c,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1848
  		.name = "HP nc8000",
8286c53e5   Daniel T Chen   [ALSA] Include qu...
1849
  		.type = AC97_TUNE_HP_MUTE_LED
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1850
1851
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1852
1853
  		.subvendor = 0x103c,
  		.subdevice = 0x0890,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1854
1855
1856
1857
  		.name = "HP nc6000",
  		.type = AC97_TUNE_MUTE_LED
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1858
1859
  		.subvendor = 0x103c,
  		.subdevice = 0x129d,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1860
1861
1862
1863
  		.name = "HP xw8000",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1864
  		.subvendor = 0x103c,
a0faefedf   Matthew Garrett   [ALSA] Add a new ...
1865
1866
1867
1868
1869
1870
1871
  		.subdevice = 0x0938,
  		.name = "HP nc4200",
  		.type = AC97_TUNE_HP_MUTE_LED
  	},
  	{
  		.subvendor = 0x103c,
  		.subdevice = 0x099c,
d82ed2ffc   Ulrich Mueller   [ALSA] intel8x0 -...
1872
  		.name = "HP nx6110/nc6120",
a0faefedf   Matthew Garrett   [ALSA] Add a new ...
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
  		.type = AC97_TUNE_HP_MUTE_LED
  	},
  	{
  		.subvendor = 0x103c,
  		.subdevice = 0x0944,
  		.name = "HP nc6220",
  		.type = AC97_TUNE_HP_MUTE_LED
  	},
  	{
  		.subvendor = 0x103c,
  		.subdevice = 0x0934,
  		.name = "HP nc8220",
  		.type = AC97_TUNE_HP_MUTE_LED
  	},
  	{
  		.subvendor = 0x103c,
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1889
  		.subdevice = 0x12f1,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1890
1891
1892
1893
  		.name = "HP xw8200",	/* AD1981B*/
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1894
1895
  		.subvendor = 0x103c,
  		.subdevice = 0x12f2,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1896
1897
1898
1899
  		.name = "HP xw6200",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1900
1901
  		.subvendor = 0x103c,
  		.subdevice = 0x3008,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1902
1903
1904
1905
  		.name = "HP xw4200",	/* AD1981B*/
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1906
  		.subvendor = 0x104d,
7e6c3989a   Daniel T Chen   ALSA: intel8x0: M...
1907
1908
1909
1910
1911
1912
  		.subdevice = 0x8144,
  		.name = "Sony",
  		.type = AC97_TUNE_INV_EAPD
  	},
  	{
  		.subvendor = 0x104d,
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1913
  		.subdevice = 0x8197,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1914
1915
1916
  		.name = "Sony S1XP",
  		.type = AC97_TUNE_INV_EAPD
  	},
5da5b6f9e   Daniel T Chen   ALSA: intel8x0 - ...
1917
1918
1919
1920
1921
1922
  	{
  		.subvendor = 0x104d,
  		.subdevice = 0x81c0,
  		.name = "Sony VAIO VGN-T350P", /*AD1981B*/
  		.type = AC97_TUNE_INV_EAPD
  	},
ebb6f6acb   Daniel T Chen   ALSA: intel8x0 - ...
1923
1924
1925
1926
1927
1928
  	{
  		.subvendor = 0x104d,
  		.subdevice = 0x81c5,
  		.name = "Sony VAIO VGN-B1VP", /*AD1981B*/
  		.type = AC97_TUNE_INV_EAPD
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1929
   	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1930
1931
  		.subvendor = 0x1043,
  		.subdevice = 0x80f3,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1932
1933
1934
1935
  		.name = "ASUS ICH5/AD1985",
  		.type = AC97_TUNE_AD_SHARING
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1936
1937
  		.subvendor = 0x10cf,
  		.subdevice = 0x11c3,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1938
1939
1940
1941
  		.name = "Fujitsu-Siemens E4010",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1942
  		.subvendor = 0x10cf,
98c7f2121   Takashi Iwai   [ALSA] Add FSC T3...
1943
1944
1945
1946
1947
1948
  		.subdevice = 0x1225,
  		.name = "Fujitsu-Siemens T3010",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
  		.subvendor = 0x10cf,
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1949
  		.subdevice = 0x1253,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1950
1951
1952
1953
  		.name = "Fujitsu S6210",	/* STAC9750/51 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
9970dce56   Takashi Iwai   [ALSA] intel8x0 -...
1954
  		.subvendor = 0x10cf,
37c34ffb3   Takashi Iwai   ALSA: intel8x0 - ...
1955
1956
1957
1958
1959
1960
  		.subdevice = 0x127d,
  		.name = "Fujitsu Lifebook P7010",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
  		.subvendor = 0x10cf,
8286c53e5   Daniel T Chen   [ALSA] Include qu...
1961
1962
1963
1964
1965
1966
  		.subdevice = 0x127e,
  		.name = "Fujitsu Lifebook C1211D",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
  		.subvendor = 0x10cf,
9970dce56   Takashi Iwai   [ALSA] intel8x0 -...
1967
1968
1969
1970
1971
  		.subdevice = 0x12ec,
  		.name = "Fujitsu-Siemens 4010",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
2eb061f41   Jaroslav Kysela   [ALSA] intel8x0 -...
1972
1973
1974
1975
1976
1977
  		.subvendor = 0x10cf,
  		.subdevice = 0x12f2,
  		.name = "Fujitsu-Siemens Celsius H320",
  		.type = AC97_TUNE_SWAP_HP
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1978
1979
  		.subvendor = 0x10f1,
  		.subdevice = 0x2665,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1980
1981
1982
1983
  		.name = "Fujitsu-Siemens Celsius",	/* AD1981? */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
1984
1985
  		.subvendor = 0x10f1,
  		.subdevice = 0x2885,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1986
1987
1988
1989
  		.name = "AMD64 Mobo",	/* ALC650 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
4f42bcc19   Takashi Iwai   [ALSA] intel8x0 -...
1990
1991
1992
1993
1994
1995
  		.subvendor = 0x10f1,
  		.subdevice = 0x2895,
  		.name = "Tyan Thunder K8WE",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6c5044472   Keith Packard   [PATCH] Merge hea...
1996
1997
1998
1999
2000
2001
  		.subvendor = 0x10f7,
  		.subdevice = 0x834c,
  		.name = "Panasonic CF-R4",
  		.type = AC97_TUNE_HP_ONLY,
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2002
2003
  		.subvendor = 0x110a,
  		.subdevice = 0x0056,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2004
2005
2006
2007
  		.name = "Fujitsu-Siemens Scenic",	/* AD1981? */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2008
2009
  		.subvendor = 0x11d4,
  		.subdevice = 0x5375,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2010
2011
2012
2013
  		.name = "ADI AD1985 (discrete)",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2014
2015
  		.subvendor = 0x1462,
  		.subdevice = 0x5470,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2016
2017
2018
2019
  		.name = "MSI P4 ATX 645 Ultra",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
bbb3c644b   Daniel T Chen   ALSA: intel8x0: M...
2020
2021
2022
2023
2024
2025
  		.subvendor = 0x161f,
  		.subdevice = 0x203a,
  		.name = "Gateway 4525GZ",		/* AD1981B */
  		.type = AC97_TUNE_INV_EAPD
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2026
2027
  		.subvendor = 0x1734,
  		.subdevice = 0x0088,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2028
2029
2030
2031
  		.name = "Fujitsu-Siemens D1522",	/* AD1981 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2032
2033
  		.subvendor = 0x8086,
  		.subdevice = 0x2000,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2034
2035
2036
2037
2038
  		.mask = 0xfff0,
  		.name = "Intel ICH5/AD1985",
  		.type = AC97_TUNE_AD_SHARING
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2039
2040
  		.subvendor = 0x8086,
  		.subdevice = 0x4000,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2041
2042
2043
2044
2045
  		.mask = 0xfff0,
  		.name = "Intel ICH5/AD1985",
  		.type = AC97_TUNE_AD_SHARING
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2046
2047
  		.subvendor = 0x8086,
  		.subdevice = 0x4856,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2048
2049
2050
2051
  		.name = "Intel D845WN (82801BA)",
  		.type = AC97_TUNE_SWAP_HP
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2052
2053
  		.subvendor = 0x8086,
  		.subdevice = 0x4d44,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2054
2055
2056
2057
  		.name = "Intel D850EMV2",	/* AD1885 */
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2058
2059
  		.subvendor = 0x8086,
  		.subdevice = 0x4d56,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2060
2061
2062
2063
  		.name = "Intel ICH/AD1885",
  		.type = AC97_TUNE_HP_ONLY
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2064
2065
  		.subvendor = 0x8086,
  		.subdevice = 0x6000,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2066
2067
2068
2069
2070
  		.mask = 0xfff0,
  		.name = "Intel ICH5/AD1985",
  		.type = AC97_TUNE_AD_SHARING
  	},
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2071
2072
  		.subvendor = 0x8086,
  		.subdevice = 0xe000,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2073
2074
2075
2076
2077
2078
  		.mask = 0xfff0,
  		.name = "Intel ICH5/AD1985",
  		.type = AC97_TUNE_AD_SHARING
  	},
  #if 0 /* FIXME: this seems wrong on most boards */
  	{
6fd8b87f0   James Courtier-Dutton   [ALSA] AC97 - ren...
2079
2080
  		.subvendor = 0x8086,
  		.subdevice = 0xa000,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2081
2082
2083
2084
2085
2086
2087
  		.mask = 0xfff0,
  		.name = "Intel ICH5/AD1985",
  		.type = AC97_TUNE_HP_ONLY
  	},
  #endif
  	{ } /* terminator */
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2088
2089
  static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
  					const char *quirk_override)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2090
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2091
2092
  	struct snd_ac97_bus *pbus;
  	struct snd_ac97_template ac97;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2093
2094
2095
  	int err;
  	unsigned int i, codecs;
  	unsigned int glob_sta = 0;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2096
2097
  	struct snd_ac97_bus_ops *ops;
  	static struct snd_ac97_bus_ops standard_bus_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2098
2099
2100
  		.write = snd_intel8x0_codec_write,
  		.read = snd_intel8x0_codec_read,
  	};
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2101
  	static struct snd_ac97_bus_ops ali_bus_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2102
2103
2104
2105
2106
  		.write = snd_intel8x0_ali_codec_write,
  		.read = snd_intel8x0_ali_codec_read,
  	};
  
  	chip->spdif_idx = -1; /* use PCMOUT (or disabled) */
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
  	if (!spdif_aclink) {
  		switch (chip->device_type) {
  		case DEVICE_NFORCE:
  			chip->spdif_idx = NVD_SPBAR;
  			break;
  		case DEVICE_ALI:
  			chip->spdif_idx = ALID_AC97SPDIFOUT;
  			break;
  		case DEVICE_INTEL_ICH4:
  			chip->spdif_idx = ICHD_SPBAR;
  			break;
  		};
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2120
2121
2122
2123
2124
2125
  
  	chip->in_ac97_init = 1;
  	
  	memset(&ac97, 0, sizeof(ac97));
  	ac97.private_data = chip;
  	ac97.private_free = snd_intel8x0_mixer_free_ac97;
f1a63a38d   Takashi Iwai   [ALSA] ac97 - Sup...
2126
  	ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2127
2128
2129
2130
2131
  	if (chip->xbox)
  		ac97.scaps |= AC97_SCAP_DETECT_BY_VENDOR;
  	if (chip->device_type != DEVICE_ALI) {
  		glob_sta = igetdword(chip, ICHREG(GLOB_STA));
  		ops = &standard_bus_ops;
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2132
2133
2134
2135
2136
2137
2138
2139
2140
  		chip->in_sdin_init = 1;
  		codecs = 0;
  		for (i = 0; i < chip->max_codecs; i++) {
  			if (! (glob_sta & chip->codec_bit[i]))
  				continue;
  			if (chip->device_type == DEVICE_INTEL_ICH4) {
  				snd_intel8x0_codec_read_test(chip, codecs);
  				chip->ac97_sdin[codecs] =
  					igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
2141
2142
  				if (snd_BUG_ON(chip->ac97_sdin[codecs] >= 3))
  					chip->ac97_sdin[codecs] = 0;
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2143
2144
2145
  			} else
  				chip->ac97_sdin[codecs] = i;
  			codecs++;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2146
  		}
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2147
2148
2149
  		chip->in_sdin_init = 0;
  		if (! codecs)
  			codecs = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
  	} else {
  		ops = &ali_bus_ops;
  		codecs = 1;
  		/* detect the secondary codec */
  		for (i = 0; i < 100; i++) {
  			unsigned int reg = igetdword(chip, ICHREG(ALI_RTSR));
  			if (reg & 0x40) {
  				codecs = 2;
  				break;
  			}
  			iputdword(chip, ICHREG(ALI_RTSR), reg | 0x40);
  			udelay(1);
  		}
  	}
  	if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0)
  		goto __err;
  	pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2167
2168
2169
2170
2171
2172
2173
2174
  	if (ac97_clock >= 8000 && ac97_clock <= 48000)
  		pbus->clock = ac97_clock;
  	/* FIXME: my test board doesn't work well with VRA... */
  	if (chip->device_type == DEVICE_ALI)
  		pbus->no_vra = 1;
  	else
  		pbus->dra = 1;
  	chip->ac97_bus = pbus;
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2175
  	chip->ncodecs = codecs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
  
  	ac97.pci = chip->pci;
  	for (i = 0; i < codecs; i++) {
  		ac97.num = i;
  		if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
  			if (err != -EACCES)
  				snd_printk(KERN_ERR "Unable to initialize codec #%d
  ", i);
  			if (i == 0)
  				goto __err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
  		}
  	}
  	/* tune up the primary codec */
  	snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
  	/* enable separate SDINs for ICH4 */
  	if (chip->device_type == DEVICE_INTEL_ICH4)
  		pbus->isdin = 1;
  	/* find the available PCM streams */
  	i = ARRAY_SIZE(ac97_pcm_defs);
  	if (chip->device_type != DEVICE_INTEL_ICH4)
  		i -= 2;		/* do not allocate PCM2IN and MIC2 */
  	if (chip->spdif_idx < 0)
  		i--;		/* do not allocate S/PDIF */
  	err = snd_ac97_pcm_assign(pbus, i, ac97_pcm_defs);
  	if (err < 0)
  		goto __err;
  	chip->ichd[ICHD_PCMOUT].pcm = &pbus->pcms[0];
  	chip->ichd[ICHD_PCMIN].pcm = &pbus->pcms[1];
  	chip->ichd[ICHD_MIC].pcm = &pbus->pcms[2];
  	if (chip->spdif_idx >= 0)
  		chip->ichd[chip->spdif_idx].pcm = &pbus->pcms[3];
  	if (chip->device_type == DEVICE_INTEL_ICH4) {
  		chip->ichd[ICHD_PCM2IN].pcm = &pbus->pcms[4];
  		chip->ichd[ICHD_MIC2].pcm = &pbus->pcms[5];
  	}
  	/* enable separate SDINs for ICH4 */
  	if (chip->device_type == DEVICE_INTEL_ICH4) {
  		struct ac97_pcm *pcm = chip->ichd[ICHD_PCM2IN].pcm;
  		u8 tmp = igetbyte(chip, ICHREG(SDM));
  		tmp &= ~(ICH_DI2L_MASK|ICH_DI1L_MASK);
  		if (pcm) {
  			tmp |= ICH_SE;	/* steer enable for multiple SDINs */
  			tmp |= chip->ac97_sdin[0] << ICH_DI1L_SHIFT;
  			for (i = 1; i < 4; i++) {
  				if (pcm->r[0].codec[i]) {
  					tmp |= chip->ac97_sdin[pcm->r[0].codec[1]->num] << ICH_DI2L_SHIFT;
  					break;
  				}
  			}
  		} else {
  			tmp &= ~ICH_SE; /* steer disable */
  		}
  		iputbyte(chip, ICHREG(SDM), tmp);
  	}
  	if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
  		chip->multi4 = 1;
4235a3178   Takashi Iwai   [ALSA] intel8x0 -...
2232
  		if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2233
  			chip->multi6 = 1;
4235a3178   Takashi Iwai   [ALSA] intel8x0 -...
2234
2235
2236
  			if (chip->ac97[0]->flags & AC97_HAS_8CH)
  				chip->multi8 = 1;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2237
2238
2239
2240
2241
2242
2243
2244
  	}
  	if (pbus->pcms[0].r[1].rslots[0]) {
  		chip->dra = 1;
  	}
  	if (chip->device_type == DEVICE_INTEL_ICH4) {
  		if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
  			chip->smp20bit = 1;
  	}
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
2245
  	if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2246
2247
2248
  		/* 48kHz only */
  		chip->ichd[chip->spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
  	}
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
2249
  	if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
  		/* use slot 10/11 for SPDIF */
  		u32 val;
  		val = igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK;
  		val |= ICH_PCM_SPDIF_1011;
  		iputdword(chip, ICHREG(GLOB_CNT), val);
  		snd_ac97_update_bits(chip->ac97[0], AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
  	}
  	chip->in_ac97_init = 0;
  	return 0;
  
   __err:
  	/* clear the cold-reset bit for the next chance */
  	if (chip->device_type != DEVICE_ALI)
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2263
2264
  		iputdword(chip, ICHREG(GLOB_CNT),
  			  igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2265
2266
2267
2268
2269
2270
2271
  	return err;
  }
  
  
  /*
   *
   */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2272
  static void do_ali_reset(struct intel8x0 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2273
2274
2275
2276
2277
2278
  {
  	iputdword(chip, ICHREG(ALI_SCR), ICH_ALI_SC_RESET);
  	iputdword(chip, ICHREG(ALI_FIFOCR1), 0x83838383);
  	iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
  	iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
  	iputdword(chip, ICHREG(ALI_INTERFACECR),
d78bec210   Wei Ni   [ALSA] intel8x0 -...
2279
  		  ICH_ALI_IF_PI|ICH_ALI_IF_PO);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2280
2281
2282
  	iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
  	iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
  }
e3e9c5e70   Thadeu Lima de Souza Cascardo   ALSA: Don't cold ...
2283
2284
2285
2286
2287
  #ifdef CONFIG_SND_AC97_POWER_SAVE
  static struct snd_pci_quirk ich_chip_reset_mode[] = {
  	SND_PCI_QUIRK(0x1014, 0x051f, "Thinkpad R32", 1),
  	{ } /* end */
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2288

e3e9c5e70   Thadeu Lima de Souza Cascardo   ALSA: Don't cold ...
2289
2290
2291
  static int snd_intel8x0_ich_chip_cold_reset(struct intel8x0 *chip)
  {
  	unsigned int cnt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2292
  	/* ACLink on, 2 channels */
e3e9c5e70   Thadeu Lima de Souza Cascardo   ALSA: Don't cold ...
2293
2294
2295
  
  	if (snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
  		return -EIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2296
2297
  	cnt = igetdword(chip, ICHREG(GLOB_CNT));
  	cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
e3e9c5e70   Thadeu Lima de Souza Cascardo   ALSA: Don't cold ...
2298

6dbe66287   Takashi Iwai   [ALSA] Add experi...
2299
2300
2301
2302
2303
2304
2305
2306
  	/* do cold reset - the full ac97 powerdown may leave the controller
  	 * in a warm state but actually it cannot communicate with the codec.
  	 */
  	iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_AC97COLD);
  	cnt = igetdword(chip, ICHREG(GLOB_CNT));
  	udelay(10);
  	iputdword(chip, ICHREG(GLOB_CNT), cnt | ICH_AC97COLD);
  	msleep(1);
e3e9c5e70   Thadeu Lima de Souza Cascardo   ALSA: Don't cold ...
2307
2308
2309
2310
  	return 0;
  }
  #define snd_intel8x0_ich_chip_can_cold_reset(chip) \
  	(!snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
6dbe66287   Takashi Iwai   [ALSA] Add experi...
2311
  #else
e16728007   Takashi Iwai   ALSA: intel8x0 - ...
2312
  #define snd_intel8x0_ich_chip_cold_reset(chip)	0
e3e9c5e70   Thadeu Lima de Souza Cascardo   ALSA: Don't cold ...
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
  #define snd_intel8x0_ich_chip_can_cold_reset(chip) (0)
  #endif
  
  static int snd_intel8x0_ich_chip_reset(struct intel8x0 *chip)
  {
  	unsigned long end_time;
  	unsigned int cnt;
  	/* ACLink on, 2 channels */
  	cnt = igetdword(chip, ICHREG(GLOB_CNT));
  	cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2323
2324
2325
2326
2327
2328
  	/* finish cold or do warm reset */
  	cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
  	iputdword(chip, ICHREG(GLOB_CNT), cnt);
  	end_time = (jiffies + (HZ / 4)) + 1;
  	do {
  		if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
e3e9c5e70   Thadeu Lima de Souza Cascardo   ALSA: Don't cold ...
2329
  			return 0;
954bea355   Takashi Iwai   [ALSA] intel8x0 -...
2330
  		schedule_timeout_uninterruptible(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2331
  	} while (time_after_eq(end_time, jiffies));
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2332
2333
2334
  	snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]
  ",
  		   igetdword(chip, ICHREG(GLOB_CNT)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2335
  	return -EIO;
e3e9c5e70   Thadeu Lima de Souza Cascardo   ALSA: Don't cold ...
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
  }
  
  static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
  {
  	unsigned long end_time;
  	unsigned int status, nstatus;
  	unsigned int cnt;
  	int err;
  
  	/* put logic to right state */
  	/* first clear status bits */
  	status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
  	if (chip->device_type == DEVICE_NFORCE)
  		status |= ICH_NVSPINT;
  	cnt = igetdword(chip, ICHREG(GLOB_STA));
  	iputdword(chip, ICHREG(GLOB_STA), cnt & status);
  
  	if (snd_intel8x0_ich_chip_can_cold_reset(chip))
  		err = snd_intel8x0_ich_chip_cold_reset(chip);
  	else
  		err = snd_intel8x0_ich_chip_reset(chip);
  	if (err < 0)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2359

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2360
2361
2362
2363
2364
2365
2366
  	if (probing) {
  		/* wait for any codec ready status.
  		 * Once it becomes ready it should remain ready
  		 * as long as we do not disable the ac97 link.
  		 */
  		end_time = jiffies + HZ;
  		do {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2367
  			status = igetdword(chip, ICHREG(GLOB_STA)) &
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2368
  				chip->codec_isr_bits;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2369
2370
  			if (status)
  				break;
954bea355   Takashi Iwai   [ALSA] intel8x0 -...
2371
  			schedule_timeout_uninterruptible(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2372
2373
2374
  		} while (time_after_eq(end_time, jiffies));
  		if (! status) {
  			/* no codec is found */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2375
2376
2377
  			snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]
  ",
  				   igetdword(chip, ICHREG(GLOB_STA)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2378
2379
  			return -EIO;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2380
2381
  		/* wait for other codecs ready status. */
  		end_time = jiffies + HZ / 4;
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2382
2383
  		while (status != chip->codec_isr_bits &&
  		       time_after_eq(end_time, jiffies)) {
954bea355   Takashi Iwai   [ALSA] intel8x0 -...
2384
  			schedule_timeout_uninterruptible(1);
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2385
2386
  			status |= igetdword(chip, ICHREG(GLOB_STA)) &
  				chip->codec_isr_bits;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2387
2388
2389
2390
2391
2392
  		}
  
  	} else {
  		/* resume phase */
  		int i;
  		status = 0;
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2393
  		for (i = 0; i < chip->ncodecs; i++)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2394
  			if (chip->ac97[i])
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2395
  				status |= chip->codec_bit[chip->ac97_sdin[i]];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2396
2397
2398
  		/* wait until all the probed codecs are ready */
  		end_time = jiffies + HZ;
  		do {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2399
  			nstatus = igetdword(chip, ICHREG(GLOB_STA)) &
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2400
  				chip->codec_isr_bits;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2401
2402
  			if (status == nstatus)
  				break;
954bea355   Takashi Iwai   [ALSA] intel8x0 -...
2403
  			schedule_timeout_uninterruptible(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2404
2405
2406
2407
2408
2409
2410
  		} while (time_after_eq(end_time, jiffies));
  	}
  
  	if (chip->device_type == DEVICE_SIS) {
  		/* unmute the output on SIS7012 */
  		iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
  	}
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
2411
  	if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2412
2413
2414
2415
2416
2417
2418
2419
  		/* enable SPDIF interrupt */
  		unsigned int val;
  		pci_read_config_dword(chip->pci, 0x4c, &val);
  		val |= 0x1000000;
  		pci_write_config_dword(chip->pci, 0x4c, val);
  	}
        	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2420
  static int snd_intel8x0_ali_chip_init(struct intel8x0 *chip, int probing)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
  {
  	u32 reg;
  	int i = 0;
  
  	reg = igetdword(chip, ICHREG(ALI_SCR));
  	if ((reg & 2) == 0)	/* Cold required */
  		reg |= 2;
  	else
  		reg |= 1;	/* Warm */
  	reg &= ~0x80000000;	/* ACLink on */
  	iputdword(chip, ICHREG(ALI_SCR), reg);
  
  	for (i = 0; i < HZ / 2; i++) {
  		if (! (igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ALI_INT_GPIO))
  			goto __ok;
954bea355   Takashi Iwai   [ALSA] intel8x0 -...
2436
  		schedule_timeout_uninterruptible(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
  	}
  	snd_printk(KERN_ERR "AC'97 reset failed.
  ");
  	if (probing)
  		return -EIO;
  
   __ok:
  	for (i = 0; i < HZ / 2; i++) {
  		reg = igetdword(chip, ICHREG(ALI_RTSR));
  		if (reg & 0x80) /* primary codec */
  			break;
  		iputdword(chip, ICHREG(ALI_RTSR), reg | 0x80);
954bea355   Takashi Iwai   [ALSA] intel8x0 -...
2449
  		schedule_timeout_uninterruptible(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2450
2451
2452
2453
2454
  	}
  
  	do_ali_reset(chip);
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2455
  static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2456
  {
253b999f5   Jaroslav Kysela   [ALSA] intel8x0 -...
2457
  	unsigned int i, timeout;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
  	int err;
  	
  	if (chip->device_type != DEVICE_ALI) {
  		if ((err = snd_intel8x0_ich_chip_init(chip, probing)) < 0)
  			return err;
  		iagetword(chip, 0);	/* clear semaphore flag */
  	} else {
  		if ((err = snd_intel8x0_ali_chip_init(chip, probing)) < 0)
  			return err;
  	}
  
  	/* disable interrupts */
  	for (i = 0; i < chip->bdbars_count; i++)
  		iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  	/* reset channels */
  	for (i = 0; i < chip->bdbars_count; i++)
  		iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
253b999f5   Jaroslav Kysela   [ALSA] intel8x0 -...
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
  	for (i = 0; i < chip->bdbars_count; i++) {
  	        timeout = 100000;
  	        while (--timeout != 0) {
          		if ((igetbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset) & ICH_RESETREGS) == 0)
          		        break;
                  }
                  if (timeout == 0)
                          printk(KERN_ERR "intel8x0: reset of registers failed?
  ");
          }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2485
2486
  	/* initialize Buffer Descriptor Lists */
  	for (i = 0; i < chip->bdbars_count; i++)
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2487
2488
  		iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset,
  			  chip->ichd[i].bdbar_addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2489
2490
  	return 0;
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2491
  static int snd_intel8x0_free(struct intel8x0 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
  {
  	unsigned int i;
  
  	if (chip->irq < 0)
  		goto __hw_end;
  	/* disable interrupts */
  	for (i = 0; i < chip->bdbars_count; i++)
  		iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  	/* reset channels */
  	for (i = 0; i < chip->bdbars_count; i++)
  		iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
2503
  	if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2504
2505
2506
2507
2508
2509
2510
  		/* stop the spdif interrupt */
  		unsigned int val;
  		pci_read_config_dword(chip->pci, 0x4c, &val);
  		val &= ~0x1000000;
  		pci_write_config_dword(chip->pci, 0x4c, val);
  	}
  	/* --- */
f000fd809   Jeff Garzik   [ALSA] Fix synchr...
2511

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2512
2513
        __hw_end:
  	if (chip->irq >= 0)
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2514
  		free_irq(chip->irq, chip);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2515
2516
2517
2518
2519
  	if (chip->bdbars.area) {
  		if (chip->fix_nocache)
  			fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0);
  		snd_dma_free_pages(&chip->bdbars);
  	}
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
2520
2521
2522
2523
  	if (chip->addr)
  		pci_iounmap(chip->pci, chip->addr);
  	if (chip->bmaddr)
  		pci_iounmap(chip->pci, chip->bmaddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
  	pci_release_regions(chip->pci);
  	pci_disable_device(chip->pci);
  	kfree(chip);
  	return 0;
  }
  
  #ifdef CONFIG_PM
  /*
   * power management
   */
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2534
  static int intel8x0_suspend(struct pci_dev *pci, pm_message_t state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2535
  {
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2536
2537
  	struct snd_card *card = pci_get_drvdata(pci);
  	struct intel8x0 *chip = card->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2538
  	int i;
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2539
  	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2540
2541
2542
2543
2544
  	for (i = 0; i < chip->pcm_devs; i++)
  		snd_pcm_suspend_all(chip->pcm[i]);
  	/* clear nocache */
  	if (chip->fix_nocache) {
  		for (i = 0; i < chip->bdbars_count; i++) {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2545
  			struct ichdev *ichdev = &chip->ichd[i];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2546
  			if (ichdev->substream && ichdev->page_attr_changed) {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2547
  				struct snd_pcm_runtime *runtime = ichdev->substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2548
2549
2550
2551
2552
  				if (runtime->dma_area)
  					fill_nocache(runtime->dma_area, runtime->dma_bytes, 0);
  			}
  		}
  	}
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2553
  	for (i = 0; i < chip->ncodecs; i++)
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2554
  		snd_ac97_suspend(chip->ac97[i]);
52b723888   Takashi Iwai   [ALSA] Fix resume...
2555
2556
  	if (chip->device_type == DEVICE_INTEL_ICH4)
  		chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
adbedd342   Len Brown   merge 2.6.13-rc4 ...
2557

30b35399c   Takashi Iwai   [ALSA] Various fi...
2558
  	if (chip->irq >= 0) {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2559
  		free_irq(chip->irq, chip);
30b35399c   Takashi Iwai   [ALSA] Various fi...
2560
2561
  		chip->irq = -1;
  	}
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2562
2563
  	pci_disable_device(pci);
  	pci_save_state(pci);
19bfafb2e   Tommi Kyntola   [ALSA] intel8x0 -...
2564
2565
2566
2567
  	/* The call below may disable built-in speaker on some laptops
  	 * after S2RAM.  So, don't touch it.
  	 */
  	/* pci_set_power_state(pci, pci_choose_state(pci, state)); */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2568
2569
  	return 0;
  }
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2570
  static int intel8x0_resume(struct pci_dev *pci)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2571
  {
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2572
2573
  	struct snd_card *card = pci_get_drvdata(pci);
  	struct intel8x0 *chip = card->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2574
  	int i;
30b35399c   Takashi Iwai   [ALSA] Various fi...
2575
  	pci_set_power_state(pci, PCI_D0);
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2576
  	pci_restore_state(pci);
30b35399c   Takashi Iwai   [ALSA] Various fi...
2577
2578
2579
2580
2581
2582
2583
  	if (pci_enable_device(pci) < 0) {
  		printk(KERN_ERR "intel8x0: pci_enable_device failed, "
  		       "disabling device
  ");
  		snd_card_disconnect(card);
  		return -EIO;
  	}
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2584
  	pci_set_master(pci);
2078f38c8   Takashi Iwai   [ALSA] intel8x0 -...
2585
  	snd_intel8x0_chip_init(chip, 0);
30b35399c   Takashi Iwai   [ALSA] Various fi...
2586
  	if (request_irq(pci->irq, snd_intel8x0_interrupt,
934c2b6d0   Takashi Iwai   ALSA: use KBUILD_...
2587
  			IRQF_SHARED, KBUILD_MODNAME, chip)) {
30b35399c   Takashi Iwai   [ALSA] Various fi...
2588
2589
2590
2591
2592
2593
  		printk(KERN_ERR "intel8x0: unable to grab IRQ %d, "
  		       "disabling device
  ", pci->irq);
  		snd_card_disconnect(card);
  		return -EIO;
  	}
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2594
  	chip->irq = pci->irq;
90158b832   Rafael J. Wysocki   [ACPI] fix resume...
2595
  	synchronize_irq(chip->irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2596

52b723888   Takashi Iwai   [ALSA] Fix resume...
2597
  	/* re-initialize mixer stuff */
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
2598
  	if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
52b723888   Takashi Iwai   [ALSA] Fix resume...
2599
2600
2601
2602
2603
2604
2605
  		/* enable separate SDINs for ICH4 */
  		iputbyte(chip, ICHREG(SDM), chip->sdm_saved);
  		/* use slot 10/11 for SPDIF */
  		iputdword(chip, ICHREG(GLOB_CNT),
  			  (igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK) |
  			  ICH_PCM_SPDIF_1011);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2606
2607
2608
  	/* refill nocache */
  	if (chip->fix_nocache)
  		fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2609
  	for (i = 0; i < chip->ncodecs; i++)
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2610
  		snd_ac97_resume(chip->ac97[i]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2611
2612
2613
2614
  
  	/* refill nocache */
  	if (chip->fix_nocache) {
  		for (i = 0; i < chip->bdbars_count; i++) {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2615
  			struct ichdev *ichdev = &chip->ichd[i];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2616
  			if (ichdev->substream && ichdev->page_attr_changed) {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2617
  				struct snd_pcm_runtime *runtime = ichdev->substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2618
2619
2620
2621
2622
  				if (runtime->dma_area)
  					fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
  			}
  		}
  	}
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
2623
2624
  	/* resume status */
  	for (i = 0; i < chip->bdbars_count; i++) {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2625
  		struct ichdev *ichdev = &chip->ichd[i];
1cfe43d21   Takashi Iwai   [ALSA] intel8x0 -...
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
  		unsigned long port = ichdev->reg_offset;
  		if (! ichdev->substream || ! ichdev->suspended)
  			continue;
  		if (ichdev->ichd == ICHD_PCMOUT)
  			snd_intel8x0_setup_pcm_out(chip, ichdev->substream->runtime);
  		iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
  		iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  		iputbyte(chip, port + ICH_REG_OFF_CIV, ichdev->civ);
  		iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  	}
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
2636
  	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2637
2638
2639
2640
2641
  	return 0;
  }
  #endif /* CONFIG_PM */
  
  #define INTEL8X0_TESTBUF_SIZE	32768	/* enough large for one shot */
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2642
  static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2643
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2644
2645
  	struct snd_pcm_substream *subs;
  	struct ichdev *ichdev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2646
  	unsigned long port;
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2647
  	unsigned long pos, pos1, t;
2ec775e70   Jaroslav Kysela   [ALSA] intel8x0: ...
2648
  	int civ, timeout = 1000, attempt = 1;
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2649
  	struct timespec start_time, stop_time;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2650
2651
2652
  
  	if (chip->ac97_bus->clock != 48000)
  		return; /* specified in module option */
2ec775e70   Jaroslav Kysela   [ALSA] intel8x0: ...
2653
        __again:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2654
2655
  	subs = chip->pcm[0]->streams[0].substream;
  	if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
99b359ba1   Takashi Iwai   [ALSA] Add missin...
2656
2657
  		snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2658
2659
2660
2661
  		return;
  	}
  	ichdev = &chip->ichd[ICHD_PCMOUT];
  	ichdev->physbuf = subs->dma_buffer.addr;
29dab4fd3   Jaroslav Kysela   [ALSA] intel8x0: ...
2662
  	ichdev->size = ichdev->fragsize = INTEL8X0_TESTBUF_SIZE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
  	ichdev->substream = NULL; /* don't process interrupts */
  
  	/* set rate */
  	if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
  		snd_printk(KERN_ERR "cannot set ac97 rate: clock = %d
  ", chip->ac97_bus->clock);
  		return;
  	}
  	snd_intel8x0_setup_periods(chip, ichdev);
  	port = ichdev->reg_offset;
  	spin_lock_irq(&chip->reg_lock);
  	chip->in_measurement = 1;
  	/* trigger */
  	if (chip->device_type != DEVICE_ALI)
  		iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE | ICH_STARTBM);
  	else {
  		iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
  		iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
  	}
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2682
  	do_posix_clock_monotonic_gettime(&start_time);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2683
  	spin_unlock_irq(&chip->reg_lock);
ef21ca24f   Nishanth Aravamudan   [ALSA] sound/pci:...
2684
  	msleep(50);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2685
2686
  	spin_lock_irq(&chip->reg_lock);
  	/* check the position */
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
  	do {
  		civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
  		pos1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
  		if (pos1 == 0) {
  			udelay(10);
  			continue;
  		}
  		if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
  		    pos1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
  			break;
  	} while (timeout--);
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
2698
2699
2700
2701
2702
2703
2704
  	if (pos1 == 0) {	/* oops, this value is not reliable */
  		pos = 0;
  	} else {
  		pos = ichdev->fragsize1;
  		pos -= pos1 << ichdev->pos_shift;
  		pos += ichdev->position;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2705
  	chip->in_measurement = 0;
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2706
  	do_posix_clock_monotonic_gettime(&stop_time);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2707
2708
  	/* stop */
  	if (chip->device_type == DEVICE_ALI) {
d78bec210   Wei Ni   [ALSA] intel8x0 -...
2709
  		iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
  		iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  		while (igetbyte(chip, port + ICH_REG_OFF_CR))
  			;
  	} else {
  		iputbyte(chip, port + ICH_REG_OFF_CR, 0);
  		while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH))
  			;
  	}
  	iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  	spin_unlock_irq(&chip->reg_lock);
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
2720
2721
2722
  	if (pos == 0) {
  		snd_printk(KERN_ERR "intel8x0: measure - unreliable DMA position..
  ");
2ec775e70   Jaroslav Kysela   [ALSA] intel8x0: ...
2723
  	      __retry:
30fd9940e   Jaroslav Kysela   [ALSA] intel8x0: ...
2724
2725
  		if (attempt < 3) {
  			msleep(300);
2ec775e70   Jaroslav Kysela   [ALSA] intel8x0: ...
2726
2727
2728
  			attempt++;
  			goto __again;
  		}
30fd9940e   Jaroslav Kysela   [ALSA] intel8x0: ...
2729
  		goto __end;
da2436a23   Jaroslav Kysela   [ALSA] intel8x0: ...
2730
  	}
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2731
  	pos /= 4;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2732
2733
  	t = stop_time.tv_sec - start_time.tv_sec;
  	t *= 1000000;
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2734
2735
2736
  	t += (stop_time.tv_nsec - start_time.tv_nsec) / 1000;
  	printk(KERN_INFO "%s: measured %lu usecs (%lu samples)
  ", __func__, t, pos);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2737
  	if (t == 0) {
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2738
2739
  		snd_printk(KERN_ERR "intel8x0: ?? calculation error..
  ");
2ec775e70   Jaroslav Kysela   [ALSA] intel8x0: ...
2740
  		goto __retry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2741
  	}
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2742
  	pos *= 1000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2743
  	pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
2ec775e70   Jaroslav Kysela   [ALSA] intel8x0: ...
2744
  	if (pos < 40000 || pos >= 60000) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2745
2746
2747
  		/* abnormal value. hw problem? */
  		printk(KERN_INFO "intel8x0: measured clock %ld rejected
  ", pos);
2ec775e70   Jaroslav Kysela   [ALSA] intel8x0: ...
2748
2749
  		goto __retry;
  	} else if (pos > 40500 && pos < 41500)
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2750
2751
  		/* first exception - 41000Hz reference clock */
  		chip->ac97_bus->clock = 41000;
29dab4fd3   Jaroslav Kysela   [ALSA] intel8x0: ...
2752
  	else if (pos > 43600 && pos < 44600)
920e4ae31   Jaroslav Kysela   [ALSA] intel8x0: ...
2753
2754
  		/* second exception - 44100HZ reference clock */
  		chip->ac97_bus->clock = 44100;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2755
2756
2757
  	else if (pos < 47500 || pos > 48500)
  		/* not 48000Hz, tuning the clock.. */
  		chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
30fd9940e   Jaroslav Kysela   [ALSA] intel8x0: ...
2758
        __end:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2759
2760
  	printk(KERN_INFO "intel8x0: clocking to %d
  ", chip->ac97_bus->clock);
6dbe66287   Takashi Iwai   [ALSA] Add experi...
2761
  	snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2762
  }
d695e4ea8   Takashi Iwai   ALSA: intel8x0 - ...
2763
2764
2765
2766
  static struct snd_pci_quirk intel8x0_clock_list[] __devinitdata = {
  	SND_PCI_QUIRK(0x0e11, 0x008a, "AD1885", 41000),
  	SND_PCI_QUIRK(0x1028, 0x00be, "AD1885", 44100),
  	SND_PCI_QUIRK(0x1028, 0x0177, "AD1980", 48000),
78fad343a   Bastien Nocera   ALSA: intel8x0 - ...
2767
  	SND_PCI_QUIRK(0x1028, 0x01ad, "AD1981B", 48000),
d695e4ea8   Takashi Iwai   ALSA: intel8x0 - ...
2768
2769
  	SND_PCI_QUIRK(0x1043, 0x80f3, "AD1985", 48000),
  	{ }	/* terminator */
2b3b5485a   Jaroslav Kysela   ALSA: intel8x0: i...
2770
2771
2772
2773
2774
  };
  
  static int __devinit intel8x0_in_clock_list(struct intel8x0 *chip)
  {
  	struct pci_dev *pci = chip->pci;
d695e4ea8   Takashi Iwai   ALSA: intel8x0 - ...
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
  	const struct snd_pci_quirk *wl;
  
  	wl = snd_pci_quirk_lookup(pci, intel8x0_clock_list);
  	if (!wl)
  		return 0;
  	printk(KERN_INFO "intel8x0: white list rate for %04x:%04x is %i
  ",
  	       pci->subsystem_vendor, pci->subsystem_device, wl->value);
  	chip->ac97_bus->clock = wl->value;
  	return 1;
2b3b5485a   Jaroslav Kysela   ALSA: intel8x0: i...
2785
  }
adf1b3d25   Takashi Iwai   [ALSA] Optimize f...
2786
  #ifdef CONFIG_PROC_FS
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2787
2788
  static void snd_intel8x0_proc_read(struct snd_info_entry * entry,
  				   struct snd_info_buffer *buffer)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2789
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2790
  	struct intel8x0 *chip = entry->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
  	unsigned int tmp;
  
  	snd_iprintf(buffer, "Intel8x0
  
  ");
  	if (chip->device_type == DEVICE_ALI)
  		return;
  	tmp = igetdword(chip, ICHREG(GLOB_STA));
  	snd_iprintf(buffer, "Global control        : 0x%08x
  ", igetdword(chip, ICHREG(GLOB_CNT)));
  	snd_iprintf(buffer, "Global status         : 0x%08x
  ", tmp);
  	if (chip->device_type == DEVICE_INTEL_ICH4)
  		snd_iprintf(buffer, "SDM                   : 0x%08x
  ", igetdword(chip, ICHREG(SDM)));
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
  	snd_iprintf(buffer, "AC'97 codecs ready    :");
  	if (tmp & chip->codec_isr_bits) {
  		int i;
  		static const char *codecs[3] = {
  			"primary", "secondary", "tertiary"
  		};
  		for (i = 0; i < chip->max_codecs; i++)
  			if (tmp & chip->codec_bit[i])
  				snd_iprintf(buffer, " %s", codecs[i]);
  	} else
  		snd_iprintf(buffer, " none");
  	snd_iprintf(buffer, "
  ");
  	if (chip->device_type == DEVICE_INTEL_ICH4 ||
  	    chip->device_type == DEVICE_SIS)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2821
2822
2823
2824
2825
2826
  		snd_iprintf(buffer, "AC'97 codecs SDIN     : %i %i %i
  ",
  			chip->ac97_sdin[0],
  			chip->ac97_sdin[1],
  			chip->ac97_sdin[2]);
  }
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2827
  static void __devinit snd_intel8x0_proc_init(struct intel8x0 * chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2828
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2829
  	struct snd_info_entry *entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2830
2831
  
  	if (! snd_card_proc_new(chip->card, "intel8x0", &entry))
bf850204a   Takashi Iwai   [ALSA] Remove unn...
2832
  		snd_info_set_text_ops(entry, chip, snd_intel8x0_proc_read);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2833
  }
adf1b3d25   Takashi Iwai   [ALSA] Optimize f...
2834
2835
2836
  #else
  #define snd_intel8x0_proc_init(x)
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2837

6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2838
  static int snd_intel8x0_dev_free(struct snd_device *device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2839
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2840
  	struct intel8x0 *chip = device->device_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2841
2842
2843
2844
2845
2846
2847
  	return snd_intel8x0_free(chip);
  }
  
  struct ich_reg_info {
  	unsigned int int_sta_mask;
  	unsigned int offset;
  };
84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
2848
2849
2850
2851
2852
2853
  static unsigned int ich_codec_bits[3] = {
  	ICH_PCR, ICH_SCR, ICH_TCR
  };
  static unsigned int sis_codec_bits[3] = {
  	ICH_PCR, ICH_SCR, ICH_SIS_TCR
  };
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2854
  static int __devinit snd_intel8x0_create(struct snd_card *card,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2855
2856
  					 struct pci_dev *pci,
  					 unsigned long device_type,
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2857
  					 struct intel8x0 ** r_intel8x0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2858
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2859
  	struct intel8x0 *chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2860
2861
2862
  	int err;
  	unsigned int i;
  	unsigned int int_sta_masks;
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
2863
2864
  	struct ichdev *ichdev;
  	static struct snd_device_ops ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
  		.dev_free =	snd_intel8x0_dev_free,
  	};
  
  	static unsigned int bdbars[] = {
  		3, /* DEVICE_INTEL */
  		6, /* DEVICE_INTEL_ICH4 */
  		3, /* DEVICE_SIS */
  		6, /* DEVICE_ALI */
  		4, /* DEVICE_NFORCE */
  	};
  	static struct ich_reg_info intel_regs[6] = {
  		{ ICH_PIINT, 0 },
  		{ ICH_POINT, 0x10 },
  		{ ICH_MCINT, 0x20 },
  		{ ICH_M2INT, 0x40 },
  		{ ICH_P2INT, 0x50 },
  		{ ICH_SPINT, 0x60 },
  	};
  	static struct ich_reg_info nforce_regs[4] = {
  		{ ICH_PIINT, 0 },
  		{ ICH_POINT, 0x10 },
  		{ ICH_MCINT, 0x20 },
  		{ ICH_NVSPINT, 0x70 },
  	};
  	static struct ich_reg_info ali_regs[6] = {
  		{ ALI_INT_PCMIN, 0x40 },
  		{ ALI_INT_PCMOUT, 0x50 },
  		{ ALI_INT_MICIN, 0x60 },
  		{ ALI_INT_CODECSPDIFOUT, 0x70 },
  		{ ALI_INT_SPDIFIN, 0xa0 },
  		{ ALI_INT_SPDIFOUT, 0xb0 },
  	};
  	struct ich_reg_info *tbl;
  
  	*r_intel8x0 = NULL;
  
  	if ((err = pci_enable_device(pci)) < 0)
  		return err;
e560d8d83   Takashi Iwai   [ALSA] Replace wi...
2903
  	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2904
2905
2906
2907
2908
2909
2910
2911
2912
  	if (chip == NULL) {
  		pci_disable_device(pci);
  		return -ENOMEM;
  	}
  	spin_lock_init(&chip->reg_lock);
  	chip->device_type = device_type;
  	chip->card = card;
  	chip->pci = pci;
  	chip->irq = -1;
c829b052d   Takashi Iwai   [ALSA] intel8x0 -...
2913
2914
2915
2916
2917
2918
  
  	/* module parameters */
  	chip->buggy_irq = buggy_irq;
  	chip->buggy_semaphore = buggy_semaphore;
  	if (xbox)
  		chip->xbox = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2919
2920
2921
2922
  
  	if (pci->vendor == PCI_VENDOR_ID_INTEL &&
  	    pci->device == PCI_DEVICE_ID_INTEL_440MX)
  		chip->fix_nocache = 1; /* enable workaround */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2923
2924
2925
2926
2927
2928
2929
2930
  	if ((err = pci_request_regions(pci, card->shortname)) < 0) {
  		kfree(chip);
  		pci_disable_device(pci);
  		return err;
  	}
  
  	if (device_type == DEVICE_ALI) {
  		/* ALI5455 has no ac97 region */
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
2931
  		chip->bmaddr = pci_iomap(pci, 0, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2932
2933
  		goto port_inited;
  	}
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
  	if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
  		chip->addr = pci_iomap(pci, 2, 0);
  	else
  		chip->addr = pci_iomap(pci, 0, 0);
  	if (!chip->addr) {
  		snd_printk(KERN_ERR "AC'97 space ioremap problem
  ");
  		snd_intel8x0_free(chip);
  		return -EIO;
  	}
  	if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
  		chip->bmaddr = pci_iomap(pci, 3, 0);
  	else
  		chip->bmaddr = pci_iomap(pci, 1, 0);
  	if (!chip->bmaddr) {
  		snd_printk(KERN_ERR "Controller space ioremap problem
  ");
  		snd_intel8x0_free(chip);
  		return -EIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2953
2954
2955
  	}
  
   port_inited:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
  	chip->bdbars_count = bdbars[device_type];
  
  	/* initialize offsets */
  	switch (device_type) {
  	case DEVICE_NFORCE:
  		tbl = nforce_regs;
  		break;
  	case DEVICE_ALI:
  		tbl = ali_regs;
  		break;
  	default:
  		tbl = intel_regs;
  		break;
  	}
  	for (i = 0; i < chip->bdbars_count; i++) {
  		ichdev = &chip->ichd[i];
  		ichdev->ichd = i;
  		ichdev->reg_offset = tbl[i].offset;
  		ichdev->int_sta_mask = tbl[i].int_sta_mask;
  		if (device_type == DEVICE_SIS) {
  			/* SiS 7012 swaps the registers */
  			ichdev->roff_sr = ICH_REG_OFF_PICB;
  			ichdev->roff_picb = ICH_REG_OFF_SR;
  		} else {
  			ichdev->roff_sr = ICH_REG_OFF_SR;
  			ichdev->roff_picb = ICH_REG_OFF_PICB;
  		}
  		if (device_type == DEVICE_ALI)
  			ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
  		/* SIS7012 handles the pcm data in bytes, others are in samples */
  		ichdev->pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
  	}
  
  	/* allocate buffer descriptor lists */
  	/* the start of each lists must be aligned to 8 bytes */
  	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  				chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
  				&chip->bdbars) < 0) {
  		snd_intel8x0_free(chip);
  		snd_printk(KERN_ERR "intel8x0: cannot allocate buffer descriptors
  ");
  		return -ENOMEM;
  	}
  	/* tables must be aligned to 8 bytes here, but the kernel pages
  	   are much bigger, so we don't care (on i386) */
  	/* workaround for 440MX */
  	if (chip->fix_nocache)
  		fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
  	int_sta_masks = 0;
  	for (i = 0; i < chip->bdbars_count; i++) {
  		ichdev = &chip->ichd[i];
beef08a54   Takashi Iwai   [ALSA] intel8x0 -...
3007
3008
3009
3010
  		ichdev->bdbar = ((u32 *)chip->bdbars.area) +
  			(i * ICH_MAX_FRAGS * 2);
  		ichdev->bdbar_addr = chip->bdbars.addr +
  			(i * sizeof(u32) * ICH_MAX_FRAGS * 2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3011
3012
  		int_sta_masks |= ichdev->int_sta_mask;
  	}
beef08a54   Takashi Iwai   [ALSA] intel8x0 -...
3013
3014
  	chip->int_sta_reg = device_type == DEVICE_ALI ?
  		ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3015
  	chip->int_sta_mask = int_sta_masks;
beef08a54   Takashi Iwai   [ALSA] intel8x0 -...
3016
  	pci_set_master(pci);
beef08a54   Takashi Iwai   [ALSA] intel8x0 -...
3017

84a43bd52   Takashi Iwai   [ALSA] intel8x0 -...
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
  	switch(chip->device_type) {
  	case DEVICE_INTEL_ICH4:
  		/* ICH4 can have three codecs */
  		chip->max_codecs = 3;
  		chip->codec_bit = ich_codec_bits;
  		chip->codec_ready_bits = ICH_PRI | ICH_SRI | ICH_TRI;
  		break;
  	case DEVICE_SIS:
  		/* recent SIS7012 can have three codecs */
  		chip->max_codecs = 3;
  		chip->codec_bit = sis_codec_bits;
  		chip->codec_ready_bits = ICH_PRI | ICH_SRI | ICH_SIS_TRI;
  		break;
  	default:
  		/* others up to two codecs */
  		chip->max_codecs = 2;
  		chip->codec_bit = ich_codec_bits;
  		chip->codec_ready_bits = ICH_PRI | ICH_SRI;
  		break;
  	}
  	for (i = 0; i < chip->max_codecs; i++)
  		chip->codec_isr_bits |= chip->codec_bit[i];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3040
3041
3042
3043
  	if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
  		snd_intel8x0_free(chip);
  		return err;
  	}
2078f38c8   Takashi Iwai   [ALSA] intel8x0 -...
3044
3045
  	/* request irq after initializaing int_sta_mask, etc */
  	if (request_irq(pci->irq, snd_intel8x0_interrupt,
934c2b6d0   Takashi Iwai   ALSA: use KBUILD_...
3046
  			IRQF_SHARED, KBUILD_MODNAME, chip)) {
2078f38c8   Takashi Iwai   [ALSA] intel8x0 -...
3047
3048
3049
3050
3051
3052
  		snd_printk(KERN_ERR "unable to grab IRQ %d
  ", pci->irq);
  		snd_intel8x0_free(chip);
  		return -EBUSY;
  	}
  	chip->irq = pci->irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
  	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  		snd_intel8x0_free(chip);
  		return err;
  	}
  
  	snd_card_set_dev(card, &pci->dev);
  
  	*r_intel8x0 = chip;
  	return 0;
  }
  
  static struct shortname_table {
  	unsigned int id;
  	const char *s;
  } shortnames[] __devinitdata = {
8cdfd2519   Takashi Iwai   [ALSA] Remove sup...
3068
3069
3070
  	{ PCI_DEVICE_ID_INTEL_82801AA_5, "Intel 82801AA-ICH" },
  	{ PCI_DEVICE_ID_INTEL_82801AB_5, "Intel 82901AB-ICH0" },
  	{ PCI_DEVICE_ID_INTEL_82801BA_4, "Intel 82801BA-ICH2" },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3071
  	{ PCI_DEVICE_ID_INTEL_440MX, "Intel 440MX" },
8cdfd2519   Takashi Iwai   [ALSA] Remove sup...
3072
3073
3074
  	{ PCI_DEVICE_ID_INTEL_82801CA_5, "Intel 82801CA-ICH3" },
  	{ PCI_DEVICE_ID_INTEL_82801DB_5, "Intel 82801DB-ICH4" },
  	{ PCI_DEVICE_ID_INTEL_82801EB_5, "Intel ICH5" },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3075
3076
3077
  	{ PCI_DEVICE_ID_INTEL_ESB_5, "Intel 6300ESB" },
  	{ PCI_DEVICE_ID_INTEL_ICH6_18, "Intel ICH6" },
  	{ PCI_DEVICE_ID_INTEL_ICH7_20, "Intel ICH7" },
3437c5df6   Jason Gaston   [PATCH] intel8x0:...
3078
  	{ PCI_DEVICE_ID_INTEL_ESB2_14, "Intel ESB2" },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3079
  	{ PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
8cdfd2519   Takashi Iwai   [ALSA] Remove sup...
3080
  	{ PCI_DEVICE_ID_NVIDIA_MCP1_AUDIO, "NVidia nForce" },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
  	{ PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
  	{ PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
  	{ PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO, "NVidia CK8S" },
  	{ PCI_DEVICE_ID_NVIDIA_CK804_AUDIO, "NVidia CK804" },
  	{ PCI_DEVICE_ID_NVIDIA_CK8_AUDIO, "NVidia CK8" },
  	{ 0x003a, "NVidia MCP04" },
  	{ 0x746d, "AMD AMD8111" },
  	{ 0x7445, "AMD AMD768" },
  	{ 0x5455, "ALi M5455" },
  	{ 0, NULL },
  };
a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
  static struct snd_pci_quirk spdif_aclink_defaults[] __devinitdata = {
  	SND_PCI_QUIRK(0x147b, 0x1c1a, "ASUS KN8", 1),
  	{ } /* end */
  };
  
  /* look up white/black list for SPDIF over ac-link */
  static int __devinit check_default_spdif_aclink(struct pci_dev *pci)
  {
  	const struct snd_pci_quirk *w;
  
  	w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults);
  	if (w) {
  		if (w->value)
  			snd_printdd(KERN_INFO "intel8x0: Using SPDIF over "
  				    "AC-Link for %s
  ", w->name);
  		else
  			snd_printdd(KERN_INFO "intel8x0: Using integrated "
  				    "SPDIF DMA for %s
  ", w->name);
  		return w->value;
  	}
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3116
3117
3118
  static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
  					const struct pci_device_id *pci_id)
  {
6b75a9d8b   Takashi Iwai   [ALSA] Remove xxx...
3119
3120
  	struct snd_card *card;
  	struct intel8x0 *chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3121
3122
  	int err;
  	struct shortname_table *name;
e58de7baf   Takashi Iwai   ALSA: Convert to ...
3123
3124
3125
  	err = snd_card_create(index, id, THIS_MODULE, 0, &card);
  	if (err < 0)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3126

a9e996604   Takashi Iwai   [ALSA] intel8x0 -...
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
  	if (spdif_aclink < 0)
  		spdif_aclink = check_default_spdif_aclink(pci);
  
  	strcpy(card->driver, "ICH");
  	if (!spdif_aclink) {
  		switch (pci_id->driver_data) {
  		case DEVICE_NFORCE:
  			strcpy(card->driver, "NFORCE");
  			break;
  		case DEVICE_INTEL_ICH4:
  			strcpy(card->driver, "ICH4");
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3139
3140
3141
3142
3143
3144
3145
3146
3147
  	}
  
  	strcpy(card->shortname, "Intel ICH");
  	for (name = shortnames; name->id; name++) {
  		if (pci->device == name->id) {
  			strcpy(card->shortname, name->s);
  			break;
  		}
  	}
beef08a54   Takashi Iwai   [ALSA] intel8x0 -...
3148
3149
3150
3151
3152
3153
3154
3155
3156
  	if (buggy_irq < 0) {
  		/* some Nforce[2] and ICH boards have problems with IRQ handling.
  		 * Needs to return IRQ_HANDLED for unknown irqs.
  		 */
  		if (pci_id->driver_data == DEVICE_NFORCE)
  			buggy_irq = 1;
  		else
  			buggy_irq = 0;
  	}
a06147d22   Takashi Iwai   [ALSA] intel8x0 -...
3157
  	if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data,
c829b052d   Takashi Iwai   [ALSA] intel8x0 -...
3158
  				       &chip)) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3159
3160
3161
  		snd_card_free(card);
  		return err;
  	}
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
3162
  	card->private_data = chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3163

b7fe46220   Clemens Ladisch   [ALSA] highlander...
3164
  	if ((err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk)) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
  		snd_card_free(card);
  		return err;
  	}
  	if ((err = snd_intel8x0_pcm(chip)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	
  	snd_intel8x0_proc_init(chip);
  
  	snprintf(card->longname, sizeof(card->longname),
3388c37e0   Takashi Iwai   [ALSA] intel8x0 -...
3176
3177
  		 "%s with %s at irq %i", card->shortname,
  		 snd_ac97_get_short_name(chip->ac97[0]), chip->irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3178

2b3b5485a   Jaroslav Kysela   ALSA: intel8x0: i...
3179
3180
3181
3182
3183
3184
3185
3186
  	if (ac97_clock == 0 || ac97_clock == 1) {
  		if (ac97_clock == 0) {
  			if (intel8x0_in_clock_list(chip) == 0)
  				intel8x0_measure_ac97_clock(chip);
  		} else {
  			intel8x0_measure_ac97_clock(chip);
  		}
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3187
3188
3189
3190
3191
3192
  
  	if ((err = snd_card_register(card)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	pci_set_drvdata(pci, card);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
  	return 0;
  }
  
  static void __devexit snd_intel8x0_remove(struct pci_dev *pci)
  {
  	snd_card_free(pci_get_drvdata(pci));
  	pci_set_drvdata(pci, NULL);
  }
  
  static struct pci_driver driver = {
3733e424c   Takashi Iwai   ALSA: Use KBUILD_...
3203
  	.name = KBUILD_MODNAME,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3204
3205
3206
  	.id_table = snd_intel8x0_ids,
  	.probe = snd_intel8x0_probe,
  	.remove = __devexit_p(snd_intel8x0_remove),
5809c6c41   Takashi Iwai   [ALSA] intel8x0 -...
3207
3208
3209
3210
  #ifdef CONFIG_PM
  	.suspend = intel8x0_suspend,
  	.resume = intel8x0_resume,
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3211
3212
3213
3214
3215
  };
  
  
  static int __init alsa_card_intel8x0_init(void)
  {
01d25d460   Takashi Iwai   [ALSA] Replace pc...
3216
  	return pci_register_driver(&driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3217
3218
3219
3220
3221
3222
3223
3224
3225
  }
  
  static void __exit alsa_card_intel8x0_exit(void)
  {
  	pci_unregister_driver(&driver);
  }
  
  module_init(alsa_card_intel8x0_init)
  module_exit(alsa_card_intel8x0_exit)