Skip to content

Instantly share code, notes, and snippets.

@tcr
Last active July 19, 2016 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcr/9d1c0442bd7d494c336a to your computer and use it in GitHub Desktop.
Save tcr/9d1c0442bd7d494c336a to your computer and use it in GitHub Desktop.
999-tim_did_a.patch
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index 1274b85..56b3d00 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -38,11 +38,141 @@
#include <linux/slab.h>
#include <linux/clk.h>
#include <linux/of.h>
+#include <linux/stat.h>
#include "rt2x00.h"
#include "rt2800lib.h"
#include "rt2800.h"
+// TCRTX
+volatile unsigned int tcr_config_twxi4_enable = 0;
+volatile unsigned int tcr_config_twxi4_value = 0;
+volatile unsigned int tcr_config_bbp_enable = 0;
+volatile unsigned int tcr_config_bbp_value = 0;
+volatile unsigned int tcr_config_txcfg_enable = 0;
+volatile unsigned int tcr_config_txcfg_value = 0;
+
+int tcr_read(struct file *filp,char *buf,size_t count,void *data )
+{
+ return 0;
+}
+
+static int tcr_readbyte(const char* str, unsigned int *output) {
+ char a = str[0];
+ char b = str[1];
+
+ if (a == 0 || b == 0) {
+ return 0;
+ }
+
+ *output = ((a > 57 ? (a > 90 ? a - 'a' : a - 'A') + 0xa : a - '0') << 8) |
+ (b > 57 ? (b > 90 ? b - 'a' : b - 'A') + 0xa : b - '0');
+ return 1;
+}
+
+ssize_t tcr_write( struct file *filp, const char __user *buff,
+ size_t len, void *data )
+{
+ char tcr_buf[255] = { 0 };
+ copy_from_user(tcr_buf, buff, len > 254 ? 254 : len);
+
+ printk(KERN_DEBUG "TCRTX: Received string '%s'\n", tcr_buf);
+ // eg "0000000000000000" or "0101010101010101"
+
+ unsigned int input = 0;
+ if (tcr_readbyte(&tcr_buf[0], &input)) {
+ tcr_config_twxi4_enable = input;
+ printk(KERN_DEBUG "TCRTX: Setting TWXI4 enable to %d\n", tcr_config_twxi4_enable ? 1 : 0);
+ }
+ if (tcr_readbyte(&tcr_buf[2], &input)) {
+ tcr_config_twxi4_value = input;
+ printk(KERN_DEBUG "TCRTX: Setting TWXI4 value to %d\n", tcr_config_twxi4_value);
+ }
+ if (tcr_readbyte(&tcr_buf[4], &input)) {
+ tcr_config_bbp_enable = input;
+ printk(KERN_DEBUG "TCRTX: Setting BBP enable to %d\n", tcr_config_bbp_enable ? 1 : 0);
+ }
+ if (tcr_readbyte(&tcr_buf[6], &input)) {
+ tcr_config_bbp_value = input;
+ printk(KERN_DEBUG "TCRTX: Setting BBP value to %d\n", tcr_config_bbp_value);
+ }
+ if (tcr_readbyte(&tcr_buf[8], &input)) {
+ tcr_config_txcfg_enable = input;
+ printk(KERN_DEBUG "TCRTX: Setting TXCFG enable to %d\n", tcr_config_txcfg_enable ? 1 : 0);
+ }
+ if (tcr_readbyte(&tcr_buf[10], &input)) {
+ tcr_config_txcfg_value = input;
+ printk(KERN_DEBUG "TCRTX: Setting TXCFG value to %d\n", tcr_config_txcfg_value);
+ }
+
+ return len;
+}
+
+static const struct file_operations tcr_proc_ops = {
+ .owner = THIS_MODULE,
+ .read = tcr_read,
+ .write = tcr_write,
+};
+
+unsigned int tcr_recal = 0;
+
+void tcr_bootup(void) {
+ // struct file* filp = NULL;
+ // struct kstat bff; mm_segment_t oldfs;
+ // loff_t file_offset;
+ // unsigned int input;
+
+ if (tcr_recal != 0) {
+ return;
+ }
+ tcr_recal = 1;
+ proc_create( "tcr-txpower", 0644, NULL, &tcr_proc_ops);
+
+ // char tcr_buf[255] = { 0 };
+ // oldfs = get_fs();
+ // set_fs(get_ds());
+ // if (vfs_stat("/FCC_CONFIG", &bff) == 0) {
+ // filp = filp_open("/FCC_CONFIG", O_RDWR | O_CREAT | O_TRUNC, 0644);
+ // vfs_read(filp, tcr_buf, 254, &file_offset);
+ // filp_close(filp, NULL);
+ // }
+ // set_fs(oldfs);
+ //
+ // printk(KERN_DEBUG "TCRTX: Read string '%s'\n", tcr_buf);
+ // // eg "000000000000" or "010101010101"
+ //
+ // if (tcr_readbyte(&tcr_buf[0], &input)) {
+ // // printk(KERN_DEBUG "TCRTX: input %d\n", input);
+ // tcr_config_twxi4_enable = input;
+ // printk(KERN_DEBUG "TCRTX: Setting TWXI4 enable to %d\n", tcr_config_twxi4_enable ? 1 : 0);
+ // }
+ // if (tcr_readbyte(&tcr_buf[2], &input)) {
+ // // printk(KERN_DEBUG "TCRTX: input %d\n", input);
+ // tcr_config_twxi4_value = input;
+ // printk(KERN_DEBUG "TCRTX: Setting TWXI4 value to %d\n", tcr_config_twxi4_value);
+ // }
+ // if (tcr_readbyte(&tcr_buf[4], &input)) {
+ // // printk(KERN_DEBUG "TCRTX: input %d\n", input);
+ // tcr_config_bbp_enable = input;
+ // printk(KERN_DEBUG "TCRTX: Setting BBP enable to %d\n", tcr_config_bbp_enable ? 1 : 0);
+ // }
+ // if (tcr_readbyte(&tcr_buf[6], &input)) {
+ // // printk(KERN_DEBUG "TCRTX: input %d\n", input);
+ // tcr_config_bbp_value = input;
+ // printk(KERN_DEBUG "TCRTX: Setting BBP value to %d\n", tcr_config_bbp_value);
+ // }
+ // if (tcr_readbyte(&tcr_buf[8], &input)) {
+ // // printk(KERN_DEBUG "TCRTX: input %d\n", input);
+ // tcr_config_txcfg_enable = input;
+ // printk(KERN_DEBUG "TCRTX: Setting TXCFG enable to %d\n", tcr_config_txcfg_enable ? 1 : 0);
+ // }
+ // if (tcr_readbyte(&tcr_buf[10], &input)) {
+ // // printk(KERN_DEBUG "TCRTX: input %d\n", input);
+ // tcr_config_txcfg_value = input;
+ // printk(KERN_DEBUG "TCRTX: Setting TXCFG value to %d\n", tcr_config_txcfg_value);
+ // }
+}
+
/*
* Register access.
* All access to the CSR registers will go through the methods
@@ -885,6 +1015,15 @@ void rt2800_write_tx_data(struct queue_entry *entry,
*/
for (i = 2; i < entry->queue->winfo_size / sizeof(__le32); i++)
_rt2x00_desc_write(txwi, i, 0);
+
+ // TCRTX
+ tcr_bootup();
+ if (tcr_config_twxi4_enable != 0) {
+ word = 0;
+ // rt2x00_set_field32(&word, 0x000f0000, tcr_config_twxi4_value);
+ word |= tcr_config_twxi4_value << 16;
+ rt2x00_desc_write(txwi, 4, word);
+ }
}
EXPORT_SYMBOL_GPL(rt2800_write_tx_data);
@@ -4410,6 +4549,12 @@ static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b,
u8 eirp_txpower_criterion;
u8 reg_limit;
+ // TCRTX
+ tcr_bootup();
+ if (tcr_config_txcfg_enable != 0) {
+ return tcr_config_txcfg_value;
+ }
+
if (rt2x00_rt(rt2x00dev, RT3593))
return min_t(u8, txpower, 0xc);
@@ -4857,6 +5002,9 @@ static void rt2800_config_txpower_rt3593(struct rt2x00_dev *rt2x00dev,
(unsigned long) regs[i]);
}
+// TCRTX
+static int tcr_bbp_first = 0;
+
/*
* We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and
* BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values,
@@ -4929,6 +5077,18 @@ static void rt2800_config_txpower_rt28xx(struct rt2x00_dev *rt2x00dev,
} else {
power_ctrl = 0;
}
+
+ //TCRTX
+ tcr_bootup();
+ if (tcr_config_bbp_enable != 0) {
+ if (tcr_bbp_first == 0) {
+ tcr_bbp_first = 1;
+ printk(KERN_DEBUG "TIM the thing worked, your new pwr value iiiiiiis %d\n", tcr_config_bbp_value);
+ printk(KERN_DEBUG "btw %p\n", &tcr_config_bbp_value);
+ }
+ power_ctrl = tcr_config_bbp_value;
+ }
+
rt2800_bbp_read(rt2x00dev, 1, &r1);
rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, power_ctrl);
rt2800_bbp_write(rt2x00dev, 1, r1);
@@ -5051,15 +5211,16 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
struct ieee80211_channel *chan,
int power_level)
{
- if (rt2x00_rt(rt2x00dev, RT3593) ||
- rt2x00_rt(rt2x00dev, RT3883))
- rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level);
- else
+ // if (rt2x00_rt(rt2x00dev, RT3593) ||
+ // rt2x00_rt(rt2x00dev, RT3883))
+ // rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level);
+ // else
rt2800_config_txpower_rt28xx(rt2x00dev, chan, power_level);
}
void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev)
{
+ // printk(KERN_DEBUG "TIM GAIN CALIBRATION\n");
rt2800_config_txpower(rt2x00dev, rt2x00dev->hw->conf.chandef.chan,
rt2x00dev->tx_power);
}
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index a0967ed..85497bb 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -1322,6 +1322,8 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
{
int retval = -ENOMEM;
+ printk(KERN_DEBUG "TIM LOOK HERE ALSO PROBEDEV");
+
/*
* Set possible interface combinations.
*/
@@ -1425,6 +1427,7 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
/*
* Register extra components.
*/
+ printk(KERN_DEBUG "LINK REG\n");
rt2x00link_register(rt2x00dev);
rt2x00leds_register(rt2x00dev);
rt2x00debug_register(rt2x00dev);
diff --git a/drivers/net/wireless/rt2x00/rt2x00link.c b/drivers/net/wireless/rt2x00/rt2x00link.c
index 9b941c0..dbadd26 100644
--- a/drivers/net/wireless/rt2x00/rt2x00link.c
+++ b/drivers/net/wireless/rt2x00/rt2x00link.c
@@ -418,8 +418,9 @@ void rt2x00link_start_agc(struct rt2x00_dev *rt2x00dev)
{
struct link *link = &rt2x00dev->link;
- if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) &&
- rt2x00dev->ops->lib->gain_calibration)
+ printk(KERN_DEBUG "OH MY GOD TIM TCRTX\n");
+ // if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) &&
+ // rt2x00dev->ops->lib->gain_calibration)
ieee80211_queue_delayed_work(rt2x00dev->hw,
&link->agc_work,
AGC_INTERVAL);
@@ -452,6 +453,8 @@ static void rt2x00link_agc(struct work_struct *work)
container_of(work, struct rt2x00_dev, link.agc_work.work);
struct link *link = &rt2x00dev->link;
+ // printk(KERN_DEBUG "LINK AGC 1");
+
/*
* When the radio is shutting down we should
* immediately cease the watchdog monitoring.
@@ -459,8 +462,12 @@ static void rt2x00link_agc(struct work_struct *work)
if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
return;
+ // printk(KERN_DEBUG "LINK AGC 2 %p\n", rt2x00dev->ops->lib->gain_calibration);
+
rt2x00dev->ops->lib->gain_calibration(rt2x00dev);
+ // printk(KERN_DEBUG "LINK AGC 3");
+
if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
ieee80211_queue_delayed_work(rt2x00dev->hw,
&link->agc_work,
@@ -490,6 +497,7 @@ static void rt2x00link_vcocal(struct work_struct *work)
void rt2x00link_register(struct rt2x00_dev *rt2x00dev)
{
+ printk(KERN_DEBUG "TIM GO DO THIS TCRTX\n");
INIT_DELAYED_WORK(&rt2x00dev->link.agc_work, rt2x00link_agc);
if (rt2x00_has_cap_vco_recalibration(rt2x00dev))
INIT_DELAYED_WORK(&rt2x00dev->link.vco_work, rt2x00link_vcocal);
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
index 68b620b..d630cc0 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
@@ -27,6 +27,13 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/dma-mapping.h>
+#include <linux/stat.h>
+
+// TCRTX
+#include <linux/proc_fs.h>
+#include <linux/string.h>
+#include <linux/vmalloc.h>
+#include <asm/uaccess.h>
#include "rt2x00.h"
#include "rt2x00lib.h"
@@ -389,6 +396,92 @@ static void rt2x00queue_create_tx_descriptor_ht(struct rt2x00_dev *rt2x00dev,
txdesc->u.ht.txop = TXOP_HTTXOP;
}
+// TCRTX
+static int tcr_proc_up = 0;
+
+volatile unsigned int tcr_config_ht = 0;
+volatile unsigned int tcr_config_40 = 0;
+
+volatile unsigned int tcr_config_twxi4_enable = 0;
+volatile unsigned int tcr_config_twxi4_value = 0;
+volatile unsigned int tcr_config_bbp_enable = 0;
+volatile unsigned int tcr_config_bbp_value = 0;
+volatile unsigned int tcr_config_txcfg_enable = 0;
+volatile unsigned int tcr_config_txcfg_value = 0;
+
+int tcr_read(struct file *filp,char *buf,size_t count,void *data )
+{
+ return 0;
+}
+
+static int tcr_readbyte(const char* str, unsigned int *output) {
+ char a = str[0];
+ char b = str[1];
+
+ if (a == 0 || b == 0) {
+ return 0;
+ }
+
+ *output = ((a > 57 ? (a > 90 ? a - 'a' : a - 'A') + 0xa : a - '0') << 8) |
+ (b > 57 ? (b > 90 ? b - 'a' : b - 'A') + 0xa : b - '0');
+ return 1;
+}
+
+ssize_t tcr_write( struct file *filp, const char __user *buff,
+ size_t len, void *data )
+{
+ char tcr_buf[255] = { 0 };
+ copy_from_user(tcr_buf, buff, len > 254 ? 254 : len);
+
+ printk(KERN_DEBUG "TCRTX: Received string '%s'\n", tcr_buf);
+ // eg "0000000000000000" or "0101010101010101"
+
+ unsigned int input = 0;
+ if (tcr_readbyte(&tcr_buf[0], &input)) {
+ // printk(KERN_DEBUG "TCRTX: input %d\n", input);
+ tcr_config_ht = input;
+ printk(KERN_DEBUG "TCRTX: Setting HT to %d\n", tcr_config_ht ? 1 : 0);
+ }
+ if (tcr_readbyte(&tcr_buf[2], &input)) {
+ // printk(KERN_DEBUG "TCRTX: input %d\n", input);
+ tcr_config_40 = input;
+ printk(KERN_DEBUG "TCRTX: Setting 40hz to %d\n", tcr_config_40 ? 1 : 0);
+ }
+ if (tcr_readbyte(&tcr_buf[4], &input)) {
+ tcr_config_twxi4_enable = input;
+ printk(KERN_DEBUG "TCRTX: Setting TWXI4 enable to %d\n", tcr_config_twxi4_enable ? 1 : 0);
+ }
+ if (tcr_readbyte(&tcr_buf[6], &input)) {
+ tcr_config_twxi4_value = input;
+ printk(KERN_DEBUG "TCRTX: Setting TWXI4 value to %d\n", tcr_config_twxi4_value);
+ }
+ if (tcr_readbyte(&tcr_buf[8], &input)) {
+ tcr_config_bbp_enable = input;
+ printk(KERN_DEBUG "TCRTX: Setting BBP enable to %d\n", tcr_config_bbp_enable ? 1 : 0);
+ }
+ if (tcr_readbyte(&tcr_buf[10], &input)) {
+ tcr_config_bbp_value = input;
+ printk(KERN_DEBUG "TCRTX: Setting BBP value to %d\n", tcr_config_bbp_value);
+ }
+ if (tcr_readbyte(&tcr_buf[12], &input)) {
+ tcr_config_txcfg_enable = input;
+ printk(KERN_DEBUG "TCRTX: Setting TXCFG enable to %d\n", tcr_config_txcfg_enable ? 1 : 0);
+ }
+ if (tcr_readbyte(&tcr_buf[14], &input)) {
+ tcr_config_txcfg_value = input;
+ printk(KERN_DEBUG "TCRTX: Setting TXCFG value to %d\n", tcr_config_txcfg_value);
+ }
+
+ return len;
+}
+
+static const struct file_operations tcr_proc_ops = {
+ .owner = THIS_MODULE,
+ .read = tcr_read,
+ .write = tcr_write,
+};
+
+
static void rt2x00queue_create_tx_descriptor(struct rt2x00_dev *rt2x00dev,
struct sk_buff *skb,
struct txentry_desc *txdesc,
@@ -478,6 +571,18 @@ static void rt2x00queue_create_tx_descriptor(struct rt2x00_dev *rt2x00dev,
txdesc->rate_mode = RATE_MODE_CCK;
}
+ // TCRTX
+ if (tcr_proc_up == 0) {
+ tcr_proc_up = 1;
+ proc_create( "tcr-wifi", 0644, NULL, &tcr_proc_ops);
+ }
+ if (tcr_config_ht != 0) {
+ txdesc->rate_mode = RATE_MODE_HT_GREENFIELD;
+ }
+ if (tcr_config_40 != 0) {
+ __set_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags);
+ }
+
/*
* Apply TX descriptor handling by components
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment