ALSA: oxfw: rename helper functions for duplex streams

In former commits, ALSA oxfw driver handles two isochronous contexts
at the same time, except for some devices which supports one endpoint
of isochronous packet stream.

This commit renames some helper functions so that they handles duplex
streams.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Sakamoto 2019-06-12 17:44:19 +09:00 committed by Takashi Iwai
parent e34244dd22
commit 779f0dba0b
5 changed files with 58 additions and 53 deletions

View File

@ -20,7 +20,7 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream)
mutex_lock(&oxfw->mutex); mutex_lock(&oxfw->mutex);
oxfw->capture_substreams++; oxfw->capture_substreams++;
err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->tx_stream, 0, 0); err = snd_oxfw_stream_start_duplex(oxfw, &oxfw->tx_stream, 0, 0);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);
@ -42,7 +42,7 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream)
mutex_lock(&oxfw->mutex); mutex_lock(&oxfw->mutex);
oxfw->playback_substreams++; oxfw->playback_substreams++;
err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->rx_stream, 0, 0); err = snd_oxfw_stream_start_duplex(oxfw, &oxfw->rx_stream, 0, 0);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);
@ -59,7 +59,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
mutex_lock(&oxfw->mutex); mutex_lock(&oxfw->mutex);
oxfw->capture_substreams--; oxfw->capture_substreams--;
snd_oxfw_stream_stop_simplex(oxfw, &oxfw->tx_stream); snd_oxfw_stream_stop_duplex(oxfw);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);
@ -74,7 +74,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
mutex_lock(&oxfw->mutex); mutex_lock(&oxfw->mutex);
oxfw->playback_substreams--; oxfw->playback_substreams--;
snd_oxfw_stream_stop_simplex(oxfw, &oxfw->rx_stream); snd_oxfw_stream_stop_duplex(oxfw);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);

View File

@ -255,7 +255,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)
oxfw->capture_substreams--; oxfw->capture_substreams--;
snd_oxfw_stream_stop_simplex(oxfw, &oxfw->tx_stream); snd_oxfw_stream_stop_duplex(oxfw);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);
@ -270,7 +270,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)
oxfw->playback_substreams--; oxfw->playback_substreams--;
snd_oxfw_stream_stop_simplex(oxfw, &oxfw->rx_stream); snd_oxfw_stream_stop_duplex(oxfw);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);
@ -284,8 +284,8 @@ static int pcm_capture_prepare(struct snd_pcm_substream *substream)
int err; int err;
mutex_lock(&oxfw->mutex); mutex_lock(&oxfw->mutex);
err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->tx_stream, err = snd_oxfw_stream_start_duplex(oxfw, &oxfw->tx_stream,
runtime->rate, runtime->channels); runtime->rate, runtime->channels);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);
if (err < 0) if (err < 0)
goto end; goto end;
@ -301,8 +301,8 @@ static int pcm_playback_prepare(struct snd_pcm_substream *substream)
int err; int err;
mutex_lock(&oxfw->mutex); mutex_lock(&oxfw->mutex);
err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->rx_stream, err = snd_oxfw_stream_start_duplex(oxfw, &oxfw->rx_stream,
runtime->rate, runtime->channels); runtime->rate, runtime->channels);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);
if (err < 0) if (err < 0)
goto end; goto end;

View File

