developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame^] | 1 | From 558aef638808667341e65d8c11ee7da4266189cd Mon Sep 17 00:00:00 2001 |
| 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Thu, 7 Jul 2022 11:09:59 +0800 |
| 4 | Subject: [PATCH] mt76: mt7915: implement bin file mode |
| 5 | |
| 6 | Change-Id: I2a726341541a11cbecdb210b33a8e79aefbd6cf3 |
| 7 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 8 | --- |
| 9 | eeprom.c | 18 +++++++++++++++++ |
| 10 | mt76.h | 1 + |
| 11 | mt7915/eeprom.c | 53 +++++++++++++++++++++++++++++++++++++++---------- |
| 12 | mt7915/mt7915.h | 10 ++++++++++ |
| 13 | 4 files changed, 71 insertions(+), 11 deletions(-) |
| 14 | |
| 15 | diff --git a/eeprom.c b/eeprom.c |
| 16 | index d172cb0..7e4cb0f 100644 |
| 17 | --- a/eeprom.c |
| 18 | +++ b/eeprom.c |
| 19 | @@ -102,6 +102,24 @@ out_put_node: |
| 20 | } |
| 21 | EXPORT_SYMBOL_GPL(mt76_get_of_eeprom); |
| 22 | |
| 23 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev) |
| 24 | +{ |
| 25 | + struct device_node *np = dev->dev->of_node; |
| 26 | + const __be32 *bin_file_mode; |
| 27 | + bool ret = false; |
| 28 | + |
| 29 | + if (!np) |
| 30 | + return false; |
| 31 | + |
| 32 | + bin_file_mode = of_get_property(np, "bin_file_mode", NULL); |
| 33 | + if (be32_to_cpu(*bin_file_mode)) |
| 34 | + ret = true; |
| 35 | + |
| 36 | + of_node_put(np); |
| 37 | + return ret; |
| 38 | +} |
| 39 | +EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode); |
| 40 | + |
| 41 | void |
| 42 | mt76_eeprom_override(struct mt76_phy *phy) |
| 43 | { |
| 44 | diff --git a/mt76.h b/mt76.h |
| 45 | index 4c8a671..4931489 100644 |
| 46 | --- a/mt76.h |
| 47 | +++ b/mt76.h |
| 48 | @@ -1005,6 +1005,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
| 49 | int mt76_eeprom_init(struct mt76_dev *dev, int len); |
| 50 | void mt76_eeprom_override(struct mt76_phy *phy); |
| 51 | int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len); |
| 52 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev); |
| 53 | |
| 54 | struct mt76_queue * |
| 55 | mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, |
| 56 | diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
| 57 | index ee3049e..98e6a76 100644 |
| 58 | --- a/mt7915/eeprom.c |
| 59 | +++ b/mt7915/eeprom.c |
| 60 | @@ -46,26 +46,36 @@ static char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| 61 | { |
| 62 | switch (mt76_chip(&dev->mt76)) { |
| 63 | case 0x7915: |
| 64 | - return dev->dbdc_support ? |
| 65 | - MT7915_EEPROM_DEFAULT_DBDC : MT7915_EEPROM_DEFAULT; |
| 66 | + if (dev->bin_file_mode) |
| 67 | + return dev->dbdc_support ? |
| 68 | + MT7915_BIN_FILE_DBDC : MT7915_BIN_FILE; |
| 69 | + else |
| 70 | + return dev->dbdc_support ? |
| 71 | + MT7915_EEPROM_DEFAULT_DBDC : MT7915_EEPROM_DEFAULT; |
| 72 | case 0x7986: |
| 73 | switch (mt7915_check_adie(dev, true)) { |
| 74 | case MT7976_ONE_ADIE_DBDC: |
| 75 | - return MT7986_EEPROM_MT7976_DEFAULT_DBDC; |
| 76 | + return dev->bin_file_mode ? |
| 77 | + MT7986_BIN_FILE_MT7976_DBDC : MT7986_EEPROM_MT7976_DEFAULT_DBDC; |
| 78 | case MT7975_ONE_ADIE: |
| 79 | - return MT7986_EEPROM_MT7975_DEFAULT; |
| 80 | + return dev->bin_file_mode ? |
| 81 | + MT7986_BIN_FILE_MT7975 : MT7986_EEPROM_MT7975_DEFAULT; |
| 82 | case MT7976_ONE_ADIE: |
| 83 | - return MT7986_EEPROM_MT7976_DEFAULT; |
| 84 | + return dev->bin_file_mode ? |
| 85 | + MT7986_BIN_FILE_MT7976 : MT7986_EEPROM_MT7976_DEFAULT; |
| 86 | case MT7975_DUAL_ADIE: |
| 87 | - return MT7986_EEPROM_MT7975_DUAL_DEFAULT; |
| 88 | + return dev->bin_file_mode ? |
| 89 | + MT7986_BIN_FILE_MT7975_DUAL : MT7986_EEPROM_MT7975_DUAL_DEFAULT; |
| 90 | case MT7976_DUAL_ADIE: |
| 91 | - return MT7986_EEPROM_MT7976_DUAL_DEFAULT; |
| 92 | + return dev->bin_file_mode ? |
| 93 | + MT7986_BIN_FILE_MT7976_DUAL : MT7986_EEPROM_MT7976_DUAL_DEFAULT; |
| 94 | default: |
| 95 | break; |
| 96 | } |
| 97 | return NULL; |
| 98 | default: |
| 99 | - return MT7916_EEPROM_DEFAULT; |
| 100 | + return dev->bin_file_mode ? |
| 101 | + MT7916_BIN_FILE : MT7916_EEPROM_DEFAULT; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | @@ -81,7 +91,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) |
| 106 | return ret; |
| 107 | |
| 108 | if (!fw || !fw->data) { |
| 109 | - dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 110 | + if (dev->bin_file_mode) |
| 111 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n"); |
| 112 | + else |
| 113 | + dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 114 | ret = -EINVAL; |
| 115 | goto out; |
| 116 | } |
| 117 | @@ -234,12 +247,30 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) |
| 118 | { |
| 119 | int ret; |
| 120 | |
| 121 | - ret = mt7915_eeprom_load(dev); |
| 122 | + dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76); |
| 123 | + |
| 124 | + if (dev->bin_file_mode) { |
| 125 | + dev->mt76.eeprom.size = mt7915_eeprom_size(dev); |
| 126 | + dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size, |
| 127 | + GFP_KERNEL); |
| 128 | + if (!dev->mt76.eeprom.data) |
| 129 | + return -ENOMEM; |
| 130 | + ret = mt7915_eeprom_load_default(dev); |
| 131 | + } else { |
| 132 | + ret = mt7915_eeprom_load(dev); |
| 133 | + } |
| 134 | + |
| 135 | if (ret < 0) { |
| 136 | if (ret != -EINVAL) |
| 137 | return ret; |
| 138 | |
| 139 | - dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); |
| 140 | + if (dev->bin_file_mode) { |
| 141 | + dev_warn(dev->mt76.dev, "bin file load fail, use default bin\n"); |
| 142 | + dev->bin_file_mode = false; |
| 143 | + } else { |
| 144 | + dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); |
| 145 | + } |
| 146 | + |
| 147 | ret = mt7915_eeprom_load_default(dev); |
| 148 | if (ret) |
| 149 | return ret; |
| 150 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| 151 | index fb8bd87..a81bc7c 100644 |
| 152 | --- a/mt7915/mt7915.h |
| 153 | +++ b/mt7915/mt7915.h |
| 154 | @@ -51,6 +51,15 @@ |
| 155 | #define MT7986_EEPROM_MT7976_DEFAULT_DBDC "mediatek/mt7986_eeprom_mt7976_dbdc.bin" |
| 156 | #define MT7986_EEPROM_MT7976_DUAL_DEFAULT "mediatek/mt7986_eeprom_mt7976_dual.bin" |
| 157 | |
| 158 | +#define MT7915_BIN_FILE "mediatek/mt7915_binfile.bin" |
| 159 | +#define MT7915_BIN_FILE_DBDC "mediatek/mt7915_binfile_dbdc.bin" |
| 160 | +#define MT7916_BIN_FILE "mediatek/mt7916_binfile.bin" |
| 161 | +#define MT7986_BIN_FILE_MT7975 "mediatek/mt7986_binfile_mt7975.bin" |
| 162 | +#define MT7986_BIN_FILE_MT7975_DUAL "mediatek/mt7986_binfile_mt7975_dual.bin" |
| 163 | +#define MT7986_BIN_FILE_MT7976 "mediatek/mt7986_binfile_mt7976.bin" |
| 164 | +#define MT7986_BIN_FILE_MT7976_DBDC "mediatek/mt7986_binfile_mt7976_dbdc.bin" |
| 165 | +#define MT7986_BIN_FILE_MT7976_DUAL "mediatek/mt7986_binfile_mt7976_dual.bin" |
| 166 | + |
| 167 | #define MT7915_EEPROM_SIZE 3584 |
| 168 | #define MT7916_EEPROM_SIZE 4096 |
| 169 | |
| 170 | @@ -377,6 +386,7 @@ struct mt7915_dev { |
| 171 | |
| 172 | bool dbdc_support; |
| 173 | bool flash_mode; |
| 174 | + bool bin_file_mode; |
| 175 | bool muru_debug; |
| 176 | bool ibf; |
| 177 | |
| 178 | -- |
| 179 | 2.18.0 |
| 180 | |