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 rtw-next v7 3/3] wifi: rtw88: rtw8822c: Replace custom DAC IQ sorting with kernel sort
Date: Fri, 28 Aug 2026 12:40:23 +0700 [thread overview]
Message-ID: <7d0ab2352317b81df10dca7ddb3e855a303b8be7.1787895379.git.ulijg308@gmail.com> (raw)
In-Reply-To: <cover.1787895379.git.ulijg308@gmail.com>
Replace the custom, nested bubble-sort logic in the calibration loop
with direct calls to the kernel's optimized heapsort implementation
inside rtw8822c_dac_cal_iq_search().
Implement a safe, overflow-proof s32 comparator using the subtraction
of relationals pattern. Since the input values are already properly
sign-extended into signed arrays, the custom circular index sorting
rules and helper functions completely disappear, reducing lines of code.
Signed-off-by: Arsenii Pashchenko <ulijg308@gmail.com>
---
drivers/net/wireless/realtek/rtw88/rtw8822c.c | 22 ++++++-------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index b010e17c9..bec1bb376 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -3,6 +3,7 @@
*/
#include <linux/module.h>
+#include <linux/sort.h>
#include "main.h"
#include "coex.h"
#include "fw.h"
@@ -153,24 +154,14 @@ static void rtw8822c_dac_restore_reg(struct rtw_dev *rtwdev,
}
}
-static void __rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, s32 *v1, s32 *v2)
+static int rtw8822c_dac_iq_cmp_s32(const void *a, const void *b)
{
- if (*v1 > *v2)
- swap(*v1, *v2);
+ s32 val_a = *(const s32 *)a;
+ s32 val_b = *(const s32 *)b;
+ return (val_a > val_b) - (val_a < val_b);
}
-static void rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, s32 *iv, s32 *qv)
-{
- u32 i, j;
-
- for (i = 0; i < DACK_SN_8822C - 1; i++) {
- for (j = 0; j < (DACK_SN_8822C - 1 - i) ; j++) {
- __rtw8822c_dac_iq_sort(rtwdev, &iv[j], &iv[j + 1]);
- __rtw8822c_dac_iq_sort(rtwdev, &qv[j], &qv[j + 1]);
- }
- }
-}
static u32 rtw8822c_dac_iq_offset(struct rtw_dev *rtwdev, s32 *vec)
{
@@ -291,7 +282,8 @@ static void rtw8822c_dac_cal_iq_search(struct rtw_dev *rtwdev,
"[DACK] q: min=%d, max=%d, delta=%d",
q_min, q_max, q_delta);
- rtw8822c_dac_iq_sort(rtwdev, iv, qv);
+ sort(iv, DACK_SN_8822C, sizeof(s32), rtw8822c_dac_iq_cmp_s32, NULL);
+ sort(qv, DACK_SN_8822C, sizeof(s32), rtw8822c_dac_iq_cmp_s32, NULL);
if (i_delta > 5 || q_delta > 5) {
temp = rtw_read32(rtwdev, 0x2dbc);
--
2.55.0
next prev parent reply other threads:[~2026-08-28 5:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 5:40 [PATCH rtw-next v7 0/3] wifi: rtw88: rtw8822c: refactor DAC IQ calibration to s32 Arsenii Pashchenko
2026-08-28 5:40 ` [PATCH rtw-next v7 1/3] wifi: rtw88: rtw8822c: Use bitfield macros for DAC IQ sampling Arsenii Pashchenko
2026-08-28 8:23 ` Ping-Ke Shih
2026-08-28 5:40 ` [PATCH rtw-next v7 2/3] wifi: rtw88: rtw8822c: Convert DAC IQ calibration path to signed math Arsenii Pashchenko
2026-08-28 8:29 ` Ping-Ke Shih
2026-08-28 5:40 ` Arsenii Pashchenko [this message]
2026-08-28 8:24 ` [PATCH rtw-next v7 3/3] wifi: rtw88: rtw8822c: Replace custom DAC IQ sorting with kernel sort 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=7d0ab2352317b81df10dca7ddb3e855a303b8be7.1787895379.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;
as well as URLs for NNTP newsgroup(s).