Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Oder Chiou <oder_chiou@realtek.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>, Shuming Fan <shumingf@realtek.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Bard Liao <yung-chuan.liao@linux.intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ASoC: rt1320: fix 32-bit link failure
Date: Tue, 23 Dec 2025 22:52:53 +0100	[thread overview]
Message-ID: <20251223215259.677762-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

A plain 64-bit division causes a link failure in some configurations:

ERROR: modpost: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-rt1320-sdw.ko] undefined!

Since this divides by a constant, using the div_u64() macro ends up
turning this into an efficient multiply/shift operation where possible.

In rt1320_calc_r0(), the open-coded shift seems a litle simpler.

Fixes: da1682d5e8b5 ("ASoC: rt1320: support calibration and temperature/r0 loading")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 sound/soc/codecs/rt1320-sdw.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
index 342494e0fc5a..245b9d9980f9 100644
--- a/sound/soc/codecs/rt1320-sdw.c
+++ b/sound/soc/codecs/rt1320-sdw.c
@@ -1065,8 +1065,8 @@ static int rt1320_invrs_load(struct rt1320_sdw_priv *rt1320)
 	r_rsratio = rt1320_rsgain_to_rsratio(rt1320, r_rsgain);
 	dev_dbg(dev, "%s, LR rsratio=%lld, %lld\n", __func__, l_rsratio, r_rsratio);
 
-	l_invrs = (l_rsratio * factor) / 1000000000U;
-	r_invrs = (r_rsratio * factor) / 1000000000U;
+	l_invrs = div_u64(l_rsratio * factor, 1000000000U);
+	r_invrs = div_u64(r_rsratio * factor, 1000000000U);
 
 	rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 6, &r0_data[0], sizeof(struct rt1320_datafixpoint));
 	rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 7, &r0_data[1], sizeof(struct rt1320_datafixpoint));
@@ -1087,15 +1087,15 @@ static int rt1320_invrs_load(struct rt1320_sdw_priv *rt1320)
 static void rt1320_calc_r0(struct rt1320_sdw_priv *rt1320)
 {
 	struct device *dev = &rt1320->sdw_slave->dev;
-	unsigned long long l_calir0, r_calir0;
-	const unsigned int factor = (1 << 27);
+	unsigned long long l_calir0, r_calir0, l_calir0_lo, r_calir0_lo;
 
-	l_calir0 = (rt1320->r0_l_reg * 1000) / factor;
-	r_calir0 = (rt1320->r0_r_reg * 1000) / factor;
+	l_calir0 = rt1320->r0_l_reg >> 27;
+	r_calir0 = rt1320->r0_r_reg >> 27;
+	l_calir0_lo = (rt1320->r0_l_reg & ((1ull << 27) - 1) * 1000) >> 27;
+	r_calir0_lo = (rt1320->r0_r_reg & ((1ull << 27) - 1) * 1000) >> 27;
 
 	dev_dbg(dev, "%s, l_calir0=%lld.%03lld ohm, r_calir0=%lld.%03lld ohm\n", __func__,
-		l_calir0 / 1000, l_calir0 % 1000,
-		r_calir0 / 1000, r_calir0 % 1000);
+		l_calir0, l_calir0_lo, r_calir0, r_calir0_lo);
 }
 
 static void rt1320_calibrate(struct rt1320_sdw_priv *rt1320)
-- 
2.39.5


             reply	other threads:[~2025-12-23 21:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-23 21:52 Arnd Bergmann [this message]
2025-12-24 14:45 ` [PATCH] ASoC: rt1320: fix 32-bit link failure 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=20251223215259.677762-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=oder_chiou@realtek.com \
    --cc=perex@perex.cz \
    --cc=sakari.ailus@linux.intel.com \
    --cc=shumingf@realtek.com \
    --cc=tiwai@suse.com \
    --cc=yung-chuan.liao@linux.intel.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