blob: 6a13ca1d545e311980eddc0ba75be8c00b111fdf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16
17/*
18 * Vortex PCM ALSA driver.
19 *
20 * Supports ADB and WT DMA. Unfortunately, WT channels do not run yet.
21 * It remains stuck,and DMA transfers do not happen.
22 */
23#include <sound/asoundef.h>
24#include <sound/driver.h>
25#include <linux/time.h>
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include "au88x0.h"
30
31#define VORTEX_PCM_TYPE(x) (x->name[40])
32
33/* hardware definition */
Takashi Iwai2fd16872005-11-17 14:55:19 +010034static struct snd_pcm_hardware snd_vortex_playback_hw_adb = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 .info =
Jaroslav Kysela41e48452005-08-18 13:43:12 +020036 (SNDRV_PCM_INFO_MMAP | /* SNDRV_PCM_INFO_RESUME | */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_INTERLEAVED |
38 SNDRV_PCM_INFO_MMAP_VALID),
39 .formats =
40 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U8 |
41 SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW,
42 .rates = SNDRV_PCM_RATE_CONTINUOUS,
43 .rate_min = 5000,
44 .rate_max = 48000,
45 .channels_min = 1,
46#ifdef CHIP_AU8830
47 .channels_max = 4,
48#else
49 .channels_max = 2,
50#endif
51 .buffer_bytes_max = 0x10000,
52 .period_bytes_min = 0x1,
53 .period_bytes_max = 0x1000,
54 .periods_min = 2,
55 .periods_max = 32,
56};
57
58#ifndef CHIP_AU8820
Takashi Iwai2fd16872005-11-17 14:55:19 +010059static struct snd_pcm_hardware snd_vortex_playback_hw_a3d = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 .info =
Jaroslav Kysela41e48452005-08-18 13:43:12 +020061 (SNDRV_PCM_INFO_MMAP | /* SNDRV_PCM_INFO_RESUME | */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_INTERLEAVED |
63 SNDRV_PCM_INFO_MMAP_VALID),
64 .formats =
65 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U8 |
66 SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW,
67 .rates = SNDRV_PCM_RATE_CONTINUOUS,
68 .rate_min = 5000,
69 .rate_max = 48000,
70 .channels_min = 1,
71 .channels_max = 1,
72 .buffer_bytes_max = 0x10000,
73 .period_bytes_min = 0x100,
74 .period_bytes_max = 0x1000,
75 .periods_min = 2,
76 .periods_max = 64,
77};
78#endif
Takashi Iwai2fd16872005-11-17 14:55:19 +010079static struct snd_pcm_hardware snd_vortex_playback_hw_spdif = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 .info =
Jaroslav Kysela41e48452005-08-18 13:43:12 +020081 (SNDRV_PCM_INFO_MMAP | /* SNDRV_PCM_INFO_RESUME | */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_INTERLEAVED |
83 SNDRV_PCM_INFO_MMAP_VALID),
84 .formats =
85 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U8 |
86 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE | SNDRV_PCM_FMTBIT_MU_LAW |
87 SNDRV_PCM_FMTBIT_A_LAW,
88 .rates =
89 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
90 .rate_min = 32000,
91 .rate_max = 48000,
92 .channels_min = 1,
93 .channels_max = 2,
94 .buffer_bytes_max = 0x10000,
95 .period_bytes_min = 0x100,
96 .period_bytes_max = 0x1000,
97 .periods_min = 2,
98 .periods_max = 64,
99};
100
101#ifndef CHIP_AU8810
Takashi Iwai2fd16872005-11-17 14:55:19 +0100102static struct snd_pcm_hardware snd_vortex_playback_hw_wt = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 .info = (SNDRV_PCM_INFO_MMAP |
104 SNDRV_PCM_INFO_INTERLEAVED |
105 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
106 .formats = SNDRV_PCM_FMTBIT_S16_LE,
107 .rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_CONTINUOUS, // SNDRV_PCM_RATE_48000,
108 .rate_min = 8000,
109 .rate_max = 48000,
110 .channels_min = 1,
111 .channels_max = 2,
112 .buffer_bytes_max = 0x10000,
113 .period_bytes_min = 0x0400,
114 .period_bytes_max = 0x1000,
115 .periods_min = 2,
116 .periods_max = 64,
117};
118#endif
119/* open callback */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100120static int snd_vortex_pcm_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 vortex_t *vortex = snd_pcm_substream_chip(substream);
Takashi Iwai2fd16872005-11-17 14:55:19 +0100123 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 int err;
125
126 /* Force equal size periods */
127 if ((err =
128 snd_pcm_hw_constraint_integer(runtime,
129 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
130 return err;
131 /* Avoid PAGE_SIZE boundary to fall inside of a period. */
132 if ((err =
133 snd_pcm_hw_constraint_pow2(runtime, 0,
134 SNDRV_PCM_HW_PARAM_PERIOD_BYTES)) < 0)
135 return err;
136
137 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
138#ifndef CHIP_AU8820
139 if (VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_A3D) {
140 runtime->hw = snd_vortex_playback_hw_a3d;
141 }
142#endif
143 if (VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_SPDIF) {
144 runtime->hw = snd_vortex_playback_hw_spdif;
145 switch (vortex->spdif_sr) {
146 case 32000:
147 runtime->hw.rates = SNDRV_PCM_RATE_32000;
148 break;
149 case 44100:
150 runtime->hw.rates = SNDRV_PCM_RATE_44100;
151 break;
152 case 48000:
153 runtime->hw.rates = SNDRV_PCM_RATE_48000;
154 break;
155 }
156 }
157 if (VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_ADB
158 || VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_I2S)
159 runtime->hw = snd_vortex_playback_hw_adb;
160 substream->runtime->private_data = NULL;
161 }
162#ifndef CHIP_AU8810
163 else {
164 runtime->hw = snd_vortex_playback_hw_wt;
165 substream->runtime->private_data = NULL;
166 }
167#endif
168 return 0;
169}
170
171/* close callback */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100172static int snd_vortex_pcm_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 //vortex_t *chip = snd_pcm_substream_chip(substream);
175 stream_t *stream = (stream_t *) substream->runtime->private_data;
176
177 // the hardware-specific codes will be here
178 if (stream != NULL) {
179 stream->substream = NULL;
180 stream->nr_ch = 0;
181 }
182 substream->runtime->private_data = NULL;
183 return 0;
184}
185
186/* hw_params callback */
187static int
Takashi Iwai2fd16872005-11-17 14:55:19 +0100188snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
189 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
191 vortex_t *chip = snd_pcm_substream_chip(substream);
192 stream_t *stream = (stream_t *) (substream->runtime->private_data);
Takashi Iwai2fd16872005-11-17 14:55:19 +0100193 struct snd_sg_buf *sgbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 int err;
195
196 // Alloc buffer memory.
197 err =
198 snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
199 if (err < 0) {
200 printk(KERN_ERR "Vortex: pcm page alloc failed!\n");
201 return err;
202 }
Takashi Iwai2fd16872005-11-17 14:55:19 +0100203 //sgbuf = (struct snd_sg_buf *) substream->runtime->dma_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 sgbuf = snd_pcm_substream_sgbuf(substream);
205 /*
206 printk(KERN_INFO "Vortex: periods %d, period_bytes %d, channels = %d\n", params_periods(hw_params),
207 params_period_bytes(hw_params), params_channels(hw_params));
208 */
209 spin_lock_irq(&chip->lock);
210 // Make audio routes and config buffer DMA.
211 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
212 int dma, type = VORTEX_PCM_TYPE(substream->pcm);
213 /* Dealloc any routes. */
214 if (stream != NULL)
215 vortex_adb_allocroute(chip, stream->dma,
216 stream->nr_ch, stream->dir,
217 stream->type);
218 /* Alloc routes. */
219 dma =
220 vortex_adb_allocroute(chip, -1,
221 params_channels(hw_params),
222 substream->stream, type);
Takashi Iwaia2786552005-08-24 17:57:25 +0200223 if (dma < 0) {
224 spin_unlock_irq(&chip->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return dma;
Takashi Iwaia2786552005-08-24 17:57:25 +0200226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 stream = substream->runtime->private_data = &chip->dma_adb[dma];
228 stream->substream = substream;
229 /* Setup Buffers. */
230 vortex_adbdma_setbuffers(chip, dma, sgbuf,
231 params_period_bytes(hw_params),
232 params_periods(hw_params));
233 }
234#ifndef CHIP_AU8810
235 else {
236 /* if (stream != NULL)
237 vortex_wt_allocroute(chip, substream->number, 0); */
238 vortex_wt_allocroute(chip, substream->number,
239 params_channels(hw_params));
240 stream = substream->runtime->private_data =
241 &chip->dma_wt[substream->number];
242 stream->dma = substream->number;
243 stream->substream = substream;
244 vortex_wtdma_setbuffers(chip, substream->number, sgbuf,
245 params_period_bytes(hw_params),
246 params_periods(hw_params));
247 }
248#endif
249 spin_unlock_irq(&chip->lock);
250 return 0;
251}
252
253/* hw_free callback */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100254static int snd_vortex_pcm_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 vortex_t *chip = snd_pcm_substream_chip(substream);
257 stream_t *stream = (stream_t *) (substream->runtime->private_data);
258
259 spin_lock_irq(&chip->lock);
260 // Delete audio routes.
261 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
262 if (stream != NULL)
263 vortex_adb_allocroute(chip, stream->dma,
264 stream->nr_ch, stream->dir,
265 stream->type);
266 }
267#ifndef CHIP_AU8810
268 else {
269 if (stream != NULL)
270 vortex_wt_allocroute(chip, stream->dma, 0);
271 }
272#endif
273 substream->runtime->private_data = NULL;
274 spin_unlock_irq(&chip->lock);
275
276 return snd_pcm_lib_free_pages(substream);
277}
278
279/* prepare callback */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100280static int snd_vortex_pcm_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 vortex_t *chip = snd_pcm_substream_chip(substream);
Takashi Iwai2fd16872005-11-17 14:55:19 +0100283 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 stream_t *stream = (stream_t *) substream->runtime->private_data;
285 int dma = stream->dma, fmt, dir;
286
287 // set up the hardware with the current configuration.
288 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
289 dir = 1;
290 else
291 dir = 0;
292 fmt = vortex_alsafmt_aspfmt(runtime->format);
293 spin_lock_irq(&chip->lock);
294 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
295 vortex_adbdma_setmode(chip, dma, 1, dir, fmt, 0 /*? */ ,
296 0);
297 vortex_adbdma_setstartbuffer(chip, dma, 0);
298 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_SPDIF)
299 vortex_adb_setsrc(chip, dma, runtime->rate, dir);
300 }
301#ifndef CHIP_AU8810
302 else {
303 vortex_wtdma_setmode(chip, dma, 1, fmt, 0, 0);
304 // FIXME: Set rate (i guess using vortex_wt_writereg() somehow).
305 vortex_wtdma_setstartbuffer(chip, dma, 0);
306 }
307#endif
308 spin_unlock_irq(&chip->lock);
309 return 0;
310}
311
312/* trigger callback */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100313static int snd_vortex_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
315 vortex_t *chip = snd_pcm_substream_chip(substream);
316 stream_t *stream = (stream_t *) substream->runtime->private_data;
317 int dma = stream->dma;
318
319 spin_lock(&chip->lock);
320 switch (cmd) {
321 case SNDRV_PCM_TRIGGER_START:
322 // do something to start the PCM engine
323 //printk(KERN_INFO "vortex: start %d\n", dma);
324 stream->fifo_enabled = 1;
325 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
326 vortex_adbdma_resetup(chip, dma);
327 vortex_adbdma_startfifo(chip, dma);
328 }
329#ifndef CHIP_AU8810
330 else {
331 printk(KERN_INFO "vortex: wt start %d\n", dma);
332 vortex_wtdma_startfifo(chip, dma);
333 }
334#endif
335 break;
336 case SNDRV_PCM_TRIGGER_STOP:
337 // do something to stop the PCM engine
338 //printk(KERN_INFO "vortex: stop %d\n", dma);
339 stream->fifo_enabled = 0;
340 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT)
341 vortex_adbdma_pausefifo(chip, dma);
342 //vortex_adbdma_stopfifo(chip, dma);
343#ifndef CHIP_AU8810
344 else {
345 printk(KERN_INFO "vortex: wt stop %d\n", dma);
346 vortex_wtdma_stopfifo(chip, dma);
347 }
348#endif
349 break;
350 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
351 //printk(KERN_INFO "vortex: pause %d\n", dma);
352 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT)
353 vortex_adbdma_pausefifo(chip, dma);
354#ifndef CHIP_AU8810
355 else
356 vortex_wtdma_pausefifo(chip, dma);
357#endif
358 break;
359 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
360 //printk(KERN_INFO "vortex: resume %d\n", dma);
361 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT)
362 vortex_adbdma_resumefifo(chip, dma);
363#ifndef CHIP_AU8810
364 else
365 vortex_wtdma_resumefifo(chip, dma);
366#endif
367 break;
368 default:
369 spin_unlock(&chip->lock);
370 return -EINVAL;
371 }
372 spin_unlock(&chip->lock);
373 return 0;
374}
375
376/* pointer callback */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100377static snd_pcm_uframes_t snd_vortex_pcm_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 vortex_t *chip = snd_pcm_substream_chip(substream);
380 stream_t *stream = (stream_t *) substream->runtime->private_data;
381 int dma = stream->dma;
382 snd_pcm_uframes_t current_ptr = 0;
383
384 spin_lock(&chip->lock);
385 if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT)
386 current_ptr = vortex_adbdma_getlinearpos(chip, dma);
387#ifndef CHIP_AU8810
388 else
389 current_ptr = vortex_wtdma_getlinearpos(chip, dma);
390#endif
391 //printk(KERN_INFO "vortex: pointer = 0x%x\n", current_ptr);
392 spin_unlock(&chip->lock);
393 return (bytes_to_frames(substream->runtime, current_ptr));
394}
395
396/* Page callback. */
397/*
Takashi Iwai2fd16872005-11-17 14:55:19 +0100398static struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400
401}
402*/
403/* operators */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100404static struct snd_pcm_ops snd_vortex_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 .open = snd_vortex_pcm_open,
406 .close = snd_vortex_pcm_close,
407 .ioctl = snd_pcm_lib_ioctl,
408 .hw_params = snd_vortex_pcm_hw_params,
409 .hw_free = snd_vortex_pcm_hw_free,
410 .prepare = snd_vortex_pcm_prepare,
411 .trigger = snd_vortex_pcm_trigger,
412 .pointer = snd_vortex_pcm_pointer,
413 .page = snd_pcm_sgbuf_ops_page,
414};
415
416/*
417* definitions of capture are omitted here...
418*/
419
420static char *vortex_pcm_prettyname[VORTEX_PCM_LAST] = {
421 "AU88x0 ADB",
422 "AU88x0 SPDIF",
423 "AU88x0 A3D",
424 "AU88x0 WT",
425 "AU88x0 I2S",
426};
427static char *vortex_pcm_name[VORTEX_PCM_LAST] = {
428 "adb",
429 "spdif",
430 "a3d",
431 "wt",
432 "i2s",
433};
434
435/* SPDIF kcontrol */
436
Takashi Iwai2fd16872005-11-17 14:55:19 +0100437static int snd_vortex_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
439 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
440 uinfo->count = 1;
441 return 0;
442}
443
Takashi Iwai2fd16872005-11-17 14:55:19 +0100444static int snd_vortex_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 ucontrol->value.iec958.status[0] = 0xff;
447 ucontrol->value.iec958.status[1] = 0xff;
448 ucontrol->value.iec958.status[2] = 0xff;
449 ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
450 return 0;
451}
452
Takashi Iwai2fd16872005-11-17 14:55:19 +0100453static int snd_vortex_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
455 vortex_t *vortex = snd_kcontrol_chip(kcontrol);
456 ucontrol->value.iec958.status[0] = 0x00;
457 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL|IEC958_AES1_CON_DIGDIGCONV_ID;
458 ucontrol->value.iec958.status[2] = 0x00;
459 switch (vortex->spdif_sr) {
460 case 32000: ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_32000; break;
461 case 44100: ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_44100; break;
462 case 48000: ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000; break;
463 }
464 return 0;
465}
466
Takashi Iwai2fd16872005-11-17 14:55:19 +0100467static int snd_vortex_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
469 vortex_t *vortex = snd_kcontrol_chip(kcontrol);
470 int spdif_sr = 48000;
471 switch (ucontrol->value.iec958.status[3] & IEC958_AES3_CON_FS) {
472 case IEC958_AES3_CON_FS_32000: spdif_sr = 32000; break;
473 case IEC958_AES3_CON_FS_44100: spdif_sr = 44100; break;
474 case IEC958_AES3_CON_FS_48000: spdif_sr = 48000; break;
475 }
476 if (spdif_sr == vortex->spdif_sr)
477 return 0;
478 vortex->spdif_sr = spdif_sr;
479 vortex_spdif_init(vortex, vortex->spdif_sr, 1);
480 return 1;
481}
482
483/* spdif controls */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100484static struct snd_kcontrol_new snd_vortex_mixer_spdif[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 {
486 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
487 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
488 .info = snd_vortex_spdif_info,
489 .get = snd_vortex_spdif_get,
490 .put = snd_vortex_spdif_put,
491 },
492 {
493 .access = SNDRV_CTL_ELEM_ACCESS_READ,
494 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
495 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
496 .info = snd_vortex_spdif_info,
497 .get = snd_vortex_spdif_mask_get
498 },
499};
500
501/* create a pcm device */
502static int __devinit snd_vortex_new_pcm(vortex_t * chip, int idx, int nr)
503{
Takashi Iwai2fd16872005-11-17 14:55:19 +0100504 struct snd_pcm *pcm;
505 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 int i;
507 int err, nr_capt;
508
509 if ((chip == 0) || (idx < 0) || (idx > VORTEX_PCM_LAST))
510 return -ENODEV;
511
512 /* idx indicates which kind of PCM device. ADB, SPDIF, I2S and A3D share the
513 * same dma engine. WT uses it own separate dma engine whcih cant capture. */
514 if (idx == VORTEX_PCM_ADB)
515 nr_capt = nr;
516 else
517 nr_capt = 0;
518 if ((err =
519 snd_pcm_new(chip->card, vortex_pcm_prettyname[idx], idx, nr,
520 nr_capt, &pcm)) < 0)
521 return err;
522 strcpy(pcm->name, vortex_pcm_name[idx]);
523 chip->pcm[idx] = pcm;
524 // This is an evil hack, but it saves a lot of duplicated code.
525 VORTEX_PCM_TYPE(pcm) = idx;
526 pcm->private_data = chip;
527 /* set operators */
528 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
529 &snd_vortex_playback_ops);
530 if (idx == VORTEX_PCM_ADB)
531 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
532 &snd_vortex_playback_ops);
533
534 /* pre-allocation of Scatter-Gather buffers */
535
536 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
537 snd_dma_pci_data(chip->pci_dev),
538 0x10000, 0x10000);
539
540 if (VORTEX_PCM_TYPE(pcm) == VORTEX_PCM_SPDIF) {
541 for (i = 0; i < ARRAY_SIZE(snd_vortex_mixer_spdif); i++) {
542 kctl = snd_ctl_new1(&snd_vortex_mixer_spdif[i], chip);
543 if (!kctl)
544 return -ENOMEM;
545 if ((err = snd_ctl_add(chip->card, kctl)) < 0)
546 return err;
547 }
548 }
549 return 0;
550}