Skip to contentSkip to conversation

ASoC: Add support for Iron Device MA5311

PATCH New Hyunuk Son 2 participants 4 messages Nov 27

Subsystems (4)
lore
Share & tools
lore

Hyunuk Son

author
#0 lore raw

v3 cover ASoC: Add support for Iron Device MA5311

This patch series adds ASoC support for the Iron Device MA5311 audio codec.

The MA5311 integrates digital speaker amplification, analog-to-digital conversion, and audio DSP functionality.

The series includes a Device Tree binding and an ASoC codec driver supporting I2S and TDM playback and capture.

Changes in v3:

Add the Reviewed-by tag to the Device Tree binding patch.

Restore DAI configuration after hardware reset.

Register the reset control only when the reset GPIO is available.

Correct BCLK calculation for I2S and TDM operation.

Remove redundant software register caches and rely on regmap caches.

Rework DAPM widgets and routes.

Hyunuk Son (2):
ASoC: dt-bindings: Add Iron Device MA5311
ASoC: codecs: Add driver for Iron Device MA5311

 .../bindings/sound/irondevice,ma5311.yaml     |   84 +
 MAINTAINERS                                   |    2 +
 sound/soc/codecs/Kconfig                      |   12 +
 sound/soc/codecs/Makefile                     |    2 +
 sound/soc/codecs/ma5311.c                     | 2300 +++++++++++++++++
 sound/soc/codecs/ma5311.h                     |  558 ++++
 6 files changed, 2958 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/irondevice,ma5311.yaml
 create mode 100644 sound/soc/codecs/ma5311.c
 create mode 100644 sound/soc/codecs/ma5311.h

base-commit: a6c7e545d8abac8ad0b48da4c8b4ca5ef8ea8eda

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v3 1/2 ASoC: dt-bindings: Add Iron Device MA5311

The Iron Device MA5311 is an audio codec integrating digital speaker amplification, analog-to-digital conversion, and audio DSP functionality.

The device uses two I2C slave addresses for separate control and ADC register banks. It also provides an active-low reset input and an interrupt output for fault and thermal warning notification.

Add the Device Tree binding to describe these hardware interfaces.

---
 .../bindings/sound/irondevice,ma5311.yaml     | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/irondevice,ma5311.yaml
Documentation/devicetree/bindings/sound/irondevice,ma5311.yaml new file +84 -0
new file mode 100644
index 000000000000..d013d539e0ef
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/irondevice,ma5311.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Iron Device MA5311 Audio Codec
+
+maintainers:
+  - Hyunuk Son <[email protected]>
+
+description:
+  The Iron Device MA5311 integrates digital speaker amplification,
+  analog-to-digital conversion, and audio DSP functionality.
+
+  The device uses two I2C slave addresses. The first address
+  provides access to the control register bank, while the second
+  provides access to the ADC register bank.
+
+  The device provides an active-low reset input and an active-low
+  interrupt output for fault and thermal warning notification.
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    enum:
+      - irondevice,ma5311
+
+  reg:
+    items:
+      - description: I2C address for control registers
+      - description: I2C address for ADC registers
+
+  reg-names:
+    items:
+      - const: control
+      - const: adc
+
+  reset-gpios:
+    maxItems: 1
+    description:
+      GPIO connected to the active-low RSTN pin.
+
+  interrupts:
+    maxItems: 1
+    description:
+      Falling-edge interrupt from the active-low INTN output.
+      INTN is deasserted when the fault condition clears.
+
+  '#sound-dai-cells':
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - '#sound-dai-cells'
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        audio-codec@3e {
+            compatible = "irondevice,ma5311";
+
+            reg = <0x3e>, <0x3f>;
+            reg-names = "control", "adc";
+
+            reset-gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
+            interrupt-parent = <&gpio>;
+            interrupts = <3 IRQ_TYPE_EDGE_FALLING>;
+
+            #sound-dai-cells = <1>;
+        };
+    };
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v3 2/2 ASoC: codecs: Add driver for Iron Device MA5311

In reply to Hyunuk Son

Add an ASoC codec driver for the Iron Device MA5311.

The driver supports audio playback and capture through I2S and TDM interfaces. It provides ALSA mixer controls for audio configuration and uses regmap for register access.

