2 * Driver for Ensoniq ES1370/ES1371 AudioPCI soundcard
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>,
4 * Thomas Sailer <sailer@ife.ee.ethz.ch>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
24 #include <linux/delay.h>
25 #include <linux/interrupt.h>
26 #include <linux/init.h>
27 #include <linux/pci.h>
28 #include <linux/slab.h>
29 #include <linux/gameport.h>
30 #include <linux/moduleparam.h>
31 #include <sound/core.h>
32 #include <sound/control.h>
33 #include <sound/pcm.h>
34 #include <sound/rawmidi.h>
36 #include <sound/ac97_codec.h>
38 #include <sound/ak4531_codec.h>
40 #include <sound/initval.h>
41 #include <sound/asoundef.h>
49 #define DRIVER_NAME "ENS1370"
51 #define DRIVER_NAME "ENS1371"
55 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Thomas Sailer <sailer@ife.ee.ethz.ch>");
56 MODULE_LICENSE("GPL");
58 MODULE_DESCRIPTION("Ensoniq AudioPCI ES1370");
59 MODULE_SUPPORTED_DEVICE("{{Ensoniq,AudioPCI-97 ES1370},"
60 "{Creative Labs,SB PCI64/128 (ES1370)}}");
63 MODULE_DESCRIPTION("Ensoniq/Creative AudioPCI ES1371+");
64 MODULE_SUPPORTED_DEVICE("{{Ensoniq,AudioPCI ES1371/73},"
65 "{Ensoniq,AudioPCI ES1373},"
66 "{Creative Labs,Ectiva EV1938},"
67 "{Creative Labs,SB PCI64/128 (ES1371/73)},"
68 "{Creative Labs,Vibra PCI128},"
72 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
73 #define SUPPORT_JOYSTICK
76 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
77 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
78 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
; /* Enable switches */
79 #ifdef SUPPORT_JOYSTICK
81 static int joystick_port
[SNDRV_CARDS
];
83 static int joystick
[SNDRV_CARDS
];
87 module_param_array(index
, int, NULL
, 0444);
88 MODULE_PARM_DESC(index
, "Index value for Ensoniq AudioPCI soundcard.");
89 module_param_array(id
, charp
, NULL
, 0444);
90 MODULE_PARM_DESC(id
, "ID string for Ensoniq AudioPCI soundcard.");
91 module_param_array(enable
, bool, NULL
, 0444);
92 MODULE_PARM_DESC(enable
, "Enable Ensoniq AudioPCI soundcard.");
93 #ifdef SUPPORT_JOYSTICK
95 module_param_array(joystick_port
, int, NULL
, 0444);
96 MODULE_PARM_DESC(joystick_port
, "Joystick port address.");
98 module_param_array(joystick
, bool, NULL
, 0444);
99 MODULE_PARM_DESC(joystick
, "Enable joystick.");
101 #endif /* SUPPORT_JOYSTICK */
104 /* This is a little confusing because all ES1371 compatible chips have the
105 same DEVICE_ID, the only thing differentiating them is the REV_ID field.
106 This is only significant if you want to enable features on the later parts.
107 Yes, I know it's stupid and why didn't we use the sub IDs?
109 #define ES1371REV_ES1373_A 0x04
110 #define ES1371REV_ES1373_B 0x06
111 #define ES1371REV_CT5880_A 0x07
112 #define CT5880REV_CT5880_C 0x02
113 #define CT5880REV_CT5880_D 0x03 /* ??? -jk */
114 #define CT5880REV_CT5880_E 0x04 /* mw */
115 #define ES1371REV_ES1371_B 0x09
116 #define EV1938REV_EV1938_A 0x00
117 #define ES1371REV_ES1373_8 0x08
123 #define ES_REG(ensoniq, x) ((ensoniq)->port + ES_REG_##x)
125 #define ES_REG_CONTROL 0x00 /* R/W: Interrupt/Chip select control register */
126 #define ES_1370_ADC_STOP (1<<31) /* disable capture buffer transfers */
127 #define ES_1370_XCTL1 (1<<30) /* general purpose output bit */
128 #define ES_1373_BYPASS_P1 (1<<31) /* bypass SRC for PB1 */
129 #define ES_1373_BYPASS_P2 (1<<30) /* bypass SRC for PB2 */
130 #define ES_1373_BYPASS_R (1<<29) /* bypass SRC for REC */
131 #define ES_1373_TEST_BIT (1<<28) /* should be set to 0 for normal operation */
132 #define ES_1373_RECEN_B (1<<27) /* mix record with playback for I2S/SPDIF out */
133 #define ES_1373_SPDIF_THRU (1<<26) /* 0 = SPDIF thru mode, 1 = SPDIF == dig out */
134 #define ES_1371_JOY_ASEL(o) (((o)&0x03)<<24)/* joystick port mapping */
135 #define ES_1371_JOY_ASELM (0x03<<24) /* mask for above */
136 #define ES_1371_JOY_ASELI(i) (((i)>>24)&0x03)
137 #define ES_1371_GPIO_IN(i) (((i)>>20)&0x0f)/* GPIO in [3:0] pins - R/O */
138 #define ES_1370_PCLKDIVO(o) (((o)&0x1fff)<<16)/* clock divide ratio for DAC2 */
139 #define ES_1370_PCLKDIVM ((0x1fff)<<16) /* mask for above */
140 #define ES_1370_PCLKDIVI(i) (((i)>>16)&0x1fff)/* clock divide ratio for DAC2 */
141 #define ES_1371_GPIO_OUT(o) (((o)&0x0f)<<16)/* GPIO out [3:0] pins - W/R */
142 #define ES_1371_GPIO_OUTM (0x0f<<16) /* mask for above */
143 #define ES_MSFMTSEL (1<<15) /* MPEG serial data format; 0 = SONY, 1 = I2S */
144 #define ES_1370_M_SBB (1<<14) /* clock source for DAC - 0 = clock generator; 1 = MPEG clocks */
145 #define ES_1371_SYNC_RES (1<<14) /* Warm AC97 reset */
146 #define ES_1370_WTSRSEL(o) (((o)&0x03)<<12)/* fixed frequency clock for DAC1 */
147 #define ES_1370_WTSRSELM (0x03<<12) /* mask for above */
148 #define ES_1371_ADC_STOP (1<<13) /* disable CCB transfer capture information */
149 #define ES_1371_PWR_INTRM (1<<12) /* power level change interrupts enable */
150 #define ES_1370_DAC_SYNC (1<<11) /* DAC's are synchronous */
151 #define ES_1371_M_CB (1<<11) /* capture clock source; 0 = AC'97 ADC; 1 = I2S */
152 #define ES_CCB_INTRM (1<<10) /* CCB voice interrupts enable */
153 #define ES_1370_M_CB (1<<9) /* capture clock source; 0 = ADC; 1 = MPEG */
154 #define ES_1370_XCTL0 (1<<8) /* generap purpose output bit */
155 #define ES_1371_PDLEV(o) (((o)&0x03)<<8) /* current power down level */
156 #define ES_1371_PDLEVM (0x03<<8) /* mask for above */
157 #define ES_BREQ (1<<7) /* memory bus request enable */
158 #define ES_DAC1_EN (1<<6) /* DAC1 playback channel enable */
159 #define ES_DAC2_EN (1<<5) /* DAC2 playback channel enable */
160 #define ES_ADC_EN (1<<4) /* ADC capture channel enable */
161 #define ES_UART_EN (1<<3) /* UART enable */
162 #define ES_JYSTK_EN (1<<2) /* Joystick module enable */
163 #define ES_1370_CDC_EN (1<<1) /* Codec interface enable */
164 #define ES_1371_XTALCKDIS (1<<1) /* Xtal clock disable */
165 #define ES_1370_SERR_DISABLE (1<<0) /* PCI serr signal disable */
166 #define ES_1371_PCICLKDIS (1<<0) /* PCI clock disable */
167 #define ES_REG_STATUS 0x04 /* R/O: Interrupt/Chip select status register */
168 #define ES_INTR (1<<31) /* Interrupt is pending */
169 #define ES_1371_ST_AC97_RST (1<<29) /* CT5880 AC'97 Reset bit */
170 #define ES_1373_REAR_BIT27 (1<<27) /* rear bits: 000 - front, 010 - mirror, 101 - separate */
171 #define ES_1373_REAR_BIT26 (1<<26)
172 #define ES_1373_REAR_BIT24 (1<<24)
173 #define ES_1373_GPIO_INT_EN(o)(((o)&0x0f)<<20)/* GPIO [3:0] pins - interrupt enable */
174 #define ES_1373_SPDIF_EN (1<<18) /* SPDIF enable */
175 #define ES_1373_SPDIF_TEST (1<<17) /* SPDIF test */
176 #define ES_1371_TEST (1<<16) /* test ASIC */
177 #define ES_1373_GPIO_INT(i) (((i)&0x0f)>>12)/* GPIO [3:0] pins - interrupt pending */
178 #define ES_1370_CSTAT (1<<10) /* CODEC is busy or register write in progress */
179 #define ES_1370_CBUSY (1<<9) /* CODEC is busy */
180 #define ES_1370_CWRIP (1<<8) /* CODEC register write in progress */
181 #define ES_1371_SYNC_ERR (1<<8) /* CODEC synchronization error occurred */
182 #define ES_1371_VC(i) (((i)>>6)&0x03) /* voice code from CCB module */
183 #define ES_1370_VC(i) (((i)>>5)&0x03) /* voice code from CCB module */
184 #define ES_1371_MPWR (1<<5) /* power level interrupt pending */
185 #define ES_MCCB (1<<4) /* CCB interrupt pending */
186 #define ES_UART (1<<3) /* UART interrupt pending */
187 #define ES_DAC1 (1<<2) /* DAC1 channel interrupt pending */
188 #define ES_DAC2 (1<<1) /* DAC2 channel interrupt pending */
189 #define ES_ADC (1<<0) /* ADC channel interrupt pending */
190 #define ES_REG_UART_DATA 0x08 /* R/W: UART data register */
191 #define ES_REG_UART_STATUS 0x09 /* R/O: UART status register */
192 #define ES_RXINT (1<<7) /* RX interrupt occurred */
193 #define ES_TXINT (1<<2) /* TX interrupt occurred */
194 #define ES_TXRDY (1<<1) /* transmitter ready */
195 #define ES_RXRDY (1<<0) /* receiver ready */
196 #define ES_REG_UART_CONTROL 0x09 /* W/O: UART control register */
197 #define ES_RXINTEN (1<<7) /* RX interrupt enable */
198 #define ES_TXINTENO(o) (((o)&0x03)<<5) /* TX interrupt enable */
199 #define ES_TXINTENM (0x03<<5) /* mask for above */
200 #define ES_TXINTENI(i) (((i)>>5)&0x03)
201 #define ES_CNTRL(o) (((o)&0x03)<<0) /* control */
202 #define ES_CNTRLM (0x03<<0) /* mask for above */
203 #define ES_REG_UART_RES 0x0a /* R/W: UART reserver register */
204 #define ES_TEST_MODE (1<<0) /* test mode enabled */
205 #define ES_REG_MEM_PAGE 0x0c /* R/W: Memory page register */
206 #define ES_MEM_PAGEO(o) (((o)&0x0f)<<0) /* memory page select - out */
207 #define ES_MEM_PAGEM (0x0f<<0) /* mask for above */
208 #define ES_MEM_PAGEI(i) (((i)>>0)&0x0f) /* memory page select - in */
209 #define ES_REG_1370_CODEC 0x10 /* W/O: Codec write register address */
210 #define ES_1370_CODEC_WRITE(a,d) ((((a)&0xff)<<8)|(((d)&0xff)<<0))
211 #define ES_REG_1371_CODEC 0x14 /* W/R: Codec Read/Write register address */
212 #define ES_1371_CODEC_RDY (1<<31) /* codec ready */
213 #define ES_1371_CODEC_WIP (1<<30) /* codec register access in progress */
214 #define ES_1371_CODEC_PIRD (1<<23) /* codec read/write select register */
215 #define ES_1371_CODEC_WRITE(a,d) ((((a)&0x7f)<<16)|(((d)&0xffff)<<0))
216 #define ES_1371_CODEC_READS(a) ((((a)&0x7f)<<16)|ES_1371_CODEC_PIRD)
217 #define ES_1371_CODEC_READ(i) (((i)>>0)&0xffff)
219 #define ES_REG_1371_SMPRATE 0x10 /* W/R: Codec rate converter interface register */
220 #define ES_1371_SRC_RAM_ADDRO(o) (((o)&0x7f)<<25)/* address of the sample rate converter */
221 #define ES_1371_SRC_RAM_ADDRM (0x7f<<25) /* mask for above */
222 #define ES_1371_SRC_RAM_ADDRI(i) (((i)>>25)&0x7f)/* address of the sample rate converter */
223 #define ES_1371_SRC_RAM_WE (1<<24) /* R/W: read/write control for sample rate converter */
224 #define ES_1371_SRC_RAM_BUSY (1<<23) /* R/O: sample rate memory is busy */
225 #define ES_1371_SRC_DISABLE (1<<22) /* sample rate converter disable */
226 #define ES_1371_DIS_P1 (1<<21) /* playback channel 1 accumulator update disable */
227 #define ES_1371_DIS_P2 (1<<20) /* playback channel 1 accumulator update disable */
228 #define ES_1371_DIS_R1 (1<<19) /* capture channel accumulator update disable */
229 #define ES_1371_SRC_RAM_DATAO(o) (((o)&0xffff)<<0)/* current value of the sample rate converter */
230 #define ES_1371_SRC_RAM_DATAM (0xffff<<0) /* mask for above */
231 #define ES_1371_SRC_RAM_DATAI(i) (((i)>>0)&0xffff)/* current value of the sample rate converter */
233 #define ES_REG_1371_LEGACY 0x18 /* W/R: Legacy control/status register */
234 #define ES_1371_JFAST (1<<31) /* fast joystick timing */
235 #define ES_1371_HIB (1<<30) /* host interrupt blocking enable */
236 #define ES_1371_VSB (1<<29) /* SB; 0 = addr 0x220xH, 1 = 0x22FxH */
237 #define ES_1371_VMPUO(o) (((o)&0x03)<<27)/* base register address; 0 = 0x320xH; 1 = 0x330xH; 2 = 0x340xH; 3 = 0x350xH */
238 #define ES_1371_VMPUM (0x03<<27) /* mask for above */
239 #define ES_1371_VMPUI(i) (((i)>>27)&0x03)/* base register address */
240 #define ES_1371_VCDCO(o) (((o)&0x03)<<25)/* CODEC; 0 = 0x530xH; 1 = undefined; 2 = 0xe80xH; 3 = 0xF40xH */
241 #define ES_1371_VCDCM (0x03<<25) /* mask for above */
242 #define ES_1371_VCDCI(i) (((i)>>25)&0x03)/* CODEC address */
243 #define ES_1371_FIRQ (1<<24) /* force an interrupt */
244 #define ES_1371_SDMACAP (1<<23) /* enable event capture for slave DMA controller */
245 #define ES_1371_SPICAP (1<<22) /* enable event capture for slave IRQ controller */
246 #define ES_1371_MDMACAP (1<<21) /* enable event capture for master DMA controller */
247 #define ES_1371_MPICAP (1<<20) /* enable event capture for master IRQ controller */
248 #define ES_1371_ADCAP (1<<19) /* enable event capture for ADLIB register; 0x388xH */
249 #define ES_1371_SVCAP (1<<18) /* enable event capture for SB registers */
250 #define ES_1371_CDCCAP (1<<17) /* enable event capture for CODEC registers */
251 #define ES_1371_BACAP (1<<16) /* enable event capture for SoundScape base address */
252 #define ES_1371_EXI(i) (((i)>>8)&0x07) /* event number */
253 #define ES_1371_AI(i) (((i)>>3)&0x1f) /* event significant I/O address */
254 #define ES_1371_WR (1<<2) /* event capture; 0 = read; 1 = write */
255 #define ES_1371_LEGINT (1<<0) /* interrupt for legacy events; 0 = interrupt did occur */
257 #define ES_REG_CHANNEL_STATUS 0x1c /* R/W: first 32-bits from S/PDIF channel status block, es1373 */
259 #define ES_REG_SERIAL 0x20 /* R/W: Serial interface control register */
260 #define ES_1371_DAC_TEST (1<<22) /* DAC test mode enable */
261 #define ES_P2_END_INCO(o) (((o)&0x07)<<19)/* binary offset value to increment / loop end */
262 #define ES_P2_END_INCM (0x07<<19) /* mask for above */
263 #define ES_P2_END_INCI(i) (((i)>>16)&0x07)/* binary offset value to increment / loop end */
264 #define ES_P2_ST_INCO(o) (((o)&0x07)<<16)/* binary offset value to increment / start */
265 #define ES_P2_ST_INCM (0x07<<16) /* mask for above */
266 #define ES_P2_ST_INCI(i) (((i)<<16)&0x07)/* binary offset value to increment / start */
267 #define ES_R1_LOOP_SEL (1<<15) /* ADC; 0 - loop mode; 1 = stop mode */
268 #define ES_P2_LOOP_SEL (1<<14) /* DAC2; 0 - loop mode; 1 = stop mode */
269 #define ES_P1_LOOP_SEL (1<<13) /* DAC1; 0 - loop mode; 1 = stop mode */
270 #define ES_P2_PAUSE (1<<12) /* DAC2; 0 - play mode; 1 = pause mode */
271 #define ES_P1_PAUSE (1<<11) /* DAC1; 0 - play mode; 1 = pause mode */
272 #define ES_R1_INT_EN (1<<10) /* ADC interrupt enable */
273 #define ES_P2_INT_EN (1<<9) /* DAC2 interrupt enable */
274 #define ES_P1_INT_EN (1<<8) /* DAC1 interrupt enable */
275 #define ES_P1_SCT_RLD (1<<7) /* force sample counter reload for DAC1 */
276 #define ES_P2_DAC_SEN (1<<6) /* when stop mode: 0 - DAC2 play back zeros; 1 = DAC2 play back last sample */
277 #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 */
278 #define ES_R1_MODEM (0x03<<4) /* mask for above */
279 #define ES_R1_MODEI(i) (((i)>>4)&0x03)
280 #define ES_P2_MODEO(o) (((o)&0x03)<<2) /* DAC2 mode; -- '' -- */
281 #define ES_P2_MODEM (0x03<<2) /* mask for above */
282 #define ES_P2_MODEI(i) (((i)>>2)&0x03)
283 #define ES_P1_MODEO(o) (((o)&0x03)<<0) /* DAC1 mode; -- '' -- */
284 #define ES_P1_MODEM (0x03<<0) /* mask for above */
285 #define ES_P1_MODEI(i) (((i)>>0)&0x03)
287 #define ES_REG_DAC1_COUNT 0x24 /* R/W: DAC1 sample count register */
288 #define ES_REG_DAC2_COUNT 0x28 /* R/W: DAC2 sample count register */
289 #define ES_REG_ADC_COUNT 0x2c /* R/W: ADC sample count register */
290 #define ES_REG_CURR_COUNT(i) (((i)>>16)&0xffff)
291 #define ES_REG_COUNTO(o) (((o)&0xffff)<<0)
292 #define ES_REG_COUNTM (0xffff<<0)
293 #define ES_REG_COUNTI(i) (((i)>>0)&0xffff)
295 #define ES_REG_DAC1_FRAME 0x30 /* R/W: PAGE 0x0c; DAC1 frame address */
296 #define ES_REG_DAC1_SIZE 0x34 /* R/W: PAGE 0x0c; DAC1 frame size */
297 #define ES_REG_DAC2_FRAME 0x38 /* R/W: PAGE 0x0c; DAC2 frame address */
298 #define ES_REG_DAC2_SIZE 0x3c /* R/W: PAGE 0x0c; DAC2 frame size */
299 #define ES_REG_ADC_FRAME 0x30 /* R/W: PAGE 0x0d; ADC frame address */
300 #define ES_REG_ADC_SIZE 0x34 /* R/W: PAGE 0x0d; ADC frame size */
301 #define ES_REG_FCURR_COUNTO(o) (((o)&0xffff)<<16)
302 #define ES_REG_FCURR_COUNTM (0xffff<<16)
303 #define ES_REG_FCURR_COUNTI(i) (((i)>>14)&0x3fffc)
304 #define ES_REG_FSIZEO(o) (((o)&0xffff)<<0)
305 #define ES_REG_FSIZEM (0xffff<<0)
306 #define ES_REG_FSIZEI(i) (((i)>>0)&0xffff)
307 #define ES_REG_PHANTOM_FRAME 0x38 /* R/W: PAGE 0x0d: phantom frame address */
308 #define ES_REG_PHANTOM_COUNT 0x3c /* R/W: PAGE 0x0d: phantom frame count */
310 #define ES_REG_UART_FIFO 0x30 /* R/W: PAGE 0x0e; UART FIFO register */
311 #define ES_REG_UF_VALID (1<<8)
312 #define ES_REG_UF_BYTEO(o) (((o)&0xff)<<0)
313 #define ES_REG_UF_BYTEM (0xff<<0)
314 #define ES_REG_UF_BYTEI(i) (((i)>>0)&0xff)
321 #define ES_PAGE_DAC 0x0c
322 #define ES_PAGE_ADC 0x0d
323 #define ES_PAGE_UART 0x0e
324 #define ES_PAGE_UART1 0x0f
327 * Sample rate converter addresses
330 #define ES_SMPREG_DAC1 0x70
331 #define ES_SMPREG_DAC2 0x74
332 #define ES_SMPREG_ADC 0x78
333 #define ES_SMPREG_VOL_ADC 0x6c
334 #define ES_SMPREG_VOL_DAC1 0x7c
335 #define ES_SMPREG_VOL_DAC2 0x7e
336 #define ES_SMPREG_TRUNC_N 0x00
337 #define ES_SMPREG_INT_REGS 0x01
338 #define ES_SMPREG_ACCUM_FRAC 0x02
339 #define ES_SMPREG_VFREQ_FRAC 0x03
345 #define ES_1370_SRCLOCK 1411200
346 #define ES_1370_SRTODIV(x) (ES_1370_SRCLOCK/(x)-2)
352 #define ES_MODE_PLAY1 0x0001
353 #define ES_MODE_PLAY2 0x0002
354 #define ES_MODE_CAPTURE 0x0004
356 #define ES_MODE_OUTPUT 0x0001 /* for MIDI */
357 #define ES_MODE_INPUT 0x0002 /* for MIDI */
363 typedef struct _snd_ensoniq ensoniq_t
;
365 struct _snd_ensoniq
{
367 struct semaphore src_mutex
;
371 unsigned long playback1size
;
372 unsigned long playback2size
;
373 unsigned long capture3size
;
377 unsigned int uartm
; /* UART mode */
379 unsigned int ctrl
; /* control register */
380 unsigned int sctrl
; /* serial control register */
381 unsigned int cssr
; /* control status register */
382 unsigned int uartc
; /* uart control register */
383 unsigned int rev
; /* chip revision */
399 unsigned short subsystem_vendor_id
;
400 unsigned short subsystem_device_id
;
402 snd_pcm_t
*pcm1
; /* DAC1/ADC PCM */
403 snd_pcm_t
*pcm2
; /* DAC2 PCM */
404 snd_pcm_substream_t
*playback1_substream
;
405 snd_pcm_substream_t
*playback2_substream
;
406 snd_pcm_substream_t
*capture_substream
;
407 unsigned int p1_dma_size
;
408 unsigned int p2_dma_size
;
409 unsigned int c_dma_size
;
410 unsigned int p1_period_size
;
411 unsigned int p2_period_size
;
412 unsigned int c_period_size
;
413 snd_rawmidi_t
*rmidi
;
414 snd_rawmidi_substream_t
*midi_input
;
415 snd_rawmidi_substream_t
*midi_output
;
418 unsigned int spdif_default
;
419 unsigned int spdif_stream
;
422 struct snd_dma_buffer dma_bug
;
425 #ifdef SUPPORT_JOYSTICK
426 struct gameport
*gameport
;
430 static irqreturn_t
snd_audiopci_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
432 static struct pci_device_id snd_audiopci_ids
[] = {
434 { 0x1274, 0x5000, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0, }, /* ES1370 */
437 { 0x1274, 0x1371, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0, }, /* ES1371 */
438 { 0x1274, 0x5880, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0, }, /* ES1373 - CT5880 */
439 { 0x1102, 0x8938, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0, }, /* Ectiva EV1938 */
444 MODULE_DEVICE_TABLE(pci
, snd_audiopci_ids
);
450 #define POLL_COUNT 0xa000
453 static unsigned int snd_es1370_fixed_rates
[] =
454 {5512, 11025, 22050, 44100};
455 static snd_pcm_hw_constraint_list_t snd_es1370_hw_constraints_rates
= {
457 .list
= snd_es1370_fixed_rates
,
460 static ratnum_t es1370_clock
= {
461 .num
= ES_1370_SRCLOCK
,
466 static snd_pcm_hw_constraint_ratnums_t snd_es1370_hw_constraints_clock
= {
468 .rats
= &es1370_clock
,
471 static ratden_t es1371_dac_clock
= {
472 .num_min
= 3000 * (1 << 15),
473 .num_max
= 48000 * (1 << 15),
477 static snd_pcm_hw_constraint_ratdens_t snd_es1371_hw_constraints_dac_clock
= {
479 .rats
= &es1371_dac_clock
,
481 static ratnum_t es1371_adc_clock
= {
487 static snd_pcm_hw_constraint_ratnums_t snd_es1371_hw_constraints_adc_clock
= {
489 .rats
= &es1371_adc_clock
,
492 static const unsigned int snd_ensoniq_sample_shift
[] =
496 * common I/O routines
501 static unsigned int snd_es1371_wait_src_ready(ensoniq_t
* ensoniq
)
503 unsigned int t
, r
= 0;
505 for (t
= 0; t
< POLL_COUNT
; t
++) {
506 r
= inl(ES_REG(ensoniq
, 1371_SMPRATE
));
507 if ((r
& ES_1371_SRC_RAM_BUSY
) == 0)
511 snd_printk("wait source ready timeout 0x%lx [0x%x]\n", ES_REG(ensoniq
, 1371_SMPRATE
), r
);
515 static unsigned int snd_es1371_src_read(ensoniq_t
* ensoniq
, unsigned short reg
)
517 unsigned int temp
, i
, orig
, r
;
520 temp
= orig
= snd_es1371_wait_src_ready(ensoniq
);
522 /* expose the SRC state bits */
523 r
= temp
& (ES_1371_SRC_DISABLE
| ES_1371_DIS_P1
|
524 ES_1371_DIS_P2
| ES_1371_DIS_R1
);
525 r
|= ES_1371_SRC_RAM_ADDRO(reg
) | 0x10000;
526 outl(r
, ES_REG(ensoniq
, 1371_SMPRATE
));
528 /* now, wait for busy and the correct time to read */
529 temp
= snd_es1371_wait_src_ready(ensoniq
);
531 if ((temp
& 0x00870000) != 0x00010000) {
532 /* wait for the right state */
533 for (i
= 0; i
< POLL_COUNT
; i
++) {
534 temp
= inl(ES_REG(ensoniq
, 1371_SMPRATE
));
535 if ((temp
& 0x00870000) == 0x00010000)
540 /* hide the state bits */
541 r
= orig
& (ES_1371_SRC_DISABLE
| ES_1371_DIS_P1
|
542 ES_1371_DIS_P2
| ES_1371_DIS_R1
);
543 r
|= ES_1371_SRC_RAM_ADDRO(reg
);
544 outl(r
, ES_REG(ensoniq
, 1371_SMPRATE
));
549 static void snd_es1371_src_write(ensoniq_t
* ensoniq
,
550 unsigned short reg
, unsigned short data
)
554 r
= snd_es1371_wait_src_ready(ensoniq
) &
555 (ES_1371_SRC_DISABLE
| ES_1371_DIS_P1
|
556 ES_1371_DIS_P2
| ES_1371_DIS_R1
);
557 r
|= ES_1371_SRC_RAM_ADDRO(reg
) | ES_1371_SRC_RAM_DATAO(data
);
558 outl(r
| ES_1371_SRC_RAM_WE
, ES_REG(ensoniq
, 1371_SMPRATE
));
561 #endif /* CHIP1371 */
565 static void snd_es1370_codec_write(ak4531_t
*ak4531
,
566 unsigned short reg
, unsigned short val
)
568 ensoniq_t
*ensoniq
= ak4531
->private_data
;
569 unsigned long end_time
= jiffies
+ HZ
/ 10;
572 printk("CODEC WRITE: reg = 0x%x, val = 0x%x (0x%x), creg = 0x%x\n", reg
, val
, ES_1370_CODEC_WRITE(reg
, val
), ES_REG(ensoniq
, 1370_CODEC
));
575 if (!(inl(ES_REG(ensoniq
, STATUS
)) & ES_1370_CSTAT
)) {
576 outw(ES_1370_CODEC_WRITE(reg
, val
), ES_REG(ensoniq
, 1370_CODEC
));
579 set_current_state(TASK_UNINTERRUPTIBLE
);
581 } while (time_after(end_time
, jiffies
));
582 snd_printk("codec write timeout, status = 0x%x\n", inl(ES_REG(ensoniq
, STATUS
)));
585 #endif /* CHIP1370 */
589 static void snd_es1371_codec_write(ac97_t
*ac97
,
590 unsigned short reg
, unsigned short val
)
592 ensoniq_t
*ensoniq
= ac97
->private_data
;
595 down(&ensoniq
->src_mutex
);
596 for (t
= 0; t
< POLL_COUNT
; t
++) {
597 if (!(inl(ES_REG(ensoniq
, 1371_CODEC
)) & ES_1371_CODEC_WIP
)) {
598 /* save the current state for latter */
599 x
= snd_es1371_wait_src_ready(ensoniq
);
600 outl((x
& (ES_1371_SRC_DISABLE
| ES_1371_DIS_P1
|
601 ES_1371_DIS_P2
| ES_1371_DIS_R1
)) | 0x00010000,
602 ES_REG(ensoniq
, 1371_SMPRATE
));
603 /* wait for not busy (state 0) first to avoid
605 for (t
= 0; t
< POLL_COUNT
; t
++) {
606 if ((inl(ES_REG(ensoniq
, 1371_SMPRATE
)) & 0x00870000) == 0x00000000)
609 /* wait for a SAFE time to write addr/data and then do it, dammit */
610 for (t
= 0; t
< POLL_COUNT
; t
++) {
611 if ((inl(ES_REG(ensoniq
, 1371_SMPRATE
)) & 0x00870000) == 0x00010000)
614 outl(ES_1371_CODEC_WRITE(reg
, val
), ES_REG(ensoniq
, 1371_CODEC
));
615 /* restore SRC reg */
616 snd_es1371_wait_src_ready(ensoniq
);
617 outl(x
, ES_REG(ensoniq
, 1371_SMPRATE
));
618 up(&ensoniq
->src_mutex
);
622 up(&ensoniq
->src_mutex
);
623 snd_printk("codec write timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq
, 1371_CODEC
), inl(ES_REG(ensoniq
, 1371_CODEC
)));
626 static unsigned short snd_es1371_codec_read(ac97_t
*ac97
,
629 ensoniq_t
*ensoniq
= ac97
->private_data
;
630 unsigned int t
, x
, fail
= 0;
633 down(&ensoniq
->src_mutex
);
634 for (t
= 0; t
< POLL_COUNT
; t
++) {
635 if (!(inl(ES_REG(ensoniq
, 1371_CODEC
)) & ES_1371_CODEC_WIP
)) {
636 /* save the current state for latter */
637 x
= snd_es1371_wait_src_ready(ensoniq
);
638 outl((x
& (ES_1371_SRC_DISABLE
| ES_1371_DIS_P1
|
639 ES_1371_DIS_P2
| ES_1371_DIS_R1
)) | 0x00010000,
640 ES_REG(ensoniq
, 1371_SMPRATE
));
641 /* wait for not busy (state 0) first to avoid
643 for (t
= 0; t
< POLL_COUNT
; t
++) {
644 if ((inl(ES_REG(ensoniq
, 1371_SMPRATE
)) & 0x00870000) == 0x00000000)
647 /* wait for a SAFE time to write addr/data and then do it, dammit */
648 for (t
= 0; t
< POLL_COUNT
; t
++) {
649 if ((inl(ES_REG(ensoniq
, 1371_SMPRATE
)) & 0x00870000) == 0x00010000)
652 outl(ES_1371_CODEC_READS(reg
), ES_REG(ensoniq
, 1371_CODEC
));
653 /* restore SRC reg */
654 snd_es1371_wait_src_ready(ensoniq
);
655 outl(x
, ES_REG(ensoniq
, 1371_SMPRATE
));
656 /* wait for WIP again */
657 for (t
= 0; t
< POLL_COUNT
; t
++) {
658 if (!(inl(ES_REG(ensoniq
, 1371_CODEC
)) & ES_1371_CODEC_WIP
))
661 /* now wait for the stinkin' data (RDY) */
662 for (t
= 0; t
< POLL_COUNT
; t
++) {
663 if ((x
= inl(ES_REG(ensoniq
, 1371_CODEC
))) & ES_1371_CODEC_RDY
) {
664 up(&ensoniq
->src_mutex
);
665 return ES_1371_CODEC_READ(x
);
668 up(&ensoniq
->src_mutex
);
670 snd_printk("codec read timeout (final) at 0x%lx, reg = 0x%x [0x%x]\n", ES_REG(ensoniq
, 1371_CODEC
), reg
, inl(ES_REG(ensoniq
, 1371_CODEC
)));
676 up(&ensoniq
->src_mutex
);
677 snd_printk("es1371: codec read timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq
, 1371_CODEC
), inl(ES_REG(ensoniq
, 1371_CODEC
)));
681 static void snd_es1371_codec_wait(ac97_t
*ac97
)
684 snd_es1371_codec_read(ac97
, AC97_RESET
);
685 snd_es1371_codec_read(ac97
, AC97_VENDOR_ID1
);
686 snd_es1371_codec_read(ac97
, AC97_VENDOR_ID2
);
690 static void snd_es1371_adc_rate(ensoniq_t
* ensoniq
, unsigned int rate
)
692 unsigned int n
, truncm
, freq
, result
;
694 down(&ensoniq
->src_mutex
);
696 if ((1 << n
) & ((1 << 15) | (1 << 13) | (1 << 11) | (1 << 9)))
698 truncm
= (21 * n
- 1) | 1;
699 freq
= ((48000UL << 15) / rate
) * n
;
700 result
= (48000UL << 15) / (freq
/ n
);
704 snd_es1371_src_write(ensoniq
, ES_SMPREG_ADC
+ ES_SMPREG_TRUNC_N
,
705 (((239 - truncm
) >> 1) << 9) | (n
<< 4));
709 snd_es1371_src_write(ensoniq
, ES_SMPREG_ADC
+ ES_SMPREG_TRUNC_N
,
710 0x8000 | (((119 - truncm
) >> 1) << 9) | (n
<< 4));
712 snd_es1371_src_write(ensoniq
, ES_SMPREG_ADC
+ ES_SMPREG_INT_REGS
,
713 (snd_es1371_src_read(ensoniq
, ES_SMPREG_ADC
+ ES_SMPREG_INT_REGS
) & 0x00ff) |
714 ((freq
>> 5) & 0xfc00));
715 snd_es1371_src_write(ensoniq
, ES_SMPREG_ADC
+ ES_SMPREG_VFREQ_FRAC
, freq
& 0x7fff);
716 snd_es1371_src_write(ensoniq
, ES_SMPREG_VOL_ADC
, n
<< 8);
717 snd_es1371_src_write(ensoniq
, ES_SMPREG_VOL_ADC
+ 1, n
<< 8);
718 up(&ensoniq
->src_mutex
);
721 static void snd_es1371_dac1_rate(ensoniq_t
* ensoniq
, unsigned int rate
)
723 unsigned int freq
, r
;
725 down(&ensoniq
->src_mutex
);
726 freq
= ((rate
<< 15) + 1500) / 3000;
727 r
= (snd_es1371_wait_src_ready(ensoniq
) & (ES_1371_SRC_DISABLE
| ES_1371_DIS_P2
| ES_1371_DIS_R1
)) | ES_1371_DIS_P1
;
728 outl(r
, ES_REG(ensoniq
, 1371_SMPRATE
));
729 snd_es1371_src_write(ensoniq
, ES_SMPREG_DAC1
+ ES_SMPREG_INT_REGS
,
730 (snd_es1371_src_read(ensoniq
, ES_SMPREG_DAC1
+ ES_SMPREG_INT_REGS
) & 0x00ff) |
731 ((freq
>> 5) & 0xfc00));
732 snd_es1371_src_write(ensoniq
, ES_SMPREG_DAC1
+ ES_SMPREG_VFREQ_FRAC
, freq
& 0x7fff);
733 r
= (snd_es1371_wait_src_ready(ensoniq
) & (ES_1371_SRC_DISABLE
| ES_1371_DIS_P2
| ES_1371_DIS_R1
));
734 outl(r
, ES_REG(ensoniq
, 1371_SMPRATE
));
735 up(&ensoniq
->src_mutex
);
738 static void snd_es1371_dac2_rate(ensoniq_t
* ensoniq
, unsigned int rate
)
740 unsigned int freq
, r
;
742 down(&ensoniq
->src_mutex
);
743 freq
= ((rate
<< 15) + 1500) / 3000;
744 r
= (snd_es1371_wait_src_ready(ensoniq
) & (ES_1371_SRC_DISABLE
| ES_1371_DIS_P1
| ES_1371_DIS_R1
)) | ES_1371_DIS_P2
;
745 outl(r
, ES_REG(ensoniq
, 1371_SMPRATE
));
746 snd_es1371_src_write(ensoniq
, ES_SMPREG_DAC2
+ ES_SMPREG_INT_REGS
,
747 (snd_es1371_src_read(ensoniq
, ES_SMPREG_DAC2
+ ES_SMPREG_INT_REGS
) & 0x00ff) |
748 ((freq
>> 5) & 0xfc00));
749 snd_es1371_src_write(ensoniq
, ES_SMPREG_DAC2
+ ES_SMPREG_VFREQ_FRAC
, freq
& 0x7fff);
750 r
= (snd_es1371_wait_src_ready(ensoniq
) & (ES_1371_SRC_DISABLE
| ES_1371_DIS_P1
| ES_1371_DIS_R1
));
751 outl(r
, ES_REG(ensoniq
, 1371_SMPRATE
));
752 up(&ensoniq
->src_mutex
);
755 #endif /* CHIP1371 */
757 static int snd_ensoniq_trigger(snd_pcm_substream_t
*substream
, int cmd
)
759 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
761 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
762 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
764 unsigned int what
= 0;
765 struct list_head
*pos
;
766 snd_pcm_substream_t
*s
;
767 snd_pcm_group_for_each(pos
, substream
) {
768 s
= snd_pcm_group_substream_entry(pos
);
769 if (s
== ensoniq
->playback1_substream
) {
771 snd_pcm_trigger_done(s
, substream
);
772 } else if (s
== ensoniq
->playback2_substream
) {
774 snd_pcm_trigger_done(s
, substream
);
775 } else if (s
== ensoniq
->capture_substream
)
778 spin_lock(&ensoniq
->reg_lock
);
779 if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_PUSH
)
780 ensoniq
->sctrl
|= what
;
782 ensoniq
->sctrl
&= ~what
;
783 outl(ensoniq
->sctrl
, ES_REG(ensoniq
, SERIAL
));
784 spin_unlock(&ensoniq
->reg_lock
);
787 case SNDRV_PCM_TRIGGER_START
:
788 case SNDRV_PCM_TRIGGER_STOP
:
790 unsigned int what
= 0;
791 struct list_head
*pos
;
792 snd_pcm_substream_t
*s
;
793 snd_pcm_group_for_each(pos
, substream
) {
794 s
= snd_pcm_group_substream_entry(pos
);
795 if (s
== ensoniq
->playback1_substream
) {
797 snd_pcm_trigger_done(s
, substream
);
798 } else if (s
== ensoniq
->playback2_substream
) {
800 snd_pcm_trigger_done(s
, substream
);
801 } else if (s
== ensoniq
->capture_substream
) {
803 snd_pcm_trigger_done(s
, substream
);
806 spin_lock(&ensoniq
->reg_lock
);
807 if (cmd
== SNDRV_PCM_TRIGGER_START
)
808 ensoniq
->ctrl
|= what
;
810 ensoniq
->ctrl
&= ~what
;
811 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
812 spin_unlock(&ensoniq
->reg_lock
);
825 static int snd_ensoniq_hw_params(snd_pcm_substream_t
* substream
,
826 snd_pcm_hw_params_t
* hw_params
)
828 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
831 static int snd_ensoniq_hw_free(snd_pcm_substream_t
* substream
)
833 return snd_pcm_lib_free_pages(substream
);
836 static int snd_ensoniq_playback1_prepare(snd_pcm_substream_t
* substream
)
838 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
839 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
840 unsigned int mode
= 0;
842 ensoniq
->p1_dma_size
= snd_pcm_lib_buffer_bytes(substream
);
843 ensoniq
->p1_period_size
= snd_pcm_lib_period_bytes(substream
);
844 if (snd_pcm_format_width(runtime
->format
) == 16)
846 if (runtime
->channels
> 1)
848 spin_lock_irq(&ensoniq
->reg_lock
);
849 ensoniq
->ctrl
&= ~ES_DAC1_EN
;
851 /* 48k doesn't need SRC (it breaks AC3-passthru) */
852 if (runtime
->rate
== 48000)
853 ensoniq
->ctrl
|= ES_1373_BYPASS_P1
;
855 ensoniq
->ctrl
&= ~ES_1373_BYPASS_P1
;
857 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
858 outl(ES_MEM_PAGEO(ES_PAGE_DAC
), ES_REG(ensoniq
, MEM_PAGE
));
859 outl(runtime
->dma_addr
, ES_REG(ensoniq
, DAC1_FRAME
));
860 outl((ensoniq
->p1_dma_size
>> 2) - 1, ES_REG(ensoniq
, DAC1_SIZE
));
861 ensoniq
->sctrl
&= ~(ES_P1_LOOP_SEL
| ES_P1_PAUSE
| ES_P1_SCT_RLD
| ES_P1_MODEM
);
862 ensoniq
->sctrl
|= ES_P1_INT_EN
| ES_P1_MODEO(mode
);
863 outl(ensoniq
->sctrl
, ES_REG(ensoniq
, SERIAL
));
864 outl((ensoniq
->p1_period_size
>> snd_ensoniq_sample_shift
[mode
]) - 1, ES_REG(ensoniq
, DAC1_COUNT
));
866 ensoniq
->ctrl
&= ~ES_1370_WTSRSELM
;
867 switch (runtime
->rate
) {
868 case 5512: ensoniq
->ctrl
|= ES_1370_WTSRSEL(0); break;
869 case 11025: ensoniq
->ctrl
|= ES_1370_WTSRSEL(1); break;
870 case 22050: ensoniq
->ctrl
|= ES_1370_WTSRSEL(2); break;
871 case 44100: ensoniq
->ctrl
|= ES_1370_WTSRSEL(3); break;
875 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
876 spin_unlock_irq(&ensoniq
->reg_lock
);
878 snd_es1371_dac1_rate(ensoniq
, runtime
->rate
);
883 static int snd_ensoniq_playback2_prepare(snd_pcm_substream_t
* substream
)
885 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
886 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
887 unsigned int mode
= 0;
889 ensoniq
->p2_dma_size
= snd_pcm_lib_buffer_bytes(substream
);
890 ensoniq
->p2_period_size
= snd_pcm_lib_period_bytes(substream
);
891 if (snd_pcm_format_width(runtime
->format
) == 16)
893 if (runtime
->channels
> 1)
895 spin_lock_irq(&ensoniq
->reg_lock
);
896 ensoniq
->ctrl
&= ~ES_DAC2_EN
;
897 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
898 outl(ES_MEM_PAGEO(ES_PAGE_DAC
), ES_REG(ensoniq
, MEM_PAGE
));
899 outl(runtime
->dma_addr
, ES_REG(ensoniq
, DAC2_FRAME
));
900 outl((ensoniq
->p2_dma_size
>> 2) - 1, ES_REG(ensoniq
, DAC2_SIZE
));
901 ensoniq
->sctrl
&= ~(ES_P2_LOOP_SEL
| ES_P2_PAUSE
| ES_P2_DAC_SEN
|
902 ES_P2_END_INCM
| ES_P2_ST_INCM
| ES_P2_MODEM
);
903 ensoniq
->sctrl
|= ES_P2_INT_EN
| ES_P2_MODEO(mode
) |
904 ES_P2_END_INCO(mode
& 2 ? 2 : 1) | ES_P2_ST_INCO(0);
905 outl(ensoniq
->sctrl
, ES_REG(ensoniq
, SERIAL
));
906 outl((ensoniq
->p2_period_size
>> snd_ensoniq_sample_shift
[mode
]) - 1, ES_REG(ensoniq
, DAC2_COUNT
));
908 if (!(ensoniq
->u
.es1370
.pclkdiv_lock
& ES_MODE_CAPTURE
)) {
909 ensoniq
->ctrl
&= ~ES_1370_PCLKDIVM
;
910 ensoniq
->ctrl
|= ES_1370_PCLKDIVO(ES_1370_SRTODIV(runtime
->rate
));
911 ensoniq
->u
.es1370
.pclkdiv_lock
|= ES_MODE_PLAY2
;
914 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
915 spin_unlock_irq(&ensoniq
->reg_lock
);
917 snd_es1371_dac2_rate(ensoniq
, runtime
->rate
);
922 static int snd_ensoniq_capture_prepare(snd_pcm_substream_t
* substream
)
924 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
925 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
926 unsigned int mode
= 0;
928 ensoniq
->c_dma_size
= snd_pcm_lib_buffer_bytes(substream
);
929 ensoniq
->c_period_size
= snd_pcm_lib_period_bytes(substream
);
930 if (snd_pcm_format_width(runtime
->format
) == 16)
932 if (runtime
->channels
> 1)
934 spin_lock_irq(&ensoniq
->reg_lock
);
935 ensoniq
->ctrl
&= ~ES_ADC_EN
;
936 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
937 outl(ES_MEM_PAGEO(ES_PAGE_ADC
), ES_REG(ensoniq
, MEM_PAGE
));
938 outl(runtime
->dma_addr
, ES_REG(ensoniq
, ADC_FRAME
));
939 outl((ensoniq
->c_dma_size
>> 2) - 1, ES_REG(ensoniq
, ADC_SIZE
));
940 ensoniq
->sctrl
&= ~(ES_R1_LOOP_SEL
| ES_R1_MODEM
);
941 ensoniq
->sctrl
|= ES_R1_INT_EN
| ES_R1_MODEO(mode
);
942 outl(ensoniq
->sctrl
, ES_REG(ensoniq
, SERIAL
));
943 outl((ensoniq
->c_period_size
>> snd_ensoniq_sample_shift
[mode
]) - 1, ES_REG(ensoniq
, ADC_COUNT
));
945 if (!(ensoniq
->u
.es1370
.pclkdiv_lock
& ES_MODE_PLAY2
)) {
946 ensoniq
->ctrl
&= ~ES_1370_PCLKDIVM
;
947 ensoniq
->ctrl
|= ES_1370_PCLKDIVO(ES_1370_SRTODIV(runtime
->rate
));
948 ensoniq
->u
.es1370
.pclkdiv_lock
|= ES_MODE_CAPTURE
;
951 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
952 spin_unlock_irq(&ensoniq
->reg_lock
);
954 snd_es1371_adc_rate(ensoniq
, runtime
->rate
);
959 static snd_pcm_uframes_t
snd_ensoniq_playback1_pointer(snd_pcm_substream_t
* substream
)
961 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
964 spin_lock(&ensoniq
->reg_lock
);
965 if (inl(ES_REG(ensoniq
, CONTROL
)) & ES_DAC1_EN
) {
966 outl(ES_MEM_PAGEO(ES_PAGE_DAC
), ES_REG(ensoniq
, MEM_PAGE
));
967 ptr
= ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq
, DAC1_SIZE
)));
968 ptr
= bytes_to_frames(substream
->runtime
, ptr
);
972 spin_unlock(&ensoniq
->reg_lock
);
976 static snd_pcm_uframes_t
snd_ensoniq_playback2_pointer(snd_pcm_substream_t
* substream
)
978 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
981 spin_lock(&ensoniq
->reg_lock
);
982 if (inl(ES_REG(ensoniq
, CONTROL
)) & ES_DAC2_EN
) {
983 outl(ES_MEM_PAGEO(ES_PAGE_DAC
), ES_REG(ensoniq
, MEM_PAGE
));
984 ptr
= ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq
, DAC2_SIZE
)));
985 ptr
= bytes_to_frames(substream
->runtime
, ptr
);
989 spin_unlock(&ensoniq
->reg_lock
);
993 static snd_pcm_uframes_t
snd_ensoniq_capture_pointer(snd_pcm_substream_t
* substream
)
995 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
998 spin_lock(&ensoniq
->reg_lock
);
999 if (inl(ES_REG(ensoniq
, CONTROL
)) & ES_ADC_EN
) {
1000 outl(ES_MEM_PAGEO(ES_PAGE_ADC
), ES_REG(ensoniq
, MEM_PAGE
));
1001 ptr
= ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq
, ADC_SIZE
)));
1002 ptr
= bytes_to_frames(substream
->runtime
, ptr
);
1006 spin_unlock(&ensoniq
->reg_lock
);
1010 static snd_pcm_hardware_t snd_ensoniq_playback1
=
1012 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1013 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1014 SNDRV_PCM_INFO_MMAP_VALID
|
1015 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_SYNC_START
),
1016 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
1019 SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1021 (SNDRV_PCM_RATE_KNOT
| /* 5512Hz rate */
1022 SNDRV_PCM_RATE_11025
| SNDRV_PCM_RATE_22050
|
1023 SNDRV_PCM_RATE_44100
),
1029 .buffer_bytes_max
= (128*1024),
1030 .period_bytes_min
= 64,
1031 .period_bytes_max
= (128*1024),
1033 .periods_max
= 1024,
1037 static snd_pcm_hardware_t snd_ensoniq_playback2
=
1039 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1040 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1041 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
|
1042 SNDRV_PCM_INFO_SYNC_START
),
1043 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
1044 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1049 .buffer_bytes_max
= (128*1024),
1050 .period_bytes_min
= 64,
1051 .period_bytes_max
= (128*1024),
1053 .periods_max
= 1024,
1057 static snd_pcm_hardware_t snd_ensoniq_capture
=
1059 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1060 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1061 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_SYNC_START
),
1062 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
1063 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_48000
,
1068 .buffer_bytes_max
= (128*1024),
1069 .period_bytes_min
= 64,
1070 .period_bytes_max
= (128*1024),
1072 .periods_max
= 1024,
1076 static int snd_ensoniq_playback1_open(snd_pcm_substream_t
* substream
)
1078 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
1079 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1081 ensoniq
->mode
|= ES_MODE_PLAY1
;
1082 ensoniq
->playback1_substream
= substream
;
1083 runtime
->hw
= snd_ensoniq_playback1
;
1084 snd_pcm_set_sync(substream
);
1085 spin_lock_irq(&ensoniq
->reg_lock
);
1086 if (ensoniq
->spdif
&& ensoniq
->playback2_substream
== NULL
)
1087 ensoniq
->spdif_stream
= ensoniq
->spdif_default
;
1088 spin_unlock_irq(&ensoniq
->reg_lock
);
1090 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1091 &snd_es1370_hw_constraints_rates
);
1093 snd_pcm_hw_constraint_ratdens(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1094 &snd_es1371_hw_constraints_dac_clock
);
1099 static int snd_ensoniq_playback2_open(snd_pcm_substream_t
* substream
)
1101 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
1102 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1104 ensoniq
->mode
|= ES_MODE_PLAY2
;
1105 ensoniq
->playback2_substream
= substream
;
1106 runtime
->hw
= snd_ensoniq_playback2
;
1107 snd_pcm_set_sync(substream
);
1108 spin_lock_irq(&ensoniq
->reg_lock
);
1109 if (ensoniq
->spdif
&& ensoniq
->playback1_substream
== NULL
)
1110 ensoniq
->spdif_stream
= ensoniq
->spdif_default
;
1111 spin_unlock_irq(&ensoniq
->reg_lock
);
1113 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1114 &snd_es1370_hw_constraints_clock
);
1116 snd_pcm_hw_constraint_ratdens(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1117 &snd_es1371_hw_constraints_dac_clock
);
1122 static int snd_ensoniq_capture_open(snd_pcm_substream_t
* substream
)
1124 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
1125 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1127 ensoniq
->mode
|= ES_MODE_CAPTURE
;
1128 ensoniq
->capture_substream
= substream
;
1129 runtime
->hw
= snd_ensoniq_capture
;
1130 snd_pcm_set_sync(substream
);
1132 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1133 &snd_es1370_hw_constraints_clock
);
1135 snd_pcm_hw_constraint_ratnums(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1136 &snd_es1371_hw_constraints_adc_clock
);
1141 static int snd_ensoniq_playback1_close(snd_pcm_substream_t
* substream
)
1143 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
1145 ensoniq
->playback1_substream
= NULL
;
1146 ensoniq
->mode
&= ~ES_MODE_PLAY1
;
1150 static int snd_ensoniq_playback2_close(snd_pcm_substream_t
* substream
)
1152 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
1154 ensoniq
->playback2_substream
= NULL
;
1155 spin_lock_irq(&ensoniq
->reg_lock
);
1157 ensoniq
->u
.es1370
.pclkdiv_lock
&= ~ES_MODE_PLAY2
;
1159 ensoniq
->mode
&= ~ES_MODE_PLAY2
;
1160 spin_unlock_irq(&ensoniq
->reg_lock
);
1164 static int snd_ensoniq_capture_close(snd_pcm_substream_t
* substream
)
1166 ensoniq_t
*ensoniq
= snd_pcm_substream_chip(substream
);
1168 ensoniq
->capture_substream
= NULL
;
1169 spin_lock_irq(&ensoniq
->reg_lock
);
1171 ensoniq
->u
.es1370
.pclkdiv_lock
&= ~ES_MODE_CAPTURE
;
1173 ensoniq
->mode
&= ~ES_MODE_CAPTURE
;
1174 spin_unlock_irq(&ensoniq
->reg_lock
);
1178 static snd_pcm_ops_t snd_ensoniq_playback1_ops
= {
1179 .open
= snd_ensoniq_playback1_open
,
1180 .close
= snd_ensoniq_playback1_close
,
1181 .ioctl
= snd_pcm_lib_ioctl
,
1182 .hw_params
= snd_ensoniq_hw_params
,
1183 .hw_free
= snd_ensoniq_hw_free
,
1184 .prepare
= snd_ensoniq_playback1_prepare
,
1185 .trigger
= snd_ensoniq_trigger
,
1186 .pointer
= snd_ensoniq_playback1_pointer
,
1189 static snd_pcm_ops_t snd_ensoniq_playback2_ops
= {
1190 .open
= snd_ensoniq_playback2_open
,
1191 .close
= snd_ensoniq_playback2_close
,
1192 .ioctl
= snd_pcm_lib_ioctl
,
1193 .hw_params
= snd_ensoniq_hw_params
,
1194 .hw_free
= snd_ensoniq_hw_free
,
1195 .prepare
= snd_ensoniq_playback2_prepare
,
1196 .trigger
= snd_ensoniq_trigger
,
1197 .pointer
= snd_ensoniq_playback2_pointer
,
1200 static snd_pcm_ops_t snd_ensoniq_capture_ops
= {
1201 .open
= snd_ensoniq_capture_open
,
1202 .close
= snd_ensoniq_capture_close
,
1203 .ioctl
= snd_pcm_lib_ioctl
,
1204 .hw_params
= snd_ensoniq_hw_params
,
1205 .hw_free
= snd_ensoniq_hw_free
,
1206 .prepare
= snd_ensoniq_capture_prepare
,
1207 .trigger
= snd_ensoniq_trigger
,
1208 .pointer
= snd_ensoniq_capture_pointer
,
1211 static void snd_ensoniq_pcm_free(snd_pcm_t
*pcm
)
1213 ensoniq_t
*ensoniq
= pcm
->private_data
;
1214 ensoniq
->pcm1
= NULL
;
1215 snd_pcm_lib_preallocate_free_for_all(pcm
);
1218 static int __devinit
snd_ensoniq_pcm(ensoniq_t
* ensoniq
, int device
, snd_pcm_t
** rpcm
)
1226 err
= snd_pcm_new(ensoniq
->card
, "ES1370/1", device
, 1, 1, &pcm
);
1228 err
= snd_pcm_new(ensoniq
->card
, "ES1371/1", device
, 1, 1, &pcm
);
1234 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ensoniq_playback2_ops
);
1236 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ensoniq_playback1_ops
);
1238 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_ensoniq_capture_ops
);
1240 pcm
->private_data
= ensoniq
;
1241 pcm
->private_free
= snd_ensoniq_pcm_free
;
1242 pcm
->info_flags
= 0;
1244 strcpy(pcm
->name
, "ES1370 DAC2/ADC");
1246 strcpy(pcm
->name
, "ES1371 DAC2/ADC");
1248 ensoniq
->pcm1
= pcm
;
1250 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1251 snd_dma_pci_data(ensoniq
->pci
), 64*1024, 128*1024);
1258 static void snd_ensoniq_pcm_free2(snd_pcm_t
*pcm
)
1260 ensoniq_t
*ensoniq
= pcm
->private_data
;
1261 ensoniq
->pcm2
= NULL
;
1262 snd_pcm_lib_preallocate_free_for_all(pcm
);
1265 static int __devinit
snd_ensoniq_pcm2(ensoniq_t
* ensoniq
, int device
, snd_pcm_t
** rpcm
)
1273 err
= snd_pcm_new(ensoniq
->card
, "ES1370/2", device
, 1, 0, &pcm
);
1275 err
= snd_pcm_new(ensoniq
->card
, "ES1371/2", device
, 1, 0, &pcm
);
1281 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ensoniq_playback1_ops
);
1283 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_ensoniq_playback2_ops
);
1285 pcm
->private_data
= ensoniq
;
1286 pcm
->private_free
= snd_ensoniq_pcm_free2
;
1287 pcm
->info_flags
= 0;
1289 strcpy(pcm
->name
, "ES1370 DAC1");
1291 strcpy(pcm
->name
, "ES1371 DAC1");
1293 ensoniq
->pcm2
= pcm
;
1295 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1296 snd_dma_pci_data(ensoniq
->pci
), 64*1024, 128*1024);
1308 * ENS1371 mixer (including SPDIF interface)
1311 static int snd_ens1373_spdif_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1313 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1318 static int snd_ens1373_spdif_default_get(snd_kcontrol_t
* kcontrol
,
1319 snd_ctl_elem_value_t
* ucontrol
)
1321 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1322 spin_lock_irq(&ensoniq
->reg_lock
);
1323 ucontrol
->value
.iec958
.status
[0] = (ensoniq
->spdif_default
>> 0) & 0xff;
1324 ucontrol
->value
.iec958
.status
[1] = (ensoniq
->spdif_default
>> 8) & 0xff;
1325 ucontrol
->value
.iec958
.status
[2] = (ensoniq
->spdif_default
>> 16) & 0xff;
1326 ucontrol
->value
.iec958
.status
[3] = (ensoniq
->spdif_default
>> 24) & 0xff;
1327 spin_unlock_irq(&ensoniq
->reg_lock
);
1331 static int snd_ens1373_spdif_default_put(snd_kcontrol_t
* kcontrol
,
1332 snd_ctl_elem_value_t
* ucontrol
)
1334 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1338 val
= ((u32
)ucontrol
->value
.iec958
.status
[0] << 0) |
1339 ((u32
)ucontrol
->value
.iec958
.status
[1] << 8) |
1340 ((u32
)ucontrol
->value
.iec958
.status
[2] << 16) |
1341 ((u32
)ucontrol
->value
.iec958
.status
[3] << 24);
1342 spin_lock_irq(&ensoniq
->reg_lock
);
1343 change
= ensoniq
->spdif_default
!= val
;
1344 ensoniq
->spdif_default
= val
;
1345 if (change
&& ensoniq
->playback1_substream
== NULL
&& ensoniq
->playback2_substream
== NULL
)
1346 outl(val
, ES_REG(ensoniq
, CHANNEL_STATUS
));
1347 spin_unlock_irq(&ensoniq
->reg_lock
);
1351 static int snd_ens1373_spdif_mask_get(snd_kcontrol_t
* kcontrol
,
1352 snd_ctl_elem_value_t
* ucontrol
)
1354 ucontrol
->value
.iec958
.status
[0] = 0xff;
1355 ucontrol
->value
.iec958
.status
[1] = 0xff;
1356 ucontrol
->value
.iec958
.status
[2] = 0xff;
1357 ucontrol
->value
.iec958
.status
[3] = 0xff;
1361 static int snd_ens1373_spdif_stream_get(snd_kcontrol_t
* kcontrol
,
1362 snd_ctl_elem_value_t
* ucontrol
)
1364 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1365 spin_lock_irq(&ensoniq
->reg_lock
);
1366 ucontrol
->value
.iec958
.status
[0] = (ensoniq
->spdif_stream
>> 0) & 0xff;
1367 ucontrol
->value
.iec958
.status
[1] = (ensoniq
->spdif_stream
>> 8) & 0xff;
1368 ucontrol
->value
.iec958
.status
[2] = (ensoniq
->spdif_stream
>> 16) & 0xff;
1369 ucontrol
->value
.iec958
.status
[3] = (ensoniq
->spdif_stream
>> 24) & 0xff;
1370 spin_unlock_irq(&ensoniq
->reg_lock
);
1374 static int snd_ens1373_spdif_stream_put(snd_kcontrol_t
* kcontrol
,
1375 snd_ctl_elem_value_t
* ucontrol
)
1377 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1381 val
= ((u32
)ucontrol
->value
.iec958
.status
[0] << 0) |
1382 ((u32
)ucontrol
->value
.iec958
.status
[1] << 8) |
1383 ((u32
)ucontrol
->value
.iec958
.status
[2] << 16) |
1384 ((u32
)ucontrol
->value
.iec958
.status
[3] << 24);
1385 spin_lock_irq(&ensoniq
->reg_lock
);
1386 change
= ensoniq
->spdif_stream
!= val
;
1387 ensoniq
->spdif_stream
= val
;
1388 if (change
&& (ensoniq
->playback1_substream
!= NULL
|| ensoniq
->playback2_substream
!= NULL
))
1389 outl(val
, ES_REG(ensoniq
, CHANNEL_STATUS
));
1390 spin_unlock_irq(&ensoniq
->reg_lock
);
1394 #define ES1371_SPDIF(xname) \
1395 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_es1371_spdif_info, \
1396 .get = snd_es1371_spdif_get, .put = snd_es1371_spdif_put }
1398 static int snd_es1371_spdif_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
1400 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1402 uinfo
->value
.integer
.min
= 0;
1403 uinfo
->value
.integer
.max
= 1;
1407 static int snd_es1371_spdif_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1409 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1411 spin_lock_irq(&ensoniq
->reg_lock
);
1412 ucontrol
->value
.integer
.value
[0] = ensoniq
->ctrl
& ES_1373_SPDIF_THRU
? 1 : 0;
1413 spin_unlock_irq(&ensoniq
->reg_lock
);
1417 static int snd_es1371_spdif_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1419 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1420 unsigned int nval1
, nval2
;
1423 nval1
= ucontrol
->value
.integer
.value
[0] ? ES_1373_SPDIF_THRU
: 0;
1424 nval2
= ucontrol
->value
.integer
.value
[0] ? ES_1373_SPDIF_EN
: 0;
1425 spin_lock_irq(&ensoniq
->reg_lock
);
1426 change
= (ensoniq
->ctrl
& ES_1373_SPDIF_THRU
) != nval1
;
1427 ensoniq
->ctrl
&= ~ES_1373_SPDIF_THRU
;
1428 ensoniq
->ctrl
|= nval1
;
1429 ensoniq
->cssr
&= ~ES_1373_SPDIF_EN
;
1430 ensoniq
->cssr
|= nval2
;
1431 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
1432 outl(ensoniq
->cssr
, ES_REG(ensoniq
, STATUS
));
1433 spin_unlock_irq(&ensoniq
->reg_lock
);
1438 /* spdif controls */
1439 static snd_kcontrol_new_t snd_es1371_mixer_spdif
[] __devinitdata
= {
1440 ES1371_SPDIF(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
)),
1442 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1443 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
1444 .info
= snd_ens1373_spdif_info
,
1445 .get
= snd_ens1373_spdif_default_get
,
1446 .put
= snd_ens1373_spdif_default_put
,
1449 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
1450 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1451 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
1452 .info
= snd_ens1373_spdif_info
,
1453 .get
= snd_ens1373_spdif_mask_get
1456 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1457 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
1458 .info
= snd_ens1373_spdif_info
,
1459 .get
= snd_ens1373_spdif_stream_get
,
1460 .put
= snd_ens1373_spdif_stream_put
1465 static int snd_es1373_rear_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
1467 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1469 uinfo
->value
.integer
.min
= 0;
1470 uinfo
->value
.integer
.max
= 1;
1474 static int snd_es1373_rear_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1476 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1479 spin_lock_irq(&ensoniq
->reg_lock
);
1480 if ((ensoniq
->cssr
& (ES_1373_REAR_BIT27
|ES_1373_REAR_BIT26
|ES_1373_REAR_BIT24
)) == ES_1373_REAR_BIT26
)
1482 ucontrol
->value
.integer
.value
[0] = val
;
1483 spin_unlock_irq(&ensoniq
->reg_lock
);
1487 static int snd_es1373_rear_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1489 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1493 nval1
= ucontrol
->value
.integer
.value
[0] ? ES_1373_REAR_BIT26
: (ES_1373_REAR_BIT27
|ES_1373_REAR_BIT24
);
1494 spin_lock_irq(&ensoniq
->reg_lock
);
1495 change
= (ensoniq
->cssr
& (ES_1373_REAR_BIT27
|ES_1373_REAR_BIT26
|ES_1373_REAR_BIT24
)) != nval1
;
1496 ensoniq
->cssr
&= ~(ES_1373_REAR_BIT27
|ES_1373_REAR_BIT26
|ES_1373_REAR_BIT24
);
1497 ensoniq
->cssr
|= nval1
;
1498 outl(ensoniq
->cssr
, ES_REG(ensoniq
, STATUS
));
1499 spin_unlock_irq(&ensoniq
->reg_lock
);
1503 static snd_kcontrol_new_t snd_ens1373_rear __devinitdata
=
1505 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1506 .name
= "AC97 2ch->4ch Copy Switch",
1507 .info
= snd_es1373_rear_info
,
1508 .get
= snd_es1373_rear_get
,
1509 .put
= snd_es1373_rear_put
,
1512 static int snd_es1373_line_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
1514 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1516 uinfo
->value
.integer
.min
= 0;
1517 uinfo
->value
.integer
.max
= 1;
1521 static int snd_es1373_line_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1523 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1526 spin_lock_irq(&ensoniq
->reg_lock
);
1527 if ((ensoniq
->ctrl
& ES_1371_GPIO_OUTM
) >= 4)
1529 ucontrol
->value
.integer
.value
[0] = val
;
1530 spin_unlock_irq(&ensoniq
->reg_lock
);
1534 static int snd_es1373_line_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1536 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1540 spin_lock_irq(&ensoniq
->reg_lock
);
1541 ctrl
= ensoniq
->ctrl
;
1542 if (ucontrol
->value
.integer
.value
[0])
1543 ensoniq
->ctrl
|= ES_1371_GPIO_OUT(4); /* switch line-in -> rear out */
1545 ensoniq
->ctrl
&= ~ES_1371_GPIO_OUT(4);
1546 changed
= (ctrl
!= ensoniq
->ctrl
);
1548 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
1549 spin_unlock_irq(&ensoniq
->reg_lock
);
1553 static snd_kcontrol_new_t snd_ens1373_line __devinitdata
=
1555 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1556 .name
= "Line In->Rear Out Switch",
1557 .info
= snd_es1373_line_info
,
1558 .get
= snd_es1373_line_get
,
1559 .put
= snd_es1373_line_put
,
1562 static void snd_ensoniq_mixer_free_ac97(ac97_t
*ac97
)
1564 ensoniq_t
*ensoniq
= ac97
->private_data
;
1565 ensoniq
->u
.es1371
.ac97
= NULL
;
1569 unsigned short vid
; /* vendor ID */
1570 unsigned short did
; /* device ID */
1571 unsigned char rev
; /* revision */
1572 } es1371_spdif_present
[] __devinitdata
= {
1573 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_CT5880
, .rev
= CT5880REV_CT5880_C
},
1574 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_CT5880
, .rev
= CT5880REV_CT5880_D
},
1575 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_CT5880
, .rev
= CT5880REV_CT5880_E
},
1576 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_ES1371
, .rev
= ES1371REV_CT5880_A
},
1577 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_ES1371
, .rev
= ES1371REV_ES1373_8
},
1578 { .vid
= PCI_ANY_ID
, .did
= PCI_ANY_ID
}
1581 static int snd_ensoniq_1371_mixer(ensoniq_t
* ensoniq
)
1583 snd_card_t
*card
= ensoniq
->card
;
1585 ac97_template_t ac97
;
1587 static ac97_bus_ops_t ops
= {
1588 .write
= snd_es1371_codec_write
,
1589 .read
= snd_es1371_codec_read
,
1590 .wait
= snd_es1371_codec_wait
,
1593 if ((err
= snd_ac97_bus(card
, 0, &ops
, NULL
, &pbus
)) < 0)
1596 memset(&ac97
, 0, sizeof(ac97
));
1597 ac97
.private_data
= ensoniq
;
1598 ac97
.private_free
= snd_ensoniq_mixer_free_ac97
;
1599 ac97
.scaps
= AC97_SCAP_AUDIO
;
1600 if ((err
= snd_ac97_mixer(pbus
, &ac97
, &ensoniq
->u
.es1371
.ac97
)) < 0)
1602 for (idx
= 0; es1371_spdif_present
[idx
].vid
!= (unsigned short)PCI_ANY_ID
; idx
++)
1603 if (ensoniq
->pci
->vendor
== es1371_spdif_present
[idx
].vid
&&
1604 ensoniq
->pci
->device
== es1371_spdif_present
[idx
].did
&&
1605 ensoniq
->rev
== es1371_spdif_present
[idx
].rev
) {
1606 snd_kcontrol_t
*kctl
;
1609 ensoniq
->spdif_default
= ensoniq
->spdif_stream
= SNDRV_PCM_DEFAULT_CON_SPDIF
;
1610 outl(ensoniq
->spdif_default
, ES_REG(ensoniq
, CHANNEL_STATUS
));
1612 if (ensoniq
->u
.es1371
.ac97
->ext_id
& AC97_EI_SPDIF
)
1615 for (i
= 0; i
< (int)ARRAY_SIZE(snd_es1371_mixer_spdif
); i
++) {
1616 kctl
= snd_ctl_new1(&snd_es1371_mixer_spdif
[i
], ensoniq
);
1619 kctl
->id
.index
= index
;
1620 if ((err
= snd_ctl_add(card
, kctl
)) < 0)
1625 if (ensoniq
->u
.es1371
.ac97
->ext_id
& AC97_EI_SDAC
) {
1626 /* mirror rear to front speakers */
1627 ensoniq
->cssr
&= ~(ES_1373_REAR_BIT27
|ES_1373_REAR_BIT24
);
1628 ensoniq
->cssr
|= ES_1373_REAR_BIT26
;
1629 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_ens1373_rear
, ensoniq
));
1633 if (((ensoniq
->subsystem_vendor_id
== 0x1274) &&
1634 (ensoniq
->subsystem_device_id
== 0x2000)) || /* GA-7DXR */
1635 ((ensoniq
->subsystem_vendor_id
== 0x1458) &&
1636 (ensoniq
->subsystem_device_id
== 0xa000))) { /* GA-8IEXP */
1637 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_ens1373_line
, ensoniq
));
1645 #endif /* CHIP1371 */
1647 /* generic control callbacks for ens1370 */
1649 #define ENSONIQ_CONTROL(xname, mask) \
1650 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, .name = xname, .info = snd_ensoniq_control_info, \
1651 .get = snd_ensoniq_control_get, .put = snd_ensoniq_control_put, \
1652 .private_value = mask }
1654 static int snd_ensoniq_control_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
1656 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1658 uinfo
->value
.integer
.min
= 0;
1659 uinfo
->value
.integer
.max
= 1;
1663 static int snd_ensoniq_control_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1665 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1666 int mask
= kcontrol
->private_value
;
1668 spin_lock_irq(&ensoniq
->reg_lock
);
1669 ucontrol
->value
.integer
.value
[0] = ensoniq
->ctrl
& mask
? 1 : 0;
1670 spin_unlock_irq(&ensoniq
->reg_lock
);
1674 static int snd_ensoniq_control_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1676 ensoniq_t
*ensoniq
= snd_kcontrol_chip(kcontrol
);
1677 int mask
= kcontrol
->private_value
;
1681 nval
= ucontrol
->value
.integer
.value
[0] ? mask
: 0;
1682 spin_lock_irq(&ensoniq
->reg_lock
);
1683 change
= (ensoniq
->ctrl
& mask
) != nval
;
1684 ensoniq
->ctrl
&= ~mask
;
1685 ensoniq
->ctrl
|= nval
;
1686 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
1687 spin_unlock_irq(&ensoniq
->reg_lock
);
1695 static snd_kcontrol_new_t snd_es1370_controls
[2] __devinitdata
= {
1696 ENSONIQ_CONTROL("PCM 0 Output also on Line-In Jack", ES_1370_XCTL0
),
1697 ENSONIQ_CONTROL("Mic +5V bias", ES_1370_XCTL1
)
1700 #define ES1370_CONTROLS ARRAY_SIZE(snd_es1370_controls)
1702 static void snd_ensoniq_mixer_free_ak4531(ak4531_t
*ak4531
)
1704 ensoniq_t
*ensoniq
= ak4531
->private_data
;
1705 ensoniq
->u
.es1370
.ak4531
= NULL
;
1708 static int __devinit
snd_ensoniq_1370_mixer(ensoniq_t
* ensoniq
)
1710 snd_card_t
*card
= ensoniq
->card
;
1715 /* try reset AK4531 */
1716 outw(ES_1370_CODEC_WRITE(AK4531_RESET
, 0x02), ES_REG(ensoniq
, 1370_CODEC
));
1717 inw(ES_REG(ensoniq
, 1370_CODEC
));
1719 outw(ES_1370_CODEC_WRITE(AK4531_RESET
, 0x03), ES_REG(ensoniq
, 1370_CODEC
));
1720 inw(ES_REG(ensoniq
, 1370_CODEC
));
1723 memset(&ak4531
, 0, sizeof(ak4531
));
1724 ak4531
.write
= snd_es1370_codec_write
;
1725 ak4531
.private_data
= ensoniq
;
1726 ak4531
.private_free
= snd_ensoniq_mixer_free_ak4531
;
1727 if ((err
= snd_ak4531_mixer(card
, &ak4531
, &ensoniq
->u
.es1370
.ak4531
)) < 0)
1729 for (idx
= 0; idx
< ES1370_CONTROLS
; idx
++) {
1730 err
= snd_ctl_add(card
, snd_ctl_new1(&snd_es1370_controls
[idx
], ensoniq
));
1737 #endif /* CHIP1370 */
1739 #ifdef SUPPORT_JOYSTICK
1742 static int __devinit
snd_ensoniq_get_joystick_port(int dev
)
1744 switch (joystick_port
[dev
]) {
1745 case 0: /* disabled */
1746 case 1: /* auto-detect */
1751 return joystick_port
[dev
];
1754 printk(KERN_ERR
"ens1371: invalid joystick port %#x", joystick_port
[dev
]);
1759 static inline int snd_ensoniq_get_joystick_port(int dev
)
1761 return joystick
[dev
] ? 0x200 : 0;
1765 static int __devinit
snd_ensoniq_create_gameport(ensoniq_t
*ensoniq
, int dev
)
1767 struct gameport
*gp
;
1770 io_port
= snd_ensoniq_get_joystick_port(dev
);
1776 case 1: /* auto_detect */
1777 for (io_port
= 0x200; io_port
<= 0x218; io_port
+= 8)
1778 if (request_region(io_port
, 8, "ens137x: gameport"))
1780 if (io_port
> 0x218) {
1781 printk(KERN_WARNING
"ens137x: no gameport ports available\n");
1787 if (!request_region(io_port
, 8, "ens137x: gameport")) {
1788 printk(KERN_WARNING
"ens137x: gameport io port 0x%#x in use\n", io_port
);
1794 ensoniq
->gameport
= gp
= gameport_allocate_port();
1796 printk(KERN_ERR
"ens137x: cannot allocate memory for gameport\n");
1797 release_region(io_port
, 8);
1801 gameport_set_name(gp
, "ES137x");
1802 gameport_set_phys(gp
, "pci%s/gameport0", pci_name(ensoniq
->pci
));
1803 gameport_set_dev_parent(gp
, &ensoniq
->pci
->dev
);
1806 ensoniq
->ctrl
|= ES_JYSTK_EN
;
1808 ensoniq
->ctrl
&= ~ES_1371_JOY_ASELM
;
1809 ensoniq
->ctrl
|= ES_1371_JOY_ASEL((io_port
- 0x200) / 8);
1811 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
1813 gameport_register_port(ensoniq
->gameport
);
1818 static void snd_ensoniq_free_gameport(ensoniq_t
*ensoniq
)
1820 if (ensoniq
->gameport
) {
1821 int port
= ensoniq
->gameport
->io
;
1823 gameport_unregister_port(ensoniq
->gameport
);
1824 ensoniq
->gameport
= NULL
;
1825 ensoniq
->ctrl
&= ~ES_JYSTK_EN
;
1826 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
1827 release_region(port
, 8);
1831 static inline int snd_ensoniq_create_gameport(ensoniq_t
*ensoniq
, long port
) { return -ENOSYS
; }
1832 static inline void snd_ensoniq_free_gameport(ensoniq_t
*ensoniq
) { }
1833 #endif /* SUPPORT_JOYSTICK */
1839 static void snd_ensoniq_proc_read(snd_info_entry_t
*entry
,
1840 snd_info_buffer_t
* buffer
)
1842 ensoniq_t
*ensoniq
= entry
->private_data
;
1845 snd_iprintf(buffer
, "Ensoniq AudioPCI ES1370\n\n");
1847 snd_iprintf(buffer
, "Ensoniq AudioPCI ES1371\n\n");
1849 snd_iprintf(buffer
, "Joystick enable : %s\n", ensoniq
->ctrl
& ES_JYSTK_EN
? "on" : "off");
1851 snd_iprintf(buffer
, "MIC +5V bias : %s\n", ensoniq
->ctrl
& ES_1370_XCTL1
? "on" : "off");
1852 snd_iprintf(buffer
, "Line In to AOUT : %s\n", ensoniq
->ctrl
& ES_1370_XCTL0
? "on" : "off");
1854 snd_iprintf(buffer
, "Joystick port : 0x%x\n", (ES_1371_JOY_ASELI(ensoniq
->ctrl
) * 8) + 0x200);
1858 static void __devinit
snd_ensoniq_proc_init(ensoniq_t
* ensoniq
)
1860 snd_info_entry_t
*entry
;
1862 if (! snd_card_proc_new(ensoniq
->card
, "audiopci", &entry
))
1863 snd_info_set_text_ops(entry
, ensoniq
, 1024, snd_ensoniq_proc_read
);
1870 static int snd_ensoniq_free(ensoniq_t
*ensoniq
)
1872 snd_ensoniq_free_gameport(ensoniq
);
1873 if (ensoniq
->irq
< 0)
1876 outl(ES_1370_SERR_DISABLE
, ES_REG(ensoniq
, CONTROL
)); /* switch everything off */
1877 outl(0, ES_REG(ensoniq
, SERIAL
)); /* clear serial interface */
1879 outl(0, ES_REG(ensoniq
, CONTROL
)); /* switch everything off */
1880 outl(0, ES_REG(ensoniq
, SERIAL
)); /* clear serial interface */
1882 synchronize_irq(ensoniq
->irq
);
1883 pci_set_power_state(ensoniq
->pci
, 3);
1886 if (ensoniq
->dma_bug
.area
)
1887 snd_dma_free_pages(&ensoniq
->dma_bug
);
1889 if (ensoniq
->irq
>= 0)
1890 free_irq(ensoniq
->irq
, (void *)ensoniq
);
1891 pci_release_regions(ensoniq
->pci
);
1892 pci_disable_device(ensoniq
->pci
);
1897 static int snd_ensoniq_dev_free(snd_device_t
*device
)
1899 ensoniq_t
*ensoniq
= device
->device_data
;
1900 return snd_ensoniq_free(ensoniq
);
1905 unsigned short svid
; /* subsystem vendor ID */
1906 unsigned short sdid
; /* subsystem device ID */
1907 } es1371_amplifier_hack
[] = {
1908 { .svid
= 0x107b, .sdid
= 0x2150 }, /* Gateway Solo 2150 */
1909 { .svid
= 0x13bd, .sdid
= 0x100c }, /* EV1938 on Mebius PC-MJ100V */
1910 { .svid
= 0x1102, .sdid
= 0x5938 }, /* Targa Xtender300 */
1911 { .svid
= 0x1102, .sdid
= 0x8938 }, /* IPC Topnote G notebook */
1912 { .svid
= PCI_ANY_ID
, .sdid
= PCI_ANY_ID
}
1915 unsigned short vid
; /* vendor ID */
1916 unsigned short did
; /* device ID */
1917 unsigned char rev
; /* revision */
1918 } es1371_ac97_reset_hack
[] = {
1919 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_CT5880
, .rev
= CT5880REV_CT5880_C
},
1920 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_CT5880
, .rev
= CT5880REV_CT5880_D
},
1921 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_CT5880
, .rev
= CT5880REV_CT5880_E
},
1922 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_ES1371
, .rev
= ES1371REV_CT5880_A
},
1923 { .vid
= PCI_VENDOR_ID_ENSONIQ
, .did
= PCI_DEVICE_ID_ENSONIQ_ES1371
, .rev
= ES1371REV_ES1373_8
},
1924 { .vid
= PCI_ANY_ID
, .did
= PCI_ANY_ID
}
1928 static int __devinit
snd_ensoniq_create(snd_card_t
* card
,
1929 struct pci_dev
*pci
,
1930 ensoniq_t
** rensoniq
)
1933 unsigned short cmdw
;
1939 static snd_device_ops_t ops
= {
1940 .dev_free
= snd_ensoniq_dev_free
,
1944 if ((err
= pci_enable_device(pci
)) < 0)
1946 ensoniq
= kzalloc(sizeof(*ensoniq
), GFP_KERNEL
);
1947 if (ensoniq
== NULL
) {
1948 pci_disable_device(pci
);
1951 spin_lock_init(&ensoniq
->reg_lock
);
1952 init_MUTEX(&ensoniq
->src_mutex
);
1953 ensoniq
->card
= card
;
1956 if ((err
= pci_request_regions(pci
, "Ensoniq AudioPCI")) < 0) {
1958 pci_disable_device(pci
);
1961 ensoniq
->port
= pci_resource_start(pci
, 0);
1962 if (request_irq(pci
->irq
, snd_audiopci_interrupt
, SA_INTERRUPT
|SA_SHIRQ
, "Ensoniq AudioPCI", (void *)ensoniq
)) {
1963 snd_printk("unable to grab IRQ %d\n", pci
->irq
);
1964 snd_ensoniq_free(ensoniq
);
1967 ensoniq
->irq
= pci
->irq
;
1969 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
1970 16, &ensoniq
->dma_bug
) < 0) {
1971 snd_printk("unable to allocate space for phantom area - dma_bug\n");
1972 snd_ensoniq_free(ensoniq
);
1976 pci_set_master(pci
);
1977 pci_read_config_byte(pci
, PCI_REVISION_ID
, &cmdb
);
1978 ensoniq
->rev
= cmdb
;
1979 pci_read_config_word(pci
, PCI_SUBSYSTEM_VENDOR_ID
, &cmdw
);
1980 ensoniq
->subsystem_vendor_id
= cmdw
;
1981 pci_read_config_word(pci
, PCI_SUBSYSTEM_ID
, &cmdw
);
1982 ensoniq
->subsystem_device_id
= cmdw
;
1985 ensoniq
->ctrl
= ES_1370_CDC_EN
| ES_1370_SERR_DISABLE
| ES_1370_PCLKDIVO(ES_1370_SRTODIV(8000));
1986 #else /* get microphone working */
1987 ensoniq
->ctrl
= ES_1370_CDC_EN
| ES_1370_PCLKDIVO(ES_1370_SRTODIV(8000));
1990 /* initialize the chips */
1991 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
1992 outl(ensoniq
->sctrl
, ES_REG(ensoniq
, SERIAL
));
1993 outl(ES_MEM_PAGEO(ES_PAGE_ADC
), ES_REG(ensoniq
, MEM_PAGE
));
1994 outl(ensoniq
->dma_bug
.addr
, ES_REG(ensoniq
, PHANTOM_FRAME
));
1995 outl(0, ES_REG(ensoniq
, PHANTOM_COUNT
));
2000 for (idx
= 0; es1371_amplifier_hack
[idx
].svid
!= (unsigned short)PCI_ANY_ID
; idx
++)
2001 if (ensoniq
->subsystem_vendor_id
== es1371_amplifier_hack
[idx
].svid
&&
2002 ensoniq
->subsystem_device_id
== es1371_amplifier_hack
[idx
].sdid
) {
2003 ensoniq
->ctrl
|= ES_1371_GPIO_OUT(1); /* turn amplifier on */
2006 /* initialize the chips */
2007 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
2008 outl(ensoniq
->sctrl
, ES_REG(ensoniq
, SERIAL
));
2009 outl(0, ES_REG(ensoniq
, 1371_LEGACY
));
2010 for (idx
= 0; es1371_ac97_reset_hack
[idx
].vid
!= (unsigned short)PCI_ANY_ID
; idx
++)
2011 if (pci
->vendor
== es1371_ac97_reset_hack
[idx
].vid
&&
2012 pci
->device
== es1371_ac97_reset_hack
[idx
].did
&&
2013 ensoniq
->rev
== es1371_ac97_reset_hack
[idx
].rev
) {
2014 ensoniq
->cssr
|= ES_1371_ST_AC97_RST
;
2015 outl(ensoniq
->cssr
, ES_REG(ensoniq
, STATUS
));
2016 /* need to delay around 20ms(bleech) to give
2017 some CODECs enough time to wakeup */
2021 /* AC'97 warm reset to start the bitclk */
2022 outl(ensoniq
->ctrl
| ES_1371_SYNC_RES
, ES_REG(ensoniq
, CONTROL
));
2023 inl(ES_REG(ensoniq
, CONTROL
));
2025 outl(ensoniq
->ctrl
, ES_REG(ensoniq
, CONTROL
));
2026 /* Init the sample rate converter */
2027 snd_es1371_wait_src_ready(ensoniq
);
2028 outl(ES_1371_SRC_DISABLE
, ES_REG(ensoniq
, 1371_SMPRATE
));
2029 for (idx
= 0; idx
< 0x80; idx
++)
2030 snd_es1371_src_write(ensoniq
, idx
, 0);
2031 snd_es1371_src_write(ensoniq
, ES_SMPREG_DAC1
+ ES_SMPREG_TRUNC_N
, 16 << 4);
2032 snd_es1371_src_write(ensoniq
, ES_SMPREG_DAC1
+ ES_SMPREG_INT_REGS
, 16 << 10);
2033 snd_es1371_src_write(ensoniq
, ES_SMPREG_DAC2
+ ES_SMPREG_TRUNC_N
, 16 << 4);
2034 snd_es1371_src_write(ensoniq
, ES_SMPREG_DAC2
+ ES_SMPREG_INT_REGS
, 16 << 10);
2035 snd_es1371_src_write(ensoniq
, ES_SMPREG_VOL_ADC
, 1 << 12);
2036 snd_es1371_src_write(ensoniq
, ES_SMPREG_VOL_ADC
+ 1, 1 << 12);
2037 snd_es1371_src_write(ensoniq
, ES_SMPREG_VOL_DAC1
, 1 << 12);
2038 snd_es1371_src_write(ensoniq
, ES_SMPREG_VOL_DAC1
+ 1, 1 << 12);
2039 snd_es1371_src_write(ensoniq
, ES_SMPREG_VOL_DAC2
, 1 << 12);
2040 snd_es1371_src_write(ensoniq
, ES_SMPREG_VOL_DAC2
+ 1, 1 << 12);
2041 snd_es1371_adc_rate(ensoniq
, 22050);
2042 snd_es1371_dac1_rate(ensoniq
, 22050);
2043 snd_es1371_dac2_rate(ensoniq
, 22050);
2045 * enabling the sample rate converter without properly programming
2046 * its parameters causes the chip to lock up (the SRC busy bit will
2047 * be stuck high, and I've found no way to rectify this other than
2048 * power cycle) - Thomas Sailer
2050 snd_es1371_wait_src_ready(ensoniq
);
2051 outl(0, ES_REG(ensoniq
, 1371_SMPRATE
));
2052 /* try reset codec directly */
2053 outl(ES_1371_CODEC_WRITE(0, 0), ES_REG(ensoniq
, 1371_CODEC
));
2055 outb(ensoniq
->uartc
= 0x00, ES_REG(ensoniq
, UART_CONTROL
));
2056 outb(0x00, ES_REG(ensoniq
, UART_RES
));
2057 outl(ensoniq
->cssr
, ES_REG(ensoniq
, STATUS
));
2058 synchronize_irq(ensoniq
->irq
);
2060 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, ensoniq
, &ops
)) < 0) {
2061 snd_ensoniq_free(ensoniq
);
2065 snd_ensoniq_proc_init(ensoniq
);
2067 snd_card_set_dev(card
, &pci
->dev
);
2069 *rensoniq
= ensoniq
;
2077 static void snd_ensoniq_midi_interrupt(ensoniq_t
* ensoniq
)
2079 snd_rawmidi_t
* rmidi
= ensoniq
->rmidi
;
2080 unsigned char status
, mask
, byte
;
2084 /* do Rx at first */
2085 spin_lock(&ensoniq
->reg_lock
);
2086 mask
= ensoniq
->uartm
& ES_MODE_INPUT
? ES_RXRDY
: 0;
2088 status
= inb(ES_REG(ensoniq
, UART_STATUS
));
2089 if ((status
& mask
) == 0)
2091 byte
= inb(ES_REG(ensoniq
, UART_DATA
));
2092 snd_rawmidi_receive(ensoniq
->midi_input
, &byte
, 1);
2094 spin_unlock(&ensoniq
->reg_lock
);
2096 /* do Tx at second */
2097 spin_lock(&ensoniq
->reg_lock
);
2098 mask
= ensoniq
->uartm
& ES_MODE_OUTPUT
? ES_TXRDY
: 0;
2100 status
= inb(ES_REG(ensoniq
, UART_STATUS
));
2101 if ((status
& mask
) == 0)
2103 if (snd_rawmidi_transmit(ensoniq
->midi_output
, &byte
, 1) != 1) {
2104 ensoniq
->uartc
&= ~ES_TXINTENM
;
2105 outb(ensoniq
->uartc
, ES_REG(ensoniq
, UART_CONTROL
));
2108 outb(byte
, ES_REG(ensoniq
, UART_DATA
));
2111 spin_unlock(&ensoniq
->reg_lock
);
2114 static int snd_ensoniq_midi_input_open(snd_rawmidi_substream_t
* substream
)
2116 ensoniq_t
*ensoniq
= substream
->rmidi
->private_data
;
2118 spin_lock_irq(&ensoniq
->reg_lock
);
2119 ensoniq
->uartm
|= ES_MODE_INPUT
;
2120 ensoniq
->midi_input
= substream
;
2121 if (!(ensoniq
->uartm
& ES_MODE_OUTPUT
)) {
2122 outb(ES_CNTRL(3), ES_REG(ensoniq
, UART_CONTROL
));
2123 outb(ensoniq
->uartc
= 0, ES_REG(ensoniq
, UART_CONTROL
));
2124 outl(ensoniq
->ctrl
|= ES_UART_EN
, ES_REG(ensoniq
, CONTROL
));
2126 spin_unlock_irq(&ensoniq
->reg_lock
);
2130 static int snd_ensoniq_midi_input_close(snd_rawmidi_substream_t
* substream
)
2132 ensoniq_t
*ensoniq
= substream
->rmidi
->private_data
;
2134 spin_lock_irq(&ensoniq
->reg_lock
);
2135 if (!(ensoniq
->uartm
& ES_MODE_OUTPUT
)) {
2136 outb(ensoniq
->uartc
= 0, ES_REG(ensoniq
, UART_CONTROL
));
2137 outl(ensoniq
->ctrl
&= ~ES_UART_EN
, ES_REG(ensoniq
, CONTROL
));
2139 outb(ensoniq
->uartc
&= ~ES_RXINTEN
, ES_REG(ensoniq
, UART_CONTROL
));
2141 ensoniq
->midi_input
= NULL
;
2142 ensoniq
->uartm
&= ~ES_MODE_INPUT
;
2143 spin_unlock_irq(&ensoniq
->reg_lock
);
2147 static int snd_ensoniq_midi_output_open(snd_rawmidi_substream_t
* substream
)
2149 ensoniq_t
*ensoniq
= substream
->rmidi
->private_data
;
2151 spin_lock_irq(&ensoniq
->reg_lock
);
2152 ensoniq
->uartm
|= ES_MODE_OUTPUT
;
2153 ensoniq
->midi_output
= substream
;
2154 if (!(ensoniq
->uartm
& ES_MODE_INPUT
)) {
2155 outb(ES_CNTRL(3), ES_REG(ensoniq
, UART_CONTROL
));
2156 outb(ensoniq
->uartc
= 0, ES_REG(ensoniq
, UART_CONTROL
));
2157 outl(ensoniq
->ctrl
|= ES_UART_EN
, ES_REG(ensoniq
, CONTROL
));
2159 spin_unlock_irq(&ensoniq
->reg_lock
);
2163 static int snd_ensoniq_midi_output_close(snd_rawmidi_substream_t
* substream
)
2165 ensoniq_t
*ensoniq
= substream
->rmidi
->private_data
;
2167 spin_lock_irq(&ensoniq
->reg_lock
);
2168 if (!(ensoniq
->uartm
& ES_MODE_INPUT
)) {
2169 outb(ensoniq
->uartc
= 0, ES_REG(ensoniq
, UART_CONTROL
));
2170 outl(ensoniq
->ctrl
&= ~ES_UART_EN
, ES_REG(ensoniq
, CONTROL
));
2172 outb(ensoniq
->uartc
&= ~ES_TXINTENM
, ES_REG(ensoniq
, UART_CONTROL
));
2174 ensoniq
->midi_output
= NULL
;
2175 ensoniq
->uartm
&= ~ES_MODE_OUTPUT
;
2176 spin_unlock_irq(&ensoniq
->reg_lock
);
2180 static void snd_ensoniq_midi_input_trigger(snd_rawmidi_substream_t
* substream
, int up
)
2182 unsigned long flags
;
2183 ensoniq_t
*ensoniq
= substream
->rmidi
->private_data
;
2186 spin_lock_irqsave(&ensoniq
->reg_lock
, flags
);
2188 if ((ensoniq
->uartc
& ES_RXINTEN
) == 0) {
2189 /* empty input FIFO */
2190 for (idx
= 0; idx
< 32; idx
++)
2191 inb(ES_REG(ensoniq
, UART_DATA
));
2192 ensoniq
->uartc
|= ES_RXINTEN
;
2193 outb(ensoniq
->uartc
, ES_REG(ensoniq
, UART_CONTROL
));
2196 if (ensoniq
->uartc
& ES_RXINTEN
) {
2197 ensoniq
->uartc
&= ~ES_RXINTEN
;
2198 outb(ensoniq
->uartc
, ES_REG(ensoniq
, UART_CONTROL
));
2201 spin_unlock_irqrestore(&ensoniq
->reg_lock
, flags
);
2204 static void snd_ensoniq_midi_output_trigger(snd_rawmidi_substream_t
* substream
, int up
)
2206 unsigned long flags
;
2207 ensoniq_t
*ensoniq
= substream
->rmidi
->private_data
;
2210 spin_lock_irqsave(&ensoniq
->reg_lock
, flags
);
2212 if (ES_TXINTENI(ensoniq
->uartc
) == 0) {
2213 ensoniq
->uartc
|= ES_TXINTENO(1);
2214 /* fill UART FIFO buffer at first, and turn Tx interrupts only if necessary */
2215 while (ES_TXINTENI(ensoniq
->uartc
) == 1 &&
2216 (inb(ES_REG(ensoniq
, UART_STATUS
)) & ES_TXRDY
)) {
2217 if (snd_rawmidi_transmit(substream
, &byte
, 1) != 1) {
2218 ensoniq
->uartc
&= ~ES_TXINTENM
;
2220 outb(byte
, ES_REG(ensoniq
, UART_DATA
));
2223 outb(ensoniq
->uartc
, ES_REG(ensoniq
, UART_CONTROL
));
2226 if (ES_TXINTENI(ensoniq
->uartc
) == 1) {
2227 ensoniq
->uartc
&= ~ES_TXINTENM
;
2228 outb(ensoniq
->uartc
, ES_REG(ensoniq
, UART_CONTROL
));
2231 spin_unlock_irqrestore(&ensoniq
->reg_lock
, flags
);
2234 static snd_rawmidi_ops_t snd_ensoniq_midi_output
=
2236 .open
= snd_ensoniq_midi_output_open
,
2237 .close
= snd_ensoniq_midi_output_close
,
2238 .trigger
= snd_ensoniq_midi_output_trigger
,
2241 static snd_rawmidi_ops_t snd_ensoniq_midi_input
=
2243 .open
= snd_ensoniq_midi_input_open
,
2244 .close
= snd_ensoniq_midi_input_close
,
2245 .trigger
= snd_ensoniq_midi_input_trigger
,
2248 static int __devinit
snd_ensoniq_midi(ensoniq_t
* ensoniq
, int device
, snd_rawmidi_t
**rrawmidi
)
2250 snd_rawmidi_t
*rmidi
;
2255 if ((err
= snd_rawmidi_new(ensoniq
->card
, "ES1370/1", device
, 1, 1, &rmidi
)) < 0)
2258 strcpy(rmidi
->name
, "ES1370");
2260 strcpy(rmidi
->name
, "ES1371");
2262 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_OUTPUT
, &snd_ensoniq_midi_output
);
2263 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_INPUT
, &snd_ensoniq_midi_input
);
2264 rmidi
->info_flags
|= SNDRV_RAWMIDI_INFO_OUTPUT
| SNDRV_RAWMIDI_INFO_INPUT
| SNDRV_RAWMIDI_INFO_DUPLEX
;
2265 rmidi
->private_data
= ensoniq
;
2266 ensoniq
->rmidi
= rmidi
;
2276 static irqreturn_t
snd_audiopci_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
2278 ensoniq_t
*ensoniq
= dev_id
;
2279 unsigned int status
, sctrl
;
2281 if (ensoniq
== NULL
)
2284 status
= inl(ES_REG(ensoniq
, STATUS
));
2285 if (!(status
& ES_INTR
))
2288 spin_lock(&ensoniq
->reg_lock
);
2289 sctrl
= ensoniq
->sctrl
;
2290 if (status
& ES_DAC1
)
2291 sctrl
&= ~ES_P1_INT_EN
;
2292 if (status
& ES_DAC2
)
2293 sctrl
&= ~ES_P2_INT_EN
;
2294 if (status
& ES_ADC
)
2295 sctrl
&= ~ES_R1_INT_EN
;
2296 outl(sctrl
, ES_REG(ensoniq
, SERIAL
));
2297 outl(ensoniq
->sctrl
, ES_REG(ensoniq
, SERIAL
));
2298 spin_unlock(&ensoniq
->reg_lock
);
2300 if (status
& ES_UART
)
2301 snd_ensoniq_midi_interrupt(ensoniq
);
2302 if ((status
& ES_DAC2
) && ensoniq
->playback2_substream
)
2303 snd_pcm_period_elapsed(ensoniq
->playback2_substream
);
2304 if ((status
& ES_ADC
) && ensoniq
->capture_substream
)
2305 snd_pcm_period_elapsed(ensoniq
->capture_substream
);
2306 if ((status
& ES_DAC1
) && ensoniq
->playback1_substream
)
2307 snd_pcm_period_elapsed(ensoniq
->playback1_substream
);
2311 static int __devinit
snd_audiopci_probe(struct pci_dev
*pci
,
2312 const struct pci_device_id
*pci_id
)
2317 int err
, pcm_devs
[2];
2319 if (dev
>= SNDRV_CARDS
)
2326 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
2330 if ((err
= snd_ensoniq_create(card
, pci
, &ensoniq
)) < 0) {
2331 snd_card_free(card
);
2335 pcm_devs
[0] = 0; pcm_devs
[1] = 1;
2337 if ((err
= snd_ensoniq_1370_mixer(ensoniq
)) < 0) {
2338 snd_card_free(card
);
2343 if ((err
= snd_ensoniq_1371_mixer(ensoniq
)) < 0) {
2344 snd_card_free(card
);
2348 if ((err
= snd_ensoniq_pcm(ensoniq
, 0, NULL
)) < 0) {
2349 snd_card_free(card
);
2352 if ((err
= snd_ensoniq_pcm2(ensoniq
, 1, NULL
)) < 0) {
2353 snd_card_free(card
);
2356 if ((err
= snd_ensoniq_midi(ensoniq
, 0, NULL
)) < 0) {
2357 snd_card_free(card
);
2361 snd_ensoniq_create_gameport(ensoniq
, dev
);
2363 strcpy(card
->driver
, DRIVER_NAME
);
2365 strcpy(card
->shortname
, "Ensoniq AudioPCI");
2366 sprintf(card
->longname
, "%s %s at 0x%lx, irq %i",
2372 if ((err
= snd_card_register(card
)) < 0) {
2373 snd_card_free(card
);
2377 pci_set_drvdata(pci
, card
);
2382 static void __devexit
snd_audiopci_remove(struct pci_dev
*pci
)
2384 snd_card_free(pci_get_drvdata(pci
));
2385 pci_set_drvdata(pci
, NULL
);
2388 static struct pci_driver driver
= {
2389 .name
= DRIVER_NAME
,
2390 .owner
= THIS_MODULE
,
2391 .id_table
= snd_audiopci_ids
,
2392 .probe
= snd_audiopci_probe
,
2393 .remove
= __devexit_p(snd_audiopci_remove
),
2396 static int __init
alsa_card_ens137x_init(void)
2398 return pci_register_driver(&driver
);
2401 static void __exit
alsa_card_ens137x_exit(void)
2403 pci_unregister_driver(&driver
);
2406 module_init(alsa_card_ens137x_init
)
2407 module_exit(alsa_card_ens137x_exit
)