mirror of https://gitee.com/openkylin/linux.git
ALSA: firewire-motu: code refactoring for detection of clock source in v2 protocol
Current implementation of driver has two similar helper functions for source detection of sampling clock. This commit merges them as a code refactoring. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Link: https://lore.kernel.org/r/20210623075941.72562-3-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
fa4db23233
commit
25eb438920
|
@ -78,10 +78,10 @@ int snd_motu_protocol_v2_set_clock_rate(struct snd_motu *motu,
|
||||||
sizeof(reg));
|
sizeof(reg));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int detect_clock_source_optical_model(struct snd_motu *motu, u32 data,
|
static int get_clock_source(struct snd_motu *motu, u32 data,
|
||||||
enum snd_motu_clock_source *src)
|
enum snd_motu_clock_source *src)
|
||||||
{
|
{
|
||||||
switch (data) {
|
switch (data & V2_CLOCK_SRC_MASK) {
|
||||||
case 0:
|
case 0:
|
||||||
*src = SND_MOTU_CLOCK_SOURCE_INTERNAL;
|
*src = SND_MOTU_CLOCK_SOURCE_INTERNAL;
|
||||||
break;
|
break;
|
||||||
|
@ -90,17 +90,26 @@ static int detect_clock_source_optical_model(struct snd_motu *motu, u32 data,
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
|
bool support_iec60958_on_opt = (motu->spec == &snd_motu_spec_828mk2 ||
|
||||||
|
motu->spec == &snd_motu_spec_traveler);
|
||||||
|
|
||||||
|
if (!support_iec60958_on_opt) {
|
||||||
|
*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX;
|
||||||
|
} else {
|
||||||
__be32 reg;
|
__be32 reg;
|
||||||
|
|
||||||
// To check the configuration of optical interface.
|
// To check the configuration of optical interface.
|
||||||
int err = snd_motu_transaction_read(motu, V2_IN_OUT_CONF_OFFSET, ®, sizeof(reg));
|
int err = snd_motu_transaction_read(motu, V2_IN_OUT_CONF_OFFSET, ®,
|
||||||
|
sizeof(reg));
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (((data & V2_OPT_IN_IFACE_MASK) >> V2_OPT_IN_IFACE_SHIFT) == V2_OPT_IFACE_MODE_SPDIF)
|
if (((data & V2_OPT_IN_IFACE_MASK) >> V2_OPT_IN_IFACE_SHIFT) ==
|
||||||
|
V2_OPT_IFACE_MODE_SPDIF)
|
||||||
*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT;
|
*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT;
|
||||||
else
|
else
|
||||||
*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX;
|
*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -120,41 +129,6 @@ static int detect_clock_source_optical_model(struct snd_motu *motu, u32 data,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int v2_detect_clock_source(struct snd_motu *motu, u32 data,
|
|
||||||
enum snd_motu_clock_source *src)
|
|
||||||
{
|
|
||||||
switch (data) {
|
|
||||||
case 0:
|
|
||||||
*src = SND_MOTU_CLOCK_SOURCE_INTERNAL;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
*src = SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
*src = SND_MOTU_CLOCK_SOURCE_SPH;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
*src = SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*src = SND_MOTU_CLOCK_SOURCE_UNKNOWN;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_clock_source(struct snd_motu *motu, u32 data,
|
|
||||||
enum snd_motu_clock_source *src)
|
|
||||||
{
|
|
||||||
data &= V2_CLOCK_SRC_MASK;
|
|
||||||
if (motu->spec == &snd_motu_spec_828mk2 ||
|
|
||||||
motu->spec == &snd_motu_spec_traveler)
|
|
||||||
return detect_clock_source_optical_model(motu, data, src);
|
|
||||||
else
|
|
||||||
return v2_detect_clock_source(motu, data, src);
|
|
||||||
}
|
|
||||||
|
|
||||||
int snd_motu_protocol_v2_get_clock_source(struct snd_motu *motu,
|
int snd_motu_protocol_v2_get_clock_source(struct snd_motu *motu,
|
||||||
enum snd_motu_clock_source *src)
|
enum snd_motu_clock_source *src)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue