blob: 13f7e62ee56b384dc1471c197a8c1d6c4faa7b38 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
3 * Driver p16v chips
4 * Version: 0.22
5 *
6 * FEATURES currently supported:
7 * Output fixed at S32_LE, 2 channel to hw:0,0
8 * Rates: 44.1, 48, 96, 192.
9 *
10 * Changelog:
11 * 0.8
12 * Use separate card based buffer for periods table.
13 * 0.9
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.
17 * 0.10
18 * Fixed missed interrupts.
19 * 0.11
20 * Add Sound card model number and names.
21 * Add Analog volume controls.
22 * 0.12
23 * Corrected playback interrupts. Now interrupt per period, instead of half period.
24 * 0.13
25 * Use single trigger for multichannel.
26 * 0.14
27 * Mic capture now works at fixed: S32_LE, 96000Hz, Stereo.
28 * 0.15
29 * Force buffer_size / period_size == INTEGER.
30 * 0.16
31 * Update p16v.c to work with changed alsa api.
32 * 0.17
33 * Update p16v.c to work with changed alsa api. Removed boot_devs.
34 * 0.18
35 * Merging with snd-emu10k1 driver.
36 * 0.19
37 * One stereo channel at 24bit now works.
38 * 0.20
39 * Added better register defines.
40 * 0.21
41 * Integrated with snd-emu10k1 driver.
42 * 0.22
43 * Removed #if 0 ... #endif
44 *
45 *
46 * BUGS:
47 * Some stability problems when unloading the snd-p16v kernel module.
48 * --
49 *
50 * TODO:
51 * SPDIF out.
52 * Find out how to change capture sample rates. E.g. To record SPDIF at 48000Hz.
53 * Currently capture fixed at 48000Hz.
54 *
55 * --
56 * GENERAL INFO:
57 * Model: SB0240
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)
63 *
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>
66 *
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.
71 *
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.
76 *
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
80 *
81 */
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>
95#include "p16v.h"
96
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
106
107/* Card IDs:
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
112 *
113 */
114
115 /* hardware definition */
116static 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. */
James Courtier-Dutton001f7582005-04-09 23:38:25 +0200122 .rates = SNDRV_PCM_RATE_192000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
123 .rate_min = 44100,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .rate_max = 192000,
125 .channels_min = 8,
126 .channels_max = 8,
James Courtier-Dutton310bacd2005-04-10 00:00:24 +0200127 .buffer_bytes_max = ((65536 - 64) * 8),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 .period_bytes_min = 64,
James Courtier-Dutton310bacd2005-04-10 00:00:24 +0200129 .period_bytes_max = (65536 - 64),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .periods_min = 2,
131 .periods_max = 8,
132 .fifo_size = 0,
133};
134
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100135static snd_pcm_hardware_t snd_p16v_capture_hw = {
James Courtier-Duttonc7025632005-05-04 17:26:28 +0200136 .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_192000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
142 .rate_min = 44100,
143 .rate_max = 192000,
144 .channels_min = 2,
145 .channels_max = 2,
146 .buffer_bytes_max = (32*1024),
147 .period_bytes_min = 64,
148 .period_bytes_max = (16*1024),
149 .periods_min = 2,
150 .periods_max = 2,
151 .fifo_size = 0,
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100152};
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static void snd_p16v_pcm_free_substream(snd_pcm_runtime_t *runtime)
155{
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100156 emu10k1_pcm_t *epcm = runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 if (epcm) {
159 //snd_printk("epcm free: %p\n", epcm);
160 kfree(epcm);
161 }
162}
163
164/* open_playback callback */
165static int snd_p16v_pcm_open_playback_channel(snd_pcm_substream_t *substream, int channel_id)
166{
167 emu10k1_t *emu = snd_pcm_substream_chip(substream);
168 emu10k1_voice_t *channel = &(emu->p16v_voices[channel_id]);
169 emu10k1_pcm_t *epcm;
170 snd_pcm_runtime_t *runtime = substream->runtime;
171 int err;
172
173 epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL);
174 //snd_printk("epcm kcalloc: %p\n", epcm);
175
176 if (epcm == NULL)
177 return -ENOMEM;
178 epcm->emu = emu;
179 epcm->substream = substream;
180 //snd_printk("epcm device=%d, channel_id=%d\n", substream->pcm->device, channel_id);
181
182 runtime->private_data = epcm;
183 runtime->private_free = snd_p16v_pcm_free_substream;
184
185 runtime->hw = snd_p16v_playback_hw;
186
187 channel->emu = emu;
188 channel->number = channel_id;
189
190 channel->use=1;
191 //snd_printk("p16v: open channel_id=%d, channel=%p, use=0x%x\n", channel_id, channel, channel->use);
192 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
193 //channel->interrupt = snd_p16v_pcm_channel_interrupt;
194 channel->epcm=epcm;
195 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
196 return err;
197
198 return 0;
199}
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100200/* open_capture callback */
201static int snd_p16v_pcm_open_capture_channel(snd_pcm_substream_t *substream, int channel_id)
202{
203 emu10k1_t *emu = snd_pcm_substream_chip(substream);
204 emu10k1_voice_t *channel = &(emu->p16v_capture_voice);
205 emu10k1_pcm_t *epcm;
206 snd_pcm_runtime_t *runtime = substream->runtime;
207 int err;
208
209 epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL);
210 //snd_printk("epcm kcalloc: %p\n", epcm);
211
212 if (epcm == NULL)
213 return -ENOMEM;
214 epcm->emu = emu;
215 epcm->substream = substream;
216 //snd_printk("epcm device=%d, channel_id=%d\n", substream->pcm->device, channel_id);
217
218 runtime->private_data = epcm;
219 runtime->private_free = snd_p16v_pcm_free_substream;
220
221 runtime->hw = snd_p16v_capture_hw;
222
223 channel->emu = emu;
224 channel->number = channel_id;
225
226 channel->use=1;
227 //snd_printk("p16v: open channel_id=%d, channel=%p, use=0x%x\n", channel_id, channel, channel->use);
228 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
229 //channel->interrupt = snd_p16v_pcm_channel_interrupt;
230 channel->epcm=epcm;
231 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
232 return err;
233
234 return 0;
235}
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238/* close callback */
239static int snd_p16v_pcm_close_playback(snd_pcm_substream_t *substream)
240{
241 emu10k1_t *emu = snd_pcm_substream_chip(substream);
242 //snd_pcm_runtime_t *runtime = substream->runtime;
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100243 //emu10k1_pcm_t *epcm = runtime->private_data;
244 emu->p16v_voices[substream->pcm->device - emu->p16v_device_offset].use=0;
245 /* FIXME: maybe zero others */
246 return 0;
247}
248
249/* close callback */
250static int snd_p16v_pcm_close_capture(snd_pcm_substream_t *substream)
251{
252 emu10k1_t *emu = snd_pcm_substream_chip(substream);
253 //snd_pcm_runtime_t *runtime = substream->runtime;
254 //emu10k1_pcm_t *epcm = runtime->private_data;
255 emu->p16v_capture_voice.use=0;
256 /* FIXME: maybe zero others */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return 0;
258}
259
260static int snd_p16v_pcm_open_playback_front(snd_pcm_substream_t *substream)
261{
262 return snd_p16v_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);
263}
264
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100265static int snd_p16v_pcm_open_capture(snd_pcm_substream_t *substream)
266{
267 // Only using channel 0 for now, but the card has 2 channels.
268 return snd_p16v_pcm_open_capture_channel(substream, 0);
269}
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/* hw_params callback */
272static int snd_p16v_pcm_hw_params_playback(snd_pcm_substream_t *substream,
273 snd_pcm_hw_params_t * hw_params)
274{
275 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 result = snd_pcm_lib_malloc_pages(substream,
277 params_buffer_bytes(hw_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 return result;
279}
280
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100281/* hw_params callback */
282static int snd_p16v_pcm_hw_params_capture(snd_pcm_substream_t *substream,
283 snd_pcm_hw_params_t * hw_params)
284{
285 int result;
286 result = snd_pcm_lib_malloc_pages(substream,
287 params_buffer_bytes(hw_params));
288 return result;
289}
290
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292/* hw_free callback */
293static int snd_p16v_pcm_hw_free_playback(snd_pcm_substream_t *substream)
294{
295 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 result = snd_pcm_lib_free_pages(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 return result;
298}
299
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100300/* hw_free callback */
301static int snd_p16v_pcm_hw_free_capture(snd_pcm_substream_t *substream)
302{
303 int result;
304 result = snd_pcm_lib_free_pages(substream);
305 return result;
306}
307
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/* prepare playback callback */
310static int snd_p16v_pcm_prepare_playback(snd_pcm_substream_t *substream)
311{
312 emu10k1_t *emu = snd_pcm_substream_chip(substream);
313 snd_pcm_runtime_t *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 int channel = substream->pcm->device - emu->p16v_device_offset;
315 u32 *table_base = (u32 *)(emu->p16v_buffer.area+(8*16*channel));
316 u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
317 int i;
318 u32 tmp;
319
320 //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));
321 //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
322 //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);
323 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel);
324 switch (runtime->rate) {
325 case 44100:
James Courtier-Dutton001f7582005-04-09 23:38:25 +0200326 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe0e0) | 0x8080);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 break;
328 case 96000:
James Courtier-Dutton001f7582005-04-09 23:38:25 +0200329 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe0e0) | 0x4040);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 break;
331 case 192000:
James Courtier-Dutton001f7582005-04-09 23:38:25 +0200332 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe0e0) | 0x2020);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 break;
James Courtier-Dutton001f7582005-04-09 23:38:25 +0200334 case 48000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 default:
James Courtier-Dutton001f7582005-04-09 23:38:25 +0200336 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe0e0) | 0x0000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 break;
338 }
339 /* FIXME: Check emu->buffer.size before actually writing to it. */
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100340 for(i=0; i < runtime->periods; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 table_base[i*2]=runtime->dma_addr+(i*period_size_bytes);
342 table_base[(i*2)+1]=period_size_bytes<<16;
343 }
344
345 snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_ADDR, channel, emu->p16v_buffer.addr+(8*16*channel));
346 snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19);
347 snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_PTR, channel, 0);
348 snd_emu10k1_ptr20_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr);
James Courtier-Dutton310bacd2005-04-10 00:00:24 +0200349 //snd_emu10k1_ptr20_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes
350 snd_emu10k1_ptr20_write(emu, PLAYBACK_PERIOD_SIZE, channel, 0); // buffer size in bytes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 snd_emu10k1_ptr20_write(emu, PLAYBACK_POINTER, channel, 0);
352 snd_emu10k1_ptr20_write(emu, 0x07, channel, 0x0);
353 snd_emu10k1_ptr20_write(emu, 0x08, channel, 0);
354
355 return 0;
356}
357
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100358/* prepare capture callback */
359static int snd_p16v_pcm_prepare_capture(snd_pcm_substream_t *substream)
360{
361 emu10k1_t *emu = snd_pcm_substream_chip(substream);
362 snd_pcm_runtime_t *runtime = substream->runtime;
363 int channel = substream->pcm->device - emu->p16v_device_offset;
James Courtier-Duttonc7025632005-05-04 17:26:28 +0200364 u32 tmp;
365 //printk("prepare capture: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));
366 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel);
367 switch (runtime->rate) {
368 case 44100:
369 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0x0e00) | 0x0800);
370 break;
371 case 96000:
372 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0x0e00) | 0x0400);
373 break;
374 case 192000:
375 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0x0e00) | 0x0200);
376 break;
377 case 48000:
378 default:
379 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0x0e00) | 0x0000);
380 break;
381 }
382 /* FIXME: Check emu->buffer.size before actually writing to it. */
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100383 snd_emu10k1_ptr20_write(emu, 0x13, channel, 0);
384 snd_emu10k1_ptr20_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr);
385 snd_emu10k1_ptr20_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes
386 snd_emu10k1_ptr20_write(emu, CAPTURE_POINTER, channel, 0);
387 //snd_emu10k1_ptr20_write(emu, CAPTURE_SOURCE, 0x0, 0x333300e4); /* Select MIC or Line in */
388 //snd_emu10k1_ptr20_write(emu, EXTENDED_INT_MASK, 0, snd_emu10k1_ptr20_read(emu, EXTENDED_INT_MASK, 0) | (0x110000<<channel));
389
390 return 0;
391}
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393static void snd_p16v_intr_enable(emu10k1_t *emu, unsigned int intrenb)
394{
395 unsigned long flags;
396 unsigned int enable;
397
398 spin_lock_irqsave(&emu->emu_lock, flags);
399 enable = inl(emu->port + INTE2) | intrenb;
400 outl(enable, emu->port + INTE2);
401 spin_unlock_irqrestore(&emu->emu_lock, flags);
402}
403
404static void snd_p16v_intr_disable(emu10k1_t *emu, unsigned int intrenb)
405{
406 unsigned long flags;
407 unsigned int disable;
408
409 spin_lock_irqsave(&emu->emu_lock, flags);
410 disable = inl(emu->port + INTE2) & (~intrenb);
411 outl(disable, emu->port + INTE2);
412 spin_unlock_irqrestore(&emu->emu_lock, flags);
413}
414
415/* trigger_playback callback */
416static int snd_p16v_pcm_trigger_playback(snd_pcm_substream_t *substream,
417 int cmd)
418{
419 emu10k1_t *emu = snd_pcm_substream_chip(substream);
420 snd_pcm_runtime_t *runtime;
421 emu10k1_pcm_t *epcm;
422 int channel;
423 int result = 0;
424 struct list_head *pos;
425 snd_pcm_substream_t *s;
426 u32 basic = 0;
427 u32 inte = 0;
428 int running=0;
429
430 switch (cmd) {
431 case SNDRV_PCM_TRIGGER_START:
432 running=1;
433 break;
434 case SNDRV_PCM_TRIGGER_STOP:
435 default:
436 running=0;
437 break;
438 }
439 snd_pcm_group_for_each(pos, substream) {
440 s = snd_pcm_group_substream_entry(pos);
441 runtime = s->runtime;
442 epcm = runtime->private_data;
443 channel = substream->pcm->device-emu->p16v_device_offset;
444 //snd_printk("p16v channel=%d\n",channel);
445 epcm->running = running;
446 basic |= (0x1<<channel);
447 inte |= (INTE2_PLAYBACK_CH_0_LOOP<<channel);
448 snd_pcm_trigger_done(s, substream);
449 }
450 //snd_printk("basic=0x%x, inte=0x%x\n",basic, inte);
451
452 switch (cmd) {
453 case SNDRV_PCM_TRIGGER_START:
454 snd_p16v_intr_enable(emu, inte);
455 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0)| (basic));
456 break;
457 case SNDRV_PCM_TRIGGER_STOP:
458 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0) & ~(basic));
459 snd_p16v_intr_disable(emu, inte);
460 break;
461 default:
462 result = -EINVAL;
463 break;
464 }
465 return result;
466}
467
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100468/* trigger_capture callback */
469static int snd_p16v_pcm_trigger_capture(snd_pcm_substream_t *substream,
470 int cmd)
471{
472 emu10k1_t *emu = snd_pcm_substream_chip(substream);
473 snd_pcm_runtime_t *runtime = substream->runtime;
474 emu10k1_pcm_t *epcm = runtime->private_data;
475 int channel = 0;
476 int result = 0;
477 u32 inte = INTE2_CAPTURE_CH_0_LOOP | INTE2_CAPTURE_CH_0_HALF_LOOP;
478
479 switch (cmd) {
480 case SNDRV_PCM_TRIGGER_START:
481 snd_p16v_intr_enable(emu, inte);
482 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0)|(0x100<<channel));
483 epcm->running = 1;
484 break;
485 case SNDRV_PCM_TRIGGER_STOP:
486 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0) & ~(0x100<<channel));
487 snd_p16v_intr_disable(emu, inte);
488 //snd_emu10k1_ptr20_write(emu, EXTENDED_INT_MASK, 0, snd_emu10k1_ptr20_read(emu, EXTENDED_INT_MASK, 0) & ~(0x110000<<channel));
489 epcm->running = 0;
490 break;
491 default:
492 result = -EINVAL;
493 break;
494 }
495 return result;
496}
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498/* pointer_playback callback */
499static snd_pcm_uframes_t
500snd_p16v_pcm_pointer_playback(snd_pcm_substream_t *substream)
501{
502 emu10k1_t *emu = snd_pcm_substream_chip(substream);
503 snd_pcm_runtime_t *runtime = substream->runtime;
504 emu10k1_pcm_t *epcm = runtime->private_data;
505 snd_pcm_uframes_t ptr, ptr1, ptr2,ptr3,ptr4 = 0;
506 int channel = substream->pcm->device - emu->p16v_device_offset;
507 if (!epcm->running)
508 return 0;
509
510 ptr3 = snd_emu10k1_ptr20_read(emu, PLAYBACK_LIST_PTR, channel);
511 ptr1 = snd_emu10k1_ptr20_read(emu, PLAYBACK_POINTER, channel);
512 ptr4 = snd_emu10k1_ptr20_read(emu, PLAYBACK_LIST_PTR, channel);
513 if (ptr3 != ptr4) ptr1 = snd_emu10k1_ptr20_read(emu, PLAYBACK_POINTER, channel);
514 ptr2 = bytes_to_frames(runtime, ptr1);
515 ptr2+= (ptr4 >> 3) * runtime->period_size;
516 ptr=ptr2;
517 if (ptr >= runtime->buffer_size)
518 ptr -= runtime->buffer_size;
519
520 return ptr;
521}
522
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100523/* pointer_capture callback */
524static snd_pcm_uframes_t
525snd_p16v_pcm_pointer_capture(snd_pcm_substream_t *substream)
526{
527 emu10k1_t *emu = snd_pcm_substream_chip(substream);
528 snd_pcm_runtime_t *runtime = substream->runtime;
529 emu10k1_pcm_t *epcm = runtime->private_data;
530 snd_pcm_uframes_t ptr, ptr1, ptr2 = 0;
531 int channel = 0;
532
533 if (!epcm->running)
534 return 0;
535
536 ptr1 = snd_emu10k1_ptr20_read(emu, CAPTURE_POINTER, channel);
537 ptr2 = bytes_to_frames(runtime, ptr1);
538 ptr=ptr2;
539 if (ptr >= runtime->buffer_size) {
540 ptr -= runtime->buffer_size;
541 printk("buffer capture limited!\n");
542 }
543 //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);
544
545 return ptr;
546}
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548/* operators */
549static snd_pcm_ops_t snd_p16v_playback_front_ops = {
550 .open = snd_p16v_pcm_open_playback_front,
551 .close = snd_p16v_pcm_close_playback,
552 .ioctl = snd_pcm_lib_ioctl,
553 .hw_params = snd_p16v_pcm_hw_params_playback,
554 .hw_free = snd_p16v_pcm_hw_free_playback,
555 .prepare = snd_p16v_pcm_prepare_playback,
556 .trigger = snd_p16v_pcm_trigger_playback,
557 .pointer = snd_p16v_pcm_pointer_playback,
558};
559
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100560static snd_pcm_ops_t snd_p16v_capture_ops = {
561 .open = snd_p16v_pcm_open_capture,
562 .close = snd_p16v_pcm_close_capture,
563 .ioctl = snd_pcm_lib_ioctl,
564 .hw_params = snd_p16v_pcm_hw_params_capture,
565 .hw_free = snd_p16v_pcm_hw_free_capture,
566 .prepare = snd_p16v_pcm_prepare_capture,
567 .trigger = snd_p16v_pcm_trigger_capture,
568 .pointer = snd_p16v_pcm_pointer_capture,
569};
570
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572int snd_p16v_free(emu10k1_t *chip)
573{
574 // release the data
575 if (chip->p16v_buffer.area) {
576 snd_dma_free_pages(&chip->p16v_buffer);
577 //snd_printk("period lables free: %p\n", &chip->p16v_buffer);
578 }
579 return 0;
580}
581
582static void snd_p16v_pcm_free(snd_pcm_t *pcm)
583{
584 emu10k1_t *emu = pcm->private_data;
585 //snd_printk("snd_p16v_pcm_free pcm: called\n");
586 snd_pcm_lib_preallocate_free_for_all(pcm);
587 emu->pcm = NULL;
588}
589
590int snd_p16v_pcm(emu10k1_t *emu, int device, snd_pcm_t **rpcm)
591{
592 snd_pcm_t *pcm;
593 snd_pcm_substream_t *substream;
594 int err;
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100595 int capture=1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 //snd_printk("snd_p16v_pcm called. device=%d\n", device);
598 emu->p16v_device_offset = device;
599 if (rpcm)
600 *rpcm = NULL;
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 if ((err = snd_pcm_new(emu->card, "p16v", device, 1, capture, &pcm)) < 0)
603 return err;
604
605 pcm->private_data = emu;
606 pcm->private_free = snd_p16v_pcm_free;
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100607 // Single playback 8 channel device.
608 // Single capture 2 channel device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_p16v_playback_front_ops);
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100610 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_p16v_capture_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 pcm->info_flags = 0;
613 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
614 strcpy(pcm->name, "p16v");
615 emu->pcm = pcm;
616
617 for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
618 substream;
619 substream = substream->next) {
620 if ((err = snd_pcm_lib_preallocate_pages(substream,
621 SNDRV_DMA_TYPE_DEV,
622 snd_dma_pci_data(emu->pci),
James Courtier-Dutton310bacd2005-04-10 00:00:24 +0200623 ((65536 - 64) * 8), ((65536 - 64) * 8))) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return err;
625 //snd_printk("preallocate playback substream: err=%d\n", err);
626 }
627
628 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
629 substream;
630 substream = substream->next) {
631 if ((err = snd_pcm_lib_preallocate_pages(substream,
632 SNDRV_DMA_TYPE_DEV,
633 snd_dma_pci_data(emu->pci),
634 64*1024, 64*1024)) < 0)
635 return err;
636 //snd_printk("preallocate capture substream: err=%d\n", err);
637 }
638
639 if (rpcm)
640 *rpcm = pcm;
641
642 return 0;
643}
644
645static int snd_p16v_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
646{
647 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
648 uinfo->count = 2;
649 uinfo->value.integer.min = 0;
650 uinfo->value.integer.max = 255;
651 return 0;
652}
653
654static int snd_p16v_volume_get(snd_kcontrol_t * kcontrol,
655 snd_ctl_elem_value_t * ucontrol, int reg, int high_low)
656{
657 emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
658 u32 value;
659
660 value = snd_emu10k1_ptr20_read(emu, reg, high_low);
661 if (high_low == 1) {
662 ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
663 ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */
664 } else {
665 ucontrol->value.integer.value[0] = 0xff - ((value >> 8) & 0xff); /* Left */
666 ucontrol->value.integer.value[1] = 0xff - ((value >> 0) & 0xff); /* Right */
667 }
668 return 0;
669}
670
671static int snd_p16v_volume_get_spdif_front(snd_kcontrol_t * kcontrol,
672 snd_ctl_elem_value_t * ucontrol)
673{
674 int high_low = 0;
675 int reg = PLAYBACK_VOLUME_MIXER7;
676 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
677}
678
679static int snd_p16v_volume_get_spdif_center_lfe(snd_kcontrol_t * kcontrol,
680 snd_ctl_elem_value_t * ucontrol)
681{
682 int high_low = 1;
683 int reg = PLAYBACK_VOLUME_MIXER7;
684 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
685}
686static int snd_p16v_volume_get_spdif_unknown(snd_kcontrol_t * kcontrol,
687 snd_ctl_elem_value_t * ucontrol)
688{
689 int high_low = 0;
690 int reg = PLAYBACK_VOLUME_MIXER8;
691 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
692}
693static int snd_p16v_volume_get_spdif_rear(snd_kcontrol_t * kcontrol,
694 snd_ctl_elem_value_t * ucontrol)
695{
696 int high_low = 1;
697 int reg = PLAYBACK_VOLUME_MIXER8;
698 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
699}
700
701static int snd_p16v_volume_get_analog_front(snd_kcontrol_t * kcontrol,
702 snd_ctl_elem_value_t * ucontrol)
703{
704 int high_low = 0;
705 int reg = PLAYBACK_VOLUME_MIXER9;
706 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
707}
708
709static int snd_p16v_volume_get_analog_center_lfe(snd_kcontrol_t * kcontrol,
710 snd_ctl_elem_value_t * ucontrol)
711{
712 int high_low = 1;
713 int reg = PLAYBACK_VOLUME_MIXER9;
714 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
715}
716static int snd_p16v_volume_get_analog_rear(snd_kcontrol_t * kcontrol,
717 snd_ctl_elem_value_t * ucontrol)
718{
719 int high_low = 1;
720 int reg = PLAYBACK_VOLUME_MIXER10;
721 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
722}
723
724static int snd_p16v_volume_get_analog_unknown(snd_kcontrol_t * kcontrol,
725 snd_ctl_elem_value_t * ucontrol)
726{
727 int high_low = 0;
728 int reg = PLAYBACK_VOLUME_MIXER10;
729 return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
730}
731
732static int snd_p16v_volume_put(snd_kcontrol_t * kcontrol,
733 snd_ctl_elem_value_t * ucontrol, int reg, int high_low)
734{
735 emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
736 u32 value;
737 value = snd_emu10k1_ptr20_read(emu, reg, 0);
738 //value = value & 0xffff;
739 if (high_low == 1) {
740 value &= 0xffff;
741 value = value | ((0xff - ucontrol->value.integer.value[0]) << 24) | ((0xff - ucontrol->value.integer.value[1]) << 16);
742 } else {
743 value &= 0xffff0000;
744 value = value | ((0xff - ucontrol->value.integer.value[0]) << 8) | ((0xff - ucontrol->value.integer.value[1]) );
745 }
746 snd_emu10k1_ptr20_write(emu, reg, 0, value);
747 return 1;
748}
749
750static int snd_p16v_volume_put_spdif_front(snd_kcontrol_t * kcontrol,
751 snd_ctl_elem_value_t * ucontrol)
752{
753 int high_low = 0;
754 int reg = PLAYBACK_VOLUME_MIXER7;
755 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
756}
757
758static int snd_p16v_volume_put_spdif_center_lfe(snd_kcontrol_t * kcontrol,
759 snd_ctl_elem_value_t * ucontrol)
760{
761 int high_low = 1;
762 int reg = PLAYBACK_VOLUME_MIXER7;
763 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
764}
765
766static int snd_p16v_volume_put_spdif_unknown(snd_kcontrol_t * kcontrol,
767 snd_ctl_elem_value_t * ucontrol)
768{
769 int high_low = 0;
770 int reg = PLAYBACK_VOLUME_MIXER8;
771 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
772}
773
774static int snd_p16v_volume_put_spdif_rear(snd_kcontrol_t * kcontrol,
775 snd_ctl_elem_value_t * ucontrol)
776{
777 int high_low = 1;
778 int reg = PLAYBACK_VOLUME_MIXER8;
779 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
780}
781
782static int snd_p16v_volume_put_analog_front(snd_kcontrol_t * kcontrol,
783 snd_ctl_elem_value_t * ucontrol)
784{
785 int high_low = 0;
786 int reg = PLAYBACK_VOLUME_MIXER9;
787 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
788}
789
790static int snd_p16v_volume_put_analog_center_lfe(snd_kcontrol_t * kcontrol,
791 snd_ctl_elem_value_t * ucontrol)
792{
793 int high_low = 1;
794 int reg = PLAYBACK_VOLUME_MIXER9;
795 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
796}
797
798static int snd_p16v_volume_put_analog_rear(snd_kcontrol_t * kcontrol,
799 snd_ctl_elem_value_t * ucontrol)
800{
801 int high_low = 1;
802 int reg = PLAYBACK_VOLUME_MIXER10;
803 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
804}
805
806static int snd_p16v_volume_put_analog_unknown(snd_kcontrol_t * kcontrol,
807 snd_ctl_elem_value_t * ucontrol)
808{
809 int high_low = 0;
810 int reg = PLAYBACK_VOLUME_MIXER10;
811 return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
812}
813
814static snd_kcontrol_new_t snd_p16v_volume_control_analog_front =
815{
816 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
817 .name = "HD Analog Front Volume",
818 .info = snd_p16v_volume_info,
819 .get = snd_p16v_volume_get_analog_front,
820 .put = snd_p16v_volume_put_analog_front
821};
822
823static snd_kcontrol_new_t snd_p16v_volume_control_analog_center_lfe =
824{
825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
826 .name = "HD Analog Center/LFE Volume",
827 .info = snd_p16v_volume_info,
828 .get = snd_p16v_volume_get_analog_center_lfe,
829 .put = snd_p16v_volume_put_analog_center_lfe
830};
831
832static snd_kcontrol_new_t snd_p16v_volume_control_analog_unknown =
833{
834 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
835 .name = "HD Analog Unknown Volume",
836 .info = snd_p16v_volume_info,
837 .get = snd_p16v_volume_get_analog_unknown,
838 .put = snd_p16v_volume_put_analog_unknown
839};
840
841static snd_kcontrol_new_t snd_p16v_volume_control_analog_rear =
842{
843 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
844 .name = "HD Analog Rear Volume",
845 .info = snd_p16v_volume_info,
846 .get = snd_p16v_volume_get_analog_rear,
847 .put = snd_p16v_volume_put_analog_rear
848};
849
850static snd_kcontrol_new_t snd_p16v_volume_control_spdif_front =
851{
852 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
853 .name = "HD SPDIF Front Volume",
854 .info = snd_p16v_volume_info,
855 .get = snd_p16v_volume_get_spdif_front,
856 .put = snd_p16v_volume_put_spdif_front
857};
858
859static snd_kcontrol_new_t snd_p16v_volume_control_spdif_center_lfe =
860{
861 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
862 .name = "HD SPDIF Center/LFE Volume",
863 .info = snd_p16v_volume_info,
864 .get = snd_p16v_volume_get_spdif_center_lfe,
865 .put = snd_p16v_volume_put_spdif_center_lfe
866};
867
868static snd_kcontrol_new_t snd_p16v_volume_control_spdif_unknown =
869{
870 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
871 .name = "HD SPDIF Unknown Volume",
872 .info = snd_p16v_volume_info,
873 .get = snd_p16v_volume_get_spdif_unknown,
874 .put = snd_p16v_volume_put_spdif_unknown
875};
876
877static snd_kcontrol_new_t snd_p16v_volume_control_spdif_rear =
878{
879 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
880 .name = "HD SPDIF Rear Volume",
881 .info = snd_p16v_volume_info,
882 .get = snd_p16v_volume_get_spdif_rear,
883 .put = snd_p16v_volume_put_spdif_rear
884};
885
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100886static int snd_p16v_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
887{
888 static char *texts[8] = { "SPDIF", "I2S", "SRC48", "SRCMulti_SPDIF", "SRCMulti_I2S", "CDIF", "FX", "AC97" };
889
890 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
891 uinfo->count = 1;
892 uinfo->value.enumerated.items = 8;
893 if (uinfo->value.enumerated.item > 7)
894 uinfo->value.enumerated.item = 7;
895 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
896 return 0;
897}
898
899static int snd_p16v_capture_source_get(snd_kcontrol_t * kcontrol,
900 snd_ctl_elem_value_t * ucontrol)
901{
902 emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
903
904 ucontrol->value.enumerated.item[0] = emu->p16v_capture_source;
905 return 0;
906}
907
908static int snd_p16v_capture_source_put(snd_kcontrol_t * kcontrol,
909 snd_ctl_elem_value_t * ucontrol)
910{
911 emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
912 unsigned int val;
913 int change = 0;
914 u32 mask;
915 u32 source;
916
917 val = ucontrol->value.enumerated.item[0] ;
918 change = (emu->p16v_capture_source != val);
919 if (change) {
920 emu->p16v_capture_source = val;
921 source = (val << 28) | (val << 24) | (val << 20) | (val << 16);
922 mask = snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0) & 0xffff;
923 snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, source | mask);
924 }
925 return change;
926}
927
928static snd_kcontrol_new_t snd_p16v_capture_source __devinitdata =
929{
930 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
931 .name = "HD Capture source",
932 .info = snd_p16v_capture_source_info,
933 .get = snd_p16v_capture_source_get,
934 .put = snd_p16v_capture_source_put
935};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936int snd_p16v_mixer(emu10k1_t *emu)
937{
938 int err;
939 snd_kcontrol_t *kctl;
940 snd_card_t *card = emu->card;
941 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_front, emu)) == NULL)
942 return -ENOMEM;
943 if ((err = snd_ctl_add(card, kctl)))
944 return err;
945 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_rear, emu)) == NULL)
946 return -ENOMEM;
947 if ((err = snd_ctl_add(card, kctl)))
948 return err;
949 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_center_lfe, emu)) == NULL)
950 return -ENOMEM;
951 if ((err = snd_ctl_add(card, kctl)))
952 return err;
953 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_unknown, emu)) == NULL)
954 return -ENOMEM;
955 if ((err = snd_ctl_add(card, kctl)))
956 return err;
957 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_front, emu)) == NULL)
958 return -ENOMEM;
959 if ((err = snd_ctl_add(card, kctl)))
960 return err;
961 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_rear, emu)) == NULL)
962 return -ENOMEM;
963 if ((err = snd_ctl_add(card, kctl)))
964 return err;
965 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_center_lfe, emu)) == NULL)
966 return -ENOMEM;
967 if ((err = snd_ctl_add(card, kctl)))
968 return err;
969 if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_unknown, emu)) == NULL)
970 return -ENOMEM;
971 if ((err = snd_ctl_add(card, kctl)))
972 return err;
James Courtier-Dutton6e4abc42005-03-26 19:35:29 +0100973 if ((kctl = snd_ctl_new1(&snd_p16v_capture_source, emu)) == NULL)
974 return -ENOMEM;
975 if ((err = snd_ctl_add(card, kctl)))
976 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 return 0;
978}
979