1 /*****************************************************************************/
4 * es1370.c -- Ensoniq ES1370/Asahi Kasei AK4531 audio driver.
6 * Copyright (C) 1998-1999 Thomas Sailer (sailer@ife.ee.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 David C. Niemi
25 * Module command line parameters:
26 * joystick if 1 enables the joystick interface on the card; but it still
27 * needs a driver for joysticks connected to a standard IBM-PC
28 * joyport. It is tested with the joy-analog driver. This
29 * module must be loaded before the joystick driver. Kmod will
31 * lineout if 1 the LINE jack is used as an output instead of an input.
32 * LINE then contains the unmixed dsp output. This can be used
33 * to make the card a four channel one: use dsp to output two
34 * channels to LINE and dac to output the other two channels to
35 * SPKR. Set the mixer to only output synth to SPKR.
36 * micz it looks like this changes the MIC input impedance. I don't know
39 * Note: sync mode is not yet supported (i.e. running dsp and dac from the same
43 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
44 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
45 * /dev/dsp1 additional DAC, like /dev/dsp, but output only,
46 * only 5512, 11025, 22050 and 44100 samples/s,
47 * outputs to mixer "SYNTH" setting
48 * /dev/midi simple MIDI UART interface, no ioctl
50 * NOTE: the card does not have any FM/Wavetable synthesizer, it is supposed
51 * to be done in software. That is what /dev/dac is for. By now (Q2 1998)
52 * there are several MIDI to PCM (WAV) packages, one of them is timidity.
55 * 26.03.98 0.1 Initial release
56 * 31.03.98 0.2 Fix bug in GETOSPACE
57 * 04.04.98 0.3 Make it work (again) under 2.0.33
58 * Fix mixer write operation not returning the actual
60 * 05.04.98 0.4 First attempt at using the new PCI stuff
61 * 29.04.98 0.5 Fix hang when ^C is pressed on amp
62 * 07.05.98 0.6 Don't double lock around stop_*() in *_release()
63 * 10.05.98 0.7 First stab at a simple midi interface (no bells&whistles)
64 * 14.05.98 0.8 Don't allow excessive interrupt rates
65 * 08.06.98 0.9 First release using Alan Cox' soundcore instead of
67 * 05.07.98 0.10 Fixed the driver to correctly maintin OSS style volume
68 * settings (not sure if this should be standard)
69 * Fixed many references: f_flags should be f_mode
70 * -- Gerald Britton <gbritton@mit.edu>
71 * 03.08.98 0.11 Now mixer behaviour can basically be selected between
72 * "OSS documented" and "OSS actual" behaviour
73 * Fixed mixer table thanks to Hakan.Lennestal@lu.erisoft.se
74 * On module startup, set DAC2 to 11kSPS instead of 5.5kSPS,
75 * as it produces an annoying ssssh in the lower sampling rate
76 * Do not include modversions.h
77 * 22.08.98 0.12 Mixer registers actually have 5 instead of 4 bits
78 * pointed out by Itai Nahshon
79 * 31.08.98 0.13 Fix realplayer problems - dac.count issues
80 * 08.10.98 0.14 Joystick support fixed
81 * -- Oliver Neukum <c188@org.chemie.uni-muenchen.de>
82 * 10.12.98 0.15 Fix drain_dac trying to wait on not yet initialized DMA
83 * 16.12.98 0.16 Don't wake up app until there are fragsize bytes to read/write
84 * 06.01.99 0.17 remove the silly SA_INTERRUPT flag.
85 * hopefully killed the egcs section type conflict
86 * 12.03.99 0.18 cinfo.blocks should be reset after GETxPTR ioctl.
87 * reported by Johan Maes <joma@telindus.be>
88 * 22.03.99 0.19 return EAGAIN instead of EBUSY when O_NONBLOCK
89 * read/write cannot be executed
90 * 07.04.99 0.20 implemented the following ioctl's: SOUND_PCM_READ_RATE,
91 * SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
92 * Alpha fixes reported by Peter Jones <pjones@redhat.com>
93 * Note: joystick address handling might still be wrong on archs
96 * some important things missing in Ensoniq documentation:
98 * Experimental PCLKDIV results: play the same waveforms on both DAC1 and DAC2
99 * and vary PCLKDIV to obtain zero beat.
102 * seems to be fs = 1411200/(PCLKDIV+2)
104 * should find out when curr_sample_ct is cleared and
105 * where exactly the CCB fetches data
107 * The card uses a 22.5792 MHz crystal.
108 * The LINEIN jack may be converted to an AOUT jack by
109 * setting pin 47 (XCTL0) of the ES1370 to high.
110 * Pin 48 (XCTL1) of the ES1370 presumably changes the input impedance of the
115 /*****************************************************************************/
117 #include <linux/config.h>
118 #include <linux/version.h>
119 #include <linux/module.h>
120 #include <linux/string.h>
121 #include <linux/ioport.h>
122 #include <linux/sched.h>
123 #include <linux/delay.h>
124 #include <linux/sound.h>
125 #include <linux/malloc.h>
126 #include <linux/soundcard.h>
127 #include <linux/pci.h>
130 #include <linux/init.h>
131 #include <linux/poll.h>
132 #include <asm/spinlock.h>
133 #include <asm/uaccess.h>
134 #include <asm/hardirq.h>
136 /* --------------------------------------------------------------------- */
138 #undef OSS_DOCUMENTED_MIXER_SEMANTICS
140 /*#define DBG(x) {x}*/
142 /* --------------------------------------------------------------------- */
144 #ifndef PCI_VENDOR_ID_ENSONIQ
145 #define PCI_VENDOR_ID_ENSONIQ 0x1274
147 #ifndef PCI_DEVICE_ID_ENSONIQ_ES1370
148 #define PCI_DEVICE_ID_ENSONIQ_ES1370 0x5000
151 #define ES1370_MAGIC ((PCI_VENDOR_ID_ENSONIQ<<16)|PCI_DEVICE_ID_ENSONIQ_ES1370)
153 #define ES1370_EXTENT 0x40
156 #define ES1370_REG_CONTROL 0x00
157 #define ES1370_REG_STATUS 0x04
158 #define ES1370_REG_UART_DATA 0x08
159 #define ES1370_REG_UART_STATUS 0x09
160 #define ES1370_REG_UART_CONTROL 0x09
161 #define ES1370_REG_UART_TEST 0x0a
162 #define ES1370_REG_MEMPAGE 0x0c
163 #define ES1370_REG_CODEC 0x10
164 #define ES1370_REG_SERIAL_CONTROL 0x20
165 #define ES1370_REG_DAC1_SCOUNT 0x24
166 #define ES1370_REG_DAC2_SCOUNT 0x28
167 #define ES1370_REG_ADC_SCOUNT 0x2c
169 #define ES1370_REG_DAC1_FRAMEADR 0xc30
170 #define ES1370_REG_DAC1_FRAMECNT 0xc34
171 #define ES1370_REG_DAC2_FRAMEADR 0xc38
172 #define ES1370_REG_DAC2_FRAMECNT 0xc3c
173 #define ES1370_REG_ADC_FRAMEADR 0xd30
174 #define ES1370_REG_ADC_FRAMECNT 0xd34
176 #define ES1370_FMT_U8_MONO 0
177 #define ES1370_FMT_U8_STEREO 1
178 #define ES1370_FMT_S16_MONO 2
179 #define ES1370_FMT_S16_STEREO 3
180 #define ES1370_FMT_STEREO 1
181 #define ES1370_FMT_S16 2
182 #define ES1370_FMT_MASK 3
184 static const unsigned sample_size
[] = { 1, 2, 2, 4 };
185 static const unsigned sample_shift
[] = { 0, 1, 1, 2 };
187 static const unsigned dac1_samplerate
[] = { 5512, 11025, 22050, 44100 };
189 #define DAC2_SRTODIV(x) (((1411200+(x)/2)/(x))-2)
190 #define DAC2_DIVTOSR(x) (1411200/((x)+2))
192 #define CTRL_ADC_STOP 0x80000000 /* 1 = ADC stopped */
193 #define CTRL_XCTL1 0x40000000 /* ? mic impedance */
194 #define CTRL_OPEN 0x20000000 /* no function, can be read and written */
195 #define CTRL_PCLKDIV 0x1fff0000 /* ADC/DAC2 clock divider */
196 #define CTRL_SH_PCLKDIV 16
197 #define CTRL_MSFMTSEL 0x00008000 /* MPEG serial data fmt: 0 = Sony, 1 = I2S */
198 #define CTRL_M_SBB 0x00004000 /* DAC2 clock: 0 = PCLKDIV, 1 = MPEG */
199 #define CTRL_WTSRSEL 0x00003000 /* DAC1 clock freq: 0=5512, 1=11025, 2=22050, 3=44100 */
200 #define CTRL_SH_WTSRSEL 12
201 #define CTRL_DAC_SYNC 0x00000800 /* 1 = DAC2 runs off DAC1 clock */
202 #define CTRL_CCB_INTRM 0x00000400 /* 1 = CCB "voice" ints enabled */
203 #define CTRL_M_CB 0x00000200 /* recording source: 0 = ADC, 1 = MPEG */
204 #define CTRL_XCTL0 0x00000100 /* 0 = Line in, 1 = Line out */
205 #define CTRL_BREQ 0x00000080 /* 1 = test mode (internal mem test) */
206 #define CTRL_DAC1_EN 0x00000040 /* enable DAC1 */
207 #define CTRL_DAC2_EN 0x00000020 /* enable DAC2 */
208 #define CTRL_ADC_EN 0x00000010 /* enable ADC */
209 #define CTRL_UART_EN 0x00000008 /* enable MIDI uart */
210 #define CTRL_JYSTK_EN 0x00000004 /* enable Joystick port (presumably at address 0x200) */
211 #define CTRL_CDC_EN 0x00000002 /* enable serial (CODEC) interface */
212 #define CTRL_SERR_DIS 0x00000001 /* 1 = disable PCI SERR signal */
214 #define STAT_INTR 0x80000000 /* wired or of all interrupt bits */
215 #define STAT_CSTAT 0x00000400 /* 1 = codec busy or codec write in progress */
216 #define STAT_CBUSY 0x00000200 /* 1 = codec busy */
217 #define STAT_CWRIP 0x00000100 /* 1 = codec write in progress */
218 #define STAT_VC 0x00000060 /* CCB int source, 0=DAC1, 1=DAC2, 2=ADC, 3=undef */
220 #define STAT_MCCB 0x00000010 /* CCB int pending */
221 #define STAT_UART 0x00000008 /* UART int pending */
222 #define STAT_DAC1 0x00000004 /* DAC1 int pending */
223 #define STAT_DAC2 0x00000002 /* DAC2 int pending */
224 #define STAT_ADC 0x00000001 /* ADC int pending */
226 #define USTAT_RXINT 0x80 /* UART rx int pending */
227 #define USTAT_TXINT 0x04 /* UART tx int pending */
228 #define USTAT_TXRDY 0x02 /* UART tx ready */
229 #define USTAT_RXRDY 0x01 /* UART rx ready */
231 #define UCTRL_RXINTEN 0x80 /* 1 = enable RX ints */
232 #define UCTRL_TXINTEN 0x60 /* TX int enable field mask */
233 #define UCTRL_ENA_TXINT 0x20 /* enable TX int */
234 #define UCTRL_CNTRL 0x03 /* control field */
235 #define UCTRL_CNTRL_SWR 0x03 /* software reset command */
237 #define SCTRL_P2ENDINC 0x00380000 /* */
238 #define SCTRL_SH_P2ENDINC 19
239 #define SCTRL_P2STINC 0x00070000 /* */
240 #define SCTRL_SH_P2STINC 16
241 #define SCTRL_R1LOOPSEL 0x00008000 /* 0 = loop mode */
242 #define SCTRL_P2LOOPSEL 0x00004000 /* 0 = loop mode */
243 #define SCTRL_P1LOOPSEL 0x00002000 /* 0 = loop mode */
244 #define SCTRL_P2PAUSE 0x00001000 /* 1 = pause mode */
245 #define SCTRL_P1PAUSE 0x00000800 /* 1 = pause mode */
246 #define SCTRL_R1INTEN 0x00000400 /* enable interrupt */
247 #define SCTRL_P2INTEN 0x00000200 /* enable interrupt */
248 #define SCTRL_P1INTEN 0x00000100 /* enable interrupt */
249 #define SCTRL_P1SCTRLD 0x00000080 /* reload sample count register for DAC1 */
250 #define SCTRL_P2DACSEN 0x00000040 /* 1 = DAC2 play back last sample when disabled */
251 #define SCTRL_R1SEB 0x00000020 /* 1 = 16bit */
252 #define SCTRL_R1SMB 0x00000010 /* 1 = stereo */
253 #define SCTRL_R1FMT 0x00000030 /* format mask */
254 #define SCTRL_SH_R1FMT 4
255 #define SCTRL_P2SEB 0x00000008 /* 1 = 16bit */
256 #define SCTRL_P2SMB 0x00000004 /* 1 = stereo */
257 #define SCTRL_P2FMT 0x0000000c /* format mask */
258 #define SCTRL_SH_P2FMT 2
259 #define SCTRL_P1SEB 0x00000002 /* 1 = 16bit */
260 #define SCTRL_P1SMB 0x00000001 /* 1 = stereo */
261 #define SCTRL_P1FMT 0x00000003 /* format mask */
262 #define SCTRL_SH_P1FMT 0
266 #define FMODE_DAC 4 /* slight misuse of mode_t */
268 /* MIDI buffer sizes */
270 #define MIDIINBUF 256
271 #define MIDIOUTBUF 256
273 #define FMODE_MIDI_SHIFT 3
274 #define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
275 #define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
277 #define SND_DEV_DSP16 5
279 /* --------------------------------------------------------------------- */
281 struct es1370_state
{
285 /* we keep sb cards in a linked list */
286 struct es1370_state
*next
;
288 /* soundcore stuff */
294 /* hardware resources */
295 unsigned long io
; /* long for SPARC */
298 /* mixer registers; there is no HW readback */
300 unsigned short vol
[10];
303 unsigned short micpreamp
;
311 struct semaphore open_sem
;
313 wait_queue_head_t open_wait
;
320 unsigned hwptr
, swptr
;
321 unsigned total_bytes
;
323 unsigned error
; /* over/underrun */
324 wait_queue_head_t wait
;
325 /* redundant, but makes calculations easier */
328 unsigned fragsamples
;
332 unsigned endcleared
:1;
333 unsigned ossfragshift
;
335 unsigned subdivision
;
336 } dma_dac1
, dma_dac2
, dma_adc
;
340 unsigned ird
, iwr
, icnt
;
341 unsigned ord
, owr
, ocnt
;
342 wait_queue_head_t iwait
;
343 wait_queue_head_t owait
;
344 unsigned char ibuf
[MIDIINBUF
];
345 unsigned char obuf
[MIDIOUTBUF
];
349 /* --------------------------------------------------------------------- */
351 static struct es1370_state
*devs
= NULL
;
353 /* --------------------------------------------------------------------- */
355 extern inline unsigned ld2(unsigned int x
)
380 /* --------------------------------------------------------------------- */
382 static void wrcodec(struct es1370_state
*s
, unsigned char idx
, unsigned char data
)
384 unsigned long tmo
= jiffies
+ HZ
/10;
387 if (!(inl(s
->io
+ES1370_REG_STATUS
) & STAT_CSTAT
)) {
388 outw((((unsigned short)idx
)<<8)|data
, s
->io
+ES1370_REG_CODEC
);
392 } while ((signed)(tmo
-jiffies
) > 0);
393 printk(KERN_ERR
"es1370: write to codec register timeout\n");
396 /* --------------------------------------------------------------------- */
398 extern inline void stop_adc(struct es1370_state
*s
)
402 spin_lock_irqsave(&s
->lock
, flags
);
403 s
->ctrl
&= ~CTRL_ADC_EN
;
404 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
405 spin_unlock_irqrestore(&s
->lock
, flags
);
408 extern inline void stop_dac1(struct es1370_state
*s
)
412 spin_lock_irqsave(&s
->lock
, flags
);
413 s
->ctrl
&= ~CTRL_DAC1_EN
;
414 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
415 spin_unlock_irqrestore(&s
->lock
, flags
);
418 extern inline void stop_dac2(struct es1370_state
*s
)
422 spin_lock_irqsave(&s
->lock
, flags
);
423 s
->ctrl
&= ~CTRL_DAC2_EN
;
424 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
425 spin_unlock_irqrestore(&s
->lock
, flags
);
428 static void start_dac1(struct es1370_state
*s
)
431 unsigned fragremain
, fshift
;
433 spin_lock_irqsave(&s
->lock
, flags
);
434 if (!(s
->ctrl
& CTRL_DAC1_EN
) && (s
->dma_dac1
.mapped
|| s
->dma_dac1
.count
> 0)
435 && s
->dma_dac1
.ready
) {
436 s
->ctrl
|= CTRL_DAC1_EN
;
437 s
->sctrl
= (s
->sctrl
& ~(SCTRL_P1LOOPSEL
| SCTRL_P1PAUSE
| SCTRL_P1SCTRLD
)) | SCTRL_P1INTEN
;
438 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
439 fragremain
= ((- s
->dma_dac1
.hwptr
) & (s
->dma_dac1
.fragsize
-1));
440 fshift
= sample_shift
[(s
->sctrl
& SCTRL_P1FMT
) >> SCTRL_SH_P1FMT
];
441 if (fragremain
< 2*fshift
)
442 fragremain
= s
->dma_dac1
.fragsize
;
443 outl((fragremain
>> fshift
) - 1, s
->io
+ES1370_REG_DAC1_SCOUNT
);
444 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
445 outl((s
->dma_dac1
.fragsize
>> fshift
) - 1, s
->io
+ES1370_REG_DAC1_SCOUNT
);
447 spin_unlock_irqrestore(&s
->lock
, flags
);
450 static void start_dac2(struct es1370_state
*s
)
453 unsigned fragremain
, fshift
;
455 spin_lock_irqsave(&s
->lock
, flags
);
456 if (!(s
->ctrl
& CTRL_DAC2_EN
) && (s
->dma_dac2
.mapped
|| s
->dma_dac2
.count
> 0)
457 && s
->dma_dac2
.ready
) {
458 s
->ctrl
|= CTRL_DAC2_EN
;
459 s
->sctrl
= (s
->sctrl
& ~(SCTRL_P2LOOPSEL
| SCTRL_P2PAUSE
| SCTRL_P2DACSEN
|
460 SCTRL_P2ENDINC
| SCTRL_P2STINC
)) | SCTRL_P2INTEN
|
461 (((s
->sctrl
& SCTRL_P2FMT
) ? 2 : 1) << SCTRL_SH_P2ENDINC
) |
462 (0 << SCTRL_SH_P2STINC
);
463 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
464 fragremain
= ((- s
->dma_dac2
.hwptr
) & (s
->dma_dac2
.fragsize
-1));
465 fshift
= sample_shift
[(s
->sctrl
& SCTRL_P2FMT
) >> SCTRL_SH_P2FMT
];
466 if (fragremain
< 2*fshift
)
467 fragremain
= s
->dma_dac2
.fragsize
;
468 outl((fragremain
>> fshift
) - 1, s
->io
+ES1370_REG_DAC2_SCOUNT
);
469 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
470 outl((s
->dma_dac2
.fragsize
>> fshift
) - 1, s
->io
+ES1370_REG_DAC2_SCOUNT
);
472 spin_unlock_irqrestore(&s
->lock
, flags
);
475 static void start_adc(struct es1370_state
*s
)
478 unsigned fragremain
, fshift
;
480 spin_lock_irqsave(&s
->lock
, flags
);
481 if (!(s
->ctrl
& CTRL_ADC_EN
) && (s
->dma_adc
.mapped
|| s
->dma_adc
.count
< (signed)(s
->dma_adc
.dmasize
- 2*s
->dma_adc
.fragsize
))
482 && s
->dma_adc
.ready
) {
483 s
->ctrl
|= CTRL_ADC_EN
;
484 s
->sctrl
= (s
->sctrl
& ~SCTRL_R1LOOPSEL
) | SCTRL_R1INTEN
;
485 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
486 fragremain
= ((- s
->dma_adc
.hwptr
) & (s
->dma_adc
.fragsize
-1));
487 fshift
= sample_shift
[(s
->sctrl
& SCTRL_R1FMT
) >> SCTRL_SH_R1FMT
];
488 if (fragremain
< 2*fshift
)
489 fragremain
= s
->dma_adc
.fragsize
;
490 outl((fragremain
>> fshift
) - 1, s
->io
+ES1370_REG_ADC_SCOUNT
);
491 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
492 outl((s
->dma_adc
.fragsize
>> fshift
) - 1, s
->io
+ES1370_REG_ADC_SCOUNT
);
494 spin_unlock_irqrestore(&s
->lock
, flags
);
497 /* --------------------------------------------------------------------- */
499 #define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
500 #define DMABUF_MINORDER 1
502 extern inline void dealloc_dmabuf(struct dmabuf
*db
)
504 unsigned long map
, mapend
;
507 /* undo marking the pages as reserved */
508 mapend
= MAP_NR(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) - 1);
509 for (map
= MAP_NR(db
->rawbuf
); map
<= mapend
; map
++)
510 clear_bit(PG_reserved
, &mem_map
[map
].flags
);
511 free_pages((unsigned long)db
->rawbuf
, db
->buforder
);
514 db
->mapped
= db
->ready
= 0;
517 static int prog_dmabuf(struct es1370_state
*s
, struct dmabuf
*db
, unsigned rate
, unsigned fmt
, unsigned reg
)
522 unsigned long map
, mapend
;
524 db
->hwptr
= db
->swptr
= db
->total_bytes
= db
->count
= db
->error
= db
->endcleared
= 0;
526 db
->ready
= db
->mapped
= 0;
527 for (order
= DMABUF_DEFAULTORDER
; order
>= DMABUF_MINORDER
&& !db
->rawbuf
; order
--)
528 db
->rawbuf
= (void *)__get_free_pages(GFP_KERNEL
, order
);
531 db
->buforder
= order
;
532 /* now mark the pages as reserved; otherwise remap_page_range doesn't do what we want */
533 mapend
= MAP_NR(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) - 1);
534 for (map
= MAP_NR(db
->rawbuf
); map
<= mapend
; map
++)
535 set_bit(PG_reserved
, &mem_map
[map
].flags
);
537 fmt
&= ES1370_FMT_MASK
;
538 bytepersec
= rate
<< sample_shift
[fmt
];
539 bufs
= PAGE_SIZE
<< db
->buforder
;
540 if (db
->ossfragshift
) {
541 if ((1000 << db
->ossfragshift
) < bytepersec
)
542 db
->fragshift
= ld2(bytepersec
/1000);
544 db
->fragshift
= db
->ossfragshift
;
546 db
->fragshift
= ld2(bytepersec
/100/(db
->subdivision
? db
->subdivision
: 1));
547 if (db
->fragshift
< 3)
550 db
->numfrag
= bufs
>> db
->fragshift
;
551 while (db
->numfrag
< 4 && db
->fragshift
> 3) {
553 db
->numfrag
= bufs
>> db
->fragshift
;
555 db
->fragsize
= 1 << db
->fragshift
;
556 if (db
->ossmaxfrags
>= 4 && db
->ossmaxfrags
< db
->numfrag
)
557 db
->numfrag
= db
->ossmaxfrags
;
558 db
->fragsamples
= db
->fragsize
>> sample_shift
[fmt
];
559 db
->dmasize
= db
->numfrag
<< db
->fragshift
;
560 memset(db
->rawbuf
, (fmt
& ES1370_FMT_S16
) ? 0 : 0x80, db
->dmasize
);
561 outl((reg
>> 8) & 15, s
->io
+ES1370_REG_MEMPAGE
);
562 outl(virt_to_bus(db
->rawbuf
), s
->io
+(reg
& 0xff));
563 outl((db
->dmasize
>> 2)-1, s
->io
+((reg
+ 4) & 0xff));
568 extern inline int prog_dmabuf_adc(struct es1370_state
*s
)
571 return prog_dmabuf(s
, &s
->dma_adc
, DAC2_DIVTOSR((s
->ctrl
& CTRL_PCLKDIV
) >> CTRL_SH_PCLKDIV
),
572 (s
->sctrl
>> SCTRL_SH_R1FMT
) & ES1370_FMT_MASK
, ES1370_REG_ADC_FRAMEADR
);
575 extern inline int prog_dmabuf_dac2(struct es1370_state
*s
)
578 return prog_dmabuf(s
, &s
->dma_dac2
, DAC2_DIVTOSR((s
->ctrl
& CTRL_PCLKDIV
) >> CTRL_SH_PCLKDIV
),
579 (s
->sctrl
>> SCTRL_SH_P2FMT
) & ES1370_FMT_MASK
, ES1370_REG_DAC2_FRAMEADR
);
582 extern inline int prog_dmabuf_dac1(struct es1370_state
*s
)
585 return prog_dmabuf(s
, &s
->dma_dac1
, dac1_samplerate
[(s
->ctrl
& CTRL_WTSRSEL
) >> CTRL_SH_WTSRSEL
],
586 (s
->sctrl
>> SCTRL_SH_P1FMT
) & ES1370_FMT_MASK
, ES1370_REG_DAC1_FRAMEADR
);
589 extern inline unsigned get_hwptr(struct es1370_state
*s
, struct dmabuf
*db
, unsigned reg
)
591 unsigned hwptr
, diff
;
593 outl((reg
>> 8) & 15, s
->io
+ES1370_REG_MEMPAGE
);
594 hwptr
= (inl(s
->io
+(reg
& 0xff)) >> 14) & 0x3fffc;
595 diff
= (db
->dmasize
+ hwptr
- db
->hwptr
) % db
->dmasize
;
600 extern inline void clear_advance(void *buf
, unsigned bsize
, unsigned bptr
, unsigned len
, unsigned char c
)
602 if (bptr
+ len
> bsize
) {
603 unsigned x
= bsize
- bptr
;
604 memset(((char *)buf
) + bptr
, c
, x
);
608 memset(((char *)buf
) + bptr
, c
, len
);
611 /* call with spinlock held! */
612 static void es1370_update_ptr(struct es1370_state
*s
)
616 /* update ADC pointer */
617 if (s
->ctrl
& CTRL_ADC_EN
) {
618 diff
= get_hwptr(s
, &s
->dma_adc
, ES1370_REG_ADC_FRAMECNT
);
619 s
->dma_adc
.total_bytes
+= diff
;
620 s
->dma_adc
.count
+= diff
;
621 if (s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
)
622 wake_up(&s
->dma_adc
.wait
);
623 if (!s
->dma_adc
.mapped
) {
624 if (s
->dma_adc
.count
> (signed)(s
->dma_adc
.dmasize
- ((3 * s
->dma_adc
.fragsize
) >> 1))) {
625 s
->ctrl
&= ~CTRL_ADC_EN
;
626 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
631 /* update DAC1 pointer */
632 if (s
->ctrl
& CTRL_DAC1_EN
) {
633 diff
= get_hwptr(s
, &s
->dma_dac1
, ES1370_REG_DAC1_FRAMECNT
);
634 s
->dma_dac1
.total_bytes
+= diff
;
635 if (s
->dma_dac1
.mapped
) {
636 s
->dma_dac1
.count
+= diff
;
637 if (s
->dma_dac1
.count
>= (signed)s
->dma_dac1
.fragsize
)
638 wake_up(&s
->dma_dac1
.wait
);
640 s
->dma_dac1
.count
-= diff
;
641 if (s
->dma_dac1
.count
<= 0) {
642 s
->ctrl
&= ~CTRL_DAC1_EN
;
643 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
645 } else if (s
->dma_dac1
.count
<= (signed)s
->dma_dac1
.fragsize
&& !s
->dma_dac1
.endcleared
) {
646 clear_advance(s
->dma_dac1
.rawbuf
, s
->dma_dac1
.dmasize
, s
->dma_dac1
.swptr
,
647 s
->dma_dac1
.fragsize
, (s
->sctrl
& SCTRL_P1SEB
) ? 0 : 0x80);
648 s
->dma_dac1
.endcleared
= 1;
650 if (s
->dma_dac1
.count
+ (signed)s
->dma_dac1
.fragsize
<= (signed)s
->dma_dac1
.dmasize
)
651 wake_up(&s
->dma_dac1
.wait
);
654 /* update DAC2 pointer */
655 if (s
->ctrl
& CTRL_DAC2_EN
) {
656 diff
= get_hwptr(s
, &s
->dma_dac2
, ES1370_REG_DAC2_FRAMECNT
);
657 s
->dma_dac2
.total_bytes
+= diff
;
658 if (s
->dma_dac2
.mapped
) {
659 s
->dma_dac2
.count
+= diff
;
660 if (s
->dma_dac2
.count
>= (signed)s
->dma_dac2
.fragsize
)
661 wake_up(&s
->dma_dac2
.wait
);
663 s
->dma_dac2
.count
-= diff
;
664 if (s
->dma_dac2
.count
<= 0) {
665 s
->ctrl
&= ~CTRL_DAC2_EN
;
666 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
668 } else if (s
->dma_dac2
.count
<= (signed)s
->dma_dac2
.fragsize
&& !s
->dma_dac2
.endcleared
) {
669 clear_advance(s
->dma_dac2
.rawbuf
, s
->dma_dac2
.dmasize
, s
->dma_dac2
.swptr
,
670 s
->dma_dac2
.fragsize
, (s
->sctrl
& SCTRL_P2SEB
) ? 0 : 0x80);
671 s
->dma_dac2
.endcleared
= 1;
673 if (s
->dma_dac2
.count
+ (signed)s
->dma_dac2
.fragsize
<= (signed)s
->dma_dac2
.dmasize
)
674 wake_up(&s
->dma_dac2
.wait
);
679 /* hold spinlock for the following! */
680 static void es1370_handle_midi(struct es1370_state
*s
)
685 if (!(s
->ctrl
& CTRL_UART_EN
))
688 while (inb(s
->io
+ES1370_REG_UART_STATUS
) & USTAT_RXRDY
) {
689 ch
= inb(s
->io
+ES1370_REG_UART_DATA
);
690 if (s
->midi
.icnt
< MIDIINBUF
) {
691 s
->midi
.ibuf
[s
->midi
.iwr
] = ch
;
692 s
->midi
.iwr
= (s
->midi
.iwr
+ 1) % MIDIINBUF
;
698 wake_up(&s
->midi
.iwait
);
700 while ((inb(s
->io
+ES1370_REG_UART_STATUS
) & USTAT_TXRDY
) && s
->midi
.ocnt
> 0) {
701 outb(s
->midi
.obuf
[s
->midi
.ord
], s
->io
+ES1370_REG_UART_DATA
);
702 s
->midi
.ord
= (s
->midi
.ord
+ 1) % MIDIOUTBUF
;
704 if (s
->midi
.ocnt
< MIDIOUTBUF
-16)
708 wake_up(&s
->midi
.owait
);
709 outb((s
->midi
.ocnt
> 0) ? UCTRL_RXINTEN
| UCTRL_ENA_TXINT
: UCTRL_RXINTEN
, s
->io
+ES1370_REG_UART_CONTROL
);
712 static void es1370_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
714 struct es1370_state
*s
= (struct es1370_state
*)dev_id
;
715 unsigned int intsrc
, sctl
;
717 /* fastpath out, to ease interrupt sharing */
718 intsrc
= inl(s
->io
+ES1370_REG_STATUS
);
719 if (!(intsrc
& 0x80000000))
722 /* clear audio interrupts first */
724 if (intsrc
& STAT_ADC
)
725 sctl
&= ~SCTRL_R1INTEN
;
726 if (intsrc
& STAT_DAC1
)
727 sctl
&= ~SCTRL_P1INTEN
;
728 if (intsrc
& STAT_DAC2
)
729 sctl
&= ~SCTRL_P2INTEN
;
730 outl(sctl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
731 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
732 es1370_update_ptr(s
);
733 es1370_handle_midi(s
);
734 spin_unlock(&s
->lock
);
737 /* --------------------------------------------------------------------- */
739 static const char invalid_magic
[] = KERN_CRIT
"es1370: invalid magic value\n";
741 #define VALIDATE_STATE(s) \
743 if (!(s) || (s)->magic != ES1370_MAGIC) { \
744 printk(invalid_magic); \
749 /* --------------------------------------------------------------------- */
751 static const struct {
758 } mixtable
[SOUND_MIXER_NRDEVICES
] = {
759 [SOUND_MIXER_VOLUME
] = { 0, 0x0, 0x1, 1, 0x0000, 1 }, /* master */
760 [SOUND_MIXER_PCM
] = { 1, 0x2, 0x3, 1, 0x0400, 1 }, /* voice */
761 [SOUND_MIXER_SYNTH
] = { 2, 0x4, 0x5, 1, 0x0060, 1 }, /* FM */
762 [SOUND_MIXER_CD
] = { 3, 0x6, 0x7, 1, 0x0006, 1 }, /* CD */
763 [SOUND_MIXER_LINE
] = { 4, 0x8, 0x9, 1, 0x0018, 1 }, /* Line */
764 [SOUND_MIXER_LINE1
] = { 5, 0xa, 0xb, 1, 0x1800, 1 }, /* AUX */
765 [SOUND_MIXER_LINE2
] = { 6, 0xc, 0x0, 0, 0x0100, 1 }, /* Mono1 */
766 [SOUND_MIXER_LINE3
] = { 7, 0xd, 0x0, 0, 0x0200, 1 }, /* Mono2 */
767 [SOUND_MIXER_MIC
] = { 8, 0xe, 0x0, 0, 0x0001, 1 }, /* Mic */
768 [SOUND_MIXER_OGAIN
] = { 9, 0xf, 0x0, 0, 0x0000, 1 } /* mono out */
771 static int mixer_ioctl(struct es1370_state
*s
, unsigned int cmd
, unsigned long arg
)
775 unsigned char l
, r
, rl
, rr
;
778 if (cmd
== SOUND_MIXER_PRIVATE1
) {
779 /* enable/disable/query mixer preamp */
780 get_user_ret(val
, (int *)arg
, -EFAULT
);
782 s
->mix
.micpreamp
= !!val
;
783 wrcodec(s
, 0x19, s
->mix
.micpreamp
);
785 return put_user(s
->mix
.micpreamp
, (int *)arg
);
787 if (cmd
== SOUND_MIXER_PRIVATE2
) {
788 /* enable/disable/query use of linein as second lineout */
789 get_user_ret(val
, (int *)arg
, -EFAULT
);
791 spin_lock_irqsave(&s
->lock
, flags
);
793 s
->ctrl
|= CTRL_XCTL0
;
795 s
->ctrl
&= ~CTRL_XCTL0
;
796 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
797 spin_unlock_irqrestore(&s
->lock
, flags
);
799 return put_user((s
->ctrl
& CTRL_XCTL0
) ? 1 : 0, (int *)arg
);
801 if (cmd
== SOUND_MIXER_PRIVATE3
) {
802 /* enable/disable/query microphone impedance setting */
803 get_user_ret(val
, (int *)arg
, -EFAULT
);
805 spin_lock_irqsave(&s
->lock
, flags
);
807 s
->ctrl
|= CTRL_XCTL1
;
809 s
->ctrl
&= ~CTRL_XCTL1
;
810 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
811 spin_unlock_irqrestore(&s
->lock
, flags
);
813 return put_user((s
->ctrl
& CTRL_XCTL1
) ? 1 : 0, (int *)arg
);
815 if (cmd
== SOUND_MIXER_INFO
) {
817 strncpy(info
.id
, "ES1370", sizeof(info
.id
));
818 strncpy(info
.name
, "Ensoniq ES1370", sizeof(info
.name
));
819 info
.modify_counter
= s
->mix
.modcnt
;
820 if (copy_to_user((void *)arg
, &info
, sizeof(info
)))
824 if (cmd
== SOUND_OLD_MIXER_INFO
) {
825 _old_mixer_info info
;
826 strncpy(info
.id
, "ES1370", sizeof(info
.id
));
827 strncpy(info
.name
, "Ensoniq ES1370", sizeof(info
.name
));
828 if (copy_to_user((void *)arg
, &info
, sizeof(info
)))
832 if (cmd
== OSS_GETVERSION
)
833 return put_user(SOUND_VERSION
, (int *)arg
);
834 if (_IOC_TYPE(cmd
) != 'M' || _IOC_SIZE(cmd
) != sizeof(int))
836 if (_IOC_DIR(cmd
) == _IOC_READ
) {
837 switch (_IOC_NR(cmd
)) {
838 case SOUND_MIXER_RECSRC
: /* Arg contains a bit for each recording source */
839 return put_user(s
->mix
.recsrc
, (int *)arg
);
841 case SOUND_MIXER_DEVMASK
: /* Arg contains a bit for each supported device */
842 for (val
= i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
843 if (mixtable
[i
].avail
)
845 return put_user(val
, (int *)arg
);
847 case SOUND_MIXER_RECMASK
: /* Arg contains a bit for each supported recording source */
848 for (val
= i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
849 if (mixtable
[i
].recmask
)
851 return put_user(val
, (int *)arg
);
853 case SOUND_MIXER_STEREODEVS
: /* Mixer channels supporting stereo */
854 for (val
= i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
855 if (mixtable
[i
].stereo
)
857 return put_user(val
, (int *)arg
);
859 case SOUND_MIXER_CAPS
:
860 return put_user(0, (int *)arg
);
864 if (i
>= SOUND_MIXER_NRDEVICES
|| !mixtable
[i
].avail
)
866 return put_user(s
->mix
.vol
[mixtable
[i
].volidx
], (int *)arg
);
869 if (_IOC_DIR(cmd
) != (_IOC_READ
|_IOC_WRITE
))
872 switch (_IOC_NR(cmd
)) {
873 case SOUND_MIXER_RECSRC
: /* Arg contains a bit for each recording source */
874 get_user_ret(val
, (int *)arg
, -EFAULT
);
875 for (j
= i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++) {
876 if (!(val
& (1 << i
)))
878 if (!mixtable
[i
].recmask
) {
882 j
|= mixtable
[i
].recmask
;
885 wrcodec(s
, 0x12, j
& 0xd5);
886 wrcodec(s
, 0x13, j
& 0xaa);
887 wrcodec(s
, 0x14, (j
>> 8) & 0x17);
888 wrcodec(s
, 0x15, (j
>> 8) & 0x0f);
889 i
= (j
& 0x37f) | ((j
<< 1) & 0x3000) | 0xc30;
891 wrcodec(s
, 0x11, i
>> 8);
896 if (i
>= SOUND_MIXER_NRDEVICES
|| !mixtable
[i
].avail
)
898 get_user_ret(val
, (int *)arg
, -EFAULT
);
902 if (mixtable
[i
].stereo
) {
903 r
= (val
>> 8) & 0xff;
910 rl
= 31 - ((l
- 7) / 3);
911 l
= (31 - rl
) * 3 + 7;
917 rr
= 31 - ((r
- 7) / 3);
918 r
= (31 - rr
) * 3 + 7;
920 wrcodec(s
, mixtable
[i
].right
, rr
);
922 if (mixtable
[i
].left
== 15) {
927 rl
= 7 - ((l
- 2) / 14);
928 r
= l
= (7 - rl
) * 14 + 2;
935 rl
= 31 - ((l
- 7) / 3);
936 r
= l
= (31 - rl
) * 3 + 7;
940 wrcodec(s
, mixtable
[i
].left
, rl
);
941 #ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
942 s
->mix
.vol
[mixtable
[i
].volidx
] = ((unsigned int)r
<< 8) | l
;
944 s
->mix
.vol
[mixtable
[i
].volidx
] = val
;
946 return put_user(s
->mix
.vol
[mixtable
[i
].volidx
], (int *)arg
);
950 /* --------------------------------------------------------------------- */
952 static loff_t
es1370_llseek(struct file
*file
, loff_t offset
, int origin
)
957 /* --------------------------------------------------------------------- */
959 static int es1370_open_mixdev(struct inode
*inode
, struct file
*file
)
961 int minor
= MINOR(inode
->i_rdev
);
962 struct es1370_state
*s
= devs
;
964 while (s
&& s
->dev_mixer
!= minor
)
969 file
->private_data
= s
;
974 static int es1370_release_mixdev(struct inode
*inode
, struct file
*file
)
976 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
983 static int es1370_ioctl_mixdev(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
985 return mixer_ioctl((struct es1370_state
*)file
->private_data
, cmd
, arg
);
988 static /*const*/ struct file_operations es1370_mixer_fops
= {
994 &es1370_ioctl_mixdev
,
998 &es1370_release_mixdev
,
1001 NULL
, /* check_media_change */
1002 NULL
, /* revalidate */
1006 /* --------------------------------------------------------------------- */
1008 static int drain_dac1(struct es1370_state
*s
, int nonblock
)
1010 DECLARE_WAITQUEUE(wait
, current
);
1011 unsigned long flags
;
1014 if (s
->dma_dac1
.mapped
|| !s
->dma_dac1
.ready
)
1016 current
->state
= TASK_INTERRUPTIBLE
;
1017 add_wait_queue(&s
->dma_dac1
.wait
, &wait
);
1019 spin_lock_irqsave(&s
->lock
, flags
);
1020 count
= s
->dma_dac1
.count
;
1021 spin_unlock_irqrestore(&s
->lock
, flags
);
1024 if (signal_pending(current
))
1027 remove_wait_queue(&s
->dma_dac1
.wait
, &wait
);
1028 current
->state
= TASK_RUNNING
;
1031 tmo
= (count
* HZ
) / dac1_samplerate
[(s
->ctrl
& CTRL_WTSRSEL
) >> CTRL_SH_WTSRSEL
];
1032 tmo
>>= sample_shift
[(s
->sctrl
& SCTRL_P1FMT
) >> SCTRL_SH_P1FMT
];
1033 if (!schedule_timeout(tmo
? : 1) && tmo
)
1034 DBG(printk(KERN_DEBUG
"es1370: dma timed out??\n");)
1036 remove_wait_queue(&s
->dma_dac1
.wait
, &wait
);
1037 current
->state
= TASK_RUNNING
;
1038 if (signal_pending(current
))
1039 return -ERESTARTSYS
;
1043 static int drain_dac2(struct es1370_state
*s
, int nonblock
)
1045 DECLARE_WAITQUEUE(wait
, current
);
1046 unsigned long flags
;
1049 if (s
->dma_dac2
.mapped
|| !s
->dma_dac2
.ready
)
1051 current
->state
= TASK_INTERRUPTIBLE
;
1052 add_wait_queue(&s
->dma_dac2
.wait
, &wait
);
1054 spin_lock_irqsave(&s
->lock
, flags
);
1055 count
= s
->dma_dac2
.count
;
1056 spin_unlock_irqrestore(&s
->lock
, flags
);
1059 if (signal_pending(current
))
1062 remove_wait_queue(&s
->dma_dac2
.wait
, &wait
);
1063 current
->state
= TASK_RUNNING
;
1066 tmo
= (count
* HZ
) / DAC2_DIVTOSR((s
->ctrl
& CTRL_PCLKDIV
) >> CTRL_SH_PCLKDIV
);
1067 tmo
>>= sample_shift
[(s
->sctrl
& SCTRL_P2FMT
) >> SCTRL_SH_P2FMT
];
1068 if (!schedule_timeout(tmo
? : 1) && tmo
)
1069 DBG(printk(KERN_DEBUG
"es1370: dma timed out??\n");)
1071 remove_wait_queue(&s
->dma_dac2
.wait
, &wait
);
1072 current
->state
= TASK_RUNNING
;
1073 if (signal_pending(current
))
1074 return -ERESTARTSYS
;
1078 /* --------------------------------------------------------------------- */
1080 static ssize_t
es1370_read(struct file
*file
, char *buffer
, size_t count
, loff_t
*ppos
)
1082 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1084 unsigned long flags
;
1089 if (ppos
!= &file
->f_pos
)
1091 if (s
->dma_adc
.mapped
)
1093 if (!s
->dma_adc
.ready
&& (ret
= prog_dmabuf_adc(s
)))
1095 if (!access_ok(VERIFY_WRITE
, buffer
, count
))
1099 spin_lock_irqsave(&s
->lock
, flags
);
1100 swptr
= s
->dma_adc
.swptr
;
1101 cnt
= s
->dma_adc
.dmasize
-swptr
;
1102 if (s
->dma_adc
.count
< cnt
)
1103 cnt
= s
->dma_adc
.count
;
1104 spin_unlock_irqrestore(&s
->lock
, flags
);
1109 if (file
->f_flags
& O_NONBLOCK
)
1110 return ret
? ret
: -EAGAIN
;
1111 interruptible_sleep_on(&s
->dma_adc
.wait
);
1112 if (signal_pending(current
))
1113 return ret
? ret
: -ERESTARTSYS
;
1116 if (copy_to_user(buffer
, s
->dma_adc
.rawbuf
+ swptr
, cnt
))
1117 return ret
? ret
: -EFAULT
;
1118 swptr
= (swptr
+ cnt
) % s
->dma_adc
.dmasize
;
1119 spin_lock_irqsave(&s
->lock
, flags
);
1120 s
->dma_adc
.swptr
= swptr
;
1121 s
->dma_adc
.count
-= cnt
;
1122 spin_unlock_irqrestore(&s
->lock
, flags
);
1131 static ssize_t
es1370_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*ppos
)
1133 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1135 unsigned long flags
;
1140 if (ppos
!= &file
->f_pos
)
1142 if (s
->dma_dac2
.mapped
)
1144 if (!s
->dma_dac2
.ready
&& (ret
= prog_dmabuf_dac2(s
)))
1146 if (!access_ok(VERIFY_READ
, buffer
, count
))
1150 spin_lock_irqsave(&s
->lock
, flags
);
1151 if (s
->dma_dac2
.count
< 0) {
1152 s
->dma_dac2
.count
= 0;
1153 s
->dma_dac2
.swptr
= s
->dma_dac2
.hwptr
;
1155 swptr
= s
->dma_dac2
.swptr
;
1156 cnt
= s
->dma_dac2
.dmasize
-swptr
;
1157 if (s
->dma_dac2
.count
+ cnt
> s
->dma_dac2
.dmasize
)
1158 cnt
= s
->dma_dac2
.dmasize
- s
->dma_dac2
.count
;
1159 spin_unlock_irqrestore(&s
->lock
, flags
);
1164 if (file
->f_flags
& O_NONBLOCK
)
1165 return ret
? ret
: -EAGAIN
;
1166 interruptible_sleep_on(&s
->dma_dac2
.wait
);
1167 if (signal_pending(current
))
1168 return ret
? ret
: -ERESTARTSYS
;
1171 if (copy_from_user(s
->dma_dac2
.rawbuf
+ swptr
, buffer
, cnt
))
1172 return ret
? ret
: -EFAULT
;
1173 swptr
= (swptr
+ cnt
) % s
->dma_dac2
.dmasize
;
1174 spin_lock_irqsave(&s
->lock
, flags
);
1175 s
->dma_dac2
.swptr
= swptr
;
1176 s
->dma_dac2
.count
+= cnt
;
1177 s
->dma_dac2
.endcleared
= 0;
1178 spin_unlock_irqrestore(&s
->lock
, flags
);
1187 static unsigned int es1370_poll(struct file
*file
, struct poll_table_struct
*wait
)
1189 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1190 unsigned long flags
;
1191 unsigned int mask
= 0;
1194 if (file
->f_mode
& FMODE_WRITE
)
1195 poll_wait(file
, &s
->dma_dac2
.wait
, wait
);
1196 if (file
->f_mode
& FMODE_READ
)
1197 poll_wait(file
, &s
->dma_adc
.wait
, wait
);
1198 spin_lock_irqsave(&s
->lock
, flags
);
1199 es1370_update_ptr(s
);
1200 if (file
->f_mode
& FMODE_READ
) {
1201 if (s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
)
1202 mask
|= POLLIN
| POLLRDNORM
;
1204 if (file
->f_mode
& FMODE_WRITE
) {
1205 if (s
->dma_dac2
.mapped
) {
1206 if (s
->dma_dac2
.count
>= (signed)s
->dma_dac2
.fragsize
)
1207 mask
|= POLLOUT
| POLLWRNORM
;
1209 if ((signed)s
->dma_dac2
.dmasize
>= s
->dma_dac2
.count
+ (signed)s
->dma_dac2
.fragsize
)
1210 mask
|= POLLOUT
| POLLWRNORM
;
1213 spin_unlock_irqrestore(&s
->lock
, flags
);
1217 static int es1370_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1219 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1225 if (vma
->vm_flags
& VM_WRITE
) {
1226 if ((ret
= prog_dmabuf_dac2(s
)) != 0)
1229 } else if (vma
->vm_flags
& VM_READ
) {
1230 if ((ret
= prog_dmabuf_adc(s
)) != 0)
1235 if (vma
->vm_offset
!= 0)
1237 size
= vma
->vm_end
- vma
->vm_start
;
1238 if (size
> (PAGE_SIZE
<< db
->buforder
))
1240 if (remap_page_range(vma
->vm_start
, virt_to_phys(db
->rawbuf
), size
, vma
->vm_page_prot
))
1246 static int es1370_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1248 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1249 unsigned long flags
;
1250 audio_buf_info abinfo
;
1252 int val
, mapped
, ret
;
1255 mapped
= ((file
->f_mode
& FMODE_WRITE
) && s
->dma_dac2
.mapped
) ||
1256 ((file
->f_mode
& FMODE_READ
) && s
->dma_adc
.mapped
);
1258 case OSS_GETVERSION
:
1259 return put_user(SOUND_VERSION
, (int *)arg
);
1261 case SNDCTL_DSP_SYNC
:
1262 if (file
->f_mode
& FMODE_WRITE
)
1263 return drain_dac2(s
, 0/*file->f_flags & O_NONBLOCK*/);
1266 case SNDCTL_DSP_SETDUPLEX
:
1269 case SNDCTL_DSP_GETCAPS
:
1270 return put_user(DSP_CAP_DUPLEX
| DSP_CAP_REALTIME
| DSP_CAP_TRIGGER
| DSP_CAP_MMAP
, (int *)arg
);
1272 case SNDCTL_DSP_RESET
:
1273 if (file
->f_mode
& FMODE_WRITE
) {
1276 s
->dma_dac2
.swptr
= s
->dma_dac2
.hwptr
= s
->dma_dac2
.count
= s
->dma_dac2
.total_bytes
= 0;
1278 if (file
->f_mode
& FMODE_READ
) {
1281 s
->dma_adc
.swptr
= s
->dma_adc
.hwptr
= s
->dma_adc
.count
= s
->dma_adc
.total_bytes
= 0;
1285 case SNDCTL_DSP_SPEED
:
1286 get_user_ret(val
, (int *)arg
, -EFAULT
);
1288 if (s
->open_mode
& (~file
->f_mode
) & (FMODE_READ
|FMODE_WRITE
))
1296 s
->dma_adc
.ready
= s
->dma_dac2
.ready
= 0;
1297 spin_lock_irqsave(&s
->lock
, flags
);
1298 s
->ctrl
= (s
->ctrl
& ~CTRL_PCLKDIV
) | (DAC2_SRTODIV(val
) << CTRL_SH_PCLKDIV
);
1299 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
1300 spin_unlock_irqrestore(&s
->lock
, flags
);
1302 return put_user(DAC2_DIVTOSR((s
->ctrl
& CTRL_PCLKDIV
) >> CTRL_SH_PCLKDIV
), (int *)arg
);
1304 case SNDCTL_DSP_STEREO
:
1305 get_user_ret(val
, (int *)arg
, -EFAULT
);
1306 if (file
->f_mode
& FMODE_READ
) {
1308 s
->dma_adc
.ready
= 0;
1309 spin_lock_irqsave(&s
->lock
, flags
);
1311 s
->sctrl
|= SCTRL_R1SMB
;
1313 s
->sctrl
&= ~SCTRL_R1SMB
;
1314 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1315 spin_unlock_irqrestore(&s
->lock
, flags
);
1317 if (file
->f_mode
& FMODE_WRITE
) {
1319 s
->dma_dac2
.ready
= 0;
1320 spin_lock_irqsave(&s
->lock
, flags
);
1322 s
->sctrl
|= SCTRL_P2SMB
;
1324 s
->sctrl
&= ~SCTRL_P2SMB
;
1325 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1326 spin_unlock_irqrestore(&s
->lock
, flags
);
1330 case SNDCTL_DSP_CHANNELS
:
1331 get_user_ret(val
, (int *)arg
, -EFAULT
);
1333 if (file
->f_mode
& FMODE_READ
) {
1335 s
->dma_adc
.ready
= 0;
1336 spin_lock_irqsave(&s
->lock
, flags
);
1338 s
->sctrl
|= SCTRL_R1SMB
;
1340 s
->sctrl
&= ~SCTRL_R1SMB
;
1341 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1342 spin_unlock_irqrestore(&s
->lock
, flags
);
1344 if (file
->f_mode
& FMODE_WRITE
) {
1346 s
->dma_dac2
.ready
= 0;
1347 spin_lock_irqsave(&s
->lock
, flags
);
1349 s
->sctrl
|= SCTRL_P2SMB
;
1351 s
->sctrl
&= ~SCTRL_P2SMB
;
1352 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1353 spin_unlock_irqrestore(&s
->lock
, flags
);
1356 return put_user((s
->sctrl
& ((file
->f_mode
& FMODE_READ
) ? SCTRL_R1SMB
: SCTRL_P2SMB
)) ? 2 : 1, (int *)arg
);
1358 case SNDCTL_DSP_GETFMTS
: /* Returns a mask */
1359 return put_user(AFMT_S16_LE
|AFMT_U8
, (int *)arg
);
1361 case SNDCTL_DSP_SETFMT
: /* Selects ONE fmt*/
1362 get_user_ret(val
, (int *)arg
, -EFAULT
);
1363 if (val
!= AFMT_QUERY
) {
1364 if (file
->f_mode
& FMODE_READ
) {
1366 s
->dma_adc
.ready
= 0;
1367 spin_lock_irqsave(&s
->lock
, flags
);
1368 if (val
== AFMT_S16_LE
)
1369 s
->sctrl
|= SCTRL_R1SEB
;
1371 s
->sctrl
&= ~SCTRL_R1SEB
;
1372 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1373 spin_unlock_irqrestore(&s
->lock
, flags
);
1375 if (file
->f_mode
& FMODE_WRITE
) {
1377 s
->dma_dac2
.ready
= 0;
1378 spin_lock_irqsave(&s
->lock
, flags
);
1379 if (val
== AFMT_S16_LE
)
1380 s
->sctrl
|= SCTRL_P2SEB
;
1382 s
->sctrl
&= ~SCTRL_P2SEB
;
1383 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1384 spin_unlock_irqrestore(&s
->lock
, flags
);
1387 return put_user((s
->sctrl
& ((file
->f_mode
& FMODE_READ
) ? SCTRL_R1SEB
: SCTRL_P2SEB
)) ?
1388 AFMT_S16_LE
: AFMT_U8
, (int *)arg
);
1390 case SNDCTL_DSP_POST
:
1393 case SNDCTL_DSP_GETTRIGGER
:
1395 if (file
->f_mode
& FMODE_READ
&& s
->ctrl
& CTRL_ADC_EN
)
1396 val
|= PCM_ENABLE_INPUT
;
1397 if (file
->f_mode
& FMODE_WRITE
&& s
->ctrl
& CTRL_DAC2_EN
)
1398 val
|= PCM_ENABLE_OUTPUT
;
1399 return put_user(val
, (int *)arg
);
1401 case SNDCTL_DSP_SETTRIGGER
:
1402 get_user_ret(val
, (int *)arg
, -EFAULT
);
1403 if (file
->f_mode
& FMODE_READ
) {
1404 if (val
& PCM_ENABLE_INPUT
) {
1405 if (!s
->dma_adc
.ready
&& (ret
= prog_dmabuf_adc(s
)))
1411 if (file
->f_mode
& FMODE_WRITE
) {
1412 if (val
& PCM_ENABLE_OUTPUT
) {
1413 if (!s
->dma_dac2
.ready
&& (ret
= prog_dmabuf_dac2(s
)))
1421 case SNDCTL_DSP_GETOSPACE
:
1422 if (!(file
->f_mode
& FMODE_WRITE
))
1424 if (!(s
->ctrl
& CTRL_DAC2_EN
) && (val
= prog_dmabuf_dac2(s
)) != 0)
1426 spin_lock_irqsave(&s
->lock
, flags
);
1427 es1370_update_ptr(s
);
1428 abinfo
.fragsize
= s
->dma_dac2
.fragsize
;
1429 abinfo
.bytes
= s
->dma_dac2
.dmasize
- s
->dma_dac2
.count
;
1430 abinfo
.fragstotal
= s
->dma_dac2
.numfrag
;
1431 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_dac2
.fragshift
;
1432 spin_unlock_irqrestore(&s
->lock
, flags
);
1433 return copy_to_user((void *)arg
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
1435 case SNDCTL_DSP_GETISPACE
:
1436 if (!(file
->f_mode
& FMODE_READ
))
1438 if (!(s
->ctrl
& CTRL_ADC_EN
) && (val
= prog_dmabuf_adc(s
)) != 0)
1440 spin_lock_irqsave(&s
->lock
, flags
);
1441 es1370_update_ptr(s
);
1442 abinfo
.fragsize
= s
->dma_adc
.fragsize
;
1443 abinfo
.bytes
= s
->dma_adc
.count
;
1444 abinfo
.fragstotal
= s
->dma_adc
.numfrag
;
1445 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_adc
.fragshift
;
1446 spin_unlock_irqrestore(&s
->lock
, flags
);
1447 return copy_to_user((void *)arg
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
1449 case SNDCTL_DSP_NONBLOCK
:
1450 file
->f_flags
|= O_NONBLOCK
;
1453 case SNDCTL_DSP_GETODELAY
:
1454 if (!(file
->f_mode
& FMODE_WRITE
))
1456 spin_lock_irqsave(&s
->lock
, flags
);
1457 es1370_update_ptr(s
);
1458 val
= s
->dma_dac2
.count
;
1459 spin_unlock_irqrestore(&s
->lock
, flags
);
1460 return put_user(val
, (int *)arg
);
1462 case SNDCTL_DSP_GETIPTR
:
1463 if (!(file
->f_mode
& FMODE_READ
))
1465 spin_lock_irqsave(&s
->lock
, flags
);
1466 es1370_update_ptr(s
);
1467 cinfo
.bytes
= s
->dma_adc
.total_bytes
;
1468 cinfo
.blocks
= s
->dma_adc
.count
>> s
->dma_adc
.fragshift
;
1469 cinfo
.ptr
= s
->dma_adc
.hwptr
;
1470 if (s
->dma_adc
.mapped
)
1471 s
->dma_adc
.count
&= s
->dma_adc
.fragsize
-1;
1472 spin_unlock_irqrestore(&s
->lock
, flags
);
1473 return copy_to_user((void *)arg
, &cinfo
, sizeof(cinfo
));
1475 case SNDCTL_DSP_GETOPTR
:
1476 if (!(file
->f_mode
& FMODE_WRITE
))
1478 spin_lock_irqsave(&s
->lock
, flags
);
1479 es1370_update_ptr(s
);
1480 cinfo
.bytes
= s
->dma_dac2
.total_bytes
;
1481 cinfo
.blocks
= s
->dma_dac2
.count
>> s
->dma_dac2
.fragshift
;
1482 cinfo
.ptr
= s
->dma_dac2
.hwptr
;
1483 if (s
->dma_dac2
.mapped
)
1484 s
->dma_dac2
.count
&= s
->dma_dac2
.fragsize
-1;
1485 spin_unlock_irqrestore(&s
->lock
, flags
);
1486 return copy_to_user((void *)arg
, &cinfo
, sizeof(cinfo
));
1488 case SNDCTL_DSP_GETBLKSIZE
:
1489 if (file
->f_mode
& FMODE_WRITE
) {
1490 if ((val
= prog_dmabuf_dac2(s
)))
1492 return put_user(s
->dma_dac2
.fragsize
, (int *)arg
);
1494 if ((val
= prog_dmabuf_adc(s
)))
1496 return put_user(s
->dma_adc
.fragsize
, (int *)arg
);
1498 case SNDCTL_DSP_SETFRAGMENT
:
1499 get_user_ret(val
, (int *)arg
, -EFAULT
);
1500 if (file
->f_mode
& FMODE_READ
) {
1501 s
->dma_adc
.ossfragshift
= val
& 0xffff;
1502 s
->dma_adc
.ossmaxfrags
= (val
>> 16) & 0xffff;
1503 if (s
->dma_adc
.ossfragshift
< 4)
1504 s
->dma_adc
.ossfragshift
= 4;
1505 if (s
->dma_adc
.ossfragshift
> 15)
1506 s
->dma_adc
.ossfragshift
= 15;
1507 if (s
->dma_adc
.ossmaxfrags
< 4)
1508 s
->dma_adc
.ossmaxfrags
= 4;
1510 if (file
->f_mode
& FMODE_WRITE
) {
1511 s
->dma_dac2
.ossfragshift
= val
& 0xffff;
1512 s
->dma_dac2
.ossmaxfrags
= (val
>> 16) & 0xffff;
1513 if (s
->dma_dac2
.ossfragshift
< 4)
1514 s
->dma_dac2
.ossfragshift
= 4;
1515 if (s
->dma_dac2
.ossfragshift
> 15)
1516 s
->dma_dac2
.ossfragshift
= 15;
1517 if (s
->dma_dac2
.ossmaxfrags
< 4)
1518 s
->dma_dac2
.ossmaxfrags
= 4;
1522 case SNDCTL_DSP_SUBDIVIDE
:
1523 if ((file
->f_mode
& FMODE_READ
&& s
->dma_adc
.subdivision
) ||
1524 (file
->f_mode
& FMODE_WRITE
&& s
->dma_dac2
.subdivision
))
1526 get_user_ret(val
, (int *)arg
, -EFAULT
);
1527 if (val
!= 1 && val
!= 2 && val
!= 4)
1529 if (file
->f_mode
& FMODE_READ
)
1530 s
->dma_adc
.subdivision
= val
;
1531 if (file
->f_mode
& FMODE_WRITE
)
1532 s
->dma_dac2
.subdivision
= val
;
1535 case SOUND_PCM_READ_RATE
:
1536 return put_user(DAC2_DIVTOSR((s
->ctrl
& CTRL_PCLKDIV
) >> CTRL_SH_PCLKDIV
), (int *)arg
);
1538 case SOUND_PCM_READ_CHANNELS
:
1539 return put_user((s
->sctrl
& ((file
->f_mode
& FMODE_READ
) ? SCTRL_R1SMB
: SCTRL_P2SMB
)) ?
1542 case SOUND_PCM_READ_BITS
:
1543 return put_user((s
->sctrl
& ((file
->f_mode
& FMODE_READ
) ? SCTRL_R1SEB
: SCTRL_P2SEB
)) ?
1544 16 : 8, (int *)arg
);
1546 case SOUND_PCM_WRITE_FILTER
:
1547 case SNDCTL_DSP_SETSYNCRO
:
1548 case SOUND_PCM_READ_FILTER
:
1552 return mixer_ioctl(s
, cmd
, arg
);
1555 static int es1370_open(struct inode
*inode
, struct file
*file
)
1557 int minor
= MINOR(inode
->i_rdev
);
1558 struct es1370_state
*s
= devs
;
1559 unsigned long flags
;
1561 while (s
&& ((s
->dev_audio
^ minor
) & ~0xf))
1566 file
->private_data
= s
;
1567 /* wait for device to become free */
1569 while (s
->open_mode
& file
->f_mode
) {
1570 if (file
->f_flags
& O_NONBLOCK
) {
1575 interruptible_sleep_on(&s
->open_wait
);
1576 if (signal_pending(current
))
1577 return -ERESTARTSYS
;
1580 spin_lock_irqsave(&s
->lock
, flags
);
1581 if (!(s
->open_mode
& (FMODE_READ
|FMODE_WRITE
)))
1582 s
->ctrl
= (s
->ctrl
& ~CTRL_PCLKDIV
) | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV
);
1583 if (file
->f_mode
& FMODE_READ
) {
1584 s
->dma_adc
.ossfragshift
= s
->dma_adc
.ossmaxfrags
= s
->dma_adc
.subdivision
= 0;
1585 s
->sctrl
&= ~SCTRL_R1FMT
;
1586 if ((minor
& 0xf) == SND_DEV_DSP16
)
1587 s
->sctrl
|= ES1370_FMT_S16_MONO
<< SCTRL_SH_R1FMT
;
1589 s
->sctrl
|= ES1370_FMT_U8_MONO
<< SCTRL_SH_R1FMT
;
1591 if (file
->f_mode
& FMODE_WRITE
) {
1592 s
->dma_dac2
.ossfragshift
= s
->dma_dac2
.ossmaxfrags
= s
->dma_dac2
.subdivision
= 0;
1593 s
->sctrl
&= ~SCTRL_P2FMT
;
1594 if ((minor
& 0xf) == SND_DEV_DSP16
)
1595 s
->sctrl
|= ES1370_FMT_S16_MONO
<< SCTRL_SH_P2FMT
;
1597 s
->sctrl
|= ES1370_FMT_U8_MONO
<< SCTRL_SH_P2FMT
;
1599 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1600 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
1601 spin_unlock_irqrestore(&s
->lock
, flags
);
1602 s
->open_mode
|= file
->f_mode
& (FMODE_READ
| FMODE_WRITE
);
1608 static int es1370_release(struct inode
*inode
, struct file
*file
)
1610 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1613 if (file
->f_mode
& FMODE_WRITE
)
1614 drain_dac2(s
, file
->f_flags
& O_NONBLOCK
);
1616 if (file
->f_mode
& FMODE_WRITE
) {
1619 dealloc_dmabuf(&s
->dma_dac2
);
1621 if (file
->f_mode
& FMODE_READ
) {
1623 dealloc_dmabuf(&s
->dma_adc
);
1625 s
->open_mode
&= (~file
->f_mode
) & (FMODE_READ
|FMODE_WRITE
);
1627 wake_up(&s
->open_wait
);
1632 static /*const*/ struct file_operations es1370_audio_fops
= {
1645 NULL
, /* check_media_change */
1646 NULL
, /* revalidate */
1650 /* --------------------------------------------------------------------- */
1652 static ssize_t
es1370_write_dac(struct file
*file
, const char *buffer
, size_t count
, loff_t
*ppos
)
1654 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1656 unsigned long flags
;
1661 if (ppos
!= &file
->f_pos
)
1663 if (s
->dma_dac1
.mapped
)
1665 if (!s
->dma_dac1
.ready
&& (ret
= prog_dmabuf_dac1(s
)))
1667 if (!access_ok(VERIFY_READ
, buffer
, count
))
1670 spin_lock_irqsave(&s
->lock
, flags
);
1671 if (s
->dma_dac1
.count
< 0) {
1672 s
->dma_dac1
.count
= 0;
1673 s
->dma_dac1
.swptr
= s
->dma_dac1
.hwptr
;
1675 swptr
= s
->dma_dac1
.swptr
;
1676 cnt
= s
->dma_dac1
.dmasize
-swptr
;
1677 if (s
->dma_dac1
.count
+ cnt
> s
->dma_dac1
.dmasize
)
1678 cnt
= s
->dma_dac1
.dmasize
- s
->dma_dac1
.count
;
1679 spin_unlock_irqrestore(&s
->lock
, flags
);
1684 if (file
->f_flags
& O_NONBLOCK
)
1685 return ret
? ret
: -EAGAIN
;
1686 interruptible_sleep_on(&s
->dma_dac1
.wait
);
1687 if (signal_pending(current
))
1688 return ret
? ret
: -ERESTARTSYS
;
1691 if (copy_from_user(s
->dma_dac1
.rawbuf
+ swptr
, buffer
, cnt
))
1692 return ret
? ret
: -EFAULT
;
1693 swptr
= (swptr
+ cnt
) % s
->dma_dac1
.dmasize
;
1694 spin_lock_irqsave(&s
->lock
, flags
);
1695 s
->dma_dac1
.swptr
= swptr
;
1696 s
->dma_dac1
.count
+= cnt
;
1697 s
->dma_dac1
.endcleared
= 0;
1698 spin_unlock_irqrestore(&s
->lock
, flags
);
1707 static unsigned int es1370_poll_dac(struct file
*file
, struct poll_table_struct
*wait
)
1709 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1710 unsigned long flags
;
1711 unsigned int mask
= 0;
1714 poll_wait(file
, &s
->dma_dac1
.wait
, wait
);
1715 spin_lock_irqsave(&s
->lock
, flags
);
1716 es1370_update_ptr(s
);
1717 if (s
->dma_dac1
.mapped
) {
1718 if (s
->dma_dac1
.count
>= (signed)s
->dma_dac1
.fragsize
)
1719 mask
|= POLLOUT
| POLLWRNORM
;
1721 if ((signed)s
->dma_dac1
.dmasize
>= s
->dma_dac1
.count
+ (signed)s
->dma_dac1
.fragsize
)
1722 mask
|= POLLOUT
| POLLWRNORM
;
1724 spin_unlock_irqrestore(&s
->lock
, flags
);
1728 static int es1370_mmap_dac(struct file
*file
, struct vm_area_struct
*vma
)
1730 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1735 if (!(vma
->vm_flags
& VM_WRITE
))
1737 if ((ret
= prog_dmabuf_dac1(s
)) != 0)
1739 if (vma
->vm_offset
!= 0)
1741 size
= vma
->vm_end
- vma
->vm_start
;
1742 if (size
> (PAGE_SIZE
<< s
->dma_dac1
.buforder
))
1744 if (remap_page_range(vma
->vm_start
, virt_to_phys(s
->dma_dac1
.rawbuf
), size
, vma
->vm_page_prot
))
1746 s
->dma_dac1
.mapped
= 1;
1750 static int es1370_ioctl_dac(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1752 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1753 unsigned long flags
;
1754 audio_buf_info abinfo
;
1761 case OSS_GETVERSION
:
1762 return put_user(SOUND_VERSION
, (int *)arg
);
1764 case SNDCTL_DSP_SYNC
:
1765 return drain_dac1(s
, 0/*file->f_flags & O_NONBLOCK*/);
1767 case SNDCTL_DSP_SETDUPLEX
:
1770 case SNDCTL_DSP_GETCAPS
:
1771 return put_user(DSP_CAP_REALTIME
| DSP_CAP_TRIGGER
| DSP_CAP_MMAP
, (int *)arg
);
1773 case SNDCTL_DSP_RESET
:
1776 s
->dma_dac1
.swptr
= s
->dma_dac1
.hwptr
= s
->dma_dac1
.count
= s
->dma_dac1
.total_bytes
= 0;
1779 case SNDCTL_DSP_SPEED
:
1780 get_user_ret(val
, (int *)arg
, -EFAULT
);
1783 s
->dma_dac1
.ready
= 0;
1784 for (ctrl
= 0; ctrl
<= 2; ctrl
++)
1785 if (val
< (dac1_samplerate
[ctrl
] + dac1_samplerate
[ctrl
+1]) / 2)
1787 spin_lock_irqsave(&s
->lock
, flags
);
1788 s
->ctrl
= (s
->ctrl
& ~CTRL_WTSRSEL
) | (ctrl
<< CTRL_SH_WTSRSEL
);
1789 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
1790 spin_unlock_irqrestore(&s
->lock
, flags
);
1792 return put_user(dac1_samplerate
[(s
->ctrl
& CTRL_WTSRSEL
) >> CTRL_SH_WTSRSEL
], (int *)arg
);
1794 case SNDCTL_DSP_STEREO
:
1795 get_user_ret(val
, (int *)arg
, -EFAULT
);
1797 s
->dma_dac1
.ready
= 0;
1798 spin_lock_irqsave(&s
->lock
, flags
);
1800 s
->sctrl
|= SCTRL_P1SMB
;
1802 s
->sctrl
&= ~SCTRL_P1SMB
;
1803 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1804 spin_unlock_irqrestore(&s
->lock
, flags
);
1807 case SNDCTL_DSP_CHANNELS
:
1808 get_user_ret(val
, (int *)arg
, -EFAULT
);
1810 if (s
->dma_dac1
.mapped
)
1813 s
->dma_dac1
.ready
= 0;
1814 spin_lock_irqsave(&s
->lock
, flags
);
1816 s
->sctrl
|= SCTRL_P1SMB
;
1818 s
->sctrl
&= ~SCTRL_P1SMB
;
1819 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1820 spin_unlock_irqrestore(&s
->lock
, flags
);
1822 return put_user((s
->sctrl
& SCTRL_P1SMB
) ? 2 : 1, (int *)arg
);
1824 case SNDCTL_DSP_GETFMTS
: /* Returns a mask */
1825 return put_user(AFMT_S16_LE
|AFMT_U8
, (int *)arg
);
1827 case SNDCTL_DSP_SETFMT
: /* Selects ONE fmt*/
1828 get_user_ret(val
, (int *)arg
, -EFAULT
);
1829 if (val
!= AFMT_QUERY
) {
1831 s
->dma_dac1
.ready
= 0;
1832 spin_lock_irqsave(&s
->lock
, flags
);
1833 if (val
== AFMT_S16_LE
)
1834 s
->sctrl
|= SCTRL_P1SEB
;
1836 s
->sctrl
&= ~SCTRL_P1SEB
;
1837 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1838 spin_unlock_irqrestore(&s
->lock
, flags
);
1840 return put_user((s
->sctrl
& SCTRL_P1SEB
) ? AFMT_S16_LE
: AFMT_U8
, (int *)arg
);
1842 case SNDCTL_DSP_POST
:
1845 case SNDCTL_DSP_GETTRIGGER
:
1846 return put_user((s
->ctrl
& CTRL_DAC1_EN
) ? PCM_ENABLE_OUTPUT
: 0, (int *)arg
);
1848 case SNDCTL_DSP_SETTRIGGER
:
1849 get_user_ret(val
, (int *)arg
, -EFAULT
);
1850 if (val
& PCM_ENABLE_OUTPUT
) {
1851 if (!s
->dma_dac1
.ready
&& (ret
= prog_dmabuf_dac1(s
)))
1858 case SNDCTL_DSP_GETOSPACE
:
1859 if (!(s
->ctrl
& CTRL_DAC2_EN
) && (val
= prog_dmabuf_dac1(s
)) != 0)
1861 spin_lock_irqsave(&s
->lock
, flags
);
1862 es1370_update_ptr(s
);
1863 abinfo
.fragsize
= s
->dma_dac1
.fragsize
;
1864 abinfo
.bytes
= s
->dma_dac1
.dmasize
- s
->dma_dac1
.count
;
1865 abinfo
.fragstotal
= s
->dma_dac1
.numfrag
;
1866 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_dac1
.fragshift
;
1867 spin_unlock_irqrestore(&s
->lock
, flags
);
1868 return copy_to_user((void *)arg
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
1870 case SNDCTL_DSP_NONBLOCK
:
1871 file
->f_flags
|= O_NONBLOCK
;
1874 case SNDCTL_DSP_GETODELAY
:
1875 spin_lock_irqsave(&s
->lock
, flags
);
1876 es1370_update_ptr(s
);
1877 val
= s
->dma_dac1
.count
;
1878 spin_unlock_irqrestore(&s
->lock
, flags
);
1879 return put_user(val
, (int *)arg
);
1881 case SNDCTL_DSP_GETOPTR
:
1882 if (!(file
->f_mode
& FMODE_WRITE
))
1884 spin_lock_irqsave(&s
->lock
, flags
);
1885 es1370_update_ptr(s
);
1886 cinfo
.bytes
= s
->dma_dac1
.total_bytes
;
1887 cinfo
.blocks
= s
->dma_dac1
.count
>> s
->dma_dac1
.fragshift
;
1888 cinfo
.ptr
= s
->dma_dac1
.hwptr
;
1889 if (s
->dma_dac1
.mapped
)
1890 s
->dma_dac1
.count
&= s
->dma_dac1
.fragsize
-1;
1891 spin_unlock_irqrestore(&s
->lock
, flags
);
1892 return copy_to_user((void *)arg
, &cinfo
, sizeof(cinfo
));
1894 case SNDCTL_DSP_GETBLKSIZE
:
1895 if ((val
= prog_dmabuf_dac1(s
)))
1897 return put_user(s
->dma_dac1
.fragsize
, (int *)arg
);
1899 case SNDCTL_DSP_SETFRAGMENT
:
1900 get_user_ret(val
, (int *)arg
, -EFAULT
);
1901 s
->dma_dac1
.ossfragshift
= val
& 0xffff;
1902 s
->dma_dac1
.ossmaxfrags
= (val
>> 16) & 0xffff;
1903 if (s
->dma_dac1
.ossfragshift
< 4)
1904 s
->dma_dac1
.ossfragshift
= 4;
1905 if (s
->dma_dac1
.ossfragshift
> 15)
1906 s
->dma_dac1
.ossfragshift
= 15;
1907 if (s
->dma_dac1
.ossmaxfrags
< 4)
1908 s
->dma_dac1
.ossmaxfrags
= 4;
1911 case SNDCTL_DSP_SUBDIVIDE
:
1912 if (s
->dma_dac1
.subdivision
)
1914 get_user_ret(val
, (int *)arg
, -EFAULT
);
1915 if (val
!= 1 && val
!= 2 && val
!= 4)
1917 s
->dma_dac1
.subdivision
= val
;
1920 case SOUND_PCM_READ_RATE
:
1921 return put_user(dac1_samplerate
[(s
->ctrl
& CTRL_WTSRSEL
) >> CTRL_SH_WTSRSEL
], (int *)arg
);
1923 case SOUND_PCM_READ_CHANNELS
:
1924 return put_user((s
->sctrl
& SCTRL_P1SMB
) ? 2 : 1, (int *)arg
);
1926 case SOUND_PCM_READ_BITS
:
1927 return put_user((s
->sctrl
& SCTRL_P1SEB
) ? 16 : 8, (int *)arg
);
1929 case SOUND_PCM_WRITE_FILTER
:
1930 case SNDCTL_DSP_SETSYNCRO
:
1931 case SOUND_PCM_READ_FILTER
:
1935 return mixer_ioctl(s
, cmd
, arg
);
1938 static int es1370_open_dac(struct inode
*inode
, struct file
*file
)
1940 int minor
= MINOR(inode
->i_rdev
);
1941 struct es1370_state
*s
= devs
;
1942 unsigned long flags
;
1944 while (s
&& ((s
->dev_dac
^ minor
) & ~0xf))
1949 /* we allow opening with O_RDWR, most programs do it although they will only write */
1951 if (file
->f_mode
& FMODE_READ
)
1954 if (!(file
->f_mode
& FMODE_WRITE
))
1956 file
->private_data
= s
;
1957 /* wait for device to become free */
1959 while (s
->open_mode
& FMODE_DAC
) {
1960 if (file
->f_flags
& O_NONBLOCK
) {
1965 interruptible_sleep_on(&s
->open_wait
);
1966 if (signal_pending(current
))
1967 return -ERESTARTSYS
;
1970 s
->dma_dac1
.ossfragshift
= s
->dma_dac1
.ossmaxfrags
= s
->dma_dac1
.subdivision
= 0;
1971 spin_lock_irqsave(&s
->lock
, flags
);
1972 s
->ctrl
= (s
->ctrl
& ~CTRL_WTSRSEL
) | (1 << CTRL_SH_WTSRSEL
);
1973 s
->sctrl
&= ~SCTRL_P1FMT
;
1974 if ((minor
& 0xf) == SND_DEV_DSP16
)
1975 s
->sctrl
|= ES1370_FMT_S16_MONO
<< SCTRL_SH_P1FMT
;
1977 s
->sctrl
|= ES1370_FMT_U8_MONO
<< SCTRL_SH_P1FMT
;
1978 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
1979 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
1980 spin_unlock_irqrestore(&s
->lock
, flags
);
1981 s
->open_mode
|= FMODE_DAC
;
1987 static int es1370_release_dac(struct inode
*inode
, struct file
*file
)
1989 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
1992 drain_dac1(s
, file
->f_flags
& O_NONBLOCK
);
1995 dealloc_dmabuf(&s
->dma_dac1
);
1996 s
->open_mode
&= ~FMODE_DAC
;
1998 wake_up(&s
->open_wait
);
2003 static /*const*/ struct file_operations es1370_dac_fops
= {
2013 &es1370_release_dac
,
2016 NULL
, /* check_media_change */
2017 NULL
, /* revalidate */
2021 /* --------------------------------------------------------------------- */
2023 static ssize_t
es1370_midi_read(struct file
*file
, char *buffer
, size_t count
, loff_t
*ppos
)
2025 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
2027 unsigned long flags
;
2032 if (ppos
!= &file
->f_pos
)
2034 if (!access_ok(VERIFY_WRITE
, buffer
, count
))
2038 spin_lock_irqsave(&s
->lock
, flags
);
2040 cnt
= MIDIINBUF
- ptr
;
2041 if (s
->midi
.icnt
< cnt
)
2043 spin_unlock_irqrestore(&s
->lock
, flags
);
2047 if (file
->f_flags
& O_NONBLOCK
)
2048 return ret
? ret
: -EAGAIN
;
2049 interruptible_sleep_on(&s
->midi
.iwait
);
2050 if (signal_pending(current
))
2051 return ret
? ret
: -ERESTARTSYS
;
2054 if (copy_to_user(buffer
, s
->midi
.ibuf
+ ptr
, cnt
))
2055 return ret
? ret
: -EFAULT
;
2056 ptr
= (ptr
+ cnt
) % MIDIINBUF
;
2057 spin_lock_irqsave(&s
->lock
, flags
);
2059 s
->midi
.icnt
-= cnt
;
2060 spin_unlock_irqrestore(&s
->lock
, flags
);
2068 static ssize_t
es1370_midi_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*ppos
)
2070 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
2072 unsigned long flags
;
2077 if (ppos
!= &file
->f_pos
)
2079 if (!access_ok(VERIFY_READ
, buffer
, count
))
2083 spin_lock_irqsave(&s
->lock
, flags
);
2085 cnt
= MIDIOUTBUF
- ptr
;
2086 if (s
->midi
.ocnt
+ cnt
> MIDIOUTBUF
)
2087 cnt
= MIDIOUTBUF
- s
->midi
.ocnt
;
2089 es1370_handle_midi(s
);
2090 spin_unlock_irqrestore(&s
->lock
, flags
);
2094 if (file
->f_flags
& O_NONBLOCK
)
2095 return ret
? ret
: -EAGAIN
;
2096 interruptible_sleep_on(&s
->midi
.owait
);
2097 if (signal_pending(current
))
2098 return ret
? ret
: -ERESTARTSYS
;
2101 if (copy_from_user(s
->midi
.obuf
+ ptr
, buffer
, cnt
))
2102 return ret
? ret
: -EFAULT
;
2103 ptr
= (ptr
+ cnt
) % MIDIOUTBUF
;
2104 spin_lock_irqsave(&s
->lock
, flags
);
2106 s
->midi
.ocnt
+= cnt
;
2107 spin_unlock_irqrestore(&s
->lock
, flags
);
2111 spin_lock_irqsave(&s
->lock
, flags
);
2112 es1370_handle_midi(s
);
2113 spin_unlock_irqrestore(&s
->lock
, flags
);
2118 static unsigned int es1370_midi_poll(struct file
*file
, struct poll_table_struct
*wait
)
2120 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
2121 unsigned long flags
;
2122 unsigned int mask
= 0;
2125 if (file
->f_mode
& FMODE_WRITE
)
2126 poll_wait(file
, &s
->midi
.owait
, wait
);
2127 if (file
->f_mode
& FMODE_READ
)
2128 poll_wait(file
, &s
->midi
.iwait
, wait
);
2129 spin_lock_irqsave(&s
->lock
, flags
);
2130 if (file
->f_mode
& FMODE_READ
) {
2131 if (s
->midi
.icnt
> 0)
2132 mask
|= POLLIN
| POLLRDNORM
;
2134 if (file
->f_mode
& FMODE_WRITE
) {
2135 if (s
->midi
.ocnt
< MIDIOUTBUF
)
2136 mask
|= POLLOUT
| POLLWRNORM
;
2138 spin_unlock_irqrestore(&s
->lock
, flags
);
2142 static int es1370_midi_open(struct inode
*inode
, struct file
*file
)
2144 int minor
= MINOR(inode
->i_rdev
);
2145 struct es1370_state
*s
= devs
;
2146 unsigned long flags
;
2148 while (s
&& s
->dev_midi
!= minor
)
2153 file
->private_data
= s
;
2154 /* wait for device to become free */
2156 while (s
->open_mode
& (file
->f_mode
<< FMODE_MIDI_SHIFT
)) {
2157 if (file
->f_flags
& O_NONBLOCK
) {
2162 interruptible_sleep_on(&s
->open_wait
);
2163 if (signal_pending(current
))
2164 return -ERESTARTSYS
;
2167 spin_lock_irqsave(&s
->lock
, flags
);
2168 if (!(s
->open_mode
& (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
))) {
2169 s
->midi
.ird
= s
->midi
.iwr
= s
->midi
.icnt
= 0;
2170 s
->midi
.ord
= s
->midi
.owr
= s
->midi
.ocnt
= 0;
2171 outb(UCTRL_CNTRL_SWR
, s
->io
+ES1370_REG_UART_CONTROL
);
2172 outb(0, s
->io
+ES1370_REG_UART_CONTROL
);
2173 outb(0, s
->io
+ES1370_REG_UART_TEST
);
2175 if (file
->f_mode
& FMODE_READ
) {
2176 s
->midi
.ird
= s
->midi
.iwr
= s
->midi
.icnt
= 0;
2178 if (file
->f_mode
& FMODE_WRITE
) {
2179 s
->midi
.ord
= s
->midi
.owr
= s
->midi
.ocnt
= 0;
2181 s
->ctrl
|= CTRL_UART_EN
;
2182 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
2183 es1370_handle_midi(s
);
2184 spin_unlock_irqrestore(&s
->lock
, flags
);
2185 s
->open_mode
|= (file
->f_mode
<< FMODE_MIDI_SHIFT
) & (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
);
2191 static int es1370_midi_release(struct inode
*inode
, struct file
*file
)
2193 struct es1370_state
*s
= (struct es1370_state
*)file
->private_data
;
2194 DECLARE_WAITQUEUE(wait
, current
);
2195 unsigned long flags
;
2196 unsigned count
, tmo
;
2200 if (file
->f_mode
& FMODE_WRITE
) {
2201 current
->state
= TASK_INTERRUPTIBLE
;
2202 add_wait_queue(&s
->midi
.owait
, &wait
);
2204 spin_lock_irqsave(&s
->lock
, flags
);
2205 count
= s
->midi
.ocnt
;
2206 spin_unlock_irqrestore(&s
->lock
, flags
);
2209 if (signal_pending(current
))
2211 if (file
->f_flags
& O_NONBLOCK
) {
2212 remove_wait_queue(&s
->midi
.owait
, &wait
);
2213 current
->state
= TASK_RUNNING
;
2216 tmo
= (count
* HZ
) / 3100;
2217 if (!schedule_timeout(tmo
? : 1) && tmo
)
2218 DBG(printk(KERN_DEBUG
"es1370: midi timed out??\n");)
2220 remove_wait_queue(&s
->midi
.owait
, &wait
);
2221 current
->state
= TASK_RUNNING
;
2224 s
->open_mode
&= (~(file
->f_mode
<< FMODE_MIDI_SHIFT
)) & (FMODE_MIDI_READ
|FMODE_MIDI_WRITE
);
2225 spin_lock_irqsave(&s
->lock
, flags
);
2226 if (!(s
->open_mode
& (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
))) {
2227 s
->ctrl
&= ~CTRL_UART_EN
;
2228 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
2230 spin_unlock_irqrestore(&s
->lock
, flags
);
2232 wake_up(&s
->open_wait
);
2237 static /*const*/ struct file_operations es1370_midi_fops
= {
2247 &es1370_midi_release
,
2250 NULL
, /* check_media_change */
2251 NULL
, /* revalidate */
2255 /* --------------------------------------------------------------------- */
2257 /* maximum number of devices */
2259 #ifdef CONFIG_SOUND_ES1370_JOYPORT_BOOT
2260 static int joystick
[NR_DEVICE
] = { 1, 0, };
2262 static int joystick
[NR_DEVICE
] = { 0, };
2264 static int lineout
[NR_DEVICE
] = { 0, };
2265 static int micz
[NR_DEVICE
] = { 0, };
2267 /* --------------------------------------------------------------------- */
2269 static struct initvol
{
2272 } initvol
[] __initdata
= {
2273 { SOUND_MIXER_WRITE_VOLUME
, 0x4040 },
2274 { SOUND_MIXER_WRITE_PCM
, 0x4040 },
2275 { SOUND_MIXER_WRITE_SYNTH
, 0x4040 },
2276 { SOUND_MIXER_WRITE_CD
, 0x4040 },
2277 { SOUND_MIXER_WRITE_LINE
, 0x4040 },
2278 { SOUND_MIXER_WRITE_LINE1
, 0x4040 },
2279 { SOUND_MIXER_WRITE_LINE2
, 0x4040 },
2280 { SOUND_MIXER_WRITE_LINE3
, 0x4040 },
2281 { SOUND_MIXER_WRITE_MIC
, 0x4040 },
2282 { SOUND_MIXER_WRITE_OGAIN
, 0x4040 }
2286 __initfunc(int init_module(void))
2288 __initfunc(int init_es1370(void))
2291 struct es1370_state
*s
;
2292 struct pci_dev
*pcidev
= NULL
;
2294 int i
, val
, index
= 0;
2296 if (!pci_present()) /* No PCI bus in this machine! */
2298 printk(KERN_INFO
"es1370: version v0.20 time " __TIME__
" " __DATE__
"\n");
2299 while (index
< NR_DEVICE
&&
2300 (pcidev
= pci_find_device(PCI_VENDOR_ID_ENSONIQ
, PCI_DEVICE_ID_ENSONIQ_ES1370
, pcidev
))) {
2301 if (pcidev
->base_address
[0] == 0 ||
2302 (pcidev
->base_address
[0] & PCI_BASE_ADDRESS_SPACE
) != PCI_BASE_ADDRESS_SPACE_IO
)
2304 if (pcidev
->irq
== 0)
2306 if (!(s
= kmalloc(sizeof(struct es1370_state
), GFP_KERNEL
))) {
2307 printk(KERN_WARNING
"es1370: out of memory\n");
2310 memset(s
, 0, sizeof(struct es1370_state
));
2311 init_waitqueue_head(&s
->dma_adc
.wait
);
2312 init_waitqueue_head(&s
->dma_dac1
.wait
);
2313 init_waitqueue_head(&s
->dma_dac2
.wait
);
2314 init_waitqueue_head(&s
->open_wait
);
2315 init_waitqueue_head(&s
->midi
.iwait
);
2316 init_waitqueue_head(&s
->midi
.owait
);
2317 s
->open_sem
= MUTEX
;
2318 s
->magic
= ES1370_MAGIC
;
2319 s
->io
= pcidev
->base_address
[0] & PCI_BASE_ADDRESS_IO_MASK
;
2320 s
->irq
= pcidev
->irq
;
2321 if (check_region(s
->io
, ES1370_EXTENT
)) {
2322 printk(KERN_ERR
"es1370: io ports %#lx-%#lx in use\n", s
->io
, s
->io
+ES1370_EXTENT
-1);
2325 request_region(s
->io
, ES1370_EXTENT
, "es1370");
2326 if (request_irq(s
->irq
, es1370_interrupt
, SA_SHIRQ
, "es1370", s
)) {
2327 printk(KERN_ERR
"es1370: irq %u in use\n", s
->irq
);
2330 /* initialize codec registers */
2331 s
->ctrl
= CTRL_CDC_EN
| CTRL_SERR_DIS
| (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV
) | (1 << CTRL_SH_WTSRSEL
);
2332 if (joystick
[index
]) {
2333 if (check_region(0x200, JOY_EXTENT
))
2334 printk(KERN_ERR
"es1370: io port 0x200 in use\n");
2336 s
->ctrl
|= CTRL_JYSTK_EN
;
2339 s
->ctrl
|= CTRL_XCTL0
;
2341 s
->ctrl
|= CTRL_XCTL1
;
2343 printk(KERN_INFO
"es1370: found adapter at io %#lx irq %u\n"
2344 KERN_INFO
"es1370: features: joystick %s, line %s, mic impedance %s\n",
2345 s
->io
, s
->irq
, (s
->ctrl
& CTRL_JYSTK_EN
) ? "on" : "off",
2346 (s
->ctrl
& CTRL_XCTL0
) ? "out" : "in",
2347 (s
->ctrl
& CTRL_XCTL1
) ? "1" : "0");
2348 /* register devices */
2349 if ((s
->dev_audio
= register_sound_dsp(&es1370_audio_fops
, -1)) < 0)
2351 if ((s
->dev_mixer
= register_sound_mixer(&es1370_mixer_fops
, -1)) < 0)
2353 if ((s
->dev_dac
= register_sound_dsp(&es1370_dac_fops
, -1)) < 0)
2355 if ((s
->dev_midi
= register_sound_midi(&es1370_midi_fops
, -1)) < 0)
2357 /* initialize the chips */
2358 outl(s
->ctrl
, s
->io
+ES1370_REG_CONTROL
);
2359 outl(s
->sctrl
, s
->io
+ES1370_REG_SERIAL_CONTROL
);
2360 wrcodec(s
, 0x16, 3); /* no RST, PD */
2361 wrcodec(s
, 0x17, 0); /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off the LRCLK2 PLL; program DAC_SYNC=0!! */
2362 wrcodec(s
, 0x18, 0); /* recording source is mixer */
2363 wrcodec(s
, 0x19, s
->mix
.micpreamp
= 1); /* turn on MIC preamp */
2366 val
= SOUND_MASK_LINE
|SOUND_MASK_SYNTH
|SOUND_MASK_CD
;
2367 mixer_ioctl(s
, SOUND_MIXER_WRITE_RECSRC
, (unsigned long)&val
);
2368 for (i
= 0; i
< sizeof(initvol
)/sizeof(initvol
[0]); i
++) {
2369 val
= initvol
[i
].vol
;
2370 mixer_ioctl(s
, initvol
[i
].mixch
, (unsigned long)&val
);
2373 /* queue it for later freeing */
2380 unregister_sound_dsp(s
->dev_dac
);
2382 unregister_sound_mixer(s
->dev_mixer
);
2384 unregister_sound_dsp(s
->dev_audio
);
2386 printk(KERN_ERR
"es1370: cannot register misc device\n");
2387 free_irq(s
->irq
, s
);
2389 release_region(s
->io
, ES1370_EXTENT
);
2391 kfree_s(s
, sizeof(struct es1370_state
));
2398 /* --------------------------------------------------------------------- */
2402 MODULE_PARM(joystick
, "1-" __MODULE_STRING(NR_DEVICE
) "i");
2403 MODULE_PARM_DESC(joystick
, "if 1 enables joystick interface (still need separate driver)");
2404 MODULE_PARM(lineout
, "1-" __MODULE_STRING(NR_DEVICE
) "i");
2405 MODULE_PARM_DESC(lineout
, "if 1 the LINE input is converted to LINE out");
2406 MODULE_PARM(micz
, "1-" __MODULE_STRING(NR_DEVICE
) "i");
2407 MODULE_PARM_DESC(micz
, "changes (??) the microphone impedance");
2409 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
2410 MODULE_DESCRIPTION("ES1370 AudioPCI Driver");
2412 void cleanup_module(void)
2414 struct es1370_state
*s
;
2416 while ((s
= devs
)) {
2418 outl(CTRL_SERR_DIS
| (1 << CTRL_SH_WTSRSEL
), s
->io
+ES1370_REG_CONTROL
); /* switch everything off */
2419 outl(0, s
->io
+ES1370_REG_SERIAL_CONTROL
); /* clear serial interrupts */
2421 free_irq(s
->irq
, s
);
2422 release_region(s
->io
, ES1370_EXTENT
);
2423 unregister_sound_dsp(s
->dev_audio
);
2424 unregister_sound_mixer(s
->dev_mixer
);
2425 unregister_sound_dsp(s
->dev_dac
);
2426 unregister_sound_midi(s
->dev_midi
);
2427 kfree_s(s
, sizeof(struct es1370_state
));
2429 printk(KERN_INFO
"es1370: unloading\n");