alsa-devel.alsa-project.org archive mirror
 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 07/14] ALSA: firewire-motu: add alternative functions to detect packet format for protocol v2
Date: Tue, 19 May 2020 20:16:34 +0900	[thread overview]
Message-ID: <20200519111641.123211-8-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20200519111641.123211-1-o-takashi@sakamocchi.jp>

This commit adds alternative functions to detect packet format so that
each function corresponds to each model.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/firewire/motu/motu-protocol-v2.c | 72 +++++++++++++++++++++++---
 sound/firewire/motu/motu.h             |  1 +
 2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/sound/firewire/motu/motu-protocol-v2.c b/sound/firewire/motu/motu-protocol-v2.c
index 6cd7a5f1f46c..cd409efe3350 100644
--- a/sound/firewire/motu/motu-protocol-v2.c
+++ b/sound/firewire/motu/motu-protocol-v2.c
@@ -164,7 +164,7 @@ int snd_motu_protocol_v2_switch_fetching_mode(struct snd_motu *motu,
 	if (enable)
 		data |= V2_CLOCK_FETCH_ENABLE;
 
-	if (motu->spec->flags & SND_MOTU_SPEC_SUPPORT_CLOCK_X4) {
+	if (motu->spec == &snd_motu_spec_traveler) {
 		// Expected for Traveler and 896HD, which implements Altera
 		// Cyclone EP1C3.
 		data |= V2_CLOCK_MODEL_SPECIFIC;
@@ -193,8 +193,6 @@ static void calculate_fixed_part(struct snd_motu_packet_format *formats,
 {
 	unsigned char pcm_chunks[3] = {0, 0, 0};
 
-	formats->msg_chunks = 2;
-
 	pcm_chunks[0] = analog_ports;
 	pcm_chunks[1] = analog_ports;
 	if (flags & SND_MOTU_SPEC_SUPPORT_CLOCK_X4)
@@ -268,12 +266,69 @@ static void calculate_differed_part(struct snd_motu_packet_format *formats,
 	formats->differed_part_pcm_chunks[1] = pcm_chunks[1];
 }
 
+static int detect_packet_formats_828mk2(struct snd_motu *motu, u32 data)
+{
+	if (((data & V2_OPT_IN_IFACE_MASK) >> V2_OPT_IN_IFACE_SHIFT) ==
+	    V2_OPT_IFACE_MODE_ADAT) {
+		motu->tx_packet_formats.pcm_chunks[0] += 8;
+		motu->tx_packet_formats.pcm_chunks[1] += 4;
+	}
+
+	if (((data & V2_OPT_OUT_IFACE_MASK) >> V2_OPT_OUT_IFACE_SHIFT) ==
+	    V2_OPT_IFACE_MODE_ADAT) {
+		motu->rx_packet_formats.pcm_chunks[0] += 8;
+		motu->rx_packet_formats.pcm_chunks[1] += 4;
+	}
+
+	return 0;
+}
+
+static int detect_packet_formats_traveler(struct snd_motu *motu, u32 data)
+{
+	if (((data & V2_OPT_IN_IFACE_MASK) >> V2_OPT_IN_IFACE_SHIFT) ==
+	    V2_OPT_IFACE_MODE_ADAT) {
+		motu->tx_packet_formats.pcm_chunks[0] += 8;
+		motu->tx_packet_formats.pcm_chunks[1] += 4;
+	}
+
+	if (((data & V2_OPT_OUT_IFACE_MASK) >> V2_OPT_OUT_IFACE_SHIFT) ==
+	    V2_OPT_IFACE_MODE_ADAT) {
+		motu->rx_packet_formats.pcm_chunks[0] += 8;
+		motu->rx_packet_formats.pcm_chunks[1] += 4;
+	}
+
+	return 0;
+}
+
+static int detect_packet_formats_8pre(struct snd_motu *motu, u32 data)
+{
+	if (((data & V2_OPT_IN_IFACE_MASK) >> V2_OPT_IN_IFACE_SHIFT) ==
+	    V2_OPT_IFACE_MODE_ADAT) {
+		motu->tx_packet_formats.pcm_chunks[0] += 8;
+		motu->tx_packet_formats.pcm_chunks[1] += 8;
+	}
+
+	if (((data & V2_OPT_OUT_IFACE_MASK) >> V2_OPT_OUT_IFACE_SHIFT) ==
+	    V2_OPT_IFACE_MODE_ADAT) {
+		motu->rx_packet_formats.pcm_chunks[0] += 8;
+		motu->rx_packet_formats.pcm_chunks[1] += 8;
+	}
+
+	return 0;
+}
+
 int snd_motu_protocol_v2_cache_packet_formats(struct snd_motu *motu)
 {
 	__be32 reg;
 	u32 data;
 	int err;
 
+	motu->tx_packet_formats.pcm_byte_offset = 10;
+	motu->rx_packet_formats.pcm_byte_offset = 10;
+
+	motu->tx_packet_formats.msg_chunks = 2;
+	motu->rx_packet_formats.msg_chunks = 2;
+
 	err = snd_motu_transaction_read(motu, V2_IN_OUT_CONF_OFFSET, &reg,
 					sizeof(reg));
 	if (err < 0)
@@ -290,10 +345,15 @@ int snd_motu_protocol_v2_cache_packet_formats(struct snd_motu *motu)
 	calculate_differed_part(&motu->rx_packet_formats, motu->spec->flags,
 			data, V2_OPT_OUT_IFACE_MASK, V2_OPT_OUT_IFACE_SHIFT);
 
-	motu->tx_packet_formats.pcm_byte_offset = 10;
-	motu->rx_packet_formats.pcm_byte_offset = 10;
 
-	return 0;
+	if (motu->spec == &snd_motu_spec_828mk2)
+		return detect_packet_formats_828mk2(motu, data);
+	else if (motu->spec == &snd_motu_spec_traveler)
+		return detect_packet_formats_traveler(motu, data);
+	else if (motu->spec == &snd_motu_spec_8pre)
+		return detect_packet_formats_8pre(motu, data);
+	else
+		return 0;
 }
 
 const struct snd_motu_spec snd_motu_spec_828mk2 = {
diff --git a/sound/firewire/motu/motu.h b/sound/firewire/motu/motu.h
index 790aa34d396f..d071b2342f11 100644
--- a/sound/firewire/motu/motu.h
+++ b/sound/firewire/motu/motu.h
@@ -36,6 +36,7 @@ struct snd_motu_packet_format {
 	unsigned char pcm_byte_offset;
 
 	unsigned char msg_chunks;
+	unsigned char pcm_chunks[3];
 	unsigned char fixed_part_pcm_chunks[3];
 	unsigned char differed_part_pcm_chunks[3];
 };
-- 
2.25.1


  parent reply	other threads:[~2020-05-19 11:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19 11:16 [PATCH 00/14] ALSA: firewire-motu: code refactoring to obsolete protocol structure Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 01/14] ALSA: firewire-motu: move spec data to v2 protocol file Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 02/14] ALSA: firewire-motu: move spec data to v3 " Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 03/14] ALSA: firewire-motu: localize protocol data Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 04/14] ALSA: firewire-motu: add wrapper functions for protocol-dependent operations Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 05/14] ALSA: firewire-motu: drop protocol structure Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 06/14] ALSA: firewire-motu: add model-specific table of chunk count Takashi Sakamoto
2020-05-19 11:16 ` Takashi Sakamoto [this message]
2020-05-19 11:16 ` [PATCH 08/14] ALSA: firewire-motu: add alternative functions to detect packet format for protocol v3 Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 09/14] ALSA: firewire-motu: use table-based calculation of packet formats for proc Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 10/14] ALSA: firewire-motu: use table-based calculation of packet formats for stream management Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 11/14] ALSA: firewire-motu: remove obsoleted codes Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 12/14] ALSA: firewire-motu: refactoring protocol v2 for clock source getter Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 13/14] ALSA: firewire-motu: refactoring protocol v3 " Takashi Sakamoto
2020-05-19 11:16 ` [PATCH 14/14] ALSA: firewire-motu: refactoring protocol v2 for fetching mode switch Takashi Sakamoto
2020-05-22 14:53 ` [PATCH 00/14] ALSA: firewire-motu: code refactoring to obsolete protocol structure 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=20200519111641.123211-8-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).