2 * Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
6 * FEATURES currently supported:
7 * Output fixed at S32_LE, 2 channel to hw:0,0
8 * Rates: 44.1, 48, 96, 192.
12 * Use separate card based buffer for periods table.
14 * Use 2 channel output streams instead of 8 channel.
15 * (8 channel output streams might be good for ASIO type output)
16 * Corrected speaker output, so Front -> Front etc.
18 * Fixed missed interrupts.
20 * Add Sound card model number and names.
21 * Add Analog volume controls.
23 * Corrected playback interrupts. Now interrupt per period, instead of half period.
25 * Use single trigger for multichannel.
27 * Mic capture now works at fixed: S32_LE, 96000Hz, Stereo.
29 * Force buffer_size / period_size == INTEGER.
31 * Update p16v.c to work with changed alsa api.
33 * Update p16v.c to work with changed alsa api. Removed boot_devs.
35 * Merging with snd-emu10k1 driver.
37 * One stereo channel at 24bit now works.
39 * Added better register defines.
41 * Integrated with snd-emu10k1 driver.
43 * Removed #if 0 ... #endif
47 * Some stability problems when unloading the snd-p16v kernel module.
52 * Find out how to change capture sample rates. E.g. To record SPDIF at 48000Hz.
53 * Currently capture fixed at 48000Hz.
58 * P16V Chip: CA0151-DBS
59 * Audigy 2 Chip: CA0102-IAT
60 * AC97 Codec: STAC 9721
61 * ADC: Philips 1361T (Stereo 24bit)
62 * DAC: CS4382-K (8-channel, 24bit, 192Khz)
64 * This code was initally based on code from ALSA's emu10k1x.c which is:
65 * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
67 * This program is free software; you can redistribute it and/or modify
68 * it under the terms of the GNU General Public License as published by
69 * the Free Software Foundation; either version 2 of the License, or
70 * (at your option) any later version.
72 * This program is distributed in the hope that it will be useful,
73 * but WITHOUT ANY WARRANTY; without even the implied warranty of
74 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 * GNU General Public License for more details.
77 * You should have received a copy of the GNU General Public License
78 * along with this program; if not, write to the Free Software
79 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
82 #include <sound/driver.h>
83 #include <linux/delay.h>
84 #include <linux/init.h>
85 #include <linux/interrupt.h>
86 #include <linux/pci.h>
87 #include <linux/slab.h>
88 #include <linux/moduleparam.h>
89 #include <sound/core.h>
90 #include <sound/initval.h>
91 #include <sound/pcm.h>
92 #include <sound/ac97_codec.h>
93 #include <sound/info.h>
94 #include <sound/emu10k1.h>
97 #define SET_CHANNEL 0 /* Testing channel outputs 0=Front, 1=Center/LFE, 2=Unknown, 3=Rear */
98 #define PCM_FRONT_CHANNEL 0
99 #define PCM_REAR_CHANNEL 1
100 #define PCM_CENTER_LFE_CHANNEL 2
101 #define PCM_UNKNOWN_CHANNEL 3
102 #define CONTROL_FRONT_CHANNEL 0
103 #define CONTROL_REAR_CHANNEL 3
104 #define CONTROL_CENTER_LFE_CHANNEL 1
105 #define CONTROL_UNKNOWN_CHANNEL 2
108 * Class 0401: 1102:0004 (rev 04) Subsystem: 1102:2002 -> Audigy2 ZS 7.1 Model:SB0350
109 * Class 0401: 1102:0004 (rev 04) Subsystem: 1102:1007 -> Audigy2 6.1 Model:SB0240
110 * Class 0401: 1102:0004 (rev 04) Subsystem: 1102:1002 -> Audigy2 Platinum Model:SB msb0240230009266
111 * Class 0401: 1102:0004 (rev 04) Subsystem: 1102:2007 -> Audigy4 Pro Model:SB0380 M1SB0380472001901E
115 /* hardware definition */
116 static snd_pcm_hardware_t snd_p16v_playback_hw = {
117 .info = (SNDRV_PCM_INFO_MMAP |
118 SNDRV_PCM_INFO_INTERLEAVED |
119 SNDRV_PCM_INFO_BLOCK_TRANSFER |
120 SNDRV_PCM_INFO_MMAP_VALID),
121 .formats = SNDRV_PCM_FMTBIT_S32_LE, /* Only supports 24-bit samples padded to 32 bits. */
122 .rates = SNDRV_PCM_RATE_192000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_48000 ,
127 .buffer_bytes_max = (32*1024),
128 .period_bytes_min = 64,
129 .period_bytes_max = (16*1024),
135 static snd_pcm_hardware_t snd_p16v_capture_hw = {
136 .info = (SNDRV_PCM_INFO_MMAP |
137 SNDRV_PCM_INFO_INTERLEAVED |
138 SNDRV_PCM_INFO_BLOCK_TRANSFER |
139 SNDRV_PCM_INFO_MMAP_VALID),
140 .formats = SNDRV_PCM_FMTBIT_S32_LE,
141 .rates = SNDRV_PCM_RATE_48000,
146 .buffer_bytes_max = (32*1024),
147 .period_bytes_min = 64,
148 .period_bytes_max = (16*1024),
155 static void snd_p16v_pcm_free_substream(snd_pcm_runtime_t *runtime)
157 emu10k1_pcm_t *epcm = runtime->private_data;
160 //snd_printk("epcm free: %p\n", epcm);
165 /* open_playback callback */
166 static int snd_p16v_pcm_open_playback_channel(snd_pcm_substream_t *substream, int channel_id)
168 emu10k1_t *emu = snd_pcm_substream_chip(substream);
169 emu10k1_voice_t *channel = &(emu->p16v_voices[channel_id]);
171 snd_pcm_runtime_t *runtime = substream->runtime;
174 epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL);
175 //snd_printk("epcm kcalloc: %p\n", epcm);
180 epcm->substream = substream;
181 //snd_printk("epcm device=%d, channel_id=%d\n", substream->pcm->device, channel_id);
183 runtime->private_data = epcm;
184 runtime->private_free = snd_p16v_pcm_free_substream;
186 runtime->hw = snd_p16v_playback_hw;
189 channel->number = channel_id;
192 //snd_printk("p16v: open channel_id=%d, channel=%p, use=0x%x\n", channel_id, channel, channel->use);
193 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
194 //channel->interrupt = snd_p16v_pcm_channel_interrupt;
196 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
201 /* open_capture callback */
202 static int snd_p16v_pcm_open_capture_channel(snd_pcm_substream_t *substream, int channel_id)
204 emu10k1_t *emu = snd_pcm_substream_chip(substream);
205 emu10k1_voice_t *channel = &(emu->p16v_capture_voice);
207 snd_pcm_runtime_t *runtime = substream->runtime;
210 epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL);
211 //snd_printk("epcm kcalloc: %p\n", epcm);
216 epcm->substream = substream;
217 //snd_printk("epcm device=%d, channel_id=%d\n", substream->pcm->device, channel_id);
219 runtime->private_data = epcm;
220 runtime->private_free = snd_p16v_pcm_free_substream;
222 runtime->hw = snd_p16v_capture_hw;
225 channel->number = channel_id;
228 //snd_printk("p16v: open channel_id=%d, channel=%p, use=0x%x\n", channel_id, channel, channel->use);
229 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
230 //channel->interrupt = snd_p16v_pcm_channel_interrupt;
232 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
240 static int snd_p16v_pcm_close_playback(snd_pcm_substream_t *substream)
242 emu10k1_t *emu = snd_pcm_substream_chip(substream);
243 //snd_pcm_runtime_t *runtime = substream->runtime;
244 //emu10k1_pcm_t *epcm = runtime->private_data;
245 emu->p16v_voices[substream->pcm->device - emu->p16v_device_offset].use=0;
246 /* FIXME: maybe zero others */
251 static int snd_p16v_pcm_close_capture(snd_pcm_substream_t *substream)
253 emu10k1_t *emu = snd_pcm_substream_chip(substream);
254 //snd_pcm_runtime_t *runtime = substream->runtime;
255 //emu10k1_pcm_t *epcm = runtime->private_data;
256 emu->p16v_capture_voice.use=0;
257 /* FIXME: maybe zero others */
261 static int snd_p16v_pcm_open_playback_front(snd_pcm_substream_t *substream)
263 return snd_p16v_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);
266 static int snd_p16v_pcm_open_capture(snd_pcm_substream_t *substream)
268 // Only using channel 0 for now, but the card has 2 channels.
269 return snd_p16v_pcm_open_capture_channel(substream, 0);
272 /* hw_params callback */
273 static int snd_p16v_pcm_hw_params_playback(snd_pcm_substream_t *substream,
274 snd_pcm_hw_params_t * hw_params)
277 result = snd_pcm_lib_malloc_pages(substream,
278 params_buffer_bytes(hw_params));
282 /* hw_params callback */
283 static int snd_p16v_pcm_hw_params_capture(snd_pcm_substream_t *substream,
284 snd_pcm_hw_params_t * hw_params)
287 result = snd_pcm_lib_malloc_pages(substream,
288 params_buffer_bytes(hw_params));
293 /* hw_free callback */
294 static int snd_p16v_pcm_hw_free_playback(snd_pcm_substream_t *substream)
297 result = snd_pcm_lib_free_pages(substream);
301 /* hw_free callback */
302 static int snd_p16v_pcm_hw_free_capture(snd_pcm_substream_t *substream)
305 result = snd_pcm_lib_free_pages(substream);
310 /* prepare playback callback */
311 static int snd_p16v_pcm_prepare_playback(snd_pcm_substream_t *substream)
313 emu10k1_t *emu = snd_pcm_substream_chip(substream);
314 snd_pcm_runtime_t *runtime = substream->runtime;
315 int channel = substream->pcm->device - emu->p16v_device_offset;
316 u32 *table_base = (u32 *)(emu->p16v_buffer.area+(8*16*channel));
317 u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
321 //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1));
322 //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
323 //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->p16v_buffer.addr, emu->p16v_buffer.area, emu->p16v_buffer.bytes);
324 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel);
325 switch (runtime->rate) {
327 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe000) | 0x8000); /* FIXME: This will change the capture rate as well! */
330 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe000) | 0x0000); /* FIXME: This will change the capture rate as well! */
333 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe000) | 0x4000); /* FIXME: This will change the capture rate as well! */
336 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe000) | 0x2000); /* FIXME: This will change the capture rate as well! */
339 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, 0x0000); /* FIXME: This will change the capture rate as well! */
342 /* FIXME: Check emu->buffer.size before actually writing to it. */
343 for(i=0; i < runtime->periods; i++) {
344 table_base[i*2]=runtime->dma_addr+(i*period_size_bytes);
345 table_base[(i*2)+1]=period_size_bytes<<16;
348 snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_ADDR, channel, emu->p16v_buffer.addr+(8*16*channel));
349 snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19);
350 snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_PTR, channel, 0);
351 snd_emu10k1_ptr20_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr);
352 snd_emu10k1_ptr20_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes
353 snd_emu10k1_ptr20_write(emu, PLAYBACK_POINTER, channel, 0);
354 snd_emu10k1_ptr20_write(emu, 0x07, channel, 0x0);
355 snd_emu10k1_ptr20_write(emu, 0x08, channel, 0);
360 /* prepare capture callback */
361 static int snd_p16v_pcm_prepare_capture(snd_pcm_substream_t *substream)
363 emu10k1_t *emu = snd_pcm_substream_chip(substream);
364 snd_pcm_runtime_t *runtime = substream->runtime;
365 int channel = substream->pcm->device - emu->p16v_device_offset;
366 //printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, frames_to_bytes(runtime, 1));
367 snd_emu10k1_ptr20_write(emu, 0x13, channel, 0);
368 snd_emu10k1_ptr20_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr);
369 snd_emu10k1_ptr20_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes
370 snd_emu10k1_ptr20_write(emu, CAPTURE_POINTER, channel, 0);
371 //snd_emu10k1_ptr20_write(emu, CAPTURE_SOURCE, 0x0, 0x333300e4); /* Select MIC or Line in */
372 //snd_emu10k1_ptr20_write(emu, EXTENDED_INT_MASK, 0, snd_emu10k1_ptr20_read(emu, EXTENDED_INT_MASK, 0) | (0x110000<<channel));
377 static void snd_p16v_intr_enable(emu10k1_t *emu, unsigned int intrenb)
382 spin_lock_irqsave(&emu->emu_lock, flags);
383 enable = inl(emu->port + INTE2) | intrenb;
384 outl(enable, emu->port + INTE2);
385 spin_unlock_irqrestore(&emu->emu_lock, flags);
388 static void snd_p16v_intr_disable(emu10k1_t *emu, unsigned int intrenb)
391 unsigned int disable;
393 spin_lock_irqsave(&emu->emu_lock, flags);
394 disable = inl(emu->port + INTE2) & (~intrenb);
395 outl(disable, emu->port + INTE2);
396 spin_unlock_irqrestore(&emu->emu_lock, flags);
399 /* trigger_playback callback */
400 static int snd_p16v_pcm_trigger_playback(snd_pcm_substream_t *substream,
403 emu10k1_t *emu = snd_pcm_substream_chip(substream);
404 snd_pcm_runtime_t *runtime;
408 struct list_head *pos;
409 snd_pcm_substream_t *s;
415 case SNDRV_PCM_TRIGGER_START:
418 case SNDRV_PCM_TRIGGER_STOP:
423 snd_pcm_group_for_each(pos, substream) {
424 s = snd_pcm_group_substream_entry(pos);
425 runtime = s->runtime;
426 epcm = runtime->private_data;
427 channel = substream->pcm->device-emu->p16v_device_offset;
428 //snd_printk("p16v channel=%d\n",channel);
429 epcm->running = running;
430 basic |= (0x1<<channel);
431 inte |= (INTE2_PLAYBACK_CH_0_LOOP<<channel);
432 snd_pcm_trigger_done(s, substream);
434 //snd_printk("basic=0x%x, inte=0x%x\n",basic, inte);
437 case SNDRV_PCM_TRIGGER_START:
438 snd_p16v_intr_enable(emu, inte);
439 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0)| (basic));
441 case SNDRV_PCM_TRIGGER_STOP:
442 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0) & ~(basic));
443 snd_p16v_intr_disable(emu, inte);
452 /* trigger_capture callback */
453 static int snd_p16v_pcm_trigger_capture(snd_pcm_substream_t *substream,
456 emu10k1_t *emu = snd_pcm_substream_chip(substream);
457 snd_pcm_runtime_t *runtime = substream->runtime;
458 emu10k1_pcm_t *epcm = runtime->private_data;
461 u32 inte = INTE2_CAPTURE_CH_0_LOOP | INTE2_CAPTURE_CH_0_HALF_LOOP;
464 case SNDRV_PCM_TRIGGER_START:
465 snd_p16v_intr_enable(emu, inte);
466 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0)|(0x100<<channel));
469 case SNDRV_PCM_TRIGGER_STOP:
470 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0) & ~(0x100<<channel));
471 snd_p16v_intr_disable(emu, inte);
472 //snd_emu10k1_ptr20_write(emu, EXTENDED_INT_MASK, 0, snd_emu10k1_ptr20_read(emu, EXTENDED_INT_MASK, 0) & ~(0x110000<<channel));
482 /* pointer_playback callback */
483 static snd_pcm_uframes_t
484 snd_p16v_pcm_pointer_playback(snd_pcm_substream_t *substream)
486 emu10k1_t *emu = snd_pcm_substream_chip(substream);
487 snd_pcm_runtime_t *runtime = substream->runtime;
488 emu10k1_pcm_t *epcm = runtime->private_data;
489 snd_pcm_uframes_t ptr, ptr1, ptr2,ptr3,ptr4 = 0;
490 int channel = substream->pcm->device - emu->p16v_device_offset;
494 ptr3 = snd_emu10k1_ptr20_read(emu, PLAYBACK_LIST_PTR, channel);
495 ptr1 = snd_emu10k1_ptr20_read(emu, PLAYBACK_POINTER, channel);
496 ptr4 = snd_emu10k1_ptr20_read(emu, PLAYBACK_LIST_PTR, channel);
497 if (ptr3 != ptr4) ptr1 = snd_emu10k1_ptr20_read(emu, PLAYBACK_POINTER, channel);
498 ptr2 = bytes_to_frames(runtime, ptr1);
499 ptr2+= (ptr4 >> 3) * runtime->period_size;
501 if (ptr >= runtime->buffer_size)
502 ptr -= runtime->buffer_size;
507 /* pointer_capture callback */
508 static snd_pcm_uframes_t
509 snd_p16v_pcm_pointer_capture(snd_pcm_substream_t *substream)
511 emu10k1_t *emu = snd_pcm_substream_chip(substream);
512 snd_pcm_runtime_t *runtime = substream->runtime;
513 emu10k1_pcm_t *epcm = runtime->private_data;
514 snd_pcm_uframes_t ptr, ptr1, ptr2 = 0;
520 ptr1 = snd_emu10k1_ptr20_read(emu, CAPTURE_POINTER, channel);
521 ptr2 = bytes_to_frames(runtime, ptr1);
523 if (ptr >= runtime->buffer_size) {
524 ptr -= runtime->buffer_size;
525 printk("buffer capture limited!\n");
527 //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate);
533 static snd_pcm_ops_t snd_p16v_playback_front_ops = {
534 .open = snd_p16v_pcm_open_playback_front,
535 .close = snd_p16v_pcm_close_playback,
536 .ioctl = snd_pcm_lib_ioctl,
537 .hw_params = snd_p16v_pcm_hw_params_playback,
538 .hw_free = snd_p16v_pcm_hw_free_playback,
539 .prepare = snd_p16v_pcm_prepare_playback,
540 .trigger = snd_p16v_pcm_trigger_playback,
541 .pointer = snd_p16v_pcm_pointer_playback,
544 static snd_pcm_ops_t snd_p16v_capture_ops = {
545 .open = snd_p16v_pcm_open_capture,
546 .close = snd_p16v_pcm_close_capture,
547 .ioctl = snd_pcm_lib_ioctl,
548 .hw_params = snd_p16v_pcm_hw_params_capture,
549 .hw_free = snd_p16v_pcm_hw_free_capture,
550 .prepare = snd_p16v_pcm_prepare_capture,
551 .trigger = snd_p16v_pcm_trigger_capture,
552 .pointer = snd_p16v_pcm_pointer_capture,
556 int snd_p16v_free(emu10k1_t *chip)
559 if (chip->p16v_buffer.area) {
560 snd_dma_free_pages(&chip->p16v_buffer);
561 //snd_printk("period lables free: %p\n", &chip->p16v_buffer);
566 static void snd_p16v_pcm_free(snd_pcm_t *pcm)
568 emu10k1_t *emu = pcm->private_data;
569 //snd_printk("snd_p16v_pcm_free pcm: called\n");
570 snd_pcm_lib_preallocate_free_for_all(pcm);
574 int snd_p16v_pcm(emu10k1_t *emu, int device, snd_pcm_t **rpcm)
577 snd_pcm_substream_t *substream;
581 //snd_printk("snd_p16v_pcm called. device=%d\n", device);
582 emu->p16v_device_offset = device;
586 if ((err = snd_pcm_new(emu->card, "p16v", device, 1, capture, &pcm)) < 0)
589 pcm->private_data = emu;
590 pcm->private_free = snd_p16v_pcm_free;
591 // Single playback 8 channel device.
592 // Single capture 2 channel device.
593 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_p16v_playback_front_ops);
594 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_p16v_capture_ops);
597 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
598 strcpy(pcm->name, "p16v");
601 for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
603 substream = substream->next) {
604 if ((err = snd_pcm_lib_preallocate_pages(substream,
606 snd_dma_pci_data(emu->pci),
607 64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */
609 //snd_printk("preallocate playback substream: err=%d\n", err);
612 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
614 substream = substream->next) {
615 if ((err = snd_pcm_lib_preallocate_pages(substream,
617 snd_dma_pci_data(emu->pci),
618 64*1024, 64*1024)) < 0)
620 //snd_printk("preallocate capture substream: err=%d\n", err);
629 static int snd_p16v_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
631 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
633 uinfo->value.integer.min = 0;
634 uinfo->value.integer.max = 255;
638 static int snd_p16v_volume_get(snd_kcontrol_t * kcontrol,
639 snd_ctl_elem_value_t * ucontrol, int reg, int high_low)
641 emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
644 value = snd_emu10k1_ptr20_read(emu, reg, high_low);
646 ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
647 ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */
649 ucontrol->value.integer.value[0] = 0xff - ((value >> 8) & 0xff); /* Left */
650 ucontrol->value.integer.value[1] = 0xff - ((value >> 0) & 0xff); /* Right */
655 static int snd_p16v_volume_get_spdif_front(snd_kcontrol_t * kcontrol,
656 snd_ctl_elem_value_t * ucontrol)
659 int reg = PLAYBACK_VOLUME_MIXER7;
660 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
663 static int snd_p16v_volume_get_spdif_center_lfe(snd_kcontrol_t * kcontrol,
664 snd_ctl_elem_value_t * ucontrol)
667 int reg = PLAYBACK_VOLUME_MIXER7;
668 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
670 static int snd_p16v_volume_get_spdif_unknown(snd_kcontrol_t * kcontrol,
671 snd_ctl_elem_value_t * ucontrol)
674 int reg = PLAYBACK_VOLUME_MIXER8;
675 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
677 static int snd_p16v_volume_get_spdif_rear(snd_kcontrol_t * kcontrol,
678 snd_ctl_elem_value_t * ucontrol)
681 int reg = PLAYBACK_VOLUME_MIXER8;
682 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
685 static int snd_p16v_volume_get_analog_front(snd_kcontrol_t * kcontrol,
686 snd_ctl_elem_value_t * ucontrol)
689 int reg = PLAYBACK_VOLUME_MIXER9;
690 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
693 static int snd_p16v_volume_get_analog_center_lfe(snd_kcontrol_t * kcontrol,
694 snd_ctl_elem_value_t * ucontrol)
697 int reg = PLAYBACK_VOLUME_MIXER9;
698 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
700 static int snd_p16v_volume_get_analog_rear(snd_kcontrol_t * kcontrol,
701 snd_ctl_elem_value_t * ucontrol)
704 int reg = PLAYBACK_VOLUME_MIXER10;
705 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
708 static int snd_p16v_volume_get_analog_unknown(snd_kcontrol_t * kcontrol,
709 snd_ctl_elem_value_t * ucontrol)
712 int reg = PLAYBACK_VOLUME_MIXER10;
713 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
716 static int snd_p16v_volume_put(snd_kcontrol_t * kcontrol,
717 snd_ctl_elem_value_t * ucontrol, int reg, int high_low)
719 emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
721 value = snd_emu10k1_ptr20_read(emu, reg, 0);
722 //value = value & 0xffff;
725 value = value | ((0xff - ucontrol->value.integer.value[0]) << 24) | ((0xff - ucontrol->value.integer.value[1]) << 16);
728 value = value | ((0xff - ucontrol->value.integer.value[0]) << 8) | ((0xff - ucontrol->value.integer.value[1]) );
730 snd_emu10k1_ptr20_write(emu, reg, 0, value);
734 static int snd_p16v_volume_put_spdif_front(snd_kcontrol_t * kcontrol,
735 snd_ctl_elem_value_t * ucontrol)
738 int reg = PLAYBACK_VOLUME_MIXER7;
739 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
742 static int snd_p16v_volume_put_spdif_center_lfe(snd_kcontrol_t * kcontrol,
743 snd_ctl_elem_value_t * ucontrol)
746 int reg = PLAYBACK_VOLUME_MIXER7;
747 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
750 static int snd_p16v_volume_put_spdif_unknown(snd_kcontrol_t * kcontrol,
751 snd_ctl_elem_value_t * ucontrol)
754 int reg = PLAYBACK_VOLUME_MIXER8;
755 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
758 static int snd_p16v_volume_put_spdif_rear(snd_kcontrol_t * kcontrol,
759 snd_ctl_elem_value_t * ucontrol)
762 int reg = PLAYBACK_VOLUME_MIXER8;
763 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
766 static int snd_p16v_volume_put_analog_front(snd_kcontrol_t * kcontrol,
767 snd_ctl_elem_value_t * ucontrol)
770 int reg = PLAYBACK_VOLUME_MIXER9;
771 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
774 static int snd_p16v_volume_put_analog_center_lfe(snd_kcontrol_t * kcontrol,
775 snd_ctl_elem_value_t * ucontrol)
778 int reg = PLAYBACK_VOLUME_MIXER9;
779 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
782 static int snd_p16v_volume_put_analog_rear(snd_kcontrol_t * kcontrol,
783 snd_ctl_elem_value_t * ucontrol)
786 int reg = PLAYBACK_VOLUME_MIXER10;
787 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
790 static int snd_p16v_volume_put_analog_unknown(snd_kcontrol_t * kcontrol,
791 snd_ctl_elem_value_t * ucontrol)
794 int reg = PLAYBACK_VOLUME_MIXER10;
795 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
798 static snd_kcontrol_new_t snd_p16v_volume_control_analog_front =
800 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
801 .name = "HD Analog Front Volume",
802 .info = snd_p16v_volume_info,
803 .get = snd_p16v_volume_get_analog_front,
804 .put = snd_p16v_volume_put_analog_front
807 static snd_kcontrol_new_t snd_p16v_volume_control_analog_center_lfe =
809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
810 .name = "HD Analog Center/LFE Volume",
811 .info = snd_p16v_volume_info,
812 .get = snd_p16v_volume_get_analog_center_lfe,
813 .put = snd_p16v_volume_put_analog_center_lfe
816 static snd_kcontrol_new_t snd_p16v_volume_control_analog_unknown =
818 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
819 .name = "HD Analog Unknown Volume",
820 .info = snd_p16v_volume_info,
821 .get = snd_p16v_volume_get_analog_unknown,
822 .put = snd_p16v_volume_put_analog_unknown
825 static snd_kcontrol_new_t snd_p16v_volume_control_analog_rear =
827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
828 .name = "HD Analog Rear Volume",
829 .info = snd_p16v_volume_info,
830 .get = snd_p16v_volume_get_analog_rear,
831 .put = snd_p16v_volume_put_analog_rear
834 static snd_kcontrol_new_t snd_p16v_volume_control_spdif_front =
836 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
837 .name = "HD SPDIF Front Volume",
838 .info = snd_p16v_volume_info,
839 .get = snd_p16v_volume_get_spdif_front,
840 .put = snd_p16v_volume_put_spdif_front
843 static snd_kcontrol_new_t snd_p16v_volume_control_spdif_center_lfe =
845 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
846 .name = "HD SPDIF Center/LFE Volume",
847 .info = snd_p16v_volume_info,
848 .get = snd_p16v_volume_get_spdif_center_lfe,
849 .put = snd_p16v_volume_put_spdif_center_lfe
852 static snd_kcontrol_new_t snd_p16v_volume_control_spdif_unknown =
854 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
855 .name = "HD SPDIF Unknown Volume",
856 .info = snd_p16v_volume_info,
857 .get = snd_p16v_volume_get_spdif_unknown,
858 .put = snd_p16v_volume_put_spdif_unknown
861 static snd_kcontrol_new_t snd_p16v_volume_control_spdif_rear =
863 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
864 .name = "HD SPDIF Rear Volume",
865 .info = snd_p16v_volume_info,
866 .get = snd_p16v_volume_get_spdif_rear,
867 .put = snd_p16v_volume_put_spdif_rear
870 static int snd_p16v_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
872 static char *texts[8] = { "SPDIF", "I2S", "SRC48", "SRCMulti_SPDIF", "SRCMulti_I2S", "CDIF", "FX", "AC97" };
874 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
876 uinfo->value.enumerated.items = 8;
877 if (uinfo->value.enumerated.item > 7)
878 uinfo->value.enumerated.item = 7;
879 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
883 static int snd_p16v_capture_source_get(snd_kcontrol_t * kcontrol,
884 snd_ctl_elem_value_t * ucontrol)
886 emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
888 ucontrol->value.enumerated.item[0] = emu->p16v_capture_source;
892 static int snd_p16v_capture_source_put(snd_kcontrol_t * kcontrol,
893 snd_ctl_elem_value_t * ucontrol)
895 emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
901 val = ucontrol->value.enumerated.item[0] ;
902 change = (emu->p16v_capture_source != val);
904 emu->p16v_capture_source = val;
905 source = (val << 28) | (val << 24) | (val << 20) | (val << 16);
906 mask = snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0) & 0xffff;
907 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, source | mask);
912 static snd_kcontrol_new_t snd_p16v_capture_source __devinitdata =
914 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
915 .name = "HD Capture source",
916 .info = snd_p16v_capture_source_info,
917 .get = snd_p16v_capture_source_get,
918 .put = snd_p16v_capture_source_put
920 int snd_p16v_mixer(emu10k1_t *emu)
923 snd_kcontrol_t *kctl;
924 snd_card_t *card = emu->card;
925 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_front, emu)) == NULL)
927 if ((err = snd_ctl_add(card, kctl)))
929 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_rear, emu)) == NULL)
931 if ((err = snd_ctl_add(card, kctl)))
933 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_center_lfe, emu)) == NULL)
935 if ((err = snd_ctl_add(card, kctl)))
937 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_unknown, emu)) == NULL)
939 if ((err = snd_ctl_add(card, kctl)))
941 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_front, emu)) == NULL)
943 if ((err = snd_ctl_add(card, kctl)))
945 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_rear, emu)) == NULL)
947 if ((err = snd_ctl_add(card, kctl)))
949 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_center_lfe, emu)) == NULL)
951 if ((err = snd_ctl_add(card, kctl)))
953 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_unknown, emu)) == NULL)
955 if ((err = snd_ctl_add(card, kctl)))
957 if ((kctl = snd_ctl_new1(&snd_p16v_capture_source, emu)) == NULL)
959 if ((err = snd_ctl_add(card, kctl)))