Blob Blame History Raw
From 675398674c4edc2058a1dd632abd5d748b4653c3 Mon Sep 17 00:00:00 2001
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Date: Sun, 14 Jun 2020 23:12:21 +0900
Subject: [PATCH] ALSA: firewire-motu: wait for notification when changing clock configuration for protocol v3
Git-commit: 675398674c4edc2058a1dd632abd5d748b4653c3
Patch-mainline: v5.9-rc1
References: jsc#SLE-16518

It costs expensive to change clock configuration for models of protocol
version 3. In current implementation, speculative strategy is used to
finish the operation; just waiting for 4 seconds. As long as I investigate,
when accepting and changing clock status actually, the device sends
notification with mask.

This commit uses wise way to wait for the notification after changing
sampling clock rate during 4 seconds.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20200614141221.53527-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>

---
 sound/firewire/motu/motu-protocol-v3.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/sound/firewire/motu/motu-protocol-v3.c b/sound/firewire/motu/motu-protocol-v3.c
index 01a47ac7bb2d..4e6b0e449ee4 100644
--- a/sound/firewire/motu/motu-protocol-v3.c
+++ b/sound/firewire/motu/motu-protocol-v3.c
@@ -24,6 +24,9 @@
 #define  V3_NO_ADAT_OPT_OUT_IFACE_A	0x00040000
 #define  V3_NO_ADAT_OPT_OUT_IFACE_B	0x00400000
 
+#define V3_MSG_FLAG_CLK_CHANGED		0x00000002
+#define V3_CLK_WAIT_MSEC		4000
+
 int snd_motu_protocol_v3_get_clock_rate(struct snd_motu *motu,
 					unsigned int *rate)
 {
@@ -79,9 +82,16 @@ int snd_motu_protocol_v3_set_clock_rate(struct snd_motu *motu,
 		return err;
 
 	if (need_to_wait) {
-		/* Cost expensive. */
-		if (msleep_interruptible(4000) > 0)
-			return -EINTR;
+		int result;
+
+		motu->msg = 0;
+		result = wait_event_interruptible_timeout(motu->hwdep_wait,
+					motu->msg & V3_MSG_FLAG_CLK_CHANGED,
+					msecs_to_jiffies(V3_CLK_WAIT_MSEC));
+		if (result < 0)
+			return result;
+		if (result == 0)
+			return -ETIMEDOUT;
 	}
 
 	return 0;
-- 
2.16.4