1 /*****************************************************************************/
4 * es1371.c -- Creative Ensoniq ES1371.
6 * Copyright (C) 1998-2001, 2003 Thomas Sailer (t.sailer@alumni.ethz.ch)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Special thanks to Ensoniq
25 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
26 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
27 * /dev/dsp1 additional DAC, like /dev/dsp, but outputs to mixer "SYNTH" setting
28 * /dev/midi simple MIDI UART interface, no ioctl
30 * NOTE: the card does not have any FM/Wavetable synthesizer, it is supposed
31 * to be done in software. That is what /dev/dac is for. By now (Q2 1998)
32 * there are several MIDI to PCM (WAV) packages, one of them is timidity.
35 * 04.06.1998 0.1 Initial release
36 * Mixer stuff should be overhauled; especially optional AC97 mixer bits
37 * should be detected. This results in strange behaviour of some mixer
38 * settings, like master volume and mic.
39 * 08.06.1998 0.2 First release using Alan Cox' soundcore instead of miscdevice
40 * 03.08.1998 0.3 Do not include modversions.h
41 * Now mixer behaviour can basically be selected between
42 * "OSS documented" and "OSS actual" behaviour
43 * 31.08.1998 0.4 Fix realplayer problems - dac.count issues
44 * 27.10.1998 0.5 Fix joystick support
45 * -- Oliver Neukum (c188@org.chemie.uni-muenchen.de)
46 * 10.12.1998 0.6 Fix drain_dac trying to wait on not yet initialized DMA
47 * 23.12.1998 0.7 Fix a few f_file & FMODE_ bugs
48 * Don't wake up app until there are fragsize bytes to read/write
49 * 06.01.1999 0.8 remove the silly SA_INTERRUPT flag.
50 * hopefully killed the egcs section type conflict
51 * 12.03.1999 0.9 cinfo.blocks should be reset after GETxPTR ioctl.
52 * reported by Johan Maes <joma@telindus.be>
53 * 22.03.1999 0.10 return EAGAIN instead of EBUSY when O_NONBLOCK
54 * read/write cannot be executed
55 * 07.04.1999 0.11 implemented the following ioctl's: SOUND_PCM_READ_RATE,
56 * SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
57 * Alpha fixes reported by Peter Jones <pjones@redhat.com>
58 * Another Alpha fix (wait_src_ready in init routine)
59 * reported by "Ivan N. Kokshaysky" <ink@jurassic.park.msu.ru>
60 * Note: joystick address handling might still be wrong on archs
62 * 15.06.1999 0.12 Fix bad allocation bug.
63 * Thanks to Deti Fliegl <fliegl@in.tum.de>
64 * 28.06.1999 0.13 Add pci_set_master
65 * 03.08.1999 0.14 adapt to Linus' new __setup/__initcall
66 * added kernel command line option "es1371=joystickaddr"
67 * removed CONFIG_SOUND_ES1371_JOYPORT_BOOT kludge
68 * 10.08.1999 0.15 (Re)added S/PDIF module option for cards revision >= 4.
69 * Initial version by Dave Platt <dplatt@snulbug.mtview.ca.us>.
70 * module_init/__setup fixes
71 * 08.16.1999 0.16 Joe Cotellese <joec@ensoniq.com>
72 * Added detection for ES1371 revision ID so that we can
73 * detect the ES1373 and later parts.
74 * added AC97 #defines for readability
75 * added a /proc file system for dumping hardware state
76 * updated SRC and CODEC w/r functions to accommodate bugs
77 * in some versions of the ES137x chips.
78 * 31.08.1999 0.17 add spin_lock_init
79 * replaced current->state = x with set_current_state(x)
80 * 03.09.1999 0.18 change read semantics for MIDI to match
81 * OSS more closely; remove possible wakeup race
82 * 21.10.1999 0.19 Round sampling rates, requested by
83 * Kasamatsu Kenichi <t29w0267@ip.media.kyoto-u.ac.jp>
84 * 27.10.1999 0.20 Added SigmaTel 3D enhancement string
85 * Codec ID printing changes
86 * 28.10.1999 0.21 More waitqueue races fixed
87 * Joe Cotellese <joec@ensoniq.com>
88 * Changed PCI detection routine so we can more easily
89 * detect ES137x chip and derivatives.
90 * 05.01.2000 0.22 Should now work with rev7 boards; patch by
91 * Eric Lemar, elemar@cs.washington.edu
92 * 08.01.2000 0.23 Prevent some ioctl's from returning bad count values on underrun/overrun;
93 * Tim Janik's BSE (Bedevilled Sound Engine) found this
94 * 07.02.2000 0.24 Use pci_alloc_consistent and pci_register_driver
95 * 07.02.2000 0.25 Use ac97_codec
96 * 01.03.2000 0.26 SPDIF patch by Mikael Bouillot <mikael.bouillot@bigfoot.com>
98 * 21.11.2000 0.27 Initialize dma buffers in poll, otherwise poll may return a bogus mask
99 * 12.12.2000 0.28 More dma buffer initializations, patch from
100 * Tjeerd Mulder <tjeerd.mulder@fujitsu-siemens.com>
101 * 05.01.2001 0.29 Hopefully updates will not be required anymore when Creative bumps
102 * the CT5880 revision.
103 * suggested by Stephan Müller <smueller@chronox.de>
104 * 31.01.2001 0.30 Register/Unregister gameport
105 * Fix SETTRIGGER non OSS API conformity
106 * 14.07.2001 0.31 Add list of laptops needing amplifier control
107 * 03.01.2003 0.32 open_mode fixes from Georg Acher <acher@in.tum.de>
110 /*****************************************************************************/
112 #include <linux/interrupt.h>
113 #include <linux/module.h>
114 #include <linux/string.h>
115 #include <linux/ioport.h>
116 #include <linux/sched.h>
117 #include <linux/delay.h>
118 #include <linux/sound.h>
119 #include <linux/slab.h>
120 #include <linux/soundcard.h>
121 #include <linux/pci.h>
122 #include <linux/init.h>
123 #include <linux/poll.h>
124 #include <linux/bitops.h>
125 #include <linux/proc_fs.h>
126 #include <linux/spinlock.h>
127 #include <linux/smp_lock.h>
128 #include <linux/ac97_codec.h>
129 #include <linux/gameport.h>
130 #include <linux/wait.h>
133 #include <asm/page.h>
134 #include <asm/uaccess.h>
136 /* --------------------------------------------------------------------- */
138 #undef OSS_DOCUMENTED_MIXER_SEMANTICS
141 /*#define DBG(x) {x}*/
143 /* --------------------------------------------------------------------- */
145 #ifndef PCI_VENDOR_ID_ENSONIQ
146 #define PCI_VENDOR_ID_ENSONIQ 0x1274
149 #ifndef PCI_VENDOR_ID_ECTIVA
150 #define PCI_VENDOR_ID_ECTIVA 0x1102
153 #ifndef PCI_DEVICE_ID_ENSONIQ_ES1371
154 #define PCI_DEVICE_ID_ENSONIQ_ES1371 0x1371
157 #ifndef PCI_DEVICE_ID_ENSONIQ_CT5880
158 #define PCI_DEVICE_ID_ENSONIQ_CT5880 0x5880
161 #ifndef PCI_DEVICE_ID_ECTIVA_EV1938
162 #define PCI_DEVICE_ID_ECTIVA_EV1938 0x8938
166 /* This is a little confusing because all ES1371 compatible chips have the
167 same DEVICE_ID, the only thing differentiating them is the REV_ID field.
168 This is only significant if you want to enable features on the later parts.
169 Yes, I know it's stupid and why didn't we use the sub IDs?
171 #define ES1371REV_ES1373_A 0x04
172 #define ES1371REV_ES1373_B 0x06
173 #define ES1371REV_CT5880_A 0x07
174 #define CT5880REV_CT5880_C 0x02
175 #define CT5880REV_CT5880_D 0x03
176 #define ES1371REV_ES1371_B 0x09
177 #define EV1938REV_EV1938_A 0x00
178 #define ES1371REV_ES1373_8 0x08
180 #define ES1371_MAGIC ((PCI_VENDOR_ID_ENSONIQ<<16)|PCI_DEVICE_ID_ENSONIQ_ES1371)
182 #define ES1371_EXTENT 0x40
185 #define ES1371_REG_CONTROL 0x00
186 #define ES1371_REG_STATUS 0x04 /* on the 5880 it is control/status */
187 #define ES1371_REG_UART_DATA 0x08
188 #define ES1371_REG_UART_STATUS 0x09
189 #define ES1371_REG_UART_CONTROL 0x09
190 #define ES1371_REG_UART_TEST 0x0a
191 #define ES1371_REG_MEMPAGE 0x0c
192 #define ES1371_REG_SRCONV 0x10
193 #define ES1371_REG_CODEC 0x14
194 #define ES1371_REG_LEGACY 0x18
195 #define ES1371_REG_SERIAL_CONTROL 0x20
196 #define ES1371_REG_DAC1_SCOUNT 0x24
197 #define ES1371_REG_DAC2_SCOUNT 0x28
198 #define ES1371_REG_ADC_SCOUNT 0x2c
200 #define ES1371_REG_DAC1_FRAMEADR 0xc30
201 #define ES1371_REG_DAC1_FRAMECNT 0xc34
202 #define ES1371_REG_DAC2_FRAMEADR 0xc38
203 #define ES1371_REG_DAC2_FRAMECNT 0xc3c
204 #define ES1371_REG_ADC_FRAMEADR 0xd30
205 #define ES1371_REG_ADC_FRAMECNT 0xd34
207 #define ES1371_FMT_U8_MONO 0
208 #define ES1371_FMT_U8_STEREO 1
209 #define ES1371_FMT_S16_MONO 2
210 #define ES1371_FMT_S16_STEREO 3
211 #define ES1371_FMT_STEREO 1
212 #define ES1371_FMT_S16 2
213 #define ES1371_FMT_MASK 3
215 static const unsigned sample_size
[] = { 1, 2, 2, 4 };
216 static const unsigned sample_shift
[] = { 0, 1, 1, 2 };
218 #define CTRL_RECEN_B 0x08000000 /* 1 = don't mix analog in to digital out */
219 #define CTRL_SPDIFEN_B 0x04000000
220 #define CTRL_JOY_SHIFT 24
221 #define CTRL_JOY_MASK 3
222 #define CTRL_JOY_200 0x00000000 /* joystick base address */
223 #define CTRL_JOY_208 0x01000000
224 #define CTRL_JOY_210 0x02000000
225 #define CTRL_JOY_218 0x03000000
226 #define CTRL_GPIO_IN0 0x00100000 /* general purpose inputs/outputs */
227 #define CTRL_GPIO_IN1 0x00200000
228 #define CTRL_GPIO_IN2 0x00400000
229 #define CTRL_GPIO_IN3 0x00800000
230 #define CTRL_GPIO_OUT0 0x00010000
231 #define CTRL_GPIO_OUT1 0x00020000
232 #define CTRL_GPIO_OUT2 0x00040000
233 #define CTRL_GPIO_OUT3 0x00080000
234 #define CTRL_MSFMTSEL 0x00008000 /* MPEG serial data fmt: 0 = Sony, 1 = I2S */
235 #define CTRL_SYNCRES 0x00004000 /* AC97 warm reset */
236 #define CTRL_ADCSTOP 0x00002000 /* stop ADC transfers */
237 #define CTRL_PWR_INTRM 0x00001000 /* 1 = power level ints enabled */
238 #define CTRL_M_CB 0x00000800 /* recording source: 0 = ADC, 1 = MPEG */
239 #define CTRL_CCB_INTRM 0x00000400 /* 1 = CCB "voice" ints enabled */
240 #define CTRL_PDLEV0 0x00000000 /* power down level */
241 #define CTRL_PDLEV1 0x00000100
242 #define CTRL_PDLEV2 0x00000200
243 #define CTRL_PDLEV3 0x00000300
244 #define CTRL_BREQ 0x00000080 /* 1 = test mode (internal mem test) */
245 #define CTRL_DAC1_EN 0x00000040 /* enable DAC1 */
246 #define CTRL_DAC2_EN 0x00000020 /* enable DAC2 */
247 #define CTRL_ADC_EN 0x00000010 /* enable ADC */
248 #define CTRL_UART_EN 0x00000008 /* enable MIDI uart */
249 #define CTRL_JYSTK_EN 0x00000004 /* enable Joystick port */
250 #define CTRL_XTALCLKDIS 0x00000002 /* 1 = disable crystal clock input */
251 #define CTRL_PCICLKDIS 0x00000001 /* 1 = disable PCI clock distribution */
254 #define STAT_INTR 0x80000000 /* wired or of all interrupt bits */
255 #define CSTAT_5880_AC97_RST 0x20000000 /* CT5880 Reset bit */
256 #define STAT_EN_SPDIF 0x00040000 /* enable S/PDIF circuitry */
257 #define STAT_TS_SPDIF 0x00020000 /* test S/PDIF circuitry */
258 #define STAT_TESTMODE 0x00010000 /* test ASIC */
259 #define STAT_SYNC_ERR 0x00000100 /* 1 = codec sync error */
260 #define STAT_VC 0x000000c0 /* CCB int source, 0=DAC1, 1=DAC2, 2=ADC, 3=undef */
262 #define STAT_MPWR 0x00000020 /* power level interrupt */
263 #define STAT_MCCB 0x00000010 /* CCB int pending */
264 #define STAT_UART 0x00000008 /* UART int pending */
265 #define STAT_DAC1 0x00000004 /* DAC1 int pending */
266 #define STAT_DAC2 0x00000002 /* DAC2 int pending */
267 #define STAT_ADC 0x00000001 /* ADC int pending */
269 #define USTAT_RXINT 0x80 /* UART rx int pending */
270 #define USTAT_TXINT 0x04 /* UART tx int pending */
271 #define USTAT_TXRDY 0x02 /* UART tx ready */
272 #define USTAT_RXRDY 0x01 /* UART rx ready */
274 #define UCTRL_RXINTEN 0x80 /* 1 = enable RX ints */
275 #define UCTRL_TXINTEN 0x60 /* TX int enable field mask */
276 #define UCTRL_ENA_TXINT 0x20 /* enable TX int */
277 #define UCTRL_CNTRL 0x03 /* control field */
278 #define UCTRL_CNTRL_SWR 0x03 /* software reset command */
280 /* sample rate converter */
281 #define SRC_OKSTATE 1
283 #define SRC_RAMADDR_MASK 0xfe000000
284 #define SRC_RAMADDR_SHIFT 25
285 #define SRC_DAC1FREEZE (1UL << 21)
286 #define SRC_DAC2FREEZE (1UL << 20)
287 #define SRC_ADCFREEZE (1UL << 19)
290 #define SRC_WE 0x01000000 /* read/write control for SRC RAM */
291 #define SRC_BUSY 0x00800000 /* SRC busy */
292 #define SRC_DIS 0x00400000 /* 1 = disable SRC */
293 #define SRC_DDAC1 0x00200000 /* 1 = disable accum update for DAC1 */
294 #define SRC_DDAC2 0x00100000 /* 1 = disable accum update for DAC2 */
295 #define SRC_DADC 0x00080000 /* 1 = disable accum update for ADC2 */
296 #define SRC_CTLMASK 0x00780000
297 #define SRC_RAMDATA_MASK 0x0000ffff
298 #define SRC_RAMDATA_SHIFT 0
300 #define SRCREG_ADC 0x78
301 #define SRCREG_DAC1 0x70
302 #define SRCREG_DAC2 0x74
303 #define SRCREG_VOL_ADC 0x6c
304 #define SRCREG_VOL_DAC1 0x7c
305 #define SRCREG_VOL_DAC2 0x7e
307 #define SRCREG_TRUNC_N 0x00
308 #define SRCREG_INT_REGS 0x01
309 #define SRCREG_ACCUM_FRAC 0x02
310 #define SRCREG_VFREQ_FRAC 0x03
312 #define CODEC_PIRD 0x00800000 /* 0 = write AC97 register */
313 #define CODEC_PIADD_MASK 0x007f0000
314 #define CODEC_PIADD_SHIFT 16
315 #define CODEC_PIDAT_MASK 0x0000ffff
316 #define CODEC_PIDAT_SHIFT 0
318 #define CODEC_RDY 0x80000000 /* AC97 read data valid */
319 #define CODEC_WIP 0x40000000 /* AC97 write in progress */
320 #define CODEC_PORD 0x00800000 /* 0 = write AC97 register */
321 #define CODEC_POADD_MASK 0x007f0000
322 #define CODEC_POADD_SHIFT 16
323 #define CODEC_PODAT_MASK 0x0000ffff
324 #define CODEC_PODAT_SHIFT 0
327 #define LEGACY_JFAST 0x80000000 /* fast joystick timing */
328 #define LEGACY_FIRQ 0x01000000 /* force IRQ */
330 #define SCTRL_DACTEST 0x00400000 /* 1 = DAC test, test vector generation purposes */
331 #define SCTRL_P2ENDINC 0x00380000 /* */
332 #define SCTRL_SH_P2ENDINC 19
333 #define SCTRL_P2STINC 0x00070000 /* */
334 #define SCTRL_SH_P2STINC 16
335 #define SCTRL_R1LOOPSEL 0x00008000 /* 0 = loop mode */
336 #define SCTRL_P2LOOPSEL 0x00004000 /* 0 = loop mode */
337 #define SCTRL_P1LOOPSEL 0x00002000 /* 0 = loop mode */
338 #define SCTRL_P2PAUSE 0x00001000 /* 1 = pause mode */
339 #define SCTRL_P1PAUSE 0x00000800 /* 1 = pause mode */
340 #define SCTRL_R1INTEN 0x00000400 /* enable interrupt */
341 #define SCTRL_P2INTEN 0x00000200 /* enable interrupt */
342 #define SCTRL_P1INTEN 0x00000100 /* enable interrupt */
343 #define SCTRL_P1SCTRLD 0x00000080 /* reload sample count register for DAC1 */
344 #define SCTRL_P2DACSEN 0x00000040 /* 1 = DAC2 play back last sample when disabled */
345 #define SCTRL_R1SEB 0x00000020 /* 1 = 16bit */
346 #define SCTRL_R1SMB 0x00000010 /* 1 = stereo */
347 #define SCTRL_R1FMT 0x00000030 /* format mask */
348 #define SCTRL_SH_R1FMT 4
349 #define SCTRL_P2SEB 0x00000008 /* 1 = 16bit */
350 #define SCTRL_P2SMB 0x00000004 /* 1 = stereo */
351 #define SCTRL_P2FMT 0x0000000c /* format mask */
352 #define SCTRL_SH_P2FMT 2
353 #define SCTRL_P1SEB 0x00000002 /* 1 = 16bit */
354 #define SCTRL_P1SMB 0x00000001 /* 1 = stereo */
355 #define SCTRL_P1FMT 0x00000003 /* format mask */
356 #define SCTRL_SH_P1FMT 0
360 #define POLL_COUNT 0x1000
361 #define FMODE_DAC 4 /* slight misuse of mode_t */
363 /* MIDI buffer sizes */
365 #define MIDIINBUF 256
366 #define MIDIOUTBUF 256
368 #define FMODE_MIDI_SHIFT 3
369 #define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
370 #define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
372 #define ES1371_MODULE_NAME "es1371"
373 #define PFX ES1371_MODULE_NAME ": "
375 /* --------------------------------------------------------------------- */
377 struct es1371_state
{
381 /* list of es1371 devices */
382 struct list_head devs
;
384 /* the corresponding pci_dev structure */
387 /* soundcore stuff */
392 /* hardware resources */
393 unsigned long io
; /* long for SPARC */
399 u8 rev
; /* the chip revision */
402 int spdif_volume
; /* S/PDIF output is enabled if != -1 */
405 /* debug /proc entry */
406 struct proc_dir_entry
*ps
;
407 #endif /* ES1371_DEBUG */
409 struct ac97_codec
*codec
;
414 unsigned dac1rate
, dac2rate
, adcrate
;
417 struct semaphore open_sem
;
419 wait_queue_head_t open_wait
;
427 unsigned hwptr
, swptr
;
428 unsigned total_bytes
;
430 unsigned error
; /* over/underrun */
431 wait_queue_head_t wait
;
432 /* redundant, but makes calculations easier */
435 unsigned fragsamples
;
439 unsigned endcleared
:1;
441 unsigned ossfragshift
;
443 unsigned subdivision
;
444 } dma_dac1
, dma_dac2
, dma_adc
;
448 unsigned ird
, iwr
, icnt
;
449 unsigned ord
, owr
, ocnt
;
450 wait_queue_head_t iwait
;
451 wait_queue_head_t owait
;
452 unsigned char ibuf
[MIDIINBUF
];
453 unsigned char obuf
[MIDIOUTBUF
];
456 struct gameport
*gameport
;
457 struct semaphore sem
;
460 /* --------------------------------------------------------------------- */
462 static LIST_HEAD(devs
);
464 /* --------------------------------------------------------------------- */
466 static inline unsigned ld2(unsigned int x
)
491 /* --------------------------------------------------------------------- */
493 static unsigned wait_src_ready(struct es1371_state
*s
)
497 for (t
= 0; t
< POLL_COUNT
; t
++) {
498 if (!((r
= inl(s
->io
+ ES1371_REG_SRCONV
)) & SRC_BUSY
))
502 printk(KERN_DEBUG PFX
"sample rate converter timeout r = 0x%08x\n", r
);
506 static unsigned src_read(struct es1371_state
*s
, unsigned reg
)
508 unsigned int temp
,i
,orig
;
511 temp
= wait_src_ready (s
);
513 /* we can only access the SRC at certain times, make sure
514 we're allowed to before we read */
517 /* expose the SRC state bits */
518 outl ( (temp
& SRC_CTLMASK
) | (reg
<< SRC_RAMADDR_SHIFT
) | 0x10000UL
,
519 s
->io
+ ES1371_REG_SRCONV
);
521 /* now, wait for busy and the correct time to read */
522 temp
= wait_src_ready (s
);
524 if ( (temp
& 0x00870000UL
) != ( SRC_OKSTATE
<< 16 )){
525 /* wait for the right state */
526 for (i
=0; i
<POLL_COUNT
; i
++){
527 temp
= inl (s
->io
+ ES1371_REG_SRCONV
);
528 if ( (temp
& 0x00870000UL
) == ( SRC_OKSTATE
<< 16 ))
533 /* hide the state bits */
534 outl ((orig
& SRC_CTLMASK
) | (reg
<< SRC_RAMADDR_SHIFT
), s
->io
+ ES1371_REG_SRCONV
);
540 static void src_write(struct es1371_state
*s
, unsigned reg
, unsigned data
)
545 r
= wait_src_ready(s
) & (SRC_DIS
| SRC_DDAC1
| SRC_DDAC2
| SRC_DADC
);
546 r
|= (reg
<< SRC_RAMADDR_SHIFT
) & SRC_RAMADDR_MASK
;
547 r
|= (data
<< SRC_RAMDATA_SHIFT
) & SRC_RAMDATA_MASK
;
548 outl(r
| SRC_WE
, s
->io
+ ES1371_REG_SRCONV
);
552 /* --------------------------------------------------------------------- */
554 /* most of the following here is black magic */
555 static void set_adc_rate(struct es1371_state
*s
, unsigned rate
)
558 unsigned int n
, truncm
, freq
;
565 if ((1 << n
) & ((1 << 15) | (1 << 13) | (1 << 11) | (1 << 9)))
567 truncm
= (21 * n
- 1) | 1;
568 freq
= ((48000UL << 15) / rate
) * n
;
569 s
->adcrate
= (48000UL << 15) / (freq
/ n
);
570 spin_lock_irqsave(&s
->lock
, flags
);
574 src_write(s
, SRCREG_ADC
+SRCREG_TRUNC_N
,
575 (((239 - truncm
) >> 1) << 9) | (n
<< 4));
579 src_write(s
, SRCREG_ADC
+SRCREG_TRUNC_N
,
580 0x8000 | (((119 - truncm
) >> 1) << 9) | (n
<< 4));
582 src_write(s
, SRCREG_ADC
+SRCREG_INT_REGS
,
583 (src_read(s
, SRCREG_ADC
+SRCREG_INT_REGS
) & 0x00ff) |
584 ((freq
>> 5) & 0xfc00));
585 src_write(s
, SRCREG_ADC
+SRCREG_VFREQ_FRAC
, freq
& 0x7fff);
586 src_write(s
, SRCREG_VOL_ADC
, n
<< 8);
587 src_write(s
, SRCREG_VOL_ADC
+1, n
<< 8);
588 spin_unlock_irqrestore(&s
->lock
, flags
);
592 static void set_dac1_rate(struct es1371_state
*s
, unsigned rate
)
595 unsigned int freq
, r
;
601 freq
= ((rate
<< 15) + 1500) / 3000;
602 s
->dac1rate
= (freq
* 3000 + 16384) >> 15;
603 spin_lock_irqsave(&s
->lock
, flags
);
604 r
= (wait_src_ready(s
) & (SRC_DIS
| SRC_DDAC2
| SRC_DADC
)) | SRC_DDAC1
;
605 outl(r
, s
->io
+ ES1371_REG_SRCONV
);
606 src_write(s
, SRCREG_DAC1
+SRCREG_INT_REGS
,
607 (src_read(s
, SRCREG_DAC1
+SRCREG_INT_REGS
) & 0x00ff) |
608 ((freq
>> 5) & 0xfc00));
609 src_write(s
, SRCREG_DAC1
+SRCREG_VFREQ_FRAC
, freq
& 0x7fff);
610 r
= (wait_src_ready(s
) & (SRC_DIS
| SRC_DDAC2
| SRC_DADC
));
611 outl(r
, s
->io
+ ES1371_REG_SRCONV
);
612 spin_unlock_irqrestore(&s
->lock
, flags
);
615 static void set_dac2_rate(struct es1371_state
*s
, unsigned rate
)
618 unsigned int freq
, r
;
624 freq
= ((rate
<< 15) + 1500) / 3000;
625 s
->dac2rate
= (freq
* 3000 + 16384) >> 15;
626 spin_lock_irqsave(&s
->lock
, flags
);
627 r
= (wait_src_ready(s
) & (SRC_DIS
| SRC_DDAC1
| SRC_DADC
)) | SRC_DDAC2
;
628 outl(r
, s
->io
+ ES1371_REG_SRCONV
);
629 src_write(s
, SRCREG_DAC2
+SRCREG_INT_REGS
,
630 (src_read(s
, SRCREG_DAC2
+SRCREG_INT_REGS
) & 0x00ff) |
631 ((freq
>> 5) & 0xfc00));
632 src_write(s
, SRCREG_DAC2
+SRCREG_VFREQ_FRAC
, freq
& 0x7fff);
633 r
= (wait_src_ready(s
) & (SRC_DIS
| SRC_DDAC1
| SRC_DADC
));
634 outl(r
, s
->io
+ ES1371_REG_SRCONV
);
635 spin_unlock_irqrestore(&s
->lock
, flags
);
638 /* --------------------------------------------------------------------- */
640 static void __devinit
src_init(struct es1371_state
*s
)
644 /* before we enable or disable the SRC we need
645 to wait for it to become ready */
648 outl(SRC_DIS
, s
->io
+ ES1371_REG_SRCONV
);
650 for (i
= 0; i
< 0x80; i
++)
653 src_write(s
, SRCREG_DAC1
+SRCREG_TRUNC_N
, 16 << 4);
654 src_write(s
, SRCREG_DAC1
+SRCREG_INT_REGS
, 16 << 10);
655 src_write(s
, SRCREG_DAC2
+SRCREG_TRUNC_N
, 16 << 4);
656 src_write(s
, SRCREG_DAC2
+SRCREG_INT_REGS
, 16 << 10);
657 src_write(s
, SRCREG_VOL_ADC
, 1 << 12);
658 src_write(s
, SRCREG_VOL_ADC
+1, 1 << 12);
659 src_write(s
, SRCREG_VOL_DAC1
, 1 << 12);
660 src_write(s
, SRCREG_VOL_DAC1
+1, 1 << 12);
661 src_write(s
, SRCREG_VOL_DAC2
, 1 << 12);
662 src_write(s
, SRCREG_VOL_DAC2
+1, 1 << 12);
663 set_adc_rate(s
, 22050);
664 set_dac1_rate(s
, 22050);
665 set_dac2_rate(s
, 22050);
668 * enabling the sample rate converter without properly programming
669 * its parameters causes the chip to lock up (the SRC busy bit will
670 * be stuck high, and I've found no way to rectify this other than
674 outl(0, s
->io
+ES1371_REG_SRCONV
);
677 /* --------------------------------------------------------------------- */
679 static void wrcodec(struct ac97_codec
*codec
, u8 addr
, u16 data
)
681 struct es1371_state
*s
= (struct es1371_state
*)codec
->private_data
;
685 spin_lock_irqsave(&s
->lock
, flags
);
686 for (t
= 0; t
< POLL_COUNT
; t
++)
687 if (!(inl(s
->io
+ES1371_REG_CODEC
) & CODEC_WIP
))
690 /* save the current state for later */
691 x
= wait_src_ready(s
);
693 /* enable SRC state data in SRC mux */
694 outl((x
& (SRC_DIS
| SRC_DDAC1
| SRC_DDAC2
| SRC_DADC
)) | 0x00010000,
695 s
->io
+ES1371_REG_SRCONV
);
697 /* wait for not busy (state 0) first to avoid
699 for (t
=0; t
<POLL_COUNT
; t
++){
700 if((inl(s
->io
+ES1371_REG_SRCONV
) & 0x00870000) ==0 )
705 /* wait for a SAFE time to write addr/data and then do it, dammit */
706 for (t
=0; t
<POLL_COUNT
; t
++){
707 if((inl(s
->io
+ES1371_REG_SRCONV
) & 0x00870000) ==0x00010000)
712 outl(((addr
<< CODEC_POADD_SHIFT
) & CODEC_POADD_MASK
) |
713 ((data
<< CODEC_PODAT_SHIFT
) & CODEC_PODAT_MASK
), s
->io
+ES1371_REG_CODEC
);
715 /* restore SRC reg */
717 outl(x
, s
->io
+ES1371_REG_SRCONV
);
718 spin_unlock_irqrestore(&s
->lock
, flags
);
721 static u16
rdcodec(struct ac97_codec
*codec
, u8 addr
)
723 struct es1371_state
*s
= (struct es1371_state
*)codec
->private_data
;
727 spin_lock_irqsave(&s
->lock
, flags
);
729 /* wait for WIP to go away */
730 for (t
= 0; t
< 0x1000; t
++)
731 if (!(inl(s
->io
+ES1371_REG_CODEC
) & CODEC_WIP
))
734 /* save the current state for later */
735 x
= (wait_src_ready(s
) & (SRC_DIS
| SRC_DDAC1
| SRC_DDAC2
| SRC_DADC
));
737 /* enable SRC state data in SRC mux */
738 outl( x
| 0x00010000,
739 s
->io
+ES1371_REG_SRCONV
);
741 /* wait for not busy (state 0) first to avoid
743 for (t
=0; t
<POLL_COUNT
; t
++){
744 if((inl(s
->io
+ES1371_REG_SRCONV
) & 0x00870000) ==0 )
749 /* wait for a SAFE time to write addr/data and then do it, dammit */
750 for (t
=0; t
<POLL_COUNT
; t
++){
751 if((inl(s
->io
+ES1371_REG_SRCONV
) & 0x00870000) ==0x00010000)
756 outl(((addr
<< CODEC_POADD_SHIFT
) & CODEC_POADD_MASK
) | CODEC_PORD
, s
->io
+ES1371_REG_CODEC
);
757 /* restore SRC reg */
759 outl(x
, s
->io
+ES1371_REG_SRCONV
);
761 /* wait for WIP again */
762 for (t
= 0; t
< 0x1000; t
++)
763 if (!(inl(s
->io
+ES1371_REG_CODEC
) & CODEC_WIP
))
766 /* now wait for the stinkin' data (RDY) */
767 for (t
= 0; t
< POLL_COUNT
; t
++)
768 if ((x
= inl(s
->io
+ES1371_REG_CODEC
)) & CODEC_RDY
)
771 spin_unlock_irqrestore(&s
->lock
, flags
);
772 return ((x
& CODEC_PIDAT_MASK
) >> CODEC_PIDAT_SHIFT
);
775 /* --------------------------------------------------------------------- */
777 static inline void stop_adc(struct es1371_state
*s
)
781 spin_lock_irqsave(&s
->lock
, flags
);
782 s
->ctrl
&= ~CTRL_ADC_EN
;
783 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
784 spin_unlock_irqrestore(&s
->lock
, flags
);
787 static inline void stop_dac1(struct es1371_state
*s
)
791 spin_lock_irqsave(&s
->lock
, flags
);
792 s
->ctrl
&= ~CTRL_DAC1_EN
;
793 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
794 spin_unlock_irqrestore(&s
->lock
, flags
);
797 static inline void stop_dac2(struct es1371_state
*s
)
801 spin_lock_irqsave(&s
->lock
, flags
);
802 s
->ctrl
&= ~CTRL_DAC2_EN
;
803 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
804 spin_unlock_irqrestore(&s
->lock
, flags
);
807 static void start_dac1(struct es1371_state
*s
)
810 unsigned fragremain
, fshift
;
812 spin_lock_irqsave(&s
->lock
, flags
);
813 if (!(s
->ctrl
& CTRL_DAC1_EN
) && (s
->dma_dac1
.mapped
|| s
->dma_dac1
.count
> 0)
814 && s
->dma_dac1
.ready
) {
815 s
->ctrl
|= CTRL_DAC1_EN
;
816 s
->sctrl
= (s
->sctrl
& ~(SCTRL_P1LOOPSEL
| SCTRL_P1PAUSE
| SCTRL_P1SCTRLD
)) | SCTRL_P1INTEN
;
817 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
818 fragremain
= ((- s
->dma_dac1
.hwptr
) & (s
->dma_dac1
.fragsize
-1));
819 fshift
= sample_shift
[(s
->sctrl
& SCTRL_P1FMT
) >> SCTRL_SH_P1FMT
];
820 if (fragremain
< 2*fshift
)
821 fragremain
= s
->dma_dac1
.fragsize
;
822 outl((fragremain
>> fshift
) - 1, s
->io
+ES1371_REG_DAC1_SCOUNT
);
823 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
824 outl((s
->dma_dac1
.fragsize
>> fshift
) - 1, s
->io
+ES1371_REG_DAC1_SCOUNT
);
826 spin_unlock_irqrestore(&s
->lock
, flags
);
829 static void start_dac2(struct es1371_state
*s
)
832 unsigned fragremain
, fshift
;
834 spin_lock_irqsave(&s
->lock
, flags
);
835 if (!(s
->ctrl
& CTRL_DAC2_EN
) && (s
->dma_dac2
.mapped
|| s
->dma_dac2
.count
> 0)
836 && s
->dma_dac2
.ready
) {
837 s
->ctrl
|= CTRL_DAC2_EN
;
838 s
->sctrl
= (s
->sctrl
& ~(SCTRL_P2LOOPSEL
| SCTRL_P2PAUSE
| SCTRL_P2DACSEN
|
839 SCTRL_P2ENDINC
| SCTRL_P2STINC
)) | SCTRL_P2INTEN
|
840 (((s
->sctrl
& SCTRL_P2FMT
) ? 2 : 1) << SCTRL_SH_P2ENDINC
) |
841 (0 << SCTRL_SH_P2STINC
);
842 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
843 fragremain
= ((- s
->dma_dac2
.hwptr
) & (s
->dma_dac2
.fragsize
-1));
844 fshift
= sample_shift
[(s
->sctrl
& SCTRL_P2FMT
) >> SCTRL_SH_P2FMT
];
845 if (fragremain
< 2*fshift
)
846 fragremain
= s
->dma_dac2
.fragsize
;
847 outl((fragremain
>> fshift
) - 1, s
->io
+ES1371_REG_DAC2_SCOUNT
);
848 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
849 outl((s
->dma_dac2
.fragsize
>> fshift
) - 1, s
->io
+ES1371_REG_DAC2_SCOUNT
);
851 spin_unlock_irqrestore(&s
->lock
, flags
);
854 static void start_adc(struct es1371_state
*s
)
857 unsigned fragremain
, fshift
;
859 spin_lock_irqsave(&s
->lock
, flags
);
860 if (!(s
->ctrl
& CTRL_ADC_EN
) && (s
->dma_adc
.mapped
|| s
->dma_adc
.count
< (signed)(s
->dma_adc
.dmasize
- 2*s
->dma_adc
.fragsize
))
861 && s
->dma_adc
.ready
) {
862 s
->ctrl
|= CTRL_ADC_EN
;
863 s
->sctrl
= (s
->sctrl
& ~SCTRL_R1LOOPSEL
) | SCTRL_R1INTEN
;
864 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
865 fragremain
= ((- s
->dma_adc
.hwptr
) & (s
->dma_adc
.fragsize
-1));
866 fshift
= sample_shift
[(s
->sctrl
& SCTRL_R1FMT
) >> SCTRL_SH_R1FMT
];
867 if (fragremain
< 2*fshift
)
868 fragremain
= s
->dma_adc
.fragsize
;
869 outl((fragremain
>> fshift
) - 1, s
->io
+ES1371_REG_ADC_SCOUNT
);
870 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
871 outl((s
->dma_adc
.fragsize
>> fshift
) - 1, s
->io
+ES1371_REG_ADC_SCOUNT
);
873 spin_unlock_irqrestore(&s
->lock
, flags
);
876 /* --------------------------------------------------------------------- */
878 #define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
879 #define DMABUF_MINORDER 1
882 static inline void dealloc_dmabuf(struct es1371_state
*s
, struct dmabuf
*db
)
884 struct page
*page
, *pend
;
887 /* undo marking the pages as reserved */
888 pend
= virt_to_page(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) - 1);
889 for (page
= virt_to_page(db
->rawbuf
); page
<= pend
; page
++)
890 ClearPageReserved(page
);
891 pci_free_consistent(s
->dev
, PAGE_SIZE
<< db
->buforder
, db
->rawbuf
, db
->dmaaddr
);
894 db
->mapped
= db
->ready
= 0;
897 static int prog_dmabuf(struct es1371_state
*s
, struct dmabuf
*db
, unsigned rate
, unsigned fmt
, unsigned reg
)
902 struct page
*page
, *pend
;
904 db
->hwptr
= db
->swptr
= db
->total_bytes
= db
->count
= db
->error
= db
->endcleared
= 0;
906 db
->ready
= db
->mapped
= 0;
907 for (order
= DMABUF_DEFAULTORDER
; order
>= DMABUF_MINORDER
; order
--)
908 if ((db
->rawbuf
= pci_alloc_consistent(s
->dev
, PAGE_SIZE
<< order
, &db
->dmaaddr
)))
912 db
->buforder
= order
;
913 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
914 pend
= virt_to_page(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) - 1);
915 for (page
= virt_to_page(db
->rawbuf
); page
<= pend
; page
++)
916 SetPageReserved(page
);
918 fmt
&= ES1371_FMT_MASK
;
919 bytepersec
= rate
<< sample_shift
[fmt
];
920 bufs
= PAGE_SIZE
<< db
->buforder
;
921 if (db
->ossfragshift
) {
922 if ((1000 << db
->ossfragshift
) < bytepersec
)
923 db
->fragshift
= ld2(bytepersec
/1000);
925 db
->fragshift
= db
->ossfragshift
;
927 db
->fragshift
= ld2(bytepersec
/100/(db
->subdivision
? db
->subdivision
: 1));
928 if (db
->fragshift
< 3)
931 db
->numfrag
= bufs
>> db
->fragshift
;
932 while (db
->numfrag
< 4 && db
->fragshift
> 3) {
934 db
->numfrag
= bufs
>> db
->fragshift
;
936 db
->fragsize
= 1 << db
->fragshift
;
937 if (db
->ossmaxfrags
>= 4 && db
->ossmaxfrags
< db
->numfrag
)
938 db
->numfrag
= db
->ossmaxfrags
;
939 db
->fragsamples
= db
->fragsize
>> sample_shift
[fmt
];
940 db
->dmasize
= db
->numfrag
<< db
->fragshift
;
941 memset(db
->rawbuf
, (fmt
& ES1371_FMT_S16
) ? 0 : 0x80, db
->dmasize
);
942 outl((reg
>> 8) & 15, s
->io
+ES1371_REG_MEMPAGE
);
943 outl(db
->dmaaddr
, s
->io
+(reg
& 0xff));
944 outl((db
->dmasize
>> 2)-1, s
->io
+((reg
+ 4) & 0xff));
950 static inline int prog_dmabuf_adc(struct es1371_state
*s
)
953 return prog_dmabuf(s
, &s
->dma_adc
, s
->adcrate
, (s
->sctrl
>> SCTRL_SH_R1FMT
) & ES1371_FMT_MASK
,
954 ES1371_REG_ADC_FRAMEADR
);
957 static inline int prog_dmabuf_dac2(struct es1371_state
*s
)
960 return prog_dmabuf(s
, &s
->dma_dac2
, s
->dac2rate
, (s
->sctrl
>> SCTRL_SH_P2FMT
) & ES1371_FMT_MASK
,
961 ES1371_REG_DAC2_FRAMEADR
);
964 static inline int prog_dmabuf_dac1(struct es1371_state
*s
)
967 return prog_dmabuf(s
, &s
->dma_dac1
, s
->dac1rate
, (s
->sctrl
>> SCTRL_SH_P1FMT
) & ES1371_FMT_MASK
,
968 ES1371_REG_DAC1_FRAMEADR
);
971 static inline unsigned get_hwptr(struct es1371_state
*s
, struct dmabuf
*db
, unsigned reg
)
973 unsigned hwptr
, diff
;
975 outl((reg
>> 8) & 15, s
->io
+ES1371_REG_MEMPAGE
);
976 hwptr
= (inl(s
->io
+(reg
& 0xff)) >> 14) & 0x3fffc;
977 diff
= (db
->dmasize
+ hwptr
- db
->hwptr
) % db
->dmasize
;
982 static inline void clear_advance(void *buf
, unsigned bsize
, unsigned bptr
, unsigned len
, unsigned char c
)
984 if (bptr
+ len
> bsize
) {
985 unsigned x
= bsize
- bptr
;
986 memset(((char *)buf
) + bptr
, c
, x
);
990 memset(((char *)buf
) + bptr
, c
, len
);
993 /* call with spinlock held! */
994 static void es1371_update_ptr(struct es1371_state
*s
)
998 /* update ADC pointer */
999 if (s
->ctrl
& CTRL_ADC_EN
) {
1000 diff
= get_hwptr(s
, &s
->dma_adc
, ES1371_REG_ADC_FRAMECNT
);
1001 s
->dma_adc
.total_bytes
+= diff
;
1002 s
->dma_adc
.count
+= diff
;
1003 if (s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
)
1004 wake_up(&s
->dma_adc
.wait
);
1005 if (!s
->dma_adc
.mapped
) {
1006 if (s
->dma_adc
.count
> (signed)(s
->dma_adc
.dmasize
- ((3 * s
->dma_adc
.fragsize
) >> 1))) {
1007 s
->ctrl
&= ~CTRL_ADC_EN
;
1008 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
1013 /* update DAC1 pointer */
1014 if (s
->ctrl
& CTRL_DAC1_EN
) {
1015 diff
= get_hwptr(s
, &s
->dma_dac1
, ES1371_REG_DAC1_FRAMECNT
);
1016 s
->dma_dac1
.total_bytes
+= diff
;
1017 if (s
->dma_dac1
.mapped
) {
1018 s
->dma_dac1
.count
+= diff
;
1019 if (s
->dma_dac1
.count
>= (signed)s
->dma_dac1
.fragsize
)
1020 wake_up(&s
->dma_dac1
.wait
);
1022 s
->dma_dac1
.count
-= diff
;
1023 if (s
->dma_dac1
.count
<= 0) {
1024 s
->ctrl
&= ~CTRL_DAC1_EN
;
1025 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
1026 s
->dma_dac1
.error
++;
1027 } else if (s
->dma_dac1
.count
<= (signed)s
->dma_dac1
.fragsize
&& !s
->dma_dac1
.endcleared
) {
1028 clear_advance(s
->dma_dac1
.rawbuf
, s
->dma_dac1
.dmasize
, s
->dma_dac1
.swptr
,
1029 s
->dma_dac1
.fragsize
, (s
->sctrl
& SCTRL_P1SEB
) ? 0 : 0x80);
1030 s
->dma_dac1
.endcleared
= 1;
1032 if (s
->dma_dac1
.count
+ (signed)s
->dma_dac1
.fragsize
<= (signed)s
->dma_dac1
.dmasize
)
1033 wake_up(&s
->dma_dac1
.wait
);
1036 /* update DAC2 pointer */
1037 if (s
->ctrl
& CTRL_DAC2_EN
) {
1038 diff
= get_hwptr(s
, &s
->dma_dac2
, ES1371_REG_DAC2_FRAMECNT
);
1039 s
->dma_dac2
.total_bytes
+= diff
;
1040 if (s
->dma_dac2
.mapped
) {
1041 s
->dma_dac2
.count
+= diff
;
1042 if (s
->dma_dac2
.count
>= (signed)s
->dma_dac2
.fragsize
)
1043 wake_up(&s
->dma_dac2
.wait
);
1045 s
->dma_dac2
.count
-= diff
;
1046 if (s
->dma_dac2
.count
<= 0) {
1047 s
->ctrl
&= ~CTRL_DAC2_EN
;
1048 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
1049 s
->dma_dac2
.error
++;
1050 } else if (s
->dma_dac2
.count
<= (signed)s
->dma_dac2
.fragsize
&& !s
->dma_dac2
.endcleared
) {
1051 clear_advance(s
->dma_dac2
.rawbuf
, s
->dma_dac2
.dmasize
, s
->dma_dac2
.swptr
,
1052 s
->dma_dac2
.fragsize
, (s
->sctrl
& SCTRL_P2SEB
) ? 0 : 0x80);
1053 s
->dma_dac2
.endcleared
= 1;
1055 if (s
->dma_dac2
.count
+ (signed)s
->dma_dac2
.fragsize
<= (signed)s
->dma_dac2
.dmasize
)
1056 wake_up(&s
->dma_dac2
.wait
);
1061 /* hold spinlock for the following! */
1062 static void es1371_handle_midi(struct es1371_state
*s
)
1067 if (!(s
->ctrl
& CTRL_UART_EN
))
1070 while (inb(s
->io
+ES1371_REG_UART_STATUS
) & USTAT_RXRDY
) {
1071 ch
= inb(s
->io
+ES1371_REG_UART_DATA
);
1072 if (s
->midi
.icnt
< MIDIINBUF
) {
1073 s
->midi
.ibuf
[s
->midi
.iwr
] = ch
;
1074 s
->midi
.iwr
= (s
->midi
.iwr
+ 1) % MIDIINBUF
;
1080 wake_up(&s
->midi
.iwait
);
1082 while ((inb(s
->io
+ES1371_REG_UART_STATUS
) & USTAT_TXRDY
) && s
->midi
.ocnt
> 0) {
1083 outb(s
->midi
.obuf
[s
->midi
.ord
], s
->io
+ES1371_REG_UART_DATA
);
1084 s
->midi
.ord
= (s
->midi
.ord
+ 1) % MIDIOUTBUF
;
1086 if (s
->midi
.ocnt
< MIDIOUTBUF
-16)
1090 wake_up(&s
->midi
.owait
);
1091 outb((s
->midi
.ocnt
> 0) ? UCTRL_RXINTEN
| UCTRL_ENA_TXINT
: UCTRL_RXINTEN
, s
->io
+ES1371_REG_UART_CONTROL
);
1094 static irqreturn_t
es1371_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1096 struct es1371_state
*s
= (struct es1371_state
*)dev_id
;
1097 unsigned int intsrc
, sctl
;
1099 /* fastpath out, to ease interrupt sharing */
1100 intsrc
= inl(s
->io
+ES1371_REG_STATUS
);
1101 if (!(intsrc
& 0x80000000))
1103 spin_lock(&s
->lock
);
1104 /* clear audio interrupts first */
1106 if (intsrc
& STAT_ADC
)
1107 sctl
&= ~SCTRL_R1INTEN
;
1108 if (intsrc
& STAT_DAC1
)
1109 sctl
&= ~SCTRL_P1INTEN
;
1110 if (intsrc
& STAT_DAC2
)
1111 sctl
&= ~SCTRL_P2INTEN
;
1112 outl(sctl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1113 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1114 es1371_update_ptr(s
);
1115 es1371_handle_midi(s
);
1116 spin_unlock(&s
->lock
);
1120 /* --------------------------------------------------------------------- */
1122 static const char invalid_magic
[] = KERN_CRIT PFX
"invalid magic value\n";
1124 #define VALIDATE_STATE(s) \
1126 if (!(s) || (s)->magic != ES1371_MAGIC) { \
1127 printk(invalid_magic); \
1132 /* --------------------------------------------------------------------- */
1134 /* Conversion table for S/PDIF PCM volume emulation through the SRC */
1135 /* dB-linear table of DAC vol values; -0dB to -46.5dB with mute */
1136 static const unsigned short DACVolTable
[101] =
1138 0x1000, 0x0f2a, 0x0e60, 0x0da0, 0x0cea, 0x0c3e, 0x0b9a, 0x0aff,
1139 0x0a6d, 0x09e1, 0x095e, 0x08e1, 0x086a, 0x07fa, 0x078f, 0x072a,
1140 0x06cb, 0x0670, 0x061a, 0x05c9, 0x057b, 0x0532, 0x04ed, 0x04ab,
1141 0x046d, 0x0432, 0x03fa, 0x03c5, 0x0392, 0x0363, 0x0335, 0x030b,
1142 0x02e2, 0x02bc, 0x0297, 0x0275, 0x0254, 0x0235, 0x0217, 0x01fb,
1143 0x01e1, 0x01c8, 0x01b0, 0x0199, 0x0184, 0x0170, 0x015d, 0x014b,
1144 0x0139, 0x0129, 0x0119, 0x010b, 0x00fd, 0x00f0, 0x00e3, 0x00d7,
1145 0x00cc, 0x00c1, 0x00b7, 0x00ae, 0x00a5, 0x009c, 0x0094, 0x008c,
1146 0x0085, 0x007e, 0x0077, 0x0071, 0x006b, 0x0066, 0x0060, 0x005b,
1147 0x0057, 0x0052, 0x004e, 0x004a, 0x0046, 0x0042, 0x003f, 0x003c,
1148 0x0038, 0x0036, 0x0033, 0x0030, 0x002e, 0x002b, 0x0029, 0x0027,
1149 0x0025, 0x0023, 0x0021, 0x001f, 0x001e, 0x001c, 0x001b, 0x0019,
1150 0x0018, 0x0017, 0x0016, 0x0014, 0x0000
1154 * when we are in S/PDIF mode, we want to disable any analog output so
1155 * we filter the mixer ioctls
1157 static int mixdev_ioctl(struct ac97_codec
*codec
, unsigned int cmd
, unsigned long arg
)
1159 struct es1371_state
*s
= (struct es1371_state
*)codec
->private_data
;
1161 unsigned long flags
;
1162 unsigned int left
, right
;
1165 /* filter mixer ioctls to catch PCM and MASTER volume when in S/PDIF mode */
1166 if (s
->spdif_volume
== -1)
1167 return codec
->mixer_ioctl(codec
, cmd
, arg
);
1169 case SOUND_MIXER_WRITE_VOLUME
:
1172 case SOUND_MIXER_WRITE_PCM
: /* use SRC for PCM volume */
1173 if (get_user(val
, (int __user
*)arg
))
1175 right
= ((val
>> 8) & 0xff);
1176 left
= (val
& 0xff);
1181 s
->spdif_volume
= (right
<< 8) | left
;
1182 spin_lock_irqsave(&s
->lock
, flags
);
1183 src_write(s
, SRCREG_VOL_DAC2
, DACVolTable
[100 - left
]);
1184 src_write(s
, SRCREG_VOL_DAC2
+1, DACVolTable
[100 - right
]);
1185 spin_unlock_irqrestore(&s
->lock
, flags
);
1188 case SOUND_MIXER_READ_PCM
:
1189 return put_user(s
->spdif_volume
, (int __user
*)arg
);
1191 return codec
->mixer_ioctl(codec
, cmd
, arg
);
1194 /* --------------------------------------------------------------------- */
1197 * AC97 Mixer Register to Connections mapping of the Concert 97 board
1199 * AC97_MASTER_VOL_STEREO Line Out
1200 * AC97_MASTER_VOL_MONO TAD Output
1201 * AC97_PCBEEP_VOL none
1202 * AC97_PHONE_VOL TAD Input (mono)
1203 * AC97_MIC_VOL MIC Input (mono)
1204 * AC97_LINEIN_VOL Line Input (stereo)
1205 * AC97_CD_VOL CD Input (stereo)
1206 * AC97_VIDEO_VOL none
1207 * AC97_AUX_VOL Aux Input (stereo)
1208 * AC97_PCMOUT_VOL Wave Output (stereo)
1211 static int es1371_open_mixdev(struct inode
*inode
, struct file
*file
)
1213 int minor
= iminor(inode
);
1214 struct list_head
*list
;
1215 struct es1371_state
*s
;
1217 for (list
= devs
.next
; ; list
= list
->next
) {
1220 s
= list_entry(list
, struct es1371_state
, devs
);
1221 if (s
->codec
->dev_mixer
== minor
)
1225 file
->private_data
= s
;
1226 return nonseekable_open(inode
, file
);
1229 static int es1371_release_mixdev(struct inode
*inode
, struct file
*file
)
1231 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
1237 static int es1371_ioctl_mixdev(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1239 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
1240 struct ac97_codec
*codec
= s
->codec
;
1242 return mixdev_ioctl(codec
, cmd
, arg
);
1245 static /*const*/ struct file_operations es1371_mixer_fops
= {
1246 .owner
= THIS_MODULE
,
1247 .llseek
= no_llseek
,
1248 .ioctl
= es1371_ioctl_mixdev
,
1249 .open
= es1371_open_mixdev
,
1250 .release
= es1371_release_mixdev
,
1253 /* --------------------------------------------------------------------- */
1255 static int drain_dac1(struct es1371_state
*s
, int nonblock
)
1257 DECLARE_WAITQUEUE(wait
, current
);
1258 unsigned long flags
;
1261 if (s
->dma_dac1
.mapped
|| !s
->dma_dac1
.ready
)
1263 add_wait_queue(&s
->dma_dac1
.wait
, &wait
);
1265 __set_current_state(TASK_INTERRUPTIBLE
);
1266 spin_lock_irqsave(&s
->lock
, flags
);
1267 count
= s
->dma_dac1
.count
;
1268 spin_unlock_irqrestore(&s
->lock
, flags
);
1271 if (signal_pending(current
))
1274 remove_wait_queue(&s
->dma_dac1
.wait
, &wait
);
1275 set_current_state(TASK_RUNNING
);
1278 tmo
= 3 * HZ
* (count
+ s
->dma_dac1
.fragsize
) / 2 / s
->dac1rate
;
1279 tmo
>>= sample_shift
[(s
->sctrl
& SCTRL_P1FMT
) >> SCTRL_SH_P1FMT
];
1280 if (!schedule_timeout(tmo
+ 1))
1281 DBG(printk(KERN_DEBUG PFX
"dac1 dma timed out??\n");)
1283 remove_wait_queue(&s
->dma_dac1
.wait
, &wait
);
1284 set_current_state(TASK_RUNNING
);
1285 if (signal_pending(current
))
1286 return -ERESTARTSYS
;
1290 static int drain_dac2(struct es1371_state
*s
, int nonblock
)
1292 DECLARE_WAITQUEUE(wait
, current
);
1293 unsigned long flags
;
1296 if (s
->dma_dac2
.mapped
|| !s
->dma_dac2
.ready
)
1298 add_wait_queue(&s
->dma_dac2
.wait
, &wait
);
1300 __set_current_state(TASK_UNINTERRUPTIBLE
);
1301 spin_lock_irqsave(&s
->lock
, flags
);
1302 count
= s
->dma_dac2
.count
;
1303 spin_unlock_irqrestore(&s
->lock
, flags
);
1306 if (signal_pending(current
))
1309 remove_wait_queue(&s
->dma_dac2
.wait
, &wait
);
1310 set_current_state(TASK_RUNNING
);
1313 tmo
= 3 * HZ
* (count
+ s
->dma_dac2
.fragsize
) / 2 / s
->dac2rate
;
1314 tmo
>>= sample_shift
[(s
->sctrl
& SCTRL_P2FMT
) >> SCTRL_SH_P2FMT
];
1315 if (!schedule_timeout(tmo
+ 1))
1316 DBG(printk(KERN_DEBUG PFX
"dac2 dma timed out??\n");)
1318 remove_wait_queue(&s
->dma_dac2
.wait
, &wait
);
1319 set_current_state(TASK_RUNNING
);
1320 if (signal_pending(current
))
1321 return -ERESTARTSYS
;
1325 /* --------------------------------------------------------------------- */
1327 static ssize_t
es1371_read(struct file
*file
, char __user
*buffer
, size_t count
, loff_t
*ppos
)
1329 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
1330 DECLARE_WAITQUEUE(wait
, current
);
1332 unsigned long flags
;
1337 if (s
->dma_adc
.mapped
)
1339 if (!access_ok(VERIFY_WRITE
, buffer
, count
))
1342 if (!s
->dma_adc
.ready
&& (ret
= prog_dmabuf_adc(s
)))
1345 add_wait_queue(&s
->dma_adc
.wait
, &wait
);
1347 spin_lock_irqsave(&s
->lock
, flags
);
1348 swptr
= s
->dma_adc
.swptr
;
1349 cnt
= s
->dma_adc
.dmasize
-swptr
;
1350 if (s
->dma_adc
.count
< cnt
)
1351 cnt
= s
->dma_adc
.count
;
1353 __set_current_state(TASK_INTERRUPTIBLE
);
1354 spin_unlock_irqrestore(&s
->lock
, flags
);
1358 if (s
->dma_adc
.enabled
)
1360 if (file
->f_flags
& O_NONBLOCK
) {
1367 if (signal_pending(current
)) {
1373 if (s
->dma_adc
.mapped
)
1380 if (copy_to_user(buffer
, s
->dma_adc
.rawbuf
+ swptr
, cnt
)) {
1385 swptr
= (swptr
+ cnt
) % s
->dma_adc
.dmasize
;
1386 spin_lock_irqsave(&s
->lock
, flags
);
1387 s
->dma_adc
.swptr
= swptr
;
1388 s
->dma_adc
.count
-= cnt
;
1389 spin_unlock_irqrestore(&s
->lock
, flags
);
1393 if (s
->dma_adc
.enabled
)
1399 remove_wait_queue(&s
->dma_adc
.wait
, &wait
);
1400 set_current_state(TASK_RUNNING
);
1404 static ssize_t
es1371_write(struct file
*file
, const char __user
*buffer
, size_t count
, loff_t
*ppos
)
1406 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
1407 DECLARE_WAITQUEUE(wait
, current
);
1409 unsigned long flags
;
1414 if (s
->dma_dac2
.mapped
)
1416 if (!access_ok(VERIFY_READ
, buffer
, count
))
1419 if (!s
->dma_dac2
.ready
&& (ret
= prog_dmabuf_dac2(s
)))
1422 add_wait_queue(&s
->dma_dac2
.wait
, &wait
);
1424 spin_lock_irqsave(&s
->lock
, flags
);
1425 if (s
->dma_dac2
.count
< 0) {
1426 s
->dma_dac2
.count
= 0;
1427 s
->dma_dac2
.swptr
= s
->dma_dac2
.hwptr
;
1429 swptr
= s
->dma_dac2
.swptr
;
1430 cnt
= s
->dma_dac2
.dmasize
-swptr
;
1431 if (s
->dma_dac2
.count
+ cnt
> s
->dma_dac2
.dmasize
)
1432 cnt
= s
->dma_dac2
.dmasize
- s
->dma_dac2
.count
;
1434 __set_current_state(TASK_INTERRUPTIBLE
);
1435 spin_unlock_irqrestore(&s
->lock
, flags
);
1439 if (s
->dma_dac2
.enabled
)
1441 if (file
->f_flags
& O_NONBLOCK
) {
1448 if (signal_pending(current
)) {
1454 if (s
->dma_dac2
.mapped
)
1461 if (copy_from_user(s
->dma_dac2
.rawbuf
+ swptr
, buffer
, cnt
)) {
1466 swptr
= (swptr
+ cnt
) % s
->dma_dac2
.dmasize
;
1467 spin_lock_irqsave(&s
->lock
, flags
);
1468 s
->dma_dac2
.swptr
= swptr
;
1469 s
->dma_dac2
.count
+= cnt
;
1470 s
->dma_dac2
.endcleared
= 0;
1471 spin_unlock_irqrestore(&s
->lock
, flags
);
1475 if (s
->dma_dac2
.enabled
)
1481 remove_wait_queue(&s
->dma_dac2
.wait
, &wait
);
1483 set_current_state(TASK_RUNNING
);
1487 /* No kernel lock - we have our own spinlock */
1488 static unsigned int es1371_poll(struct file
*file
, struct poll_table_struct
*wait
)
1490 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
1491 unsigned long flags
;
1492 unsigned int mask
= 0;
1495 if (file
->f_mode
& FMODE_WRITE
) {
1496 if (!s
->dma_dac2
.ready
&& prog_dmabuf_dac2(s
))
1498 poll_wait(file
, &s
->dma_dac2
.wait
, wait
);
1500 if (file
->f_mode
& FMODE_READ
) {
1501 if (!s
->dma_adc
.ready
&& prog_dmabuf_adc(s
))
1503 poll_wait(file
, &s
->dma_adc
.wait
, wait
);
1505 spin_lock_irqsave(&s
->lock
, flags
);
1506 es1371_update_ptr(s
);
1507 if (file
->f_mode
& FMODE_READ
) {
1508 if (s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
)
1509 mask
|= POLLIN
| POLLRDNORM
;
1511 if (file
->f_mode
& FMODE_WRITE
) {
1512 if (s
->dma_dac2
.mapped
) {
1513 if (s
->dma_dac2
.count
>= (signed)s
->dma_dac2
.fragsize
)
1514 mask
|= POLLOUT
| POLLWRNORM
;
1516 if ((signed)s
->dma_dac2
.dmasize
>= s
->dma_dac2
.count
+ (signed)s
->dma_dac2
.fragsize
)
1517 mask
|= POLLOUT
| POLLWRNORM
;
1520 spin_unlock_irqrestore(&s
->lock
, flags
);
1524 static int es1371_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1526 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
1535 if (vma
->vm_flags
& VM_WRITE
) {
1536 if ((ret
= prog_dmabuf_dac2(s
)) != 0) {
1540 } else if (vma
->vm_flags
& VM_READ
) {
1541 if ((ret
= prog_dmabuf_adc(s
)) != 0) {
1549 if (vma
->vm_pgoff
!= 0) {
1553 size
= vma
->vm_end
- vma
->vm_start
;
1554 if (size
> (PAGE_SIZE
<< db
->buforder
)) {
1558 if (remap_pfn_range(vma
, vma
->vm_start
,
1559 virt_to_phys(db
->rawbuf
) >> PAGE_SHIFT
,
1560 size
, vma
->vm_page_prot
)) {
1571 static int es1371_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1573 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
1574 unsigned long flags
;
1575 audio_buf_info abinfo
;
1578 int val
, mapped
, ret
;
1579 void __user
*argp
= (void __user
*)arg
;
1580 int __user
*p
= argp
;
1583 mapped
= ((file
->f_mode
& FMODE_WRITE
) && s
->dma_dac2
.mapped
) ||
1584 ((file
->f_mode
& FMODE_READ
) && s
->dma_adc
.mapped
);
1586 case OSS_GETVERSION
:
1587 return put_user(SOUND_VERSION
, p
);
1589 case SNDCTL_DSP_SYNC
:
1590 if (file
->f_mode
& FMODE_WRITE
)
1591 return drain_dac2(s
, 0/*file->f_flags & O_NONBLOCK*/);
1594 case SNDCTL_DSP_SETDUPLEX
:
1597 case SNDCTL_DSP_GETCAPS
:
1598 return put_user(DSP_CAP_DUPLEX
| DSP_CAP_REALTIME
| DSP_CAP_TRIGGER
| DSP_CAP_MMAP
, p
);
1600 case SNDCTL_DSP_RESET
:
1601 if (file
->f_mode
& FMODE_WRITE
) {
1603 synchronize_irq(s
->irq
);
1604 s
->dma_dac2
.swptr
= s
->dma_dac2
.hwptr
= s
->dma_dac2
.count
= s
->dma_dac2
.total_bytes
= 0;
1606 if (file
->f_mode
& FMODE_READ
) {
1608 synchronize_irq(s
->irq
);
1609 s
->dma_adc
.swptr
= s
->dma_adc
.hwptr
= s
->dma_adc
.count
= s
->dma_adc
.total_bytes
= 0;
1613 case SNDCTL_DSP_SPEED
:
1614 if (get_user(val
, p
))
1617 if (file
->f_mode
& FMODE_READ
) {
1619 s
->dma_adc
.ready
= 0;
1620 set_adc_rate(s
, val
);
1622 if (file
->f_mode
& FMODE_WRITE
) {
1624 s
->dma_dac2
.ready
= 0;
1625 set_dac2_rate(s
, val
);
1628 return put_user((file
->f_mode
& FMODE_READ
) ? s
->adcrate
: s
->dac2rate
, p
);
1630 case SNDCTL_DSP_STEREO
:
1631 if (get_user(val
, p
))
1633 if (file
->f_mode
& FMODE_READ
) {
1635 s
->dma_adc
.ready
= 0;
1636 spin_lock_irqsave(&s
->lock
, flags
);
1638 s
->sctrl
|= SCTRL_R1SMB
;
1640 s
->sctrl
&= ~SCTRL_R1SMB
;
1641 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1642 spin_unlock_irqrestore(&s
->lock
, flags
);
1644 if (file
->f_mode
& FMODE_WRITE
) {
1646 s
->dma_dac2
.ready
= 0;
1647 spin_lock_irqsave(&s
->lock
, flags
);
1649 s
->sctrl
|= SCTRL_P2SMB
;
1651 s
->sctrl
&= ~SCTRL_P2SMB
;
1652 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1653 spin_unlock_irqrestore(&s
->lock
, flags
);
1657 case SNDCTL_DSP_CHANNELS
:
1658 if (get_user(val
, p
))
1661 if (file
->f_mode
& FMODE_READ
) {
1663 s
->dma_adc
.ready
= 0;
1664 spin_lock_irqsave(&s
->lock
, flags
);
1666 s
->sctrl
|= SCTRL_R1SMB
;
1668 s
->sctrl
&= ~SCTRL_R1SMB
;
1669 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1670 spin_unlock_irqrestore(&s
->lock
, flags
);
1672 if (file
->f_mode
& FMODE_WRITE
) {
1674 s
->dma_dac2
.ready
= 0;
1675 spin_lock_irqsave(&s
->lock
, flags
);
1677 s
->sctrl
|= SCTRL_P2SMB
;
1679 s
->sctrl
&= ~SCTRL_P2SMB
;
1680 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1681 spin_unlock_irqrestore(&s
->lock
, flags
);
1684 return put_user((s
->sctrl
& ((file
->f_mode
& FMODE_READ
) ? SCTRL_R1SMB
: SCTRL_P2SMB
)) ? 2 : 1, p
);
1686 case SNDCTL_DSP_GETFMTS
: /* Returns a mask */
1687 return put_user(AFMT_S16_LE
|AFMT_U8
, p
);
1689 case SNDCTL_DSP_SETFMT
: /* Selects ONE fmt*/
1690 if (get_user(val
, p
))
1692 if (val
!= AFMT_QUERY
) {
1693 if (file
->f_mode
& FMODE_READ
) {
1695 s
->dma_adc
.ready
= 0;
1696 spin_lock_irqsave(&s
->lock
, flags
);
1697 if (val
== AFMT_S16_LE
)
1698 s
->sctrl
|= SCTRL_R1SEB
;
1700 s
->sctrl
&= ~SCTRL_R1SEB
;
1701 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1702 spin_unlock_irqrestore(&s
->lock
, flags
);
1704 if (file
->f_mode
& FMODE_WRITE
) {
1706 s
->dma_dac2
.ready
= 0;
1707 spin_lock_irqsave(&s
->lock
, flags
);
1708 if (val
== AFMT_S16_LE
)
1709 s
->sctrl
|= SCTRL_P2SEB
;
1711 s
->sctrl
&= ~SCTRL_P2SEB
;
1712 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1713 spin_unlock_irqrestore(&s
->lock
, flags
);
1716 return put_user((s
->sctrl
& ((file
->f_mode
& FMODE_READ
) ? SCTRL_R1SEB
: SCTRL_P2SEB
)) ?
1717 AFMT_S16_LE
: AFMT_U8
, p
);
1719 case SNDCTL_DSP_POST
:
1722 case SNDCTL_DSP_GETTRIGGER
:
1724 if (file
->f_mode
& FMODE_READ
&& s
->ctrl
& CTRL_ADC_EN
)
1725 val
|= PCM_ENABLE_INPUT
;
1726 if (file
->f_mode
& FMODE_WRITE
&& s
->ctrl
& CTRL_DAC2_EN
)
1727 val
|= PCM_ENABLE_OUTPUT
;
1728 return put_user(val
, p
);
1730 case SNDCTL_DSP_SETTRIGGER
:
1731 if (get_user(val
, p
))
1733 if (file
->f_mode
& FMODE_READ
) {
1734 if (val
& PCM_ENABLE_INPUT
) {
1735 if (!s
->dma_adc
.ready
&& (ret
= prog_dmabuf_adc(s
)))
1737 s
->dma_adc
.enabled
= 1;
1740 s
->dma_adc
.enabled
= 0;
1744 if (file
->f_mode
& FMODE_WRITE
) {
1745 if (val
& PCM_ENABLE_OUTPUT
) {
1746 if (!s
->dma_dac2
.ready
&& (ret
= prog_dmabuf_dac2(s
)))
1748 s
->dma_dac2
.enabled
= 1;
1751 s
->dma_dac2
.enabled
= 0;
1757 case SNDCTL_DSP_GETOSPACE
:
1758 if (!(file
->f_mode
& FMODE_WRITE
))
1760 if (!s
->dma_dac2
.ready
&& (val
= prog_dmabuf_dac2(s
)) != 0)
1762 spin_lock_irqsave(&s
->lock
, flags
);
1763 es1371_update_ptr(s
);
1764 abinfo
.fragsize
= s
->dma_dac2
.fragsize
;
1765 count
= s
->dma_dac2
.count
;
1768 abinfo
.bytes
= s
->dma_dac2
.dmasize
- count
;
1769 abinfo
.fragstotal
= s
->dma_dac2
.numfrag
;
1770 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_dac2
.fragshift
;
1771 spin_unlock_irqrestore(&s
->lock
, flags
);
1772 return copy_to_user(argp
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
1774 case SNDCTL_DSP_GETISPACE
:
1775 if (!(file
->f_mode
& FMODE_READ
))
1777 if (!s
->dma_adc
.ready
&& (val
= prog_dmabuf_adc(s
)) != 0)
1779 spin_lock_irqsave(&s
->lock
, flags
);
1780 es1371_update_ptr(s
);
1781 abinfo
.fragsize
= s
->dma_adc
.fragsize
;
1782 count
= s
->dma_adc
.count
;
1785 abinfo
.bytes
= count
;
1786 abinfo
.fragstotal
= s
->dma_adc
.numfrag
;
1787 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_adc
.fragshift
;
1788 spin_unlock_irqrestore(&s
->lock
, flags
);
1789 return copy_to_user(argp
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
1791 case SNDCTL_DSP_NONBLOCK
:
1792 file
->f_flags
|= O_NONBLOCK
;
1795 case SNDCTL_DSP_GETODELAY
:
1796 if (!(file
->f_mode
& FMODE_WRITE
))
1798 if (!s
->dma_dac2
.ready
&& (val
= prog_dmabuf_dac2(s
)) != 0)
1800 spin_lock_irqsave(&s
->lock
, flags
);
1801 es1371_update_ptr(s
);
1802 count
= s
->dma_dac2
.count
;
1803 spin_unlock_irqrestore(&s
->lock
, flags
);
1806 return put_user(count
, p
);
1808 case SNDCTL_DSP_GETIPTR
:
1809 if (!(file
->f_mode
& FMODE_READ
))
1811 if (!s
->dma_adc
.ready
&& (val
= prog_dmabuf_adc(s
)) != 0)
1813 spin_lock_irqsave(&s
->lock
, flags
);
1814 es1371_update_ptr(s
);
1815 cinfo
.bytes
= s
->dma_adc
.total_bytes
;
1816 count
= s
->dma_adc
.count
;
1819 cinfo
.blocks
= count
>> s
->dma_adc
.fragshift
;
1820 cinfo
.ptr
= s
->dma_adc
.hwptr
;
1821 if (s
->dma_adc
.mapped
)
1822 s
->dma_adc
.count
&= s
->dma_adc
.fragsize
-1;
1823 spin_unlock_irqrestore(&s
->lock
, flags
);
1824 if (copy_to_user(argp
, &cinfo
, sizeof(cinfo
)))
1828 case SNDCTL_DSP_GETOPTR
:
1829 if (!(file
->f_mode
& FMODE_WRITE
))
1831 if (!s
->dma_dac2
.ready
&& (val
= prog_dmabuf_dac2(s
)) != 0)
1833 spin_lock_irqsave(&s
->lock
, flags
);
1834 es1371_update_ptr(s
);
1835 cinfo
.bytes
= s
->dma_dac2
.total_bytes
;
1836 count
= s
->dma_dac2
.count
;
1839 cinfo
.blocks
= count
>> s
->dma_dac2
.fragshift
;
1840 cinfo
.ptr
= s
->dma_dac2
.hwptr
;
1841 if (s
->dma_dac2
.mapped
)
1842 s
->dma_dac2
.count
&= s
->dma_dac2
.fragsize
-1;
1843 spin_unlock_irqrestore(&s
->lock
, flags
);
1844 if (copy_to_user(argp
, &cinfo
, sizeof(cinfo
)))
1848 case SNDCTL_DSP_GETBLKSIZE
:
1849 if (file
->f_mode
& FMODE_WRITE
) {
1850 if ((val
= prog_dmabuf_dac2(s
)))
1852 return put_user(s
->dma_dac2
.fragsize
, p
);
1854 if ((val
= prog_dmabuf_adc(s
)))
1856 return put_user(s
->dma_adc
.fragsize
, p
);
1858 case SNDCTL_DSP_SETFRAGMENT
:
1859 if (get_user(val
, p
))
1861 if (file
->f_mode
& FMODE_READ
) {
1862 s
->dma_adc
.ossfragshift
= val
& 0xffff;
1863 s
->dma_adc
.ossmaxfrags
= (val
>> 16) & 0xffff;
1864 if (s
->dma_adc
.ossfragshift
< 4)
1865 s
->dma_adc
.ossfragshift
= 4;
1866 if (s
->dma_adc
.ossfragshift
> 15)
1867 s
->dma_adc
.ossfragshift
= 15;
1868 if (s
->dma_adc
.ossmaxfrags
< 4)
1869 s
->dma_adc
.ossmaxfrags
= 4;
1871 if (file
->f_mode
& FMODE_WRITE
) {
1872 s
->dma_dac2
.ossfragshift
= val
& 0xffff;
1873 s
->dma_dac2
.ossmaxfrags
= (val
>> 16) & 0xffff;
1874 if (s
->dma_dac2
.ossfragshift
< 4)
1875 s
->dma_dac2
.ossfragshift
= 4;
1876 if (s
->dma_dac2
.ossfragshift
> 15)
1877 s
->dma_dac2
.ossfragshift
= 15;
1878 if (s
->dma_dac2
.ossmaxfrags
< 4)
1879 s
->dma_dac2
.ossmaxfrags
= 4;
1883 case SNDCTL_DSP_SUBDIVIDE
:
1884 if ((file
->f_mode
& FMODE_READ
&& s
->dma_adc
.subdivision
) ||
1885 (file
->f_mode
& FMODE_WRITE
&& s
->dma_dac2
.subdivision
))
1887 if (get_user(val
, p
))
1889 if (val
!= 1 && val
!= 2 && val
!= 4)
1891 if (file
->f_mode
& FMODE_READ
)
1892 s
->dma_adc
.subdivision
= val
;
1893 if (file
->f_mode
& FMODE_WRITE
)
1894 s
->dma_dac2
.subdivision
= val
;
1897 case SOUND_PCM_READ_RATE
:
1898 return put_user((file
->f_mode
& FMODE_READ
) ? s
->adcrate
: s
->dac2rate
, p
);
1900 case SOUND_PCM_READ_CHANNELS
:
1901 return put_user((s
->sctrl
& ((file
->f_mode
& FMODE_READ
) ? SCTRL_R1SMB
: SCTRL_P2SMB
)) ? 2 : 1, p
);
1903 case SOUND_PCM_READ_BITS
:
1904 return put_user((s
->sctrl
& ((file
->f_mode
& FMODE_READ
) ? SCTRL_R1SEB
: SCTRL_P2SEB
)) ? 16 : 8, p
);
1906 case SOUND_PCM_WRITE_FILTER
:
1907 case SNDCTL_DSP_SETSYNCRO
:
1908 case SOUND_PCM_READ_FILTER
:
1912 return mixdev_ioctl(s
->codec
, cmd
, arg
);
1915 static int es1371_open(struct inode
*inode
, struct file
*file
)
1917 int minor
= iminor(inode
);
1918 DECLARE_WAITQUEUE(wait
, current
);
1919 unsigned long flags
;
1920 struct list_head
*list
;
1921 struct es1371_state
*s
;
1923 for (list
= devs
.next
; ; list
= list
->next
) {
1926 s
= list_entry(list
, struct es1371_state
, devs
);
1927 if (!((s
->dev_audio
^ minor
) & ~0xf))
1931 file
->private_data
= s
;
1932 /* wait for device to become free */
1934 while (s
->open_mode
& file
->f_mode
) {
1935 if (file
->f_flags
& O_NONBLOCK
) {
1939 add_wait_queue(&s
->open_wait
, &wait
);
1940 __set_current_state(TASK_INTERRUPTIBLE
);
1943 remove_wait_queue(&s
->open_wait
, &wait
);
1944 set_current_state(TASK_RUNNING
);
1945 if (signal_pending(current
))
1946 return -ERESTARTSYS
;
1949 if (file
->f_mode
& FMODE_READ
) {
1950 s
->dma_adc
.ossfragshift
= s
->dma_adc
.ossmaxfrags
= s
->dma_adc
.subdivision
= 0;
1951 s
->dma_adc
.enabled
= 1;
1952 set_adc_rate(s
, 8000);
1954 if (file
->f_mode
& FMODE_WRITE
) {
1955 s
->dma_dac2
.ossfragshift
= s
->dma_dac2
.ossmaxfrags
= s
->dma_dac2
.subdivision
= 0;
1956 s
->dma_dac2
.enabled
= 1;
1957 set_dac2_rate(s
, 8000);
1959 spin_lock_irqsave(&s
->lock
, flags
);
1960 if (file
->f_mode
& FMODE_READ
) {
1961 s
->sctrl
&= ~SCTRL_R1FMT
;
1962 if ((minor
& 0xf) == SND_DEV_DSP16
)
1963 s
->sctrl
|= ES1371_FMT_S16_MONO
<< SCTRL_SH_R1FMT
;
1965 s
->sctrl
|= ES1371_FMT_U8_MONO
<< SCTRL_SH_R1FMT
;
1967 if (file
->f_mode
& FMODE_WRITE
) {
1968 s
->sctrl
&= ~SCTRL_P2FMT
;
1969 if ((minor
& 0xf) == SND_DEV_DSP16
)
1970 s
->sctrl
|= ES1371_FMT_S16_MONO
<< SCTRL_SH_P2FMT
;
1972 s
->sctrl
|= ES1371_FMT_U8_MONO
<< SCTRL_SH_P2FMT
;
1974 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
1975 spin_unlock_irqrestore(&s
->lock
, flags
);
1976 s
->open_mode
|= file
->f_mode
& (FMODE_READ
| FMODE_WRITE
);
1978 init_MUTEX(&s
->sem
);
1979 return nonseekable_open(inode
, file
);
1982 static int es1371_release(struct inode
*inode
, struct file
*file
)
1984 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
1988 if (file
->f_mode
& FMODE_WRITE
)
1989 drain_dac2(s
, file
->f_flags
& O_NONBLOCK
);
1991 if (file
->f_mode
& FMODE_WRITE
) {
1993 dealloc_dmabuf(s
, &s
->dma_dac2
);
1995 if (file
->f_mode
& FMODE_READ
) {
1997 dealloc_dmabuf(s
, &s
->dma_adc
);
1999 s
->open_mode
&= ~(file
->f_mode
& (FMODE_READ
|FMODE_WRITE
));
2001 wake_up(&s
->open_wait
);
2006 static /*const*/ struct file_operations es1371_audio_fops
= {
2007 .owner
= THIS_MODULE
,
2008 .llseek
= no_llseek
,
2009 .read
= es1371_read
,
2010 .write
= es1371_write
,
2011 .poll
= es1371_poll
,
2012 .ioctl
= es1371_ioctl
,
2013 .mmap
= es1371_mmap
,
2014 .open
= es1371_open
,
2015 .release
= es1371_release
,
2018 /* --------------------------------------------------------------------- */
2020 static ssize_t
es1371_write_dac(struct file
*file
, const char __user
*buffer
, size_t count
, loff_t
*ppos
)
2022 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2023 DECLARE_WAITQUEUE(wait
, current
);
2025 unsigned long flags
;
2030 if (s
->dma_dac1
.mapped
)
2032 if (!s
->dma_dac1
.ready
&& (ret
= prog_dmabuf_dac1(s
)))
2034 if (!access_ok(VERIFY_READ
, buffer
, count
))
2036 add_wait_queue(&s
->dma_dac1
.wait
, &wait
);
2038 spin_lock_irqsave(&s
->lock
, flags
);
2039 if (s
->dma_dac1
.count
< 0) {
2040 s
->dma_dac1
.count
= 0;
2041 s
->dma_dac1
.swptr
= s
->dma_dac1
.hwptr
;
2043 swptr
= s
->dma_dac1
.swptr
;
2044 cnt
= s
->dma_dac1
.dmasize
-swptr
;
2045 if (s
->dma_dac1
.count
+ cnt
> s
->dma_dac1
.dmasize
)
2046 cnt
= s
->dma_dac1
.dmasize
- s
->dma_dac1
.count
;
2048 __set_current_state(TASK_INTERRUPTIBLE
);
2049 spin_unlock_irqrestore(&s
->lock
, flags
);
2053 if (s
->dma_dac1
.enabled
)
2055 if (file
->f_flags
& O_NONBLOCK
) {
2061 if (signal_pending(current
)) {
2068 if (copy_from_user(s
->dma_dac1
.rawbuf
+ swptr
, buffer
, cnt
)) {
2073 swptr
= (swptr
+ cnt
) % s
->dma_dac1
.dmasize
;
2074 spin_lock_irqsave(&s
->lock
, flags
);
2075 s
->dma_dac1
.swptr
= swptr
;
2076 s
->dma_dac1
.count
+= cnt
;
2077 s
->dma_dac1
.endcleared
= 0;
2078 spin_unlock_irqrestore(&s
->lock
, flags
);
2082 if (s
->dma_dac1
.enabled
)
2085 remove_wait_queue(&s
->dma_dac1
.wait
, &wait
);
2086 set_current_state(TASK_RUNNING
);
2090 /* No kernel lock - we have our own spinlock */
2091 static unsigned int es1371_poll_dac(struct file
*file
, struct poll_table_struct
*wait
)
2093 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2094 unsigned long flags
;
2095 unsigned int mask
= 0;
2098 if (!s
->dma_dac1
.ready
&& prog_dmabuf_dac1(s
))
2100 poll_wait(file
, &s
->dma_dac1
.wait
, wait
);
2101 spin_lock_irqsave(&s
->lock
, flags
);
2102 es1371_update_ptr(s
);
2103 if (s
->dma_dac1
.mapped
) {
2104 if (s
->dma_dac1
.count
>= (signed)s
->dma_dac1
.fragsize
)
2105 mask
|= POLLOUT
| POLLWRNORM
;
2107 if ((signed)s
->dma_dac1
.dmasize
>= s
->dma_dac1
.count
+ (signed)s
->dma_dac1
.fragsize
)
2108 mask
|= POLLOUT
| POLLWRNORM
;
2110 spin_unlock_irqrestore(&s
->lock
, flags
);
2114 static int es1371_mmap_dac(struct file
*file
, struct vm_area_struct
*vma
)
2116 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2121 if (!(vma
->vm_flags
& VM_WRITE
))
2124 if ((ret
= prog_dmabuf_dac1(s
)) != 0)
2127 if (vma
->vm_pgoff
!= 0)
2129 size
= vma
->vm_end
- vma
->vm_start
;
2130 if (size
> (PAGE_SIZE
<< s
->dma_dac1
.buforder
))
2133 if (remap_pfn_range(vma
, vma
->vm_start
,
2134 virt_to_phys(s
->dma_dac1
.rawbuf
) >> PAGE_SHIFT
,
2135 size
, vma
->vm_page_prot
))
2137 s
->dma_dac1
.mapped
= 1;
2144 static int es1371_ioctl_dac(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
2146 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2147 unsigned long flags
;
2148 audio_buf_info abinfo
;
2152 int __user
*p
= (int __user
*)arg
;
2156 case OSS_GETVERSION
:
2157 return put_user(SOUND_VERSION
, p
);
2159 case SNDCTL_DSP_SYNC
:
2160 return drain_dac1(s
, 0/*file->f_flags & O_NONBLOCK*/);
2162 case SNDCTL_DSP_SETDUPLEX
:
2165 case SNDCTL_DSP_GETCAPS
:
2166 return put_user(DSP_CAP_REALTIME
| DSP_CAP_TRIGGER
| DSP_CAP_MMAP
, p
);
2168 case SNDCTL_DSP_RESET
:
2170 synchronize_irq(s
->irq
);
2171 s
->dma_dac1
.swptr
= s
->dma_dac1
.hwptr
= s
->dma_dac1
.count
= s
->dma_dac1
.total_bytes
= 0;
2174 case SNDCTL_DSP_SPEED
:
2175 if (get_user(val
, p
))
2179 s
->dma_dac1
.ready
= 0;
2180 set_dac1_rate(s
, val
);
2182 return put_user(s
->dac1rate
, p
);
2184 case SNDCTL_DSP_STEREO
:
2185 if (get_user(val
, p
))
2188 s
->dma_dac1
.ready
= 0;
2189 spin_lock_irqsave(&s
->lock
, flags
);
2191 s
->sctrl
|= SCTRL_P1SMB
;
2193 s
->sctrl
&= ~SCTRL_P1SMB
;
2194 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
2195 spin_unlock_irqrestore(&s
->lock
, flags
);
2198 case SNDCTL_DSP_CHANNELS
:
2199 if (get_user(val
, p
))
2203 s
->dma_dac1
.ready
= 0;
2204 spin_lock_irqsave(&s
->lock
, flags
);
2206 s
->sctrl
|= SCTRL_P1SMB
;
2208 s
->sctrl
&= ~SCTRL_P1SMB
;
2209 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
2210 spin_unlock_irqrestore(&s
->lock
, flags
);
2212 return put_user((s
->sctrl
& SCTRL_P1SMB
) ? 2 : 1, p
);
2214 case SNDCTL_DSP_GETFMTS
: /* Returns a mask */
2215 return put_user(AFMT_S16_LE
|AFMT_U8
, p
);
2217 case SNDCTL_DSP_SETFMT
: /* Selects ONE fmt*/
2218 if (get_user(val
, p
))
2220 if (val
!= AFMT_QUERY
) {
2222 s
->dma_dac1
.ready
= 0;
2223 spin_lock_irqsave(&s
->lock
, flags
);
2224 if (val
== AFMT_S16_LE
)
2225 s
->sctrl
|= SCTRL_P1SEB
;
2227 s
->sctrl
&= ~SCTRL_P1SEB
;
2228 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
2229 spin_unlock_irqrestore(&s
->lock
, flags
);
2231 return put_user((s
->sctrl
& SCTRL_P1SEB
) ? AFMT_S16_LE
: AFMT_U8
, p
);
2233 case SNDCTL_DSP_POST
:
2236 case SNDCTL_DSP_GETTRIGGER
:
2237 return put_user((s
->ctrl
& CTRL_DAC1_EN
) ? PCM_ENABLE_OUTPUT
: 0, p
);
2239 case SNDCTL_DSP_SETTRIGGER
:
2240 if (get_user(val
, p
))
2242 if (val
& PCM_ENABLE_OUTPUT
) {
2243 if (!s
->dma_dac1
.ready
&& (ret
= prog_dmabuf_dac1(s
)))
2245 s
->dma_dac1
.enabled
= 1;
2248 s
->dma_dac1
.enabled
= 0;
2253 case SNDCTL_DSP_GETOSPACE
:
2254 if (!s
->dma_dac1
.ready
&& (val
= prog_dmabuf_dac1(s
)) != 0)
2256 spin_lock_irqsave(&s
->lock
, flags
);
2257 es1371_update_ptr(s
);
2258 abinfo
.fragsize
= s
->dma_dac1
.fragsize
;
2259 count
= s
->dma_dac1
.count
;
2262 abinfo
.bytes
= s
->dma_dac1
.dmasize
- count
;
2263 abinfo
.fragstotal
= s
->dma_dac1
.numfrag
;
2264 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_dac1
.fragshift
;
2265 spin_unlock_irqrestore(&s
->lock
, flags
);
2266 return copy_to_user((void __user
*)arg
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
2268 case SNDCTL_DSP_NONBLOCK
:
2269 file
->f_flags
|= O_NONBLOCK
;
2272 case SNDCTL_DSP_GETODELAY
:
2273 if (!s
->dma_dac1
.ready
&& (val
= prog_dmabuf_dac1(s
)) != 0)
2275 spin_lock_irqsave(&s
->lock
, flags
);
2276 es1371_update_ptr(s
);
2277 count
= s
->dma_dac1
.count
;
2278 spin_unlock_irqrestore(&s
->lock
, flags
);
2281 return put_user(count
, p
);
2283 case SNDCTL_DSP_GETOPTR
:
2284 if (!s
->dma_dac1
.ready
&& (val
= prog_dmabuf_dac1(s
)) != 0)
2286 spin_lock_irqsave(&s
->lock
, flags
);
2287 es1371_update_ptr(s
);
2288 cinfo
.bytes
= s
->dma_dac1
.total_bytes
;
2289 count
= s
->dma_dac1
.count
;
2292 cinfo
.blocks
= count
>> s
->dma_dac1
.fragshift
;
2293 cinfo
.ptr
= s
->dma_dac1
.hwptr
;
2294 if (s
->dma_dac1
.mapped
)
2295 s
->dma_dac1
.count
&= s
->dma_dac1
.fragsize
-1;
2296 spin_unlock_irqrestore(&s
->lock
, flags
);
2297 if (copy_to_user((void __user
*)arg
, &cinfo
, sizeof(cinfo
)))
2301 case SNDCTL_DSP_GETBLKSIZE
:
2302 if ((val
= prog_dmabuf_dac1(s
)))
2304 return put_user(s
->dma_dac1
.fragsize
, p
);
2306 case SNDCTL_DSP_SETFRAGMENT
:
2307 if (get_user(val
, p
))
2309 s
->dma_dac1
.ossfragshift
= val
& 0xffff;
2310 s
->dma_dac1
.ossmaxfrags
= (val
>> 16) & 0xffff;
2311 if (s
->dma_dac1
.ossfragshift
< 4)
2312 s
->dma_dac1
.ossfragshift
= 4;
2313 if (s
->dma_dac1
.ossfragshift
> 15)
2314 s
->dma_dac1
.ossfragshift
= 15;
2315 if (s
->dma_dac1
.ossmaxfrags
< 4)
2316 s
->dma_dac1
.ossmaxfrags
= 4;
2319 case SNDCTL_DSP_SUBDIVIDE
:
2320 if (s
->dma_dac1
.subdivision
)
2322 if (get_user(val
, p
))
2324 if (val
!= 1 && val
!= 2 && val
!= 4)
2326 s
->dma_dac1
.subdivision
= val
;
2329 case SOUND_PCM_READ_RATE
:
2330 return put_user(s
->dac1rate
, p
);
2332 case SOUND_PCM_READ_CHANNELS
:
2333 return put_user((s
->sctrl
& SCTRL_P1SMB
) ? 2 : 1, p
);
2335 case SOUND_PCM_READ_BITS
:
2336 return put_user((s
->sctrl
& SCTRL_P1SEB
) ? 16 : 8, p
);
2338 case SOUND_PCM_WRITE_FILTER
:
2339 case SNDCTL_DSP_SETSYNCRO
:
2340 case SOUND_PCM_READ_FILTER
:
2344 return mixdev_ioctl(s
->codec
, cmd
, arg
);
2347 static int es1371_open_dac(struct inode
*inode
, struct file
*file
)
2349 int minor
= iminor(inode
);
2350 DECLARE_WAITQUEUE(wait
, current
);
2351 unsigned long flags
;
2352 struct list_head
*list
;
2353 struct es1371_state
*s
;
2355 for (list
= devs
.next
; ; list
= list
->next
) {
2358 s
= list_entry(list
, struct es1371_state
, devs
);
2359 if (!((s
->dev_dac
^ minor
) & ~0xf))
2363 /* we allow opening with O_RDWR, most programs do it although they will only write */
2365 if (file
->f_mode
& FMODE_READ
)
2368 if (!(file
->f_mode
& FMODE_WRITE
))
2370 file
->private_data
= s
;
2371 /* wait for device to become free */
2373 while (s
->open_mode
& FMODE_DAC
) {
2374 if (file
->f_flags
& O_NONBLOCK
) {
2378 add_wait_queue(&s
->open_wait
, &wait
);
2379 __set_current_state(TASK_INTERRUPTIBLE
);
2382 remove_wait_queue(&s
->open_wait
, &wait
);
2383 set_current_state(TASK_RUNNING
);
2384 if (signal_pending(current
))
2385 return -ERESTARTSYS
;
2388 s
->dma_dac1
.ossfragshift
= s
->dma_dac1
.ossmaxfrags
= s
->dma_dac1
.subdivision
= 0;
2389 s
->dma_dac1
.enabled
= 1;
2390 set_dac1_rate(s
, 8000);
2391 spin_lock_irqsave(&s
->lock
, flags
);
2392 s
->sctrl
&= ~SCTRL_P1FMT
;
2393 if ((minor
& 0xf) == SND_DEV_DSP16
)
2394 s
->sctrl
|= ES1371_FMT_S16_MONO
<< SCTRL_SH_P1FMT
;
2396 s
->sctrl
|= ES1371_FMT_U8_MONO
<< SCTRL_SH_P1FMT
;
2397 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
2398 spin_unlock_irqrestore(&s
->lock
, flags
);
2399 s
->open_mode
|= FMODE_DAC
;
2401 return nonseekable_open(inode
, file
);
2404 static int es1371_release_dac(struct inode
*inode
, struct file
*file
)
2406 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2410 drain_dac1(s
, file
->f_flags
& O_NONBLOCK
);
2413 dealloc_dmabuf(s
, &s
->dma_dac1
);
2414 s
->open_mode
&= ~FMODE_DAC
;
2416 wake_up(&s
->open_wait
);
2421 static /*const*/ struct file_operations es1371_dac_fops
= {
2422 .owner
= THIS_MODULE
,
2423 .llseek
= no_llseek
,
2424 .write
= es1371_write_dac
,
2425 .poll
= es1371_poll_dac
,
2426 .ioctl
= es1371_ioctl_dac
,
2427 .mmap
= es1371_mmap_dac
,
2428 .open
= es1371_open_dac
,
2429 .release
= es1371_release_dac
,
2432 /* --------------------------------------------------------------------- */
2434 static ssize_t
es1371_midi_read(struct file
*file
, char __user
*buffer
, size_t count
, loff_t
*ppos
)
2436 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2437 DECLARE_WAITQUEUE(wait
, current
);
2439 unsigned long flags
;
2444 if (!access_ok(VERIFY_WRITE
, buffer
, count
))
2449 add_wait_queue(&s
->midi
.iwait
, &wait
);
2451 spin_lock_irqsave(&s
->lock
, flags
);
2453 cnt
= MIDIINBUF
- ptr
;
2454 if (s
->midi
.icnt
< cnt
)
2457 __set_current_state(TASK_INTERRUPTIBLE
);
2458 spin_unlock_irqrestore(&s
->lock
, flags
);
2462 if (file
->f_flags
& O_NONBLOCK
) {
2468 if (signal_pending(current
)) {
2475 if (copy_to_user(buffer
, s
->midi
.ibuf
+ ptr
, cnt
)) {
2480 ptr
= (ptr
+ cnt
) % MIDIINBUF
;
2481 spin_lock_irqsave(&s
->lock
, flags
);
2483 s
->midi
.icnt
-= cnt
;
2484 spin_unlock_irqrestore(&s
->lock
, flags
);
2490 __set_current_state(TASK_RUNNING
);
2491 remove_wait_queue(&s
->midi
.iwait
, &wait
);
2495 static ssize_t
es1371_midi_write(struct file
*file
, const char __user
*buffer
, size_t count
, loff_t
*ppos
)
2497 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2498 DECLARE_WAITQUEUE(wait
, current
);
2500 unsigned long flags
;
2505 if (!access_ok(VERIFY_READ
, buffer
, count
))
2510 add_wait_queue(&s
->midi
.owait
, &wait
);
2512 spin_lock_irqsave(&s
->lock
, flags
);
2514 cnt
= MIDIOUTBUF
- ptr
;
2515 if (s
->midi
.ocnt
+ cnt
> MIDIOUTBUF
)
2516 cnt
= MIDIOUTBUF
- s
->midi
.ocnt
;
2518 __set_current_state(TASK_INTERRUPTIBLE
);
2519 es1371_handle_midi(s
);
2521 spin_unlock_irqrestore(&s
->lock
, flags
);
2525 if (file
->f_flags
& O_NONBLOCK
) {
2531 if (signal_pending(current
)) {
2538 if (copy_from_user(s
->midi
.obuf
+ ptr
, buffer
, cnt
)) {
2543 ptr
= (ptr
+ cnt
) % MIDIOUTBUF
;
2544 spin_lock_irqsave(&s
->lock
, flags
);
2546 s
->midi
.ocnt
+= cnt
;
2547 spin_unlock_irqrestore(&s
->lock
, flags
);
2551 spin_lock_irqsave(&s
->lock
, flags
);
2552 es1371_handle_midi(s
);
2553 spin_unlock_irqrestore(&s
->lock
, flags
);
2555 __set_current_state(TASK_RUNNING
);
2556 remove_wait_queue(&s
->midi
.owait
, &wait
);
2560 /* No kernel lock - we have our own spinlock */
2561 static unsigned int es1371_midi_poll(struct file
*file
, struct poll_table_struct
*wait
)
2563 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2564 unsigned long flags
;
2565 unsigned int mask
= 0;
2568 if (file
->f_mode
& FMODE_WRITE
)
2569 poll_wait(file
, &s
->midi
.owait
, wait
);
2570 if (file
->f_mode
& FMODE_READ
)
2571 poll_wait(file
, &s
->midi
.iwait
, wait
);
2572 spin_lock_irqsave(&s
->lock
, flags
);
2573 if (file
->f_mode
& FMODE_READ
) {
2574 if (s
->midi
.icnt
> 0)
2575 mask
|= POLLIN
| POLLRDNORM
;
2577 if (file
->f_mode
& FMODE_WRITE
) {
2578 if (s
->midi
.ocnt
< MIDIOUTBUF
)
2579 mask
|= POLLOUT
| POLLWRNORM
;
2581 spin_unlock_irqrestore(&s
->lock
, flags
);
2585 static int es1371_midi_open(struct inode
*inode
, struct file
*file
)
2587 int minor
= iminor(inode
);
2588 DECLARE_WAITQUEUE(wait
, current
);
2589 unsigned long flags
;
2590 struct list_head
*list
;
2591 struct es1371_state
*s
;
2593 for (list
= devs
.next
; ; list
= list
->next
) {
2596 s
= list_entry(list
, struct es1371_state
, devs
);
2597 if (s
->dev_midi
== minor
)
2601 file
->private_data
= s
;
2602 /* wait for device to become free */
2604 while (s
->open_mode
& (file
->f_mode
<< FMODE_MIDI_SHIFT
)) {
2605 if (file
->f_flags
& O_NONBLOCK
) {
2609 add_wait_queue(&s
->open_wait
, &wait
);
2610 __set_current_state(TASK_INTERRUPTIBLE
);
2613 remove_wait_queue(&s
->open_wait
, &wait
);
2614 set_current_state(TASK_RUNNING
);
2615 if (signal_pending(current
))
2616 return -ERESTARTSYS
;
2619 spin_lock_irqsave(&s
->lock
, flags
);
2620 if (!(s
->open_mode
& (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
))) {
2621 s
->midi
.ird
= s
->midi
.iwr
= s
->midi
.icnt
= 0;
2622 s
->midi
.ord
= s
->midi
.owr
= s
->midi
.ocnt
= 0;
2623 outb(UCTRL_CNTRL_SWR
, s
->io
+ES1371_REG_UART_CONTROL
);
2624 outb(0, s
->io
+ES1371_REG_UART_CONTROL
);
2625 outb(0, s
->io
+ES1371_REG_UART_TEST
);
2627 if (file
->f_mode
& FMODE_READ
) {
2628 s
->midi
.ird
= s
->midi
.iwr
= s
->midi
.icnt
= 0;
2630 if (file
->f_mode
& FMODE_WRITE
) {
2631 s
->midi
.ord
= s
->midi
.owr
= s
->midi
.ocnt
= 0;
2633 s
->ctrl
|= CTRL_UART_EN
;
2634 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
2635 es1371_handle_midi(s
);
2636 spin_unlock_irqrestore(&s
->lock
, flags
);
2637 s
->open_mode
|= (file
->f_mode
<< FMODE_MIDI_SHIFT
) & (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
);
2639 return nonseekable_open(inode
, file
);
2642 static int es1371_midi_release(struct inode
*inode
, struct file
*file
)
2644 struct es1371_state
*s
= (struct es1371_state
*)file
->private_data
;
2645 DECLARE_WAITQUEUE(wait
, current
);
2646 unsigned long flags
;
2647 unsigned count
, tmo
;
2651 if (file
->f_mode
& FMODE_WRITE
) {
2652 add_wait_queue(&s
->midi
.owait
, &wait
);
2654 __set_current_state(TASK_INTERRUPTIBLE
);
2655 spin_lock_irqsave(&s
->lock
, flags
);
2656 count
= s
->midi
.ocnt
;
2657 spin_unlock_irqrestore(&s
->lock
, flags
);
2660 if (signal_pending(current
))
2662 if (file
->f_flags
& O_NONBLOCK
)
2664 tmo
= (count
* HZ
) / 3100;
2665 if (!schedule_timeout(tmo
? : 1) && tmo
)
2666 printk(KERN_DEBUG PFX
"midi timed out??\n");
2668 remove_wait_queue(&s
->midi
.owait
, &wait
);
2669 set_current_state(TASK_RUNNING
);
2672 s
->open_mode
&= ~((file
->f_mode
<< FMODE_MIDI_SHIFT
) & (FMODE_MIDI_READ
|FMODE_MIDI_WRITE
));
2673 spin_lock_irqsave(&s
->lock
, flags
);
2674 if (!(s
->open_mode
& (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
))) {
2675 s
->ctrl
&= ~CTRL_UART_EN
;
2676 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
2678 spin_unlock_irqrestore(&s
->lock
, flags
);
2680 wake_up(&s
->open_wait
);
2685 static /*const*/ struct file_operations es1371_midi_fops
= {
2686 .owner
= THIS_MODULE
,
2687 .llseek
= no_llseek
,
2688 .read
= es1371_midi_read
,
2689 .write
= es1371_midi_write
,
2690 .poll
= es1371_midi_poll
,
2691 .open
= es1371_midi_open
,
2692 .release
= es1371_midi_release
,
2695 /* --------------------------------------------------------------------- */
2698 * for debugging purposes, we'll create a proc device that dumps the
2703 static int proc_es1371_dump (char *buf
, char **start
, off_t fpos
, int length
, int *eof
, void *data
)
2705 struct es1371_state
*s
;
2708 if (list_empty(&devs
))
2710 s
= list_entry(devs
.next
, struct es1371_state
, devs
);
2711 /* print out header */
2712 len
+= sprintf(buf
+ len
, "\t\tCreative ES137x Debug Dump-o-matic\n");
2714 /* print out CODEC state */
2715 len
+= sprintf (buf
+ len
, "AC97 CODEC state\n");
2716 for (cnt
=0; cnt
<= 0x7e; cnt
= cnt
+2)
2717 len
+= sprintf (buf
+ len
, "reg:0x%02x val:0x%04x\n", cnt
, rdcodec(s
->codec
, cnt
));
2724 *start
= buf
+ fpos
;
2725 if ((len
-= fpos
) > length
)
2731 #endif /* ES1371_DEBUG */
2733 /* --------------------------------------------------------------------- */
2735 /* maximum number of devices; only used for command line params */
2738 static int spdif
[NR_DEVICE
];
2739 static int nomix
[NR_DEVICE
];
2740 static int amplifier
[NR_DEVICE
];
2742 static unsigned int devindex
;
2744 module_param_array(spdif
, bool, NULL
, 0);
2745 MODULE_PARM_DESC(spdif
, "if 1 the output is in S/PDIF digital mode");
2746 module_param_array(nomix
, bool, NULL
, 0);
2747 MODULE_PARM_DESC(nomix
, "if 1 no analog audio is mixed to the digital output");
2748 module_param_array(amplifier
, bool, NULL
, 0);
2749 MODULE_PARM_DESC(amplifier
, "Set to 1 if the machine needs the amp control enabling (many laptops)");
2751 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
2752 MODULE_DESCRIPTION("ES1371 AudioPCI97 Driver");
2753 MODULE_LICENSE("GPL");
2756 /* --------------------------------------------------------------------- */
2758 static struct initvol
{
2761 } initvol
[] __devinitdata
= {
2762 { SOUND_MIXER_WRITE_LINE
, 0x4040 },
2763 { SOUND_MIXER_WRITE_CD
, 0x4040 },
2764 { MIXER_WRITE(SOUND_MIXER_VIDEO
), 0x4040 },
2765 { SOUND_MIXER_WRITE_LINE1
, 0x4040 },
2766 { SOUND_MIXER_WRITE_PCM
, 0x4040 },
2767 { SOUND_MIXER_WRITE_VOLUME
, 0x4040 },
2768 { MIXER_WRITE(SOUND_MIXER_PHONEOUT
), 0x4040 },
2769 { SOUND_MIXER_WRITE_OGAIN
, 0x4040 },
2770 { MIXER_WRITE(SOUND_MIXER_PHONEIN
), 0x4040 },
2771 { SOUND_MIXER_WRITE_SPEAKER
, 0x4040 },
2772 { SOUND_MIXER_WRITE_MIC
, 0x4040 },
2773 { SOUND_MIXER_WRITE_RECLEV
, 0x4040 },
2774 { SOUND_MIXER_WRITE_IGAIN
, 0x4040 }
2780 } amplifier_needed
[] =
2782 { 0x107B, 0x2150 }, /* Gateway Solo 2150 */
2783 { 0x13BD, 0x100C }, /* Mebius PC-MJ100V */
2784 { 0x1102, 0x5938 }, /* Targa Xtender 300 */
2785 { 0x1102, 0x8938 }, /* IPC notebook */
2786 { PCI_ANY_ID
, PCI_ANY_ID
}
2789 static int __devinit
es1371_probe(struct pci_dev
*pcidev
, const struct pci_device_id
*pciid
)
2791 struct es1371_state
*s
;
2792 struct gameport
*gp
;
2794 int i
, gpio
, val
, res
= -1;
2800 if ((res
=pci_enable_device(pcidev
)))
2803 if (!(pci_resource_flags(pcidev
, 0) & IORESOURCE_IO
))
2805 if (pcidev
->irq
== 0)
2807 i
= pci_set_dma_mask(pcidev
, 0xffffffff);
2809 printk(KERN_WARNING
"es1371: architecture does not support 32bit PCI busmaster DMA\n");
2812 if (!(s
= kmalloc(sizeof(struct es1371_state
), GFP_KERNEL
))) {
2813 printk(KERN_WARNING PFX
"out of memory\n");
2816 memset(s
, 0, sizeof(struct es1371_state
));
2818 s
->codec
= ac97_alloc_codec();
2819 if(s
->codec
== NULL
)
2822 init_waitqueue_head(&s
->dma_adc
.wait
);
2823 init_waitqueue_head(&s
->dma_dac1
.wait
);
2824 init_waitqueue_head(&s
->dma_dac2
.wait
);
2825 init_waitqueue_head(&s
->open_wait
);
2826 init_waitqueue_head(&s
->midi
.iwait
);
2827 init_waitqueue_head(&s
->midi
.owait
);
2828 init_MUTEX(&s
->open_sem
);
2829 spin_lock_init(&s
->lock
);
2830 s
->magic
= ES1371_MAGIC
;
2832 s
->io
= pci_resource_start(pcidev
, 0);
2833 s
->irq
= pcidev
->irq
;
2834 s
->vendor
= pcidev
->vendor
;
2835 s
->device
= pcidev
->device
;
2836 pci_read_config_byte(pcidev
, PCI_REVISION_ID
, &s
->rev
);
2837 s
->codec
->private_data
= s
;
2839 s
->codec
->codec_read
= rdcodec
;
2840 s
->codec
->codec_write
= wrcodec
;
2841 printk(KERN_INFO PFX
"found chip, vendor id 0x%04x device id 0x%04x revision 0x%02x\n",
2842 s
->vendor
, s
->device
, s
->rev
);
2843 if (!request_region(s
->io
, ES1371_EXTENT
, "es1371")) {
2844 printk(KERN_ERR PFX
"io ports %#lx-%#lx in use\n", s
->io
, s
->io
+ES1371_EXTENT
-1);
2848 if ((res
=request_irq(s
->irq
, es1371_interrupt
, SA_SHIRQ
, "es1371",s
))) {
2849 printk(KERN_ERR PFX
"irq %u in use\n", s
->irq
);
2852 printk(KERN_INFO PFX
"found es1371 rev %d at io %#lx irq %u\n",
2853 s
->rev
, s
->io
, s
->irq
);
2854 /* register devices */
2855 if ((res
=(s
->dev_audio
= register_sound_dsp(&es1371_audio_fops
,-1)))<0)
2857 if ((res
=(s
->codec
->dev_mixer
= register_sound_mixer(&es1371_mixer_fops
, -1))) < 0)
2859 if ((res
=(s
->dev_dac
= register_sound_dsp(&es1371_dac_fops
, -1))) < 0)
2861 if ((res
=(s
->dev_midi
= register_sound_midi(&es1371_midi_fops
, -1)))<0 )
2864 /* initialize the debug proc device */
2865 s
->ps
= create_proc_read_entry("es1371",0,NULL
,proc_es1371_dump
,NULL
);
2866 #endif /* ES1371_DEBUG */
2868 /* initialize codec registers */
2871 /* Check amplifier requirements */
2873 if (amplifier
[devindex
])
2874 s
->ctrl
|= CTRL_GPIO_OUT0
;
2875 else for(idx
= 0; amplifier_needed
[idx
].svid
!= PCI_ANY_ID
; idx
++)
2877 if(pcidev
->subsystem_vendor
== amplifier_needed
[idx
].svid
&&
2878 pcidev
->subsystem_device
== amplifier_needed
[idx
].sdid
)
2880 s
->ctrl
|= CTRL_GPIO_OUT0
; /* turn internal amplifier on */
2881 printk(KERN_INFO PFX
"Enabling internal amplifier.\n");
2885 for (gpio
= 0x218; gpio
>= 0x200; gpio
-= 0x08)
2886 if (request_region(gpio
, JOY_EXTENT
, "es1371"))
2890 printk(KERN_ERR PFX
"no free joystick address found\n");
2891 } else if (!(s
->gameport
= gp
= gameport_allocate_port())) {
2892 printk(KERN_ERR PFX
"can not allocate memory for gameport\n");
2893 release_region(gpio
, JOY_EXTENT
);
2895 gameport_set_name(gp
, "ESS1371 Gameport");
2896 gameport_set_phys(gp
, "isa%04x/gameport0", gpio
);
2897 gp
->dev
.parent
= &s
->dev
->dev
;
2899 s
->ctrl
|= CTRL_JYSTK_EN
| (((gpio
>> 3) & CTRL_JOY_MASK
) << CTRL_JOY_SHIFT
);
2904 s
->spdif_volume
= -1;
2905 /* check to see if s/pdif mode is being requested */
2906 if (spdif
[devindex
]) {
2908 printk(KERN_INFO PFX
"enabling S/PDIF output\n");
2909 s
->spdif_volume
= 0;
2910 cssr
|= STAT_EN_SPDIF
;
2911 s
->ctrl
|= CTRL_SPDIFEN_B
;
2912 if (nomix
[devindex
]) /* don't mix analog inputs to s/pdif output */
2913 s
->ctrl
|= CTRL_RECEN_B
;
2915 printk(KERN_ERR PFX
"revision %d does not support S/PDIF\n", s
->rev
);
2918 /* initialize the chips */
2919 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
2920 outl(s
->sctrl
, s
->io
+ES1371_REG_SERIAL_CONTROL
);
2921 outl(LEGACY_JFAST
, s
->io
+ES1371_REG_LEGACY
);
2922 pci_set_master(pcidev
); /* enable bus mastering */
2923 /* if we are a 5880 turn on the AC97 */
2924 if (s
->vendor
== PCI_VENDOR_ID_ENSONIQ
&&
2925 ((s
->device
== PCI_DEVICE_ID_ENSONIQ_CT5880
&& s
->rev
>= CT5880REV_CT5880_C
) ||
2926 (s
->device
== PCI_DEVICE_ID_ENSONIQ_ES1371
&& s
->rev
== ES1371REV_CT5880_A
) ||
2927 (s
->device
== PCI_DEVICE_ID_ENSONIQ_ES1371
&& s
->rev
== ES1371REV_ES1373_8
))) {
2928 cssr
|= CSTAT_5880_AC97_RST
;
2929 outl(cssr
, s
->io
+ES1371_REG_STATUS
);
2930 /* need to delay around 20ms(bleech) to give
2931 some CODECs enough time to wakeup */
2932 tmo
= jiffies
+ (HZ
/ 50) + 1;
2934 tmo2
= tmo
- jiffies
;
2937 schedule_timeout(tmo2
);
2940 /* AC97 warm reset to start the bitclk */
2941 outl(s
->ctrl
| CTRL_SYNCRES
, s
->io
+ES1371_REG_CONTROL
);
2943 outl(s
->ctrl
, s
->io
+ES1371_REG_CONTROL
);
2944 /* init the sample rate converter */
2947 if (!ac97_probe_codec(s
->codec
)) {
2951 /* set default values */
2955 val
= SOUND_MASK_LINE
;
2956 mixdev_ioctl(s
->codec
, SOUND_MIXER_WRITE_RECSRC
, (unsigned long)&val
);
2957 for (i
= 0; i
< sizeof(initvol
)/sizeof(initvol
[0]); i
++) {
2958 val
= initvol
[i
].vol
;
2959 mixdev_ioctl(s
->codec
, initvol
[i
].mixch
, (unsigned long)&val
);
2961 /* mute master and PCM when in S/PDIF mode */
2962 if (s
->spdif_volume
!= -1) {
2964 s
->codec
->mixer_ioctl(s
->codec
, SOUND_MIXER_WRITE_VOLUME
, (unsigned long)&val
);
2965 s
->codec
->mixer_ioctl(s
->codec
, SOUND_MIXER_WRITE_PCM
, (unsigned long)&val
);
2968 /* turn on S/PDIF output driver if requested */
2969 outl(cssr
, s
->io
+ES1371_REG_STATUS
);
2971 /* register gameport */
2973 gameport_register_port(s
->gameport
);
2975 /* store it in the driver field */
2976 pci_set_drvdata(pcidev
, s
);
2977 /* put it into driver list */
2978 list_add_tail(&s
->devs
, &devs
);
2979 /* increment devindex */
2980 if (devindex
< NR_DEVICE
-1)
2986 release_region(s
->gameport
->io
, JOY_EXTENT
);
2987 gameport_free_port(s
->gameport
);
2991 remove_proc_entry("es1371", NULL
);
2993 unregister_sound_midi(s
->dev_midi
);
2995 unregister_sound_dsp(s
->dev_dac
);
2997 unregister_sound_mixer(s
->codec
->dev_mixer
);
2999 unregister_sound_dsp(s
->dev_audio
);
3001 printk(KERN_ERR PFX
"cannot register misc device\n");
3002 free_irq(s
->irq
, s
);
3004 release_region(s
->io
, ES1371_EXTENT
);
3007 ac97_release_codec(s
->codec
);
3012 static void __devexit
es1371_remove(struct pci_dev
*dev
)
3014 struct es1371_state
*s
= pci_get_drvdata(dev
);
3021 remove_proc_entry("es1371", NULL
);
3022 #endif /* ES1371_DEBUG */
3023 outl(0, s
->io
+ES1371_REG_CONTROL
); /* switch everything off */
3024 outl(0, s
->io
+ES1371_REG_SERIAL_CONTROL
); /* clear serial interrupts */
3025 synchronize_irq(s
->irq
);
3026 free_irq(s
->irq
, s
);
3028 int gpio
= s
->gameport
->io
;
3029 gameport_unregister_port(s
->gameport
);
3030 release_region(gpio
, JOY_EXTENT
);
3032 release_region(s
->io
, ES1371_EXTENT
);
3033 unregister_sound_dsp(s
->dev_audio
);
3034 unregister_sound_mixer(s
->codec
->dev_mixer
);
3035 unregister_sound_dsp(s
->dev_dac
);
3036 unregister_sound_midi(s
->dev_midi
);
3037 ac97_release_codec(s
->codec
);
3039 pci_set_drvdata(dev
, NULL
);
3042 static struct pci_device_id id_table
[] = {
3043 { PCI_VENDOR_ID_ENSONIQ
, PCI_DEVICE_ID_ENSONIQ_ES1371
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0 },
3044 { PCI_VENDOR_ID_ENSONIQ
, PCI_DEVICE_ID_ENSONIQ_CT5880
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0 },
3045 { PCI_VENDOR_ID_ECTIVA
, PCI_DEVICE_ID_ECTIVA_EV1938
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0 },
3049 MODULE_DEVICE_TABLE(pci
, id_table
);
3051 static struct pci_driver es1371_driver
= {
3053 .id_table
= id_table
,
3054 .probe
= es1371_probe
,
3055 .remove
= __devexit_p(es1371_remove
),
3058 static int __init
init_es1371(void)
3060 printk(KERN_INFO PFX
"version v0.32 time " __TIME__
" " __DATE__
"\n");
3061 return pci_module_init(&es1371_driver
);
3064 static void __exit
cleanup_es1371(void)
3066 printk(KERN_INFO PFX
"unloading\n");
3067 pci_unregister_driver(&es1371_driver
);
3070 module_init(init_es1371
);
3071 module_exit(cleanup_es1371
);
3073 /* --------------------------------------------------------------------- */
3077 /* format is: es1371=[spdif,[nomix,[amplifier]]] */
3079 static int __init
es1371_setup(char *str
)
3081 static unsigned __initdata nr_dev
= 0;
3083 if (nr_dev
>= NR_DEVICE
)
3087 ((get_option(&str
, &spdif
[nr_dev
]) == 2)
3088 && (get_option(&str
, &nomix
[nr_dev
]) == 2)
3089 && (get_option(&str
, &lifier
[nr_dev
])));
3095 __setup("es1371=", es1371_setup
);