Commit 1dc59210 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai

ALSA: fireworks: unify substream counter

This commit is a part of preparation to perform allocation/release
of isochronous resources in pcm.hw_params/hw_free callbacks.

It's inconvenient to handle two isochronous context separately
each other. This commit unifies the counters to handle the two
at the same time.
Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 33e41a5c
...@@ -89,8 +89,7 @@ struct snd_efw { ...@@ -89,8 +89,7 @@ struct snd_efw {
struct amdtp_stream rx_stream; struct amdtp_stream rx_stream;
struct cmp_connection out_conn; struct cmp_connection out_conn;
struct cmp_connection in_conn; struct cmp_connection in_conn;
unsigned int capture_substreams; unsigned int substreams_counter;
unsigned int playback_substreams;
/* hardware metering parameters */ /* hardware metering parameters */
unsigned int phys_out; unsigned int phys_out;
......
...@@ -18,7 +18,7 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream) ...@@ -18,7 +18,7 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream)
goto end; goto end;
mutex_lock(&efw->mutex); mutex_lock(&efw->mutex);
efw->capture_substreams++; ++efw->substreams_counter;
err = snd_efw_stream_start_duplex(efw, 0); err = snd_efw_stream_start_duplex(efw, 0);
mutex_unlock(&efw->mutex); mutex_unlock(&efw->mutex);
if (err < 0) if (err < 0)
...@@ -38,7 +38,7 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream) ...@@ -38,7 +38,7 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream)
goto end; goto end;
mutex_lock(&efw->mutex); mutex_lock(&efw->mutex);
efw->playback_substreams++; ++efw->substreams_counter;
err = snd_efw_stream_start_duplex(efw, 0); err = snd_efw_stream_start_duplex(efw, 0);
mutex_unlock(&efw->mutex); mutex_unlock(&efw->mutex);
if (err < 0) if (err < 0)
...@@ -52,7 +52,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream) ...@@ -52,7 +52,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
struct snd_efw *efw = substream->rmidi->private_data; struct snd_efw *efw = substream->rmidi->private_data;
mutex_lock(&efw->mutex); mutex_lock(&efw->mutex);
efw->capture_substreams--; --efw->substreams_counter;
snd_efw_stream_stop_duplex(efw); snd_efw_stream_stop_duplex(efw);
mutex_unlock(&efw->mutex); mutex_unlock(&efw->mutex);
...@@ -65,7 +65,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream) ...@@ -65,7 +65,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
struct snd_efw *efw = substream->rmidi->private_data; struct snd_efw *efw = substream->rmidi->private_data;
mutex_lock(&efw->mutex); mutex_lock(&efw->mutex);
efw->playback_substreams--; --efw->substreams_counter;
snd_efw_stream_stop_duplex(efw); snd_efw_stream_stop_duplex(efw);
mutex_unlock(&efw->mutex); mutex_unlock(&efw->mutex);
......
...@@ -232,7 +232,7 @@ static int pcm_capture_hw_params(struct snd_pcm_substream *substream, ...@@ -232,7 +232,7 @@ static int pcm_capture_hw_params(struct snd_pcm_substream *substream,
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
mutex_lock(&efw->mutex); mutex_lock(&efw->mutex);
efw->capture_substreams++; ++efw->substreams_counter;
mutex_unlock(&efw->mutex); mutex_unlock(&efw->mutex);
} }
...@@ -251,7 +251,7 @@ static int pcm_playback_hw_params(struct snd_pcm_substream *substream, ...@@ -251,7 +251,7 @@ static int pcm_playback_hw_params(struct snd_pcm_substream *substream,
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
mutex_lock(&efw->mutex); mutex_lock(&efw->mutex);
efw->playback_substreams++; ++efw->substreams_counter;
mutex_unlock(&efw->mutex); mutex_unlock(&efw->mutex);
} }
...@@ -264,7 +264,7 @@ static int pcm_capture_hw_free(struct snd_pcm_substream *substream) ...@@ -264,7 +264,7 @@ static int pcm_capture_hw_free(struct snd_pcm_substream *substream)
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) { if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
mutex_lock(&efw->mutex); mutex_lock(&efw->mutex);
efw->capture_substreams--; --efw->substreams_counter;
mutex_unlock(&efw->mutex); mutex_unlock(&efw->mutex);
} }
...@@ -278,7 +278,7 @@ static int pcm_playback_hw_free(struct snd_pcm_substream *substream) ...@@ -278,7 +278,7 @@ static int pcm_playback_hw_free(struct snd_pcm_substream *substream)
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) { if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
mutex_lock(&efw->mutex); mutex_lock(&efw->mutex);
efw->playback_substreams--; --efw->substreams_counter;
mutex_unlock(&efw->mutex); mutex_unlock(&efw->mutex);
} }
......
...@@ -194,9 +194,9 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate) ...@@ -194,9 +194,9 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
unsigned int curr_rate; unsigned int curr_rate;
int err = 0; int err = 0;
/* Need no substreams */ // Need no substreams.
if (efw->playback_substreams == 0 && efw->capture_substreams == 0) if (efw->substreams_counter == 0)
goto end; return -EIO;
/* /*
* Considering JACK/FFADO streaming: * Considering JACK/FFADO streaming:
...@@ -206,19 +206,15 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate) ...@@ -206,19 +206,15 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
if (err < 0) if (err < 0)
goto end; goto end;
/* packet queueing error */
if (amdtp_streaming_error(&efw->tx_stream))
stop_stream(efw, &efw->tx_stream);
if (amdtp_streaming_error(&efw->rx_stream))
stop_stream(efw, &efw->rx_stream);
/* stop streams if rate is different */ /* stop streams if rate is different */
err = snd_efw_command_get_sampling_rate(efw, &curr_rate); err = snd_efw_command_get_sampling_rate(efw, &curr_rate);
if (err < 0) if (err < 0)
goto end; goto end;
if (rate == 0) if (rate == 0)
rate = curr_rate; rate = curr_rate;
if (rate != curr_rate) { if (rate != curr_rate ||
amdtp_streaming_error(&efw->tx_stream) ||
amdtp_streaming_error(&efw->rx_stream)) {
stop_stream(efw, &efw->tx_stream); stop_stream(efw, &efw->tx_stream);
stop_stream(efw, &efw->rx_stream); stop_stream(efw, &efw->rx_stream);
} }
...@@ -237,13 +233,12 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate) ...@@ -237,13 +233,12 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
} }
} }
/* start slave if needed */ if (!amdtp_stream_running(&efw->tx_stream)) {
if (efw->capture_substreams > 0 &&
!amdtp_stream_running(&efw->tx_stream)) {
err = start_stream(efw, &efw->tx_stream, rate); err = start_stream(efw, &efw->tx_stream, rate);
if (err < 0) { if (err < 0) {
dev_err(&efw->unit->device, dev_err(&efw->unit->device,
"fail to start AMDTP slave stream:%d\n", err); "fail to start AMDTP slave stream:%d\n", err);
stop_stream(efw, &efw->tx_stream);
stop_stream(efw, &efw->rx_stream); stop_stream(efw, &efw->rx_stream);
} }
} }
...@@ -253,10 +248,8 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate) ...@@ -253,10 +248,8 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
void snd_efw_stream_stop_duplex(struct snd_efw *efw) void snd_efw_stream_stop_duplex(struct snd_efw *efw)
{ {
if (efw->capture_substreams == 0) { if (efw->substreams_counter == 0) {
stop_stream(efw, &efw->tx_stream); stop_stream(efw, &efw->tx_stream);
if (efw->playback_substreams == 0)
stop_stream(efw, &efw->rx_stream); stop_stream(efw, &efw->rx_stream);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment