From: Arsenii Pashchenko <ulijg308@gmail.com>
To: pkshih@realtek.com
Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
Arsenii Pashchenko <ulijg308@gmail.com>
Subject: [PATCH wireless-next v2 4/4] wifi: rtw88: rtw8822c: simplify amplitude search and offset via s32
Date: Thu, 13 Aug 2026 12:47:32 +0700 [thread overview]
Message-ID: <0bb6e2fb78d0b2def623210938204a0efbbe2034.1786599645.git.ulijg308@gmail.com> (raw)
In-Reply-To: <cover.1786599645.git.ulijg308@gmail.com>
Complete the signed data transition by removing the complex
rtw8822c_rf_minmax_cmp() helper. On a true linear s32 scale, finding
the delta amplitude simplifies to a direct difference (max - min)
without any nested circular wrap-around conditions.
Refactor rtw8822c_dac_iq_offset() to directly calculate the trimmed
arithmetic mean, casting back to the hardware register's offset
orientation only at the final assignment using a ternary operator.
Signed-off-by: Arsenii Pashchenko <ulijg308@gmail.com>
---
drivers/net/wireless/realtek/rtw88/rtw8822c.c | 103 +++++-------------
1 file changed, 25 insertions(+), 78 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index 642ac2e2b..6fcdfc64c 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -155,38 +155,6 @@ static void rtw8822c_dac_restore_reg(struct rtw_dev *rtwdev,
}
}
-static void rtw8822c_rf_minmax_cmp(struct rtw_dev *rtwdev, s32 value_s32,
- s32 *min_s32, s32 *max_s32)
-{
- u32 value = (u32)value_s32;
- u32 *min = (u32 *)min_s32;
- u32 *max = (u32 *)max_s32;
- if (value >= 0x200) {
- if (*min >= 0x200) {
- if (*min > value)
- *min = value;
- } else {
- *min = value;
- }
- if (*max >= 0x200) {
- if (*max < value)
- *max = value;
- }
- } else {
- if (*min < 0x200) {
- if (*min > value)
- *min = value;
- }
-
- if (*max >= 0x200) {
- *max = value;
- } else {
- if (*max < value)
- *max = value;
- }
- }
-}
-
static int rtw8822c_dac_iq_cmp_s32(const void *a, const void *b)
{
s32 va = *(const s32 *)a;
@@ -201,31 +169,16 @@ static void rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, s32 *iv, s32 *qv)
sort(qv, DACK_SN_8822C, sizeof(s32), rtw8822c_dac_iq_cmp_s32, NULL);
}
-static void rtw8822c_dac_iq_offset(struct rtw_dev *rtwdev, s32 *vec_s32, u32 *val)
+static s32 rtw8822c_dac_iq_offset(struct rtw_dev *rtwdev, s32 *vec)
{
- u32 *vec = (u32 *)vec_s32;
- u32 p, m, t, i;
+ s32 sum = 0;
- m = 0;
- p = 0;
- for (i = 10; i < DACK_SN_8822C - 10; i++) {
- if (vec[i] > 0x200)
- m = (0x400 - vec[i]) + m;
- else
- p = vec[i] + p;
- }
+ for (u32 i = 10; i < DACK_SN_8822C - 10; i++)
+ sum += vec[i];
- if (p > m) {
- t = p - m;
- t = t / (DACK_SN_8822C - 20);
- } else {
- t = m - p;
- t = t / (DACK_SN_8822C - 20);
- if (t != 0x0)
- t = 0x400 - t;
- }
+ s32 avg = sum / (DACK_SN_8822C - 20);
- *val = t;
+ return avg >= 0 ? avg : 0x400 + avg;
}
static u32 rtw8822c_get_path_write_addr(u8 path)
@@ -280,7 +233,7 @@ static bool rtw8822c_dac_iq_check(struct rtw_dev *rtwdev, s32 value)
static void rtw8822c_dac_cal_iq_sample(struct rtw_dev *rtwdev, s32 *iv, s32 *qv)
{
u32 temp;
- int i = 0, cnt = 0;
+ u32 i = 0, cnt = 0;
while (i < DACK_SN_8822C && cnt < 10000) {
cnt++;
@@ -298,34 +251,28 @@ static void rtw8822c_dac_cal_iq_search(struct rtw_dev *rtwdev,
s32 *iv, s32 *qv,
u32 *i_value, u32 *q_value)
{
- u32 i_max = 0, q_max = 0, i_min = 0, q_min = 0;
- u32 i_delta, q_delta;
+ s32 i_max = 0, q_max = 0, i_min = 0, q_min = 0;
u32 temp;
- int i, cnt = 0;
+ u32 i, cnt = 0;
do {
- i_min = (u32)iv[0];
- i_max = (u32)iv[0];
- q_min = (u32)qv[0];
- q_max = (u32)qv[0];
+ i_min = iv[0];
+ i_max = iv[0];
+ q_min = qv[0];
+ q_max = qv[0];
for (i = 0; i < DACK_SN_8822C; i++) {
- rtw8822c_rf_minmax_cmp(rtwdev, iv[i], (s32 *)&i_min, (s32 *)&i_max);
- rtw8822c_rf_minmax_cmp(rtwdev, qv[i], (s32 *)&q_min, (s32 *)&q_max);
+ if (iv[i] < i_min)
+ i_min = iv[i];
+ if (iv[i] > i_max)
+ i_max = iv[i];
+ if (qv[i] < q_min)
+ q_min = qv[i];
+ if (qv[i] > q_max)
+ q_max = qv[i];
}
- if (i_max < 0x200 && i_min < 0x200)
- i_delta = i_max - i_min;
- else if (i_max >= 0x200 && i_min >= 0x200)
- i_delta = i_max - i_min;
- else
- i_delta = i_max + (0x400 - i_min);
-
- if (q_max < 0x200 && q_min < 0x200)
- q_delta = q_max - q_min;
- else if (q_max >= 0x200 && q_min >= 0x200)
- q_delta = q_max - q_min;
- else
- q_delta = q_max + (0x400 - q_min);
+ u32 i_delta = (u32)(i_max - i_min);
+ u32 q_delta = (u32)(q_max - q_min);
rtw_dbg(rtwdev, RTW_DBG_RFK,
"[DACK] i: min=0x%08x, max=0x%08x, delta=0x%08x\n",
@@ -348,8 +295,8 @@ static void rtw8822c_dac_cal_iq_search(struct rtw_dev *rtwdev,
}
} while (cnt++ < 100);
- rtw8822c_dac_iq_offset(rtwdev, iv, i_value);
- rtw8822c_dac_iq_offset(rtwdev, qv, q_value);
+ *i_value = rtw8822c_dac_iq_offset(rtwdev, iv);
+ *q_value = rtw8822c_dac_iq_offset(rtwdev, qv);
}
static void rtw8822c_dac_cal_rf_mode(struct rtw_dev *rtwdev,
--
2.55.0
next prev parent reply other threads:[~2026-08-13 5:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 5:47 [PATCH wireless-next v2 0/4] wifi: rtw88: rtw8822c: refactor DAC IQ calibration to s32 Arsenii Pashchenko
2026-08-13 5:47 ` [PATCH wireless-next v2 1/4] wifi: rtw88: rtw8822c: convert DAC IQ buffers and signatures " Arsenii Pashchenko
2026-08-13 5:47 ` [PATCH wireless-next v2 2/4] wifi: rtw88: rtw8822c: use sign_extend32 for DAC IQ validation Arsenii Pashchenko
2026-08-13 5:47 ` [PATCH wireless-next v2 3/4] wifi: rtw88: rtw8822c: switch to the kernel's sort() library Arsenii Pashchenko
2026-08-13 5:47 ` Arsenii Pashchenko [this message]
2026-08-13 5:54 ` [PATCH wireless-next v2 0/4] wifi: rtw88: rtw8822c: refactor DAC IQ calibration to s32 Ping-Ke Shih
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=0bb6e2fb78d0b2def623210938204a0efbbe2034.1786599645.git.ulijg308@gmail.com \
--to=ulijg308@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=pkshih@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox