mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 21:38:32 +08:00
ALSA: firewire: arrange common PCM info/constraints for AMDTP engine applications
In ALSA firewire stack, 8 drivers uses IEC 61883-1/6 engine for data transmission. They have common PCM info/constraints and duplicated codes. This commit unifies the codes into fireiwre-lib. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
c6706de0ce
commit
55799c5ab9
@ -148,8 +148,27 @@ EXPORT_SYMBOL(amdtp_rate_table);
|
||||
int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
|
||||
struct snd_pcm_runtime *runtime)
|
||||
{
|
||||
struct snd_pcm_hardware *hw = &runtime->hw;
|
||||
int err;
|
||||
|
||||
hw->info = SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID;
|
||||
|
||||
/* SNDRV_PCM_INFO_BATCH */
|
||||
hw->periods_min = 2;
|
||||
hw->periods_max = UINT_MAX;
|
||||
|
||||
/* bytes for a frame */
|
||||
hw->period_bytes_min = 4 * hw->channels_max;
|
||||
|
||||
/* Just to prevent from allocating much pages. */
|
||||
hw->period_bytes_max = hw->period_bytes_min * 2048;
|
||||
hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
|
||||
|
||||
/*
|
||||
* Currently firewire-lib processes 16 packets in one software
|
||||
* interrupt callback. This equals to 2msec but actually the
|
||||
|
@ -92,19 +92,6 @@ limit_channels_and_rates(struct snd_pcm_hardware *hw,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
limit_period_and_buffer(struct snd_pcm_hardware *hw)
|
||||
{
|
||||
hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */
|
||||
hw->periods_max = UINT_MAX;
|
||||
|
||||
hw->period_bytes_min = 4 * hw->channels_max; /* bytes for a frame */
|
||||
|
||||
/* Just to prevent from allocating much pages. */
|
||||
hw->period_bytes_max = hw->period_bytes_min * 2048;
|
||||
hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
|
||||
}
|
||||
|
||||
static int
|
||||
pcm_init_hw_params(struct snd_bebob *bebob,
|
||||
struct snd_pcm_substream *substream)
|
||||
@ -114,13 +101,6 @@ pcm_init_hw_params(struct snd_bebob *bebob,
|
||||
struct snd_bebob_stream_formation *formations;
|
||||
int err;
|
||||
|
||||
runtime->hw.info = SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
||||
runtime->hw.formats = AM824_IN_PCM_FORMAT_BITS;
|
||||
s = &bebob->tx_stream;
|
||||
@ -132,7 +112,6 @@ pcm_init_hw_params(struct snd_bebob *bebob,
|
||||
}
|
||||
|
||||
limit_channels_and_rates(&runtime->hw, formations);
|
||||
limit_period_and_buffer(&runtime->hw);
|
||||
|
||||
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
|
||||
hw_rule_channels, formations,
|
||||
|
@ -51,18 +51,6 @@ static int limit_channels_and_rates(struct snd_dice *dice,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void limit_period_and_buffer(struct snd_pcm_hardware *hw)
|
||||
{
|
||||
hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */
|
||||
hw->periods_max = UINT_MAX;
|
||||
|
||||
hw->period_bytes_min = 4 * hw->channels_max; /* byte for a frame */
|
||||
|
||||
/* Just to prevent from allocating much pages. */
|
||||
hw->period_bytes_max = hw->period_bytes_min * 2048;
|
||||
hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
|
||||
}
|
||||
|
||||
static int init_hw_info(struct snd_dice *dice,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
@ -74,13 +62,6 @@ static int init_hw_info(struct snd_dice *dice,
|
||||
unsigned int count, size;
|
||||
int err;
|
||||
|
||||
hw->info = SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID |
|
||||
SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
||||
hw->formats = AM824_IN_PCM_FORMAT_BITS;
|
||||
dir = AMDTP_IN_STREAM;
|
||||
@ -107,7 +88,6 @@ static int init_hw_info(struct snd_dice *dice,
|
||||
substream->pcm->device, size);
|
||||
if (err < 0)
|
||||
return err;
|
||||
limit_period_and_buffer(hw);
|
||||
|
||||
return amdtp_am824_add_pcm_hw_constraints(stream, runtime);
|
||||
}
|
||||
|
@ -58,31 +58,11 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
|
||||
static int pcm_init_hw_params(struct snd_dg00x *dg00x,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
static const struct snd_pcm_hardware hardware = {
|
||||
.info = SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID,
|
||||
.rates = SNDRV_PCM_RATE_44100 |
|
||||
SNDRV_PCM_RATE_48000 |
|
||||
SNDRV_PCM_RATE_88200 |
|
||||
SNDRV_PCM_RATE_96000,
|
||||
.rate_min = 44100,
|
||||
.rate_max = 96000,
|
||||
.channels_min = 10,
|
||||
.channels_max = 18,
|
||||
.period_bytes_min = 4 * 18,
|
||||
.period_bytes_max = 4 * 18 * 2048,
|
||||
.buffer_bytes_max = 4 * 18 * 2048 * 2,
|
||||
.periods_min = 2,
|
||||
.periods_max = UINT_MAX,
|
||||
};
|
||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||
struct snd_pcm_hardware *hw = &runtime->hw;
|
||||
struct amdtp_stream *s;
|
||||
int err;
|
||||
|
||||
substream->runtime->hw = hardware;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
||||
substream->runtime->hw.formats = SNDRV_PCM_FMTBIT_S32;
|
||||
@ -92,6 +72,15 @@ static int pcm_init_hw_params(struct snd_dg00x *dg00x,
|
||||
s = &dg00x->rx_stream;
|
||||
}
|
||||
|
||||
hw->channels_min = 10;
|
||||
hw->channels_max = 18;
|
||||
|
||||
hw->rates = SNDRV_PCM_RATE_44100 |
|
||||
SNDRV_PCM_RATE_48000 |
|
||||
SNDRV_PCM_RATE_88200 |
|
||||
SNDRV_PCM_RATE_96000;
|
||||
snd_pcm_limit_hw_rates(runtime);
|
||||
|
||||
err = snd_pcm_hw_rule_add(substream->runtime, 0,
|
||||
SNDRV_PCM_HW_PARAM_CHANNELS,
|
||||
hw_rule_channels, NULL,
|
||||
|
@ -91,18 +91,6 @@ static void limit_channels_and_rates(struct snd_pcm_hardware *hw,
|
||||
}
|
||||
}
|
||||
|
||||
static void limit_period_and_buffer(struct snd_pcm_hardware *hw)
|
||||
{
|
||||
hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */
|
||||
hw->periods_max = UINT_MAX;
|
||||
|
||||
hw->period_bytes_min = 4 * hw->channels_max; /* bytes for a frame */
|
||||
|
||||
/* Just to prevent from allocating much pages. */
|
||||
hw->period_bytes_max = hw->period_bytes_min * 2048;
|
||||
hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
|
||||
}
|
||||
|
||||
static int pcm_init_hw_params(struct snd_ff *ff,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
@ -111,13 +99,6 @@ static int pcm_init_hw_params(struct snd_ff *ff,
|
||||
const unsigned int *pcm_channels;
|
||||
int err;
|
||||
|
||||
runtime->hw.info = SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
||||
runtime->hw.formats = SNDRV_PCM_FMTBIT_S32;
|
||||
s = &ff->tx_stream;
|
||||
@ -128,9 +109,7 @@ static int pcm_init_hw_params(struct snd_ff *ff,
|
||||
pcm_channels = ff->spec->pcm_playback_channels;
|
||||
}
|
||||
|
||||
/* limit rates */
|
||||
limit_channels_and_rates(&runtime->hw, pcm_channels);
|
||||
limit_period_and_buffer(&runtime->hw);
|
||||
|
||||
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
|
||||
hw_rule_channels, (void *)pcm_channels,
|
||||
|
@ -129,19 +129,6 @@ limit_channels(struct snd_pcm_hardware *hw, unsigned int *pcm_channels)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
limit_period_and_buffer(struct snd_pcm_hardware *hw)
|
||||
{
|
||||
hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */
|
||||
hw->periods_max = UINT_MAX;
|
||||
|
||||
hw->period_bytes_min = 4 * hw->channels_max; /* bytes for a frame */
|
||||
|
||||
/* Just to prevent from allocating much pages. */
|
||||
hw->period_bytes_max = hw->period_bytes_min * 2048;
|
||||
hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
|
||||
}
|
||||
|
||||
static int
|
||||
pcm_init_hw_params(struct snd_efw *efw,
|
||||
struct snd_pcm_substream *substream)
|
||||
@ -151,13 +138,6 @@ pcm_init_hw_params(struct snd_efw *efw,
|
||||
unsigned int *pcm_channels;
|
||||
int err;
|
||||
|
||||
runtime->hw.info = SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
||||
runtime->hw.formats = AM824_IN_PCM_FORMAT_BITS;
|
||||
s = &efw->tx_stream;
|
||||
@ -173,7 +153,6 @@ pcm_init_hw_params(struct snd_efw *efw,
|
||||
snd_pcm_limit_hw_rates(runtime);
|
||||
|
||||
limit_channels(&runtime->hw, pcm_channels);
|
||||
limit_period_and_buffer(&runtime->hw);
|
||||
|
||||
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
|
||||
hw_rule_channels, pcm_channels,
|
||||
|
@ -96,18 +96,6 @@ static void limit_channels_and_rates(struct snd_motu *motu,
|
||||
snd_pcm_limit_hw_rates(runtime);
|
||||
}
|
||||
|
||||
static void limit_period_and_buffer(struct snd_pcm_hardware *hw)
|
||||
{
|
||||
hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */
|
||||
hw->periods_max = UINT_MAX;
|
||||
|
||||
hw->period_bytes_min = 4 * hw->channels_max; /* byte for a frame */
|
||||
|
||||
/* Just to prevent from allocating much pages. */
|
||||
hw->period_bytes_max = hw->period_bytes_min * 2048;
|
||||
hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
|
||||
}
|
||||
|
||||
static int init_hw_info(struct snd_motu *motu,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
@ -117,13 +105,6 @@ static int init_hw_info(struct snd_motu *motu,
|
||||
struct snd_motu_packet_format *formats;
|
||||
int err;
|
||||
|
||||
hw->info = SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID |
|
||||
SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
||||
hw->formats = SNDRV_PCM_FMTBIT_S32;
|
||||
stream = &motu->tx_stream;
|
||||
@ -135,7 +116,6 @@ static int init_hw_info(struct snd_motu *motu,
|
||||
}
|
||||
|
||||
limit_channels_and_rates(motu, runtime, formats);
|
||||
limit_period_and_buffer(hw);
|
||||
|
||||
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
|
||||
motu_rate_constraint, formats,
|
||||
|
@ -106,18 +106,6 @@ static void limit_channels_and_rates(struct snd_pcm_hardware *hw, u8 **formats)
|
||||
}
|
||||
}
|
||||
|
||||
static void limit_period_and_buffer(struct snd_pcm_hardware *hw)
|
||||
{
|
||||
hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */
|
||||
hw->periods_max = UINT_MAX;
|
||||
|
||||
hw->period_bytes_min = 4 * hw->channels_max; /* bytes for a frame */
|
||||
|
||||
/* Just to prevent from allocating much pages. */
|
||||
hw->period_bytes_max = hw->period_bytes_min * 2048;
|
||||
hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;
|
||||
}
|
||||
|
||||
static int init_hw_params(struct snd_oxfw *oxfw,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
@ -126,13 +114,6 @@ static int init_hw_params(struct snd_oxfw *oxfw,
|
||||
struct amdtp_stream *stream;
|
||||
int err;
|
||||
|
||||
runtime->hw.info = SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
||||
runtime->hw.formats = AM824_IN_PCM_FORMAT_BITS;
|
||||
stream = &oxfw->tx_stream;
|
||||
@ -144,7 +125,6 @@ static int init_hw_params(struct snd_oxfw *oxfw,
|
||||
}
|
||||
|
||||
limit_channels_and_rates(&runtime->hw, formats);
|
||||
limit_period_and_buffer(&runtime->hw);
|
||||
|
||||
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
|
||||
hw_rule_channels, formats,
|
||||
|
@ -8,41 +8,14 @@
|
||||
|
||||
#include "tascam.h"
|
||||
|
||||
static void set_buffer_params(struct snd_pcm_hardware *hw)
|
||||
{
|
||||
hw->period_bytes_min = 4 * hw->channels_min;
|
||||
hw->period_bytes_max = hw->period_bytes_min * 2048;
|
||||
hw->buffer_bytes_max = hw->period_bytes_max * 2;
|
||||
|
||||
hw->periods_min = 2;
|
||||
hw->periods_max = UINT_MAX;
|
||||
}
|
||||
|
||||
static int pcm_init_hw_params(struct snd_tscm *tscm,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
static const struct snd_pcm_hardware hardware = {
|
||||
.info = SNDRV_PCM_INFO_BATCH |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_JOINT_DUPLEX |
|
||||
SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID,
|
||||
.rates = SNDRV_PCM_RATE_44100 |
|
||||
SNDRV_PCM_RATE_48000 |
|
||||
SNDRV_PCM_RATE_88200 |
|
||||
SNDRV_PCM_RATE_96000,
|
||||
.rate_min = 44100,
|
||||
.rate_max = 96000,
|
||||
.channels_min = 10,
|
||||
.channels_max = 18,
|
||||
};
|
||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||
struct snd_pcm_hardware *hw = &runtime->hw;
|
||||
struct amdtp_stream *stream;
|
||||
unsigned int pcm_channels;
|
||||
|
||||
runtime->hw = hardware;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
||||
runtime->hw.formats = SNDRV_PCM_FMTBIT_S32;
|
||||
stream = &tscm->tx_stream;
|
||||
@ -59,7 +32,11 @@ static int pcm_init_hw_params(struct snd_tscm *tscm,
|
||||
pcm_channels += 2;
|
||||
runtime->hw.channels_min = runtime->hw.channels_max = pcm_channels;
|
||||
|
||||
set_buffer_params(&runtime->hw);
|
||||
hw->rates = SNDRV_PCM_RATE_44100 |
|
||||
SNDRV_PCM_RATE_48000 |
|
||||
SNDRV_PCM_RATE_88200 |
|
||||
SNDRV_PCM_RATE_96000;
|
||||
snd_pcm_limit_hw_rates(runtime);
|
||||
|
||||
return amdtp_tscm_add_pcm_hw_constraints(stream, runtime);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user