From: <jack.yu@realtek.com>
To: <broonie@kernel.org>, <lgirdwood@gmail.com>
Cc: <alsa-devel@alsa-project.org>, <lars@metafoo.de>,
<flove@realtek.com>, <oder_chiou@realtek.com>,
<shumingf@realtek.com>, <derek.fang@realtek.com>,
Jack Yu <jack.yu@realtek.com>
Subject: [PATCH] ASoC: rt1320-sdw: use ACPI SDCA init table on MSI MS-2631
Date: Thu, 3 Dec 2026 15:10:17 +0800 [thread overview]
Message-ID: <20261203071017.3129092-1-jack.yu@realtek.com> (raw)
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
next reply other threads:[~2026-12-03 7:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 7:10 jack.yu [this message]
2026-12-04 16:29 ` [PATCH] ASoC: rt1320-sdw: use ACPI SDCA init table on MSI MS-2631 Mark Brown
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=20261203071017.3129092-1-jack.yu@realtek.com \
--to=jack.yu@realtek.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=derek.fang@realtek.com \
--cc=flove@realtek.com \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=oder_chiou@realtek.com \
--cc=shumingf@realtek.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 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.