2 * Digital Audio (PCM) abstract layer
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * Abramo Bagnara <abramo@alsa-project.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <sound/driver.h>
24 #include <linux/slab.h>
25 #include <linux/time.h>
26 #include <sound/core.h>
27 #include <sound/control.h>
28 #include <sound/info.h>
29 #include <sound/pcm.h>
30 #include <sound/pcm_params.h>
31 #include <sound/timer.h>
34 * fill ring buffer with silence
35 * runtime->silence_start: starting pointer to silence area
36 * runtime->silence_filled: size filled with silence
37 * runtime->silence_threshold: threshold from application
38 * runtime->silence_size: maximal size from application
40 * when runtime->silence_size >= runtime->boundary - fill processed area with silence immediately
42 void snd_pcm_playback_silence(snd_pcm_substream_t *substream, snd_pcm_uframes_t new_hw_ptr)
44 snd_pcm_runtime_t *runtime = substream->runtime;
45 snd_pcm_uframes_t frames, ofs, transfer;
47 if (runtime->silence_size < runtime->boundary) {
48 snd_pcm_sframes_t noise_dist, n;
49 if (runtime->silence_start != runtime->control->appl_ptr) {
50 n = runtime->control->appl_ptr - runtime->silence_start;
52 n += runtime->boundary;
53 if ((snd_pcm_uframes_t)n < runtime->silence_filled)
54 runtime->silence_filled -= n;
56 runtime->silence_filled = 0;
57 runtime->silence_start = runtime->control->appl_ptr;
59 if (runtime->silence_filled == runtime->buffer_size)
61 snd_assert(runtime->silence_filled <= runtime->buffer_size, return);
62 noise_dist = snd_pcm_playback_hw_avail(runtime) + runtime->silence_filled;
63 if (noise_dist >= (snd_pcm_sframes_t) runtime->silence_threshold)
65 frames = runtime->silence_threshold - noise_dist;
66 if (frames > runtime->silence_size)
67 frames = runtime->silence_size;
69 if (new_hw_ptr == ULONG_MAX) { /* initialization */
70 snd_pcm_sframes_t avail = snd_pcm_playback_hw_avail(runtime);
71 runtime->silence_filled = avail > 0 ? avail : 0;
72 runtime->silence_start = (runtime->status->hw_ptr +
73 runtime->silence_filled) %
76 ofs = runtime->status->hw_ptr;
77 frames = new_hw_ptr - ofs;
78 if ((snd_pcm_sframes_t)frames < 0)
79 frames += runtime->boundary;
80 runtime->silence_filled -= frames;
81 if ((snd_pcm_sframes_t)runtime->silence_filled < 0) {
82 runtime->silence_filled = 0;
83 runtime->silence_start = (ofs + frames) - runtime->buffer_size;
85 runtime->silence_start = ofs - runtime->silence_filled;
87 if ((snd_pcm_sframes_t)runtime->silence_start < 0)
88 runtime->silence_start += runtime->boundary;
90 frames = runtime->buffer_size - runtime->silence_filled;
92 snd_assert(frames <= runtime->buffer_size, return);
95 ofs = (runtime->silence_start + runtime->silence_filled) % runtime->buffer_size;
97 transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames;
98 if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ||
99 runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED) {
100 if (substream->ops->silence) {
102 err = substream->ops->silence(substream, -1, ofs, transfer);
103 snd_assert(err >= 0, );
105 char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, ofs);
106 snd_pcm_format_set_silence(runtime->format, hwbuf, transfer * runtime->channels);
110 unsigned int channels = runtime->channels;
111 if (substream->ops->silence) {
112 for (c = 0; c < channels; ++c) {
114 err = substream->ops->silence(substream, c, ofs, transfer);
115 snd_assert(err >= 0, );
118 size_t dma_csize = runtime->dma_bytes / channels;
119 for (c = 0; c < channels; ++c) {
120 char *hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, ofs);
121 snd_pcm_format_set_silence(runtime->format, hwbuf, transfer);
125 runtime->silence_filled += transfer;
131 static void xrun(snd_pcm_substream_t *substream)
133 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
134 #ifdef CONFIG_SND_DEBUG
135 if (substream->pstr->xrun_debug) {
136 snd_printd(KERN_DEBUG "XRUN: pcmC%dD%d%c\n",
137 substream->pcm->card->number,
138 substream->pcm->device,
139 substream->stream ? 'c' : 'p');
140 if (substream->pstr->xrun_debug > 1)
146 static inline snd_pcm_uframes_t snd_pcm_update_hw_ptr_pos(snd_pcm_substream_t *substream,
147 snd_pcm_runtime_t *runtime)
149 snd_pcm_uframes_t pos;
151 pos = substream->ops->pointer(substream);
152 if (pos == SNDRV_PCM_POS_XRUN)
153 return pos; /* XRUN */
154 if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP)
155 snd_timestamp_now((snd_timestamp_t*)&runtime->status->tstamp, runtime->tstamp_timespec);
156 #ifdef CONFIG_SND_DEBUG
157 if (pos >= runtime->buffer_size) {
158 snd_printk(KERN_ERR "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size);
161 snd_runtime_check(pos < runtime->buffer_size, return 0);
162 pos -= pos % runtime->min_align;
166 static inline int snd_pcm_update_hw_ptr_post(snd_pcm_substream_t *substream,
167 snd_pcm_runtime_t *runtime)
169 snd_pcm_uframes_t avail;
171 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
172 avail = snd_pcm_playback_avail(runtime);
174 avail = snd_pcm_capture_avail(runtime);
175 if (avail > runtime->avail_max)
176 runtime->avail_max = avail;
177 if (avail >= runtime->stop_threshold) {
178 if (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING)
179 snd_pcm_drain_done(substream);
184 if (avail >= runtime->control->avail_min)
185 wake_up(&runtime->sleep);
189 static inline int snd_pcm_update_hw_ptr_interrupt(snd_pcm_substream_t *substream)
191 snd_pcm_runtime_t *runtime = substream->runtime;
192 snd_pcm_uframes_t pos;
193 snd_pcm_uframes_t new_hw_ptr, hw_ptr_interrupt;
194 snd_pcm_sframes_t delta;
196 pos = snd_pcm_update_hw_ptr_pos(substream, runtime);
197 if (pos == SNDRV_PCM_POS_XRUN) {
201 if (runtime->period_size == runtime->buffer_size)
203 new_hw_ptr = runtime->hw_ptr_base + pos;
204 hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size;
206 delta = hw_ptr_interrupt - new_hw_ptr;
208 if ((snd_pcm_uframes_t)delta < runtime->buffer_size / 2) {
209 #ifdef CONFIG_SND_DEBUG
210 if (runtime->periods > 1 && substream->pstr->xrun_debug) {
211 snd_printd(KERN_ERR "Unexpected hw_pointer value [1] (stream = %i, delta: -%ld, max jitter = %ld): wrong interrupt acknowledge?\n", substream->stream, (long) delta, runtime->buffer_size / 2);
212 if (substream->pstr->xrun_debug > 1)
219 runtime->hw_ptr_base += runtime->buffer_size;
220 if (runtime->hw_ptr_base == runtime->boundary)
221 runtime->hw_ptr_base = 0;
222 new_hw_ptr = runtime->hw_ptr_base + pos;
225 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
226 runtime->silence_size > 0)
227 snd_pcm_playback_silence(substream, new_hw_ptr);
229 runtime->status->hw_ptr = new_hw_ptr;
230 runtime->hw_ptr_interrupt = new_hw_ptr - new_hw_ptr % runtime->period_size;
232 return snd_pcm_update_hw_ptr_post(substream, runtime);
235 /* CAUTION: call it with irq disabled */
236 int snd_pcm_update_hw_ptr(snd_pcm_substream_t *substream)
238 snd_pcm_runtime_t *runtime = substream->runtime;
239 snd_pcm_uframes_t pos;
240 snd_pcm_uframes_t old_hw_ptr, new_hw_ptr;
241 snd_pcm_sframes_t delta;
243 old_hw_ptr = runtime->status->hw_ptr;
244 pos = snd_pcm_update_hw_ptr_pos(substream, runtime);
245 if (pos == SNDRV_PCM_POS_XRUN) {
249 new_hw_ptr = runtime->hw_ptr_base + pos;
251 delta = old_hw_ptr - new_hw_ptr;
253 if ((snd_pcm_uframes_t)delta < runtime->buffer_size / 2) {
254 #ifdef CONFIG_SND_DEBUG
255 if (runtime->periods > 2 && substream->pstr->xrun_debug) {
256 snd_printd(KERN_ERR "Unexpected hw_pointer value [2] (stream = %i, delta: -%ld, max jitter = %ld): wrong interrupt acknowledge?\n", substream->stream, (long) delta, runtime->buffer_size / 2);
257 if (substream->pstr->xrun_debug > 1)
263 runtime->hw_ptr_base += runtime->buffer_size;
264 if (runtime->hw_ptr_base == runtime->boundary)
265 runtime->hw_ptr_base = 0;
266 new_hw_ptr = runtime->hw_ptr_base + pos;
268 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
269 runtime->silence_size > 0)
270 snd_pcm_playback_silence(substream, new_hw_ptr);
272 runtime->status->hw_ptr = new_hw_ptr;
274 return snd_pcm_update_hw_ptr_post(substream, runtime);
278 * snd_pcm_set_ops - set the PCM operators
279 * @pcm: the pcm instance
280 * @direction: stream direction, SNDRV_PCM_STREAM_XXX
281 * @ops: the operator table
283 * Sets the given PCM operators to the pcm instance.
285 void snd_pcm_set_ops(snd_pcm_t *pcm, int direction, snd_pcm_ops_t *ops)
287 snd_pcm_str_t *stream = &pcm->streams[direction];
288 snd_pcm_substream_t *substream;
290 for (substream = stream->substream; substream != NULL; substream = substream->next)
291 substream->ops = ops;
296 * snd_pcm_sync - set the PCM sync id
297 * @substream: the pcm substream
299 * Sets the PCM sync identifier for the card.
301 void snd_pcm_set_sync(snd_pcm_substream_t * substream)
303 snd_pcm_runtime_t *runtime = substream->runtime;
305 runtime->sync.id32[0] = substream->pcm->card->number;
306 runtime->sync.id32[1] = -1;
307 runtime->sync.id32[2] = -1;
308 runtime->sync.id32[3] = -1;
312 * Standard ioctl routine
315 /* Code taken from alsa-lib */
316 #define assert(a) snd_assert((a), return -EINVAL)
318 static inline unsigned int div32(unsigned int a, unsigned int b,
329 static inline unsigned int div_down(unsigned int a, unsigned int b)
336 static inline unsigned int div_up(unsigned int a, unsigned int b)
348 static inline unsigned int mul(unsigned int a, unsigned int b)
352 if (div_down(UINT_MAX, a) < b)
357 static inline unsigned int muldiv32(unsigned int a, unsigned int b,
358 unsigned int c, unsigned int *r)
360 u_int64_t n = (u_int64_t) a * b;
374 int snd_interval_refine_min(snd_interval_t *i, unsigned int min, int openmin)
377 assert(!snd_interval_empty(i));
380 i->openmin = openmin;
382 } else if (i->min == min && !i->openmin && openmin) {
392 if (snd_interval_checkempty(i)) {
393 snd_interval_none(i);
399 int snd_interval_refine_max(snd_interval_t *i, unsigned int max, int openmax)
402 assert(!snd_interval_empty(i));
405 i->openmax = openmax;
407 } else if (i->max == max && !i->openmax && openmax) {
417 if (snd_interval_checkempty(i)) {
418 snd_interval_none(i);
425 * snd_interval_refine - refine the interval value of configurator
426 * @i: the interval value to refine
427 * @v: the interval value to refer to
429 * Refines the interval value with the reference value.
430 * The interval is changed to the range satisfying both intervals.
431 * The interval status (min, max, integer, etc.) are evaluated.
433 * Returns non-zero if the value is changed, zero if not changed.
435 int snd_interval_refine(snd_interval_t *i, const snd_interval_t *v)
438 assert(!snd_interval_empty(i));
439 if (i->min < v->min) {
441 i->openmin = v->openmin;
443 } else if (i->min == v->min && !i->openmin && v->openmin) {
447 if (i->max > v->max) {
449 i->openmax = v->openmax;
451 } else if (i->max == v->max && !i->openmax && v->openmax) {
455 if (!i->integer && v->integer) {
468 } else if (!i->openmin && !i->openmax && i->min == i->max)
470 if (snd_interval_checkempty(i)) {
471 snd_interval_none(i);
477 int snd_interval_refine_first(snd_interval_t *i)
479 assert(!snd_interval_empty(i));
480 if (snd_interval_single(i))
483 i->openmax = i->openmin;
489 int snd_interval_refine_last(snd_interval_t *i)
491 assert(!snd_interval_empty(i));
492 if (snd_interval_single(i))
495 i->openmin = i->openmax;
501 int snd_interval_refine_set(snd_interval_t *i, unsigned int val)
506 t.openmin = t.openmax = 0;
508 return snd_interval_refine(i, &t);
511 void snd_interval_mul(const snd_interval_t *a, const snd_interval_t *b, snd_interval_t *c)
513 if (a->empty || b->empty) {
514 snd_interval_none(c);
518 c->min = mul(a->min, b->min);
519 c->openmin = (a->openmin || b->openmin);
520 c->max = mul(a->max, b->max);
521 c->openmax = (a->openmax || b->openmax);
522 c->integer = (a->integer && b->integer);
526 * snd_interval_div - refine the interval value with division
530 * Returns non-zero if the value is changed, zero if not changed.
532 void snd_interval_div(const snd_interval_t *a, const snd_interval_t *b, snd_interval_t *c)
535 if (a->empty || b->empty) {
536 snd_interval_none(c);
540 c->min = div32(a->min, b->max, &r);
541 c->openmin = (r || a->openmin || b->openmax);
543 c->max = div32(a->max, b->min, &r);
548 c->openmax = (a->openmax || b->openmin);
557 * snd_interval_muldivk - refine the interval value
561 * Returns non-zero if the value is changed, zero if not changed.
563 void snd_interval_muldivk(const snd_interval_t *a, const snd_interval_t *b,
564 unsigned int k, snd_interval_t *c)
567 if (a->empty || b->empty) {
568 snd_interval_none(c);
572 c->min = muldiv32(a->min, b->min, k, &r);
573 c->openmin = (r || a->openmin || b->openmin);
574 c->max = muldiv32(a->max, b->max, k, &r);
579 c->openmax = (a->openmax || b->openmax);
584 * snd_interval_mulkdiv - refine the interval value
588 * Returns non-zero if the value is changed, zero if not changed.
590 void snd_interval_mulkdiv(const snd_interval_t *a, unsigned int k,
591 const snd_interval_t *b, snd_interval_t *c)
594 if (a->empty || b->empty) {
595 snd_interval_none(c);
599 c->min = muldiv32(a->min, k, b->max, &r);
600 c->openmin = (r || a->openmin || b->openmax);
602 c->max = muldiv32(a->max, k, b->min, &r);
607 c->openmax = (a->openmax || b->openmin);
620 * snd_interval_ratnum - refine the interval value
622 * Returns non-zero if the value is changed, zero if not changed.
624 int snd_interval_ratnum(snd_interval_t *i,
625 unsigned int rats_count, ratnum_t *rats,
626 unsigned int *nump, unsigned int *denp)
628 unsigned int best_num, best_diff, best_den;
633 best_num = best_den = best_diff = 0;
634 for (k = 0; k < rats_count; ++k) {
635 unsigned int num = rats[k].num;
637 unsigned int q = i->min;
641 den = div_down(num, q);
642 if (den < rats[k].den_min)
644 if (den > rats[k].den_max)
645 den = rats[k].den_max;
648 r = (den - rats[k].den_min) % rats[k].den_step;
652 diff = num - q * den;
654 diff * best_den < best_diff * den) {
664 t.min = div_down(best_num, best_den);
665 t.openmin = !!(best_num % best_den);
667 best_num = best_den = best_diff = 0;
668 for (k = 0; k < rats_count; ++k) {
669 unsigned int num = rats[k].num;
671 unsigned int q = i->max;
677 den = div_up(num, q);
678 if (den > rats[k].den_max)
680 if (den < rats[k].den_min)
681 den = rats[k].den_min;
684 r = (den - rats[k].den_min) % rats[k].den_step;
686 den += rats[k].den_step - r;
688 diff = q * den - num;
690 diff * best_den < best_diff * den) {
700 t.max = div_up(best_num, best_den);
701 t.openmax = !!(best_num % best_den);
703 err = snd_interval_refine(i, &t);
707 if (snd_interval_single(i)) {
717 * snd_interval_ratden - refine the interval value
719 * Returns non-zero if the value is changed, zero if not changed.
721 int snd_interval_ratden(snd_interval_t *i,
722 unsigned int rats_count, ratden_t *rats,
723 unsigned int *nump, unsigned int *denp)
725 unsigned int best_num, best_diff, best_den;
730 best_num = best_den = best_diff = 0;
731 for (k = 0; k < rats_count; ++k) {
733 unsigned int den = rats[k].den;
734 unsigned int q = i->min;
737 if (num > rats[k].num_max)
739 if (num < rats[k].num_min)
740 num = rats[k].num_max;
743 r = (num - rats[k].num_min) % rats[k].num_step;
745 num += rats[k].num_step - r;
747 diff = num - q * den;
749 diff * best_den < best_diff * den) {
759 t.min = div_down(best_num, best_den);
760 t.openmin = !!(best_num % best_den);
762 best_num = best_den = best_diff = 0;
763 for (k = 0; k < rats_count; ++k) {
765 unsigned int den = rats[k].den;
766 unsigned int q = i->max;
769 if (num < rats[k].num_min)
771 if (num > rats[k].num_max)
772 num = rats[k].num_max;
775 r = (num - rats[k].num_min) % rats[k].num_step;
779 diff = q * den - num;
781 diff * best_den < best_diff * den) {
791 t.max = div_up(best_num, best_den);
792 t.openmax = !!(best_num % best_den);
794 err = snd_interval_refine(i, &t);
798 if (snd_interval_single(i)) {
808 * snd_interval_list - refine the interval value from the list
809 * @i: the interval value to refine
810 * @count: the number of elements in the list
811 * @list: the value list
812 * @mask: the bit-mask to evaluate
814 * Refines the interval value from the list.
815 * When mask is non-zero, only the elements corresponding to bit 1 are
818 * Returns non-zero if the value is changed, zero if not changed.
820 int snd_interval_list(snd_interval_t *i, unsigned int count, unsigned int *list, unsigned int mask)
824 for (k = 0; k < count; k++) {
825 if (mask && !(mask & (1 << k)))
827 if (i->min == list[k] && !i->openmin)
829 if (i->min < list[k]) {
839 for (k = count; k-- > 0;) {
840 if (mask && !(mask & (1 << k)))
842 if (i->max == list[k] && !i->openmax)
844 if (i->max > list[k]) {
854 if (snd_interval_checkempty(i)) {
861 int snd_interval_step(snd_interval_t *i, unsigned int min, unsigned int step)
865 n = (i->min - min) % step;
866 if (n != 0 || i->openmin) {
870 n = (i->max - min) % step;
871 if (n != 0 || i->openmax) {
875 if (snd_interval_checkempty(i)) {
882 /* Info constraints helpers */
885 * snd_pcm_hw_rule_add - add the hw-constraint rule
886 * @runtime: the pcm runtime instance
887 * @cond: condition bits
888 * @var: the variable to evaluate
889 * @func: the evaluation function
890 * @private: the private data pointer passed to function
891 * @dep: the dependent variables
893 * Returns zero if successful, or a negative error code on failure.
895 int snd_pcm_hw_rule_add(snd_pcm_runtime_t *runtime, unsigned int cond,
897 snd_pcm_hw_rule_func_t func, void *private,
900 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
901 snd_pcm_hw_rule_t *c;
905 if (constrs->rules_num >= constrs->rules_all) {
906 snd_pcm_hw_rule_t *new;
907 unsigned int new_rules = constrs->rules_all + 16;
908 new = kcalloc(new_rules, sizeof(*c), GFP_KERNEL);
911 if (constrs->rules) {
912 memcpy(new, constrs->rules,
913 constrs->rules_num * sizeof(*c));
914 kfree(constrs->rules);
916 constrs->rules = new;
917 constrs->rules_all = new_rules;
919 c = &constrs->rules[constrs->rules_num];
923 c->private = private;
926 snd_assert(k < ARRAY_SIZE(c->deps), return -EINVAL);
930 dep = va_arg(args, int);
932 constrs->rules_num++;
938 * snd_pcm_hw_constraint_mask
940 int snd_pcm_hw_constraint_mask(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
943 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
944 snd_mask_t *maskp = constrs_mask(constrs, var);
945 *maskp->bits &= mask;
946 memset(maskp->bits + 1, 0, (SNDRV_MASK_MAX-32) / 8); /* clear rest */
947 if (*maskp->bits == 0)
953 * snd_pcm_hw_constraint_mask64
955 int snd_pcm_hw_constraint_mask64(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
958 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
959 snd_mask_t *maskp = constrs_mask(constrs, var);
960 maskp->bits[0] &= (u_int32_t)mask;
961 maskp->bits[1] &= (u_int32_t)(mask >> 32);
962 memset(maskp->bits + 2, 0, (SNDRV_MASK_MAX-64) / 8); /* clear rest */
963 if (! maskp->bits[0] && ! maskp->bits[1])
969 * snd_pcm_hw_constraint_integer
971 int snd_pcm_hw_constraint_integer(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var)
973 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
974 return snd_interval_setinteger(constrs_interval(constrs, var));
978 * snd_pcm_hw_constraint_minmax
980 int snd_pcm_hw_constraint_minmax(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
981 unsigned int min, unsigned int max)
983 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
987 t.openmin = t.openmax = 0;
989 return snd_interval_refine(constrs_interval(constrs, var), &t);
992 static int snd_pcm_hw_rule_list(snd_pcm_hw_params_t *params,
993 snd_pcm_hw_rule_t *rule)
995 snd_pcm_hw_constraint_list_t *list = rule->private;
996 return snd_interval_list(hw_param_interval(params, rule->var), list->count, list->list, list->mask);
1001 * snd_pcm_hw_constraint_list
1003 int snd_pcm_hw_constraint_list(snd_pcm_runtime_t *runtime,
1005 snd_pcm_hw_param_t var,
1006 snd_pcm_hw_constraint_list_t *l)
1008 return snd_pcm_hw_rule_add(runtime, cond, var,
1009 snd_pcm_hw_rule_list, l,
1013 static int snd_pcm_hw_rule_ratnums(snd_pcm_hw_params_t *params,
1014 snd_pcm_hw_rule_t *rule)
1016 snd_pcm_hw_constraint_ratnums_t *r = rule->private;
1017 unsigned int num = 0, den = 0;
1019 err = snd_interval_ratnum(hw_param_interval(params, rule->var),
1020 r->nrats, r->rats, &num, &den);
1021 if (err >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) {
1022 params->rate_num = num;
1023 params->rate_den = den;
1029 * snd_pcm_hw_constraint_ratnums
1031 int snd_pcm_hw_constraint_ratnums(snd_pcm_runtime_t *runtime,
1033 snd_pcm_hw_param_t var,
1034 snd_pcm_hw_constraint_ratnums_t *r)
1036 return snd_pcm_hw_rule_add(runtime, cond, var,
1037 snd_pcm_hw_rule_ratnums, r,
1041 static int snd_pcm_hw_rule_ratdens(snd_pcm_hw_params_t *params,
1042 snd_pcm_hw_rule_t *rule)
1044 snd_pcm_hw_constraint_ratdens_t *r = rule->private;
1045 unsigned int num = 0, den = 0;
1046 int err = snd_interval_ratden(hw_param_interval(params, rule->var),
1047 r->nrats, r->rats, &num, &den);
1048 if (err >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) {
1049 params->rate_num = num;
1050 params->rate_den = den;
1056 * snd_pcm_hw_constraint_ratdens
1058 int snd_pcm_hw_constraint_ratdens(snd_pcm_runtime_t *runtime,
1060 snd_pcm_hw_param_t var,
1061 snd_pcm_hw_constraint_ratdens_t *r)
1063 return snd_pcm_hw_rule_add(runtime, cond, var,
1064 snd_pcm_hw_rule_ratdens, r,
1068 static int snd_pcm_hw_rule_msbits(snd_pcm_hw_params_t *params,
1069 snd_pcm_hw_rule_t *rule)
1071 unsigned int l = (unsigned long) rule->private;
1072 int width = l & 0xffff;
1073 unsigned int msbits = l >> 16;
1074 snd_interval_t *i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
1075 if (snd_interval_single(i) && snd_interval_value(i) == width)
1076 params->msbits = msbits;
1081 * snd_pcm_hw_constraint_msbits
1083 int snd_pcm_hw_constraint_msbits(snd_pcm_runtime_t *runtime,
1086 unsigned int msbits)
1088 unsigned long l = (msbits << 16) | width;
1089 return snd_pcm_hw_rule_add(runtime, cond, -1,
1090 snd_pcm_hw_rule_msbits,
1092 SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1);
1095 static int snd_pcm_hw_rule_step(snd_pcm_hw_params_t *params,
1096 snd_pcm_hw_rule_t *rule)
1098 unsigned long step = (unsigned long) rule->private;
1099 return snd_interval_step(hw_param_interval(params, rule->var), 0, step);
1103 * snd_pcm_hw_constraint_step
1105 int snd_pcm_hw_constraint_step(snd_pcm_runtime_t *runtime,
1107 snd_pcm_hw_param_t var,
1110 return snd_pcm_hw_rule_add(runtime, cond, var,
1111 snd_pcm_hw_rule_step, (void *) step,
1115 static int snd_pcm_hw_rule_pow2(snd_pcm_hw_params_t *params, snd_pcm_hw_rule_t *rule)
1117 static int pow2_sizes[] = {
1118 1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7,
1119 1<<8, 1<<9, 1<<10, 1<<11, 1<<12, 1<<13, 1<<14, 1<<15,
1120 1<<16, 1<<17, 1<<18, 1<<19, 1<<20, 1<<21, 1<<22, 1<<23,
1121 1<<24, 1<<25, 1<<26, 1<<27, 1<<28, 1<<29, 1<<30
1123 return snd_interval_list(hw_param_interval(params, rule->var),
1124 ARRAY_SIZE(pow2_sizes), pow2_sizes, 0);
1128 * snd_pcm_hw_constraint_pow2
1130 int snd_pcm_hw_constraint_pow2(snd_pcm_runtime_t *runtime,
1132 snd_pcm_hw_param_t var)
1134 return snd_pcm_hw_rule_add(runtime, cond, var,
1135 snd_pcm_hw_rule_pow2, NULL,
1139 /* To use the same code we have in alsa-lib */
1140 #define snd_pcm_t snd_pcm_substream_t
1141 #define assert(i) snd_assert((i), return -EINVAL)
1143 #define INT_MIN ((int)((unsigned int)INT_MAX+1))
1146 void _snd_pcm_hw_param_any(snd_pcm_hw_params_t *params, snd_pcm_hw_param_t var)
1148 if (hw_is_mask(var)) {
1149 snd_mask_any(hw_param_mask(params, var));
1150 params->cmask |= 1 << var;
1151 params->rmask |= 1 << var;
1154 if (hw_is_interval(var)) {
1155 snd_interval_any(hw_param_interval(params, var));
1156 params->cmask |= 1 << var;
1157 params->rmask |= 1 << var;
1164 * snd_pcm_hw_param_any
1166 int snd_pcm_hw_param_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1167 snd_pcm_hw_param_t var)
1169 _snd_pcm_hw_param_any(params, var);
1170 return snd_pcm_hw_refine(pcm, params);
1173 void _snd_pcm_hw_params_any(snd_pcm_hw_params_t *params)
1176 memset(params, 0, sizeof(*params));
1177 for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++)
1178 _snd_pcm_hw_param_any(params, k);
1179 for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
1180 _snd_pcm_hw_param_any(params, k);
1185 * snd_pcm_hw_params_any
1187 * Fill PARAMS with full configuration space boundaries
1189 int snd_pcm_hw_params_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
1191 _snd_pcm_hw_params_any(params);
1192 return snd_pcm_hw_refine(pcm, params);
1196 * snd_pcm_hw_param_value
1198 * Return the value for field PAR if it's fixed in configuration space
1199 * defined by PARAMS. Return -EINVAL otherwise
1201 int snd_pcm_hw_param_value(const snd_pcm_hw_params_t *params,
1202 snd_pcm_hw_param_t var, int *dir)
1204 if (hw_is_mask(var)) {
1205 const snd_mask_t *mask = hw_param_mask_c(params, var);
1206 if (!snd_mask_single(mask))
1210 return snd_mask_value(mask);
1212 if (hw_is_interval(var)) {
1213 const snd_interval_t *i = hw_param_interval_c(params, var);
1214 if (!snd_interval_single(i))
1218 return snd_interval_value(i);
1225 * snd_pcm_hw_param_value_min
1227 * Return the minimum value for field PAR.
1229 unsigned int snd_pcm_hw_param_value_min(const snd_pcm_hw_params_t *params,
1230 snd_pcm_hw_param_t var, int *dir)
1232 if (hw_is_mask(var)) {
1235 return snd_mask_min(hw_param_mask_c(params, var));
1237 if (hw_is_interval(var)) {
1238 const snd_interval_t *i = hw_param_interval_c(params, var);
1241 return snd_interval_min(i);
1248 * snd_pcm_hw_param_value_max
1250 * Return the maximum value for field PAR.
1252 unsigned int snd_pcm_hw_param_value_max(const snd_pcm_hw_params_t *params,
1253 snd_pcm_hw_param_t var, int *dir)
1255 if (hw_is_mask(var)) {
1258 return snd_mask_max(hw_param_mask_c(params, var));
1260 if (hw_is_interval(var)) {
1261 const snd_interval_t *i = hw_param_interval_c(params, var);
1263 *dir = - (int) i->openmax;
1264 return snd_interval_max(i);
1270 void _snd_pcm_hw_param_setempty(snd_pcm_hw_params_t *params,
1271 snd_pcm_hw_param_t var)
1273 if (hw_is_mask(var)) {
1274 snd_mask_none(hw_param_mask(params, var));
1275 params->cmask |= 1 << var;
1276 params->rmask |= 1 << var;
1277 } else if (hw_is_interval(var)) {
1278 snd_interval_none(hw_param_interval(params, var));
1279 params->cmask |= 1 << var;
1280 params->rmask |= 1 << var;
1286 int _snd_pcm_hw_param_setinteger(snd_pcm_hw_params_t *params,
1287 snd_pcm_hw_param_t var)
1290 assert(hw_is_interval(var));
1291 changed = snd_interval_setinteger(hw_param_interval(params, var));
1293 params->cmask |= 1 << var;
1294 params->rmask |= 1 << var;
1300 * snd_pcm_hw_param_setinteger
1302 * Inside configuration space defined by PARAMS remove from PAR all
1303 * non integer values. Reduce configuration space accordingly.
1304 * Return -EINVAL if the configuration space is empty
1306 int snd_pcm_hw_param_setinteger(snd_pcm_t *pcm,
1307 snd_pcm_hw_params_t *params,
1308 snd_pcm_hw_param_t var)
1310 int changed = _snd_pcm_hw_param_setinteger(params, var);
1313 if (params->rmask) {
1314 int err = snd_pcm_hw_refine(pcm, params);
1321 int _snd_pcm_hw_param_first(snd_pcm_hw_params_t *params,
1322 snd_pcm_hw_param_t var)
1325 if (hw_is_mask(var))
1326 changed = snd_mask_refine_first(hw_param_mask(params, var));
1327 else if (hw_is_interval(var))
1328 changed = snd_interval_refine_first(hw_param_interval(params, var));
1334 params->cmask |= 1 << var;
1335 params->rmask |= 1 << var;
1342 * snd_pcm_hw_param_first
1344 * Inside configuration space defined by PARAMS remove from PAR all
1345 * values > minimum. Reduce configuration space accordingly.
1346 * Return the minimum.
1348 int snd_pcm_hw_param_first(snd_pcm_t *pcm,
1349 snd_pcm_hw_params_t *params,
1350 snd_pcm_hw_param_t var, int *dir)
1352 int changed = _snd_pcm_hw_param_first(params, var);
1355 if (params->rmask) {
1356 int err = snd_pcm_hw_refine(pcm, params);
1359 return snd_pcm_hw_param_value(params, var, dir);
1362 int _snd_pcm_hw_param_last(snd_pcm_hw_params_t *params,
1363 snd_pcm_hw_param_t var)
1366 if (hw_is_mask(var))
1367 changed = snd_mask_refine_last(hw_param_mask(params, var));
1368 else if (hw_is_interval(var))
1369 changed = snd_interval_refine_last(hw_param_interval(params, var));
1375 params->cmask |= 1 << var;
1376 params->rmask |= 1 << var;
1383 * snd_pcm_hw_param_last
1385 * Inside configuration space defined by PARAMS remove from PAR all
1386 * values < maximum. Reduce configuration space accordingly.
1387 * Return the maximum.
1389 int snd_pcm_hw_param_last(snd_pcm_t *pcm,
1390 snd_pcm_hw_params_t *params,
1391 snd_pcm_hw_param_t var, int *dir)
1393 int changed = _snd_pcm_hw_param_last(params, var);
1396 if (params->rmask) {
1397 int err = snd_pcm_hw_refine(pcm, params);
1400 return snd_pcm_hw_param_value(params, var, dir);
1403 int _snd_pcm_hw_param_min(snd_pcm_hw_params_t *params,
1404 snd_pcm_hw_param_t var, unsigned int val, int dir)
1411 } else if (dir < 0) {
1418 if (hw_is_mask(var))
1419 changed = snd_mask_refine_min(hw_param_mask(params, var), val + !!open);
1420 else if (hw_is_interval(var))
1421 changed = snd_interval_refine_min(hw_param_interval(params, var), val, open);
1427 params->cmask |= 1 << var;
1428 params->rmask |= 1 << var;
1434 * snd_pcm_hw_param_min
1436 * Inside configuration space defined by PARAMS remove from PAR all
1437 * values < VAL. Reduce configuration space accordingly.
1438 * Return new minimum or -EINVAL if the configuration space is empty
1440 int snd_pcm_hw_param_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1441 snd_pcm_hw_param_t var, unsigned int val, int *dir)
1443 int changed = _snd_pcm_hw_param_min(params, var, val, dir ? *dir : 0);
1446 if (params->rmask) {
1447 int err = snd_pcm_hw_refine(pcm, params);
1451 return snd_pcm_hw_param_value_min(params, var, dir);
1454 int _snd_pcm_hw_param_max(snd_pcm_hw_params_t *params,
1455 snd_pcm_hw_param_t var, unsigned int val, int dir)
1462 } else if (dir > 0) {
1467 if (hw_is_mask(var)) {
1468 if (val == 0 && open) {
1469 snd_mask_none(hw_param_mask(params, var));
1472 changed = snd_mask_refine_max(hw_param_mask(params, var), val - !!open);
1473 } else if (hw_is_interval(var))
1474 changed = snd_interval_refine_max(hw_param_interval(params, var), val, open);
1480 params->cmask |= 1 << var;
1481 params->rmask |= 1 << var;
1487 * snd_pcm_hw_param_max
1489 * Inside configuration space defined by PARAMS remove from PAR all
1490 * values >= VAL + 1. Reduce configuration space accordingly.
1491 * Return new maximum or -EINVAL if the configuration space is empty
1493 int snd_pcm_hw_param_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1494 snd_pcm_hw_param_t var, unsigned int val, int *dir)
1496 int changed = _snd_pcm_hw_param_max(params, var, val, dir ? *dir : 0);
1499 if (params->rmask) {
1500 int err = snd_pcm_hw_refine(pcm, params);
1504 return snd_pcm_hw_param_value_max(params, var, dir);
1507 int _snd_pcm_hw_param_set(snd_pcm_hw_params_t *params,
1508 snd_pcm_hw_param_t var, unsigned int val, int dir)
1511 if (hw_is_mask(var)) {
1512 snd_mask_t *m = hw_param_mask(params, var);
1513 if (val == 0 && dir < 0) {
1521 changed = snd_mask_refine_set(hw_param_mask(params, var), val);
1523 } else if (hw_is_interval(var)) {
1524 snd_interval_t *i = hw_param_interval(params, var);
1525 if (val == 0 && dir < 0) {
1527 snd_interval_none(i);
1528 } else if (dir == 0)
1529 changed = snd_interval_refine_set(i, val);
1543 changed = snd_interval_refine(i, &t);
1550 params->cmask |= 1 << var;
1551 params->rmask |= 1 << var;
1557 * snd_pcm_hw_param_set
1559 * Inside configuration space defined by PARAMS remove from PAR all
1560 * values != VAL. Reduce configuration space accordingly.
1561 * Return VAL or -EINVAL if the configuration space is empty
1563 int snd_pcm_hw_param_set(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1564 snd_pcm_hw_param_t var, unsigned int val, int dir)
1566 int changed = _snd_pcm_hw_param_set(params, var, val, dir);
1569 if (params->rmask) {
1570 int err = snd_pcm_hw_refine(pcm, params);
1574 return snd_pcm_hw_param_value(params, var, NULL);
1577 int _snd_pcm_hw_param_mask(snd_pcm_hw_params_t *params,
1578 snd_pcm_hw_param_t var, const snd_mask_t *val)
1581 assert(hw_is_mask(var));
1582 changed = snd_mask_refine(hw_param_mask(params, var), val);
1584 params->cmask |= 1 << var;
1585 params->rmask |= 1 << var;
1591 * snd_pcm_hw_param_mask
1593 * Inside configuration space defined by PARAMS remove from PAR all values
1594 * not contained in MASK. Reduce configuration space accordingly.
1595 * This function can be called only for SNDRV_PCM_HW_PARAM_ACCESS,
1596 * SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SUBFORMAT.
1597 * Return 0 on success or -EINVAL
1598 * if the configuration space is empty
1600 int snd_pcm_hw_param_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1601 snd_pcm_hw_param_t var, const snd_mask_t *val)
1603 int changed = _snd_pcm_hw_param_mask(params, var, val);
1606 if (params->rmask) {
1607 int err = snd_pcm_hw_refine(pcm, params);
1614 static int boundary_sub(int a, int adir,
1618 adir = adir < 0 ? -1 : (adir > 0 ? 1 : 0);
1619 bdir = bdir < 0 ? -1 : (bdir > 0 ? 1 : 0);
1621 *cdir = adir - bdir;
1623 assert(*c > INT_MIN);
1625 } else if (*cdir == 2) {
1626 assert(*c < INT_MAX);
1632 static int boundary_lt(unsigned int a, int adir,
1633 unsigned int b, int bdir)
1635 assert(a > 0 || adir >= 0);
1636 assert(b > 0 || bdir >= 0);
1640 } else if (adir > 0)
1645 } else if (bdir > 0)
1647 return a < b || (a == b && adir < bdir);
1650 /* Return 1 if min is nearer to best than max */
1651 static int boundary_nearer(int min, int mindir,
1652 int best, int bestdir,
1653 int max, int maxdir)
1657 boundary_sub(best, bestdir, min, mindir, &dmin, &dmindir);
1658 boundary_sub(max, maxdir, best, bestdir, &dmax, &dmaxdir);
1659 return boundary_lt(dmin, dmindir, dmax, dmaxdir);
1663 * snd_pcm_hw_param_near
1665 * Inside configuration space defined by PARAMS set PAR to the available value
1666 * nearest to VAL. Reduce configuration space accordingly.
1667 * This function cannot be called for SNDRV_PCM_HW_PARAM_ACCESS,
1668 * SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SUBFORMAT.
1669 * Return the value found.
1671 int snd_pcm_hw_param_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1672 snd_pcm_hw_param_t var, unsigned int best, int *dir)
1674 snd_pcm_hw_params_t *save = NULL;
1676 unsigned int saved_min;
1680 int valdir = dir ? *dir : 0;
1685 mindir = maxdir = valdir;
1688 else if (maxdir == 0)
1694 save = kmalloc(sizeof(*save), GFP_KERNEL);
1699 min = snd_pcm_hw_param_min(pcm, params, var, min, &mindir);
1701 snd_pcm_hw_params_t *params1;
1704 if ((unsigned int)min == saved_min && mindir == valdir)
1706 params1 = kmalloc(sizeof(*params1), GFP_KERNEL);
1707 if (params1 == NULL) {
1712 max = snd_pcm_hw_param_max(pcm, params1, var, max, &maxdir);
1717 if (boundary_nearer(max, maxdir, best, valdir, min, mindir)) {
1724 max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir);
1731 v = snd_pcm_hw_param_last(pcm, params, var, dir);
1733 v = snd_pcm_hw_param_first(pcm, params, var, dir);
1739 * snd_pcm_hw_param_choose
1741 * Choose one configuration from configuration space defined by PARAMS
1742 * The configuration chosen is that obtained fixing in this order:
1743 * first access, first format, first subformat, min channels,
1744 * min rate, min period time, max buffer size, min tick time
1746 int snd_pcm_hw_params_choose(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
1750 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_ACCESS, NULL);
1753 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_FORMAT, NULL);
1756 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_SUBFORMAT, NULL);
1759 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_CHANNELS, NULL);
1762 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_RATE, NULL);
1765 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_PERIOD_TIME, NULL);
1768 err = snd_pcm_hw_param_last(pcm, params, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, NULL);
1771 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_TICK_TIME, NULL);
1780 static int snd_pcm_lib_ioctl_reset(snd_pcm_substream_t *substream,
1783 snd_pcm_runtime_t *runtime = substream->runtime;
1784 unsigned long flags;
1785 snd_pcm_stream_lock_irqsave(substream, flags);
1786 if (snd_pcm_running(substream) &&
1787 snd_pcm_update_hw_ptr(substream) >= 0)
1788 runtime->status->hw_ptr %= runtime->buffer_size;
1790 runtime->status->hw_ptr = 0;
1791 snd_pcm_stream_unlock_irqrestore(substream, flags);
1795 static int snd_pcm_lib_ioctl_channel_info(snd_pcm_substream_t *substream,
1798 snd_pcm_channel_info_t *info = arg;
1799 snd_pcm_runtime_t *runtime = substream->runtime;
1801 if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) {
1805 width = snd_pcm_format_physical_width(runtime->format);
1809 switch (runtime->access) {
1810 case SNDRV_PCM_ACCESS_MMAP_INTERLEAVED:
1811 case SNDRV_PCM_ACCESS_RW_INTERLEAVED:
1812 info->first = info->channel * width;
1813 info->step = runtime->channels * width;
1815 case SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED:
1816 case SNDRV_PCM_ACCESS_RW_NONINTERLEAVED:
1818 size_t size = runtime->dma_bytes / runtime->channels;
1819 info->first = info->channel * size * 8;
1831 * snd_pcm_lib_ioctl - a generic PCM ioctl callback
1832 * @substream: the pcm substream instance
1833 * @cmd: ioctl command
1834 * @arg: ioctl argument
1836 * Processes the generic ioctl commands for PCM.
1837 * Can be passed as the ioctl callback for PCM ops.
1839 * Returns zero if successful, or a negative error code on failure.
1841 int snd_pcm_lib_ioctl(snd_pcm_substream_t *substream,
1842 unsigned int cmd, void *arg)
1845 case SNDRV_PCM_IOCTL1_INFO:
1847 case SNDRV_PCM_IOCTL1_RESET:
1848 return snd_pcm_lib_ioctl_reset(substream, arg);
1849 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
1850 return snd_pcm_lib_ioctl_channel_info(substream, arg);
1860 * snd_pcm_playback_ready - check whether the playback buffer is available
1861 * @substream: the pcm substream instance
1863 * Checks whether enough free space is available on the playback buffer.
1865 * Returns non-zero if available, or zero if not.
1867 int snd_pcm_playback_ready(snd_pcm_substream_t *substream)
1869 snd_pcm_runtime_t *runtime = substream->runtime;
1870 return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
1874 * snd_pcm_capture_ready - check whether the capture buffer is available
1875 * @substream: the pcm substream instance
1877 * Checks whether enough capture data is available on the capture buffer.
1879 * Returns non-zero if available, or zero if not.
1881 int snd_pcm_capture_ready(snd_pcm_substream_t *substream)
1883 snd_pcm_runtime_t *runtime = substream->runtime;
1884 return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
1888 * snd_pcm_playback_data - check whether any data exists on the playback buffer
1889 * @substream: the pcm substream instance
1891 * Checks whether any data exists on the playback buffer. If stop_threshold
1892 * is bigger or equal to boundary, then this function returns always non-zero.
1894 * Returns non-zero if exists, or zero if not.
1896 int snd_pcm_playback_data(snd_pcm_substream_t *substream)
1898 snd_pcm_runtime_t *runtime = substream->runtime;
1900 if (runtime->stop_threshold >= runtime->boundary)
1902 return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
1906 * snd_pcm_playback_empty - check whether the playback buffer is empty
1907 * @substream: the pcm substream instance
1909 * Checks whether the playback buffer is empty.
1911 * Returns non-zero if empty, or zero if not.
1913 int snd_pcm_playback_empty(snd_pcm_substream_t *substream)
1915 snd_pcm_runtime_t *runtime = substream->runtime;
1916 return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
1920 * snd_pcm_capture_empty - check whether the capture buffer is empty
1921 * @substream: the pcm substream instance
1923 * Checks whether the capture buffer is empty.
1925 * Returns non-zero if empty, or zero if not.
1927 int snd_pcm_capture_empty(snd_pcm_substream_t *substream)
1929 snd_pcm_runtime_t *runtime = substream->runtime;
1930 return snd_pcm_capture_avail(runtime) == 0;
1933 static void snd_pcm_system_tick_set(snd_pcm_substream_t *substream,
1934 unsigned long ticks)
1936 snd_pcm_runtime_t *runtime = substream->runtime;
1938 del_timer(&runtime->tick_timer);
1940 ticks /= (1000000 / HZ);
1941 if (ticks % (1000000 / HZ))
1943 mod_timer(&runtime->tick_timer, jiffies + ticks);
1947 /* Temporary alias */
1948 void snd_pcm_tick_set(snd_pcm_substream_t *substream, unsigned long ticks)
1950 snd_pcm_system_tick_set(substream, ticks);
1953 void snd_pcm_tick_prepare(snd_pcm_substream_t *substream)
1955 snd_pcm_runtime_t *runtime = substream->runtime;
1956 snd_pcm_uframes_t frames = ULONG_MAX;
1957 snd_pcm_uframes_t avail, dist;
1961 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1962 if (runtime->silence_size >= runtime->boundary) {
1964 } else if (runtime->silence_size > 0 &&
1965 runtime->silence_filled < runtime->buffer_size) {
1966 snd_pcm_sframes_t noise_dist;
1967 noise_dist = snd_pcm_playback_hw_avail(runtime) + runtime->silence_filled;
1968 snd_assert(noise_dist <= (snd_pcm_sframes_t)runtime->silence_threshold, );
1969 frames = noise_dist - runtime->silence_threshold;
1971 avail = snd_pcm_playback_avail(runtime);
1973 avail = snd_pcm_capture_avail(runtime);
1975 if (avail < runtime->control->avail_min) {
1976 snd_pcm_sframes_t n = runtime->control->avail_min - avail;
1977 if (n > 0 && frames > (snd_pcm_uframes_t)n)
1980 if (avail < runtime->buffer_size) {
1981 snd_pcm_sframes_t n = runtime->buffer_size - avail;
1982 if (n > 0 && frames > (snd_pcm_uframes_t)n)
1985 if (frames == ULONG_MAX) {
1986 snd_pcm_tick_set(substream, 0);
1989 dist = runtime->status->hw_ptr - runtime->hw_ptr_base;
1990 /* Distance to next interrupt */
1991 dist = runtime->period_size - dist % runtime->period_size;
1992 if (dist <= frames) {
1993 snd_pcm_tick_set(substream, 0);
1996 /* the base time is us */
1999 div64_32(&n, runtime->tick_time * runtime->rate, &r);
2000 ticks = n + (r > 0 ? 1 : 0);
2001 if (ticks < runtime->sleep_min)
2002 ticks = runtime->sleep_min;
2003 snd_pcm_tick_set(substream, (unsigned long) ticks);
2006 void snd_pcm_tick_elapsed(snd_pcm_substream_t *substream)
2008 snd_pcm_runtime_t *runtime;
2009 unsigned long flags;
2011 snd_assert(substream != NULL, return);
2012 runtime = substream->runtime;
2013 snd_assert(runtime != NULL, return);
2015 snd_pcm_stream_lock_irqsave(substream, flags);
2016 if (!snd_pcm_running(substream) ||
2017 snd_pcm_update_hw_ptr(substream) < 0)
2019 if (runtime->sleep_min)
2020 snd_pcm_tick_prepare(substream);
2022 snd_pcm_stream_unlock_irqrestore(substream, flags);
2026 * snd_pcm_period_elapsed - update the pcm status for the next period
2027 * @substream: the pcm substream instance
2029 * This function is called from the interrupt handler when the
2030 * PCM has processed the period size. It will update the current
2031 * pointer, set up the tick, wake up sleepers, etc.
2033 * Even if more than one periods have elapsed since the last call, you
2034 * have to call this only once.
2036 void snd_pcm_period_elapsed(snd_pcm_substream_t *substream)
2038 snd_pcm_runtime_t *runtime;
2039 unsigned long flags;
2041 snd_assert(substream != NULL, return);
2042 runtime = substream->runtime;
2043 snd_assert(runtime != NULL, return);
2045 if (runtime->transfer_ack_begin)
2046 runtime->transfer_ack_begin(substream);
2048 snd_pcm_stream_lock_irqsave(substream, flags);
2049 if (!snd_pcm_running(substream) ||
2050 snd_pcm_update_hw_ptr_interrupt(substream) < 0)
2053 if (substream->timer_running)
2054 snd_timer_interrupt(substream->timer, 1);
2055 if (runtime->sleep_min)
2056 snd_pcm_tick_prepare(substream);
2058 snd_pcm_stream_unlock_irqrestore(substream, flags);
2059 if (runtime->transfer_ack_end)
2060 runtime->transfer_ack_end(substream);
2061 kill_fasync(&runtime->fasync, SIGIO, POLL_IN);
2064 static int snd_pcm_lib_write_transfer(snd_pcm_substream_t *substream,
2066 unsigned long data, unsigned int off,
2067 snd_pcm_uframes_t frames)
2069 snd_pcm_runtime_t *runtime = substream->runtime;
2071 char __user *buf = (char __user *) data + frames_to_bytes(runtime, off);
2072 if (substream->ops->copy) {
2073 if ((err = substream->ops->copy(substream, -1, hwoff, buf, frames)) < 0)
2076 char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff);
2077 snd_assert(runtime->dma_area, return -EFAULT);
2078 if (copy_from_user(hwbuf, buf, frames_to_bytes(runtime, frames)))
2084 typedef int (*transfer_f)(snd_pcm_substream_t *substream, unsigned int hwoff,
2085 unsigned long data, unsigned int off,
2086 snd_pcm_uframes_t size);
2088 static snd_pcm_sframes_t snd_pcm_lib_write1(snd_pcm_substream_t *substream,
2090 snd_pcm_uframes_t size,
2092 transfer_f transfer)
2094 snd_pcm_runtime_t *runtime = substream->runtime;
2095 snd_pcm_uframes_t xfer = 0;
2096 snd_pcm_uframes_t offset = 0;
2101 if (size > runtime->xfer_align)
2102 size -= size % runtime->xfer_align;
2104 snd_pcm_stream_lock_irq(substream);
2105 switch (runtime->status->state) {
2106 case SNDRV_PCM_STATE_PREPARED:
2107 case SNDRV_PCM_STATE_RUNNING:
2108 case SNDRV_PCM_STATE_PAUSED:
2110 case SNDRV_PCM_STATE_XRUN:
2113 case SNDRV_PCM_STATE_SUSPENDED:
2122 snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
2123 snd_pcm_uframes_t avail;
2124 snd_pcm_uframes_t cont;
2125 if (runtime->sleep_min == 0 && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2126 snd_pcm_update_hw_ptr(substream);
2127 avail = snd_pcm_playback_avail(runtime);
2128 if (((avail < runtime->control->avail_min && size > avail) ||
2129 (size >= runtime->xfer_align && avail < runtime->xfer_align))) {
2131 enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED } state;
2139 init_waitqueue_entry(&wait, current);
2140 add_wait_queue(&runtime->sleep, &wait);
2142 if (signal_pending(current)) {
2146 set_current_state(TASK_INTERRUPTIBLE);
2147 snd_pcm_stream_unlock_irq(substream);
2148 tout = schedule_timeout(10 * HZ);
2149 snd_pcm_stream_lock_irq(substream);
2151 if (runtime->status->state != SNDRV_PCM_STATE_PREPARED &&
2152 runtime->status->state != SNDRV_PCM_STATE_PAUSED) {
2153 state = runtime->status->state == SNDRV_PCM_STATE_SUSPENDED ? SUSPENDED : EXPIRED;
2157 switch (runtime->status->state) {
2158 case SNDRV_PCM_STATE_XRUN:
2159 case SNDRV_PCM_STATE_DRAINING:
2162 case SNDRV_PCM_STATE_SUSPENDED:
2168 avail = snd_pcm_playback_avail(runtime);
2169 if (avail >= runtime->control->avail_min) {
2175 remove_wait_queue(&runtime->sleep, &wait);
2188 snd_printd("playback write error (DMA or IRQ trouble?)\n");
2195 if (avail > runtime->xfer_align)
2196 avail -= avail % runtime->xfer_align;
2197 frames = size > avail ? avail : size;
2198 cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size;
2201 snd_assert(frames != 0, snd_pcm_stream_unlock_irq(substream); return -EINVAL);
2202 appl_ptr = runtime->control->appl_ptr;
2203 appl_ofs = appl_ptr % runtime->buffer_size;
2204 snd_pcm_stream_unlock_irq(substream);
2205 if ((err = transfer(substream, appl_ofs, data, offset, frames)) < 0)
2207 snd_pcm_stream_lock_irq(substream);
2208 switch (runtime->status->state) {
2209 case SNDRV_PCM_STATE_XRUN:
2212 case SNDRV_PCM_STATE_SUSPENDED:
2219 if (appl_ptr >= runtime->boundary) {
2220 runtime->control->appl_ptr = 0;
2222 runtime->control->appl_ptr = appl_ptr;
2224 if (substream->ops->ack)
2225 substream->ops->ack(substream);
2230 if (runtime->status->state == SNDRV_PCM_STATE_PREPARED &&
2231 snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) {
2232 err = snd_pcm_start(substream);
2236 if (runtime->sleep_min &&
2237 runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2238 snd_pcm_tick_prepare(substream);
2241 snd_pcm_stream_unlock_irq(substream);
2243 return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
2246 snd_pcm_sframes_t snd_pcm_lib_write(snd_pcm_substream_t *substream, const void __user *buf, snd_pcm_uframes_t size)
2248 snd_pcm_runtime_t *runtime;
2251 snd_assert(substream != NULL, return -ENXIO);
2252 runtime = substream->runtime;
2253 snd_assert(runtime != NULL, return -ENXIO);
2254 snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
2255 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
2258 snd_assert(substream->ffile != NULL, return -ENXIO);
2259 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK);
2260 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
2261 if (substream->oss.oss) {
2262 snd_pcm_oss_setup_t *setup = substream->oss.setup;
2263 if (setup != NULL) {
2264 if (setup->nonblock)
2266 else if (setup->block)
2272 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
2273 runtime->channels > 1)
2275 return snd_pcm_lib_write1(substream, (unsigned long)buf, size, nonblock,
2276 snd_pcm_lib_write_transfer);
2279 static int snd_pcm_lib_writev_transfer(snd_pcm_substream_t *substream,
2281 unsigned long data, unsigned int off,
2282 snd_pcm_uframes_t frames)
2284 snd_pcm_runtime_t *runtime = substream->runtime;
2286 void __user **bufs = (void __user **)data;
2287 int channels = runtime->channels;
2289 if (substream->ops->copy) {
2290 snd_assert(substream->ops->silence != NULL, return -EINVAL);
2291 for (c = 0; c < channels; ++c, ++bufs) {
2292 if (*bufs == NULL) {
2293 if ((err = substream->ops->silence(substream, c, hwoff, frames)) < 0)
2296 char __user *buf = *bufs + samples_to_bytes(runtime, off);
2297 if ((err = substream->ops->copy(substream, c, hwoff, buf, frames)) < 0)
2302 /* default transfer behaviour */
2303 size_t dma_csize = runtime->dma_bytes / channels;
2304 snd_assert(runtime->dma_area, return -EFAULT);
2305 for (c = 0; c < channels; ++c, ++bufs) {
2306 char *hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, hwoff);
2307 if (*bufs == NULL) {
2308 snd_pcm_format_set_silence(runtime->format, hwbuf, frames);
2310 char __user *buf = *bufs + samples_to_bytes(runtime, off);
2311 if (copy_from_user(hwbuf, buf, samples_to_bytes(runtime, frames)))
2319 snd_pcm_sframes_t snd_pcm_lib_writev(snd_pcm_substream_t *substream,
2321 snd_pcm_uframes_t frames)
2323 snd_pcm_runtime_t *runtime;
2326 snd_assert(substream != NULL, return -ENXIO);
2327 runtime = substream->runtime;
2328 snd_assert(runtime != NULL, return -ENXIO);
2329 snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
2330 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
2333 snd_assert(substream->ffile != NULL, return -ENXIO);
2334 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK);
2335 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
2336 if (substream->oss.oss) {
2337 snd_pcm_oss_setup_t *setup = substream->oss.setup;
2338 if (setup != NULL) {
2339 if (setup->nonblock)
2341 else if (setup->block)
2347 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
2349 return snd_pcm_lib_write1(substream, (unsigned long)bufs, frames,
2350 nonblock, snd_pcm_lib_writev_transfer);
2353 static int snd_pcm_lib_read_transfer(snd_pcm_substream_t *substream,
2355 unsigned long data, unsigned int off,
2356 snd_pcm_uframes_t frames)
2358 snd_pcm_runtime_t *runtime = substream->runtime;
2360 char __user *buf = (char __user *) data + frames_to_bytes(runtime, off);
2361 if (substream->ops->copy) {
2362 if ((err = substream->ops->copy(substream, -1, hwoff, buf, frames)) < 0)
2365 char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff);
2366 snd_assert(runtime->dma_area, return -EFAULT);
2367 if (copy_to_user(buf, hwbuf, frames_to_bytes(runtime, frames)))
2373 static snd_pcm_sframes_t snd_pcm_lib_read1(snd_pcm_substream_t *substream,
2375 snd_pcm_uframes_t size,
2377 transfer_f transfer)
2379 snd_pcm_runtime_t *runtime = substream->runtime;
2380 snd_pcm_uframes_t xfer = 0;
2381 snd_pcm_uframes_t offset = 0;
2386 if (size > runtime->xfer_align)
2387 size -= size % runtime->xfer_align;
2389 snd_pcm_stream_lock_irq(substream);
2390 switch (runtime->status->state) {
2391 case SNDRV_PCM_STATE_PREPARED:
2392 if (size >= runtime->start_threshold) {
2393 err = snd_pcm_start(substream);
2398 case SNDRV_PCM_STATE_DRAINING:
2399 case SNDRV_PCM_STATE_RUNNING:
2400 case SNDRV_PCM_STATE_PAUSED:
2402 case SNDRV_PCM_STATE_XRUN:
2405 case SNDRV_PCM_STATE_SUSPENDED:
2414 snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
2415 snd_pcm_uframes_t avail;
2416 snd_pcm_uframes_t cont;
2417 if (runtime->sleep_min == 0 && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2418 snd_pcm_update_hw_ptr(substream);
2420 avail = snd_pcm_capture_avail(runtime);
2421 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
2422 if (avail < runtime->xfer_align) {
2426 } else if ((avail < runtime->control->avail_min && size > avail) ||
2427 (size >= runtime->xfer_align && avail < runtime->xfer_align)) {
2429 enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED } state;
2437 init_waitqueue_entry(&wait, current);
2438 add_wait_queue(&runtime->sleep, &wait);
2440 if (signal_pending(current)) {
2444 set_current_state(TASK_INTERRUPTIBLE);
2445 snd_pcm_stream_unlock_irq(substream);
2446 tout = schedule_timeout(10 * HZ);
2447 snd_pcm_stream_lock_irq(substream);
2449 if (runtime->status->state != SNDRV_PCM_STATE_PREPARED &&
2450 runtime->status->state != SNDRV_PCM_STATE_PAUSED) {
2451 state = runtime->status->state == SNDRV_PCM_STATE_SUSPENDED ? SUSPENDED : EXPIRED;
2455 switch (runtime->status->state) {
2456 case SNDRV_PCM_STATE_XRUN:
2459 case SNDRV_PCM_STATE_SUSPENDED:
2462 case SNDRV_PCM_STATE_DRAINING:
2467 avail = snd_pcm_capture_avail(runtime);
2468 if (avail >= runtime->control->avail_min) {
2474 remove_wait_queue(&runtime->sleep, &wait);
2487 snd_printd("capture read error (DMA or IRQ trouble?)\n");
2494 if (avail > runtime->xfer_align)
2495 avail -= avail % runtime->xfer_align;
2496 frames = size > avail ? avail : size;
2497 cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size;
2500 snd_assert(frames != 0, snd_pcm_stream_unlock_irq(substream); return -EINVAL);
2501 appl_ptr = runtime->control->appl_ptr;
2502 appl_ofs = appl_ptr % runtime->buffer_size;
2503 snd_pcm_stream_unlock_irq(substream);
2504 if ((err = transfer(substream, appl_ofs, data, offset, frames)) < 0)
2506 snd_pcm_stream_lock_irq(substream);
2507 switch (runtime->status->state) {
2508 case SNDRV_PCM_STATE_XRUN:
2511 case SNDRV_PCM_STATE_SUSPENDED:
2518 if (appl_ptr >= runtime->boundary) {
2519 runtime->control->appl_ptr = 0;
2521 runtime->control->appl_ptr = appl_ptr;
2523 if (substream->ops->ack)
2524 substream->ops->ack(substream);
2529 if (runtime->sleep_min &&
2530 runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2531 snd_pcm_tick_prepare(substream);
2534 snd_pcm_stream_unlock_irq(substream);
2536 return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
2539 snd_pcm_sframes_t snd_pcm_lib_read(snd_pcm_substream_t *substream, void __user *buf, snd_pcm_uframes_t size)
2541 snd_pcm_runtime_t *runtime;
2544 snd_assert(substream != NULL, return -ENXIO);
2545 runtime = substream->runtime;
2546 snd_assert(runtime != NULL, return -ENXIO);
2547 snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
2548 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
2551 snd_assert(substream->ffile != NULL, return -ENXIO);
2552 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK);
2553 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
2554 if (substream->oss.oss) {
2555 snd_pcm_oss_setup_t *setup = substream->oss.setup;
2556 if (setup != NULL) {
2557 if (setup->nonblock)
2559 else if (setup->block)
2564 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED)
2566 return snd_pcm_lib_read1(substream, (unsigned long)buf, size, nonblock, snd_pcm_lib_read_transfer);
2569 static int snd_pcm_lib_readv_transfer(snd_pcm_substream_t *substream,
2571 unsigned long data, unsigned int off,
2572 snd_pcm_uframes_t frames)
2574 snd_pcm_runtime_t *runtime = substream->runtime;
2576 void __user **bufs = (void __user **)data;
2577 int channels = runtime->channels;
2579 if (substream->ops->copy) {
2580 for (c = 0; c < channels; ++c, ++bufs) {
2584 buf = *bufs + samples_to_bytes(runtime, off);
2585 if ((err = substream->ops->copy(substream, c, hwoff, buf, frames)) < 0)
2589 snd_pcm_uframes_t dma_csize = runtime->dma_bytes / channels;
2590 snd_assert(runtime->dma_area, return -EFAULT);
2591 for (c = 0; c < channels; ++c, ++bufs) {
2597 hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, hwoff);
2598 buf = *bufs + samples_to_bytes(runtime, off);
2599 if (copy_to_user(buf, hwbuf, samples_to_bytes(runtime, frames)))
2606 snd_pcm_sframes_t snd_pcm_lib_readv(snd_pcm_substream_t *substream,
2608 snd_pcm_uframes_t frames)
2610 snd_pcm_runtime_t *runtime;
2613 snd_assert(substream != NULL, return -ENXIO);
2614 runtime = substream->runtime;
2615 snd_assert(runtime != NULL, return -ENXIO);
2616 snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
2617 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
2620 snd_assert(substream->ffile != NULL, return -ENXIO);
2621 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK);
2622 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
2623 if (substream->oss.oss) {
2624 snd_pcm_oss_setup_t *setup = substream->oss.setup;
2625 if (setup != NULL) {
2626 if (setup->nonblock)
2628 else if (setup->block)
2634 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
2636 return snd_pcm_lib_read1(substream, (unsigned long)bufs, frames, nonblock, snd_pcm_lib_readv_transfer);
2643 EXPORT_SYMBOL(snd_interval_refine);
2644 EXPORT_SYMBOL(snd_interval_list);
2645 EXPORT_SYMBOL(snd_interval_ratnum);
2646 EXPORT_SYMBOL(snd_interval_ratden);
2647 EXPORT_SYMBOL(snd_interval_muldivk);
2648 EXPORT_SYMBOL(snd_interval_mulkdiv);
2649 EXPORT_SYMBOL(snd_interval_div);
2650 EXPORT_SYMBOL(_snd_pcm_hw_params_any);
2651 EXPORT_SYMBOL(_snd_pcm_hw_param_min);
2652 EXPORT_SYMBOL(_snd_pcm_hw_param_set);
2653 EXPORT_SYMBOL(_snd_pcm_hw_param_setempty);
2654 EXPORT_SYMBOL(_snd_pcm_hw_param_setinteger);
2655 EXPORT_SYMBOL(snd_pcm_hw_param_value_min);
2656 EXPORT_SYMBOL(snd_pcm_hw_param_value_max);
2657 EXPORT_SYMBOL(snd_pcm_hw_param_mask);
2658 EXPORT_SYMBOL(snd_pcm_hw_param_first);
2659 EXPORT_SYMBOL(snd_pcm_hw_param_last);
2660 EXPORT_SYMBOL(snd_pcm_hw_param_near);
2661 EXPORT_SYMBOL(snd_pcm_hw_param_set);
2662 EXPORT_SYMBOL(snd_pcm_hw_refine);
2663 EXPORT_SYMBOL(snd_pcm_hw_params);
2664 EXPORT_SYMBOL(snd_pcm_hw_constraints_init);
2665 EXPORT_SYMBOL(snd_pcm_hw_constraints_complete);
2666 EXPORT_SYMBOL(snd_pcm_hw_constraint_list);
2667 EXPORT_SYMBOL(snd_pcm_hw_constraint_step);
2668 EXPORT_SYMBOL(snd_pcm_hw_constraint_ratnums);
2669 EXPORT_SYMBOL(snd_pcm_hw_constraint_ratdens);
2670 EXPORT_SYMBOL(snd_pcm_hw_constraint_msbits);
2671 EXPORT_SYMBOL(snd_pcm_hw_constraint_minmax);
2672 EXPORT_SYMBOL(snd_pcm_hw_constraint_integer);
2673 EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2);
2674 EXPORT_SYMBOL(snd_pcm_hw_rule_add);
2675 EXPORT_SYMBOL(snd_pcm_set_ops);
2676 EXPORT_SYMBOL(snd_pcm_set_sync);
2677 EXPORT_SYMBOL(snd_pcm_lib_ioctl);
2678 EXPORT_SYMBOL(snd_pcm_playback_ready);
2679 EXPORT_SYMBOL(snd_pcm_capture_ready);
2680 EXPORT_SYMBOL(snd_pcm_playback_data);
2681 EXPORT_SYMBOL(snd_pcm_capture_empty);
2682 EXPORT_SYMBOL(snd_pcm_stop);
2683 EXPORT_SYMBOL(snd_pcm_period_elapsed);
2684 EXPORT_SYMBOL(snd_pcm_lib_write);
2685 EXPORT_SYMBOL(snd_pcm_lib_read);
2686 EXPORT_SYMBOL(snd_pcm_lib_writev);
2687 EXPORT_SYMBOL(snd_pcm_lib_readv);
2688 EXPORT_SYMBOL(snd_pcm_lib_buffer_bytes);
2689 EXPORT_SYMBOL(snd_pcm_lib_period_bytes);
2691 EXPORT_SYMBOL(snd_pcm_lib_preallocate_free);
2692 EXPORT_SYMBOL(snd_pcm_lib_preallocate_free_for_all);
2693 EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages);
2694 EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages_for_all);
2695 EXPORT_SYMBOL(snd_pcm_sgbuf_ops_page);
2696 EXPORT_SYMBOL(snd_pcm_lib_malloc_pages);
2697 EXPORT_SYMBOL(snd_pcm_lib_free_pages);