RE: [PATCH 4/4] wifi: rtw88: rtw8822c: simplify amplitude search and offset via s32
Ping-Ke Shih <[email protected]>
| Newsgroups | org.kernel.vger.linux-wireless,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Arsenii Pashchenko <[email protected]> wrote: > 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 <[email protected]> > --- > 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); No declaration in the middle. > > - *val = t; > + return avg >= 0 ? avg : 0x400 + avg; Return type is 's32', but here doesn't do sign_extension()? > } > > static u32 rtw8822c_get_path_write_addr(u8 path)