* [PATCH] staging: rtl8723bs: refactor switch-case
@ 2026-03-28 16:33 Bera Yüzlü
2026-03-30 9:35 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Bera Yüzlü @ 2026-03-28 16:33 UTC (permalink / raw)
To: gregkh; +Cc: filippo.muschera, linux-staging, linux-kernel,
Bera Yüzlü
Refactored huge switch-case to lookup table. Used if-else for dynamic
values.
Signed-off-by: Bera Yüzlü <b9788213@gmail.com>
---
.../staging/rtl8723bs/hal/HalBtc8723b1Ant.c | 269 +++++-------------
1 file changed, 69 insertions(+), 200 deletions(-)
diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
index b3e34f97cfc6..c02df8e3c398 100644
--- a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
+++ b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
@@ -989,6 +989,51 @@ static void halbtc8723b1ant_SetFwPstdma(
pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
}
+static const u32 FwPstdma_table[41][5] = {
+ {0, 0, 0, 0, 0}, // 0
+ {0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0},
+ {0x51, 0x1d, 0x1d, 0x0, 0x10},
+ {0x93, 0x15, 0x3, 0x14, 0x0},
+ {0x61, 0x15, 0x3, 0x11, 0x10}, // 5
+ {0x61, 0x20, 0x3, 0x11, 0x11},
+ {0x13, 0xc, 0x5, 0x0, 0x0},
+ {0x93, 0x25, 0x3, 0x10, 0x0},
+ {0, 0, 0, 0, 0},
+ {0x13, 0xa, 0xa, 0x0, 0x40}, // 10
+ {0, 0, 0, 0, 0},
+ {0x51, 0x0a, 0x0a, 0x0, 0x50},
+ {0x51, 0x12, 0x12, 0x0, 0x10},
+ {0, 0, 0, 0, 0},
+ {0x13, 0xa, 0x3, 0x8, 0x0}, // 15
+ {0x93, 0x15, 0x3, 0x10, 0x0},
+ {0, 0, 0, 0, 0},
+ {0x93, 0x25, 0x3, 0x10, 0x0},
+ {0, 0, 0, 0, 0},
+ {0x61, 0x3f, 0x03, 0x11, 0x10}, // 20
+ {0x61, 0x25, 0x03, 0x11, 0x11},
+ {0x61, 0x25, 0x03, 0x11, 0x10},
+ {0xe3, 0x25, 0x3, 0x31, 0x18},
+ {0xe3, 0x15, 0x3, 0x31, 0x18},
+ {0xe3, 0xa, 0x3, 0x31, 0x18}, // 25
+ {0xe3, 0xa, 0x3, 0x31, 0x18},
+ {0xe3, 0x25, 0x3, 0x31, 0x98},
+ {0x69, 0x25, 0x3, 0x31, 0x0},
+ {0xab, 0x1a, 0x1a, 0x1, 0x10},
+ {0x51, 0x30, 0x3, 0x10, 0x10}, // 30
+ {0xd3, 0x1a, 0x1a, 0x0, 0x58},
+ {0x61, 0x35, 0x3, 0x11, 0x11},
+ {0xa3, 0x25, 0x3, 0x30, 0x90},
+ {0x53, 0x1a, 0x1a, 0x0, 0x10},
+ {0x63, 0x1a, 0x1a, 0x0, 0x10}, // 35
+ {0xd3, 0x12, 0x3, 0x14, 0x50},
+ {0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0},
+ /* SoftAP only with no sta associated, BT disable , TDMA mode for power saving */
+ /* here softap mode screen off will cost 70-80mA for phone */
+ {0x23, 0x18, 0x00, 0x10, 0x24}, // 40
+};
static void halbtc8723b1ant_PsTdma(
struct btc_coexist *pBtCoexist, bool bForceExec, bool bTurnOn, u8 type
@@ -1032,207 +1077,31 @@ static void halbtc8723b1ant_PsTdma(
if (pBtLinkInfo->bSlaveRole)
psTdmaByte4Val = psTdmaByte4Val | 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
+ if (type == 1)
+ halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val,
+ 0x3a + nWiFiDurationAdjust, 0x03,
+ psTdmaByte3Val, psTdmaByte4Val);
+ else if (type == 2)
+ halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val,
+ 0x2d + nWiFiDurationAdjust, 0x03,
+ psTdmaByte3Val, psTdmaByte4Val);
+ else if (type == 9 || type == 11)
+ halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val,
+ 0x21, 0x3,
+ psTdmaByte3Val, psTdmaByte4Val);
+ else if (type == 14)
+ halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51,
+ 0x21, 0x3,
+ 0x10, psTdmaByte4Val);
+ else if (type == 0 || type == 17 || type == 19 || type == 37 || type == 38 || type == 39)
+ halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51,
+ 0x1a, 0x1a,
+ 0x0, psTdmaByte4Val);
+ else if (type < 41)
+ halbtc8723b1ant_SetFwPstdma(pBtCoexist, FwPstdma_table[type][0],
+ FwPstdma_table[type][1], FwPstdma_table[type][2],
+ FwPstdma_table[type][3], FwPstdma_table[type][4]);
- switch (type) {
- default:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val
- );
- break;
- case 1:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist,
- psTdmaByte0Val,
- 0x3a + nWiFiDurationAdjust,
- 0x03,
- psTdmaByte3Val,
- psTdmaByte4Val
- );
- break;
- case 2:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist,
- psTdmaByte0Val,
- 0x2d + nWiFiDurationAdjust,
- 0x03,
- psTdmaByte3Val,
- psTdmaByte4Val
- );
- break;
- case 3:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, 0x10
- );
- break;
- case 4:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0
- );
- break;
- case 5:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x10
- );
- break;
- case 6:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x11
- );
- break;
- case 7:
- halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);
- break;
- case 8:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0
- );
- break;
- case 9:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist,
- psTdmaByte0Val,
- 0x21,
- 0x3,
- psTdmaByte3Val,
- psTdmaByte4Val
- );
- break;
- case 10:
- halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);
- break;
- case 11:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist,
- psTdmaByte0Val,
- 0x21,
- 0x03,
- psTdmaByte3Val,
- psTdmaByte4Val
- );
- break;
- case 12:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50
- );
- break;
- case 13:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x51, 0x12, 0x12, 0x0, 0x10
- );
- break;
- case 14:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x51, 0x21, 0x3, 0x10, psTdmaByte4Val
- );
- break;
- case 15:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0
- );
- break;
- case 16:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0
- );
- break;
- case 18:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0
- );
- break;
- case 20:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x61, 0x3f, 0x03, 0x11, 0x10
-
- );
- break;
- case 21:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11
- );
- break;
- case 22:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10
- );
- break;
- case 23:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18
- );
- break;
- case 24:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18
- );
- break;
- case 25:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18
- );
- break;
- case 26:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18
- );
- break;
- case 27:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98
- );
- break;
- case 28:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0
- );
- break;
- case 29:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10
- );
- break;
- case 30:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10
- );
- break;
- case 31:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xd3, 0x1a, 0x1a, 0x0, 0x58
- );
- break;
- case 32:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11
- );
- break;
- case 33:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90
- );
- break;
- case 34:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10
- );
- break;
- case 35:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10
- );
- break;
- case 36:
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50
- );
- break;
- case 40: /* SoftAP only with no sta associated, BT disable , TDMA mode for power saving */
- /* here softap mode screen off will cost 70-80mA for phone */
- halbtc8723b1ant_SetFwPstdma(
- pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24
- );
- break;
- }
} else {
/* disable PS tdma */
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] staging: rtl8723bs: refactor switch-case
2026-03-28 16:33 [PATCH] staging: rtl8723bs: refactor switch-case Bera Yüzlü
@ 2026-03-30 9:35 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-03-30 9:35 UTC (permalink / raw)
To: Bera Yüzlü
Cc: gregkh, filippo.muschera, linux-staging, linux-kernel
On Sat, Mar 28, 2026 at 07:33:58PM +0300, Bera Yüzlü wrote:
> Refactored huge switch-case to lookup table. Used if-else for dynamic
> values.
>
> Signed-off-by: Bera Yüzlü <b9788213@gmail.com>
> ---
> .../staging/rtl8723bs/hal/HalBtc8723b1Ant.c | 269 +++++-------------
> 1 file changed, 69 insertions(+), 200 deletions(-)
>
> diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
> index b3e34f97cfc6..c02df8e3c398 100644
> --- a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
> +++ b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
> @@ -989,6 +989,51 @@ static void halbtc8723b1ant_SetFwPstdma(
> pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
> }
>
> +static const u32 FwPstdma_table[41][5] = {
> + {0, 0, 0, 0, 0}, // 0
> + {0, 0, 0, 0, 0},
> + {0, 0, 0, 0, 0},
> + {0x51, 0x1d, 0x1d, 0x0, 0x10},
> + {0x93, 0x15, 0x3, 0x14, 0x0},
> + {0x61, 0x15, 0x3, 0x11, 0x10}, // 5
> + {0x61, 0x20, 0x3, 0x11, 0x11},
> + {0x13, 0xc, 0x5, 0x0, 0x0},
> + {0x93, 0x25, 0x3, 0x10, 0x0},
> + {0, 0, 0, 0, 0},
> + {0x13, 0xa, 0xa, 0x0, 0x40}, // 10
> + {0, 0, 0, 0, 0},
> + {0x51, 0x0a, 0x0a, 0x0, 0x50},
> + {0x51, 0x12, 0x12, 0x0, 0x10},
> + {0, 0, 0, 0, 0},
> + {0x13, 0xa, 0x3, 0x8, 0x0}, // 15
> + {0x93, 0x15, 0x3, 0x10, 0x0},
> + {0, 0, 0, 0, 0},
This patch is sort of a pain in the butt to review... I'm not
sure that it improves readability. I had to read until I got
to 17 before I found a mistake.
> + {0x93, 0x25, 0x3, 0x10, 0x0},
> + {0, 0, 0, 0, 0},
> + {0x61, 0x3f, 0x03, 0x11, 0x10}, // 20
[ snip ]
> + else if (type == 0 || type == 17 || type == 19 || type == 37 || type == 38 || type == 39)
> + halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51,
> + 0x1a, 0x1a,
> + 0x0, psTdmaByte4Val);
In the original code there was no entry for 17 but in the new patch it's
treated like a 0. What's the deal with that?
$ grep 17 drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
regards,
dan carpenter
> + else if (type < 41)
> + halbtc8723b1ant_SetFwPstdma(pBtCoexist, FwPstdma_table[type][0],
> + FwPstdma_table[type][1], FwPstdma_table[type][2],
> + FwPstdma_table[type][3], FwPstdma_table[type][4]);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-30 9:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-28 16:33 [PATCH] staging: rtl8723bs: refactor switch-case Bera Yüzlü
2026-03-30 9:35 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox