Blame view

sound/pci/ens1370.c 79 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  /*
   *  Driver for Ensoniq ES1370/ES1371 AudioPCI soundcard
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
3
   *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   *		     Thomas Sailer <sailer@ife.ee.ethz.ch>
   *
   *   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
   *
   */
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
21
22
23
  /* Power-Management-Code ( CONFIG_PM )
   * for ens1371 only ( FIXME )
   * derived from cs4281.c, atiixp.c and via82xx.c
631dd1a88   Justin P. Mattock   Update broken web...
24
   * using http://www.alsa-project.org/~tiwai/writing-an-alsa-driver/ 
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
25
26
   * by Kurt J. Bosch
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
29
30
31
32
33
  #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/gameport.h>
65a772172   Paul Gortmaker   sound: fix driver...
34
  #include <linux/module.h>
62932df8f   Ingo Molnar   [ALSA] semaphore ...
35
  #include <linux/mutex.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  #include <sound/core.h>
  #include <sound/control.h>
  #include <sound/pcm.h>
  #include <sound/rawmidi.h>
  #ifdef CHIP1371
  #include <sound/ac97_codec.h>
  #else
  #include <sound/ak4531_codec.h>
  #endif
  #include <sound/initval.h>
  #include <sound/asoundef.h>
  
  #ifndef CHIP1371
  #undef CHIP1370
  #define CHIP1370
  #endif
  
  #ifdef CHIP1370
  #define DRIVER_NAME "ENS1370"
  #else
  #define DRIVER_NAME "ENS1371"
  #endif
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
58
  MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Thomas Sailer <sailer@ife.ee.ethz.ch>");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  MODULE_LICENSE("GPL");
  #ifdef CHIP1370
  MODULE_DESCRIPTION("Ensoniq AudioPCI ES1370");
  MODULE_SUPPORTED_DEVICE("{{Ensoniq,AudioPCI-97 ES1370},"
  	        "{Creative Labs,SB PCI64/128 (ES1370)}}");
  #endif
  #ifdef CHIP1371
  MODULE_DESCRIPTION("Ensoniq/Creative AudioPCI ES1371+");
  MODULE_SUPPORTED_DEVICE("{{Ensoniq,AudioPCI ES1371/73},"
  		"{Ensoniq,AudioPCI ES1373},"
  		"{Creative Labs,Ectiva EV1938},"
  		"{Creative Labs,SB PCI64/128 (ES1371/73)},"
  		"{Creative Labs,Vibra PCI128},"
  		"{Ectiva,EV1938}}");
  #endif
  
  #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
  #define SUPPORT_JOYSTICK
  #endif
  
  static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
  static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
a67ff6a54   Rusty Russell   ALSA: module_para...
81
  static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable switches */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
  #ifdef SUPPORT_JOYSTICK
  #ifdef CHIP1371
  static int joystick_port[SNDRV_CARDS];
  #else
a67ff6a54   Rusty Russell   ALSA: module_para...
86
  static bool joystick[SNDRV_CARDS];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
88
  #endif
  #endif
156b2aa3b   Clemens Ladisch   [ALSA] ens1371: f...
89
90
91
92
  #ifdef CHIP1371
  static int spdif[SNDRV_CARDS];
  static int lineio[SNDRV_CARDS];
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  
  module_param_array(index, int, NULL, 0444);
  MODULE_PARM_DESC(index, "Index value for Ensoniq AudioPCI soundcard.");
  module_param_array(id, charp, NULL, 0444);
  MODULE_PARM_DESC(id, "ID string for Ensoniq AudioPCI soundcard.");
  module_param_array(enable, bool, NULL, 0444);
  MODULE_PARM_DESC(enable, "Enable Ensoniq AudioPCI soundcard.");
  #ifdef SUPPORT_JOYSTICK
  #ifdef CHIP1371
  module_param_array(joystick_port, int, NULL, 0444);
  MODULE_PARM_DESC(joystick_port, "Joystick port address.");
  #else
  module_param_array(joystick, bool, NULL, 0444);
  MODULE_PARM_DESC(joystick, "Enable joystick.");
  #endif
  #endif /* SUPPORT_JOYSTICK */
156b2aa3b   Clemens Ladisch   [ALSA] ens1371: f...
109
110
111
112
113
114
  #ifdef CHIP1371
  module_param_array(spdif, int, NULL, 0444);
  MODULE_PARM_DESC(spdif, "S/PDIF output (-1 = none, 0 = auto, 1 = force).");
  module_param_array(lineio, int, NULL, 0444);
  MODULE_PARM_DESC(lineio, "Line In to Rear Out (0 = auto, 1 = force).");
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
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
  /* ES1371 chip ID */
  /* This is a little confusing because all ES1371 compatible chips have the
     same DEVICE_ID, the only thing differentiating them is the REV_ID field.
     This is only significant if you want to enable features on the later parts.
     Yes, I know it's stupid and why didn't we use the sub IDs?
  */
  #define ES1371REV_ES1373_A  0x04
  #define ES1371REV_ES1373_B  0x06
  #define ES1371REV_CT5880_A  0x07
  #define CT5880REV_CT5880_C  0x02
  #define CT5880REV_CT5880_D  0x03	/* ??? -jk */
  #define CT5880REV_CT5880_E  0x04	/* mw */
  #define ES1371REV_ES1371_B  0x09
  #define EV1938REV_EV1938_A  0x00
  #define ES1371REV_ES1373_8  0x08
  
  /*
   * Direct registers
   */
  
  #define ES_REG(ensoniq, x) ((ensoniq)->port + ES_REG_##x)
  
  #define ES_REG_CONTROL	0x00	/* R/W: Interrupt/Chip select control register */
  #define   ES_1370_ADC_STOP	(1<<31)		/* disable capture buffer transfers */
  #define   ES_1370_XCTL1 	(1<<30)		/* general purpose output bit */
  #define   ES_1373_BYPASS_P1	(1<<31)		/* bypass SRC for PB1 */
  #define   ES_1373_BYPASS_P2	(1<<30)		/* bypass SRC for PB2 */
  #define   ES_1373_BYPASS_R	(1<<29)		/* bypass SRC for REC */
  #define   ES_1373_TEST_BIT	(1<<28)		/* should be set to 0 for normal operation */
  #define   ES_1373_RECEN_B	(1<<27)		/* mix record with playback for I2S/SPDIF out */
  #define   ES_1373_SPDIF_THRU	(1<<26)		/* 0 = SPDIF thru mode, 1 = SPDIF == dig out */
  #define   ES_1371_JOY_ASEL(o)	(((o)&0x03)<<24)/* joystick port mapping */
  #define   ES_1371_JOY_ASELM	(0x03<<24)	/* mask for above */
  #define   ES_1371_JOY_ASELI(i)  (((i)>>24)&0x03)
  #define   ES_1371_GPIO_IN(i)	(((i)>>20)&0x0f)/* GPIO in [3:0] pins - R/O */
  #define   ES_1370_PCLKDIVO(o)	(((o)&0x1fff)<<16)/* clock divide ratio for DAC2 */
  #define   ES_1370_PCLKDIVM	((0x1fff)<<16)	/* mask for above */
  #define   ES_1370_PCLKDIVI(i)	(((i)>>16)&0x1fff)/* clock divide ratio for DAC2 */
  #define   ES_1371_GPIO_OUT(o)	(((o)&0x0f)<<16)/* GPIO out [3:0] pins - W/R */
  #define   ES_1371_GPIO_OUTM     (0x0f<<16)	/* mask for above */
  #define   ES_MSFMTSEL		(1<<15)		/* MPEG serial data format; 0 = SONY, 1 = I2S */
  #define   ES_1370_M_SBB		(1<<14)		/* clock source for DAC - 0 = clock generator; 1 = MPEG clocks */
  #define   ES_1371_SYNC_RES	(1<<14)		/* Warm AC97 reset */
  #define   ES_1370_WTSRSEL(o)	(((o)&0x03)<<12)/* fixed frequency clock for DAC1 */
  #define   ES_1370_WTSRSELM	(0x03<<12)	/* mask for above */
  #define   ES_1371_ADC_STOP	(1<<13)		/* disable CCB transfer capture information */
  #define   ES_1371_PWR_INTRM	(1<<12)		/* power level change interrupts enable */
  #define   ES_1370_DAC_SYNC	(1<<11)		/* DAC's are synchronous */
  #define   ES_1371_M_CB		(1<<11)		/* capture clock source; 0 = AC'97 ADC; 1 = I2S */
  #define   ES_CCB_INTRM		(1<<10)		/* CCB voice interrupts enable */
  #define   ES_1370_M_CB		(1<<9)		/* capture clock source; 0 = ADC; 1 = MPEG */
  #define   ES_1370_XCTL0		(1<<8)		/* generap purpose output bit */
  #define   ES_1371_PDLEV(o)	(((o)&0x03)<<8)	/* current power down level */
  #define   ES_1371_PDLEVM	(0x03<<8)	/* mask for above */
  #define   ES_BREQ		(1<<7)		/* memory bus request enable */
  #define   ES_DAC1_EN		(1<<6)		/* DAC1 playback channel enable */
  #define   ES_DAC2_EN		(1<<5)		/* DAC2 playback channel enable */
  #define   ES_ADC_EN		(1<<4)		/* ADC capture channel enable */
  #define   ES_UART_EN		(1<<3)		/* UART enable */
  #define   ES_JYSTK_EN		(1<<2)		/* Joystick module enable */
  #define   ES_1370_CDC_EN	(1<<1)		/* Codec interface enable */
  #define   ES_1371_XTALCKDIS	(1<<1)		/* Xtal clock disable */
  #define   ES_1370_SERR_DISABLE	(1<<0)		/* PCI serr signal disable */
  #define   ES_1371_PCICLKDIS     (1<<0)		/* PCI clock disable */
  #define ES_REG_STATUS	0x04	/* R/O: Interrupt/Chip select status register */
  #define   ES_INTR               (1<<31)		/* Interrupt is pending */
  #define   ES_1371_ST_AC97_RST	(1<<29)		/* CT5880 AC'97 Reset bit */
  #define   ES_1373_REAR_BIT27	(1<<27)		/* rear bits: 000 - front, 010 - mirror, 101 - separate */
  #define   ES_1373_REAR_BIT26	(1<<26)
  #define   ES_1373_REAR_BIT24	(1<<24)
  #define   ES_1373_GPIO_INT_EN(o)(((o)&0x0f)<<20)/* GPIO [3:0] pins - interrupt enable */
  #define   ES_1373_SPDIF_EN	(1<<18)		/* SPDIF enable */
  #define   ES_1373_SPDIF_TEST	(1<<17)		/* SPDIF test */
  #define   ES_1371_TEST          (1<<16)		/* test ASIC */
  #define   ES_1373_GPIO_INT(i)	(((i)&0x0f)>>12)/* GPIO [3:0] pins - interrupt pending */
  #define   ES_1370_CSTAT		(1<<10)		/* CODEC is busy or register write in progress */
  #define   ES_1370_CBUSY         (1<<9)		/* CODEC is busy */
  #define   ES_1370_CWRIP		(1<<8)		/* CODEC register write in progress */
  #define   ES_1371_SYNC_ERR	(1<<8)		/* CODEC synchronization error occurred */
  #define   ES_1371_VC(i)         (((i)>>6)&0x03)	/* voice code from CCB module */
  #define   ES_1370_VC(i)		(((i)>>5)&0x03)	/* voice code from CCB module */
  #define   ES_1371_MPWR          (1<<5)		/* power level interrupt pending */
  #define   ES_MCCB		(1<<4)		/* CCB interrupt pending */
  #define   ES_UART		(1<<3)		/* UART interrupt pending */
  #define   ES_DAC1		(1<<2)		/* DAC1 channel interrupt pending */
  #define   ES_DAC2		(1<<1)		/* DAC2 channel interrupt pending */
  #define   ES_ADC		(1<<0)		/* ADC channel interrupt pending */
  #define ES_REG_UART_DATA 0x08	/* R/W: UART data register */
  #define ES_REG_UART_STATUS 0x09	/* R/O: UART status register */
  #define   ES_RXINT		(1<<7)		/* RX interrupt occurred */
  #define   ES_TXINT		(1<<2)		/* TX interrupt occurred */
  #define   ES_TXRDY		(1<<1)		/* transmitter ready */
  #define   ES_RXRDY		(1<<0)		/* receiver ready */
  #define ES_REG_UART_CONTROL 0x09	/* W/O: UART control register */
  #define   ES_RXINTEN		(1<<7)		/* RX interrupt enable */
  #define   ES_TXINTENO(o)	(((o)&0x03)<<5)	/* TX interrupt enable */
  #define   ES_TXINTENM		(0x03<<5)	/* mask for above */
  #define   ES_TXINTENI(i)	(((i)>>5)&0x03)
  #define   ES_CNTRL(o)		(((o)&0x03)<<0)	/* control */
  #define   ES_CNTRLM		(0x03<<0)	/* mask for above */
  #define ES_REG_UART_RES	0x0a	/* R/W: UART reserver register */
  #define   ES_TEST_MODE		(1<<0)		/* test mode enabled */
  #define ES_REG_MEM_PAGE	0x0c	/* R/W: Memory page register */
  #define   ES_MEM_PAGEO(o)	(((o)&0x0f)<<0)	/* memory page select - out */
  #define   ES_MEM_PAGEM		(0x0f<<0)	/* mask for above */
  #define   ES_MEM_PAGEI(i)	(((i)>>0)&0x0f) /* memory page select - in */
  #define ES_REG_1370_CODEC 0x10	/* W/O: Codec write register address */
  #define   ES_1370_CODEC_WRITE(a,d) ((((a)&0xff)<<8)|(((d)&0xff)<<0))
  #define ES_REG_1371_CODEC 0x14	/* W/R: Codec Read/Write register address */
  #define   ES_1371_CODEC_RDY	   (1<<31)	/* codec ready */
  #define   ES_1371_CODEC_WIP	   (1<<30)	/* codec register access in progress */
6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
227
  #define   EV_1938_CODEC_MAGIC	   (1<<26)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
282
283
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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
  #define   ES_1371_CODEC_PIRD	   (1<<23)	/* codec read/write select register */
  #define   ES_1371_CODEC_WRITE(a,d) ((((a)&0x7f)<<16)|(((d)&0xffff)<<0))
  #define   ES_1371_CODEC_READS(a)   ((((a)&0x7f)<<16)|ES_1371_CODEC_PIRD)
  #define   ES_1371_CODEC_READ(i)    (((i)>>0)&0xffff)
  
  #define ES_REG_1371_SMPRATE 0x10	/* W/R: Codec rate converter interface register */
  #define   ES_1371_SRC_RAM_ADDRO(o) (((o)&0x7f)<<25)/* address of the sample rate converter */
  #define   ES_1371_SRC_RAM_ADDRM	   (0x7f<<25)	/* mask for above */
  #define   ES_1371_SRC_RAM_ADDRI(i) (((i)>>25)&0x7f)/* address of the sample rate converter */
  #define   ES_1371_SRC_RAM_WE	   (1<<24)	/* R/W: read/write control for sample rate converter */
  #define   ES_1371_SRC_RAM_BUSY     (1<<23)	/* R/O: sample rate memory is busy */
  #define   ES_1371_SRC_DISABLE      (1<<22)	/* sample rate converter disable */
  #define   ES_1371_DIS_P1	   (1<<21)	/* playback channel 1 accumulator update disable */
  #define   ES_1371_DIS_P2	   (1<<20)	/* playback channel 1 accumulator update disable */
  #define   ES_1371_DIS_R1	   (1<<19)	/* capture channel accumulator update disable */
  #define   ES_1371_SRC_RAM_DATAO(o) (((o)&0xffff)<<0)/* current value of the sample rate converter */
  #define   ES_1371_SRC_RAM_DATAM	   (0xffff<<0)	/* mask for above */
  #define   ES_1371_SRC_RAM_DATAI(i) (((i)>>0)&0xffff)/* current value of the sample rate converter */
  
  #define ES_REG_1371_LEGACY 0x18	/* W/R: Legacy control/status register */
  #define   ES_1371_JFAST		(1<<31)		/* fast joystick timing */
  #define   ES_1371_HIB		(1<<30)		/* host interrupt blocking enable */
  #define   ES_1371_VSB		(1<<29)		/* SB; 0 = addr 0x220xH, 1 = 0x22FxH */
  #define   ES_1371_VMPUO(o)	(((o)&0x03)<<27)/* base register address; 0 = 0x320xH; 1 = 0x330xH; 2 = 0x340xH; 3 = 0x350xH */
  #define   ES_1371_VMPUM		(0x03<<27)	/* mask for above */
  #define   ES_1371_VMPUI(i)	(((i)>>27)&0x03)/* base register address */
  #define   ES_1371_VCDCO(o)	(((o)&0x03)<<25)/* CODEC; 0 = 0x530xH; 1 = undefined; 2 = 0xe80xH; 3 = 0xF40xH */
  #define   ES_1371_VCDCM		(0x03<<25)	/* mask for above */
  #define   ES_1371_VCDCI(i)	(((i)>>25)&0x03)/* CODEC address */
  #define   ES_1371_FIRQ		(1<<24)		/* force an interrupt */
  #define   ES_1371_SDMACAP	(1<<23)		/* enable event capture for slave DMA controller */
  #define   ES_1371_SPICAP	(1<<22)		/* enable event capture for slave IRQ controller */
  #define   ES_1371_MDMACAP	(1<<21)		/* enable event capture for master DMA controller */
  #define   ES_1371_MPICAP	(1<<20)		/* enable event capture for master IRQ controller */
  #define   ES_1371_ADCAP		(1<<19)		/* enable event capture for ADLIB register; 0x388xH */
  #define   ES_1371_SVCAP		(1<<18)		/* enable event capture for SB registers */
  #define   ES_1371_CDCCAP	(1<<17)		/* enable event capture for CODEC registers */
  #define   ES_1371_BACAP		(1<<16)		/* enable event capture for SoundScape base address */
  #define   ES_1371_EXI(i)	(((i)>>8)&0x07)	/* event number */
  #define   ES_1371_AI(i)		(((i)>>3)&0x1f)	/* event significant I/O address */
  #define   ES_1371_WR		(1<<2)	/* event capture; 0 = read; 1 = write */
  #define   ES_1371_LEGINT	(1<<0)	/* interrupt for legacy events; 0 = interrupt did occur */
  
  #define ES_REG_CHANNEL_STATUS 0x1c /* R/W: first 32-bits from S/PDIF channel status block, es1373 */
  
  #define ES_REG_SERIAL	0x20	/* R/W: Serial interface control register */
  #define   ES_1371_DAC_TEST	(1<<22)		/* DAC test mode enable */
  #define   ES_P2_END_INCO(o)	(((o)&0x07)<<19)/* binary offset value to increment / loop end */
  #define   ES_P2_END_INCM	(0x07<<19)	/* mask for above */
  #define   ES_P2_END_INCI(i)	(((i)>>16)&0x07)/* binary offset value to increment / loop end */
  #define   ES_P2_ST_INCO(o)	(((o)&0x07)<<16)/* binary offset value to increment / start */
  #define   ES_P2_ST_INCM		(0x07<<16)	/* mask for above */
  #define   ES_P2_ST_INCI(i)	(((i)<<16)&0x07)/* binary offset value to increment / start */
  #define   ES_R1_LOOP_SEL	(1<<15)		/* ADC; 0 - loop mode; 1 = stop mode */
  #define   ES_P2_LOOP_SEL	(1<<14)		/* DAC2; 0 - loop mode; 1 = stop mode */
  #define   ES_P1_LOOP_SEL	(1<<13)		/* DAC1; 0 - loop mode; 1 = stop mode */
  #define   ES_P2_PAUSE		(1<<12)		/* DAC2; 0 - play mode; 1 = pause mode */
  #define   ES_P1_PAUSE		(1<<11)		/* DAC1; 0 - play mode; 1 = pause mode */
  #define   ES_R1_INT_EN		(1<<10)		/* ADC interrupt enable */
  #define   ES_P2_INT_EN		(1<<9)		/* DAC2 interrupt enable */
  #define   ES_P1_INT_EN		(1<<8)		/* DAC1 interrupt enable */
  #define   ES_P1_SCT_RLD		(1<<7)		/* force sample counter reload for DAC1 */
  #define   ES_P2_DAC_SEN		(1<<6)		/* when stop mode: 0 - DAC2 play back zeros; 1 = DAC2 play back last sample */
  #define   ES_R1_MODEO(o)	(((o)&0x03)<<4)	/* ADC mode; 0 = 8-bit mono; 1 = 8-bit stereo; 2 = 16-bit mono; 3 = 16-bit stereo */
  #define   ES_R1_MODEM		(0x03<<4)	/* mask for above */
  #define   ES_R1_MODEI(i)	(((i)>>4)&0x03)
  #define   ES_P2_MODEO(o)	(((o)&0x03)<<2)	/* DAC2 mode; -- '' -- */
  #define   ES_P2_MODEM		(0x03<<2)	/* mask for above */
  #define   ES_P2_MODEI(i)	(((i)>>2)&0x03)
  #define   ES_P1_MODEO(o)	(((o)&0x03)<<0)	/* DAC1 mode; -- '' -- */
  #define   ES_P1_MODEM		(0x03<<0)	/* mask for above */
  #define   ES_P1_MODEI(i)	(((i)>>0)&0x03)
  
  #define ES_REG_DAC1_COUNT 0x24	/* R/W: DAC1 sample count register */
  #define ES_REG_DAC2_COUNT 0x28	/* R/W: DAC2 sample count register */
  #define ES_REG_ADC_COUNT  0x2c	/* R/W: ADC sample count register */
  #define   ES_REG_CURR_COUNT(i)  (((i)>>16)&0xffff)
  #define   ES_REG_COUNTO(o)	(((o)&0xffff)<<0)
  #define   ES_REG_COUNTM		(0xffff<<0)
  #define   ES_REG_COUNTI(i)	(((i)>>0)&0xffff)
  
  #define ES_REG_DAC1_FRAME 0x30	/* R/W: PAGE 0x0c; DAC1 frame address */
  #define ES_REG_DAC1_SIZE  0x34	/* R/W: PAGE 0x0c; DAC1 frame size */
  #define ES_REG_DAC2_FRAME 0x38	/* R/W: PAGE 0x0c; DAC2 frame address */
  #define ES_REG_DAC2_SIZE  0x3c	/* R/W: PAGE 0x0c; DAC2 frame size */
  #define ES_REG_ADC_FRAME  0x30	/* R/W: PAGE 0x0d; ADC frame address */
  #define ES_REG_ADC_SIZE	  0x34	/* R/W: PAGE 0x0d; ADC frame size */
  #define   ES_REG_FCURR_COUNTO(o) (((o)&0xffff)<<16)
  #define   ES_REG_FCURR_COUNTM    (0xffff<<16)
  #define   ES_REG_FCURR_COUNTI(i) (((i)>>14)&0x3fffc)
  #define   ES_REG_FSIZEO(o)	 (((o)&0xffff)<<0)
  #define   ES_REG_FSIZEM		 (0xffff<<0)
  #define   ES_REG_FSIZEI(i)	 (((i)>>0)&0xffff)
  #define ES_REG_PHANTOM_FRAME 0x38 /* R/W: PAGE 0x0d: phantom frame address */
  #define ES_REG_PHANTOM_COUNT 0x3c /* R/W: PAGE 0x0d: phantom frame count */
  
  #define ES_REG_UART_FIFO  0x30	/* R/W: PAGE 0x0e; UART FIFO register */
  #define   ES_REG_UF_VALID	 (1<<8)
  #define   ES_REG_UF_BYTEO(o)	 (((o)&0xff)<<0)
  #define   ES_REG_UF_BYTEM	 (0xff<<0)
  #define   ES_REG_UF_BYTEI(i)	 (((i)>>0)&0xff)
  
  
  /*
   *  Pages
   */
  
  #define ES_PAGE_DAC	0x0c
  #define ES_PAGE_ADC	0x0d
  #define ES_PAGE_UART	0x0e
  #define ES_PAGE_UART1	0x0f
  
  /*
   *  Sample rate converter addresses
   */
  
  #define ES_SMPREG_DAC1		0x70
  #define ES_SMPREG_DAC2		0x74
  #define ES_SMPREG_ADC		0x78
  #define ES_SMPREG_VOL_ADC	0x6c
  #define ES_SMPREG_VOL_DAC1	0x7c
  #define ES_SMPREG_VOL_DAC2	0x7e
  #define ES_SMPREG_TRUNC_N	0x00
  #define ES_SMPREG_INT_REGS	0x01
  #define ES_SMPREG_ACCUM_FRAC	0x02
  #define ES_SMPREG_VFREQ_FRAC	0x03
  
  /*
   *  Some contants
   */
  
  #define ES_1370_SRCLOCK	   1411200
  #define ES_1370_SRTODIV(x) (ES_1370_SRCLOCK/(x)-2)
  
  /*
   *  Open modes
   */
  
  #define ES_MODE_PLAY1	0x0001
  #define ES_MODE_PLAY2	0x0002
  #define ES_MODE_CAPTURE	0x0004
  
  #define ES_MODE_OUTPUT	0x0001	/* for MIDI */
  #define ES_MODE_INPUT	0x0002	/* for MIDI */
  
  /*
  
   */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
376
  struct ensoniq {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
377
  	spinlock_t reg_lock;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
378
  	struct mutex src_mutex;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
  
  	int irq;
  
  	unsigned long playback1size;
  	unsigned long playback2size;
  	unsigned long capture3size;
  
  	unsigned long port;
  	unsigned int mode;
  	unsigned int uartm;	/* UART mode */
  
  	unsigned int ctrl;	/* control register */
  	unsigned int sctrl;	/* serial control register */
  	unsigned int cssr;	/* control status register */
  	unsigned int uartc;	/* uart control register */
  	unsigned int rev;	/* chip revision */
  
  	union {
  #ifdef CHIP1371
  		struct {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
399
  			struct snd_ac97 *ac97;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
401
402
403
  		} es1371;
  #else
  		struct {
  			int pclkdiv_lock;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
404
  			struct snd_ak4531 *ak4531;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
405
406
407
408
409
  		} es1370;
  #endif
  	} u;
  
  	struct pci_dev *pci;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
410
411
412
413
414
415
  	struct snd_card *card;
  	struct snd_pcm *pcm1;	/* DAC1/ADC PCM */
  	struct snd_pcm *pcm2;	/* DAC2 PCM */
  	struct snd_pcm_substream *playback1_substream;
  	struct snd_pcm_substream *playback2_substream;
  	struct snd_pcm_substream *capture_substream;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
416
417
418
419
420
421
  	unsigned int p1_dma_size;
  	unsigned int p2_dma_size;
  	unsigned int c_dma_size;
  	unsigned int p1_period_size;
  	unsigned int p2_period_size;
  	unsigned int c_period_size;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
422
423
424
  	struct snd_rawmidi *rmidi;
  	struct snd_rawmidi_substream *midi_input;
  	struct snd_rawmidi_substream *midi_output;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
425
426
427
428
429
430
431
432
433
434
435
436
437
  
  	unsigned int spdif;
  	unsigned int spdif_default;
  	unsigned int spdif_stream;
  
  #ifdef CHIP1370
  	struct snd_dma_buffer dma_bug;
  #endif
  
  #ifdef SUPPORT_JOYSTICK
  	struct gameport *gameport;
  #endif
  };
7d12e780e   David Howells   IRQ: Maintain reg...
438
  static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
439

cebe41d4b   Alexey Dobriyan   sound: use DEFINE...
440
  static DEFINE_PCI_DEVICE_TABLE(snd_audiopci_ids) = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
441
  #ifdef CHIP1370
28d27aae9   Joe Perches   sound: Use PCI_VD...
442
  	{ PCI_VDEVICE(ENSONIQ, 0x5000), 0, },	/* ES1370 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443
444
  #endif
  #ifdef CHIP1371
28d27aae9   Joe Perches   sound: Use PCI_VD...
445
446
  	{ PCI_VDEVICE(ENSONIQ, 0x1371), 0, },	/* ES1371 */
  	{ PCI_VDEVICE(ENSONIQ, 0x5880), 0, },	/* ES1373 - CT5880 */
0d7392e54   Joe Perches   sound: Use PCI_VD...
447
  	{ PCI_VDEVICE(ECTIVA, 0x8938), 0, },	/* Ectiva EV1938 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
  #endif
  	{ 0, }
  };
  
  MODULE_DEVICE_TABLE(pci, snd_audiopci_ids);
  
  /*
   *  constants
   */
  
  #define POLL_COUNT	0xa000
  
  #ifdef CHIP1370
  static unsigned int snd_es1370_fixed_rates[] =
  	{5512, 11025, 22050, 44100};
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
463
  static struct snd_pcm_hw_constraint_list snd_es1370_hw_constraints_rates = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
464
465
466
467
  	.count = 4, 
  	.list = snd_es1370_fixed_rates,
  	.mask = 0,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
468
  static struct snd_ratnum es1370_clock = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
469
470
471
472
473
  	.num = ES_1370_SRCLOCK,
  	.den_min = 29, 
  	.den_max = 353,
  	.den_step = 1,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
474
  static struct snd_pcm_hw_constraint_ratnums snd_es1370_hw_constraints_clock = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
475
476
477
478
  	.nrats = 1,
  	.rats = &es1370_clock,
  };
  #else
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
479
  static struct snd_ratden es1371_dac_clock = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
480
481
482
483
484
  	.num_min = 3000 * (1 << 15),
  	.num_max = 48000 * (1 << 15),
  	.num_step = 3000,
  	.den = 1 << 15,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
485
  static struct snd_pcm_hw_constraint_ratdens snd_es1371_hw_constraints_dac_clock = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
486
487
488
  	.nrats = 1,
  	.rats = &es1371_dac_clock,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
489
  static struct snd_ratnum es1371_adc_clock = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
490
491
492
493
494
  	.num = 48000 << 15,
  	.den_min = 32768, 
  	.den_max = 393216,
  	.den_step = 1,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
495
  static struct snd_pcm_hw_constraint_ratnums snd_es1371_hw_constraints_adc_clock = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
496
497
498
499
500
501
502
503
504
505
506
507
  	.nrats = 1,
  	.rats = &es1371_adc_clock,
  };
  #endif
  static const unsigned int snd_ensoniq_sample_shift[] =
  	{0, 1, 1, 2};
  
  /*
   *  common I/O routines
   */
  
  #ifdef CHIP1371
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
508
  static unsigned int snd_es1371_wait_src_ready(struct ensoniq * ensoniq)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
509
510
511
512
513
514
515
516
517
  {
  	unsigned int t, r = 0;
  
  	for (t = 0; t < POLL_COUNT; t++) {
  		r = inl(ES_REG(ensoniq, 1371_SMPRATE));
  		if ((r & ES_1371_SRC_RAM_BUSY) == 0)
  			return r;
  		cond_resched();
  	}
810fd3f3f   Rene Herman   ALSA: ens1370: SR...
518
519
  	snd_printk(KERN_ERR "wait src ready timeout 0x%lx [0x%x]
  ",
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
520
  		   ES_REG(ensoniq, 1371_SMPRATE), r);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
521
522
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
523
  static unsigned int snd_es1371_src_read(struct ensoniq * ensoniq, unsigned short reg)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
  {
  	unsigned int temp, i, orig, r;
  
  	/* wait for ready */
  	temp = orig = snd_es1371_wait_src_ready(ensoniq);
  
  	/* expose the SRC state bits */
  	r = temp & (ES_1371_SRC_DISABLE | ES_1371_DIS_P1 |
  		    ES_1371_DIS_P2 | ES_1371_DIS_R1);
  	r |= ES_1371_SRC_RAM_ADDRO(reg) | 0x10000;
  	outl(r, ES_REG(ensoniq, 1371_SMPRATE));
  
  	/* now, wait for busy and the correct time to read */
  	temp = snd_es1371_wait_src_ready(ensoniq);
  	
  	if ((temp & 0x00870000) != 0x00010000) {
  		/* wait for the right state */
  		for (i = 0; i < POLL_COUNT; i++) {
  			temp = inl(ES_REG(ensoniq, 1371_SMPRATE));
  			if ((temp & 0x00870000) == 0x00010000)
  				break;
  		}
  	}
  
  	/* hide the state bits */	
  	r = orig & (ES_1371_SRC_DISABLE | ES_1371_DIS_P1 |
  		   ES_1371_DIS_P2 | ES_1371_DIS_R1);
  	r |= ES_1371_SRC_RAM_ADDRO(reg);
  	outl(r, ES_REG(ensoniq, 1371_SMPRATE));
  	
  	return temp;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
556
  static void snd_es1371_src_write(struct ensoniq * ensoniq,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557
558
559
560
561
562
563
564
565
566
567
568
569
570
  				 unsigned short reg, unsigned short data)
  {
  	unsigned int r;
  
  	r = snd_es1371_wait_src_ready(ensoniq) &
  	    (ES_1371_SRC_DISABLE | ES_1371_DIS_P1 |
  	     ES_1371_DIS_P2 | ES_1371_DIS_R1);
  	r |= ES_1371_SRC_RAM_ADDRO(reg) | ES_1371_SRC_RAM_DATAO(data);
  	outl(r | ES_1371_SRC_RAM_WE, ES_REG(ensoniq, 1371_SMPRATE));
  }
  
  #endif /* CHIP1371 */
  
  #ifdef CHIP1370
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
571
  static void snd_es1370_codec_write(struct snd_ak4531 *ak4531,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
572
573
  				   unsigned short reg, unsigned short val)
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
574
  	struct ensoniq *ensoniq = ak4531->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
575
576
577
  	unsigned long end_time = jiffies + HZ / 10;
  
  #if 0
ee419653a   Takashi Iwai   ALSA: Fix missing...
578
579
580
  	printk(KERN_DEBUG
  	       "CODEC WRITE: reg = 0x%x, val = 0x%x (0x%x), creg = 0x%x
  ",
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
581
  	       reg, val, ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
582
583
584
585
586
587
  #endif
  	do {
  		if (!(inl(ES_REG(ensoniq, STATUS)) & ES_1370_CSTAT)) {
  			outw(ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC));
  			return;
  		}
8433a509c   Nishanth Aravamudan   [ALSA] Fix schedu...
588
  		schedule_timeout_uninterruptible(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
589
  	} while (time_after(end_time, jiffies));
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
590
591
592
  	snd_printk(KERN_ERR "codec write timeout, status = 0x%x
  ",
  		   inl(ES_REG(ensoniq, STATUS)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
593
594
595
596
597
  }
  
  #endif /* CHIP1370 */
  
  #ifdef CHIP1371
6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
598
599
600
601
  static inline bool is_ev1938(struct ensoniq *ensoniq)
  {
  	return ensoniq->pci->device == 0x8938;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
602
  static void snd_es1371_codec_write(struct snd_ac97 *ac97,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
603
604
  				   unsigned short reg, unsigned short val)
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
605
  	struct ensoniq *ensoniq = ac97->private_data;
6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
606
  	unsigned int t, x, flag;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
607

6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
608
  	flag = is_ev1938(ensoniq) ? EV_1938_CODEC_MAGIC : 0;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
609
  	mutex_lock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
610
611
612
613
614
615
616
617
618
619
  	for (t = 0; t < POLL_COUNT; t++) {
  		if (!(inl(ES_REG(ensoniq, 1371_CODEC)) & ES_1371_CODEC_WIP)) {
  			/* save the current state for latter */
  			x = snd_es1371_wait_src_ready(ensoniq);
  			outl((x & (ES_1371_SRC_DISABLE | ES_1371_DIS_P1 |
  			           ES_1371_DIS_P2 | ES_1371_DIS_R1)) | 0x00010000,
  			     ES_REG(ensoniq, 1371_SMPRATE));
  			/* wait for not busy (state 0) first to avoid
  			   transition states */
  			for (t = 0; t < POLL_COUNT; t++) {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
620
621
  				if ((inl(ES_REG(ensoniq, 1371_SMPRATE)) & 0x00870000) ==
  				    0x00000000)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
622
623
624
625
  					break;
  			}
  			/* wait for a SAFE time to write addr/data and then do it, dammit */
  			for (t = 0; t < POLL_COUNT; t++) {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
626
627
  				if ((inl(ES_REG(ensoniq, 1371_SMPRATE)) & 0x00870000) ==
  				    0x00010000)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
628
629
  					break;
  			}
6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
630
631
  			outl(ES_1371_CODEC_WRITE(reg, val) | flag,
  			     ES_REG(ensoniq, 1371_CODEC));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
632
633
634
  			/* restore SRC reg */
  			snd_es1371_wait_src_ready(ensoniq);
  			outl(x, ES_REG(ensoniq, 1371_SMPRATE));
62932df8f   Ingo Molnar   [ALSA] semaphore ...
635
  			mutex_unlock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
636
637
638
  			return;
  		}
  	}
62932df8f   Ingo Molnar   [ALSA] semaphore ...
639
  	mutex_unlock(&ensoniq->src_mutex);
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
640
641
642
  	snd_printk(KERN_ERR "codec write timeout at 0x%lx [0x%x]
  ",
  		   ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
643
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
644
  static unsigned short snd_es1371_codec_read(struct snd_ac97 *ac97,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
645
646
  					    unsigned short reg)
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
647
  	struct ensoniq *ensoniq = ac97->private_data;
6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
648
  	unsigned int t, x, flag, fail = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
649

6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
650
  	flag = is_ev1938(ensoniq) ? EV_1938_CODEC_MAGIC : 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
651
        __again:
62932df8f   Ingo Molnar   [ALSA] semaphore ...
652
  	mutex_lock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
653
654
655
656
657
658
659
660
661
662
  	for (t = 0; t < POLL_COUNT; t++) {
  		if (!(inl(ES_REG(ensoniq, 1371_CODEC)) & ES_1371_CODEC_WIP)) {
  			/* save the current state for latter */
  			x = snd_es1371_wait_src_ready(ensoniq);
  			outl((x & (ES_1371_SRC_DISABLE | ES_1371_DIS_P1 |
  			           ES_1371_DIS_P2 | ES_1371_DIS_R1)) | 0x00010000,
  			     ES_REG(ensoniq, 1371_SMPRATE));
  			/* wait for not busy (state 0) first to avoid
  			   transition states */
  			for (t = 0; t < POLL_COUNT; t++) {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
663
664
  				if ((inl(ES_REG(ensoniq, 1371_SMPRATE)) & 0x00870000) ==
  				    0x00000000)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
665
666
667
668
  					break;
  			}
  			/* wait for a SAFE time to write addr/data and then do it, dammit */
  			for (t = 0; t < POLL_COUNT; t++) {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
669
670
  				if ((inl(ES_REG(ensoniq, 1371_SMPRATE)) & 0x00870000) ==
  				    0x00010000)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
671
672
  					break;
  			}
6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
673
674
  			outl(ES_1371_CODEC_READS(reg) | flag,
  			     ES_REG(ensoniq, 1371_CODEC));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
675
676
677
678
679
680
681
682
683
684
685
  			/* restore SRC reg */
  			snd_es1371_wait_src_ready(ensoniq);
  			outl(x, ES_REG(ensoniq, 1371_SMPRATE));
  			/* wait for WIP again */
  			for (t = 0; t < POLL_COUNT; t++) {
  				if (!(inl(ES_REG(ensoniq, 1371_CODEC)) & ES_1371_CODEC_WIP))
  					break;		
  			}
  			/* now wait for the stinkin' data (RDY) */
  			for (t = 0; t < POLL_COUNT; t++) {
  				if ((x = inl(ES_REG(ensoniq, 1371_CODEC))) & ES_1371_CODEC_RDY) {
6ebb8a4a4   Clemens Ladisch   ALSA: ens1371: fi...
686
687
688
689
690
  					if (is_ev1938(ensoniq)) {
  						for (t = 0; t < 100; t++)
  							inl(ES_REG(ensoniq, CONTROL));
  						x = inl(ES_REG(ensoniq, 1371_CODEC));
  					}
62932df8f   Ingo Molnar   [ALSA] semaphore ...
691
  					mutex_unlock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
692
693
694
  					return ES_1371_CODEC_READ(x);
  				}
  			}
62932df8f   Ingo Molnar   [ALSA] semaphore ...
695
  			mutex_unlock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
696
  			if (++fail > 10) {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
697
698
699
700
701
  				snd_printk(KERN_ERR "codec read timeout (final) "
  					   "at 0x%lx, reg = 0x%x [0x%x]
  ",
  					   ES_REG(ensoniq, 1371_CODEC), reg,
  					   inl(ES_REG(ensoniq, 1371_CODEC)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
702
703
704
705
706
  				return 0;
  			}
  			goto __again;
  		}
  	}
62932df8f   Ingo Molnar   [ALSA] semaphore ...
707
  	mutex_unlock(&ensoniq->src_mutex);
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
708
709
710
  	snd_printk(KERN_ERR "es1371: codec read timeout at 0x%lx [0x%x]
  ",
  		   ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
711
712
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
713
  static void snd_es1371_codec_wait(struct snd_ac97 *ac97)
072c01194   Jaroslav Kysela   [ALSA] ens1371 - ...
714
715
716
717
718
719
720
  {
  	msleep(750);
  	snd_es1371_codec_read(ac97, AC97_RESET);
  	snd_es1371_codec_read(ac97, AC97_VENDOR_ID1);
  	snd_es1371_codec_read(ac97, AC97_VENDOR_ID2);
  	msleep(50);
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
721
  static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
722
723
  {
  	unsigned int n, truncm, freq, result;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
724
  	mutex_lock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
  	n = rate / 3000;
  	if ((1 << n) & ((1 << 15) | (1 << 13) | (1 << 11) | (1 << 9)))
  		n--;
  	truncm = (21 * n - 1) | 1;
  	freq = ((48000UL << 15) / rate) * n;
  	result = (48000UL << 15) / (freq / n);
  	if (rate >= 24000) {
  		if (truncm > 239)
  			truncm = 239;
  		snd_es1371_src_write(ensoniq, ES_SMPREG_ADC + ES_SMPREG_TRUNC_N,
  				(((239 - truncm) >> 1) << 9) | (n << 4));
  	} else {
  		if (truncm > 119)
  			truncm = 119;
  		snd_es1371_src_write(ensoniq, ES_SMPREG_ADC + ES_SMPREG_TRUNC_N,
  				0x8000 | (((119 - truncm) >> 1) << 9) | (n << 4));
  	}
  	snd_es1371_src_write(ensoniq, ES_SMPREG_ADC + ES_SMPREG_INT_REGS,
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
743
744
745
  			     (snd_es1371_src_read(ensoniq, ES_SMPREG_ADC +
  						  ES_SMPREG_INT_REGS) & 0x00ff) |
  			     ((freq >> 5) & 0xfc00));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
746
747
748
  	snd_es1371_src_write(ensoniq, ES_SMPREG_ADC + ES_SMPREG_VFREQ_FRAC, freq & 0x7fff);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_ADC, n << 8);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_ADC + 1, n << 8);
62932df8f   Ingo Molnar   [ALSA] semaphore ...
749
  	mutex_unlock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
750
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
751
  static void snd_es1371_dac1_rate(struct ensoniq * ensoniq, unsigned int rate)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
752
753
  {
  	unsigned int freq, r;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
754
  	mutex_lock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
755
  	freq = ((rate << 15) + 1500) / 3000;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
756
757
758
  	r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE |
  						   ES_1371_DIS_P2 | ES_1371_DIS_R1)) |
  		ES_1371_DIS_P1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
759
760
  	outl(r, ES_REG(ensoniq, 1371_SMPRATE));
  	snd_es1371_src_write(ensoniq, ES_SMPREG_DAC1 + ES_SMPREG_INT_REGS,
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
761
762
  			     (snd_es1371_src_read(ensoniq, ES_SMPREG_DAC1 +
  						  ES_SMPREG_INT_REGS) & 0x00ff) |
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
763
764
  			     ((freq >> 5) & 0xfc00));
  	snd_es1371_src_write(ensoniq, ES_SMPREG_DAC1 + ES_SMPREG_VFREQ_FRAC, freq & 0x7fff);
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
765
766
  	r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE |
  						   ES_1371_DIS_P2 | ES_1371_DIS_R1));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
767
  	outl(r, ES_REG(ensoniq, 1371_SMPRATE));
62932df8f   Ingo Molnar   [ALSA] semaphore ...
768
  	mutex_unlock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
769
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
770
  static void snd_es1371_dac2_rate(struct ensoniq * ensoniq, unsigned int rate)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
771
772
  {
  	unsigned int freq, r;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
773
  	mutex_lock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
774
  	freq = ((rate << 15) + 1500) / 3000;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
775
776
777
  	r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE |
  						   ES_1371_DIS_P1 | ES_1371_DIS_R1)) |
  		ES_1371_DIS_P2;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
778
779
  	outl(r, ES_REG(ensoniq, 1371_SMPRATE));
  	snd_es1371_src_write(ensoniq, ES_SMPREG_DAC2 + ES_SMPREG_INT_REGS,
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
780
781
  			     (snd_es1371_src_read(ensoniq, ES_SMPREG_DAC2 +
  						  ES_SMPREG_INT_REGS) & 0x00ff) |
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
782
  			     ((freq >> 5) & 0xfc00));
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
783
784
785
786
  	snd_es1371_src_write(ensoniq, ES_SMPREG_DAC2 + ES_SMPREG_VFREQ_FRAC,
  			     freq & 0x7fff);
  	r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE |
  						   ES_1371_DIS_P1 | ES_1371_DIS_R1));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
787
  	outl(r, ES_REG(ensoniq, 1371_SMPRATE));
62932df8f   Ingo Molnar   [ALSA] semaphore ...
788
  	mutex_unlock(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
789
790
791
  }
  
  #endif /* CHIP1371 */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
792
  static int snd_ensoniq_trigger(struct snd_pcm_substream *substream, int cmd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
793
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
794
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
795
796
797
798
799
  	switch (cmd) {
  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  	{
  		unsigned int what = 0;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
800
  		struct snd_pcm_substream *s;
ef991b95a   Takashi Iwai   [ALSA] Add snd_pc...
801
  		snd_pcm_group_for_each_entry(s, substream) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
  			if (s == ensoniq->playback1_substream) {
  				what |= ES_P1_PAUSE;
  				snd_pcm_trigger_done(s, substream);
  			} else if (s == ensoniq->playback2_substream) {
  				what |= ES_P2_PAUSE;
  				snd_pcm_trigger_done(s, substream);
  			} else if (s == ensoniq->capture_substream)
  				return -EINVAL;
  		}
  		spin_lock(&ensoniq->reg_lock);
  		if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  			ensoniq->sctrl |= what;
  		else
  			ensoniq->sctrl &= ~what;
  		outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
  		spin_unlock(&ensoniq->reg_lock);
  		break;
  	}
  	case SNDRV_PCM_TRIGGER_START:
  	case SNDRV_PCM_TRIGGER_STOP:
  	{
  		unsigned int what = 0;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
824
  		struct snd_pcm_substream *s;
ef991b95a   Takashi Iwai   [ALSA] Add snd_pc...
825
  		snd_pcm_group_for_each_entry(s, substream) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
  			if (s == ensoniq->playback1_substream) {
  				what |= ES_DAC1_EN;
  				snd_pcm_trigger_done(s, substream);
  			} else if (s == ensoniq->playback2_substream) {
  				what |= ES_DAC2_EN;
  				snd_pcm_trigger_done(s, substream);
  			} else if (s == ensoniq->capture_substream) {
  				what |= ES_ADC_EN;
  				snd_pcm_trigger_done(s, substream);
  			}
  		}
  		spin_lock(&ensoniq->reg_lock);
  		if (cmd == SNDRV_PCM_TRIGGER_START)
  			ensoniq->ctrl |= what;
  		else
  			ensoniq->ctrl &= ~what;
  		outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  		spin_unlock(&ensoniq->reg_lock);
  		break;
  	}
  	default:
  		return -EINVAL;
  	}
  	return 0;
  }
  
  /*
   *  PCM part
   */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
855
856
  static int snd_ensoniq_hw_params(struct snd_pcm_substream *substream,
  				 struct snd_pcm_hw_params *hw_params)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
857
858
859
  {
  	return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
860
  static int snd_ensoniq_hw_free(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
861
862
863
  {
  	return snd_pcm_lib_free_pages(substream);
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
864
  static int snd_ensoniq_playback1_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
865
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
866
867
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
  	unsigned int mode = 0;
  
  	ensoniq->p1_dma_size = snd_pcm_lib_buffer_bytes(substream);
  	ensoniq->p1_period_size = snd_pcm_lib_period_bytes(substream);
  	if (snd_pcm_format_width(runtime->format) == 16)
  		mode |= 0x02;
  	if (runtime->channels > 1)
  		mode |= 0x01;
  	spin_lock_irq(&ensoniq->reg_lock);
  	ensoniq->ctrl &= ~ES_DAC1_EN;
  #ifdef CHIP1371
  	/* 48k doesn't need SRC (it breaks AC3-passthru) */
  	if (runtime->rate == 48000)
  		ensoniq->ctrl |= ES_1373_BYPASS_P1;
  	else
  		ensoniq->ctrl &= ~ES_1373_BYPASS_P1;
  #endif
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE));
  	outl(runtime->dma_addr, ES_REG(ensoniq, DAC1_FRAME));
  	outl((ensoniq->p1_dma_size >> 2) - 1, ES_REG(ensoniq, DAC1_SIZE));
  	ensoniq->sctrl &= ~(ES_P1_LOOP_SEL | ES_P1_PAUSE | ES_P1_SCT_RLD | ES_P1_MODEM);
  	ensoniq->sctrl |= ES_P1_INT_EN | ES_P1_MODEO(mode);
  	outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
892
893
  	outl((ensoniq->p1_period_size >> snd_ensoniq_sample_shift[mode]) - 1,
  	     ES_REG(ensoniq, DAC1_COUNT));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
  #ifdef CHIP1370
  	ensoniq->ctrl &= ~ES_1370_WTSRSELM;
  	switch (runtime->rate) {
  	case 5512: ensoniq->ctrl |= ES_1370_WTSRSEL(0); break;
  	case 11025: ensoniq->ctrl |= ES_1370_WTSRSEL(1); break;
  	case 22050: ensoniq->ctrl |= ES_1370_WTSRSEL(2); break;
  	case 44100: ensoniq->ctrl |= ES_1370_WTSRSEL(3); break;
  	default: snd_BUG();
  	}
  #endif
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	spin_unlock_irq(&ensoniq->reg_lock);
  #ifndef CHIP1370
  	snd_es1371_dac1_rate(ensoniq, runtime->rate);
  #endif
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
911
  static int snd_ensoniq_playback2_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
912
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
913
914
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
  	unsigned int mode = 0;
  
  	ensoniq->p2_dma_size = snd_pcm_lib_buffer_bytes(substream);
  	ensoniq->p2_period_size = snd_pcm_lib_period_bytes(substream);
  	if (snd_pcm_format_width(runtime->format) == 16)
  		mode |= 0x02;
  	if (runtime->channels > 1)
  		mode |= 0x01;
  	spin_lock_irq(&ensoniq->reg_lock);
  	ensoniq->ctrl &= ~ES_DAC2_EN;
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE));
  	outl(runtime->dma_addr, ES_REG(ensoniq, DAC2_FRAME));
  	outl((ensoniq->p2_dma_size >> 2) - 1, ES_REG(ensoniq, DAC2_SIZE));
  	ensoniq->sctrl &= ~(ES_P2_LOOP_SEL | ES_P2_PAUSE | ES_P2_DAC_SEN |
  			    ES_P2_END_INCM | ES_P2_ST_INCM | ES_P2_MODEM);
  	ensoniq->sctrl |= ES_P2_INT_EN | ES_P2_MODEO(mode) |
  			  ES_P2_END_INCO(mode & 2 ? 2 : 1) | ES_P2_ST_INCO(0);
  	outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
