From: Chancel Liu <chancel.liu@gmail.com>
To: joakim.zhang@cixtech.com, lgirdwood@gmail.com,
broonie@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, perex@perex.cz, tiwai@suse.com,
p.zabel@pengutronix.de
Cc: cix-kernel-upstream@cixtech.com, linux-sound@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 4/4] ASoC: cdns: Add Cadence I2S-MC controller driver
Date: Wed, 23 Sep 2026 13:25:20 +0800 [thread overview]
Message-ID: <6b1637d5-ce36-4702-a404-89ed6c65155f@gmail.com> (raw)
In-Reply-To: <20260922112134.4167305-5-joakim.zhang@cixtech.com>
> +static int cdns_i2s_mc_clks_enable(struct cdns_i2s_mc_priv *i2s_mc_priv)
> +{
> + int ret;
> +
> + ret = clk_prepare_enable(i2s_mc_priv->clk_hst);
> + if (ret)
> + return ret;
> +
> + ret = clk_prepare_enable(i2s_mc_priv->clk_i2s);
> + if (ret)
> + clk_disable_unprepare(i2s_mc_priv->clk_hst);
> +
> + return ret;
> +}
> +
> +static void cdns_i2s_mc_clks_disable(struct cdns_i2s_mc_priv *i2s_mc_priv)
> +{
> + clk_disable_unprepare(i2s_mc_priv->clk_hst);
> + clk_disable_unprepare(i2s_mc_priv->clk_i2s);
> +}
> +
It's better disable the clocks in reverse order of enablement。
> +static void cdns_i2s_mc_adjust_pin_config(u8 *pin_mask, u32 slots)
> +{
> + u8 mask = 0, num = 0;
> + int i;
> +
> + /*
> + * Wired-out pins may sit at any index among the 8 data pins, so
> + * scan the whole mask and keep the lowest pins until enough slots
> + * are covered.
> + */
> + for (i = 0; i < BITS_PER_BYTE; i++) {
> + if (*pin_mask & (0x1 << i)) {
> + mask |= (0x1 << i);
> + if (++num == slots / 2) {
> + *pin_mask = mask;
> + break;
> + }
> + }
> + }
> +}
> +
> +static void cdns_i2s_mc_tx_config(struct cdns_i2s_mc_priv *i2s_mc_priv, bool on)
> +{
> + u32 irq_mask = 0, clk_mask = 0, i2s_mask = 0;
> +
> + irq_mask |= FIELD_PREP(I2S_CID_CTRL_I2S_MASK,
> + i2s_mc_priv->pin_tx_mask_adjust);
> +
> + clk_mask |= FIELD_PREP(I2S_CID_CTRL_I2S_STROBE,
> + i2s_mc_priv->pin_tx_mask_adjust) |
> + I2S_CID_CTRL_STROBE_TS;
> +
> + i2s_mask |= FIELD_PREP(I2S_CTRL_I2S_EN, i2s_mc_priv->pin_tx_mask_adjust);
> +
> + if (on) {
> + /* Transmitter data underrun interrupt unmask */
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CID_CTRL, irq_mask, irq_mask);
> +
> + /* Transmitter clock enable */
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CID_CTRL, clk_mask, 0);
> +
> + /*
> + * Transmitter enable
> + * Transmitter synchronizing unit out of reset
> + */
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CTRL,
> + i2s_mask | I2S_CTRL_TSYNC_RST,
> + i2s_mask | I2S_CTRL_TSYNC_RST);
> + } else {
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CTRL,
> + i2s_mask | I2S_CTRL_TSYNC_RST, 0);
> +
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CID_CTRL, clk_mask, clk_mask);
> +
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CID_CTRL, irq_mask, 0);
> + }
> +}
> +
> +static void cdns_i2s_mc_rx_config(struct cdns_i2s_mc_priv *i2s_mc_priv, bool on)
> +{
> + u32 irq_mask = 0, clk_mask = 0, i2s_mask = 0;
> +
> + irq_mask |= FIELD_PREP(I2S_CID_CTRL_I2S_MASK,
> + i2s_mc_priv->pin_rx_mask_adjust);
> +
> + clk_mask |= FIELD_PREP(I2S_CID_CTRL_I2S_STROBE,
> + i2s_mc_priv->pin_rx_mask_adjust) |
> + I2S_CID_CTRL_STROBE_RS;
> +
> + i2s_mask |= FIELD_PREP(I2S_CTRL_I2S_EN, i2s_mc_priv->pin_rx_mask_adjust);
> +
> + if (on) {
> + /* Receiver data overrun interrupt unmask */
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CID_CTRL, irq_mask, irq_mask);
> +
> + /* Receiver clock enable */
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CID_CTRL, clk_mask, 0);
> +
> + /*
> + * Receiver enable
> + * Receiver synchronizing unit out of reset
> + */
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CTRL,
> + i2s_mask | I2S_CTRL_RSYNC_RST,
> + i2s_mask | I2S_CTRL_RSYNC_RST);
> + } else {
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CTRL,
> + i2s_mask | I2S_CTRL_RSYNC_RST, 0);
> +
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CID_CTRL, clk_mask, clk_mask);
> +
> + regmap_update_bits(i2s_mc_priv->regmap, I2S_CID_CTRL, irq_mask, 0);
> + }
> +}
> +
The TX and RX configuration look similar. Perhaps they be factored out
into a helper to reduce duplication?
> +static int cdns_i2s_mc_hw_params(struct snd_pcm_substream *substream,
> + struct snd_pcm_hw_params *params,
> + struct snd_soc_dai *cpu_dai)
> +{
> + struct cdns_i2s_mc_priv *i2s_mc_priv = snd_soc_dai_get_drvdata(cpu_dai);
> + struct device *dev = i2s_mc_priv->dev;
> + u32 rate, sample_rate = 0;
> + u32 slots, slot_width, resolution, ctrl;
> + unsigned long i2s_clk_rate;
> + u8 pin_tx_num, pin_rx_num;
> + struct clk *clk_parent;
> + bool is_master_mode;
> + int ret;
> +
> + rate = params_rate(params);
> + slot_width = i2s_mc_priv->devtype_data->data_width;
Is the slot width fixed by the hardware? If it is configurable, it might
be better to obtain it through .set_tdm_slot().
> + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
> + is_master_mode = ctrl & I2S_CTRL_T_MS;
> + else
> + is_master_mode = ctrl & I2S_CTRL_R_MS;
> +
The master mode is already known in .set_fmt(). It might be cleaner to
store the master state in the private data and use it here. This would
avoid an unnecessary register read.
> +static const struct snd_soc_dai_ops cdns_i2s_mc_dai_ops = {
> + .probe = cdns_i2s_mc_dai_probe,
> + .set_fmt = cdns_i2s_mc_set_fmt,
> +
> + .hw_params = cdns_i2s_mc_hw_params,
Nit: Remove blank line here.
Regards,
Chancel Liu
next prev parent reply other threads:[~2026-09-23 5:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 11:21 [PATCH 0/4] ASoC: Add Cadence I2S-SC and I2S-MC controller support joakim.zhang
2026-09-22 11:21 ` [PATCH 1/4] ASoC: dt-bindings: Add Cadence I2S-SC controller joakim.zhang
2026-09-22 14:23 ` Mark Brown
2026-09-24 7:33 ` Joakim Zhang (张强庆)
2026-09-22 15:35 ` Rob Herring (Arm)
2026-09-22 11:21 ` [PATCH 2/4] ASoC: cdns: Add Cadence I2S-SC controller driver joakim.zhang
2026-09-22 14:34 ` Mark Brown
2026-09-24 10:41 ` Joakim Zhang (张强庆)
2026-09-22 11:21 ` [PATCH 3/4] ASoC: dt-bindings: Add Cadence I2S-MC controller joakim.zhang
2026-09-22 15:35 ` Rob Herring (Arm)
2026-09-22 11:21 ` [PATCH 4/4] ASoC: cdns: Add Cadence I2S-MC controller driver joakim.zhang
2026-09-22 15:01 ` Uwe Kleine-König
2026-09-24 10:41 ` Joakim Zhang (张强庆)
2026-09-23 5:25 ` Chancel Liu [this message]
2026-09-24 10:43 ` Joakim Zhang (张强庆)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6b1637d5-ce36-4702-a404-89ed6c65155f@gmail.com \
--to=chancel.liu@gmail.com \
--cc=broonie@kernel.org \
--cc=cix-kernel-upstream@cixtech.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=joakim.zhang@cixtech.com \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=perex@perex.cz \
--cc=robh@kernel.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®