Skip to content

Commit 8e27987

Browse files
TE-N-ShengjiuWangbroonie
authored andcommitted
ASoC: fsl_sai: add bitcount and timestamp controls
The transmitter and receiver implement separate timestamp counters and bit counters. The bit counter increments at the end of each bit in a frame whenever the transmitter or receiver is enabled. The bit counter can be reset by software. The timestamp counter increments on the bus interface clock whenever it is enabled. The current value of the timestamp counter is latched whenever the bit counter increments. Reading the bit counter register will cause the latched timestamp value to be saved in the bit counter timestamp register. The timestamp counter can be reset by software, this also resets the latched timestamp value and the bit counter timestamp register. The timestamp counter and bit counter can be used by software to track the progress of the transmitter and receiver. It can also be used to calculate the relative frequency of the bit clock against the bus interface clock. These bitcount and timestamp registers are volatile, and supported when the module has timestamp features. Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com> Link: https://patch.msgid.link/20260310104235.1234569-3-shengjiu.wang@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 819cf1d commit 8e27987

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

sound/soc/fsl/fsl_sai.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,52 @@ static const struct snd_pcm_hw_constraint_list fsl_sai_rate_constraints = {
4141
.list = fsl_sai_rates,
4242
};
4343

44+
static const char * const inc_mode[] = {
45+
"On enabled and bitcount increment", "On enabled"
46+
};
47+
48+
static SOC_ENUM_SINGLE_DECL(transmit_tstmp_enum,
49+
FSL_SAI_TTCTL, FSL_SAI_xTCTL_TSINC_SHIFT, inc_mode);
50+
static SOC_ENUM_SINGLE_DECL(receive_tstmp_enum,
51+
FSL_SAI_RTCTL, FSL_SAI_xTCTL_TSINC_SHIFT, inc_mode);
52+
53+
static const struct snd_kcontrol_new fsl_sai_timestamp_ctrls[] = {
54+
FSL_ASOC_SINGLE_EXT("Transmit Timestamp Control Switch", FSL_SAI_TTCTL,
55+
FSL_SAI_xTCTL_TSEN_SHIFT, 1, 0,
56+
fsl_asoc_get_volsw, fsl_asoc_put_volsw),
57+
FSL_ASOC_ENUM_EXT("Transmit Timestamp Increment", transmit_tstmp_enum,
58+
fsl_asoc_get_enum_double, fsl_asoc_put_enum_double),
59+
FSL_ASOC_SINGLE_EXT("Transmit Timestamp Reset Switch", FSL_SAI_TTCTL,
60+
FSL_SAI_xTCTL_RTSC_SHIFT, 1, 0,
61+
fsl_asoc_get_volsw, fsl_asoc_put_volsw),
62+
FSL_ASOC_SINGLE_EXT("Transmit Bit Counter Reset Switch", FSL_SAI_TTCTL,
63+
FSL_SAI_xTCTL_RBC_SHIFT, 1, 0,
64+
fsl_asoc_get_volsw, fsl_asoc_put_volsw),
65+
FSL_ASOC_SINGLE_XR_SX_EXT_RO("Transmit Timestamp Counter", FSL_SAI_TTCTN,
66+
1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx),
67+
FSL_ASOC_SINGLE_XR_SX_EXT_RO("Transmit Bit Counter", FSL_SAI_TBCTN,
68+
1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx),
69+
FSL_ASOC_SINGLE_XR_SX_EXT_RO("Transmit Latched Timestamp Counter", FSL_SAI_TTCAP,
70+
1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx),
71+
FSL_ASOC_SINGLE_EXT("Receive Timestamp Control Switch", FSL_SAI_RTCTL,
72+
FSL_SAI_xTCTL_TSEN_SHIFT, 1, 0,
73+
fsl_asoc_get_volsw, fsl_asoc_put_volsw),
74+
FSL_ASOC_ENUM_EXT("Receive Timestamp Increment", receive_tstmp_enum,
75+
fsl_asoc_get_enum_double, fsl_asoc_put_enum_double),
76+
FSL_ASOC_SINGLE_EXT("Receive Timestamp Reset Switch", FSL_SAI_RTCTL,
77+
FSL_SAI_xTCTL_RTSC_SHIFT, 1, 0,
78+
fsl_asoc_get_volsw, fsl_asoc_put_volsw),
79+
FSL_ASOC_SINGLE_EXT("Receive Bit Counter Reset Switch", FSL_SAI_RTCTL,
80+
FSL_SAI_xTCTL_RBC_SHIFT, 1, 0,
81+
fsl_asoc_get_volsw, fsl_asoc_put_volsw),
82+
FSL_ASOC_SINGLE_XR_SX_EXT_RO("Receive Timestamp Counter", FSL_SAI_RTCTN,
83+
1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx),
84+
FSL_ASOC_SINGLE_XR_SX_EXT_RO("Receive Bit Counter", FSL_SAI_RBCTN,
85+
1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx),
86+
FSL_ASOC_SINGLE_XR_SX_EXT_RO("Receive Latched Timestamp Counter", FSL_SAI_RTCAP,
87+
1, 32, 0, 0xffffffff, 0, fsl_asoc_get_xr_sx),
88+
};
89+
4490
/**
4591
* fsl_sai_dir_is_synced - Check if stream is synced by the opposite stream
4692
*
@@ -1010,6 +1056,17 @@ static int fsl_sai_dai_resume(struct snd_soc_component *component)
10101056
return 0;
10111057
}
10121058

1059+
static int fsl_sai_component_probe(struct snd_soc_component *component)
1060+
{
1061+
struct fsl_sai *sai = snd_soc_component_get_drvdata(component);
1062+
1063+
if (sai->verid.feature & FSL_SAI_VERID_TSTMP_EN)
1064+
snd_soc_add_component_controls(component, fsl_sai_timestamp_ctrls,
1065+
ARRAY_SIZE(fsl_sai_timestamp_ctrls));
1066+
1067+
return 0;
1068+
}
1069+
10131070
static struct snd_soc_dai_driver fsl_sai_dai_template[] = {
10141071
{
10151072
.name = "sai-tx-rx",
@@ -1063,6 +1120,7 @@ static struct snd_soc_dai_driver fsl_sai_dai_template[] = {
10631120

10641121
static const struct snd_soc_component_driver fsl_component = {
10651122
.name = "fsl-sai",
1123+
.probe = fsl_sai_component_probe,
10661124
.resume = fsl_sai_dai_resume,
10671125
.legacy_dai_naming = 1,
10681126
};
@@ -1211,6 +1269,14 @@ static bool fsl_sai_volatile_reg(struct device *dev, unsigned int reg)
12111269
case FSL_SAI_RDR5:
12121270
case FSL_SAI_RDR6:
12131271
case FSL_SAI_RDR7:
1272+
case FSL_SAI_TTCTN:
1273+
case FSL_SAI_RTCTN:
1274+
case FSL_SAI_TTCTL:
1275+
case FSL_SAI_TBCTN:
1276+
case FSL_SAI_TTCAP:
1277+
case FSL_SAI_RTCTL:
1278+
case FSL_SAI_RBCTN:
1279+
case FSL_SAI_RTCAP:
12141280
return true;
12151281
default:
12161282
return false;

sound/soc/fsl/fsl_sai.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,13 @@
196196
#define FSL_SAI_MDIV_MASK 0xFFFFF
197197

198198
/* SAI timestamp and bitcounter */
199+
#define FSL_SAI_xTCTL_TSEN_SHIFT 0
199200
#define FSL_SAI_xTCTL_TSEN BIT(0)
201+
#define FSL_SAI_xTCTL_TSINC_SHIFT 1
200202
#define FSL_SAI_xTCTL_TSINC BIT(1)
203+
#define FSL_SAI_xTCTL_RTSC_SHIFT 8
201204
#define FSL_SAI_xTCTL_RTSC BIT(8)
205+
#define FSL_SAI_xTCTL_RBC_SHIFT 9
202206
#define FSL_SAI_xTCTL_RBC BIT(9)
203207

204208
/* SAI type */

0 commit comments

Comments
 (0)