blob: 1357d9a4974280f037e313632145a484a1e5ad26 [file] [log] [blame]
developer4eb49d92022-12-05 11:29:56 +08001From a811ab8ab270c406e6360910a3dc09255990b3aa Mon Sep 17 00:00:00 2001
developer072c5612022-07-15 18:30:03 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Thu, 7 Jul 2022 11:09:59 +0800
developer4eb49d92022-12-05 11:29:56 +08004Subject: [PATCH 1122/1128] mt76: mt7915: implement bin file mode
developer072c5612022-07-15 18:30:03 +08005
developer072c5612022-07-15 18:30:03 +08006Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
7---
developer55a79b52022-11-18 16:01:14 +08008 eeprom.c | 18 +++++++++++++++
9 mt76.h | 1 +
10 mt7915/eeprom.c | 52 ++++++++++++++++++++------------------------
11 mt7915/eeprom.h | 44 +++++++++++++++++++++++++++++++++++++
12 mt7915/mt7915.h | 17 ++++++++++++---
developerea1a48c2022-11-21 11:36:55 +080013 mt7915/mtk_debugfs.c | 41 ++++++++++++++++++++++++++++++++++
14 6 files changed, 141 insertions(+), 32 deletions(-)
developer072c5612022-07-15 18:30:03 +080015
16diff --git a/eeprom.c b/eeprom.c
developer3609d782022-11-29 18:07:22 +080017index e083964b..5b9faf7e 100644
developer072c5612022-07-15 18:30:03 +080018--- a/eeprom.c
19+++ b/eeprom.c
developer28b11e22022-09-05 19:09:45 +080020@@ -104,6 +104,24 @@ out_put_node:
developer072c5612022-07-15 18:30:03 +080021 }
22 EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
23
24+bool mt76_check_bin_file_mode(struct mt76_dev *dev)
25+{
26+ struct device_node *np = dev->dev->of_node;
27+ const __be32 *bin_file_mode;
28+ bool ret = false;
29+
30+ if (!np)
31+ return false;
32+
33+ bin_file_mode = of_get_property(np, "bin_file_mode", NULL);
34+ if (bin_file_mode && be32_to_cpu(*bin_file_mode))
35+ ret = true;
36+
37+ of_node_put(np);
38+ return ret;
39+}
40+EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode);
41+
42 void
43 mt76_eeprom_override(struct mt76_phy *phy)
44 {
45diff --git a/mt76.h b/mt76.h
developer3609d782022-11-29 18:07:22 +080046index 8139b4ad..db2075c3 100644
developer072c5612022-07-15 18:30:03 +080047--- a/mt76.h
48+++ b/mt76.h
developer3609d782022-11-29 18:07:22 +080049@@ -1027,6 +1027,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
developer072c5612022-07-15 18:30:03 +080050 int mt76_eeprom_init(struct mt76_dev *dev, int len);
51 void mt76_eeprom_override(struct mt76_phy *phy);
52 int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len);
53+bool mt76_check_bin_file_mode(struct mt76_dev *dev);
54
55 struct mt76_queue *
56 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
57diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developer3609d782022-11-29 18:07:22 +080058index 0f5862e3..4d2d9ca2 100644
developer072c5612022-07-15 18:30:03 +080059--- a/mt7915/eeprom.c
60+++ b/mt7915/eeprom.c
developer55a79b52022-11-18 16:01:14 +080061@@ -42,33 +42,6 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
62 }
63 }
64
65-static char *mt7915_eeprom_name(struct mt7915_dev *dev)
66-{
67- switch (mt76_chip(&dev->mt76)) {
68- case 0x7915:
developer072c5612022-07-15 18:30:03 +080069- return dev->dbdc_support ?
70- MT7915_EEPROM_DEFAULT_DBDC : MT7915_EEPROM_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080071- case 0x7986:
72- switch (mt7915_check_adie(dev, true)) {
73- case MT7976_ONE_ADIE_DBDC:
developer072c5612022-07-15 18:30:03 +080074- return MT7986_EEPROM_MT7976_DEFAULT_DBDC;
developer55a79b52022-11-18 16:01:14 +080075- case MT7975_ONE_ADIE:
developer072c5612022-07-15 18:30:03 +080076- return MT7986_EEPROM_MT7975_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080077- case MT7976_ONE_ADIE:
developer072c5612022-07-15 18:30:03 +080078- return MT7986_EEPROM_MT7976_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080079- case MT7975_DUAL_ADIE:
developer072c5612022-07-15 18:30:03 +080080- return MT7986_EEPROM_MT7975_DUAL_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080081- case MT7976_DUAL_ADIE:
developer072c5612022-07-15 18:30:03 +080082- return MT7986_EEPROM_MT7976_DUAL_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080083- default:
84- break;
85- }
86- return NULL;
87- default:
developer072c5612022-07-15 18:30:03 +080088- return MT7916_EEPROM_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080089- }
90-}
91-
92 static int
93 mt7915_eeprom_load_default(struct mt7915_dev *dev)
94 {
95@@ -81,7 +54,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev)
developer072c5612022-07-15 18:30:03 +080096 return ret;
97
98 if (!fw || !fw->data) {
99- dev_err(dev->mt76.dev, "Invalid default bin\n");
100+ if (dev->bin_file_mode)
101+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n");
102+ else
103+ dev_err(dev->mt76.dev, "Invalid default bin\n");
104 ret = -EINVAL;
105 goto out;
106 }
developer55a79b52022-11-18 16:01:14 +0800107@@ -106,6 +82,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
108
109 if (ret) {
110 dev->flash_mode = true;
111+ dev->eeprom_mode = FLASH_MODE;
112 } else {
113 u8 free_block_num;
114 u32 block_num, i;
115@@ -121,6 +98,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
116 for (i = 0; i < block_num; i++)
117 mt7915_mcu_get_eeprom(dev,
118 i * MT7915_EEPROM_BLOCK_SIZE);
119+ dev->eeprom_mode = EFUSE_MODE;
120 }
121
122 return mt7915_check_eeprom(dev);
123@@ -224,12 +202,28 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
developer072c5612022-07-15 18:30:03 +0800124 {
125 int ret;
126
127- ret = mt7915_eeprom_load(dev);
128+ dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
129+
130+ if (dev->bin_file_mode) {
131+ dev->mt76.eeprom.size = mt7915_eeprom_size(dev);
132+ dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
developer55a79b52022-11-18 16:01:14 +0800133+ GFP_KERNEL);
developer072c5612022-07-15 18:30:03 +0800134+ if (!dev->mt76.eeprom.data)
135+ return -ENOMEM;
136+ ret = mt7915_eeprom_load_default(dev);
developer55a79b52022-11-18 16:01:14 +0800137+ dev->eeprom_mode = BIN_FILE_MODE;
developer072c5612022-07-15 18:30:03 +0800138+ } else {
139+ ret = mt7915_eeprom_load(dev);
140+ }
141+
142 if (ret < 0) {
143 if (ret != -EINVAL)
144 return ret;
145
developer55a79b52022-11-18 16:01:14 +0800146 dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
147+ dev->bin_file_mode = false;
148+ dev->eeprom_mode = DEFAULT_BIN_MODE;
developer072c5612022-07-15 18:30:03 +0800149+
150 ret = mt7915_eeprom_load_default(dev);
151 if (ret)
152 return ret;
developer55a79b52022-11-18 16:01:14 +0800153diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developer3609d782022-11-29 18:07:22 +0800154index fdae347e..f228926b 100644
developer55a79b52022-11-18 16:01:14 +0800155--- a/mt7915/eeprom.h
156+++ b/mt7915/eeprom.h
157@@ -108,6 +108,13 @@ enum mt7915_sku_rate_group {
158 MAX_SKU_RATE_GROUP_NUM,
159 };
160
161+enum mt7915_eeprom_mode {
162+ DEFAULT_BIN_MODE,
163+ EFUSE_MODE,
164+ FLASH_MODE,
165+ BIN_FILE_MODE,
166+};
167+
168 static inline int
169 mt7915_get_channel_group_5g(int channel, bool is_7976)
170 {
171@@ -184,6 +191,43 @@ mt7915_get_cal_group_size(struct mt7915_dev *dev)
172 }
173 }
174
175+static inline char *mt7915_eeprom_name(struct mt7915_dev *dev)
176+{
177+ switch (mt76_chip(&dev->mt76)) {
178+ case 0x7915:
179+ if (dev->bin_file_mode)
180+ return dev->dbdc_support ?
181+ MT7915_BIN_FILE_DBDC : MT7915_BIN_FILE;
182+ else
183+ return dev->dbdc_support ?
184+ MT7915_EEPROM_DEFAULT_DBDC : MT7915_EEPROM_DEFAULT;
185+ case 0x7986:
186+ switch (mt7915_check_adie(dev, true)) {
187+ case MT7976_ONE_ADIE_DBDC:
188+ return dev->bin_file_mode ?
189+ MT7986_BIN_FILE_MT7976_DBDC : MT7986_EEPROM_MT7976_DEFAULT_DBDC;
190+ case MT7975_ONE_ADIE:
191+ return dev->bin_file_mode ?
192+ MT7986_BIN_FILE_MT7975 : MT7986_EEPROM_MT7975_DEFAULT;
193+ case MT7976_ONE_ADIE:
194+ return dev->bin_file_mode ?
195+ MT7986_BIN_FILE_MT7976 : MT7986_EEPROM_MT7976_DEFAULT;
196+ case MT7975_DUAL_ADIE:
197+ return dev->bin_file_mode ?
198+ MT7986_BIN_FILE_MT7975_DUAL : MT7986_EEPROM_MT7975_DUAL_DEFAULT;
199+ case MT7976_DUAL_ADIE:
200+ return dev->bin_file_mode ?
201+ MT7986_BIN_FILE_MT7976_DUAL : MT7986_EEPROM_MT7976_DUAL_DEFAULT;
202+ default:
203+ break;
204+ }
205+ return NULL;
206+ default:
207+ return dev->bin_file_mode ?
208+ MT7916_BIN_FILE : MT7916_EEPROM_DEFAULT;
209+ }
210+}
211+
212 extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM];
213
214 #endif
developer072c5612022-07-15 18:30:03 +0800215diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer3609d782022-11-29 18:07:22 +0800216index aaab5f7a..5a206f7a 100644
developer072c5612022-07-15 18:30:03 +0800217--- a/mt7915/mt7915.h
218+++ b/mt7915/mt7915.h
developer55a79b52022-11-18 16:01:14 +0800219@@ -42,15 +42,24 @@
220 #define MT7986_ROM_PATCH "mediatek/mt7986_rom_patch.bin"
221 #define MT7986_ROM_PATCH_MT7975 "mediatek/mt7986_rom_patch_mt7975.bin"
222
223-#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin"
224-#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin"
225-#define MT7916_EEPROM_DEFAULT "mediatek/mt7916_eeprom.bin"
226+#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin"
227+#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin"
228+#define MT7916_EEPROM_DEFAULT "mediatek/mt7916_eeprom.bin"
229 #define MT7986_EEPROM_MT7975_DEFAULT "mediatek/mt7986_eeprom_mt7975.bin"
230 #define MT7986_EEPROM_MT7975_DUAL_DEFAULT "mediatek/mt7986_eeprom_mt7975_dual.bin"
231 #define MT7986_EEPROM_MT7976_DEFAULT "mediatek/mt7986_eeprom_mt7976.bin"
developer072c5612022-07-15 18:30:03 +0800232 #define MT7986_EEPROM_MT7976_DEFAULT_DBDC "mediatek/mt7986_eeprom_mt7976_dbdc.bin"
233 #define MT7986_EEPROM_MT7976_DUAL_DEFAULT "mediatek/mt7986_eeprom_mt7976_dual.bin"
234
developer55a79b52022-11-18 16:01:14 +0800235+#define MT7915_BIN_FILE "mediatek/mt7915_binfile.bin"
236+#define MT7915_BIN_FILE_DBDC "mediatek/mt7915_binfile_dbdc.bin"
237+#define MT7916_BIN_FILE "mediatek/mt7916_binfile.bin"
developer072c5612022-07-15 18:30:03 +0800238+#define MT7986_BIN_FILE_MT7975 "mediatek/mt7986_binfile_mt7975.bin"
239+#define MT7986_BIN_FILE_MT7975_DUAL "mediatek/mt7986_binfile_mt7975_dual.bin"
240+#define MT7986_BIN_FILE_MT7976 "mediatek/mt7986_binfile_mt7976.bin"
241+#define MT7986_BIN_FILE_MT7976_DBDC "mediatek/mt7986_binfile_mt7976_dbdc.bin"
242+#define MT7986_BIN_FILE_MT7976_DUAL "mediatek/mt7986_binfile_mt7976_dual.bin"
243+
244 #define MT7915_EEPROM_SIZE 3584
245 #define MT7916_EEPROM_SIZE 4096
246
developer3609d782022-11-29 18:07:22 +0800247@@ -397,6 +406,8 @@ struct mt7915_dev {
developer072c5612022-07-15 18:30:03 +0800248
249 bool dbdc_support;
250 bool flash_mode;
251+ bool bin_file_mode;
developer55a79b52022-11-18 16:01:14 +0800252+ u8 eeprom_mode;
developer072c5612022-07-15 18:30:03 +0800253 bool muru_debug;
254 bool ibf;
255
developer55a79b52022-11-18 16:01:14 +0800256diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developer4eb49d92022-12-05 11:29:56 +0800257index d96f222a..9a9e0cb6 100644
developer55a79b52022-11-18 16:01:14 +0800258--- a/mt7915/mtk_debugfs.c
259+++ b/mt7915/mtk_debugfs.c
260@@ -3,6 +3,7 @@
261 #include "mt7915_debug.h"
262 #include "mac.h"
263 #include "mcu.h"
264+#include "eeprom.h"
265
266 #ifdef MTK_DEBUG
267 #define LWTBL_IDX2BASE_ID GENMASK(14, 8)
developerea1a48c2022-11-21 11:36:55 +0800268@@ -2893,6 +2894,44 @@ mt7915_wa_debug(void *data, u64 val)
developer55a79b52022-11-18 16:01:14 +0800269 DEFINE_DEBUGFS_ATTRIBUTE(fops_wa_debug, NULL, mt7915_wa_debug,
270 "0x%llx\n");
271
272+static int mt7915_show_eeprom_mode(struct seq_file *s, void *data)
273+{
274+ struct mt7915_dev *dev = dev_get_drvdata(s->private);
275+ struct mt76_dev *mdev = &dev->mt76;
developerea1a48c2022-11-21 11:36:55 +0800276+#ifdef CONFIG_NL80211_TESTMODE
developer55a79b52022-11-18 16:01:14 +0800277+ char *mtd_name = mdev->test_mtd.name;
278+ u32 mtd_offset = mdev->test_mtd.offset;
developerea1a48c2022-11-21 11:36:55 +0800279+#else
280+ char *mtd_name;
281+ u32 mtd_offset;
282+#endif
developer55a79b52022-11-18 16:01:14 +0800283+
284+ seq_printf(s, "Current eeprom mode:\n");
285+
286+ switch (dev->eeprom_mode) {
287+ case DEFAULT_BIN_MODE:
288+ seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev));
289+ break;
290+ case EFUSE_MODE:
291+ seq_printf(s, " efuse mode\n");
292+ break;
293+ case FLASH_MODE:
294+ if (mtd_name)
295+ seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n",
296+ mtd_name, mtd_offset);
297+ else
298+ seq_printf(s, " flash mode\n");
299+ break;
300+ case BIN_FILE_MODE:
301+ seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev));
302+ break;
303+ default:
304+ break;
305+ }
306+
307+ return 0;
308+}
309+
310 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
311 {
312 struct mt7915_dev *dev = phy->dev;
developerea1a48c2022-11-21 11:36:55 +0800313@@ -2973,6 +3012,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
developer55a79b52022-11-18 16:01:14 +0800314 debugfs_create_devm_seqfile(dev->mt76.dev, "fw_version", dir,
315 mt7915_dump_version);
316
317+ debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir,
318+ mt7915_show_eeprom_mode);
319 return 0;
320 }
321 #endif
developer072c5612022-07-15 18:30:03 +0800322--
developer4eb49d92022-12-05 11:29:56 +08003232.36.1
developer072c5612022-07-15 18:30:03 +0800324