1 From 599235bd9d22c8cad90b0a7621b46d70cca94d31 Mon Sep 17 00:00:00 2001
2 From: Viorel Suman <viorel.suman@nxp.com>
3 Date: Wed, 5 Jun 2019 13:46:32 +0000
4 Subject: [PATCH] MLK-21957-3: ASoC: fsl_sai: add bitcount and timestamp
7 Bitcount and timestamp support added in SAI IP recently.
8 Add the related controls in SAI driver.
10 Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
12 sound/soc/fsl/fsl_sai.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++-
13 sound/soc/fsl/fsl_sai.h | 6 +++
14 2 files changed, 102 insertions(+), 1 deletion(-)
16 --- a/sound/soc/fsl/fsl_sai.c
17 +++ b/sound/soc/fsl/fsl_sai.c
18 @@ -992,6 +992,90 @@ static const struct snd_soc_dai_ops fsl_
19 .shutdown = fsl_sai_shutdown,
23 + *en_sl[] = { "Disabled", "Enabled", },
24 + *inc_sl[] = { "On enabled and bitcount increment", "On enabled", };
26 +static const struct soc_enum tstmp_enum[] = {
27 +SOC_ENUM_SINGLE(FSL_SAI_TTCTL, 0, ARRAY_SIZE(en_sl), en_sl),
28 +SOC_ENUM_SINGLE(FSL_SAI_RTCTL, 0, ARRAY_SIZE(en_sl), en_sl),
29 +SOC_ENUM_SINGLE(FSL_SAI_TTCTL, 1, ARRAY_SIZE(inc_sl), inc_sl),
30 +SOC_ENUM_SINGLE(FSL_SAI_RTCTL, 1, ARRAY_SIZE(inc_sl), inc_sl),
33 +int fsl_sai_get_reg(struct snd_kcontrol *kcontrol,
34 + struct snd_ctl_elem_value *ucontrol)
36 + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
37 + struct soc_mreg_control *mc =
38 + (struct soc_mreg_control *)kcontrol->private_value;
39 + bool pm_active = pm_runtime_active(component->dev);
40 + unsigned int regval;
44 + regcache_cache_bypass(component->regmap, true);
46 + ret = snd_soc_component_read(component, mc->regbase, ®val);
49 + regcache_cache_bypass(component->regmap, false);
54 + ucontrol->value.integer.value[0] = regval;
59 +#define SOC_SINGLE_REG_RO(xname, xreg) \
60 +{ .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = (xname), \
61 + .access = SNDRV_CTL_ELEM_ACCESS_READ | \
62 + SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
63 + .info = snd_soc_info_xr_sx, .get = fsl_sai_get_reg, \
64 + .private_value = (unsigned long)&(struct soc_mreg_control) \
65 + { .regbase = xreg, .regcount = 1, .nbits = 32, \
66 + .invert = 0, .min = 0, .max = 0xffffffff, } }
68 +static const struct snd_kcontrol_new fsl_sai_pb_ctrls[] = {
69 + SOC_ENUM("Playback Timestamp Control", tstmp_enum[0]),
70 + SOC_ENUM("Playback Timestamp Increment", tstmp_enum[2]),
71 + SOC_SINGLE("Playback Timestamp Reset", FSL_SAI_TTCTL, 8, 1, 0),
72 + SOC_SINGLE("Playback Bit Counter Reset", FSL_SAI_TTCTL, 9, 1, 0),
73 + SOC_SINGLE_REG_RO("Playback Timestamp Counter", FSL_SAI_TTCTN),
74 + SOC_SINGLE_REG_RO("Playback Bit Counter", FSL_SAI_TBCTN),
75 + SOC_SINGLE_REG_RO("Playback Latched Timestamp Counter", FSL_SAI_TTCAP),
78 +static const struct snd_kcontrol_new fsl_sai_cp_ctrls[] = {
79 + SOC_ENUM("Capture Timestamp Control", tstmp_enum[1]),
80 + SOC_ENUM("Capture Timestamp Increment", tstmp_enum[3]),
81 + SOC_SINGLE("Capture Timestamp Reset", FSL_SAI_RTCTL, 8, 1, 0),
82 + SOC_SINGLE("Capture Bit Counter Reset", FSL_SAI_RTCTL, 9, 1, 0),
83 + SOC_SINGLE_REG_RO("Capture Timestamp Counter", FSL_SAI_RTCTN),
84 + SOC_SINGLE_REG_RO("Capture Bit Counter", FSL_SAI_RBCTN),
85 + SOC_SINGLE_REG_RO("Capture Latched Timestamp Counter", FSL_SAI_RTCAP),
88 +static int fsl_sai_pcm_new(struct snd_soc_pcm_runtime *rtd,
89 + struct snd_soc_dai *dai)
91 + struct fsl_sai *sai = dev_get_drvdata(dai->dev);
92 + struct snd_pcm *pcm = rtd->pcm;
93 + bool ts_enabled = sai->verid.timestamp_en;
94 + struct snd_soc_component *comp = dai->component;
96 + if (ts_enabled && pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)
97 + snd_soc_add_component_controls(comp, fsl_sai_pb_ctrls,
98 + ARRAY_SIZE(fsl_sai_pb_ctrls));
100 + if (ts_enabled && pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream)
101 + snd_soc_add_component_controls(comp, fsl_sai_cp_ctrls,
102 + ARRAY_SIZE(fsl_sai_cp_ctrls));
106 static int fsl_sai_dai_probe(struct snd_soc_dai *cpu_dai)
108 struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev);
109 @@ -1030,6 +1114,7 @@ static int fsl_sai_dai_resume(struct snd
112 static struct snd_soc_dai_driver fsl_sai_dai_template = {
113 + .pcm_new = fsl_sai_pcm_new,
114 .probe = fsl_sai_dai_probe,
116 .stream_name = "CPU-Playback",
117 @@ -1054,7 +1139,7 @@ static struct snd_soc_dai_driver fsl_sai
120 static const struct snd_soc_component_driver fsl_component = {
125 static struct reg_default fsl_sai_v2_reg_defaults[] = {
126 @@ -1141,6 +1226,14 @@ static bool fsl_sai_readable_reg(struct
130 + case FSL_SAI_TTCTN:
131 + case FSL_SAI_RTCTN:
132 + case FSL_SAI_TTCTL:
133 + case FSL_SAI_TBCTN:
134 + case FSL_SAI_TTCAP:
135 + case FSL_SAI_RTCTL:
136 + case FSL_SAI_RBCTN:
137 + case FSL_SAI_RTCAP:
141 @@ -1214,6 +1307,8 @@ static bool fsl_sai_writeable_reg(struct
145 + case FSL_SAI_TTCTL:
146 + case FSL_SAI_RTCTL:
150 --- a/sound/soc/fsl/fsl_sai.h
151 +++ b/sound/soc/fsl/fsl_sai.h
154 #define SAI_FLAG_PMQOS BIT(0)
156 +/* SAI timestamp and bitcounter */
157 +#define FSL_SAI_xTCTL_TSEN BIT(0)
158 +#define FSL_SAI_xTCTL_TSINC BIT(1)
159 +#define FSL_SAI_xTCTL_RTSC BIT(8)
160 +#define FSL_SAI_xTCTL_RBC BIT(9)
162 struct fsl_sai_soc_data {
163 unsigned int fifo_depth;