2 * C-Media CMI8788 driver - PCM code
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/pci.h>
21 #include <sound/control.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
27 /* most DMA channels have a 16-bit counter for 32-bit words */
28 #define BUFFER_BYTES_MAX ((1 << 16) * 4)
29 /* the multichannel DMA channel has a 24-bit counter */
30 #define BUFFER_BYTES_MAX_MULTICH ((1 << 24) * 4)
32 #define FIFO_BYTES 256
33 #define FIFO_BYTES_MULTICH 1024
35 #define PERIOD_BYTES_MIN 64
37 #define DEFAULT_BUFFER_BYTES (BUFFER_BYTES_MAX / 2)
38 #define DEFAULT_BUFFER_BYTES_MULTICH (1024 * 1024)
40 static const struct snd_pcm_hardware oxygen_stereo_hardware = {
41 .info = SNDRV_PCM_INFO_MMAP |
42 SNDRV_PCM_INFO_MMAP_VALID |
43 SNDRV_PCM_INFO_INTERLEAVED |
44 SNDRV_PCM_INFO_PAUSE |
45 SNDRV_PCM_INFO_SYNC_START |
46 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
47 .formats = SNDRV_PCM_FMTBIT_S16_LE |
48 SNDRV_PCM_FMTBIT_S32_LE,
49 .rates = SNDRV_PCM_RATE_32000 |
50 SNDRV_PCM_RATE_44100 |
51 SNDRV_PCM_RATE_48000 |
52 SNDRV_PCM_RATE_64000 |
53 SNDRV_PCM_RATE_88200 |
54 SNDRV_PCM_RATE_96000 |
55 SNDRV_PCM_RATE_176400 |
56 SNDRV_PCM_RATE_192000,
61 .buffer_bytes_max = BUFFER_BYTES_MAX,
62 .period_bytes_min = PERIOD_BYTES_MIN,
63 .period_bytes_max = BUFFER_BYTES_MAX,
65 .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN,
66 .fifo_size = FIFO_BYTES,
68 static const struct snd_pcm_hardware oxygen_multichannel_hardware = {
69 .info = SNDRV_PCM_INFO_MMAP |
70 SNDRV_PCM_INFO_MMAP_VALID |
71 SNDRV_PCM_INFO_INTERLEAVED |
72 SNDRV_PCM_INFO_PAUSE |
73 SNDRV_PCM_INFO_SYNC_START |
74 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
75 .formats = SNDRV_PCM_FMTBIT_S16_LE |
76 SNDRV_PCM_FMTBIT_S32_LE,
77 .rates = SNDRV_PCM_RATE_32000 |
78 SNDRV_PCM_RATE_44100 |
79 SNDRV_PCM_RATE_48000 |
80 SNDRV_PCM_RATE_64000 |
81 SNDRV_PCM_RATE_88200 |
82 SNDRV_PCM_RATE_96000 |
83 SNDRV_PCM_RATE_176400 |
84 SNDRV_PCM_RATE_192000,
89 .buffer_bytes_max = BUFFER_BYTES_MAX_MULTICH,
90 .period_bytes_min = PERIOD_BYTES_MIN,
91 .period_bytes_max = BUFFER_BYTES_MAX_MULTICH,
93 .periods_max = BUFFER_BYTES_MAX_MULTICH / PERIOD_BYTES_MIN,
94 .fifo_size = FIFO_BYTES_MULTICH,
96 static const struct snd_pcm_hardware oxygen_ac97_hardware = {
97 .info = SNDRV_PCM_INFO_MMAP |
98 SNDRV_PCM_INFO_MMAP_VALID |
99 SNDRV_PCM_INFO_INTERLEAVED |
100 SNDRV_PCM_INFO_PAUSE |
101 SNDRV_PCM_INFO_SYNC_START |
102 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
103 .formats = SNDRV_PCM_FMTBIT_S16_LE,
104 .rates = SNDRV_PCM_RATE_48000,
109 .buffer_bytes_max = BUFFER_BYTES_MAX,
110 .period_bytes_min = PERIOD_BYTES_MIN,
111 .period_bytes_max = BUFFER_BYTES_MAX,
113 .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN,
114 .fifo_size = FIFO_BYTES,
117 static const struct snd_pcm_hardware *const oxygen_hardware[PCM_COUNT] = {
118 [PCM_A] = &oxygen_stereo_hardware,
119 [PCM_B] = &oxygen_stereo_hardware,
120 [PCM_C] = &oxygen_stereo_hardware,
121 [PCM_SPDIF] = &oxygen_stereo_hardware,
122 [PCM_MULTICH] = &oxygen_multichannel_hardware,
123 [PCM_AC97] = &oxygen_ac97_hardware,
126 static inline unsigned int
127 oxygen_substream_channel(struct snd_pcm_substream *substream)
129 return (unsigned int)(uintptr_t)substream->runtime->private_data;
132 static int oxygen_open(struct snd_pcm_substream *substream,
133 unsigned int channel)
135 struct oxygen *chip = snd_pcm_substream_chip(substream);
136 struct snd_pcm_runtime *runtime = substream->runtime;
139 runtime->private_data = (void *)(uintptr_t)channel;
140 if (channel == PCM_B && chip->has_ac97_1 &&
141 (chip->model.device_config & CAPTURE_2_FROM_AC97_1))
142 runtime->hw = oxygen_ac97_hardware;
144 runtime->hw = *oxygen_hardware[channel];
147 runtime->hw.rates &= ~(SNDRV_PCM_RATE_32000 |
148 SNDRV_PCM_RATE_64000);
149 runtime->hw.rate_min = 44100;
153 runtime->hw.fifo_size = 0;
156 runtime->hw.channels_max = chip->model.dac_channels_pcm;
159 if (chip->model.pcm_hardware_filter)
160 chip->model.pcm_hardware_filter(channel, &runtime->hw);
161 err = snd_pcm_hw_constraint_step(runtime, 0,
162 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
165 err = snd_pcm_hw_constraint_step(runtime, 0,
166 SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 32);
169 if (runtime->hw.formats & SNDRV_PCM_FMTBIT_S32_LE) {
170 err = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
174 if (runtime->hw.channels_max > 2) {
175 err = snd_pcm_hw_constraint_step(runtime, 0,
176 SNDRV_PCM_HW_PARAM_CHANNELS,
181 snd_pcm_set_sync(substream);
182 chip->streams[channel] = substream;
184 mutex_lock(&chip->mutex);
185 chip->pcm_active |= 1 << channel;
186 if (channel == PCM_SPDIF) {
187 chip->spdif_pcm_bits = chip->spdif_bits;
188 chip->controls[CONTROL_SPDIF_PCM]->vd[0].access &=
189 ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
190 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
191 SNDRV_CTL_EVENT_MASK_INFO,
192 &chip->controls[CONTROL_SPDIF_PCM]->id);
194 mutex_unlock(&chip->mutex);
199 static int oxygen_rec_a_open(struct snd_pcm_substream *substream)
201 return oxygen_open(substream, PCM_A);
204 static int oxygen_rec_b_open(struct snd_pcm_substream *substream)
206 return oxygen_open(substream, PCM_B);
209 static int oxygen_rec_c_open(struct snd_pcm_substream *substream)
211 return oxygen_open(substream, PCM_C);
214 static int oxygen_spdif_open(struct snd_pcm_substream *substream)
216 return oxygen_open(substream, PCM_SPDIF);
219 static int oxygen_multich_open(struct snd_pcm_substream *substream)
221 return oxygen_open(substream, PCM_MULTICH);
224 static int oxygen_ac97_open(struct snd_pcm_substream *substream)
226 return oxygen_open(substream, PCM_AC97);
229 static int oxygen_close(struct snd_pcm_substream *substream)
231 struct oxygen *chip = snd_pcm_substream_chip(substream);
232 unsigned int channel = oxygen_substream_channel(substream);
234 mutex_lock(&chip->mutex);
235 chip->pcm_active &= ~(1 << channel);
236 if (channel == PCM_SPDIF) {
237 chip->controls[CONTROL_SPDIF_PCM]->vd[0].access |=
238 SNDRV_CTL_ELEM_ACCESS_INACTIVE;
239 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
240 SNDRV_CTL_EVENT_MASK_INFO,
241 &chip->controls[CONTROL_SPDIF_PCM]->id);
243 if (channel == PCM_SPDIF || channel == PCM_MULTICH)
244 oxygen_update_spdif_source(chip);
245 mutex_unlock(&chip->mutex);
247 chip->streams[channel] = NULL;
251 static unsigned int oxygen_format(struct snd_pcm_hw_params *hw_params)
253 if (params_format(hw_params) == SNDRV_PCM_FORMAT_S32_LE)
254 return OXYGEN_FORMAT_24;
256 return OXYGEN_FORMAT_16;
259 static unsigned int oxygen_rate(struct snd_pcm_hw_params *hw_params)
261 switch (params_rate(hw_params)) {
263 return OXYGEN_RATE_32000;
265 return OXYGEN_RATE_44100;
267 return OXYGEN_RATE_48000;
269 return OXYGEN_RATE_64000;
271 return OXYGEN_RATE_88200;
273 return OXYGEN_RATE_96000;
275 return OXYGEN_RATE_176400;
277 return OXYGEN_RATE_192000;
281 static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params)
283 if (params_format(hw_params) == SNDRV_PCM_FORMAT_S32_LE)
284 return OXYGEN_I2S_BITS_24;
286 return OXYGEN_I2S_BITS_16;
289 static unsigned int oxygen_play_channels(struct snd_pcm_hw_params *hw_params)
291 switch (params_channels(hw_params)) {
293 return OXYGEN_PLAY_CHANNELS_2;
295 return OXYGEN_PLAY_CHANNELS_4;
297 return OXYGEN_PLAY_CHANNELS_6;
299 return OXYGEN_PLAY_CHANNELS_8;
303 static const unsigned int channel_base_registers[PCM_COUNT] = {
304 [PCM_A] = OXYGEN_DMA_A_ADDRESS,
305 [PCM_B] = OXYGEN_DMA_B_ADDRESS,
306 [PCM_C] = OXYGEN_DMA_C_ADDRESS,
307 [PCM_SPDIF] = OXYGEN_DMA_SPDIF_ADDRESS,
308 [PCM_MULTICH] = OXYGEN_DMA_MULTICH_ADDRESS,
309 [PCM_AC97] = OXYGEN_DMA_AC97_ADDRESS,
312 static int oxygen_hw_params(struct snd_pcm_substream *substream,
313 struct snd_pcm_hw_params *hw_params)
315 struct oxygen *chip = snd_pcm_substream_chip(substream);
316 unsigned int channel = oxygen_substream_channel(substream);
319 err = snd_pcm_lib_malloc_pages(substream,
320 params_buffer_bytes(hw_params));
324 oxygen_write32(chip, channel_base_registers[channel],
325 (u32)substream->runtime->dma_addr);
326 if (channel == PCM_MULTICH) {
327 oxygen_write32(chip, OXYGEN_DMA_MULTICH_COUNT,
328 params_buffer_bytes(hw_params) / 4 - 1);
329 oxygen_write32(chip, OXYGEN_DMA_MULTICH_TCOUNT,
330 params_period_bytes(hw_params) / 4 - 1);
332 oxygen_write16(chip, channel_base_registers[channel] + 4,
333 params_buffer_bytes(hw_params) / 4 - 1);
334 oxygen_write16(chip, channel_base_registers[channel] + 6,
335 params_period_bytes(hw_params) / 4 - 1);
340 static u16 get_mclk(struct oxygen *chip, unsigned int channel,
341 struct snd_pcm_hw_params *params)
343 unsigned int mclks, shift;
345 if (channel == PCM_MULTICH)
346 mclks = chip->model.dac_mclks;
348 mclks = chip->model.adc_mclks;
350 if (params_rate(params) <= 48000)
352 else if (params_rate(params) <= 96000)
357 return OXYGEN_I2S_MCLK(mclks >> shift);
360 static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
361 struct snd_pcm_hw_params *hw_params)
363 struct oxygen *chip = snd_pcm_substream_chip(substream);
366 err = oxygen_hw_params(substream, hw_params);
370 spin_lock_irq(&chip->reg_lock);
371 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT,
372 oxygen_format(hw_params) << OXYGEN_REC_FORMAT_A_SHIFT,
373 OXYGEN_REC_FORMAT_A_MASK);
374 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT,
375 oxygen_rate(hw_params) |
376 chip->model.adc_i2s_format |
377 get_mclk(chip, PCM_A, hw_params) |
378 oxygen_i2s_bits(hw_params),
379 OXYGEN_I2S_RATE_MASK |
380 OXYGEN_I2S_FORMAT_MASK |
381 OXYGEN_I2S_MCLK_MASK |
382 OXYGEN_I2S_BITS_MASK);
383 spin_unlock_irq(&chip->reg_lock);
385 mutex_lock(&chip->mutex);
386 chip->model.set_adc_params(chip, hw_params);
387 mutex_unlock(&chip->mutex);
391 static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
392 struct snd_pcm_hw_params *hw_params)
394 struct oxygen *chip = snd_pcm_substream_chip(substream);
398 err = oxygen_hw_params(substream, hw_params);
402 is_ac97 = chip->has_ac97_1 &&
403 (chip->model.device_config & CAPTURE_2_FROM_AC97_1);
405 spin_lock_irq(&chip->reg_lock);
406 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT,
407 oxygen_format(hw_params) << OXYGEN_REC_FORMAT_B_SHIFT,
408 OXYGEN_REC_FORMAT_B_MASK);
410 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT,
411 oxygen_rate(hw_params) |
412 chip->model.adc_i2s_format |
413 get_mclk(chip, PCM_B, hw_params) |
414 oxygen_i2s_bits(hw_params),
415 OXYGEN_I2S_RATE_MASK |
416 OXYGEN_I2S_FORMAT_MASK |
417 OXYGEN_I2S_MCLK_MASK |
418 OXYGEN_I2S_BITS_MASK);
419 spin_unlock_irq(&chip->reg_lock);
422 mutex_lock(&chip->mutex);
423 chip->model.set_adc_params(chip, hw_params);
424 mutex_unlock(&chip->mutex);
429 static int oxygen_rec_c_hw_params(struct snd_pcm_substream *substream,
430 struct snd_pcm_hw_params *hw_params)
432 struct oxygen *chip = snd_pcm_substream_chip(substream);
435 err = oxygen_hw_params(substream, hw_params);
439 spin_lock_irq(&chip->reg_lock);
440 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT,
441 oxygen_format(hw_params) << OXYGEN_REC_FORMAT_C_SHIFT,
442 OXYGEN_REC_FORMAT_C_MASK);
443 spin_unlock_irq(&chip->reg_lock);
447 static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream,
448 struct snd_pcm_hw_params *hw_params)
450 struct oxygen *chip = snd_pcm_substream_chip(substream);
453 err = oxygen_hw_params(substream, hw_params);
457 mutex_lock(&chip->mutex);
458 spin_lock_irq(&chip->reg_lock);
459 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
460 OXYGEN_SPDIF_OUT_ENABLE);
461 oxygen_write8_masked(chip, OXYGEN_PLAY_FORMAT,
462 oxygen_format(hw_params) << OXYGEN_SPDIF_FORMAT_SHIFT,
463 OXYGEN_SPDIF_FORMAT_MASK);
464 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL,
465 oxygen_rate(hw_params) << OXYGEN_SPDIF_OUT_RATE_SHIFT,
466 OXYGEN_SPDIF_OUT_RATE_MASK);
467 oxygen_update_spdif_source(chip);
468 spin_unlock_irq(&chip->reg_lock);
469 mutex_unlock(&chip->mutex);
473 static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
474 struct snd_pcm_hw_params *hw_params)
476 struct oxygen *chip = snd_pcm_substream_chip(substream);
479 err = oxygen_hw_params(substream, hw_params);
483 mutex_lock(&chip->mutex);
484 spin_lock_irq(&chip->reg_lock);
485 oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS,
486 oxygen_play_channels(hw_params),
487 OXYGEN_PLAY_CHANNELS_MASK);
488 oxygen_write8_masked(chip, OXYGEN_PLAY_FORMAT,
489 oxygen_format(hw_params) << OXYGEN_MULTICH_FORMAT_SHIFT,
490 OXYGEN_MULTICH_FORMAT_MASK);
491 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
492 oxygen_rate(hw_params) |
493 chip->model.dac_i2s_format |
494 get_mclk(chip, PCM_MULTICH, hw_params) |
495 oxygen_i2s_bits(hw_params),
496 OXYGEN_I2S_RATE_MASK |
497 OXYGEN_I2S_FORMAT_MASK |
498 OXYGEN_I2S_MCLK_MASK |
499 OXYGEN_I2S_BITS_MASK);
500 oxygen_update_spdif_source(chip);
501 spin_unlock_irq(&chip->reg_lock);
503 chip->model.set_dac_params(chip, hw_params);
504 oxygen_update_dac_routing(chip);
505 mutex_unlock(&chip->mutex);
509 static int oxygen_hw_free(struct snd_pcm_substream *substream)
511 struct oxygen *chip = snd_pcm_substream_chip(substream);
512 unsigned int channel = oxygen_substream_channel(substream);
513 unsigned int channel_mask = 1 << channel;
515 spin_lock_irq(&chip->reg_lock);
516 chip->interrupt_mask &= ~channel_mask;
517 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
519 oxygen_set_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask);
520 oxygen_clear_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask);
521 spin_unlock_irq(&chip->reg_lock);
523 return snd_pcm_lib_free_pages(substream);
526 static int oxygen_spdif_hw_free(struct snd_pcm_substream *substream)
528 struct oxygen *chip = snd_pcm_substream_chip(substream);
530 spin_lock_irq(&chip->reg_lock);
531 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
532 OXYGEN_SPDIF_OUT_ENABLE);
533 spin_unlock_irq(&chip->reg_lock);
534 return oxygen_hw_free(substream);
537 static int oxygen_prepare(struct snd_pcm_substream *substream)
539 struct oxygen *chip = snd_pcm_substream_chip(substream);
540 unsigned int channel = oxygen_substream_channel(substream);
541 unsigned int channel_mask = 1 << channel;
543 spin_lock_irq(&chip->reg_lock);
544 oxygen_set_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask);
545 oxygen_clear_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask);
547 if (substream->runtime->no_period_wakeup)
548 chip->interrupt_mask &= ~channel_mask;
550 chip->interrupt_mask |= channel_mask;
551 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
552 spin_unlock_irq(&chip->reg_lock);
556 static int oxygen_trigger(struct snd_pcm_substream *substream, int cmd)
558 struct oxygen *chip = snd_pcm_substream_chip(substream);
559 struct snd_pcm_substream *s;
560 unsigned int mask = 0;
564 case SNDRV_PCM_TRIGGER_STOP:
565 case SNDRV_PCM_TRIGGER_START:
566 case SNDRV_PCM_TRIGGER_SUSPEND:
569 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
570 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
577 snd_pcm_group_for_each_entry(s, substream) {
578 if (snd_pcm_substream_chip(s) == chip) {
579 mask |= 1 << oxygen_substream_channel(s);
580 snd_pcm_trigger_done(s, substream);
584 spin_lock(&chip->reg_lock);
586 if (cmd == SNDRV_PCM_TRIGGER_START)
587 chip->pcm_running |= mask;
589 chip->pcm_running &= ~mask;
590 oxygen_write8(chip, OXYGEN_DMA_STATUS, chip->pcm_running);
592 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
593 oxygen_set_bits8(chip, OXYGEN_DMA_PAUSE, mask);
595 oxygen_clear_bits8(chip, OXYGEN_DMA_PAUSE, mask);
597 spin_unlock(&chip->reg_lock);
601 static snd_pcm_uframes_t oxygen_pointer(struct snd_pcm_substream *substream)
603 struct oxygen *chip = snd_pcm_substream_chip(substream);
604 struct snd_pcm_runtime *runtime = substream->runtime;
605 unsigned int channel = oxygen_substream_channel(substream);
608 /* no spinlock, this read should be atomic */
609 curr_addr = oxygen_read32(chip, channel_base_registers[channel]);
610 return bytes_to_frames(runtime, curr_addr - (u32)runtime->dma_addr);
613 static struct snd_pcm_ops oxygen_rec_a_ops = {
614 .open = oxygen_rec_a_open,
615 .close = oxygen_close,
616 .ioctl = snd_pcm_lib_ioctl,
617 .hw_params = oxygen_rec_a_hw_params,
618 .hw_free = oxygen_hw_free,
619 .prepare = oxygen_prepare,
620 .trigger = oxygen_trigger,
621 .pointer = oxygen_pointer,
624 static struct snd_pcm_ops oxygen_rec_b_ops = {
625 .open = oxygen_rec_b_open,
626 .close = oxygen_close,
627 .ioctl = snd_pcm_lib_ioctl,
628 .hw_params = oxygen_rec_b_hw_params,
629 .hw_free = oxygen_hw_free,
630 .prepare = oxygen_prepare,
631 .trigger = oxygen_trigger,
632 .pointer = oxygen_pointer,
635 static struct snd_pcm_ops oxygen_rec_c_ops = {
636 .open = oxygen_rec_c_open,
637 .close = oxygen_close,
638 .ioctl = snd_pcm_lib_ioctl,
639 .hw_params = oxygen_rec_c_hw_params,
640 .hw_free = oxygen_hw_free,
641 .prepare = oxygen_prepare,
642 .trigger = oxygen_trigger,
643 .pointer = oxygen_pointer,
646 static struct snd_pcm_ops oxygen_spdif_ops = {
647 .open = oxygen_spdif_open,
648 .close = oxygen_close,
649 .ioctl = snd_pcm_lib_ioctl,
650 .hw_params = oxygen_spdif_hw_params,
651 .hw_free = oxygen_spdif_hw_free,
652 .prepare = oxygen_prepare,
653 .trigger = oxygen_trigger,
654 .pointer = oxygen_pointer,
657 static struct snd_pcm_ops oxygen_multich_ops = {
658 .open = oxygen_multich_open,
659 .close = oxygen_close,
660 .ioctl = snd_pcm_lib_ioctl,
661 .hw_params = oxygen_multich_hw_params,
662 .hw_free = oxygen_hw_free,
663 .prepare = oxygen_prepare,
664 .trigger = oxygen_trigger,
665 .pointer = oxygen_pointer,
668 static struct snd_pcm_ops oxygen_ac97_ops = {
669 .open = oxygen_ac97_open,
670 .close = oxygen_close,
671 .ioctl = snd_pcm_lib_ioctl,
672 .hw_params = oxygen_hw_params,
673 .hw_free = oxygen_hw_free,
674 .prepare = oxygen_prepare,
675 .trigger = oxygen_trigger,
676 .pointer = oxygen_pointer,
679 static void oxygen_pcm_free(struct snd_pcm *pcm)
681 snd_pcm_lib_preallocate_free_for_all(pcm);
684 int oxygen_pcm_init(struct oxygen *chip)
690 outs = !!(chip->model.device_config & PLAYBACK_0_TO_I2S);
691 ins = !!(chip->model.device_config & (CAPTURE_0_FROM_I2S_1 |
692 CAPTURE_0_FROM_I2S_2));
694 err = snd_pcm_new(chip->card, "Multichannel",
699 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
700 &oxygen_multich_ops);
701 if (chip->model.device_config & CAPTURE_0_FROM_I2S_1)
702 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
704 else if (chip->model.device_config & CAPTURE_0_FROM_I2S_2)
705 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
707 pcm->private_data = chip;
708 pcm->private_free = oxygen_pcm_free;
709 strcpy(pcm->name, "Multichannel");
711 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
713 snd_dma_pci_data(chip->pci),
714 DEFAULT_BUFFER_BYTES_MULTICH,
715 BUFFER_BYTES_MAX_MULTICH);
717 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
719 snd_dma_pci_data(chip->pci),
720 DEFAULT_BUFFER_BYTES,
724 outs = !!(chip->model.device_config & PLAYBACK_1_TO_SPDIF);
725 ins = !!(chip->model.device_config & CAPTURE_1_FROM_SPDIF);
727 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm);
731 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
734 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
736 pcm->private_data = chip;
737 pcm->private_free = oxygen_pcm_free;
738 strcpy(pcm->name, "Digital");
739 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
740 snd_dma_pci_data(chip->pci),
741 DEFAULT_BUFFER_BYTES,
745 if (chip->has_ac97_1) {
746 outs = !!(chip->model.device_config & PLAYBACK_2_TO_AC97_1);
747 ins = !!(chip->model.device_config & CAPTURE_2_FROM_AC97_1);
750 ins = !!(chip->model.device_config & CAPTURE_2_FROM_I2S_2);
753 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2",
758 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
760 oxygen_write8_masked(chip, OXYGEN_REC_ROUTING,
761 OXYGEN_REC_B_ROUTE_AC97_1,
762 OXYGEN_REC_B_ROUTE_MASK);
765 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
767 pcm->private_data = chip;
768 pcm->private_free = oxygen_pcm_free;
769 strcpy(pcm->name, outs ? "Front Panel" : "Analog 2");
770 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
771 snd_dma_pci_data(chip->pci),
772 DEFAULT_BUFFER_BYTES,