934
935
  	outl((ensoniq->p2_period_size >> snd_ensoniq_sample_shift[mode]) - 1,
  	     ES_REG(ensoniq, DAC2_COUNT));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
936
937
938
939
940
941
942
943
944
945
946
947
948
949
  #ifdef CHIP1370
  	if (!(ensoniq->u.es1370.pclkdiv_lock & ES_MODE_CAPTURE)) {
  		ensoniq->ctrl &= ~ES_1370_PCLKDIVM;
  		ensoniq->ctrl |= ES_1370_PCLKDIVO(ES_1370_SRTODIV(runtime->rate));
  		ensoniq->u.es1370.pclkdiv_lock |= ES_MODE_PLAY2;
  	}
  #endif
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	spin_unlock_irq(&ensoniq->reg_lock);
  #ifndef CHIP1370
  	snd_es1371_dac2_rate(ensoniq, runtime->rate);
  #endif
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
950
  static int snd_ensoniq_capture_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
951
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
952
953
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
  	unsigned int mode = 0;
  
  	ensoniq->c_dma_size = snd_pcm_lib_buffer_bytes(substream);
  	ensoniq->c_period_size = snd_pcm_lib_period_bytes(substream);
  	if (snd_pcm_format_width(runtime->format) == 16)
  		mode |= 0x02;
  	if (runtime->channels > 1)
  		mode |= 0x01;
  	spin_lock_irq(&ensoniq->reg_lock);
  	ensoniq->ctrl &= ~ES_ADC_EN;
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	outl(ES_MEM_PAGEO(ES_PAGE_ADC), ES_REG(ensoniq, MEM_PAGE));
  	outl(runtime->dma_addr, ES_REG(ensoniq, ADC_FRAME));
  	outl((ensoniq->c_dma_size >> 2) - 1, ES_REG(ensoniq, ADC_SIZE));
  	ensoniq->sctrl &= ~(ES_R1_LOOP_SEL | ES_R1_MODEM);
  	ensoniq->sctrl |= ES_R1_INT_EN | ES_R1_MODEO(mode);
  	outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
971
972
  	outl((ensoniq->c_period_size >> snd_ensoniq_sample_shift[mode]) - 1,
  	     ES_REG(ensoniq, ADC_COUNT));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
973
974
975
976
977
978
979
980
981
982
983
984
985
986
  #ifdef CHIP1370
  	if (!(ensoniq->u.es1370.pclkdiv_lock & ES_MODE_PLAY2)) {
  		ensoniq->ctrl &= ~ES_1370_PCLKDIVM;
  		ensoniq->ctrl |= ES_1370_PCLKDIVO(ES_1370_SRTODIV(runtime->rate));
  		ensoniq->u.es1370.pclkdiv_lock |= ES_MODE_CAPTURE;
  	}
  #endif
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	spin_unlock_irq(&ensoniq->reg_lock);
  #ifndef CHIP1370
  	snd_es1371_adc_rate(ensoniq, runtime->rate);
  #endif
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
987
  static snd_pcm_uframes_t snd_ensoniq_playback1_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
