26 #include <linux/kernel.h>
27 #include <linux/module.h>
36 #define DEFAULT_RSSI -128
62 #define AVG_FACTOR 1000
63 #define MOVING_AVERAGE(__avg, __val) \
65 struct avg_val __new; \
67 (__avg).avg_weight ? \
68 ((((__avg).avg_weight * ((AVG_SAMPLES) - 1)) + \
69 ((__val) * (AVG_FACTOR))) / \
71 ((__val) * (AVG_FACTOR)); \
72 __new.avg = __new.avg_weight / (AVG_FACTOR); \
76 static int rt2x00link_antenna_get_link_rssi(
struct rt2x00_dev *rt2x00dev)
80 if (ant->
rssi_ant.avg && rt2x00dev->
link.qual.rx_success)
85 static int rt2x00link_antenna_get_rssi_history(
struct rt2x00_dev *rt2x00dev)
94 static void rt2x00link_antenna_update_rssi_history(
struct rt2x00_dev *rt2x00dev,
101 static void rt2x00link_antenna_reset(
struct rt2x00_dev *rt2x00dev)
103 rt2x00dev->
link.ant.rssi_ant.avg = 0;
104 rt2x00dev->
link.ant.rssi_ant.avg_weight = 0;
107 static void rt2x00lib_antenna_diversity_sample(
struct rt2x00_dev *rt2x00dev)
113 int sample_current = rt2x00link_antenna_get_link_rssi(rt2x00dev);
114 int sample_other = rt2x00link_antenna_get_rssi_history(rt2x00dev);
131 if (sample_current >= sample_other) {
132 rt2x00link_antenna_update_rssi_history(rt2x00dev,
140 new_ant.rx = other_antenna;
143 new_ant.tx = other_antenna;
148 static void rt2x00lib_antenna_diversity_eval(
struct rt2x00_dev *rt2x00dev)
161 rssi_curr = rt2x00link_antenna_get_link_rssi(rt2x00dev);
162 rssi_old = rt2x00link_antenna_get_rssi_history(rt2x00dev);
163 rt2x00link_antenna_update_rssi_history(rt2x00dev, rssi_curr);
174 if (
abs(rssi_curr - rssi_old) < 5)
188 static bool rt2x00lib_antenna_diversity(
struct rt2x00_dev *rt2x00dev)
209 rt2x00lib_antenna_diversity_sample(rt2x00dev);
211 }
else if (rt2x00dev->
link.count & 1) {
212 rt2x00lib_antenna_diversity_eval(rt2x00dev);
310 rt2x00dev->
link.count = 0;
311 memset(qual, 0,
sizeof(*qual));
323 rt2x00dev->
ops->lib->reset_tuner(rt2x00dev, qual);
326 rt2x00link_antenna_reset(rt2x00dev);
329 static void rt2x00link_reset_qual(
struct rt2x00_dev *rt2x00dev)
357 rt2x00dev->
ops->lib->link_stats(rt2x00dev, qual);
377 rt2x00dev->
ops->lib->link_tuner(rt2x00dev, qual, link->
count);
389 if (rt2x00lib_antenna_diversity(rt2x00dev))
390 rt2x00link_reset_qual(rt2x00dev);
404 struct link *link = &rt2x00dev->
link;
407 rt2x00dev->
ops->lib->watchdog)
418 static void rt2x00link_watchdog(
struct work_struct *work)
422 struct link *link = &rt2x00dev->
link;
431 rt2x00dev->
ops->lib->watchdog(rt2x00dev);
441 struct link *link = &rt2x00dev->
link;
444 rt2x00dev->
ops->lib->gain_calibration)
452 struct link *link = &rt2x00dev->
link;
455 rt2x00dev->
ops->lib->vco_calibration)
471 static void rt2x00link_agc(
struct work_struct *work)
475 struct link *link = &rt2x00dev->
link;
484 rt2x00dev->
ops->lib->gain_calibration(rt2x00dev);
492 static void rt2x00link_vcocal(
struct work_struct *work)
496 struct link *link = &rt2x00dev->
link;
505 rt2x00dev->
ops->lib->vco_calibration(rt2x00dev);