blob: db53404bcd597b5b51065c0f8d58de54d10bb48f [file] [log] [blame]
developer55a79b52022-11-18 16:01:14 +08001From f7cb9b3ad2c0207db231a16d04beea22be1ef798 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
developerb403ad02022-11-08 10:16:29 +08004Subject: [PATCH 1121/1128] mt76: mt7915: implement bin file mode
developer072c5612022-07-15 18:30:03 +08005
6Change-Id: I2a726341541a11cbecdb210b33a8e79aefbd6cf3
7Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
8---
developer55a79b52022-11-18 16:01:14 +08009 eeprom.c | 18 +++++++++++++++
10 mt76.h | 1 +
11 mt7915/eeprom.c | 52 ++++++++++++++++++++------------------------
12 mt7915/eeprom.h | 44 +++++++++++++++++++++++++++++++++++++
13 mt7915/mt7915.h | 17 ++++++++++++---
14 mt7915/mtk_debugfs.c | 36 ++++++++++++++++++++++++++++++
15 6 files changed, 136 insertions(+), 32 deletions(-)
developer072c5612022-07-15 18:30:03 +080016
17diff --git a/eeprom.c b/eeprom.c
developer55a79b52022-11-18 16:01:14 +080018index e083964..5b9faf7 100644
developer072c5612022-07-15 18:30:03 +080019--- a/eeprom.c
20+++ b/eeprom.c
developer28b11e22022-09-05 19:09:45 +080021@@ -104,6 +104,24 @@ out_put_node:
developer072c5612022-07-15 18:30:03 +080022 }
23 EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
24
25+bool mt76_check_bin_file_mode(struct mt76_dev *dev)
26+{
27+ struct device_node *np = dev->dev->of_node;
28+ const __be32 *bin_file_mode;
29+ bool ret = false;
30+
31+ if (!np)
32+ return false;
33+
34+ bin_file_mode = of_get_property(np, "bin_file_mode", NULL);
35+ if (bin_file_mode && be32_to_cpu(*bin_file_mode))
36+ ret = true;
37+
38+ of_node_put(np);
39+ return ret;
40+}
41+EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode);
42+
43 void
44 mt76_eeprom_override(struct mt76_phy *phy)
45 {
46diff --git a/mt76.h b/mt76.h
developer55a79b52022-11-18 16:01:14 +080047index 0a9552b..e29f490 100644
developer072c5612022-07-15 18:30:03 +080048--- a/mt76.h
49+++ b/mt76.h
developer047bc182022-11-16 12:20:48 +080050@@ -1010,6 +1010,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
developer072c5612022-07-15 18:30:03 +080051 int mt76_eeprom_init(struct mt76_dev *dev, int len);
52 void mt76_eeprom_override(struct mt76_phy *phy);
53 int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len);
54+bool mt76_check_bin_file_mode(struct mt76_dev *dev);
55
56 struct mt76_queue *
57 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
58diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developer55a79b52022-11-18 16:01:14 +080059index 0f5862e..4d2d9ca 100644
developer072c5612022-07-15 18:30:03 +080060--- a/mt7915/eeprom.c
61+++ b/mt7915/eeprom.c
developer55a79b52022-11-18 16:01:14 +080062@@ -42,33 +42,6 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
63 }
64 }
65
66-static char *mt7915_eeprom_name(struct mt7915_dev *dev)
67-{
68- switch (mt76_chip(&dev->mt76)) {
69- case 0x7915:
developer072c5612022-07-15 18:30:03 +080070- return dev->dbdc_support ?
71- MT7915_EEPROM_DEFAULT_DBDC : MT7915_EEPROM_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080072- case 0x7986:
73- switch (mt7915_check_adie(dev, true)) {
74- case MT7976_ONE_ADIE_DBDC:
developer072c5612022-07-15 18:30:03 +080075- return MT7986_EEPROM_MT7976_DEFAULT_DBDC;
developer55a79b52022-11-18 16:01:14 +080076- case MT7975_ONE_ADIE:
developer072c5612022-07-15 18:30:03 +080077- return MT7986_EEPROM_MT7975_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080078- case MT7976_ONE_ADIE:
developer072c5612022-07-15 18:30:03 +080079- return MT7986_EEPROM_MT7976_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080080- case MT7975_DUAL_ADIE:
developer072c5612022-07-15 18:30:03 +080081- return MT7986_EEPROM_MT7975_DUAL_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080082- case MT7976_DUAL_ADIE:
developer072c5612022-07-15 18:30:03 +080083- return MT7986_EEPROM_MT7976_DUAL_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080084- default:
85- break;
86- }
87- return NULL;
88- default:
developer072c5612022-07-15 18:30:03 +080089- return MT7916_EEPROM_DEFAULT;
developer55a79b52022-11-18 16:01:14 +080090- }
91-}
92-
93 static int
94 mt7915_eeprom_load_default(struct mt7915_dev *dev)
95 {
96@@ -81,7 +54,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev)
developer072c5612022-07-15 18:30:03 +080097 return ret;
98
99 if (!fw || !fw->data) {
100- dev_err(dev->mt76.dev, "Invalid default bin\n");
101+ if (dev->bin_file_mode)
102+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n");
103+ else
104+ dev_err(dev->mt76.dev, "Invalid default bin\n");
105 ret = -EINVAL;
106 goto out;
107 }
developer55a79b52022-11-18 16:01:14 +0800108@@ -106,6 +82,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
109
110 if (ret) {
111 dev->flash_mode = true;
112+ dev->eeprom_mode = FLASH_MODE;
113 } else {
114 u8 free_block_num;
115 u32 block_num, i;
116@@ -121,6 +98,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
117 for (i = 0; i < block_num; i++)
118 mt7915_mcu_get_eeprom(dev,
119 i * MT7915_EEPROM_BLOCK_SIZE);
120+ dev->eeprom_mode = EFUSE_MODE;
121 }
122
123 return mt7915_check_eeprom(dev);
124@@ -224,12 +202,28 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
developer072c5612022-07-15 18:30:03 +0800125 {
126 int ret;
127
128- ret = mt7915_eeprom_load(dev);
129+ dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
130+
131+ if (dev->bin_file_mode) {
132+ dev->mt76.eeprom.size = mt7915_eeprom_size(dev);
133+ dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
developer55a79b52022-11-18 16:01:14 +0800134+ GFP_KERNEL);
developer072c5612022-07-15 18:30:03 +0800135+ if (!dev->mt76.eeprom.data)
136+ return -ENOMEM;
137+ ret = mt7915_eeprom_load_default(dev);
developer55a79b52022-11-18 16:01:14 +0800138+ dev->eeprom_mode = BIN_FILE_MODE;
developer072c5612022-07-15 18:30:03 +0800139+ } else {
140+ ret = mt7915_eeprom_load(dev);
141+ }
142+
143 if (ret < 0) {
144 if (ret != -EINVAL)
145 return ret;
146
developer55a79b52022-11-18 16:01:14 +0800147 dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
148+ dev->bin_file_mode = false;
149+ dev->eeprom_mode = DEFAULT_BIN_MODE;
developer072c5612022-07-15 18:30:03 +0800150+
151 ret = mt7915_eeprom_load_default(dev);
152 if (ret)
153 return ret;
developer55a79b52022-11-18 16:01:14 +0800154diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
155index fdae347..f228926 100644
156--- a/mt7915/eeprom.h
157+++ b/mt7915/eeprom.h
158@@ -108,6 +108,13 @@ enum mt7915_sku_rate_group {
159 MAX_SKU_RATE_GROUP_NUM,
160 };
161
162+enum mt7915_eeprom_mode {
163+ DEFAULT_BIN_MODE,
164+ EFUSE_MODE,
165+ FLASH_MODE,
166+ BIN_FILE_MODE,
167+};
168+
169 static inline int
170 mt7915_get_channel_group_5g(int channel, bool is_7976)
171 {
172@@ -184,6 +191,43 @@ mt7915_get_cal_group_size(struct mt7915_dev *dev)
173 }
174 }
175
176+static inline char *mt7915_eeprom_name(struct mt7915_dev *dev)
177+{
178+ switch (mt76_chip(&dev->mt76)) {
179+ case 0x7915:
180+ if (dev->bin_file_mode)
181+ return dev->dbdc_support ?
182+ MT7915_BIN_FILE_DBDC : MT7915_BIN_FILE;
183+ else
184+ return dev->dbdc_support ?
185+ MT7915_EEPROM_DEFAULT_DBDC : MT7915_EEPROM_DEFAULT;
186+ case 0x7986:
187+ switch (mt7915_check_adie(dev, true)) {
188+ case MT7976_ONE_ADIE_DBDC:
189+ return dev->bin_file_mode ?
190+ MT7986_BIN_FILE_MT7976_DBDC : MT7986_EEPROM_MT7976_DEFAULT_DBDC;
191+ case MT7975_ONE_ADIE:
192+ return dev->bin_file_mode ?
193+ MT7986_BIN_FILE_MT7975 : MT7986_EEPROM_MT7975_DEFAULT;
194+ case MT7976_ONE_ADIE:
195+ return dev->bin_file_mode ?
196+ MT7986_BIN_FILE_MT7976 : MT7986_EEPROM_MT7976_DEFAULT;
197+ case MT7975_DUAL_ADIE:
198+ return dev->bin_file_mode ?
199+ MT7986_BIN_FILE_MT7975_DUAL : MT7986_EEPROM_MT7975_DUAL_DEFAULT;
200+ case MT7976_DUAL_ADIE:
201+ return dev->bin_file_mode ?
202+ MT7986_BIN_FILE_MT7976_DUAL : MT7986_EEPROM_MT7976_DUAL_DEFAULT;
203+ default:
204+ break;
205+ }
206+ return NULL;
207+ default:
208+ return dev->bin_file_mode ?
209+ MT7916_BIN_FILE : MT7916_EEPROM_DEFAULT;
210+ }
211+}
212+
213 extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM];
214
215 #endif
developer072c5612022-07-15 18:30:03 +0800216diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer55a79b52022-11-18 16:01:14 +0800217index 1cfa6f0..9b72f41 100644
developer072c5612022-07-15 18:30:03 +0800218--- a/mt7915/mt7915.h
219+++ b/mt7915/mt7915.h
developer55a79b52022-11-18 16:01:14 +0800220@@ -42,15 +42,24 @@
221 #define MT7986_ROM_PATCH "mediatek/mt7986_rom_patch.bin"
222 #define MT7986_ROM_PATCH_MT7975 "mediatek/mt7986_rom_patch_mt7975.bin"
223
224-#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin"
225-#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin"
226-#define MT7916_EEPROM_DEFAULT "mediatek/mt7916_eeprom.bin"
227+#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin"
228+#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin"
229+#define MT7916_EEPROM_DEFAULT "mediatek/mt7916_eeprom.bin"
230 #define MT7986_EEPROM_MT7975_DEFAULT "mediatek/mt7986_eeprom_mt7975.bin"
231 #define MT7986_EEPROM_MT7975_DUAL_DEFAULT "mediatek/mt7986_eeprom_mt7975_dual.bin"
232 #define MT7986_EEPROM_MT7976_DEFAULT "mediatek/mt7986_eeprom_mt7976.bin"
developer072c5612022-07-15 18:30:03 +0800233 #define MT7986_EEPROM_MT7976_DEFAULT_DBDC "mediatek/mt7986_eeprom_mt7976_dbdc.bin"
234 #define MT7986_EEPROM_MT7976_DUAL_DEFAULT "mediatek/mt7986_eeprom_mt7976_dual.bin"
235
developer55a79b52022-11-18 16:01:14 +0800236+#define MT7915_BIN_FILE "mediatek/mt7915_binfile.bin"
237+#define MT7915_BIN_FILE_DBDC "mediatek/mt7915_binfile_dbdc.bin"
238+#define MT7916_BIN_FILE "mediatek/mt7916_binfile.bin"
developer072c5612022-07-15 18:30:03 +0800239+#define MT7986_BIN_FILE_MT7975 "mediatek/mt7986_binfile_mt7975.bin"
240+#define MT7986_BIN_FILE_MT7975_DUAL "mediatek/mt7986_binfile_mt7975_dual.bin"
241+#define MT7986_BIN_FILE_MT7976 "mediatek/mt7986_binfile_mt7976.bin"
242+#define MT7986_BIN_FILE_MT7976_DBDC "mediatek/mt7986_binfile_mt7976_dbdc.bin"
243+#define MT7986_BIN_FILE_MT7976_DUAL "mediatek/mt7986_binfile_mt7976_dual.bin"
244+
245 #define MT7915_EEPROM_SIZE 3584
246 #define MT7916_EEPROM_SIZE 4096
247
developer55a79b52022-11-18 16:01:14 +0800248@@ -395,6 +404,8 @@ struct mt7915_dev {
developer072c5612022-07-15 18:30:03 +0800249
250 bool dbdc_support;
251 bool flash_mode;
252+ bool bin_file_mode;
developer55a79b52022-11-18 16:01:14 +0800253+ u8 eeprom_mode;
developer072c5612022-07-15 18:30:03 +0800254 bool muru_debug;
255 bool ibf;
256
developer55a79b52022-11-18 16:01:14 +0800257diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
258index 9de5b0f..36cb6f0 100644
259--- a/mt7915/mtk_debugfs.c
260+++ b/mt7915/mtk_debugfs.c
261@@ -3,6 +3,7 @@
262 #include "mt7915_debug.h"
263 #include "mac.h"
264 #include "mcu.h"
265+#include "eeprom.h"
266
267 #ifdef MTK_DEBUG
268 #define LWTBL_IDX2BASE_ID GENMASK(14, 8)
269@@ -2893,6 +2894,39 @@ mt7915_wa_debug(void *data, u64 val)
270 DEFINE_DEBUGFS_ATTRIBUTE(fops_wa_debug, NULL, mt7915_wa_debug,
271 "0x%llx\n");
272
273+static int mt7915_show_eeprom_mode(struct seq_file *s, void *data)
274+{
275+ struct mt7915_dev *dev = dev_get_drvdata(s->private);
276+ struct mt76_dev *mdev = &dev->mt76;
277+ char *mtd_name = mdev->test_mtd.name;
278+ u32 mtd_offset = mdev->test_mtd.offset;
279+
280+ seq_printf(s, "Current eeprom mode:\n");
281+
282+ switch (dev->eeprom_mode) {
283+ case DEFAULT_BIN_MODE:
284+ seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev));
285+ break;
286+ case EFUSE_MODE:
287+ seq_printf(s, " efuse mode\n");
288+ break;
289+ case FLASH_MODE:
290+ if (mtd_name)
291+ seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n",
292+ mtd_name, mtd_offset);
293+ else
294+ seq_printf(s, " flash mode\n");
295+ break;
296+ case BIN_FILE_MODE:
297+ seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev));
298+ break;
299+ default:
300+ break;
301+ }
302+
303+ return 0;
304+}
305+
306 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
307 {
308 struct mt7915_dev *dev = phy->dev;
309@@ -2973,6 +3007,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
310 debugfs_create_devm_seqfile(dev->mt76.dev, "fw_version", dir,
311 mt7915_dump_version);
312
313+ debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir,
314+ mt7915_show_eeprom_mode);
315 return 0;
316 }
317 #endif
developer072c5612022-07-15 18:30:03 +0800318--
developerb403ad02022-11-08 10:16:29 +08003192.18.0
developer072c5612022-07-15 18:30:03 +0800320