988
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
989
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
  	size_t ptr;
  
  	spin_lock(&ensoniq->reg_lock);
  	if (inl(ES_REG(ensoniq, CONTROL)) & ES_DAC1_EN) {
  		outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE));
  		ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, DAC1_SIZE)));
  		ptr = bytes_to_frames(substream->runtime, ptr);
  	} else {
  		ptr = 0;
  	}
  	spin_unlock(&ensoniq->reg_lock);
  	return ptr;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1003
  static snd_pcm_uframes_t snd_ensoniq_playback2_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1004
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1005
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
  	size_t ptr;
  
  	spin_lock(&ensoniq->reg_lock);
  	if (inl(ES_REG(ensoniq, CONTROL)) & ES_DAC2_EN) {
  		outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE));
  		ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, DAC2_SIZE)));
  		ptr = bytes_to_frames(substream->runtime, ptr);
  	} else {
  		ptr = 0;
  	}
  	spin_unlock(&ensoniq->reg_lock);
  	return ptr;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1019
  static snd_pcm_uframes_t snd_ensoniq_capture_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1020
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1021
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
  	size_t ptr;
  
  	spin_lock(&ensoniq->reg_lock);
  	if (inl(ES_REG(ensoniq, CONTROL)) & ES_ADC_EN) {
  		outl(ES_MEM_PAGEO(ES_PAGE_ADC), ES_REG(ensoniq, MEM_PAGE));
  		ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, ADC_SIZE)));
  		ptr = bytes_to_frames(substream->runtime, ptr);
  	} else {
  		ptr = 0;
  	}
  	spin_unlock(&ensoniq->reg_lock);
  	return ptr;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1035
  static struct snd_pcm_hardware snd_ensoniq_playback1 =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
  {
  	.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_SYNC_START),
  	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  	.rates =
  #ifndef CHIP1370
  				SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  #else
  				(SNDRV_PCM_RATE_KNOT | 	/* 5512Hz rate */
  				 SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_22050 | 
  				 SNDRV_PCM_RATE_44100),
  #endif
  	.rate_min =		4000,
  	.rate_max =		48000,
  	.channels_min =		1,
  	.channels_max =		2,
  	.buffer_bytes_max =	(128*1024),
  	.period_bytes_min =	64,
  	.period_bytes_max =	(128*1024),
  	.periods_min =		1,
  	.periods_max =		1024,
  	.fifo_size =		0,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1061
  static struct snd_pcm_hardware snd_ensoniq_playback2 =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
  {
  	.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_SYNC_START),
  	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  	.rate_min =		4000,
  	.rate_max =		48000,
  	.channels_min =		1,
  	.channels_max =		2,
  	.buffer_bytes_max =	(128*1024),
  	.period_bytes_min =	64,
  	.period_bytes_max =	(128*1024),
  	.periods_min =		1,
  	.periods_max =		1024,
  	.fifo_size =		0,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1080
  static struct snd_pcm_hardware snd_ensoniq_capture =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
  {
  	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
  				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
  	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  	.rate_min =		4000,
  	.rate_max =		48000,
  	.channels_min =		1,
  	.channels_max =		2,
  	.buffer_bytes_max =	(128*1024),
  	.period_bytes_min =	64,
  	.period_bytes_max =	(128*1024),
  	.periods_min =		1,
  	.periods_max =		1024,
  	.fifo_size =		0,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1098
  static int snd_ensoniq_playback1_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1099
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1100
1101
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
  
  	ensoniq->mode |= ES_MODE_PLAY1;
  	ensoniq->playback1_substream = substream;
  	runtime->hw = snd_ensoniq_playback1;
  	snd_pcm_set_sync(substream);
  	spin_lock_irq(&ensoniq->reg_lock);
  	if (ensoniq->spdif && ensoniq->playback2_substream == NULL)
  		ensoniq->spdif_stream = ensoniq->spdif_default;
  	spin_unlock_irq(&ensoniq->reg_lock);
  #ifdef CHIP1370
  	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  				   &snd_es1370_hw_constraints_rates);
  #else
  	snd_pcm_hw_constraint_ratdens(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  				      &snd_es1371_hw_constraints_dac_clock);
  #endif
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1120
  static int snd_ensoniq_playback2_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1121
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1122
1123
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
  
  	ensoniq->mode |= ES_MODE_PLAY2;
  	ensoniq->playback2_substream = substream;
  	runtime->hw = snd_ensoniq_playback2;
  	snd_pcm_set_sync(substream);
  	spin_lock_irq(&ensoniq->reg_lock);
  	if (ensoniq->spdif && ensoniq->playback1_substream == NULL)
  		ensoniq->spdif_stream = ensoniq->spdif_default;
  	spin_unlock_irq(&ensoniq->reg_lock);
  #ifdef CHIP1370
  	snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  				      &snd_es1370_hw_constraints_clock);
  #else
  	snd_pcm_hw_constraint_ratdens(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  				      &snd_es1371_hw_constraints_dac_clock);
  #endif
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1142
  static int snd_ensoniq_capture_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1143
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1144
1145
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
  
  	ensoniq->mode |= ES_MODE_CAPTURE;
  	ensoniq->capture_substream = substream;
  	runtime->hw = snd_ensoniq_capture;
  	snd_pcm_set_sync(substream);
  #ifdef CHIP1370
  	snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  				      &snd_es1370_hw_constraints_clock);
  #else
  	snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  				      &snd_es1371_hw_constraints_adc_clock);
  #endif
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1160
  static int snd_ensoniq_playback1_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1161
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1162
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1163
1164
1165
1166
1167
  
  	ensoniq->playback1_substream = NULL;
  	ensoniq->mode &= ~ES_MODE_PLAY1;
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1168
  static int snd_ensoniq_playback2_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1169
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1170
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
  
  	ensoniq->playback2_substream = NULL;
  	spin_lock_irq(&ensoniq->reg_lock);
  #ifdef CHIP1370
  	ensoniq->u.es1370.pclkdiv_lock &= ~ES_MODE_PLAY2;
  #endif
  	ensoniq->mode &= ~ES_MODE_PLAY2;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1181
  static int snd_ensoniq_capture_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1182
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1183
  	struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
  
  	ensoniq->capture_substream = NULL;
  	spin_lock_irq(&ensoniq->reg_lock);
  #ifdef CHIP1370
  	ensoniq->u.es1370.pclkdiv_lock &= ~ES_MODE_CAPTURE;
  #endif
  	ensoniq->mode &= ~ES_MODE_CAPTURE;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1194
  static struct snd_pcm_ops snd_ensoniq_playback1_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1195
1196
1197
1198
1199
1200
1201
1202
1203
  	.open =		snd_ensoniq_playback1_open,
  	.close =	snd_ensoniq_playback1_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_ensoniq_hw_params,
  	.hw_free =	snd_ensoniq_hw_free,
  	.prepare =	snd_ensoniq_playback1_prepare,
  	.trigger =	snd_ensoniq_trigger,
  	.pointer =	snd_ensoniq_playback1_pointer,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1204
  static struct snd_pcm_ops snd_ensoniq_playback2_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1205
1206
1207
1208
1209
1210
1211
1212
1213
  	.open =		snd_ensoniq_playback2_open,
  	.close =	snd_ensoniq_playback2_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_ensoniq_hw_params,
  	.hw_free =	snd_ensoniq_hw_free,
  	.prepare =	snd_ensoniq_playback2_prepare,
  	.trigger =	snd_ensoniq_trigger,
  	.pointer =	snd_ensoniq_playback2_pointer,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1214
  static struct snd_pcm_ops snd_ensoniq_capture_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1215
1216
1217
1218
1219
1220
1221
1222
1223
  	.open =		snd_ensoniq_capture_open,
  	.close =	snd_ensoniq_capture_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_ensoniq_hw_params,
  	.hw_free =	snd_ensoniq_hw_free,
  	.prepare =	snd_ensoniq_capture_prepare,
  	.trigger =	snd_ensoniq_trigger,
  	.pointer =	snd_ensoniq_capture_pointer,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1224
