Skip to content

Commit d5a4335

Browse files
plaesKalle Valo
authored andcommitted
b43: Use cordic algorithm from kernel library
Kernel library has a common cordic algorithm which is identical to internally implemented one, so use it and drop the duplicate implementation. Acked-by: Larry Finger <Larry.Finger@lwfinger.net> Signed-off-by: Priit Laes <plaes@plaes.org> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
1 parent 8ea3819 commit d5a4335

File tree

5 files changed

+15
-68
lines changed

5 files changed

+15
-68
lines changed

drivers/net/wireless/broadcom/b43/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config B43
44
select BCMA if B43_BCMA
55
select SSB if B43_SSB
66
select FW_LOADER
7+
select CORDIC
78
---help---
89
b43 is a driver for the Broadcom 43xx series wireless devices.
910

drivers/net/wireless/broadcom/b43/phy_common.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -604,50 +604,3 @@ void b43_phy_force_clock(struct b43_wldev *dev, bool force)
604604
#endif
605605
}
606606
}
607-
608-
/* http://bcm-v4.sipsolutions.net/802.11/PHY/Cordic */
609-
struct b43_c32 b43_cordic(int theta)
610-
{
611-
static const u32 arctg[] = {
612-
2949120, 1740967, 919879, 466945, 234379, 117304,
613-
58666, 29335, 14668, 7334, 3667, 1833,
614-
917, 458, 229, 115, 57, 29,
615-
};
616-
u8 i;
617-
s32 tmp;
618-
s8 signx = 1;
619-
s32 angle = 0;
620-
struct b43_c32 ret = { .i = 39797, .q = 0, };
621-
622-
while (theta > (180 << 16))
623-
theta -= (360 << 16);
624-
while (theta < -(180 << 16))
625-
theta += (360 << 16);
626-
627-
if (theta > (90 << 16)) {
628-
theta -= (180 << 16);
629-
signx = -1;
630-
} else if (theta < -(90 << 16)) {
631-
theta += (180 << 16);
632-
signx = -1;
633-
}
634-
635-
for (i = 0; i <= 17; i++) {
636-
if (theta > angle) {
637-
tmp = ret.i - (ret.q >> i);
638-
ret.q += ret.i >> i;
639-
ret.i = tmp;
640-
angle += arctg[i];
641-
} else {
642-
tmp = ret.i + (ret.q >> i);
643-
ret.q -= ret.i >> i;
644-
ret.i = tmp;
645-
angle -= arctg[i];
646-
}
647-
}
648-
649-
ret.i *= signx;
650-
ret.q *= signx;
651-
652-
return ret;
653-
}

drivers/net/wireless/broadcom/b43/phy_common.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77

88
struct b43_wldev;
99

10-
/* Complex number using 2 32-bit signed integers */
11-
struct b43_c32 { s32 i, q; };
12-
13-
#define CORDIC_CONVERT(value) (((value) >= 0) ? \
14-
((((value) >> 15) + 1) >> 1) : \
15-
-((((-(value)) >> 15) + 1) >> 1))
16-
1710
/* PHY register routing bits */
1811
#define B43_PHYROUTE 0x0C00 /* PHY register routing bits mask */
1912
#define B43_PHYROUTE_BASE 0x0000 /* Base registers */
@@ -450,6 +443,4 @@ bool b43_is_40mhz(struct b43_wldev *dev);
450443

451444
void b43_phy_force_clock(struct b43_wldev *dev, bool force);
452445

453-
struct b43_c32 b43_cordic(int theta);
454-
455446
#endif /* LINUX_B43_PHY_COMMON_H_ */

drivers/net/wireless/broadcom/b43/phy_lp.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
2424
*/
2525

26+
#include <linux/cordic.h>
2627
#include <linux/slab.h>
2728

