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 13/14] ALSA: firewire-motu: refactoring protocol v3 for clock source getter
Date: Tue, 19 May 2020 20:16:40 +0900	[thread overview]
Message-ID: <20200519111641.123211-14-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20200519111641.123211-1-o-takashi@sakamocchi.jp>

This commit splits the method to get clock source for protocol
version 3 so that model-dependent operations are explicitly defined.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/firewire/motu/motu-protocol-v3.c | 98 +++++++++++++++++++-------
 1 file changed, 72 insertions(+), 26 deletions(-)

diff --git a/sound/firewire/motu/motu-protocol-v3.c b/sound/firewire/motu/motu-protocol-v3.c
index cc100d7be0bf..fd49d1fcf473 100644
--- a/sound/firewire/motu/motu-protocol-v3.c
+++ b/sound/firewire/motu/motu-protocol-v3.c
@@ -87,54 +87,100 @@ int snd_motu_protocol_v3_set_clock_rate(struct snd_motu *motu,
 	return 0;
 }
 
-int snd_motu_protocol_v3_get_clock_source(struct snd_motu *motu,
-					  enum snd_motu_clock_source *src)
+static int detect_clock_source_828mk3(struct snd_motu *motu, u32 data,
+				      enum snd_motu_clock_source *src)
 {
-	__be32 reg;
-	u32 data;
-	unsigned int val;
-	int err;
-
-	err = snd_motu_transaction_read(motu, V3_CLOCK_STATUS_OFFSET, &reg,
-					sizeof(reg));
-	if (err < 0)
-		return err;
-	data = be32_to_cpu(reg);
-
-	val = data & V3_CLOCK_SOURCE_MASK;
-	if (val == 0x00) {
+	switch (data) {
+	case 0x00:
 		*src = SND_MOTU_CLOCK_SOURCE_INTERNAL;
-	} else if (val == 0x01) {
+		break;
+	case 0x01:
 		*src = SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC;
-	} else if (val == 0x02) {
+		break;
+	case 0x02:
 		*src = SND_MOTU_CLOCK_SOURCE_SPH;
-	} else if (val == 0x10) {
+		break;
+	case 0x10:
 		*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX;
-	} else if (val == 0x18 || val == 0x19) {
-		err = snd_motu_transaction_read(motu, V3_OPT_IFACE_MODE_OFFSET,
-						&reg, sizeof(reg));
+		break;
+	case 0x18:
+	case 0x19:
+	{
+		__be32 reg;
+		u32 options;
+		int err;
+
+		err = snd_motu_transaction_read(motu,
+				V3_OPT_IFACE_MODE_OFFSET, &reg, sizeof(reg));
 		if (err < 0)
 			return err;
-		data = be32_to_cpu(reg);
+		options = be32_to_cpu(reg);
 
-		if (val == 0x18) {
-			if (data & V3_NO_ADAT_OPT_IN_IFACE_A)
+		if (data == 0x18) {
+			if (options & V3_NO_ADAT_OPT_IN_IFACE_A)
 				*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A;
 			else
 				*src = SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A;
 		} else {
-			if (data & V3_NO_ADAT_OPT_IN_IFACE_B)
+			if (options & V3_NO_ADAT_OPT_IN_IFACE_B)
 				*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B;
 			else
 				*src = SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B;
 		}
-	} else {
+
+		break;
+	}
+	default:
 		*src = SND_MOTU_CLOCK_SOURCE_UNKNOWN;
+		break;
 	}
 
 	return 0;
 }
 
+static int v3_detect_clock_source(struct snd_motu *motu, u32 data,
+				  enum snd_motu_clock_source *src)
+{
+	switch (data) {
+	case 0x00:
+		*src = SND_MOTU_CLOCK_SOURCE_INTERNAL;
+		break;
+	case 0x01:
+		*src = SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC;
+		break;
+	case 0x02:
+		*src = SND_MOTU_CLOCK_SOURCE_SPH;
+		break;
+	case 0x10:
+		*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX;
+		break;
+	default:
+		*src = SND_MOTU_CLOCK_SOURCE_UNKNOWN;
+		break;
+	}
+
+	return 0;
+}
+
+int snd_motu_protocol_v3_get_clock_source(struct snd_motu *motu,
+					  enum snd_motu_clock_source *src)
+{
+	__be32 reg;
+	u32 data;
+	int err;
+
+	err = snd_motu_transaction_read(motu, V3_CLOCK_STATUS_OFFSET, &reg,
+					sizeof(reg));
+	if (err < 0)
+		return err;
+	data = be32_to_cpu(reg) & V3_CLOCK_SOURCE_MASK;
+
+	if (motu->spec == &snd_motu_spec_828mk3)
+		return detect_clock_source_828mk3(motu, data, src);
+	else
+		return v3_detect_clock_source(motu, data, src);
+}
+
 int snd_motu_protocol_v3_switch_fetching_mode(struct snd_motu *motu,
 					      bool enable)
 {
-- 
2.25.1


  parent reply	other threads:[~2020-05-19 11:26 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 ` [PATCH 07/14] ALSA: firewire-motu: add alternative functions to detect packet format for protocol v2 Takashi Sakamoto
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 ` Takashi Sakamoto [this message]
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-14-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).