1225
  static int __devinit snd_ensoniq_pcm(struct ensoniq * ensoniq, int device,
  				     struct snd_pcm ** rpcm)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1226
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1227
  	struct snd_pcm *pcm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
  	int err;
  
  	if (rpcm)
  		*rpcm = NULL;
  #ifdef CHIP1370
  	err = snd_pcm_new(ensoniq->card, "ES1370/1", device, 1, 1, &pcm);
  #else
  	err = snd_pcm_new(ensoniq->card, "ES1371/1", device, 1, 1, &pcm);
  #endif
  	if (err < 0)
  		return err;
  
  #ifdef CHIP1370
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ensoniq_playback2_ops);
  #else
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ensoniq_playback1_ops);
  #endif
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ensoniq_capture_ops);
  
  	pcm->private_data = ensoniq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
  	pcm->info_flags = 0;
  #ifdef CHIP1370
  	strcpy(pcm->name, "ES1370 DAC2/ADC");
  #else
  	strcpy(pcm->name, "ES1371 DAC2/ADC");
  #endif
  	ensoniq->pcm1 = pcm;
  
  	snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  					      snd_dma_pci_data(ensoniq->pci), 64*1024, 128*1024);
  
  	if (rpcm)
  		*rpcm = pcm;
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1263
1264
  static int __devinit snd_ensoniq_pcm2(struct ensoniq * ensoniq, int device,
  				      struct snd_pcm ** rpcm)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1265
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1266
  	struct snd_pcm *pcm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
  	int err;
  
  	if (rpcm)
  		*rpcm = NULL;
  #ifdef CHIP1370
  	err = snd_pcm_new(ensoniq->card, "ES1370/2", device, 1, 0, &pcm);
  #else
  	err = snd_pcm_new(ensoniq->card, "ES1371/2", device, 1, 0, &pcm);
  #endif
  	if (err < 0)
  		return err;
  
  #ifdef CHIP1370
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ensoniq_playback1_ops);
  #else
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ensoniq_playback2_ops);
  #endif
  	pcm->private_data = ensoniq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
  	pcm->info_flags = 0;
  #ifdef CHIP1370
  	strcpy(pcm->name, "ES1370 DAC1");
  #else
  	strcpy(pcm->name, "ES1371 DAC1");
  #endif
  	ensoniq->pcm2 = pcm;
  
  	snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  					      snd_dma_pci_data(ensoniq->pci), 64*1024, 128*1024);
  
  	if (rpcm)
  		*rpcm = pcm;
  	return 0;
  }
  
  /*
   *  Mixer section
   */
  
  /*
   * ENS1371 mixer (including SPDIF interface)
   */
  #ifdef CHIP1371
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1309
1310
  static int snd_ens1373_spdif_info(struct snd_kcontrol *kcontrol,
  				  struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1311
1312
1313
1314
1315
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  	uinfo->count = 1;
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1316
1317
  static int snd_ens1373_spdif_default_get(struct snd_kcontrol *kcontrol,
                                           struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1318
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1319
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1320
1321
1322
1323
1324
1325
1326
1327
  	spin_lock_irq(&ensoniq->reg_lock);
  	ucontrol->value.iec958.status[0] = (ensoniq->spdif_default >> 0) & 0xff;
  	ucontrol->value.iec958.status[1] = (ensoniq->spdif_default >> 8) & 0xff;
  	ucontrol->value.iec958.status[2] = (ensoniq->spdif_default >> 16) & 0xff;
  	ucontrol->value.iec958.status[3] = (ensoniq->spdif_default >> 24) & 0xff;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1328
1329
  static int snd_ens1373_spdif_default_put(struct snd_kcontrol *kcontrol,
                                           struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1330
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1331
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
  	unsigned int val;
  	int change;
  
  	val = ((u32)ucontrol->value.iec958.status[0] << 0) |
  	      ((u32)ucontrol->value.iec958.status[1] << 8) |
  	      ((u32)ucontrol->value.iec958.status[2] << 16) |
  	      ((u32)ucontrol->value.iec958.status[3] << 24);
  	spin_lock_irq(&ensoniq->reg_lock);
  	change = ensoniq->spdif_default != val;
  	ensoniq->spdif_default = val;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1342
1343
  	if (change && ensoniq->playback1_substream == NULL &&
  	    ensoniq->playback2_substream == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1344
1345
1346
1347
  		outl(val, ES_REG(ensoniq, CHANNEL_STATUS));
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return change;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1348
1349
  static int snd_ens1373_spdif_mask_get(struct snd_kcontrol *kcontrol,
  				      struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1350
1351
1352
1353
1354
1355
1356
  {
  	ucontrol->value.iec958.status[0] = 0xff;
  	ucontrol->value.iec958.status[1] = 0xff;
  	ucontrol->value.iec958.status[2] = 0xff;
  	ucontrol->value.iec958.status[3] = 0xff;
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1357
1358
  static int snd_ens1373_spdif_stream_get(struct snd_kcontrol *kcontrol,
  					struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1359
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1360
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1361
1362
1363
1364
1365
1366
1367
1368
  	spin_lock_irq(&ensoniq->reg_lock);
  	ucontrol->value.iec958.status[0] = (ensoniq->spdif_stream >> 0) & 0xff;
  	ucontrol->value.iec958.status[1] = (ensoniq->spdif_stream >> 8) & 0xff;
  	ucontrol->value.iec958.status[2] = (ensoniq->spdif_stream >> 16) & 0xff;
  	ucontrol->value.iec958.status[3] = (ensoniq->spdif_stream >> 24) & 0xff;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1369
1370
  static int snd_ens1373_spdif_stream_put(struct snd_kcontrol *kcontrol,
                                          struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1371
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1372
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
  	unsigned int val;
  	int change;
  
  	val = ((u32)ucontrol->value.iec958.status[0] << 0) |
  	      ((u32)ucontrol->value.iec958.status[1] << 8) |
  	      ((u32)ucontrol->value.iec958.status[2] << 16) |
  	      ((u32)ucontrol->value.iec958.status[3] << 24);
  	spin_lock_irq(&ensoniq->reg_lock);
  	change = ensoniq->spdif_stream != val;
  	ensoniq->spdif_stream = val;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1383
1384
  	if (change && (ensoniq->playback1_substream != NULL ||
  		       ensoniq->playback2_substream != NULL))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1385
1386
1387
1388
1389
1390
1391
1392
  		outl(val, ES_REG(ensoniq, CHANNEL_STATUS));
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return change;
  }
  
  #define ES1371_SPDIF(xname) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_es1371_spdif_info, \
    .get = snd_es1371_spdif_get, .put = snd_es1371_spdif_put }
a5ce88909   Takashi Iwai   [ALSA] Clean up w...
1393
  #define snd_es1371_spdif_info		snd_ctl_boolean_mono_info
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1394

eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1395
1396
  static int snd_es1371_spdif_get(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1397
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1398
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1399
1400
1401
1402
1403
1404
  	
  	spin_lock_irq(&ensoniq->reg_lock);
  	ucontrol->value.integer.value[0] = ensoniq->ctrl & ES_1373_SPDIF_THRU ? 1 : 0;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1405
1406
  static int snd_es1371_spdif_put(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1407
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1408
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
  	unsigned int nval1, nval2;
  	int change;
  	
  	nval1 = ucontrol->value.integer.value[0] ? ES_1373_SPDIF_THRU : 0;
  	nval2 = ucontrol->value.integer.value[0] ? ES_1373_SPDIF_EN : 0;
  	spin_lock_irq(&ensoniq->reg_lock);
  	change = (ensoniq->ctrl & ES_1373_SPDIF_THRU) != nval1;
  	ensoniq->ctrl &= ~ES_1373_SPDIF_THRU;
  	ensoniq->ctrl |= nval1;
  	ensoniq->cssr &= ~ES_1373_SPDIF_EN;
  	ensoniq->cssr |= nval2;
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	outl(ensoniq->cssr, ES_REG(ensoniq, STATUS));
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return change;
  }
  
  
  /* spdif controls */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1428
  static struct snd_kcontrol_new snd_es1371_mixer_spdif[] __devinitdata = {
10e8d78a9   Clemens Ladisch   [ALSA] use SNDRV_...
1429
  	ES1371_SPDIF(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH)),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1430
  	{
5549d5499   Clemens Ladisch   [ALSA] use PCM in...
1431
  		.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1432
1433
1434
1435
1436
1437
1438
  		.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  		.info =		snd_ens1373_spdif_info,
  		.get =		snd_ens1373_spdif_default_get,
  		.put =		snd_ens1373_spdif_default_put,
  	},
  	{
  		.access =	SNDRV_CTL_ELEM_ACCESS_READ,
5549d5499   Clemens Ladisch   [ALSA] use PCM in...
1439
  		.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1440
1441
1442
1443
1444
  		.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
  		.info =		snd_ens1373_spdif_info,
  		.get =		snd_ens1373_spdif_mask_get
  	},
  	{
5549d5499   Clemens Ladisch   [ALSA] use PCM in...
1445
  		.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1446
1447
1448
1449
1450
1451
  		.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
  		.info =		snd_ens1373_spdif_info,
  		.get =		snd_ens1373_spdif_stream_get,
  		.put =		snd_ens1373_spdif_stream_put
  	},
  };
a5ce88909   Takashi Iwai   [ALSA] Clean up w...
1452
  #define snd_es1373_rear_info		snd_ctl_boolean_mono_info
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1453

eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1454
1455
  static int snd_es1373_rear_get(struct snd_kcontrol *kcontrol,
  			       struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1456
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1457
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1458
1459
1460
  	int val = 0;
  	
  	spin_lock_irq(&ensoniq->reg_lock);
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1461
1462
  	if ((ensoniq->cssr & (ES_1373_REAR_BIT27|ES_1373_REAR_BIT26|
  			      ES_1373_REAR_BIT24)) == ES_1373_REAR_BIT26)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1463
1464
1465
1466
1467
  	    	val = 1;
  	ucontrol->value.integer.value[0] = val;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1468
1469
  static int snd_es1373_rear_put(struct snd_kcontrol *kcontrol,
  			       struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1470
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1471
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1472
1473
1474
  	unsigned int nval1;
  	int change;
  	
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1475
1476
  	nval1 = ucontrol->value.integer.value[0] ?
  		ES_1373_REAR_BIT26 : (ES_1373_REAR_BIT27|ES_1373_REAR_BIT24);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1477
  	spin_lock_irq(&ensoniq->reg_lock);
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1478
1479
  	change = (ensoniq->cssr & (ES_1373_REAR_BIT27|
  				   ES_1373_REAR_BIT26|ES_1373_REAR_BIT24)) != nval1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1480
1481
1482
1483
1484
1485
  	ensoniq->cssr &= ~(ES_1373_REAR_BIT27|ES_1373_REAR_BIT26|ES_1373_REAR_BIT24);
  	ensoniq->cssr |= nval1;
  	outl(ensoniq->cssr, ES_REG(ensoniq, STATUS));
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return change;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1486
  static struct snd_kcontrol_new snd_ens1373_rear __devinitdata =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1487
1488
1489
1490
1491
1492
1493
  {
  	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name =		"AC97 2ch->4ch Copy Switch",
  	.info =		snd_es1373_rear_info,
  	.get =		snd_es1373_rear_get,
  	.put =		snd_es1373_rear_put,
  };
a5ce88909   Takashi Iwai   [ALSA] Clean up w...
1494
  #define snd_es1373_line_info		snd_ctl_boolean_mono_info
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1495

eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1496
1497
  static int snd_es1373_line_get(struct snd_kcontrol *kcontrol,
  			       struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1498
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1499
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1500
1501
1502
1503
1504
1505
1506
1507
1508
  	int val = 0;
  	
  	spin_lock_irq(&ensoniq->reg_lock);
  	if ((ensoniq->ctrl & ES_1371_GPIO_OUTM) >= 4)
  	    	val = 1;
  	ucontrol->value.integer.value[0] = val;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1509
1510
  static int snd_es1373_line_put(struct snd_kcontrol *kcontrol,
  			       struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1511
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1512
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
  	int changed;
  	unsigned int ctrl;
  	
  	spin_lock_irq(&ensoniq->reg_lock);
  	ctrl = ensoniq->ctrl;
  	if (ucontrol->value.integer.value[0])
  		ensoniq->ctrl |= ES_1371_GPIO_OUT(4);	/* switch line-in -> rear out */
  	else
  		ensoniq->ctrl &= ~ES_1371_GPIO_OUT(4);
  	changed = (ctrl != ensoniq->ctrl);
  	if (changed)
  		outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return changed;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1528
  static struct snd_kcontrol_new snd_ens1373_line __devinitdata =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1529
1530
1531
1532
1533
1534
1535
  {
  	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name =		"Line In->Rear Out Switch",
  	.info =		snd_es1373_line_info,
  	.get =		snd_es1373_line_get,
  	.put =		snd_es1373_line_put,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1536
  static void snd_ensoniq_mixer_free_ac97(struct snd_ac97 *ac97)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1537
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1538
  	struct ensoniq *ensoniq = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1539
1540
  	ensoniq->u.es1371.ac97 = NULL;
  }
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1541
  struct es1371_quirk {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1542
1543
1544
  	unsigned short vid;		/* vendor ID */
  	unsigned short did;		/* device ID */
  	unsigned char rev;		/* revision */
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1545
  };
076c0e4fd   Randy Dunlap   [ALSA] fix ensoni...
1546
1547
  static int es1371_quirk_lookup(struct ensoniq *ensoniq,
  				struct es1371_quirk *list)
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
  {
  	while (list->vid != (unsigned short)PCI_ANY_ID) {
  		if (ensoniq->pci->vendor == list->vid &&
  		    ensoniq->pci->device == list->did &&
  		    ensoniq->rev == list->rev)
  			return 1;
  		list++;
  	}
  	return 0;
  }
  
  static struct es1371_quirk es1371_spdif_present[] __devinitdata = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1560
1561
1562
1563
1564
1565
1566
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_C },
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_D },
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_E },
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_ES1371, .rev = ES1371REV_CT5880_A },
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_ES1371, .rev = ES1371REV_ES1373_8 },
  	{ .vid = PCI_ANY_ID, .did = PCI_ANY_ID }
  };
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1567
1568
1569
1570
1571
1572
1573
1574
  static struct snd_pci_quirk ens1373_line_quirk[] __devinitdata = {
  	SND_PCI_QUIRK_ID(0x1274, 0x2000), /* GA-7DXR */
  	SND_PCI_QUIRK_ID(0x1458, 0xa000), /* GA-8IEXP */
  	{ } /* end */
  };
  
  static int __devinit snd_ensoniq_1371_mixer(struct ensoniq *ensoniq,
  					    int has_spdif, int has_line)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1575
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1576
1577
1578
  	struct snd_card *card = ensoniq->card;
  	struct snd_ac97_bus *pbus;
  	struct snd_ac97_template ac97;
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1579
  	int err;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1580
  	static struct snd_ac97_bus_ops ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1581
1582
  		.write = snd_es1371_codec_write,
  		.read = snd_es1371_codec_read,
072c01194   Jaroslav Kysela   [ALSA] ens1371 - ...
1583
  		.wait = snd_es1371_codec_wait,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1584
1585
1586
1587
1588
1589
1590
1591
  	};
  
  	if ((err = snd_ac97_bus(card, 0, &ops, NULL, &pbus)) < 0)
  		return err;
  
  	memset(&ac97, 0, sizeof(ac97));
  	ac97.private_data = ensoniq;
  	ac97.private_free = snd_ensoniq_mixer_free_ac97;
462dba28e   Rene Herman   ALSA: ALSA: ens13...
1592
  	ac97.pci = ensoniq->pci;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1593
1594
1595
  	ac97.scaps = AC97_SCAP_AUDIO;
  	if ((err = snd_ac97_mixer(pbus, &ac97, &ensoniq->u.es1371.ac97)) < 0)
  		return err;
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1596
1597
1598
  	if (has_spdif > 0 ||
  	    (!has_spdif && es1371_quirk_lookup(ensoniq, es1371_spdif_present))) {
  		struct snd_kcontrol *kctl;
405b0a377   Harvey Harrison   [ALSA] sound: ens...
1599
  		int i, is_spdif = 0;
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1600
1601
1602
1603
1604
1605
  
  		ensoniq->spdif_default = ensoniq->spdif_stream =
  			SNDRV_PCM_DEFAULT_CON_SPDIF;
  		outl(ensoniq->spdif_default, ES_REG(ensoniq, CHANNEL_STATUS));
  
  		if (ensoniq->u.es1371.ac97->ext_id & AC97_EI_SPDIF)
405b0a377   Harvey Harrison   [ALSA] sound: ens...
1606
  			is_spdif++;
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1607
1608
1609
1610
1611
  
  		for (i = 0; i < ARRAY_SIZE(snd_es1371_mixer_spdif); i++) {
  			kctl = snd_ctl_new1(&snd_es1371_mixer_spdif[i], ensoniq);
  			if (!kctl)
  				return -ENOMEM;
405b0a377   Harvey Harrison   [ALSA] sound: ens...
1612
  			kctl->id.index = is_spdif;
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1613
1614
1615
  			err = snd_ctl_add(card, kctl);
  			if (err < 0)
  				return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1616
  		}
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1617
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1618
1619
1620
1621
1622
1623
1624
1625
  	if (ensoniq->u.es1371.ac97->ext_id & AC97_EI_SDAC) {
  		/* mirror rear to front speakers */
  		ensoniq->cssr &= ~(ES_1373_REAR_BIT27|ES_1373_REAR_BIT24);
  		ensoniq->cssr |= ES_1373_REAR_BIT26;
  		err = snd_ctl_add(card, snd_ctl_new1(&snd_ens1373_rear, ensoniq));
  		if (err < 0)
  			return err;
  	}
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1626
1627
1628
1629
  	if (has_line > 0 ||
  	    snd_pci_quirk_lookup(ensoniq->pci, ens1373_line_quirk)) {
  		 err = snd_ctl_add(card, snd_ctl_new1(&snd_ens1373_line,
  						      ensoniq));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
  		 if (err < 0)
  			 return err;
  	}
  
  	return 0;
  }
  
  #endif /* CHIP1371 */
  
  /* generic control callbacks for ens1370 */
  #ifdef CHIP1370
  #define ENSONIQ_CONTROL(xname, mask) \
  { .iface = SNDRV_CTL_ELEM_IFACE_CARD, .name = xname, .info = snd_ensoniq_control_info, \
    .get = snd_ensoniq_control_get, .put = snd_ensoniq_control_put, \
    .private_value = mask }
a5ce88909   Takashi Iwai   [ALSA] Clean up w...
1645
  #define snd_ensoniq_control_info	snd_ctl_boolean_mono_info
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1646

eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1647
1648
  static int snd_ensoniq_control_get(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1649
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1650
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1651
1652
1653
1654
1655
1656
1657
  	int mask = kcontrol->private_value;
  	
  	spin_lock_irq(&ensoniq->reg_lock);
  	ucontrol->value.integer.value[0] = ensoniq->ctrl & mask ? 1 : 0;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1658
1659
  static int snd_ensoniq_control_put(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1660
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1661
  	struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
  	int mask = kcontrol->private_value;
  	unsigned int nval;
  	int change;
  	
  	nval = ucontrol->value.integer.value[0] ? mask : 0;
  	spin_lock_irq(&ensoniq->reg_lock);
  	change = (ensoniq->ctrl & mask) != nval;
  	ensoniq->ctrl &= ~mask;
  	ensoniq->ctrl |= nval;
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return change;
  }
  
  /*
   * ENS1370 mixer
   */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1679
  static struct snd_kcontrol_new snd_es1370_controls[2] __devinitdata = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1680
1681
1682
1683
1684
  ENSONIQ_CONTROL("PCM 0 Output also on Line-In Jack", ES_1370_XCTL0),
  ENSONIQ_CONTROL("Mic +5V bias", ES_1370_XCTL1)
  };
  
  #define ES1370_CONTROLS ARRAY_SIZE(snd_es1370_controls)
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1685
  static void snd_ensoniq_mixer_free_ak4531(struct snd_ak4531 *ak4531)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1686
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1687
  	struct ensoniq *ensoniq = ak4531->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1688
1689
  	ensoniq->u.es1370.ak4531 = NULL;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1690
  static int __devinit snd_ensoniq_1370_mixer(struct ensoniq * ensoniq)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1691
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1692
1693
  	struct snd_card *card = ensoniq->card;
  	struct snd_ak4531 ak4531;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
  	unsigned int idx;
  	int err;
  
  	/* try reset AK4531 */
  	outw(ES_1370_CODEC_WRITE(AK4531_RESET, 0x02), ES_REG(ensoniq, 1370_CODEC));
  	inw(ES_REG(ensoniq, 1370_CODEC));
  	udelay(100);
  	outw(ES_1370_CODEC_WRITE(AK4531_RESET, 0x03), ES_REG(ensoniq, 1370_CODEC));
  	inw(ES_REG(ensoniq, 1370_CODEC));
  	udelay(100);
  
  	memset(&ak4531, 0, sizeof(ak4531));
  	ak4531.write = snd_es1370_codec_write;
  	ak4531.private_data = ensoniq;
  	ak4531.private_free = snd_ensoniq_mixer_free_ak4531;
  	if ((err = snd_ak4531_mixer(card, &ak4531, &ensoniq->u.es1370.ak4531)) < 0)
  		return err;
  	for (idx = 0; idx < ES1370_CONTROLS; idx++) {
  		err = snd_ctl_add(card, snd_ctl_new1(&snd_es1370_controls[idx], ensoniq));
  		if (err < 0)
  			return err;
  	}
  	return 0;
  }
  
  #endif /* CHIP1370 */
  
  #ifdef SUPPORT_JOYSTICK
  
  #ifdef CHIP1371
  static int __devinit snd_ensoniq_get_joystick_port(int dev)
  {
  	switch (joystick_port[dev]) {
  	case 0: /* disabled */
  	case 1: /* auto-detect */
  	case 0x200:
  	case 0x208:
  	case 0x210:
  	case 0x218:
  		return joystick_port[dev];
  
  	default:
  		printk(KERN_ERR "ens1371: invalid joystick port %#x", joystick_port[dev]);
  		return 0;
  	}
  }
  #else
  static inline int snd_ensoniq_get_joystick_port(int dev)
  {
  	return joystick[dev] ? 0x200 : 0;
  }
  #endif
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1746
  static int __devinit snd_ensoniq_create_gameport(struct ensoniq *ensoniq, int dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
  {
  	struct gameport *gp;
  	int io_port;
  
  	io_port = snd_ensoniq_get_joystick_port(dev);
  
  	switch (io_port) {
  	case 0:
  		return -ENOSYS;
  
  	case 1: /* auto_detect */
  		for (io_port = 0x200; io_port <= 0x218; io_port += 8)
  			if (request_region(io_port, 8, "ens137x: gameport"))
  				break;
  		if (io_port > 0x218) {
  			printk(KERN_WARNING "ens137x: no gameport ports available
  ");
  			return -EBUSY;
  		}
  		break;
  
  	default:
  		if (!request_region(io_port, 8, "ens137x: gameport")) {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1770
1771
1772
  			printk(KERN_WARNING "ens137x: gameport io port 0x%#x in use
  ",
  			       io_port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
  			return -EBUSY;
  		}
  		break;
  	}
  
  	ensoniq->gameport = gp = gameport_allocate_port();
  	if (!gp) {
  		printk(KERN_ERR "ens137x: cannot allocate memory for gameport
  ");
  		release_region(io_port, 8);
  		return -ENOMEM;
  	}
  
  	gameport_set_name(gp, "ES137x");
  	gameport_set_phys(gp, "pci%s/gameport0", pci_name(ensoniq->pci));
  	gameport_set_dev_parent(gp, &ensoniq->pci->dev);
  	gp->io = io_port;
  
  	ensoniq->ctrl |= ES_JYSTK_EN;
  #ifdef CHIP1371
  	ensoniq->ctrl &= ~ES_1371_JOY_ASELM;
  	ensoniq->ctrl |= ES_1371_JOY_ASEL((io_port - 0x200) / 8);
  #endif
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  
  	gameport_register_port(ensoniq->gameport);
  
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1802
  static void snd_ensoniq_free_gameport(struct ensoniq *ensoniq)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
  {
  	if (ensoniq->gameport) {
  		int port = ensoniq->gameport->io;
  
  		gameport_unregister_port(ensoniq->gameport);
  		ensoniq->gameport = NULL;
  		ensoniq->ctrl &= ~ES_JYSTK_EN;
  		outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  		release_region(port, 8);
  	}
  }
  #else
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1815
1816
  static inline int snd_ensoniq_create_gameport(struct ensoniq *ensoniq, long port) { return -ENOSYS; }
  static inline void snd_ensoniq_free_gameport(struct ensoniq *ensoniq) { }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1817
1818
1819
1820
1821
  #endif /* SUPPORT_JOYSTICK */
  
  /*
  
   */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1822
1823
  static void snd_ensoniq_proc_read(struct snd_info_entry *entry, 
  				  struct snd_info_buffer *buffer)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1824
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1825
  	struct ensoniq *ensoniq = entry->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
  
  #ifdef CHIP1370
  	snd_iprintf(buffer, "Ensoniq AudioPCI ES1370
  
  ");
  #else
  	snd_iprintf(buffer, "Ensoniq AudioPCI ES1371
  
  ");
  #endif
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1836
1837
1838
  	snd_iprintf(buffer, "Joystick enable  : %s
  ",
  		    ensoniq->ctrl & ES_JYSTK_EN ? "on" : "off");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1839
  #ifdef CHIP1370
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1840
1841
1842
1843
1844
1845
  	snd_iprintf(buffer, "MIC +5V bias     : %s
  ",
  		    ensoniq->ctrl & ES_1370_XCTL1 ? "on" : "off");
  	snd_iprintf(buffer, "Line In to AOUT  : %s
  ",
  		    ensoniq->ctrl & ES_1370_XCTL0 ? "on" : "off");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1846
  #else
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1847
1848
1849
  	snd_iprintf(buffer, "Joystick port    : 0x%x
  ",
  		    (ES_1371_JOY_ASELI(ensoniq->ctrl) * 8) + 0x200);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1850
1851
  #endif
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1852
  static void __devinit snd_ensoniq_proc_init(struct ensoniq * ensoniq)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1853
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1854
  	struct snd_info_entry *entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1855
1856
  
  	if (! snd_card_proc_new(ensoniq->card, "audiopci", &entry))
bf850204a   Takashi Iwai   [ALSA] Remove unn...
1857
  		snd_info_set_text_ops(entry, ensoniq, snd_ensoniq_proc_read);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1858
1859
1860
1861
1862
  }
  
  /*
  
   */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1863
  static int snd_ensoniq_free(struct ensoniq *ensoniq)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
  {
  	snd_ensoniq_free_gameport(ensoniq);
  	if (ensoniq->irq < 0)
  		goto __hw_end;
  #ifdef CHIP1370
  	outl(ES_1370_SERR_DISABLE, ES_REG(ensoniq, CONTROL));	/* switch everything off */
  	outl(0, ES_REG(ensoniq, SERIAL));	/* clear serial interface */
  #else
  	outl(0, ES_REG(ensoniq, CONTROL));	/* switch everything off */
  	outl(0, ES_REG(ensoniq, SERIAL));	/* clear serial interface */
  #endif
f000fd809   Jeff Garzik   [ALSA] Fix synchr...
1875
1876
  	if (ensoniq->irq >= 0)
  		synchronize_irq(ensoniq->irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1877
1878
1879
1880
1881
1882
1883
  	pci_set_power_state(ensoniq->pci, 3);
        __hw_end:
  #ifdef CHIP1370
  	if (ensoniq->dma_bug.area)
  		snd_dma_free_pages(&ensoniq->dma_bug);
  #endif
  	if (ensoniq->irq >= 0)
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1884
  		free_irq(ensoniq->irq, ensoniq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1885
1886
1887
1888
1889
  	pci_release_regions(ensoniq->pci);
  	pci_disable_device(ensoniq->pci);
  	kfree(ensoniq);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1890
  static int snd_ensoniq_dev_free(struct snd_device *device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1891
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1892
  	struct ensoniq *ensoniq = device->device_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1893
1894
1895
1896
  	return snd_ensoniq_free(ensoniq);
  }
  
  #ifdef CHIP1371
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1897
1898
1899
1900
1901
1902
  static struct snd_pci_quirk es1371_amplifier_hack[] __devinitdata = {
  	SND_PCI_QUIRK_ID(0x107b, 0x2150),	/* Gateway Solo 2150 */
  	SND_PCI_QUIRK_ID(0x13bd, 0x100c),	/* EV1938 on Mebius PC-MJ100V */
  	SND_PCI_QUIRK_ID(0x1102, 0x5938),	/* Targa Xtender300 */
  	SND_PCI_QUIRK_ID(0x1102, 0x8938),	/* IPC Topnote G notebook */
  	{ } /* end */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1903
  };
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1904
1905
  
  static struct es1371_quirk es1371_ac97_reset_hack[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1906
1907
1908
1909
1910
1911
1912
1913
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_C },
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_D },
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_CT5880, .rev = CT5880REV_CT5880_E },
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_ES1371, .rev = ES1371REV_CT5880_A },
  	{ .vid = PCI_VENDOR_ID_ENSONIQ, .did = PCI_DEVICE_ID_ENSONIQ_ES1371, .rev = ES1371REV_ES1373_8 },
  	{ .vid = PCI_ANY_ID, .did = PCI_ANY_ID }
  };
  #endif
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1914
  static void snd_ensoniq_chip_init(struct ensoniq *ensoniq)
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1915
1916
1917
  {
  #ifdef CHIP1371
  	int idx;
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1918
  #endif
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
1919
1920
1921
  	/* this code was part of snd_ensoniq_create before intruduction
  	  * of suspend/resume
  	  */
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
  #ifdef CHIP1370
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
  	outl(ES_MEM_PAGEO(ES_PAGE_ADC), ES_REG(ensoniq, MEM_PAGE));
  	outl(ensoniq->dma_bug.addr, ES_REG(ensoniq, PHANTOM_FRAME));
  	outl(0, ES_REG(ensoniq, PHANTOM_COUNT));
  #else
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
  	outl(0, ES_REG(ensoniq, 1371_LEGACY));
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
1932
1933
1934
1935
1936
1937
  	if (es1371_quirk_lookup(ensoniq, es1371_ac97_reset_hack)) {
  	    outl(ensoniq->cssr, ES_REG(ensoniq, STATUS));
  	    /* need to delay around 20ms(bleech) to give
  	       some CODECs enough time to wakeup */
  	    msleep(20);
  	}
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
  	/* AC'97 warm reset to start the bitclk */
  	outl(ensoniq->ctrl | ES_1371_SYNC_RES, ES_REG(ensoniq, CONTROL));
  	inl(ES_REG(ensoniq, CONTROL));
  	udelay(20);
  	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
  	/* Init the sample rate converter */
  	snd_es1371_wait_src_ready(ensoniq);	
  	outl(ES_1371_SRC_DISABLE, ES_REG(ensoniq, 1371_SMPRATE));
  	for (idx = 0; idx < 0x80; idx++)
  		snd_es1371_src_write(ensoniq, idx, 0);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_DAC1 + ES_SMPREG_TRUNC_N, 16 << 4);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_DAC1 + ES_SMPREG_INT_REGS, 16 << 10);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_DAC2 + ES_SMPREG_TRUNC_N, 16 << 4);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_DAC2 + ES_SMPREG_INT_REGS, 16 << 10);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_ADC, 1 << 12);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_ADC + 1, 1 << 12);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_DAC1, 1 << 12);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_DAC1 + 1, 1 << 12);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_DAC2, 1 << 12);
  	snd_es1371_src_write(ensoniq, ES_SMPREG_VOL_DAC2 + 1, 1 << 12);
  	snd_es1371_adc_rate(ensoniq, 22050);
  	snd_es1371_dac1_rate(ensoniq, 22050);
  	snd_es1371_dac2_rate(ensoniq, 22050);
  	/* WARNING:
  	 * enabling the sample rate converter without properly programming
  	 * its parameters causes the chip to lock up (the SRC busy bit will
  	 * be stuck high, and I've found no way to rectify this other than
  	 * power cycle) - Thomas Sailer
  	 */
  	snd_es1371_wait_src_ready(ensoniq);
  	outl(0, ES_REG(ensoniq, 1371_SMPRATE));
  	/* try reset codec directly */
  	outl(ES_1371_CODEC_WRITE(0, 0), ES_REG(ensoniq, 1371_CODEC));
  #endif
  	outb(ensoniq->uartc = 0x00, ES_REG(ensoniq, UART_CONTROL));
  	outb(0x00, ES_REG(ensoniq, UART_RES));
  	outl(ensoniq->cssr, ES_REG(ensoniq, STATUS));
  	synchronize_irq(ensoniq->irq);
  }
  
  #ifdef CONFIG_PM
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
1979
  static int snd_ensoniq_suspend(struct pci_dev *pci, pm_message_t state)
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1980
  {
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
1981
1982
  	struct snd_card *card = pci_get_drvdata(pci);
  	struct ensoniq *ensoniq = card->private_data;
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1983
  	
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
1984
  	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1985
1986
1987
1988
  	snd_pcm_suspend_all(ensoniq->pcm1);
  	snd_pcm_suspend_all(ensoniq->pcm2);
  	
  #ifdef CHIP1371	
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
1989
  	snd_ac97_suspend(ensoniq->u.es1371.ac97);
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1990
  #else
15f500a69   Takashi Iwai   [ALSA] ens1370 - ...
1991
1992
1993
1994
1995
1996
1997
  	/* try to reset AK4531 */
  	outw(ES_1370_CODEC_WRITE(AK4531_RESET, 0x02), ES_REG(ensoniq, 1370_CODEC));
  	inw(ES_REG(ensoniq, 1370_CODEC));
  	udelay(100);
  	outw(ES_1370_CODEC_WRITE(AK4531_RESET, 0x03), ES_REG(ensoniq, 1370_CODEC));
  	inw(ES_REG(ensoniq, 1370_CODEC));
  	udelay(100);
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
1998
  	snd_ak4531_suspend(ensoniq->u.es1370.ak4531);
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
1999
  #endif	
30b35399c   Takashi Iwai   [ALSA] Various fi...
2000

fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2001
2002
  	pci_disable_device(pci);
  	pci_save_state(pci);
30b35399c   Takashi Iwai   [ALSA] Various fi...
2003
  	pci_set_power_state(pci, pci_choose_state(pci, state));
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
2004
2005
  	return 0;
  }
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2006
  static int snd_ensoniq_resume(struct pci_dev *pci)
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
2007
  {
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2008
2009
  	struct snd_card *card = pci_get_drvdata(pci);
  	struct ensoniq *ensoniq = card->private_data;
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
2010

fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2011
  	pci_set_power_state(pci, PCI_D0);
30b35399c   Takashi Iwai   [ALSA] Various fi...
2012
2013
2014
2015
2016
2017
2018
2019
  	pci_restore_state(pci);
  	if (pci_enable_device(pci) < 0) {
  		printk(KERN_ERR DRIVER_NAME ": pci_enable_device failed, "
  		       "disabling device
  ");
  		snd_card_disconnect(card);
  		return -EIO;
  	}
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2020
  	pci_set_master(pci);
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
2021
2022
2023
2024
  
  	snd_ensoniq_chip_init(ensoniq);
  
  #ifdef CHIP1371	
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2025
  	snd_ac97_resume(ensoniq->u.es1371.ac97);
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
2026
  #else
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2027
  	snd_ak4531_resume(ensoniq->u.es1370.ak4531);
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
2028
  #endif	
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2029
  	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
2030
2031
2032
  	return 0;
  }
  #endif /* CONFIG_PM */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2033
  static int __devinit snd_ensoniq_create(struct snd_card *card,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2034
  				     struct pci_dev *pci,
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2035
  				     struct ensoniq ** rensoniq)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2036
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2037
  	struct ensoniq *ensoniq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2038
  	int err;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2039
  	static struct snd_device_ops ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2040
2041
2042
2043
2044
2045
  		.dev_free =	snd_ensoniq_dev_free,
  	};
  
  	*rensoniq = NULL;
  	if ((err = pci_enable_device(pci)) < 0)
  		return err;
