33 #include <linux/pci.h>
34 #include <linux/slab.h>
35 #include <linux/gameport.h>
36 #include <linux/module.h>
57 #define DRIVER_NAME "ENS1370"
58 #define CHIP_NAME "ES1370"
60 #define DRIVER_NAME "ENS1371"
61 #define CHIP_NAME "ES1371"
70 "{Creative Labs,SB PCI64/128 (ES1370)}}");
75 "{Ensoniq,AudioPCI ES1373},"
76 "{Creative Labs,Ectiva EV1938},"
77 "{Creative Labs,SB PCI64/128 (ES1371/73)},"
78 "{Creative Labs,Vibra PCI128},"
82 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
83 #define SUPPORT_JOYSTICK
89 #ifdef SUPPORT_JOYSTICK
107 #ifdef SUPPORT_JOYSTICK
129 #define ES1371REV_ES1373_A 0x04
130 #define ES1371REV_ES1373_B 0x06
131 #define ES1371REV_CT5880_A 0x07
132 #define CT5880REV_CT5880_C 0x02
133 #define CT5880REV_CT5880_D 0x03
134 #define CT5880REV_CT5880_E 0x04
135 #define ES1371REV_ES1371_B 0x09
136 #define EV1938REV_EV1938_A 0x00
137 #define ES1371REV_ES1373_8 0x08
143 #define ES_REG(ensoniq, x) ((ensoniq)->port + ES_REG_##x)
145 #define ES_REG_CONTROL 0x00
146 #define ES_1370_ADC_STOP (1<<31)
147 #define ES_1370_XCTL1 (1<<30)
148 #define ES_1373_BYPASS_P1 (1<<31)
149 #define ES_1373_BYPASS_P2 (1<<30)
150 #define ES_1373_BYPASS_R (1<<29)
151 #define ES_1373_TEST_BIT (1<<28)
152 #define ES_1373_RECEN_B (1<<27)
153 #define ES_1373_SPDIF_THRU (1<<26)
154 #define ES_1371_JOY_ASEL(o) (((o)&0x03)<<24)
155 #define ES_1371_JOY_ASELM (0x03<<24)
156 #define ES_1371_JOY_ASELI(i) (((i)>>24)&0x03)
157 #define ES_1371_GPIO_IN(i) (((i)>>20)&0x0f)
158 #define ES_1370_PCLKDIVO(o) (((o)&0x1fff)<<16)
159 #define ES_1370_PCLKDIVM ((0x1fff)<<16)
160 #define ES_1370_PCLKDIVI(i) (((i)>>16)&0x1fff)
161 #define ES_1371_GPIO_OUT(o) (((o)&0x0f)<<16)
162 #define ES_1371_GPIO_OUTM (0x0f<<16)
163 #define ES_MSFMTSEL (1<<15)
164 #define ES_1370_M_SBB (1<<14)
165 #define ES_1371_SYNC_RES (1<<14)
166 #define ES_1370_WTSRSEL(o) (((o)&0x03)<<12)
167 #define ES_1370_WTSRSELM (0x03<<12)
168 #define ES_1371_ADC_STOP (1<<13)
169 #define ES_1371_PWR_INTRM (1<<12)
170 #define ES_1370_DAC_SYNC (1<<11)
171 #define ES_1371_M_CB (1<<11)
172 #define ES_CCB_INTRM (1<<10)
173 #define ES_1370_M_CB (1<<9)
174 #define ES_1370_XCTL0 (1<<8)
175 #define ES_1371_PDLEV(o) (((o)&0x03)<<8)
176 #define ES_1371_PDLEVM (0x03<<8)
177 #define ES_BREQ (1<<7)
178 #define ES_DAC1_EN (1<<6)
179 #define ES_DAC2_EN (1<<5)
180 #define ES_ADC_EN (1<<4)
181 #define ES_UART_EN (1<<3)
182 #define ES_JYSTK_EN (1<<2)
183 #define ES_1370_CDC_EN (1<<1)
184 #define ES_1371_XTALCKDIS (1<<1)
185 #define ES_1370_SERR_DISABLE (1<<0)
186 #define ES_1371_PCICLKDIS (1<<0)
187 #define ES_REG_STATUS 0x04
188 #define ES_INTR (1<<31)
189 #define ES_1371_ST_AC97_RST (1<<29)
190 #define ES_1373_REAR_BIT27 (1<<27)
191 #define ES_1373_REAR_BIT26 (1<<26)
192 #define ES_1373_REAR_BIT24 (1<<24)
193 #define ES_1373_GPIO_INT_EN(o)(((o)&0x0f)<<20)
194 #define ES_1373_SPDIF_EN (1<<18)
195 #define ES_1373_SPDIF_TEST (1<<17)
196 #define ES_1371_TEST (1<<16)
197 #define ES_1373_GPIO_INT(i) (((i)&0x0f)>>12)
198 #define ES_1370_CSTAT (1<<10)
199 #define ES_1370_CBUSY (1<<9)
200 #define ES_1370_CWRIP (1<<8)
201 #define ES_1371_SYNC_ERR (1<<8)
202 #define ES_1371_VC(i) (((i)>>6)&0x03)
203 #define ES_1370_VC(i) (((i)>>5)&0x03)
204 #define ES_1371_MPWR (1<<5)
205 #define ES_MCCB (1<<4)
206 #define ES_UART (1<<3)
207 #define ES_DAC1 (1<<2)
208 #define ES_DAC2 (1<<1)
209 #define ES_ADC (1<<0)
210 #define ES_REG_UART_DATA 0x08
211 #define ES_REG_UART_STATUS 0x09
212 #define ES_RXINT (1<<7)
213 #define ES_TXINT (1<<2)
214 #define ES_TXRDY (1<<1)
215 #define ES_RXRDY (1<<0)
216 #define ES_REG_UART_CONTROL 0x09
217 #define ES_RXINTEN (1<<7)
218 #define ES_TXINTENO(o) (((o)&0x03)<<5)
219 #define ES_TXINTENM (0x03<<5)
220 #define ES_TXINTENI(i) (((i)>>5)&0x03)
221 #define ES_CNTRL(o) (((o)&0x03)<<0)
222 #define ES_CNTRLM (0x03<<0)
223 #define ES_REG_UART_RES 0x0a
224 #define ES_TEST_MODE (1<<0)
225 #define ES_REG_MEM_PAGE 0x0c
226 #define ES_MEM_PAGEO(o) (((o)&0x0f)<<0)
227 #define ES_MEM_PAGEM (0x0f<<0)
228 #define ES_MEM_PAGEI(i) (((i)>>0)&0x0f)
229 #define ES_REG_1370_CODEC 0x10
230 #define ES_1370_CODEC_WRITE(a,d) ((((a)&0xff)<<8)|(((d)&0xff)<<0))
231 #define ES_REG_1371_CODEC 0x14
232 #define ES_1371_CODEC_RDY (1<<31)
233 #define ES_1371_CODEC_WIP (1<<30)
234 #define EV_1938_CODEC_MAGIC (1<<26)
235 #define ES_1371_CODEC_PIRD (1<<23)
236 #define ES_1371_CODEC_WRITE(a,d) ((((a)&0x7f)<<16)|(((d)&0xffff)<<0))
237 #define ES_1371_CODEC_READS(a) ((((a)&0x7f)<<16)|ES_1371_CODEC_PIRD)
238 #define ES_1371_CODEC_READ(i) (((i)>>0)&0xffff)
240 #define ES_REG_1371_SMPRATE 0x10
241 #define ES_1371_SRC_RAM_ADDRO(o) (((o)&0x7f)<<25)
242 #define ES_1371_SRC_RAM_ADDRM (0x7f<<25)
243 #define ES_1371_SRC_RAM_ADDRI(i) (((i)>>25)&0x7f)
244 #define ES_1371_SRC_RAM_WE (1<<24)
245 #define ES_1371_SRC_RAM_BUSY (1<<23)
246 #define ES_1371_SRC_DISABLE (1<<22)
247 #define ES_1371_DIS_P1 (1<<21)
248 #define ES_1371_DIS_P2 (1<<20)
249 #define ES_1371_DIS_R1 (1<<19)
250 #define ES_1371_SRC_RAM_DATAO(o) (((o)&0xffff)<<0)
251 #define ES_1371_SRC_RAM_DATAM (0xffff<<0)
252 #define ES_1371_SRC_RAM_DATAI(i) (((i)>>0)&0xffff)
254 #define ES_REG_1371_LEGACY 0x18
255 #define ES_1371_JFAST (1<<31)
256 #define ES_1371_HIB (1<<30)
257 #define ES_1371_VSB (1<<29)
258 #define ES_1371_VMPUO(o) (((o)&0x03)<<27)
259 #define ES_1371_VMPUM (0x03<<27)
260 #define ES_1371_VMPUI(i) (((i)>>27)&0x03)
261 #define ES_1371_VCDCO(o) (((o)&0x03)<<25)
262 #define ES_1371_VCDCM (0x03<<25)
263 #define ES_1371_VCDCI(i) (((i)>>25)&0x03)
264 #define ES_1371_FIRQ (1<<24)
265 #define ES_1371_SDMACAP (1<<23)
266 #define ES_1371_SPICAP (1<<22)
267 #define ES_1371_MDMACAP (1<<21)
268 #define ES_1371_MPICAP (1<<20)
269 #define ES_1371_ADCAP (1<<19)
270 #define ES_1371_SVCAP (1<<18)
271 #define ES_1371_CDCCAP (1<<17)
272 #define ES_1371_BACAP (1<<16)
273 #define ES_1371_EXI(i) (((i)>>8)&0x07)
274 #define ES_1371_AI(i) (((i)>>3)&0x1f)
275 #define ES_1371_WR (1<<2)
276 #define ES_1371_LEGINT (1<<0)
278 #define ES_REG_CHANNEL_STATUS 0x1c
280 #define ES_REG_SERIAL 0x20
281 #define ES_1371_DAC_TEST (1<<22)
282 #define ES_P2_END_INCO(o) (((o)&0x07)<<19)
283 #define ES_P2_END_INCM (0x07<<19)
284 #define ES_P2_END_INCI(i) (((i)>>16)&0x07)
285 #define ES_P2_ST_INCO(o) (((o)&0x07)<<16)
286 #define ES_P2_ST_INCM (0x07<<16)
287 #define ES_P2_ST_INCI(i) (((i)<<16)&0x07)
288 #define ES_R1_LOOP_SEL (1<<15)
289 #define ES_P2_LOOP_SEL (1<<14)
290 #define ES_P1_LOOP_SEL (1<<13)
291 #define ES_P2_PAUSE (1<<12)
292 #define ES_P1_PAUSE (1<<11)
293 #define ES_R1_INT_EN (1<<10)
294 #define ES_P2_INT_EN (1<<9)
295 #define ES_P1_INT_EN (1<<8)
296 #define ES_P1_SCT_RLD (1<<7)
297 #define ES_P2_DAC_SEN (1<<6)
298 #define ES_R1_MODEO(o) (((o)&0x03)<<4)
299 #define ES_R1_MODEM (0x03<<4)
300 #define ES_R1_MODEI(i) (((i)>>4)&0x03)
301 #define ES_P2_MODEO(o) (((o)&0x03)<<2)
302 #define ES_P2_MODEM (0x03<<2)
303 #define ES_P2_MODEI(i) (((i)>>2)&0x03)
304 #define ES_P1_MODEO(o) (((o)&0x03)<<0)
305 #define ES_P1_MODEM (0x03<<0)
306 #define ES_P1_MODEI(i) (((i)>>0)&0x03)
308 #define ES_REG_DAC1_COUNT 0x24
309 #define ES_REG_DAC2_COUNT 0x28
310 #define ES_REG_ADC_COUNT 0x2c
311 #define ES_REG_CURR_COUNT(i) (((i)>>16)&0xffff)
312 #define ES_REG_COUNTO(o) (((o)&0xffff)<<0)
313 #define ES_REG_COUNTM (0xffff<<0)
314 #define ES_REG_COUNTI(i) (((i)>>0)&0xffff)
316 #define ES_REG_DAC1_FRAME 0x30
317 #define ES_REG_DAC1_SIZE 0x34
318 #define ES_REG_DAC2_FRAME 0x38
319 #define ES_REG_DAC2_SIZE 0x3c
320 #define ES_REG_ADC_FRAME 0x30
321 #define ES_REG_ADC_SIZE 0x34
322 #define ES_REG_FCURR_COUNTO(o) (((o)&0xffff)<<16)
323 #define ES_REG_FCURR_COUNTM (0xffff<<16)
324 #define ES_REG_FCURR_COUNTI(i) (((i)>>14)&0x3fffc)
325 #define ES_REG_FSIZEO(o) (((o)&0xffff)<<0)
326 #define ES_REG_FSIZEM (0xffff<<0)
327 #define ES_REG_FSIZEI(i) (((i)>>0)&0xffff)
328 #define ES_REG_PHANTOM_FRAME 0x38
329 #define ES_REG_PHANTOM_COUNT 0x3c
331 #define ES_REG_UART_FIFO 0x30
332 #define ES_REG_UF_VALID (1<<8)
333 #define ES_REG_UF_BYTEO(o) (((o)&0xff)<<0)
334 #define ES_REG_UF_BYTEM (0xff<<0)
335 #define ES_REG_UF_BYTEI(i) (((i)>>0)&0xff)
342 #define ES_PAGE_DAC 0x0c
343 #define ES_PAGE_ADC 0x0d
344 #define ES_PAGE_UART 0x0e
345 #define ES_PAGE_UART1 0x0f
351 #define ES_SMPREG_DAC1 0x70
352 #define ES_SMPREG_DAC2 0x74
353 #define ES_SMPREG_ADC 0x78
354 #define ES_SMPREG_VOL_ADC 0x6c
355 #define ES_SMPREG_VOL_DAC1 0x7c
356 #define ES_SMPREG_VOL_DAC2 0x7e
357 #define ES_SMPREG_TRUNC_N 0x00
358 #define ES_SMPREG_INT_REGS 0x01
359 #define ES_SMPREG_ACCUM_FRAC 0x02
360 #define ES_SMPREG_VFREQ_FRAC 0x03
366 #define ES_1370_SRCLOCK 1411200
367 #define ES_1370_SRTODIV(x) (ES_1370_SRCLOCK/(x)-2)
373 #define ES_MODE_PLAY1 0x0001
374 #define ES_MODE_PLAY2 0x0002
375 #define ES_MODE_CAPTURE 0x0004
377 #define ES_MODE_OUTPUT 0x0001
378 #define ES_MODE_INPUT 0x0002
442 #ifdef SUPPORT_JOYSTICK
467 #define POLL_COUNT 0xa000
470 static unsigned int snd_es1370_fixed_rates[] =
471 {5512, 11025, 22050, 44100};
474 .list = snd_es1370_fixed_rates,
485 .rats = &es1370_clock,
496 .rats = &es1371_dac_clock,
506 .rats = &es1371_adc_clock,
509 static const unsigned int snd_ensoniq_sample_shift[] =
518 static unsigned int snd_es1371_wait_src_ready(
struct ensoniq *
ensoniq)
520 unsigned int t,
r = 0;
529 ES_REG(ensoniq, 1371_SMPRATE), r);
533 static unsigned int snd_es1371_src_read(
struct ensoniq * ensoniq,
unsigned short reg)
535 unsigned int temp,
i, orig,
r;
538 temp = orig = snd_es1371_wait_src_ready(ensoniq);
547 temp = snd_es1371_wait_src_ready(ensoniq);
549 if ((temp & 0x00870000) != 0x00010000) {
552 temp =
inl(
ES_REG(ensoniq, 1371_SMPRATE));
553 if ((temp & 0x00870000) == 0x00010000)
567 static void snd_es1371_src_write(
struct ensoniq * ensoniq,
568 unsigned short reg,
unsigned short data)
572 r = snd_es1371_wait_src_ready(ensoniq) &
583 static void snd_es1370_codec_write(
struct snd_ak4531 *ak4531,
584 unsigned short reg,
unsigned short val)
587 unsigned long end_time =
jiffies +
HZ / 10;
591 "CODEC WRITE: reg = 0x%x, val = 0x%x (0x%x), creg = 0x%x\n",
609 static inline bool is_ev1938(
struct ensoniq *ensoniq)
611 return ensoniq->
pci->device == 0x8938;
614 static void snd_es1371_codec_write(
struct snd_ac97 *ac97,
615 unsigned short reg,
unsigned short val)
625 x = snd_es1371_wait_src_ready(ensoniq);
628 ES_REG(ensoniq, 1371_SMPRATE));
632 if ((
inl(
ES_REG(ensoniq, 1371_SMPRATE)) & 0x00870000) ==
638 if ((
inl(
ES_REG(ensoniq, 1371_SMPRATE)) & 0x00870000) ==
643 ES_REG(ensoniq, 1371_CODEC));
645 snd_es1371_wait_src_ready(ensoniq);
656 static unsigned short snd_es1371_codec_read(
struct snd_ac97 *ac97,
660 unsigned int t,
x,
flag, fail = 0;
666 if (!(
inl(
ES_REG(ensoniq, 1371_CODEC)) & ES_1371_CODEC_WIP)) {
668 x = snd_es1371_wait_src_ready(ensoniq);
671 ES_REG(ensoniq, 1371_SMPRATE));
675 if ((
inl(
ES_REG(ensoniq, 1371_SMPRATE)) & 0x00870000) ==
681 if ((
inl(
ES_REG(ensoniq, 1371_SMPRATE)) & 0x00870000) ==
686 ES_REG(ensoniq, 1371_CODEC));
688 snd_es1371_wait_src_ready(ensoniq);
692 if (!(
inl(
ES_REG(ensoniq, 1371_CODEC)) & ES_1371_CODEC_WIP))
698 if (is_ev1938(ensoniq)) {
699 for (t = 0; t < 100; t++)
710 "at 0x%lx, reg = 0x%x [0x%x]\n",
711 ES_REG(ensoniq, 1371_CODEC), reg,
724 static void snd_es1371_codec_wait(
struct snd_ac97 *ac97)
733 static void snd_es1371_adc_rate(
struct ensoniq * ensoniq,
unsigned int rate)
739 if ((1 << n) & ((1 << 15) | (1 << 13) | (1 << 11) | (1 << 9)))
741 truncm = (21 * n - 1) | 1;
742 freq = ((48000
UL << 15) / rate) *
n;
743 result = (48000
UL << 15) / (freq / n);
748 (((239 - truncm) >> 1) << 9) | (n << 4));
753 0x8000 | (((119 - truncm) >> 1) << 9) | (n << 4));
758 ((freq >> 5) & 0xfc00));
765 static void snd_es1371_dac1_rate(
struct ensoniq * ensoniq,
unsigned int rate)
767 unsigned int freq,
r;
770 freq = ((rate << 15) + 1500) / 3000;
778 ((freq >> 5) & 0xfc00));
786 static void snd_es1371_dac2_rate(
struct ensoniq * ensoniq,
unsigned int rate)
788 unsigned int freq,
r;
791 freq = ((rate << 15) + 1500) / 3000;
799 ((freq >> 5) & 0xfc00));
817 unsigned int what = 0;
822 snd_pcm_trigger_done(s, substream);
825 snd_pcm_trigger_done(s, substream);
833 ensoniq->
sctrl &= ~what;
841 unsigned int what = 0;
846 snd_pcm_trigger_done(s, substream);
849 snd_pcm_trigger_done(s, substream);
852 snd_pcm_trigger_done(s, substream);
859 ensoniq->
ctrl &= ~what;
889 unsigned int mode = 0;
891 ensoniq->
p1_dma_size = snd_pcm_lib_buffer_bytes(substream);
901 if (runtime->
rate == 48000)
914 ES_REG(ensoniq, DAC1_COUNT));
917 switch (runtime->
rate) {
926 spin_unlock_irq(&ensoniq->
reg_lock);
928 snd_es1371_dac1_rate(ensoniq, runtime->
rate);
937 unsigned int mode = 0;
939 ensoniq->
p2_dma_size = snd_pcm_lib_buffer_bytes(substream);
957 ES_REG(ensoniq, DAC2_COUNT));
966 spin_unlock_irq(&ensoniq->
reg_lock);
968 snd_es1371_dac2_rate(ensoniq, runtime->
rate);
977 unsigned int mode = 0;
979 ensoniq->
c_dma_size = snd_pcm_lib_buffer_bytes(substream);
980 ensoniq->
c_period_size = snd_pcm_lib_period_bytes(substream);
995 ES_REG(ensoniq, ADC_COUNT));
1004 spin_unlock_irq(&ensoniq->
reg_lock);
1006 snd_es1371_adc_rate(ensoniq, runtime->
rate);
1020 ptr = bytes_to_frames(substream->
runtime, ptr);
1037 ptr = bytes_to_frames(substream->
runtime, ptr);
1054 ptr = bytes_to_frames(substream->
runtime, ptr);
1081 .buffer_bytes_max = (128*1024),
1085 .periods_max = 1024,
1102 .period_bytes_min = 64,
1103 .period_bytes_max = (128*1024),
1121 .period_bytes_min = 64,
1122 .period_bytes_max = (128*1024),
1135 runtime->
hw = snd_ensoniq_playback1;
1140 spin_unlock_irq(&ensoniq->
reg_lock);
1143 &snd_es1370_hw_constraints_rates);
1146 &snd_es1371_hw_constraints_dac_clock);
1158 runtime->
hw = snd_ensoniq_playback2;
1163 spin_unlock_irq(&ensoniq->
reg_lock);
1166 &snd_es1370_hw_constraints_clock);
1169 &snd_es1371_hw_constraints_dac_clock);
1181 runtime->
hw = snd_ensoniq_capture;
1185 &snd_es1370_hw_constraints_clock);
1188 &snd_es1371_hw_constraints_adc_clock);
1212 spin_unlock_irq(&ensoniq->
reg_lock);
1226 spin_unlock_irq(&ensoniq->
reg_lock);
1230 static struct snd_pcm_ops snd_ensoniq_playback1_ops = {
1231 .open = snd_ensoniq_playback1_open,
1232 .close = snd_ensoniq_playback1_close,
1234 .hw_params = snd_ensoniq_hw_params,
1235 .hw_free = snd_ensoniq_hw_free,
1236 .prepare = snd_ensoniq_playback1_prepare,
1237 .trigger = snd_ensoniq_trigger,
1238 .pointer = snd_ensoniq_playback1_pointer,
1241 static struct snd_pcm_ops snd_ensoniq_playback2_ops = {
1242 .open = snd_ensoniq_playback2_open,
1243 .close = snd_ensoniq_playback2_close,
1245 .hw_params = snd_ensoniq_hw_params,
1246 .hw_free = snd_ensoniq_hw_free,
1247 .prepare = snd_ensoniq_playback2_prepare,
1248 .trigger = snd_ensoniq_trigger,
1249 .pointer = snd_ensoniq_playback2_pointer,
1252 static struct snd_pcm_ops snd_ensoniq_capture_ops = {
1253 .open = snd_ensoniq_capture_open,
1254 .close = snd_ensoniq_capture_close,
1256 .hw_params = snd_ensoniq_hw_params,
1257 .hw_free = snd_ensoniq_hw_free,
1258 .prepare = snd_ensoniq_capture_prepare,
1259 .trigger = snd_ensoniq_trigger,
1260 .pointer = snd_ensoniq_capture_pointer,
1271 static int __devinit snd_ensoniq_pcm(
struct ensoniq * ensoniq,
int device,
1293 ensoniq->
pcm1 = pcm;
1300 surround_map, 2, 0,
NULL);
1313 static int __devinit snd_ensoniq_pcm2(
struct ensoniq * ensoniq,
int device,
1333 ensoniq->
pcm2 = pcm;
1343 surround_map, 2, 0,
NULL);
1361 static int snd_ens1373_spdif_info(
struct snd_kcontrol *kcontrol,
1369 static int snd_ens1373_spdif_default_get(
struct snd_kcontrol *kcontrol,
1378 spin_unlock_irq(&ensoniq->
reg_lock);
1382 static int snd_ens1373_spdif_default_put(
struct snd_kcontrol *kcontrol,
1389 val = ((
u32)ucontrol->
value.iec958.status[0] << 0) |
1390 ((
u32)ucontrol->
value.iec958.status[1] << 8) |
1391 ((
u32)ucontrol->
value.iec958.status[2] << 16) |
1392 ((
u32)ucontrol->
value.iec958.status[3] << 24);
1399 spin_unlock_irq(&ensoniq->
reg_lock);
1403 static int snd_ens1373_spdif_mask_get(
struct snd_kcontrol *kcontrol,
1406 ucontrol->
value.iec958.status[0] = 0xff;
1407 ucontrol->
value.iec958.status[1] = 0xff;
1408 ucontrol->
value.iec958.status[2] = 0xff;
1409 ucontrol->
value.iec958.status[3] = 0xff;
1413 static int snd_ens1373_spdif_stream_get(
struct snd_kcontrol *kcontrol,
1422 spin_unlock_irq(&ensoniq->
reg_lock);
1426 static int snd_ens1373_spdif_stream_put(
struct snd_kcontrol *kcontrol,
1433 val = ((
u32)ucontrol->
value.iec958.status[0] << 0) |
1434 ((
u32)ucontrol->
value.iec958.status[1] << 8) |
1435 ((
u32)ucontrol->
value.iec958.status[2] << 16) |
1436 ((
u32)ucontrol->
value.iec958.status[3] << 24);
1443 spin_unlock_irq(&ensoniq->
reg_lock);
1447 #define ES1371_SPDIF(xname) \
1448 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_es1371_spdif_info, \
1449 .get = snd_es1371_spdif_get, .put = snd_es1371_spdif_put }
1451 #define snd_es1371_spdif_info snd_ctl_boolean_mono_info
1453 static int snd_es1371_spdif_get(
struct snd_kcontrol *kcontrol,
1460 spin_unlock_irq(&ensoniq->
reg_lock);
1464 static int snd_es1371_spdif_put(
struct snd_kcontrol *kcontrol,
1468 unsigned int nval1, nval2;
1476 ensoniq->
ctrl |= nval1;
1478 ensoniq->
cssr |= nval2;
1481 spin_unlock_irq(&ensoniq->
reg_lock);
1492 .info = snd_ens1373_spdif_info,
1493 .get = snd_ens1373_spdif_default_get,
1494 .put = snd_ens1373_spdif_default_put,
1500 .info = snd_ens1373_spdif_info,
1501 .get = snd_ens1373_spdif_mask_get
1506 .info = snd_ens1373_spdif_info,
1507 .get = snd_ens1373_spdif_stream_get,
1508 .put = snd_ens1373_spdif_stream_put
1513 #define snd_es1373_rear_info snd_ctl_boolean_mono_info
1515 static int snd_es1373_rear_get(
struct snd_kcontrol *kcontrol,
1525 ucontrol->
value.integer.value[0] =
val;
1526 spin_unlock_irq(&ensoniq->
reg_lock);
1530 static int snd_es1373_rear_put(
struct snd_kcontrol *kcontrol,
1537 nval1 = ucontrol->
value.integer.value[0] ?
1543 ensoniq->
cssr |= nval1;
1545 spin_unlock_irq(&ensoniq->
reg_lock);
1552 .name =
"AC97 2ch->4ch Copy Switch",
1553 .info = snd_es1373_rear_info,
1554 .get = snd_es1373_rear_get,
1555 .put = snd_es1373_rear_put,
1558 #define snd_es1373_line_info snd_ctl_boolean_mono_info
1560 static int snd_es1373_line_get(
struct snd_kcontrol *kcontrol,
1569 ucontrol->
value.integer.value[0] =
val;
1570 spin_unlock_irq(&ensoniq->
reg_lock);
1574 static int snd_es1373_line_put(
struct snd_kcontrol *kcontrol,
1582 ctrl = ensoniq->
ctrl;
1583 if (ucontrol->
value.integer.value[0])
1587 changed = (ctrl != ensoniq->
ctrl);
1590 spin_unlock_irq(&ensoniq->
reg_lock);
1597 .name =
"Line In->Rear Out Switch",
1598 .info = snd_es1373_line_info,
1599 .get = snd_es1373_line_get,
1600 .put = snd_es1373_line_put,
1603 static void snd_ensoniq_mixer_free_ac97(
struct snd_ac97 *ac97)
1606 ensoniq->
u.es1371.ac97 =
NULL;
1609 struct es1371_quirk {
1615 static int es1371_quirk_lookup(
struct ensoniq *ensoniq,
1616 struct es1371_quirk *
list)
1618 while (list->vid != (
unsigned short)
PCI_ANY_ID) {
1619 if (ensoniq->
pci->vendor == list->vid &&
1620 ensoniq->
pci->device == list->did &&
1621 ensoniq->
rev == list->rev)
1628 static struct es1371_quirk es1371_spdif_present[] __devinitdata = {
1637 static struct snd_pci_quirk ens1373_line_quirk[] __devinitdata = {
1638 SND_PCI_QUIRK_ID(0x1274, 0x2000),
1639 SND_PCI_QUIRK_ID(0x1458, 0xa000),
1643 static int __devinit snd_ensoniq_1371_mixer(
struct ensoniq *ensoniq,
1644 int has_spdif,
int has_line)
1651 .write = snd_es1371_codec_write,
1652 .read = snd_es1371_codec_read,
1653 .wait = snd_es1371_codec_wait,
1659 memset(&ac97, 0,
sizeof(ac97));
1666 if (has_spdif > 0 ||
1667 (!has_spdif && es1371_quirk_lookup(ensoniq, es1371_spdif_present))) {
1669 int i, is_spdif = 0;
1678 for (i = 0; i <
ARRAY_SIZE(snd_es1371_mixer_spdif); i++) {
1679 kctl =
snd_ctl_new1(&snd_es1371_mixer_spdif[i], ensoniq);
1682 kctl->
id.index = is_spdif;
1697 snd_pci_quirk_lookup(ensoniq->
pci, ens1373_line_quirk)) {
1711 #define ENSONIQ_CONTROL(xname, mask) \
1712 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, .name = xname, .info = snd_ensoniq_control_info, \
1713 .get = snd_ensoniq_control_get, .put = snd_ensoniq_control_put, \
1714 .private_value = mask }
1716 #define snd_ensoniq_control_info snd_ctl_boolean_mono_info
1718 static int snd_ensoniq_control_get(
struct snd_kcontrol *kcontrol,
1725 ucontrol->
value.integer.value[0] = ensoniq->
ctrl & mask ? 1 : 0;
1726 spin_unlock_irq(&ensoniq->
reg_lock);
1730 static int snd_ensoniq_control_put(
struct snd_kcontrol *kcontrol,
1738 nval = ucontrol->
value.integer.value[0] ? mask : 0;
1740 change = (ensoniq->
ctrl &
mask) != nval;
1741 ensoniq->
ctrl &= ~mask;
1742 ensoniq->
ctrl |= nval;
1744 spin_unlock_irq(&ensoniq->
reg_lock);
1757 #define ES1370_CONTROLS ARRAY_SIZE(snd_es1370_controls)
1759 static void snd_ensoniq_mixer_free_ak4531(
struct snd_ak4531 *ak4531)
1765 static int __devinit snd_ensoniq_1370_mixer(
struct ensoniq * ensoniq)
1780 memset(&ak4531, 0,
sizeof(ak4531));
1781 ak4531.
write = snd_es1370_codec_write;
1796 #ifdef SUPPORT_JOYSTICK
1799 static int __devinit snd_ensoniq_get_joystick_port(
int dev)
1801 switch (joystick_port[dev]) {
1808 return joystick_port[
dev];
1811 printk(
KERN_ERR "ens1371: invalid joystick port %#x", joystick_port[dev]);
1816 static inline int snd_ensoniq_get_joystick_port(
int dev)
1818 return joystick[
dev] ? 0x200 : 0;
1822 static int __devinit snd_ensoniq_create_gameport(
struct ensoniq *ensoniq,
int dev)
1827 io_port = snd_ensoniq_get_joystick_port(dev);
1834 for (io_port = 0x200; io_port <= 0x218; io_port += 8)
1837 if (io_port > 0x218) {
1852 ensoniq->gameport = gp = gameport_allocate_port();
1854 printk(
KERN_ERR "ens137x: cannot allocate memory for gameport\n");
1859 gameport_set_name(gp,
"ES137x");
1861 gameport_set_dev_parent(gp, &ensoniq->
pci->dev);
1871 gameport_register_port(ensoniq->gameport);
1876 static void snd_ensoniq_free_gameport(
struct ensoniq *ensoniq)
1878 if (ensoniq->gameport) {
1879 int port = ensoniq->gameport->io;
1882 ensoniq->gameport =
NULL;
1889 static inline int snd_ensoniq_create_gameport(
struct ensoniq *ensoniq,
long port) {
return -
ENOSYS; }
1890 static inline void snd_ensoniq_free_gameport(
struct ensoniq *ensoniq) { }
1902 snd_iprintf(buffer,
"Ensoniq AudioPCI " CHIP_NAME "\n\n");
1903 snd_iprintf(buffer,
"Joystick enable : %s\n",
1906 snd_iprintf(buffer,
"MIC +5V bias : %s\n",
1908 snd_iprintf(buffer,
"Line In to AOUT : %s\n",
1911 snd_iprintf(buffer,
"Joystick port : 0x%x\n",
1916 static void __devinit snd_ensoniq_proc_init(
struct ensoniq * ensoniq)
1920 if (! snd_card_proc_new(ensoniq->
card,
"audiopci", &entry))
1921 snd_info_set_text_ops(entry, ensoniq, snd_ensoniq_proc_read);
1928 static int snd_ensoniq_free(
struct ensoniq *ensoniq)
1930 snd_ensoniq_free_gameport(ensoniq);
1931 if (ensoniq->
irq < 0)
1940 if (ensoniq->
irq >= 0)
1948 if (ensoniq->
irq >= 0)
1956 static int snd_ensoniq_dev_free(
struct snd_device *device)
1959 return snd_ensoniq_free(ensoniq);
1963 static struct snd_pci_quirk es1371_amplifier_hack[] __devinitdata = {
1964 SND_PCI_QUIRK_ID(0x107b, 0x2150),
1965 SND_PCI_QUIRK_ID(0x13bd, 0x100c),
1966 SND_PCI_QUIRK_ID(0x1102, 0x5938),
1967 SND_PCI_QUIRK_ID(0x1102, 0x8938),
1971 static struct es1371_quirk es1371_ac97_reset_hack[] = {
1981 static void snd_ensoniq_chip_init(
struct ensoniq *ensoniq)
1999 if (es1371_quirk_lookup(ensoniq, es1371_ac97_reset_hack)) {
2011 snd_es1371_wait_src_ready(ensoniq);
2013 for (idx = 0; idx < 0x80; idx++)
2014 snd_es1371_src_write(ensoniq, idx, 0);
2025 snd_es1371_adc_rate(ensoniq, 22050);
2026 snd_es1371_dac1_rate(ensoniq, 22050);
2027 snd_es1371_dac2_rate(ensoniq, 22050);
2034 snd_es1371_wait_src_ready(ensoniq);
2045 #ifdef CONFIG_PM_SLEEP
2046 static int snd_ensoniq_suspend(
struct device *dev)
2054 snd_pcm_suspend_all(ensoniq->
pcm1);
2055 snd_pcm_suspend_all(ensoniq->
pcm2);
2058 snd_ac97_suspend(ensoniq->
u.es1371.ac97);
2067 snd_ak4531_suspend(ensoniq->
u.
es1370.ak4531);
2076 static int snd_ensoniq_resume(
struct device *dev)
2086 "disabling device\n");
2092 snd_ensoniq_chip_init(ensoniq);
2095 snd_ac97_resume(ensoniq->
u.es1371.ac97);
2097 snd_ak4531_resume(ensoniq->
u.
es1370.ak4531);
2103 static SIMPLE_DEV_PM_OPS(snd_ensoniq_pm, snd_ensoniq_suspend, snd_ensoniq_resume);
2104 #define SND_ENSONIQ_PM_OPS &snd_ensoniq_pm
2106 #define SND_ENSONIQ_PM_OPS NULL
2111 struct ensoniq ** rensoniq)
2113 struct ensoniq *ensoniq;
2122 ensoniq = kzalloc(
sizeof(*ensoniq),
GFP_KERNEL);
2123 if (ensoniq ==
NULL) {
2139 KBUILD_MODNAME, ensoniq)) {
2141 snd_ensoniq_free(ensoniq);
2149 snd_ensoniq_free(ensoniq);
2167 if (snd_pci_quirk_lookup(pci, es1371_amplifier_hack))
2170 if (es1371_quirk_lookup(ensoniq, es1371_ac97_reset_hack))
2174 snd_ensoniq_chip_init(ensoniq);
2177 snd_ensoniq_free(ensoniq);
2181 snd_ensoniq_proc_init(ensoniq);
2185 *rensoniq = ensoniq;
2193 static void snd_ensoniq_midi_interrupt(
struct ensoniq * ensoniq)
2204 status =
inb(
ES_REG(ensoniq, UART_STATUS));
2205 if ((status & mask) == 0)
2216 status =
inb(
ES_REG(ensoniq, UART_STATUS));
2217 if ((status & mask) == 0)
2232 struct ensoniq *ensoniq = substream->
rmidi->private_data;
2242 spin_unlock_irq(&ensoniq->
reg_lock);
2248 struct ensoniq *ensoniq = substream->
rmidi->private_data;
2259 spin_unlock_irq(&ensoniq->
reg_lock);
2265 struct ensoniq *ensoniq = substream->
rmidi->private_data;
2275 spin_unlock_irq(&ensoniq->
reg_lock);
2281 struct ensoniq *ensoniq = substream->
rmidi->private_data;
2292 spin_unlock_irq(&ensoniq->
reg_lock);
2298 unsigned long flags;
2299 struct ensoniq *ensoniq = substream->
rmidi->private_data;
2306 for (idx = 0; idx < 32; idx++)
2317 spin_unlock_irqrestore(&ensoniq->
reg_lock, flags);
2322 unsigned long flags;
2323 struct ensoniq *ensoniq = substream->
rmidi->private_data;
2347 spin_unlock_irqrestore(&ensoniq->
reg_lock, flags);
2352 .open = snd_ensoniq_midi_output_open,
2353 .close = snd_ensoniq_midi_output_close,
2354 .trigger = snd_ensoniq_midi_output_trigger,
2359 .open = snd_ensoniq_midi_input_open,
2360 .close = snd_ensoniq_midi_input_close,
2361 .trigger = snd_ensoniq_midi_input_trigger,
2364 static int __devinit snd_ensoniq_midi(
struct ensoniq * ensoniq,
int device,
2380 ensoniq->
rmidi = rmidi;
2392 struct ensoniq *ensoniq =
dev_id;
2395 if (ensoniq ==
NULL)
2403 sctrl = ensoniq->
sctrl;
2415 snd_ensoniq_midi_interrupt(ensoniq);
2430 struct ensoniq *ensoniq;
2431 int err, pcm_devs[2];
2444 if ((err = snd_ensoniq_create(card, pci, &ensoniq)) < 0) {
2450 pcm_devs[0] = 0; pcm_devs[1] = 1;
2452 if ((err = snd_ensoniq_1370_mixer(ensoniq)) < 0) {
2458 if ((err = snd_ensoniq_1371_mixer(ensoniq,
spdif[dev], lineio[dev])) < 0) {
2463 if ((err = snd_ensoniq_pcm(ensoniq, 0,
NULL)) < 0) {
2467 if ((err = snd_ensoniq_pcm2(ensoniq, 1,
NULL)) < 0) {
2471 if ((err = snd_ensoniq_midi(ensoniq, 0,
NULL)) < 0) {
2476 snd_ensoniq_create_gameport(ensoniq, dev);
2492 pci_set_drvdata(pci, card);
2500 pci_set_drvdata(pci,
NULL);
2504 .name = KBUILD_MODNAME,
2505 .id_table = snd_audiopci_ids,
2506 .probe = snd_audiopci_probe,