---
 MAINTAINERS               |    2 +
 sound/soc/codecs/Kconfig  |   12 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/ma5311.c | 2300 +++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/ma5311.h |  558 +++++++++
 5 files changed, 2874 insertions(+)
 create mode 100644 sound/soc/codecs/ma5311.c
 create mode 100644 sound/soc/codecs/ma5311.h
MAINTAINERS +2 -0
index ca6853f7eb9f..7c9860e9d999 100644
@@ -14128,9 +14128,11 @@ F:	net/netfilter/ipvs/
 
 IRON DEVICE AUDIO CODEC DRIVERS
 M:	Kiseok Jo <[email protected]>
+M:	Hyunuk Son <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/sound/irondevice,*
+F:	sound/soc/codecs/ma5311.*
 F:	sound/soc/codecs/sma*
 
 IRQ DOMAINS (IRQ NUMBER MAPPING LIBRARY)
sound/soc/codecs/Kconfig +12 -0
index 6239de3afa5a..720b27f6cdd1 100644
@@ -145,6 +145,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_LM4857
 	imply SND_SOC_LM49453
 	imply SND_SOC_LOCHNAGAR_SC
+	imply SND_SOC_MA5311
 	imply SND_SOC_MAX98088
 	imply SND_SOC_MAX98090
 	imply SND_SOC_MAX98095
@@ -1448,6 +1449,17 @@ config SND_SOC_LOCHNAGAR_SC
 	  This driver support the sound card functionality of the Cirrus
 	  Logic Lochnagar audio development board.
 
+config SND_SOC_MA5311
+	tristate "Iron Device MA5311 Audio Codec"
+	depends on I2C && GPIOLIB
+	select REGMAP_I2C
+	help
+	  Enable support for the Iron Device MA5311 audio codec with
+	  playback and capture over an I2S/TDM interface.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called snd-soc-ma5311.
+
 config SND_SOC_MADERA
 	tristate
 	select SND_SOC_WM_ADSP
sound/soc/codecs/Makefile +2 -0
index 459a2aa463f3..ae6a83872ea5 100644
@@ -167,6 +167,7 @@ snd-soc-lpass-rx-macro-y := lpass-rx-macro.o
 snd-soc-lpass-tx-macro-y := lpass-tx-macro.o
 snd-soc-lpass-wsa-macro-y := lpass-wsa-macro.o
 snd-soc-lpass-va-macro-y := lpass-va-macro.o
+snd-soc-ma5311-y := ma5311.o
 snd-soc-madera-y := madera.o
 snd-soc-max9759-y := max9759.o
 snd-soc-max9768-y := max9768.o
@@ -614,6 +615,7 @@ obj-$(CONFIG_SND_SOC_JZ4770_CODEC)	+= snd-soc-jz4770-codec.o
 obj-$(CONFIG_SND_SOC_LM4857)	+= snd-soc-lm4857.o
 obj-$(CONFIG_SND_SOC_LM49453)   += snd-soc-lm49453.o
 obj-$(CONFIG_SND_SOC_LOCHNAGAR_SC)	+= snd-soc-lochnagar-sc.o
+obj-$(CONFIG_SND_SOC_MA5311)	+= snd-soc-ma5311.o
 obj-$(CONFIG_SND_SOC_MADERA)	+= snd-soc-madera.o
 obj-$(CONFIG_SND_SOC_MAX9759)	+= snd-soc-max9759.o
 obj-$(CONFIG_SND_SOC_MAX9768)	+= snd-soc-max9768.o
sound/soc/codecs/ma5311.c new file +2300 -0

2,300 lines not on this page · raw message

sound/soc/codecs/ma5311.h new file +558 -0

558 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v3 2/2] ASoC: codecs: Add driver for Iron Device MA5311

Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [Medium] ASoC: ma5311: broken slot lookup and restore in ma5311_reset_control_put() - [Medium] ASoC…

Thank you for your contribution! Sashiko AI review found 7 potential issues to consider:
- [Medium] ASoC: ma5311: broken slot lookup and restore in ma5311_reset_control_put()
- [Medium] ASoC: ma5311: premature speaker mode write in ma5311_aif_in_event()
- [Medium] ASoC: ma5311: unlocked amp_power_status check in ma5311_dapm_aif_in_put()
- [Medium] ASoC: ma5311: zero rx_mask clobbers RX slots in ma5311_dai_set_tdm_slot()
- [Medium] ASoC: ma5311: flag_dai_tdm skips TDM TX setup in ma5311_dai_hw_params()
- [Medium] ASoC: ma5311: PLL and ADC clock left enabled by ma5311_dai_hw_params()
- [Low] ASoC: ma5311: duplicate format validation switch in ma5311_dai_set_fmt()
--

commit 047836593fa27eab5c43de3db5553f6e85de9ab6
Author: Hyunuk Son <[email protected]>

ASoC: codecs: Add driver for Iron Device MA5311

This commit adds an ASoC codec driver for the Iron Device MA5311 audio codec supporting I2S and TDM playback and capture.

Quoted 5 lines
sound/soc/codecs/ma5311.c new file +0 -0
new file mode 100644
index 0000000000000..d548fcd0267b4

[ ... ]

Quoted 25 lines
sound/soc/codecs/ma5311.c new file +25 -0
+static int ma5311_reset_control_put(struct snd_kcontrol *kcontrol,
+				    struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct ma5311_priv *ma5311 = snd_soc_component_get_drvdata(component);
+	struct snd_soc_dapm_context *dapm =
+		snd_soc_component_to_dapm(component);
+	struct snd_kcontrol *slot_control;
+	unsigned int val = ucontrol->value.enumerated.item[0];
+	unsigned int rx_slot;
+	int ret = 0;
+
+	if (!val)
+		return 0;
+
+	if (!ma5311->reset_gpio)
+		return -ENODEV;
+
+	if (val >= ARRAY_SIZE(ma5311_reset_text))
+		return -EINVAL;
+
+	slot_control = snd_soc_card_get_kcontrol(component->card,
+						 "RX Slot Configuration");
+	if (!slot_control)
+		return -ENOENT;

[ ... ]

sound/soc/codecs/ma5311.c line 868

Quoted 8 lines
sound/soc/codecs/ma5311.c new file +8 -0
+	rx_slot = snd_soc_dapm_kcontrol_get_value(slot_control);
+	rx_slot &= MA5311_TDM_SLOT0_RX_POS_MASK |
+		MA5311_TDM_SLOT1_RX_POS_MASK;
+	ma5311->dai_tdm1_rx_pos = rx_slot;
+
+	ma5311->flag_ext_rst = true;
+	ret = ma5311_reset(component);
+	ma5311->flag_ext_rst = false;

[Severity: Medium]
Does looking up "RX Slot Configuration" via snd_soc_card_get_kcontrol() fail with -ENOENT whenever component->name_prefix is set (for example on multi-amplifier TDM boards), where snd_soc_component_get_kcontrol() is needed instead?

Also, overwriting ma5311->dai_tdm1_rx_pos with snd_soc_dapm_kcontrol_get_value(slot_control) discards any TDM RX slot configuration set through ma5311_dai_set_tdm_slot() or ma5311_dai_hw_params(), because those paths update MA5311_DAC_37_TDM1 and ma5311->dai_tdm1_rx_pos directly without updating slot_control's cached DAPM value. In addition, I2S playback in ma5311_dai_hw_params() clears MA5311_DAC_37_TDM1 and ma5311->dai_tdm1_rx_pos to MA5311_DISABLE_TDM_SLOT, and switching back to SND_SOC_DAIFMT_DSP_A playback never restores them.

[ ... ]

Quoted 16 lines
sound/soc/codecs/ma5311.c new file +16 -0
+static int ma5311_dapm_aif_in_put(struct snd_kcontrol *kcontrol,
+				  struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_dapm_context *dapm =
+		snd_soc_dapm_kcontrol_to_dapm(kcontrol);
+	struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
+	struct ma5311_priv *ma5311 = snd_soc_component_get_drvdata(component);
+	unsigned int val = ucontrol->value.enumerated.item[0];
+	unsigned int old_val = snd_soc_dapm_kcontrol_get_value(kcontrol);
+
+	if (val >= ARRAY_SIZE(ma5311_aif_in_source_text)) {
+		dev_err(ma5311->dev, "%s: Out of range\n", __func__);
+		return -EINVAL;
+	}
+
+	if (old_val == val)

sound/soc/codecs/ma5311.c line 1010

Quoted 10 lines
sound/soc/codecs/ma5311.c new file +10 -0
+		return 0;
+
+	if (ma5311->amp_power_status) {
+		dev_warn(ma5311->dev,
+			 "Cannot change AIF IN Source during playback\n");
+		return -EBUSY;
+	}
+
+	return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
+}

[Severity: Medium]
Can ma5311_dapm_aif_in_put() race with playback startup because old_val and ma5311->amp_power_status are checked before taking card->dapm_mutex?

CPU0 CPU1
ma5311_dapm_aif_in_put()
if (ma5311->amp_power_status)

    (false)
                                      soc_pcm_prepare()
                                        mutex_lock_nested(&card->dapm_mutex)
                                        ...
                                        ma5311_aif_in_event()
                                        ma5311_startup()
                                          ma5311->amp_power_status = true
                                        mutex_unlock(&card->dapm_mutex)

snd_soc_dapm_put_enum_double()
mutex_lock_nested(&card->dapm_mutex)
snd_soc_dapm_mux_update_power() <-- updates mux while powered

Because both "Mono Both" and "Stereo" routes connect from "AIF IN", the "AIF IN Source" widget stays powered across the mux change and SND_SOC_DAPM_PRE_PMU does not re-fire, leaving the kcontrol out of sync with ma5311->amp_mode and the hardware registers.

[ ... ]

Quoted 32 lines
sound/soc/codecs/ma5311.c new file +32 -0
+static int ma5311_aif_in_event(struct snd_soc_dapm_widget *w,
+			       struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+	struct ma5311_priv *ma5311 = snd_soc_component_get_drvdata(component);
+	unsigned int mux = snd_soc_dapm_kcontrol_get_value(w->kcontrols[0]);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		switch (mux) {
+		case MA5311_MONO_BOTH_MODE:
+			regmap_update_bits(ma5311->ctrl_regmap,
+					   MA5311_DAC_10_SYSTEM_CTRL3,
+					   MA5311_SPK_MODE_MASK,
+					   MA5311_SPK_MONO_BOTH);
+			regmap_update_bits(ma5311->ctrl_regmap,
+					   MA5311_DAC_37_TDM1,
+					   MA5311_DAC_TDM_STEREO_MASK,
+					   MA5311_DAC_TDM_MONO);
+			break;
+		case MA5311_STEREO_MODE:
+			regmap_update_bits(ma5311->ctrl_regmap,
+					   MA5311_DAC_10_SYSTEM_CTRL3,
+					   MA5311_SPK_MODE_MASK,
+					   MA5311_SPK_STEREO);
+			regmap_update_bits(ma5311->ctrl_regmap,
+					   MA5311_DAC_37_TDM1,
+					   MA5311_DAC_TDM_STEREO_MASK,
+					   MA5311_DAC_TDM_STEREO);
+			break;
+		default:
+			dev_err(ma5311->dev, "%s: Invalid value (%u)\n",

sound/soc/codecs/ma5311.c line 1065

Quoted 10 lines
sound/soc/codecs/ma5311.c new file +10 -0
+				__func__, mux);
+			return -EINVAL;
+		}
+
+		ma5311->amp_mode = mux;
+		break;
+	}
+
+	return 0;
+}

[Severity: Medium]
Does writing MA5311_DAC_10_SYSTEM_CTRL3 and MA5311_DAC_37_TDM1 in ma5311_aif_in_event() cause the post-power-on writes in ma5311_startup() to be skipped by regcache?

During DAPM power-up, "AIF IN Source" (a mux widget) runs ma5311_aif_in_event() before "AMP Power" (an out_drv widget) runs ma5311_startup(). ma5311_aif_in_event() writes the speaker mode while MA5311_PLL_MASK and MA5311_POWER_MASK are still off, and because ctrl_regmap uses REGCACHE_FLAT, the later regmap_update_bits() calls on MA5311_DAC_10_SYSTEM_CTRL3 and MA5311_DAC_37_TDM1 in ma5311_startup() after enabling PLL and chip power become cache-hit no-ops.