e560d8d83   Takashi Iwai   [ALSA] Replace wi...
2046
  	ensoniq = kzalloc(sizeof(*ensoniq), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2047
2048
2049
2050
2051
  	if (ensoniq == NULL) {
  		pci_disable_device(pci);
  		return -ENOMEM;
  	}
  	spin_lock_init(&ensoniq->reg_lock);
62932df8f   Ingo Molnar   [ALSA] semaphore ...
2052
  	mutex_init(&ensoniq->src_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2053
2054
2055
2056
2057
2058
2059
2060
2061
  	ensoniq->card = card;
  	ensoniq->pci = pci;
  	ensoniq->irq = -1;
  	if ((err = pci_request_regions(pci, "Ensoniq AudioPCI")) < 0) {
  		kfree(ensoniq);
  		pci_disable_device(pci);
  		return err;
  	}
  	ensoniq->port = pci_resource_start(pci, 0);
437a5a460   Takashi Iwai   [ALSA] Remove IRQ...
2062
  	if (request_irq(pci->irq, snd_audiopci_interrupt, IRQF_SHARED,
934c2b6d0   Takashi Iwai   ALSA: use KBUILD_...
2063
  			KBUILD_MODNAME, ensoniq)) {
99b359ba1   Takashi Iwai   [ALSA] Add missin...
2064
2065
  		snd_printk(KERN_ERR "unable to grab IRQ %d
  ", pci->irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2066
2067
2068
2069
2070
2071
2072
  		snd_ensoniq_free(ensoniq);
  		return -EBUSY;
  	}
  	ensoniq->irq = pci->irq;
  #ifdef CHIP1370
  	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  				16, &ensoniq->dma_bug) < 0) {
99b359ba1   Takashi Iwai   [ALSA] Add missin...
2073
2074
  		snd_printk(KERN_ERR "unable to allocate space for phantom area - dma_bug
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2075
2076
2077
2078
2079
  		snd_ensoniq_free(ensoniq);
  		return -EBUSY;
  	}
  #endif
  	pci_set_master(pci);
44c10138f   Auke Kok   PCI: Change all d...
2080
  	ensoniq->rev = pci->revision;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2081
2082
  #ifdef CHIP1370
  #if 0
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2083
2084
  	ensoniq->ctrl = ES_1370_CDC_EN | ES_1370_SERR_DISABLE |
  		ES_1370_PCLKDIVO(ES_1370_SRTODIV(8000));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2085
2086
2087
2088
  #else	/* get microphone working */
  	ensoniq->ctrl = ES_1370_CDC_EN | ES_1370_PCLKDIVO(ES_1370_SRTODIV(8000));
  #endif
  	ensoniq->sctrl = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2089
2090
2091
2092
  #else
  	ensoniq->ctrl = 0;
  	ensoniq->sctrl = 0;
  	ensoniq->cssr = 0;
5da8fa251   Takashi Iwai   [ALSA] ens1371 - ...
2093
2094
2095
2096
2097
  	if (snd_pci_quirk_lookup(pci, es1371_amplifier_hack))
  		ensoniq->ctrl |= ES_1371_GPIO_OUT(1);	/* turn amplifier on */
  
  	if (es1371_quirk_lookup(ensoniq, es1371_ac97_reset_hack))
  		ensoniq->cssr |= ES_1371_ST_AC97_RST;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2098
  #endif
f31a31b90   Kurt J. Bosch   [ALSA] Fix missin...
2099
2100
  
  	snd_ensoniq_chip_init(ensoniq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
  
  	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ensoniq, &ops)) < 0) {
  		snd_ensoniq_free(ensoniq);
  		return err;
  	}
  
  	snd_ensoniq_proc_init(ensoniq);
  
  	snd_card_set_dev(card, &pci->dev);
  
  	*rensoniq = ensoniq;
  	return 0;
  }
  
  /*
   *  MIDI section
   */
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2118
  static void snd_ensoniq_midi_interrupt(struct ensoniq * ensoniq)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2119
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2120
  	struct snd_rawmidi *rmidi = ensoniq->rmidi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
  	unsigned char status, mask, byte;
  
  	if (rmidi == NULL)
  		return;
  	/* do Rx at first */
  	spin_lock(&ensoniq->reg_lock);
  	mask = ensoniq->uartm & ES_MODE_INPUT ? ES_RXRDY : 0;
  	while (mask) {
  		status = inb(ES_REG(ensoniq, UART_STATUS));
  		if ((status & mask) == 0)
  			break;
  		byte = inb(ES_REG(ensoniq, UART_DATA));
  		snd_rawmidi_receive(ensoniq->midi_input, &byte, 1);
  	}
  	spin_unlock(&ensoniq->reg_lock);
  
  	/* do Tx at second */
  	spin_lock(&ensoniq->reg_lock);
  	mask = ensoniq->uartm & ES_MODE_OUTPUT ? ES_TXRDY : 0;
  	while (mask) {
  		status = inb(ES_REG(ensoniq, UART_STATUS));
  		if ((status & mask) == 0)
  			break;
  		if (snd_rawmidi_transmit(ensoniq->midi_output, &byte, 1) != 1) {
  			ensoniq->uartc &= ~ES_TXINTENM;
  			outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL));
  			mask &= ~ES_TXRDY;
  		} else {
  			outb(byte, ES_REG(ensoniq, UART_DATA));
  		}
  	}
  	spin_unlock(&ensoniq->reg_lock);
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2154
  static int snd_ensoniq_midi_input_open(struct snd_rawmidi_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2155
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2156
  	struct ensoniq *ensoniq = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
  
  	spin_lock_irq(&ensoniq->reg_lock);
  	ensoniq->uartm |= ES_MODE_INPUT;
  	ensoniq->midi_input = substream;
  	if (!(ensoniq->uartm & ES_MODE_OUTPUT)) {
  		outb(ES_CNTRL(3), ES_REG(ensoniq, UART_CONTROL));
  		outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL));
  		outl(ensoniq->ctrl |= ES_UART_EN, ES_REG(ensoniq, CONTROL));
  	}
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2169
  static int snd_ensoniq_midi_input_close(struct snd_rawmidi_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2170
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2171
  	struct ensoniq *ensoniq = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
  
  	spin_lock_irq(&ensoniq->reg_lock);
  	if (!(ensoniq->uartm & ES_MODE_OUTPUT)) {
  		outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL));
  		outl(ensoniq->ctrl &= ~ES_UART_EN, ES_REG(ensoniq, CONTROL));
  	} else {
  		outb(ensoniq->uartc &= ~ES_RXINTEN, ES_REG(ensoniq, UART_CONTROL));
  	}
  	ensoniq->midi_input = NULL;
  	ensoniq->uartm &= ~ES_MODE_INPUT;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2185
  static int snd_ensoniq_midi_output_open(struct snd_rawmidi_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2186
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2187
  	struct ensoniq *ensoniq = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
  
  	spin_lock_irq(&ensoniq->reg_lock);
  	ensoniq->uartm |= ES_MODE_OUTPUT;
  	ensoniq->midi_output = substream;
  	if (!(ensoniq->uartm & ES_MODE_INPUT)) {
  		outb(ES_CNTRL(3), ES_REG(ensoniq, UART_CONTROL));
  		outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL));
  		outl(ensoniq->ctrl |= ES_UART_EN, ES_REG(ensoniq, CONTROL));
  	}
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2200
  static int snd_ensoniq_midi_output_close(struct snd_rawmidi_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2201
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2202
  	struct ensoniq *ensoniq = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
  
  	spin_lock_irq(&ensoniq->reg_lock);
  	if (!(ensoniq->uartm & ES_MODE_INPUT)) {
  		outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL));
  		outl(ensoniq->ctrl &= ~ES_UART_EN, ES_REG(ensoniq, CONTROL));
  	} else {
  		outb(ensoniq->uartc &= ~ES_TXINTENM, ES_REG(ensoniq, UART_CONTROL));
  	}
  	ensoniq->midi_output = NULL;
  	ensoniq->uartm &= ~ES_MODE_OUTPUT;
  	spin_unlock_irq(&ensoniq->reg_lock);
  	return 0;
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2216
  static void snd_ensoniq_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2217
