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 static struct snd_pcm_hardware oxygen_hardware
[PCM_COUNT
] = {
29 .info
= SNDRV_PCM_INFO_MMAP
|
30 SNDRV_PCM_INFO_MMAP_VALID
|
31 SNDRV_PCM_INFO_INTERLEAVED
|
32 SNDRV_PCM_INFO_PAUSE
|
33 SNDRV_PCM_INFO_SYNC_START
,
34 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
35 SNDRV_PCM_FMTBIT_S32_LE
,
36 .rates
= SNDRV_PCM_RATE_32000
|
37 SNDRV_PCM_RATE_44100
|
38 SNDRV_PCM_RATE_48000
|
39 SNDRV_PCM_RATE_64000
|
40 SNDRV_PCM_RATE_88200
|
41 SNDRV_PCM_RATE_96000
|
42 SNDRV_PCM_RATE_176400
|
43 SNDRV_PCM_RATE_192000
,
48 .buffer_bytes_max
= 256 * 1024,
49 .period_bytes_min
= 128,
50 .period_bytes_max
= 128 * 1024,
55 .info
= SNDRV_PCM_INFO_MMAP
|
56 SNDRV_PCM_INFO_MMAP_VALID
|
57 SNDRV_PCM_INFO_INTERLEAVED
|
58 SNDRV_PCM_INFO_PAUSE
|
59 SNDRV_PCM_INFO_SYNC_START
,
60 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
61 SNDRV_PCM_FMTBIT_S32_LE
,
62 .rates
= SNDRV_PCM_RATE_32000
|
63 SNDRV_PCM_RATE_44100
|
64 SNDRV_PCM_RATE_48000
|
65 SNDRV_PCM_RATE_64000
|
66 SNDRV_PCM_RATE_88200
|
67 SNDRV_PCM_RATE_96000
|
68 SNDRV_PCM_RATE_176400
|
69 SNDRV_PCM_RATE_192000
,
74 .buffer_bytes_max
= 256 * 1024,
75 .period_bytes_min
= 128,
76 .period_bytes_max
= 128 * 1024,
81 .info
= SNDRV_PCM_INFO_MMAP
|
82 SNDRV_PCM_INFO_MMAP_VALID
|
83 SNDRV_PCM_INFO_INTERLEAVED
|
84 SNDRV_PCM_INFO_PAUSE
|
85 SNDRV_PCM_INFO_SYNC_START
,
86 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
87 SNDRV_PCM_FMTBIT_S32_LE
,
88 .rates
= SNDRV_PCM_RATE_32000
|
89 SNDRV_PCM_RATE_44100
|
90 SNDRV_PCM_RATE_48000
|
91 SNDRV_PCM_RATE_64000
|
92 SNDRV_PCM_RATE_88200
|
93 SNDRV_PCM_RATE_96000
|
94 SNDRV_PCM_RATE_176400
|
95 SNDRV_PCM_RATE_192000
,
100 .buffer_bytes_max
= 256 * 1024,
101 .period_bytes_min
= 128,
102 .period_bytes_max
= 128 * 1024,
107 .info
= SNDRV_PCM_INFO_MMAP
|
108 SNDRV_PCM_INFO_MMAP_VALID
|
109 SNDRV_PCM_INFO_INTERLEAVED
|
110 SNDRV_PCM_INFO_PAUSE
|
111 SNDRV_PCM_INFO_SYNC_START
,
112 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
113 SNDRV_PCM_FMTBIT_S32_LE
,
114 .rates
= SNDRV_PCM_RATE_32000
|
115 SNDRV_PCM_RATE_44100
|
116 SNDRV_PCM_RATE_48000
|
117 SNDRV_PCM_RATE_64000
|
118 SNDRV_PCM_RATE_88200
|
119 SNDRV_PCM_RATE_96000
|
120 SNDRV_PCM_RATE_176400
|
121 SNDRV_PCM_RATE_192000
,
126 .buffer_bytes_max
= 256 * 1024,
127 .period_bytes_min
= 128,
128 .period_bytes_max
= 128 * 1024,
133 .info
= SNDRV_PCM_INFO_MMAP
|
134 SNDRV_PCM_INFO_MMAP_VALID
|
135 SNDRV_PCM_INFO_INTERLEAVED
|
136 SNDRV_PCM_INFO_PAUSE
|
137 SNDRV_PCM_INFO_SYNC_START
,
138 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
139 SNDRV_PCM_FMTBIT_S32_LE
,
140 .rates
= SNDRV_PCM_RATE_32000
|
141 SNDRV_PCM_RATE_44100
|
142 SNDRV_PCM_RATE_48000
|
143 SNDRV_PCM_RATE_64000
|
144 SNDRV_PCM_RATE_88200
|
145 SNDRV_PCM_RATE_96000
|
146 SNDRV_PCM_RATE_176400
|
147 SNDRV_PCM_RATE_192000
,
152 .buffer_bytes_max
= 2048 * 1024,
153 .period_bytes_min
= 128,
154 .period_bytes_max
= 256 * 1024,
156 .periods_max
= 16384,
159 .info
= SNDRV_PCM_INFO_MMAP
|
160 SNDRV_PCM_INFO_MMAP_VALID
|
161 SNDRV_PCM_INFO_INTERLEAVED
|
162 SNDRV_PCM_INFO_PAUSE
|
163 SNDRV_PCM_INFO_SYNC_START
,
164 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
165 .rates
= SNDRV_PCM_RATE_48000
,
170 .buffer_bytes_max
= 256 * 1024,
171 .period_bytes_min
= 128,
172 .period_bytes_max
= 128 * 1024,
178 static inline unsigned int
179 oxygen_substream_channel(struct snd_pcm_substream
*substream
)
181 return (unsigned int)(uintptr_t)substream
->runtime
->private_data
;
184 static int oxygen_open(struct snd_pcm_substream
*substream
,
185 unsigned int channel
)
187 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
188 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
191 runtime
->private_data
= (void *)(uintptr_t)channel
;
192 runtime
->hw
= oxygen_hardware
[channel
];
193 if (chip
->model
->pcm_hardware_filter
)
194 chip
->model
->pcm_hardware_filter(channel
, &runtime
->hw
);
195 err
= snd_pcm_hw_constraint_step(runtime
, 0,
196 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, 32);
199 err
= snd_pcm_hw_constraint_step(runtime
, 0,
200 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 32);
203 if (runtime
->hw
.formats
& SNDRV_PCM_FMTBIT_S32_LE
) {
204 err
= snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
208 if (runtime
->hw
.channels_max
> 2) {
209 err
= snd_pcm_hw_constraint_step(runtime
, 0,
210 SNDRV_PCM_HW_PARAM_CHANNELS
,
215 snd_pcm_set_sync(substream
);
216 chip
->streams
[channel
] = substream
;
218 mutex_lock(&chip
->mutex
);
219 chip
->pcm_active
|= 1 << channel
;
220 if (channel
== PCM_SPDIF
) {
221 chip
->spdif_pcm_bits
= chip
->spdif_bits
;
222 chip
->controls
[CONTROL_SPDIF_PCM
]->vd
[0].access
&=
223 ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
224 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
225 SNDRV_CTL_EVENT_MASK_INFO
,
226 &chip
->controls
[CONTROL_SPDIF_PCM
]->id
);
228 mutex_unlock(&chip
->mutex
);
233 static int oxygen_rec_a_open(struct snd_pcm_substream
*substream
)
235 return oxygen_open(substream
, PCM_A
);
238 static int oxygen_rec_b_open(struct snd_pcm_substream
*substream
)
240 return oxygen_open(substream
, PCM_B
);
243 static int oxygen_rec_c_open(struct snd_pcm_substream
*substream
)
245 return oxygen_open(substream
, PCM_C
);
248 static int oxygen_spdif_open(struct snd_pcm_substream
*substream
)
250 return oxygen_open(substream
, PCM_SPDIF
);
253 static int oxygen_multich_open(struct snd_pcm_substream
*substream
)
255 return oxygen_open(substream
, PCM_MULTICH
);
258 static int oxygen_ac97_open(struct snd_pcm_substream
*substream
)
260 return oxygen_open(substream
, PCM_AC97
);
263 static int oxygen_close(struct snd_pcm_substream
*substream
)
265 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
266 unsigned int channel
= oxygen_substream_channel(substream
);
268 mutex_lock(&chip
->mutex
);
269 chip
->pcm_active
&= ~(1 << channel
);
270 if (channel
== PCM_SPDIF
) {
271 chip
->controls
[CONTROL_SPDIF_PCM
]->vd
[0].access
|=
272 SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
273 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
274 SNDRV_CTL_EVENT_MASK_INFO
,
275 &chip
->controls
[CONTROL_SPDIF_PCM
]->id
);
277 if (channel
== PCM_SPDIF
|| channel
== PCM_MULTICH
)
278 oxygen_update_spdif_source(chip
);
279 mutex_unlock(&chip
->mutex
);
281 chip
->streams
[channel
] = NULL
;
285 static unsigned int oxygen_format(struct snd_pcm_hw_params
*hw_params
)
287 if (params_format(hw_params
) == SNDRV_PCM_FORMAT_S32_LE
)
288 return OXYGEN_FORMAT_24
;
290 return OXYGEN_FORMAT_16
;
293 static unsigned int oxygen_rate(struct snd_pcm_hw_params
*hw_params
)
295 switch (params_rate(hw_params
)) {
297 return OXYGEN_RATE_32000
;
299 return OXYGEN_RATE_44100
;
301 return OXYGEN_RATE_48000
;
303 return OXYGEN_RATE_64000
;
305 return OXYGEN_RATE_88200
;
307 return OXYGEN_RATE_96000
;
309 return OXYGEN_RATE_176400
;
311 return OXYGEN_RATE_192000
;
315 static unsigned int oxygen_i2s_mclk(struct snd_pcm_hw_params
*hw_params
)
317 return params_rate(hw_params
) <= 96000
318 ? OXYGEN_I2S_MCLK_256
: OXYGEN_I2S_MCLK_128
;
321 static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params
*hw_params
)
323 if (params_format(hw_params
) == SNDRV_PCM_FORMAT_S32_LE
)
324 return OXYGEN_I2S_BITS_24
;
326 return OXYGEN_I2S_BITS_16
;
329 static unsigned int oxygen_play_channels(struct snd_pcm_hw_params
*hw_params
)
331 switch (params_channels(hw_params
)) {
333 return OXYGEN_PLAY_CHANNELS_2
;
335 return OXYGEN_PLAY_CHANNELS_4
;
337 return OXYGEN_PLAY_CHANNELS_6
;
339 return OXYGEN_PLAY_CHANNELS_8
;
343 static const unsigned int channel_base_registers
[PCM_COUNT
] = {
344 [PCM_A
] = OXYGEN_DMA_A_ADDRESS
,
345 [PCM_B
] = OXYGEN_DMA_B_ADDRESS
,
346 [PCM_C
] = OXYGEN_DMA_C_ADDRESS
,
347 [PCM_SPDIF
] = OXYGEN_DMA_SPDIF_ADDRESS
,
348 [PCM_MULTICH
] = OXYGEN_DMA_MULTICH_ADDRESS
,
349 [PCM_AC97
] = OXYGEN_DMA_AC97_ADDRESS
,
352 static int oxygen_hw_params(struct snd_pcm_substream
*substream
,
353 struct snd_pcm_hw_params
*hw_params
)
355 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
356 unsigned int channel
= oxygen_substream_channel(substream
);
359 err
= snd_pcm_lib_malloc_pages(substream
,
360 params_buffer_bytes(hw_params
));
364 oxygen_write32(chip
, channel_base_registers
[channel
],
365 (u32
)substream
->runtime
->dma_addr
);
366 if (channel
== PCM_MULTICH
) {
367 oxygen_write32(chip
, OXYGEN_DMA_MULTICH_COUNT
,
368 params_buffer_bytes(hw_params
) / 4 - 1);
369 oxygen_write32(chip
, OXYGEN_DMA_MULTICH_TCOUNT
,
370 params_period_bytes(hw_params
) / 4 - 1);
372 oxygen_write16(chip
, channel_base_registers
[channel
] + 4,
373 params_buffer_bytes(hw_params
) / 4 - 1);
374 oxygen_write16(chip
, channel_base_registers
[channel
] + 6,
375 params_period_bytes(hw_params
) / 4 - 1);
380 static int oxygen_rec_a_hw_params(struct snd_pcm_substream
*substream
,
381 struct snd_pcm_hw_params
*hw_params
)
383 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
386 err
= oxygen_hw_params(substream
, hw_params
);
390 spin_lock_irq(&chip
->reg_lock
);
391 oxygen_write8_masked(chip
, OXYGEN_REC_FORMAT
,
392 oxygen_format(hw_params
) << OXYGEN_REC_FORMAT_A_SHIFT
,
393 OXYGEN_REC_FORMAT_A_MASK
);
394 oxygen_write16_masked(chip
, OXYGEN_I2S_A_FORMAT
,
395 oxygen_rate(hw_params
) |
396 oxygen_i2s_mclk(hw_params
) |
397 chip
->model
->adc_i2s_format
|
398 oxygen_i2s_bits(hw_params
),
399 OXYGEN_I2S_RATE_MASK
|
400 OXYGEN_I2S_FORMAT_MASK
|
401 OXYGEN_I2S_MCLK_MASK
|
402 OXYGEN_I2S_BITS_MASK
);
403 oxygen_write8_masked(chip
, OXYGEN_REC_ROUTING
,
404 OXYGEN_REC_A_ROUTE_I2S_ADC_1
,
405 OXYGEN_REC_A_ROUTE_MASK
);
406 spin_unlock_irq(&chip
->reg_lock
);
408 mutex_lock(&chip
->mutex
);
409 chip
->model
->set_adc_params(chip
, hw_params
);
410 mutex_unlock(&chip
->mutex
);
414 static int oxygen_rec_b_hw_params(struct snd_pcm_substream
*substream
,
415 struct snd_pcm_hw_params
*hw_params
)
417 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
420 err
= oxygen_hw_params(substream
, hw_params
);
424 spin_lock_irq(&chip
->reg_lock
);
425 oxygen_write8_masked(chip
, OXYGEN_REC_FORMAT
,
426 oxygen_format(hw_params
) << OXYGEN_REC_FORMAT_B_SHIFT
,
427 OXYGEN_REC_FORMAT_B_MASK
);
428 oxygen_write16_masked(chip
, OXYGEN_I2S_B_FORMAT
,
429 oxygen_rate(hw_params
) |
430 oxygen_i2s_mclk(hw_params
) |
431 chip
->model
->adc_i2s_format
|
432 oxygen_i2s_bits(hw_params
),
433 OXYGEN_I2S_RATE_MASK
|
434 OXYGEN_I2S_FORMAT_MASK
|
435 OXYGEN_I2S_MCLK_MASK
|
436 OXYGEN_I2S_BITS_MASK
);
437 oxygen_write8_masked(chip
, OXYGEN_REC_ROUTING
,
438 OXYGEN_REC_B_ROUTE_I2S_ADC_2
,
439 OXYGEN_REC_B_ROUTE_MASK
);
440 spin_unlock_irq(&chip
->reg_lock
);
442 mutex_lock(&chip
->mutex
);
443 chip
->model
->set_adc_params(chip
, hw_params
);
444 mutex_unlock(&chip
->mutex
);
448 static int oxygen_rec_c_hw_params(struct snd_pcm_substream
*substream
,
449 struct snd_pcm_hw_params
*hw_params
)
451 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
454 err
= oxygen_hw_params(substream
, hw_params
);
458 spin_lock_irq(&chip
->reg_lock
);
459 oxygen_write8_masked(chip
, OXYGEN_REC_FORMAT
,
460 oxygen_format(hw_params
) << OXYGEN_REC_FORMAT_C_SHIFT
,
461 OXYGEN_REC_FORMAT_C_MASK
);
462 oxygen_write8_masked(chip
, OXYGEN_REC_ROUTING
,
463 OXYGEN_REC_C_ROUTE_SPDIF
,
464 OXYGEN_REC_C_ROUTE_MASK
);
465 spin_unlock_irq(&chip
->reg_lock
);
469 static int oxygen_spdif_hw_params(struct snd_pcm_substream
*substream
,
470 struct snd_pcm_hw_params
*hw_params
)
472 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
475 err
= oxygen_hw_params(substream
, hw_params
);
479 spin_lock_irq(&chip
->reg_lock
);
480 oxygen_clear_bits32(chip
, OXYGEN_SPDIF_CONTROL
,
481 OXYGEN_SPDIF_OUT_ENABLE
);
482 oxygen_write8_masked(chip
, OXYGEN_PLAY_FORMAT
,
483 oxygen_format(hw_params
) << OXYGEN_SPDIF_FORMAT_SHIFT
,
484 OXYGEN_SPDIF_FORMAT_MASK
);
485 oxygen_write32_masked(chip
, OXYGEN_SPDIF_CONTROL
,
486 oxygen_rate(hw_params
) << OXYGEN_SPDIF_OUT_RATE_SHIFT
,
487 OXYGEN_SPDIF_OUT_RATE_MASK
);
488 oxygen_update_spdif_source(chip
);
489 spin_unlock_irq(&chip
->reg_lock
);
493 static int oxygen_multich_hw_params(struct snd_pcm_substream
*substream
,
494 struct snd_pcm_hw_params
*hw_params
)
496 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
499 err
= oxygen_hw_params(substream
, hw_params
);
503 spin_lock_irq(&chip
->reg_lock
);
504 oxygen_write8_masked(chip
, OXYGEN_PLAY_CHANNELS
,
505 oxygen_play_channels(hw_params
),
506 OXYGEN_PLAY_CHANNELS_MASK
);
507 oxygen_write8_masked(chip
, OXYGEN_PLAY_FORMAT
,
508 oxygen_format(hw_params
) << OXYGEN_MULTICH_FORMAT_SHIFT
,
509 OXYGEN_MULTICH_FORMAT_MASK
);
510 oxygen_write16_masked(chip
, OXYGEN_I2S_MULTICH_FORMAT
,
511 oxygen_rate(hw_params
) |
512 chip
->model
->dac_i2s_format
|
513 oxygen_i2s_bits(hw_params
),
514 OXYGEN_I2S_RATE_MASK
|
515 OXYGEN_I2S_FORMAT_MASK
|
516 OXYGEN_I2S_BITS_MASK
);
517 oxygen_write16_masked(chip
, OXYGEN_PLAY_ROUTING
,
518 OXYGEN_PLAY_MULTICH_I2S_DAC
,
519 OXYGEN_PLAY_MUTE01
| OXYGEN_PLAY_MUTE23
|
520 OXYGEN_PLAY_MUTE45
| OXYGEN_PLAY_MUTE67
|
521 OXYGEN_PLAY_MULTICH_MASK
);
522 oxygen_update_dac_routing(chip
);
523 oxygen_update_spdif_source(chip
);
524 spin_unlock_irq(&chip
->reg_lock
);
526 mutex_lock(&chip
->mutex
);
527 chip
->model
->set_dac_params(chip
, hw_params
);
528 mutex_unlock(&chip
->mutex
);
532 static int oxygen_hw_free(struct snd_pcm_substream
*substream
)
534 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
535 unsigned int channel
= oxygen_substream_channel(substream
);
537 spin_lock_irq(&chip
->reg_lock
);
538 chip
->interrupt_mask
&= ~(1 << channel
);
539 oxygen_write16(chip
, OXYGEN_INTERRUPT_MASK
, chip
->interrupt_mask
);
540 spin_unlock_irq(&chip
->reg_lock
);
542 return snd_pcm_lib_free_pages(substream
);
545 static int oxygen_spdif_hw_free(struct snd_pcm_substream
*substream
)
547 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
549 spin_lock_irq(&chip
->reg_lock
);
550 oxygen_clear_bits32(chip
, OXYGEN_SPDIF_CONTROL
,
551 OXYGEN_SPDIF_OUT_ENABLE
);
552 spin_unlock_irq(&chip
->reg_lock
);
553 return oxygen_hw_free(substream
);
556 static int oxygen_prepare(struct snd_pcm_substream
*substream
)
558 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
559 unsigned int channel
= oxygen_substream_channel(substream
);
560 unsigned int channel_mask
= 1 << channel
;
562 spin_lock_irq(&chip
->reg_lock
);
563 oxygen_set_bits8(chip
, OXYGEN_DMA_FLUSH
, channel_mask
);
564 oxygen_clear_bits8(chip
, OXYGEN_DMA_FLUSH
, channel_mask
);
566 chip
->interrupt_mask
|= channel_mask
;
567 oxygen_write16(chip
, OXYGEN_INTERRUPT_MASK
, chip
->interrupt_mask
);
568 spin_unlock_irq(&chip
->reg_lock
);
572 static int oxygen_trigger(struct snd_pcm_substream
*substream
, int cmd
)
574 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
575 struct snd_pcm_substream
*s
;
576 unsigned int mask
= 0;
580 case SNDRV_PCM_TRIGGER_STOP
:
581 case SNDRV_PCM_TRIGGER_START
:
584 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
585 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
592 snd_pcm_group_for_each_entry(s
, substream
) {
593 if (snd_pcm_substream_chip(s
) == chip
) {
594 mask
|= 1 << oxygen_substream_channel(s
);
595 snd_pcm_trigger_done(s
, substream
);
599 spin_lock(&chip
->reg_lock
);
601 if (cmd
== SNDRV_PCM_TRIGGER_START
)
602 chip
->pcm_running
|= mask
;
604 chip
->pcm_running
&= ~mask
;
605 oxygen_write8(chip
, OXYGEN_DMA_STATUS
, chip
->pcm_running
);
607 if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_PUSH
)
608 oxygen_set_bits8(chip
, OXYGEN_DMA_PAUSE
, mask
);
610 oxygen_clear_bits8(chip
, OXYGEN_DMA_PAUSE
, mask
);
612 spin_unlock(&chip
->reg_lock
);
616 static snd_pcm_uframes_t
oxygen_pointer(struct snd_pcm_substream
*substream
)
618 struct oxygen
*chip
= snd_pcm_substream_chip(substream
);
619 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
620 unsigned int channel
= oxygen_substream_channel(substream
);
623 /* no spinlock, this read should be atomic */
624 curr_addr
= oxygen_read32(chip
, channel_base_registers
[channel
]);
625 return bytes_to_frames(runtime
, curr_addr
- (u32
)runtime
->dma_addr
);
628 static struct snd_pcm_ops oxygen_rec_a_ops
= {
629 .open
= oxygen_rec_a_open
,
630 .close
= oxygen_close
,
631 .ioctl
= snd_pcm_lib_ioctl
,
632 .hw_params
= oxygen_rec_a_hw_params
,
633 .hw_free
= oxygen_hw_free
,
634 .prepare
= oxygen_prepare
,
635 .trigger
= oxygen_trigger
,
636 .pointer
= oxygen_pointer
,
639 static struct snd_pcm_ops oxygen_rec_b_ops
= {
640 .open
= oxygen_rec_b_open
,
641 .close
= oxygen_close
,
642 .ioctl
= snd_pcm_lib_ioctl
,
643 .hw_params
= oxygen_rec_b_hw_params
,
644 .hw_free
= oxygen_hw_free
,
645 .prepare
= oxygen_prepare
,
646 .trigger
= oxygen_trigger
,
647 .pointer
= oxygen_pointer
,
650 static struct snd_pcm_ops oxygen_rec_c_ops
= {
651 .open
= oxygen_rec_c_open
,
652 .close
= oxygen_close
,
653 .ioctl
= snd_pcm_lib_ioctl
,
654 .hw_params
= oxygen_rec_c_hw_params
,
655 .hw_free
= oxygen_hw_free
,
656 .prepare
= oxygen_prepare
,
657 .trigger
= oxygen_trigger
,
658 .pointer
= oxygen_pointer
,
661 static struct snd_pcm_ops oxygen_spdif_ops
= {
662 .open
= oxygen_spdif_open
,
663 .close
= oxygen_close
,
664 .ioctl
= snd_pcm_lib_ioctl
,
665 .hw_params
= oxygen_spdif_hw_params
,
666 .hw_free
= oxygen_spdif_hw_free
,
667 .prepare
= oxygen_prepare
,
668 .trigger
= oxygen_trigger
,
669 .pointer
= oxygen_pointer
,
672 static struct snd_pcm_ops oxygen_multich_ops
= {
673 .open
= oxygen_multich_open
,
674 .close
= oxygen_close
,
675 .ioctl
= snd_pcm_lib_ioctl
,
676 .hw_params
= oxygen_multich_hw_params
,
677 .hw_free
= oxygen_hw_free
,
678 .prepare
= oxygen_prepare
,
679 .trigger
= oxygen_trigger
,
680 .pointer
= oxygen_pointer
,
683 static struct snd_pcm_ops oxygen_ac97_ops
= {
684 .open
= oxygen_ac97_open
,
685 .close
= oxygen_close
,
686 .ioctl
= snd_pcm_lib_ioctl
,
687 .hw_params
= oxygen_hw_params
,
688 .hw_free
= oxygen_hw_free
,
689 .prepare
= oxygen_prepare
,
690 .trigger
= oxygen_trigger
,
691 .pointer
= oxygen_pointer
,
694 static void oxygen_pcm_free(struct snd_pcm
*pcm
)
696 snd_pcm_lib_preallocate_free_for_all(pcm
);
699 int __devinit
oxygen_pcm_init(struct oxygen
*chip
)
705 outs
= 1; /* OXYGEN_CHANNEL_MULTICH is always used */
706 ins
= !!(chip
->model
->used_channels
& (OXYGEN_CHANNEL_A
|
708 err
= snd_pcm_new(chip
->card
, "Analog", 0, outs
, ins
, &pcm
);
711 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &oxygen_multich_ops
);
712 if (chip
->model
->used_channels
& OXYGEN_CHANNEL_A
)
713 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
715 else if (chip
->model
->used_channels
& OXYGEN_CHANNEL_B
)
716 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
718 pcm
->private_data
= chip
;
719 pcm
->private_free
= oxygen_pcm_free
;
720 strcpy(pcm
->name
, "Analog");
721 snd_pcm_lib_preallocate_pages(pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
,
723 snd_dma_pci_data(chip
->pci
),
724 512 * 1024, 2048 * 1024);
726 snd_pcm_lib_preallocate_pages(pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
,
728 snd_dma_pci_data(chip
->pci
),
729 128 * 1024, 256 * 1024);
731 outs
= !!(chip
->model
->used_channels
& OXYGEN_CHANNEL_SPDIF
);
732 ins
= !!(chip
->model
->used_channels
& OXYGEN_CHANNEL_C
);
734 err
= snd_pcm_new(chip
->card
, "Digital", 1, outs
, ins
, &pcm
);
738 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
741 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
743 pcm
->private_data
= chip
;
744 pcm
->private_free
= oxygen_pcm_free
;
745 strcpy(pcm
->name
, "Digital");
746 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
747 snd_dma_pci_data(chip
->pci
),
748 128 * 1024, 256 * 1024);
751 outs
= chip
->has_ac97_1
&&
752 (chip
->model
->used_channels
& OXYGEN_CHANNEL_AC97
);
753 ins
= (chip
->model
->used_channels
& (OXYGEN_CHANNEL_A
|
755 == (OXYGEN_CHANNEL_A
| OXYGEN_CHANNEL_B
);
757 err
= snd_pcm_new(chip
->card
, ins
? "Analog2" : "AC97",
762 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
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
, ins
? "Analog 2" : "Front Panel");
770 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
771 snd_dma_pci_data(chip
->pci
),
772 128 * 1024, 256 * 1024);