RE: [PATCH rtw-next v7 2/3] wifi: rtw88: rtw8822c: Convert DAC IQ calibration path to signed math
From: Ping-Ke Shih
Date: Fri Aug 28 2026 - 04:30:48 EST
Arsenii Pashchenko <ulijg308@xxxxxxxxx> wrote:
> Convert the temporary stack arrays 'iv' and 'qv' from u32 to s32.
> Update all internal function signatures to accept s32 pointers and
> handle signed values natively.
>
> Use sign_extend32() combined with FIELD_GET_SIGNED() to properly interpret
> the 10-bit hardware values as signed integers. This allows flattening
> the complex nested unsigned boundary conditions in
> rtw8822c_dac_iq_check() into a simple amplitude boundary check. Ensure
> rtw8822c_dac_iq_offset() properly maps the signed average back to a
> 10-bit unsigned format expected by the hardware registers via GENMASK().
>
> Signed-off-by: Arsenii Pashchenko <ulijg308@xxxxxxxxx>
[...]
> -static void rtw8822c_dac_iq_offset(struct rtw_dev *rtwdev, u32 *vec, u32 *val)
> +static u32 rtw8822c_dac_iq_offset(struct rtw_dev *rtwdev, s32 *vec)
> {
> - u32 p, m, t, i;
> + s32 sum = 0;
> + s32 avg;
> + u32 i;
>
> - 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 (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;
> - }
> + avg = sum / (DACK_SN_8822C - 20);
>
> - *val = t;
> + /* Map the signed average back to a 10-bit hardware format.
> + * Example: avg = -1, returns 0x3FF (signed 10-bit value)
> + */
The first line of comment block should be empty, like
/*
* comment start here.
* second.
*/
> + return avg & GENMASK(9, 0);
> }
>
> static u32 rtw8822c_get_path_write_addr(u8 path)