Also, ma5311_shutdown() forces MA5311_SPK_MUTE in MA5311_DAC_0E_MUTE_VOL_CTRL on DAPM power-down, but ma5311_startup() never restores ma5311->dai_spk_mute on power-up. Finally, "AIF IN Source" subscribes to SND_SOC_DAPM_POST_PMU in ma5311_dapm_widgets even though ma5311_aif_in_event() only handles SND_SOC_DAPM_PRE_PMU.

[ ... ]

Quoted 3 lines
sound/soc/codecs/ma5311.c new file +3 -0
+static int ma5311_setup_pll(struct snd_soc_component *component,
+			    unsigned int bclk)
+{

[ ... ]

Quoted 3 lines
sound/soc/codecs/ma5311.c new file +3 -0
+	regmap_update_bits(ma5311->ctrl_regmap,
+			   MA5311_DAC_A2_TOP_MAN2,
+			   MA5311_PLL_MASK, MA5311_PLL_ON);

[ ... ]

Quoted 4 lines
sound/soc/codecs/ma5311.c new file +4 -0
+static int ma5311_dai_hw_params(struct snd_pcm_substream *substream,
+				struct snd_pcm_hw_params *params,
+				struct snd_soc_dai *dai)
+{

[ ... ]

sound/soc/codecs/ma5311.c line 1586

Quoted 6 lines
sound/soc/codecs/ma5311.c new file +6 -0
+	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+		regmap_update_bits(ma5311->ctrl_regmap,
+				   MA5311_DAC_B8_TOP_MAN5,
+				   MA5311_DAC_ADC_CLK_ON_MASK,
+				   MA5311_DAC_ADC_CLK_ON);
+		ma5311->dai_adc_clk = MA5311_DAC_ADC_CLK_ON;

[Severity: Medium]
Can ma5311_dai_hw_params() leave the PLL and ADC clock enabled when hw_params fails or a substream is closed without starting?

ma5311_setup_pll() turns on MA5311_PLL_ON during ma5311_dai_hw_params() before params_format(params) is validated and before DAPM powers up the widgets. Because the PLL is only turned off in DAPM power-down callbacks (ma5311_shutdown() and ma5311_adc_event()), an unsupported PCM format or a substream closed before DAPM power-up leaves the PLL powered on. Likewise, capture hw_params enables MA5311_DAC_ADC_CLK_ON in MA5311_DAC_B8_TOP_MAN5, and no error path or DAPM power-down callback ever disables it.

In addition, ma5311_i2c_probe() initializes ma5311->dai_sdo_len and ma5311->dai_sck_rate to 16-bit/32FS (0x5c), whereas ma5311_ctrl_reg_def initializes register 0xa1 to 24-bit/64FS (0x40), and ma5311_dai_set_fmt() repeats the switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) check twice.

[ ... ]

Quoted 16 lines
sound/soc/codecs/ma5311.c new file +16 -0
+		case SND_SOC_DAIFMT_DSP_A:
+			dev_info(component->dev, "Working in TDM TX Mode\n");
+			regmap_update_bits(ma5311->ctrl_regmap,
+					   MA5311_DAC_A1_TOP_MAN1_FOR_SDO,
+					   MA5311_TOP_MAN1_O_FORMAT_MASK,
+					   MA5311_TOP_MAN1_O_FORMAT_TDM);
+			ma5311->dai_o_format = MA5311_TOP_MAN1_O_FORMAT_TDM;
+
+			if (!ma5311->flag_dai_tdm) {
+				regmap_update_bits(ma5311->ctrl_regmap,
+						   MA5311_DAC_38_TDM2,
+						   MA5311_ADC_TDM2_SETTING_MASK,
+						   MA5311_DAC_38_CAPTURE_8CH_CFG);
+				ma5311->dai_tdm2_capture_cfg = MA5311_DAC_38_CAPTURE_8CH_CFG;
+
+				regmap_write(ma5311->ctrl_regmap,

sound/soc/codecs/ma5311.c line 1792

Quoted 10 lines
sound/soc/codecs/ma5311.c new file +10 -0
+					     MA5311_DAC_39_DATA_PATH, MA5311_ADC_DATA_PATH_TDM_8CH);
+				ma5311->dai_data_path = MA5311_ADC_DATA_PATH_TDM_8CH;
+
+				regmap_write(ma5311->ctrl_regmap,
+					     MA5311_DAC_3A_TDM_SLOT_ENABLE,
+					     MA5311_TDM_SLOT_ENABLE_ALL);
+				ma5311->dai_tdm_slot_enable = MA5311_TDM_SLOT_ENABLE_ALL;
+			}
+
+			break;

[Severity: Medium]
Does gating the TDM capture register setup on !ma5311->flag_dai_tdm leave all TX TDM slots disabled if ma5311_dai_set_tdm_slot() was called with tx_mask == 0?

ma5311_dai_set_tdm_slot() only configures MA5311_DAC_38_TDM2, MA5311_DAC_39_DATA_PATH, and MA5311_DAC_3A_TDM_SLOT_ENABLE when tx_mask is GENMASK(7, 0), yet it sets ma5311->flag_dai_tdm = true unconditionally. Similarly, I2S capture in ma5311_dai_hw_params() writes MA5311_ADC_DATA_PATH_I2S and MA5311_TDM_SLOT_DISABLE_ALL without clearing flag_dai_tdm, so a subsequent DSP_A capture session also skips enabling the TDM data path and TX slots.

Quoted 27 lines
sound/soc/codecs/ma5311.c new file +27 -0
+		}
+	}
+
+	return 0;
+}
+
+static int ma5311_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+	struct snd_soc_component *component = dai->component;
+	struct ma5311_priv *ma5311 = snd_soc_component_get_drvdata(component);
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+	case SND_SOC_DAIFMT_DSP_A:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+	case SND_SOC_DAIFMT_NB_NF:
+	case SND_SOC_DAIFMT_NB_IF:
+	case SND_SOC_DAIFMT_IB_NF:
+	case SND_SOC_DAIFMT_IB_IF:
+		break;
+	default:
+		return -EINVAL;

