From: Ping-Ke Shih <pkshih@realtek.com>
To: Arsenii Pashchenko <ulijg308@gmail.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 2/4] wifi: rtw88: rtw8822c: use sign_extend32 for DAC IQ validation
Date: Fri, 14 Aug 2026 07:49:41 +0000 [thread overview]
Message-ID: <9be26fe7c6814b17baf2bb08fbfff6eb@realtek.com> (raw)
In-Reply-To: <a016d09710dce6f27a60e8fb3c16cdc28ef24a08.1786545572.git.ulijg308@gmail.com>
Arsenii Pashchenko <ulijg308@gmail.com> wrote:
> Leverage the kernel's native sign_extend32() macro to properly
> interpret the 10-bit raw values from hardware registers as signed
> 32-bit (s10) integers covering the [-512, 511] range.
New API FIELD_GET_SIGNED() is introduced. I think this is suitable
to this case.
>
> This allows us to completely rewrite rtw8822c_dac_iq_check() to use
> a simple, clean amplitude boundary check instead of complex, nested
> unsigned boundary conditions. Drop the temporary u32 casts inside
> the check and sampling routines.
>
> Signed-off-by: Arsenii Pashchenko <ulijg308@gmail.com>
> ---
> drivers/net/wireless/realtek/rtw88/rtw8822c.c | 24 +++++++++----------
> 1 file changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
> b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
> index 896e3e7b9..d06986d09 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/bitops.h>
I guess you need this because of sign_extend32(). Have you tried to build
without this? I feel it is existing in include chain already.
> #include "main.h"
> #include "coex.h"
> #include "fw.h"
> @@ -277,18 +278,15 @@ static u32 rtw8822c_get_path_read_addr(u8 path)
> return base_addr;
> }
>
> -static bool rtw8822c_dac_iq_check(struct rtw_dev *rtwdev, s32 value_s32)
> +static bool rtw8822c_dac_iq_check(struct rtw_dev *rtwdev, s32 value)
> {
> - u32 value = (u32)value_s32;
> - bool ret = true;
>
> - if ((value >= 0x200 && (0x400 - value) > 0x64) ||
> - (value < 0x200 && value > 0x64)) {
> - ret = false;
> + if (value > 100 || value < -100) {
The change is identical?
> rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] Error overflow\n");
> + return false;
> }
>
> - return ret;
> + return true;
> }
>
> static void rtw8822c_dac_cal_iq_sample(struct rtw_dev *rtwdev, s32 *iv, s32 *qv)
> @@ -299,8 +297,8 @@ static void rtw8822c_dac_cal_iq_sample(struct rtw_dev *rtwdev, s32 *iv, s32 *qv)
> while (i < DACK_SN_8822C && cnt < 10000) {
> cnt++;
> temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff);
> - iv[i] = (s32)((temp & 0x3ff000) >> 12);
> - qv[i] = (s32)(temp & 0x3ff);
> + iv[i] = sign_extend32((temp & 0x3ff000) >> 12, 9);
> + qv[i] = sign_extend32(temp & 0x3ff, 9);
FIELD_GET_SIGNED()
>
> if (rtw8822c_dac_iq_check(rtwdev, iv[i]) &&
> rtw8822c_dac_iq_check(rtwdev, qv[i]))
> @@ -352,11 +350,11 @@ static void rtw8822c_dac_cal_iq_search(struct rtw_dev *rtwdev,
>
> if (i_delta > 5 || q_delta > 5) {
> temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff);
> - iv[0] = (s32)((temp & 0x3ff000) >> 12);
> - qv[0] = (s32)(temp & 0x3ff);
> + iv[0] = sign_extend32((temp & 0x3ff000) >> 12, 9);
> + qv[0] = sign_extend32(temp & 0x3ff, 9);
FIELD_GET_SIGNED()
> temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff);
> - iv[DACK_SN_8822C - 1] = (s32)((temp & 0x3ff000) >> 12);
> - qv[DACK_SN_8822C - 1] = (s32)(temp & 0x3ff);
> + iv[DACK_SN_8822C - 1] = sign_extend32((temp & 0x3ff000) >> 12, 9);
> + qv[DACK_SN_8822C - 1] = sign_extend32(temp & 0x3ff, 9);
FIELD_GET_SIGNED()
Please use real hardware to verify the values.
> } else {
> break;
> }
> --
> 2.55.0
next prev parent reply other threads:[~2026-08-14 7:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 14:45 [PATCH 0/4] wifi: rtw88: rtw8822c: refactor DAC IQ calibration to s32 Arsenii Pashchenko
2026-08-12 14:45 ` [PATCH 1/4] wifi: rtw88: rtw8822c: convert DAC IQ buffers and signatures " Arsenii Pashchenko
2026-08-14 7:42 ` Ping-Ke Shih
2026-08-12 14:45 ` [PATCH 2/4] wifi: rtw88: rtw8822c: use sign_extend32 for DAC IQ validation Arsenii Pashchenko
2026-08-14 7:49 ` Ping-Ke Shih [this message]
2026-08-14 8:03 ` Ping-Ke Shih
2026-08-12 14:45 ` [PATCH 3/4] wifi: rtw88: rtw8822c: switch to the kernel's sort() library Arsenii Pashchenko
2026-08-14 7:57 ` Ping-Ke Shih
2026-08-12 14:45 ` [PATCH 4/4] wifi: rtw88: rtw8822c: simplify amplitude search and offset via s32 Arsenii Pashchenko
2026-08-14 8:10 ` 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=9be26fe7c6814b17baf2bb08fbfff6eb@realtek.com \
--to=pkshih@realtek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=ulijg308@gmail.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.