summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2019-09-10 09:51:52 -0400
committerTakashi Iwai <tiwai@suse.de>2019-09-10 10:16:46 -0400
commite1a00b5b253a4f97216b9a33199a863987075162 (patch)
tree160710c7527cbd1e503560557936aa82b1804046
parent2617120f4de6d0423384e0e86b14c78b9de84d5a (diff)
ALSA: firewire-tascam: check intermediate state of clock status and retry
2 bytes in MSB of register for clock status is zero during intermediate state after changing status of sampling clock in models of TASCAM FireWire series. The duration of this state differs depending on cases. During the state, it's better to retry reading the register for current status of the clock. In current implementation, the intermediate state is checked only when getting current sampling transmission frequency, then retry reading. This care is required for the other operations to read the register. This commit moves the codes of check and retry into helper function commonly used for operations to read the register. Fixes: e453df44f0d6 ("ALSA: firewire-tascam: add PCM functionality") Cc: <stable@vger.kernel.org> # v4.4+ Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Link: https://lore.kernel.org/r/20190910135152.29800-3-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/firewire/tascam/tascam-stream.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/sound/firewire/tascam/tascam-stream.c b/sound/firewire/tascam/tascam-stream.c
index e852e46ebe6f..ccfa92fbc145 100644
--- a/sound/firewire/tascam/tascam-stream.c
+++ b/sound/firewire/tascam/tascam-stream.c
@@ -8,20 +8,37 @@
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include "tascam.h" 9#include "tascam.h"
10 10
11#define CLOCK_STATUS_MASK 0xffff0000
12#define CLOCK_CONFIG_MASK 0x0000ffff
13
11#define CALLBACK_TIMEOUT 500 14#define CALLBACK_TIMEOUT 500
12 15
13static int get_clock(struct snd_tscm *tscm, u32 *data) 16static int get_clock(struct snd_tscm *tscm, u32 *data)
14{ 17{
18 int trial = 0;
15 __be32 reg; 19 __be32 reg;
16 int err; 20 int err;
17 21
18 err = snd_fw_transaction(tscm->unit, TCODE_READ_QUADLET_REQUEST, 22 while (trial++ < 5) {
19 TSCM_ADDR_BASE + TSCM_OFFSET_CLOCK_STATUS, 23 err = snd_fw_transaction(tscm->unit, TCODE_READ_QUADLET_REQUEST,
20 &reg, sizeof(reg), 0); 24 TSCM_ADDR_BASE + TSCM_OFFSET_CLOCK_STATUS,
21 if (err >= 0) 25 &reg, sizeof(reg), 0);
26 if (err < 0)
27 return err;
28
22 *data = be32_to_cpu(reg); 29 *data = be32_to_cpu(reg);
30 if (*data & CLOCK_STATUS_MASK)
31 break;
23 32
24 return err; 33 // In intermediate state after changing clock status.
34 msleep(50);
35 }
36
37 // Still in the intermediate state.
38 if (trial >= 5)
39 return -EAGAIN;
40
41 return 0;
25} 42}
26 43
27static int set_clock(struct snd_tscm *tscm, unsigned int rate, 44static int set_clock(struct snd_tscm *tscm, unsigned int rate,
@@ -34,7 +51,7 @@ static int set_clock(struct snd_tscm *tscm, unsigned int rate,
34 err = get_clock(tscm, &data); 51 err = get_clock(tscm, &data);
35 if (err < 0) 52 if (err < 0)
36 return err; 53 return err;
37 data &= 0x0000ffff; 54 data &= CLOCK_CONFIG_MASK;
38 55
39 if (rate > 0) { 56 if (rate > 0) {
40 data &= 0x000000ff; 57 data &= 0x000000ff;
@@ -79,17 +96,14 @@ static int set_clock(struct snd_tscm *tscm, unsigned int rate,
79 96
80int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate) 97int snd_tscm_stream_get_rate(struct snd_tscm *tscm, unsigned int *rate)
81{ 98{
82 u32 data = 0x0; 99 u32 data;
83 unsigned int trials = 0;
84 int err; 100 int err;
85 101
86 while (data == 0x0 || trials++ < 5) { 102 err = get_clock(tscm, &data);
87 err = get_clock(tscm, &data); 103 if (err < 0)
88 if (err < 0) 104 return err;
89 return err;
90 105
91 data = (data & 0xff000000) >> 24; 106 data = (data & 0xff000000) >> 24;
92 }
93 107
94 /* Check base rate. */ 108 /* Check base rate. */
95 if ((data & 0x0f) == 0x01) 109 if ((data & 0x0f) == 0x01)