@ -194,8 +194,7 @@ static int check_connection_used_by_others(struct snd_oxfw *oxfw,
return err; return err;
} }
int snd_oxfw_stream_init_simplex(struct snd_oxfw *oxfw, static int init_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
struct amdtp_stream *stream)
{ {
struct cmp_connection *conn; struct cmp_connection *conn;
enum cmp_direction c_dir; enum cmp_direction c_dir;
@ -214,13 +213,12 @@ int snd_oxfw_stream_init_simplex(struct snd_oxfw *oxfw,
err = cmp_connection_init(conn, oxfw->unit, c_dir, 0); err = cmp_connection_init(conn, oxfw->unit, c_dir, 0);
if (err < 0) if (err < 0)
goto end; return err;
err = amdtp_am824_init(stream, oxfw->unit, s_dir, CIP_NONBLOCKING); err = amdtp_am824_init(stream, oxfw->unit, s_dir, CIP_NONBLOCKING);
if (err < 0) { if (err < 0) {
amdtp_stream_destroy(stream);
cmp_connection_destroy(conn); cmp_connection_destroy(conn);
goto end; return err;
} }
/* /*
@ -234,13 +232,13 @@ int snd_oxfw_stream_init_simplex(struct snd_oxfw *oxfw,
if (oxfw->wrong_dbs) if (oxfw->wrong_dbs)
oxfw->tx_stream.flags |= CIP_WRONG_DBS; oxfw->tx_stream.flags |= CIP_WRONG_DBS;
} }
end:
return err; return 0;
} }
int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw, int snd_oxfw_stream_start_duplex(struct snd_oxfw *oxfw,
struct amdtp_stream *stream, struct amdtp_stream *stream,
unsigned int rate, unsigned int pcm_channels) unsigned int rate, unsigned int pcm_channels)
{ {
struct snd_oxfw_stream_formation formation; struct snd_oxfw_stream_formation formation;
enum avc_general_plug_dir dir; enum avc_general_plug_dir dir;
@ -323,8 +321,7 @@ error:
return err; return err;
} }
void snd_oxfw_stream_stop_simplex(struct snd_oxfw *oxfw, void snd_oxfw_stream_stop_duplex(struct snd_oxfw *oxfw)
struct amdtp_stream *stream)
{ {
if (oxfw->capture_substreams == 0 && oxfw->playback_substreams == 0) { if (oxfw->capture_substreams == 0 && oxfw->playback_substreams == 0) {
amdtp_stream_stop(&oxfw->rx_stream); amdtp_stream_stop(&oxfw->rx_stream);
@ -337,12 +334,7 @@ void snd_oxfw_stream_stop_simplex(struct snd_oxfw *oxfw,
} }
} }
/* static void destroy_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
* This function should be called before starting the stream or after stopping
* the streams.
*/
void snd_oxfw_stream_destroy_simplex(struct snd_oxfw *oxfw,
struct amdtp_stream *stream)
{ {
struct cmp_connection *conn; struct cmp_connection *conn;
@ -355,8 +347,36 @@ void snd_oxfw_stream_destroy_simplex(struct snd_oxfw *oxfw,
cmp_connection_destroy(conn); cmp_connection_destroy(conn);
} }
void snd_oxfw_stream_update_simplex(struct snd_oxfw *oxfw, int snd_oxfw_stream_init_duplex(struct snd_oxfw *oxfw)
struct amdtp_stream *stream) {
int err;
err = init_stream(oxfw, &oxfw->rx_stream);
if (err < 0)
return err;
if (oxfw->has_output) {
err = init_stream(oxfw, &oxfw->tx_stream);
if (err < 0) {
destroy_stream(oxfw, &oxfw->rx_stream);
return err;
}
}
return 0;
}
// This function should be called before starting the stream or after stopping
// the streams.
void snd_oxfw_stream_destroy_duplex(struct snd_oxfw *oxfw)
{
destroy_stream(oxfw, &oxfw->rx_stream);
if (oxfw->has_output)
destroy_stream(oxfw, &oxfw->tx_stream);
}
void snd_oxfw_stream_update_duplex(struct snd_oxfw *oxfw)
{ {
amdtp_stream_stop(&oxfw->rx_stream); amdtp_stream_stop(&oxfw->rx_stream);
cmp_connection_break(&oxfw->in_conn); cmp_connection_break(&oxfw->in_conn);

View File

@ -118,9 +118,7 @@ static void oxfw_card_free(struct snd_card *card)
{ {
struct snd_oxfw *oxfw = card->private_data; struct snd_oxfw *oxfw = card->private_data;
snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); snd_oxfw_stream_destroy_duplex(oxfw);
if (oxfw->has_output)
snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
} }
static int detect_quirks(struct snd_oxfw *oxfw) static int detect_quirks(struct snd_oxfw *oxfw)
@ -211,14 +209,9 @@ static void do_registration(struct work_struct *work)
if (err < 0) if (err < 0)
goto error; goto error;
err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream); err = snd_oxfw_stream_init_duplex(oxfw);
if (err < 0) if (err < 0)
goto error; goto error;
if (oxfw->has_output) {
err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream);
if (err < 0)
goto error;
}
err = snd_oxfw_create_pcm(oxfw); err = snd_oxfw_create_pcm(oxfw);
if (err < 0) if (err < 0)
@ -285,11 +278,7 @@ static void oxfw_bus_reset(struct fw_unit *unit)
if (oxfw->registered) { if (oxfw->registered) {
mutex_lock(&oxfw->mutex); mutex_lock(&oxfw->mutex);
snd_oxfw_stream_update_duplex(oxfw);
snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream);
if (oxfw->has_output)
snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream);
mutex_unlock(&oxfw->mutex); mutex_unlock(&oxfw->mutex);
if (oxfw->entry->vendor_id == OUI_STANTON) if (oxfw->entry->vendor_id == OUI_STANTON)

View File

@ -99,17 +99,13 @@ int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate,
enum avc_general_plug_dir dir, enum avc_general_plug_dir dir,
unsigned short pid); unsigned short pid);
int snd_oxfw_stream_init_simplex(struct snd_oxfw *oxfw, int snd_oxfw_stream_init_duplex(struct snd_oxfw *oxfw);
struct amdtp_stream *stream); int snd_oxfw_stream_start_duplex(struct snd_oxfw *oxfw,
int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw,
struct amdtp_stream *stream, struct amdtp_stream *stream,
unsigned int rate, unsigned int pcm_channels); unsigned int rate, unsigned int pcm_channels);
void snd_oxfw_stream_stop_simplex(struct snd_oxfw *oxfw, void snd_oxfw_stream_stop_duplex(struct snd_oxfw *oxfw);
struct amdtp_stream *stream); void snd_oxfw_stream_destroy_duplex(struct snd_oxfw *oxfw);
void snd_oxfw_stream_destroy_simplex(struct snd_oxfw *oxfw, void snd_oxfw_stream_update_duplex(struct snd_oxfw *oxfw);
struct amdtp_stream *stream);
void snd_oxfw_stream_update_simplex(struct snd_oxfw *oxfw,
struct amdtp_stream *stream);
struct snd_oxfw_stream_formation { struct snd_oxfw_stream_formation {
unsigned int rate; unsigned int rate;