Commit 98650454 authored by Rafał Miłecki's avatar Rafał Miłecki Committed by John W. Linville

b43: make cordic common (LP-PHY and N-PHY need it)

Signed-off-by: default avatarRafał Miłecki <zajec5@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 3ed0fac3
...@@ -421,3 +421,41 @@ void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on) ...@@ -421,3 +421,41 @@ void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on)
{ {
b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4); b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4);
} }
struct b43_c32 b43_cordic(int theta)
{
u32 arctg[] = { 2949120, 1740967, 919879, 466945, 234379, 117304,
58666, 29335, 14668, 7334, 3667, 1833, 917, 458,
229, 115, 57, 29, };
int i, tmp, signx = 1, angle = 0;
struct b43_c32 ret = { .i = 39797, .q = 0, };
theta = clamp_t(int, theta, -180, 180);
if (theta > 90) {
theta -= 180;
signx = -1;
} else if (theta < -90) {
theta += 180;
signx = -1;
}
for (i = 0; i <= 17; i++) {
if (theta > angle) {
tmp = ret.i - (ret.q >> i);
ret.q += ret.i >> i;
ret.i = tmp;
angle += arctg[i];
} else {
tmp = ret.i + (ret.q >> i);
ret.q -= ret.i >> i;
ret.i = tmp;
angle -= arctg[i];
}
}
ret.i *= signx;
ret.q *= signx;
return ret;
}
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
struct b43_wldev; struct b43_wldev;
/* Complex number using 2 32-bit signed integers */
struct b43_c32 { s32 i, q; };
/* PHY register routing bits */ /* PHY register routing bits */
#define B43_PHYROUTE 0x0C00 /* PHY register routing bits mask */ #define B43_PHYROUTE 0x0C00 /* PHY register routing bits mask */
...@@ -421,5 +423,6 @@ int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset); ...@@ -421,5 +423,6 @@ int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset);
*/ */
void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on); void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on);
struct b43_c32 b43_cordic(int theta);
#endif /* LINUX_B43_PHY_COMMON_H_ */ #endif /* LINUX_B43_PHY_COMMON_H_ */
...@@ -1767,47 +1767,6 @@ static int lpphy_calc_rx_iq_comp(struct b43_wldev *dev, u16 samples) ...@@ -1767,47 +1767,6 @@ static int lpphy_calc_rx_iq_comp(struct b43_wldev *dev, u16 samples)
return ret; return ret;
} }
/* Complex number using 2 32-bit signed integers */
typedef struct {s32 i, q;} lpphy_c32;
static lpphy_c32 lpphy_cordic(int theta)
{
u32 arctg[] = { 2949120, 1740967, 919879, 466945, 234379, 117304,
58666, 29335, 14668, 7334, 3667, 1833, 917, 458,
229, 115, 57, 29, };
int i, tmp, signx = 1, angle = 0;
lpphy_c32 ret = { .i = 39797, .q = 0, };
theta = clamp_t(int, theta, -180, 180);
if (theta > 90) {
theta -= 180;
signx = -1;
} else if (theta < -90) {
theta += 180;
signx = -1;
}
for (i = 0; i <= 17; i++) {
if (theta > angle) {
tmp = ret.i - (ret.q >> i);
ret.q += ret.i >> i;
ret.i = tmp;
angle += arctg[i];
} else {
tmp = ret.i + (ret.q >> i);
ret.q -= ret.i >> i;
ret.i = tmp;
angle -= arctg[i];
}
}
ret.i *= signx;
ret.q *= signx;
return ret;
}
static void lpphy_run_samples(struct b43_wldev *dev, u16 samples, u16 loops, static void lpphy_run_samples(struct b43_wldev *dev, u16 samples, u16 loops,
u16 wait) u16 wait)
{ {
...@@ -1826,7 +1785,7 @@ static void lpphy_start_tx_tone(struct b43_wldev *dev, s32 freq, u16 max) ...@@ -1826,7 +1785,7 @@ static void lpphy_start_tx_tone(struct b43_wldev *dev, s32 freq, u16 max)
struct b43_phy_lp *lpphy = dev->phy.lp; struct b43_phy_lp *lpphy = dev->phy.lp;
u16 buf[64]; u16 buf[64];
int i, samples = 0, angle = 0, rotation = (9 * freq) / 500; int i, samples = 0, angle = 0, rotation = (9 * freq) / 500;
lpphy_c32 sample; struct b43_c32 sample;
lpphy->tx_tone_freq = freq; lpphy->tx_tone_freq = freq;
...@@ -1842,7 +1801,7 @@ static void lpphy_start_tx_tone(struct b43_wldev *dev, s32 freq, u16 max) ...@@ -1842,7 +1801,7 @@ static void lpphy_start_tx_tone(struct b43_wldev *dev, s32 freq, u16 max)
} }
for (i = 0; i < samples; i++) { for (i = 0; i < samples; i++) {
sample = lpphy_cordic(angle); sample = b43_cordic(angle);
angle += rotation; angle += rotation;
buf[i] = ((sample.i * max) & 0xFF) << 8; buf[i] = ((sample.i * max) & 0xFF) << 8;
buf[i] |= (sample.q * max) & 0xFF; buf[i] |= (sample.q * max) & 0xFF;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment