Commit 7b47c0d7 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai

ALSA: firewire-motu: refactoring protocol v3 for clock source getter

This commit splits the method to get clock source for protocol
version 3 so that model-dependent operations are explicitly defined.
Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20200519111641.123211-14-o-takashi@sakamocchi.jpSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 2b8f050e
...@@ -87,54 +87,100 @@ int snd_motu_protocol_v3_set_clock_rate(struct snd_motu *motu, ...@@ -87,54 +87,100 @@ int snd_motu_protocol_v3_set_clock_rate(struct snd_motu *motu,
return 0; return 0;
} }
int snd_motu_protocol_v3_get_clock_source(struct snd_motu *motu, static int detect_clock_source_828mk3(struct snd_motu *motu, u32 data,
enum snd_motu_clock_source *src) enum snd_motu_clock_source *src)
{ {
__be32 reg; switch (data) {
u32 data; case 0x00:
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) {
*src = SND_MOTU_CLOCK_SOURCE_INTERNAL; *src = SND_MOTU_CLOCK_SOURCE_INTERNAL;
} else if (val == 0x01) { break;
case 0x01:
*src = SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC; *src = SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC;
} else if (val == 0x02) { break;
case 0x02:
*src = SND_MOTU_CLOCK_SOURCE_SPH; *src = SND_MOTU_CLOCK_SOURCE_SPH;
} else if (val == 0x10) { break;
case 0x10:
*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX; *src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX;
} else if (val == 0x18 || val == 0x19) { break;
err = snd_motu_transaction_read(motu, V3_OPT_IFACE_MODE_OFFSET, case 0x18:
&reg, sizeof(reg)); 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) if (err < 0)
return err; return err;
data = be32_to_cpu(reg); options = be32_to_cpu(reg);
if (val == 0x18) { if (data == 0x18) {
if (data & V3_NO_ADAT_OPT_IN_IFACE_A) if (options & V3_NO_ADAT_OPT_IN_IFACE_A)
*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A; *src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A;
else else
*src = SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A; *src = SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A;
} else { } 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; *src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B;
else else
*src = SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B; *src = SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B;
} }
} else {
break;
}
default:
*src = SND_MOTU_CLOCK_SOURCE_UNKNOWN; *src = SND_MOTU_CLOCK_SOURCE_UNKNOWN;
break;
} }
return 0; 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, int snd_motu_protocol_v3_switch_fetching_mode(struct snd_motu *motu,
bool enable) bool enable)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment