1 /****************************************************************************/
4 * esssolo1.c -- ESS Technology Solo1 (ES1946) audio driver.
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 * Module command line parameters:
26 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
27 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
28 * /dev/midi simple MIDI UART interface, no ioctl
31 * 10.11.1998 0.1 Initial release (without any hardware)
32 * 22.03.1999 0.2 cinfo.blocks should be reset after GETxPTR ioctl.
33 * reported by Johan Maes <joma@telindus.be>
34 * return EAGAIN instead of EBUSY when O_NONBLOCK
35 * read/write cannot be executed
36 * 07.04.1999 0.3 implemented the following ioctl's: SOUND_PCM_READ_RATE,
37 * SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
38 * Alpha fixes reported by Peter Jones <pjones@redhat.com>
39 * 15.06.1999 0.4 Fix bad allocation bug.
40 * Thanks to Deti Fliegl <fliegl@in.tum.de>
41 * 28.06.1999 0.5 Add pci_set_master
42 * 12.08.1999 0.6 Fix MIDI UART crashing the driver
43 * Changed mixer semantics from OSS documented
44 * behaviour to OSS "code behaviour".
45 * Recording might actually work now.
46 * The real DDMA controller address register is at PCI config
47 * 0x60, while the register at 0x18 is used as a placeholder
48 * register for BIOS address allocation. This register
49 * is supposed to be copied into 0x60, according
50 * to the Solo1 datasheet. When I do that, I can access
51 * the DDMA registers except the mask bit, which
52 * is stuck at 1. When I copy the contents of 0x18 +0x10
53 * to the DDMA base register, everything seems to work.
54 * The fun part is that the Windows Solo1 driver doesn't
55 * seem to do these tricks.
56 * Bugs remaining: plops and clicks when starting/stopping playback
57 * 31.08.1999 0.7 add spin_lock_init
58 * replaced current->state = x with set_current_state(x)
59 * 03.09.1999 0.8 change read semantics for MIDI to match
60 * OSS more closely; remove possible wakeup race
61 * 07.10.1999 0.9 Fix initialization; complain if sequencer writes time out
62 * Revised resource grabbing for the FM synthesizer
63 * 28.10.1999 0.10 More waitqueue races fixed
64 * 09.12.1999 0.11 Work around stupid Alpha port issue (virt_to_bus(kmalloc(GFP_DMA)) > 16M)
65 * Disabling recording on Alpha
66 * 12.01.2000 0.12 Prevent some ioctl's from returning bad count values on underrun/overrun;
67 * Tim Janik's BSE (Bedevilled Sound Engine) found this
68 * Integrated (aka redid 8-)) APM support patch by Zach Brown
69 * 07.02.2000 0.13 Use pci_alloc_consistent and pci_register_driver
70 * 19.02.2000 0.14 Use pci_dma_supported to determine if recording should be disabled
71 * 13.03.2000 0.15 Reintroduce initialization of a couple of PCI config space registers
72 * 21.11.2000 0.16 Initialize dma buffers in poll, otherwise poll may return a bogus mask
73 * 12.12.2000 0.17 More dma buffer initializations, patch from
74 * Tjeerd Mulder <tjeerd.mulder@fujitsu-siemens.com>
75 * 31.01.2001 0.18 Register/Unregister gameport, original patch from
76 * Nathaniel Daw <daw@cs.cmu.edu>
77 * Fix SETTRIGGER non OSS API conformity
78 * 10.03.2001 provide abs function, prevent picking up a bogus kernel macro
79 * for abs. Bug report by Andrew Morton <andrewm@uow.edu.au>
80 * 15.05.2001 pci_enable_device moved, return values in probe cleaned
81 * up. Marcus Meissner <mm@caldera.de>
82 * 22.05.2001 0.19 more cleanups, changed PM to PCI 2.4 style, got rid
83 * of global list of devices, using pci device data.
84 * Marcus Meissner <mm@caldera.de>
85 * 03.01.2003 0.20 open_mode fixes from Georg Acher <acher@in.tum.de>
88 /*****************************************************************************/
90 #include <linux/interrupt.h>
91 #include <linux/module.h>
92 #include <linux/string.h>
93 #include <linux/ioport.h>
94 #include <linux/sched.h>
95 #include <linux/delay.h>
96 #include <linux/sound.h>
97 #include <linux/slab.h>
98 #include <linux/soundcard.h>
99 #include <linux/pci.h>
100 #include <linux/bitops.h>
101 #include <linux/init.h>
102 #include <linux/poll.h>
103 #include <linux/spinlock.h>
104 #include <linux/smp_lock.h>
105 #include <linux/gameport.h>
106 #include <linux/wait.h>
107 #include <linux/dma-mapping.h>
110 #include <asm/page.h>
111 #include <asm/uaccess.h>
115 /* --------------------------------------------------------------------- */
117 #undef OSS_DOCUMENTED_MIXER_SEMANTICS
119 /* --------------------------------------------------------------------- */
121 #ifndef PCI_VENDOR_ID_ESS
122 #define PCI_VENDOR_ID_ESS 0x125d
124 #ifndef PCI_DEVICE_ID_ESS_SOLO1
125 #define PCI_DEVICE_ID_ESS_SOLO1 0x1969
128 #define SOLO1_MAGIC ((PCI_VENDOR_ID_ESS<<16)|PCI_DEVICE_ID_ESS_SOLO1)
130 #define DDMABASE_OFFSET 0 /* chip bug workaround kludge */
131 #define DDMABASE_EXTENT 16
133 #define IOBASE_EXTENT 16
134 #define SBBASE_EXTENT 16
135 #define VCBASE_EXTENT (DDMABASE_EXTENT+DDMABASE_OFFSET)
136 #define MPUBASE_EXTENT 4
137 #define GPBASE_EXTENT 4
138 #define GAMEPORT_EXTENT 4
140 #define FMSYNTH_EXTENT 4
142 /* MIDI buffer sizes */
144 #define MIDIINBUF 256
145 #define MIDIOUTBUF 256
147 #define FMODE_MIDI_SHIFT 3
148 #define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
149 #define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
151 #define FMODE_DMFM 0x10
153 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
154 #define SUPPORT_JOYSTICK 1
157 static struct pci_driver solo1_driver
;
159 /* --------------------------------------------------------------------- */
165 /* the corresponding pci_dev structure */
168 /* soundcore stuff */
174 /* hardware resources */
175 unsigned long iobase
, sbbase
, vcbase
, ddmabase
, mpubase
; /* long for SPARC */
178 /* mixer registers */
180 unsigned short vol
[10];
183 unsigned short micpreamp
;
190 unsigned char clkdiv
;
194 struct semaphore open_sem
;
196 wait_queue_head_t open_wait
;
204 unsigned hwptr
, swptr
;
205 unsigned total_bytes
;
207 unsigned error
; /* over/underrun */
208 wait_queue_head_t wait
;
209 /* redundant, but makes calculations easier */
212 unsigned fragsamples
;
216 unsigned endcleared
:1;
218 unsigned ossfragshift
;
220 unsigned subdivision
;
225 unsigned ird
, iwr
, icnt
;
226 unsigned ord
, owr
, ocnt
;
227 wait_queue_head_t iwait
;
228 wait_queue_head_t owait
;
229 struct timer_list timer
;
230 unsigned char ibuf
[MIDIINBUF
];
231 unsigned char obuf
[MIDIOUTBUF
];
235 struct gameport
*gameport
;
239 /* --------------------------------------------------------------------- */
241 static inline void write_seq(struct solo1_state
*s
, unsigned char data
)
246 /* the local_irq_save stunt is to send the data within the command window */
247 for (i
= 0; i
< 0xffff; i
++) {
248 local_irq_save(flags
);
249 if (!(inb(s
->sbbase
+0xc) & 0x80)) {
250 outb(data
, s
->sbbase
+0xc);
251 local_irq_restore(flags
);
254 local_irq_restore(flags
);
256 printk(KERN_ERR
"esssolo1: write_seq timeout\n");
257 outb(data
, s
->sbbase
+0xc);
260 static inline int read_seq(struct solo1_state
*s
, unsigned char *data
)
266 for (i
= 0; i
< 0xffff; i
++)
267 if (inb(s
->sbbase
+0xe) & 0x80) {
268 *data
= inb(s
->sbbase
+0xa);
271 printk(KERN_ERR
"esssolo1: read_seq timeout\n");
275 static inline int reset_ctrl(struct solo1_state
*s
)
279 outb(3, s
->sbbase
+6); /* clear sequencer and FIFO */
281 outb(0, s
->sbbase
+6);
282 for (i
= 0; i
< 0xffff; i
++)
283 if (inb(s
->sbbase
+0xe) & 0x80)
284 if (inb(s
->sbbase
+0xa) == 0xaa) {
285 write_seq(s
, 0xc6); /* enter enhanced mode */
291 static void write_ctrl(struct solo1_state
*s
, unsigned char reg
, unsigned char data
)
298 static unsigned char read_ctrl(struct solo1_state
*s
, unsigned char reg
)
309 static void write_mixer(struct solo1_state
*s
, unsigned char reg
, unsigned char data
)
311 outb(reg
, s
->sbbase
+4);
312 outb(data
, s
->sbbase
+5);
315 static unsigned char read_mixer(struct solo1_state
*s
, unsigned char reg
)
317 outb(reg
, s
->sbbase
+4);
318 return inb(s
->sbbase
+5);
321 /* --------------------------------------------------------------------- */
323 static inline unsigned ld2(unsigned int x
)
348 /* --------------------------------------------------------------------- */
350 static inline void stop_dac(struct solo1_state
*s
)
354 spin_lock_irqsave(&s
->lock
, flags
);
355 s
->ena
&= ~FMODE_WRITE
;
356 write_mixer(s
, 0x78, 0x10);
357 spin_unlock_irqrestore(&s
->lock
, flags
);
360 static void start_dac(struct solo1_state
*s
)
364 spin_lock_irqsave(&s
->lock
, flags
);
365 if (!(s
->ena
& FMODE_WRITE
) && (s
->dma_dac
.mapped
|| s
->dma_dac
.count
> 0) && s
->dma_dac
.ready
) {
366 s
->ena
|= FMODE_WRITE
;
367 write_mixer(s
, 0x78, 0x12);
369 write_mixer(s
, 0x78, 0x13);
371 spin_unlock_irqrestore(&s
->lock
, flags
);
374 static inline void stop_adc(struct solo1_state
*s
)
378 spin_lock_irqsave(&s
->lock
, flags
);
379 s
->ena
&= ~FMODE_READ
;
380 write_ctrl(s
, 0xb8, 0xe);
381 spin_unlock_irqrestore(&s
->lock
, flags
);
384 static void start_adc(struct solo1_state
*s
)
388 spin_lock_irqsave(&s
->lock
, flags
);
389 if (!(s
->ena
& FMODE_READ
) && (s
->dma_adc
.mapped
|| s
->dma_adc
.count
< (signed)(s
->dma_adc
.dmasize
- 2*s
->dma_adc
.fragsize
))
390 && s
->dma_adc
.ready
) {
391 s
->ena
|= FMODE_READ
;
392 write_ctrl(s
, 0xb8, 0xf);
394 printk(KERN_DEBUG
"solo1: DMAbuffer: 0x%08lx\n", (long)s
->dma_adc
.rawbuf
);
395 printk(KERN_DEBUG
"solo1: DMA: mask: 0x%02x cnt: 0x%04x addr: 0x%08x stat: 0x%02x\n",
396 inb(s
->ddmabase
+0xf), inw(s
->ddmabase
+4), inl(s
->ddmabase
), inb(s
->ddmabase
+8));
398 outb(0, s
->ddmabase
+0xd); /* master reset */
399 outb(1, s
->ddmabase
+0xf); /* mask */
400 outb(0x54/*0x14*/, s
->ddmabase
+0xb); /* DMA_MODE_READ | DMA_MODE_AUTOINIT */
401 outl(virt_to_bus(s
->dma_adc
.rawbuf
), s
->ddmabase
);
402 outw(s
->dma_adc
.dmasize
-1, s
->ddmabase
+4);
403 outb(0, s
->ddmabase
+0xf);
405 spin_unlock_irqrestore(&s
->lock
, flags
);
407 printk(KERN_DEBUG
"solo1: start DMA: reg B8: 0x%02x SBstat: 0x%02x\n"
408 KERN_DEBUG
"solo1: DMA: stat: 0x%02x cnt: 0x%04x mask: 0x%02x\n",
409 read_ctrl(s
, 0xb8), inb(s
->sbbase
+0xc),
410 inb(s
->ddmabase
+8), inw(s
->ddmabase
+4), inb(s
->ddmabase
+0xf));
411 printk(KERN_DEBUG
"solo1: A1: 0x%02x A2: 0x%02x A4: 0x%02x A5: 0x%02x A8: 0x%02x\n"
412 KERN_DEBUG
"solo1: B1: 0x%02x B2: 0x%02x B4: 0x%02x B7: 0x%02x B8: 0x%02x B9: 0x%02x\n",
413 read_ctrl(s
, 0xa1), read_ctrl(s
, 0xa2), read_ctrl(s
, 0xa4), read_ctrl(s
, 0xa5), read_ctrl(s
, 0xa8),
414 read_ctrl(s
, 0xb1), read_ctrl(s
, 0xb2), read_ctrl(s
, 0xb4), read_ctrl(s
, 0xb7), read_ctrl(s
, 0xb8),
419 /* --------------------------------------------------------------------- */
421 #define DMABUF_DEFAULTORDER (15-PAGE_SHIFT)
422 #define DMABUF_MINORDER 1
424 static inline void dealloc_dmabuf(struct solo1_state
*s
, struct dmabuf
*db
)
426 struct page
*page
, *pend
;
429 /* undo marking the pages as reserved */
430 pend
= virt_to_page(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) - 1);
431 for (page
= virt_to_page(db
->rawbuf
); page
<= pend
; page
++)
432 ClearPageReserved(page
);
433 pci_free_consistent(s
->dev
, PAGE_SIZE
<< db
->buforder
, db
->rawbuf
, db
->dmaaddr
);
436 db
->mapped
= db
->ready
= 0;
439 static int prog_dmabuf(struct solo1_state
*s
, struct dmabuf
*db
)
442 unsigned bytespersec
;
443 unsigned bufs
, sample_shift
= 0;
444 struct page
*page
, *pend
;
446 db
->hwptr
= db
->swptr
= db
->total_bytes
= db
->count
= db
->error
= db
->endcleared
= 0;
448 db
->ready
= db
->mapped
= 0;
449 for (order
= DMABUF_DEFAULTORDER
; order
>= DMABUF_MINORDER
; order
--)
450 if ((db
->rawbuf
= pci_alloc_consistent(s
->dev
, PAGE_SIZE
<< order
, &db
->dmaaddr
)))
454 db
->buforder
= order
;
455 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
456 pend
= virt_to_page(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) - 1);
457 for (page
= virt_to_page(db
->rawbuf
); page
<= pend
; page
++)
458 SetPageReserved(page
);
460 if (s
->fmt
& (AFMT_S16_LE
| AFMT_U16_LE
))
464 bytespersec
= s
->rate
<< sample_shift
;
465 bufs
= PAGE_SIZE
<< db
->buforder
;
466 if (db
->ossfragshift
) {
467 if ((1000 << db
->ossfragshift
) < bytespersec
)
468 db
->fragshift
= ld2(bytespersec
/1000);
470 db
->fragshift
= db
->ossfragshift
;
472 db
->fragshift
= ld2(bytespersec
/100/(db
->subdivision
? db
->subdivision
: 1));
473 if (db
->fragshift
< 3)
476 db
->numfrag
= bufs
>> db
->fragshift
;
477 while (db
->numfrag
< 4 && db
->fragshift
> 3) {
479 db
->numfrag
= bufs
>> db
->fragshift
;
481 db
->fragsize
= 1 << db
->fragshift
;
482 if (db
->ossmaxfrags
>= 4 && db
->ossmaxfrags
< db
->numfrag
)
483 db
->numfrag
= db
->ossmaxfrags
;
484 db
->fragsamples
= db
->fragsize
>> sample_shift
;
485 db
->dmasize
= db
->numfrag
<< db
->fragshift
;
490 static inline int prog_dmabuf_adc(struct solo1_state
*s
)
496 /* check if PCI implementation supports 24bit busmaster DMA */
497 if (s
->dev
->dma_mask
> 0xffffff)
499 if ((c
= prog_dmabuf(s
, &s
->dma_adc
)))
501 va
= s
->dma_adc
.dmaaddr
;
502 if ((va
& ~((1<<24)-1)))
503 panic("solo1: buffer above 16M boundary");
504 outb(0, s
->ddmabase
+0xd); /* clear */
505 outb(1, s
->ddmabase
+0xf); /* mask */
506 /*outb(0, s->ddmabase+8);*/ /* enable (enable is active low!) */
507 outb(0x54, s
->ddmabase
+0xb); /* DMA_MODE_READ | DMA_MODE_AUTOINIT */
508 outl(va
, s
->ddmabase
);
509 outw(s
->dma_adc
.dmasize
-1, s
->ddmabase
+4);
510 c
= - s
->dma_adc
.fragsamples
;
511 write_ctrl(s
, 0xa4, c
);
512 write_ctrl(s
, 0xa5, c
>> 8);
513 outb(0, s
->ddmabase
+0xf);
514 s
->dma_adc
.ready
= 1;
518 static inline int prog_dmabuf_dac(struct solo1_state
*s
)
524 if ((c
= prog_dmabuf(s
, &s
->dma_dac
)))
526 memset(s
->dma_dac
.rawbuf
, (s
->fmt
& (AFMT_U8
| AFMT_U16_LE
)) ? 0 : 0x80, s
->dma_dac
.dmasize
); /* almost correct for U16 */
527 va
= s
->dma_dac
.dmaaddr
;
528 if ((va
^ (va
+ s
->dma_dac
.dmasize
- 1)) & ~((1<<20)-1))
529 panic("solo1: buffer crosses 1M boundary");
531 /* warning: s->dma_dac.dmasize & 0xffff must not be zero! i.e. this limits us to a 32k buffer */
532 outw(s
->dma_dac
.dmasize
, s
->iobase
+4);
533 c
= - s
->dma_dac
.fragsamples
;
534 write_mixer(s
, 0x74, c
);
535 write_mixer(s
, 0x76, c
>> 8);
536 outb(0xa, s
->iobase
+6);
537 s
->dma_dac
.ready
= 1;
541 static inline void clear_advance(void *buf
, unsigned bsize
, unsigned bptr
, unsigned len
, unsigned char c
)
543 if (bptr
+ len
> bsize
) {
544 unsigned x
= bsize
- bptr
;
545 memset(((char *)buf
) + bptr
, c
, x
);
549 memset(((char *)buf
) + bptr
, c
, len
);
552 /* call with spinlock held! */
554 static void solo1_update_ptr(struct solo1_state
*s
)
559 /* update ADC pointer */
560 if (s
->ena
& FMODE_READ
) {
561 hwptr
= (s
->dma_adc
.dmasize
- 1 - inw(s
->ddmabase
+4)) % s
->dma_adc
.dmasize
;
562 diff
= (s
->dma_adc
.dmasize
+ hwptr
- s
->dma_adc
.hwptr
) % s
->dma_adc
.dmasize
;
563 s
->dma_adc
.hwptr
= hwptr
;
564 s
->dma_adc
.total_bytes
+= diff
;
565 s
->dma_adc
.count
+= diff
;
567 printk(KERN_DEBUG
"solo1: rd: hwptr %u swptr %u dmasize %u count %u\n",
568 s
->dma_adc
.hwptr
, s
->dma_adc
.swptr
, s
->dma_adc
.dmasize
, s
->dma_adc
.count
);
570 if (s
->dma_adc
.mapped
) {
571 if (s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
)
572 wake_up(&s
->dma_adc
.wait
);
574 if (s
->dma_adc
.count
> (signed)(s
->dma_adc
.dmasize
- ((3 * s
->dma_adc
.fragsize
) >> 1))) {
575 s
->ena
&= ~FMODE_READ
;
576 write_ctrl(s
, 0xb8, 0xe);
579 if (s
->dma_adc
.count
> 0)
580 wake_up(&s
->dma_adc
.wait
);
583 /* update DAC pointer */
584 if (s
->ena
& FMODE_WRITE
) {
585 hwptr
= (s
->dma_dac
.dmasize
- inw(s
->iobase
+4)) % s
->dma_dac
.dmasize
;
586 diff
= (s
->dma_dac
.dmasize
+ hwptr
- s
->dma_dac
.hwptr
) % s
->dma_dac
.dmasize
;
587 s
->dma_dac
.hwptr
= hwptr
;
588 s
->dma_dac
.total_bytes
+= diff
;
590 printk(KERN_DEBUG
"solo1: wr: hwptr %u swptr %u dmasize %u count %u\n",
591 s
->dma_dac
.hwptr
, s
->dma_dac
.swptr
, s
->dma_dac
.dmasize
, s
->dma_dac
.count
);
593 if (s
->dma_dac
.mapped
) {
594 s
->dma_dac
.count
+= diff
;
595 if (s
->dma_dac
.count
>= (signed)s
->dma_dac
.fragsize
)
596 wake_up(&s
->dma_dac
.wait
);
598 s
->dma_dac
.count
-= diff
;
599 if (s
->dma_dac
.count
<= 0) {
600 s
->ena
&= ~FMODE_WRITE
;
601 write_mixer(s
, 0x78, 0x12);
603 } else if (s
->dma_dac
.count
<= (signed)s
->dma_dac
.fragsize
&& !s
->dma_dac
.endcleared
) {
604 clear_advance(s
->dma_dac
.rawbuf
, s
->dma_dac
.dmasize
, s
->dma_dac
.swptr
,
605 s
->dma_dac
.fragsize
, (s
->fmt
& (AFMT_U8
| AFMT_U16_LE
)) ? 0 : 0x80);
606 s
->dma_dac
.endcleared
= 1;
608 if (s
->dma_dac
.count
< (signed)s
->dma_dac
.dmasize
)
609 wake_up(&s
->dma_dac
.wait
);
614 /* --------------------------------------------------------------------- */
616 static void prog_codec(struct solo1_state
*s
)
624 /* program sampling rates */
625 filter
= s
->rate
* 9 / 20; /* Set filter roll-off to 90% of rate/2 */
626 fdiv
= 256 - 7160000 / (filter
* 82);
627 spin_lock_irqsave(&s
->lock
, flags
);
628 write_ctrl(s
, 0xa1, s
->clkdiv
);
629 write_ctrl(s
, 0xa2, fdiv
);
630 write_mixer(s
, 0x70, s
->clkdiv
);
631 write_mixer(s
, 0x72, fdiv
);
632 /* program ADC parameters */
633 write_ctrl(s
, 0xb8, 0xe);
634 write_ctrl(s
, 0xb9, /*0x1*/0);
635 write_ctrl(s
, 0xa8, (s
->channels
> 1) ? 0x11 : 0x12);
637 if (s
->fmt
& (AFMT_S16_LE
| AFMT_U16_LE
))
639 if (s
->fmt
& (AFMT_S16_LE
| AFMT_S8
))
643 write_ctrl(s
, 0xb7, (c
& 0x70) | 1);
644 write_ctrl(s
, 0xb7, c
);
645 write_ctrl(s
, 0xb1, 0x50);
646 write_ctrl(s
, 0xb2, 0x50);
647 /* program DAC parameters */
649 if (s
->fmt
& (AFMT_S16_LE
| AFMT_U16_LE
))
651 if (s
->fmt
& (AFMT_S16_LE
| AFMT_S8
))
655 write_mixer(s
, 0x7a, c
);
656 write_mixer(s
, 0x78, 0x10);
658 spin_unlock_irqrestore(&s
->lock
, flags
);
661 /* --------------------------------------------------------------------- */
663 static const char invalid_magic
[] = KERN_CRIT
"solo1: invalid magic value\n";
665 #define VALIDATE_STATE(s) \
667 if (!(s) || (s)->magic != SOLO1_MAGIC) { \
668 printk(invalid_magic); \
673 /* --------------------------------------------------------------------- */
675 static int mixer_ioctl(struct solo1_state
*s
, unsigned int cmd
, unsigned long arg
)
677 static const unsigned int mixer_src
[8] = {
678 SOUND_MASK_MIC
, SOUND_MASK_MIC
, SOUND_MASK_CD
, SOUND_MASK_VOLUME
,
679 SOUND_MASK_MIC
, 0, SOUND_MASK_LINE
, 0
681 static const unsigned char mixtable1
[SOUND_MIXER_NRDEVICES
] = {
682 [SOUND_MIXER_PCM
] = 1, /* voice */
683 [SOUND_MIXER_SYNTH
] = 2, /* FM */
684 [SOUND_MIXER_CD
] = 3, /* CD */
685 [SOUND_MIXER_LINE
] = 4, /* Line */
686 [SOUND_MIXER_LINE1
] = 5, /* AUX */
687 [SOUND_MIXER_MIC
] = 6, /* Mic */
688 [SOUND_MIXER_LINE2
] = 7, /* Mono in */
689 [SOUND_MIXER_SPEAKER
] = 8, /* Speaker */
690 [SOUND_MIXER_RECLEV
] = 9, /* Recording level */
691 [SOUND_MIXER_VOLUME
] = 10 /* Master Volume */
693 static const unsigned char mixreg
[] = {
702 unsigned char l
, r
, rl
, rr
, vidx
;
704 int __user
*p
= (int __user
*)arg
;
708 if (cmd
== SOUND_MIXER_PRIVATE1
) {
709 /* enable/disable/query mixer preamp */
710 if (get_user(val
, p
))
713 val
= val
? 0xff : 0xf7;
714 write_mixer(s
, 0x7d, (read_mixer(s
, 0x7d) | 0x08) & val
);
716 val
= (read_mixer(s
, 0x7d) & 0x08) ? 1 : 0;
717 return put_user(val
, p
);
719 if (cmd
== SOUND_MIXER_PRIVATE2
) {
720 /* enable/disable/query spatializer */
721 if (get_user(val
, p
))
725 write_mixer(s
, 0x52, val
);
726 write_mixer(s
, 0x50, val
? 0x08 : 0);
728 return put_user(read_mixer(s
, 0x52), p
);
730 if (cmd
== SOUND_MIXER_INFO
) {
732 strncpy(info
.id
, "Solo1", sizeof(info
.id
));
733 strncpy(info
.name
, "ESS Solo1", sizeof(info
.name
));
734 info
.modify_counter
= s
->mix
.modcnt
;
735 if (copy_to_user((void __user
*)arg
, &info
, sizeof(info
)))
739 if (cmd
== SOUND_OLD_MIXER_INFO
) {
740 _old_mixer_info info
;
741 strncpy(info
.id
, "Solo1", sizeof(info
.id
));
742 strncpy(info
.name
, "ESS Solo1", sizeof(info
.name
));
743 if (copy_to_user((void __user
*)arg
, &info
, sizeof(info
)))
747 if (cmd
== OSS_GETVERSION
)
748 return put_user(SOUND_VERSION
, p
);
749 if (_IOC_TYPE(cmd
) != 'M' || _SIOC_SIZE(cmd
) != sizeof(int))
751 if (_SIOC_DIR(cmd
) == _SIOC_READ
) {
752 switch (_IOC_NR(cmd
)) {
753 case SOUND_MIXER_RECSRC
: /* Arg contains a bit for each recording source */
754 return put_user(mixer_src
[read_mixer(s
, 0x1c) & 7], p
);
756 case SOUND_MIXER_DEVMASK
: /* Arg contains a bit for each supported device */
757 return put_user(SOUND_MASK_PCM
| SOUND_MASK_SYNTH
| SOUND_MASK_CD
|
758 SOUND_MASK_LINE
| SOUND_MASK_LINE1
| SOUND_MASK_MIC
|
759 SOUND_MASK_VOLUME
| SOUND_MASK_LINE2
| SOUND_MASK_RECLEV
|
760 SOUND_MASK_SPEAKER
, p
);
762 case SOUND_MIXER_RECMASK
: /* Arg contains a bit for each supported recording source */
763 return put_user(SOUND_MASK_LINE
| SOUND_MASK_MIC
| SOUND_MASK_CD
| SOUND_MASK_VOLUME
, p
);
765 case SOUND_MIXER_STEREODEVS
: /* Mixer channels supporting stereo */
766 return put_user(SOUND_MASK_PCM
| SOUND_MASK_SYNTH
| SOUND_MASK_CD
|
767 SOUND_MASK_LINE
| SOUND_MASK_LINE1
| SOUND_MASK_MIC
|
768 SOUND_MASK_VOLUME
| SOUND_MASK_LINE2
| SOUND_MASK_RECLEV
, p
);
770 case SOUND_MIXER_CAPS
:
771 return put_user(SOUND_CAP_EXCL_INPUT
, p
);
775 if (i
>= SOUND_MIXER_NRDEVICES
|| !(vidx
= mixtable1
[i
]))
777 return put_user(s
->mix
.vol
[vidx
-1], p
);
780 if (_SIOC_DIR(cmd
) != (_SIOC_READ
|_SIOC_WRITE
))
783 switch (_IOC_NR(cmd
)) {
784 case SOUND_MIXER_RECSRC
: /* Arg contains a bit for each recording source */
787 static const unsigned char regs
[] = {
788 0x1c, 0x1a, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x60, 0x62, 0x6d, 0x7c
792 for (i
= 0; i
< sizeof(regs
); i
++)
793 printk(KERN_DEBUG
"solo1: mixer reg 0x%02x: 0x%02x\n",
794 regs
[i
], read_mixer(s
, regs
[i
]));
795 printk(KERN_DEBUG
"solo1: ctrl reg 0x%02x: 0x%02x\n",
796 0xb4, read_ctrl(s
, 0xb4));
799 if (get_user(val
, p
))
805 val
&= ~mixer_src
[read_mixer(s
, 0x1c) & 7];
806 for (i
= 0; i
< 8; i
++) {
807 if (mixer_src
[i
] & val
)
812 write_mixer(s
, 0x1c, i
);
815 case SOUND_MIXER_VOLUME
:
816 if (get_user(val
, p
))
821 r
= (val
>> 8) & 0xff;
828 rl
= (l
* 2 - 11) / 3;
829 l
= (rl
* 3 + 11) / 2;
835 rr
= (r
* 2 - 11) / 3;
836 r
= (rr
* 3 + 11) / 2;
838 write_mixer(s
, 0x60, rl
);
839 write_mixer(s
, 0x62, rr
);
840 #ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
841 s
->mix
.vol
[9] = ((unsigned int)r
<< 8) | l
;
845 return put_user(s
->mix
.vol
[9], p
);
847 case SOUND_MIXER_SPEAKER
:
848 if (get_user(val
, p
))
857 write_mixer(s
, 0x3c, rl
);
858 #ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
859 s
->mix
.vol
[7] = l
* 0x101;
863 return put_user(s
->mix
.vol
[7], p
);
865 case SOUND_MIXER_RECLEV
:
866 if (get_user(val
, p
))
868 l
= (val
<< 1) & 0x1fe;
873 r
= (val
>> 7) & 0x1fe;
880 r
= (rl
* 13 + 5) / 2;
881 l
= (rr
* 13 + 5) / 2;
882 write_ctrl(s
, 0xb4, (rl
<< 4) | rr
);
883 #ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
884 s
->mix
.vol
[8] = ((unsigned int)r
<< 8) | l
;
888 return put_user(s
->mix
.vol
[8], p
);
892 if (i
>= SOUND_MIXER_NRDEVICES
|| !(vidx
= mixtable1
[i
]))
894 if (get_user(val
, p
))
896 l
= (val
<< 1) & 0x1fe;
901 r
= (val
>> 7) & 0x1fe;
908 r
= (rl
* 13 + 5) / 2;
909 l
= (rr
* 13 + 5) / 2;
910 write_mixer(s
, mixreg
[vidx
-1], (rl
<< 4) | rr
);
911 #ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
912 s
->mix
.vol
[vidx
-1] = ((unsigned int)r
<< 8) | l
;
914 s
->mix
.vol
[vidx
-1] = val
;
916 return put_user(s
->mix
.vol
[vidx
-1], p
);
920 /* --------------------------------------------------------------------- */
922 static int solo1_open_mixdev(struct inode
*inode
, struct file
*file
)
924 unsigned int minor
= iminor(inode
);
925 struct solo1_state
*s
= NULL
;
926 struct pci_dev
*pci_dev
= NULL
;
928 while ((pci_dev
= pci_find_device(PCI_ANY_ID
, PCI_ANY_ID
, pci_dev
)) != NULL
) {
929 struct pci_driver
*drvr
;
930 drvr
= pci_dev_driver (pci_dev
);
931 if (drvr
!= &solo1_driver
)
933 s
= (struct solo1_state
*)pci_get_drvdata(pci_dev
);
936 if (s
->dev_mixer
== minor
)
942 file
->private_data
= s
;
943 return nonseekable_open(inode
, file
);
946 static int solo1_release_mixdev(struct inode
*inode
, struct file
*file
)
948 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
954 static int solo1_ioctl_mixdev(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
956 return mixer_ioctl((struct solo1_state
*)file
->private_data
, cmd
, arg
);
959 static /*const*/ struct file_operations solo1_mixer_fops
= {
960 .owner
= THIS_MODULE
,
962 .ioctl
= solo1_ioctl_mixdev
,
963 .open
= solo1_open_mixdev
,
964 .release
= solo1_release_mixdev
,
967 /* --------------------------------------------------------------------- */
969 static int drain_dac(struct solo1_state
*s
, int nonblock
)
971 DECLARE_WAITQUEUE(wait
, current
);
976 if (s
->dma_dac
.mapped
)
978 add_wait_queue(&s
->dma_dac
.wait
, &wait
);
980 set_current_state(TASK_INTERRUPTIBLE
);
981 spin_lock_irqsave(&s
->lock
, flags
);
982 count
= s
->dma_dac
.count
;
983 spin_unlock_irqrestore(&s
->lock
, flags
);
986 if (signal_pending(current
))
989 remove_wait_queue(&s
->dma_dac
.wait
, &wait
);
990 set_current_state(TASK_RUNNING
);
993 tmo
= 3 * HZ
* (count
+ s
->dma_dac
.fragsize
) / 2 / s
->rate
;
994 if (s
->fmt
& (AFMT_S16_LE
| AFMT_U16_LE
))
998 if (!schedule_timeout(tmo
+ 1))
999 printk(KERN_DEBUG
"solo1: dma timed out??\n");
1001 remove_wait_queue(&s
->dma_dac
.wait
, &wait
);
1002 set_current_state(TASK_RUNNING
);
1003 if (signal_pending(current
))
1004 return -ERESTARTSYS
;
1008 /* --------------------------------------------------------------------- */
1010 static ssize_t
solo1_read(struct file
*file
, char __user
*buffer
, size_t count
, loff_t
*ppos
)
1012 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1013 DECLARE_WAITQUEUE(wait
, current
);
1015 unsigned long flags
;
1020 if (s
->dma_adc
.mapped
)
1022 if (!s
->dma_adc
.ready
&& (ret
= prog_dmabuf_adc(s
)))
1024 if (!access_ok(VERIFY_WRITE
, buffer
, count
))
1027 add_wait_queue(&s
->dma_adc
.wait
, &wait
);
1029 spin_lock_irqsave(&s
->lock
, flags
);
1030 swptr
= s
->dma_adc
.swptr
;
1031 cnt
= s
->dma_adc
.dmasize
-swptr
;
1032 if (s
->dma_adc
.count
< cnt
)
1033 cnt
= s
->dma_adc
.count
;
1035 __set_current_state(TASK_INTERRUPTIBLE
);
1036 spin_unlock_irqrestore(&s
->lock
, flags
);
1040 printk(KERN_DEBUG
"solo1_read: reg B8: 0x%02x DMAstat: 0x%02x DMAcnt: 0x%04x SBstat: 0x%02x cnt: %u\n",
1041 read_ctrl(s
, 0xb8), inb(s
->ddmabase
+8), inw(s
->ddmabase
+4), inb(s
->sbbase
+0xc), cnt
);
1044 if (s
->dma_adc
.enabled
)
1047 printk(KERN_DEBUG
"solo1_read: regs: A1: 0x%02x A2: 0x%02x A4: 0x%02x A5: 0x%02x A8: 0x%02x\n"
1048 KERN_DEBUG
"solo1_read: regs: B1: 0x%02x B2: 0x%02x B7: 0x%02x B8: 0x%02x B9: 0x%02x\n"
1049 KERN_DEBUG
"solo1_read: DMA: addr: 0x%08x cnt: 0x%04x stat: 0x%02x mask: 0x%02x\n"
1050 KERN_DEBUG
"solo1_read: SBstat: 0x%02x cnt: %u\n",
1051 read_ctrl(s
, 0xa1), read_ctrl(s
, 0xa2), read_ctrl(s
, 0xa4), read_ctrl(s
, 0xa5), read_ctrl(s
, 0xa8),
1052 read_ctrl(s
, 0xb1), read_ctrl(s
, 0xb2), read_ctrl(s
, 0xb7), read_ctrl(s
, 0xb8), read_ctrl(s
, 0xb9),
1053 inl(s
->ddmabase
), inw(s
->ddmabase
+4), inb(s
->ddmabase
+8), inb(s
->ddmabase
+15), inb(s
->sbbase
+0xc), cnt
);
1055 if (inb(s
->ddmabase
+15) & 1)
1056 printk(KERN_ERR
"solo1: cannot start recording, DDMA mask bit stuck at 1\n");
1057 if (file
->f_flags
& O_NONBLOCK
) {
1064 printk(KERN_DEBUG
"solo1_read: regs: A1: 0x%02x A2: 0x%02x A4: 0x%02x A5: 0x%02x A8: 0x%02x\n"
1065 KERN_DEBUG
"solo1_read: regs: B1: 0x%02x B2: 0x%02x B7: 0x%02x B8: 0x%02x B9: 0x%02x\n"
1066 KERN_DEBUG
"solo1_read: DMA: addr: 0x%08x cnt: 0x%04x stat: 0x%02x mask: 0x%02x\n"
1067 KERN_DEBUG
"solo1_read: SBstat: 0x%02x cnt: %u\n",
1068 read_ctrl(s
, 0xa1), read_ctrl(s
, 0xa2), read_ctrl(s
, 0xa4), read_ctrl(s
, 0xa5), read_ctrl(s
, 0xa8),
1069 read_ctrl(s
, 0xb1), read_ctrl(s
, 0xb2), read_ctrl(s
, 0xb7), read_ctrl(s
, 0xb8), read_ctrl(s
, 0xb9),
1070 inl(s
->ddmabase
), inw(s
->ddmabase
+4), inb(s
->ddmabase
+8), inb(s
->ddmabase
+15), inb(s
->sbbase
+0xc), cnt
);
1072 if (signal_pending(current
)) {
1079 if (copy_to_user(buffer
, s
->dma_adc
.rawbuf
+ swptr
, cnt
)) {
1084 swptr
= (swptr
+ cnt
) % s
->dma_adc
.dmasize
;
1085 spin_lock_irqsave(&s
->lock
, flags
);
1086 s
->dma_adc
.swptr
= swptr
;
1087 s
->dma_adc
.count
-= cnt
;
1088 spin_unlock_irqrestore(&s
->lock
, flags
);
1092 if (s
->dma_adc
.enabled
)
1095 printk(KERN_DEBUG
"solo1_read: reg B8: 0x%02x DMAstat: 0x%02x DMAcnt: 0x%04x SBstat: 0x%02x\n",
1096 read_ctrl(s
, 0xb8), inb(s
->ddmabase
+8), inw(s
->ddmabase
+4), inb(s
->sbbase
+0xc));
1099 remove_wait_queue(&s
->dma_adc
.wait
, &wait
);
1100 set_current_state(TASK_RUNNING
);
1104 static ssize_t
solo1_write(struct file
*file
, const char __user
*buffer
, size_t count
, loff_t
*ppos
)
1106 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1107 DECLARE_WAITQUEUE(wait
, current
);
1109 unsigned long flags
;
1114 if (s
->dma_dac
.mapped
)
1116 if (!s
->dma_dac
.ready
&& (ret
= prog_dmabuf_dac(s
)))
1118 if (!access_ok(VERIFY_READ
, buffer
, count
))
1121 printk(KERN_DEBUG
"solo1_write: reg 70: 0x%02x 71: 0x%02x 72: 0x%02x 74: 0x%02x 76: 0x%02x 78: 0x%02x 7A: 0x%02x\n"
1122 KERN_DEBUG
"solo1_write: DMA: addr: 0x%08x cnt: 0x%04x stat: 0x%02x SBstat: 0x%02x\n",
1123 read_mixer(s
, 0x70), read_mixer(s
, 0x71), read_mixer(s
, 0x72), read_mixer(s
, 0x74), read_mixer(s
, 0x76),
1124 read_mixer(s
, 0x78), read_mixer(s
, 0x7a), inl(s
->iobase
), inw(s
->iobase
+4), inb(s
->iobase
+6), inb(s
->sbbase
+0xc));
1125 printk(KERN_DEBUG
"solo1_write: reg 78: 0x%02x reg 7A: 0x%02x DMAcnt: 0x%04x DMAstat: 0x%02x SBstat: 0x%02x\n",
1126 read_mixer(s
, 0x78), read_mixer(s
, 0x7a), inw(s
->iobase
+4), inb(s
->iobase
+6), inb(s
->sbbase
+0xc));
1129 add_wait_queue(&s
->dma_dac
.wait
, &wait
);
1131 spin_lock_irqsave(&s
->lock
, flags
);
1132 if (s
->dma_dac
.count
< 0) {
1133 s
->dma_dac
.count
= 0;
1134 s
->dma_dac
.swptr
= s
->dma_dac
.hwptr
;
1136 swptr
= s
->dma_dac
.swptr
;
1137 cnt
= s
->dma_dac
.dmasize
-swptr
;
1138 if (s
->dma_dac
.count
+ cnt
> s
->dma_dac
.dmasize
)
1139 cnt
= s
->dma_dac
.dmasize
- s
->dma_dac
.count
;
1141 __set_current_state(TASK_INTERRUPTIBLE
);
1142 spin_unlock_irqrestore(&s
->lock
, flags
);
1146 if (s
->dma_dac
.enabled
)
1148 if (file
->f_flags
& O_NONBLOCK
) {
1154 if (signal_pending(current
)) {
1161 if (copy_from_user(s
->dma_dac
.rawbuf
+ swptr
, buffer
, cnt
)) {
1166 swptr
= (swptr
+ cnt
) % s
->dma_dac
.dmasize
;
1167 spin_lock_irqsave(&s
->lock
, flags
);
1168 s
->dma_dac
.swptr
= swptr
;
1169 s
->dma_dac
.count
+= cnt
;
1170 s
->dma_dac
.endcleared
= 0;
1171 spin_unlock_irqrestore(&s
->lock
, flags
);
1175 if (s
->dma_dac
.enabled
)
1178 remove_wait_queue(&s
->dma_dac
.wait
, &wait
);
1179 set_current_state(TASK_RUNNING
);
1183 /* No kernel lock - we have our own spinlock */
1184 static unsigned int solo1_poll(struct file
*file
, struct poll_table_struct
*wait
)
1186 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1187 unsigned long flags
;
1188 unsigned int mask
= 0;
1191 if (file
->f_mode
& FMODE_WRITE
) {
1192 if (!s
->dma_dac
.ready
&& prog_dmabuf_dac(s
))
1194 poll_wait(file
, &s
->dma_dac
.wait
, wait
);
1196 if (file
->f_mode
& FMODE_READ
) {
1197 if (!s
->dma_adc
.ready
&& prog_dmabuf_adc(s
))
1199 poll_wait(file
, &s
->dma_adc
.wait
, wait
);
1201 spin_lock_irqsave(&s
->lock
, flags
);
1202 solo1_update_ptr(s
);
1203 if (file
->f_mode
& FMODE_READ
) {
1204 if (s
->dma_adc
.mapped
) {
1205 if (s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
)
1206 mask
|= POLLIN
| POLLRDNORM
;
1208 if (s
->dma_adc
.count
> 0)
1209 mask
|= POLLIN
| POLLRDNORM
;
1212 if (file
->f_mode
& FMODE_WRITE
) {
1213 if (s
->dma_dac
.mapped
) {
1214 if (s
->dma_dac
.count
>= (signed)s
->dma_dac
.fragsize
)
1215 mask
|= POLLOUT
| POLLWRNORM
;
1217 if ((signed)s
->dma_dac
.dmasize
> s
->dma_dac
.count
)
1218 mask
|= POLLOUT
| POLLWRNORM
;
1221 spin_unlock_irqrestore(&s
->lock
, flags
);
1226 static int solo1_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1228 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1235 if (vma
->vm_flags
& VM_WRITE
) {
1236 if ((ret
= prog_dmabuf_dac(s
)) != 0)
1239 } else if (vma
->vm_flags
& VM_READ
) {
1240 if ((ret
= prog_dmabuf_adc(s
)) != 0)
1246 if (vma
->vm_pgoff
!= 0)
1248 size
= vma
->vm_end
- vma
->vm_start
;
1249 if (size
> (PAGE_SIZE
<< db
->buforder
))
1252 if (remap_pfn_range(vma
, vma
->vm_start
,
1253 virt_to_phys(db
->rawbuf
) >> PAGE_SHIFT
,
1254 size
, vma
->vm_page_prot
))
1263 static int solo1_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1265 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1266 unsigned long flags
;
1267 audio_buf_info abinfo
;
1269 int val
, mapped
, ret
, count
;
1271 unsigned rate1
, rate2
;
1272 void __user
*argp
= (void __user
*)arg
;
1273 int __user
*p
= argp
;
1276 mapped
= ((file
->f_mode
& FMODE_WRITE
) && s
->dma_dac
.mapped
) ||
1277 ((file
->f_mode
& FMODE_READ
) && s
->dma_adc
.mapped
);
1279 case OSS_GETVERSION
:
1280 return put_user(SOUND_VERSION
, p
);
1282 case SNDCTL_DSP_SYNC
:
1283 if (file
->f_mode
& FMODE_WRITE
)
1284 return drain_dac(s
, 0/*file->f_flags & O_NONBLOCK*/);
1287 case SNDCTL_DSP_SETDUPLEX
:
1290 case SNDCTL_DSP_GETCAPS
:
1291 return put_user(DSP_CAP_DUPLEX
| DSP_CAP_REALTIME
| DSP_CAP_TRIGGER
| DSP_CAP_MMAP
, p
);
1293 case SNDCTL_DSP_RESET
:
1294 if (file
->f_mode
& FMODE_WRITE
) {
1296 synchronize_irq(s
->irq
);
1297 s
->dma_dac
.swptr
= s
->dma_dac
.hwptr
= s
->dma_dac
.count
= s
->dma_dac
.total_bytes
= 0;
1299 if (file
->f_mode
& FMODE_READ
) {
1301 synchronize_irq(s
->irq
);
1302 s
->dma_adc
.swptr
= s
->dma_adc
.hwptr
= s
->dma_adc
.count
= s
->dma_adc
.total_bytes
= 0;
1307 case SNDCTL_DSP_SPEED
:
1308 if (get_user(val
, p
))
1313 s
->dma_adc
.ready
= s
->dma_dac
.ready
= 0;
1314 /* program sampling rates */
1319 div1
= (768000 + val
/ 2) / val
;
1320 rate1
= (768000 + div1
/ 2) / div1
;
1322 div2
= (793800 + val
/ 2) / val
;
1323 rate2
= (793800 + div2
/ 2) / div2
;
1324 div2
= (-div2
) & 0x7f;
1325 if (abs(val
- rate2
) < abs(val
- rate1
)) {
1333 return put_user(s
->rate
, p
);
1335 case SNDCTL_DSP_STEREO
:
1336 if (get_user(val
, p
))
1340 s
->dma_adc
.ready
= s
->dma_dac
.ready
= 0;
1341 /* program channels */
1342 s
->channels
= val
? 2 : 1;
1346 case SNDCTL_DSP_CHANNELS
:
1347 if (get_user(val
, p
))
1352 s
->dma_adc
.ready
= s
->dma_dac
.ready
= 0;
1353 /* program channels */
1354 s
->channels
= (val
>= 2) ? 2 : 1;
1357 return put_user(s
->channels
, p
);
1359 case SNDCTL_DSP_GETFMTS
: /* Returns a mask */
1360 return put_user(AFMT_S16_LE
|AFMT_U16_LE
|AFMT_S8
|AFMT_U8
, p
);
1362 case SNDCTL_DSP_SETFMT
: /* Selects ONE fmt*/
1363 if (get_user(val
, p
))
1365 if (val
!= AFMT_QUERY
) {
1368 s
->dma_adc
.ready
= s
->dma_dac
.ready
= 0;
1369 /* program format */
1370 if (val
!= AFMT_S16_LE
&& val
!= AFMT_U16_LE
&&
1371 val
!= AFMT_S8
&& val
!= AFMT_U8
)
1376 return put_user(s
->fmt
, p
);
1378 case SNDCTL_DSP_POST
:
1381 case SNDCTL_DSP_GETTRIGGER
:
1383 if (file
->f_mode
& s
->ena
& FMODE_READ
)
1384 val
|= PCM_ENABLE_INPUT
;
1385 if (file
->f_mode
& s
->ena
& FMODE_WRITE
)
1386 val
|= PCM_ENABLE_OUTPUT
;
1387 return put_user(val
, p
);
1389 case SNDCTL_DSP_SETTRIGGER
:
1390 if (get_user(val
, p
))
1392 if (file
->f_mode
& FMODE_READ
) {
1393 if (val
& PCM_ENABLE_INPUT
) {
1394 if (!s
->dma_adc
.ready
&& (ret
= prog_dmabuf_adc(s
)))
1396 s
->dma_dac
.enabled
= 1;
1398 if (inb(s
->ddmabase
+15) & 1)
1399 printk(KERN_ERR
"solo1: cannot start recording, DDMA mask bit stuck at 1\n");
1401 s
->dma_dac
.enabled
= 0;
1405 if (file
->f_mode
& FMODE_WRITE
) {
1406 if (val
& PCM_ENABLE_OUTPUT
) {
1407 if (!s
->dma_dac
.ready
&& (ret
= prog_dmabuf_dac(s
)))
1409 s
->dma_dac
.enabled
= 1;
1412 s
->dma_dac
.enabled
= 0;
1418 case SNDCTL_DSP_GETOSPACE
:
1419 if (!(file
->f_mode
& FMODE_WRITE
))
1421 if (!s
->dma_dac
.ready
&& (val
= prog_dmabuf_dac(s
)) != 0)
1423 spin_lock_irqsave(&s
->lock
, flags
);
1424 solo1_update_ptr(s
);
1425 abinfo
.fragsize
= s
->dma_dac
.fragsize
;
1426 count
= s
->dma_dac
.count
;
1429 abinfo
.bytes
= s
->dma_dac
.dmasize
- count
;
1430 abinfo
.fragstotal
= s
->dma_dac
.numfrag
;
1431 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_dac
.fragshift
;
1432 spin_unlock_irqrestore(&s
->lock
, flags
);
1433 return copy_to_user(argp
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
1435 case SNDCTL_DSP_GETISPACE
:
1436 if (!(file
->f_mode
& FMODE_READ
))
1438 if (!s
->dma_adc
.ready
&& (val
= prog_dmabuf_adc(s
)) != 0)
1440 spin_lock_irqsave(&s
->lock
, flags
);
1441 solo1_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(argp
, &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 if (!s
->dma_dac
.ready
&& (val
= prog_dmabuf_dac(s
)) != 0)
1458 spin_lock_irqsave(&s
->lock
, flags
);
1459 solo1_update_ptr(s
);
1460 count
= s
->dma_dac
.count
;
1461 spin_unlock_irqrestore(&s
->lock
, flags
);
1464 return put_user(count
, p
);
1466 case SNDCTL_DSP_GETIPTR
:
1467 if (!(file
->f_mode
& FMODE_READ
))
1469 if (!s
->dma_adc
.ready
&& (val
= prog_dmabuf_adc(s
)) != 0)
1471 spin_lock_irqsave(&s
->lock
, flags
);
1472 solo1_update_ptr(s
);
1473 cinfo
.bytes
= s
->dma_adc
.total_bytes
;
1474 cinfo
.blocks
= s
->dma_adc
.count
>> s
->dma_adc
.fragshift
;
1475 cinfo
.ptr
= s
->dma_adc
.hwptr
;
1476 if (s
->dma_adc
.mapped
)
1477 s
->dma_adc
.count
&= s
->dma_adc
.fragsize
-1;
1478 spin_unlock_irqrestore(&s
->lock
, flags
);
1479 if (copy_to_user(argp
, &cinfo
, sizeof(cinfo
)))
1483 case SNDCTL_DSP_GETOPTR
:
1484 if (!(file
->f_mode
& FMODE_WRITE
))
1486 if (!s
->dma_dac
.ready
&& (val
= prog_dmabuf_dac(s
)) != 0)
1488 spin_lock_irqsave(&s
->lock
, flags
);
1489 solo1_update_ptr(s
);
1490 cinfo
.bytes
= s
->dma_dac
.total_bytes
;
1491 count
= s
->dma_dac
.count
;
1494 cinfo
.blocks
= count
>> s
->dma_dac
.fragshift
;
1495 cinfo
.ptr
= s
->dma_dac
.hwptr
;
1496 if (s
->dma_dac
.mapped
)
1497 s
->dma_dac
.count
&= s
->dma_dac
.fragsize
-1;
1498 spin_unlock_irqrestore(&s
->lock
, flags
);
1500 printk(KERN_DEBUG
"esssolo1: GETOPTR: bytes %u blocks %u ptr %u, buforder %u numfrag %u fragshift %u\n"
1501 KERN_DEBUG
"esssolo1: swptr %u count %u fragsize %u dmasize %u fragsamples %u\n",
1502 cinfo
.bytes
, cinfo
.blocks
, cinfo
.ptr
, s
->dma_dac
.buforder
, s
->dma_dac
.numfrag
, s
->dma_dac
.fragshift
,
1503 s
->dma_dac
.swptr
, s
->dma_dac
.count
, s
->dma_dac
.fragsize
, s
->dma_dac
.dmasize
, s
->dma_dac
.fragsamples
);
1505 if (copy_to_user(argp
, &cinfo
, sizeof(cinfo
)))
1509 case SNDCTL_DSP_GETBLKSIZE
:
1510 if (file
->f_mode
& FMODE_WRITE
) {
1511 if ((val
= prog_dmabuf_dac(s
)))
1513 return put_user(s
->dma_dac
.fragsize
, p
);
1515 if ((val
= prog_dmabuf_adc(s
)))
1517 return put_user(s
->dma_adc
.fragsize
, p
);
1519 case SNDCTL_DSP_SETFRAGMENT
:
1520 if (get_user(val
, p
))
1522 if (file
->f_mode
& FMODE_READ
) {
1523 s
->dma_adc
.ossfragshift
= val
& 0xffff;
1524 s
->dma_adc
.ossmaxfrags
= (val
>> 16) & 0xffff;
1525 if (s
->dma_adc
.ossfragshift
< 4)
1526 s
->dma_adc
.ossfragshift
= 4;
1527 if (s
->dma_adc
.ossfragshift
> 15)
1528 s
->dma_adc
.ossfragshift
= 15;
1529 if (s
->dma_adc
.ossmaxfrags
< 4)
1530 s
->dma_adc
.ossmaxfrags
= 4;
1532 if (file
->f_mode
& FMODE_WRITE
) {
1533 s
->dma_dac
.ossfragshift
= val
& 0xffff;
1534 s
->dma_dac
.ossmaxfrags
= (val
>> 16) & 0xffff;
1535 if (s
->dma_dac
.ossfragshift
< 4)
1536 s
->dma_dac
.ossfragshift
= 4;
1537 if (s
->dma_dac
.ossfragshift
> 15)
1538 s
->dma_dac
.ossfragshift
= 15;
1539 if (s
->dma_dac
.ossmaxfrags
< 4)
1540 s
->dma_dac
.ossmaxfrags
= 4;
1544 case SNDCTL_DSP_SUBDIVIDE
:
1545 if ((file
->f_mode
& FMODE_READ
&& s
->dma_adc
.subdivision
) ||
1546 (file
->f_mode
& FMODE_WRITE
&& s
->dma_dac
.subdivision
))
1548 if (get_user(val
, p
))
1550 if (val
!= 1 && val
!= 2 && val
!= 4)
1552 if (file
->f_mode
& FMODE_READ
)
1553 s
->dma_adc
.subdivision
= val
;
1554 if (file
->f_mode
& FMODE_WRITE
)
1555 s
->dma_dac
.subdivision
= val
;
1558 case SOUND_PCM_READ_RATE
:
1559 return put_user(s
->rate
, p
);
1561 case SOUND_PCM_READ_CHANNELS
:
1562 return put_user(s
->channels
, p
);
1564 case SOUND_PCM_READ_BITS
:
1565 return put_user((s
->fmt
& (AFMT_S8
|AFMT_U8
)) ? 8 : 16, p
);
1567 case SOUND_PCM_WRITE_FILTER
:
1568 case SNDCTL_DSP_SETSYNCRO
:
1569 case SOUND_PCM_READ_FILTER
:
1573 return mixer_ioctl(s
, cmd
, arg
);
1576 static int solo1_release(struct inode
*inode
, struct file
*file
)
1578 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1582 if (file
->f_mode
& FMODE_WRITE
)
1583 drain_dac(s
, file
->f_flags
& O_NONBLOCK
);
1585 if (file
->f_mode
& FMODE_WRITE
) {
1587 outb(0, s
->iobase
+6); /* disable DMA */
1588 dealloc_dmabuf(s
, &s
->dma_dac
);
1590 if (file
->f_mode
& FMODE_READ
) {
1592 outb(1, s
->ddmabase
+0xf); /* mask DMA channel */
1593 outb(0, s
->ddmabase
+0xd); /* DMA master clear */
1594 dealloc_dmabuf(s
, &s
->dma_adc
);
1596 s
->open_mode
&= ~(FMODE_READ
| FMODE_WRITE
);
1597 wake_up(&s
->open_wait
);
1603 static int solo1_open(struct inode
*inode
, struct file
*file
)
1605 unsigned int minor
= iminor(inode
);
1606 DECLARE_WAITQUEUE(wait
, current
);
1607 struct solo1_state
*s
= NULL
;
1608 struct pci_dev
*pci_dev
= NULL
;
1610 while ((pci_dev
= pci_find_device(PCI_ANY_ID
, PCI_ANY_ID
, pci_dev
)) != NULL
) {
1611 struct pci_driver
*drvr
;
1613 drvr
= pci_dev_driver(pci_dev
);
1614 if (drvr
!= &solo1_driver
)
1616 s
= (struct solo1_state
*)pci_get_drvdata(pci_dev
);
1619 if (!((s
->dev_audio
^ minor
) & ~0xf))
1625 file
->private_data
= s
;
1626 /* wait for device to become free */
1628 while (s
->open_mode
& (FMODE_READ
| FMODE_WRITE
)) {
1629 if (file
->f_flags
& O_NONBLOCK
) {
1633 add_wait_queue(&s
->open_wait
, &wait
);
1634 __set_current_state(TASK_INTERRUPTIBLE
);
1637 remove_wait_queue(&s
->open_wait
, &wait
);
1638 set_current_state(TASK_RUNNING
);
1639 if (signal_pending(current
))
1640 return -ERESTARTSYS
;
1646 s
->clkdiv
= 96 | 0x80;
1648 s
->dma_adc
.ossfragshift
= s
->dma_adc
.ossmaxfrags
= s
->dma_adc
.subdivision
= 0;
1649 s
->dma_adc
.enabled
= 1;
1650 s
->dma_dac
.ossfragshift
= s
->dma_dac
.ossmaxfrags
= s
->dma_dac
.subdivision
= 0;
1651 s
->dma_dac
.enabled
= 1;
1652 s
->open_mode
|= file
->f_mode
& (FMODE_READ
| FMODE_WRITE
);
1655 return nonseekable_open(inode
, file
);
1658 static /*const*/ struct file_operations solo1_audio_fops
= {
1659 .owner
= THIS_MODULE
,
1660 .llseek
= no_llseek
,
1662 .write
= solo1_write
,
1664 .ioctl
= solo1_ioctl
,
1667 .release
= solo1_release
,
1670 /* --------------------------------------------------------------------- */
1672 /* hold spinlock for the following! */
1673 static void solo1_handle_midi(struct solo1_state
*s
)
1681 while (!(inb(s
->mpubase
+1) & 0x80)) {
1682 ch
= inb(s
->mpubase
);
1683 if (s
->midi
.icnt
< MIDIINBUF
) {
1684 s
->midi
.ibuf
[s
->midi
.iwr
] = ch
;
1685 s
->midi
.iwr
= (s
->midi
.iwr
+ 1) % MIDIINBUF
;
1691 wake_up(&s
->midi
.iwait
);
1693 while (!(inb(s
->mpubase
+1) & 0x40) && s
->midi
.ocnt
> 0) {
1694 outb(s
->midi
.obuf
[s
->midi
.ord
], s
->mpubase
);
1695 s
->midi
.ord
= (s
->midi
.ord
+ 1) % MIDIOUTBUF
;
1697 if (s
->midi
.ocnt
< MIDIOUTBUF
-16)
1701 wake_up(&s
->midi
.owait
);
1704 static irqreturn_t
solo1_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1706 struct solo1_state
*s
= (struct solo1_state
*)dev_id
;
1707 unsigned int intsrc
;
1709 /* fastpath out, to ease interrupt sharing */
1710 intsrc
= inb(s
->iobase
+7); /* get interrupt source(s) */
1713 (void)inb(s
->sbbase
+0xe); /* clear interrupt */
1714 spin_lock(&s
->lock
);
1715 /* clear audio interrupts first */
1717 write_mixer(s
, 0x7a, read_mixer(s
, 0x7a) & 0x7f);
1718 solo1_update_ptr(s
);
1719 solo1_handle_midi(s
);
1720 spin_unlock(&s
->lock
);
1724 static void solo1_midi_timer(unsigned long data
)
1726 struct solo1_state
*s
= (struct solo1_state
*)data
;
1727 unsigned long flags
;
1729 spin_lock_irqsave(&s
->lock
, flags
);
1730 solo1_handle_midi(s
);
1731 spin_unlock_irqrestore(&s
->lock
, flags
);
1732 s
->midi
.timer
.expires
= jiffies
+1;
1733 add_timer(&s
->midi
.timer
);
1736 /* --------------------------------------------------------------------- */
1738 static ssize_t
solo1_midi_read(struct file
*file
, char __user
*buffer
, size_t count
, loff_t
*ppos
)
1740 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1741 DECLARE_WAITQUEUE(wait
, current
);
1743 unsigned long flags
;
1748 if (!access_ok(VERIFY_WRITE
, buffer
, count
))
1753 add_wait_queue(&s
->midi
.iwait
, &wait
);
1755 spin_lock_irqsave(&s
->lock
, flags
);
1757 cnt
= MIDIINBUF
- ptr
;
1758 if (s
->midi
.icnt
< cnt
)
1761 __set_current_state(TASK_INTERRUPTIBLE
);
1762 spin_unlock_irqrestore(&s
->lock
, flags
);
1766 if (file
->f_flags
& O_NONBLOCK
) {
1772 if (signal_pending(current
)) {
1779 if (copy_to_user(buffer
, s
->midi
.ibuf
+ ptr
, cnt
)) {
1784 ptr
= (ptr
+ cnt
) % MIDIINBUF
;
1785 spin_lock_irqsave(&s
->lock
, flags
);
1787 s
->midi
.icnt
-= cnt
;
1788 spin_unlock_irqrestore(&s
->lock
, flags
);
1794 __set_current_state(TASK_RUNNING
);
1795 remove_wait_queue(&s
->midi
.iwait
, &wait
);
1799 static ssize_t
solo1_midi_write(struct file
*file
, const char __user
*buffer
, size_t count
, loff_t
*ppos
)
1801 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1802 DECLARE_WAITQUEUE(wait
, current
);
1804 unsigned long flags
;
1809 if (!access_ok(VERIFY_READ
, buffer
, count
))
1814 add_wait_queue(&s
->midi
.owait
, &wait
);
1816 spin_lock_irqsave(&s
->lock
, flags
);
1818 cnt
= MIDIOUTBUF
- ptr
;
1819 if (s
->midi
.ocnt
+ cnt
> MIDIOUTBUF
)
1820 cnt
= MIDIOUTBUF
- s
->midi
.ocnt
;
1822 __set_current_state(TASK_INTERRUPTIBLE
);
1823 solo1_handle_midi(s
);
1825 spin_unlock_irqrestore(&s
->lock
, flags
);
1829 if (file
->f_flags
& O_NONBLOCK
) {
1835 if (signal_pending(current
)) {
1842 if (copy_from_user(s
->midi
.obuf
+ ptr
, buffer
, cnt
)) {
1847 ptr
= (ptr
+ cnt
) % MIDIOUTBUF
;
1848 spin_lock_irqsave(&s
->lock
, flags
);
1850 s
->midi
.ocnt
+= cnt
;
1851 spin_unlock_irqrestore(&s
->lock
, flags
);
1855 spin_lock_irqsave(&s
->lock
, flags
);
1856 solo1_handle_midi(s
);
1857 spin_unlock_irqrestore(&s
->lock
, flags
);
1859 __set_current_state(TASK_RUNNING
);
1860 remove_wait_queue(&s
->midi
.owait
, &wait
);
1864 /* No kernel lock - we have our own spinlock */
1865 static unsigned int solo1_midi_poll(struct file
*file
, struct poll_table_struct
*wait
)
1867 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1868 unsigned long flags
;
1869 unsigned int mask
= 0;
1872 if (file
->f_flags
& FMODE_WRITE
)
1873 poll_wait(file
, &s
->midi
.owait
, wait
);
1874 if (file
->f_flags
& FMODE_READ
)
1875 poll_wait(file
, &s
->midi
.iwait
, wait
);
1876 spin_lock_irqsave(&s
->lock
, flags
);
1877 if (file
->f_flags
& FMODE_READ
) {
1878 if (s
->midi
.icnt
> 0)
1879 mask
|= POLLIN
| POLLRDNORM
;
1881 if (file
->f_flags
& FMODE_WRITE
) {
1882 if (s
->midi
.ocnt
< MIDIOUTBUF
)
1883 mask
|= POLLOUT
| POLLWRNORM
;
1885 spin_unlock_irqrestore(&s
->lock
, flags
);
1889 static int solo1_midi_open(struct inode
*inode
, struct file
*file
)
1891 unsigned int minor
= iminor(inode
);
1892 DECLARE_WAITQUEUE(wait
, current
);
1893 unsigned long flags
;
1894 struct solo1_state
*s
= NULL
;
1895 struct pci_dev
*pci_dev
= NULL
;
1897 while ((pci_dev
= pci_find_device(PCI_ANY_ID
, PCI_ANY_ID
, pci_dev
)) != NULL
) {
1898 struct pci_driver
*drvr
;
1900 drvr
= pci_dev_driver(pci_dev
);
1901 if (drvr
!= &solo1_driver
)
1903 s
= (struct solo1_state
*)pci_get_drvdata(pci_dev
);
1906 if (s
->dev_midi
== minor
)
1912 file
->private_data
= s
;
1913 /* wait for device to become free */
1915 while (s
->open_mode
& (file
->f_mode
<< FMODE_MIDI_SHIFT
)) {
1916 if (file
->f_flags
& O_NONBLOCK
) {
1920 add_wait_queue(&s
->open_wait
, &wait
);
1921 __set_current_state(TASK_INTERRUPTIBLE
);
1924 remove_wait_queue(&s
->open_wait
, &wait
);
1925 set_current_state(TASK_RUNNING
);
1926 if (signal_pending(current
))
1927 return -ERESTARTSYS
;
1930 spin_lock_irqsave(&s
->lock
, flags
);
1931 if (!(s
->open_mode
& (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
))) {
1932 s
->midi
.ird
= s
->midi
.iwr
= s
->midi
.icnt
= 0;
1933 s
->midi
.ord
= s
->midi
.owr
= s
->midi
.ocnt
= 0;
1934 outb(0xff, s
->mpubase
+1); /* reset command */
1935 outb(0x3f, s
->mpubase
+1); /* uart command */
1936 if (!(inb(s
->mpubase
+1) & 0x80))
1938 s
->midi
.ird
= s
->midi
.iwr
= s
->midi
.icnt
= 0;
1939 outb(0xb0, s
->iobase
+ 7); /* enable A1, A2, MPU irq's */
1940 init_timer(&s
->midi
.timer
);
1941 s
->midi
.timer
.expires
= jiffies
+1;
1942 s
->midi
.timer
.data
= (unsigned long)s
;
1943 s
->midi
.timer
.function
= solo1_midi_timer
;
1944 add_timer(&s
->midi
.timer
);
1946 if (file
->f_mode
& FMODE_READ
) {
1947 s
->midi
.ird
= s
->midi
.iwr
= s
->midi
.icnt
= 0;
1949 if (file
->f_mode
& FMODE_WRITE
) {
1950 s
->midi
.ord
= s
->midi
.owr
= s
->midi
.ocnt
= 0;
1952 spin_unlock_irqrestore(&s
->lock
, flags
);
1953 s
->open_mode
|= (file
->f_mode
<< FMODE_MIDI_SHIFT
) & (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
);
1955 return nonseekable_open(inode
, file
);
1958 static int solo1_midi_release(struct inode
*inode
, struct file
*file
)
1960 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
1961 DECLARE_WAITQUEUE(wait
, current
);
1962 unsigned long flags
;
1963 unsigned count
, tmo
;
1968 if (file
->f_mode
& FMODE_WRITE
) {
1969 add_wait_queue(&s
->midi
.owait
, &wait
);
1971 __set_current_state(TASK_INTERRUPTIBLE
);
1972 spin_lock_irqsave(&s
->lock
, flags
);
1973 count
= s
->midi
.ocnt
;
1974 spin_unlock_irqrestore(&s
->lock
, flags
);
1977 if (signal_pending(current
))
1979 if (file
->f_flags
& O_NONBLOCK
)
1981 tmo
= (count
* HZ
) / 3100;
1982 if (!schedule_timeout(tmo
? : 1) && tmo
)
1983 printk(KERN_DEBUG
"solo1: midi timed out??\n");
1985 remove_wait_queue(&s
->midi
.owait
, &wait
);
1986 set_current_state(TASK_RUNNING
);
1989 s
->open_mode
&= ~((file
->f_mode
<< FMODE_MIDI_SHIFT
) & (FMODE_MIDI_READ
|FMODE_MIDI_WRITE
));
1990 spin_lock_irqsave(&s
->lock
, flags
);
1991 if (!(s
->open_mode
& (FMODE_MIDI_READ
| FMODE_MIDI_WRITE
))) {
1992 outb(0x30, s
->iobase
+ 7); /* enable A1, A2 irq's */
1993 del_timer(&s
->midi
.timer
);
1995 spin_unlock_irqrestore(&s
->lock
, flags
);
1996 wake_up(&s
->open_wait
);
2002 static /*const*/ struct file_operations solo1_midi_fops
= {
2003 .owner
= THIS_MODULE
,
2004 .llseek
= no_llseek
,
2005 .read
= solo1_midi_read
,
2006 .write
= solo1_midi_write
,
2007 .poll
= solo1_midi_poll
,
2008 .open
= solo1_midi_open
,
2009 .release
= solo1_midi_release
,
2012 /* --------------------------------------------------------------------- */
2014 static int solo1_dmfm_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
2016 static const unsigned char op_offset
[18] = {
2017 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
2018 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
2019 0x10, 0x11, 0x12, 0x13, 0x14, 0x15
2021 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
2022 struct dm_fm_voice v
;
2023 struct dm_fm_note n
;
2024 struct dm_fm_params p
;
2029 case FM_IOCTL_RESET
:
2030 for (regb
= 0xb0; regb
< 0xb9; regb
++) {
2031 outb(regb
, s
->sbbase
);
2032 outb(0, s
->sbbase
+1);
2033 outb(regb
, s
->sbbase
+2);
2034 outb(0, s
->sbbase
+3);
2038 case FM_IOCTL_PLAY_NOTE
:
2039 if (copy_from_user(&n
, (void __user
*)arg
, sizeof(n
)))
2050 outb(0xa0 + regb
, io
);
2051 outb(n
.fnum
& 0xff, io
+1);
2052 outb(0xb0 + regb
, io
);
2053 outb(((n
.fnum
>> 8) & 3) | ((n
.octave
& 7) << 2) | ((n
.key_on
& 1) << 5), io
+1);
2056 case FM_IOCTL_SET_VOICE
:
2057 if (copy_from_user(&v
, (void __user
*)arg
, sizeof(v
)))
2061 regb
= op_offset
[v
.voice
];
2062 io
= s
->sbbase
+ ((v
.op
& 1) << 1);
2063 outb(0x20 + regb
, io
);
2064 outb(((v
.am
& 1) << 7) | ((v
.vibrato
& 1) << 6) | ((v
.do_sustain
& 1) << 5) |
2065 ((v
.kbd_scale
& 1) << 4) | (v
.harmonic
& 0xf), io
+1);
2066 outb(0x40 + regb
, io
);
2067 outb(((v
.scale_level
& 0x3) << 6) | (v
.volume
& 0x3f), io
+1);
2068 outb(0x60 + regb
, io
);
2069 outb(((v
.attack
& 0xf) << 4) | (v
.decay
& 0xf), io
+1);
2070 outb(0x80 + regb
, io
);
2071 outb(((v
.sustain
& 0xf) << 4) | (v
.release
& 0xf), io
+1);
2072 outb(0xe0 + regb
, io
);
2073 outb(v
.waveform
& 0x7, io
+1);
2081 outb(0xc0 + regb
, io
);
2082 outb(((v
.right
& 1) << 5) | ((v
.left
& 1) << 4) | ((v
.feedback
& 7) << 1) |
2083 (v
.connection
& 1), io
+1);
2086 case FM_IOCTL_SET_PARAMS
:
2087 if (copy_from_user(&p
, (void __user
*)arg
, sizeof(p
)))
2089 outb(0x08, s
->sbbase
);
2090 outb((p
.kbd_split
& 1) << 6, s
->sbbase
+1);
2091 outb(0xbd, s
->sbbase
);
2092 outb(((p
.am_depth
& 1) << 7) | ((p
.vib_depth
& 1) << 6) | ((p
.rhythm
& 1) << 5) | ((p
.bass
& 1) << 4) |
2093 ((p
.snare
& 1) << 3) | ((p
.tomtom
& 1) << 2) | ((p
.cymbal
& 1) << 1) | (p
.hihat
& 1), s
->sbbase
+1);
2096 case FM_IOCTL_SET_OPL
:
2097 outb(4, s
->sbbase
+2);
2098 outb(arg
, s
->sbbase
+3);
2101 case FM_IOCTL_SET_MODE
:
2102 outb(5, s
->sbbase
+2);
2103 outb(arg
& 1, s
->sbbase
+3);
2111 static int solo1_dmfm_open(struct inode
*inode
, struct file
*file
)
2113 unsigned int minor
= iminor(inode
);
2114 DECLARE_WAITQUEUE(wait
, current
);
2115 struct solo1_state
*s
= NULL
;
2116 struct pci_dev
*pci_dev
= NULL
;
2118 while ((pci_dev
= pci_find_device(PCI_ANY_ID
, PCI_ANY_ID
, pci_dev
)) != NULL
) {
2119 struct pci_driver
*drvr
;
2121 drvr
= pci_dev_driver(pci_dev
);
2122 if (drvr
!= &solo1_driver
)
2124 s
= (struct solo1_state
*)pci_get_drvdata(pci_dev
);
2127 if (s
->dev_dmfm
== minor
)
2133 file
->private_data
= s
;
2134 /* wait for device to become free */
2136 while (s
->open_mode
& FMODE_DMFM
) {
2137 if (file
->f_flags
& O_NONBLOCK
) {
2141 add_wait_queue(&s
->open_wait
, &wait
);
2142 __set_current_state(TASK_INTERRUPTIBLE
);
2145 remove_wait_queue(&s
->open_wait
, &wait
);
2146 set_current_state(TASK_RUNNING
);
2147 if (signal_pending(current
))
2148 return -ERESTARTSYS
;
2151 if (!request_region(s
->sbbase
, FMSYNTH_EXTENT
, "ESS Solo1")) {
2153 printk(KERN_ERR
"solo1: FM synth io ports in use, opl3 loaded?\n");
2156 /* init the stuff */
2158 outb(0x20, s
->sbbase
+1); /* enable waveforms */
2159 outb(4, s
->sbbase
+2);
2160 outb(0, s
->sbbase
+3); /* no 4op enabled */
2161 outb(5, s
->sbbase
+2);
2162 outb(1, s
->sbbase
+3); /* enable OPL3 */
2163 s
->open_mode
|= FMODE_DMFM
;
2165 return nonseekable_open(inode
, file
);
2168 static int solo1_dmfm_release(struct inode
*inode
, struct file
*file
)
2170 struct solo1_state
*s
= (struct solo1_state
*)file
->private_data
;
2176 s
->open_mode
&= ~FMODE_DMFM
;
2177 for (regb
= 0xb0; regb
< 0xb9; regb
++) {
2178 outb(regb
, s
->sbbase
);
2179 outb(0, s
->sbbase
+1);
2180 outb(regb
, s
->sbbase
+2);
2181 outb(0, s
->sbbase
+3);
2183 release_region(s
->sbbase
, FMSYNTH_EXTENT
);
2184 wake_up(&s
->open_wait
);
2190 static /*const*/ struct file_operations solo1_dmfm_fops
= {
2191 .owner
= THIS_MODULE
,
2192 .llseek
= no_llseek
,
2193 .ioctl
= solo1_dmfm_ioctl
,
2194 .open
= solo1_dmfm_open
,
2195 .release
= solo1_dmfm_release
,
2198 /* --------------------------------------------------------------------- */
2200 static struct initvol
{
2203 } initvol
[] __devinitdata
= {
2204 { SOUND_MIXER_WRITE_VOLUME
, 0x4040 },
2205 { SOUND_MIXER_WRITE_PCM
, 0x4040 },
2206 { SOUND_MIXER_WRITE_SYNTH
, 0x4040 },
2207 { SOUND_MIXER_WRITE_CD
, 0x4040 },
2208 { SOUND_MIXER_WRITE_LINE
, 0x4040 },
2209 { SOUND_MIXER_WRITE_LINE1
, 0x4040 },
2210 { SOUND_MIXER_WRITE_LINE2
, 0x4040 },
2211 { SOUND_MIXER_WRITE_RECLEV
, 0x4040 },
2212 { SOUND_MIXER_WRITE_SPEAKER
, 0x4040 },
2213 { SOUND_MIXER_WRITE_MIC
, 0x4040 }
2216 static int setup_solo1(struct solo1_state
*s
)
2218 struct pci_dev
*pcidev
= s
->dev
;
2222 /* initialize DDMA base address */
2223 printk(KERN_DEBUG
"solo1: ddma base address: 0x%lx\n", s
->ddmabase
);
2224 pci_write_config_word(pcidev
, 0x60, (s
->ddmabase
& (~0xf)) | 1);
2225 /* set DMA policy to DDMA, IRQ emulation off (CLKRUN disabled for now) */
2226 pci_write_config_dword(pcidev
, 0x50, 0);
2227 /* disable legacy audio address decode */
2228 pci_write_config_word(pcidev
, 0x40, 0x907f);
2230 /* initialize the chips */
2231 if (!reset_ctrl(s
)) {
2232 printk(KERN_ERR
"esssolo1: cannot reset controller\n");
2235 outb(0xb0, s
->iobase
+7); /* enable A1, A2, MPU irq's */
2237 /* initialize mixer regs */
2238 write_mixer(s
, 0x7f, 0); /* disable music digital recording */
2239 write_mixer(s
, 0x7d, 0x0c); /* enable mic preamp, MONO_OUT is 2nd DAC right channel */
2240 write_mixer(s
, 0x64, 0x45); /* volume control */
2241 write_mixer(s
, 0x48, 0x10); /* enable music DAC/ES6xx interface */
2242 write_mixer(s
, 0x50, 0); /* disable spatializer */
2243 write_mixer(s
, 0x52, 0);
2244 write_mixer(s
, 0x14, 0); /* DAC1 minimum volume */
2245 write_mixer(s
, 0x71, 0x20); /* enable new 0xA1 reg format */
2246 outb(0, s
->ddmabase
+0xd); /* DMA master clear */
2247 outb(1, s
->ddmabase
+0xf); /* mask channel */
2248 /*outb(0, s->ddmabase+0x8);*/ /* enable controller (enable is low active!!) */
2250 pci_set_master(pcidev
); /* enable bus mastering */
2254 val
= SOUND_MASK_LINE
;
2255 mixer_ioctl(s
, SOUND_MIXER_WRITE_RECSRC
, (unsigned long)&val
);
2256 for (i
= 0; i
< sizeof(initvol
)/sizeof(initvol
[0]); i
++) {
2257 val
= initvol
[i
].vol
;
2258 mixer_ioctl(s
, initvol
[i
].mixch
, (unsigned long)&val
);
2260 val
= 1; /* enable mic preamp */
2261 mixer_ioctl(s
, SOUND_MIXER_PRIVATE1
, (unsigned long)&val
);
2267 solo1_suspend(struct pci_dev
*pci_dev
, pm_message_t state
) {
2268 struct solo1_state
*s
= (struct solo1_state
*)pci_get_drvdata(pci_dev
);
2271 outb(0, s
->iobase
+6);
2272 /* DMA master clear */
2273 outb(0, s
->ddmabase
+0xd);
2274 /* reset sequencer and FIFO */
2275 outb(3, s
->sbbase
+6);
2276 /* turn off DDMA controller address space */
2277 pci_write_config_word(s
->dev
, 0x60, 0);
2282 solo1_resume(struct pci_dev
*pci_dev
) {
2283 struct solo1_state
*s
= (struct solo1_state
*)pci_get_drvdata(pci_dev
);
2290 #ifdef SUPPORT_JOYSTICK
2291 static int __devinit
solo1_register_gameport(struct solo1_state
*s
, int io_port
)
2293 struct gameport
*gp
;
2295 if (!request_region(io_port
, GAMEPORT_EXTENT
, "ESS Solo1")) {
2296 printk(KERN_ERR
"solo1: gameport io ports are in use\n");
2300 s
->gameport
= gp
= gameport_allocate_port();
2302 printk(KERN_ERR
"solo1: can not allocate memory for gameport\n");
2303 release_region(io_port
, GAMEPORT_EXTENT
);
2307 gameport_set_name(gp
, "ESS Solo1 Gameport");
2308 gameport_set_phys(gp
, "isa%04x/gameport0", io_port
);
2309 gp
->dev
.parent
= &s
->dev
->dev
;
2312 gameport_register_port(gp
);
2317 static inline void solo1_unregister_gameport(struct solo1_state
*s
)
2320 int gpio
= s
->gameport
->io
;
2321 gameport_unregister_port(s
->gameport
);
2322 release_region(gpio
, GAMEPORT_EXTENT
);
2326 static inline int solo1_register_gameport(struct solo1_state
*s
, int io_port
) { return -ENOSYS
; }
2327 static inline void solo1_unregister_gameport(struct solo1_state
*s
) { }
2328 #endif /* SUPPORT_JOYSTICK */
2330 static int __devinit
solo1_probe(struct pci_dev
*pcidev
, const struct pci_device_id
*pciid
)
2332 struct solo1_state
*s
;
2336 if ((ret
=pci_enable_device(pcidev
)))
2338 if (!(pci_resource_flags(pcidev
, 0) & IORESOURCE_IO
) ||
2339 !(pci_resource_flags(pcidev
, 1) & IORESOURCE_IO
) ||
2340 !(pci_resource_flags(pcidev
, 2) & IORESOURCE_IO
) ||
2341 !(pci_resource_flags(pcidev
, 3) & IORESOURCE_IO
))
2343 if (pcidev
->irq
== 0)
2346 /* Recording requires 24-bit DMA, so attempt to set dma mask
2347 * to 24 bits first, then 32 bits (playback only) if that fails.
2349 if (pci_set_dma_mask(pcidev
, 0x00ffffff) &&
2350 pci_set_dma_mask(pcidev
, DMA_32BIT_MASK
)) {
2351 printk(KERN_WARNING
"solo1: architecture does not support 24bit or 32bit PCI busmaster DMA\n");
2355 if (!(s
= kmalloc(sizeof(struct solo1_state
), GFP_KERNEL
))) {
2356 printk(KERN_WARNING
"solo1: out of memory\n");
2359 memset(s
, 0, sizeof(struct solo1_state
));
2360 init_waitqueue_head(&s
->dma_adc
.wait
);
2361 init_waitqueue_head(&s
->dma_dac
.wait
);
2362 init_waitqueue_head(&s
->open_wait
);
2363 init_waitqueue_head(&s
->midi
.iwait
);
2364 init_waitqueue_head(&s
->midi
.owait
);
2365 init_MUTEX(&s
->open_sem
);
2366 spin_lock_init(&s
->lock
);
2367 s
->magic
= SOLO1_MAGIC
;
2369 s
->iobase
= pci_resource_start(pcidev
, 0);
2370 s
->sbbase
= pci_resource_start(pcidev
, 1);
2371 s
->vcbase
= pci_resource_start(pcidev
, 2);
2372 s
->ddmabase
= s
->vcbase
+ DDMABASE_OFFSET
;
2373 s
->mpubase
= pci_resource_start(pcidev
, 3);
2374 gpio
= pci_resource_start(pcidev
, 4);
2375 s
->irq
= pcidev
->irq
;
2377 if (!request_region(s
->iobase
, IOBASE_EXTENT
, "ESS Solo1")) {
2378 printk(KERN_ERR
"solo1: io ports in use\n");
2381 if (!request_region(s
->sbbase
+FMSYNTH_EXTENT
, SBBASE_EXTENT
-FMSYNTH_EXTENT
, "ESS Solo1")) {
2382 printk(KERN_ERR
"solo1: io ports in use\n");
2385 if (!request_region(s
->ddmabase
, DDMABASE_EXTENT
, "ESS Solo1")) {
2386 printk(KERN_ERR
"solo1: io ports in use\n");
2389 if (!request_region(s
->mpubase
, MPUBASE_EXTENT
, "ESS Solo1")) {
2390 printk(KERN_ERR
"solo1: io ports in use\n");
2393 if ((ret
=request_irq(s
->irq
,solo1_interrupt
,SA_SHIRQ
,"ESS Solo1",s
))) {
2394 printk(KERN_ERR
"solo1: irq %u in use\n", s
->irq
);
2397 /* register devices */
2398 if ((s
->dev_audio
= register_sound_dsp(&solo1_audio_fops
, -1)) < 0) {
2402 if ((s
->dev_mixer
= register_sound_mixer(&solo1_mixer_fops
, -1)) < 0) {
2406 if ((s
->dev_midi
= register_sound_midi(&solo1_midi_fops
, -1)) < 0) {
2410 if ((s
->dev_dmfm
= register_sound_special(&solo1_dmfm_fops
, 15 /* ?? */)) < 0) {
2414 if (setup_solo1(s
)) {
2418 /* register gameport */
2419 solo1_register_gameport(s
, gpio
);
2420 /* store it in the driver field */
2421 pci_set_drvdata(pcidev
, s
);
2425 unregister_sound_special(s
->dev_dmfm
);
2427 unregister_sound_midi(s
->dev_midi
);
2429 unregister_sound_mixer(s
->dev_mixer
);
2431 unregister_sound_dsp(s
->dev_audio
);
2433 printk(KERN_ERR
"solo1: initialisation error\n");
2434 free_irq(s
->irq
, s
);
2436 release_region(s
->mpubase
, MPUBASE_EXTENT
);
2438 release_region(s
->ddmabase
, DDMABASE_EXTENT
);
2440 release_region(s
->sbbase
+FMSYNTH_EXTENT
, SBBASE_EXTENT
-FMSYNTH_EXTENT
);
2442 release_region(s
->iobase
, IOBASE_EXTENT
);
2448 static void __devexit
solo1_remove(struct pci_dev
*dev
)
2450 struct solo1_state
*s
= pci_get_drvdata(dev
);
2454 /* stop DMA controller */
2455 outb(0, s
->iobase
+6);
2456 outb(0, s
->ddmabase
+0xd); /* DMA master clear */
2457 outb(3, s
->sbbase
+6); /* reset sequencer and FIFO */
2458 synchronize_irq(s
->irq
);
2459 pci_write_config_word(s
->dev
, 0x60, 0); /* turn off DDMA controller address space */
2460 free_irq(s
->irq
, s
);
2461 solo1_unregister_gameport(s
);
2462 release_region(s
->iobase
, IOBASE_EXTENT
);
2463 release_region(s
->sbbase
+FMSYNTH_EXTENT
, SBBASE_EXTENT
-FMSYNTH_EXTENT
);
2464 release_region(s
->ddmabase
, DDMABASE_EXTENT
);
2465 release_region(s
->mpubase
, MPUBASE_EXTENT
);
2466 unregister_sound_dsp(s
->dev_audio
);
2467 unregister_sound_mixer(s
->dev_mixer
);
2468 unregister_sound_midi(s
->dev_midi
);
2469 unregister_sound_special(s
->dev_dmfm
);
2471 pci_set_drvdata(dev
, NULL
);
2474 static struct pci_device_id id_table
[] = {
2475 { PCI_VENDOR_ID_ESS
, PCI_DEVICE_ID_ESS_SOLO1
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0 },
2479 MODULE_DEVICE_TABLE(pci
, id_table
);
2481 static struct pci_driver solo1_driver
= {
2482 .name
= "ESS Solo1",
2483 .id_table
= id_table
,
2484 .probe
= solo1_probe
,
2485 .remove
= __devexit_p(solo1_remove
),
2486 .suspend
= solo1_suspend
,
2487 .resume
= solo1_resume
,
2491 static int __init
init_solo1(void)
2493 printk(KERN_INFO
"solo1: version v0.20 time " __TIME__
" " __DATE__
"\n");
2494 return pci_register_driver(&solo1_driver
);
2497 /* --------------------------------------------------------------------- */
2499 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
2500 MODULE_DESCRIPTION("ESS Solo1 Driver");
2501 MODULE_LICENSE("GPL");
2504 static void __exit
cleanup_solo1(void)
2506 printk(KERN_INFO
"solo1: unloading\n");
2507 pci_unregister_driver(&solo1_driver
);
2510 /* --------------------------------------------------------------------- */
2512 module_init(init_solo1
);
2513 module_exit(cleanup_solo1
);