2218
  {
  	unsigned long flags;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2219
  	struct ensoniq *ensoniq = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
  	int idx;
  
  	spin_lock_irqsave(&ensoniq->reg_lock, flags);
  	if (up) {
  		if ((ensoniq->uartc & ES_RXINTEN) == 0) {
  			/* empty input FIFO */
  			for (idx = 0; idx < 32; idx++)
  				inb(ES_REG(ensoniq, UART_DATA));
  			ensoniq->uartc |= ES_RXINTEN;
  			outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL));
  		}
  	} else {
  		if (ensoniq->uartc & ES_RXINTEN) {
  			ensoniq->uartc &= ~ES_RXINTEN;
  			outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL));
  		}
  	}
  	spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2239
  static void snd_ensoniq_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2240
2241
  {
  	unsigned long flags;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2242
  	struct ensoniq *ensoniq = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
  	unsigned char byte;
  
  	spin_lock_irqsave(&ensoniq->reg_lock, flags);
  	if (up) {
  		if (ES_TXINTENI(ensoniq->uartc) == 0) {
  			ensoniq->uartc |= ES_TXINTENO(1);
  			/* fill UART FIFO buffer at first, and turn Tx interrupts only if necessary */
  			while (ES_TXINTENI(ensoniq->uartc) == 1 &&
  			       (inb(ES_REG(ensoniq, UART_STATUS)) & ES_TXRDY)) {
  				if (snd_rawmidi_transmit(substream, &byte, 1) != 1) {
  					ensoniq->uartc &= ~ES_TXINTENM;
  				} else {
  					outb(byte, ES_REG(ensoniq, UART_DATA));
  				}
  			}
  			outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL));
  		}
  	} else {
  		if (ES_TXINTENI(ensoniq->uartc) == 1) {
  			ensoniq->uartc &= ~ES_TXINTENM;
  			outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL));
  		}
  	}
  	spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
  }
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2268
  static struct snd_rawmidi_ops snd_ensoniq_midi_output =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2269
2270
2271
2272
2273
  {
  	.open =		snd_ensoniq_midi_output_open,
  	.close =	snd_ensoniq_midi_output_close,
  	.trigger =	snd_ensoniq_midi_output_trigger,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2274
  static struct snd_rawmidi_ops snd_ensoniq_midi_input =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2275
2276
2277
2278
2279
  {
  	.open =		snd_ensoniq_midi_input_open,
  	.close =	snd_ensoniq_midi_input_close,
  	.trigger =	snd_ensoniq_midi_input_trigger,
  };
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2280
2281
  static int __devinit snd_ensoniq_midi(struct ensoniq * ensoniq, int device,
  				      struct snd_rawmidi **rrawmidi)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2282
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2283
  	struct snd_rawmidi *rmidi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
  	int err;
  
  	if (rrawmidi)
  		*rrawmidi = NULL;
  	if ((err = snd_rawmidi_new(ensoniq->card, "ES1370/1", device, 1, 1, &rmidi)) < 0)
  		return err;
  #ifdef CHIP1370
  	strcpy(rmidi->name, "ES1370");
  #else
  	strcpy(rmidi->name, "ES1371");
  #endif
  	snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_ensoniq_midi_output);
  	snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_ensoniq_midi_input);
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2297
2298
  	rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT |
  		SNDRV_RAWMIDI_INFO_DUPLEX;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
  	rmidi->private_data = ensoniq;
  	ensoniq->rmidi = rmidi;
  	if (rrawmidi)
  		*rrawmidi = rmidi;
  	return 0;
  }
  
  /*
   *  Interrupt handler
   */
7d12e780e   David Howells   IRQ: Maintain reg...
2309
  static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2310
  {
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2311
  	struct ensoniq *ensoniq = dev_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
  	unsigned int status, sctrl;
  
  	if (ensoniq == NULL)
  		return IRQ_NONE;
  
  	status = inl(ES_REG(ensoniq, STATUS));
  	if (!(status & ES_INTR))
  		return IRQ_NONE;
  
  	spin_lock(&ensoniq->reg_lock);
  	sctrl = ensoniq->sctrl;
  	if (status & ES_DAC1)
  		sctrl &= ~ES_P1_INT_EN;
  	if (status & ES_DAC2)
  		sctrl &= ~ES_P2_INT_EN;
  	if (status & ES_ADC)
  		sctrl &= ~ES_R1_INT_EN;
  	outl(sctrl, ES_REG(ensoniq, SERIAL));
  	outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
  	spin_unlock(&ensoniq->reg_lock);
  
  	if (status & ES_UART)
  		snd_ensoniq_midi_interrupt(ensoniq);
  	if ((status & ES_DAC2) && ensoniq->playback2_substream)
  		snd_pcm_period_elapsed(ensoniq->playback2_substream);
  	if ((status & ES_ADC) && ensoniq->capture_substream)
  		snd_pcm_period_elapsed(ensoniq->capture_substream);
  	if ((status & ES_DAC1) && ensoniq->playback1_substream)
  		snd_pcm_period_elapsed(ensoniq->playback1_substream);
  	return IRQ_HANDLED;
  }
  
  static int __devinit snd_audiopci_probe(struct pci_dev *pci,
  					const struct pci_device_id *pci_id)
  {
  	static int dev;
eb3414b46   Takashi Iwai   [ALSA] Remove xxx...
2348
2349
  	struct snd_card *card;
  	struct ensoniq *ensoniq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2350
2351
2352
2353
2354
2355
2356
2357
  	int err, pcm_devs[2];
  
  	if (dev >= SNDRV_CARDS)
  		return -ENODEV;
  	if (!enable[dev]) {
  		dev++;
  		return -ENOENT;
  	}
e58de7baf   Takashi Iwai   ALSA: Convert to ...
2358
2359
2360
  	err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  	if (err < 0)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2361
2362
2363
2364
2365
  
  	if ((err = snd_ensoniq_create(card, pci, &ensoniq)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2366
  	card->private_data = ensoniq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2367
2368
2369
2370
2371
2372
2373
2374
2375
  
  	pcm_devs[0] = 0; pcm_devs[1] = 1;
  #ifdef CHIP1370
  	if ((err = snd_ensoniq_1370_mixer(ensoniq)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  #endif
  #ifdef CHIP1371
015b6a198   Jaroslav Kysela   [ALSA] ens1371: a...
2376
  	if ((err = snd_ensoniq_1371_mixer(ensoniq, spdif[dev], lineio[dev])) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
  		snd_card_free(card);
  		return err;
  	}
  #endif
  	if ((err = snd_ensoniq_pcm(ensoniq, 0, NULL)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	if ((err = snd_ensoniq_pcm2(ensoniq, 1, NULL)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	if ((err = snd_ensoniq_midi(ensoniq, 0, NULL)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  
  	snd_ensoniq_create_gameport(ensoniq, dev);
  
  	strcpy(card->driver, DRIVER_NAME);
  
  	strcpy(card->shortname, "Ensoniq AudioPCI");
  	sprintf(card->longname, "%s %s at 0x%lx, irq %i",
  		card->shortname,
  		card->driver,
  		ensoniq->port,
  		ensoniq->irq);
  
  	if ((err = snd_card_register(card)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  
  	pci_set_drvdata(pci, card);
  	dev++;
  	return 0;
  }
  
  static void __devexit snd_audiopci_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_...
2422
  	.name = KBUILD_MODNAME,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2423
2424
2425
  	.id_table = snd_audiopci_ids,
  	.probe = snd_audiopci_probe,
  	.remove = __devexit_p(snd_audiopci_remove),
fe8be1078   Takashi Iwai   [ALSA] ens137x - ...
2426
2427
2428
2429
  #ifdef CONFIG_PM
  	.suspend = snd_ensoniq_suspend,
  	.resume = snd_ensoniq_resume,
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2430
2431
2432
2433
  };
  	
  static int __init alsa_card_ens137x_init(void)
  {
01d25d460   Takashi Iwai   [ALSA] Replace pc...
2434
  	return pci_register_driver(&driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2435
2436
2437
2438
2439
2440
2441
2442
2443
  }
  
  static void __exit alsa_card_ens137x_exit(void)
  {
  	pci_unregister_driver(&driver);
  }
  
  module_init(alsa_card_ens137x_init)
  module_exit(alsa_card_ens137x_exit)