Skip to content

Commit 83bea08

Browse files
Viorel Sumanbroonie
authored andcommitted
ASoC: fsl_spdif: implement bypass mode from in to out
Implement SPDIF bypass mode. It implies internal SoC routing of SPDIF input signal to SPDIF output signal. The test bed requires two boards: B1 configured in bypass mode, and B2 to feed B1 SPDIF RX port and read B1 SPDIF TX port: B2 TX -> B1 RX, B2 RX <- B1 TX. The test procedure: a) Boot both boards b) B2: start "arecord <spdifcard> -r 48kHz | aplay <local DAC>" c) B2: start "aplay <spdifcard> -r 48kHz <2ch 48kHz audio file>" d) B1: enable bypass mode: amixer -cimxspdif cset numid=8,iface=PCM,name='Bypass Mode' on e) B2: check DAC audio, make sure the same sample rate is used at steps b) and c), in example above the rate is 48kHz. f) B1: try to run "aplay" or "arecord" on imxspdif card while in bypass mode - both must fail until bypass mode is disabled g) B1: disable bypass mode: amixer -cimxspdif cset numid=8,iface=PCM,name='Bypass Mode' off h) B1: check the usual playback and capture on imxspdif card. During this test try to set bypass mode - must not be allowed while playback or capture is running. Signed-off-by: Viorel Suman <viorel.suman@nxp.com> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com> Link: https://lore.kernel.org/r/1632649760-1651-1-git-send-email-shengjiu.wang@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent cd96663 commit 83bea08

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

sound/soc/fsl/fsl_spdif.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct spdif_mixer_control {
111111
* @dma_params_tx: DMA parameters for transmit channel
112112
* @dma_params_rx: DMA parameters for receive channel
113113
* @regcache_srpc: regcache for SRPC
114+
* @bypass: status of bypass input to output
114115
*/
115116
struct fsl_spdif_priv {
116117
const struct fsl_spdif_soc_data *soc;
@@ -133,6 +134,7 @@ struct fsl_spdif_priv {
133134
struct snd_dmaengine_dai_dma_data dma_params_rx;
134135
/* regcache for SRPC */
135136
u32 regcache_srpc;
137+
bool bypass;
136138
};
137139

138140
static struct fsl_spdif_soc_data fsl_spdif_vf610 = {
@@ -905,6 +907,69 @@ static int fsl_spdif_rx_rcm_put(struct snd_kcontrol *kcontrol,
905907
return 0;
906908
}
907909

910+
static int fsl_spdif_bypass_get(struct snd_kcontrol *kcontrol,
911+
struct snd_ctl_elem_value *ucontrol)
912+
{
913+
struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
914+
struct fsl_spdif_priv *priv = snd_soc_dai_get_drvdata(dai);
915+
916+
ucontrol->value.integer.value[0] = priv->bypass ? 1 : 0;
917+
918+
return 0;
919+
}
920+
921+
static int fsl_spdif_bypass_put(struct snd_kcontrol *kcontrol,
922+
struct snd_ctl_elem_value *ucontrol)
923+
{
924+
struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
925+
struct fsl_spdif_priv *priv = snd_soc_dai_get_drvdata(dai);
926+
struct snd_soc_card *card = dai->component->card;
927+
bool set = (ucontrol->value.integer.value[0] != 0);
928+
struct regmap *regmap = priv->regmap;
929+
struct snd_soc_pcm_runtime *rtd;
930+
u32 scr, mask;
931+
int stream;
932+
933+
rtd = snd_soc_get_pcm_runtime(card, card->dai_link);
934+
935+
if (priv->bypass == set)
936+
return 0; /* nothing to do */
937+
938+
if (snd_soc_dai_active(dai)) {
939+
dev_err(dai->dev, "Cannot change BYPASS mode while stream is running.\n");
940+
return -EBUSY;
941+
}
942+
943+
pm_runtime_get_sync(dai->dev);
944+
945+
if (set) {
946+
/* Disable interrupts */
947+
regmap_update_bits(regmap, REG_SPDIF_SIE, 0xffffff, 0);
948+
949+
/* Configure BYPASS mode */
950+
scr = SCR_TXSEL_RX | SCR_RXFIFO_OFF;
951+
mask = SCR_RXFIFO_FSEL_MASK | SCR_RXFIFO_AUTOSYNC_MASK |
952+
SCR_RXFIFO_CTL_MASK | SCR_RXFIFO_OFF_MASK | SCR_TXSEL_MASK;
953+
/* Power up SPDIF module */
954+
mask |= SCR_LOW_POWER;
955+
} else {
956+
/* Power down SPDIF module, disable TX */
957+
scr = SCR_LOW_POWER | SCR_TXSEL_OFF;
958+
mask = SCR_LOW_POWER | SCR_TXSEL_MASK;
959+
}
960+
961+
regmap_update_bits(regmap, REG_SPDIF_SCR, mask, scr);
962+
963+
/* Disable playback & capture if BYPASS mode is enabled, enable otherwise */
964+
for_each_pcm_streams(stream)
965+
rtd->pcm->streams[stream].substream_count = (set ? 0 : 1);
966+
967+
priv->bypass = set;
968+
pm_runtime_put_sync(dai->dev);
969+
970+
return 0;
971+
}
972+
908973
/* DPLL lock information */
909974
static int fsl_spdif_rxrate_info(struct snd_kcontrol *kcontrol,
910975
struct snd_ctl_elem_info *uinfo)
@@ -1075,6 +1140,15 @@ static struct snd_kcontrol_new fsl_spdif_ctrls[] = {
10751140
.info = fsl_spdif_rxrate_info,
10761141
.get = fsl_spdif_rxrate_get,
10771142
},
1143+
/* RX bypass controller */
1144+
{
1145+
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1146+
.name = "Bypass Mode",
1147+
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1148+
.info = snd_ctl_boolean_mono_info,
1149+
.get = fsl_spdif_bypass_get,
1150+
.put = fsl_spdif_bypass_put,
1151+
},
10781152
/* User bit sync mode set/get controller */
10791153
{
10801154
.iface = SNDRV_CTL_ELEM_IFACE_PCM,

0 commit comments

Comments
 (0)