* [PATCH] ASoC: rt1320-sdw: use ACPI SDCA init table on MSI MS-2631
@ 2026-12-03 7:10 jack.yu
2026-12-04 16:29 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: jack.yu @ 2026-12-03 7:10 UTC (permalink / raw)
To: broonie, lgirdwood
Cc: alsa-devel, lars, flove, oder_chiou, shumingf, derek.fang,
Jack Yu
From: Jack Yu <jack.yu@realtek.com>
On the MSI Stealth 16 AI+ (MS-2631), the RT1320 amplifiers stay
silent after a cold boot. The generic rt1320_vc_blind_write[] preset
does not match this board; the BIOS provides a board-specific SDCA
initial settings.
Add a DMI quirk to apply the ACPI table instead, with the same PDE23
sequencing as the generic preset, falling back to it if no table exists.
Signed-off-by: Jack Yu <jack.yu@realtek.com>
---
sound/soc/codecs/rt1320-sdw.c | 171 +++++++++++++++++++++++++++++++++-
sound/soc/codecs/rt1320-sdw.h | 10 ++
2 files changed, 179 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
index 6724012d5c09..9c6c3c203cfd 100644
--- a/sound/soc/codecs/rt1320-sdw.c
+++ b/sound/soc/codecs/rt1320-sdw.c
@@ -11,6 +11,7 @@
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/dmi.h>
+#include <linux/property.h>
#include <linux/firmware.h>
#include <sound/core.h>
#include <sound/pcm.h>
@@ -19,9 +20,22 @@
#include <sound/initval.h>
#include <sound/tlv.h>
#include <sound/sdw.h>
+#include <sound/sdca.h>
+#include <sound/sdca_function.h>
#include "rt1320-sdw.h"
#include "rt-sdw-common.h"
+static const struct dmi_system_id rt1320_dmi_platform_quirks[] = {
+ {
+ .ident = "MSI Stealth 16 AI+",
+ .matches = {
+ DMI_MATCH(DMI_BOARD_VENDOR, "Micro-Star International Co., Ltd."),
+ DMI_MATCH(DMI_BOARD_NAME, "MS-2631"),
+ },
+ },
+ {}
+};
+
/*
* The 'blind writes' is an SDCA term to deal with platform-specific initialization.
* It might include vendor-specific or SDCA control registers.
@@ -2528,6 +2542,151 @@ static void rt1320_vc_preset(struct rt1320_sdw_priv *rt1320)
}
}
+static int rt1320_soft_reset(struct rt1320_sdw_priv *rt1320)
+{
+ int ret;
+
+ ret = sdw_write_no_pm(rt1320->sdw_slave, 0xc000, 0x03);
+ if (ret < 0) {
+ dev_warn(&rt1320->sdw_slave->dev, "%s: soft reset failed: %d\n",
+ __func__, ret);
+ return ret;
+ }
+ msleep(20);
+
+ return 0;
+}
+
+static int rt1320_get_acpi_init_table(struct rt1320_sdw_priv *rt1320)
+{
+ struct sdw_slave *slave = rt1320->sdw_slave;
+ struct device *dev = &slave->dev;
+ struct fwnode_handle *node = NULL;
+ int i, size, ret;
+
+ if (rt1320->acpi_init_table)
+ return 0;
+
+ for (i = 0; i < slave->sdca_data.num_functions; i++) {
+ if (slave->sdca_data.function[i].type == SDCA_FUNCTION_TYPE_SMART_AMP) {
+ node = slave->sdca_data.function[i].node;
+ break;
+ }
+ }
+ if (!node)
+ return -ENODEV;
+
+ size = fwnode_property_count_u8(node, RT1320_SDCA_INIT_TABLE);
+ if (size <= 0)
+ return size ? size : -ENOENT;
+ if (size % sizeof(struct rt1320_init_write))
+ return -EINVAL;
+
+ rt1320->acpi_init_table = devm_kmalloc(dev, size, GFP_KERNEL);
+ if (!rt1320->acpi_init_table)
+ return -ENOMEM;
+
+ ret = fwnode_property_read_u8_array(node, RT1320_SDCA_INIT_TABLE,
+ (u8 *)rt1320->acpi_init_table, size);
+ if (ret) {
+ devm_kfree(dev, rt1320->acpi_init_table);
+ rt1320->acpi_init_table = NULL;
+ return ret;
+ }
+
+ rt1320->acpi_init_num = size / sizeof(struct rt1320_init_write);
+ dev_dbg(dev, "%s: %d init writes from ACPI\n", __func__, rt1320->acpi_init_num);
+
+ return 0;
+}
+
+static void rt1320_dump_bypass_state(struct rt1320_sdw_priv *rt1320)
+{
+ unsigned int c5c3 = 0, c5c8 = 0;
+
+ regmap_read(rt1320->regmap, 0xc5c3, &c5c3);
+ regmap_read(rt1320->regmap, 0xc5c8, &c5c8);
+
+ dev_dbg(&rt1320->sdw_slave->dev, "%s: c5c3=0x%02x c5c8=0x%02x, DSP bypass: %s\n",
+ __func__, c5c3, c5c8,
+ (c5c3 == 0xf2 && c5c8 == 0x03) ? "yes" : "no");
+}
+
+static int rt1320_write_acpi_init_table(struct rt1320_sdw_priv *rt1320)
+{
+ struct sdw_slave *slave = rt1320->sdw_slave;
+ struct device *dev = &slave->dev;
+ const unsigned int pde23 = SDW_SDCA_CTL(FUNC_NUM_AMP, RT1320_SDCA_ENT_PDE23,
+ RT1320_SDCA_CTL_REQ_POWER_STATE, 0);
+ bool mcu_released = false, ps0 = false;
+ unsigned int addr, val, retry, tmp = 0;
+ int i, ret, failed = 0;
+
+ ret = rt1320_get_acpi_init_table(rt1320);
+ if (ret)
+ return ret;
+
+ dev_dbg(dev, "%s: applying ACPI initialization table (%d writes)\n",
+ __func__, rt1320->acpi_init_num);
+
+ for (i = 0; i < rt1320->acpi_init_num; i++) {
+ addr = le32_to_cpu(rt1320->acpi_init_table[i].addr);
+ val = rt1320->acpi_init_table[i].val;
+
+ if (mcu_released && !ps0 && addr >= 0x10000000 && addr < 0x20000000) {
+ for (retry = 200; retry; retry--) {
+ regmap_read(rt1320->regmap, RT1320_KR0_INT_READY, &tmp);
+ if (tmp == 0x1f)
+ break;
+ usleep_range(1000, 1500);
+ }
+ if (!retry)
+ dev_warn(dev, "%s: MCU is NOT ready (0x%x)\n", __func__, tmp);
+
+ regmap_write(rt1320->regmap, pde23, 0x00);
+ rt1320_pde_transition_delay(rt1320, FUNC_NUM_AMP,
+ RT1320_SDCA_ENT_PDE23, 0x00);
+ ps0 = true;
+ }
+
+ ret = regmap_write(rt1320->regmap, addr, val);
+ if (ret) {
+ failed++;
+ dev_dbg(dev, "%s: write 0x%08x=0x%02x failed: %d\n",
+ __func__, addr, val, ret);
+ }
+
+ if (addr == 0xd486 && !(val & 0x80))
+ mcu_released = true;
+ }
+
+ regmap_write(rt1320->regmap, pde23, 0x03);
+ rt1320_pde_transition_delay(rt1320, FUNC_NUM_AMP, RT1320_SDCA_ENT_PDE23, 0x03);
+
+ if (failed)
+ dev_warn(dev, "%s: %d of %d init writes failed\n",
+ __func__, failed, rt1320->acpi_init_num);
+
+ rt1320_dump_bypass_state(rt1320);
+
+ return 0;
+}
+
+static void rt1320_vc_board_preset(struct rt1320_sdw_priv *rt1320)
+{
+ int ret;
+
+ if (rt1320->use_acpi_init_table) {
+ ret = rt1320_write_acpi_init_table(rt1320);
+ if (!ret)
+ return;
+ dev_warn(&rt1320->sdw_slave->dev,
+ "%s: no usable ACPI init table (%d), falling back to generic preset\n",
+ __func__, ret);
+ }
+ rt1320_vc_preset(rt1320);
+}
+
static void rt1321_preset(struct rt1320_sdw_priv *rt1320)
{
const struct reg_sequence *blindwrite;
@@ -2575,6 +2734,7 @@ static int rt1320_io_init(struct device *dev, struct sdw_slave *slave)
{
struct rt1320_sdw_priv *rt1320 = dev_get_drvdata(dev);
unsigned int amp_func_status, val, tmp;
+ bool force_preset = false;
if (rt1320->hw_init)
return 0;
@@ -2590,6 +2750,10 @@ static int rt1320_io_init(struct device *dev, struct sdw_slave *slave)
*/
/* update count of parent 'active' children */
pm_runtime_set_active(&slave->dev);
+ if (rt1320->use_acpi_init_table) {
+ rt1320_soft_reset(rt1320);
+ force_preset = true;
+ }
}
pm_runtime_get_noresume(&slave->dev);
@@ -2625,13 +2789,13 @@ static int rt1320_io_init(struct device *dev, struct sdw_slave *slave)
dev_dbg(dev, "%s amp func_status=0x%x\n", __func__, amp_func_status);
/* initialization write */
- if ((amp_func_status & FUNCTION_NEEDS_INITIALIZATION)) {
+ if ((amp_func_status & FUNCTION_NEEDS_INITIALIZATION) || force_preset) {
switch (rt1320->dev_id) {
case RT1320_DEV_ID:
if (rt1320->version_id < RT1320_VC)
rt1320_vab_preset(rt1320);
else
- rt1320_vc_preset(rt1320);
+ rt1320_vc_board_preset(rt1320);
break;
case RT1321_DEV_ID:
rt1321_preset(rt1320);
@@ -3735,6 +3899,9 @@ static int rt1320_sdw_init(struct device *dev, struct regmap *regmap,
rt1320->fu_mixer_mute[2] = rt1320->fu_mixer_mute[3] = true;
rt1320->brown_out = 1;
+ rt1320->use_acpi_init_table =
+ !!dmi_check_system(rt1320_dmi_platform_quirks);
+
INIT_WORK(&rt1320->load_dspfw_work, rt1320_load_dspfw_work);
ret = devm_snd_soc_register_component(dev,
diff --git a/sound/soc/codecs/rt1320-sdw.h b/sound/soc/codecs/rt1320-sdw.h
index 99f8ba6462a4..7a1bff24dbbf 100644
--- a/sound/soc/codecs/rt1320-sdw.h
+++ b/sound/soc/codecs/rt1320-sdw.h
@@ -127,6 +127,13 @@ enum rt1321_version_id {
#define RT1321_CMD_PARAM_ADDR 0x3fc2d310
#define RT1321_DSPFW_STATUS_ADDR 0x3fc2dfc4
+#define RT1320_SDCA_INIT_TABLE "mipi-sdca-function-initialization-table"
+
+struct rt1320_init_write {
+ __le32 addr;
+ u8 val;
+} __packed;
+
/* moudleid + commandtype + reserved1 + commandlength */
#define RT1320_FW_CMD_HDR_SIZE 8
@@ -220,6 +227,9 @@ struct rt1320_sdw_priv {
bool cali_done;
bool fw_load_done;
bool rae_update_done;
+ bool use_acpi_init_table;
+ struct rt1320_init_write *acpi_init_table;
+ int acpi_init_num;
struct work_struct load_dspfw_work;
struct sdw_bpt_msg bra_msg;
unsigned short l_adv_gain, r_adv_gain;
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ASoC: rt1320-sdw: use ACPI SDCA init table on MSI MS-2631
2026-12-03 7:10 [PATCH] ASoC: rt1320-sdw: use ACPI SDCA init table on MSI MS-2631 jack.yu
@ 2026-12-04 16:29 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-12-04 16:29 UTC (permalink / raw)
To: jack.yu
Cc: broonie, lgirdwood, alsa-devel, lars, flove, oder_chiou, shumingf,
derek.fang
j Insert your comments under the relevant lines of code. Lines
# starting with "> " are quoted diff context and lines starting
# with "| " are comments from other reviewers, or your own that were
# already sent; these are not sent. Everything you type is sent
# exactly as written and where you wrote it -- including any trailer
# (Reviewed-by:, etc.) you place inline. The only change made on
# send is to drop quoted diff left below your last comment; quoted
# context you keep above a comment is sent as-is. Trim freely.
# To discard a run of quoted context without deleting it by hand, put
# ">--cut--" alone on a line -- everything quoted above it back to your last
# note is dropped when you send.
#
> On the MSI Stealth 16 AI+ (MS-2631), the RT1320 amplifiers stay
> silent after a cold boot. The generic rt1320_vc_blind_write[] preset
> does not match this board; the BIOS provides a board-specific SDCA
> initial settings.
> Add a DMI quirk to apply the ACPI table instead, with the same PDE23
> sequencing as the generic preset, falling back to it if no table exists.
> @@ -2590,6 +2750,10 @@ static int rt1320_io_init(struct device *dev, struct sdw_slave *slave)
> */
> /* update count of parent 'active' children */
> pm_runtime_set_active(&slave->dev);
> + if (rt1320->use_acpi_init_table) {
> + rt1320_soft_reset(rt1320);
> + force_preset = true;
It's a bit more complex than this, see 04c3ee0f5d15 (ASoC: rt1320: avoid
re-initialize in advanced mode) for issues around not resetting when we
don't need to - we might have state we can't easily reuse.
--
Mark Brown <broonie@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 16:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 7:10 [PATCH] ASoC: rt1320-sdw: use ACPI SDCA init table on MSI MS-2631 jack.yu
2026-12-04 16:29 ` Mark Brown
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.