staging: rtl8723bs: refactor switch-case
PATCH 1/1 staging: rtl8723bs: refactor switch-case
Refactored huge switch-case to lookup table. Used if-else for dynamic values.
--- .../staging/rtl8723bs/hal/HalBtc8723b1Ant.c | 269 +++++------------- 1 file changed, 69 insertions(+), 200 deletions(-)
drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +69 -200
@@ -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 */
Signature · 1 line
2.53.0
Quoted 25 lines · Bera Yüzlü
Refactored huge switch-case to lookup table. Used if-else for dynamic values.
Signed-off-by Bera Yüzlü <[email protected]>--- .../staging/rtl8723bs/hal/HalBtc8723b1Ant.c | 269 +++++------------- 1 file changed, 69 insertions(+), 200 deletions(-)drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +9
-0@@ -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 },
drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c static void halbtc8723b1ant_SetFwPstdma( · line 1010
Quoted 10 lines
drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +10
-0+ {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.
Quoted 3 lines
drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +3
-0+ {0x93, 0x25, 0x3, 0x10, 0x0}, + {0, 0, 0, 0, 0}, + {0x61, 0x3f, 0x03, 0x11, 0x10}, // 20
[ snip ]
drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c static void halbtc8723b1ant_PsTdma( · line 1099
Quoted 4 lines
drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +4
-0+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
Quoted 4 lines
drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +4
-0+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 ]);
Greg KH
maintainerQuoted 2 lines · Bera Yüzlü
Refactored huge switch-case to lookup table. Used if-else for dynamic values.
That says what you did, but not why?
And did you test this?
And why do this at all?
thanks,
greg k-h