sound/soc/codecs/wm8962.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-)
The slot_width can be different with the params_width(), for example,
DSP_A mode, slot_width = 32, but data format is S16_LE, if the word
length is configured to be 16, there is no sound on the right speaker.
So add .set_tdm_slot() callback function to configure the slot_width and
update the word length according to slot_width in hw_params().
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
---
sound/soc/codecs/wm8962.c | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index bff864467416..4a3943161b54 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -85,6 +85,8 @@ struct wm8962_priv {
int irq;
bool master_flag;
+ int tdm_width;
+ int tdm_slots;
};
/* We can't use the same notifier block for more than one supply and
@@ -2612,6 +2614,21 @@ static int wm8962_set_bias_level(struct snd_soc_component *component,
return 0;
}
+static int wm8962_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
+ unsigned int rx_mask, int slots, int slot_width)
+{
+ struct snd_soc_component *component = dai->component;
+ struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component);
+
+ if (slots <= 0 || slot_width <= 0)
+ return 0;
+
+ wm8962->tdm_width = slot_width;
+ wm8962->tdm_slots = slots;
+
+ return 0;
+}
+
static const struct {
int rate;
int reg;
@@ -2639,10 +2656,21 @@ static int wm8962_hw_params(struct snd_pcm_substream *substream,
int i;
int aif0 = 0;
int adctl3 = 0;
+ int width;
+
+ if (wm8962->tdm_width && wm8962->tdm_slots) {
+ wm8962->bclk = snd_soc_calc_bclk(params_rate(params),
+ wm8962->tdm_width,
+ params_channels(params),
+ wm8962->tdm_slots);
+ width = wm8962->tdm_width;
+ } else {
+ wm8962->bclk = snd_soc_params_to_bclk(params);
+ width = params_width(params);
- wm8962->bclk = snd_soc_params_to_bclk(params);
- if (params_channels(params) == 1)
- wm8962->bclk *= 2;
+ if (params_channels(params) == 1)
+ wm8962->bclk *= 2;
+ }
wm8962->lrclk = params_rate(params);
@@ -2660,7 +2688,7 @@ static int wm8962_hw_params(struct snd_pcm_substream *substream,
if (wm8962->lrclk % 8000 == 0)
adctl3 |= WM8962_SAMPLE_RATE_INT_MODE;
- switch (params_width(params)) {
+ switch (width) {
case 16:
break;
case 20:
@@ -3039,6 +3067,7 @@ static const struct snd_soc_dai_ops wm8962_dai_ops = {
.hw_params = wm8962_hw_params,
.set_sysclk = wm8962_set_dai_sysclk,
.set_fmt = wm8962_set_dai_fmt,
+ .set_tdm_slot = wm8962_set_tdm_slot,
.mute_stream = wm8962_mute,
.no_capture_mute = 1,
};
--
2.34.1
On Tue, Jan 27, 2026 at 06:33:26PM +0800, Shengjiu Wang wrote:
> The slot_width can be different with the params_width(), for example,
> DSP_A mode, slot_width = 32, but data format is S16_LE, if the word
> length is configured to be 16, there is no sound on the right speaker.
>
> So add .set_tdm_slot() callback function to configure the slot_width and
> update the word length according to slot_width in hw_params().
>
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> ---
> +static int wm8962_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
> + unsigned int rx_mask, int slots, int slot_width)
> +{
> + struct snd_soc_component *component = dai->component;
> + struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component);
> +
> + if (slots <= 0 || slot_width <= 0)
> + return 0;
You probably shouldn't bail out here, how does one disable TDM if
it is no longer required?
I think the rest looks good.
Thanks,
Charles
On Tue, Jan 27, 2026 at 7:03 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> On Tue, Jan 27, 2026 at 06:33:26PM +0800, Shengjiu Wang wrote:
> > The slot_width can be different with the params_width(), for example,
> > DSP_A mode, slot_width = 32, but data format is S16_LE, if the word
> > length is configured to be 16, there is no sound on the right speaker.
> >
> > So add .set_tdm_slot() callback function to configure the slot_width and
> > update the word length according to slot_width in hw_params().
> >
> > Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> > ---
> > +static int wm8962_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
> > + unsigned int rx_mask, int slots, int slot_width)
> > +{
> > + struct snd_soc_component *component = dai->component;
> > + struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component);
> > +
> > + if (slots <= 0 || slot_width <= 0)
> > + return 0;
>
> You probably shouldn't bail out here, how does one disable TDM if
> it is no longer required?
Should we add some checks for the slots and slot_width here?
or just remove these two lines?
Best regards
Shengjiu Wang
>
> I think the rest looks good.
>
> Thanks,
> Charles
On Tue, Jan 27, 2026 at 09:01:02PM +0800, Shengjiu Wang wrote:
> On Tue, Jan 27, 2026 at 7:03 PM Charles Keepax
> <ckeepax@opensource.cirrus.com> wrote:
> >
> > On Tue, Jan 27, 2026 at 06:33:26PM +0800, Shengjiu Wang wrote:
> > > The slot_width can be different with the params_width(), for example,
> > > DSP_A mode, slot_width = 32, but data format is S16_LE, if the word
> > > length is configured to be 16, there is no sound on the right speaker.
> > >
> > > So add .set_tdm_slot() callback function to configure the slot_width and
> > > update the word length according to slot_width in hw_params().
> > >
> > > Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> > > ---
> > > +static int wm8962_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
> > > + unsigned int rx_mask, int slots, int slot_width)
> > > +{
> > > + struct snd_soc_component *component = dai->component;
> > > + struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component);
> > > +
> > > + if (slots <= 0 || slot_width <= 0)
> > > + return 0;
> >
> > You probably shouldn't bail out here, how does one disable TDM if
> > it is no longer required?
>
> Should we add some checks for the slots and slot_width here?
> or just remove these two lines?
>
I think its ok to just remove these, if you call set_tdm_slot
with weird numbers that is probably a bug in the calling code,
but not super picky either way.
Thanks,
Charles
© 2016 - 2026 Red Hat, Inc.