From: "Bera Yüzlü" <b9788213@gmail.com>
To: gregkh@linuxfoundation.org
Cc: filippo.muschera@gmail.com, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org, "Bera Yüzlü" <b9788213@gmail.com>
Subject: [PATCH] staging: rtl8723bs: refactor switch-case
Date: Sat, 28 Mar 2026 19:33:58 +0300 [thread overview]
Message-ID: <20260328163357.163332-2-b9788213@gmail.com> (raw)
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
next reply other threads:[~2026-03-28 16:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-28 16:33 Bera Yüzlü [this message]
2026-03-30 9:35 ` [PATCH] staging: rtl8723bs: refactor switch-case Dan Carpenter
2026-03-30 16:01 ` Greg KH
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=20260328163357.163332-2-b9788213@gmail.com \
--to=b9788213@gmail.com \
--cc=filippo.muschera@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/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