2 * Driver for ESS Solo-1 (ES1938, ES1946, ES1969) soundcard
3 * Copyright (c) by Jaromir Koutek <miri@punknet.cz>,
4 * Jaroslav Kysela <perex@suse.cz>,
5 * Thomas Sailer <sailer@ife.ee.ethz.ch>,
6 * Abramo Bagnara <abramo@alsa-project.org>,
7 * Markus Gruber <gruber@eikon.tum.de>
9 * Rewritten from sonicvibes.c source.
12 * Rewrite better spinlocks
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 - Capture data is written unaligned starting from dma_base + 1 so I need to
34 disable mmap and to add a copy callback.
35 - After several cycle of the following:
36 while : ; do arecord -d1 -f cd -t raw | aplay -f cd ; done
37 a "playback write error (DMA or IRQ trouble?)" may happen.
38 This is due to playback interrupts not generated.
39 I suspect a timing issue.
40 - Sometimes the interrupt handler is invoked wrongly during playback.
41 This generates some harmless "Unexpected hw_pointer: wrong interrupt
43 I've seen that using small period sizes.
50 #include <sound/driver.h>
51 #include <linux/init.h>
52 #include <linux/interrupt.h>
53 #include <linux/pci.h>
54 #include <linux/slab.h>
55 #include <linux/gameport.h>
56 #include <linux/moduleparam.h>
57 #include <linux/delay.h>
58 #include <sound/core.h>
59 #include <sound/control.h>
60 #include <sound/pcm.h>
61 #include <sound/opl3.h>
62 #include <sound/mpu401.h>
63 #include <sound/initval.h>
67 MODULE_AUTHOR("Jaromir Koutek <miri@punknet.cz>");
68 MODULE_DESCRIPTION("ESS Solo-1");
69 MODULE_LICENSE("GPL");
70 MODULE_SUPPORTED_DEVICE("{{ESS,ES1938},"
73 "{TerraTec,128i PCI}}");
75 #ifndef PCI_VENDOR_ID_ESS
76 #define PCI_VENDOR_ID_ESS 0x125d
78 #ifndef PCI_DEVICE_ID_ESS_ES1938
79 #define PCI_DEVICE_ID_ESS_ES1938 0x1969
82 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
83 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
84 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
86 module_param_array(index, int, NULL, 0444);
87 MODULE_PARM_DESC(index, "Index value for ESS Solo-1 soundcard.");
88 module_param_array(id, charp, NULL, 0444);
89 MODULE_PARM_DESC(id, "ID string for ESS Solo-1 soundcard.");
90 module_param_array(enable, bool, NULL, 0444);
91 MODULE_PARM_DESC(enable, "Enable ESS Solo-1 soundcard.");
93 #define SLIO_REG(chip, x) ((chip)->io_port + ESSIO_REG_##x)
95 #define SLDM_REG(chip, x) ((chip)->ddma_port + ESSDM_REG_##x)
97 #define SLSB_REG(chip, x) ((chip)->sb_port + ESSSB_REG_##x)
99 #define SL_PCI_LEGACYCONTROL 0x40
100 #define SL_PCI_CONFIG 0x50
101 #define SL_PCI_DDMACONTROL 0x60
103 #define ESSIO_REG_AUDIO2DMAADDR 0
104 #define ESSIO_REG_AUDIO2DMACOUNT 4
105 #define ESSIO_REG_AUDIO2MODE 6
106 #define ESSIO_REG_IRQCONTROL 7
108 #define ESSDM_REG_DMAADDR 0x00
109 #define ESSDM_REG_DMACOUNT 0x04
110 #define ESSDM_REG_DMACOMMAND 0x08
111 #define ESSDM_REG_DMASTATUS 0x08
112 #define ESSDM_REG_DMAMODE 0x0b
113 #define ESSDM_REG_DMACLEAR 0x0d
114 #define ESSDM_REG_DMAMASK 0x0f
116 #define ESSSB_REG_FMLOWADDR 0x00
117 #define ESSSB_REG_FMHIGHADDR 0x02
118 #define ESSSB_REG_MIXERADDR 0x04
119 #define ESSSB_REG_MIXERDATA 0x05
121 #define ESSSB_IREG_AUDIO1 0x14
122 #define ESSSB_IREG_MICMIX 0x1a
123 #define ESSSB_IREG_RECSRC 0x1c
124 #define ESSSB_IREG_MASTER 0x32
125 #define ESSSB_IREG_FM 0x36
126 #define ESSSB_IREG_AUXACD 0x38
127 #define ESSSB_IREG_AUXB 0x3a
128 #define ESSSB_IREG_PCSPEAKER 0x3c
129 #define ESSSB_IREG_LINE 0x3e
130 #define ESSSB_IREG_SPATCONTROL 0x50
131 #define ESSSB_IREG_SPATLEVEL 0x52
132 #define ESSSB_IREG_MASTER_LEFT 0x60
133 #define ESSSB_IREG_MASTER_RIGHT 0x62
134 #define ESSSB_IREG_MPU401CONTROL 0x64
135 #define ESSSB_IREG_MICMIXRECORD 0x68
136 #define ESSSB_IREG_AUDIO2RECORD 0x69
137 #define ESSSB_IREG_AUXACDRECORD 0x6a
138 #define ESSSB_IREG_FMRECORD 0x6b
139 #define ESSSB_IREG_AUXBRECORD 0x6c
140 #define ESSSB_IREG_MONO 0x6d
141 #define ESSSB_IREG_LINERECORD 0x6e
142 #define ESSSB_IREG_MONORECORD 0x6f
143 #define ESSSB_IREG_AUDIO2SAMPLE 0x70
144 #define ESSSB_IREG_AUDIO2MODE 0x71
145 #define ESSSB_IREG_AUDIO2FILTER 0x72
146 #define ESSSB_IREG_AUDIO2TCOUNTL 0x74
147 #define ESSSB_IREG_AUDIO2TCOUNTH 0x76
148 #define ESSSB_IREG_AUDIO2CONTROL1 0x78
149 #define ESSSB_IREG_AUDIO2CONTROL2 0x7a
150 #define ESSSB_IREG_AUDIO2 0x7c
152 #define ESSSB_REG_RESET 0x06
154 #define ESSSB_REG_READDATA 0x0a
155 #define ESSSB_REG_WRITEDATA 0x0c
156 #define ESSSB_REG_READSTATUS 0x0c
158 #define ESSSB_REG_STATUS 0x0e
160 #define ESS_CMD_EXTSAMPLERATE 0xa1
161 #define ESS_CMD_FILTERDIV 0xa2
162 #define ESS_CMD_DMACNTRELOADL 0xa4
163 #define ESS_CMD_DMACNTRELOADH 0xa5
164 #define ESS_CMD_ANALOGCONTROL 0xa8
165 #define ESS_CMD_IRQCONTROL 0xb1
166 #define ESS_CMD_DRQCONTROL 0xb2
167 #define ESS_CMD_RECLEVEL 0xb4
168 #define ESS_CMD_SETFORMAT 0xb6
169 #define ESS_CMD_SETFORMAT2 0xb7
170 #define ESS_CMD_DMACONTROL 0xb8
171 #define ESS_CMD_DMATYPE 0xb9
172 #define ESS_CMD_OFFSETLEFT 0xba
173 #define ESS_CMD_OFFSETRIGHT 0xbb
174 #define ESS_CMD_READREG 0xc0
175 #define ESS_CMD_ENABLEEXT 0xc6
176 #define ESS_CMD_PAUSEDMA 0xd0
177 #define ESS_CMD_ENABLEAUDIO1 0xd1
178 #define ESS_CMD_STOPAUDIO1 0xd3
179 #define ESS_CMD_AUDIO1STATUS 0xd8
180 #define ESS_CMD_CONTDMA 0xd4
181 #define ESS_CMD_TESTIRQ 0xf2
183 #define ESS_RECSRC_MIC 0
184 #define ESS_RECSRC_AUXACD 2
185 #define ESS_RECSRC_AUXB 5
186 #define ESS_RECSRC_LINE 6
187 #define ESS_RECSRC_NONE 7
197 typedef struct _snd_es1938 es1938_t;
199 #define SAVED_REG_SIZE 32 /* max. number of registers to save */
204 unsigned long io_port;
205 unsigned long sb_port;
206 unsigned long vc_port;
207 unsigned long mpu_port;
208 unsigned long game_port;
209 unsigned long ddma_port;
211 unsigned char irqmask;
212 unsigned char revision;
214 snd_kcontrol_t *hw_volume;
215 snd_kcontrol_t *hw_switch;
216 snd_kcontrol_t *master_volume;
217 snd_kcontrol_t *master_switch;
222 snd_pcm_substream_t *capture_substream;
223 snd_pcm_substream_t *playback1_substream;
224 snd_pcm_substream_t *playback2_substream;
226 snd_rawmidi_t *rmidi;
228 unsigned int dma1_size;
229 unsigned int dma2_size;
230 unsigned int dma1_start;
231 unsigned int dma2_start;
232 unsigned int dma1_shift;
233 unsigned int dma2_shift;
237 spinlock_t mixer_lock;
238 snd_info_entry_t *proc_entry;
240 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
241 struct gameport gameport;
244 unsigned char saved_regs[SAVED_REG_SIZE];
248 static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *regs);
250 static struct pci_device_id snd_es1938_ids[] = {
251 { 0x125d, 0x1969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Solo-1 */
255 MODULE_DEVICE_TABLE(pci, snd_es1938_ids);
257 #define RESET_LOOP_TIMEOUT 0x10000
258 #define WRITE_LOOP_TIMEOUT 0x10000
259 #define GET_LOOP_TIMEOUT 0x01000
262 /* -----------------------------------------------------------------
263 * Write to a mixer register
264 * -----------------------------------------------------------------*/
265 static void snd_es1938_mixer_write(es1938_t *chip, unsigned char reg, unsigned char val)
268 spin_lock_irqsave(&chip->mixer_lock, flags);
269 outb(reg, SLSB_REG(chip, MIXERADDR));
270 outb(val, SLSB_REG(chip, MIXERDATA));
271 spin_unlock_irqrestore(&chip->mixer_lock, flags);
273 snd_printk("Mixer reg %02x set to %02x\n", reg, val);
277 /* -----------------------------------------------------------------
278 * Read from a mixer register
279 * -----------------------------------------------------------------*/
280 static int snd_es1938_mixer_read(es1938_t *chip, unsigned char reg)
284 spin_lock_irqsave(&chip->mixer_lock, flags);
285 outb(reg, SLSB_REG(chip, MIXERADDR));
286 data = inb(SLSB_REG(chip, MIXERDATA));
287 spin_unlock_irqrestore(&chip->mixer_lock, flags);
289 snd_printk("Mixer reg %02x now is %02x\n", reg, data);
294 /* -----------------------------------------------------------------
295 * Write to some bits of a mixer register (return old value)
296 * -----------------------------------------------------------------*/
297 static int snd_es1938_mixer_bits(es1938_t *chip, unsigned char reg, unsigned char mask, unsigned char val)
300 unsigned char old, new, oval;
301 spin_lock_irqsave(&chip->mixer_lock, flags);
302 outb(reg, SLSB_REG(chip, MIXERADDR));
303 old = inb(SLSB_REG(chip, MIXERDATA));
306 new = (old & ~mask) | (val & mask);
307 outb(new, SLSB_REG(chip, MIXERDATA));
309 snd_printk("Mixer reg %02x was %02x, set to %02x\n", reg, old, new);
312 spin_unlock_irqrestore(&chip->mixer_lock, flags);
316 /* -----------------------------------------------------------------
317 * Write command to Controller Registers
318 * -----------------------------------------------------------------*/
319 static void snd_es1938_write_cmd(es1938_t *chip, unsigned char cmd)
323 for (i = 0; i < WRITE_LOOP_TIMEOUT; i++) {
324 if (!(v = inb(SLSB_REG(chip, READSTATUS)) & 0x80)) {
325 outb(cmd, SLSB_REG(chip, WRITEDATA));
329 printk("snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v);
332 /* -----------------------------------------------------------------
333 * Read the Read Data Buffer
334 * -----------------------------------------------------------------*/
335 static int snd_es1938_get_byte(es1938_t *chip)
339 for (i = GET_LOOP_TIMEOUT; i; i--)
340 if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80)
341 return inb(SLSB_REG(chip, READDATA));
342 snd_printk("get_byte timeout: status 0x02%x\n", v);
346 /* -----------------------------------------------------------------
347 * Write value cmd register
348 * -----------------------------------------------------------------*/
349 static void snd_es1938_write(es1938_t *chip, unsigned char reg, unsigned char val)
352 spin_lock_irqsave(&chip->reg_lock, flags);
353 snd_es1938_write_cmd(chip, reg);
354 snd_es1938_write_cmd(chip, val);
355 spin_unlock_irqrestore(&chip->reg_lock, flags);
357 snd_printk("Reg %02x set to %02x\n", reg, val);
361 /* -----------------------------------------------------------------
362 * Read data from cmd register and return it
363 * -----------------------------------------------------------------*/
364 static unsigned char snd_es1938_read(es1938_t *chip, unsigned char reg)
368 spin_lock_irqsave(&chip->reg_lock, flags);
369 snd_es1938_write_cmd(chip, ESS_CMD_READREG);
370 snd_es1938_write_cmd(chip, reg);
371 val = snd_es1938_get_byte(chip);
372 spin_unlock_irqrestore(&chip->reg_lock, flags);
374 snd_printk("Reg %02x now is %02x\n", reg, val);
379 /* -----------------------------------------------------------------
380 * Write data to cmd register and return old value
381 * -----------------------------------------------------------------*/
382 static int snd_es1938_bits(es1938_t *chip, unsigned char reg, unsigned char mask, unsigned char val)
385 unsigned char old, new, oval;
386 spin_lock_irqsave(&chip->reg_lock, flags);
387 snd_es1938_write_cmd(chip, ESS_CMD_READREG);
388 snd_es1938_write_cmd(chip, reg);
389 old = snd_es1938_get_byte(chip);
392 snd_es1938_write_cmd(chip, reg);
393 new = (old & ~mask) | (val & mask);
394 snd_es1938_write_cmd(chip, new);
396 snd_printk("Reg %02x was %02x, set to %02x\n", reg, old, new);
399 spin_unlock_irqrestore(&chip->reg_lock, flags);
403 /* --------------------------------------------------------------------
405 * --------------------------------------------------------------------*/
406 static void snd_es1938_reset(es1938_t *chip)
410 outb(3, SLSB_REG(chip, RESET));
411 inb(SLSB_REG(chip, RESET));
412 outb(0, SLSB_REG(chip, RESET));
413 for (i = 0; i < RESET_LOOP_TIMEOUT; i++) {
414 if (inb(SLSB_REG(chip, STATUS)) & 0x80) {
415 if (inb(SLSB_REG(chip, READDATA)) == 0xaa)
419 snd_printk("ESS Solo-1 reset failed\n");
422 snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT);
424 /* Demand transfer DMA: 4 bytes per DMA request */
425 snd_es1938_write(chip, ESS_CMD_DMATYPE, 2);
427 /* Change behaviour of register A1
429 2nd channel DAC asynchronous */
430 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2MODE, 0x32);
431 /* enable/select DMA channel and IRQ channel */
432 snd_es1938_bits(chip, ESS_CMD_IRQCONTROL, 0xf0, 0x50);
433 snd_es1938_bits(chip, ESS_CMD_DRQCONTROL, 0xf0, 0x50);
434 snd_es1938_write_cmd(chip, ESS_CMD_ENABLEAUDIO1);
435 /* Set spatializer parameters to recommended values */
436 snd_es1938_mixer_write(chip, 0x54, 0x8f);
437 snd_es1938_mixer_write(chip, 0x56, 0x95);
438 snd_es1938_mixer_write(chip, 0x58, 0x94);
439 snd_es1938_mixer_write(chip, 0x5a, 0x80);
442 /* --------------------------------------------------------------------
444 * --------------------------------------------------------------------*/
445 static void snd_es1938_reset_fifo(es1938_t *chip)
447 outb(2, SLSB_REG(chip, RESET));
448 outb(0, SLSB_REG(chip, RESET));
451 static ratnum_t clocks[2] = {
466 static snd_pcm_hw_constraint_ratnums_t hw_constraints_clocks = {
472 static void snd_es1938_rate_set(es1938_t *chip,
473 snd_pcm_substream_t *substream,
476 unsigned int bits, div0;
477 snd_pcm_runtime_t *runtime = substream->runtime;
478 if (runtime->rate_num == clocks[0].num)
479 bits = 128 - runtime->rate_den;
481 bits = 256 - runtime->rate_den;
483 /* set filter register */
484 div0 = 256 - 7160000*20/(8*82*runtime->rate);
487 snd_es1938_mixer_write(chip, 0x70, bits);
488 snd_es1938_mixer_write(chip, 0x72, div0);
490 snd_es1938_write(chip, 0xA1, bits);
491 snd_es1938_write(chip, 0xA2, div0);
495 /* --------------------------------------------------------------------
496 * Configure Solo1 builtin DMA Controller
497 * --------------------------------------------------------------------*/
499 static void snd_es1938_playback1_setdma(es1938_t *chip)
501 outb(0x00, SLIO_REG(chip, AUDIO2MODE));
502 outl(chip->dma2_start, SLIO_REG(chip, AUDIO2DMAADDR));
503 outw(0, SLIO_REG(chip, AUDIO2DMACOUNT));
504 outw(chip->dma2_size, SLIO_REG(chip, AUDIO2DMACOUNT));
507 static void snd_es1938_playback2_setdma(es1938_t *chip)
509 /* Enable DMA controller */
510 outb(0xc4, SLDM_REG(chip, DMACOMMAND));
511 /* 1. Master reset */
512 outb(0, SLDM_REG(chip, DMACLEAR));
514 outb(1, SLDM_REG(chip, DMAMASK));
515 outb(0x18, SLDM_REG(chip, DMAMODE));
516 outl(chip->dma1_start, SLDM_REG(chip, DMAADDR));
517 outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT));
519 outb(0, SLDM_REG(chip, DMAMASK));
522 static void snd_es1938_capture_setdma(es1938_t *chip)
524 /* Enable DMA controller */
525 outb(0xc4, SLDM_REG(chip, DMACOMMAND));
526 /* 1. Master reset */
527 outb(0, SLDM_REG(chip, DMACLEAR));
529 outb(1, SLDM_REG(chip, DMAMASK));
530 outb(0x14, SLDM_REG(chip, DMAMODE));
531 outl(chip->dma1_start, SLDM_REG(chip, DMAADDR));
532 outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT));
534 outb(0, SLDM_REG(chip, DMAMASK));
537 /* ----------------------------------------------------------------------
542 static int snd_es1938_capture_trigger(snd_pcm_substream_t * substream,
545 es1938_t *chip = snd_pcm_substream_chip(substream);
548 case SNDRV_PCM_TRIGGER_START:
550 chip->active |= ADC1;
552 case SNDRV_PCM_TRIGGER_STOP:
554 chip->active &= ~ADC1;
559 snd_es1938_write(chip, ESS_CMD_DMACONTROL, val);
563 static int snd_es1938_playback1_trigger(snd_pcm_substream_t * substream,
566 es1938_t *chip = snd_pcm_substream_chip(substream);
568 case SNDRV_PCM_TRIGGER_START:
569 /* According to the documentation this should be:
570 0x13 but that value may randomly swap stereo channels */
571 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x92);
573 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x93);
574 /* This two stage init gives the FIFO -> DAC connection time to
575 * settle before first data from DMA flows in. This should ensure
576 * no swapping of stereo channels. Report a bug if otherwise :-) */
577 outb(0x0a, SLIO_REG(chip, AUDIO2MODE));
578 chip->active |= DAC2;
580 case SNDRV_PCM_TRIGGER_STOP:
581 outb(0, SLIO_REG(chip, AUDIO2MODE));
582 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0);
583 chip->active &= ~DAC2;
591 static int snd_es1938_playback2_trigger(snd_pcm_substream_t * substream,
594 es1938_t *chip = snd_pcm_substream_chip(substream);
597 case SNDRV_PCM_TRIGGER_START:
599 chip->active |= DAC1;
601 case SNDRV_PCM_TRIGGER_STOP:
603 chip->active &= ~DAC1;
608 snd_es1938_write(chip, ESS_CMD_DMACONTROL, val);
612 static int snd_es1938_playback_trigger(snd_pcm_substream_t *substream,
615 switch (substream->number) {
617 return snd_es1938_playback1_trigger(substream, cmd);
619 return snd_es1938_playback2_trigger(substream, cmd);
625 /* --------------------------------------------------------------------
626 * First channel for Extended Mode Audio 1 ADC Operation
627 * --------------------------------------------------------------------*/
628 static int snd_es1938_capture_prepare(snd_pcm_substream_t * substream)
630 es1938_t *chip = snd_pcm_substream_chip(substream);
631 snd_pcm_runtime_t *runtime = substream->runtime;
633 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
634 unsigned int count = snd_pcm_lib_period_bytes(substream);
636 chip->dma1_size = size;
637 chip->dma1_start = runtime->dma_addr;
639 mono = (runtime->channels > 1) ? 0 : 1;
640 is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
641 u = snd_pcm_format_unsigned(runtime->format);
643 chip->dma1_shift = 2 - mono - is8;
645 snd_es1938_reset_fifo(chip);
648 snd_es1938_bits(chip, ESS_CMD_ANALOGCONTROL, 0x03, (mono ? 2 : 1));
650 /* set clock and counters */
651 snd_es1938_rate_set(chip, substream, ADC1);
653 count = 0x10000 - count;
654 snd_es1938_write(chip, ESS_CMD_DMACNTRELOADL, count & 0xff);
655 snd_es1938_write(chip, ESS_CMD_DMACNTRELOADH, count >> 8);
657 /* initialize and configure ADC */
658 snd_es1938_write(chip, ESS_CMD_SETFORMAT2, u ? 0x51 : 0x71);
659 snd_es1938_write(chip, ESS_CMD_SETFORMAT2, 0x90 |
661 (is8 ? 0x00 : 0x04) |
662 (mono ? 0x40 : 0x08));
664 // snd_es1938_reset_fifo(chip);
666 /* 11. configure system interrupt controller and DMA controller */
667 snd_es1938_capture_setdma(chip);
673 /* ------------------------------------------------------------------------------
674 * Second Audio channel DAC Operation
675 * ------------------------------------------------------------------------------*/
676 static int snd_es1938_playback1_prepare(snd_pcm_substream_t * substream)
678 es1938_t *chip = snd_pcm_substream_chip(substream);
679 snd_pcm_runtime_t *runtime = substream->runtime;
681 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
682 unsigned int count = snd_pcm_lib_period_bytes(substream);
684 chip->dma2_size = size;
685 chip->dma2_start = runtime->dma_addr;
687 mono = (runtime->channels > 1) ? 0 : 1;
688 is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
689 u = snd_pcm_format_unsigned(runtime->format);
691 chip->dma2_shift = 2 - mono - is8;
693 snd_es1938_reset_fifo(chip);
695 /* set clock and counters */
696 snd_es1938_rate_set(chip, substream, DAC2);
699 count = 0x10000 - count;
700 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2TCOUNTL, count & 0xff);
701 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2TCOUNTH, count >> 8);
703 /* initialize and configure Audio 2 DAC */
704 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL2, 0x40 | (u ? 0 : 4) | (mono ? 0 : 2) | (is8 ? 0 : 1));
707 snd_es1938_playback1_setdma(chip);
712 static int snd_es1938_playback2_prepare(snd_pcm_substream_t * substream)
714 es1938_t *chip = snd_pcm_substream_chip(substream);
715 snd_pcm_runtime_t *runtime = substream->runtime;
717 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
718 unsigned int count = snd_pcm_lib_period_bytes(substream);
720 chip->dma1_size = size;
721 chip->dma1_start = runtime->dma_addr;
723 mono = (runtime->channels > 1) ? 0 : 1;
724 is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
725 u = snd_pcm_format_unsigned(runtime->format);
727 chip->dma1_shift = 2 - mono - is8;
729 count = 0x10000 - count;
732 snd_es1938_reset_fifo(chip);
734 snd_es1938_bits(chip, ESS_CMD_ANALOGCONTROL, 0x03, (mono ? 2 : 1));
736 /* set clock and counters */
737 snd_es1938_rate_set(chip, substream, DAC1);
738 snd_es1938_write(chip, ESS_CMD_DMACNTRELOADL, count & 0xff);
739 snd_es1938_write(chip, ESS_CMD_DMACNTRELOADH, count >> 8);
741 /* initialized and configure DAC */
742 snd_es1938_write(chip, ESS_CMD_SETFORMAT, u ? 0x80 : 0x00);
743 snd_es1938_write(chip, ESS_CMD_SETFORMAT, u ? 0x51 : 0x71);
744 snd_es1938_write(chip, ESS_CMD_SETFORMAT2,
745 0x90 | (mono ? 0x40 : 0x08) |
746 (is8 ? 0x00 : 0x04) | (u ? 0x00 : 0x20));
749 snd_es1938_playback2_setdma(chip);
754 static int snd_es1938_playback_prepare(snd_pcm_substream_t *substream)
756 switch (substream->number) {
758 return snd_es1938_playback1_prepare(substream);
760 return snd_es1938_playback2_prepare(substream);
766 static snd_pcm_uframes_t snd_es1938_capture_pointer(snd_pcm_substream_t * substream)
768 es1938_t *chip = snd_pcm_substream_chip(substream);
772 /* This stuff is *needed*, don't ask why - AB */
773 old = inw(SLDM_REG(chip, DMACOUNT));
774 while ((new = inw(SLDM_REG(chip, DMACOUNT))) != old)
776 ptr = chip->dma1_size - 1 - new;
778 ptr = inl(SLDM_REG(chip, DMAADDR)) - chip->dma1_start;
780 return ptr >> chip->dma1_shift;
783 static snd_pcm_uframes_t snd_es1938_playback1_pointer(snd_pcm_substream_t * substream)
785 es1938_t *chip = snd_pcm_substream_chip(substream);
788 ptr = chip->dma2_size - inw(SLIO_REG(chip, AUDIO2DMACOUNT));
790 ptr = inl(SLIO_REG(chip, AUDIO2DMAADDR)) - chip->dma2_start;
792 return ptr >> chip->dma2_shift;
795 static snd_pcm_uframes_t snd_es1938_playback2_pointer(snd_pcm_substream_t * substream)
797 es1938_t *chip = snd_pcm_substream_chip(substream);
801 /* This stuff is *needed*, don't ask why - AB */
802 old = inw(SLDM_REG(chip, DMACOUNT));
803 while ((new = inw(SLDM_REG(chip, DMACOUNT))) != old)
805 ptr = chip->dma1_size - 1 - new;
807 ptr = inl(SLDM_REG(chip, DMAADDR)) - chip->dma1_start;
809 return ptr >> chip->dma1_shift;
812 static snd_pcm_uframes_t snd_es1938_playback_pointer(snd_pcm_substream_t *substream)
814 switch (substream->number) {
816 return snd_es1938_playback1_pointer(substream);
818 return snd_es1938_playback2_pointer(substream);
824 static int snd_es1938_capture_copy(snd_pcm_substream_t *substream,
826 snd_pcm_uframes_t pos,
828 snd_pcm_uframes_t count)
830 snd_pcm_runtime_t *runtime = substream->runtime;
831 es1938_t *chip = snd_pcm_substream_chip(substream);
832 pos <<= chip->dma1_shift;
833 count <<= chip->dma1_shift;
834 snd_assert(pos + count <= chip->dma1_size, return -EINVAL);
835 if (pos + count < chip->dma1_size) {
836 if (copy_to_user(dst, runtime->dma_area + pos + 1, count))
839 if (copy_to_user(dst, runtime->dma_area + pos + 1, count - 1))
841 if (put_user(runtime->dma_area[0], ((unsigned char __user *)dst) + count - 1))
850 static int snd_es1938_pcm_hw_params(snd_pcm_substream_t *substream,
851 snd_pcm_hw_params_t * hw_params)
856 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
861 static int snd_es1938_pcm_hw_free(snd_pcm_substream_t *substream)
863 return snd_pcm_lib_free_pages(substream);
866 /* ----------------------------------------------------------------------
867 * Audio1 Capture (ADC)
868 * ----------------------------------------------------------------------*/
869 static snd_pcm_hardware_t snd_es1938_capture =
871 .info = (SNDRV_PCM_INFO_INTERLEAVED |
872 SNDRV_PCM_INFO_BLOCK_TRANSFER),
873 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE,
874 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
879 .buffer_bytes_max = 0x8000, /* DMA controller screws on higher values */
880 .period_bytes_min = 64,
881 .period_bytes_max = 0x8000,
887 /* -----------------------------------------------------------------------
888 * Audio2 Playback (DAC)
889 * -----------------------------------------------------------------------*/
890 static snd_pcm_hardware_t snd_es1938_playback =
892 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
893 SNDRV_PCM_INFO_BLOCK_TRANSFER |
894 SNDRV_PCM_INFO_MMAP_VALID),
895 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE,
896 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
901 .buffer_bytes_max = 0x8000, /* DMA controller screws on higher values */
902 .period_bytes_min = 64,
903 .period_bytes_max = 0x8000,
909 static int snd_es1938_capture_open(snd_pcm_substream_t * substream)
911 es1938_t *chip = snd_pcm_substream_chip(substream);
912 snd_pcm_runtime_t *runtime = substream->runtime;
914 if (chip->playback2_substream)
916 chip->capture_substream = substream;
917 runtime->hw = snd_es1938_capture;
918 snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
919 &hw_constraints_clocks);
920 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, 0xff00);
924 static int snd_es1938_playback_open(snd_pcm_substream_t * substream)
926 es1938_t *chip = snd_pcm_substream_chip(substream);
927 snd_pcm_runtime_t *runtime = substream->runtime;
929 switch (substream->number) {
931 chip->playback1_substream = substream;
934 if (chip->capture_substream)
936 chip->playback2_substream = substream;
942 runtime->hw = snd_es1938_playback;
943 snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
944 &hw_constraints_clocks);
945 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, 0xff00);
949 static int snd_es1938_capture_close(snd_pcm_substream_t * substream)
951 es1938_t *chip = snd_pcm_substream_chip(substream);
953 chip->capture_substream = NULL;
957 static int snd_es1938_playback_close(snd_pcm_substream_t * substream)
959 es1938_t *chip = snd_pcm_substream_chip(substream);
961 switch (substream->number) {
963 chip->playback1_substream = NULL;
966 chip->playback2_substream = NULL;
975 static snd_pcm_ops_t snd_es1938_playback_ops = {
976 .open = snd_es1938_playback_open,
977 .close = snd_es1938_playback_close,
978 .ioctl = snd_pcm_lib_ioctl,
979 .hw_params = snd_es1938_pcm_hw_params,
980 .hw_free = snd_es1938_pcm_hw_free,
981 .prepare = snd_es1938_playback_prepare,
982 .trigger = snd_es1938_playback_trigger,
983 .pointer = snd_es1938_playback_pointer,
986 static snd_pcm_ops_t snd_es1938_capture_ops = {
987 .open = snd_es1938_capture_open,
988 .close = snd_es1938_capture_close,
989 .ioctl = snd_pcm_lib_ioctl,
990 .hw_params = snd_es1938_pcm_hw_params,
991 .hw_free = snd_es1938_pcm_hw_free,
992 .prepare = snd_es1938_capture_prepare,
993 .trigger = snd_es1938_capture_trigger,
994 .pointer = snd_es1938_capture_pointer,
995 .copy = snd_es1938_capture_copy,
998 static void snd_es1938_free_pcm(snd_pcm_t *pcm)
1000 snd_pcm_lib_preallocate_free_for_all(pcm);
1003 static int __devinit snd_es1938_new_pcm(es1938_t *chip, int device)
1008 if ((err = snd_pcm_new(chip->card, "es-1938-1946", device, 2, 1, &pcm)) < 0)
1010 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1938_playback_ops);
1011 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es1938_capture_ops);
1013 pcm->private_data = chip;
1014 pcm->private_free = snd_es1938_free_pcm;
1015 pcm->info_flags = 0;
1016 strcpy(pcm->name, "ESS Solo-1");
1018 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1019 snd_dma_pci_data(chip->pci), 64*1024, 64*1024);
1025 /* -------------------------------------------------------------------
1027 * *** Mixer part ***
1030 static int snd_es1938_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1032 static char *texts[8] = {
1033 "Mic", "Mic Master", "CD", "AOUT",
1034 "Mic1", "Mix", "Line", "Master"
1037 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1039 uinfo->value.enumerated.items = 8;
1040 if (uinfo->value.enumerated.item > 7)
1041 uinfo->value.enumerated.item = 7;
1042 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1046 static int snd_es1938_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1048 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1049 ucontrol->value.enumerated.item[0] = snd_es1938_mixer_read(chip, 0x1c) & 0x07;
1053 static int snd_es1938_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1055 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1056 unsigned char val = ucontrol->value.enumerated.item[0];
1060 return snd_es1938_mixer_bits(chip, 0x1c, 0x07, val) != val;
1063 static int snd_es1938_info_spatializer_enable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1065 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1067 uinfo->value.integer.min = 0;
1068 uinfo->value.integer.max = 1;
1072 static int snd_es1938_get_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1074 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1075 unsigned char val = snd_es1938_mixer_read(chip, 0x50);
1076 ucontrol->value.integer.value[0] = !!(val & 8);
1080 static int snd_es1938_put_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1082 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1083 unsigned char oval, nval;
1085 nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
1086 oval = snd_es1938_mixer_read(chip, 0x50) & 0x0c;
1087 change = nval != oval;
1089 snd_es1938_mixer_write(chip, 0x50, nval & ~0x04);
1090 snd_es1938_mixer_write(chip, 0x50, nval);
1095 static int snd_es1938_info_hw_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1097 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1099 uinfo->value.integer.min = 0;
1100 uinfo->value.integer.max = 63;
1104 static int snd_es1938_get_hw_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1106 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1107 ucontrol->value.integer.value[0] = snd_es1938_mixer_read(chip, 0x61) & 0x3f;
1108 ucontrol->value.integer.value[1] = snd_es1938_mixer_read(chip, 0x63) & 0x3f;
1112 static int snd_es1938_info_hw_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1114 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1116 uinfo->value.integer.min = 0;
1117 uinfo->value.integer.max = 1;
1121 static int snd_es1938_get_hw_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1123 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1124 ucontrol->value.integer.value[0] = !(snd_es1938_mixer_read(chip, 0x61) & 0x40);
1125 ucontrol->value.integer.value[1] = !(snd_es1938_mixer_read(chip, 0x63) & 0x40);
1129 static void snd_es1938_hwv_free(snd_kcontrol_t *kcontrol)
1131 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1132 chip->master_volume = NULL;
1133 chip->master_switch = NULL;
1134 chip->hw_volume = NULL;
1135 chip->hw_switch = NULL;
1138 static int snd_es1938_reg_bits(es1938_t *chip, unsigned char reg,
1139 unsigned char mask, unsigned char val)
1142 return snd_es1938_mixer_bits(chip, reg, mask, val);
1144 return snd_es1938_bits(chip, reg, mask, val);
1147 static int snd_es1938_reg_read(es1938_t *chip, unsigned char reg)
1150 return snd_es1938_mixer_read(chip, reg);
1152 return snd_es1938_read(chip, reg);
1155 #define ES1938_SINGLE(xname, xindex, reg, shift, mask, invert) \
1156 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1157 .info = snd_es1938_info_single, \
1158 .get = snd_es1938_get_single, .put = snd_es1938_put_single, \
1159 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1161 static int snd_es1938_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1163 int mask = (kcontrol->private_value >> 16) & 0xff;
1165 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1167 uinfo->value.integer.min = 0;
1168 uinfo->value.integer.max = mask;
1172 static int snd_es1938_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1174 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1175 int reg = kcontrol->private_value & 0xff;
1176 int shift = (kcontrol->private_value >> 8) & 0xff;
1177 int mask = (kcontrol->private_value >> 16) & 0xff;
1178 int invert = (kcontrol->private_value >> 24) & 0xff;
1181 val = snd_es1938_reg_read(chip, reg);
1182 ucontrol->value.integer.value[0] = (val >> shift) & mask;
1184 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1188 static int snd_es1938_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1190 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1191 int reg = kcontrol->private_value & 0xff;
1192 int shift = (kcontrol->private_value >> 8) & 0xff;
1193 int mask = (kcontrol->private_value >> 16) & 0xff;
1194 int invert = (kcontrol->private_value >> 24) & 0xff;
1197 val = (ucontrol->value.integer.value[0] & mask);
1202 return snd_es1938_reg_bits(chip, reg, mask, val) != val;
1205 #define ES1938_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1206 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1207 .info = snd_es1938_info_double, \
1208 .get = snd_es1938_get_double, .put = snd_es1938_put_double, \
1209 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1211 static int snd_es1938_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1213 int mask = (kcontrol->private_value >> 24) & 0xff;
1215 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1217 uinfo->value.integer.min = 0;
1218 uinfo->value.integer.max = mask;
1222 static int snd_es1938_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1224 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1225 int left_reg = kcontrol->private_value & 0xff;
1226 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1227 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1228 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1229 int mask = (kcontrol->private_value >> 24) & 0xff;
1230 int invert = (kcontrol->private_value >> 22) & 1;
1231 unsigned char left, right;
1233 left = snd_es1938_reg_read(chip, left_reg);
1234 if (left_reg != right_reg)
1235 right = snd_es1938_reg_read(chip, right_reg);
1238 ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
1239 ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
1241 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1242 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1247 static int snd_es1938_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1249 es1938_t *chip = snd_kcontrol_chip(kcontrol);
1250 int left_reg = kcontrol->private_value & 0xff;
1251 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1252 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1253 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1254 int mask = (kcontrol->private_value >> 24) & 0xff;
1255 int invert = (kcontrol->private_value >> 22) & 1;
1257 unsigned char val1, val2, mask1, mask2;
1259 val1 = ucontrol->value.integer.value[0] & mask;
1260 val2 = ucontrol->value.integer.value[1] & mask;
1265 val1 <<= shift_left;
1266 val2 <<= shift_right;
1267 mask1 = mask << shift_left;
1268 mask2 = mask << shift_right;
1269 if (left_reg != right_reg) {
1271 if (snd_es1938_reg_bits(chip, left_reg, mask1, val1) != val1)
1273 if (snd_es1938_reg_bits(chip, right_reg, mask2, val2) != val2)
1276 change = (snd_es1938_reg_bits(chip, left_reg, mask1 | mask2,
1277 val1 | val2) != (val1 | val2));
1282 static snd_kcontrol_new_t snd_es1938_controls[] = {
1283 ES1938_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
1284 ES1938_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
1286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1287 .name = "Hardware Master Playback Volume",
1288 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1289 .info = snd_es1938_info_hw_volume,
1290 .get = snd_es1938_get_hw_volume,
1293 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1294 .name = "Hardware Master Playback Switch",
1295 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1296 .info = snd_es1938_info_hw_switch,
1297 .get = snd_es1938_get_hw_switch,
1299 ES1938_SINGLE("Hardware Volume Split", 0, 0x64, 7, 1, 0),
1300 ES1938_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
1301 ES1938_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
1302 ES1938_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
1303 ES1938_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1304 ES1938_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
1305 ES1938_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
1306 ES1938_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
1307 ES1938_SINGLE("PC Speaker Volume", 0, 0x3c, 0, 7, 0),
1308 ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1309 ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1311 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1312 .name = "Capture Source",
1313 .info = snd_es1938_info_mux,
1314 .get = snd_es1938_get_mux,
1315 .put = snd_es1938_put_mux,
1317 ES1938_DOUBLE("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
1318 ES1938_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
1319 ES1938_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
1320 ES1938_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
1321 ES1938_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
1322 ES1938_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0),
1323 ES1938_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
1324 ES1938_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0),
1325 ES1938_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
1326 ES1938_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0),
1327 ES1938_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
1329 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1330 .name = "3D Control - Switch",
1331 .info = snd_es1938_info_spatializer_enable,
1332 .get = snd_es1938_get_spatializer_enable,
1333 .put = snd_es1938_put_spatializer_enable,
1335 ES1938_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0)
1339 /* ---------------------------------------------------------------------------- */
1340 /* ---------------------------------------------------------------------------- */
1343 * initialize the chip - used by resume callback, too
1345 static void snd_es1938_chip_init(es1938_t *chip)
1348 snd_es1938_reset(chip);
1350 /* configure native mode */
1352 /* enable bus master */
1353 pci_set_master(chip->pci);
1355 /* disable legacy audio */
1356 pci_write_config_word(chip->pci, SL_PCI_LEGACYCONTROL, 0x805f);
1359 pci_write_config_word(chip->pci, SL_PCI_DDMACONTROL, chip->ddma_port | 1);
1361 /* set DMA/IRQ policy */
1362 pci_write_config_dword(chip->pci, SL_PCI_CONFIG, 0);
1364 /* enable Audio 1, Audio 2, MPU401 IRQ and HW volume IRQ*/
1365 outb(0xf0, SLIO_REG(chip, IRQCONTROL));
1368 outb(0, SLDM_REG(chip, DMACLEAR));
1376 static unsigned char saved_regs[SAVED_REG_SIZE+1] = {
1377 0x14, 0x1a, 0x1c, 0x3a, 0x3c, 0x3e, 0x36, 0x38,
1378 0x50, 0x52, 0x60, 0x61, 0x62, 0x63, 0x64, 0x68,
1379 0x69, 0x6a, 0x6b, 0x6d, 0x6e, 0x6f, 0x7c, 0x7d,
1384 static int es1938_suspend(snd_card_t *card, unsigned int state)
1386 es1938_t *chip = card->pm_private_data;
1387 unsigned char *s, *d;
1389 snd_pcm_suspend_all(chip->pcm);
1391 /* save mixer-related registers */
1392 for (s = saved_regs, d = chip->saved_regs; *s; s++, d++)
1393 *d = snd_es1938_reg_read(chip, *s);
1395 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
1397 pci_disable_device(chip->pci);
1398 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1402 static int es1938_resume(snd_card_t *card, unsigned int state)
1404 es1938_t *chip = card->pm_private_data;
1405 unsigned char *s, *d;
1407 pci_enable_device(chip->pci);
1408 snd_es1938_chip_init(chip);
1410 /* restore mixer-related registers */
1411 for (s = saved_regs, d = chip->saved_regs; *s; s++, d++) {
1413 snd_es1938_mixer_write(chip, *s, *d);
1415 snd_es1938_write(chip, *s, *d);
1418 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1421 #endif /* CONFIG_PM */
1423 static int snd_es1938_free(es1938_t *chip)
1426 outb(0x00, SLIO_REG(chip, IRQCONTROL));
1428 snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0);*/
1429 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
1430 if (chip->gameport.io)
1431 gameport_unregister_port(&chip->gameport);
1434 free_irq(chip->irq, (void *)chip);
1435 pci_release_regions(chip->pci);
1436 pci_disable_device(chip->pci);
1441 static int snd_es1938_dev_free(snd_device_t *device)
1443 es1938_t *chip = device->device_data;
1444 return snd_es1938_free(chip);
1447 static int __devinit snd_es1938_create(snd_card_t * card,
1448 struct pci_dev * pci,
1453 static snd_device_ops_t ops = {
1454 .dev_free = snd_es1938_dev_free,
1459 /* enable PCI device */
1460 if ((err = pci_enable_device(pci)) < 0)
1462 /* check, if we can restrict PCI DMA transfers to 24 bits */
1463 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
1464 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
1465 snd_printk("architecture does not support 24bit PCI busmaster DMA\n");
1466 pci_disable_device(pci);
1470 chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
1472 pci_disable_device(pci);
1475 spin_lock_init(&chip->reg_lock);
1476 spin_lock_init(&chip->mixer_lock);
1479 if ((err = pci_request_regions(pci, "ESS Solo-1")) < 0) {
1481 pci_disable_device(pci);
1484 chip->io_port = pci_resource_start(pci, 0);
1485 chip->sb_port = pci_resource_start(pci, 1);
1486 chip->vc_port = pci_resource_start(pci, 2);
1487 chip->mpu_port = pci_resource_start(pci, 3);
1488 chip->game_port = pci_resource_start(pci, 4);
1489 if (request_irq(pci->irq, snd_es1938_interrupt, SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip)) {
1490 snd_printk("unable to grab IRQ %d\n", pci->irq);
1491 snd_es1938_free(chip);
1494 chip->irq = pci->irq;
1495 #ifdef ES1938_DDEBUG
1496 snd_printk("create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n",
1497 chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port);
1500 chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */
1502 snd_es1938_chip_init(chip);
1504 snd_card_set_pm_callback(card, es1938_suspend, es1938_resume, chip);
1506 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1507 snd_es1938_free(chip);
1511 snd_card_set_dev(card, &pci->dev);
1517 /* --------------------------------------------------------------------
1519 * -------------------------------------------------------------------- */
1520 static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1522 es1938_t *chip = dev_id;
1523 unsigned char status, audiostatus;
1526 status = inb(SLIO_REG(chip, IRQCONTROL));
1528 printk("Es1938debug - interrupt status: =0x%x\n", status);
1532 if (status & 0x10) {
1534 printk("Es1938debug - AUDIO channel 1 interrupt\n");
1535 printk("Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n", inw(SLDM_REG(chip, DMACOUNT)));
1536 printk("Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n", inl(SLDM_REG(chip, DMAADDR)));
1537 printk("Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n", inl(SLDM_REG(chip, DMASTATUS)));
1541 audiostatus = inb(SLSB_REG(chip, STATUS));
1542 if (chip->active & ADC1)
1543 snd_pcm_period_elapsed(chip->capture_substream);
1544 else if (chip->active & DAC1)
1545 snd_pcm_period_elapsed(chip->playback2_substream);
1549 if (status & 0x20) {
1551 printk("Es1938debug - AUDIO channel 2 interrupt\n");
1552 printk("Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n", inw(SLIO_REG(chip, AUDIO2DMACOUNT)));
1553 printk("Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n", inl(SLIO_REG(chip, AUDIO2DMAADDR)));
1558 snd_es1938_mixer_bits(chip, ESSSB_IREG_AUDIO2CONTROL2, 0x80, 0);
1559 if (chip->active & DAC2)
1560 snd_pcm_period_elapsed(chip->playback1_substream);
1563 /* Hardware volume */
1564 if (status & 0x40) {
1565 int split = snd_es1938_mixer_read(chip, 0x64) & 0x80;
1567 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id);
1568 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id);
1570 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id);
1571 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id);
1574 snd_es1938_mixer_write(chip, 0x66, 0x00);
1578 if (status & 0x80) {
1579 // snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0); /* ack? */
1582 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
1585 return IRQ_RETVAL(handled);
1588 #define ES1938_DMA_SIZE 64
1590 static int __devinit snd_es1938_mixer(es1938_t *chip)
1598 strcpy(card->mixername, "ESS Solo-1");
1600 for (idx = 0; idx < ARRAY_SIZE(snd_es1938_controls); idx++) {
1601 snd_kcontrol_t *kctl;
1602 kctl = snd_ctl_new1(&snd_es1938_controls[idx], chip);
1605 chip->master_volume = kctl;
1606 kctl->private_free = snd_es1938_hwv_free;
1609 chip->master_switch = kctl;
1610 kctl->private_free = snd_es1938_hwv_free;
1613 chip->hw_volume = kctl;
1614 kctl->private_free = snd_es1938_hwv_free;
1617 chip->hw_switch = kctl;
1618 kctl->private_free = snd_es1938_hwv_free;
1621 if ((err = snd_ctl_add(card, kctl)) < 0)
1628 static int __devinit snd_es1938_probe(struct pci_dev *pci,
1629 const struct pci_device_id *pci_id)
1637 if (dev >= SNDRV_CARDS)
1644 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1647 for (idx = 0; idx < 5; idx++) {
1648 if (pci_resource_start(pci, idx) == 0 ||
1649 !(pci_resource_flags(pci, idx) & IORESOURCE_IO)) {
1650 snd_card_free(card);
1654 if ((err = snd_es1938_create(card, pci, &chip)) < 0) {
1655 snd_card_free(card);
1659 strcpy(card->driver, "ES1938");
1660 strcpy(card->shortname, "ESS ES1938 (Solo-1)");
1661 sprintf(card->longname, "%s rev %i, irq %i",
1666 if ((err = snd_es1938_new_pcm(chip, 0)) < 0) {
1667 snd_card_free(card);
1670 if ((err = snd_es1938_mixer(chip)) < 0) {
1671 snd_card_free(card);
1674 if (snd_opl3_create(card,
1675 SLSB_REG(chip, FMLOWADDR),
1676 SLSB_REG(chip, FMHIGHADDR),
1677 OPL3_HW_OPL3, 1, &opl3) < 0) {
1678 printk(KERN_ERR "es1938: OPL3 not detected at 0x%lx\n",
1679 SLSB_REG(chip, FMLOWADDR));
1681 if ((err = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
1682 snd_card_free(card);
1685 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
1686 snd_card_free(card);
1690 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
1691 chip->mpu_port, 1, chip->irq, 0, &chip->rmidi) < 0) {
1692 printk(KERN_ERR "es1938: unable to initialize MPU-401\n");
1694 snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0x40);*/
1696 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
1697 chip->gameport.io = chip->game_port;
1698 gameport_register_port(&chip->gameport);
1701 if ((err = snd_card_register(card)) < 0) {
1702 snd_card_free(card);
1706 pci_set_drvdata(pci, card);
1711 static void __devexit snd_es1938_remove(struct pci_dev *pci)
1713 snd_card_free(pci_get_drvdata(pci));
1714 pci_set_drvdata(pci, NULL);
1717 static struct pci_driver driver = {
1718 .name = "ESS ES1938 (Solo-1)",
1719 .id_table = snd_es1938_ids,
1720 .probe = snd_es1938_probe,
1721 .remove = __devexit_p(snd_es1938_remove),
1722 SND_PCI_PM_CALLBACKS
1725 static int __init alsa_card_es1938_init(void)
1727 return pci_module_init(&driver);
1730 static void __exit alsa_card_es1938_exit(void)
1732 pci_unregister_driver(&driver);
1735 module_init(alsa_card_es1938_init)
1736 module_exit(alsa_card_es1938_exit)