All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH 09/19] ALSA: fireworks: configure stream parameters in pcm.hw_params callback
Date: Wed, 12 Jun 2019 17:44:12 +0900	[thread overview]
Message-ID: <20190612084422.5344-10-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20190612084422.5344-1-o-takashi@sakamocchi.jp>

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

This commit splits out an operation to configure stream parameters into
pcm.hw_params callback. In pcm.prepare callback, establishing
connections and start isochronous contexts.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/firewire/fireworks/fireworks_stream.c | 82 ++++++++++++---------
 1 file changed, 49 insertions(+), 33 deletions(-)

diff --git a/sound/firewire/fireworks/fireworks_stream.c b/sound/firewire/fireworks/fireworks_stream.c
index e1ebead583e9..1abc15760513 100644
--- a/sound/firewire/fireworks/fireworks_stream.c
+++ b/sound/firewire/fireworks/fireworks_stream.c
@@ -52,54 +52,38 @@ stop_stream(struct snd_efw *efw, struct amdtp_stream *stream)
 		cmp_connection_break(&efw->in_conn);
 }
 
-static int
-start_stream(struct snd_efw *efw, struct amdtp_stream *stream,
-	     unsigned int sampling_rate)
+static int start_stream(struct snd_efw *efw, struct amdtp_stream *stream,
+			unsigned int rate)
 {
 	struct cmp_connection *conn;
-	unsigned int mode, pcm_channels, midi_ports;
 	int err;
 
-	err = snd_efw_get_multiplier_mode(sampling_rate, &mode);
-	if (err < 0)
-		goto end;
-	if (stream == &efw->tx_stream) {
+	if (stream == &efw->tx_stream)
 		conn = &efw->out_conn;
-		pcm_channels = efw->pcm_capture_channels[mode];
-		midi_ports = efw->midi_out_ports;
-	} else {
+	else
 		conn = &efw->in_conn;
-		pcm_channels = efw->pcm_playback_channels[mode];
-		midi_ports = efw->midi_in_ports;
-	}
 
-	err = amdtp_am824_set_parameters(stream, sampling_rate,
-					 pcm_channels, midi_ports, false);
-	if (err < 0)
-		goto end;
-
-	/*  establish connection via CMP */
+	// Establish connection via CMP.
 	err = cmp_connection_establish(conn,
-				amdtp_stream_get_max_payload(stream));
+				       amdtp_stream_get_max_payload(stream));
 	if (err < 0)
-		goto end;
+		return err;
 
-	/* start amdtp stream */
-	err = amdtp_stream_start(stream,
-				 conn->resources.channel,
-				 conn->speed);
+	// Start amdtp stream.
+	err = amdtp_stream_start(stream, conn->resources.channel, conn->speed);
 	if (err < 0) {
-		stop_stream(efw, stream);
-		goto end;
+		cmp_connection_break(conn);
+		return err;
 	}
 
-	/* wait first callback */
+	// Wait first callback.
 	if (!amdtp_stream_wait_callback(stream, CALLBACK_TIMEOUT)) {
-		stop_stream(efw, stream);
-		err = -ETIMEDOUT;
+		amdtp_stream_stop(stream);
+		cmp_connection_break(conn);
+		return -ETIMEDOUT;
 	}
-end:
-	return err;
+
+	return 0;
 }
 
 /*
@@ -189,6 +173,24 @@ int snd_efw_stream_init_duplex(struct snd_efw *efw)
 	return err;
 }
 
+static int keep_resources(struct snd_efw *efw, struct amdtp_stream *stream,
+			  unsigned int rate, unsigned int mode)
+{
+	unsigned int pcm_channels;
+	unsigned int midi_ports;
+
+	if (stream == &efw->tx_stream) {
+		pcm_channels = efw->pcm_capture_channels[mode];
+		midi_ports = efw->midi_out_ports;
+	} else {
+		pcm_channels = efw->pcm_playback_channels[mode];
+		midi_ports = efw->midi_in_ports;
+	}
+
+	return amdtp_am824_set_parameters(stream, rate, pcm_channels,
+					  midi_ports, false);
+}
+
 int snd_efw_stream_reserve_duplex(struct snd_efw *efw, unsigned int rate)
 {
 	unsigned int curr_rate;
@@ -212,9 +214,23 @@ int snd_efw_stream_reserve_duplex(struct snd_efw *efw, unsigned int rate)
 	}
 
 	if (efw->substreams_counter == 0 || rate != curr_rate) {
+		unsigned int mode;
+
 		err = snd_efw_command_set_sampling_rate(efw, rate);
 		if (err < 0)
 			return err;
+
+		err = snd_efw_get_multiplier_mode(rate, &mode);
+		if (err < 0)
+			return err;
+
+		err = keep_resources(efw, &efw->tx_stream, rate, mode);
+		if (err < 0)
+			return err;
+
+		err = keep_resources(efw, &efw->rx_stream, rate, mode);
+		if (err < 0)
+			return err;
 	}
 
 	return 0;
-- 
2.20.1

  parent reply	other threads:[~2019-06-12  8:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-12  8:44 [PATCH 00/19] ALSA: bebob/fireworks/oxfw: code refactoring toward rework for reservation of isochronous resources Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 01/19] ALSA: bebob: configure sampling transfer frequency in pcm.hw_params callback Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 02/19] ALSA: bebob: don't set XRUN in stop streaming Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 03/19] ALSA: bebob: obsolete useless member of private structure Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 04/19] ALSA: bebob: code refactoring to initialize/destroy stream data Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 05/19] ALSA: fireworks: unify substream counter Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 06/19] ALSA: fireworks: code refactoring for rawmidi.open/close Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 07/19] ALSA: fireworks: code refactoring for pcm.hw_params/hw_free Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 08/19] ALSA: fireworks: configure sampling transfer frequency in pcm.hw_params callback Takashi Sakamoto
2019-06-12  8:44 ` Takashi Sakamoto [this message]
2019-06-12  8:44 ` [PATCH 10/19] ALSA: fireworks: don't set XRUN in stop streaming Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 11/19] ALSA: oxfw: code refactoring for stop condition of packet streaming Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 12/19] ALSA: oxfw: set packet parameter according to current configuration Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 13/19] ALSA: oxfw: start duplex streams if supported Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 14/19] ALSA: oxfw: break packet streaming at bus-reset handler Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 15/19] ALSA: oxfw: expand stop procedure for packet streaming Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 16/19] ALSA: oxfw: rename helper functions for duplex streams Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 17/19] ALSA: oxfw: unify substreams counter Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 18/19] ALSA: oxfw: configure packet format in pcm.hw_params callback Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 19/19] ALSA: oxfw: configure stream parameter " Takashi Sakamoto
2019-06-12 13:30 ` [PATCH 00/19] ALSA: bebob/fireworks/oxfw: code refactoring toward rework for reservation of isochronous resources Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190612084422.5344-10-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.