2829
#include "b43.h"
@@ -1780,9 +1781,9 @@ static void lpphy_start_tx_tone(struct b43_wldev *dev, s32 freq, u16 max)
17801781
{
17811782
struct b43_phy_lp *lpphy = dev->phy.lp;
17821783
u16 buf[64];
1783-
int i, samples = 0, angle = 0;
1784+
int i, samples = 0, theta = 0;
17841785
int rotation = (((36 * freq) / 20) << 16) / 100;
1785-
struct b43_c32 sample;
1786+
struct cordic_iq sample;
17861787

17871788
lpphy->tx_tone_freq = freq;
17881789

@@ -1798,10 +1799,10 @@ static void lpphy_start_tx_tone(struct b43_wldev *dev, s32 freq, u16 max)
17981799
}
17991800

18001801
for (i = 0; i < samples; i++) {
1801-
sample = b43_cordic(angle);
1802-
angle += rotation;
1803-
buf[i] = CORDIC_CONVERT((sample.i * max) & 0xFF) << 8;
1804-
buf[i] |= CORDIC_CONVERT((sample.q * max) & 0xFF);
1802+
sample = cordic_calc_iq(CORDIC_FIXED(theta));
1803+
theta += rotation;
1804+
buf[i] = CORDIC_FLOAT((sample.i * max) & 0xFF) << 8;
1805+
buf[i] |= CORDIC_FLOAT((sample.q * max) & 0xFF);
18051806
}
18061807

18071808
b43_lptab_write_bulk(dev, B43_LPTAB16(5, 0), samples, buf);

drivers/net/wireless/broadcom/b43/phy_n.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
2424
*/
2525

26+
#include <linux/cordic.h>
2627
#include <linux/delay.h>
2728
#include <linux/slab.h>
2829
#include <linux/types.h>
@@ -1513,7 +1514,7 @@ static void b43_radio_init2055(struct b43_wldev *dev)
15131514

15141515
/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/LoadSampleTable */
15151516
static int b43_nphy_load_samples(struct b43_wldev *dev,
1516-
struct b43_c32 *samples, u16 len) {
1517+
struct cordic_iq *samples, u16 len) {
15171518
struct b43_phy_n *nphy = dev->phy.n;
15181519
u16 i;
15191520
u32 *data;
@@ -1544,7 +1545,7 @@ static u16 b43_nphy_gen_load_samples(struct b43_wldev *dev, u32 freq, u16 max,
15441545
{
15451546
int i;
15461547
u16 bw, len, rot, angle;
1547-
struct b43_c32 *samples;
1548+
struct cordic_iq *samples;
15481549

15491550
bw = b43_is_40mhz(dev) ? 40 : 20;
15501551
len = bw << 3;
@@ -1561,7 +1562,7 @@ static u16 b43_nphy_gen_load_samples(struct b43_wldev *dev, u32 freq, u16 max,
15611562
len = bw << 1;
15621563
}
15631564

1564-
samples = kcalloc(len, sizeof(struct b43_c32), GFP_KERNEL);
1565+
samples = kcalloc(len, sizeof(struct cordic_iq), GFP_KERNEL);
15651566
if (!samples) {
15661567
b43err(dev->wl, "allocation for samples generation failed\n");
15671568
return 0;
@@ -1570,10 +1571,10 @@ static u16 b43_nphy_gen_load_samples(struct b43_wldev *dev, u32 freq, u16 max,
15701571
angle = 0;
15711572

15721573
for (i = 0; i < len; i++) {
1573-
samples[i] = b43_cordic(angle);
1574+
samples[i] = cordic_calc_iq(CORDIC_FIXED(angle));
15741575
angle += rot;
1575-
samples[i].q = CORDIC_CONVERT(samples[i].q * max);
1576-
samples[i].i = CORDIC_CONVERT(samples[i].i * max);
1576+
samples[i].q = CORDIC_FLOAT(samples[i].q * max);
1577+
samples[i].i = CORDIC_FLOAT(samples[i].i * max);
15771578
}
15781579

15791580
i = b43_nphy_load_samples(dev, samples, len);

0 commit comments

Comments
 (0)