sound/soc/codecs/ma5311.c line 1829

Quoted 10 lines
sound/soc/codecs/ma5311.c new file +10 -0
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+	case SND_SOC_DAIFMT_DSP_A:
+		break;
+
+	default:
+		return -EINVAL;
+	}

[Severity: Low]
This second switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) block duplicates the check at the start of ma5311_dai_set_fmt().

[ ... ]

Quoted 9 lines
sound/soc/codecs/ma5311.c new file +9 -0
+static int ma5311_dai_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 ma5311_priv *ma5311 = snd_soc_component_get_drvdata(component);
+	unsigned int rx_val = MA5311_TDM_SLOT0_RX_POS_0 |
+			      MA5311_TDM_SLOT1_RX_POS_1;
+	int ret;

[ ... ]

Quoted 8 lines
sound/soc/codecs/ma5311.c new file +8 -0
+	switch (rx_mask) {
+	case 0:
+		break;
+
+	case BIT(0) | BIT(1):
+		rx_val = MA5311_TDM_SLOT0_RX_POS_0 |
+			 MA5311_TDM_SLOT1_RX_POS_1;
+		break;

[ ... ]

sound/soc/codecs/ma5311.c line 2030

Quoted 9 lines
sound/soc/codecs/ma5311.c new file +9 -0
+	ret = regmap_update_bits(ma5311->ctrl_regmap,
+				 MA5311_DAC_37_TDM1,
+				 MA5311_TDM_SLOT0_RX_POS_MASK |
+				 MA5311_TDM_SLOT1_RX_POS_MASK,
+				 rx_val);
+	if (ret)
+		return ret;
+
+	ma5311->dai_tdm1_rx_pos = rx_val;

[Severity: Medium]
When rx_mask is 0, does ma5311_dai_set_tdm_slot() unintentionally reset MA5311_DAC_37_TDM1 and ma5311->dai_tdm1_rx_pos to Slot01?

rx_val is initialized to MA5311_TDM_SLOT0_RX_POS_0 | MA5311_TDM_SLOT1_RX_POS_1, and case 0 breaks out of switch (rx_mask) before unconditionally writing rx_val to MA5311_DAC_37_TDM1, clobbering any previously configured RX slots when a caller only wants to configure tx_mask.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2