[PATCH AUTOSEL 6.19-6.18] ASoC: rt1321: fix DMIC ch2/3 mask issue
From: Sasha Levin
Date: Tue Mar 10 2026 - 05:07:08 EST
From: Shuming Fan <shumingf@xxxxxxxxxxx>
[ Upstream commit 986841dcad257615a6e3f89231bb38e1f3506b77 ]
This patch fixed the DMIC ch2/3 mask missing problem.
Signed-off-by: Shuming Fan <shumingf@xxxxxxxxxxx>
Link: https://patch.msgid.link/20260225091210.3648905-1-shumingf@xxxxxxxxxxx
Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
LLM Generated explanations, may be completely bogus:
## Analysis
### What the commit fixes
The RT1321 codec's DMIC (Digital Microphone) channel mask was hardcoded
to `BIT(0) | BIT(1)`, which only enables channels 0 and 1. When more
than 2 channels are requested (e.g., channels 2/3), those channels would
be silently ignored because the mask didn't include them.
The fix dynamically calculates the channel mask using
`GENMASK(num_channels - 1, 0)` based on the actual number of channels
from the audio parameters, so all requested channels are properly
enabled.
### Stable kernel criteria assessment
- **Fixes a real bug**: Yes - DMIC channels 2/3 are non-functional on
RT1321 hardware
- **Obviously correct**: Yes - using `params_channels()` with
`GENMASK()` is the standard pattern (already used elsewhere in this
driver for RT1320_DEV_ID)
- **Small and contained**: Yes - 3 lines changed in 1 file, only affects
the RT1321 code path
- **No new features**: Correct - this purely fixes broken channel
masking
- **Author**: Shuming Fan from Realtek (the codec vendor),
reviewed/merged by Mark Brown (ASoC maintainer)
### Risk assessment
Very low risk. The change is isolated to the `RT1321_DEV_ID` case in
`rt1320_sdw_hw_params()`. It cannot affect RT1320 or any other device
path. The fix pattern (dynamic channel mask from params) is standard
practice.
### Applicability to stable trees
RT1321 support was added in commit `7bf9e646af9a0` which first appeared
in v6.18. This fix is only relevant to stable trees that include that
commit (6.18.y and newer).
### Verification
- `git log --oneline -20 -- sound/soc/codecs/rt1320-sdw.c` confirmed the
file history and that RT1321 support was added in 7bf9e646af9a0
- `git tag --contains 7bf9e646af9a0` confirmed RT1321 support first
appeared in v6.18
- `git show e52b9ff96a5eb --stat` confirmed the fix is 3 insertions, 2
deletions in a single file
- Read the diff: verified the old code hardcoded `BIT(0) | BIT(1)` and
the new code uses `GENMASK(num_channels - 1, 0)`
- The RT1320_DEV_ID case already had a different (working) channel mask
approach, confirming this was an RT1321-specific oversight
This is a small, obvious bug fix from the hardware vendor that fixes
non-functional DMIC channels on RT1321 hardware. It meets all stable
kernel criteria.
**YES**
sound/soc/codecs/rt1320-sdw.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
index e6142645b9038..4d09dd06f2d83 100644
--- a/sound/soc/codecs/rt1320-sdw.c
+++ b/sound/soc/codecs/rt1320-sdw.c
@@ -1455,7 +1455,7 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream,
struct sdw_port_config port_config;
struct sdw_port_config dmic_port_config[2];
struct sdw_stream_runtime *sdw_stream;
- int retval;
+ int retval, num_channels;
unsigned int sampling_rate;
dev_dbg(dai->dev, "%s %s", __func__, dai->name);
@@ -1487,7 +1487,8 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream,
dmic_port_config[1].num = 10;
break;
case RT1321_DEV_ID:
- dmic_port_config[0].ch_mask = BIT(0) | BIT(1);
+ num_channels = params_channels(params);
+ dmic_port_config[0].ch_mask = GENMASK(num_channels - 1, 0);
dmic_port_config[0].num = 8;
break;
default:
--
2.51.0